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

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