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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/oamuser/user/useradd.c
          +++ new/usr/src/cmd/oamuser/user/useradd.c
↓ open down ↓ 44 lines elided ↑ open up ↑
  45   45  #include        <project.h>
  46   46  #include        <unistd.h>
  47   47  #include        <user_attr.h>
  48   48  #include        <libcmdutils.h>
  49   49  #include        "users.h"
  50   50  #include        "messages.h"
  51   51  #include        "userdisp.h"
  52   52  #include        "funcs.h"
  53   53  
  54   54  /*
  55      - *  useradd [-u uid [-o] | -g group | -G group [[, group]...] | -d dir [-m]
       55 + *  useradd [-u uid [-o] | -g group | -G group [[, group]...]
       56 + *              | -d dir [-m [-z|Z]]
  56   57   *              | -s shell | -c comment | -k skel_dir | -b base_dir] ]
  57   58   *              [ -A authorization [, authorization ...]]
  58   59   *              [ -P profile [, profile ...]]
  59   60   *              [ -K key=value ]
  60   61   *              [ -R role [, role ...]] [-p project [, project ...]] login
  61   62   *  useradd -D [ -g group ] [ -b base_dir | -f inactive | -e expire |
  62   63   *              -s shell | -k skel_dir ]
  63   64   *              [ -A authorization [, authorization ...]]
  64   65   *              [ -P profile [, profile ...]] [ -K key=value ]
  65   66   *              [ -R role [, role ...]] [-p project [, project ...]] login
↓ open down ↓ 23 lines elided ↑ open up ↑
  89   90  static void cleanup();
  90   91  
  91   92  extern int check_perm(), valid_expire();
  92   93  extern int putusrdef(), valid_uid();
  93   94  extern int call_passmgmt(), edit_group(), create_home();
  94   95  extern int edit_project();
  95   96  extern int **valid_lgroup();
  96   97  extern projid_t **valid_lproject();
  97   98  extern void update_def(struct userdefs *);
  98   99  extern void import_def(struct userdefs *);
      100 +extern int get_default_zfs_flags();
  99  101  
 100  102  static uid_t uid;                       /* new uid */
 101  103  static char *logname;                   /* login name to add */
 102  104  static struct userdefs *usrdefs;        /* defaults for useradd */
 103  105  
 104  106  char *cmdname;
 105  107  
 106  108  static char homedir[ PATH_MAX + 1 ];    /* home directory */
 107  109  static char gidstring[32];              /* group id string representation */
 108  110  static gid_t gid;                       /* gid of new login */
