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


  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 
  32 #pragma ident   "%Z%%M% %I%     %E% SMI"
  33 
  34 #include <sys/types.h>
  35 #include <stdio.h>
  36 #include <userdefs.h>
  37 #include "messages.h"
  38 #include <unistd.h>
  39 #include <sys/stat.h>
  40 #include <utime.h>
  41 
  42 #define SBUFSZ  256
  43 
  44 extern int access(), rm_files();
  45 
  46 static char cmdbuf[SBUFSZ];     /* buffer for system call */
  47 
  48 /*
  49  *      Move directory contents from one place to another
  50  */
  51 int
  52 move_dir(char *from, char *to, char *login)
  53                 /* directory to move files from */
  54                 /* dirctory to move files to */
  55                 /* login id of owner */

  56 {
  57         size_t len = 0;
  58         int rc = EX_SUCCESS;
  59         struct stat statbuf;
  60         struct utimbuf times;
  61         /*
  62          * ***** THIS IS WHERE SUFFICIENT SPACE CHECK GOES
  63          */
  64 
  65         if (access(from, F_OK) == 0) {  /* home dir exists */
  66                 /* move all files */
  67                 (void) sprintf(cmdbuf,
  68                         "cd %s && find . -print | cpio -m -pd %s",
  69                         from, to);
  70 
  71                 if (system(cmdbuf) != 0) {
  72                         errmsg(M_NOSPACE, from, to);
  73                         return (EX_NOSPACE);
  74                 }
  75 
  76                 /*
  77                  * Check that to dir is not a subdirectory of from
  78                  */
  79                 len = strlen(from);
  80                 if (strncmp(from, to, len) == 0 &&
  81                     strncmp(to+len, "/", 1) == 0) {
  82                         errmsg(M_RMFILES);
  83                         return (EX_HOMEDIR);
  84                 }
  85                 /* Retain the original permission and modification time */
  86                 if (stat(from, &statbuf) == 0) {
  87                         chmod(to, statbuf.st_mode);
  88                         times.actime = statbuf.st_atime;
  89                         times.modtime = statbuf.st_mtime;
  90                         (void) utime(to, &times);
  91 
  92                 }
  93 
  94                 /* Remove the files in the old place */
  95                 rc = rm_files(from, login);
  96 
  97         }
  98 
  99         return (rc);
 100 }


  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 
  23 /*
  24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 


  32 #include <sys/types.h>
  33 #include <stdio.h>
  34 #include <userdefs.h>
  35 #include "messages.h"
  36 #include <unistd.h>
  37 #include <sys/stat.h>
  38 #include <utime.h>
  39 
  40 #define SBUFSZ  256
  41 
  42 extern int access(), rm_files();
  43 
  44 static char cmdbuf[SBUFSZ];     /* buffer for system call */
  45 
  46 /*
  47  *      Move directory contents from one place to another
  48  */
  49 int
  50 move_dir(char *from, char *to, char *login, int flags)
  51                 /* directory to move files from */
  52                 /* dirctory to move files to */
  53                 /* login id of owner */
  54                 /* miscellaneous flags */
  55 {
  56         size_t len = 0;
  57         int rc = EX_SUCCESS;
  58         struct stat statbuf;
  59         struct utimbuf times;
  60         /*
  61          * ***** THIS IS WHERE SUFFICIENT SPACE CHECK GOES
  62          */
  63 
  64         if (access(from, F_OK) == 0) {  /* home dir exists */
  65                 /* move all files */
  66                 (void) sprintf(cmdbuf,
  67                         "cd %s && find . -print | cpio -m -pd %s",
  68                         from, to);
  69 
  70                 if (system(cmdbuf) != 0) {
  71                         errmsg(M_NOSPACE, from, to);
  72                         return (EX_NOSPACE);
  73                 }
  74 
  75                 /*
  76                  * Check that to dir is not a subdirectory of from
  77                  */
  78                 len = strlen(from);
  79                 if (strncmp(from, to, len) == 0 &&
  80                     strncmp(to+len, "/", 1) == 0) {
  81                         errmsg(M_RMFILES);
  82                         return (EX_HOMEDIR);
  83                 }
  84                 /* Retain the original permission and modification time */
  85                 if (stat(from, &statbuf) == 0) {
  86                         chmod(to, statbuf.st_mode);
  87                         times.actime = statbuf.st_atime;
  88                         times.modtime = statbuf.st_mtime;
  89                         (void) utime(to, &times);
  90 
  91                 }
  92 
  93                 /* Remove the files in the old place */
  94                 rc = rm_files(from, login, flags);
  95 
  96         }
  97 
  98         return (rc);
  99 }