Blame SOURCES/0090-upload-read-credentials-from-environment-variables.patch

562801
From 5b7d6f911920043671ef8aa0a9e559bfb6f3a3c8 Mon Sep 17 00:00:00 2001
562801
From: Jakub Filak <jfilak@redhat.com>
562801
Date: Tue, 30 Sep 2014 01:46:07 +0200
562801
Subject: [LIBREPORT PATCH 90/93] upload: read credentials from environment
562801
 variables
562801
562801
We use environment variables for the per-user-configuration.
562801
562801
Adding new configuration options to the configuration file for
562801
credentials doesn't make sense because the credentials can be part of
562801
the URL (everything is plain text in the configuration file). But it
562801
does make sense to add a support for environment variables which are
562801
used to propagate the configuration from the GUI where the URL field is
562801
plain text but the password field cannot be read.
562801
562801
Related to rhbz#1066486
562801
562801
Signed-off-by: Jakub Filak <jfilak@redhat.com>
562801
562801
Conflicts:
562801
	doc/reporter-upload.txt
562801
---
562801
 doc/reporter-upload.txt            |  5 +++++
562801
 src/plugins/report_Uploader.xml.in | 10 ++++++++++
562801
 src/plugins/reporter-upload.c      | 24 +++++++++++++++++++++++-
562801
 3 files changed, 38 insertions(+), 1 deletion(-)
562801
562801
diff --git a/doc/reporter-upload.txt b/doc/reporter-upload.txt
562801
index 8df7ea2..e813c58 100644
562801
--- a/doc/reporter-upload.txt
562801
+++ b/doc/reporter-upload.txt
562801
@@ -68,6 +68,11 @@ the configuration file.
562801
 'Upload_URL'::
562801
    The URL where should be the tarball uploaded.
562801
 
562801
+'Upload_Username'::
562801
+   User name for the upload URL
562801
+
562801
+'Upload_Password'::
562801
+   Password for the upload URL
562801
 
562801
 SEE ALSO
562801
 --------
562801
diff --git a/src/plugins/report_Uploader.xml.in b/src/plugins/report_Uploader.xml.in
562801
index df01e21..a136aad 100644
562801
--- a/src/plugins/report_Uploader.xml.in
562801
+++ b/src/plugins/report_Uploader.xml.in
562801
@@ -19,6 +19,16 @@
562801
             <_note-html>Examples:
ftp://[user[:pass]@]host/dir/[file.tar.gz]
scp://[user[:pass]@]host/dir/[file.tar.gz]
file:///dir/[file.tar.gz]</_note-html>
562801
             <default-value></default-value>
562801
         </option>
562801
+        <option type="text" name="Upload_Username">
562801
+            <_label>User name</_label>
562801
+            <allow-empty>no</allow-empty>
562801
+            <_description>Use this field if you do not want to have user name in URL</_description>
562801
+        </option>
562801
+        <option type="password" name="Upload_Password">
562801
+            <_label>Password</_label>
562801
+            <allow-empty>no</allow-empty>
562801
+            <_description>Use this field if you do not want to have password in URL</_description>
562801
+        </option>
562801
         <advanced-options>
562801
             <option type="text" name="http_proxy">
562801
                 <_label>HTTP Proxy</_label>
562801
diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c
562801
index 7783557..f934953 100644
562801
--- a/src/plugins/reporter-upload.c
562801
+++ b/src/plugins/reporter-upload.c
562801
@@ -148,9 +148,31 @@ static int create_and_upload_archive(
562801
     /* Upload from /tmp to /tmp + deletion -> BAD, exclude this possibility */
562801
     if (url && url[0] && strcmp(url, "file://"LARGE_DATA_TMP_DIR"/") != 0)
562801
     {
562801
-        char *remote_name = upload_file(url, tempfile);
562801
+        post_state_t *state = new_post_state(POST_WANT_ERROR_MSG);
562801
+        state->username = getenv("Upload_Username");
562801
+        char *password_inp = NULL;
562801
+        if (state->username != NULL && state->username[0] != '\0')
562801
+        {
562801
+            /* Load Password only if Username is configured, it doesn't make */
562801
+            /* much sense to load Password without Username. */
562801
+            state->password = getenv("Upload_Password");
562801
+            if (state->password == NULL && state->password[0] == '\0')
562801
+            {
562801
+                /* Be permissive and nice, ask only once and don't check */
562801
+                /* the result. User can dismiss this prompt but the upload */
562801
+                /* may work somehow??? */
562801
+                char *msg = xasprintf(_("Please enter password for uploading:"), state->username);
562801
+                state->password = password_inp = ask_password(msg);
562801
+                free(msg);
562801
+            }
562801
+        }
562801
+
562801
+        char *remote_name = upload_file_ext(state, url, tempfile, UPLOAD_FILE_HANDLE_ACCESS_DENIALS);
562801
+
562801
         result = (remote_name == NULL); /* error if NULL */
562801
         free(remote_name);
562801
+        free(password_inp);
562801
+        free_post_state(state);
562801
         /* cleanup code will delete tempfile */
562801
     }
562801
     else
562801
-- 
562801
1.8.3.1
562801