default value set in sudoers so that we never lower the user's umask
when running a command.
sudo_mode == MODE_LIST)
exit(rc);
- /* Override user's umask if configured to do so. */
- if (def_umask != 0777)
- (void) umask(def_umask);
+ /*
+ * Override user's umask if configured to do so.
+ * If user's umask is more restrictive, OR in those bits too.
+ */
+ if (def_umask != 0777) {
+ mode_t mask = umask(def_umask);
+ mask |= def_umask;
+ if (mask != def_umask)
+ umask(mask);
+ }
/* Restore coredumpsize resource limit. */
#if defined(RLIMIT_CORE) && !defined(SUDO_DEVEL)
=item umask
Umask to use when running the command. Negate this option or set
-it to 0777 to preserve the user's umask. The default is C<@sudo_umask@>.
+it to 0777 to preserve the user's umask. The actual umask that is
+used will be the union of the user's umask and C<@sudo_umask@>.
+This guarantees that B<sudo> never lowers the umask when running a
+command. Note on systems that use PAM, the default PAM configuration
+may specify its own umask which will override the value set in
+I<sudoers>.
=back