↓ open down ↓ 21 lines elided ↑ open up ↑
 130  132  } path_opt_t;
 131  133  
 132  134  
 133  135  static void valid_input(path_opt_t, const char *);
 134  136  
 135  137  int
 136  138  main(argc, argv)
 137  139  int argc;
 138  140  char *argv[];
 139  141  {
 140      -        int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
      142 +        int ch, ret, mflag = 0, oflag = 0, Dflag = 0;
      143 +        int zflag = 0, Zflag = 0, **gidlist = NULL;
 141  144          projid_t **projlist = NULL;
 142  145          char *ptr;                      /* loc in a str, may be set by strtol */
 143  146          struct group *g_ptr;
 144  147          struct project p_ptr;
 145  148          char mybuf[PROJECT_BUFSZ];
 146  149          struct stat statbuf;            /* status buffer for stat */
 147  150          int warning;
 148  151          int busy = 0;
 149  152          char **nargv;                   /* arguments for execvp of passmgmt */
 150  153          int argindex;                   /* argument index into nargv */
      154 +        int zfs_flags = 0;                      /* create_home flags */
 151  155  
 152  156          cmdname = argv[0];
 153  157  
 154  158          if (geteuid() != 0) {
 155  159                  errmsg(M_PERM_DENIED);
 156  160                  exit(EX_NO_PERM);
 157  161          }
 158  162  
 159  163          opterr = 0;                     /* no print errors from getopt */
 160  164          usertype = getusertype(argv[0]);
 161  165  
 162  166          change_key(USERATTR_TYPE_KW, usertype);
 163  167  
 164  168          while ((ch = getopt(argc, argv,
 165      -                    "b:c:Dd:e:f:G:g:k:mop:s:u:A:P:R:K:")) != EOF)
      169 +                    "b:c:Dd:e:f:G:g:k:mzZop:s:u:A:P:R:K:")) != EOF)
 166  170                  switch (ch) {
 167  171                  case 'b':
 168  172                          base_dir = optarg;
 169  173                          break;
 170  174  
 171  175                  case 'c':
 172  176                          comment = optarg;
 173  177                          break;
 174  178  
 175  179                  case 'D':
↓ open down ↓ 37 lines elided ↑ open up ↑
 213  217                          break;
 214  218  
 215  219                  case 's':
 216  220                          shell = optarg;
 217  221                          break;
 218  222  
 219  223                  case 'u':
 220  224                          uidstr = optarg;
 221  225                          break;
 222  226  
      227 +                case 'Z':
      228 +                        Zflag++;
      229 +                        break;
      230 +
      231 +                case 'z':
      232 +                        zflag++;
      233 +                        break;
      234 +
 223  235                  case 'A':
 224  236                          change_key(USERATTR_AUTHS_KW, optarg);
 225  237                          break;
 226  238  
 227  239                  case 'P':
 228  240                          change_key(USERATTR_PROFILES_KW, optarg);
 229  241                          break;
 230  242  
 231  243                  case 'R':
 232  244                          if (is_role(usertype)) {
↓ open down ↓ 9 lines elided ↑ open up ↑
 242  254  
 243  255                  default:
 244  256                  case '?':
 245  257                          if (is_role(usertype))
 246  258                                  errmsg(M_ARUSAGE);
 247  259                          else
 248  260                                  errmsg(M_AUSAGE);
 249  261                          exit(EX_SYNTAX);
 250  262                  }
 251  263  
      264 +        if (((!mflag) && (zflag || Zflag)) || (zflag && Zflag) ||
      265 +            (mflag > 1 && (zflag || Zflag))) {
      266 +                if (is_role(usertype))
      267 +                        errmsg(M_ARUSAGE);
      268 +                else
      269 +                        errmsg(M_AUSAGE);
      270 +                exit(EX_SYNTAX);
      271 +        }
      272 +
      273 +
 252  274          /* get defaults for adding new users */
 253  275          usrdefs = getusrdef(usertype);
 254  276  
 255  277          if (Dflag) {
 256  278                  /* DISPLAY mode */
 257  279  
 258  280                  /* check syntax */
 259  281                  if (optind != argc) {
 260  282                          if (is_role(usertype))
 261  283                                  errmsg(M_ARUSAGE);
↓ open down ↓ 417 lines elided ↑ open up ↑
 679  701  
 680  702          /* update project database */
 681  703          if ((projects != NULL) &&
 682  704              edit_project(logname, (char *)NULL, projlist, 0)) {
 683  705                  errmsg(M_UPDATE, "created");
 684  706                  cleanup(logname);
 685  707                  exit(EX_UPDATE);
 686  708          }
 687  709  
 688  710          /* create home directory */
 689      -        if (mflag &&
 690      -            (create_home(homedir, skel_dir, uid, gid) != EX_SUCCESS)) {
      711 +        if (mflag) {
      712 +                zfs_flags = get_default_zfs_flags();
      713 +
      714 +                if (zflag || mflag > 1)
      715 +                        zfs_flags |= CHANGE_ZFS_FS;
      716 +                else if (Zflag)
      717 +                        zfs_flags &= ~CHANGE_ZFS_FS;
      718 +                ret = create_home(homedir, skel_dir, uid, gid, zfs_flags);
      719 +        }
      720 +        if (ret != EX_SUCCESS) {
      721 +                (void) edit_project(logname, (char *)NULL, (projid_t **)NULL,
      722 +                    0);
 691  723                  (void) edit_group(logname, (char *)0, (int **)0, 1);
 692  724                  cleanup(logname);
 693  725                  exit(EX_HOMEDIR);
 694  726          }
 695  727  
 696  728          return (ret);
 697  729  }
 698  730  
 699  731  static void
 700  732  cleanup(logname)
↓ open down ↓ 65 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX