commit d987892af18fbd9fc9f99dbfeaba704c323ab819
Author: Jiri Moskovcak <jmoskovc@redhat.com>
Date:   Wed Mar 23 18:29:48 2011 +0100

    mad oopses world-readable

diff --git a/src/daemon/abrt.conf b/src/daemon/abrt.conf
index 7f5a9c5..460bf06 100644
--- a/src/daemon/abrt.conf
+++ b/src/daemon/abrt.conf
@@ -33,4 +33,4 @@ MaxCrashReportsSize = 1000
 # So far we support only one line here
 #
 [ LogScanners ]
-abrt-dump-oops = abrt-dump-oops -drw /var/log/messages
+abrt-dump-oops = abrt-dump-oops -drwx /var/log/messages
diff --git a/src/lib/dump_dir.c b/src/lib/dump_dir.c
index 045149a..725496f 100644
--- a/src/lib/dump_dir.c
+++ b/src/lib/dump_dir.c
@@ -321,7 +321,7 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
         else
         {
             if (!(flags & DD_FAIL_QUIETLY_EACCES))
-                perror_msg("Can't access '%s'", dir);
+                VERB1 perror_msg("Can't access '%s'", dir);
         }
         dd_close(dd);
         return NULL;
@@ -367,6 +367,15 @@ struct dump_dir *dd_opendir(const char *dir, int flags)
  */
 struct dump_dir *dd_create(const char *dir, uid_t uid)
 {
+    mode_t dir_mode;
+    /* we need world readable dump dir for some problems like kerneloops
+     * where is no sensitive data and which should be visible and reportable
+     * by all
+     */
+    if(uid == (uid_t)-1L)
+        dir_mode = 0755;
+    else
+        dir_mode = 0750;
     struct dump_dir *dd = dd_init();
 
     /* Unlike dd_opendir, can't use realpath: the directory doesn't exist yet,
@@ -396,7 +405,7 @@ struct dump_dir *dd_create(const char *dir, uid_t uid)
      * the user to replace any file in the directory, changing security-sensitive data
      * (e.g. "uid", "analyzer", "executable")
      */
-    if (mkdir(dir, 0750) == -1)
+    if (mkdir(dir, dir_mode) == -1)
     {
         int err = errno;
         if (!created_parents && errno == ENOENT)
@@ -427,7 +436,7 @@ struct dump_dir *dd_create(const char *dir, uid_t uid)
     }
 
     /* mkdir's mode (above) can be affected by umask, fix it */
-    if (chmod(dir, 0750) == -1)
+    if (chmod(dir, dir_mode) == -1)
     {
         perror_msg("can't change mode of '%s'", dir);
         dd_close(dd);
@@ -472,9 +481,11 @@ void dd_create_basic_files(struct dump_dir *dd, uid_t uid)
     sprintf(long_str, "%lu", (long)t);
     dd_save_text(dd, FILENAME_TIME, long_str);
 
-    if (uid == (uid_t)-1)
-        uid = getuid();
-    sprintf(long_str, "%lu", (long)uid);
+    if (uid == (uid_t)-1L)
+        sprintf(long_str, "%i", -1);
+    else
+        sprintf(long_str, "%li", (long)uid);
+
     dd_save_text(dd, FILENAME_UID, long_str);
 
     struct utsname buf;
@@ -522,8 +533,12 @@ void dd_sanitize_mode_and_owner(struct dump_dir *dd)
         struct stat statbuf;
         if (lstat(full_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
         {
-            if ((statbuf.st_mode & 0777) != 0640)
-                chmod(full_path, 0640);
+            /* The files permission can be 644 as when it shouldn't be readable
+            *  by the world then the directory is not world readable (executable)
+            *  so others can't get to these files anyway
+            */
+            if ((statbuf.st_mode & 0777) != 0644)
+                chmod(full_path, 0644);
             if (statbuf.st_uid != dd->dd_uid || statbuf.st_gid != dd->dd_gid)
             {
                 if (chown(full_path, dd->dd_uid, dd->dd_gid) != 0)
@@ -664,7 +679,7 @@ static bool save_binary_file(const char *path, const char* data, unsigned size,
 {
     /* "Why 0640?!" See dd_create() for security analysis */
     unlink(path);
-    int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0640);
+    int fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0644);
     if (fd < 0)
     {
         perror_msg("Can't open file '%s'", path);
diff --git a/src/plugins/abrt-dump-oops.c b/src/plugins/abrt-dump-oops.c
index f78ad23..3689530 100644
--- a/src/plugins/abrt-dump-oops.c
+++ b/src/plugins/abrt-dump-oops.c
@@ -25,6 +25,8 @@
 
 #define PROGNAME "abrt-dump-oops"
 
+static bool world_readable_dump = false;
+
 static void queue_oops(GList **vec, const char *data, const char *version)
 {
     char *ver_data = xasprintf("%s\n%s", version, data);
@@ -492,7 +494,10 @@ static int save_oops_to_dump_dir(GList *oops_list, unsigned oops_cnt)
 
     time_t t = time(NULL);
     const char *iso_date = iso_date_string(&t);
-    uid_t my_euid = geteuid();
+    uid_t my_euid = (uid_t)-1L;
+    if (!world_readable_dump)
+        my_euid = geteuid();
+
     pid_t my_pid = getpid();
     int errors = 0;
     while (idx != 0 && --countdown != 0)
@@ -504,10 +509,10 @@ static int save_oops_to_dump_dir(GList *oops_list, unsigned oops_cnt)
         char *second_line = (char*)strchr(first_line, '\n'); /* never NULL */
         *second_line++ = '\0';
 
-        struct dump_dir *dd = dd_create(path, /*uid:*/ my_euid);
+        struct dump_dir *dd = dd_create(path, /*uid:*/ (uid_t)-1L);
         if (dd)
         {
-            dd_create_basic_files(dd, /*uid:*/ 0);
+            dd_create_basic_files(dd, /*uid:*/ my_euid);
             dd_save_text(dd, FILENAME_ANALYZER, "Kerneloops");
 // TODO: drop FILENAME_EXECUTABLE?
             dd_save_text(dd, FILENAME_EXECUTABLE, "kernel");
@@ -552,6 +557,7 @@ int main(int argc, char **argv)
         OPT_d = 1 << 3,
         OPT_o = 1 << 4,
         OPT_w = 1 << 5,
+        OPT_x = 1 << 6,
     };
     /* Keep enum above and order of options below in sync! */
     struct options program_options[] = {
@@ -561,6 +567,7 @@ int main(int argc, char **argv)
         OPT_BOOL('d', NULL, NULL, _("Create ABRT dump for every oops found")),
         OPT_BOOL('o', NULL, NULL, _("Print found oopses on standard output")),
         OPT_BOOL('w', NULL, NULL, _("Do not exit, watch the file for new oopses")),
+        OPT_BOOL('x', NULL, NULL, _("Make the dump directory world readable")), //oopses doesn't contain any sensitive info, and even the old koops app was showing the oopses to all users
         OPT_END()
     };
     unsigned opts = parse_opts(argc, argv, program_options, program_usage_string);
@@ -593,6 +600,9 @@ int main(int argc, char **argv)
         /* Scan dmesg (only once even with -w) */
         scan_dmesg(&oops_list);
 
+    if(opts & OPT_x)
+        world_readable_dump = true;
+
     int partial_line_len = 0;
     struct stat statbuf;
     int file_fd = -1;
