Blame SOURCES/0078-tcurl-add-support-for-http-basic-auth.patch

ecf709
From 1c543722b2b1c55b06c3cc02ace987fc68bc26d7 Mon Sep 17 00:00:00 2001
ecf709
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
ecf709
Date: Tue, 28 Feb 2017 13:32:31 +0100
ecf709
Subject: [PATCH 78/90] tcurl: add support for http basic auth
ecf709
ecf709
Reviewed-by: Simo Sorce <simo@redhat.com>
ecf709
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
ecf709
(cherry picked from commit c2ea75da72b426d98ba489039e220d417bfb4c2a)
ecf709
---
ecf709
 src/tests/tcurl_test_tool.c | 14 ++++++++++++++
ecf709
 src/util/tev_curl.c         | 24 ++++++++++++++++++++++++
ecf709
 src/util/tev_curl.h         | 15 +++++++++++++++
ecf709
 3 files changed, 53 insertions(+)
ecf709
ecf709
diff --git a/src/tests/tcurl_test_tool.c b/src/tests/tcurl_test_tool.c
ecf709
index 9cec000fbf2e4eca2fdc5213c8b3b4cb10f1df1b..4ceef8e06040ea0abd4d112a5b7845f436c69488 100644
ecf709
--- a/src/tests/tcurl_test_tool.c
ecf709
+++ b/src/tests/tcurl_test_tool.c
ecf709
@@ -45,6 +45,9 @@ struct tool_options {
ecf709
     const char *socket_path;
ecf709
     const char *capath;
ecf709
     const char *cacert;
ecf709
+
ecf709
+    const char *username;
ecf709
+    const char *password;
ecf709
 };
ecf709
 
ecf709
 static void request_done(struct tevent_req *req)
ecf709
@@ -194,6 +197,14 @@ prepare_requests(TALLOC_CTX *mem_ctx,
ecf709
             }
ecf709
         }
ecf709
 
ecf709
+        if (opts->username != NULL && opts->password != NULL) {
ecf709
+            ret = tcurl_req_http_basic_auth(requests[i], opts->username,
ecf709
+                                            opts->password);
ecf709
+            if (ret != EOK) {
ecf709
+                goto done;
ecf709
+            }
ecf709
+        }
ecf709
+
ecf709
         i++;
ecf709
     }
ecf709
 
ecf709
@@ -299,6 +310,9 @@ int main(int argc, const char *argv[])
ecf709
         { "verify-host", '\0', POPT_ARG_NONE, &opts.verify_host, '\0', "Verify host when TLS is enabled", NULL },
ecf709
         { "capath", '\0', POPT_ARG_STRING, &opts.capath, '\0', "Path to CA directory where peer certificate is stored", NULL },
ecf709
         { "cacert", '\0', POPT_ARG_STRING, &opts.cacert, '\0', "Path to CA certificate", NULL },
ecf709
+        /* BASIC AUTH */
ecf709
+        { "username", '\0', POPT_ARG_STRING, &opts.username, '\0', "Username for basic authentication", NULL },
ecf709
+        { "password", '\0', POPT_ARG_STRING, &opts.password, '\0', "Password for basic authentication", NULL },
ecf709
         POPT_TABLEEND
ecf709
     };
ecf709
 
ecf709
diff --git a/src/util/tev_curl.c b/src/util/tev_curl.c
ecf709
index c155f4c038d4215933ee30d41c694ad4a14ae132..8faf07c714b636a0351be365597de68d2f68a1be 100644
ecf709
--- a/src/util/tev_curl.c
ecf709
+++ b/src/util/tev_curl.c
ecf709
@@ -1092,3 +1092,27 @@ errno_t tcurl_req_set_client_cert(struct tcurl_request *tcurl_req,
ecf709
 
ecf709
     return EOK;
ecf709
 }
ecf709
+
ecf709
+errno_t tcurl_req_http_basic_auth(struct tcurl_request *tcurl_req,
ecf709
+                                  const char *username,
ecf709
+                                  const char *password)
ecf709
+{
ecf709
+    errno_t ret;
ecf709
+
ecf709
+    ret = tcurl_set_option(tcurl_req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
ecf709
+    if (ret != EOK) {
ecf709
+        return ret;
ecf709
+    }
ecf709
+
ecf709
+    ret = tcurl_set_option(tcurl_req, CURLOPT_USERNAME, username);
ecf709
+    if (ret != EOK) {
ecf709
+        return ret;
ecf709
+    }
ecf709
+
ecf709
+    ret = tcurl_set_option(tcurl_req, CURLOPT_PASSWORD, password);
ecf709
+    if (ret != EOK) {
ecf709
+        return ret;
ecf709
+    }
ecf709
+
ecf709
+    return EOK;
ecf709
+}
ecf709
diff --git a/src/util/tev_curl.h b/src/util/tev_curl.h
ecf709
index 933abcb9b531412737e8fcf391644d828b125cf8..c733127b3686b5665f53cf53ea72674e0d7af64e 100644
ecf709
--- a/src/util/tev_curl.h
ecf709
+++ b/src/util/tev_curl.h
ecf709
@@ -243,4 +243,19 @@ errno_t tcurl_req_set_client_cert(struct tcurl_request *tcurl_req,
ecf709
                                   const char *cert,
ecf709
                                   const char *key);
ecf709
 
ecf709
+/**
ecf709
+ * @brief Force HTTP basic authentication with @username and @password.
ecf709
+ *
ecf709
+ * @param[in]  tcurl_request
ecf709
+ * @param[in]  username
ecf709
+ * @param[in]  password
ecf709
+ *
ecf709
+ * @returns errno code
ecf709
+ *
ecf709
+ * @see tcurl_http
ecf709
+ */
ecf709
+errno_t tcurl_req_http_basic_auth(struct tcurl_request *tcurl_req,
ecf709
+                                  const char *username,
ecf709
+                                  const char *password);
ecf709
+
ecf709
 #endif /* __TEV_CURL_H */
ecf709
-- 
ecf709
2.9.3
ecf709