summaryrefslogtreecommitdiff
path: root/usr/src/cmd/svr4pkg/pkgadd/check.c
blob: 012a3bffe725a1478b4c37ffbc9e4b862635c1d5 (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
/*
 * 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.
 */

#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <dirent.h>
#include <sys/types.h>
#include <locale.h>
#include <libintl.h>
#include <pkgstrct.h>
#include <pkglocs.h>
#include <assert.h>

#include <instzones_api.h>
#include <pkglib.h>
#include <messages.h>

#include <install.h>
#include <libinst.h>
#include <libadm.h>

extern int	npkgs;	/* the number of packages yet to be installed */

/*
 * ckquit is a global that controls 'ckyorn' (defined in libadm)
 * If ckquit is non-zero, then "quit" is allowed as an answer when
 * ckyorn is called. If is it zero, then "quit" is not an allowed answer.
 */
extern int	ckquit;

extern struct admin adm;

/*
 * each one of these represents a single kind of dependency check
 */

static depckError_t er_ckconflict = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckdepend = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckcfcontent = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckinstance = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckdirs = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpartinst = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpartrem = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpkgdirs = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpkgfilebad = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpkgfiles = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckpriv = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckrunlevel = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_cksetuid = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_ckspace = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_newonly = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_prereqinc = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_prereqinst = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_runlevel = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_same = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_overwrite = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_uniq1 = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_attrib = {0, NULL};
static depckError_t er_setuidf = {0, NULL};
static depckError_t er_setgidf = {0, NULL};
static depckError_t er_overwr = {0, NULL};

/*
 * each one of these represents a localized message for a single kind
 * of dependency check
 */

static char *IMSG_ABADFILE = (char *)NULL;
static char *IMSG_BADFILE = (char *)NULL;
static char *IMSG_CKRUNLVL = (char *)NULL;
static char *IMSG_CNFFAILED = (char *)NULL;
static char *IMSG_DEPEND = (char *)NULL;
static char *IMSG_CFCONTENT = (char *)NULL;
static char *IMSG_INSTANCE = "INSTANCE %s <%s> on %s <%s>";
static char *IMSG_DIRS  = (char *)NULL;
static char *IMSG_NEWONLY = (char *)NULL;
static char *IMSG_PARTINST = (char *)NULL;
static char *IMSG_PARTREM = (char *)NULL;
static char *IMSG_PKGDIRS = (char *)NULL;
static char *IMSG_PRENCI  = (char *)NULL;
static char *IMSG_PREREQ  = (char *)NULL;
static char *IMSG_PRIV = (char *)NULL;
static char *IMSG_RUNLEVEL = (char *)NULL;
static char *IMSG_SAME = (char *)NULL;
static char *IMSG_OVERWRITE = (char *)NULL;
static char *IMSG_UNIQ1 = (char *)NULL;
static char *IMSG_SETUID = (char *)NULL;
static char *IMSG_SPCFAILED = (char *)NULL;
static char *IMSG_ATTRIB;
static char *IMSG_SETUIDF;
static char *IMSG_SETGIDF;
static char *IMSG_OVERWR;

/*
 * each one of these represents a function to handle a single kind of
 * dependency check
 */

static int ckconflict(char *a_msg, char *a_pkg);
static int ckdepend(char *a_msg, char *a_pkg);
static int ckcfcontent(char *a_msg, char *a_pkg);
static int ckinstance(char *a_msg, char *a_pkg);
static int ckdirs(char *a_msg, char *a_pkg);
static int ckpartinst(char *a_msg, char *a_pkg);
static int ckpartrem(char *a_msg, char *a_pkg);
static int ckpkgfilebad(char *a_msg, char *a_pkg);
static int ckpkgdirs(char *a_msg, char *a_pkg);
static int ckpkgfiles(char *a_msg, char *a_pkg);
static int ckprereqinc(char *a_msg, char *a_pkg);
static int ckprereqinst(char *a_msg, char *a_pkg);
static int ckpriv(char *a_msg, char *a_pkg);
static int ckrunlevel(char *a_msg, char *a_pkg);
static int cksetuid(char *a_msg, char *a_pkg);
static int ckspace(char *a_msg, char *a_pkg);
static int attrib(char *a_msg, char *a_pkg);
static int setuidf(char *a_msg, char *a_pkg);
static int setgidf(char *a_msg, char *a_pkg);
static int overwr(char *a_msg, char *a_pkg);

static depckl_t DEPCKL[] = {
	/*
	 * name,	ignore_values,	err_msg,	depcklFunc,	recrd
	 * ---
	 * ignore_values == NULL:
	 * package and zone information is collected in the "record" object for
	 * each occurance - then a message is constructed for each zone that
	 * reported the condition - the message includes that portion of the
	 * check past the "=" - then the specified "depcklFunc" is called to
	 * process each message.
	 * Message format:
	 * 	%s %s <%s> %s <%s>
	 * Message arguments:
	 *	value, "package", package-name, "zone/zones", zone-name
	 * ---
	 * ignore-values == "???":
	 * these checks are ignored if they return one of the listed values
	 * if they do NOT return one of the listed values, then the package
	 * and zone information is collected in the "record" object for each
	 * occurance - then a single unified message is constructed for all
	 * zones that report the same condition; then the specified "depcklFunc"
	 * is called to process the resulting combined message.
	 * Message format:
	 * 	%s <%s> %s <%s>
	 * Message arguments:
	 *	"package", package-name, "zone/zones", zone-name(s)
	 * ---
	 * ignore-values="":
	 * same as above BUT no check to ignore is done; message always reported
	 */

	{ "install-same-instance=true",	"",		&IMSG_SAME,
					NULL,		&er_same
	},
	{ "ckpkgfilebad=",		NULL,		&IMSG_ABADFILE,
					&ckpkgfilebad,	&er_ckpkgfilebad
	},
	{ "ckdirs=",			NULL,		&IMSG_DIRS,
					&ckdirs,	&er_ckdirs
	},
	{ "prerequisite-incomplete=",	NULL,		&IMSG_PRENCI,
					&ckprereqinc,	&er_prereqinc
	},
	{ "prerequisite-installed=",	NULL,		&IMSG_PREREQ,
					&ckprereqinst,	&er_prereqinst
	},
	{ "runlevel=",			NULL,		&IMSG_RUNLEVEL,
					NULL,		&er_runlevel
	},
	{ "conflict-contents=",		NULL,		&IMSG_CFCONTENT,
					&ckcfcontent,	&er_ckcfcontent
	},
	{ "ckconflict=",		"0",		&IMSG_CNFFAILED,
					&ckconflict,	&er_ckconflict
	},
	{ "ckdepend=",			"0",		&IMSG_DEPEND,
					&ckdepend,	&er_ckdepend
	},
	{ "ckpartialinstall=",		"0",		&IMSG_PARTINST,
					&ckpartinst,	&er_ckpartinst
	},
	{ "ckpartialremove=",		"0",		&IMSG_PARTREM,
					&ckpartrem,	&er_ckpartrem
	},
	{ "ckpkgdirs=",			"0",		&IMSG_PKGDIRS,
					&ckpkgdirs,	&er_ckpkgdirs
	},
	{ "ckpkgfiles=",		"0",		&IMSG_BADFILE,
					&ckpkgfiles,	&er_ckpkgfiles
	},
	{ "ckpriv=",			"0",		&IMSG_PRIV,
					&ckpriv,	&er_ckpriv
	},
	{ "ckrunlevel=",		"0",		&IMSG_CKRUNLVL,
					&ckrunlevel,	&er_ckrunlevel
	},
	{ "cksetuid=",			"0",		&IMSG_SETUID,
					&cksetuid,	&er_cksetuid
	},
	{ "ckspace=",			"0",		&IMSG_SPCFAILED,
					&ckspace,	&er_ckspace
	},
	{ "install-new-only=true",	"",		&IMSG_NEWONLY,
					NULL,		&er_newonly
	},
	{ "install-ovewrite=true",	"",		&IMSG_OVERWRITE,
					NULL,		&er_overwrite
	},
	{ "install-too-many-instances=true",	"",	&IMSG_UNIQ1,
					NULL,		&er_uniq1
	},
	{ "ckinstance=",		"0",		&IMSG_INSTANCE,
					&ckinstance,	&er_ckinstance
	},
	{ "conflict-attributes=",	NULL,		&IMSG_ATTRIB,
					&attrib,	&er_attrib
	},
	{ "setuid=",			NULL,		&IMSG_SETUIDF,
					&setuidf,	&er_setuidf
	},
	{ "setgid=",			NULL,		&IMSG_SETGIDF,
					&setgidf,	&er_setgidf
	},
	{ "setuid-overwrite=true",	"",		&IMSG_OVERWR,
					&overwr,	&er_overwr
	},

	{ NULL,				NULL,	NULL,
				NULL,		NULL }
};

/*
 * Name:	preinstall_verify
 * Description:	verify results of preinstallation dependency checking
 * Arguments:	a_pkglist - pointer to array of strings representing the names
 *			of all the packages that have been checked
 *		a_zlst - list of zones that dependencies were checked on
 *		a_zoneTempDir - pointer to string representing the path where
 *			the files containing the preinstallation dependency
 *			check data are located
 * Returns:	int
 *		== 0 - continue processing
 *		!= 0 - do not continue processing
 */

int
preinstall_verify(char **a_pkglist, zoneList_t a_zlst, char *a_zoneTempDir)
{
	char		*pkginst;
	int		i;
	int		savenpkgs = npkgs;

	/*
	 * entry assertions
	 */

	assert(a_pkglist != (char **)NULL);
	assert(a_zlst != (zoneList_t)NULL);
	assert(a_zoneTempDir != (char *)NULL);

	/*
	 * entry debugging info
	 */

	echoDebug(DBG_PREIVFY_ENTRY);

	/*
	 * localize messages
	 */

	IMSG_ABADFILE = MSG_PKGADDCHK_ABADFILE;
	IMSG_BADFILE = MSG_PKGADDCHK_BADFILE;
	IMSG_CFCONTENT = MSG_PKGADDCHK_CFCONTENT;
	IMSG_CKRUNLVL = MSG_PKGADDCHK_CKRUNLVL;
	IMSG_CNFFAILED = MSG_PKGADDCHK_CNFFAILED;
	IMSG_DEPEND = MSG_PKGADDCHK_DEPEND;
	IMSG_DIRS  = MSG_PKGADDCHK_DIRS;
	IMSG_NEWONLY = MSG_PKGADDCHK_NEWONLY;
	IMSG_OVERWRITE = MSG_PKGADDCHK_OVERWRITE;
	IMSG_PARTINST = MSG_PKGADDCHK_PARTINST;
	IMSG_PARTREM = MSG_PKGADDCHK_PARTREM;
	IMSG_PKGDIRS = MSG_PKGADDCHK_PKGDIRS;
	IMSG_PRENCI  = MSG_PKGADDCHK_PRENCI;
	IMSG_PREREQ  = MSG_PKGADDCHK_PREREQ;
	IMSG_PRIV = MSG_PKGADDCHK_PRIV;
	IMSG_RUNLEVEL = MSG_PKGADDCHK_RUNLEVEL;
	IMSG_SAME = MSG_PKGADDCHK_SAME;
	IMSG_SETUID = MSG_PKGADDCHK_SETUID;
	IMSG_SPCFAILED = MSG_PKGADDCHK_SPCFAILED;
	IMSG_UNIQ1 = MSG_PKGADDCHK_UNIQ1;
	IMSG_ATTRIB = gettext("\\nattribute change for %s <%s> on %s <%s>\n");
	IMSG_SETUIDF = gettext("\\nsetuid %s in %s <%s> on %s <%s>\n");
	IMSG_SETGIDF = gettext("\\nsetgid %s in %s <%s> on %s <%s>\n");
	IMSG_OVERWR = gettext("\\nFiles that are setuid will be overwritten "
	    "by installation of %s\n<%s> on %s <%s>.\n");

	/*
	 * outer loop - process each package first
	 */

	for (i = 0; (pkginst = a_pkglist[i]) != NULL; i++) {

		char	*zoneName;
		int	zoneIndex;

		/*
		 * if this package is marked "install in this zone only", then
		 * do not check dependencies in any zone
		 */

		if (pkgPackageIsThisZone(pkginst) == B_TRUE) {
			echoDebug(DBG_PREIVFY_SKIP_THISZONE, pkginst);
			continue;
		}

		/*
		 * inner loop - for each package process each zone second
		 */

		for (zoneIndex = 0;
			(zoneName = z_zlist_get_zonename(a_zlst, zoneIndex)) !=
				(char *)NULL; zoneIndex++) {

			FILE	*fp;
			char	line[PATH_MAX+1];
			char	preinstallcheckPath[PATH_MAX+1];
			int	len;

			/* skip the zone if it is NOT bootable */

			if (z_zlist_is_zone_runnable(a_zlst,
							zoneIndex) == B_FALSE) {
				continue;
			}

			/* create path to this packages preinstall check data */

			len = snprintf(preinstallcheckPath,
				sizeof (preinstallcheckPath),
				"%s/%s.%s.preinstallcheck.txt", a_zoneTempDir,
				pkginst, zoneName);

			if (len > sizeof (preinstallcheckPath)) {
				progerr(ERR_CREATE_PATH_3, a_zoneTempDir,
					pkginst, zoneName);
				continue;
			}

			/* error if preinstall check data path is not a file */

			if (isfile((char *)NULL, preinstallcheckPath) != 0) {
				echoDebug(DBG_PREIVFY_NOFILE,
					pkginst, zoneName, preinstallcheckPath,
					strerror(errno));
				progerr(ERR_PREIVFY_NOFILE,
					pkginst, zoneName);
				continue;
			}

			/* open the preinstall check data file */

			fp = fopen(preinstallcheckPath, "r");
			if (fp == (FILE *)NULL) {
				progerr(ERR_PREIVFY_OPEN_FILE,
					preinstallcheckPath, pkginst, zoneName,
					strerror(errno));
				continue;
			}

			/* read and process each preinstall check data line */

			while (fgets(line, sizeof (line), fp) != (char *)NULL) {
				int	j;
				int	len;

				/* remove all new-lines from end of line */

				len = strlen(line);
				while ((len > 0) && (line[len-1] == '\n')) {
					line[--len] = '\0';
				}

				/* ignore comment lines */

				if (line[0] == '#') {
					continue;
				}

				/* ignore empty lines */

				if (line[0] == '\0') {
					continue;
				}

				/* scan dependency list for this item */

				for (j = 0;
					DEPCKL[j].name != (char *)NULL; j++) {
					len = strlen(DEPCKL[j].name);

					if (strncmp(line, DEPCKL[j].name,
							len) == 0) {
						break;
					}
				}

				echoDebug(DBG_PREIVFY_SCAN, line, pkginst,
						zoneName);

				/* ignore line if not found */

				if (DEPCKL[j].name == (char *)NULL) {
					progerr(ERR_PREIVFY_UNKNOWN_LINE, line,
							pkginst, zoneName);
					continue;
				}

				if ((DEPCKL[j].ignore_values != (char *)NULL) &&
					(*(DEPCKL[j].ignore_values) != '\0') &&
					(strchr(DEPCKL[j].ignore_values,
						line[len]) != (char *)NULL)) {
						continue;
				}

				/* found match - record this dependency issue */

				depchkRecordError(DEPCKL[j].record, pkginst,
					zoneName, &line[len]);
			}

			/* close preinstall check data file */

			(void) fclose(fp);
		}
	}

	/*
	 * all dependency issues have been recorded; report results
	 */

	i = depchkReportErrors(DEPCKL);

	/* restore "npkgs" */

	npkgs = savenpkgs;

	/* return continue/dont dontinue results */

	return (i);
}

/*
 * Name:	getyorn
 * Description:	Deliver dependency check reason; ask question; return response
 * Arguments:	a_msg - pointer to string representing the message to output
 *			such as 'The package <..> contains <...>'
 *		a_pkg - pointer to string representing the package for which
 *			the question is being asked
 *		a_nocheck - should the message be output?
 *			== 0 - do not output the message
 *			!= 0 - output the message
 *		a_quit - should the question NOT be asked?
 *			== 0 - ask the question
 *			!= 0 - do not ask the question - return "no"
 *		a_helpMsg - pointer to string representing help message to be
 *			made available if the question is asked
 *			== NULL - no help message is available
 *		a_adminMsg - pointer to string representing the dependency check
 *			failure 'reason' - such as "Privilege checking failed."
 *			== NULL - no failure reason is available
 * Returns:	int - results of question/response actions
 *			0 - success
 *			1 - end of file
 *			2 - undefined error
 *			3 - answer was not "y"/was "q"
 *			4 - quit action taken
 *			5 - interactive mode required
 */

static int
getyorn(char *a_msg, char *a_pkg, int a_nocheck, int a_quit,
	char *a_helpMsg, char *a_adminMsg)
{
	char	ans[MAX_INPUT];
	char	ask_cont[MSG_MAX];
	int	n;
	int	saveCkquit;

	/*
	 * entry assertions
	 */

	assert(a_pkg != (char *)NULL);
	assert(*a_pkg != '\0');

	/*
	 * entry debugging info
	 */

	echoDebug(DBG_PREIVFY_GETYORN_ARGS, a_pkg, a_nocheck, a_quit, a_msg,
			a_adminMsg ? a_adminMsg : "");

	/* return success (0) if "nocheck" is non-zero */

	if (a_nocheck != 0) {
		echoDebug(DBG_PREIVFY_GETYORN_NOCHECK, a_pkg);
		return (0);
	}

	/* output reason for this particular failure */

	if ((a_msg != (char *)NULL) && (*a_msg != '\0')) {
		ptext(stderr, "%s", a_msg);
	}

	/* return "4 (administration)" if "quit" is non-zero */

	if (a_quit != 0) {
		/* output failure "admin reason" if available */
		if ((a_adminMsg != (char *)NULL) && (*a_adminMsg != '\0')) {
			ptext(stderr, a_adminMsg);
		}
		echoDebug(DBG_PREIVFY_GETYORN_QUIT, a_pkg);
		return (4);
	}

	/* return "5 (administration interaction required)" if -n */

	if (echoGetFlag() == B_FALSE) {
		ptext(stderr, MSG_PREIVFY_GETYORN_SUSP, a_pkg);
		echoDebug(DBG_PREIVFY_GETYORN_QUIT_USER, a_pkg);
		return (5);
	}

	/* prepare question to ask "continue with pkg <xxx>?" */

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

	/* ask question */

	saveCkquit = ckquit;
	ckquit = 0;

	n = ckyorn(ans, NULL, NULL, a_helpMsg, ask_cont);

	ckquit = saveCkquit;

	if (n != 0) {
		ptext(stderr, MSG_PREIVFY_GETYORN_TERM, a_pkg);
		echoDebug(DBG_PREIVFY_GETYORN_CKYORN, a_pkg, n);
		return (n);
	}

	/* return "3 (interruption) if not "y" or "Y" */

	if (strchr("yY", *ans) == NULL) {
		ptext(stderr, MSG_PREIVFY_GETYORN_TERM_USER, a_pkg);
		echoDebug(DBG_PREIVFY_GETYORN_NOT_Y, a_pkg, ans);
		return (3);
	}

	/* return "0 - success" */

	echoDebug(DBG_PREIVFY_GETYORN_SUCCESS, a_pkg);

	return (0);
}

/*
 * Trigger:	prerequisite-incomplete=<<package>>
 * Sequence:	- one or more: prerequisite-incomplete=<<package>>
 *		- one: ckdepend=<<n>>
 * Actions:	Output message if "idepend!=nocheck"
 *		Return 0
 *		Terminate when 'ckdepend' processed
 */

static int
ckprereqinc(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPRENCI, a_pkg, a_msg);

	if (!(ADM(idepend, "nocheck"))) {
		ptext(stderr, "%s", a_msg);
	}

	return (0);
}

