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

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