19781SMoriah.Waterland@Sun.COM /*
29781SMoriah.Waterland@Sun.COM * CDDL HEADER START
39781SMoriah.Waterland@Sun.COM *
49781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the
59781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License").
69781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License.
79781SMoriah.Waterland@Sun.COM *
89781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing.
109781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions
119781SMoriah.Waterland@Sun.COM * and limitations under the License.
129781SMoriah.Waterland@Sun.COM *
139781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
149781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
169781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
179781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
189781SMoriah.Waterland@Sun.COM *
199781SMoriah.Waterland@Sun.COM * CDDL HEADER END
209781SMoriah.Waterland@Sun.COM */
219781SMoriah.Waterland@Sun.COM
229781SMoriah.Waterland@Sun.COM /*
23*9869SCasper.Dik@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
249781SMoriah.Waterland@Sun.COM * Use is subject to license terms.
259781SMoriah.Waterland@Sun.COM */
269781SMoriah.Waterland@Sun.COM
279781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
289781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
299781SMoriah.Waterland@Sun.COM
309781SMoriah.Waterland@Sun.COM
319781SMoriah.Waterland@Sun.COM #include <stdio.h>
329781SMoriah.Waterland@Sun.COM #include <errno.h>
339781SMoriah.Waterland@Sun.COM #include <string.h>
349781SMoriah.Waterland@Sun.COM #include <limits.h>
359781SMoriah.Waterland@Sun.COM #include <stdlib.h>
369781SMoriah.Waterland@Sun.COM #include <unistd.h>
379781SMoriah.Waterland@Sun.COM #include <sys/types.h>
389781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
399781SMoriah.Waterland@Sun.COM #include <locale.h>
409781SMoriah.Waterland@Sun.COM #include <libintl.h>
419781SMoriah.Waterland@Sun.COM #include <pkglib.h>
429781SMoriah.Waterland@Sun.COM #include <libadm.h>
439781SMoriah.Waterland@Sun.COM #include <libinst.h>
449781SMoriah.Waterland@Sun.COM
459781SMoriah.Waterland@Sun.COM extern int dbchg, warnflag, otherstoo;
469781SMoriah.Waterland@Sun.COM extern char *pkginst;
479781SMoriah.Waterland@Sun.COM
489781SMoriah.Waterland@Sun.COM #define EPTMALLOC 128
499781SMoriah.Waterland@Sun.COM
509781SMoriah.Waterland@Sun.COM #define ERR_WRENT "write of entry failed, errno=%d"
519781SMoriah.Waterland@Sun.COM #define ERR_MEMORY "no memory, errno=%d"
529781SMoriah.Waterland@Sun.COM #define ERR_READ_C "bad read of contents file"
539781SMoriah.Waterland@Sun.COM #define ERR_READ_DB "bad read of the database"
549781SMoriah.Waterland@Sun.COM
559781SMoriah.Waterland@Sun.COM extern struct cfent **eptlist;
569781SMoriah.Waterland@Sun.COM extern int eptnum;
579781SMoriah.Waterland@Sun.COM
589781SMoriah.Waterland@Sun.COM int
delmap(int flag,char * pkginst,PKGserver * pkgserver,VFP_T ** tmpfp)59*9869SCasper.Dik@Sun.COM delmap(int flag, char *pkginst, PKGserver *pkgserver, VFP_T **tmpfp)
609781SMoriah.Waterland@Sun.COM {
619781SMoriah.Waterland@Sun.COM struct cfent *ept;
629781SMoriah.Waterland@Sun.COM struct pinfo *pinfo;
639781SMoriah.Waterland@Sun.COM int n;
649781SMoriah.Waterland@Sun.COM char *unknown = "Unknown";
659781SMoriah.Waterland@Sun.COM
669781SMoriah.Waterland@Sun.COM
67*9869SCasper.Dik@Sun.COM if (!ocfile(pkgserver, tmpfp, 0L) ||
68*9869SCasper.Dik@Sun.COM pkgopenfilter(*pkgserver, pkginst) != 0) {
699781SMoriah.Waterland@Sun.COM quit(99);
709781SMoriah.Waterland@Sun.COM }
719781SMoriah.Waterland@Sun.COM
729781SMoriah.Waterland@Sun.COM /* re-use any memory used to store pathnames */
739781SMoriah.Waterland@Sun.COM (void) pathdup(NULL);
749781SMoriah.Waterland@Sun.COM
759781SMoriah.Waterland@Sun.COM if (eptlist != NULL)
769781SMoriah.Waterland@Sun.COM free(eptlist);
779781SMoriah.Waterland@Sun.COM eptlist = (struct cfent **)calloc(EPTMALLOC,
789781SMoriah.Waterland@Sun.COM sizeof (struct cfent *));
799781SMoriah.Waterland@Sun.COM if (eptlist == NULL) {
809781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_MEMORY), errno);
819781SMoriah.Waterland@Sun.COM quit(99);
829781SMoriah.Waterland@Sun.COM }
839781SMoriah.Waterland@Sun.COM
849781SMoriah.Waterland@Sun.COM ept = (struct cfent *)calloc(1,
859781SMoriah.Waterland@Sun.COM (unsigned)sizeof (struct cfent));
869781SMoriah.Waterland@Sun.COM if (!ept) {
879781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_MEMORY), errno);
889781SMoriah.Waterland@Sun.COM quit(99);
899781SMoriah.Waterland@Sun.COM }
909781SMoriah.Waterland@Sun.COM
919781SMoriah.Waterland@Sun.COM eptnum = 0;
92*9869SCasper.Dik@Sun.COM while (n = srchcfile(ept, "*", *pkgserver)) {
939781SMoriah.Waterland@Sun.COM if (n < 0) {
949781SMoriah.Waterland@Sun.COM char *errstr = getErrstr();
959781SMoriah.Waterland@Sun.COM progerr(gettext("bad read of contents file"));
969781SMoriah.Waterland@Sun.COM progerr(gettext("pathname=%s"),
979781SMoriah.Waterland@Sun.COM (ept->path && *ept->path) ? ept->path :
989781SMoriah.Waterland@Sun.COM unknown);
999781SMoriah.Waterland@Sun.COM progerr(gettext("problem=%s"),
1009781SMoriah.Waterland@Sun.COM (errstr && *errstr) ? errstr : unknown);
1019781SMoriah.Waterland@Sun.COM exit(99);
1029781SMoriah.Waterland@Sun.COM }
1039781SMoriah.Waterland@Sun.COM pinfo = eptstat(ept, pkginst, (flag ? '@' : '-'));
1049781SMoriah.Waterland@Sun.COM if (ept->npkgs > 0) {
105*9869SCasper.Dik@Sun.COM if (putcvfpfile(ept, *tmpfp)) {
1069781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_WRENT), errno);
1079781SMoriah.Waterland@Sun.COM quit(99);
1089781SMoriah.Waterland@Sun.COM }
109*9869SCasper.Dik@Sun.COM } else if (ept->path != NULL) {
110*9869SCasper.Dik@Sun.COM (void) vfpSetModified(*tmpfp);
111*9869SCasper.Dik@Sun.COM /* add "-<path>" to the file */
112*9869SCasper.Dik@Sun.COM vfpPutc(*tmpfp, '-');
113*9869SCasper.Dik@Sun.COM vfpPuts(*tmpfp, ept->path);
114*9869SCasper.Dik@Sun.COM vfpPutc(*tmpfp, '\n');
1159781SMoriah.Waterland@Sun.COM }
1169781SMoriah.Waterland@Sun.COM
1179781SMoriah.Waterland@Sun.COM if (flag || (pinfo == NULL))
1189781SMoriah.Waterland@Sun.COM continue;
1199781SMoriah.Waterland@Sun.COM
1209781SMoriah.Waterland@Sun.COM dbchg++;
1219781SMoriah.Waterland@Sun.COM
1229781SMoriah.Waterland@Sun.COM /*
1239781SMoriah.Waterland@Sun.COM * If (otherstoo > 0), more than one package has an
1249781SMoriah.Waterland@Sun.COM * interest in the ept entry in the database. Setting
1259781SMoriah.Waterland@Sun.COM * ept->ftype = '\0' effectively marks the file as being
1269781SMoriah.Waterland@Sun.COM * "shared", thus ensuring the ept entry will not
1279781SMoriah.Waterland@Sun.COM * subsequently be removed. Shared editable files (ftype
1289781SMoriah.Waterland@Sun.COM * 'e') are a special case: they should be passed to a
1299781SMoriah.Waterland@Sun.COM * class action script if present. Setting ept->ftype =
1309781SMoriah.Waterland@Sun.COM * '^' indicates this special case of shared editable
1319781SMoriah.Waterland@Sun.COM * file, allowing the distinction to be made later.
1329781SMoriah.Waterland@Sun.COM */
1339781SMoriah.Waterland@Sun.COM if (!pinfo->editflag && otherstoo)
1349781SMoriah.Waterland@Sun.COM ept->ftype = (ept->ftype == 'e') ? '^' : '\0';
1359781SMoriah.Waterland@Sun.COM if (*pinfo->aclass)
1369781SMoriah.Waterland@Sun.COM (void) strcpy(ept->pkg_class, pinfo->aclass);
1379781SMoriah.Waterland@Sun.COM eptlist[eptnum] = ept;
1389781SMoriah.Waterland@Sun.COM
1399781SMoriah.Waterland@Sun.COM ept->path = pathdup(ept->path);
1409781SMoriah.Waterland@Sun.COM if (ept->ainfo.local != NULL)
1419781SMoriah.Waterland@Sun.COM ept->ainfo.local = pathdup(ept->ainfo.local);
1429781SMoriah.Waterland@Sun.COM
1439781SMoriah.Waterland@Sun.COM ept = (struct cfent *)calloc(1, sizeof (struct cfent));
1449781SMoriah.Waterland@Sun.COM if ((++eptnum % EPTMALLOC) == 0) {
1459781SMoriah.Waterland@Sun.COM eptlist = (struct cfent **)realloc(eptlist,
1469781SMoriah.Waterland@Sun.COM (eptnum+EPTMALLOC)*sizeof (struct cfent *));
1479781SMoriah.Waterland@Sun.COM if (eptlist == NULL) {
1489781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_MEMORY), errno);
1499781SMoriah.Waterland@Sun.COM quit(99);
1509781SMoriah.Waterland@Sun.COM }
1519781SMoriah.Waterland@Sun.COM }
1529781SMoriah.Waterland@Sun.COM }
1539781SMoriah.Waterland@Sun.COM
1549781SMoriah.Waterland@Sun.COM eptlist[eptnum] = (struct cfent *)NULL;
1559781SMoriah.Waterland@Sun.COM
156*9869SCasper.Dik@Sun.COM n = swapcfile(*pkgserver, tmpfp, pkginst, dbchg);
1579781SMoriah.Waterland@Sun.COM if (n == RESULT_WRN) {
1589781SMoriah.Waterland@Sun.COM warnflag++;
1599781SMoriah.Waterland@Sun.COM } else if (n == RESULT_ERR) {
1609781SMoriah.Waterland@Sun.COM quit(99);
1619781SMoriah.Waterland@Sun.COM }
1629781SMoriah.Waterland@Sun.COM
1639781SMoriah.Waterland@Sun.COM return (0);
1649781SMoriah.Waterland@Sun.COM }
165