/*
 * Trigger:	prerequisite-installed=<<package>>
 * Sequence:	- one or more: prerequisite-installed=<<package>>
 *		- one: ckdepend=<<n>>
 * Actions:	Output message if "idepend!=nocheck"
 *		Return 0
 *		Terminate when 'ckdepend' processed
 */

static int
ckprereqinst(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPREREQ, a_pkg, a_msg);

	if (!(ADM(idepend, "nocheck"))) {
		ptext(stderr, "%s", a_msg);
	}

	return (0);
}

/*
 * Trigger:	ckpartialinstall=<<n>>
 * Sequence:	- one: ckpartialinstall=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckpartinst(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPARTIALINSTALL, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(partial, "nocheck"),
			ADM(partial, "quit"), HLP_PKGADDCHK_PARTIAL, NULL));
}

/*
 * Trigger:	ckpartialremove=<<n>>
 * Sequence:	- one: ckpartialremove=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckpartrem(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPARTIALREMOVE, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(partial, "nocheck"),
		ADM(partial, "quit"), HLP_PKGADDCHK_PARTIAL, NULL));
}

/*
 * 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
 */

static int
ckrunlevel(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKRUNLEVEL, a_pkg, a_msg);
	return (0);
}

/*
 * Trigger:	conflict-contents=<<n>>
 * Sequence:	- one or more of:
 *		-- conflict-contents=<<path>>
 *		-- conflict-attributes=<<path>>
 *		- one: ckconflict=<<n>>
 * Actions:	output message
 * Return value:	int
 *			0 - success
 */

