Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions etc/davfs2.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# use_proxy 1 # system wide config file only
# proxy # system wide config file only
# proxy_type http # system wide config file only
# trust_ca_cert
# servercert # deprecated: use trust_ca_cert
# trust_server_cert
Expand Down
11 changes: 11 additions & 0 deletions man/davfs2.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ must be appended, separated by a colon. Examples: \fIfoo.bar:1704\fP or
.br
\fBOnly allowed in the system wide configuration file.\fR

.TP
.B proxy_type
Type of the proxy. Supported values are: http, socks4, socks4a, socks5. When
set to socks4 or socks4a, a username is required for authenticating with the
proxy. The username (and password) can be provided interactively in the
terminal or in the file specified in \fBsecrets\fR.
.br
Default: http
.br
\fBOnly allowed in the system wide configuration file.\fR

.TP
.B trust_ca_cert
Name of a certificate file in PEM format. The name of the file may be
Expand Down
6 changes: 3 additions & 3 deletions man/mount.davfs.8
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,10 @@ line arguments; especially relevant in the context of CI runners.
.TP
.B https_proxy http_proxy all_proxy
If no proxy is defined in the configuration file the value is taken from
this environment variables. The proxy may be given with or without scheme
and with or without port
this environment variables. The proxy must be given with scheme and with or
without port.
.br
http_proxy=[http://]foo.bar[:3218]
http_proxy=http://foo.bar[:3218]
.br
Only used when the mounting user is root.

Expand Down
5 changes: 5 additions & 0 deletions src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
variable. */
#define DAV_DEFAULT_PROXY_PORT 8080

/* The default proxy type.
May be overridden by system config file, user config file or environment
variable. */
#define DAV_DEFAULT_PROXY_TYPE dav_proxy_type_http

/* Whether to use a proxy if one is specified.
May be overridden by command line or fstab. */
#define DAV_USE_PROXY 1
Expand Down
65 changes: 54 additions & 11 deletions src/mount_davfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <stdlib.h>
#endif
#include <string.h>
#include <strings.h>
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif
Expand Down Expand Up @@ -215,6 +216,9 @@ log_dbg_config(dav_args *args);
static int
parse_line(char *line, int parmc, char *parmv[]);

static int
parse_proxy_type(const char *s, dav_proxy_type *p_type);

static void
proxy_from_env(dav_args *args);

Expand Down Expand Up @@ -1850,6 +1854,7 @@ new_args(void)

args->p_host = NULL;
args->p_port = DAV_DEFAULT_PROXY_PORT;
args->p_type = DAV_DEFAULT_PROXY_TYPE;
args->p_user = NULL;
args->p_passwd = NULL;
args->useproxy = DAV_USE_PROXY;
Expand Down Expand Up @@ -1958,6 +1963,8 @@ log_dbg_config(dav_args *args)
" p_host: %s", args->p_host);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
" p_port: %i", args->p_port);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
" p_type: %i", (int)args->p_type);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
" useproxy: %i", args->useproxy);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
Expand Down Expand Up @@ -2172,9 +2179,25 @@ parse_line(char *line, int parmc, char *parmv[])
return parm_no;
}

/* Parses proxy type from string and returns 0 on success and -1 on error */
static int
parse_proxy_type(const char *s, dav_proxy_type *p_type)
{
if (strcmp(s, "http") == 0)
*p_type = dav_proxy_type_http;
else if (strcmp(s, "socks4") == 0)
*p_type = dav_proxy_type_socks4;
else if (strcmp(s, "socks4a") == 0)
*p_type = dav_proxy_type_socks4a;
else if (strcmp(s, "socks5") == 0)
*p_type = dav_proxy_type_socks5;
else
return -1;
return 0;
}

