From 2a03b255b471fc1ac6c37a22ff21c67922e8c129 Mon Sep 17 00:00:00 2001 From: jkim Date: Tue, 8 Mar 2011 20:13:29 +0000 Subject: [PATCH] Stop hard-coding default directory mode as 0777. --- usr.sbin/pw/cpdir.c | 3 ++- usr.sbin/pw/pw.h | 1 + usr.sbin/pw/pw_conf.c | 4 ++-- usr.sbin/pw/pw_user.c | 10 ++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/usr.sbin/pw/cpdir.c b/usr.sbin/pw/cpdir.c index f37042165776..017c20070abb 100644 --- a/usr.sbin/pw/cpdir.c +++ b/usr.sbin/pw/cpdir.c @@ -41,6 +41,7 @@ static const char rcsid[] = #include #include +#include "pw.h" #include "pwupd.h" void @@ -81,7 +82,7 @@ copymkdir(char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid else { if (S_ISDIR(st.st_mode)) { /* Recurse for this */ if (strcmp(e->d_name, ".") != 0 && strcmp(e->d_name, "..") != 0) - copymkdir(dst, src, (st.st_mode & 0777), uid, gid); + copymkdir(dst, src, st.st_mode & _DEF_DIRMODE, uid, gid); chflags(dst, st.st_flags); /* propogate flags */ } else if (S_ISLNK(st.st_mode) && (len = readlink(src, lnk, sizeof(lnk))) != -1) { lnk[len] = '\0'; diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index 7568c2236e3d..6e521d10a482 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/pw/pw.h @@ -95,6 +95,7 @@ struct userconf int numgroups; /* (internal) size of default_group array */ }; +#define _DEF_DIRMODE (S_IRWXU | S_IRWXG | S_IRWXO) #define _PATH_PW_CONF "/etc/pw.conf" #define _UC_MAXLINE 1024 #define _UC_MAXSHELLS 32 diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c index 51672b9ae493..edeb0151aa7e 100644 --- a/usr.sbin/pw/pw_conf.c +++ b/usr.sbin/pw/pw_conf.c @@ -91,7 +91,7 @@ static struct userconf config = NULL, /* Mail to send to new accounts */ "/var/log/userlog", /* Where to log changes */ "/home", /* Where to create home directory */ - 0777, /* Home directory perms, modified by umask */ + _DEF_DIRMODE, /* Home directory perms, modified by umask */ "/bin", /* Where shells are located */ system_shells, /* List of shells (first is default) */ bourne_shell, /* Default shell */ @@ -302,7 +302,7 @@ read_userconfig(char const * file) case _UC_HOMEMODE: modeset = setmode(q); config.homemode = (q == NULL || !boolean_val(q, 1)) - ? 0777 : getmode(modeset, 0777); + ? _DEF_DIRMODE : getmode(modeset, _DEF_DIRMODE); free(modeset); break; case _UC_SHELLPATH: diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index dd92c435b4e4..db33746651fe 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -107,7 +107,6 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) struct stat st; char line[_PASSWORD_LEN+1]; FILE *fp; - mode_t dmode; char *dmode_c; void *set = NULL; @@ -151,13 +150,12 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) cnf->home = arg->val; } - dmode = S_IRWXU | S_IRWXG | S_IRWXO; if ((arg = getarg(args, 'M')) != NULL) { dmode_c = arg->val; if ((set = setmode(dmode_c)) == NULL) errx(EX_DATAERR, "invalid directory creation mode '%s'", dmode_c); - cnf->homemode = getmode(set, dmode); + cnf->homemode = getmode(set, _DEF_DIRMODE); free(set); } @@ -186,7 +184,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) if (strchr(cnf->home+1, '/') == NULL) { strcpy(dbuf, "/usr"); strncat(dbuf, cnf->home, MAXPATHLEN-5); - if (mkdir(dbuf, dmode) != -1 || errno == EEXIST) { + if (mkdir(dbuf, _DEF_DIRMODE) != -1 || errno == EEXIST) { chown(dbuf, 0, 0); /* * Skip first "/" and create symlink: @@ -202,7 +200,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) while ((p = strchr(++p, '/')) != NULL) { *p = '\0'; if (stat(dbuf, &st) == -1) { - if (mkdir(dbuf, dmode) == -1) + if (mkdir(dbuf, _DEF_DIRMODE) == -1) goto direrr; chown(dbuf, 0, 0); } else if (!S_ISDIR(st.st_mode)) @@ -211,7 +209,7 @@ pw_user(struct userconf * cnf, int mode, struct cargs * args) } } if (stat(dbuf, &st) == -1) { - if (mkdir(dbuf, dmode) == -1) { + if (mkdir(dbuf, _DEF_DIRMODE) == -1) { direrr: err(EX_OSFILE, "mkdir '%s'", dbuf); } chown(dbuf, 0, 0);