xref: /onnv-gate/usr/src/cmd/svr4pkg/libinst/setlist.c (revision 9781:ccf49524d5dc)
1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM  *
4*9781SMoriah.Waterland@Sun.COM  * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM  * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM  * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM  *
8*9781SMoriah.Waterland@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM  * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM  * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM  *
13*9781SMoriah.Waterland@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM  *
19*9781SMoriah.Waterland@Sun.COM  * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM  */
21*9781SMoriah.Waterland@Sun.COM 
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*9781SMoriah.Waterland@Sun.COM  * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM  */
26*9781SMoriah.Waterland@Sun.COM 
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM 
30*9781SMoriah.Waterland@Sun.COM 
31*9781SMoriah.Waterland@Sun.COM 
32*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
33*9781SMoriah.Waterland@Sun.COM #include <errno.h>
34*9781SMoriah.Waterland@Sun.COM #include <string.h>
35*9781SMoriah.Waterland@Sun.COM #include <ctype.h>
36*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
37*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
38*9781SMoriah.Waterland@Sun.COM #include <locale.h>
39*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
40*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
41*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
42*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
43*9781SMoriah.Waterland@Sun.COM 
44*9781SMoriah.Waterland@Sun.COM int	cl_NClasses = -1;
45*9781SMoriah.Waterland@Sun.COM static int	cl_handle = -1;	/* list array handle */
46*9781SMoriah.Waterland@Sun.COM 
47*9781SMoriah.Waterland@Sun.COM struct cl_attr	**cl_Classes = NULL;
48*9781SMoriah.Waterland@Sun.COM 
49*9781SMoriah.Waterland@Sun.COM static int new_order;
50*9781SMoriah.Waterland@Sun.COM static struct cl_attr	*new_cl_attr(char *cl_name);
51*9781SMoriah.Waterland@Sun.COM 
52*9781SMoriah.Waterland@Sun.COM static unsigned	s_verify(char *class_name), d_verify(char *class_name);
53*9781SMoriah.Waterland@Sun.COM static unsigned	s_pathtype(char *class_name);
54*9781SMoriah.Waterland@Sun.COM 
55*9781SMoriah.Waterland@Sun.COM #define	MALSIZ	64
56*9781SMoriah.Waterland@Sun.COM #define	ERR_MEMORY	"memory allocation failure"
57*9781SMoriah.Waterland@Sun.COM 
58*9781SMoriah.Waterland@Sun.COM static struct cl_attr *
new_cl_attr(char * cl_name)59*9781SMoriah.Waterland@Sun.COM new_cl_attr(char *cl_name)
60*9781SMoriah.Waterland@Sun.COM {
61*9781SMoriah.Waterland@Sun.COM 	struct cl_attr *class, **class_ptr;
62*9781SMoriah.Waterland@Sun.COM 
63*9781SMoriah.Waterland@Sun.COM 	if (cl_handle == -1) {
64*9781SMoriah.Waterland@Sun.COM 		cl_handle = ar_create(MALSIZ, sizeof (struct cl_attr),
65*9781SMoriah.Waterland@Sun.COM 		    "package class");
66*9781SMoriah.Waterland@Sun.COM 		if (cl_handle == -1) {
67*9781SMoriah.Waterland@Sun.COM 			progerr(gettext(ERR_MEMORY));
68*9781SMoriah.Waterland@Sun.COM 			return (NULL);
69*9781SMoriah.Waterland@Sun.COM 		}
70*9781SMoriah.Waterland@Sun.COM 	}
71*9781SMoriah.Waterland@Sun.COM 
72*9781SMoriah.Waterland@Sun.COM 	class_ptr = (struct cl_attr **)ar_next_avail(cl_handle);
73*9781SMoriah.Waterland@Sun.COM 
74*9781SMoriah.Waterland@Sun.COM 	if (class_ptr == NULL || *class_ptr == NULL) {
75*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_MEMORY));
76*9781SMoriah.Waterland@Sun.COM 		return (NULL);
77*9781SMoriah.Waterland@Sun.COM 	}
78*9781SMoriah.Waterland@Sun.COM 
79*9781SMoriah.Waterland@Sun.COM 	class = *class_ptr;
80*9781SMoriah.Waterland@Sun.COM 
81*9781SMoriah.Waterland@Sun.COM 	strcpy(class->name, cl_name);
82*9781SMoriah.Waterland@Sun.COM 	class->inst_script = NULL;
83*9781SMoriah.Waterland@Sun.COM 	class->rem_script = NULL;
84*9781SMoriah.Waterland@Sun.COM 	class->src_verify = s_verify(cl_name);
85*9781SMoriah.Waterland@Sun.COM 	class->dst_verify = d_verify(cl_name);
86*9781SMoriah.Waterland@Sun.COM 	class->relpath_2_CAS = s_pathtype(cl_name);
87*9781SMoriah.Waterland@Sun.COM 
88*9781SMoriah.Waterland@Sun.COM 	return (class);
89*9781SMoriah.Waterland@Sun.COM }
90*9781SMoriah.Waterland@Sun.COM 
91*9781SMoriah.Waterland@Sun.COM /* Insert a single class into the list. */
92*9781SMoriah.Waterland@Sun.COM void
addlist(struct cl_attr *** listp,char * item)93*9781SMoriah.Waterland@Sun.COM addlist(struct cl_attr ***listp, char *item)
94*9781SMoriah.Waterland@Sun.COM {
95*9781SMoriah.Waterland@Sun.COM 	int	i;
96*9781SMoriah.Waterland@Sun.COM 
97*9781SMoriah.Waterland@Sun.COM 	/* If the list is already there, scan for this item */
98*9781SMoriah.Waterland@Sun.COM 	if (*listp) {
99*9781SMoriah.Waterland@Sun.COM 		for (i = 0; (*listp)[i]; i++)
100*9781SMoriah.Waterland@Sun.COM 			if (strcmp(item, (*listp)[i]->name) == 0)
101*9781SMoriah.Waterland@Sun.COM 				return;
102*9781SMoriah.Waterland@Sun.COM 	} else {
103*9781SMoriah.Waterland@Sun.COM 		i = 0;
104*9781SMoriah.Waterland@Sun.COM 	}
105*9781SMoriah.Waterland@Sun.COM 
106*9781SMoriah.Waterland@Sun.COM 	/* Insert the new entry */
107*9781SMoriah.Waterland@Sun.COM 	if (new_cl_attr(item) == NULL)
108*9781SMoriah.Waterland@Sun.COM 		quit(99);
109*9781SMoriah.Waterland@Sun.COM 
110*9781SMoriah.Waterland@Sun.COM 	/* Point the passed pointer to the head of the list. */
111*9781SMoriah.Waterland@Sun.COM 	(*listp) = (struct cl_attr **)ar_get_head(cl_handle);
112*9781SMoriah.Waterland@Sun.COM }
113*9781SMoriah.Waterland@Sun.COM 
114*9781SMoriah.Waterland@Sun.COM /*
115*9781SMoriah.Waterland@Sun.COM  * Create a list of all classes involved in this installation as well as
116*9781SMoriah.Waterland@Sun.COM  * their attributes.
117*9781SMoriah.Waterland@Sun.COM  */
118*9781SMoriah.Waterland@Sun.COM int
setlist(struct cl_attr *** plist,char * slist)119*9781SMoriah.Waterland@Sun.COM setlist(struct cl_attr ***plist, char *slist)
120*9781SMoriah.Waterland@Sun.COM {
121*9781SMoriah.Waterland@Sun.COM 	struct cl_attr	**list, *struct_ptr;
122*9781SMoriah.Waterland@Sun.COM 	char	*pt;
123*9781SMoriah.Waterland@Sun.COM 	int	n;
124*9781SMoriah.Waterland@Sun.COM 	int	i;
125*9781SMoriah.Waterland@Sun.COM 	int	sn = -1;
126*9781SMoriah.Waterland@Sun.COM 
127*9781SMoriah.Waterland@Sun.COM 	/* Initialize the environment scanners. */
128*9781SMoriah.Waterland@Sun.COM 	(void) s_verify(NULL);
129*9781SMoriah.Waterland@Sun.COM 	(void) d_verify(NULL);
130*9781SMoriah.Waterland@Sun.COM 	(void) s_pathtype(NULL);
131*9781SMoriah.Waterland@Sun.COM 
132*9781SMoriah.Waterland@Sun.COM 	n = 0;
133*9781SMoriah.Waterland@Sun.COM 
134*9781SMoriah.Waterland@Sun.COM 	/*
135*9781SMoriah.Waterland@Sun.COM 	 * This looks like a serious memory leak, however pkgmk depends on
136*9781SMoriah.Waterland@Sun.COM 	 * this creating a second list and forgetting any prior ones. The
137*9781SMoriah.Waterland@Sun.COM 	 * pkgmk utility does a reasonable job of keeping track of a prior
138*9781SMoriah.Waterland@Sun.COM 	 * list constructed from the prototype file using addlist() above.
139*9781SMoriah.Waterland@Sun.COM 	 * Perhaps this should be reviewed later, but I do not believe this
140*9781SMoriah.Waterland@Sun.COM 	 * to be a problem from what I've seen. - JST
141*9781SMoriah.Waterland@Sun.COM 	 */
142*9781SMoriah.Waterland@Sun.COM 	cl_handle = -1;		/* forget other lists */
143*9781SMoriah.Waterland@Sun.COM 
144*9781SMoriah.Waterland@Sun.COM 	/* Isolate the first token. */
145*9781SMoriah.Waterland@Sun.COM 	pt = strtok(slist, " \t\n");
146*9781SMoriah.Waterland@Sun.COM 	while (pt) {
147*9781SMoriah.Waterland@Sun.COM 		if (sn == -1 && strcmp(pt, "none") == 0)
148*9781SMoriah.Waterland@Sun.COM 			sn = n;
149*9781SMoriah.Waterland@Sun.COM 
150*9781SMoriah.Waterland@Sun.COM 		/* Add new class to list. */
151*9781SMoriah.Waterland@Sun.COM 		if ((struct_ptr = new_cl_attr(pt)) == NULL)
152*9781SMoriah.Waterland@Sun.COM 			quit(99);
153*9781SMoriah.Waterland@Sun.COM 
154*9781SMoriah.Waterland@Sun.COM 		/* Next token. */
155*9781SMoriah.Waterland@Sun.COM 		n++;
156*9781SMoriah.Waterland@Sun.COM 		pt = strtok(NULL, " \t\n");
157*9781SMoriah.Waterland@Sun.COM 		if (pt && sn != -1)
158*9781SMoriah.Waterland@Sun.COM 			if (strcmp(pt, "none") == 0)
159*9781SMoriah.Waterland@Sun.COM 				pt = strtok(NULL, " \t\n");
160*9781SMoriah.Waterland@Sun.COM 	}
161*9781SMoriah.Waterland@Sun.COM 	/*
162*9781SMoriah.Waterland@Sun.COM 	 * According to the ABI, if there is a class "none", it will be
163*9781SMoriah.Waterland@Sun.COM 	 * the first class to be installed.  This insures that iff there
164*9781SMoriah.Waterland@Sun.COM 	 * is a class "none", it will be the first to be installed.
165*9781SMoriah.Waterland@Sun.COM 	 * If there is no class "none", nothing happens!
166*9781SMoriah.Waterland@Sun.COM 	 */
167*9781SMoriah.Waterland@Sun.COM 	new_order = 0;
168*9781SMoriah.Waterland@Sun.COM 
169*9781SMoriah.Waterland@Sun.COM 	/* Get the head of the array. */
170*9781SMoriah.Waterland@Sun.COM 	list = (struct cl_attr **)ar_get_head(cl_handle);
171*9781SMoriah.Waterland@Sun.COM 
172*9781SMoriah.Waterland@Sun.COM 	if (sn > 0) {
173*9781SMoriah.Waterland@Sun.COM 		struct_ptr = list[sn];
174*9781SMoriah.Waterland@Sun.COM 		for (i = sn; i > 0; i--)
175*9781SMoriah.Waterland@Sun.COM 			list[i] = list[i - 1];
176*9781SMoriah.Waterland@Sun.COM 		list[0] = struct_ptr;
177*9781SMoriah.Waterland@Sun.COM 		new_order++;	/* the order is different now */
178*9781SMoriah.Waterland@Sun.COM 	}
179*9781SMoriah.Waterland@Sun.COM 
180*9781SMoriah.Waterland@Sun.COM 	/* Point the passed pointer to the head of the list. */
181*9781SMoriah.Waterland@Sun.COM 	*plist = list;
182*9781SMoriah.Waterland@Sun.COM 
183*9781SMoriah.Waterland@Sun.COM 	return (n);
184*9781SMoriah.Waterland@Sun.COM }
185*9781SMoriah.Waterland@Sun.COM 
186*9781SMoriah.Waterland@Sun.COM /* Process the class list from the caller. */
187*9781SMoriah.Waterland@Sun.COM void
cl_sets(char * slist)188*9781SMoriah.Waterland@Sun.COM cl_sets(char *slist)
189*9781SMoriah.Waterland@Sun.COM {
190*9781SMoriah.Waterland@Sun.COM 	char *list_ptr;
191*9781SMoriah.Waterland@Sun.COM 
192*9781SMoriah.Waterland@Sun.COM 	/* If there is a list, process it; else skip it */
193*9781SMoriah.Waterland@Sun.COM 	if (slist && *slist) {
194*9781SMoriah.Waterland@Sun.COM 		list_ptr = qstrdup(slist);
195*9781SMoriah.Waterland@Sun.COM 
196*9781SMoriah.Waterland@Sun.COM 		if (list_ptr && *list_ptr) {
197*9781SMoriah.Waterland@Sun.COM 			cl_NClasses = setlist(&cl_Classes, list_ptr);
198*9781SMoriah.Waterland@Sun.COM 			if (new_order)		/* if list order changed ... */
199*9781SMoriah.Waterland@Sun.COM 				/* ... tell the environment. */
200*9781SMoriah.Waterland@Sun.COM 				cl_putl("CLASSES", cl_Classes);
201*9781SMoriah.Waterland@Sun.COM 		}
202*9781SMoriah.Waterland@Sun.COM 	}
203*9781SMoriah.Waterland@Sun.COM }
204*9781SMoriah.Waterland@Sun.COM 
205*9781SMoriah.Waterland@Sun.COM int
cl_getn(void)206*9781SMoriah.Waterland@Sun.COM cl_getn(void)
207*9781SMoriah.Waterland@Sun.COM {
208*9781SMoriah.Waterland@Sun.COM 	return (cl_NClasses);
209*9781SMoriah.Waterland@Sun.COM }
210*9781SMoriah.Waterland@Sun.COM 
211*9781SMoriah.Waterland@Sun.COM /*
212*9781SMoriah.Waterland@Sun.COM  * Since the order may have changed, this puts the CLASSES list back into
213*9781SMoriah.Waterland@Sun.COM  * the environment in the precise order to be used.
214*9781SMoriah.Waterland@Sun.COM  */
215*9781SMoriah.Waterland@Sun.COM void
cl_putl(char * parm_name,struct cl_attr ** list)216*9781SMoriah.Waterland@Sun.COM cl_putl(char *parm_name, struct cl_attr **list)
217*9781SMoriah.Waterland@Sun.COM {
218*9781SMoriah.Waterland@Sun.COM 	int i;
219*9781SMoriah.Waterland@Sun.COM 	size_t j;
220*9781SMoriah.Waterland@Sun.COM 	char *pt = NULL;
221*9781SMoriah.Waterland@Sun.COM 
222*9781SMoriah.Waterland@Sun.COM 	if (list && *list) {
223*9781SMoriah.Waterland@Sun.COM 		j = 1; /* room for ending null */
224*9781SMoriah.Waterland@Sun.COM 		for (i = 0; list[i]; i++)
225*9781SMoriah.Waterland@Sun.COM 			j += strlen(list[i]->name) + 1;
226*9781SMoriah.Waterland@Sun.COM 		pt = calloc(j, sizeof (char));
227*9781SMoriah.Waterland@Sun.COM 		(void) strcpy(pt, list[0]->name);
228*9781SMoriah.Waterland@Sun.COM 		for (i = 1; list[i]; i++) {
229*9781SMoriah.Waterland@Sun.COM 			(void) strcat(pt, " ");
230*9781SMoriah.Waterland@Sun.COM 			(void) strcat(pt, list[i]->name);
231*9781SMoriah.Waterland@Sun.COM 		}
232*9781SMoriah.Waterland@Sun.COM 		if (parm_name && *parm_name)
233*9781SMoriah.Waterland@Sun.COM 			putparam(parm_name, pt);
234*9781SMoriah.Waterland@Sun.COM 		free(pt);
235*9781SMoriah.Waterland@Sun.COM 	}
236*9781SMoriah.Waterland@Sun.COM }
237*9781SMoriah.Waterland@Sun.COM 
238*9781SMoriah.Waterland@Sun.COM 
239*9781SMoriah.Waterland@Sun.COM int
cl_idx(char * cl_nam)240*9781SMoriah.Waterland@Sun.COM cl_idx(char *cl_nam)
241*9781SMoriah.Waterland@Sun.COM {
242*9781SMoriah.Waterland@Sun.COM 	int	n;
243*9781SMoriah.Waterland@Sun.COM 
244*9781SMoriah.Waterland@Sun.COM 	for (n = 0; n < cl_NClasses; n++)
245*9781SMoriah.Waterland@Sun.COM 		if (strcmp(cl_Classes[n]->name, cl_nam) == 0)
246*9781SMoriah.Waterland@Sun.COM 			return (n);
247*9781SMoriah.Waterland@Sun.COM 	return (-1);
248*9781SMoriah.Waterland@Sun.COM }
249*9781SMoriah.Waterland@Sun.COM 
250*9781SMoriah.Waterland@Sun.COM /* Return source verification level for this class */
251*9781SMoriah.Waterland@Sun.COM unsigned
cl_svfy(int idx)252*9781SMoriah.Waterland@Sun.COM cl_svfy(int idx)
253*9781SMoriah.Waterland@Sun.COM {
254*9781SMoriah.Waterland@Sun.COM 	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
255*9781SMoriah.Waterland@Sun.COM 		return (cl_Classes[idx]->src_verify);
256*9781SMoriah.Waterland@Sun.COM 	return (0);
257*9781SMoriah.Waterland@Sun.COM }
258*9781SMoriah.Waterland@Sun.COM 
259*9781SMoriah.Waterland@Sun.COM /* Return destination verify level for this class */
260*9781SMoriah.Waterland@Sun.COM unsigned
cl_dvfy(int idx)261*9781SMoriah.Waterland@Sun.COM cl_dvfy(int idx)
262*9781SMoriah.Waterland@Sun.COM {
263*9781SMoriah.Waterland@Sun.COM 	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
264*9781SMoriah.Waterland@Sun.COM 		return (cl_Classes[idx]->dst_verify);
265*9781SMoriah.Waterland@Sun.COM 	return (0);
266*9781SMoriah.Waterland@Sun.COM }
267*9781SMoriah.Waterland@Sun.COM 
268*9781SMoriah.Waterland@Sun.COM /* Return path argument type for this class. */
269*9781SMoriah.Waterland@Sun.COM unsigned
cl_pthrel(int idx)270*9781SMoriah.Waterland@Sun.COM cl_pthrel(int idx)
271*9781SMoriah.Waterland@Sun.COM {
272*9781SMoriah.Waterland@Sun.COM 	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
273*9781SMoriah.Waterland@Sun.COM 		return (cl_Classes[idx]->relpath_2_CAS);
274*9781SMoriah.Waterland@Sun.COM 	return (0);
275*9781SMoriah.Waterland@Sun.COM }
276*9781SMoriah.Waterland@Sun.COM 
277*9781SMoriah.Waterland@Sun.COM /* Return the class name associated with this class index */
278*9781SMoriah.Waterland@Sun.COM char *
cl_nam(int idx)279*9781SMoriah.Waterland@Sun.COM cl_nam(int idx)
280*9781SMoriah.Waterland@Sun.COM {
281*9781SMoriah.Waterland@Sun.COM 	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
282*9781SMoriah.Waterland@Sun.COM 		return (cl_Classes[idx]->name);
283*9781SMoriah.Waterland@Sun.COM 	return (NULL);
284*9781SMoriah.Waterland@Sun.COM }
285*9781SMoriah.Waterland@Sun.COM 
286*9781SMoriah.Waterland@Sun.COM void
cl_setl(struct cl_attr ** cl_lst)287*9781SMoriah.Waterland@Sun.COM cl_setl(struct cl_attr **cl_lst)
288*9781SMoriah.Waterland@Sun.COM {
289*9781SMoriah.Waterland@Sun.COM 	int	i;
290*9781SMoriah.Waterland@Sun.COM 	int	sn = -1;
291*9781SMoriah.Waterland@Sun.COM 	struct cl_attr	*pt;
292*9781SMoriah.Waterland@Sun.COM 
293*9781SMoriah.Waterland@Sun.COM 	if (cl_lst) {
294*9781SMoriah.Waterland@Sun.COM 		for (cl_NClasses = 0; cl_lst[cl_NClasses]; cl_NClasses++)
295*9781SMoriah.Waterland@Sun.COM 			if (strcmp(cl_lst[cl_NClasses]->name, "none") == 0)
296*9781SMoriah.Waterland@Sun.COM 				if (sn == -1)
297*9781SMoriah.Waterland@Sun.COM 					sn = cl_NClasses;
298*9781SMoriah.Waterland@Sun.COM 		if (sn > 0) {
299*9781SMoriah.Waterland@Sun.COM 			pt = cl_lst[sn];
300*9781SMoriah.Waterland@Sun.COM 			for (i = sn; i > 0; i--)
301*9781SMoriah.Waterland@Sun.COM 				cl_lst[i] = cl_lst[i - 1];
302*9781SMoriah.Waterland@Sun.COM 			cl_lst[0] = pt;
303*9781SMoriah.Waterland@Sun.COM 		}
304*9781SMoriah.Waterland@Sun.COM 		i = 1;
305*9781SMoriah.Waterland@Sun.COM 		while (i < cl_NClasses) {
306*9781SMoriah.Waterland@Sun.COM 			if (strcmp(cl_lst[i]->name, "none") == 0)
307*9781SMoriah.Waterland@Sun.COM 				for (sn = i; sn < (cl_NClasses - 1); sn++)
308*9781SMoriah.Waterland@Sun.COM 					cl_lst[sn] = cl_lst[sn + 1];
309*9781SMoriah.Waterland@Sun.COM 			i++;
310*9781SMoriah.Waterland@Sun.COM 		}
311*9781SMoriah.Waterland@Sun.COM 		cl_Classes = cl_lst;
312*9781SMoriah.Waterland@Sun.COM 	} else {
313*9781SMoriah.Waterland@Sun.COM 		cl_Classes = NULL;
314*9781SMoriah.Waterland@Sun.COM 		cl_NClasses = -1;
315*9781SMoriah.Waterland@Sun.COM 	}
316*9781SMoriah.Waterland@Sun.COM }
317*9781SMoriah.Waterland@Sun.COM 
318*9781SMoriah.Waterland@Sun.COM /*
319*9781SMoriah.Waterland@Sun.COM  * Scan the given environment variable for an occurrance of the given
320*9781SMoriah.Waterland@Sun.COM  * class name. Return 0 if not found or 1 if found.
321*9781SMoriah.Waterland@Sun.COM  */
322*9781SMoriah.Waterland@Sun.COM static unsigned
is_in_env(char * class_name,char * paramname,char ** paramvalue,int * noentry)323*9781SMoriah.Waterland@Sun.COM is_in_env(char *class_name, char *paramname, char **paramvalue, int *noentry)
324*9781SMoriah.Waterland@Sun.COM {
325*9781SMoriah.Waterland@Sun.COM 	unsigned retval = 0;
326*9781SMoriah.Waterland@Sun.COM 	char *test_class;
327*9781SMoriah.Waterland@Sun.COM 
328*9781SMoriah.Waterland@Sun.COM 	if (class_name && *class_name) {
329*9781SMoriah.Waterland@Sun.COM 		/*
330*9781SMoriah.Waterland@Sun.COM 		 * If a prior getenv() has not failed and there is no
331*9781SMoriah.Waterland@Sun.COM 		 * environment string then get environment info on
332*9781SMoriah.Waterland@Sun.COM 		 * this parameter.
333*9781SMoriah.Waterland@Sun.COM 		 */
334*9781SMoriah.Waterland@Sun.COM 		if (!(*noentry) && *paramvalue == NULL) {
335*9781SMoriah.Waterland@Sun.COM 			*paramvalue = getenv(paramname);
336*9781SMoriah.Waterland@Sun.COM 			if (*paramvalue == NULL)
337*9781SMoriah.Waterland@Sun.COM 				(*noentry)++;
338*9781SMoriah.Waterland@Sun.COM 		}
339*9781SMoriah.Waterland@Sun.COM 
340*9781SMoriah.Waterland@Sun.COM 		/* If there's something there, evaluate it. */
341*9781SMoriah.Waterland@Sun.COM 		if (!(*noentry)) {
342*9781SMoriah.Waterland@Sun.COM 			int n;
343*9781SMoriah.Waterland@Sun.COM 
344*9781SMoriah.Waterland@Sun.COM 			n = strlen(class_name);	/* end of class name */
345*9781SMoriah.Waterland@Sun.COM 			test_class = *paramvalue;	/* environ ptr */
346*9781SMoriah.Waterland@Sun.COM 
347*9781SMoriah.Waterland@Sun.COM 			while (test_class = strstr(test_class, class_name)) {
348*9781SMoriah.Waterland@Sun.COM 				/*
349*9781SMoriah.Waterland@Sun.COM 				 * At this point we have a pointer to a
350*9781SMoriah.Waterland@Sun.COM 				 * substring within param that matches
351*9781SMoriah.Waterland@Sun.COM 				 * class_name for its length, but class_name
352*9781SMoriah.Waterland@Sun.COM 				 * may be a substring of the test_class, so
353*9781SMoriah.Waterland@Sun.COM 				 * we check that next.
354*9781SMoriah.Waterland@Sun.COM 				 */
355*9781SMoriah.Waterland@Sun.COM 				if (isspace(*(test_class + n)) ||
356*9781SMoriah.Waterland@Sun.COM 				    *(test_class + n) == '\0') {
357*9781SMoriah.Waterland@Sun.COM 					retval = 1;
358*9781SMoriah.Waterland@Sun.COM 					break;
359*9781SMoriah.Waterland@Sun.COM 				}
360*9781SMoriah.Waterland@Sun.COM 				if (*(++test_class) == '\0')
361*9781SMoriah.Waterland@Sun.COM 					break;
362*9781SMoriah.Waterland@Sun.COM 			}
363*9781SMoriah.Waterland@Sun.COM 		}
364*9781SMoriah.Waterland@Sun.COM 	}
365*9781SMoriah.Waterland@Sun.COM 	return (retval);
366*9781SMoriah.Waterland@Sun.COM }
367*9781SMoriah.Waterland@Sun.COM 
368*9781SMoriah.Waterland@Sun.COM /* Assign source path verification level to this class */
369*9781SMoriah.Waterland@Sun.COM static unsigned
s_verify(char * class_name)370*9781SMoriah.Waterland@Sun.COM s_verify(char *class_name)
371*9781SMoriah.Waterland@Sun.COM {
372*9781SMoriah.Waterland@Sun.COM 	static int noentry;
373*9781SMoriah.Waterland@Sun.COM 	static char *noverify;
374*9781SMoriah.Waterland@Sun.COM 
375*9781SMoriah.Waterland@Sun.COM 	if (class_name == NULL) {	/* initialize */
376*9781SMoriah.Waterland@Sun.COM 		noentry = 0;
377*9781SMoriah.Waterland@Sun.COM 		noverify = NULL;
378*9781SMoriah.Waterland@Sun.COM 	} else {
379*9781SMoriah.Waterland@Sun.COM 		if (is_in_env(class_name, "PKG_SRC_NOVERIFY", &noverify,
380*9781SMoriah.Waterland@Sun.COM 		    &noentry))
381*9781SMoriah.Waterland@Sun.COM 			return (NOVERIFY);
382*9781SMoriah.Waterland@Sun.COM 		else
383*9781SMoriah.Waterland@Sun.COM 			return (DEFAULT);
384*9781SMoriah.Waterland@Sun.COM 	}
385*9781SMoriah.Waterland@Sun.COM 	return (0);
386*9781SMoriah.Waterland@Sun.COM }
387*9781SMoriah.Waterland@Sun.COM 
388*9781SMoriah.Waterland@Sun.COM /*
389*9781SMoriah.Waterland@Sun.COM  * Set destination verify to default. This is usually called by pkgdbmerg()
390*9781SMoriah.Waterland@Sun.COM  * in order to correct verification conflicts.
391*9781SMoriah.Waterland@Sun.COM  */
392*9781SMoriah.Waterland@Sun.COM void
cl_def_dverify(int idx)393*9781SMoriah.Waterland@Sun.COM cl_def_dverify(int idx)
394*9781SMoriah.Waterland@Sun.COM {
395*9781SMoriah.Waterland@Sun.COM 	if (cl_Classes && idx >= 0 && idx < cl_NClasses)
396*9781SMoriah.Waterland@Sun.COM 		cl_Classes[idx]->dst_verify = DEFAULT;
397*9781SMoriah.Waterland@Sun.COM }
398*9781SMoriah.Waterland@Sun.COM 
399*9781SMoriah.Waterland@Sun.COM /* Assign destination path verification level to this path. */
400*9781SMoriah.Waterland@Sun.COM static unsigned
d_verify(char * class_name)401*9781SMoriah.Waterland@Sun.COM d_verify(char *class_name)
402*9781SMoriah.Waterland@Sun.COM {
403*9781SMoriah.Waterland@Sun.COM 	static int noentry;
404*9781SMoriah.Waterland@Sun.COM 	static char *qkverify;
405*9781SMoriah.Waterland@Sun.COM 
406*9781SMoriah.Waterland@Sun.COM 	if (class_name == NULL) {	/* initialize */
407*9781SMoriah.Waterland@Sun.COM 		noentry = 0;
408*9781SMoriah.Waterland@Sun.COM 		qkverify = NULL;
409*9781SMoriah.Waterland@Sun.COM 	} else {
410*9781SMoriah.Waterland@Sun.COM 		if (is_in_env(class_name, "PKG_DST_QKVERIFY", &qkverify,
411*9781SMoriah.Waterland@Sun.COM 		    &noentry))
412*9781SMoriah.Waterland@Sun.COM 			return (QKVERIFY);
413*9781SMoriah.Waterland@Sun.COM 		else
414*9781SMoriah.Waterland@Sun.COM 			return (DEFAULT);
415*9781SMoriah.Waterland@Sun.COM 	}
416*9781SMoriah.Waterland@Sun.COM 	return (0);
417*9781SMoriah.Waterland@Sun.COM }
418*9781SMoriah.Waterland@Sun.COM 
419*9781SMoriah.Waterland@Sun.COM /* Assign CAS path type to this class */
420*9781SMoriah.Waterland@Sun.COM static unsigned
s_pathtype(char * class_name)421*9781SMoriah.Waterland@Sun.COM s_pathtype(char *class_name)
422*9781SMoriah.Waterland@Sun.COM {
423*9781SMoriah.Waterland@Sun.COM 	static int noentry;
424*9781SMoriah.Waterland@Sun.COM 	static char *type_list;
425*9781SMoriah.Waterland@Sun.COM 
426*9781SMoriah.Waterland@Sun.COM 	if (class_name == NULL) {	/* initialize */
427*9781SMoriah.Waterland@Sun.COM 		noentry = 0;
428*9781SMoriah.Waterland@Sun.COM 		type_list = NULL;
429*9781SMoriah.Waterland@Sun.COM 	} else {
430*9781SMoriah.Waterland@Sun.COM 		if (is_in_env(class_name, "PKG_CAS_PASSRELATIVE", &type_list,
431*9781SMoriah.Waterland@Sun.COM 		    &noentry))
432*9781SMoriah.Waterland@Sun.COM 			return (REL_2_CAS);
433*9781SMoriah.Waterland@Sun.COM 		else
434*9781SMoriah.Waterland@Sun.COM 			return (DEFAULT);
435*9781SMoriah.Waterland@Sun.COM 	}
436*9781SMoriah.Waterland@Sun.COM 	return (0);
437*9781SMoriah.Waterland@Sun.COM }
438