xref: /titanic_52/usr/src/cmd/svr4pkg/pkginstall/instvol.c (revision 6e1ae2a33c618c4c2b14aec7d2f21743ddea5837)
15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland  * CDDL HEADER START
35c51f124SMoriah Waterland  *
45c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland  *
85c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland  * See the License for the specific language governing permissions
115c51f124SMoriah Waterland  * and limitations under the License.
125c51f124SMoriah Waterland  *
135c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland  *
195c51f124SMoriah Waterland  * CDDL HEADER END
205c51f124SMoriah Waterland  */
215c51f124SMoriah Waterland 
225c51f124SMoriah Waterland /*
23*6e1ae2a3SGary Pennington  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
245c51f124SMoriah Waterland  */
255c51f124SMoriah Waterland 
265c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
275c51f124SMoriah Waterland /* All Rights Reserved */
285c51f124SMoriah Waterland 
295c51f124SMoriah Waterland 
305c51f124SMoriah Waterland #include <stdio.h>
315c51f124SMoriah Waterland #include <string.h>
325c51f124SMoriah Waterland #include <locale.h>
335c51f124SMoriah Waterland #include <libintl.h>
345c51f124SMoriah Waterland #include <dirent.h>
355c51f124SMoriah Waterland #include <pkgstrct.h>
365c51f124SMoriah Waterland #include <pkgdev.h>
375c51f124SMoriah Waterland #include <pkglocs.h>
385c51f124SMoriah Waterland #include <archives.h>
395c51f124SMoriah Waterland #include <errno.h>
405c51f124SMoriah Waterland #include <fcntl.h>
415c51f124SMoriah Waterland #include <sys/stat.h>
425c51f124SMoriah Waterland #include <sys/param.h>
435c51f124SMoriah Waterland #include <stdlib.h>
445c51f124SMoriah Waterland #include <unistd.h>
455c51f124SMoriah Waterland #include <assert.h>
465c51f124SMoriah Waterland #include <wait.h>
475c51f124SMoriah Waterland 
485c51f124SMoriah Waterland /*
495c51f124SMoriah Waterland  * libinstzones includes
505c51f124SMoriah Waterland  */
515c51f124SMoriah Waterland 
525c51f124SMoriah Waterland #include <instzones_api.h>
535c51f124SMoriah Waterland 
545c51f124SMoriah Waterland /*
555c51f124SMoriah Waterland  * consolidation pkg command library includes
565c51f124SMoriah Waterland  */
575c51f124SMoriah Waterland 
585c51f124SMoriah Waterland #include <pkglib.h>
595c51f124SMoriah Waterland #include <pkgweb.h>
605c51f124SMoriah Waterland 
615c51f124SMoriah Waterland /*
625c51f124SMoriah Waterland  * local pkg command library includes
635c51f124SMoriah Waterland  */
645c51f124SMoriah Waterland 
655c51f124SMoriah Waterland #include <install.h>
665c51f124SMoriah Waterland #include <libinst.h>
675c51f124SMoriah Waterland #include <libadm.h>
685c51f124SMoriah Waterland #include <dryrun.h>
695c51f124SMoriah Waterland #include <messages.h>
705c51f124SMoriah Waterland 
715c51f124SMoriah Waterland /*
725c51f124SMoriah Waterland  * pkginstall local includes
735c51f124SMoriah Waterland  */
745c51f124SMoriah Waterland 
755c51f124SMoriah Waterland #include "pkginstall.h"
765c51f124SMoriah Waterland 
775c51f124SMoriah Waterland extern int		pkgverbose;
785c51f124SMoriah Waterland extern fsblkcnt_t	pkgmap_blks; 		/* main.c */
795c51f124SMoriah Waterland 
805c51f124SMoriah Waterland extern struct pkgdev pkgdev;
815c51f124SMoriah Waterland 
825c51f124SMoriah Waterland extern char	tmpdir[];
835c51f124SMoriah Waterland extern char	pkgbin[];
845c51f124SMoriah Waterland extern char	instdir[];
855c51f124SMoriah Waterland extern char	saveSpoolInstallDir[];
865c51f124SMoriah Waterland extern char	*pkginst;
875c51f124SMoriah Waterland 
885c51f124SMoriah Waterland extern int	dbchg;
895c51f124SMoriah Waterland extern int	nosetuid;
905c51f124SMoriah Waterland extern int	nocnflct;
915c51f124SMoriah Waterland extern int	warnflag;
925c51f124SMoriah Waterland 
935c51f124SMoriah Waterland #define	DMRG_DONE	-1
945c51f124SMoriah Waterland 
955c51f124SMoriah Waterland #define	ck_efile(s, p)	\
965c51f124SMoriah Waterland 		((p->cinfo.modtime >= 0) && \
975c51f124SMoriah Waterland 		p->ainfo.local && \
985c51f124SMoriah Waterland 		cverify(0, &p->ftype, s, &p->cinfo, 1))
995c51f124SMoriah Waterland 
1005c51f124SMoriah Waterland static int	eocflag;
1015c51f124SMoriah Waterland 
1025c51f124SMoriah Waterland /*
1035c51f124SMoriah Waterland  * The variable below indicates that fix_attributes() will be inadequate
1045c51f124SMoriah Waterland  * because a replacement was permitted.
1055c51f124SMoriah Waterland  */
1065c51f124SMoriah Waterland static int	repl_permitted = 0;
1075c51f124SMoriah Waterland 
1085c51f124SMoriah Waterland static int	domerg(struct cfextra **extlist, int part, int nparts,
1095c51f124SMoriah Waterland 			int myclass, char **srcp, char **dstp,
110*6e1ae2a3SGary Pennington 			char **r_updated);
1115c51f124SMoriah Waterland static void	endofclass(struct cfextra **extlist, int myclass,
11262224350SCasper H.S. Dik 			int ckflag, PKGserver server, VFP_T **a_cfTmpVfp);
1135c51f124SMoriah Waterland static int	fix_attributes(struct cfextra **, int);
1145c51f124SMoriah Waterland static int	dir_is_populated(char *dirpath);
1155c51f124SMoriah Waterland static boolean_t absolutepath(char *path);
1165c51f124SMoriah Waterland static boolean_t parametricpath(char *path, char **relocpath);
1175c51f124SMoriah Waterland 
1185c51f124SMoriah Waterland /* Used to keep track of the entries in extlist that are regular files. */
1195c51f124SMoriah Waterland struct reg_files {
1205c51f124SMoriah Waterland 	struct reg_files *next;
1215c51f124SMoriah Waterland 	int val;
1225c51f124SMoriah Waterland };
1235c51f124SMoriah Waterland static struct reg_files *regfiles_head = NULL;
1245c51f124SMoriah Waterland 
1255c51f124SMoriah Waterland /*
1265c51f124SMoriah Waterland  * This is the function that actually installs one volume (usually that's
1275c51f124SMoriah Waterland  * all there is). Upon entry, the extlist is entirely correct:
1285c51f124SMoriah Waterland  *
1295c51f124SMoriah Waterland  *	1. It contains only those files which are to be installed
1305c51f124SMoriah Waterland  *	   from all volumes.
1315c51f124SMoriah Waterland  *	2. The mode bits in the ainfo structure for each file are set
1325c51f124SMoriah Waterland  *	   correctly in accordance with administrative defaults.
1335c51f124SMoriah Waterland  *	3. mstat.setuid/setgid reflect what the status *was* before
1345c51f124SMoriah Waterland  *	   pkgdbmerg() processed compliance.
1355c51f124SMoriah Waterland  */
1365c51f124SMoriah Waterland void
1375c51f124SMoriah Waterland instvol(struct cfextra **extlist, char *srcinst, int part,
13862224350SCasper H.S. Dik 	int nparts, PKGserver pkgserver, VFP_T **a_cfTmpVfp,
139*6e1ae2a3SGary Pennington 	char **r_updated, char *a_zoneName)
1405c51f124SMoriah Waterland {
1415c51f124SMoriah Waterland 	FILE		*listfp;
1425c51f124SMoriah Waterland 	char		*updated = (char *)NULL;
1435c51f124SMoriah Waterland 	char		*relocpath = (char *)NULL;
1445c51f124SMoriah Waterland 	char		*dstp;
1455c51f124SMoriah Waterland 	char		*listfile;
1465c51f124SMoriah Waterland 	char		*srcp;
1475c51f124SMoriah Waterland 	char		*pspool_loc;
1485c51f124SMoriah Waterland 	char		scrpt_dst[PATH_MAX];
1495c51f124SMoriah Waterland 	int		count;
1505c51f124SMoriah Waterland 	int		entryidx;	/* array of current package objects */
1515c51f124SMoriah Waterland 	int		n;
1525c51f124SMoriah Waterland 	int		nc = 0;
1535c51f124SMoriah Waterland 	int		pass;		/* pass count through the for loop. */
1545c51f124SMoriah Waterland 	int		tcount;
1555c51f124SMoriah Waterland 	struct cfent	*ept;
1565c51f124SMoriah Waterland 	struct cfextra	*ext;
1575c51f124SMoriah Waterland 	struct mergstat	*mstat;
1585c51f124SMoriah Waterland 	struct reg_files *rfp = NULL;
1595c51f124SMoriah Waterland 
1605c51f124SMoriah Waterland 	/*
161*6e1ae2a3SGary Pennington 	 * r_updated is an optional parameter that can be passed in
162*6e1ae2a3SGary Pennington 	 * by the caller if the caller wants to know if any objects are
163*6e1ae2a3SGary Pennington 	 * updated. Do not initialize r_updated; the call to instvol
164*6e1ae2a3SGary Pennington 	 * could be cumulative and any previous update indication must not
165*6e1ae2a3SGary Pennington 	 * be disturbed - this flag is only set, it must never be reset.
166*6e1ae2a3SGary Pennington 	 * This flag is a "char *" pointer so that the object that was
167*6e1ae2a3SGary Pennington 	 * updated can be displayed in debugging output.
1685c51f124SMoriah Waterland 	 */
1695c51f124SMoriah Waterland 
1705c51f124SMoriah Waterland 	if (part == 1) {
1715c51f124SMoriah Waterland 		pkgvolume(&pkgdev, srcinst, part, nparts);
1725c51f124SMoriah Waterland 	}
1735c51f124SMoriah Waterland 
1745c51f124SMoriah Waterland 	tcount = 0;
1755c51f124SMoriah Waterland 	nc = cl_getn();
1765c51f124SMoriah Waterland 
1775c51f124SMoriah Waterland 	/*
1785c51f124SMoriah Waterland 	 * For each class in this volume, install those files.
1795c51f124SMoriah Waterland 	 *
1805c51f124SMoriah Waterland 	 * NOTE : This loop index may be decremented by code below forcing a
1815c51f124SMoriah Waterland 	 * second trip through for the same class. This happens only when a
1825c51f124SMoriah Waterland 	 * class is split between an archive and the tree. Examples would be
1835c51f124SMoriah Waterland 	 * old WOS packages and the occasional class containing dynamic
1845c51f124SMoriah Waterland 	 * libraries which require special treatment.
1855c51f124SMoriah Waterland 	 */
1865c51f124SMoriah Waterland 
1875c51f124SMoriah Waterland 	if (is_depend_pkginfo_DB() == B_FALSE) {
1885c51f124SMoriah Waterland 	    int		classidx;	/* the current class */
1895c51f124SMoriah Waterland 
1905c51f124SMoriah Waterland 	    for (classidx = 0; classidx < nc; classidx++) {
1915c51f124SMoriah Waterland 		int pass_relative = 0;
1925c51f124SMoriah Waterland 		int rel_init = 0;
1935c51f124SMoriah Waterland 
1945c51f124SMoriah Waterland 		eocflag = count = pass = 0;
1955c51f124SMoriah Waterland 		listfp = (FILE *)0;
1965c51f124SMoriah Waterland 		listfile = NULL;
1975c51f124SMoriah Waterland 
1985c51f124SMoriah Waterland 		/* Now what do we pass to the class action script */
1995c51f124SMoriah Waterland 
2005c51f124SMoriah Waterland 		if (cl_pthrel(classidx) == REL_2_CAS) {
2015c51f124SMoriah Waterland 			pass_relative = 1;
2025c51f124SMoriah Waterland 		}
2035c51f124SMoriah Waterland 
2045c51f124SMoriah Waterland 		for (;;) {
2055c51f124SMoriah Waterland 			if (!tcount++) {
2065c51f124SMoriah Waterland 				/* first file to install */
2075c51f124SMoriah Waterland 				if (a_zoneName == (char *)NULL) {
2085c51f124SMoriah Waterland 					echo(MSG_INS_N_N, part, nparts);
2095c51f124SMoriah Waterland 				} else {
2105c51f124SMoriah Waterland 					echo(MSG_INS_N_N_LZ, part, nparts,
2115c51f124SMoriah Waterland 						a_zoneName);
2125c51f124SMoriah Waterland 				}
2135c51f124SMoriah Waterland 			}
2145c51f124SMoriah Waterland 
2155c51f124SMoriah Waterland 			/*
2165c51f124SMoriah Waterland 			 * If there's an install class action script and no
2175c51f124SMoriah Waterland 			 * list file has been created yet, create that file
2185c51f124SMoriah Waterland 			 * and provide the pointer in listfp.
2195c51f124SMoriah Waterland 			 */
2205c51f124SMoriah Waterland 			if (cl_iscript(classidx) && !listfp) {
2215c51f124SMoriah Waterland 				/* create list file */
2225c51f124SMoriah Waterland 				putparam("TMPDIR", tmpdir);
2235c51f124SMoriah Waterland 				listfile = tempnam(tmpdir, "list");
2245c51f124SMoriah Waterland 				if ((listfp = fopen(listfile, "w")) == NULL) {
2255c51f124SMoriah Waterland 					progerr(ERR_WTMPFILE, listfile);
2265c51f124SMoriah Waterland 					quit(99);
2275c51f124SMoriah Waterland 				}
2285c51f124SMoriah Waterland 			}
2295c51f124SMoriah Waterland 
2305c51f124SMoriah Waterland 			/*
2315c51f124SMoriah Waterland 			 * The following function goes through the package
2325c51f124SMoriah Waterland 			 * object list returning the array index of the next
2335c51f124SMoriah Waterland 			 * regular file. If it encounters a directory,
2345c51f124SMoriah Waterland 			 * symlink, named pipe or device, it just creates it.
2355c51f124SMoriah Waterland 			 */
2365c51f124SMoriah Waterland 
2375c51f124SMoriah Waterland 			entryidx = domerg(extlist, (pass++ ? 0 : part), nparts,
238*6e1ae2a3SGary Pennington 				classidx, &srcp, &dstp, &updated);
2395c51f124SMoriah Waterland 
2405c51f124SMoriah Waterland 			/* Evaluate the return code */
2415c51f124SMoriah Waterland 			if (entryidx == DMRG_DONE) {
2425c51f124SMoriah Waterland 				/*
2435c51f124SMoriah Waterland 				 * Set ept to the first entry in extlist
2445c51f124SMoriah Waterland 				 * which is guaranteed to exist so
2455c51f124SMoriah Waterland 				 * later checks against ept->ftype are
2465c51f124SMoriah Waterland 				 * not compared to NULL.
2475c51f124SMoriah Waterland 				 */
2485c51f124SMoriah Waterland 				ext = extlist[0];
2495c51f124SMoriah Waterland 				ept = &(ext->cf_ent);
2505c51f124SMoriah Waterland 				break; /* no more entries to process */
2515c51f124SMoriah Waterland 			}
2525c51f124SMoriah Waterland 
2535c51f124SMoriah Waterland 			ext = extlist[entryidx];
2545c51f124SMoriah Waterland 			ept = &(ext->cf_ent);
2555c51f124SMoriah Waterland 			mstat = &(ext->mstat);
2565c51f124SMoriah Waterland 
2575c51f124SMoriah Waterland 			/*
2585c51f124SMoriah Waterland 			 * If not installing from a partially spooled package
2595c51f124SMoriah Waterland 			 * (the "save/pspool" area), and the file contents can
2605c51f124SMoriah Waterland 			 * be changed (type is 'e' or 'v'), and the class is not
2615c51f124SMoriah Waterland 			 * "none": copy the file from the package (in pristine
2625c51f124SMoriah Waterland 			 * state with no actions performed) into the appropriate
2635c51f124SMoriah Waterland 			 * location in the packages destination "save/pspool"
2645c51f124SMoriah Waterland 			 * area.
2655c51f124SMoriah Waterland 			 */
2665c51f124SMoriah Waterland 
2675c51f124SMoriah Waterland 			if ((!is_partial_inst()) &&
2685c51f124SMoriah Waterland 				((ept->ftype == 'e') || (ept->ftype == 'v')) &&
2695c51f124SMoriah Waterland 				(strcmp(ept->pkg_class, "none") != 0)) {
2705c51f124SMoriah Waterland 
2715c51f124SMoriah Waterland 				if (absolutepath(ext->map_path) == B_TRUE &&
2725c51f124SMoriah Waterland 					parametricpath(ext->cf_ent.ainfo.local,
2735c51f124SMoriah Waterland 						&relocpath) == B_FALSE) {
2745c51f124SMoriah Waterland 					pspool_loc = ROOT;
2755c51f124SMoriah Waterland 				} else {
2765c51f124SMoriah Waterland 					pspool_loc = RELOC;
2775c51f124SMoriah Waterland 				}
2785c51f124SMoriah Waterland 
2795c51f124SMoriah Waterland 				n = snprintf(scrpt_dst, PATH_MAX, "%s/%s/%s",
2805c51f124SMoriah Waterland 					saveSpoolInstallDir, pspool_loc,
2815c51f124SMoriah Waterland 					relocpath ? relocpath : ext->map_path);
2825c51f124SMoriah Waterland 
2835c51f124SMoriah Waterland 				if (n >= PATH_MAX) {
2845c51f124SMoriah Waterland 					progerr(ERR_CREATE_PATH_2,
2855c51f124SMoriah Waterland 						saveSpoolInstallDir,
2865c51f124SMoriah Waterland 						ext->map_path);
2875c51f124SMoriah Waterland 					quit(99);
2885c51f124SMoriah Waterland 				}
2895c51f124SMoriah Waterland 
2905c51f124SMoriah Waterland 				/* copy, preserve source file mode */
2915c51f124SMoriah Waterland 
2925c51f124SMoriah Waterland 				if (cppath(MODE_SRC, srcp, scrpt_dst, 0644)) {
2935c51f124SMoriah Waterland 					warnflag++;
2945c51f124SMoriah Waterland 				}
2955c51f124SMoriah Waterland 			}
2965c51f124SMoriah Waterland 
2975c51f124SMoriah Waterland 			/*
2985c51f124SMoriah Waterland 			 * If this isn't writeable anyway, it's not going
2995c51f124SMoriah Waterland 			 * into the list file. Only count it if it's going
3005c51f124SMoriah Waterland 			 * into the list file.
3015c51f124SMoriah Waterland 			 */
3025c51f124SMoriah Waterland 			if (is_fs_writeable(ext->cf_ent.path,
3035c51f124SMoriah Waterland 				&(ext->fsys_value)))
3045c51f124SMoriah Waterland 				count++;
3055c51f124SMoriah Waterland 
3065c51f124SMoriah Waterland 			pkgvolume(&pkgdev, srcinst, part, nparts);
3075c51f124SMoriah Waterland 
3085c51f124SMoriah Waterland 			/*
3095c51f124SMoriah Waterland 			 * If source verification is OK for this class, make
3105c51f124SMoriah Waterland 			 * sure the source we're passing to the class action
3115c51f124SMoriah Waterland 			 * script is useable.
3125c51f124SMoriah Waterland 			 */
3135c51f124SMoriah Waterland 			if (cl_svfy(classidx) != NOVERIFY) {
3145c51f124SMoriah Waterland 				if (cl_iscript(classidx) ||
3155c51f124SMoriah Waterland 					((ept->ftype == 'e') ||
3165c51f124SMoriah Waterland 					(ept->ftype == 'n'))) {
3175c51f124SMoriah Waterland 					if (ck_efile(srcp, ept)) {
3185c51f124SMoriah Waterland 						progerr(ERR_CORRUPT,
3195c51f124SMoriah Waterland 							srcp);
3205c51f124SMoriah Waterland 						logerr(getErrbufAddr());
3215c51f124SMoriah Waterland 						warnflag++;
3225c51f124SMoriah Waterland 						continue;
3235c51f124SMoriah Waterland 					}
3245c51f124SMoriah Waterland 				}
3255c51f124SMoriah Waterland 			}
3265c51f124SMoriah Waterland 
3275c51f124SMoriah Waterland 			/*
3285c51f124SMoriah Waterland 			 * If there's a class action script for this class,
3295c51f124SMoriah Waterland 			 * just collect names in a temporary file
3305c51f124SMoriah Waterland 			 * that will be used as the stdin when the
3315c51f124SMoriah Waterland 			 * class action script is invoked.
3325c51f124SMoriah Waterland 			 */
3335c51f124SMoriah Waterland 
3345c51f124SMoriah Waterland 			if ((cl_iscript(classidx)) &&
3355c51f124SMoriah Waterland 					((is_fs_writeable(ept->path,
3365c51f124SMoriah Waterland 						&(ext->fsys_value))))) {
3375c51f124SMoriah Waterland 				if (pass_relative) {
3385c51f124SMoriah Waterland 					if (!rel_init) {
3395c51f124SMoriah Waterland 						(void) fputs(instdir, listfp);
3405c51f124SMoriah Waterland 						(void) putc('\n', listfp);
3415c51f124SMoriah Waterland 						rel_init++;
3425c51f124SMoriah Waterland 					}
3435c51f124SMoriah Waterland 					(void) fputs(ext->map_path, listfp);
3445c51f124SMoriah Waterland 					(void) putc('\n', listfp);
3455c51f124SMoriah Waterland 				} else {
3465c51f124SMoriah Waterland 					(void) fputs(srcp ?
3475c51f124SMoriah Waterland 						srcp : "/dev/null", listfp);
3485c51f124SMoriah Waterland 					(void) putc(' ', listfp);
3495c51f124SMoriah Waterland 					(void) fputs(dstp, listfp);
3505c51f124SMoriah Waterland 					(void) putc('\n', listfp);
3515c51f124SMoriah Waterland 				}
3525c51f124SMoriah Waterland 				/*
3535c51f124SMoriah Waterland 				 * Note which entries in extlist are regular
3545c51f124SMoriah Waterland 				 * files to be installed via the class action
3555c51f124SMoriah Waterland 				 * script.
3565c51f124SMoriah Waterland 				 */
3575c51f124SMoriah Waterland 				if (regfiles_head == NULL) {
3585c51f124SMoriah Waterland 					assert(rfp == NULL);
3595c51f124SMoriah Waterland 					regfiles_head =
3605c51f124SMoriah Waterland 					    malloc(sizeof (struct reg_files));
3615c51f124SMoriah Waterland 					if (regfiles_head == NULL) {
3625c51f124SMoriah Waterland 						progerr(ERR_MEMORY, errno);
3635c51f124SMoriah Waterland 						quit(99);
3645c51f124SMoriah Waterland 					}
3655c51f124SMoriah Waterland 					regfiles_head->next = NULL;
3665c51f124SMoriah Waterland 					regfiles_head->val = entryidx;
3675c51f124SMoriah Waterland 					rfp = regfiles_head;
3685c51f124SMoriah Waterland 				} else {
3695c51f124SMoriah Waterland 					assert(rfp != NULL);
3705c51f124SMoriah Waterland 					rfp->next =
3715c51f124SMoriah Waterland 					    malloc(sizeof (struct reg_files));
3725c51f124SMoriah Waterland 					if (rfp->next == NULL) {
3735c51f124SMoriah Waterland 						progerr(ERR_MEMORY, errno);
3745c51f124SMoriah Waterland 						quit(99);
3755c51f124SMoriah Waterland 					}
3765c51f124SMoriah Waterland 					rfp = rfp->next;
3775c51f124SMoriah Waterland 					rfp->next = NULL;
3785c51f124SMoriah Waterland 					rfp->val = entryidx;
3795c51f124SMoriah Waterland 				}
3805c51f124SMoriah Waterland 
3815c51f124SMoriah Waterland 				/*
3825c51f124SMoriah Waterland 				 * A warning message about unwritable targets
3835c51f124SMoriah Waterland 				 * in a class may be appropriate here.
3845c51f124SMoriah Waterland 				 */
3855c51f124SMoriah Waterland 				continue;
3865c51f124SMoriah Waterland 			}
3875c51f124SMoriah Waterland 
3885c51f124SMoriah Waterland 			/*
3895c51f124SMoriah Waterland 			 * If not installing from a partially spooled package
3905c51f124SMoriah Waterland 			 * (the "save/pspool" area), and the file contents can
3915c51f124SMoriah Waterland 			 * be changed (type is 'e' or 'v') and the class
3925c51f124SMoriah Waterland 			 * identifier is not "none": copy the file from the
3935c51f124SMoriah Waterland 			 * package (in pristine state with no actions performed)
3945c51f124SMoriah Waterland 			 * into the appropriate location in the packages
3955c51f124SMoriah Waterland 			 * destination "save/pspool" area.
3965c51f124SMoriah Waterland 			 */
3975c51f124SMoriah Waterland 
3985c51f124SMoriah Waterland 			if ((!is_partial_inst()) &&
3995c51f124SMoriah Waterland 			    ((ept->ftype == 'e') || (ept->ftype == 'v') &&
4005c51f124SMoriah Waterland 			    (strcmp(ept->pkg_class, "none") != 0))) {
4015c51f124SMoriah Waterland 
4025c51f124SMoriah Waterland 				if (absolutepath(ext->map_path) == B_TRUE &&
4035c51f124SMoriah Waterland 					parametricpath(ext->cf_ent.ainfo.local,
4045c51f124SMoriah Waterland 						&relocpath) == B_FALSE) {
4055c51f124SMoriah Waterland 					pspool_loc = ROOT;
4065c51f124SMoriah Waterland 				} else {
4075c51f124SMoriah Waterland 					pspool_loc = RELOC;
4085c51f124SMoriah Waterland 				}
4095c51f124SMoriah Waterland 
4105c51f124SMoriah Waterland 				n = snprintf(scrpt_dst, PATH_MAX, "%s/%s/%s",
4115c51f124SMoriah Waterland 					saveSpoolInstallDir, pspool_loc,
4125c51f124SMoriah Waterland 					relocpath ? relocpath : ext->map_path);
4135c51f124SMoriah Waterland 
4145c51f124SMoriah Waterland 				if (n >= PATH_MAX) {
4155c51f124SMoriah Waterland 					progerr(ERR_CREATE_PATH_2,
4165c51f124SMoriah Waterland 						saveSpoolInstallDir,
4175c51f124SMoriah Waterland 						ext->map_path);
4185c51f124SMoriah Waterland 					quit(99);
4195c51f124SMoriah Waterland 				}
4205c51f124SMoriah Waterland 
4215c51f124SMoriah Waterland 				/* copy, preserve source file mode */
4225c51f124SMoriah Waterland 
4235c51f124SMoriah Waterland 				if (cppath(MODE_SRC, srcp, scrpt_dst, 0644)) {
4245c51f124SMoriah Waterland 					warnflag++;
4255c51f124SMoriah Waterland 				}
4265c51f124SMoriah Waterland 			}
4275c51f124SMoriah Waterland 
4285c51f124SMoriah Waterland 			/*
4295c51f124SMoriah Waterland 			 * There are several tests here to determine
4305c51f124SMoriah Waterland 			 * how we're going to deal with objects
4315c51f124SMoriah Waterland 			 * intended for remote read-only filesystems.
4325c51f124SMoriah Waterland 			 * We don't use is_served() because this may be
4335c51f124SMoriah Waterland 			 * a server. We're actually interested in if
4345c51f124SMoriah Waterland 			 * it's *really* remote and *really* not
4355c51f124SMoriah Waterland 			 * writeable.
4365c51f124SMoriah Waterland 			 */
4375c51f124SMoriah Waterland 
4385c51f124SMoriah Waterland 			n = is_remote_fs(ept->path, &(ext->fsys_value));
4395c51f124SMoriah Waterland 			if ((n != 0) &&
4405c51f124SMoriah Waterland 				!is_fs_writeable(ept->path,
4415c51f124SMoriah Waterland 				&(ext->fsys_value))) {
4425c51f124SMoriah Waterland 
4435c51f124SMoriah Waterland 				/*
4445c51f124SMoriah Waterland 				 * Don't change the file, we can't write
4455c51f124SMoriah Waterland 				 * to it anyway.
4465c51f124SMoriah Waterland 				 */
4475c51f124SMoriah Waterland 
4485c51f124SMoriah Waterland 				mstat->attrchg = 0;
4495c51f124SMoriah Waterland 				mstat->contchg = 0;
4505c51f124SMoriah Waterland 
4515c51f124SMoriah Waterland 				/*
4525c51f124SMoriah Waterland 				 * If it's currently mounted, we can
4535c51f124SMoriah Waterland 				 * at least test it for existence.
4545c51f124SMoriah Waterland 				 */
4555c51f124SMoriah Waterland 
4565c51f124SMoriah Waterland 				if (is_mounted(ept->path, &(ext->fsys_value))) {
4575c51f124SMoriah Waterland 					if (!isfile(NULL, dstp)) {
4585c51f124SMoriah Waterland 						echo(MSG_IS_PRESENT, dstp);
4595c51f124SMoriah Waterland 					} else {
4605c51f124SMoriah Waterland 						echo(WRN_INSTVOL_NONE, dstp);
4615c51f124SMoriah Waterland 					}
4625c51f124SMoriah Waterland 				} else {
4635c51f124SMoriah Waterland 					char *server_host;
4645c51f124SMoriah Waterland 
4655c51f124SMoriah Waterland 					server_host = get_server_host(
4665c51f124SMoriah Waterland 						ext->fsys_value);
4675c51f124SMoriah Waterland 
4685c51f124SMoriah Waterland 					/* If not, we're just stuck. */
4695c51f124SMoriah Waterland 					echo(WRN_INSTVOL_NOVERIFY,
4705c51f124SMoriah Waterland 						dstp, server_host);
4715c51f124SMoriah Waterland 				}
4725c51f124SMoriah Waterland 
4735c51f124SMoriah Waterland 				continue;
4745c51f124SMoriah Waterland 			}
4755c51f124SMoriah Waterland 
4765c51f124SMoriah Waterland 			/* echo output destination name */
4775c51f124SMoriah Waterland 
4785c51f124SMoriah Waterland 			echo("%s", dstp);
4795c51f124SMoriah Waterland 
4805c51f124SMoriah Waterland 			/*
4815c51f124SMoriah Waterland 			 * if no source then no need to copy/verify
4825c51f124SMoriah Waterland 			 */
4835c51f124SMoriah Waterland 
4845c51f124SMoriah Waterland 			if (srcp == (char *)NULL) {
4855c51f124SMoriah Waterland 				continue;
4865c51f124SMoriah Waterland 			}
4875c51f124SMoriah Waterland 
4885c51f124SMoriah Waterland 			/*
4895c51f124SMoriah Waterland 			 * If doing a partial installation (creating a
4905c51f124SMoriah Waterland 			 * non-global zone), extra steps need to be taken:
4915c51f124SMoriah Waterland 			 *
492*6e1ae2a3SGary Pennington 			 * If the file is not type 'e' and not type 'v' and
4935c51f124SMoriah Waterland 			 * the class is "none": then the file must already
4945c51f124SMoriah Waterland 			 * exist (as a result of the initial non-global zone
4955c51f124SMoriah Waterland 			 * installation which caused all non-e/v files to be
4965c51f124SMoriah Waterland 			 * copied from the global zone to the non-global
4975c51f124SMoriah Waterland 			 * zone). If this is the case, verify that the file
4985c51f124SMoriah Waterland 			 * exists and has the correct attributes.
4995c51f124SMoriah Waterland 			 */
5005c51f124SMoriah Waterland 
5015c51f124SMoriah Waterland 			if (is_partial_inst() != 0) {
5025c51f124SMoriah Waterland 
5035c51f124SMoriah Waterland 				/*
5045c51f124SMoriah Waterland 				 * if not type 'e|v' and class 'none', then the
5055c51f124SMoriah Waterland 				 * file must already exist.
5065c51f124SMoriah Waterland 				 */
5075c51f124SMoriah Waterland 
5085c51f124SMoriah Waterland 				if ((ept->ftype != 'e') &&
5095c51f124SMoriah Waterland 					(ept->ftype != 'v') &&
5105c51f124SMoriah Waterland 					(strcmp(cl_nam(ept->pkg_class_idx),
5115c51f124SMoriah Waterland 								"none") == 0)) {
5125c51f124SMoriah Waterland 
5135c51f124SMoriah Waterland 					/* is file changed? */
5145c51f124SMoriah Waterland 					n = finalck(ept, 1, 1, B_TRUE);
5155c51f124SMoriah Waterland 
516*6e1ae2a3SGary Pennington 					/* not - ok - warn */
517*6e1ae2a3SGary Pennington 					if (n != 0) {
5185c51f124SMoriah Waterland 						/* output warning message */
5195c51f124SMoriah Waterland 						logerr(NOTE_INSTVOL_FINALCKFAIL,
520*6e1ae2a3SGary Pennington 						    pkginst, ext->map_path);
5215c51f124SMoriah Waterland 					}
5225c51f124SMoriah Waterland 					continue;
5235c51f124SMoriah Waterland 				}
5245c51f124SMoriah Waterland 			}
5255c51f124SMoriah Waterland 
5265c51f124SMoriah Waterland 			/*
5275c51f124SMoriah Waterland 			 * Copy from source media to target path and fix file
5285c51f124SMoriah Waterland 			 * mode and permission now in case installation halted.
5295c51f124SMoriah Waterland 			 */
5305c51f124SMoriah Waterland 
5315c51f124SMoriah Waterland 			/*
5325c51f124SMoriah Waterland 			 * If the filesystem is read-only don't attempt
5335c51f124SMoriah Waterland 			 * to copy a file. Just check that the content
5345c51f124SMoriah Waterland 			 * and attributes of the file are correct.
5355c51f124SMoriah Waterland 			 *
5365c51f124SMoriah Waterland 			 * Normally this doesn't happen, because files,
5375c51f124SMoriah Waterland 			 * which don't change, are not returned by
538*6e1ae2a3SGary Pennington 			 * domerg().
5395c51f124SMoriah Waterland 			 */
5405c51f124SMoriah Waterland 			n = 0;
5415c51f124SMoriah Waterland 			if (is_fs_writeable(ept->path,
5425c51f124SMoriah Waterland 			    &(ext->fsys_value)))
5435c51f124SMoriah Waterland 				n = cppath(MODE_SET|DIR_DISPLAY, srcp,
5445c51f124SMoriah Waterland 				    dstp, ept->ainfo.mode);
5455c51f124SMoriah Waterland 
5465c51f124SMoriah Waterland 			if (n != 0) {
5475c51f124SMoriah Waterland 				warnflag++;
5485c51f124SMoriah Waterland 			} else if (!finalck(ept, 1, 1, B_FALSE)) {
5495c51f124SMoriah Waterland 				/*
5505c51f124SMoriah Waterland 				 * everything checks here
5515c51f124SMoriah Waterland 				 */
5525c51f124SMoriah Waterland 				mstat->attrchg = 0;
5535c51f124SMoriah Waterland 				mstat->contchg = 0;
5545c51f124SMoriah Waterland 			}
5555c51f124SMoriah Waterland 
5565c51f124SMoriah Waterland 			/* NOTE: a package object was updated */
5575c51f124SMoriah Waterland 
5585c51f124SMoriah Waterland 			if (updated == (char *)NULL) {
5595c51f124SMoriah Waterland 				echoDebug(DBG_INSTVOL_OBJ_UPDATED, dstp);
5605c51f124SMoriah Waterland 				updated = dstp;
5615c51f124SMoriah Waterland 			}
5625c51f124SMoriah Waterland 		}
5635c51f124SMoriah Waterland 
5645c51f124SMoriah Waterland 		/*
5655c51f124SMoriah Waterland 		 * We have now completed processing of all pathnames
5665c51f124SMoriah Waterland 		 * associated with this volume and class.
5675c51f124SMoriah Waterland 		 */
5685c51f124SMoriah Waterland 		if (cl_iscript(classidx)) {
5695c51f124SMoriah Waterland 			/*
5705c51f124SMoriah Waterland 			 * Execute appropriate class action script
5715c51f124SMoriah Waterland 			 * with list of source/destination pathnames
5725c51f124SMoriah Waterland 			 * as the input to the script.
5735c51f124SMoriah Waterland 			 */
5745c51f124SMoriah Waterland 
5755c51f124SMoriah Waterland 			if (chdir(pkgbin)) {
5765c51f124SMoriah Waterland 				progerr(ERR_CHGDIR, pkgbin);
5775c51f124SMoriah Waterland 				quit(99);
5785c51f124SMoriah Waterland 			}
5795c51f124SMoriah Waterland 
5805c51f124SMoriah Waterland 			if (listfp) {
5815c51f124SMoriah Waterland 				(void) fclose(listfp);
5825c51f124SMoriah Waterland 			}
5835c51f124SMoriah Waterland 
584*6e1ae2a3SGary Pennington 			/* nothing updated */
5855c51f124SMoriah Waterland 
5865c51f124SMoriah Waterland 			echoDebug(DBG_INSTVOL_CAS_INFO, is_partial_inst(),
587*6e1ae2a3SGary Pennington 				updated ? updated : "");
5885c51f124SMoriah Waterland 
5895c51f124SMoriah Waterland 			if ((is_partial_inst() != 0) &&
590*6e1ae2a3SGary Pennington 					(updated == (char *)NULL)) {
5915c51f124SMoriah Waterland 
5925c51f124SMoriah Waterland 				/*
5935c51f124SMoriah Waterland 				 * installing in non-global zone, and no object
594*6e1ae2a3SGary Pennington 				 * has been updated (installed/verified):
595*6e1ae2a3SGary Pennington 				 * do not run the class action script.
5965c51f124SMoriah Waterland 				 */
5975c51f124SMoriah Waterland 
5985c51f124SMoriah Waterland 				echoDebug(DBG_INSTVOL_NOT_RUNNING_CAS,
5995c51f124SMoriah Waterland 					a_zoneName ? a_zoneName : "?",
6005c51f124SMoriah Waterland 					eocflag ? "ENDOFCLASS" :
6015c51f124SMoriah Waterland 							cl_iscript(classidx),
6025c51f124SMoriah Waterland 					cl_nam(classidx),
6035c51f124SMoriah Waterland 					cl_iscript(classidx));
6045c51f124SMoriah Waterland 
6055c51f124SMoriah Waterland 			} else {
6065c51f124SMoriah Waterland 				/* run the class action script */
6075c51f124SMoriah Waterland 
6085c51f124SMoriah Waterland 				echoDebug(DBG_INSTVOL_RUNNING_CAS,
6095c51f124SMoriah Waterland 					a_zoneName ? a_zoneName : "?",
6105c51f124SMoriah Waterland 					eocflag ? "ENDOFCLASS" :
6115c51f124SMoriah Waterland 							cl_iscript(classidx),
6125c51f124SMoriah Waterland 					cl_nam(classidx),
6135c51f124SMoriah Waterland 					cl_iscript(classidx));
6145c51f124SMoriah Waterland 
6155c51f124SMoriah Waterland 				/* Use ULIMIT if supplied. */
6165c51f124SMoriah Waterland 				set_ulimit(cl_iscript(classidx), ERR_CASFAIL);
6175c51f124SMoriah Waterland 
6185c51f124SMoriah Waterland 				if (eocflag) {
6195c51f124SMoriah Waterland 					/*
6205c51f124SMoriah Waterland 					 * end of class detected.
6215c51f124SMoriah Waterland 					 * Since there are no more volumes which
6225c51f124SMoriah Waterland 					 * contain pathnames associated with
6235c51f124SMoriah Waterland 					 * this class, execute class action
6245c51f124SMoriah Waterland 					 * script with the ENDOFCLASS argument;
6255c51f124SMoriah Waterland 					 * we do this even if none of the path
6265c51f124SMoriah Waterland 					 * names associated with this class and
6275c51f124SMoriah Waterland 					 * volume needed installation to
6285c51f124SMoriah Waterland 					 * guarantee the class action script is
6295c51f124SMoriah Waterland 					 * executed at least once during package
6305c51f124SMoriah Waterland 					 * installation.
6315c51f124SMoriah Waterland 					 */
6325c51f124SMoriah Waterland 					if (pkgverbose) {
6335c51f124SMoriah Waterland 						n = pkgexecl((listfp ?
6345c51f124SMoriah Waterland 							listfile : CAS_STDIN),
6355c51f124SMoriah Waterland 							CAS_STDOUT,
6365c51f124SMoriah Waterland 							CAS_USER, CAS_GRP,
6375c51f124SMoriah Waterland 							SHELL, "-x",
6385c51f124SMoriah Waterland 							cl_iscript(classidx),
6395c51f124SMoriah Waterland 							"ENDOFCLASS", NULL);
6405c51f124SMoriah Waterland 					} else {
6415c51f124SMoriah Waterland 						n = pkgexecl(
6425c51f124SMoriah Waterland 							(listfp ?
6435c51f124SMoriah Waterland 							listfile : CAS_STDIN),
6445c51f124SMoriah Waterland 							CAS_STDOUT, CAS_USER,
6455c51f124SMoriah Waterland 							CAS_GRP, SHELL,
6465c51f124SMoriah Waterland 							cl_iscript(classidx),
6475c51f124SMoriah Waterland 							"ENDOFCLASS", NULL);
6485c51f124SMoriah Waterland 					}
6495c51f124SMoriah Waterland 					ckreturn(n, ERR_CASFAIL);
6505c51f124SMoriah Waterland 				} else if (count) {
6515c51f124SMoriah Waterland 					/* execute class action script */
6525c51f124SMoriah Waterland 					if (pkgverbose) {
6535c51f124SMoriah Waterland 						n = pkgexecl(listfile,
6545c51f124SMoriah Waterland 							CAS_STDOUT, CAS_USER,
6555c51f124SMoriah Waterland 							CAS_GRP, SHELL, "-x",
6565c51f124SMoriah Waterland 							cl_iscript(classidx),
6575c51f124SMoriah Waterland 							NULL);
6585c51f124SMoriah Waterland 					} else {
6595c51f124SMoriah Waterland 						n = pkgexecl(listfile,
6605c51f124SMoriah Waterland 							CAS_STDOUT, CAS_USER,
6615c51f124SMoriah Waterland 							CAS_GRP, SHELL,
6625c51f124SMoriah Waterland 							cl_iscript(classidx),
6635c51f124SMoriah Waterland 							NULL);
6645c51f124SMoriah Waterland 					}
6655c51f124SMoriah Waterland 					ckreturn(n, ERR_CASFAIL);
6665c51f124SMoriah Waterland 				}
6675c51f124SMoriah Waterland 
6685c51f124SMoriah Waterland 				/*
6695c51f124SMoriah Waterland 				 * Ensure the mod times on disk match those
6705c51f124SMoriah Waterland 				 * in the pkgmap. In this case, call cverify
6715c51f124SMoriah Waterland 				 * with checksumming disabled, since the only
6725c51f124SMoriah Waterland 				 * action that needs to be done is to verify
6735c51f124SMoriah Waterland 				 * that the attributes are correct.
6745c51f124SMoriah Waterland 				 */
6755c51f124SMoriah Waterland 
6765c51f124SMoriah Waterland 				if ((rfp = regfiles_head) != NULL) {
6775c51f124SMoriah Waterland 					while (rfp != NULL) {
6785c51f124SMoriah Waterland 					    ept = &(extlist[rfp->val]->cf_ent);
6795c51f124SMoriah Waterland 					    cverify(1, &ept->ftype, ept->path,
6805c51f124SMoriah Waterland 						&ept->cinfo, 0);
6815c51f124SMoriah Waterland 					    rfp = rfp->next;
6825c51f124SMoriah Waterland 					}
6835c51f124SMoriah Waterland 					regfiles_free();
6845c51f124SMoriah Waterland 				}
6855c51f124SMoriah Waterland 
6865c51f124SMoriah Waterland 				clr_ulimit();
6875c51f124SMoriah Waterland 
6885c51f124SMoriah Waterland 				if ((r_updated != (char **)NULL) &&
6895c51f124SMoriah Waterland 					(*r_updated == (char *)NULL) &&
6905c51f124SMoriah Waterland 					(updated == (char *)NULL)) {
6915c51f124SMoriah Waterland 					updated = "postinstall";
6925c51f124SMoriah Waterland 					echoDebug(DBG_INSTVOL_OBJ_UPDATED,
6935c51f124SMoriah Waterland 								updated);
6945c51f124SMoriah Waterland 				}
6955c51f124SMoriah Waterland 			}
6965c51f124SMoriah Waterland 			if (listfile) {
6975c51f124SMoriah Waterland 				(void) remove(listfile);
6985c51f124SMoriah Waterland 			}
6995c51f124SMoriah Waterland 		}
7005c51f124SMoriah Waterland 
7015c51f124SMoriah Waterland 		if (eocflag && (!is_partial_inst() || (is_partial_inst() &&
7025c51f124SMoriah Waterland 			strcmp(cl_nam(classidx), "none") != 0))) {
7035c51f124SMoriah Waterland 			if (cl_dvfy(classidx) == QKVERIFY && !repl_permitted) {
7045c51f124SMoriah Waterland 				/*
7055c51f124SMoriah Waterland 				 * The quick verify just fixes everything.
7065c51f124SMoriah Waterland 				 * If it returns 0, all is well. If it
7075c51f124SMoriah Waterland 				 * returns 1, then the class installation
7085c51f124SMoriah Waterland 				 * was incomplete and we retry on the
7095c51f124SMoriah Waterland 				 * stuff that failed in the conventional
7105c51f124SMoriah Waterland 				 * way (without a CAS). this is primarily
7115c51f124SMoriah Waterland 				 * to accomodate old archives such as are
7125c51f124SMoriah Waterland 				 * found in pre-2.5 WOS; but, it is also
7135c51f124SMoriah Waterland 				 * used when a critical dynamic library
7145c51f124SMoriah Waterland 				 * is not archived with its class.
7155c51f124SMoriah Waterland 				 */
7165c51f124SMoriah Waterland 				if (!fix_attributes(extlist, classidx)) {
7175c51f124SMoriah Waterland 					/*
7185c51f124SMoriah Waterland 					 * Reset the CAS pointer. If the
7195c51f124SMoriah Waterland 					 * function returns 0 then there
7205c51f124SMoriah Waterland 					 * was no script there in the first
7215c51f124SMoriah Waterland 					 * place and we'll just have to
7225c51f124SMoriah Waterland 					 * call this a miss.
7235c51f124SMoriah Waterland 					 */
7245c51f124SMoriah Waterland 					if (cl_deliscript(classidx))
7255c51f124SMoriah Waterland 						/*
7265c51f124SMoriah Waterland 						 * Decrement classidx for
7275c51f124SMoriah Waterland 						 * next pass.
7285c51f124SMoriah Waterland 						 */
7295c51f124SMoriah Waterland 						classidx--;
7305c51f124SMoriah Waterland 				}
7315c51f124SMoriah Waterland 			} else {
7325c51f124SMoriah Waterland 				/*
7335c51f124SMoriah Waterland 				 * Finalize merge. This checks to make sure
7345c51f124SMoriah Waterland 				 * file attributes are correct and any links
7355c51f124SMoriah Waterland 				 * specified are created.
7365c51f124SMoriah Waterland 				 */
7375c51f124SMoriah Waterland 				(void) endofclass(extlist, classidx,
7385c51f124SMoriah Waterland 					(cl_iscript(classidx) ? 0 : 1),
73962224350SCasper H.S. Dik 					pkgserver, a_cfTmpVfp);
7405c51f124SMoriah Waterland 			}
7415c51f124SMoriah Waterland 		}
7425c51f124SMoriah Waterland 	    }
7435c51f124SMoriah Waterland 	}
7445c51f124SMoriah Waterland 
7455c51f124SMoriah Waterland 	/*
7465c51f124SMoriah Waterland 	 * Instead of creating links back to the GZ files the logic is
7475c51f124SMoriah Waterland 	 * to let zdo recreate the files from the GZ then invoke pkgadd to
7485c51f124SMoriah Waterland 	 * install the editable files and skip over any 'f'type files.
7495c51f124SMoriah Waterland 	 * The commented out block is to create the links which should be
7505c51f124SMoriah Waterland 	 * removed once the current code is tested to be correct.
7515c51f124SMoriah Waterland 	 */
7525c51f124SMoriah Waterland 
7535c51f124SMoriah Waterland 	/*
7545c51f124SMoriah Waterland 	 * Go through extlist creating links for 'f'type files
7555c51f124SMoriah Waterland 	 * if we're in a global zone. Note that this code lies
7565c51f124SMoriah Waterland 	 * here instead of in the main loop to support CAF packages.
7575c51f124SMoriah Waterland 	 * In a CAF package the files are installed by the i.none script
7585c51f124SMoriah Waterland 	 * and don't exist until all files are done being processed, thus
7595c51f124SMoriah Waterland 	 * the additional loop through extlist.
7605c51f124SMoriah Waterland 	 */
7615c51f124SMoriah Waterland 
7625c51f124SMoriah Waterland 	/*
7635c51f124SMoriah Waterland 	 * output appropriate completion message
7645c51f124SMoriah Waterland 	 */
7655c51f124SMoriah Waterland 
7665c51f124SMoriah Waterland 	if (is_depend_pkginfo_DB() == B_TRUE) {
7675c51f124SMoriah Waterland 		/* updating database only (hollow package) */
7685c51f124SMoriah Waterland 		if (a_zoneName == (char *)NULL) {
7695c51f124SMoriah Waterland 			echo(MSG_DBUPD_N_N, part, nparts);
7705c51f124SMoriah Waterland 		} else {
7715c51f124SMoriah Waterland 			echo(MSG_DBUPD_N_N_LZ, part, nparts, a_zoneName);
7725c51f124SMoriah Waterland 		}
7735c51f124SMoriah Waterland 	} else if (tcount == 0) {
7745c51f124SMoriah Waterland 		/* updating package (non-hollow package) */
7755c51f124SMoriah Waterland 		if (a_zoneName == (char *)NULL) {
7765c51f124SMoriah Waterland 			echo(MSG_INST_N_N, part, nparts);
7775c51f124SMoriah Waterland 		} else {
7785c51f124SMoriah Waterland 			echo(MSG_INST_N_N_LZ, part, nparts, a_zoneName);
7795c51f124SMoriah Waterland 		}
7805c51f124SMoriah Waterland 	}
7815c51f124SMoriah Waterland 
7825c51f124SMoriah Waterland 	/*
783*6e1ae2a3SGary Pennington 	 * if any package objects were updated (not otherwise already in
784*6e1ae2a3SGary Pennington 	 * existence), set the updated flag as appropriate
7855c51f124SMoriah Waterland 	 */
7865c51f124SMoriah Waterland 
7875c51f124SMoriah Waterland 	if (updated != (char *)NULL) {
7885c51f124SMoriah Waterland 		echoDebug(DBG_INSTVOL_OBJ_UPDATED, updated);
7895c51f124SMoriah Waterland 		if (r_updated != (char **)NULL) {
7905c51f124SMoriah Waterland 			*r_updated = updated;
7915c51f124SMoriah Waterland 		}
7925c51f124SMoriah Waterland 	}
7935c51f124SMoriah Waterland 
7945c51f124SMoriah Waterland }
7955c51f124SMoriah Waterland 
7965c51f124SMoriah Waterland /*
7975c51f124SMoriah Waterland  * Name:	domerg
7985c51f124SMoriah Waterland  * Description: For the specified class, review each entry and return the array
7995c51f124SMoriah Waterland  *		index number of the next regular file to process. Hard links are
8005c51f124SMoriah Waterland  *		skipped (they are created in endofclass() and directories,
8015c51f124SMoriah Waterland  *		symlinks, pipes and devices are created here, as well as any
8025c51f124SMoriah Waterland  *		file that already exists and has the correct attributes.
8035c51f124SMoriah Waterland  * Arguments:	struct cfextra **extlist - [RO, *RW]
8045c51f124SMoriah Waterland  *			- Pointer to list of cfextra structures representing
8055c51f124SMoriah Waterland  *			  the pkgmap of the package to be installed
8065c51f124SMoriah Waterland  *		int part - [RO, *RO]
8075c51f124SMoriah Waterland  *			- the part of the package currently being processed;
8085c51f124SMoriah Waterland  *			  packages begin with part "1" and proceed for the
8095c51f124SMoriah Waterland  *			  number (nparts) that comprise the package (volume).
8105c51f124SMoriah Waterland  *		int nparts - [RO, *RO]
8115c51f124SMoriah Waterland  *			- the number of parts the package is divided into
8125c51f124SMoriah Waterland  *		int myclass - [RO, *RO]
8135c51f124SMoriah Waterland  *			- index into class array of the current class
8145c51f124SMoriah Waterland  *		char **srcp - [RW, *RW]
8155c51f124SMoriah Waterland  *			- pointer to pointer to string representing the source
8165c51f124SMoriah Waterland  *			  path for the next package to process - if this
8175c51f124SMoriah Waterland  *			  function returns != DMRG_DONE then this pointer is
8185c51f124SMoriah Waterland  *			  set to a pointer to a string representing the source
8195c51f124SMoriah Waterland  *			  path for the next object from the package to process
8205c51f124SMoriah Waterland  *		char **dstp - [RW, *RW]
8215c51f124SMoriah Waterland  *			- pointer to pointer to string representing the target
8225c51f124SMoriah Waterland  *			  path for the next package to process - if this
8235c51f124SMoriah Waterland  *			  function returns != DMRG_DONE then this pointer is
8245c51f124SMoriah Waterland  *			  set to a pointer to a string representing the target
8255c51f124SMoriah Waterland  *			  path for the next object from the package to process
8265c51f124SMoriah Waterland  *		char **r_updated - [RO, *RW]
8275c51f124SMoriah Waterland  *			- pointer to pointer to string - set if the last path
828*6e1ae2a3SGary Pennington  *			  returned exists or does not need updating. This is
829*6e1ae2a3SGary Pennington  *			  always set when a path to be installed exists and
830*6e1ae2a3SGary Pennington  *			  has the correct contents.
8315c51f124SMoriah Waterland  * Returns:	int
8325c51f124SMoriah Waterland  *			!= DMRG_DONE - index into extlist of the next path to
8335c51f124SMoriah Waterland  *				be processed - that needs to be installed/copied
8345c51f124SMoriah Waterland  *			== DMRG_DONE - all entries processed
8355c51f124SMoriah Waterland  */
8365c51f124SMoriah Waterland 
8375c51f124SMoriah Waterland static int
8385c51f124SMoriah Waterland domerg(struct cfextra **extlist, int part, int nparts,
8395c51f124SMoriah Waterland 	int myclass, char **srcp, char **dstp,
840*6e1ae2a3SGary Pennington 	char **r_updated)
8415c51f124SMoriah Waterland {
8425c51f124SMoriah Waterland 	boolean_t	stateFlag = B_FALSE;
8435c51f124SMoriah Waterland 	int		i;
8445c51f124SMoriah Waterland 	int		msg_ugid;
8455c51f124SMoriah Waterland 	static int	maxvol = 0;
8465c51f124SMoriah Waterland 	static int	svindx = 0;
8475c51f124SMoriah Waterland 	static int	svpart = 0;
8485c51f124SMoriah Waterland 	struct cfent	*ept = (struct cfent *)NULL;
8495c51f124SMoriah Waterland 	struct mergstat *mstat = (struct mergstat *)NULL;
8505c51f124SMoriah Waterland 
8515c51f124SMoriah Waterland 	/* reset returned path pointers */
8525c51f124SMoriah Waterland 
8535c51f124SMoriah Waterland 	*dstp = (char *)NULL;
8545c51f124SMoriah Waterland 	*srcp = (char *)NULL;
8555c51f124SMoriah Waterland 
8565c51f124SMoriah Waterland 	/* set to start or continue based on which part being processed */
8575c51f124SMoriah Waterland 
8585c51f124SMoriah Waterland 	if (part != 0) {
8595c51f124SMoriah Waterland 		maxvol = 0;
8605c51f124SMoriah Waterland 		svindx = 0;
8615c51f124SMoriah Waterland 		svpart = part;
8625c51f124SMoriah Waterland 	} else {
8635c51f124SMoriah Waterland 		i = svindx;
8645c51f124SMoriah Waterland 		part = svpart;
8655c51f124SMoriah Waterland 	}
8665c51f124SMoriah Waterland 
8675c51f124SMoriah Waterland 	/*
8685c51f124SMoriah Waterland 	 * This goes through the pkgmap entries one by one testing them
8695c51f124SMoriah Waterland 	 * for inclusion in the package database as well as for validity
8705c51f124SMoriah Waterland 	 * against existing files.
8715c51f124SMoriah Waterland 	 */
8725c51f124SMoriah Waterland 	for (i = svindx; extlist[i]; i++) {
8735c51f124SMoriah Waterland 		ept = &(extlist[i]->cf_ent);
8745c51f124SMoriah Waterland 		mstat = &(extlist[i]->mstat);
8755c51f124SMoriah Waterland 
8765c51f124SMoriah Waterland 		/* if this isn't the class of current interest, skip it */
8775c51f124SMoriah Waterland 
8785c51f124SMoriah Waterland 		if (myclass != ept->pkg_class_idx) {
8795c51f124SMoriah Waterland 			continue;
8805c51f124SMoriah Waterland 		}
8815c51f124SMoriah Waterland 
8825c51f124SMoriah Waterland 		/* if the class is invalid, announce it & exit */
8835c51f124SMoriah Waterland 		if (ept->pkg_class_idx == -1) {
8845c51f124SMoriah Waterland 			progerr(ERR_CLIDX, ept->pkg_class_idx,
8855c51f124SMoriah Waterland 			    (ept->path && *ept->path) ? ept->path : "unknown");
88662224350SCasper H.S. Dik 			logerr(gettext("pathname=%s"),
8875c51f124SMoriah Waterland 			    (ept->path && *ept->path) ? ept->path : "unknown");
88862224350SCasper H.S. Dik 			logerr(gettext("class=<%s>"),
8895c51f124SMoriah Waterland 			    (ept->pkg_class && *ept->pkg_class) ?
8905c51f124SMoriah Waterland 			    ept->pkg_class : "Unknown");
89162224350SCasper H.S. Dik 			logerr(gettext("CLASSES=<%s>"),
8925c51f124SMoriah Waterland 			    getenv("CLASSES") ? getenv("CLASSES") : "Not Set");
8935c51f124SMoriah Waterland 			quit(99);
8945c51f124SMoriah Waterland 		}
8955c51f124SMoriah Waterland 
8965c51f124SMoriah Waterland 		/*
8975c51f124SMoriah Waterland 		 * Next check to see if we are going to try to delete a
8985c51f124SMoriah Waterland 		 * populated directory in some distressing way.
8995c51f124SMoriah Waterland 		 */
9005c51f124SMoriah Waterland 		if (mstat->dir2nondir)
9015c51f124SMoriah Waterland 			if (dir_is_populated(ept->path)) {
9025c51f124SMoriah Waterland 				logerr(WRN_INSTVOL_NOTDIR, ept->path);
9035c51f124SMoriah Waterland 				warnflag++;
9045c51f124SMoriah Waterland 				mstat->denied = 1;	/* install denied! */
9055c51f124SMoriah Waterland 				continue;
9065c51f124SMoriah Waterland 			} else {	/* Replace is OK. */
9075c51f124SMoriah Waterland 				/*
9085c51f124SMoriah Waterland 				 * Remove this directory, so it won't
9095c51f124SMoriah Waterland 				 * interfere with creation of the new object.
9105c51f124SMoriah Waterland 				 */
9115c51f124SMoriah Waterland 				if (rmdir(ept->path)) {
9125c51f124SMoriah Waterland 					/*
9135c51f124SMoriah Waterland 					 * If it didn't work, there's nothing
9145c51f124SMoriah Waterland 					 * we can do. To continue would
9155c51f124SMoriah Waterland 					 * likely corrupt the filesystem
9165c51f124SMoriah Waterland 					 * which is unacceptable.
9175c51f124SMoriah Waterland 					 */
9185c51f124SMoriah Waterland 					progerr(ERR_RMDIR, ept->path);
9195c51f124SMoriah Waterland 					quit(99);
9205c51f124SMoriah Waterland 				}
9215c51f124SMoriah Waterland 
9225c51f124SMoriah Waterland 				repl_permitted = 1;	/* flag it */
9235c51f124SMoriah Waterland 			}
9245c51f124SMoriah Waterland 
9255c51f124SMoriah Waterland 		/* adjust the max volume number appropriately */
9265c51f124SMoriah Waterland 
9275c51f124SMoriah Waterland 		if (ept->volno > maxvol) {
9285c51f124SMoriah Waterland 			maxvol = ept->volno;
9295c51f124SMoriah Waterland 		}
9305c51f124SMoriah Waterland 
9315c51f124SMoriah Waterland 		/* if this part goes into another volume, skip it */
9325c51f124SMoriah Waterland 
9335c51f124SMoriah Waterland 		if (part != ept->volno) {
9345c51f124SMoriah Waterland 			continue;
9355c51f124SMoriah Waterland 		}
9365c51f124SMoriah Waterland 
9375c51f124SMoriah Waterland 		/*
9385c51f124SMoriah Waterland 		 * If it's a conflicting file and it's not supposed to be
9395c51f124SMoriah Waterland 		 * installed, note it and skip.
9405c51f124SMoriah Waterland 		 */
9415c51f124SMoriah Waterland 		if (nocnflct && mstat->shared && ept->ftype != 'e') {
9425c51f124SMoriah Waterland 			if (mstat->contchg || mstat->attrchg) {
9435c51f124SMoriah Waterland 				echo(MSG_SHIGN, ept->path);
9445c51f124SMoriah Waterland 			}
9455c51f124SMoriah Waterland 			continue;
9465c51f124SMoriah Waterland 		}
9475c51f124SMoriah Waterland 
9485c51f124SMoriah Waterland 		/*
9495c51f124SMoriah Waterland 		 * If we want to set uid or gid but user says no, note it.
9505c51f124SMoriah Waterland 		 * Remember that the actual mode bits in the structure have
9515c51f124SMoriah Waterland 		 * already been adjusted and the mstat flag is telling us
9525c51f124SMoriah Waterland 		 * about the original mode.
9535c51f124SMoriah Waterland 		 */
9545c51f124SMoriah Waterland 		if (nosetuid && (mstat->setuid || mstat->setgid)) {
9555c51f124SMoriah Waterland 			msg_ugid = 1;	/* don't repeat attribute message. */
9565c51f124SMoriah Waterland 			if (is_fs_writeable(ept->path,
9575c51f124SMoriah Waterland 				&(extlist[i]->fsys_value))) {
9585c51f124SMoriah Waterland 				if (!(mstat->contchg) && mstat->attrchg) {
9595c51f124SMoriah Waterland 					echo(MSG_UGMOD, ept->path);
9605c51f124SMoriah Waterland 				} else {
9615c51f124SMoriah Waterland 					echo(MSG_UGID, ept->path);
9625c51f124SMoriah Waterland 				}
9635c51f124SMoriah Waterland 			}
9645c51f124SMoriah Waterland 		} else {
9655c51f124SMoriah Waterland 			msg_ugid = 0;
9665c51f124SMoriah Waterland 		}
9675c51f124SMoriah Waterland 
9685c51f124SMoriah Waterland 		switch (ept->ftype) {
9695c51f124SMoriah Waterland 			case 'l':	/* hard link */
9705c51f124SMoriah Waterland 				/* links treated as object "update/skip" */
9715c51f124SMoriah Waterland 				stateFlag = B_TRUE;
9725c51f124SMoriah Waterland 				continue; /* defer to final proc */
9735c51f124SMoriah Waterland 
9745c51f124SMoriah Waterland 			case 's': /* for symlink, verify without fix first */
9755c51f124SMoriah Waterland 				/* links treated as object "update/skip" */
9765c51f124SMoriah Waterland 				stateFlag = B_TRUE;
9775c51f124SMoriah Waterland 
9785c51f124SMoriah Waterland 				/* Do this only for default verify */
9795c51f124SMoriah Waterland 				if (cl_dvfy(myclass) == DEFAULT) {
9805c51f124SMoriah Waterland 					if (averify(0, &ept->ftype,
9815c51f124SMoriah Waterland 						ept->path, &ept->ainfo))
9825c51f124SMoriah Waterland 						echo(MSG_SLINK, ept->path);
9835c51f124SMoriah Waterland 				}
9845c51f124SMoriah Waterland 
9855c51f124SMoriah Waterland 				/*FALLTHRU*/
9865c51f124SMoriah Waterland 
9875c51f124SMoriah Waterland 			case 'd':	/* directory */
9885c51f124SMoriah Waterland 			case 'x':	/* exclusive directory */
9895c51f124SMoriah Waterland 			case 'c':	/* character special device */
9905c51f124SMoriah Waterland 			case 'b':	/* block special device */
9915c51f124SMoriah Waterland 			case 'p':	/* named pipe */
9925c51f124SMoriah Waterland 				/* these NOT treated as object "update/skip" */
9935c51f124SMoriah Waterland 				stateFlag = B_FALSE;
9945c51f124SMoriah Waterland 
9955c51f124SMoriah Waterland 				/*
9965c51f124SMoriah Waterland 				 * If we can't get to it for legitimate reasons,
9975c51f124SMoriah Waterland 				 * don't try to verify it.
9985c51f124SMoriah Waterland 				 */
999*6e1ae2a3SGary Pennington 				if (is_remote_fs(ept->path,
10005c51f124SMoriah Waterland 				    &(extlist[i]->fsys_value)) &&
10015c51f124SMoriah Waterland 				    !is_fs_writeable(ept->path,
10025c51f124SMoriah Waterland 				    &(extlist[i]->fsys_value))) {
10035c51f124SMoriah Waterland 					mstat->attrchg = 0;
10045c51f124SMoriah Waterland 					mstat->contchg = 0;
10055c51f124SMoriah Waterland 					break;
10065c51f124SMoriah Waterland 				}
10075c51f124SMoriah Waterland 
10085c51f124SMoriah Waterland 				if (averify(1, &ept->ftype, ept->path,
10095c51f124SMoriah Waterland 							&ept->ainfo) == 0) {
10105c51f124SMoriah Waterland 					mstat->contchg = mstat->attrchg = 0;
10115c51f124SMoriah Waterland 				} else {
10125c51f124SMoriah Waterland 					progerr(ERR_CREATE_PKGOBJ, ept->path);
10135c51f124SMoriah Waterland 					logerr(getErrbufAddr());
10145c51f124SMoriah Waterland 					warnflag++;
10155c51f124SMoriah Waterland 				}
10165c51f124SMoriah Waterland 
10175c51f124SMoriah Waterland 				break;
10185c51f124SMoriah Waterland 
10195c51f124SMoriah Waterland 			case 'i':	/* information file */
10205c51f124SMoriah Waterland 				/* not treated as object "update/skip" */
10215c51f124SMoriah Waterland 				stateFlag = B_FALSE;
10225c51f124SMoriah Waterland 				break;
10235c51f124SMoriah Waterland 
10245c51f124SMoriah Waterland 			default:
10255c51f124SMoriah Waterland 				/* all files treated as object "update/skip" */
10265c51f124SMoriah Waterland 				stateFlag = B_TRUE;
10275c51f124SMoriah Waterland 				break;
10285c51f124SMoriah Waterland 		}
10295c51f124SMoriah Waterland 
10305c51f124SMoriah Waterland 		/*
10315c51f124SMoriah Waterland 		 * Both contchg and shared flags have to be taken into
10325c51f124SMoriah Waterland 		 * account. contchg is set if the file is already present
10335c51f124SMoriah Waterland 		 * in the package database, if it does not exist or if it
10345c51f124SMoriah Waterland 		 * exists and is modified.
10355c51f124SMoriah Waterland 		 * The shared flag is set when 'e' or 'v' file is not
10365c51f124SMoriah Waterland 		 * present in the package database, exists and is not
10375c51f124SMoriah Waterland 		 * modified. It also has to be checked here.
10385c51f124SMoriah Waterland 		 * Shared flag is also set when file is present in package
10395c51f124SMoriah Waterland 		 * database and owned by more than one package, but for
10405c51f124SMoriah Waterland 		 * this case contchg has already been set.
10415c51f124SMoriah Waterland 		 */
10425c51f124SMoriah Waterland 		if (mstat->contchg || (mstat->shared &&
10435c51f124SMoriah Waterland 		    ((ept->ftype == 'e') || (ept->ftype == 'v')))) {
10445c51f124SMoriah Waterland 			*dstp = ept->path;
10455c51f124SMoriah Waterland 			if ((ept->ftype == 'f') || (ept->ftype == 'e') ||
10465c51f124SMoriah Waterland 				(ept->ftype == 'v')) {
10475c51f124SMoriah Waterland 				*srcp = ept->ainfo.local;
10485c51f124SMoriah Waterland 				if (is_partial_inst() != 0) {
10495c51f124SMoriah Waterland 					if (*srcp[0] == '~') {
1050d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						/* Done only for C style */
1051d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						char *tmp_ptr;
1052d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						tmp_ptr = extlist[i]->map_path;
1053d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						if (ept->ftype != 'f') {
1054d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							/*
1055d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							 * translate source
1056d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							 * pathname
1057d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							 */
1058d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							*srcp =
1059d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							    srcpath(instdir,
1060d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							    tmp_ptr,
1061d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							    part,
1062d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							    nparts);
1063d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						} else {
1064d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						/*
1065d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * instdir has the absolute path
1066d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * to saveSpoolInstallDir for
1067d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * the package. This is only
1068d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * useful for 'e','v' types.
1069d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 *
1070d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * For 'f', we generate the
1071d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * absolute src path with the
1072d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * help of install root and the
1073d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 * basedir.
1074d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						 */
1075d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							*srcp = trans_srcp_pi(
1076d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 							    ept->ainfo.local);
1077d676c667Sphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India 						}
10785c51f124SMoriah Waterland 					} else {
10795c51f124SMoriah Waterland 						*srcp = extlist[i]->map_path;
10805c51f124SMoriah Waterland 					}
10815c51f124SMoriah Waterland 				} else {
10825c51f124SMoriah Waterland 					if (*srcp[0] == '~') {
10835c51f124SMoriah Waterland 						/* translate source pathname */
10845c51f124SMoriah Waterland 						*srcp = srcpath(instdir,
10855c51f124SMoriah Waterland 						    &(ept->ainfo.local[1]),
10865c51f124SMoriah Waterland 						    part, nparts);
10875c51f124SMoriah Waterland 					}
10885c51f124SMoriah Waterland 				}
10895c51f124SMoriah Waterland 
10905c51f124SMoriah Waterland 				echoDebug(DBG_DOMERG_NO_SUCH_FILE,
10915c51f124SMoriah Waterland 					ept->ftype, cl_nam(ept->pkg_class_idx),
10925c51f124SMoriah Waterland 					ept->path);
10935c51f124SMoriah Waterland 			} else {
10945c51f124SMoriah Waterland 				/*
10955c51f124SMoriah Waterland 				 * At this point, we're returning a non-file
10965c51f124SMoriah Waterland 				 * that couldn't be created in the standard
10975c51f124SMoriah Waterland 				 * way. If it refers to a filesystem that is
10985c51f124SMoriah Waterland 				 * not writeable by us, don't waste the
10995c51f124SMoriah Waterland 				 * calling process's time.
11005c51f124SMoriah Waterland 				 */
11015c51f124SMoriah Waterland 				if (!is_fs_writeable(ept->path,
11025c51f124SMoriah Waterland 					&(extlist[i]->fsys_value))) {
11035c51f124SMoriah Waterland 					echoDebug(DBG_DOMERG_NOT_WRITABLE,
11045c51f124SMoriah Waterland 						ept->ftype,
11055c51f124SMoriah Waterland 						cl_nam(ept->pkg_class_idx),
11065c51f124SMoriah Waterland 						ept->path);
11075c51f124SMoriah Waterland 					continue;
11085c51f124SMoriah Waterland 				}
11095c51f124SMoriah Waterland 
11105c51f124SMoriah Waterland 				*srcp = NULL;
11115c51f124SMoriah Waterland 				echoDebug(DBG_DOMERG_NOT_THERE,
11125c51f124SMoriah Waterland 					ept->ftype, cl_nam(ept->pkg_class_idx),
11135c51f124SMoriah Waterland 					ept->path);
11145c51f124SMoriah Waterland 			}
11155c51f124SMoriah Waterland 
11165c51f124SMoriah Waterland 			svindx = i+1;
11175c51f124SMoriah Waterland 			backup(*dstp, 1);
11185c51f124SMoriah Waterland 			return (i);
11195c51f124SMoriah Waterland 		}
11205c51f124SMoriah Waterland 
11215c51f124SMoriah Waterland 		if (mstat->attrchg) {
11225c51f124SMoriah Waterland 			backup(ept->path, 0);
11235c51f124SMoriah Waterland 			if (!msg_ugid)
11245c51f124SMoriah Waterland 				echo(MSG_ATTRIB, ept->path);
11255c51f124SMoriah Waterland 
11265c51f124SMoriah Waterland 			/* fix the attributes now for robustness sake */
11275c51f124SMoriah Waterland 			if (averify(1, &ept->ftype,
11285c51f124SMoriah Waterland 				ept->path,
11295c51f124SMoriah Waterland 				&ept->ainfo) == 0) {
11305c51f124SMoriah Waterland 				mstat->attrchg = 0;
11315c51f124SMoriah Waterland 			}
11325c51f124SMoriah Waterland 		}
11335c51f124SMoriah Waterland 
11345c51f124SMoriah Waterland 		/*
1135*6e1ae2a3SGary Pennington 		 * package object exists, or does not need updating:
1136*6e1ae2a3SGary Pennington 		 * treat the object as if it were "updated"
11375c51f124SMoriah Waterland 		 */
11385c51f124SMoriah Waterland 
11395c51f124SMoriah Waterland 		/* LINTED warning: statement has no consequent: if */
11405c51f124SMoriah Waterland 		if ((stateFlag == B_FALSE) || (ept == (struct cfent *)NULL)) {
11415c51f124SMoriah Waterland 			/*
11425c51f124SMoriah Waterland 			 * the object in question is a directory or special
11435c51f124SMoriah Waterland 			 * file - the fact that this type of object already
11445c51f124SMoriah Waterland 			 * exists or does not need updating must not trigger
1145*6e1ae2a3SGary Pennington 			 * the object updated indication - that would cause
1146*6e1ae2a3SGary Pennington 			 * class action scripts to be run when installing a
1147*6e1ae2a3SGary Pennington 			 * new non-global zone
11485c51f124SMoriah Waterland 			 */
11495c51f124SMoriah Waterland 		} else {
11505c51f124SMoriah Waterland 			if (r_updated != (char **)NULL) {
11515c51f124SMoriah Waterland 				if (*r_updated == (char *)NULL) {
11525c51f124SMoriah Waterland 					echoDebug(DBG_INSTVOL_OBJ_UPDATED,
11535c51f124SMoriah Waterland 								ept->path);
11545c51f124SMoriah Waterland 				}
11555c51f124SMoriah Waterland 				*r_updated = ept->path;
11565c51f124SMoriah Waterland 			}
11575c51f124SMoriah Waterland 		}
11585c51f124SMoriah Waterland 	}
11595c51f124SMoriah Waterland 
11605c51f124SMoriah Waterland 	if (maxvol == part) {
11615c51f124SMoriah Waterland 		eocflag++;	/* endofclass */
11625c51f124SMoriah Waterland 	}
11635c51f124SMoriah Waterland 
11645c51f124SMoriah Waterland 	return (DMRG_DONE);	/* no remaining entries on this volume */
11655c51f124SMoriah Waterland }
11665c51f124SMoriah Waterland 
11675c51f124SMoriah Waterland /*
11685c51f124SMoriah Waterland  * Determine if the provided directory is populated. Return 0 if so and 1 if
11695c51f124SMoriah Waterland  * not. This also returns 0 if the dirpath is not a directory or if it does
11705c51f124SMoriah Waterland  * not exist.
11715c51f124SMoriah Waterland  */
11725c51f124SMoriah Waterland static int
11735c51f124SMoriah Waterland dir_is_populated(char *dirpath) {
11745c51f124SMoriah Waterland 	DIR	*dirfp;
11755c51f124SMoriah Waterland 	struct	dirent *drp;
11765c51f124SMoriah Waterland 	int	retcode = 0;
11775c51f124SMoriah Waterland 
11785c51f124SMoriah Waterland 	if ((dirfp = opendir(dirpath)) != NULL) {
11795c51f124SMoriah Waterland 		while ((drp = readdir(dirfp)) != NULL) {
11805c51f124SMoriah Waterland 			if (strcmp(drp->d_name, ".") == 0) {
11815c51f124SMoriah Waterland 				continue;
11825c51f124SMoriah Waterland 			}
11835c51f124SMoriah Waterland 			if (strcmp(drp->d_name, "..") == 0) {
11845c51f124SMoriah Waterland 				continue;
11855c51f124SMoriah Waterland 			}
11865c51f124SMoriah Waterland 			/*
11875c51f124SMoriah Waterland 			 * If we get here, there's a real file in the
11885c51f124SMoriah Waterland 			 * directory
11895c51f124SMoriah Waterland 			 */
11905c51f124SMoriah Waterland 			retcode = 1;
11915c51f124SMoriah Waterland 			break;
11925c51f124SMoriah Waterland 		}
11935c51f124SMoriah Waterland 		(void) closedir(dirfp);
11945c51f124SMoriah Waterland 	}
11955c51f124SMoriah Waterland 
11965c51f124SMoriah Waterland 	return (retcode);
11975c51f124SMoriah Waterland }
11985c51f124SMoriah Waterland 
11995c51f124SMoriah Waterland /*
12005c51f124SMoriah Waterland  * This is the function that cleans up the installation of this class.
12015c51f124SMoriah Waterland  * This is where hard links get put in since the stuff they're linking
12025c51f124SMoriah Waterland  * probably exists by now.
12035c51f124SMoriah Waterland  */
12045c51f124SMoriah Waterland static void
12055c51f124SMoriah Waterland endofclass(struct cfextra **extlist, int myclass, int ckflag,
120662224350SCasper H.S. Dik 	PKGserver pkgserver, VFP_T **a_cfTmpVfp)
12075c51f124SMoriah Waterland {
12085c51f124SMoriah Waterland 	char		*temppath;
12095c51f124SMoriah Waterland 	char 		*pspool_loc;
12105c51f124SMoriah Waterland 	char 		*relocpath = (char *)NULL;
12115c51f124SMoriah Waterland 	char 		scrpt_dst[PATH_MAX];
12125c51f124SMoriah Waterland 	int		flag;
12135c51f124SMoriah Waterland 	int		idx;
12145c51f124SMoriah Waterland 	int		n;
12155c51f124SMoriah Waterland 	struct cfent	*ept;	/* entry from the internal list */
12165c51f124SMoriah Waterland 	struct cfextra	entry;	/* entry from the package database */
12175c51f124SMoriah Waterland 	struct mergstat	*mstat;	/* merge status */
12185c51f124SMoriah Waterland 	struct pinfo	*pinfo;
12195c51f124SMoriah Waterland 
12205c51f124SMoriah Waterland 	/* open the package database (contents) file */
12215c51f124SMoriah Waterland 
122262224350SCasper H.S. Dik 	if (!ocfile(&pkgserver, a_cfTmpVfp, pkgmap_blks)) {
12235c51f124SMoriah Waterland 		quit(99);
12245c51f124SMoriah Waterland 	}
12255c51f124SMoriah Waterland 
12265c51f124SMoriah Waterland 	echo(MSG_VERIFYING_CLASS, cl_nam(myclass));
12275c51f124SMoriah Waterland 
12285c51f124SMoriah Waterland 	for (idx = 0; /* void */; idx++) {
12295c51f124SMoriah Waterland 		/* find next package object in this class */
12305c51f124SMoriah Waterland 		while (extlist[idx]) {
12315c51f124SMoriah Waterland 			if ((extlist[idx]->cf_ent.ftype != 'i') &&
12325c51f124SMoriah Waterland 				extlist[idx]->cf_ent.pkg_class_idx == myclass) {
12335c51f124SMoriah Waterland 				break;
12345c51f124SMoriah Waterland 			}
12355c51f124SMoriah Waterland 			idx++;
12365c51f124SMoriah Waterland 		}
12375c51f124SMoriah Waterland 
123862224350SCasper H.S. Dik 		if (extlist[idx] == NULL)
12395c51f124SMoriah Waterland 			break;
124062224350SCasper H.S. Dik 
12415c51f124SMoriah Waterland 
12425c51f124SMoriah Waterland 		ept = &(extlist[idx]->cf_ent);
12435c51f124SMoriah Waterland 		mstat = &(extlist[idx]->mstat);
12445c51f124SMoriah Waterland 
124562224350SCasper H.S. Dik 		temppath = extlist[idx]->client_path;
12465c51f124SMoriah Waterland 
12475c51f124SMoriah Waterland 		/*
12485c51f124SMoriah Waterland 		 * At this point  the only difference between the entry
12495c51f124SMoriah Waterland 		 * in the contents file and the entry in extlist[] is
12505c51f124SMoriah Waterland 		 * that the status indicator contains CONFIRM_CONT.
125162224350SCasper H.S. Dik 		 * This function should return one or something is wrong.
12525c51f124SMoriah Waterland 		 */
12535c51f124SMoriah Waterland 
125462224350SCasper H.S. Dik 		n = srchcfile(&(entry.cf_ent), temppath, pkgserver);
12555c51f124SMoriah Waterland 
125662224350SCasper H.S. Dik 		if (n < 0) {
12575c51f124SMoriah Waterland 			char	*errstr = getErrstr();
12585c51f124SMoriah Waterland 			progerr(ERR_CFBAD);
125962224350SCasper H.S. Dik 			logerr(gettext("pathname=%s"),
12605c51f124SMoriah Waterland 				entry.cf_ent.path && *entry.cf_ent.path ?
12615c51f124SMoriah Waterland 				entry.cf_ent.path : "Unknown");
126262224350SCasper H.S. Dik 			logerr(gettext("problem=%s"),
12635c51f124SMoriah Waterland 				(errstr && *errstr) ? errstr : "Unknown");
12645c51f124SMoriah Waterland 			quit(99);
12655c51f124SMoriah Waterland 		} else if (n != 1) {
12665c51f124SMoriah Waterland 			/*
12675c51f124SMoriah Waterland 			 * Check if path should be in the package
12685c51f124SMoriah Waterland 			 * database.
12695c51f124SMoriah Waterland 			 */
12705c51f124SMoriah Waterland 			if ((mstat->shared && nocnflct)) {
12715c51f124SMoriah Waterland 				continue;
12725c51f124SMoriah Waterland 			}
12735c51f124SMoriah Waterland 			progerr(ERR_CFMISSING, ept->path);
12745c51f124SMoriah Waterland 			quit(99);
12755c51f124SMoriah Waterland 		}
12765c51f124SMoriah Waterland 
12775c51f124SMoriah Waterland 		/*
12785c51f124SMoriah Waterland 		 * If merge was not appropriate for this object, now is the
12795c51f124SMoriah Waterland 		 * time to choose one or the other.
12805c51f124SMoriah Waterland 		 */
12815c51f124SMoriah Waterland 		if (mstat->denied) {
12825c51f124SMoriah Waterland 			/*
12835c51f124SMoriah Waterland 			 * If installation was denied AFTER the package
12845c51f124SMoriah Waterland 			 * database was updated, skip this. We've already
12855c51f124SMoriah Waterland 			 * announced the discrepancy and the verifications
12865c51f124SMoriah Waterland 			 * that follow will make faulty decisions based on
12875c51f124SMoriah Waterland 			 * the ftype, which may not be correct.
12885c51f124SMoriah Waterland 			 */
12895c51f124SMoriah Waterland 			progerr(ERR_COULD_NOT_INSTALL, ept->path);
12905c51f124SMoriah Waterland 			warnflag++;
12915c51f124SMoriah Waterland 		} else {
12925c51f124SMoriah Waterland 			if (mstat->replace)
12935c51f124SMoriah Waterland 				/*
12945c51f124SMoriah Waterland 				 * This replaces the old entry with the new
12955c51f124SMoriah Waterland 				 * one. This should never happen in the new
12965c51f124SMoriah Waterland 				 * DB since the entries are already identical.
12975c51f124SMoriah Waterland 				 */
12985c51f124SMoriah Waterland 				repl_cfent(ept, &(entry.cf_ent));
12995c51f124SMoriah Waterland 
13005c51f124SMoriah Waterland 			/*
13015c51f124SMoriah Waterland 			 * Validate this entry and change the status flag in
13025c51f124SMoriah Waterland 			 * the package database.
13035c51f124SMoriah Waterland 			 */
13045c51f124SMoriah Waterland 			if (ept->ftype == RM_RDY) {
13055c51f124SMoriah Waterland 				(void) eptstat(&(entry.cf_ent), pkginst,
13065c51f124SMoriah Waterland 					STAT_NEXT);
13075c51f124SMoriah Waterland 			} else {
13085c51f124SMoriah Waterland 				/* check the hard link now. */
13095c51f124SMoriah Waterland 				if (ept->ftype == 'l') {
13105c51f124SMoriah Waterland 					if (averify(0, &ept->ftype,
13115c51f124SMoriah Waterland 						ept->path, &ept->ainfo)) {
13125c51f124SMoriah Waterland 						echo(MSG_HRDLINK,
13135c51f124SMoriah Waterland 							ept->path);
13145c51f124SMoriah Waterland 						mstat->attrchg++;
13155c51f124SMoriah Waterland 					}
13165c51f124SMoriah Waterland 				}
13175c51f124SMoriah Waterland 
13185c51f124SMoriah Waterland 				/*
13195c51f124SMoriah Waterland 				 * Don't install or verify objects for
13205c51f124SMoriah Waterland 				 * remote, read-only filesystems.  We need
13215c51f124SMoriah Waterland 				 * only flag them as shared from some server.
13225c51f124SMoriah Waterland 				 * Otherwise, ok to do final check.
13235c51f124SMoriah Waterland 				 */
13245c51f124SMoriah Waterland 				if (is_remote_fs(ept->path,
13255c51f124SMoriah Waterland 					&(extlist[idx]->fsys_value)) &&
13265c51f124SMoriah Waterland 					!is_fs_writeable(ept->path,
13275c51f124SMoriah Waterland 					&(extlist[idx]->fsys_value))) {
13285c51f124SMoriah Waterland 					flag = -1;
13295c51f124SMoriah Waterland 				} else {
13305c51f124SMoriah Waterland 					flag = finalck(ept, mstat->attrchg,
13315c51f124SMoriah Waterland 						(ckflag ? mstat->contchg :
1332*6e1ae2a3SGary Pennington 						(-1)), B_FALSE);
13335c51f124SMoriah Waterland 				}
13345c51f124SMoriah Waterland 
13355c51f124SMoriah Waterland 				pinfo = entry.cf_ent.pinfo;
13365c51f124SMoriah Waterland 
13375c51f124SMoriah Waterland 				/* Find this package in the list. */
13385c51f124SMoriah Waterland 				while (pinfo) {
13395c51f124SMoriah Waterland 					if (strcmp(pkginst, pinfo->pkg) == 0) {
13405c51f124SMoriah Waterland 						break;
13415c51f124SMoriah Waterland 					}
13425c51f124SMoriah Waterland 					pinfo = pinfo->next;
13435c51f124SMoriah Waterland 				}
13445c51f124SMoriah Waterland 
13455c51f124SMoriah Waterland 				/*
13465c51f124SMoriah Waterland 				 * If this package owns this file, then store
13475c51f124SMoriah Waterland 				 * it in the database with the appropriate
13485c51f124SMoriah Waterland 				 * status. Need to check pinfo in case it
13495c51f124SMoriah Waterland 				 * points to NULL which could happen if
13505c51f124SMoriah Waterland 				 * pinfo->next = NULL above.
13515c51f124SMoriah Waterland 				 */
13525c51f124SMoriah Waterland 				if (pinfo) {
13535c51f124SMoriah Waterland 					if (flag < 0 || is_served(ept->path,
13545c51f124SMoriah Waterland 						&(extlist[idx]->fsys_value))) {
13555c51f124SMoriah Waterland 						/*
13565c51f124SMoriah Waterland 						 * This is provided to
13575c51f124SMoriah Waterland 						 * clients by a server.
13585c51f124SMoriah Waterland 						 */
13595c51f124SMoriah Waterland 						pinfo->status = SERVED_FILE;
13605c51f124SMoriah Waterland 					} else {
13615c51f124SMoriah Waterland 						/*
13625c51f124SMoriah Waterland 						 * It's either there or it's
13635c51f124SMoriah Waterland 						 * not.
13645c51f124SMoriah Waterland 						 */
13655c51f124SMoriah Waterland 						pinfo->status = (flag ?
13665c51f124SMoriah Waterland 							NOT_FND : ENTRY_OK);
13675c51f124SMoriah Waterland 					}
13685c51f124SMoriah Waterland 				}
13695c51f124SMoriah Waterland 			}
13705c51f124SMoriah Waterland 		}
13715c51f124SMoriah Waterland 
13725c51f124SMoriah Waterland 		/*
13735c51f124SMoriah Waterland 		 * If not installing from a partially spooled package, the
13745c51f124SMoriah Waterland 		 * "save/pspool" area, and the file contents can be
13755c51f124SMoriah Waterland 		 * changed (type is 'e' or 'v'), and the class IS "none":
13765c51f124SMoriah Waterland 		 * copy the installed volatile file into the appropriate
13775c51f124SMoriah Waterland 		 * location in the packages destination "save/pspool" area.
13785c51f124SMoriah Waterland 		 */
13795c51f124SMoriah Waterland 
13805c51f124SMoriah Waterland 		if ((!is_partial_inst()) &&
13815c51f124SMoriah Waterland 			((ept->ftype == 'e') || (ept->ftype == 'v')) &&
13825c51f124SMoriah Waterland 			(strcmp(ept->pkg_class, "none") == 0)) {
13835c51f124SMoriah Waterland 
13845c51f124SMoriah Waterland 			if (absolutepath(extlist[idx]->map_path) == B_TRUE &&
13855c51f124SMoriah Waterland 				parametricpath(extlist[idx]->cf_ent.ainfo.local,
13865c51f124SMoriah Waterland 					&relocpath) == B_FALSE) {
13875c51f124SMoriah Waterland 				pspool_loc = ROOT;
13885c51f124SMoriah Waterland 			} else {
13895c51f124SMoriah Waterland 				pspool_loc = RELOC;
13905c51f124SMoriah Waterland 			}
13915c51f124SMoriah Waterland 
13925c51f124SMoriah Waterland 			n = snprintf(scrpt_dst, PATH_MAX, "%s/%s/%s",
13935c51f124SMoriah Waterland 				saveSpoolInstallDir, pspool_loc,
13945c51f124SMoriah Waterland 				relocpath ? relocpath : extlist[idx]->map_path);
13955c51f124SMoriah Waterland 
13965c51f124SMoriah Waterland 			if (n >= PATH_MAX) {
13975c51f124SMoriah Waterland 				progerr(ERR_CREATE_PATH_2,
13985c51f124SMoriah Waterland 					saveSpoolInstallDir,
13995c51f124SMoriah Waterland 					extlist[idx]->map_path);
14005c51f124SMoriah Waterland 				quit(99);
14015c51f124SMoriah Waterland 			}
14025c51f124SMoriah Waterland 
14035c51f124SMoriah Waterland 			/* copy, preserve source file mode */
14045c51f124SMoriah Waterland 
14055c51f124SMoriah Waterland 			if (cppath(MODE_SRC, ept->path, scrpt_dst, 0644)) {
14065c51f124SMoriah Waterland 				warnflag++;
14075c51f124SMoriah Waterland 			}
14085c51f124SMoriah Waterland 		}
14095c51f124SMoriah Waterland 
14105c51f124SMoriah Waterland 		/*
14115c51f124SMoriah Waterland 		 * Now insert this potentially changed package database
14125c51f124SMoriah Waterland 		 * entry.
14135c51f124SMoriah Waterland 		 */
14145c51f124SMoriah Waterland 		if (entry.cf_ent.npkgs) {
14155c51f124SMoriah Waterland 			if (putcvfpfile(&(entry.cf_ent), *a_cfTmpVfp)) {
14165c51f124SMoriah Waterland 				quit(99);
14175c51f124SMoriah Waterland 			}
14185c51f124SMoriah Waterland 		}
14195c51f124SMoriah Waterland 	}
14205c51f124SMoriah Waterland 
142162224350SCasper H.S. Dik 	n = swapcfile(pkgserver, a_cfTmpVfp, pkginst, dbchg);
14225c51f124SMoriah Waterland 	if (n == RESULT_WRN) {
14235c51f124SMoriah Waterland 		warnflag++;
14245c51f124SMoriah Waterland 	} else if (n == RESULT_ERR) {
14255c51f124SMoriah Waterland 		quit(99);
14265c51f124SMoriah Waterland 	}
14275c51f124SMoriah Waterland }
14285c51f124SMoriah Waterland 
14295c51f124SMoriah Waterland /*
14305c51f124SMoriah Waterland  * This function goes through and fixes all the attributes. This is called
14315c51f124SMoriah Waterland  * out by using DST_QKVERIFY=this_class in the pkginfo file. The primary
14325c51f124SMoriah Waterland  * use for this is to fix up files installed by a class action script
14335c51f124SMoriah Waterland  * which is time-critical and reliable enough to assume likely success.
14345c51f124SMoriah Waterland  * The first such format was for WOS compressed-cpio'd file sets.
14355c51f124SMoriah Waterland  * The second format is the Class Archive Format.
14365c51f124SMoriah Waterland  */
14375c51f124SMoriah Waterland static int
14385c51f124SMoriah Waterland fix_attributes(struct cfextra **extlist, int idx)
14395c51f124SMoriah Waterland {
14405c51f124SMoriah Waterland 	struct	cfextra *ext;
14415c51f124SMoriah Waterland 	int	i, retval = 1;
14425c51f124SMoriah Waterland 	int 	nc = cl_getn();
14435c51f124SMoriah Waterland 	int	n;
14445c51f124SMoriah Waterland 	struct cfent *ept;
14455c51f124SMoriah Waterland 	struct mergstat *mstat;
14465c51f124SMoriah Waterland 	char scrpt_dst[PATH_MAX];
14475c51f124SMoriah Waterland 	char *pspool_loc;
14485c51f124SMoriah Waterland 	char *relocpath = (char *)NULL;
14495c51f124SMoriah Waterland 
14505c51f124SMoriah Waterland 	for (i = 0; extlist[i]; i++) {
14515c51f124SMoriah Waterland 		ext = extlist[i];
14525c51f124SMoriah Waterland 		ept = &(extlist[i]->cf_ent);
14535c51f124SMoriah Waterland 		mstat = &(extlist[i]->mstat);
14545c51f124SMoriah Waterland 
14555c51f124SMoriah Waterland 		/*
14565c51f124SMoriah Waterland 		 * We don't care about 'i'nfo files because, they
14575c51f124SMoriah Waterland 		 * aren't laid down, 'e'ditable files can change
14585c51f124SMoriah Waterland 		 * anyway, so who cares and 's'ymlinks were already
14595c51f124SMoriah Waterland 		 * fixed in domerg(); however, certain old WOS
14605c51f124SMoriah Waterland 		 * package symlinks depend on a bug in the old
14615c51f124SMoriah Waterland 		 * pkgadd which has recently been expunged. For
14625c51f124SMoriah Waterland 		 * those packages in 2.2, we repeat the verification
14635c51f124SMoriah Waterland 		 * of symlinks.
14645c51f124SMoriah Waterland 		 *
14655c51f124SMoriah Waterland 		 * By 2.6 or so, ftype == 's' should be added to this.
14665c51f124SMoriah Waterland 		 */
14675c51f124SMoriah Waterland 		if (ept->ftype == 'i' || ept->ftype == 'e' ||
14685c51f124SMoriah Waterland 			(mstat->shared && nocnflct))
14695c51f124SMoriah Waterland 			continue;
14705c51f124SMoriah Waterland 
14715c51f124SMoriah Waterland 		if (mstat->denied) {
14725c51f124SMoriah Waterland 			progerr(ERR_COULD_NOT_INSTALL, ept->path);
14735c51f124SMoriah Waterland 			warnflag++;
14745c51f124SMoriah Waterland 			continue;
14755c51f124SMoriah Waterland 		}
14765c51f124SMoriah Waterland 
14775c51f124SMoriah Waterland 		if (ept->pkg_class_idx < 0 || ept->pkg_class_idx > nc) {
14785c51f124SMoriah Waterland 			progerr(ERR_CLIDX, ept->pkg_class_idx,
14795c51f124SMoriah Waterland 			    (ept->path && *ept->path) ? ept->path : "unknown");
14805c51f124SMoriah Waterland 			continue;
14815c51f124SMoriah Waterland 		}
14825c51f124SMoriah Waterland 
14835c51f124SMoriah Waterland 		/* If this is the right class, do the fast verify. */
14845c51f124SMoriah Waterland 		if (ept->pkg_class_idx == idx) {
14855c51f124SMoriah Waterland 			if (fverify(1, &ept->ftype, ept->path,
14865c51f124SMoriah Waterland 				&ept->ainfo, &ept->cinfo) == 0) {
14875c51f124SMoriah Waterland 				mstat->attrchg = 0;
14885c51f124SMoriah Waterland 				mstat->contchg =  0;
14895c51f124SMoriah Waterland 			} else	/* We'll try full verify later */
14905c51f124SMoriah Waterland 				retval = 0;
14915c51f124SMoriah Waterland 		}
14925c51f124SMoriah Waterland 		/*
14935c51f124SMoriah Waterland 		 * Need to copy the installed volitale file back to the
14945c51f124SMoriah Waterland 		 * partial spooled area if we are installing to a local zone
14955c51f124SMoriah Waterland 		 * or similar installation method.
14965c51f124SMoriah Waterland 		 */
14975c51f124SMoriah Waterland 
14985c51f124SMoriah Waterland 		if ((!is_partial_inst()) &&
14995c51f124SMoriah Waterland 			((ept->ftype == 'e') || (ept->ftype == 'v')) &&
15005c51f124SMoriah Waterland 			(strcmp(ept->pkg_class, "none") == 0)) {
15015c51f124SMoriah Waterland 
15025c51f124SMoriah Waterland 			if (absolutepath(ext->map_path) == B_TRUE &&
15035c51f124SMoriah Waterland 				parametricpath(ext->cf_ent.ainfo.local,
15045c51f124SMoriah Waterland 					&relocpath) == B_FALSE) {
15055c51f124SMoriah Waterland 				pspool_loc = ROOT;
15065c51f124SMoriah Waterland 			} else {
15075c51f124SMoriah Waterland 				pspool_loc = RELOC;
15085c51f124SMoriah Waterland 			}
15095c51f124SMoriah Waterland 
15105c51f124SMoriah Waterland 			n = snprintf(scrpt_dst, PATH_MAX, "%s/%s/%s",
15115c51f124SMoriah Waterland 				saveSpoolInstallDir, pspool_loc,
15125c51f124SMoriah Waterland 				relocpath ? relocpath : ext->map_path);
15135c51f124SMoriah Waterland 
15145c51f124SMoriah Waterland 			if (n >= PATH_MAX) {
15155c51f124SMoriah Waterland 				progerr(ERR_CREATE_PATH_2,
15165c51f124SMoriah Waterland 					saveSpoolInstallDir,
15175c51f124SMoriah Waterland 					ext->map_path);
15185c51f124SMoriah Waterland 				quit(99);
15195c51f124SMoriah Waterland 			}
15205c51f124SMoriah Waterland 
15215c51f124SMoriah Waterland 			/* copy, preserve source file mode */
15225c51f124SMoriah Waterland 
15235c51f124SMoriah Waterland 			if (cppath(MODE_SRC, ept->path, scrpt_dst, 0644)) {
15245c51f124SMoriah Waterland 				warnflag++;
15255c51f124SMoriah Waterland 			}
15265c51f124SMoriah Waterland 		}
15275c51f124SMoriah Waterland 	}
15285c51f124SMoriah Waterland 
15295c51f124SMoriah Waterland 	return (retval);
15305c51f124SMoriah Waterland }
15315c51f124SMoriah Waterland 
15325c51f124SMoriah Waterland /*
15335c51f124SMoriah Waterland  * Check to see if first charcter in path is a '/'.
15345c51f124SMoriah Waterland  *
15355c51f124SMoriah Waterland  * Return:
15365c51f124SMoriah Waterland  * 			B_TRUE - if path is prepended with '/'
15375c51f124SMoriah Waterland  * 			B_FALSE - if not
15385c51f124SMoriah Waterland  */
15395c51f124SMoriah Waterland static boolean_t
15405c51f124SMoriah Waterland absolutepath(char *path)
15415c51f124SMoriah Waterland {
15425c51f124SMoriah Waterland 	assert(path != NULL);
15435c51f124SMoriah Waterland 	assert(path[0] != '\0');
15445c51f124SMoriah Waterland 
15455c51f124SMoriah Waterland 	return (path[0] == '/' ? B_TRUE : B_FALSE);
15465c51f124SMoriah Waterland }
15475c51f124SMoriah Waterland 
15485c51f124SMoriah Waterland /*
15495c51f124SMoriah Waterland  * Check to see if path contains a '$' which makes it
15505c51f124SMoriah Waterland  * a parametric path and therefore relocatable.
15515c51f124SMoriah Waterland  *
15525c51f124SMoriah Waterland  * Parameters:
15535c51f124SMoriah Waterland  *             path - The path to determine if it is absolute
15545c51f124SMoriah Waterland  *             relocpath - The value of the unconditioned path
15555c51f124SMoriah Waterland  *                         i.e. $OPTDIR/usr/ls
15565c51f124SMoriah Waterland  * Return:
15575c51f124SMoriah Waterland  * 			B_TRUE - if path is a parametric path
15585c51f124SMoriah Waterland  * 			B_FALSE - if not
15595c51f124SMoriah Waterland  */
15605c51f124SMoriah Waterland static boolean_t
15615c51f124SMoriah Waterland parametricpath(char *path, char **relocpath)
15625c51f124SMoriah Waterland {
15635c51f124SMoriah Waterland 	assert(path != NULL);
15645c51f124SMoriah Waterland 	assert(path[0] != '\0');
15655c51f124SMoriah Waterland 
15665c51f124SMoriah Waterland 	/*
15675c51f124SMoriah Waterland 	 * If this is a valid parametric path then a '$' MUST occur at the
15685c51f124SMoriah Waterland 	 * first or second character.
15695c51f124SMoriah Waterland 	 */
15705c51f124SMoriah Waterland 
15715c51f124SMoriah Waterland 	if (path[0] == '$' || path[1] == '$') {
15725c51f124SMoriah Waterland 		/*
15735c51f124SMoriah Waterland 		 * If a parametric path exists then when copying the
15745c51f124SMoriah Waterland 		 * path to the pspool directoy from the installing
15755c51f124SMoriah Waterland 		 * pkgs reloc directory we want to use the uncononditional
15765c51f124SMoriah Waterland 		 * varaiable path.
15775c51f124SMoriah Waterland 		 */
15785c51f124SMoriah Waterland 		*relocpath = (path + 1);
15795c51f124SMoriah Waterland 		return (B_TRUE);
15805c51f124SMoriah Waterland 	}
15815c51f124SMoriah Waterland 	return (B_FALSE);
15825c51f124SMoriah Waterland }
15835c51f124SMoriah Waterland 
15845c51f124SMoriah Waterland void
15855c51f124SMoriah Waterland regfiles_free()
15865c51f124SMoriah Waterland {
15875c51f124SMoriah Waterland 	if (regfiles_head != NULL) {
15885c51f124SMoriah Waterland 		struct reg_files *rfp = regfiles_head->next;
15895c51f124SMoriah Waterland 
15905c51f124SMoriah Waterland 		while (rfp != NULL) {
15915c51f124SMoriah Waterland 			free(regfiles_head);
15925c51f124SMoriah Waterland 			regfiles_head = rfp;
15935c51f124SMoriah Waterland 			rfp = regfiles_head->next;
15945c51f124SMoriah Waterland 		}
15955c51f124SMoriah Waterland 		free(regfiles_head);
15965c51f124SMoriah Waterland 		regfiles_head = NULL;
15975c51f124SMoriah Waterland 	}
15985c51f124SMoriah Waterland }
1599