/* Checks for a matching xxx_proxy environment variable, and if found
stores values in args->p_host and ars->p_port. */
stores values in args->p_host, args->p_port and args->p_type. */
static void
proxy_from_env(dav_args *args)
{
Expand All @@ -2193,12 +2216,17 @@ proxy_from_env(dav_args *args)
int port = 0;
split_uri(&scheme, &host, &port, NULL, env);

if (scheme && strcmp(scheme, "http") == 0 && host) {
if (args->p_host) free(args->p_host);
args->p_host = host;
host = NULL;
if (port)
args->p_port = port;
if (scheme && host) {
if (parse_proxy_type(scheme, &args->p_type) == 0) {
if (args->p_host) free(args->p_host);
args->p_host = host;
host = NULL;
if (port)
args->p_port = port;
} else {
WARN(_("unsupported proxy scheme in environment variable: %s"),
scheme);
}
}

if (scheme) free(scheme);
Expand Down Expand Up @@ -2278,6 +2306,11 @@ read_config(dav_args *args, const char * filename, int system)
if (split_uri(NULL, &args->p_host, &args->p_port, NULL,
parmv[1]) != 0)
ERR_AT_LINE(filename, lineno, _("malformed line"));
} else if (system && strcmp(parmv[0], "proxy_type") == 0) {
if (parse_proxy_type(parmv[1], &args->p_type) != 0) {
ERR_AT_LINE(filename, lineno,
_("unsupported proxy type: %s"), parmv[1]);
}
} else if (system && strcmp(parmv[0], "use_proxy") == 0) {
args->useproxy = arg_to_int(parmv[1], 10, parmv[0]);
} else if (strcmp(parmv[0], "ask_auth") == 0) {
Expand Down Expand Up @@ -2576,8 +2609,8 @@ read_secrets(dav_args *args, const char *filename)
not contain userinfo. It shall not contain a query or fragment component;
they would be treated as part of path.
The path component must *not* be %-encoded. scheme, if present in uri,
must be either http or https. If host is a IPv6 address, it must be enclosed
in square brackets.
must be either http, https, socks4, socks4a or socks5. If host is an IPv6
address, it must be enclosed in square brackets.
The pointers to the components may be NULL. If they point to a non-NULL
string, it is freed and then replaced by a newly allocated string.
If no scheme is foud the default sheme "http" is returned.
Expand All @@ -2593,10 +2626,20 @@ split_uri(char **scheme, char **host, int *port,char **path, const char *uri)
int po = 0;
const char *ho = strstr(uri, "://");
if (ho) {
if ((ho - uri) == 4 && strcasestr(uri, "http") == uri) {
if ((ho - uri) == 4 && strncasecmp(uri, "http", 4) == 0) {
sch = "http";
} else if ((ho - uri) == 5 && strcasestr(uri, "https") == uri) {
} else if ((ho - uri) == 5 && strncasecmp(uri, "https", 5) == 0) {
sch = "https";
} else if ((ho - uri) == 6) {
if (strncasecmp(uri, "socks5", 6) == 0) {
sch = "socks5";
} else if (strncasecmp(uri, "socks4", 6) == 0) {
sch = "socks4";
} else {
return -1;
}
} else if ((ho - uri) == 7 && strncasecmp(uri, "socks4a", 7) == 0) {
sch = "socks4a";
} else {
return -1;
}
Expand Down
15 changes: 12 additions & 3 deletions src/mount_davfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
/* Data Types */
/*============*/

/* This enum lists the supported proxy types */
typedef enum dav_proxy_type {
dav_proxy_type_http,
dav_proxy_type_socks4,
dav_proxy_type_socks4a,
dav_proxy_type_socks5
} dav_proxy_type;

/* This data structure holds almost everything davfs gathers while reading and
checking command line and configuration files. (See comment for data origin;
highest precedence first.)
Expand Down Expand Up @@ -61,11 +69,12 @@ typedef struct {
char *password; /* User secrets file, system secrets file */
char *clicert; /* User config file, system config file */
char *clicert_pw; /* User secrets file, system secrets file */
char *p_host; /* User config file, sys conf f., environment */
int p_port; /* User config file, sys conf f., environment */
char *p_host; /* System config file, environment */
int p_port; /* System config file, environment */
dav_proxy_type p_type; /* System config file, environment */
char *p_user; /* User secrets file, system secrets file */
char *p_passwd; /* User secrets file, system secrets file */
int useproxy; /* User config file, sys conf f., command line */
int useproxy; /* System config file, command line */
int askauth; /* User config file, sys conf f., command line */
int locks; /* User config file, sys conf f., command line */
char * lock_owner; /* User config file, system config file */
Expand Down
41 changes: 35 additions & 6 deletions src/webdav.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,41 @@ dav_init_webdav(const dav_args *args)
ne_add_server_auth(session, NE_AUTH_ALL, auth, "server");

if (args->useproxy && args->p_host) {
ne_session_proxy(session, args->p_host, args->p_port);
if (args->p_user)
p_username = ne_strdup(args->p_user);
if (args->p_passwd)
p_password = ne_strdup(args->p_passwd);
ne_add_proxy_auth(session, NE_AUTH_ALL, auth, "proxy");
if (args->p_type == dav_proxy_type_http) {
ne_session_proxy(session, args->p_host, args->p_port);
if (args->p_user)
p_username = ne_strdup(args->p_user);
if (args->p_passwd)
p_password = ne_strdup(args->p_passwd);
ne_add_proxy_auth(session, NE_AUTH_ALL, auth, "proxy");
} else {
enum ne_sock_sversion socks_ver = NE_SOCK_SOCKSV5;
switch (args->p_type) {
case dav_proxy_type_socks4:
if (!args->p_user) {
ERR(_("proxy username not set,"
" but is required for socks4"));
}
socks_ver = NE_SOCK_SOCKSV4;
break;
case dav_proxy_type_socks4a:
if (!args->p_user) {
ERR(_("proxy username not set,"
" but is required for socks4a"));
}
socks_ver = NE_SOCK_SOCKSV4A;
break;
case dav_proxy_type_socks5:
socks_ver = NE_SOCK_SOCKSV5;
break;
default:
ERR(_("invalid proxy type: %i"), (int)args->p_type);
break;
}

ne_session_socks_proxy(session, socks_ver,
args->p_host, args->p_port, args->p_user, args->p_passwd);
}
}


Expand Down