diff options
author | Jiri Moskovcak <jmoskovc@redhat.com> | 2011-03-15 17:39:32 +0100 |
---|---|---|
committer | Jiri Moskovcak <jmoskovc@redhat.com> | 2011-03-15 17:39:32 +0100 |
commit | b405c9d1d89315e52a876652a8ad499483ae9743 (patch) | |
tree | 8a7ea09bbabf816a765848e4c5ae6db706379a3e /src | |
parent | c5ae380aa5e2f29f15f40ad9478e4082d28ba0a6 (diff) | |
parent | eb936eda33ad2b3c0b192215120498feaeb10483 (diff) | |
download | abrt-b405c9d1d89315e52a876652a8ad499483ae9743.tar.gz abrt-b405c9d1d89315e52a876652a8ad499483ae9743.tar.xz abrt-b405c9d1d89315e52a876652a8ad499483ae9743.zip |
Merge branch 'master' of ssh://git.fedorahosted.org/git/abrt
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/MiddleWare.cpp | 5 | ||||
-rw-r--r-- | src/gui-wizard-gtk/wizard.c | 13 | ||||
-rw-r--r-- | src/include/report/dump_dir.h | 3 | ||||
-rw-r--r-- | src/lib/dump_dir.c | 49 |
4 files changed, 69 insertions, 1 deletions
diff --git a/src/daemon/MiddleWare.cpp b/src/daemon/MiddleWare.cpp index 84400361..6ee0d0c0 100644 --- a/src/daemon/MiddleWare.cpp +++ b/src/daemon/MiddleWare.cpp @@ -532,6 +532,11 @@ mw_result_t LoadDebugDump(const char *dump_dir_name, crash_data_t **crash_data) res = MW_ERROR; goto ret; } + + /* Reset mode/uig/gid to correct values for all files created by event run */ + dd_sanitize_mode_and_owner(dd); + + /* Update count */ char *count_str = dd_load_text_ext(dd, FILENAME_COUNT, DD_FAIL_QUIETLY_ENOENT); unsigned long count = strtoul(count_str, NULL, 10); count++; diff --git a/src/gui-wizard-gtk/wizard.c b/src/gui-wizard-gtk/wizard.c index 0a2a6043..9a642f59 100644 --- a/src/gui-wizard-gtk/wizard.c +++ b/src/gui-wizard-gtk/wizard.c @@ -779,6 +779,17 @@ static gboolean consume_cmd_output(GIOChannel *source, GIOCondition condition, g strbuf_clear(evd->event_log); evd->event_log_state = LOGSTATE_FIRSTLINE; + if (geteuid() == 0) + { + /* Reset mode/uig/gid to correct values for all files created by event run */ + struct dump_dir *dd = dd_opendir(g_dump_dir_name, 0); + if (dd) + { + dd_sanitize_mode_and_owner(dd); + dd_close(dd); + } + } + /* Stop if exit code is not 0, or no more commands */ if (retval != 0 || spawn_next_command_in_evd(evd) < 0 @@ -904,6 +915,8 @@ static void start_event_run(const char *event_name, ); gtk_label_set_text(status_label, start_msg); +//TODO: save_to_event_log(evd, "message that we run event foo")? + /* Freeze assistant so it can't move away from the page until event run is done */ gtk_assistant_set_page_complete(g_assistant, page, false); } diff --git a/src/include/report/dump_dir.h b/src/include/report/dump_dir.h index 86bfcf0e..a97a4f5c 100644 --- a/src/include/report/dump_dir.h +++ b/src/include/report/dump_dir.h @@ -50,8 +50,11 @@ struct dump_dir *dd_opendir(const char *dir, int flags); * (IOW: if you aren't running under root): */ struct dump_dir *dd_create(const char *dir, uid_t uid); + void dd_create_basic_files(struct dump_dir *dd, uid_t uid); int dd_exist(struct dump_dir *dd, const char *path); +void dd_sanitize_mode_and_owner(struct dump_dir *dd); + DIR *dd_init_next_file(struct dump_dir *dd); int dd_get_next_file(struct dump_dir *dd, char **short_name, char **full_name); diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c index d0b1d478..fefec608 100644 --- a/src/lib/dump_dir.c +++ b/src/lib/dump_dir.c @@ -491,6 +491,53 @@ void dd_create_basic_files(struct dump_dir *dd, uid_t uid) free(release); } +void dd_sanitize_mode_and_owner(struct dump_dir *dd) +{ + /* Don't sanitize if we aren't run under root: + * we assume that during file creation (by whatever means, + * even by "hostname >file" in abrt_event.conf) + * normal umask-based mode setting takes care of correct mode, + * and uid:gid is, of course, set to user's uid and gid. + * + * For root operating on /var/spool/abrt/USERS_PROBLEM, this isn't true: + * "hostname >file", for example, would create file OWNED BY ROOT! + * This routine resets mode and uid:gid for all such files. + */ + if (dd->dd_uid == (uid_t)-1) + return; + + if (!dd->locked) + error_msg_and_die("dump_dir is not opened"); /* bug */ + + DIR *d = opendir(dd->dd_dirname); + if (!d) + return; + + struct dirent *dent; + while ((dent = readdir(d)) != NULL) + { + if (dent->d_name[0] == '.') /* ".lock", ".", ".."? skip */ + continue; + char *full_path = concat_path_file(dd->dd_dirname, dent->d_name); + struct stat statbuf; + if (lstat(full_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) + { + if ((statbuf.st_mode & 0777) != 0640) + chmod(full_path, 0640); + if (statbuf.st_uid != dd->dd_uid || statbuf.st_gid != dd->dd_gid) + { + if (chown(full_path, dd->dd_uid, dd->dd_gid) != 0) + { + perror_msg("can't change '%s' ownership to %lu:%lu", full_path, + (long)dd->dd_uid, (long)dd->dd_gid); + } + } + } + free(full_path); + } + closedir(d); +} + static int delete_file_dir(const char *dir, bool skip_lock_file) { DIR *d = opendir(dir); @@ -615,7 +662,7 @@ static char *load_text_file(const char *path, unsigned flags) static bool save_binary_file(const char *path, const char* data, unsigned size, uid_t uid, gid_t gid) { - /* "Why 0640?!" See ::Create() for security analysis */ + /* "Why 0640?!" See dd_create() for security analysis */ unlink(path); int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0640); if (fd < 0) |