From: Michael Tremer Date: Tue, 17 Oct 2023 16:24:58 +0000 (+0000) Subject: downloader: Add method enable authentication X-Git-Tag: 0.9.30~1457 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d2ae99c18dcc5885adde693abd1c475d8c84b49;p=pakfire.git downloader: Add method enable authentication Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index 0c9aa96ef..db6375cb5 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -84,6 +84,9 @@ struct pakfire_transfer { char baseurl[PATH_MAX]; struct pakfire_mirrorlist* mirrors; struct pakfire_mirror* mirror; + + // Authentication + unsigned int auth; }; struct pakfire_downloader { @@ -531,6 +534,13 @@ int pakfire_downloader_transfer_set_target( return pakfire_string_set(transfer->path, path); } +int pakfire_downloader_transfer_auth(struct pakfire_transfer* transfer) { + // Enable authentication + transfer->auth = 1; + + return 0; +} + static int pakfire_transfer_select_mirror(struct pakfire_downloader* downloader, struct pakfire_transfer* transfer) { // Choose the next mirror @@ -935,6 +945,23 @@ static int pakfire_downloader_transfer_prepare(struct pakfire_downloader* downlo } } + // Authentication + if (transfer->auth) { + // Request SPNEGO + r = curl_easy_setopt(transfer->handle, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE|CURLAUTH_ONLY); + if (r) { + CTX_ERROR(downloader->ctx, "Could not enable SPNEGO\n"); + return r; + } + + // Set an empty username + r = curl_easy_setopt(transfer->handle, CURLOPT_USERPWD, ":"); + if (r) { + CTX_ERROR(downloader->ctx, "Could not set username\n"); + return r; + } + } + // Drop any previously used EVP contexts if (transfer->evp) { EVP_MD_CTX_free(transfer->evp);