Stop hard-coding default directory mode as 0777.

This commit is contained in:
jkim 2011-03-08 20:13:29 +00:00
parent 8a28fc08af
commit 2a03b255b4
4 changed files with 9 additions and 9 deletions

View File

@ -41,6 +41,7 @@ static const char rcsid[] =
#include <sys/param.h>
#include <dirent.h>
#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';

View File

@ -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

View File

@ -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:

View File

@ -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);