(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
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 dateaccount expiry date\n
\t-p datepassword 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_MAXLINE1024
#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.cSat Apr 6 00:19:11 2002
+++ pw/pw_conf.cThu 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 =