xref: /titanic_52/usr/src/cmd/svr4pkg/pkgremove/delmap.c (revision 5c51f1241dbbdf2656d0e10011981411ed0c9673)
1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland  * CDDL HEADER START
3*5c51f124SMoriah Waterland  *
4*5c51f124SMoriah Waterland  * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland  * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland  * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland  *
8*5c51f124SMoriah Waterland  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland  * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland  * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland  * and limitations under the License.
12*5c51f124SMoriah Waterland  *
13*5c51f124SMoriah Waterland  * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland  * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland  * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland  *
19*5c51f124SMoriah Waterland  * CDDL HEADER END
20*5c51f124SMoriah Waterland  */
21*5c51f124SMoriah Waterland 
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*5c51f124SMoriah Waterland  * Use is subject to license terms.
25*5c51f124SMoriah Waterland  */
26*5c51f124SMoriah Waterland 
27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*5c51f124SMoriah Waterland /* All Rights Reserved */
29*5c51f124SMoriah Waterland 
30*5c51f124SMoriah Waterland 
31*5c51f124SMoriah Waterland #include <stdio.h>
32*5c51f124SMoriah Waterland #include <errno.h>
33*5c51f124SMoriah Waterland #include <string.h>
34*5c51f124SMoriah Waterland #include <limits.h>
35*5c51f124SMoriah Waterland #include <stdlib.h>
36*5c51f124SMoriah Waterland #include <unistd.h>
37*5c51f124SMoriah Waterland #include <sys/types.h>
38*5c51f124SMoriah Waterland #include <pkgstrct.h>
39*5c51f124SMoriah Waterland #include <locale.h>
40*5c51f124SMoriah Waterland #include <libintl.h>
41*5c51f124SMoriah Waterland #include <pkglib.h>
42*5c51f124SMoriah Waterland #include <libadm.h>
43*5c51f124SMoriah Waterland #include <libinst.h>
44*5c51f124SMoriah Waterland 
45*5c51f124SMoriah Waterland extern int	dbchg, warnflag, otherstoo;
46*5c51f124SMoriah Waterland extern char	*pkginst;
47*5c51f124SMoriah Waterland 
48*5c51f124SMoriah Waterland #define	EPTMALLOC	128
49*5c51f124SMoriah Waterland 
50*5c51f124SMoriah Waterland #define	ERR_WRENT	"write of entry failed, errno=%d"
51*5c51f124SMoriah Waterland #define	ERR_MEMORY	"no memory, errno=%d"
52*5c51f124SMoriah Waterland #define	ERR_READ_C	"bad read of contents file"
53*5c51f124SMoriah Waterland #define	ERR_READ_DB	"bad read of the database"
54*5c51f124SMoriah Waterland 
55*5c51f124SMoriah Waterland extern struct cfent	**eptlist;
56*5c51f124SMoriah Waterland extern int	eptnum;
57*5c51f124SMoriah Waterland 
58*5c51f124SMoriah Waterland int
59*5c51f124SMoriah Waterland delmap(int flag, char *pkginst)
60*5c51f124SMoriah Waterland {
61*5c51f124SMoriah Waterland 	struct cfent	*ept;
62*5c51f124SMoriah Waterland 	struct pinfo	*pinfo;
63*5c51f124SMoriah Waterland 	VFP_T		*vfp;
64*5c51f124SMoriah Waterland 	VFP_T		*vfpo;
65*5c51f124SMoriah Waterland 	int		n;
66*5c51f124SMoriah Waterland 	char		*unknown = "Unknown";
67*5c51f124SMoriah Waterland 
68*5c51f124SMoriah Waterland 
69*5c51f124SMoriah Waterland 	if (!ocfile(&vfp, &vfpo, 0L)) {
70*5c51f124SMoriah Waterland 		quit(99);
71*5c51f124SMoriah Waterland 	}
72*5c51f124SMoriah Waterland 
73*5c51f124SMoriah Waterland 	/* re-use any memory used to store pathnames */
74*5c51f124SMoriah Waterland 	(void) pathdup(NULL);
75*5c51f124SMoriah Waterland 
76*5c51f124SMoriah Waterland 	if (eptlist != NULL)
77*5c51f124SMoriah Waterland 		free(eptlist);
78*5c51f124SMoriah Waterland 	eptlist = (struct cfent **)calloc(EPTMALLOC,
79*5c51f124SMoriah Waterland 					sizeof (struct cfent *));
80*5c51f124SMoriah Waterland 	if (eptlist == NULL) {
81*5c51f124SMoriah Waterland 		progerr(gettext(ERR_MEMORY), errno);
82*5c51f124SMoriah Waterland 		quit(99);
83*5c51f124SMoriah Waterland 	}
84*5c51f124SMoriah Waterland 
85*5c51f124SMoriah Waterland 	ept = (struct cfent *)calloc(1,
86*5c51f124SMoriah Waterland 				(unsigned)sizeof (struct cfent));
87*5c51f124SMoriah Waterland 	if (!ept) {
88*5c51f124SMoriah Waterland 		progerr(gettext(ERR_MEMORY), errno);
89*5c51f124SMoriah Waterland 		quit(99);
90*5c51f124SMoriah Waterland 	}
91*5c51f124SMoriah Waterland 
92*5c51f124SMoriah Waterland 	eptnum = 0;
93*5c51f124SMoriah Waterland 	while (n = srchcfile(ept, "*", vfp, (VFP_T *)NULL)) {
94*5c51f124SMoriah Waterland 		if (n < 0) {
95*5c51f124SMoriah Waterland 			char	*errstr = getErrstr();
96*5c51f124SMoriah Waterland 			progerr(gettext("bad read of contents file"));
97*5c51f124SMoriah Waterland 			progerr(gettext("pathname=%s"),
98*5c51f124SMoriah Waterland 				(ept->path && *ept->path) ? ept->path :
99*5c51f124SMoriah Waterland 				unknown);
100*5c51f124SMoriah Waterland 			progerr(gettext("problem=%s"),
101*5c51f124SMoriah Waterland 				(errstr && *errstr) ? errstr : unknown);
102*5c51f124SMoriah Waterland 			exit(99);
103*5c51f124SMoriah Waterland 		}
104*5c51f124SMoriah Waterland 		pinfo = eptstat(ept, pkginst, (flag ? '@' : '-'));
105*5c51f124SMoriah Waterland 		if (ept->npkgs > 0) {
106*5c51f124SMoriah Waterland 			if (putcvfpfile(ept, vfpo)) {
107*5c51f124SMoriah Waterland 				progerr(gettext(ERR_WRENT), errno);
108*5c51f124SMoriah Waterland 				quit(99);
109*5c51f124SMoriah Waterland 			}
110*5c51f124SMoriah Waterland 		}
111*5c51f124SMoriah Waterland 
112*5c51f124SMoriah Waterland 		if (flag || (pinfo == NULL))
113*5c51f124SMoriah Waterland 			continue;
114*5c51f124SMoriah Waterland 
115*5c51f124SMoriah Waterland 		dbchg++;
116*5c51f124SMoriah Waterland 
117*5c51f124SMoriah Waterland 		/*
118*5c51f124SMoriah Waterland 		 * If (otherstoo > 0), more than one package has an
119*5c51f124SMoriah Waterland 		 * interest in the ept entry in the database. Setting
120*5c51f124SMoriah Waterland 		 * ept->ftype = '\0' effectively marks the file as being
121*5c51f124SMoriah Waterland 		 * "shared", thus ensuring the ept entry will not
122*5c51f124SMoriah Waterland 		 * subsequently be removed. Shared editable files (ftype
123*5c51f124SMoriah Waterland 		 * 'e') are a special case: they should be passed to a
124*5c51f124SMoriah Waterland 		 * class action script if present. Setting ept->ftype =
125*5c51f124SMoriah Waterland 		 * '^' indicates this special case of shared editable
126*5c51f124SMoriah Waterland 		 * file, allowing the distinction to be made later.
127*5c51f124SMoriah Waterland 		 */
128*5c51f124SMoriah Waterland 		if (!pinfo->editflag && otherstoo)
129*5c51f124SMoriah Waterland 			ept->ftype = (ept->ftype == 'e') ? '^' : '\0';
130*5c51f124SMoriah Waterland 		if (*pinfo->aclass)
131*5c51f124SMoriah Waterland 			(void) strcpy(ept->pkg_class, pinfo->aclass);
132*5c51f124SMoriah Waterland 		eptlist[eptnum] = ept;
133*5c51f124SMoriah Waterland 
134*5c51f124SMoriah Waterland 		ept->path = pathdup(ept->path);
135*5c51f124SMoriah Waterland 		if (ept->ainfo.local != NULL)
136*5c51f124SMoriah Waterland 			ept->ainfo.local = pathdup(ept->ainfo.local);
137*5c51f124SMoriah Waterland 
138*5c51f124SMoriah Waterland 		ept = (struct cfent *)calloc(1, sizeof (struct cfent));
139*5c51f124SMoriah Waterland 		if ((++eptnum % EPTMALLOC) == 0) {
140*5c51f124SMoriah Waterland 			eptlist = (struct cfent **)realloc(eptlist,
141*5c51f124SMoriah Waterland 			(eptnum+EPTMALLOC)*sizeof (struct cfent *));
142*5c51f124SMoriah Waterland 			if (eptlist == NULL) {
143*5c51f124SMoriah Waterland 				progerr(gettext(ERR_MEMORY), errno);
144*5c51f124SMoriah Waterland 				quit(99);
145*5c51f124SMoriah Waterland 			}
146*5c51f124SMoriah Waterland 		}
147*5c51f124SMoriah Waterland 	}
148*5c51f124SMoriah Waterland 
149*5c51f124SMoriah Waterland 	eptlist[eptnum] = (struct cfent *)NULL;
150*5c51f124SMoriah Waterland 
151*5c51f124SMoriah Waterland 	n = swapcfile(&vfp, &vfpo, pkginst, dbchg);
152*5c51f124SMoriah Waterland 	if (n == RESULT_WRN) {
153*5c51f124SMoriah Waterland 		warnflag++;
154*5c51f124SMoriah Waterland 	} else if (n == RESULT_ERR) {
155*5c51f124SMoriah Waterland 		quit(99);
156*5c51f124SMoriah Waterland 	}
157*5c51f124SMoriah Waterland 
158*5c51f124SMoriah Waterland 	return (0);
159*5c51f124SMoriah Waterland }
160