/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <errno.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <zone.h>
#include "setupfiles.h"
int flags);
int flags);
/*
* __setupfiles - Process copy and link files directions in min $HOME.
*
* Entry pwd = user's password file entry.
* min_sl = user's minimum SL.
* flags = DBUG, if print debug messages.
* DIAG, if print diagnostics (perrors).
* IGNE, continue rather than abort on failures.
* REPC, if replace existing file.
* REPL, if replace existing symbolic link.
* process is running as user at correct label.
*
* Exit None.
*
* Returns 0, if success.
* errno, if failure.
*
* Uses COPY, CP, LINK, MAXPATHLEN.
*
* Calls blequal, copyfile, feof, fgets, fopen,
* mkdirs, getzoneid, getzonelabelbyid, linkfile, strcat, strcpy,
* strlen.
*
* This program assumes the /zone is the autofs mountpoint for
* cross-zone mounts.
*
* It also assumes that the user's home directory path is the
* the same in each zone, relative to the zone's root.
*
* At this point, the cross-zone automounter only supports home
* directories starting with /home
*/
int
{
dperror("setupfiles can't get process label");
return (errno);
}
/* at min SL no files to setup */
return (0);
}
/* get current home real path */
/* Get zone id from min_sl */
dperror("setupfiles can't get zoneid for min sl");
return (errno);
}
/*
* Since the global zone home directories aren't public
* information, we don't support copy and link files there.
*/
if (min_zoneid == GLOBAL_ZONEID)
return (0);
/*
* Get zone root path from zone id
*
* directory is available, which is not true in labeled zones
*/
sizeof (zoneroot)) == -1) {
dperror("setupfiles can't get zone root path for min sl");
return (errno);
}
/* process copy files */
dperror("setupfiles copy path");
return (errno);
}
/* make any needed subdirectories */
return (errno);
else
continue;
}
/* copy the file */
return (errno);
else
continue;
}
} /* while (fgets( ... ) != NULL) */
} else {
dperror("setupfiles copy file open");
} /* process copy files */
/* process link files */
dperror("setupfiles link path");
return (errno);
}
/* make any needed subdirectories */
return (errno);
else
continue;
}
/* link the file */
return (errno);
else
continue;
}
} /* while (fgets ... ) != NULL) */
} else {
dperror("setupfiles link file open");
} /* process link files */
return (0);
} /* setupfiles() */
/*
* mkdirs - Make any needed subdirectories in target's path.
*
* Entry home = base directory.
* file = file to create with intermediate subdirectories.
* flags = from __setupfiles -- for dprintf and dperror.
*
* Exit Needed subdirectories made.
*
* Returns 0, if success.
* errno, if failure.
*
* Uses MAXPATHLEN.
*
* Calls mkdir, strcat, strcpy, strlen, strtok.
*/
static int
{
char *tok;
dperror("setupfiles mkdirs");
return (errno);
}
return (0);
}
dperror("setupfiles mkdir");
return (errno);
}
}
return (0);
} /* mkdirs() */
/*
* copyfile - Copy a file from the base home directory to the current.
*
* Entry min_home = from home directory.
* home = current (to) home directory.
* target = file to copy.
* flags = from __setupfiles.
* REPC, if replace existing file.
*
* Exit File copied.
*
* Returns 0, if success.
* errno, if failure.
*
* Uses CP, MAXPATHLEN.
*
* Calls access, execlp, exit, lstat, strcat, strcpy, strlen, unlink,
* vfork, waitpid.
*/
static int
{
/* prepare target */
sizeof (dest) - 1) {
dperror("setupfiles copy to home");
return (errno);
}
/* target exists */
/* unlink and replace */
dperror("setupfiles copy unlink");
dprintf("setupfiles copy unable to unlink %s\n",
dest);
return (errno);
}
} else {
/* target exists and is not to be replaced */
return (0);
}
/* error on target */
dperror("setupfiles copy");
return (errno);
}
/* prepare source */
sizeof (src) - 1) {
dperror("setupfiles copy from home");
return (errno);
}
/* can't access source */
dperror("setupfiles copy source access");
return (errno);
}
/* attempt the copy */
} else {
/* execute "cp -p min_home home" */
/* can't execute cp */
dperror("setupfiles copy exec");
dprintf("setupfiles copy couldn't exec \"%s -p\"\n",
CP);
exit(2);
}
}
return (0);
} /* copyfile() */
/*
* linkfile - Make a symlink from the the current directory to the base
* home directory.
*
* Entry min_home = from home directory.
* home = current (to) home directory.
* target = file to copy.
* flags = from __setupfiles.
* REPL, if replace existing symlink.
*
* Exit File symlinked.
*
* Returns 0, if success.
* errno, if failure.
*
* Uses MAXPATHLEN.
*
* Calls lstat, symlink, strcat, strcpy, strlen, unlink.
*/
static int
{
/* prepare target */
sizeof (dest) - 1) {
dperror("setupfiles link to home");
return (errno);
}
/* target exists */
/* unlink and replace */
dperror("setupfiles link unlink");
dprintf("setupfiles link unable to unlink %s\n",
dest);
return (errno);
}
} else {
/* target exists and is not to be replaced */
return (0);
}
/* error on target */
dperror("setupfiles link");
return (errno);
}
sizeof (src) - 1) {
dperror("setupfiles link from home");
return (errno);
}
/* attempt the copy */
dperror("setupfiles link symlink");
return (errno);
}
return (0);
} /* linkfile */