Blame SOURCES/0082-ureport-support-HTTP-Basic-authentication.patch

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