Blame SOURCES/0102-ureport-get-rhsm-entitlement-cert-dir-from-rhsm-conf.patch

28bab8
From 2b20c9f91342da7744ae40ee623735ab95f83219 Mon Sep 17 00:00:00 2001
28bab8
From: Jakub Filak <jfilak@redhat.com>
28bab8
Date: Wed, 22 Oct 2014 14:27:00 +0200
28bab8
Subject: [LIBREPORT PATCH 102/105] ureport: get rhsm entitlement cert dir from
28bab8
 rhsm conf
28bab8
28bab8
Related #1140224
28bab8
28bab8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
28bab8
---
28bab8
 src/lib/ureport.c | 46 +++++++++++++++++++++++++++++++++++++++++-----
28bab8
 1 file changed, 41 insertions(+), 5 deletions(-)
28bab8
28bab8
diff --git a/src/lib/ureport.c b/src/lib/ureport.c
28bab8
index 5782b4e..41f4531 100644
28bab8
--- a/src/lib/ureport.c
28bab8
+++ b/src/lib/ureport.c
28bab8
@@ -32,7 +32,6 @@
28bab8
 
28bab8
 #define RHSM_WEB_SERVICE_URL "https://api.access.redhat.com/rs/telemetry/abrt"
28bab8
 
28bab8
-#define RHSMENT_PEM_DIR_PATH "/etc/pki/entitlement"
28bab8
 #define RHSMENT_ENT_DATA_BEGIN_TAG "-----BEGIN ENTITLEMENT DATA-----"
28bab8
 #define RHSMENT_ENT_DATA_END_TAG "-----END ENTITLEMENT DATA-----"
28bab8
 #define RHSMENT_SIG_DATA_BEGIN_TAG "-----BEGIN RSA SIGNATURE-----"
28bab8
@@ -69,6 +68,33 @@ ureport_server_config_set_url(struct ureport_server_config *config,
28bab8
     config->ur_url = server_url;
28bab8
 }
28bab8
 
28bab8
+static char *
28bab8
+rhsm_config_get_entitlement_cert_dir(void)
28bab8
+{
28bab8
+    char *result = getenv("LIBREPORT_DEBUG_RHSMENT_PEM_DIR_PATH");
28bab8
+    if (result != NULL)
28bab8
+        return xstrdup(result);
28bab8
+
28bab8
+    result = run_in_shell_and_save_output(0,
28bab8
+            "python -c \"from rhsm.config import initConfig; print(initConfig().get('rhsm', 'entitlementCertDir'))\"",
28bab8
+            NULL, NULL);
28bab8
+
28bab8
+    /* run_in_shell_and_save_output always returns non-NULL */
28bab8
+    if (result[0] != '/')
28bab8
+        goto error;
28bab8
+
28bab8
+    char *newline = strchrnul(result, '\n');
28bab8
+    if (!newline)
28bab8
+        goto error;
28bab8
+
28bab8
+    *newline = '\0';
28bab8
+    return result;
28bab8
+error:
28bab8
+    error_msg("Failed to get 'rhsm':'entitlementCertDir' from rhsm.config python module.");
28bab8
+    free(result);
28bab8
+    return NULL;
28bab8
+}
28bab8
+
28bab8
 void
28bab8
 ureport_server_config_set_client_auth(struct ureport_server_config *config,
28bab8
                                       const char *client_auth)
28bab8
@@ -91,13 +117,21 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
28bab8
         if (config->ur_url == NULL)
28bab8
             ureport_server_config_set_url(config, xstrdup(RHSM_WEB_SERVICE_URL));
28bab8
 
28bab8
-        GList *certs = get_file_list(RHSMENT_PEM_DIR_PATH, "pem");
28bab8
+        char *rhsm_dir = rhsm_config_get_entitlement_cert_dir();
28bab8
+        if (rhsm_dir == NULL)
28bab8
+        {
28bab8
+            log_notice("Not using client authentication");
28bab8
+            return;
28bab8
+        }
28bab8
+
28bab8
+        GList *certs = get_file_list(rhsm_dir, "pem");
28bab8
         if (g_list_length(certs) < 2)
28bab8
         {
28bab8
             g_list_free_full(certs, (GDestroyNotify)free_file_obj);
28bab8
 
28bab8
-            log_notice(RHSMENT_PEM_DIR_PATH" does not contain unique cert-key files pair");
28bab8
+            log_notice("'%s' does not contain a cert-key files pair", rhsm_dir);
28bab8
             log_notice("Not using client authentication");
28bab8
+            free(rhsm_dir);
28bab8
             return;
28bab8
         }
28bab8
 
28bab8
@@ -116,8 +150,9 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
28bab8
         {
28bab8
             g_list_free_full(certs, (GDestroyNotify)free_file_obj);
28bab8
 
28bab8
-            log_notice(RHSMENT_PEM_DIR_PATH" contains only key files");
28bab8
+            log_notice("'%s' does not contain a cert file (only keys)", rhsm_dir);
28bab8
             log_notice("Not using client authentication");
28bab8
+            free(rhsm_dir);
28bab8
             return;
28bab8
         }
28bab8
 
28bab8
@@ -125,7 +160,8 @@ ureport_server_config_set_client_auth(struct ureport_server_config *config,
28bab8
         /* Yes, the key file may not exists. I over took this code from
28bab8
          * sos-uploader and they are pretty happy with this approach, so why
28bab8
          * shouldn't we?. */
28bab8
-        config->ur_client_key = xasprintf("%s/%s-key.pem", RHSMENT_PEM_DIR_PATH, fo_get_filename(cert));
28bab8
+        config->ur_client_key = xasprintf("%s/%s-key.pem", rhsm_dir, fo_get_filename(cert));
28bab8
+        free(rhsm_dir);
28bab8
 
28bab8
         log_debug("Using cert files: '%s' : '%s'", config->ur_client_cert, config->ur_client_key);
28bab8
 
28bab8
-- 
28bab8
1.8.3.1
28bab8