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

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