summaryrefslogtreecommitdiff
path: root/usr/src/cmd/svr4pkg/pkginstall/check.c
blob: 1f320adab296dd68d9a884ad10e11f62ee92dc5d (plain)
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
/*
 * 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 <limits.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>	/* mkdir declaration is here? */
#include <unistd.h>
#include <errno.h>
#include <utmpx.h>
#include <dirent.h>
#include <sys/types.h>
#include <locale.h>
#include <libintl.h>
#include <pkgstrct.h>
#include <pkglocs.h>
#include "install.h"
#include <pkglib.h>
#include "libadm.h"
#include "libinst.h"
#include "pkginstall.h"

extern struct admin adm;
extern struct cfextra **extlist;
extern int	ckquit, nocnflct, nosetuid, rprcflag;
extern char	ilockfile[], rlockfile[], instdir[], savlog[],
		tmpdir[], pkgloc[], pkgloc_sav[], pkgbin[], pkgsav[],
		*pkginst, *msgtext;
extern char	saveSpoolInstallDir[];

static boolean_t	preinstallCheck = B_FALSE;
static char		*zoneName = (char *)NULL;

static char	ask_cont[100];

#define	DISPSIZ	20	/* number of items to display on one page */

#define	MSG_RUNLEVEL	"\\nThe current run-level of this machine is <%s>, " \
			"which is not a run-level suggested for installation " \
			"of this package.  Suggested run-levels (in order of " \
			"preference) include:"
#define	HLP_RUNLEVEL	"If this package is not installed in a run-level " \
			"which has been suggested, it is possible that the " \
			"package may not install or operate properly.  If " \
			"you wish to follow the run-level suggestions, " \
			"answer 'n' to stop installation of the package."
#define	MSG_STATECHG	"\\nTo change states, execute\\n\\tshutdown -y " \
			"-i%s -g0\\nafter exiting the installation process. " \
			"Please note that after changing states you " \
			"may have to mount appropriate filesystem(s) " \
			"in order to install this package."

#define	ASK_CONFLICT	"Do you want to install these conflicting files"
#define	MSG_CONFLICT	"\\nThe following files are already installed on the " \
			"system and are being used by another package:"
#define	MSG_ROGUE	"\\n* - conflict with a file which does not " \
			"belong to any package."
#define	HLP_CONFLICT	"If you choose to install conflicting files, the " \
			"files listed above will be overwritten and/or have " \
			"their access permissions changed.  If you choose " \
			"not to install these files, installation will " \
			"proceed but these specific files will not be " \
			"installed.  Note that sane operation of the " \
			"software being installed may require these files " \
			"be installed; thus choosing to not to do so may " \
			"cause inapropriate operation.  If you wish to stop " \
			"installation of this package, enter 'q' to quit."

#define	ASK_SETUID	"Do you want to install these as setuid/setgid files"
#define	MSG_SETUID	"\\nThe following files are being installed with " \
			"setuid and/or setgid permissions:"
#define	MSG_OVERWR	"\\n* - overwriting a file which is also " \
			"setuid/setgid."
#define	HLP_SETUID	"The package being installed appears to contain " \
			"processes which will have their effective user or " \
			"group ids set upon execution.  History has shown " \
			"that these types of processes can be a source of " \
			"security problems on your system.  If you choose " \
			"not to install these as setuid files, installation " \
			"will proceed but these specific files will be " \
			"installed as regular files with setuid and/or " \
			"setgid permissions reset.  Note that sane " \
			"operation of the software being installed may " \
			"require that these files be installed with setuid " \
			"or setgid permissions as delivered; thus choosing " \
			"to install them as regular files may cause " \
			"inapropriate operation.  If you wish to stop " \
			"installation of this package, enter 'q' to quit."
#define	MSG_PARTINST	"\\nThe installation of this package was previously " \
			"terminated and installation was never successfully " \
			"completed."
#define	MSG_PARTREM	"\\nThe removal of this package was terminated at " \
			"some point in time, and package removal was only " \
			"partially completed."
#define	HLP_PARTIAL	"Installation of partially installed packages is " \
			"normally allowable, but some packages providers " \
			"may suggest that a partially installed package be " \
			"completely removed before re-attempting " \
			"installation.  Check the documentation provided " \
			"with this package, and then answer 'y' if you feel " \
			"it is advisable to continue the installation process."

