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

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