From k.stevenson@louisville.edu  Mon Feb 21 07:40:59 2000
Return-Path: <k.stevenson@louisville.edu>
Received: from erouter0.it-datacntr.louisville.edu (erouter0.it-datacntr.louisville.edu [136.165.1.36])
	by hub.freebsd.org (Postfix) with ESMTP id EEE0C37BF88
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Feb 2000 07:40:57 -0800 (PST)
	(envelope-from k.stevenson@louisville.edu)
Received: from osaka.louisville.edu (osaka.louisville.edu [136.165.1.114])
	by erouter0.it-datacntr.louisville.edu (Postfix) with ESMTP id 8C02924DAB
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 21 Feb 2000 10:40:56 -0500 (EST)
Received: by osaka.louisville.edu (Postfix, from userid 15)
	id 534B418605; Mon, 21 Feb 2000 10:40:56 -0500 (EST)
Message-Id: <20000221154056.534B418605@osaka.louisville.edu>
Date: Mon, 21 Feb 2000 10:40:56 -0500 (EST)
From: k.stevenson@louisville.edu
Reply-To: ktstev01@osaka.louisville.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] pw(8) hardcodes directory creation modes
X-Send-Pr-Version: 3.2

>Number:         16880
>Category:       bin
>Synopsis:       [PATCH] pw(8) hardcodes directory creation modes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    le
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb 21 07:50:01 PST 2000
>Closed-Date:    Fri May 04 17:37:24 GMT 2007
>Last-Modified:  Fri May 04 17:37:24 GMT 2007
>Originator:     Keith Stevenson
>Release:        FreeBSD 3.4-STABLE i386
>Organization:
University of Louisville
>Environment:

	FreeBSD-STABLE and FreeBSD-CURRENT


>Description:

	pw(8) ignores umask and always creates directories as mode 0755.  The
enclosed patch against CURRENT respects the parent process umask and adds a
-U option to specify the umask on the command line.

>How-To-Repeat:

	Set umask to something more restrictive than 022 and use pw to create
an account and home directory.

>Fix:
	
	Patch against Current.  Patch has been moderately tested.


Index: pw.8
===================================================================
RCS file: /opt/ncvs/src/usr.sbin/pw/pw.8,v
retrieving revision 1.17
diff -u -r1.17 pw.8
--- pw.8	1999/08/28 01:19:18	1.17
+++ pw.8	2000/02/20 02:41:11
@@ -41,6 +41,7 @@
 .Op Fl u Ar uid
 .Op Fl c Ar comment
 .Op Fl d Ar dir
+.Op Fl U Ar umask
 .Op Fl e Ar date
 .Op Fl p Ar date
 .Op Fl g Ar group
@@ -346,6 +347,8 @@
 - normally
 .Pa /home
 with the account name as a subdirectory.
+.It Fl U Ar umask
+Set the umask to be used when creating the account's home directory and skeleton files.  Default is parent process umask.
 .It Fl e Ar date
 Set the account's expiration date. 
 Format of the date is either a UNIX time in decimal, or a date in
Index: pw.c
===================================================================
RCS file: /opt/ncvs/src/usr.sbin/pw/pw.c,v
retrieving revision 1.18
diff -u -r1.18 pw.c
--- pw.c	2000/01/15 00:20:20	1.18
+++ pw.c	2000/02/20 02:41:12
@@ -29,6 +29,7 @@
   "$FreeBSD: src/usr.sbin/pw/pw.c,v 1.18 2000/01/15 00:20:20 davidn Exp $";
 #endif /* not lint */
 
+#include <ctype.h>
 #include <err.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -89,6 +90,8 @@
 
 static struct cargs arglist;
 
+static int mask;
+
 static int      getindex(const char *words[], const char *word);
 static void     cmdhelp(int mode, int which);
 
@@ -105,13 +108,13 @@
 	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:Db:NPy:Y",
