Blame SOURCES/0183-uploader-add-possibility-to-set-SSH-keyfiles.patch

562801
From 31854cdc27bff5507c5fc9ae8a029d3bd6f48c5e Mon Sep 17 00:00:00 2001
562801
From: Matej Habrnal <mhabrnal@redhat.com>
562801
Date: Mon, 21 Mar 2016 11:27:00 +0100
562801
Subject: [PATCH] uploader: add possibility to set SSH keyfiles
562801
562801
The SSH key files can be set by command line arguments -u (public key) and -r
562801
(private key) or in configuration file upload.conf or in environment variables.
562801
562801
Related to rhbz#1289513
562801
562801
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
562801
---
562801
 doc/Makefile.am                    |  2 ++
562801
 doc/report_Uploader.conf.txt       | 46 ++++++++++++++++++++++++++++++++++++++
562801
 doc/reporter-upload.txt            | 21 ++++++++++++++++-
562801
 doc/upload.conf.txt                | 18 +++++++++++++++
562801
 src/plugins/Makefile.am            |  4 +++-
562801
 src/plugins/report_Uploader.conf   | 23 +++++++++++++++++++
562801
 src/plugins/report_Uploader.xml.in | 10 +++++++++
562801
 src/plugins/reporter-upload.c      | 43 ++++++++++++++++++++++++++++++-----
562801
 src/plugins/upload.conf            | 12 ++++++++++
562801
 9 files changed, 171 insertions(+), 8 deletions(-)
562801
 create mode 100644 doc/report_Uploader.conf.txt
562801
 create mode 100644 doc/upload.conf.txt
562801
 create mode 100644 src/plugins/report_Uploader.conf
562801
 create mode 100644 src/plugins/upload.conf
562801
562801
diff --git a/doc/Makefile.am b/doc/Makefile.am
562801
index da4785e..17ef32b 100644
562801
--- a/doc/Makefile.am
562801
+++ b/doc/Makefile.am
562801
@@ -51,10 +51,12 @@ MAN5_TXT += report_rhel_bugzilla.conf.txt
562801
 MAN5_TXT += report_logger.conf.txt
562801
 MAN5_TXT += report_mailx.conf.txt
562801
 MAN5_TXT += report_uploader.conf.txt
562801
+MAN5_TXT += report_Uploader.conf.txt
562801
 MAN5_TXT += rhtsupport.conf.txt
562801
 MAN5_TXT += rhtsupport_event.conf.txt
562801
 MAN5_TXT += uploader_event.conf.txt
562801
 MAN5_TXT += ureport.conf.txt
562801
+MAN5_TXT += upload.conf.txt
562801
 
562801
 # Manual pages are generated from .txt via Docbook
562801
 man1_MANS = ${MAN1_TXT:%.txt=%.1}
562801
diff --git a/doc/report_Uploader.conf.txt b/doc/report_Uploader.conf.txt
562801
new file mode 100644
562801
index 0000000..0d344a5
562801
--- /dev/null
562801
+++ b/doc/report_Uploader.conf.txt
562801
@@ -0,0 +1,46 @@
562801
+report_Uploader.conf(5)
562801
+======================
562801
+
562801
+NAME
562801
+----
562801
+report_Uploader.conf - libreport's configuration file for 'report_Uploader' events.
562801
+
562801
+DESCRIPTION
562801
+-----------
562801
+This configuration file contains values for options defined in
562801
+/usr/share/libreport/events/report_Uploader.xml and is placed in
562801
+/etc/libreport/events/report_Uploader.conf.
562801
+
562801
+Configuration file lines should have 'PARAM = VALUE' format. The parameters are:
562801
+
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
+'Upload_SSHPublicKey'::
562801
+    Path to SSH public key file
562801
+
562801
+'Upload_SSHPrivateKey'::
562801
+    Path to SSH private key file
562801
+
562801
+'http_proxy'::
562801
+    The proxy server to use for HTTP
562801
+
562801
+'HTTPS_PROXY'::
562801
+    The proxy server to use for HTTPS
562801
+
562801
+'FTP_PROXY'::
562801
+    The proxy server to use for FTP
562801
+
562801
+SEE ALSO
562801
+--------
562801
+report_event.conf(5), reporter-upload(1)
562801
+
562801
+AUTHOR
562801
+------
562801
+* ABRT team
562801
diff --git a/doc/reporter-upload.txt b/doc/reporter-upload.txt
562801
index e813c58..0107041 100644
562801
--- a/doc/reporter-upload.txt
562801
+++ b/doc/reporter-upload.txt
562801
@@ -7,7 +7,7 @@ reporter-upload - Uploads compressed tarball of problem directory.
562801
 
