|
|
a60cd7 |
From 5560ca0e51919bc5aeccb22584e24219040dc78b Mon Sep 17 00:00:00 2001
|
|
|
a60cd7 |
From: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
Date: Tue, 24 Mar 2015 20:57:34 +0100
|
|
|
a60cd7 |
Subject: [PATCH] cli: use the DBus methods for getting problem information
|
|
|
a60cd7 |
|
|
|
a60cd7 |
The dump directory is no longer accessible by non-root users and we also
|
|
|
a60cd7 |
want to get rid of direct access to allow administrators (wheel members)
|
|
|
a60cd7 |
see problem data without the need to ChownProblem directory before.
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Related: #1224984
|
|
|
a60cd7 |
|
|
|
a60cd7 |
Signed-off-by: Jakub Filak <jfilak@redhat.com>
|
|
|
a60cd7 |
---
|
|
|
a60cd7 |
src/cli/abrt-cli-core.c | 74 ++++++++++++++++++++++++-------------------------
|
|
|
a60cd7 |
src/cli/abrt-cli-core.h | 4 ++-
|
|
|
a60cd7 |
src/cli/list.c | 45 +++++++++++-------------------
|
|
|
a60cd7 |
src/cli/process.c | 6 +---
|
|
|
a60cd7 |
src/cli/status.c | 66 +++++++++++++------------------------------
|
|
|
a60cd7 |
5 files changed, 77 insertions(+), 118 deletions(-)
|
|
|
a60cd7 |
|
|
|
a60cd7 |
diff --git a/src/cli/abrt-cli-core.c b/src/cli/abrt-cli-core.c
|
|
|
a60cd7 |
index 23a74a8..77a37f7 100644
|
|
|
a60cd7 |
--- a/src/cli/abrt-cli-core.c
|
|
|
a60cd7 |
+++ b/src/cli/abrt-cli-core.c
|
|
|
a60cd7 |
@@ -39,24 +39,22 @@ vector_of_problem_data_t *new_vector_of_problem_data(void)
|
|
|
a60cd7 |
return g_ptr_array_new_with_free_func((void (*)(void*)) &problem_data_free);
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-static int
|
|
|
a60cd7 |
-append_problem_data(struct dump_dir *dd, void *arg)
|
|
|
a60cd7 |
+vector_of_problem_data_t *fetch_crash_infos(void)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- vector_of_problem_data_t *vpd = arg;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- problem_data_t *problem_data = create_problem_data_from_dump_dir(dd);
|
|
|
a60cd7 |
- problem_data_add(problem_data, CD_DUMPDIR, dd->dd_dirname,
|
|
|
a60cd7 |
- CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE + CD_FLAG_LIST);
|
|
|
a60cd7 |
- g_ptr_array_add(vpd, problem_data);
|
|
|
a60cd7 |
- return 0;
|
|
|
a60cd7 |
-}
|
|
|
a60cd7 |
+ GList *problems = get_problems_over_dbus(/*don't authorize*/false);
|
|
|
a60cd7 |
+ if (problems == ERR_PTR)
|
|
|
a60cd7 |
+ return NULL;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-vector_of_problem_data_t *fetch_crash_infos(GList *dir_list)
|
|
|
a60cd7 |
-{
|
|
|
a60cd7 |
vector_of_problem_data_t *vpd = new_vector_of_problem_data();
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- for (GList *li = dir_list; li; li = li->next)
|
|
|
a60cd7 |
- for_each_problem_in_dir(li->data, getuid(), append_problem_data, vpd);
|
|
|
a60cd7 |
+ for (GList *iter = problems; iter; iter = g_list_next(iter))
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ problem_data_t *problem_data = get_full_problem_data_over_dbus((const char *)(iter->data));
|
|
|
a60cd7 |
+ if (problem_data == ERR_PTR)
|
|
|
a60cd7 |
+ continue;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ g_ptr_array_add(vpd, problem_data);
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
|
|
|
a60cd7 |
return vpd;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
@@ -74,36 +72,38 @@ static bool isxdigit_str(const char *str)
|
|
|
a60cd7 |
return true;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-struct name_resolution_param {
|
|
|
a60cd7 |
- const char *shortcut;
|
|
|
a60cd7 |
- unsigned strlen_shortcut;
|
|
|
a60cd7 |
- char *found_name;
|
|
|
a60cd7 |
-};
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
-static int find_dir_by_hash(struct dump_dir *dd, void *arg)
|
|
|
a60cd7 |
+char *find_problem_by_hash(const char *hash, GList *problems)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- struct name_resolution_param *param = arg;
|
|
|
a60cd7 |
- char hash_str[SHA1_RESULT_LEN*2 + 1];
|
|
|
a60cd7 |
- str_to_sha1str(hash_str, dd->dd_dirname);
|
|
|
a60cd7 |
- if (strncasecmp(param->shortcut, hash_str, param->strlen_shortcut) == 0)
|
|
|
a60cd7 |
+ unsigned hash_len = strlen(hash);
|
|
|
a60cd7 |
+ if (!isxdigit_str(hash) || hash_len < 5)
|
|
|
a60cd7 |
+ return NULL;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ char *found_name = NULL;
|
|
|
a60cd7 |
+ for (GList *iter = problems; iter; iter = g_list_next(iter))
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- if (param->found_name)
|
|
|
a60cd7 |
- error_msg_and_die(_("'%s' identifies more than one problem directory"), param->shortcut);
|
|
|
a60cd7 |
- param->found_name = xstrdup(dd->dd_dirname);
|
|
|
a60cd7 |
+ char hash_str[SHA1_RESULT_LEN*2 + 1];
|
|
|
a60cd7 |
+ str_to_sha1str(hash_str, (const char *)(iter->data));
|
|
|
a60cd7 |
+ if (strncasecmp(hash, hash_str, hash_len) == 0)
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ if (found_name)
|
|
|
a60cd7 |
+ error_msg_and_die(_("'%s' identifies more than one problem directory"), hash);
|
|
|
a60cd7 |
+ found_name = xstrdup((const char *)(iter->data));
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
- return 0;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ return found_name;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
|
|
|
a60cd7 |
char *hash2dirname(const char *hash)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- unsigned hash_len = strlen(hash);
|
|
|
a60cd7 |
- if (!isxdigit_str(hash) || hash_len < 5)
|
|
|
a60cd7 |
+ /* Try loading by dirname hash */
|
|
|
a60cd7 |
+ GList *problems = get_problems_over_dbus(/*don't authorize*/false);
|
|
|
a60cd7 |
+ if (problems == ERR_PTR)
|
|
|
a60cd7 |
return NULL;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- /* Try loading by dirname hash */
|
|
|
a60cd7 |
- struct name_resolution_param param = { hash, hash_len, NULL };
|
|
|
a60cd7 |
- GList *dir_list = get_problem_storages();
|
|
|
a60cd7 |
- for (GList *li = dir_list; li; li = li->next)
|
|
|
a60cd7 |
- for_each_problem_in_dir(li->data, getuid(), find_dir_by_hash, ¶m;;
|
|
|
a60cd7 |
- return param.found_name;
|
|
|
a60cd7 |
+ char *found_name = find_problem_by_hash(hash, problems);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ g_list_free_full(problems, free);
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ return found_name;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
diff --git a/src/cli/abrt-cli-core.h b/src/cli/abrt-cli-core.h
|
|
|
a60cd7 |
index 83d0b5d..33b2ea6 100644
|
|
|
a60cd7 |
--- a/src/cli/abrt-cli-core.h
|
|
|
a60cd7 |
+++ b/src/cli/abrt-cli-core.h
|
|
|
a60cd7 |
@@ -28,9 +28,11 @@ problem_data_t *get_problem_data(vector_of_problem_data_t *vector, unsigned i);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
void free_vector_of_problem_data(vector_of_problem_data_t *vector);
|
|
|
a60cd7 |
vector_of_problem_data_t *new_vector_of_problem_data(void);
|
|
|
a60cd7 |
-vector_of_problem_data_t *fetch_crash_infos(GList *dir_list);
|
|
|
a60cd7 |
+vector_of_problem_data_t *fetch_crash_infos(void);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
/* Returns malloced string, or NULL if not found: */
|
|
|
a60cd7 |
+char *find_problem_by_hash(const char *hash, GList *problems);
|
|
|
a60cd7 |
+/* Returns malloced string, or NULL if not found: */
|
|
|
a60cd7 |
char *hash2dirname(const char *hash);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
|
|
|
a60cd7 |
diff --git a/src/cli/list.c b/src/cli/list.c
|
|
|
a60cd7 |
index ccb5f3b..1594906 100644
|
|
|
a60cd7 |
--- a/src/cli/list.c
|
|
|
a60cd7 |
+++ b/src/cli/list.c
|
|
|
a60cd7 |
@@ -30,33 +30,28 @@
|
|
|
a60cd7 |
* ~/.abrt/spool and /var/tmp/abrt? needs more _meditation_.
|
|
|
a60cd7 |
*/
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-static problem_data_t *load_problem_data(const char *dump_dir_name)
|
|
|
a60cd7 |
+static problem_data_t *load_problem_data(const char *problem_id)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- /* First, try loading by dirname */
|
|
|
a60cd7 |
- int sv_logmode = logmode;
|
|
|
a60cd7 |
- logmode = 0; /* suppress EPERM/EACCES errors in opendir */
|
|
|
a60cd7 |
- struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ DD_OPEN_READONLY);
|
|
|
a60cd7 |
- logmode = sv_logmode;
|
|
|
a60cd7 |
+ char *name2 = NULL;
|
|
|
a60cd7 |
+
|
|
|
a60cd7 |
+ /* First, check if there is a problem with the passed id */
|
|
|
a60cd7 |
+ GList *problems = get_problems_over_dbus(/*don't authorize*/false);
|
|
|
a60cd7 |
+ GList *item = g_list_find_custom(problems, problem_id, (GCompareFunc)strcmp);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
/* (git requires at least 5 char hash prefix, we do the same) */
|
|
|
a60cd7 |
- if (!dd && errno == ENOENT)
|
|
|
a60cd7 |
+ if (item == NULL)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
/* Try loading by dirname hash */
|
|
|
a60cd7 |
- char *name2 = hash2dirname(dump_dir_name);
|
|
|
a60cd7 |
- if (name2)
|
|
|
a60cd7 |
- dd = dd_opendir(name2, /*flags:*/ DD_OPEN_READONLY);
|
|
|
a60cd7 |
- free(name2);
|
|
|
a60cd7 |
- }
|
|
|
a60cd7 |
+ name2 = find_problem_by_hash(problem_id, problems);
|
|
|
a60cd7 |
+ if (name2 == NULL)
|
|
|
a60cd7 |
+ return NULL;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- if (!dd)
|
|
|
a60cd7 |
- return NULL;
|
|
|
a60cd7 |
+ problem_id = name2;
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- problem_data_t *problem_data = create_problem_data_from_dump_dir(dd);
|
|
|
a60cd7 |
- problem_data_add(problem_data, CD_DUMPDIR, dd->dd_dirname,
|
|
|
a60cd7 |
- CD_FLAG_TXT + CD_FLAG_ISNOTEDITABLE + CD_FLAG_LIST);
|
|
|
a60cd7 |
- dd_close(dd);
|
|
|
a60cd7 |
+ problem_data_t *problem_data = get_full_problem_data_over_dbus(problem_id);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- return problem_data;
|
|
|
a60cd7 |
+ return (problem_data == ERR_PTR ? NULL : problem_data);
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
|
|
|
a60cd7 |
/** Prints basic information about a crash to stdout. */
|
|
|
a60cd7 |
@@ -176,7 +171,7 @@ static bool print_crash_list(vector_of_problem_data_t *crash_list, int detailed,
|
|
|
a60cd7 |
int cmd_list(int argc, const char **argv)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
const char *program_usage_string = _(
|
|
|
a60cd7 |
- "& list [options] [DIR]..."
|
|
|
a60cd7 |
+ "& list [options]"
|
|
|
a60cd7 |
);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
int opt_not_reported = 0;
|
|
|
a60cd7 |
@@ -194,15 +189,8 @@ int cmd_list(int argc, const char **argv)
|
|
|
a60cd7 |
};
|
|
|
a60cd7 |
|
|
|
a60cd7 |
parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
|
a60cd7 |
- argv += optind;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- GList *D_list = NULL;
|
|
|
a60cd7 |
- while (*argv)
|
|
|
a60cd7 |
- D_list = g_list_append(D_list, xstrdup(*argv++));
|
|
|
a60cd7 |
- if (!D_list)
|
|
|
a60cd7 |
- D_list = get_problem_storages();
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- vector_of_problem_data_t *ci = fetch_crash_infos(D_list);
|
|
|
a60cd7 |
+ vector_of_problem_data_t *ci = fetch_crash_infos();
|
|
|
a60cd7 |
|
|
|
a60cd7 |
g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_LAST_OCCURRENCE);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
@@ -212,7 +200,6 @@ int cmd_list(int argc, const char **argv)
|
|
|
a60cd7 |
print_crash_list(ci, opt_detailed, opt_not_reported, opt_since, opt_until, CD_TEXT_ATT_SIZE_BZ);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
free_vector_of_problem_data(ci);
|
|
|
a60cd7 |
- list_free_with_free(D_list);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
#if SUGGEST_AUTOREPORTING != 0
|
|
|
a60cd7 |
load_abrt_conf();
|
|
|
a60cd7 |
diff --git a/src/cli/process.c b/src/cli/process.c
|
|
|
a60cd7 |
index 7f4fff5..39462f9 100644
|
|
|
a60cd7 |
--- a/src/cli/process.c
|
|
|
a60cd7 |
+++ b/src/cli/process.c
|
|
|
a60cd7 |
@@ -152,18 +152,14 @@ int cmd_process(int argc, const char **argv)
|
|
|
a60cd7 |
};
|
|
|
a60cd7 |
|
|
|
a60cd7 |
parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
|
a60cd7 |
- argv += optind;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- GList *D_list = get_problem_storages();
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- vector_of_problem_data_t *ci = fetch_crash_infos(D_list);
|
|
|
a60cd7 |
+ vector_of_problem_data_t *ci = fetch_crash_infos();
|
|
|
a60cd7 |
|
|
|
a60cd7 |
g_ptr_array_sort_with_data(ci, &cmp_problem_data, (char *) FILENAME_LAST_OCCURRENCE);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
process_crashes(ci, opt_since);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
free_vector_of_problem_data(ci);
|
|
|
a60cd7 |
- list_free_with_free(D_list);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
return 0;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
diff --git a/src/cli/status.c b/src/cli/status.c
|
|
|
a60cd7 |
index 1de2d41..68bdd0e 100644
|
|
|
a60cd7 |
--- a/src/cli/status.c
|
|
|
a60cd7 |
+++ b/src/cli/status.c
|
|
|
a60cd7 |
@@ -21,53 +21,36 @@
|
|
|
a60cd7 |
#include <sys/types.h>
|
|
|
a60cd7 |
#include "problem_api.h"
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-struct time_range {
|
|
|
a60cd7 |
- unsigned count;
|
|
|
a60cd7 |
- unsigned long since;
|
|
|
a60cd7 |
-};
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
-static int count_dir_if_newer_than(struct dump_dir *dd, void *arg)
|
|
|
a60cd7 |
-{
|
|
|
a60cd7 |
- struct time_range *me = arg;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- if (dd_exist(dd, FILENAME_REPORTED_TO))
|
|
|
a60cd7 |
- return 0;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- char *time_str = dd_load_text(dd, FILENAME_LAST_OCCURRENCE);
|
|
|
a60cd7 |
- long val = atol(time_str);
|
|
|
a60cd7 |
- free(time_str);
|
|
|
a60cd7 |
- if (val < me->since)
|
|
|
a60cd7 |
- return 0;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- me->count++;
|
|
|
a60cd7 |
- return 0;
|
|
|
a60cd7 |
-}
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
-static void count_problems_in_dir(gpointer data, gpointer arg)
|
|
|
a60cd7 |
+static unsigned int count_problem_dirs(unsigned long since)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
- char *path = data;
|
|
|
a60cd7 |
- struct time_range *me = arg;
|
|
|
a60cd7 |
+ unsigned count = 0;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- log_info("scanning '%s' for problems since %lu", path, me->since);
|
|
|
a60cd7 |
+ GList *problems = get_problems_over_dbus(/*don't authorize*/false);
|
|
|
a60cd7 |
+ for (GList *iter = problems; iter != NULL; iter = g_list_next(iter))
|
|
|
a60cd7 |
+ {
|
|
|
a60cd7 |
+ const char *problem_id = (const char *)iter->data;
|
|
|
a60cd7 |
+ if (test_exist_over_dbus(problem_id, FILENAME_REPORTED_TO))
|
|
|
a60cd7 |
+ continue;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- for_each_problem_in_dir(path, getuid(), count_dir_if_newer_than, me);
|
|
|
a60cd7 |
-}
|
|
|
a60cd7 |
+ char *time_str = load_text_over_dbus(problem_id, FILENAME_LAST_OCCURRENCE);
|
|
|
a60cd7 |
+ if (time_str == NULL)
|
|
|
a60cd7 |
+ continue;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
-static unsigned int count_problem_dirs(GList *paths, unsigned long since)
|
|
|
a60cd7 |
-{
|
|
|
a60cd7 |
- struct time_range me;
|
|
|
a60cd7 |
- me.count = 0;
|
|
|
a60cd7 |
- me.since = since;
|
|
|
a60cd7 |
+ long val = atol(time_str);
|
|
|
a60cd7 |
+ free(time_str);
|
|
|
a60cd7 |
+ if (val < since)
|
|
|
a60cd7 |
+ return 0;
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- g_list_foreach(paths, count_problems_in_dir, &me);
|
|
|
a60cd7 |
+ count++;
|
|
|
a60cd7 |
+ }
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- return me.count;
|
|
|
a60cd7 |
+ return count;
|
|
|
a60cd7 |
}
|
|
|
a60cd7 |
|
|
|
a60cd7 |
int cmd_status(int argc, const char **argv)
|
|
|
a60cd7 |
{
|
|
|
a60cd7 |
const char *program_usage_string = _(
|
|
|
a60cd7 |
- "& status [DIR]..."
|
|
|
a60cd7 |
+ "& status"
|
|
|
a60cd7 |
);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
int opt_bare = 0; /* must be _int_, OPT_BOOL expects that! */
|
|
|
a60cd7 |
@@ -81,17 +64,8 @@ int cmd_status(int argc, const char **argv)
|
|
|
a60cd7 |
};
|
|
|
a60cd7 |
|
|
|
a60cd7 |
parse_opts(argc, (char **)argv, program_options, program_usage_string);
|
|
|
a60cd7 |
- argv += optind;
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- GList *problem_dir_list = NULL;
|
|
|
a60cd7 |
- while (*argv)
|
|
|
a60cd7 |
- problem_dir_list = g_list_append(problem_dir_list, xstrdup(*argv++));
|
|
|
a60cd7 |
- if (!problem_dir_list)
|
|
|
a60cd7 |
- problem_dir_list = get_problem_storages();
|
|
|
a60cd7 |
-
|
|
|
a60cd7 |
- unsigned int problem_count = count_problem_dirs(problem_dir_list, opt_since);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
- list_free_with_free(problem_dir_list);
|
|
|
a60cd7 |
+ unsigned int problem_count = count_problem_dirs(opt_since);
|
|
|
a60cd7 |
|
|
|
a60cd7 |
/* show only if there is at least 1 problem or user set the -v */
|
|
|
a60cd7 |
if (problem_count > 0 || g_verbose > 0)
|
|
|
a60cd7 |
--
|
|
|
a60cd7 |
2.4.3
|
|
|
a60cd7 |
|