xref: /onnv-gate/usr/src/cmd/svr4pkg/libinst/psvr4ck.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 <stdlib.h>
34*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
35*9781SMoriah.Waterland@Sun.COM #include <string.h>
36*9781SMoriah.Waterland@Sun.COM #include <dirent.h>
37*9781SMoriah.Waterland@Sun.COM #include <ctype.h>
38*9781SMoriah.Waterland@Sun.COM #include <sys/utsname.h>
39*9781SMoriah.Waterland@Sun.COM #include <locale.h>
40*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
41*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
42*9781SMoriah.Waterland@Sun.COM #include <libinst.h>
43*9781SMoriah.Waterland@Sun.COM #include <libadm.h>
44*9781SMoriah.Waterland@Sun.COM 
45*9781SMoriah.Waterland@Sun.COM #ifdef	MAILCMD
46*9781SMoriah.Waterland@Sun.COM #undef  MAILCMD
47*9781SMoriah.Waterland@Sun.COM #define	MAILCMD		"/bin/mail"
48*9781SMoriah.Waterland@Sun.COM #endif	/* MAILCMD */
49*9781SMoriah.Waterland@Sun.COM #define	ERR_MAIL	"unable to send electronic mail notification"
50*9781SMoriah.Waterland@Sun.COM #define	ERR_OVERWRITE	"unable to determine overwrite list"
51*9781SMoriah.Waterland@Sun.COM #define	ERR_PIPE	"unable to open pipe to process <%s>"
52*9781SMoriah.Waterland@Sun.COM #define	ASK_CONT	"Do you want to continue processing this package"
53*9781SMoriah.Waterland@Sun.COM #define	MSG_CONFLICT	"The following files are currently being used by " \
54*9781SMoriah.Waterland@Sun.COM 			"other packages on the system, and may be " \
55*9781SMoriah.Waterland@Sun.COM 			"overwritten by the installation of this pre-SVR4 " \
56*9781SMoriah.Waterland@Sun.COM 			"package:"
57*9781SMoriah.Waterland@Sun.COM #define	HLP_CONFLICT	"If you choose to continue installation, it is " \
58*9781SMoriah.Waterland@Sun.COM 			"possible that you will overwrite files which are " \
59*9781SMoriah.Waterland@Sun.COM 			"part of another package that is already installed " \
60*9781SMoriah.Waterland@Sun.COM 			"on the system.  If you want to assure that the " \
61*9781SMoriah.Waterland@Sun.COM 			"files are not overwritten, answer 'n' to stop the " \
62*9781SMoriah.Waterland@Sun.COM 			"installation process."
63*9781SMoriah.Waterland@Sun.COM #define	MSG_NOTVER	"The media being processed is in an old (pre-SVR4) " \
64*9781SMoriah.Waterland@Sun.COM 			"format and it is not possible to verify that the " \
65*9781SMoriah.Waterland@Sun.COM 			"inserted media belongs to the <%s> package."
66*9781SMoriah.Waterland@Sun.COM #define	HLP_NOTVER	"If you choose to continue installation, it is " \
67*9781SMoriah.Waterland@Sun.COM 			"possible that you will install the wrong package.  " \
68*9781SMoriah.Waterland@Sun.COM 			"If you are sure the media being installed contains " \
69*9781SMoriah.Waterland@Sun.COM 			"the package you wish to install, answer 'y' to " \
70*9781SMoriah.Waterland@Sun.COM 			"continue the installation process."
71*9781SMoriah.Waterland@Sun.COM #define	MSG_CONFIRM	"The media being processed is in an old (pre-SVR4) " \
72*9781SMoriah.Waterland@Sun.COM 			"format and appears to be part of the <%s> package."
73*9781SMoriah.Waterland@Sun.COM #define	HLP_CONFIRM	"The installation of older-style (pre-SVR4) packages " \
74*9781SMoriah.Waterland@Sun.COM 			"is, in general, not as robust as installing " \
75*9781SMoriah.Waterland@Sun.COM 			"standard packages.  Older packages may attempt " \
76*9781SMoriah.Waterland@Sun.COM 			"things during installation which overwrite existing " \
77*9781SMoriah.Waterland@Sun.COM 			"files or otherwise modify the system without your " \
78*9781SMoriah.Waterland@Sun.COM 			"approval.  If you wish to allow installation of " \
79*9781SMoriah.Waterland@Sun.COM 			"identified pre-SVR4 package, answer 'y' to continue " \
80*9781SMoriah.Waterland@Sun.COM 			"the installation process."
81*9781SMoriah.Waterland@Sun.COM 
82*9781SMoriah.Waterland@Sun.COM static char	*Rlist[] = {
83*9781SMoriah.Waterland@Sun.COM 	"/install/install/Rlist",
84*9781SMoriah.Waterland@Sun.COM 	"/install/install/RLIST",
85*9781SMoriah.Waterland@Sun.COM 	"/install/install/rlist",
86*9781SMoriah.Waterland@Sun.COM 	NULL
87*9781SMoriah.Waterland@Sun.COM };
88*9781SMoriah.Waterland@Sun.COM 
89*9781SMoriah.Waterland@Sun.COM static char	ckcmd[] = "/usr/sbin/pkgchk -L -i %s";
90*9781SMoriah.Waterland@Sun.COM 
91*9781SMoriah.Waterland@Sun.COM /*
92*9781SMoriah.Waterland@Sun.COM  * Remove the list & both #defines below for on1095 -- JST
93*9781SMoriah.Waterland@Sun.COM  * Further, please note :
94*9781SMoriah.Waterland@Sun.COM  * This is NOT a database (Oh, yeah it looks like it, but it isn't). For that
95*9781SMoriah.Waterland@Sun.COM  * reason these are in alphabetical order. Any additions must maintain this
96*9781SMoriah.Waterland@Sun.COM  * order and must not increase the list length beyond 120.
97*9781SMoriah.Waterland@Sun.COM  */
98*9781SMoriah.Waterland@Sun.COM #define	TREEHEIGHT	7
99*9781SMoriah.Waterland@Sun.COM #define	TREEFILL	4	/* number of fill entries per side */
100*9781SMoriah.Waterland@Sun.COM 
101*9781SMoriah.Waterland@Sun.COM #ifdef	ALLOW_EXCEPTION_PKG_LIST
102*9781SMoriah.Waterland@Sun.COM static char *x_pkg[] =
103*9781SMoriah.Waterland@Sun.COM {
104*9781SMoriah.Waterland@Sun.COM 	"AAAA1",	/* fill to avoid constraint tests in loop */
105*9781SMoriah.Waterland@Sun.COM 	"AAAA2",
106*9781SMoriah.Waterland@Sun.COM 	"AAAA3",
107*9781SMoriah.Waterland@Sun.COM 	"AAAA4",
108*9781SMoriah.Waterland@Sun.COM 	/* '+' means packages known to be non-compliant */
109*9781SMoriah.Waterland@Sun.COM 	"SPROcpl",	/* + bugID 1133962 */
110*9781SMoriah.Waterland@Sun.COM 	"SPROlklnt",	/* + SW Lock_Lint */
111*9781SMoriah.Waterland@Sun.COM 	"SPROltool",	/* + SW Loop Profiling Tools */
112*9781SMoriah.Waterland@Sun.COM 	"SPROssbd",	/* + SW ssbd component for SC 3.0 */
113*9781SMoriah.Waterland@Sun.COM 	"SPROtha",	/* + Performance Analzyer */
114*9781SMoriah.Waterland@Sun.COM 	"SUNW3270c",	/* + SunLink Client 3270 */
115*9781SMoriah.Waterland@Sun.COM 	"SUNW3270g",	/* SunLink CG3270 8.0 */
116*9781SMoriah.Waterland@Sun.COM 	"SUNW3270t",	/* + SunLink TN3270*Server */
117*9781SMoriah.Waterland@Sun.COM 	"SUNW86nma",	/* SunNet Manager Core Tools for x86 */
118*9781SMoriah.Waterland@Sun.COM 	"SUNW86nmc",	/* SunNet Manager Agents & Libraries for x86 */
119*9781SMoriah.Waterland@Sun.COM 	"SUNW86nmp",	/* SunNet Manager SNMP daemon for x86 */
120*9781SMoriah.Waterland@Sun.COM 	"SUNWabcg",	/* SunLink CG320 8.0 User's Guide */
121*9781SMoriah.Waterland@Sun.COM 	"SUNWbf",	/* + 2.0 FDDI/S Beta */
122*9781SMoriah.Waterland@Sun.COM 	"SUNWbsccu",	/* SunLink BSC Core Util */
123*9781SMoriah.Waterland@Sun.COM 	"SUNWbscdr",	/* SunLink BSC Drivers */
124*9781SMoriah.Waterland@Sun.COM 	"SUNWcosiA",	/* OSI Core Stack Kernel Files 1 */
125*9781SMoriah.Waterland@Sun.COM 	"SUNWcosiC",	/* Stack Mgmnt Utilities 2 */
126*9781SMoriah.Waterland@Sun.COM 	"SUNWcosia",	/* + OSI Core Stack Kernel Files */
127*9781SMoriah.Waterland@Sun.COM 	"SUNWcosib",	/* OSI Core Stack Configuration Files */
128*9781SMoriah.Waterland@Sun.COM 	"SUNWcosic",	/* OSI Core Stack Utilities */
129*9781SMoriah.Waterland@Sun.COM 	"SUNWcosid",	/* OSI Core Stack Development Kit (new pakage) */
130*9781SMoriah.Waterland@Sun.COM 	"SUNWcosij",	/* OSI Core Stack User Space Utilities */
131*9781SMoriah.Waterland@Sun.COM 	"SUNWdniCU",	/* + SunLink DNI Core Utilities 8.0 */
132*9781SMoriah.Waterland@Sun.COM 	"SUNWdniKR",	/* + SunLink DNI Kernel 8.0 */
133*9781SMoriah.Waterland@Sun.COM 	"SUNWdniMA",	/* SunLink DNI Mail Agent 8.0 */
134*9781SMoriah.Waterland@Sun.COM 	"SUNWflex",	/* + FLEX LM DEVEL PKG */
135*9781SMoriah.Waterland@Sun.COM 	"SUNWftama",	/* OSI FTAM Configuration Files */
136*9781SMoriah.Waterland@Sun.COM 	"SUNWftamb",	/* OSI FTAM Executable, Libraries and Man Pages */
137*9781SMoriah.Waterland@Sun.COM 	"SUNWhsis",	/* SunConnect HSI/S */
138*9781SMoriah.Waterland@Sun.COM 	"SUNWjaCL",	/* + Frances Ho confirms for SUNpics */
139*9781SMoriah.Waterland@Sun.COM 	"SUNWjncmt",	/* SunNet Manager Core Tools(Japan) */
140*9781SMoriah.Waterland@Sun.COM 	"SUNWjnmag",	/* SunNet Manager Agents & Libraries (Japan) */
141*9781SMoriah.Waterland@Sun.COM 	"SUNWjnmpd",	/* SunNet Manager SNMP daemon(Japan) */
142*9781SMoriah.Waterland@Sun.COM 	"SUNWlicsw",	/* + FLEXlm */
143*9781SMoriah.Waterland@Sun.COM 	"SUNWlit",	/* STE LIC INSTALL TOOL */
144*9781SMoriah.Waterland@Sun.COM 	"SUNWllc2a",	/* X.25 LLC2 KRNL MOD, INCLDS FL */
145*9781SMoriah.Waterland@Sun.COM 	"SUNWllc2b",	/* X.25 USR PROG, MAN PAGES */
146*9781SMoriah.Waterland@Sun.COM 	"SUNWmd",	/* + Suhas Patil request 1994-07-12 */
147*9781SMoriah.Waterland@Sun.COM 	"SUNWmhs1a",	/* MHS Message Transfer Agent Configuration Files */
148*9781SMoriah.Waterland@Sun.COM 	"SUNWmhs1b",	/* MHS Message Transfer Agent Executable and Man Pgs */
149*9781SMoriah.Waterland@Sun.COM 	"SUNWomgta",	/* OSI Mgmnt Configuration Files */
150*9781SMoriah.Waterland@Sun.COM 	"SUNWomgtb",	/* OSI Mgmnt Configuration Files */
151*9781SMoriah.Waterland@Sun.COM 	"SUNWomgtc",	/* OSI Mgmnt SunNet Mgr Proxy Agent Executable Files */
152*9781SMoriah.Waterland@Sun.COM 	"SUNWomgtd",	/* OSI Mgmnt SunNet Mgr Proxy Agent Config Files */
153*9781SMoriah.Waterland@Sun.COM 	"SUNWp2pnm",	/* SunLink SNA Peer-to-Peer Network Management */
154*9781SMoriah.Waterland@Sun.COM 	"SUNWprsto",	/* + Varun Mehta request 1994-07-11 */
155*9781SMoriah.Waterland@Sun.COM 	"SUNWrup2p",	/* Sunlink SNA Peer-to-Peer Run Time Environment */
156*9781SMoriah.Waterland@Sun.COM 	"SUNWs3270",	/* + SunLink SNA3270/RJE */
157*9781SMoriah.Waterland@Sun.COM 	"SUNWscmmd",	/* SunLink Comm Daemon */
158*9781SMoriah.Waterland@Sun.COM 	"SUNWsdlc",	/* SunLink IBM SDLC */
159*9781SMoriah.Waterland@Sun.COM 	"SUNWsm-ml",	/* ShowMe Motif Libs */
160*9781SMoriah.Waterland@Sun.COM 	"SUNWsm-ol",	/* ShowMe Online help */
161*9781SMoriah.Waterland@Sun.COM 	"SUNWsmCmg",
162*9781SMoriah.Waterland@Sun.COM 	"SUNWsmap",	/* SunLink Mapper */
163*9781SMoriah.Waterland@Sun.COM 	"SUNWsmaud",	/* ShowMe Audio */
164*9781SMoriah.Waterland@Sun.COM 	"SUNWsmsha",	/* ShowMe SharedApp */
165*9781SMoriah.Waterland@Sun.COM 	"SUNWsmvid",	/* ShowMe Video */
166*9781SMoriah.Waterland@Sun.COM 	"SUNWsmwtb",	/* ShowMe Whiteboard */
167*9781SMoriah.Waterland@Sun.COM 	"SUNWsnmag",	/* + Steve Wong request 1994-02-15 */
168*9781SMoriah.Waterland@Sun.COM 	"SUNWsnmct",	/* + Steve Wong request 1994-02-15 */
169*9781SMoriah.Waterland@Sun.COM 	"SUNWsnmja",	/* SunNet Manager 2.2 Japanese feature */
170*9781SMoriah.Waterland@Sun.COM 	"SUNWsnmpd",	/* SunNet Manager SNMP daemon */
171*9781SMoriah.Waterland@Sun.COM 	"SUNWsnp2p",	/* + SunLink SNA P-to-P */
172*9781SMoriah.Waterland@Sun.COM 	"SUNWspii",	/* 1.0 SPARCprinterII */
173*9781SMoriah.Waterland@Sun.COM 	"SUNWsrjec",	/* + SunLink Client SNA RJE */
174*9781SMoriah.Waterland@Sun.COM 	"SUNWsteCL",	/* + Frances Ho confirms for SUNPics */
175*9781SMoriah.Waterland@Sun.COM 	"SUNWsteNP",	/* 2.5 NeWSprint */
176*9781SMoriah.Waterland@Sun.COM 	"SUNWte320",	/* + TE320 8.0 */
177*9781SMoriah.Waterland@Sun.COM 	"SUNWtris",	/* SunConnect TRI/S */
178*9781SMoriah.Waterland@Sun.COM 	"SUNWvtcfg",	/* OSI Virtual Terminal Configuration Files */
179*9781SMoriah.Waterland@Sun.COM 	"SUNWvtexe",	/* OSI Virtual Terminal User Program and Man Pages */
180*9781SMoriah.Waterland@Sun.COM 	"SUNWx25a",	/* + X.25 KRNL MOD, INCLDS FLS */
181*9781SMoriah.Waterland@Sun.COM 	"SUNWx25b",	/* + X.25 USR PROG AND LIB */
182*9781SMoriah.Waterland@Sun.COM 	"zzzz1",	/* fill to avoid constraint tests in loop */
183*9781SMoriah.Waterland@Sun.COM 	"zzzz2",
184*9781SMoriah.Waterland@Sun.COM 	"zzzz3",
185*9781SMoriah.Waterland@Sun.COM 	"zzzz4"
186*9781SMoriah.Waterland@Sun.COM };
187*9781SMoriah.Waterland@Sun.COM #endif
188*9781SMoriah.Waterland@Sun.COM 
189*9781SMoriah.Waterland@Sun.COM /*
190*9781SMoriah.Waterland@Sun.COM  * Structure to hold the list of pkg names that are known to not behave
191*9781SMoriah.Waterland@Sun.COM  * properly when sym link destinations are not followed.
192*9781SMoriah.Waterland@Sun.COM  */
193*9781SMoriah.Waterland@Sun.COM 
194*9781SMoriah.Waterland@Sun.COM #ifdef	ALLOW_EXCEPTION_PKG_LIST
195*9781SMoriah.Waterland@Sun.COM static char *x_pkg_link[] =
196*9781SMoriah.Waterland@Sun.COM {
197*9781SMoriah.Waterland@Sun.COM 	"AAAA1",	/* fill to avoid constraint tests in loop */
198*9781SMoriah.Waterland@Sun.COM 	"AAAA2",
199*9781SMoriah.Waterland@Sun.COM 	"AAAA3",
200*9781SMoriah.Waterland@Sun.COM 	"AAAA4",
201*9781SMoriah.Waterland@Sun.COM 	/* '+' means packages known to be non-compliant */
202*9781SMoriah.Waterland@Sun.COM 	"SUNWixfta",
203*9781SMoriah.Waterland@Sun.COM 	"SUNWixsna",
204*9781SMoriah.Waterland@Sun.COM 	"zzzz1",	/* fill to avoid constraint tests in loop */
205*9781SMoriah.Waterland@Sun.COM 	"zzzz2",
206*9781SMoriah.Waterland@Sun.COM 	"zzzz3",
207*9781SMoriah.Waterland@Sun.COM 	"zzzz4"
208*9781SMoriah.Waterland@Sun.COM };
209*9781SMoriah.Waterland@Sun.COM #endif
210*9781SMoriah.Waterland@Sun.COM 
211*9781SMoriah.Waterland@Sun.COM /*
212*9781SMoriah.Waterland@Sun.COM  * This function determines if the package being added is a known old-style
213*9781SMoriah.Waterland@Sun.COM  * package which requires user interaction during procedure scripts. It is
214*9781SMoriah.Waterland@Sun.COM  * to be removed for on1095. -- JST
215*9781SMoriah.Waterland@Sun.COM  * It also is used for the determining if a pkg is known to have symlinks
216*9781SMoriah.Waterland@Sun.COM  * that need to be processed the old way.
217*9781SMoriah.Waterland@Sun.COM  */
218*9781SMoriah.Waterland@Sun.COM 
219*9781SMoriah.Waterland@Sun.COM #ifdef	ALLOW_EXCEPTION_PKG_LIST
220*9781SMoriah.Waterland@Sun.COM int
exception_pkg(char * pkginst,int pkg_list)221*9781SMoriah.Waterland@Sun.COM exception_pkg(char *pkginst, int pkg_list)
222*9781SMoriah.Waterland@Sun.COM {
223*9781SMoriah.Waterland@Sun.COM 	int	retvalue = 0;
224*9781SMoriah.Waterland@Sun.COM 	int	list_sz;
225*9781SMoriah.Waterland@Sun.COM 	int	list_cntr;	/* starting point for binary search */
226*9781SMoriah.Waterland@Sun.COM 	register int	pos;		/* current position */
227*9781SMoriah.Waterland@Sun.COM 	register int	level;		/* current height in the tree */
228*9781SMoriah.Waterland@Sun.COM 	register int 	incr;		/* increment for step */
229*9781SMoriah.Waterland@Sun.COM 	int	result;		/* result of strcmp */
230*9781SMoriah.Waterland@Sun.COM 	register char **x_ptr = x_pkg;
231*9781SMoriah.Waterland@Sun.COM 	register char **x_ptr_link = x_pkg_link;
232*9781SMoriah.Waterland@Sun.COM 	char	*pkgend;
233*9781SMoriah.Waterland@Sun.COM 	char	*pkgname = strdup(pkginst);
234*9781SMoriah.Waterland@Sun.COM 
235*9781SMoriah.Waterland@Sun.COM 	/*
236*9781SMoriah.Waterland@Sun.COM 	 * NOTE : If more structures need to be defined the following if
237*9781SMoriah.Waterland@Sun.COM 	 * statement needs to be revised to handle multiple flags
238*9781SMoriah.Waterland@Sun.COM 	 */
239*9781SMoriah.Waterland@Sun.COM 
240*9781SMoriah.Waterland@Sun.COM 	if (pkg_list)
241*9781SMoriah.Waterland@Sun.COM 		list_sz = (sizeof (x_pkg_link) / sizeof (char *));
242*9781SMoriah.Waterland@Sun.COM 	else
243*9781SMoriah.Waterland@Sun.COM 		list_sz = (sizeof (x_pkg) / sizeof (char *));
244*9781SMoriah.Waterland@Sun.COM 
245*9781SMoriah.Waterland@Sun.COM 	/*
246*9781SMoriah.Waterland@Sun.COM 	 * NOTE : shifts are used instead of integer division to save
247*9781SMoriah.Waterland@Sun.COM 	 * time. Numerous other checks are omitted also. This tree
248*9781SMoriah.Waterland@Sun.COM 	 * contains double nodes but is entirely connected and closed.
249*9781SMoriah.Waterland@Sun.COM 	 */
250*9781SMoriah.Waterland@Sun.COM 
251*9781SMoriah.Waterland@Sun.COM 	list_cntr = list_sz >> 1;
252*9781SMoriah.Waterland@Sun.COM 	incr = list_cntr - TREEFILL;
253*9781SMoriah.Waterland@Sun.COM 
254*9781SMoriah.Waterland@Sun.COM 	pkgend = strchr(pkgname, '.');
255*9781SMoriah.Waterland@Sun.COM 
256*9781SMoriah.Waterland@Sun.COM 	if (pkgend)
257*9781SMoriah.Waterland@Sun.COM 		*pkgend = '\0';	/* terminate the instance to a name */
258*9781SMoriah.Waterland@Sun.COM 
259*9781SMoriah.Waterland@Sun.COM 	for (level = TREEHEIGHT, 	/* start at the top level */
260*9781SMoriah.Waterland@Sun.COM 	    pos = list_cntr;		/*   ... in the middle */
261*9781SMoriah.Waterland@Sun.COM 	    level;		/* for as long as we're in the tree */
262*9781SMoriah.Waterland@Sun.COM 	    level--, pos += (result > 0) ? incr : -incr) {
263*9781SMoriah.Waterland@Sun.COM 
264*9781SMoriah.Waterland@Sun.COM 		if (pkg_list)
265*9781SMoriah.Waterland@Sun.COM 			result = strcmp(pkgname, *(x_ptr_link + pos));
266*9781SMoriah.Waterland@Sun.COM 		else
267*9781SMoriah.Waterland@Sun.COM 			result = strcmp(pkgname, *(x_ptr + pos));
268*9781SMoriah.Waterland@Sun.COM 
269*9781SMoriah.Waterland@Sun.COM 		if (result == 0) {
270*9781SMoriah.Waterland@Sun.COM 			retvalue = 1;
271*9781SMoriah.Waterland@Sun.COM 			break;
272*9781SMoriah.Waterland@Sun.COM 		}
273*9781SMoriah.Waterland@Sun.COM 
274*9781SMoriah.Waterland@Sun.COM 		incr = (incr & 0x0001) | (incr >> 1);	/* halve it & rnd up */
275*9781SMoriah.Waterland@Sun.COM 	}
276*9781SMoriah.Waterland@Sun.COM 
277*9781SMoriah.Waterland@Sun.COM 	free(pkgname);
278*9781SMoriah.Waterland@Sun.COM 
279*9781SMoriah.Waterland@Sun.COM 	return (retvalue);
280*9781SMoriah.Waterland@Sun.COM }
281*9781SMoriah.Waterland@Sun.COM 
282*9781SMoriah.Waterland@Sun.COM #endif
283*9781SMoriah.Waterland@Sun.COM 
284*9781SMoriah.Waterland@Sun.COM void
psvr4pkg(char ** ppkg)285*9781SMoriah.Waterland@Sun.COM psvr4pkg(char	**ppkg)
286*9781SMoriah.Waterland@Sun.COM {
287*9781SMoriah.Waterland@Sun.COM 	struct dirent *drp;
288*9781SMoriah.Waterland@Sun.COM 	DIR	*dirfp;
289*9781SMoriah.Waterland@Sun.COM 	char	*pt;
290*9781SMoriah.Waterland@Sun.COM 	int	n;
291*9781SMoriah.Waterland@Sun.COM 	char	ans[MAX_INPUT], path[PATH_MAX];
292*9781SMoriah.Waterland@Sun.COM 
293*9781SMoriah.Waterland@Sun.COM 	if (*ppkg) {
294*9781SMoriah.Waterland@Sun.COM 		(void) snprintf(path, sizeof (path),
295*9781SMoriah.Waterland@Sun.COM 				"/install/new/usr/options/%s.name",
296*9781SMoriah.Waterland@Sun.COM 				*ppkg);
297*9781SMoriah.Waterland@Sun.COM 		if (access(path, 0)) {
298*9781SMoriah.Waterland@Sun.COM 			ptext(stderr, gettext(MSG_NOTVER), *ppkg);
299*9781SMoriah.Waterland@Sun.COM 			if (n = ckyorn(ans, NULL, NULL, gettext(HLP_NOTVER),
300*9781SMoriah.Waterland@Sun.COM 			    gettext(ASK_CONT)))
301*9781SMoriah.Waterland@Sun.COM 				quit(n);
302*9781SMoriah.Waterland@Sun.COM 			if (strchr("yY", *ans) == NULL)
303*9781SMoriah.Waterland@Sun.COM 				quit(3);
304*9781SMoriah.Waterland@Sun.COM 		}
305*9781SMoriah.Waterland@Sun.COM 		return;
306*9781SMoriah.Waterland@Sun.COM 	}
307*9781SMoriah.Waterland@Sun.COM 
308*9781SMoriah.Waterland@Sun.COM 	if (dirfp = opendir("/install/new/usr/options")) {
309*9781SMoriah.Waterland@Sun.COM 		while (drp = readdir(dirfp)) {
310*9781SMoriah.Waterland@Sun.COM 			if (drp->d_name[0] == '.')
311*9781SMoriah.Waterland@Sun.COM 				continue;
312*9781SMoriah.Waterland@Sun.COM 			if (pt = strchr(drp->d_name, '.')) {
313*9781SMoriah.Waterland@Sun.COM 				if (strcmp(pt, ".name") == 0) {
314*9781SMoriah.Waterland@Sun.COM 					*pt = '\0';
315*9781SMoriah.Waterland@Sun.COM 					*ppkg = qstrdup(drp->d_name);
316*9781SMoriah.Waterland@Sun.COM 					break;
317*9781SMoriah.Waterland@Sun.COM 				}
318*9781SMoriah.Waterland@Sun.COM 			}
319*9781SMoriah.Waterland@Sun.COM 		}
320*9781SMoriah.Waterland@Sun.COM 		(void) closedir(dirfp);
321*9781SMoriah.Waterland@Sun.COM 	}
322*9781SMoriah.Waterland@Sun.COM 
323*9781SMoriah.Waterland@Sun.COM 	if (*ppkg) {
324*9781SMoriah.Waterland@Sun.COM 		ptext(stderr, gettext(MSG_CONFIRM), *ppkg);
325*9781SMoriah.Waterland@Sun.COM 		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_CONFIRM),
326*9781SMoriah.Waterland@Sun.COM 		    gettext(ASK_CONT)))
327*9781SMoriah.Waterland@Sun.COM 			quit(n);
328*9781SMoriah.Waterland@Sun.COM 	} else {
329*9781SMoriah.Waterland@Sun.COM 		ptext(stderr, gettext(MSG_NOTVER), *ppkg);
330*9781SMoriah.Waterland@Sun.COM 		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_NOTVER),
331*9781SMoriah.Waterland@Sun.COM 		    gettext(ASK_CONT)))
332*9781SMoriah.Waterland@Sun.COM 			quit(n);
333*9781SMoriah.Waterland@Sun.COM 	}
334*9781SMoriah.Waterland@Sun.COM 	if (strchr("yY", *ans) == NULL)
335*9781SMoriah.Waterland@Sun.COM 		quit(3);
336*9781SMoriah.Waterland@Sun.COM }
337*9781SMoriah.Waterland@Sun.COM 
338*9781SMoriah.Waterland@Sun.COM void
psvr4cnflct(void)339*9781SMoriah.Waterland@Sun.COM psvr4cnflct(void)
340*9781SMoriah.Waterland@Sun.COM {
341*9781SMoriah.Waterland@Sun.COM 	FILE	*pp;
342*9781SMoriah.Waterland@Sun.COM 	int	n, found;
343*9781SMoriah.Waterland@Sun.COM 	char	*pt,
344*9781SMoriah.Waterland@Sun.COM 		ans[MAX_INPUT],
345*9781SMoriah.Waterland@Sun.COM 		cmd[PATH_MAX+sizeof (ckcmd)],
346*9781SMoriah.Waterland@Sun.COM 		path[PATH_MAX];
347*9781SMoriah.Waterland@Sun.COM 
348*9781SMoriah.Waterland@Sun.COM 	for (n = 0; Rlist[n] != NULL; n++) {
349*9781SMoriah.Waterland@Sun.COM 		if (access(Rlist[n], 0) == 0)
350*9781SMoriah.Waterland@Sun.COM 			break;
351*9781SMoriah.Waterland@Sun.COM 	}
352*9781SMoriah.Waterland@Sun.COM 	if (Rlist[n] == NULL)
353*9781SMoriah.Waterland@Sun.COM 		return; /* Rlist file not found on device */
354*9781SMoriah.Waterland@Sun.COM 
355*9781SMoriah.Waterland@Sun.COM 	(void) sprintf(cmd, ckcmd, Rlist[n]);
356*9781SMoriah.Waterland@Sun.COM 	echo(gettext("## Checking for conflicts with installed packages"));
357*9781SMoriah.Waterland@Sun.COM 	echo(gettext("   (using %s provided by pre-SVR4 package)"), Rlist[n]);
358*9781SMoriah.Waterland@Sun.COM 	if ((pp = popen(cmd, "r")) == NULL) {
359*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PIPE), cmd);
360*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_OVERWRITE));
361*9781SMoriah.Waterland@Sun.COM 		quit(99);
362*9781SMoriah.Waterland@Sun.COM 	}
363*9781SMoriah.Waterland@Sun.COM 
364*9781SMoriah.Waterland@Sun.COM 	found = 0;
365*9781SMoriah.Waterland@Sun.COM 	while (fgets(path, PATH_MAX, pp)) {
366*9781SMoriah.Waterland@Sun.COM 		if (!found++)
367*9781SMoriah.Waterland@Sun.COM 			ptext(stderr, gettext(MSG_CONFLICT));
368*9781SMoriah.Waterland@Sun.COM 		if (pt = strpbrk(path, " \t\n"))
369*9781SMoriah.Waterland@Sun.COM 			*pt = '\0';
370*9781SMoriah.Waterland@Sun.COM 		echo("\t%s", path);
371*9781SMoriah.Waterland@Sun.COM 	}
372*9781SMoriah.Waterland@Sun.COM 	if (pclose(pp)) {
373*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_OVERWRITE));
374*9781SMoriah.Waterland@Sun.COM 		quit(99);
375*9781SMoriah.Waterland@Sun.COM 	}
376*9781SMoriah.Waterland@Sun.COM 
377*9781SMoriah.Waterland@Sun.COM 	if (found) {
378*9781SMoriah.Waterland@Sun.COM 		if (n = ckyorn(ans, NULL, NULL, gettext(HLP_CONFLICT),
379*9781SMoriah.Waterland@Sun.COM 		    gettext(ASK_CONT)))
380*9781SMoriah.Waterland@Sun.COM 			quit(n);
381*9781SMoriah.Waterland@Sun.COM 		if (strchr("yY", *ans) == NULL)
382*9781SMoriah.Waterland@Sun.COM 			quit(3);
383*9781SMoriah.Waterland@Sun.COM 	}
384*9781SMoriah.Waterland@Sun.COM }
385*9781SMoriah.Waterland@Sun.COM 
386*9781SMoriah.Waterland@Sun.COM void
psvr4mail(char * list,char * msg,int retcode,char * pkg)387*9781SMoriah.Waterland@Sun.COM psvr4mail(char *list, char *msg, int retcode, char *pkg)
388*9781SMoriah.Waterland@Sun.COM {
389*9781SMoriah.Waterland@Sun.COM 	struct utsname utsbuf;
390*9781SMoriah.Waterland@Sun.COM 	FILE	*pp;
391*9781SMoriah.Waterland@Sun.COM 	char	cmd[BUFSIZ];
392*9781SMoriah.Waterland@Sun.COM 
393*9781SMoriah.Waterland@Sun.COM 	if (list == NULL)
394*9781SMoriah.Waterland@Sun.COM 		return;
395*9781SMoriah.Waterland@Sun.COM 
396*9781SMoriah.Waterland@Sun.COM 	while (isspace(*list))
397*9781SMoriah.Waterland@Sun.COM 		list++;
398*9781SMoriah.Waterland@Sun.COM 	if (*list == '\0')
399*9781SMoriah.Waterland@Sun.COM 		return;
400*9781SMoriah.Waterland@Sun.COM 
401*9781SMoriah.Waterland@Sun.COM 	/* send e-mail notifications */
402*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(cmd, sizeof (cmd), "%s %s", MAILCMD, list);
403*9781SMoriah.Waterland@Sun.COM 	if ((pp = popen(cmd, "w")) == NULL) {
404*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PIPE), MAILCMD);
405*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_MAIL));
406*9781SMoriah.Waterland@Sun.COM 		quit(99);
407*9781SMoriah.Waterland@Sun.COM 	}
408*9781SMoriah.Waterland@Sun.COM 
409*9781SMoriah.Waterland@Sun.COM 	(void) strcpy(utsbuf.nodename, gettext("(unknown)"));
410*9781SMoriah.Waterland@Sun.COM 	(void) uname(&utsbuf);
411*9781SMoriah.Waterland@Sun.COM 	ptext(pp, msg, pkg, utsbuf.nodename, retcode);
412*9781SMoriah.Waterland@Sun.COM 
413*9781SMoriah.Waterland@Sun.COM 	if (pclose(pp)) {
414*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_MAIL));
415*9781SMoriah.Waterland@Sun.COM 		quit(99);
416*9781SMoriah.Waterland@Sun.COM 	}
417*9781SMoriah.Waterland@Sun.COM }
418