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