static int
ckcfcontent(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKCFCONTENT, a_pkg, a_msg);

	ptext(stderr, "%s", a_msg);

	return (0);
}

/*
 * Trigger:	ckinstance=<<n>>
 * Sequence:	- one or more of:
 *		-- install-instance=true
 *		-- install-new-only=true\n
 *		-- install-same-instance=true\n
 *		-- install-ovewrite=true\n
 *		-- install-too-many-instances=true\n
 *		-- install-new-instance=true\n
 *		- one: ckpdepend=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckinstance(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKINSTANCE, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(instance, "nocheck"),
		ADM(instance, "quit"), HLP_PKGADDCHK_DEPEND,
		ERR_PKGADDCHK_DEPFAILED));
}

/*
 * Trigger:	ckdepend=<<n>>
 * Sequence:	- one or more of:
 *		-- incompat=<<package>>
 *		-- prerequisite-incomplete=<<package>>
 *		-- prerequisite-installed=<<package>>
 *		-- dependson=<<package>>
 *		-- dependsonme=<<package>>
 *		- one: ckpdepend=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckdepend(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKDEPEND, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(idepend, "nocheck"),
		ADM(idepend, "quit"), HLP_PKGADDCHK_DEPEND,
		ERR_PKGADDCHK_DEPFAILED));
}

/*
 * Trigger:	ckspace=<<n>>
 * Sequence:	- one: ckspace=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckspace(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKSPACE, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(space, "nocheck"),
		ADM(space, "quit"), HLP_PKGADDCHK_SPACE,
		ERR_PKGADDCHK_SPCFAILED));
}

/*
 * Trigger:	ckpkgdirs=<<n>>
 * Sequence:	- one: ckpkgdirs=<<n>>
 * Actions:	output message
 *		Return 4
 */

