|
|
562801 |
From 2725a768826f832a2b37ee21fa306d6ec02472b9 Mon Sep 17 00:00:00 2001
|
|
|
562801 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
562801 |
Date: Tue, 16 Sep 2014 12:57:49 +0200
|
|
|
562801 |
Subject: [LIBREPORT PATCH 82/93] ureport: support HTTP Basic authentication
|
|
|
562801 |
|
|
|
562801 |
Relate to rhbz#1139987
|
|
|
562801 |
|
|
|
562801 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
562801 |
---
|
|
|
562801 |
src/include/ureport.h | 16 ++++++++++++++++
|
|
|
562801 |
src/lib/ureport.c | 36 ++++++++++++++++++++++++++++++++++++
|
|
|
562801 |
2 files changed, 52 insertions(+)
|
|
|
562801 |
|
|
|
562801 |
diff --git a/src/include/ureport.h b/src/include/ureport.h
|
|
|
562801 |
index 3fffed7..3ee12cd 100644
|
|
|
562801 |
--- a/src/include/ureport.h
|
|
|
562801 |
+++ b/src/include/ureport.h
|
|
|
562801 |
@@ -23,6 +23,8 @@
|
|
|
562801 |
extern "C" {
|
|
|
562801 |
#endif
|
|
|
562801 |
|
|
|
562801 |
+#include "internal_libreport.h"
|
|
|
562801 |
+
|
|
|
562801 |
#define UREPORT_CONF_FILE_PATH PLUGINS_CONF_DIR"/ureport.conf"
|
|
|
562801 |
|
|
|
562801 |
#define UREPORT_OPTION_VALUE_FROM_CONF(settings, opt, var, tr) do { const char *value = getenv("uReport_"opt); \
|
|
|
562801 |
@@ -50,6 +52,8 @@ struct ureport_server_config
|
|
|
562801 |
char *ur_client_cert; ///< Path to certificate used for client
|
|
|
562801 |
///< authentication (or NULL)
|
|
|
562801 |
char *ur_client_key; ///< Private key for the certificate
|
|
|
562801 |
+ char *ur_username; ///< username for basic HTTP auth
|
|
|
562801 |
+ char *ur_password; ///< password for basic HTTP auth
|
|
|
562801 |
map_string_t *ur_http_headers; ///< Additional HTTP headers
|
|
|
562801 |
|
|
|
562801 |
struct ureport_preferences ur_prefs; ///< configuration for uReport generation
|
|
|
562801 |
@@ -99,6 +103,18 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
const char *client_auth);
|
|
|
562801 |
|
|
|
562801 |
/*
|
|
|
562801 |
+ * Configure user name and password for HTTP Basic authentication
|
|
|
562801 |
+ *
|
|
|
562801 |
+ * @param config Configured structure
|
|
|
562801 |
+ * @param username User name
|
|
|
562801 |
+ * @param password Password
|
|
|
562801 |
+ */
|
|
|
562801 |
+#define ureport_server_config_set_basic_auth libreport_ureport_server_config_set_basic_auth
|
|
|
562801 |
+void
|
|
|
562801 |
+ureport_server_config_set_basic_auth(struct ureport_server_config *config,
|
|
|
562801 |
+ const char *username, const char *password);
|
|
|
562801 |
+
|
|
|
562801 |
+/*
|
|
|
562801 |
* uReport server response
|
|
|
562801 |
*/
|
|
|
562801 |
struct ureport_server_response
|
|
|
562801 |
diff --git a/src/lib/ureport.c b/src/lib/ureport.c
|
|
|
562801 |
index e1816ef..5453a37 100644
|
|
|
562801 |
--- a/src/lib/ureport.c
|
|
|
562801 |
+++ b/src/lib/ureport.c
|
|
|
562801 |
@@ -70,8 +70,12 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
|
|
|
562801 |
if (strcmp(client_auth, "") == 0)
|
|
|
562801 |
{
|
|
|
562801 |
+ free(config->ur_client_cert);
|
|
|
562801 |
config->ur_client_cert = NULL;
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_client_key);
|
|
|
562801 |
config->ur_client_key = NULL;
|
|
|
562801 |
+
|
|
|
562801 |
log_notice("Not using client authentication");
|
|
|
562801 |
}
|
|
|
562801 |
else if (strcmp(client_auth, "rhsm") == 0)
|
|
|
562801 |
@@ -181,10 +185,29 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
|
|
|
562801 |
{
|
|
|
562801 |
log_notice("Using client certificate: %s", config->ur_client_cert);
|
|
|
562801 |
log_notice("Using client private key: %s", config->ur_client_key);
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_username);
|
|
|
562801 |
+ config->ur_username = NULL;
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_password);
|
|
|
562801 |
+ config->ur_password = NULL;
|
|
|
562801 |
}
|
|
|
562801 |
}
|
|
|
562801 |
|
|
|
562801 |
void
|
|
|
562801 |
+ureport_server_config_set_basic_auth(struct ureport_server_config *config,
|
|
|
562801 |
+ const char *login, const char *password)
|
|
|
562801 |
+{
|
|
|
562801 |
+ ureport_server_config_set_client_auth(config, "");
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_username);
|
|
|
562801 |
+ config->ur_username = xstrdup(login);
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_password);
|
|
|
562801 |
+ config->ur_password = xstrdup(password);
|
|
|
562801 |
+}
|
|
|
562801 |
+
|
|
|
562801 |
+void
|
|
|
562801 |
ureport_server_config_load(struct ureport_server_config *config,
|
|
|
562801 |
map_string_t *settings)
|
|
|
562801 |
{
|
|
|
562801 |
@@ -216,6 +239,8 @@ ureport_server_config_init(struct ureport_server_config *config)
|
|
|
562801 |
config->ur_ssl_verify = true;
|
|
|
562801 |
config->ur_client_cert = NULL;
|
|
|
562801 |
config->ur_client_key = NULL;
|
|
|
562801 |
+ config->ur_username = NULL;
|
|
|
562801 |
+ config->ur_password = NULL;
|
|
|
562801 |
config->ur_http_headers = new_map_string();
|
|
|
562801 |
config->ur_prefs.urp_auth_items = NULL;
|
|
|
562801 |
}
|
|
|
562801 |
@@ -229,6 +254,12 @@ ureport_server_config_destroy(struct ureport_server_config *config)
|
|
|
562801 |
free(config->ur_client_key);
|
|
|
562801 |
config->ur_client_key = DESTROYED_POINTER;
|
|
|
562801 |
|
|
|
562801 |
+ free(config->ur_username);
|
|
|
562801 |
+ config->ur_username = DESTROYED_POINTER;
|
|
|
562801 |
+
|
|
|
562801 |
+ free(config->ur_password);
|
|
|
562801 |
+ config->ur_password = DESTROYED_POINTER;
|
|
|
562801 |
+
|
|
|
562801 |
g_list_free_full(config->ur_prefs.urp_auth_items, free);
|
|
|
562801 |
config->ur_prefs.urp_auth_items = DESTROYED_POINTER;
|
|
|
562801 |
|
|
|
562801 |
@@ -619,6 +650,11 @@ ureport_do_post(const char *json, struct ureport_server_config *config,
|
|
|
562801 |
post_state->client_cert_path = config->ur_client_cert;
|
|
|
562801 |
post_state->client_key_path = config->ur_client_key;
|
|
|
562801 |
}
|
|
|
562801 |
+ else if (config->ur_username && config->ur_password)
|
|
|
562801 |
+ {
|
|
|
562801 |
+ post_state->username = config->ur_username;
|
|
|
562801 |
+ post_state->password = config->ur_password;
|
|
|
562801 |
+ }
|
|
|
562801 |
|
|
|
562801 |
char **headers = xmalloc(sizeof(char *) * (3 + size_map_string(config->ur_http_headers)));
|
|
|
562801 |
headers[0] = (char *)"Accept: application/json";
|
|
|
562801 |
--
|
|
|
562801 |
1.8.3.1
|
|
|
562801 |
|