562801
 SYNOPSIS
562801
 --------
562801
-'reporter-upload' [-c CONFFILE]... [-d DIR] [-u URL]
562801
+'reporter-upload' [-c CONFFILE]... [-d DIR] [-u URL] [-b FILE] [-r FILE]
562801
 
562801
 DESCRIPTION
562801
 -----------
562801
@@ -24,6 +24,12 @@ The options are:
562801
 'URL'::
562801
         The URL where tarball should be uploaded.
562801
 
562801
+'SSHPublicKey'::
562801
+        The SSH public key.
562801
+
562801
+'SSHPrivateKey'::
562801
+        The SSH private key.
562801
+
562801
 Integration with ABRT events
562801
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
562801
 'reporter-upload' can be used as a reporter, to allow users to upload
562801
@@ -59,6 +65,13 @@ OPTIONS
562801
    If URL ends with a slash, the archive name will be generated and appended
562801
    to URL; otherwise, URL will be used as full file name.
562801
 
562801
+-b::
562801
+--pubkey FILE::
562801
+   Set SSH public key file.
562801
+
562801
+-r::
562801
+--key FILE::
562801
+   Set SSH private key file.
562801
 
562801
 ENVIRONMENT VARIABLES
562801
 ---------------------
562801
@@ -74,6 +87,12 @@ the configuration file.
562801
 'Upload_Password'::
562801
    Password for the upload URL
562801
 
562801
+'Upload_SSHPublicKey'::
562801
+   Path to SSH public key file
562801
+
562801
+'Upload_SSHPrivateKey'::
562801
+   Path to SSH private key file
562801
+
562801
 SEE ALSO
562801
 --------
562801
 uploader_event.conf(5)
562801
diff --git a/doc/upload.conf.txt b/doc/upload.conf.txt
562801
new file mode 100644
562801
index 0000000..de7b435
562801
--- /dev/null
562801
+++ b/doc/upload.conf.txt
562801
@@ -0,0 +1,18 @@
562801
+upload.conf(5)
562801
+===============
562801
+
562801
+NAME
562801
+----
562801
+upload.conf - configuration file for libreport.
562801
+
562801
+DESCRIPTION
562801
+-----------
562801
+This configuration file provides default configuration for 'reporter-upload'.
562801
+
562801
+SEE ALSO
562801
+--------
562801
+reporter-upload(1)
562801
+
562801
+AUTHOR
562801
+------
562801
+* ABRT team
562801
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
562801
index d5d75b6..59fc440 100644
562801
--- a/src/plugins/Makefile.am
562801
+++ b/src/plugins/Makefile.am
562801
@@ -38,6 +38,7 @@ defaultreportpluginsconfdir = $(DEFAULT_REPORT_PLUGINS_CONF_DIR)
562801
 dist_defaultreportpluginsconf_DATA = $(reporters_plugin_conf) \
562801
     rhtsupport.conf \
562801
     mailx.conf \
562801
+    upload.conf \
562801
     ureport.conf
562801
 
562801
 dist_reportpluginsconf_DATA = $(reporters_plugin_format_conf) \
562801
@@ -66,7 +67,8 @@ dist_events_DATA = $(reporters_events) \
562801
     report_EmergencyAnalysis.xml
562801
 
562801
 dist_eventsconf_DATA = $(reporters_events_conf) \
562801
-    report_Logger.conf
562801
+    report_Logger.conf \
562801
+    report_Uploader.conf
562801
 
562801
 @INTLTOOL_XML_RULE@
562801
 
562801
diff --git a/src/plugins/report_Uploader.conf b/src/plugins/report_Uploader.conf
562801
new file mode 100644
562801
index 0000000..f54dbc7
562801
--- /dev/null
562801
+++ b/src/plugins/report_Uploader.conf
562801
@@ -0,0 +1,23 @@
562801
+# The URL where should be the tarball uploaded
562801
+#Upload_URL =
562801
+
562801
+# User name for the upload URL
562801
+#Upload_Username =
562801
+
562801
+# Password for the upload URL
562801
+#Upload_Password =
562801
+
562801
+# Path to SSH public key file
562801
+#Upload_SSHPublicKey =
562801
+
562801
+# Path to SSH private key file
562801
+#Upload_SSHPrivateKey =
562801
+
562801
+# The proxy server to use for HTTP
562801
+#http_proxy =
562801
+
562801
+# The proxy server to use for HTTPS
562801
+#HTTPS_PROXY =
562801
+
562801
+# The proxy server to use for FTP
562801
+#FTP_PROXY =
562801
diff --git a/src/plugins/report_Uploader.xml.in b/src/plugins/report_Uploader.xml.in
562801
index db00c23..aff5f65 100644
562801
--- a/src/plugins/report_Uploader.xml.in
562801
+++ b/src/plugins/report_Uploader.xml.in
562801
@@ -45,6 +45,16 @@
562801
                 <allow-empty>yes</allow-empty>
562801
                 <_note-html>Sets the proxy server to use for FTP</_note-html>
562801
             </option>
562801
+            <option type="text" name="Upload_SSHPublicKey">
562801
+                <_label>SSH Public key file</_label>
562801
+                <allow-empty>yes</allow-empty>
562801
+                <_note-html>Use this field to specify SSH public keyfile</_note-html>
562801
+            </option>
562801
+            <option type="text" name="Upload_SSHPrivateKey">
562801
+                <_label>SSH Private key file</_label>
562801
+                <allow-empty>yes</allow-empty>
562801
+                <_note-html>Use this field to specify SSH private keyfile</_note-html>
562801
+            </option>
562801
         </advanced-options>
562801
     </options>
562801
 </event>
562801
diff --git a/src/plugins/reporter-upload.c b/src/plugins/reporter-upload.c
562801
index 971c5c1..36509fb 100644
562801
--- a/src/plugins/reporter-upload.c
562801
+++ b/src/plugins/reporter-upload.c
562801
@@ -32,16 +32,17 @@ static char *ask_url(const char *message)
562801
     return url;
562801
 }
562801
 