static int
ckpkgdirs(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPKGDIRS, a_pkg, a_msg);

	ptext(stderr, "%s", a_msg);

	return (4);
}

/*
 * Trigger:	ckdirs=<<path>>
 * Sequence:	- one: ckdirs=<<path>>
 * Actions:	output message
 *		Return 4
 */

static int
ckdirs(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKDIRS, a_pkg, a_msg);

	ptext(stderr, "%s", a_msg);

	ptext(stderr, ERR_PKGADDCHK_MKPKGDIR);

	return (4);
}

/*
 * Trigger:	ckpkgfilebad=<<path>>
 * Sequence:	- one or more:
 *		-- ckpkgfilebad=<<path>>
 *		- one ckpkgfiles=<n>
 * Actions:	output message
 *		Return 0
 */

static int
ckpkgfilebad(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPKGFILEBAD, a_pkg, a_msg);

	ptext(stderr, "%s", a_msg);

	return (0);
}

/*
 * Trigger:	ckconflict=<<n>>
 * Sequence:	- one or more:
 *		-- conflict-contents=<<path>>
 *		-- conflict-attributes=<<path>>
 *		- one: ckconflict=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckconflict(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKCONFLICT, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(conflict, "nocheck"),
		ADM(conflict, "quit"), HLP_PKGADDCHK_CONFLICT,
		ERR_PKGADDCHK_CNFFAILED));
}

/*
 * Trigger:	cksetuid=<<n>>
 * Sequence:	- one or more:
 *		-- setuid=<path>:<owner>
 *		-- setgid=<path>:<group>
 *		-- setuid-overwrite=true
 *		- one: cksetuid=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
cksetuid(char *a_msg, char *a_pkg)
{
	char	ans[MAX_INPUT];
	char	ask_cont[MSG_MAX];
	int	n;
	int	saveCkquit;

	echoDebug(DBG_PREIVFY_CKSETUID, a_pkg, a_msg);

	n = getyorn(a_msg, a_pkg, ADM(setuid, "nocheck"),
		ADM(setuid, "quit"), HLP_PKGADDCHK_SETUID, NULL);

	/* if user did not answer "n" return answer given */

	if (n != 3) {
		return (n);
	}

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

	saveCkquit = ckquit;
	ckquit = 0;

	n = ckyorn(ans, NULL, NULL, gettext(HLP_PKGADDCHK_CONT), ask_cont);

	ckquit = saveCkquit;

	if (n != 0) {
		ptext(stderr, MSG_PREIVFY_GETYORN_TERM, a_pkg);
		echoDebug(DBG_PREIVFY_GETYORN_CKYORN, a_pkg, n);
		return (n);
	}

	/* return "3 (interruption) if not "y" or "Y" */

	if (strchr("yY", *ans) == NULL) {
		ptext(stderr, MSG_PREIVFY_GETYORN_TERM_USER, a_pkg);
		echoDebug(DBG_PREIVFY_GETYORN_NOT_Y, a_pkg, ans);
		return (3);
	}

	/* return "0 - success" */

	echoDebug(DBG_PREIVFY_GETYORN_SUCCESS, a_pkg);

	return (0);
}

