Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes needed for the integration of ABRT in QE workflows #388

Merged
merged 10 commits into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
*.lo
*.la


# ignore binaries
src/client-python/reportclient/_reportclient.so
src/gui-wizard-gtk/report-gtk
src/cli/report-cli
src/plugins/reporter-bugzilla
src/plugins/reporter-kerneloops
src/plugins/reporter-mailx
src/plugins/reporter-mantisbt
src/plugins/reporter-print
src/plugins/reporter-rhtsupport
src/plugins/reporter-upload
src/plugins/reporter-ureport
src/plugins/report
src/report-newt/report-newt
src/report-python/__init__.pyc
src/gtk-helpers/test-desktop-utils

# autotools
Expand All @@ -30,7 +34,9 @@ m4
missing
ABOUT-NLS
aclocal.m4
ar-lib
autom4te.cache
compile
config.guess
config.log
config.h
Expand Down Expand Up @@ -80,6 +86,8 @@ src/gui-wizard-gtk/wizard_glade.c
# testsuite
tests/atconfig
tests/atlocal
tests/ureport/rhsm/__init__.pyc
tests/ureport/rhsm/config.pyc
tests/testsuite
tests/testsuite.log
tests/package.m4
Expand All @@ -93,6 +101,7 @@ libreport.spec
libreport-version

#generated api docs
apidoc/Doxyfile
apidoc/html/*
!apidoc/html/Makefile.am

Expand Down
18 changes: 17 additions & 1 deletion doc/reporter-ureport.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ reporter-ureport - Reports ABRT problems in format of micro report

SYNOPSIS
--------
'reporter-ureport' [-v] [-c CONFFILE] [-u URL] [-k] [-A -a bthash -B -b bug-id -E -e email] [-r] [-d DIR]
'reporter-ureport' [-v] [-c CONFFILE] [-u URL] [-k] [-A -a bthash -B -b bug-id -E -e email -l DATA -L FIELD -T TYPE -r RESULT_TYPE] [-d DIR]

DESCRIPTION
-----------
Expand Down Expand Up @@ -119,6 +119,22 @@ OPTIONS
-i AUTH_DATA_ITEMS::
List of dump dir files included in the 'auth' uReport object.

-l DATA::
Attach DATA (requires -T and -a|-A)

-L REPORT_RESULT_FILED::
Attach the value of REPORT_RESULT_FILED member of the last report result
indentified by REPORT_RESULT_TYPE passed with -r option
(requires -r, -T and -a|-A).

-T ATTACHMENT_TYPE::
Specifies the attachment type when attaching an arbitrary data to BTHASH
(takes effect only with -l or -L)

-r REPORT_RESULT_TYP::
Used to single out report results ('reported_to' file lines) when attaching
an arbitrary data to BTHASH (takes effect only with -L)

ENVIRONMENT VARIABLES
---------------------
Environment variables take precedence over values provided in
Expand Down
3 changes: 3 additions & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ src/lib/abrt_sock.c
src/lib/client.c
src/lib/create_dump_dir.c
src/lib/curl.c
src/lib/dump_dir.c
src/lib/event_config.c
src/lib/iso_date_string.c
src/lib/ureport.c
src/lib/make_descr.c
src/lib/parse_options.c
src/lib/problem_data.c
src/lib/problem_report.c
src/lib/reported_to.c
src/lib/reporters.c
src/lib/run_event.c
src/plugins/abrt_rh_support.c
Expand Down
76 changes: 70 additions & 6 deletions src/include/dump_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#ifndef LIBREPORT_DUMP_DIR_H_
#define LIBREPORT_DUMP_DIR_H_

/* For const_string_vector_const_ptr_t */
#include "libreport_types.h"

#include <stdint.h>

/* For DIR */
Expand Down Expand Up @@ -218,20 +221,57 @@ int dd_set_no_owner(struct dump_dir *dd);
uid_t dd_get_owner(struct dump_dir *dd);

/* reported_to handling */
#define add_reported_to_data libreport_add_reported_to_data
int add_reported_to_data(char **reported_to, const char *line);
#define add_reported_to libreport_add_reported_to
void add_reported_to(struct dump_dir *dd, const char *line);
struct report_result {
char *label;
char *url;
char *msg;
char *bthash;
/* char *whole_line; */
/* time_t timestamp; */
time_t timestamp;
/* ^^^ if you add more fields, don't forget to update free_report_result() */
};
typedef struct report_result report_result_t;

/* Appends a new unique line to the list of report results
*
* If the reported_to data already contains the given line, the line will not
* be added again.
*
* @param reported_to The data
* @param line The appended line
* @return 1 if the line was added at the end of the reported_to; otherwise 0.
*/
#define add_reported_to_data libreport_add_reported_to_data
int add_reported_to_data(char **reported_to, const char *line);

