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