/*
 * Trigger:	ckpriv=<<n>>
 * Sequence:	- one: ckpriv=<<n>>
 * Actions:	process according to settings
 * 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
 */

static int
ckpriv(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPRIV, a_pkg, a_msg);

	return (getyorn(a_msg, a_pkg, ADM(action, "nocheck"),
		ADM(action, "quit"), HLP_PKGADDCHK_PRIV,
		ERR_PKGADDCHK_PRIVFAILED));
}

/*
 * Trigger:	ckpkgfiles=<<n>>
 * Sequence:	- one or more:
 *		-- ckpkgfilebad=<path>
 *		- one: ckpkgfiles=<<n>>
 * Return value:	int
 *			0 - success
 *			4 - failure
 */

static int
ckpkgfiles(char *a_msg, char *a_pkg)
{
	echoDebug(DBG_PREIVFY_CKPKGFILES, a_pkg, a_msg);

	ptext(stderr, "%s", a_msg);

	return (4);
}

static int
attrib(char *a_msg, char *a_pkg)
{
	return (getyorn(a_msg, a_pkg, ADM(instance, "nocheck"),
		ADM(instance, "quit"), HLP_PKGADDCHK_CONT,
		ERR_PKGADDCHK_DEPFAILED));
}

/* ARGSUSED1 */
static int
setuidf(char *a_msg, char *a_pkg)
{
	char *cp;

	if ((cp = strchr(a_msg, ':')) != NULL)
		*cp = ' ';
	return (0);
}

/* ARGSUSED1 */
static int
setgidf(char *a_msg, char *a_pkg)
{
	char *cp;

	if ((cp = strchr(a_msg, ':')) != NULL)
		*cp = ' ';
	return (0);
}

static int
overwr(char *a_msg, char *a_pkg)
{
	return (getyorn(a_msg, a_pkg, ADM(instance, "nocheck"),
		ADM(instance, "quit"), HLP_PKGADDCHK_SETUID,
		ERR_PKGADDCHK_DEPFAILED));
}