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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
/*
* 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 2009 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 <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <dirent.h>
#include <sys/stat.h>
#include <pkginfo.h>
#include <pkglocs.h>
#include <sys/types.h>
#include <pkgstrct.h>
#include <pkgtrans.h>
#include <locale.h>
#include <libintl.h>
#include <pkglib.h>
#include <libadm.h>
#include <libinst.h>
#define MAXPATHS 1024
#define MSG_CHK_STRM "Checking uninstalled stream format package " \
"<%s> from <%s>\n"
#define MSG_CHK_DIR "Checking uninstalled directory format package " \
"<%s> from <%s>\n"
#define MSG_NOTROOT "NOTE: \"root\" permission may be required to " \
"validate all objects in the client filesystem."
#define MSG_CONT "Continuing."
#define WRN_F_SPOOL "WARNING: %s is spooled. Ignoring \"f\" argument"
#define ERR_ROOT_SET "Could not set install root from the environment."
#define ERR_ROOT_CMD "Command line install root contends with environment."
#define ERR_IOPEN "unable to open input file <%s>"
#define ERR_IEMPTY "no pathnames in file specified by -i option"
#define ERR_POPTION "no pathname included with -p option"
#define ERR_PARTIAL_POPTION "no pathname included with -P option"
#define ERR_MAXPATHS "too many pathnames in option list (limit is %d)"
#define ERR_NOTROOT "You must be \"root\" for \"%s -f\" to" \
"execute properly."
#define ERR_SEL_PKG "No packages selected for verification."
#define ERR_CAT_LNGTH "The category argument exceeds the SVr4 ABI\n" \
" defined maximum supported length of 16 characters."
#define ERR_CAT_FND "Category argument <%s> cannot be found."
#define ERR_CAT_INV "Category argument <%s> is invalid."
#define ERR_TOO_MANY "too many pathnames in list, limit is %d"
#define ERR_PATHS_INVALID "Pathnames in %s are not valid."
#define ERR_MKDIR "unable to make directory <%s>"
#define ERR_USAGE "usage:\n" \
"\t%s [-l|vqacnxf] [-R rootdir] [-p path[, ...] | " \
"-P path[, ...]]\n" \
"\t\t[-i file] [options]\n" \
"\t%s -d device [-f][-l|v] [-p path[, ...] | " \
"-P path[, ...]]\n" \
"\t\t[-V ...] [-M] [-i file] [-Y category[, ...] | " \
"pkginst [...]]\n" \
"\twhere options may include ONE of the " \
"following:\n " \
"\t\t-m pkgmap [-e envfile]\n" \
"\t\tpkginst [...]\n" \
"\t\t-Y category[, ...]\n"
#define LINK 1
char **pkg = NULL;
int pkgcnt = 0;
char *basedir;
char *pathlist[MAXPATHS], *ppathlist[MAXPATHS], pkgspool[PATH_MAX];
short used[MAXPATHS];
short npaths;
struct cfent **eptlist;
int aflag = (-1);
int cflag = (-1);
int vflag = 0;
int nflag = 0;
int lflag = 0;
int Lflag = 0;
int fflag = 0;
int xflag = 0;
int qflag = 0;
int Rflag = 0;
int dflag = 0;
char *device;
char *uniTmp;
static char *mapfile,
*spooldir,
*tmpdir,
*envfile;
static int errflg = 0;
static int map_client = 1;
void quit(int);
static void setpathlist(char *);
static void usage(void);
extern char **environ;
extern char *pkgdir;
/* checkmap.c */
extern int checkmap(int, int, char *, char *, char *, char *, int);
/* scriptvfy.c */
extern int checkscripts(char *inst_dir, int silent);
int
main(int argc, char *argv[])
{
int pkgfmt = 0; /* Makes more sense as a pointer, but */
/* 18N is compromised. */
char file[PATH_MAX+1],
*abi_sym_ptr,
*vfstab_file = NULL;
char *all_pkgs[4] = {"all", NULL};
char **category = NULL;
char *catg_arg = NULL;
int c;
int n = 0;
char *prog,
*Rvalue,
*dvalue;
int dbcreate = 0;
int pathtype;
/* initialize locale mechanism */
(void) setlocale(LC_ALL, "");
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
/* determine program name */
prog = set_prog_name(argv[0]);
/* establish installation root directory */
if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) {
progerr(gettext(ERR_ROOT_SET));
quit(1);
}
/* check if not ABI compliant mode */
abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS");
if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0) {
set_nonABI_symlinks();
}
/* bugId 4012147 */
if ((uniTmp = getenv("PKG_NO_UNIFIED")) != NULL)
map_client = 0;
while ((c = getopt(argc, argv, "Y:R:e:p:d:nLli:vaV:Mm:cqxfQP:?"))
!= EOF) {
switch (c) {
case 'p':
pathlist[npaths] = strtok(optarg, " , ");
if (pathlist[npaths++] == NULL) {
progerr(gettext(ERR_POPTION));
quit(1);
}
while (pathlist[npaths] = strtok(NULL, " , ")) {
if (npaths++ >= MAXPATHS) {
progerr(gettext(ERR_MAXPATHS),
MAXPATHS);
quit(1);
}
}
break;
case 'd':
dvalue = optarg;
dflag = 1;
break;
case 'n':
nflag++;
break;
case 'M':
map_client = 0;
break;
/*
* Allow admin to establish the client filesystem using a
* vfstab-like file of stable format.
*/
case 'V':
vfstab_file = flex_device(optarg, 2);
map_client = 1;
break;
case 'f':
if (getuid()) {
progerr(gettext(ERR_NOTROOT), prog);
quit(1);
}
fflag++;
break;
case 'i':
setpathlist(optarg);
break;
case 'v':
vflag++;
break;
case 'l':
lflag++;
break;
case 'L':
Lflag++;
break;
case 'x':
if (aflag < 0)
aflag = 0;
if (cflag < 0)
cflag = 0;
xflag++;
break;
case 'q':
qflag++;
break;
case 'a':
if (cflag < 0)
cflag = 0;
aflag = 1;
break;
case 'c':
if (aflag < 0)
aflag = 0;
cflag = 1;
break;
case 'e':
envfile = optarg;
break;
case 'm':
mapfile = optarg;
break;
case 'R':
Rvalue = optarg;
Rflag = 1;
break;
case 'Y':
catg_arg = strdup(optarg);
if ((category = get_categories(catg_arg)) == NULL) {
progerr(gettext(ERR_CAT_INV), catg_arg);
quit(1);
} else if (is_not_valid_length(category)) {
progerr(gettext(ERR_CAT_LNGTH));
quit(1);
}
break;
case 'Q':
dbcreate++;
break;
case 'P':
ppathlist[npaths] = strtok(optarg, " , ");
if ((ppathlist[npaths] == NULL) ||
(ppathlist[npaths][0] == '-')) {
progerr(gettext(ERR_PARTIAL_POPTION));
quit(1);
}
npaths++;
while (ppathlist[npaths] = strtok(NULL, " , ")) {
if (npaths++ >= MAXPATHS) {
progerr(gettext(ERR_MAXPATHS),
MAXPATHS);
quit(1);
}
}
break;
default:
usage();
/*NOTREACHED*/
/*
* Although usage() calls a noreturn function,
* needed to add return (1); so that main() would
* pass compilation checks. The statement below
* should never be executed.
*/
return (1);
}
}
/* Check for incompatible options */
if (dflag && Rflag)
usage();
/* Check for root dir and device dir if set */
if (Rflag) {
if (!set_inst_root(Rvalue)) {
progerr(gettext(ERR_ROOT_CMD));
quit(1);
}
}
if (dflag)
device = flex_device(dvalue, 1);
if (lflag || Lflag) {
/* we're only supposed to list information */
if ((cflag >= 0) || (aflag >= 0) ||
qflag || xflag || fflag || nflag || vflag)
usage();
}
set_PKGpaths(get_inst_root());
if (catg_arg != NULL && device == NULL) {
if (argc - optind) {
usage();
}
pkg = gpkglist(pkgdir, all_pkgs, category);
if (pkg == NULL) {
progerr(gettext(ERR_CAT_FND), catg_arg);
quit(1);
} else {
for (pkgcnt = 0; pkg[pkgcnt] != NULL; pkgcnt++);
}
} else if (catg_arg != NULL && optind < argc) {
usage();
} else {
pkg = &argv[optind];
pkgcnt = (argc - optind);
}
/* read the environment for the pkgserver */
pkgserversetmode(DEFAULTMODE);
environ = NULL; /* Sever the parent environment. */
if (vcfile() == 0) {
quit(99);
}
errflg = 0;
if (mapfile) {
/* check for incompatible options */
if (device || pkgcnt)
usage();
put_path_params(); /* Restore what's needed. */
/* send pathtype if partial path */
pathtype = (ppathlist[0] != NULL) ? 1 : 0;
if (checkmap(0, (device != NULL), mapfile, envfile, NULL,
NULL, pathtype))
errflg++;
} else if (device) {
/* check for incompatible options */
if ((cflag >= 0) || (aflag >= 0))
usage();
if (qflag || xflag || nflag || envfile)
usage();
tmpdir = NULL;
if ((spooldir = devattr(device, "pathname")) == NULL)
spooldir = device;
if (isdir(spooldir)) {
tmpdir = spooldir = qstrdup(tmpnam(NULL));
if (fflag) {
logerr(gettext(WRN_F_SPOOL), *pkg);
fflag = 0;
}
if (mkdir(spooldir, 0755)) {
progerr(gettext(ERR_MKDIR), spooldir);
quit(99);
}
if (n = pkgtrans(device, spooldir, pkg, PT_SILENT,
NULL, NULL))
quit(n);
if (catg_arg != NULL)
pkg = gpkglist(spooldir, all_pkgs, category);
else
pkg = gpkglist(spooldir, all_pkgs, NULL);
pkgfmt = 0;
} else {
if (catg_arg != NULL)
pkg = gpkglist(spooldir,
pkgcnt ? pkg : all_pkgs, category);
else
pkg = gpkglist(spooldir,
pkgcnt ? pkg : all_pkgs, NULL);
pkgfmt = 1;
}
/*
* At this point pkg[] is the list of packages to check. They
* are in directory format in spooldir.
*/
if (pkg == NULL) {
if (catg_arg != NULL) {
progerr(gettext(ERR_CAT_FND), catg_arg);
quit(1);
} else {
progerr(gettext(ERR_SEL_PKG));
quit(1);
}
}
aflag = 0;
for (n = 0; pkg[n]; n++) {
char locenv[PATH_MAX];
if (pkgfmt)
(void) printf(
gettext(MSG_CHK_DIR), pkg[n], device);
else
(void) printf(
gettext(MSG_CHK_STRM), pkg[n], device);
(void) snprintf(pkgspool, sizeof (pkgspool),
"%s/%s", spooldir, pkg[n]);
(void) snprintf(file, sizeof (file),
"%s/install", pkgspool);
/* Here we check the install scripts. */
(void) printf(
gettext("## Checking control scripts.\n"));
(void) checkscripts(file, 0);
/* Verify consistency with the pkgmap. */
(void) printf(
gettext("## Checking package objects.\n"));
(void) snprintf(file, sizeof (file),
"%s/pkgmap", pkgspool);
(void) snprintf(locenv, sizeof (locenv),
"%s/pkginfo", pkgspool);
envfile = locenv;
/*
* NOTE : checkmap() frees the environ data and
* pointer when it's through with them.
*/
if (checkmap(0, (device != NULL), file, envfile,
pkg[n], NULL, 0))
errflg++;
(void) printf(
gettext("## Checking is complete.\n"));
}
} else {
if (envfile)
usage();
put_path_params(); /* Restore what's needed. */
/*
* If this is a check of a client of some sort, we'll need to
* mount up the client's filesystems. If the caller isn't
* root, this may not be possible.
*/
if (is_an_inst_root()) {
if (getuid()) {
logerr(gettext(MSG_NOTROOT));
logerr(gettext(MSG_CONT));
} else {
if (get_mntinfo(map_client, vfstab_file))
map_client = 0;
if (map_client)
mount_client();
}
}
(void) snprintf(file, sizeof (file),
"%s/contents", get_PKGADM());
if (ppathlist[0] != NULL) {
for (n = 0; ppathlist[n]; n++) {
if (checkmap(1, (device != NULL), file, NULL,
NULL, ppathlist[n], 1))
errflg++;
}
} else if (pkg[0] != NULL) {
if (checkmap(1, (device != NULL), file, NULL,
pkg[0], NULL, 0)) {
errflg++;
}
} else {
if (checkmap(1, (device != NULL), file, NULL,
NULL, NULL, 0)) {
errflg++;
}
}
if (map_client) {
unmount_client();
}
}
quit(errflg ? 1 : 0);
/* LINTED: no return */
}
static void
setpathlist(char *file)
{
int fd;
struct stat st;
FILE *fplist;
char pathname[PATH_MAX];
/*
* This trap laid to catch a mismatch between the declaration above and
* the hard-coded constant in the fscanf below
*/
#if PATH_MAX != 1024
#error "PATH_MAX changed, so we have a bug to fix"
#endif
if (strcmp(file, "-") == 0) {
fplist = stdin;
} else {
if ((fd = open(file, O_RDONLY)) == -1) {
progerr(gettext(ERR_IOPEN), file);
quit(1);
}
if (fstat(fd, &st) == -1) {
progerr(gettext(ERR_IOPEN), file);
quit(1);
}
if (S_ISDIR(st.st_mode) || S_ISBLK(st.st_mode)) {
progerr(gettext(ERR_PATHS_INVALID), file);
quit(1);
}
if ((fplist = fdopen(fd, "r")) == NULL) {
progerr(gettext(ERR_IOPEN), file);
quit(1);
}
}
while (fscanf(fplist, "%1024s", pathname) == 1) {
if (*pathname == '\0') {
progerr(gettext(ERR_PATHS_INVALID), file);
quit(1);
}
pathlist[npaths] = qstrdup(pathname);
if (npaths++ > MAXPATHS) {
progerr(gettext(ERR_TOO_MANY), MAXPATHS);
quit(1);
}
}
if (npaths == 0) {
progerr(gettext(ERR_IEMPTY));
quit(1);
}
(void) fclose(fplist);
}
void
quit(int n)
{
/* cleanup any temporary directories */
(void) chdir("/");
if (tmpdir != NULL) {
(void) rrmdir(tmpdir);
free(tmpdir);
tmpdir = NULL;
}
(void) pkghead(NULL);
exit(n);
/*NOTREACHED*/
}
static void
usage(void)
{
char *prog = get_prog_name();
(void) fprintf(stderr, gettext(ERR_USAGE), prog, prog);
quit(1);
/*NOTREACHED*/
}
|