check.c revision 9781:ccf49524d5dc
10SN/A/*
2157SN/A * CDDL HEADER START
30SN/A *
40SN/A * The contents of this file are subject to the terms of the
50SN/A * Common Development and Distribution License (the "License").
60SN/A * You may not use this file except in compliance with the License.
7157SN/A *
80SN/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9157SN/A * or http://www.opensolaris.org/os/licensing.
100SN/A * See the License for the specific language governing permissions
110SN/A * and limitations under the License.
120SN/A *
130SN/A * When distributing Covered Code, include this CDDL HEADER in each
140SN/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150SN/A * If applicable, add the following below this CDDL HEADER, with the
160SN/A * fields enclosed by brackets "[]" replaced with your own identifying
170SN/A * information: Portions Copyright [yyyy] [name of copyright owner]
180SN/A *
190SN/A * CDDL HEADER END
200SN/A */
21157SN/A
22157SN/A/*
23157SN/A * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
240SN/A * Use is subject to license terms.
250SN/A */
260SN/A
270SN/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
280SN/A/* All Rights Reserved */
290SN/A
300SN/A
310SN/A#include <stdio.h>
320SN/A#include <stdlib.h>
330SN/A#include <unistd.h>
340SN/A#include <string.h>
350SN/A#ifndef SUNOS41
360SN/A#include <utmpx.h>
370SN/A#endif
380SN/A#include <dirent.h>
390SN/A#include <sys/types.h>
400SN/A#include <pkgstrct.h>
410SN/A#include <locale.h>
420SN/A#include <libintl.h>
430SN/A#include "install.h"
440SN/A#include <pkglib.h>
450SN/A#include "libadm.h"
460SN/A#include "libinst.h"
470SN/A#include "wsreg_pkgrm.h"
480SN/A#include "messages.h"
490SN/A
500SN/Aextern struct admin adm;
510SN/A/* extern struct cfent **eptlist; */
520SN/A
530SN/Aextern char	pkgloc[], *pkginst, *msgtext;
540SN/A
550SN/Astatic boolean_t	preremoveCheck = B_FALSE;
560SN/Astatic char		*zoneName = (char *)NULL;
570SN/A
580SN/A
590SN/Avoid
600SN/ArcksetPreremoveCheck(boolean_t a_preremoveCheck)
610SN/A{
620SN/A	preremoveCheck = a_preremoveCheck;
630SN/A}
640SN/A
650SN/Avoid
660SN/ArcksetZoneName(char *a_zoneName)
670SN/A{
680SN/A	zoneName = a_zoneName;
690SN/A}
700SN/A
710SN/Aint
720SN/Arckrunlevel(void)
730SN/A{
740SN/A	struct utmpx utmpx;
750SN/A	struct utmpx *putmpx;
760SN/A	char	ans[MAX_INPUT];
770SN/A	char	*pt;
780SN/A	char	*rstates;
790SN/A	int	n;
800SN/A	char	*uxstate;
810SN/A
820SN/A	if (ADM(runlevel, "nocheck")) {
830SN/A		return (0);
840SN/A	}
850SN/A
860SN/A	pt = getenv("RSTATES");
870SN/A	if (pt == NULL) {
880SN/A		return (0);
890SN/A	}
900SN/A
910SN/A	utmpx.ut_type = RUN_LVL;
920SN/A	putmpx = getutxid(&utmpx);
930SN/A	if (putmpx == NULL) {
940SN/A		progerr(ERR_RUNSTATE);
950SN/A		return (99);
960SN/A	}
970SN/A	uxstate = strtok(&putmpx->ut_line[10], " \t\n");
980SN/A
990SN/A	rstates = qstrdup(pt);
1000SN/A	if ((pt = strtok(pt, " \t\n, ")) == NULL)
1010SN/A		return (0); /* no list is no list */
1020SN/A	do {
1030SN/A		if (strcmp(pt, uxstate) == NULL) {
1040SN/A			free(rstates);
1050SN/A			return (0);
1060SN/A		}
1070SN/A	} while (pt = strtok(NULL, " \t\n, "));
1080SN/A
1090SN/A	if (preremoveCheck == B_FALSE) {
1100SN/A		msgtext = MSG_PKGREMOVE_RUNLEVEL;
1110SN/A		ptext(stderr, msgtext, uxstate);
1120SN/A	} else {
1130SN/A		(void) fprintf(stdout, "runlevel=%s", uxstate);
1140SN/A	}
1150SN/A
1160SN/A	pt = strtok(rstates, " \t\n, ");
1170SN/A	do {
1180SN/A		if (preremoveCheck == B_FALSE) {
1190SN/A			ptext(stderr, "\\t%s", pt);
1200SN/A		} else {
1210SN/A			(void) fprintf(stdout, ":%s", pt);
1220SN/A		}
1230SN/A	} while (pt = strtok(NULL, " \t\n, "));
1240SN/A
1250SN/A	if (preremoveCheck == B_TRUE) {
1260SN/A		(void) fprintf(stdout, "\n");
1270SN/A	}
1280SN/A
1290SN/A	free(rstates);
1300SN/A
1310SN/A	if (ADM(runlevel, "quit")) {
1320SN/A		return (4);
1330SN/A	}
1340SN/A
1350SN/A	if (echoGetFlag() == B_FALSE) {
1360SN/A		return (5);
1370SN/A	}
1380SN/A
1390SN/A	msgtext = NULL;
1400SN/A
1410SN/A	n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_RUNLEVEL,
1420SN/A	    ASK_PKGREMOVE_CONTINUE);
1430SN/A
1440SN/A	if (n != 0) {
1450SN/A		return (n);
1460SN/A	}
1470SN/A
1480SN/A	if (strchr("yY", *ans) == NULL) {
1490SN/A		return (3);
1500SN/A	}
1510SN/A
1520SN/A	return (0);
1530SN/A}
1540SN/A
1550SN/Aint
1560SN/Arckpatchpkg(char *p, char *pt)
1570SN/A{
1580SN/A	int n;
1590SN/A	char ans[MAX_INPUT];
1600SN/A
1610SN/A	ptext(stderr, WRN_PKGREMOVE_PATCHES, p, p, p, pt);
1620SN/A
1630SN/A	n = ckyorn(ans, NULL, NULL, NULL, ASK_PKGREMOVE_CONTINUE);
1640SN/A
1650SN/A	if (n != 0) {
1660SN/A		return (n);
1670SN/A	}
1680SN/A
1690SN/A	if (strchr("yY", *ans) == NULL) {
1700SN/A		return (3);
1710SN/A	}
1720SN/A
1730SN/A	return (0);
1740SN/A}
1750SN/A
1760SN/Aint
1770SN/Arckdepend(void)
1780SN/A{
1790SN/A	int	n;
1800SN/A	char	ans[MAX_INPUT];
1810SN/A	char	**id, **name;
1820SN/A
1830SN/A	if (ADM(rdepend, "nocheck")) {
1840SN/A		return (0);
1850SN/A	}
1860SN/A
1870SN/A	if (zoneName == (char *)NULL) {
1880SN/A		echo(MSG_CHECKREMOVE_PKG_IN_GZ, pkginst);
1890SN/A	} else {
1900SN/A		echo(MSG_CHECKREMOVE_PKG_IN_ZONE, pkginst, zoneName);
1910SN/A	}
1920SN/A
1930SN/A	if (wsreg_pkgrm_check(get_inst_root(), pkginst, &id, &name) > 0) {
1940SN/A		int i;
1950SN/A
1960SN/A		if (ADM(rdepend, "quit")) {
1970SN/A			return (4);
1980SN/A		}
1990SN/A
2000SN/A		if (echoGetFlag() == B_FALSE) {
201			return (5);
202		}
203
204		msgtext = MSG_PKGREMOVE_WSDEPEND;
205		echo(msgtext);
206
207		(void) printf("%-36s  %s", MSG_PKGREMOVE_ID_STR,
208		    MSG_PKGREMOVE_NAME_STR);
209		(void) printf("\n------------------------------------  "
210		    "--------------------------------------\n");
211
212		for (i = 0; id[i] != NULL; i++) {
213			(void) printf("%-36s  %s\n", id[i],
214			    (name[i])?(name[i]):"");
215			free(id[i]);
216			if (name[i]) {
217				free(name[i]);
218			}
219		}
220
221		free(id);
222		free(name);
223
224		msgtext = NULL;
225
226		n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_WSDEPEND,
227		    ASK_PKGREMOVE_CONTINUE);
228
229		if (n != 0) {
230			return (n);
231		}
232
233		if (strchr("yY", *ans) == NULL) {
234			return (3);
235		}
236	}
237
238	if (dockdeps(pkginst, 1, preremoveCheck)) {
239		msgtext = MSG_PKGREMOVE_DEPEND;
240
241		if (preremoveCheck == B_FALSE) {
242			echo(msgtext);
243		}
244
245		if (ADM(rdepend, "quit")) {
246			return (4);
247		}
248
249		if (echoGetFlag() == B_FALSE) {
250			return (5);
251		}
252
253		msgtext = NULL;
254
255		n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_DEPEND,
256		    ASK_PKGREMOVE_CONTINUE);
257
258		if (n != 0) {
259			return (n);
260		}
261
262		if (strchr("yY", *ans) == NULL) {
263			return (3);
264		}
265	}
266
267	return (0);
268}
269
270int
271rckpriv(void)
272{
273	struct dirent	*dp;
274	DIR		*dirfp;
275	int		n;
276	char		found;
277	char		ans[MAX_INPUT];
278	char		path[PATH_MAX];
279
280	if (ADM(action, "nocheck")) {
281		return (0);
282	}
283
284	(void) snprintf(path, sizeof (path), "%s/install", pkgloc);
285	if ((dirfp = opendir(path)) == NULL)
286		return (0);
287
288	found = 0;
289	while ((dp = readdir(dirfp)) != NULL) {
290		if ((strcmp(dp->d_name, "preremove") == NULL) ||
291		    (strcmp(dp->d_name, "postremove") == NULL) ||
292		    (strncmp(dp->d_name, "r.", 2) == NULL)) {
293			found++;
294			break;
295		}
296	}
297	(void) closedir(dirfp);
298
299	if (found) {
300		if (preremoveCheck == B_FALSE) {
301			ptext(stderr, MSG_PKGREMOVE_PRIV);
302		}
303		msgtext = MSG_PKGSCRIPTS_FOUND;
304
305		if (ADM(action, "quit")) {
306			return (4);
307		}
308
309		if (echoGetFlag() == B_FALSE) {
310			return (5);
311		}
312
313		msgtext = NULL;
314
315		n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_PRIV,
316		    ASK_PKGREMOVE_CONTINUE);
317
318		if (n != 0) {
319			return (n);
320		}
321
322		if (strchr("yY", *ans) == NULL) {
323			return (3);
324		}
325	}
326
327	return (0);
328}
329