#define	HLP_SPACE	"It appears that there is not enough free space on " \
			"your system in which to install this package.  It " \
			"is possible that one or more filesystems are not " \
			"properly mounted.  Neither installation of the " \
			"package nor its operation can be guaranteed under " \
			"these conditions.  If you choose to disregard this " \
			"warning, enter 'y' to continue the installation " \
			"process."
#define	HLP_DEPEND	"The package being installed has indicated a " \
			"dependency on the existence (or non-existence) " \
			"of another software package.  If this dependency is " \
			"not met before continuing, the package may not " \
			"install or operate properly.  If you wish to " \
			"disregard this dependency, answer 'y' to continue " \
			"the installation process."

#define	MSG_PRIV	"\\nThis package contains scripts which will be " \
			"executed with super-user permission during the " \
			"process of installing this package."
#define	HLP_PRIV	"During the installation of this package, certain " \
			"scripts provided with the package will execute with " \
			"super-user permission.  These scripts may modify or " \
			"otherwise change your system without your " \
			"knowledge.  If you are certain of the origin and " \
			"trustworthiness of the package being installed, " \
			"answer 'y' to continue the installation process."

#define	ASK_CONT	"Do you want to continue with the installation of <%s>"
#define	HLP_CONT	"If you choose 'y', installation of this package " \
			"will continue.  If you want to stop installation " \
			"of this package, choose 'n'."

#define	MSG_MKPKGDIR	"unable to make packaging directory <%s>"

#define	MSG_CKCONFL_GZ	"## Checking for conflicts with packages already " \
			"installed."
#define	MSG_CKCONFL_LZ	"## Checking for conflicts with packages already " \
			"installed in zone <%s>."
#define	MSG_CKDEPEND_GZ	"## Verifying package dependencies."
#define	MSG_CKDEPEND_LZ	"## Verifying package dependencies in zone <%s>."
#define	MSG_CKSPACE_GZ	"## Verifying disk space requirements."
#define	MSG_CKSPACE_LZ	"## Verifying disk space requirements in zone <%s>."
#define	MSG_CKUID_GZ	"## Checking for setuid/setgid programs."
#define	MSG_CKUID_LZ	"## Checking for setuid/setgid programs in zone <%s>."

#define	MSG_SCRFND	"Package scripts were found."
#define	MSG_UIDFND	"Setuid/setgid processes detected."
#define	MSG_ATTRONLY	"!%s %s <attribute change only>"

#define	MSG_CONTDISP	"[Hit <RETURN> to continue display]"

#define	ERR_NO_RUNST	"unable to determine current run-state"
#define	ERR_DEPFAILED	"Dependency checking failed."
#define	ERR_SPCFAILED	"Space checking failed."
#define	ERR_CNFFAILED	"Conflict checking failed."
#define	ERR_BADFILE	"packaging file <%s> is corrupt"

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 * If "preinstallcheck" is set to B_TRUE:
 *			8 - partial install detected
 *			9 - partial removal detected
 */

int
ckpartial(void)
{
	char	ans[MAX_INPUT];
	int	n;

	if (ADM(partial, "nocheck")) {
		return (0);
	}

	if (access(ilockfile, F_OK) == 0) {
		if (preinstallCheck == B_TRUE) {
			return (8);	/* partial install detected */
		}

		(void) snprintf(ask_cont, sizeof (ask_cont),
			gettext(ASK_CONT), pkginst);

		msgtext = gettext(MSG_PARTINST);
		ptext(stderr, msgtext);

		if (ADM(partial, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		ckquit = 0;
		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_PARTIAL),
				ask_cont)) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			return (3);
		}
		ckquit = 1;
	}

	if (access(rlockfile, F_OK) == 0) {
		if (preinstallCheck == B_TRUE) {
			return (9);	/* partial removal detected */
		}

		(void) snprintf(ask_cont, sizeof (ask_cont),
			gettext(ASK_CONT), pkginst);


		msgtext = gettext(MSG_PARTREM);
		ptext(stderr, msgtext);

		if (ADM(partial, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		ckquit = 0;
		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_PARTIAL),
			ask_cont)) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			return (3);
		}
		ckquit = 1;
	}

	return (0);
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 *			99 - fatal error
 */

