Print this page
293 useradd/del/mod should be ZFS-aware

@@ -50,11 +50,12 @@
 #include        "messages.h"
 #include        "userdisp.h"
 #include        "funcs.h"
 
 /*
- *  useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m]
+ *  useradd [-u uid [-o] | -g group | -G group [[, group]...]
+ *              | -d dir [-m [-z|Z]]
  *              | -s shell | -c comment | -k skel_dir | -b base_dir] ]
  *              [ -A authorization [, authorization ...]]
  *              [ -P profile [, profile ...]]
  *              [ -K key=value ]
  *              [ -R role [, role ...]] [-p project [, project ...]] login

@@ -94,10 +95,11 @@
 extern int edit_project();
 extern int **valid_lgroup();
 extern projid_t **valid_lproject();
 extern void update_def(struct userdefs *);
 extern void import_def(struct userdefs *);
+extern int get_default_zfs_flags();
 
 static uid_t uid;                       /* new uid */
 static char *logname;                   /* login name to add */
 static struct userdefs *usrdefs;        /* defaults for useradd */
 

@@ -135,21 +137,23 @@
 int
 main(argc, argv)
 int argc;
 char *argv[];
 {
-        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
+        int ch, ret, mflag = 0, oflag = 0, Dflag = 0;
+        int zflag = 0, Zflag = 0, **gidlist = NULL;
         projid_t **projlist = NULL;
         char *ptr;                      /* loc in a str, may be set by strtol */
         struct group *g_ptr;
         struct project p_ptr;
         char mybuf[PROJECT_BUFSZ];
         struct stat statbuf;            /* status buffer for stat */
         int warning;
         int busy = 0;
         char **nargv;                   /* arguments for execvp of passmgmt */
         int argindex;                   /* argument index into nargv */
+        int zfs_flags = 0;                      /* create_home flags */
 
         cmdname = argv[0];
 
         if (geteuid() != 0) {
                 errmsg(M_PERM_DENIED);

@@ -160,11 +164,11 @@
         usertype = getusertype(argv[0]);
 
         change_key(USERATTR_TYPE_KW, usertype);
 
         while ((ch = getopt(argc, argv,
-                    "b:c:Dd:e:f:G:g:k:mop:s:u:A:P:R:K:")) != EOF)
+                    "b:c:Dd:e:f:G:g:k:mzZop:s:u:A:P:R:K:")) != EOF)
                 switch (ch) {
                 case 'b':
                         base_dir = optarg;
                         break;
 

@@ -218,10 +222,18 @@
 
                 case 'u':
                         uidstr = optarg;
                         break;
 
+                case 'Z':
+                        Zflag++;
+                        break;
+
+                case 'z':
+                        zflag++;
+                        break;
+
                 case 'A':
                         change_key(USERATTR_AUTHS_KW, optarg);
                         break;
 
                 case 'P':

@@ -247,10 +259,20 @@
                         else
                                 errmsg(M_AUSAGE);
                         exit(EX_SYNTAX);
                 }
 
+        if (((!mflag) && (zflag || Zflag)) || (zflag && Zflag) ||
+            (mflag > 1 && (zflag || Zflag))) {
+                if (is_role(usertype))
+                        errmsg(M_ARUSAGE);
+                else
+                        errmsg(M_AUSAGE);
+                exit(EX_SYNTAX);
+        }
+
+
         /* get defaults for adding new users */
         usrdefs = getusrdef(usertype);
 
         if (Dflag) {
                 /* DISPLAY mode */

@@ -684,12 +706,22 @@
                 cleanup(logname);
                 exit(EX_UPDATE);
         }
 
         /* create home directory */
-        if (mflag &&
-            (create_home(homedir, skel_dir, uid, gid) != EX_SUCCESS)) {
+        if (mflag) {
+                zfs_flags = get_default_zfs_flags();
+
+                if (zflag || mflag > 1)
+                        zfs_flags |= CHANGE_ZFS_FS;
+                else if (Zflag)
+                        zfs_flags &= ~CHANGE_ZFS_FS;
+                ret = create_home(homedir, skel_dir, uid, gid, zfs_flags);
+        }
+        if (ret != EX_SUCCESS) {
+                (void) edit_project(logname, (char *)NULL, (projid_t **)NULL,
+                    0);
                 (void) edit_group(logname, (char *)0, (int **)0, 1);
                 cleanup(logname);
                 exit(EX_HOMEDIR);
         }