/* Appends a new unique entry to the list of report results
*
* result->label must be non-empty string which does not contain ':' character.
*
* The function converts the result to a valid reported_to line and calls
* add_reported_to_data().
*
* @param reported_to The data
* @param result The appended entry
* @return -EINVAL if result->label is invalid; otherwise return value of
* add_reported_to_data
*/
#define add_reported_to_entry_data libreport_add_reported_to_entry_data
int add_reported_to_entry_data(char **reported_to, struct report_result *result);

/* This is a wrapper of add_reported_to_data which accepts 'struct dump_dir *'
* in the first argument instead of 'char **'. The added line is stored in
* 'reported_to' dump directory file.
*/
#define add_reported_to libreport_add_reported_to
void add_reported_to(struct dump_dir *dd, const char *line);

/* This is a wrapper of add_reported_to_entry_data which accepts 'struct
* dump_dir *' in the first argument instead of 'char **'. The added entry is
* stored in 'reported_to' dump directory file.
*/
#define add_reported_to_entry libreport_add_reported_to_entry
void add_reported_to_entry(struct dump_dir *dd, struct report_result *result);

#define free_report_result libreport_free_report_result
void free_report_result(struct report_result *result);
#define find_in_reported_to_data libreport_find_in_reported_to_data
Expand Down Expand Up @@ -298,6 +338,30 @@ typedef int (*save_data_call_back)(struct dump_dir *, void *args);
*/
struct dump_dir *create_dump_dir(const char *base_dir_name, const char *type,
uid_t uid, save_data_call_back save_data, void *args);

/* Creates a new archive from the dump directory contents
*
* The dd argument must be opened for reading.
*
* The archive_name must not exist. The file will be created with 0600 mode.
*
* The archive type is deduced from archive_name suffix. The supported archive
* suffixes are the following:
* - '.tag.gz' (note: the implementation uses child gzip process)
*
* The archive will include only the files that are not in the exclude_elements
* list. See get_global_always_excluded_elements().
*
* The argument "flags" is currently unused.
*
* @return 0 on success; otherwise non-0 value. -ENOSYS if archive type is not
* supported. -EEXIST if the archive file already exists. -ECHILD if child
* process fails. Other negative values can be converted to errno values by
* turning them positive.
*/
int dd_create_archive(struct dump_dir *dd, const char *archive_name,
const_string_vector_const_ptr_t exclude_elements, int flags);

