Browse Source

Check for auth error when uploading a share to a server.

When attempting to upload a share to a remote server (http or https
URI), check the response code to detect authentication failure
(curl_easy_perform does not do that by itself).
master
Damien Goutte-Gattat 2 months ago
parent
commit
c0870023c1
  1. 2
      configure.ac
  2. 12
      src/scheme-libcurl.c

2
configure.ac

@ -45,7 +45,7 @@ PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.22],
[have_gio=no])
dnl Check for LibCURL
LIBCURL_CHECK_CONFIG([yes], [],
LIBCURL_CHECK_CONFIG([yes], [7.10.8],
[have_libcurl=yes
CFLAGS="$CFLAGS $LIBCURL_CPPFLAGS"
LIBS="$LIBS $LIBCURL"],

12
src/scheme-libcurl.c

@ -154,16 +154,26 @@ gfsec_scheme_libcurl_put_file(gfsec_scheme_t scheme,
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
curl_easy_setopt(curl, CURLOPT_READDATA, (void *)&data);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, dummy_write_cb);
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
if ( curl_easy_setopt(curl, CURLOPT_URL, url) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, len) != 0 )
if ( ret == 0 && curl_easy_setopt(curl, CURLOPT_INFILESIZE, len) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
if ( ret == 0 && curl_easy_perform(curl) != 0 )
ret = GFSEC_SCHEME_STATUS_ERROR;
/* Check for authentication error. */
if ( ret == 0 ) {
long http_code;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if ( http_code == 401 )
ret = GFSEC_SCHEME_STATUS_ERROR;
}
curl_easy_cleanup(curl);
free(url);

Loading…
Cancel
Save