int
ckrunlevel(void)
{
	struct utmpx utmpx;
	struct utmpx *putmpx;
	char	ans[MAX_INPUT], *pt, *istates, *pstate;
	int	n;
	char	*uxstate;

	if (ADM(runlevel, "nocheck")) {
		return (0);
	}

	pt = getenv("ISTATES");
	if (pt == NULL) {
		return (0);
	}

	utmpx.ut_type = RUN_LVL;
	putmpx = getutxid(&utmpx);
	if (putmpx == NULL) {
		progerr(gettext(ERR_NO_RUNST));
		return (99);
	}

	(void) snprintf(ask_cont, sizeof (ask_cont),
			gettext(ASK_CONT), pkginst);

	/*
	 * this cryptic code is trying to pull the run level
	 * out of the utmpx entry...the level starts in column
	 * 11 - looks like "run-level %c"
	 */
	uxstate = strtok(&putmpx->ut_line[10], " \t\n");

	istates = qstrdup(pt);
	if ((pt = strtok(pt, " \t\n, ")) == NULL) {
		return (0); /* no list is no list */
	}

	pstate = pt;
	do {
		if (strcmp(pt, uxstate) == 0) {
			free(istates);
			return (0);
		}
	} while (pt = strtok(NULL, " \t\n, "));

	if (preinstallCheck == B_FALSE) {
		msgtext = gettext(MSG_RUNLEVEL);
		ptext(stderr, msgtext, uxstate);
	} else {
		(void) fprintf(stdout, "runlevel=%s", uxstate);
	}

	pt = strtok(istates, " \t\n, ");
	do {
		if (preinstallCheck == B_FALSE) {
			ptext(stderr, "\\t%s", pt);
		} else {
			(void) fprintf(stdout, ":%s", pt);
		}
	} while (pt = strtok(NULL, " \t\n, "));

	if (preinstallCheck == B_TRUE) {
		(void) fprintf(stdout, "\n");
	}

	free(istates);

	if (preinstallCheck == B_TRUE) {
		return (4);
	}

	if (ADM(runlevel, "quit")) {
		return (4);
	}

	if (echoGetFlag() == B_FALSE) {
		return (5);
	}

	msgtext = NULL;

	ckquit = 0;
	if (n = ckyorn(ans, NULL, NULL, gettext(HLP_RUNLEVEL),
		ask_cont)) {
		return (n);
	}

	ckquit = 1;

	if (strchr("yY", *ans) != NULL) {
		return (0);
	} else {
		if (preinstallCheck == B_FALSE) {
			ptext(stderr, gettext(MSG_STATECHG), pstate);
		}
		return (3);
	}
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */

int
ckdepend(void)
{
	int	n;
	char	ans[MAX_INPUT];
	char	path[PATH_MAX];

	if (ADM(idepend, "nocheck")) {
		return (0);
	}

	(void) snprintf(path, sizeof (path), "%s/%s", instdir, DEPEND_FILE);
	if (access(path, F_OK) != 0) {
		return (0); /* no dependency file provided by package */
	}

	if (zoneName == (char *)NULL) {
		echo(gettext(MSG_CKDEPEND_GZ));
	} else {
		echo(gettext(MSG_CKDEPEND_LZ), zoneName);
	}

	if (dockdeps(path, 0, preinstallCheck)) {
		(void) snprintf(ask_cont, sizeof (ask_cont),
			gettext(ASK_CONT), pkginst);
		msgtext = gettext(ERR_DEPFAILED);

		if (preinstallCheck == B_TRUE) {
			return (4);
		}

		if (ADM(idepend, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		ckquit = 0;
		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_DEPEND),
			ask_cont)) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			return (3);
		}

		ckquit = 1;
	}

	return (0);
}

void
cksetZoneName(char *a_zoneName)
{
	zoneName = a_zoneName;
}