#ifdef __cplusplus
}
#endif
Expand Down
33 changes: 33 additions & 0 deletions src/include/internal_libreport.h
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,17 @@ int get_mountinfo_for_mount_point(FILE *fin, struct mountinfo *mntnf, const char
#define iso_date_string libreport_iso_date_string
char *iso_date_string(const time_t *pt);
#define LIBREPORT_ISO_DATE_STRING_SAMPLE "YYYY-MM-DD-hh:mm:ss"
#define LIBREPORT_ISO_DATE_STRING_FORMAT "%Y-%m-%d-%H:%M:%S"

/* Parses date into integer UNIX time stamp
*
* @param date The parsed date string
* @param pt Return value
* @return 0 on success; otherwise non-0 number. -EINVAL if the parameter date
* does not match LIBREPORT_ISO_DATE_STRING_FORMAT
*/
#define iso_date_string_parse libreport_iso_date_string_parse
int iso_date_string_parse(const char *date, time_t *pt);

enum {
MAKEDESC_SHOW_FILES = (1 << 0),
Expand Down Expand Up @@ -1146,6 +1157,28 @@ void show_usage_and_die(const char *usage, const struct options *opt) NORETURN;
*/
struct abrt_post_state;

/* Decomposes uri to its base elements, removes userinfo out of the hostname and
* composes a new uri without userinfo.
*
* The function does not validate the url.
*
* @param uri The uri that might contain userinfo
* @param result The userinfo free uri will be store here. Cannot be null. Must
* be de-allocated by free.
* @param scheme Scheme of the uri. Can be NULL. Result can be NULL. Result
* must be de-allocated by free.
* @param hostname Hostname of the uri. Can be NULL. Result can be NULL. Result
* must be de-allocated by free.
* @param username Username of the uri. Can be NULL. Result can be NULL. Result
* must be de-allocated by free.
* @param password Password of the uri. Can be NULL. Result can be NULL. Result
* must be de-allocated by free.
* @param location Location of the uri. Can be NULL. Result is never NULL. Result
* must be de-allocated by free.
*/
#define uri_userinfo_remove libreport_uri_userinfo_remove
int uri_userinfo_remove(const char *uri, char **result, char **scheme, char **hostname, char **username, char **password, char **location);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions src/include/libreport_curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ enum {
#define upload_file libreport_upload_file
char *upload_file(const char *url, const char *filename);

/* Uploads filename to url.
*
* If url does not ends with '/', base name of filename will be amended.
*
* Fails if the url does not have scheme or hostname.
*
* @return Resulting URL on success (the URL does not contain userinfo);
* otherwise NULL.
*/
#define upload_file_ext libreport_upload_file_ext
char *upload_file_ext(post_state_t *post_state,
const char *url,
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ libreport_la_SOURCES = \
xml_parser.c \
libreport_init.c \
reporters.c \
global_configuration.c
global_configuration.c \
uriparser.c

libreport_la_CPPFLAGS = \
-I$(srcdir)/../include \
Expand All @@ -90,6 +91,7 @@ libreport_la_CPPFLAGS = \
$(SATYR_CFLAGS) \
-D_GNU_SOURCE
libreport_la_LDFLAGS = \
-ltar \
-version-info 0:1:0
libreport_la_LIBADD = \
$(GLIB_LIBS) \
Expand Down
67 changes: 47 additions & 20 deletions src/lib/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,27 +600,48 @@ char *upload_file_ext(post_state_t *state, const char *url, const char *filename
{
/* we don't want to print the whole url as it may contain password
* rhbz#856960
* there can be '@' in the login or password so let's try to find the
* first '@' from the end
*
* jfilak:
* We want to print valid URLs in useful messages.
*
* The old code had this approach:
* there can be '@' in the login or password so let's try to find the
* first '@' from the end
*
* The new implementation decomposes URI to its base elements and uses only
* scheme and hostname for the logging purpose. These elements should not
* contain any sensitive information.
*/
const char *clean_url = strrchr(url, '@');
if (clean_url)
clean_url++;
else
clean_url = url;

char *whole_url;
unsigned len = strlen(url);
if (len > 0 && url[len-1] == '/')
whole_url = concat_path_file(url, strrchr(filename, '/') ? : filename);
else
whole_url = xstrdup(url);


const char *username_bck = state->username;
const char *password_bck = state->password;

char *whole_url = NULL;
char *scheme = NULL;
char *hostname = NULL;
char *username = NULL;
char *password = NULL;
char *clean_url = NULL;

if (uri_userinfo_remove(url, &clean_url, &scheme, &hostname, &username, &password, NULL) != 0)
goto finito;

if (scheme == NULL || hostname == NULL)
{
log_warning(_("Ingoring URL without scheme and hostname"));
goto finito;
}

if (username && (state->username == NULL || state->username[0] == '\0'))
{
state->username = username;
state->password = password;
}

unsigned len = strlen(clean_url);
if (len > 0 && clean_url[len-1] == '/')
whole_url = concat_path_file(clean_url, strrchr(filename, '/') ? : filename);
else
whole_url = xstrdup(clean_url);

/* work around bug in libssh2(curl with scp://)
* libssh2_aget_disconnect() calls close(0)
Expand All @@ -634,7 +655,9 @@ char *upload_file_ext(post_state_t *state, const char *url, const char *filename
*/
do_post:

log(_("Sending %s to %s"), filename, clean_url);
/* Do not include the path part of the URL as it can contain sensitive data
* in case of typos */
log(_("Sending %s to %s//%s"), filename, scheme, hostname);
post(state,
whole_url,
/*content_type:*/ "application/octet-stream",
Expand All @@ -658,13 +681,13 @@ char *upload_file_ext(post_state_t *state, const char *url, const char *filename
(state->curl_result == CURLE_LOGIN_DENIED
|| state->curl_result == CURLE_REMOTE_ACCESS_DENIED))
{
char *msg = xasprintf(_("Please enter user name for '%s':"), clean_url);
char *msg = xasprintf(_("Please enter user name for '%s//%s':"), scheme, hostname);
free(username);
username = ask(msg);
free(msg);
if (username != NULL && username[0] != '\0')
{
msg = xasprintf(_("Please enter password for '%s':"), username);
msg = xasprintf(_("Please enter password for '%s//%s@%s':"), scheme, username, hostname);
free(password);
password = ask_password(msg);
free(msg);
Expand All @@ -687,13 +710,17 @@ char *upload_file_ext(post_state_t *state, const char *url, const char *filename
else
{
/* This ends up a "reporting status message" in abrtd */
log(_("Successfully sent %s to %s"), filename, clean_url);
log(_("Successfully created %s"), whole_url);
}

close(stdin_bck);

finito:
free(password);
free(username);
free(hostname);
free(scheme);
free(clean_url);

state->username = username_bck;
state->password = password_bck;
Expand Down
Loading