-			"V:C:qn:u:rY",
-			"V:C:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:FNPY",
-			"V:C:qn:u:FPa7",
-			"V:C:q",
-			"V:C:q",
-			"V:C:q"
+			"V:C:U:qn:u:c:d:e:p:g:G:mk:s:oL:i:w:h:Db:NPy:Y",
+			"V:C:U:qn:u:rY",
+			"V:C:U:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:FNPY",
+			"V:C:U:qn:u:FPa7",
+			"V:C:U:q",
+			"V:C:U:q",
+			"V:C:U:q"
 		},
 		{ /* grp  */
 			"V:C:qn:g:h:M:pNPY",
@@ -128,7 +131,6 @@
 		pw_group
 	};
 
-	umask(0);		/* We wish to handle this manually */
 	LIST_INIT(&arglist);
 
 	/*
@@ -221,6 +223,30 @@
 			setgrdir(etcpath);
 		}
 	}
+
+	/*
+	 * Set the umask if specified on the command line
+	 */
+
+	if (getarg(&arglist, 'U') != NULL) {
+		char * um = getarg(&arglist, 'U')-> val;
+		if (um != NULL) {
+			if (isdigit(*um)) {
+				mask = 0;
+				do {
+					if (*um >= '8' || *um < '0') {
+						fprintf(stderr, "Illegal umask: %s\n", um);
+						exit(EX_USAGE);
+					}
+					mask = (mask << 3) + (*um - '0');
+				} while (*++um != '\0');
+				umask(mask);
+			} else {
+				fprintf(stderr, "Illegal umask: %s\n", um);
+				exit(EX_USAGE);
+			}
+		}
+	}
     
 	/*
 	 * Now, let's do the common initialisation
@@ -301,6 +327,7 @@
 				"\t-u uid         user id\n"
 				"\t-c comment     user name/comment\n"
 				"\t-d directory   home directory\n"
+				"\t-U umask       Directory/file creation mask\n"
 				"\t-e date        account expiry date\n"
 				"\t-p date        password expiry date\n"
 				"\t-g grp         initial group\n"
Index: pw_user.c
===================================================================
RCS file: /opt/ncvs/src/usr.sbin/pw/pw_user.c,v
retrieving revision 1.34
diff -u -r1.34 pw_user.c
--- pw_user.c	2000/01/15 00:20:21	1.34
+++ pw_user.c	2000/02/20 02:41:16
@@ -179,7 +179,7 @@
 			if (strchr(cnf->home+1, '/') == NULL) {
 				strcpy(dbuf, "/usr");
 				strncat(dbuf, cnf->home, MAXPATHLEN-5);
-				if (mkdir(dbuf, 0755) != -1 || errno == EEXIST) {
+				if (mkdir(dbuf, 0777) != -1 || errno == EEXIST) {
 					chown(dbuf, 0, 0);
 					symlink(dbuf, cnf->home);
 				}
@@ -191,7 +191,7 @@
 				while ((p = strchr(++p, '/')) != NULL) {
 					*p = '\0';
 					if (stat(dbuf, &st) == -1) {
-						if (mkdir(dbuf, 0755) == -1)
+						if (mkdir(dbuf, 0777) == -1)
 							goto direrr;
 						chown(dbuf, 0, 0);
 					} else if (!S_ISDIR(st.st_mode))
@@ -200,7 +200,7 @@
 				}
 			}
 			if (stat(dbuf, &st) == -1) {
-				if (mkdir(dbuf, 0755) == -1) {
+				if (mkdir(dbuf, 0777) == -1) {
 				direrr:	err(EX_OSFILE, "mkdir '%s'", dbuf);
 				}
 				chown(dbuf, 0, 0);
@@ -734,7 +734,7 @@
 	 * 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);
+		copymkdir(pwd->pw_dir, cnf->dotdir, 0777, 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:

From: Keith Stevenson <k.stevenson@louisville.edu>
To: FreeBSD-gnats-submit@freebsd.org
Cc: freebsd-bugs@freebsd.org
Subject: Re: bin/16880: [PATCH] pw(8) hardcodes directory creation modes
Date: Tue, 29 Feb 2000 21:38:33 -0500

 --PNTmBPCT7hxwcZjr
 Content-Type: text/plain; charset=us-ascii
 
 Attached is an updated patch which fixes some nits raised by Sheldon Hearn.
 
 Regards,
 --Keith Stevenson--
 
 -- 
 Keith Stevenson
 System Programmer - Data Center Services - University of Louisville
 k.stevenson@louisville.edu
 PGP key fingerprint =  4B 29 A8 95 A8 82 EA A2  29 CE 68 DE FC EE B6 A0
 
 --PNTmBPCT7hxwcZjr
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename="pw.patch"
 
 cvs server: Diffing .
 Index: pw.8
 ===================================================================
 RCS file: /opt/ncvs/src/usr.sbin/pw/pw.8,v
 retrieving revision 1.17
 diff -u -r1.17 pw.8
 --- pw.8	1999/08/28 01:19:18	1.17
 +++ pw.8	2000/03/01 02:01:10
 @@ -41,6 +41,7 @@
  .Op Fl u Ar uid
  .Op Fl c Ar comment
  .Op Fl d Ar dir
 +.Op Fl U Ar umask
  .Op Fl e Ar date
  .Op Fl p Ar date
  .Op Fl g Ar group
 @@ -346,6 +347,12 @@
  - normally
  .Pa /home
  with the account name as a subdirectory.
 +.It Fl U Ar umask
 +Set the
 +.Xr umask 2
 +to be used when creating the account's home directory and skeleton files.
 +Default is parent process
 +.Xr umask 2 .
  .It Fl e Ar date
  Set the account's expiration date. 
  Format of the date is either a UNIX time in decimal, or a date in
 @@ -870,6 +877,7 @@
  .Sh SEE ALSO
  .Xr chpass 1 ,
  .Xr passwd 1 ,
 +.Xr umask 2 ,
  .Xr group 5 ,
  .Xr login.conf 5 ,
  .Xr passwd 5 ,
 Index: pw.c
 ===================================================================
 RCS file: /opt/ncvs/src/usr.sbin/pw/pw.c,v
 retrieving revision 1.18
 diff -u -r1.18 pw.c
 --- pw.c	2000/01/15 00:20:20	1.18
 +++ pw.c	2000/03/01 02:01:11
 @@ -29,6 +29,7 @@
    "$FreeBSD: src/usr.sbin/pw/pw.c,v 1.18 2000/01/15 00:20:20 davidn Exp $";
  #endif /* not lint */
  
 +#include <ctype.h>
  #include <err.h>
  #include <fcntl.h>
  #include <paths.h>
 @@ -89,6 +90,8 @@
  
  static struct cargs arglist;
  
 +static mode_t mask;
 +
  static int      getindex(const char *words[], const char *word);
  static void     cmdhelp(int mode, int which);
  
 @@ -105,13 +108,13 @@
  	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:Db:NPy:Y",
 -			"V:C:qn:u:rY",
 -			"V:C:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:FNPY",
 -			"V:C:qn:u:FPa7",
 -			"V:C:q",
 -			"V:C:q",
 -			"V:C:q"
 +			"V:C:U:qn:u:c:d:e:p:g:G:mk:s:oL:i:w:h:Db:NPy:Y",
 +			"V:C:U:qn:u:rY",
 +			"V:C:U:qn:u:c:d:e:p:g:G:ml:k:s:w:L:h:FNPY",
 +			"V:C:U:qn:u:FPa7",
 +			"V:C:U:q",
 +			"V:C:U:q",
 +			"V:C:U:q"
  		},
  		{ /* grp  */
  			"V:C:qn:g:h:M:pNPY",
 @@ -128,7 +131,6 @@
  		pw_group
  	};
  
 -	umask(0);		/* We wish to handle this manually */
  	LIST_INIT(&arglist);
  
  	/*
 @@ -221,6 +223,30 @@
  			setgrdir(etcpath);
  		}
  	}
 +
 +	/*
 +	 * Set the umask if specified on the command line
 +	 */
 +
 +	if (getarg(&arglist, 'U') != NULL) {
 +		char * um = getarg(&arglist, 'U')-> val;
 +		if (um != NULL) {
 +			if (isdigit(*um)) {
 +				mask = 0;
 +				do {
 +					if (*um >= '8' || *um < '0') {
 +						fprintf(stderr, "Illegal umask: %s\n", um);
 +						exit(EX_USAGE);
 +					}
 +					mask = (mask << 3) + (*um - '0');
 +				} while (*++um != '\0');
 +				umask(mask);
 +			} else {
 +				fprintf(stderr, "Illegal umask: %s\n", um);
 +				exit(EX_USAGE);
 +			}
 +		}
 +	}
      
  	/*
  	 * Now, let's do the common initialisation
 @@ -301,6 +327,7 @@
  				"\t-u uid         user id\n"
  				"\t-c comment     user name/comment\n"
  				"\t-d directory   home directory\n"
 +				"\t-U umask       Directory/file creation mask\n"
  				"\t-e date        account expiry date\n"
  				"\t-p date        password expiry date\n"
  				"\t-g grp         initial group\n"
 Index: pw_user.c
 ===================================================================
 RCS file: /opt/ncvs/src/usr.sbin/pw/pw_user.c,v
 retrieving revision 1.34
 diff -u -r1.34 pw_user.c
 --- pw_user.c	2000/01/15 00:20:21	1.34
 +++ pw_user.c	2000/03/01 02:01:15
 @@ -179,7 +179,7 @@
  			if (strchr(cnf->home+1, '/') == NULL) {
  				strcpy(dbuf, "/usr");
  				strncat(dbuf, cnf->home, MAXPATHLEN-5);
 -				if (mkdir(dbuf, 0755) != -1 || errno == EEXIST) {
 +				if (mkdir(dbuf, 0777) != -1 || errno == EEXIST) {
  					chown(dbuf, 0, 0);
  					symlink(dbuf, cnf->home);
  				}
 @@ -191,7 +191,7 @@
  				while ((p = strchr(++p, '/')) != NULL) {
  					*p = '\0';
  					if (stat(dbuf, &st) == -1) {
 -						if (mkdir(dbuf, 0755) == -1)
 +						if (mkdir(dbuf, 0777) == -1)
  							goto direrr;
  						chown(dbuf, 0, 0);
  					} else if (!S_ISDIR(st.st_mode))
 @@ -200,7 +200,7 @@
  				}
  			}
  			if (stat(dbuf, &st) == -1) {
 -				if (mkdir(dbuf, 0755) == -1) {
 +				if (mkdir(dbuf, 0777) == -1) {
  				direrr:	err(EX_OSFILE, "mkdir '%s'", dbuf);
  				}
  				chown(dbuf, 0, 0);
 @@ -734,7 +734,7 @@
  	 * 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);
 +		copymkdir(pwd->pw_dir, cnf->dotdir, 0777, 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);
  	}
 
 --PNTmBPCT7hxwcZjr--
 
Responsible-Changed-From-To: freebsd-bugs->davidn 
Responsible-Changed-By: nra 
Responsible-Changed-When: Wed Jul 19 20:39:05 PDT 2000 
Responsible-Changed-Why:  
David seems to be working with pw(8) alot these days. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16880 
Responsible-Changed-From-To: davidn->freebsd-bugs 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Fri Mar 14 21:47:26 PST 2003 
Responsible-Changed-Why:  

davidn is no longer with us 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16880 
Responsible-Changed-From-To: freebsd-bugs->le 
Responsible-Changed-By: le 
Responsible-Changed-When: Mon Mar 26 23:17:57 UTC 2007 
Responsible-Changed-Why:  
Have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16880 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/16880: commit references a PR
Date: Mon, 26 Mar 2007 23:29:27 +0000 (UTC)

 le          2007-03-26 23:29:20 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/pw          pw.8 pw.c pw_user.c 
   Log:
   Introduce the new option -M to allow to set the permissions of
   the user's newly created home directory.  If omitted, it's derived
   from the current umask.
   
   PR:      bin/16880, bin/83253 (partially), bin/104248
   MFC in:  1 month
   
   Revision  Changes    Path
   1.40      +12 -1     src/usr.sbin/pw/pw.8
   1.29      +2 -3      src/usr.sbin/pw/pw.c
   1.59      +17 -4     src/usr.sbin/pw/pw_user.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: le 
State-Changed-When: Mon Mar 26 23:35:19 UTC 2007 
State-Changed-Why:  
A patch similar to yours was committed to -CURRENT. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16880 
State-Changed-From-To: patched->closed 
State-Changed-By: le 
State-Changed-When: Fri May 4 17:37:16 UTC 2007 
State-Changed-Why:  
MFC happened. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=16880 
>Unformatted:
