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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/oamuser/user/userdel.c
          +++ new/usr/src/cmd/oamuser/user/userdel.c
↓ open down ↓ 38 lines elided ↑ open up ↑
  39   39  #include <sys/stat.h>
  40   40  #include <userdefs.h>
  41   41  #include <stdlib.h>
  42   42  #include <errno.h>
  43   43  #include <unistd.h>
  44   44  #include <strings.h>
  45   45  #include "users.h"
  46   46  #include "messages.h"
  47   47  #include "funcs.h"
  48   48  
  49      -/*******************************************************************************
  50      - *  userdel [-r] login
       49 +/*
       50 + *  userdel [-r [-z|Z]] login
  51   51   *
  52   52   *      This command deletes user logins.  Arguments are:
  53   53   *
  54   54   *      -r - when given, this option removes home directory & its contents
  55   55   *
  56   56   *      login - a string of printable chars except colon (:)
  57      - ******************************************************************************/
       57 + */
  58   58  
  59      -extern int check_perm(), isbusy();
       59 +extern int check_perm(), isbusy(), get_default_zfs_flags();
  60   60  extern int rm_files(), call_passmgmt(), edit_group();
  61   61  
  62   62  static char *logname;                   /* login name to delete */
  63   63  static char *nargv[20];         /* arguments for execvp of passmgmt */
  64   64  
  65   65  char *cmdname;
  66   66  
  67   67  int
  68   68  main(int argc, char **argv)
  69   69  {
  70      -        int ch, ret = 0, rflag = 0, argindex, tries;
       70 +        int ch, ret = 0, rflag = 0, zflag = 0, Zflag = 0;
       71 +        int zfs_flags = 0, argindex, tries;
  71   72          struct passwd *pstruct;
  72   73          struct stat statbuf;
  73   74  #ifndef att
  74   75          FILE *pwf;              /* fille ptr for opened passwd file */
  75   76  #endif
  76   77          char *usertype = NULL;
  77   78          int rc;
  78   79  
  79   80          cmdname = argv[0];
  80   81  
  81      -        if( geteuid() != 0 ) {
  82      -                errmsg( M_PERM_DENIED );
  83      -                exit( EX_NO_PERM );
       82 +        if (geteuid() != 0) {
       83 +                errmsg(M_PERM_DENIED);
       84 +                exit(EX_NO_PERM);
  84   85          }
  85   86  
  86   87          opterr = 0;                     /* no print errors from getopt */
  87   88          usertype = getusertype(argv[0]);
  88      -        
  89      -        while( (ch = getopt(argc, argv, "r")) != EOF ) {
  90      -                switch(ch) {
       89 +
       90 +        while ((ch = getopt(argc, argv, "rzZ")) != EOF) {
       91 +                switch (ch) {
  91   92                          case 'r':
  92   93                                  rflag++;
  93   94                                  break;
       95 +                        case 'Z':
       96 +                                Zflag++;
       97 +                                break;
       98 +                        case 'z':
       99 +                                zflag++;
      100 +                                break;
  94  101                          case '?':
  95  102                                  if (is_role(usertype))
  96      -                                        errmsg( M_DRUSAGE );
      103 +                                        errmsg(M_DRUSAGE);
  97  104                                  else
  98      -                                        errmsg( M_DUSAGE );
  99      -                                exit( EX_SYNTAX );
      105 +                                        errmsg(M_DUSAGE);
      106 +                                exit(EX_SYNTAX);
 100  107                  }
 101  108          }
 102  109  
 103      -        if( optind != argc - 1 ) {
      110 +        if (optind != argc - 1) {
 104  111                  if (is_role(usertype))
 105      -                        errmsg( M_DRUSAGE );
      112 +                        errmsg(M_DRUSAGE);
 106  113                  else
 107      -                        errmsg( M_DUSAGE );
 108      -                exit( EX_SYNTAX );
      114 +                        errmsg(M_DUSAGE);
      115 +                exit(EX_SYNTAX);
      116 +        }
      117 +
      118 +        if (((!rflag) && (Zflag || zflag)) || (Zflag && zflag)) {
      119 +                if (is_role(usertype))
      120 +                        errmsg(M_DRUSAGE);
      121 +                else
      122 +                        errmsg(M_DUSAGE);
      123 +                exit(EX_SYNTAX);
 109  124          }
 110  125  
 111  126          logname = argv[optind];
 112  127  
 113  128  #ifdef att
 114  129          pstruct = getpwnam(logname);
 115  130  #else
 116  131          /*
 117  132           * Do this with fgetpwent to make sure we are only looking on local
 118  133           * system (since passmgmt only works on local system).
 119  134           */
 120  135          if ((pwf = fopen("/etc/passwd", "r")) == NULL) {
 121      -                errmsg( M_OOPS, "open", "/etc/passwd");
      136 +                errmsg(M_OOPS, "open", "/etc/passwd");
 122  137                  exit(EX_FAILURE);
 123  138          }
 124  139          while ((pstruct = fgetpwent(pwf)) != NULL)
 125  140                  if (strcmp(pstruct->pw_name, logname) == 0)
 126  141                          break;
 127  142  
 128  143          fclose(pwf);
 129  144  #endif
 130  145  
 131  146          if (pstruct == NULL) {
 132      -                errmsg( M_EXIST, logname );
 133      -                exit( EX_NAME_NOT_EXIST );
      147 +                errmsg(M_EXIST, logname);
      148 +                exit(EX_NAME_NOT_EXIST);
 134  149          }
 135  150  
 136      -        if( isbusy(logname) ) {
 137      -                errmsg( M_BUSY, logname, "remove" );
 138      -                exit( EX_BUSY );
      151 +        if (isbusy(logname)) {
      152 +                errmsg(M_BUSY, logname, "remove");
      153 +                exit(EX_BUSY);
 139  154          }
 140  155  
 141  156          /* that's it for validations - now do the work */
 142  157          /* set up arguments to  passmgmt in nargv array */
 143  158          nargv[0] = PASSMGMT;
 144  159          nargv[1] = "-d";        /* delete */
 145  160          argindex = 2;           /* next argument */
 146  161  
 147  162          /* finally - login name */
 148  163          nargv[argindex++] = logname;
 149  164  
 150  165          /* set the last to null */
 151  166          nargv[argindex++] = NULL;
 152  167  
 153  168          /* remove home directory */
 154      -        if( rflag ) {
      169 +        if (rflag) {
 155  170                  /* Check Permissions */
 156      -                if( stat( pstruct->pw_dir, &statbuf ) ) {
 157      -                        errmsg(M_OOPS, "find status about home directory", 
      171 +                if (stat(pstruct->pw_dir, &statbuf)) {
      172 +                        errmsg(M_OOPS, "find status about home directory",
 158  173                              strerror(errno));
 159      -                        exit( EX_HOMEDIR );
      174 +                        exit(EX_HOMEDIR);
 160  175                  }
 161      -                        
 162      -                if( check_perm( statbuf, pstruct->pw_uid, pstruct->pw_gid,
 163      -                    S_IWOTH|S_IXOTH ) != 0 ) {
 164      -                        errmsg( M_NO_PERM, logname, pstruct->pw_dir );
 165      -                        exit( EX_HOMEDIR );
      176 +
      177 +                if (check_perm(statbuf, pstruct->pw_uid, pstruct->pw_gid,
      178 +                    S_IWOTH|S_IXOTH) != 0) {
      179 +                        errmsg(M_NO_PERM, logname, pstruct->pw_dir);
      180 +                        exit(EX_HOMEDIR);
 166  181                  }
      182 +                zfs_flags = get_default_zfs_flags();
      183 +                if (zflag)
      184 +                        zfs_flags |= CHANGE_ZFS_FS;
      185 +                else if (Zflag)
      186 +                        zfs_flags &= ~CHANGE_ZFS_FS;
 167  187  
 168      -                if( rm_files(pstruct->pw_dir, logname) != EX_SUCCESS ) 
 169      -                        exit( EX_HOMEDIR );
      188 +                if (rm_files(pstruct->pw_dir, logname, zfs_flags) != EX_SUCCESS)
      189 +                        exit(EX_HOMEDIR);
 170  190          }
 171  191  
 172  192          /* now call passmgmt */
 173  193          ret = PEX_FAILED;
 174      -        for( tries = 3; ret != PEX_SUCCESS && tries--; ) {
 175      -                switch( ret = call_passmgmt( nargv ) ) {
      194 +        for (tries = 3; ret != PEX_SUCCESS && tries--; ) {
      195 +                switch (ret = call_passmgmt(nargv)) {
 176  196                  case PEX_SUCCESS:
 177      -                        ret = edit_group( logname, (char *)0, (int **)0, 1 );
 178      -                        if( ret != EX_SUCCESS )
 179      -                                errmsg( M_UPDATE, "deleted" );
      197 +                        ret = edit_group(logname, (char *)0, (int **)0, 1);
      198 +                        if (ret != EX_SUCCESS)
      199 +                                errmsg(M_UPDATE, "deleted");
 180  200                          break;
 181  201  
 182  202                  case PEX_BUSY:
 183  203                          break;
 184  204  
 185  205                  case PEX_HOSED_FILES:
 186      -                        errmsg( M_HOSED_FILES );
 187      -                        exit( EX_INCONSISTENT );
      206 +                        errmsg(M_HOSED_FILES);
      207 +                        exit(EX_INCONSISTENT);
 188  208                          break;
 189  209  
 190  210                  case PEX_SYNTAX:
 191  211                  case PEX_BADARG:
 192  212                          /* should NEVER occur that passmgmt usage is wrong */
 193  213                          if (is_role(usertype))
 194      -                                errmsg( M_DRUSAGE );
      214 +                                errmsg(M_DRUSAGE);
 195  215                          else
 196      -                                errmsg( M_DUSAGE );
 197      -                        exit( EX_SYNTAX );
      216 +                                errmsg(M_DUSAGE);
      217 +                        exit(EX_SYNTAX);
 198  218                          break;
 199  219  
 200  220                  case PEX_BADUID:
 201      -                        /* uid is used - shouldn't happen but print message anyway */
 202      -                        errmsg( M_UID_USED, pstruct->pw_uid );
 203      -                        exit( EX_ID_EXISTS );
      221 +                /*
      222 +                 * uid is used - shouldn't happen but print message anyway
      223 +                 */
      224 +                        errmsg(M_UID_USED, pstruct->pw_uid);
      225 +                        exit(EX_ID_EXISTS);
 204  226                          break;
 205  227  
 206  228                  case PEX_BADNAME:
 207  229                          /* invalid loname */
 208      -                        errmsg( M_USED, logname);
 209      -                        exit( EX_NAME_EXISTS );
      230 +                        errmsg(M_USED, logname);
      231 +                        exit(EX_NAME_EXISTS);
 210  232                          break;
 211  233  
 212  234                  default:
 213      -                        errmsg( M_UPDATE, "deleted" );
 214      -                        exit( ret );
      235 +                        errmsg(M_UPDATE, "deleted");
      236 +                        exit(ret);
 215  237                          break;
 216  238                  }
 217  239          }
 218      -        if( tries == 0 ) 
 219      -                errmsg( M_UPDATE, "deleted" );
      240 +        if (tries == 0)
      241 +                errmsg(M_UPDATE, "deleted");
 220  242  
 221  243  /*
 222  244   * Now, remove this user from all project entries
 223  245   */
 224  246  
 225  247          rc = edit_project(logname, (char *)0, (projid_t **)0, 1);
 226  248          if (rc != EX_SUCCESS) {
 227  249                  errmsg(M_UPDATE, "modified");
 228  250                  exit(rc);
 229  251          }
 230      -        
 231      -        exit( ret );
      252 +
      253 +        exit(ret);
 232  254          /*NOTREACHED*/
 233  255  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX