Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Oct 2006 06:41:46 GMT
From:      "Dr. Markus Waldeck"<waldeck@gmx.de>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/104248: pw does not support the setting of the mode of the home directory
Message-ID:  <200610100641.k9A6fkae025911@www.freebsd.org>
Resent-Message-ID: <200610100650.k9A6oFwK090051@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         104248
>Category:       bin
>Synopsis:       pw does not support the setting of the mode of the home directory
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 10 06:50:14 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Dr. Markus Waldeck
>Release:        6.1
>Organization:
>Environment:
FreeBSD fb 6.1-RELEASE FreeBSD 6.1-RELEASE #0: Sun May 7 04:32:43 UTC 2006 root@opus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386

>Description:
There is not possibility to set the mode of the home directory when a new user is created.
Instead the mode (0755) is hard coded (!) in the pw source code.
>How-To-Repeat:

>Fix:
I have made a patch for pw (attached).
New option: -A
New entry for pw.conf: homemode

Patch attached with submission follows:

diff -rc pw/pw.8 pwM/pw.8
*** pw/pw.8	Wed Aug 23 07:46:41 2006
--- pwM/pw.8	Tue Oct  3 12:09:27 2006
***************
*** 55,60 ****
--- 55,61 ----
  .Op Fl N
  .Op Fl P
  .Op Fl Y
+ .Op Fl A Ar mode
  .Nm
  .Op Fl V Ar etcdir
  .Ar useradd
