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

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