From kutulu@kutulu.org  Thu Dec 19 10:26:59 2002
Return-Path: <kutulu@kutulu.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CE2D637B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Dec 2002 10:26:59 -0800 (PST)
Received: from basement.kutulu.org (pcp01881232pcs.longhl01.md.comcast.net [68.32.161.3])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 308EE43EB2
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 19 Dec 2002 10:26:54 -0800 (PST)
	(envelope-from kutulu@kutulu.org)
Received: by basement.kutulu.org (Postfix, from userid 1001)
	id 039CEAA95; Thu, 19 Dec 2002 13:27:06 -0500 (EST)
Message-Id: <20021219182706.039CEAA95@basement.kutulu.org>
Date: Thu, 19 Dec 2002 13:27:06 -0500 (EST)
From: Michael Edenfield <kutulu@kutulu.org>
Reply-To: Kutulu <kutulu@kutulu.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: customize home-directory permissions in pw(8)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         46379
>Category:       bin
>Synopsis:       customize home-directory permissions in pw(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 19 10:30:02 PST 2002
>Closed-Date:    Wed Nov 12 20:41:21 PST 2003
>Last-Modified:  Wed Nov 12 20:41:21 PST 2003
>Originator:     Michael Edenfield <kutulu@kutulu.org>
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD basement.kutulu.org 5.0-CURRENT FreeBSD 5.0-CURRENT #5: Sat Dec 14 21:13:44 EST 2002 root@basement.kutulu.org:/usr/obj/usr/src/sys/GATEWAY i386
>Description:

The following patch adds the ability to specify customized permissions to be given to the home directory created by pw(8).  By 
setting defaults in the pw.conf file, this will also add the same feature to adduser(8).
 
>How-To-Repeat:
>Fix:

diff -ur pw.old/pw.c pw/pw.c
--- pw.old/pw.c	Sat Apr  6 00:19:11 2002
+++ pw/pw.c	Thu Dec 19 01:41:56 2002
@@ -106,7 +106,7 @@
 	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:c:d:e:f: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",
@@ -306,6 +306,7 @@
 				"\t-u uid         user id\n"
 				"\t-c comment     user name/comment\n"
 				"\t-d directory   home directory\n"
+				"\t-f perms       permissions for home dir\n"
 				"\t-e date        account expiry date\n"
 				"\t-p date        password expiry date\n"
 				"\t-g grp         initial group\n"
@@ -321,6 +322,7 @@
 				"\t-V etcdir      alternate /etc location\n"
 			        "\t-D             set user defaults\n"
 				"\t-b dir         default home root dir\n"
+				"\t-f perms       default home dir permissions\n"
 				"\t-e period      default expiry period\n"
 				"\t-p period      default password change period\n"
 				"\t-g group       default group\n"
diff -ur pw.old/pw.h pw/pw.h
--- pw.old/pw.h	Sat Apr  6 00:19:11 2002
+++ pw/pw.h	Thu Dec 19 01:49:01 2002
@@ -81,6 +81,7 @@
 	char	*newmail;		/* Mail to send to new accounts */
 	char	*logfile;		/* Where to log changes */
 	char	*home;			/* Where to create home directory */
+	mode_t	homeperms;		/* What permission to give home directory */
 	char	*shelldir;		/* Where shells are located */
 	char	**shells;		/* List of shells */
 	char	*shell_default;		/* Default shell */
@@ -97,6 +98,7 @@
 #define _PATH_PW_CONF	"/etc/pw.conf"
 #define _UC_MAXLINE	1024
 #define _UC_MAXSHELLS	32
+#define _UC_DEFPERMS	S_IRWXU || S_IRGRP || S_IXGRP || S_IROTH || S_IXOTH
 
 struct userconf *read_userconfig(char const * file);
 int write_userconfig(char const * file);
diff -ur pw.old/pw_conf.c pw/pw_conf.c
--- pw.old/pw_conf.c	Sat Apr  6 00:19:11 2002
+++ pw/pw_conf.c	Thu Dec 19 02:02:25 2002
@@ -32,6 +32,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 
 #include "pw.h"
 
@@ -47,6 +48,7 @@
 	_UC_NEWMAIL,
 	_UC_LOGFILE,
 	_UC_HOMEROOT,
+	_UC_HOMEPERMS,
 	_UC_SHELLPATH,
 	_UC_SHELLS,
 	_UC_DEFAULTSHELL,
@@ -90,6 +92,7 @@
 	NULL,			/* Mail to send to new accounts */
 	"/var/log/userlog",	/* Where to log changes */
 	"/home",		/* Where to create home directory */
+	_UC_DEFPERMS,		/* Permissions to give home directory */
 	"/bin",			/* Where shells are located */
 	system_shells,		/* List of shells (first is default) */
 	bourne_shell,		/* Default shell */
@@ -114,6 +117,7 @@
 	"\n# Mail this file to new user (/etc/newuser.msg or no)\n",
 	"\n# Log add/change/remove information in this file\n",
 	"\n# Root directory in which $HOME directory is created\n",
+	"\n# Permissions given to newly-created $HOME directory\n",
 	"\n# Colon separated list of directories containing valid shells\n",
 	"\n# Comma separated list of available shells (without paths)\n",
 	"\n# Default shell (without path)\n",
@@ -139,6 +143,7 @@
 	"newmail",
 	"logfile",
 	"home",
+	"homeperms",
 	"shellpath",
 	"shells",
 	"defaultshell",
@@ -294,6 +299,10 @@
 					config.home = (q == NULL || !boolean_val(q, 1))
 						? "/home" : newstr(q);
 					break;
+				case _UC_HOMEPERMS:
+					if ((q = unquote(q)) != NULL && isdigit(*q))
+						config.homeperms = (mode_t) strtol(q, (char **)NULL, 8);
+					break;
 				case _UC_SHELLPATH:
 					config.shelldir = (q == NULL || !boolean_val(q, 1))
 						? "/bin" : newstr(q);
@@ -412,6 +421,10 @@
 					break;
 				case _UC_HOMEROOT:
 					val = config.home;
+					break;
+				case _UC_HOMEPERMS:
+					sprintf(buf, "%lu", (unsigned long) config.homeperms);
+					quote = 0;
 					break;
 				case _UC_SHELLPATH:
 					val = config.shelldir;
diff -ur pw.old/pw_user.c pw/pw_user.c
--- pw.old/pw_user.c	Mon Nov  4 20:38:02 2002
+++ pw/pw_user.c	Thu Dec 19 02:01:15 2002
@@ -76,6 +76,7 @@
  * -u uid         user id
  * -c comment     user name/comment
  * -d directory   home directory
+ * -f perms       permissions on directory
  * -e date        account expiry date
  * -p date        password expiry date
  * -g grp         primary group
@@ -155,6 +156,11 @@
 		cnf->home = arg->val;
 	}
 
+	if ((arg = getarg(args, 'f')) != NULL) {
+		if (isdigit(*(arg->val)))
+			cnf->homeperms = (mode_t) strtol(arg->val, (char **)NULL, 8);
+	}
+
 	/*
 	 * If we'll need to use it or we're updating it,
 	 * then create the base home directory if necessary
@@ -745,7 +751,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, cnf->homeperms, 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:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Wed Nov 12 20:40:59 PST 2003 
State-Changed-Why:  
Closed at submitter's request. 

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