# HG changeset patch # User Mike Becker # Date 1444653376 -7200 # Node ID 3cfb4670d9e65c94973e0e7cc9f61dedc5585a33 # Parent 2721730643196067341c0d400c0dffdc38505b76 added possibility to configure authentication methods via coma separated list in config.xml diff -r 272173064319 -r 3cfb4670d9e6 dav/config.c --- a/dav/config.c Thu Oct 08 14:25:53 2015 +0200 +++ b/dav/config.c Mon Oct 12 14:36:16 2015 +0200 @@ -161,6 +161,7 @@ repo->decrypt_name = false; repo->decrypt_content = true; repo->ssl_version = CURL_SSLVERSION_DEFAULT; + repo->authmethods = CURLAUTH_BASIC; return repo; } @@ -202,7 +203,7 @@ ucx_map_cstr_put(repos, repo->name, repo); } -int repo_add_config(Repository *repo, char *key, char *value) { +int repo_add_config(Repository *repo, char *key, char *value) { if(xstreq(key, "name")) { repo->name = strdup(value); } else if(xstreq(key, "url")) { @@ -253,6 +254,30 @@ else { fprintf(stderr, "Unknown ssl version: %s\n", value); } + } else if(xstreq(key, "authmethods")) { + repo->authmethods = CURLAUTH_NONE; + const char *delims = " ,\r\n"; + char *meths = strdup(value); + char *meth = strtok(meths, delims); + while (meth) { + if(xstrEQ(value, "basic")) { + repo->authmethods |= CURLAUTH_BASIC; + } else if(xstrEQ(value, "digest")) { + repo->authmethods |= CURLAUTH_DIGEST; + } else if(xstrEQ(value, "negotiate")) { + repo->authmethods |= CURLAUTH_GSSNEGOTIATE; + } else if(xstrEQ(value, "ntlm")) { + repo->authmethods |= CURLAUTH_NTLM; + } else if(xstrEQ(value, "any")) { + repo->authmethods = CURLAUTH_ANY; + } else if(xstrEQ(value, "none")) { + /* skip */ + } else { + fprintf(stderr, "Unknown authentication method: %s\n", value); + } + meth = strtok(NULL, delims); + } + free(meths); } else { return -1; } diff -r 272173064319 -r 3cfb4670d9e6 dav/config.h --- a/dav/config.h Thu Oct 08 14:25:53 2015 +0200 +++ b/dav/config.h Mon Oct 12 14:36:16 2015 +0200 @@ -63,6 +63,7 @@ bool decrypt_content; bool decrypt_name; int ssl_version; + unsigned long authmethods; }; struct Proxy { diff -r 272173064319 -r 3cfb4670d9e6 dav/main.c --- a/dav/main.c Thu Oct 08 14:25:53 2015 +0200 +++ b/dav/main.c Mon Oct 12 14:36:16 2015 +0200 @@ -344,6 +344,7 @@ DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password); sn->flags = get_repository_flags(repo); sn->key = dav_context_get_key(ctx, repo->default_key); + curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods); curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version); return sn; }