562801
-static int interactive_upload_file(const char *url, const char *file_name, char **remote_name)
562801
+static int interactive_upload_file(const char *url, const char *file_name,
562801
+                                   map_string_t *settings, char **remote_name)
562801
 {
562801
     post_state_t *state = new_post_state(POST_WANT_ERROR_MSG);
562801
-    state->username = getenv("Upload_Username");
562801
+    state->username = get_map_string_item_or_NULL(settings, "UploadUsername");
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
+        state->password = get_map_string_item_or_NULL(settings, "UploadPassword");
562801
         if (state->password == NULL)
562801
         {
562801
             /* Be permissive and nice, ask only once and don't check */
562801
@@ -53,6 +54,15 @@ static int interactive_upload_file(const char *url, const char *file_name, char
562801
         }
562801
     }
562801
 
562801
+    /* set SSH keys */
562801
+    state->client_ssh_public_keyfile = get_map_string_item_or_NULL(settings, "SSHPublicKey");
562801
+    state->client_ssh_private_keyfile = get_map_string_item_or_NULL(settings, "SSHPrivateKey");
562801
+
562801
+    if (state->client_ssh_public_keyfile != NULL)
562801
+        log_debug("Using SSH public key '%s'", state->client_ssh_public_keyfile);
562801
+    if (state->client_ssh_private_keyfile != NULL)
562801
+        log_debug("Using SSH private key '%s'", state->client_ssh_private_keyfile);
562801
+
562801
     char *tmp = upload_file_ext(state, url, file_name, UPLOAD_FILE_HANDLE_ACCESS_DENIALS);
562801
 
562801
     if (remote_name)
562801
@@ -70,6 +80,7 @@ static int interactive_upload_file(const char *url, const char *file_name, char
562801
 static int create_and_upload_archive(
562801
                 const char *dump_dir_name,
562801
                 const char *url,
562801
+                map_string_t *settings,
562801
                 char **remote_name)
562801
 {
562801
     int result = 1; /* error */
562801
@@ -102,7 +113,7 @@ static int create_and_upload_archive(
562801
     /* Upload the 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
-        result = interactive_upload_file(url, tempfile, remote_name);
562801
+        result = interactive_upload_file(url, tempfile, settings, remote_name);
562801
     else
562801
     {
562801
         result = 0; /* success */
562801
@@ -140,10 +151,12 @@ int main(int argc, char **argv)
562801
     const char *dump_dir_name = ".";
562801
     const char *conf_file = NULL;
562801
     const char *url = NULL;
562801
+    const char *ssh_public_key = NULL;
562801
+    const char *ssh_private_key = NULL;
562801
 
562801
     /* Can't keep these strings/structs static: _() doesn't support that */
562801
     const char *program_usage_string = _(
562801
-        "& [-v] -d DIR [-c CONFFILE] [-u URL]\n"
562801
+        "& [-v] -d DIR [-c CONFFILE] [-u URL] [-b FILE] [-r FILE]\n"
562801
         "\n"
562801
         "Uploads compressed tarball of problem directory DIR to URL.\n"
562801
         "If URL is not specified, creates tarball in "LARGE_DATA_TMP_DIR" and exits.\n"
562801
@@ -166,6 +179,8 @@ int main(int argc, char **argv)
562801
         OPT_d = 1 << 1,
562801
         OPT_c = 1 << 2,
562801
         OPT_u = 1 << 3,
562801
+        OPT_b = 1 << 4,
562801
+        OPT_r = 1 << 5,
562801
     };
562801
     /* Keep enum above and order of options below in sync! */
562801
     struct options program_options[] = {
562801
@@ -173,6 +188,8 @@ int main(int argc, char **argv)
562801
         OPT_STRING('d', NULL, &dump_dir_name, "DIR"     , _("Problem directory")),
562801
         OPT_STRING('c', NULL, &conf_file    , "CONFFILE", _("Config file")),
562801
         OPT_STRING('u', NULL, &url          , "URL"     , _("Base URL to upload to")),
562801
+        OPT_STRING('b', "pubkey",  &ssh_public_key , "FILE" , _("SSH public key file")),
562801
+        OPT_STRING('r', "key",     &ssh_private_key, "FILE" , _("SSH private key file")),
562801
         OPT_END()
562801
     };
562801
     /*unsigned opts =*/ parse_opts(argc, argv, program_options, program_usage_string);
562801
@@ -203,8 +220,22 @@ int main(int argc, char **argv)
562801
     if (!conf_url || conf_url[0] == '\0')
562801
         conf_url = input_url = ask_url(_("Please enter a URL (scp, ftp, etc.) where the problem data is to be exported:"));
562801
 
562801
+    set_map_string_item_from_string(settings, "UploadUsername", getenv("Upload_Username"));
562801
+    set_map_string_item_from_string(settings, "UploadPassword", getenv("Upload_Password"));
562801
+
562801
+    /* set SSH keys */
562801
+    if (ssh_public_key)
562801
+        set_map_string_item_from_string(settings, "SSHPublicKey", ssh_public_key);
562801
+    else if (getenv("Upload_SSHPublicKey") != NULL)
562801
+        set_map_string_item_from_string(settings, "SSHPublicKey", getenv("Upload_SSHPublicKey"));
562801
+
562801
+    if (ssh_private_key)
562801
+        set_map_string_item_from_string(settings, "SSHPrivateKey", ssh_private_key);
562801
+    else if (getenv("Upload_SSHPrivateKey") != NULL)
562801
+        set_map_string_item_from_string(settings, "SSHPrivateKey", getenv("Upload_SSHPrivateKey"));
562801
+
562801
     char *remote_name = NULL;
562801
-    const int result = create_and_upload_archive(dump_dir_name, conf_url, &remote_name);
562801
+    const int result = create_and_upload_archive(dump_dir_name, conf_url, settings, &remote_name);
562801
     if (result != 0)
562801
         goto finito;
562801
 
562801
diff --git a/src/plugins/upload.conf b/src/plugins/upload.conf
562801
new file mode 100644
562801
index 0000000..f32a2a0
562801
--- /dev/null
562801
+++ b/src/plugins/upload.conf
562801
@@ -0,0 +1,12 @@
562801
+# reporter-upload configuration file
562801
+# check man reporter-upload for more details
562801
+
562801
+#URL = scp://USERNAME:PASSWORD@SERVERNAME/var/spool/abrt-upload/
562801
+#URL = ftp://USERNAME:PASSWORD@SERVERNAME/var/spool/abrt-upload/
562801
+#URL = file:///var/spool/abrt-upload/
562801
+
562801
+# Specify SSH public key
562801
+#SSHPublicKey =
562801
+
562801
+# Specify SSH private key
562801
+#SSHPrivateKey =
562801
-- 
562801
1.8.3.1
562801