From 3c2f49703ae54ddb33adbb78fd4fbb81b0fcbaac Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 25 Mar 2011 16:22:57 +0100 Subject: fixes for missing uid case Signed-off-by: Denys Vlasenko --- src/daemon/Daemon.cpp | 2 +- src/plugins/abrt-action-analyze-c.c | 19 +++++++++++++++---- src/plugins/abrt-action-generate-backtrace.c | 22 ++++++++++++++++------ src/plugins/abrt-action-mailx.c | 10 +++++----- 4 files changed, 37 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/daemon/Daemon.cpp b/src/daemon/Daemon.cpp index 7bb772c8..1d0467bb 100644 --- a/src/daemon/Daemon.cpp +++ b/src/daemon/Daemon.cpp @@ -404,7 +404,7 @@ static gboolean handle_inotify_cb(GIOChannel *gio, GIOCondition condition, gpoin * not the one which is deleted */ send_dbus_sig_Crash(get_crash_item_content_or_NULL(crash_data, FILENAME_PACKAGE), - (first)? first: fullname, + (first) ? first : fullname, uid_str ); break; diff --git a/src/plugins/abrt-action-analyze-c.c b/src/plugins/abrt-action-analyze-c.c index 3c7d4f1d..3dfbe485 100644 --- a/src/plugins/abrt-action-analyze-c.c +++ b/src/plugins/abrt-action-analyze-c.c @@ -50,12 +50,23 @@ static char *run_unstrip_n(const char *dump_dir_name, unsigned timeout_sec) struct dump_dir *dd = dd_opendir(dump_dir_name, /*flags:*/ 0); if (!dd) return NULL; - char *uid_str = dd_load_text(dd, FILENAME_UID); + + char *uid_str = dd_load_text_ext(dd, FILENAME_UID, DD_FAIL_QUIETLY_ENOENT | DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE); dd_close(dd); - unsigned uid = xatoi_positive(uid_str); - free(uid_str); + uid_t uid = -1L; + if (uid_str) + { + uid = xatoi_positive(uid_str); + free(uid_str); + if (uid == geteuid()) + { + uid = -1L; /* no need to setuid/gid if we are already under right uid */ + } + } - int flags = EXECFLG_INPUT_NUL | EXECFLG_OUTPUT | EXECFLG_SETGUID | EXECFLG_SETSID | EXECFLG_QUIET; + int flags = EXECFLG_INPUT_NUL | EXECFLG_OUTPUT | EXECFLG_SETSID | EXECFLG_QUIET; + if (uid != (uid_t)-1L) + flags |= EXECFLG_SETGUID; VERB1 flags &= ~EXECFLG_QUIET; int pipeout[2]; char* args[4]; diff --git a/src/plugins/abrt-action-generate-backtrace.c b/src/plugins/abrt-action-generate-backtrace.c index 445a7b76..0c2d9a0a 100644 --- a/src/plugins/abrt-action-generate-backtrace.c +++ b/src/plugins/abrt-action-generate-backtrace.c @@ -67,7 +67,7 @@ static char* exec_vp(char **args, uid_t uid, int redirect_stderr, int *status) /* Nuke everything which may make setlocale() switch to non-POSIX locale: * we need to avoid having gdb output in some obscure language. */ - static const char *const unsetenv_vec[] = { + static const char *const env_vec[] = { "LANG", "LC_ALL", "LC_COLLATE", @@ -84,13 +84,15 @@ static char* exec_vp(char **args, uid_t uid, int redirect_stderr, int *status) NULL }; - int flags = EXECFLG_INPUT_NUL | EXECFLG_OUTPUT | EXECFLG_SETGUID | EXECFLG_SETSID | EXECFLG_QUIET; + int flags = EXECFLG_INPUT_NUL | EXECFLG_OUTPUT | EXECFLG_SETSID | EXECFLG_QUIET; + if (uid != (uid_t)-1L) + flags |= EXECFLG_SETGUID; if (redirect_stderr) flags |= EXECFLG_ERR2OUT; VERB1 flags &= ~EXECFLG_QUIET; int pipeout[2]; - pid_t child = fork_execv_on_steroids(flags, args, pipeout, (char**)unsetenv_vec, /*dir:*/ NULL, uid); + pid_t child = fork_execv_on_steroids(flags, args, pipeout, (char**)env_vec, /*dir:*/ NULL, uid); /* We use this function to run gdb and unstrip. Bugs in gdb or corrupted * coredumps were observed to cause gdb to enter infinite loop. @@ -136,9 +138,17 @@ static char* exec_vp(char **args, uid_t uid, int redirect_stderr, int *status) static char *get_backtrace(struct dump_dir *dd) { - char *uid_str = dd_load_text(dd, FILENAME_UID); - uid_t uid = xatoi_positive(uid_str); - free(uid_str); + char *uid_str = dd_load_text_ext(dd, FILENAME_UID, DD_FAIL_QUIETLY_ENOENT | DD_LOAD_TEXT_RETURN_NULL_ON_FAILURE); + uid_t uid = -1L; + if (uid_str) + { + uid = xatoi_positive(uid_str); + free(uid_str); + if (uid == geteuid()) + { + uid = -1L; /* no need to setuid/gid if we are already under right uid */ + } + } char *executable = dd_load_text(dd, FILENAME_EXECUTABLE); dd_close(dd); diff --git a/src/plugins/abrt-action-mailx.c b/src/plugins/abrt-action-mailx.c index dcea685b..5b5a377e 100644 --- a/src/plugins/abrt-action-mailx.c +++ b/src/plugins/abrt-action-mailx.c @@ -22,17 +22,18 @@ #define PROGNAME "abrt-action-mailx" -static void exec_and_feed_input(uid_t uid, const char* text, char **args) +static void exec_and_feed_input(const char* text, char **args) { int pipein[2]; pid_t child = fork_execv_on_steroids( - EXECFLG_INPUT | EXECFLG_QUIET | EXECFLG_SETGUID, + EXECFLG_INPUT | EXECFLG_QUIET, args, pipein, /*env_vec:*/ NULL, /*dir:*/ NULL, - uid); + /*uid (ignored):*/ 0 + ); full_write_str(pipein[1], text); close(pipein[1]); @@ -106,8 +107,7 @@ static void create_and_send_email( args = append_str_to_vector(args, &arg_size, email_to); log(_("Sending an email...")); - const char *uid_str = get_crash_item_content_or_NULL(crash_data, FILENAME_UID); - exec_and_feed_input(xatoi_positive(uid_str), dsc, args); + exec_and_feed_input(dsc, args); free(dsc); -- cgit