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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/oamuser/user/usermod.c
          +++ new/usr/src/cmd/oamuser/user/usermod.c
↓ open down ↓ 42 lines elided ↑ open up ↑
  43   43  #include <userdefs.h>
  44   44  #include <user_attr.h>
  45   45  #include <nss_dbdefs.h>
  46   46  #include <errno.h>
  47   47  #include <project.h>
  48   48  #include "users.h"
  49   49  #include "messages.h"
  50   50  #include "funcs.h"
  51   51  
  52   52  /*
  53      - *  usermod [-u uid [-o] | -g group | -G group [[,group]...] | -d dir [-m]
       53 + *  usermod [-u uid [-o] | -g group | -G group [[,group]...]
       54 + *              | -d dir [-m [-z|Z]]
  54   55   *              | -s shell | -c comment | -l new_logname]
  55   56   *              | -f inactive | -e expire ]
  56   57   *              [ -A authorization [, authorization ...]]
  57   58   *              [ -P profile [, profile ...]]
  58   59   *              [ -R role [, role ...]]
  59   60   *              [ -K key=value ]
  60   61   *              [ -p project [, project]] login
  61   62   *
  62   63   *      This command adds new user logins to the system.  Arguments are:
  63   64   *
↓ open down ↓ 11 lines elided ↑ open up ↑
  75   76   *      authorization - One or more comma separated authorizations defined
  76   77   *                      in auth_attr(4).
  77   78   *      profile - One or more comma separated execution profiles defined
  78   79   *                in prof_attr(4)
  79   80   *      role - One or more comma-separated role names defined in user_attr(4)
  80   81   *      key=value - One or more -K options each specifying a valid user_attr(4)
  81   82   *              attribute.
  82   83   *
  83   84   */
  84   85  
  85      -extern int **valid_lgroup(), isbusy();
       86 +extern int **valid_lgroup(), isbusy(), get_default_zfs_flags();
  86   87  extern int valid_uid(), check_perm(), create_home(), move_dir();
  87   88  extern int valid_expire(), edit_group(), call_passmgmt();
  88   89  extern projid_t **valid_lproject();
  89   90  
  90   91  static uid_t uid;               /* new uid */
  91   92  static gid_t gid;                       /* gid of new login */
  92   93  static char *new_logname = NULL;        /* new login name with -l option */
  93   94  static char *uidstr = NULL;             /* uid from command line */
  94   95  static char *group = NULL;              /* group from command line */
  95   96  static char *grps = NULL;               /* multi groups from command line */