void
cksetPreinstallCheck(boolean_t a_preinstallCheck)
{
	preinstallCheck = a_preinstallCheck;
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */
int
ckspace(void)
{
	int	n;
	char	ans[MAX_INPUT];
	char	path[PATH_MAX];

	if (ADM(space, "nocheck")) {
		return (0);
	}

	if (zoneName == (char *)NULL) {
		echo(gettext(MSG_CKSPACE_GZ));
	} else {
		echo(gettext(MSG_CKSPACE_LZ), zoneName);
	}

	(void) snprintf(path, sizeof (path), "%s/install/space", instdir);
	if (access(path, F_OK) == 0) {
		n = dockspace(path);
	} else {
		n = dockspace(NULL);
	}

	if (n) {
		msgtext = gettext(ERR_SPCFAILED);
		(void) snprintf(ask_cont, sizeof (ask_cont),
			gettext(ASK_CONT), pkginst);

		if (preinstallCheck == B_TRUE) {
			return (4);
		}

		if (ADM(space, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		ckquit = 0;
		n = ckyorn(ans, NULL, NULL, gettext(HLP_SPACE), ask_cont);
		if (n != 0) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			return (3);
		}

		ckquit = 1;
	}
	return (0);
}

void
ckdirs(void)
{
	char	path[PATH_MAX];

	if (mkpath(get_PKGADM())) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", get_PKGADM());
		} else {
			progerr(gettext(MSG_MKPKGDIR), get_PKGADM());
		}
		quit(99);
	}

	(void) snprintf(path, sizeof (path), "%s/admin", get_PKGADM());

	if (mkpath(path)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", path);
		} else {
			progerr(gettext(MSG_MKPKGDIR), path);
		}
		quit(99);
	}

	(void) snprintf(path, sizeof (path), "%s/logs", get_PKGADM());

	if (mkpath(path)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", path);
		} else {
			progerr(gettext(MSG_MKPKGDIR), path);
		}
		quit(99);
	}

	if (mkpath(PKGSCR)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", PKGSCR);
		} else {
			progerr(gettext(MSG_MKPKGDIR), PKGSCR);
		}
		quit(99);
	}

	if (mkpath(get_PKGLOC())) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", get_PKGLOC());
		} else {
			progerr(gettext(MSG_MKPKGDIR), get_PKGLOC());
		}
		quit(99);
	}
}

/*
 * Return value:	int
 *			0 - success
 *			99 - failure
 */

int
ckpkgdirs(void)
{
	boolean_t nonExistentPkgloc = B_FALSE;

	/*
	 * If pkgloc doesn't exist make sure it gets removed after creating
	 * it if this is a preinstall check. All dryrun and preinstallation
	 * checks must not modify the file system.
	 */

	if (access(pkgloc, F_OK) != 0) {
		nonExistentPkgloc = B_TRUE;
	}

	if (mkpath(pkgloc)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", pkgloc);
		} else {
			progerr(gettext(MSG_MKPKGDIR), pkgloc);
		}
		return (99);
	}

	if (mkpath(pkgbin)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", pkgbin);
		} else {
			progerr(gettext(MSG_MKPKGDIR), pkgbin);
		}
		return (99);
	}

	if (mkpath(pkgsav)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", pkgsav);
		} else {
			progerr(gettext(MSG_MKPKGDIR), pkgsav);
		}
		return (99);
	}

	if (!is_spool_create() && mkpath(saveSpoolInstallDir)) {
		if (preinstallCheck == B_TRUE) {
			(void) fprintf(stdout, "ckdirs=%s\n", pkgsav);
		} else {
			progerr(gettext(MSG_MKPKGDIR), pkgsav);
		}
		return (99);
	}

	if (preinstallCheck && nonExistentPkgloc) {
		rrmdir(pkgloc);
	}

	return (0);
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */

