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

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