diff -rc pw/pw.c pwM/pw.c
*** pw/pw.c	Wed Aug 23 07:46:41 2006
--- pwM/pw.c	Tue Oct  3 12:27:22 2006
***************
*** 106,112 ****
  	static const char *opts[W_NUM][M_NUM] =
  	{
  		{ /* user */
! 			"V:C:qn:u:c:d:e:p:g:G:mk:s:oL:i:w:h:H:Db:NPy:Y",
  			"V:C:qn:u:rY",
  			"V:C:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:H:FNPY",
  			"V:C:qn:u:FPa7",
--- 106,112 ----
  	static const char *opts[W_NUM][M_NUM] =
  	{
  		{ /* user */
! 			"V:C:qn:u:c:d:e:p:g:G:mk:A:s:oL:i:w:h:H:Db:NPy:Y",
  			"V:C:qn:u:rY",
  			"V:C:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:H:FNPY",
  			"V:C:qn:u:FPa7",
diff -rc pw/pw.conf.5 pwM/pw.conf.5
*** pw/pw.conf.5	Wed Aug 23 07:46:41 2006
--- pwM/pw.conf.5	Tue Oct  3 11:22:52 2006
***************
*** 78,83 ****
--- 78,85 ----
  log user/group modifications to this file
  .It home
  root directory for home directories
+ .It homemode
+ file permission for home directories
  .It shellpath
  paths in which to locate shell programs
  .It shells
diff -rc pw/pw.h pwM/pw.h
*** pw/pw.h	Wed Aug 23 07:46:41 2006
--- pwM/pw.h	Tue Oct  3 11:22:52 2006
***************
*** 81,86 ****
--- 81,87 ----
  	char	*newmail;		/* Mail to send to new accounts */
  	char	*logfile;		/* Where to log changes */
  	char	*home;			/* Where to create home directory */
+ 	mode_t  homemode;		/* Which mode for the home directory */
  	char	*shelldir;		/* Where shells are located */
  	char	**shells;		/* List of shells */
  	char	*shell_default;		/* Default shell */
Only in pwM: pw.patch
diff -rc pw/pw_conf.c pwM/pw_conf.c
*** pw/pw_conf.c	Wed Aug 23 07:46:41 2006
--- pwM/pw_conf.c	Tue Oct  3 12:43:34 2006
***************
*** 47,52 ****
--- 47,53 ----
  	_UC_NEWMAIL,
  	_UC_LOGFILE,
  	_UC_HOMEROOT,
+ 	_UC_HOMEMODE,
  	_UC_SHELLPATH,
  	_UC_SHELLS,
  	_UC_DEFAULTSHELL,
***************
*** 90,95 ****
--- 91,97 ----
  	NULL,			/* Mail to send to new accounts */
  	"/var/log/userlog",	/* Where to log changes */
  	"/home",		/* Where to create home directory */
+ 	0755,			/* Which mode for the home directory */
  	"/bin",			/* Where shells are located */
  	system_shells,		/* List of shells (first is default) */
  	bourne_shell,		/* Default shell */
***************
*** 139,144 ****
--- 141,147 ----
  	"newmail",
  	"logfile",
  	"home",
+ 	"homemode",
  	"shellpath",
  	"shells",
  	"defaultshell",
***************
*** 255,260 ****
--- 258,264 ----
  				static char const toks[] = " \t\r\n,=";
  				char           *q = strtok(NULL, toks);
  				int             i = 0;
+ 				mode_t         *modeset;
  
  				while (i < _UC_FIELDS && strcmp(p, kwds[i]) != 0)
  					++i;
***************
*** 290,295 ****
--- 294,305 ----
  					config.logfile = (q == NULL || !boolean_val(q, 1))
  						? NULL : newstr(q);
  					break;
+ 				case _UC_HOMEMODE:
+ 					modeset = setmode(q);
+ 					config.homemode = (q == NULL || !boolean_val(q, 1))
+ 						? 0755 : getmode(modeset, 0755);
+ 					free(modeset);
+ 					break;
  				case _UC_HOMEROOT:
  					config.home = (q == NULL || !boolean_val(q, 1))
  						? "/home" : newstr(q);
***************
*** 412,417 ****
--- 422,431 ----
  					break;
  				case _UC_HOMEROOT:
  					val = config.home;
+ 					break;
+ 				case _UC_HOMEMODE:
+ 					sprintf(buf, "%04o", config.homemode);
+ 					quote = 0;
  					break;
  				case _UC_SHELLPATH:
  					val = config.shelldir;
diff -rc pw/pw_user.c pwM/pw_user.c
*** pw/pw_user.c	Wed Aug 23 07:46:41 2006
--- pwM/pw_user.c	Tue Oct  3 11:56:19 2006
***************
*** 76,81 ****
--- 76,82 ----
   * -u uid         user id
   * -c comment     user name/comment
   * -d directory   home directory
+  * -A mode        file permissions of the home directory
   * -e date        account expiry date
   * -p date        password expiry date
   * -g grp         primary group
***************
*** 157,162 ****
--- 158,172 ----
  	}
  
  	/*
+ 	 * Setting of the mode for the home directory
+ 	 */
+ 	if ((arg = getarg(args, 'A')) != NULL) {
+ 		mode_t *modeset = setmode(arg->val);
+ 		cnf->homemode = getmode(modeset, 0);
+ 		free(modeset);
+ 	}
+ 
+ 	/*
  	 * If we'll need to use it or we're updating it,
  	 * then create the base home directory if necessary
  	 */
***************
*** 181,187 ****
  			if (strchr(cnf->home+1, '/') == NULL) {
  				strcpy(dbuf, "/usr");
  				strncat(dbuf, cnf->home, MAXPATHLEN-5);
! 				if (mkdir(dbuf, 0755) != -1 || errno == EEXIST) {
  					chown(dbuf, 0, 0);
  					/*
  					 * Skip first "/" and create symlink:
--- 191,197 ----
  			if (strchr(cnf->home+1, '/') == NULL) {
  				strcpy(dbuf, "/usr");
  				strncat(dbuf, cnf->home, MAXPATHLEN-5);
! 				if (mkdir(dbuf, cnf->homemode) != -1 || errno == EEXIST) {
  					chown(dbuf, 0, 0);
  					/*
  					 * Skip first "/" and create symlink:
***************
*** 197,203 ****
  				while ((p = strchr(++p, '/')) != NULL) {
  					*p = '\0';
  					if (stat(dbuf, &st) == -1) {
! 						if (mkdir(dbuf, 0755) == -1)
  							goto direrr;
  						chown(dbuf, 0, 0);
  					} else if (!S_ISDIR(st.st_mode))
--- 207,213 ----
  				while ((p = strchr(++p, '/')) != NULL) {
  					*p = '\0';
  					if (stat(dbuf, &st) == -1) {
! 						if (mkdir(dbuf, cnf->homemode) == -1)
  							goto direrr;
  						chown(dbuf, 0, 0);
  					} else if (!S_ISDIR(st.st_mode))
***************
*** 206,212 ****
  				}
  			}
  			if (stat(dbuf, &st) == -1) {
! 				if (mkdir(dbuf, 0755) == -1) {
  				direrr:	err(EX_OSFILE, "mkdir '%s'", dbuf);
  				}
  				chown(dbuf, 0, 0);
--- 216,222 ----
  				}
  			}
  			if (stat(dbuf, &st) == -1) {
! 				if (mkdir(dbuf, cnf->homemode) == -1) {
  				direrr:	err(EX_OSFILE, "mkdir '%s'", dbuf);
  				}
  				chown(dbuf, 0, 0);
***************
*** 763,769 ****
  	 * existing files will *not* be overwritten.
  	 */
  	if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && pwd->pw_dir[1]) {
! 		copymkdir(pwd->pw_dir, cnf->dotdir, 0755, pwd->pw_uid, pwd->pw_gid);
  		pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
  		       pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);
  	}
--- 773,779 ----
  	 * existing files will *not* be overwritten.
  	 */
  	if (!PWALTDIR() && getarg(args, 'm') != NULL && pwd->pw_dir && *pwd->pw_dir == '/' && pwd->pw_dir[1]) {
! 		copymkdir(pwd->pw_dir, cnf->dotdir, cnf->homemode, pwd->pw_uid, pwd->pw_gid);
  		pw_log(cnf, mode, W_USER, "%s(%ld) home %s made",
  		       pwd->pw_name, (long) pwd->pw_uid, pwd->pw_dir);
  	}

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200610100641.k9A6fkae025911>