int
ckconflct(void)
{
	int	i, n, count, has_a_rogue = 0;
	char	ans[MAX_INPUT];

	if (ADM(conflict, "nochange")) {
		nocnflct++;
		return (0);
	}

	if (ADM(conflict, "nocheck")) {
		return (0);
	}

	if (zoneName == (char *)NULL) {
		echo(gettext(MSG_CKCONFL_GZ));
	} else {
		echo(gettext(MSG_CKCONFL_LZ), zoneName);
	}

	count = 0;
	for (i = 0; extlist[i]; i++) {
		struct cfent *ept;
		struct mergstat *mstat;

		if (extlist[i]->cf_ent.ftype == 'i') {
			continue;
		}

		ept = &(extlist[i]->cf_ent);
		mstat = &(extlist[i]->mstat);

		if (is_remote_fs(ept->path, &(extlist[i]->fsys_value)) &&
			!is_fs_writeable(ept->path,
				&(extlist[i]->fsys_value))) {
			continue;
		}

		/*
		 * If no other package claims it or it's from a continuation
		 * file, skip it.
		 */
		if (!mstat->shared || mstat->preloaded) {
			continue;
		}

		if (ept->ftype == 'e') {
			continue;
		}

		if (mstat->rogue) {
			has_a_rogue = 1;
		}

		if (mstat->contchg) {
			if (!count++) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(MSG_CONFLICT));
				}
			} else if ((echoGetFlag() == B_TRUE) &&
					((count % DISPSIZ) == 0)) {
				echo(gettext(MSG_CONTDISP));
				(void) getc(stdin);
			}
			/*
			 * NOTE : The leading "!" in this string forces
			 * puttext() to print leading white space.
			 */

			if (preinstallCheck == B_FALSE) {
				ptext(stderr, "!%s %s",
					(mstat->rogue) ? "*" : " ", ept->path);
			} else {
				(void) fprintf(stdout,
					"conflict-contents=%s\n", ept->path);
			}
		} else if (mstat->attrchg) {
			if (!count++) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(MSG_CONFLICT));
				}
			} else if ((echoGetFlag() == B_TRUE) &&
					((count % DISPSIZ) == 0)) {
				echo(gettext(MSG_CONTDISP));
				(void) getc(stdin);
			}
			if (preinstallCheck == B_FALSE) {
				ptext(stderr, gettext(MSG_ATTRONLY),
					(mstat->rogue) ? "*" : " ", ept->path);
			} else {
				(void) fprintf(stdout,
					"conflict-attributes=%s\n", ept->path);
			}
		}
	}

	if (count) {
		if (has_a_rogue) {
			if (preinstallCheck == B_FALSE) {
				ptext(stderr, gettext(MSG_ROGUE));
			}
		}

		msgtext = gettext(ERR_CNFFAILED);

		if (preinstallCheck == B_TRUE) {
			return (4);
		}

		if (ADM(conflict, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_CONFLICT),
			gettext(ASK_CONFLICT))) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			ckquit = 0;
			(void) snprintf(ask_cont, sizeof (ask_cont),
				gettext(ASK_CONT), pkginst);

			if (n = ckyorn(ans, NULL, NULL, gettext(HLP_CONT),
				ask_cont)) {
				return (n);
			}

			if (strchr("yY", *ans) == NULL) {
				return (3);
			}
			ckquit = 1;
			nocnflct++;
			rprcflag++;
		}
	}
	return (0);
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */

int
cksetuid(void)
{
	int	i, n, count, overwriting = 0;
	char	ans[MAX_INPUT];

	/* See if the administrative defaults already resolve this check. */
	if (ADM(setuid, "nocheck")) {
		return (0);
	}

	if (ADM(setuid, "nochange")) {
		nosetuid++;	/* Do not install processes as setuid/gid. */
		return (0);
	}

	/* The administrative defaults require review of the package. */

	if (zoneName == (char *)NULL) {
		echo(gettext(MSG_CKUID_GZ));
	} else {
		echo(gettext(MSG_CKUID_LZ), zoneName);
	}

	count = 0;
	for (i = 0; extlist[i]; i++) {
		int overwr;
		struct mergstat *mstat = &(extlist[i]->mstat);

		/*
		 * Provide the administrator with info as to whether there is
		 * already a setuid process in place. This is only necessary
		 * to help the administrator decide whether or not to lay
		 * down the process, it doesn't have anything to do with the
		 * administrative defaults.
		 */
		if (mstat->osetuid || mstat->osetgid) {
			overwr = 1;
			overwriting = 1;
		} else
			overwr = 0;

		if (mstat->setuid || mstat->setgid) {
			if (!count++) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(MSG_SETUID));
				}
			} else if ((echoGetFlag() == B_TRUE) &&
					((count % DISPSIZ) == 0)) {
				echo(gettext(MSG_CONTDISP));
				(void) getc(stdin);
			}
			/*
			 * NOTE : The leading "!" in these strings forces
			 * puttext() to print leading white space.
			 */

			if (mstat->setuid && mstat->setgid) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(
						"!%s %s <setuid %s setgid %s>"),
						(overwr) ? "*" : " ",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.owner,
						extlist[i]->cf_ent.ainfo.group);
				} else {
					(void) fprintf(stdout, "setuid=%s:%s\n",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.owner);
					(void) fprintf(stdout, "setgid=%s:%s\n",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.group);
				}
			} else if (mstat->setuid) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(
						"!%s %s <setuid %s>"),
						(overwr) ? "*" : " ",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.owner);
				} else {
					(void) fprintf(stdout, "setuid=%s:%s\n",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.owner);
				}
			} else if (mstat->setgid) {
				if (preinstallCheck == B_FALSE) {
					ptext(stderr, gettext(
						"!%s%s <setgid %s>"),
						(overwr) ? "*" : " ",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.group);
				} else {
					(void) fprintf(stdout, "setgid=%s:%s\n",
						extlist[i]->cf_ent.path,
						extlist[i]->cf_ent.ainfo.group);
				}
			}
		}
	}

	if (count) {
		if (overwriting) {
			if (preinstallCheck == B_FALSE) {
				ptext(stderr, gettext(MSG_OVERWR));
			} else {
				(void) fprintf(stdout,
					"setuid-overwrite=true\n");
			}
		}

		msgtext = gettext(MSG_UIDFND);

		if (preinstallCheck == B_TRUE) {
			return (4);
		}

		if (ADM(setuid, "quit")) {
			return (4);
		}
		if (echoGetFlag() == B_FALSE) {
			return (5);
		}
		msgtext = NULL;

		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_SETUID),
			gettext(ASK_SETUID))) {
			return (n);
		}
		if (strchr("yY", *ans) == NULL) {
			ckquit = 0;
			(void) snprintf(ask_cont, sizeof (ask_cont),
				gettext(ASK_CONT), pkginst);
			if (n = ckyorn(ans, NULL, NULL, gettext(HLP_CONT),
				ask_cont)) {
				return (n);
			}
			if (strchr("yY", *ans) == NULL) {
				return (3);
			}
			ckquit = 1;
			nosetuid++;
			rprcflag++;
		}
	}

	return (0);
}

