10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
22*108Sbasabi
23*108Sbasabi /*
24*108Sbasabi * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
25*108Sbasabi * Use is subject to license terms.
26*108Sbasabi */
27*108Sbasabi
280Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
290Sstevel@tonic-gate /* All Rights Reserved */
300Sstevel@tonic-gate
310Sstevel@tonic-gate
320Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
330Sstevel@tonic-gate
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <stdio.h>
360Sstevel@tonic-gate #include <userdefs.h>
370Sstevel@tonic-gate #include "messages.h"
380Sstevel@tonic-gate #include <unistd.h>
390Sstevel@tonic-gate #include <sys/stat.h>
400Sstevel@tonic-gate #include <utime.h>
410Sstevel@tonic-gate
420Sstevel@tonic-gate #define SBUFSZ 256
430Sstevel@tonic-gate
440Sstevel@tonic-gate extern int access(), rm_files();
450Sstevel@tonic-gate
460Sstevel@tonic-gate static char cmdbuf[SBUFSZ]; /* buffer for system call */
470Sstevel@tonic-gate
480Sstevel@tonic-gate /*
490Sstevel@tonic-gate * Move directory contents from one place to another
500Sstevel@tonic-gate */
510Sstevel@tonic-gate int
move_dir(char * from,char * to,char * login)52*108Sbasabi move_dir(char *from, char *to, char *login)
53*108Sbasabi /* directory to move files from */
54*108Sbasabi /* dirctory to move files to */
55*108Sbasabi /* login id of owner */
560Sstevel@tonic-gate {
570Sstevel@tonic-gate size_t len = 0;
58*108Sbasabi int rc = EX_SUCCESS;
590Sstevel@tonic-gate struct stat statbuf;
600Sstevel@tonic-gate struct utimbuf times;
610Sstevel@tonic-gate /*
620Sstevel@tonic-gate * ***** THIS IS WHERE SUFFICIENT SPACE CHECK GOES
630Sstevel@tonic-gate */
640Sstevel@tonic-gate
650Sstevel@tonic-gate if (access(from, F_OK) == 0) { /* home dir exists */
660Sstevel@tonic-gate /* move all files */
670Sstevel@tonic-gate (void) sprintf(cmdbuf,
680Sstevel@tonic-gate "cd %s && find . -print | cpio -m -pd %s",
690Sstevel@tonic-gate from, to);
700Sstevel@tonic-gate
710Sstevel@tonic-gate if (system(cmdbuf) != 0) {
720Sstevel@tonic-gate errmsg(M_NOSPACE, from, to);
730Sstevel@tonic-gate return (EX_NOSPACE);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * Check that to dir is not a subdirectory of from
780Sstevel@tonic-gate */
790Sstevel@tonic-gate len = strlen(from);
800Sstevel@tonic-gate if (strncmp(from, to, len) == 0 &&
810Sstevel@tonic-gate strncmp(to+len, "/", 1) == 0) {
820Sstevel@tonic-gate errmsg(M_RMFILES);
830Sstevel@tonic-gate return (EX_HOMEDIR);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate /* Retain the original permission and modification time */
860Sstevel@tonic-gate if (stat(from, &statbuf) == 0) {
870Sstevel@tonic-gate chmod(to, statbuf.st_mode);
880Sstevel@tonic-gate times.actime = statbuf.st_atime;
890Sstevel@tonic-gate times.modtime = statbuf.st_mtime;
900Sstevel@tonic-gate (void) utime(to, ×);
910Sstevel@tonic-gate
920Sstevel@tonic-gate }
930Sstevel@tonic-gate
940Sstevel@tonic-gate /* Remove the files in the old place */
950Sstevel@tonic-gate rc = rm_files(from, login);
960Sstevel@tonic-gate
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate return (rc);
1000Sstevel@tonic-gate }
101