From owner-freebsd-questions Wed Dec 18 23:19: 1 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id AEE0A37B401 for ; Wed, 18 Dec 2002 23:18:56 -0800 (PST) Received: from basement.kutulu.org (pcp01881232pcs.longhl01.md.comcast.net [68.32.161.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id D748943ED4 for ; Wed, 18 Dec 2002 23:18:55 -0800 (PST) (envelope-from kutulu@kutulu.org) Received: by basement.kutulu.org (Postfix, from userid 1001) id 61A1EA934; Thu, 19 Dec 2002 02:19:06 -0500 (EST) Date: Thu, 19 Dec 2002 02:19:06 -0500 From: Kutulu To: freebsd-questions@freebsd.org Cc: kutulu@kutulu.org Subject: new pw(8) feature - home directory permissions. Message-ID: <20021219071906.GA79994@basement.kutulu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0F1p//8PRICkK4MW" Content-Disposition: inline User-Agent: Mutt/1.4i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline (I apologize in advance if this is too mundane for -hackers...) After seeing multiple people on IRC ask how to specify the permissions for the home directory adduser(8) creates, I went in and added that feature to pw(8). A diff is attached. As this is my first FreeBSD diff ever, comments from veteran hackers are highly requested. If this is something people find useful, I will also go into adduser(8) and add support for the new flag there, and of course, edit the man pages. In particular, I want someone who knows what they're doing to make sure I have my types and signs and such correct. I also don't like 'f' as the name of the option but the obvious ones ('m' and 'p') are taken. Thanks, --Mike Edenfield --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pw.homeperms.diff" 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_IROTH 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 #include #include +#include #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); } --0F1p//8PRICkK4MW-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message