Don't set the umask to 0 any more: it's ugly and pointless.
authorMatt McCutchen <matt@mattmccutchen.net>
Mon, 1 Feb 2010 18:29:39 +0000 (13:29 -0500)
committerWayne Davison <wayned@samba.org>
Sat, 24 Apr 2010 16:28:58 +0000 (09:28 -0700)
clientserver.c
main.c
pipe.c
t_stub.c
util.c

index a7996c7..878254f 100644 (file)
@@ -48,7 +48,6 @@ extern int write_batch;
 extern int default_af_hint;
 extern int logfile_format_has_i;
 extern int logfile_format_has_o_or_i;
 extern int default_af_hint;
 extern int logfile_format_has_i;
 extern int logfile_format_has_o_or_i;
-extern mode_t orig_umask;
 extern char *bind_address;
 extern char *config_file;
 extern char *logfile_format;
 extern char *bind_address;
 extern char *config_file;
 extern char *logfile_format;
@@ -676,7 +675,6 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
        if (*lp_prexfer_exec(i) || *lp_postxfer_exec(i)) {
                int status;
 
        if (*lp_prexfer_exec(i) || *lp_postxfer_exec(i)) {
                int status;
 
-               umask(orig_umask);
                /* For post-xfer exec, fork a new process to run the rsync
                 * daemon while this process waits for the exit status and
                 * runs the indicated command at that point. */
                /* For post-xfer exec, fork a new process to run the rsync
                 * daemon while this process waits for the exit status and
                 * runs the indicated command at that point. */
@@ -745,7 +743,6 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
                        set_blocking(fds[1]);
                        pre_exec_fd = fds[1];
                }
                        set_blocking(fds[1]);
                        pre_exec_fd = fds[1];
                }
-               umask(0);
        }
 #endif
 
        }
 #endif
 
@@ -1076,7 +1073,7 @@ static void create_pid_file(void)
                return;
 
        cleanup_set_pid(pid);
                return;
 
        cleanup_set_pid(pid);
-       if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666 & ~orig_umask)) == -1) {
+       if ((fd = do_open(pid_file, O_WRONLY|O_CREAT|O_EXCL, 0666)) == -1) {
          failure:
                cleanup_set_pid(0);
                fprintf(stderr, "failed to create pid file %s: %s\n", pid_file, strerror(errno));
          failure:
                cleanup_set_pid(0);
                fprintf(stderr, "failed to create pid file %s: %s\n", pid_file, strerror(errno));
diff --git a/main.c b/main.c
index 4f3729e..6641291 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1521,9 +1521,10 @@ int main(int argc,char *argv[])
                exit_cleanup(RERR_SYNTAX);
        }
 
                exit_cleanup(RERR_SYNTAX);
        }
 
-       /* we set a 0 umask so that correct file permissions can be
-        * carried across */
-       orig_umask = umask(0);
+       /* Get the umask for use in permission calculations.  We no longer set
+        * it to zero; that is ugly and pointless now that all the callers that
+        * relied on it have been reeducated to work with default ACLs. */
+       umask(orig_umask = umask(0));
 
 #if defined CONFIG_LOCALE && defined HAVE_SETLOCALE
        setlocale(LC_CTYPE, "");
 
 #if defined CONFIG_LOCALE && defined HAVE_SETLOCALE
        setlocale(LC_CTYPE, "");
diff --git a/pipe.c b/pipe.c
index a33117c..236cc61 100644 (file)
--- a/pipe.c
+++ b/pipe.c
@@ -27,7 +27,6 @@ extern int am_server;
 extern int blocking_io;
 extern int filesfrom_fd;
 extern int munge_symlinks;
 extern int blocking_io;
 extern int filesfrom_fd;
 extern int munge_symlinks;
-extern mode_t orig_umask;
 extern char *logfile_name;
 extern int remote_option_cnt;
 extern const char **remote_options;
 extern char *logfile_name;
 extern int remote_option_cnt;
 extern const char **remote_options;
@@ -78,7 +77,6 @@ pid_t piped_child(char **command, int *f_in, int *f_out)
                        close(to_child_pipe[0]);
                if (from_child_pipe[1] != STDOUT_FILENO)
                        close(from_child_pipe[1]);
                        close(to_child_pipe[0]);
                if (from_child_pipe[1] != STDOUT_FILENO)
                        close(from_child_pipe[1]);
-               umask(orig_umask);
                set_blocking(STDIN_FILENO);
                if (blocking_io > 0)
                        set_blocking(STDOUT_FILENO);
                set_blocking(STDIN_FILENO);
                if (blocking_io > 0)
                        set_blocking(STDOUT_FILENO);
index e176b8b..4459308 100644 (file)
--- a/t_stub.c
+++ b/t_stub.c
@@ -26,7 +26,6 @@ int module_id = -1;
 int relative_paths = 0;
 int module_dirlen = 0;
 int preserve_xattrs = 0;
 int relative_paths = 0;
 int module_dirlen = 0;
 int preserve_xattrs = 0;
-mode_t orig_umask = 002;
 char number_separator = ',';
 char *partial_dir;
 char *module_dir;
 char number_separator = ',';
 char *partial_dir;
 char *module_dir;
diff --git a/util.c b/util.c
index c058050..2c4c571 100644 (file)
--- a/util.c
+++ b/util.c
@@ -32,7 +32,6 @@ extern int relative_paths;
 extern int preserve_xattrs;
 extern char *module_dir;
 extern unsigned int module_dirlen;
 extern int preserve_xattrs;
 extern char *module_dir;
 extern unsigned int module_dirlen;
-extern mode_t orig_umask;
 extern char *partial_dir;
 extern filter_rule_list daemon_filter_list;
 
 extern char *partial_dir;
 extern filter_rule_list daemon_filter_list;
 
@@ -178,18 +177,11 @@ int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t mode)
        }
 }
 
        }
 }
 
-/* This creates a new directory with default permissions.  Since there
- * might be some directory-default permissions affecting this, we can't
- * force the permissions directly using the original umask and mkdir(). */
+/* This creates a new directory with default permissions.  Now that we
+ * leave the original umask set, we can just mkdir with mode 777. */
 int mkdir_defmode(char *fname)
 {
 int mkdir_defmode(char *fname)
 {
-       int ret;
-
-       umask(orig_umask);
-       ret = do_mkdir(fname, ACCESSPERMS);
-       umask(0);
-
-       return ret;
+       return do_mkdir(fname, ACCESSPERMS);
 }
 
 /* Create any necessary directories in fname.  Any missing directories are
 }
 
 /* Create any necessary directories in fname.  Any missing directories are
@@ -216,8 +208,6 @@ int make_path(char *fname, int flags)
        } else
                end = fname + strlen(fname);
 
        } else
                end = fname + strlen(fname);
 
-       umask(orig_umask); /* NOTE: don't return before setting this back to 0! */
-
        /* Try to find an existing dir, starting from the deepest dir. */
        for (p = end; ; ) {
                if (do_mkdir(fname, ACCESSPERMS) == 0) {
        /* Try to find an existing dir, starting from the deepest dir. */
        for (p = end; ; ) {
                if (do_mkdir(fname, ACCESSPERMS) == 0) {
@@ -258,8 +248,6 @@ int make_path(char *fname, int flags)
                        ret++;
        }
 
                        ret++;
        }
 
-       umask(0);
-
        if (flags & MKP_DROP_NAME)
                *end = '/';
 
        if (flags & MKP_DROP_NAME)
                *end = '/';