/*
 * Return value:	int
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */

int
ckpriv(void)
{
	struct dirent *dp;
	DIR	*dirfp;
	int	n, found;
	char	ans[MAX_INPUT], path[PATH_MAX];

	if (ADM(action, "nocheck")) {
		return (0);
	}

	(void) snprintf(path, sizeof (path), "%s/install", instdir);
	if ((dirfp = opendir(path)) == NULL) {
		return (0);
	}

	found = 0;
	while ((dp = readdir(dirfp)) != NULL) {
		if (strcmp(dp->d_name, "preinstall") == 0 ||
			strcmp(dp->d_name, "postinstall") == 0 ||
			strncmp(dp->d_name, "i.", 2) == 0) {
			found++;
			break;
		}
	}
	(void) closedir(dirfp);

	if (found) {
		if (preinstallCheck == B_FALSE) {
			ptext(stderr, gettext(MSG_PRIV));
			msgtext = gettext(MSG_SCRFND);
		}
		(void) snprintf(ask_cont, sizeof (ask_cont),
				gettext(ASK_CONT), pkginst);

		if (preinstallCheck == B_TRUE) {
			return (4);
		}

		if (ADM(action, "quit")) {
			return (4);
		}

		if (echoGetFlag() == B_FALSE) {
			return (5);
		}

		msgtext = NULL;

		ckquit = 0;
		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_PRIV),
			ask_cont)) {
			return (n);
		}

		if (strchr("yY", *ans) == NULL) {
			return (3);
		}
		ckquit = 1;
	}

	return (0);
}

/*
 * Return value:	int
 *			0 - success
 *			99 - failure
 */

int
ckpkgfiles(void)
{
	register int i;
	struct cfent	*ept;
	int	errflg;
	char	source[PATH_MAX];

	errflg = 0;
	for (i = 0; extlist[i]; i++) {
		ept = &(extlist[i]->cf_ent);
		if (ept->ftype != 'i') {
			continue;
		}

		if (ept->ainfo.local) {
			(void) snprintf(source, sizeof (source),
				"%s/%s", instdir, ept->ainfo.local);
		} else if (strcmp(ept->path, PKGINFO) == 0) {
			(void) snprintf(source, sizeof (source),
				"%s/%s", instdir, ept->path);
		} else {
			(void) snprintf(source, sizeof (source),
				"%s/install/%s", instdir, ept->path);
		}
		if (cverify(0, &ept->ftype, source, &ept->cinfo, 1)) {
			errflg++;
			if (preinstallCheck == B_FALSE) {
				progerr(gettext(ERR_BADFILE), source);
				logerr(getErrbufAddr());
			} else {
				(void) fprintf(stdout, "ckpkgfilebad=%s",
					source);
			}
		}
	}

	if (errflg) {
		return (99);
	} else {
		return (0);
	}
}