↓ open down ↓ 42 lines elided ↑ open up ↑
 138  139          npw->pw_shell = strcpmalloc(opw->pw_shell);
 139  140  
 140  141          return (npw);
 141  142  }
 142  143  
 143  144  int
 144  145  main(argc, argv)
 145  146  int argc;
 146  147  char **argv;
 147  148  {
 148      -        int ch, ret = EX_SUCCESS, call_pass = 0, oflag = 0;
 149      -        int tries, mflag = 0, inact, **gidlist, flag = 0;
      149 +        int ch, ret = EX_SUCCESS, call_pass = 0, oflag = 0, zfs_flags = 0;
      150 +        int tries, mflag = 0, inact, **gidlist, flag = 0, zflag = 0, Zflag = 0;
 150  151          boolean_t fail_if_busy = B_FALSE;
 151  152          char *ptr;
 152  153          struct passwd *pstruct;         /* password struct for login */
 153  154          struct passwd *pw;
 154  155          struct group *g_ptr;    /* validated group from -g */
 155  156          struct stat statbuf;            /* status buffer for stat */
 156  157  #ifndef att
 157  158          FILE *pwf;              /* fille ptr for opened passwd file */
 158  159  #endif
 159  160          int warning;
↓ open down ↓ 9 lines elided ↑ open up ↑
 169  170          if (geteuid() != 0) {
 170  171                  errmsg(M_PERM_DENIED);
 171  172                  exit(EX_NO_PERM);
 172  173          }
 173  174  
 174  175          opterr = 0;                     /* no print errors from getopt */
 175  176          /* get user type based on the program name */
 176  177          usertype = getusertype(argv[0]);
 177  178  
 178  179          while ((ch = getopt(argc, argv,
 179      -                                "c:d:e:f:G:g:l:mop:s:u:A:P:R:K:")) != EOF)
      180 +                                "c:d:e:f:G:g:l:mzZop:s:u:A:P:R:K:")) != EOF)
 180  181                  switch (ch) {
 181  182                  case 'c':
 182  183                          comment = optarg;
 183  184                          flag++;
 184  185                          break;
 185  186                  case 'd':
 186  187                          dir = optarg;
 187  188                          fail_if_busy = B_TRUE;
 188  189                          flag++;
 189  190                          break;
↓ open down ↓ 35 lines elided ↑ open up ↑
 225  226                          break;
 226  227                  case 's':
 227  228                          shell = optarg;
 228  229                          flag++;
 229  230                          break;
 230  231                  case 'u':
 231  232                          uidstr = optarg;
 232  233                          flag++;
 233  234                          fail_if_busy = B_TRUE;
 234  235                          break;
      236 +                case 'Z':
      237 +                        Zflag++;
      238 +                        break;
      239 +                case 'z':
      240 +                        zflag++;
      241 +                        break;
 235  242                  case 'A':
 236  243                          change_key(USERATTR_AUTHS_KW, optarg);
 237  244                          flag++;
 238  245                          break;
 239  246                  case 'P':
 240  247                          change_key(USERATTR_PROFILES_KW, optarg);
 241  248                          flag++;
 242  249                          break;
 243  250                  case 'R':
 244  251                          change_key(USERATTR_ROLES_KW, optarg);
↓ open down ↓ 5 lines elided ↑ open up ↑
 250  257                          break;
 251  258                  default:
 252  259                  case '?':
 253  260                          if (is_role(usertype))
 254  261                                  errmsg(M_MRUSAGE);
 255  262                          else
 256  263                                  errmsg(M_MUSAGE);
 257  264                          exit(EX_SYNTAX);
 258  265                  }
 259  266  
      267 +        if (((!mflag) && (zflag || Zflag)) || (zflag && Zflag) ||
      268 +            (mflag > 1 && (zflag || Zflag))) {
      269 +                if (is_role(usertype))
      270 +                        errmsg(M_ARUSAGE);
      271 +                else
      272 +                        errmsg(M_AUSAGE);
      273 +                exit(EX_SYNTAX);
      274 +        }
      275 +
      276 +
 260  277          if (optind != argc - 1 || flag == 0) {
 261  278                  if (is_role(usertype))
 262  279                          errmsg(M_MRUSAGE);
 263  280                  else
 264  281                          errmsg(M_MUSAGE);
 265  282                  exit(EX_SYNTAX);
 266  283          }
 267  284  
 268  285          if ((!uidstr && oflag) || (mflag && !dir)) {
 269  286                  if (is_role(usertype))
↓ open down ↓ 213 lines elided ↑ open up ↑
 483  500  
 484  501          if (mflag) {
 485  502                  if (stat(dir, &statbuf) == 0) {
 486  503                          /* Home directory exists */
 487  504                          if (check_perm(statbuf, pstruct->pw_uid,
 488  505                              pstruct->pw_gid, S_IWOTH|S_IXOTH) != 0) {
 489  506                                  errmsg(M_NO_PERM, logname, dir);
 490  507                                  exit(EX_NO_PERM);
 491  508                          }
 492  509  
 493      -                } else ret = create_home(dir, NULL, uid, gid);
      510 +                } else {
      511 +                        zfs_flags = get_default_zfs_flags();
      512 +                        if (zflag || mflag > 1)
      513 +                                zfs_flags |= CHANGE_ZFS_FS;
      514 +                        else if (Zflag)
      515 +                                zfs_flags &= ~CHANGE_ZFS_FS;
      516 +                        ret = create_home(dir, NULL, uid, gid, zfs_flags);
      517 +                }
 494  518  
 495  519                  if (ret == EX_SUCCESS)
 496      -                        ret = move_dir(pstruct->pw_dir, dir, logname);
      520 +                        ret = move_dir(pstruct->pw_dir, dir,
      521 +                            logname, zfs_flags);
 497  522  
 498  523                  if (ret != EX_SUCCESS)
 499  524                          exit(ret);
 500  525          }
 501  526  
 502  527          if (shell) {
 503  528                  if (REL_PATH(shell)) {
 504  529                          errmsg(M_RELPATH, shell);
 505  530                          exit(EX_BADARG);
 506  531                  }
↓ open down ↓ 180 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX