15c51f124SMoriah Waterland /*
25c51f124SMoriah Waterland * CDDL HEADER START
35c51f124SMoriah Waterland *
45c51f124SMoriah Waterland * The contents of this file are subject to the terms of the
55c51f124SMoriah Waterland * Common Development and Distribution License (the "License").
65c51f124SMoriah Waterland * You may not use this file except in compliance with the License.
75c51f124SMoriah Waterland *
85c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing.
105c51f124SMoriah Waterland * See the License for the specific language governing permissions
115c51f124SMoriah Waterland * and limitations under the License.
125c51f124SMoriah Waterland *
135c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
145c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the
165c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
175c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
185c51f124SMoriah Waterland *
195c51f124SMoriah Waterland * CDDL HEADER END
205c51f124SMoriah Waterland */
215c51f124SMoriah Waterland
225c51f124SMoriah Waterland /*
23*62224350SCasper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
245c51f124SMoriah Waterland * Use is subject to license terms.
255c51f124SMoriah Waterland */
265c51f124SMoriah Waterland
275c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
285c51f124SMoriah Waterland /* All Rights Reserved */
295c51f124SMoriah Waterland
305c51f124SMoriah Waterland
315c51f124SMoriah Waterland #include <stdio.h>
325c51f124SMoriah Waterland #include <errno.h>
335c51f124SMoriah Waterland #include <string.h>
345c51f124SMoriah Waterland #include <limits.h>
355c51f124SMoriah Waterland #include <stdlib.h>
365c51f124SMoriah Waterland #include <unistd.h>
375c51f124SMoriah Waterland #include <sys/types.h>
385c51f124SMoriah Waterland #include <pkgstrct.h>
395c51f124SMoriah Waterland #include <locale.h>
405c51f124SMoriah Waterland #include <libintl.h>
415c51f124SMoriah Waterland #include <pkglib.h>
425c51f124SMoriah Waterland #include <libadm.h>
435c51f124SMoriah Waterland #include <libinst.h>
445c51f124SMoriah Waterland
455c51f124SMoriah Waterland extern int dbchg, warnflag, otherstoo;
465c51f124SMoriah Waterland extern char *pkginst;
475c51f124SMoriah Waterland
485c51f124SMoriah Waterland #define EPTMALLOC 128
495c51f124SMoriah Waterland
505c51f124SMoriah Waterland #define ERR_WRENT "write of entry failed, errno=%d"
515c51f124SMoriah Waterland #define ERR_MEMORY "no memory, errno=%d"
525c51f124SMoriah Waterland #define ERR_READ_C "bad read of contents file"
535c51f124SMoriah Waterland #define ERR_READ_DB "bad read of the database"
545c51f124SMoriah Waterland
555c51f124SMoriah Waterland extern struct cfent **eptlist;
565c51f124SMoriah Waterland extern int eptnum;
575c51f124SMoriah Waterland
585c51f124SMoriah Waterland int
delmap(int flag,char * pkginst,PKGserver * pkgserver,VFP_T ** tmpfp)59*62224350SCasper H.S. Dik delmap(int flag, char *pkginst, PKGserver *pkgserver, VFP_T **tmpfp)
605c51f124SMoriah Waterland {
615c51f124SMoriah Waterland struct cfent *ept;
625c51f124SMoriah Waterland struct pinfo *pinfo;
635c51f124SMoriah Waterland int n;
645c51f124SMoriah Waterland char *unknown = "Unknown";
655c51f124SMoriah Waterland
665c51f124SMoriah Waterland
67*62224350SCasper H.S. Dik if (!ocfile(pkgserver, tmpfp, 0L) ||
68*62224350SCasper H.S. Dik pkgopenfilter(*pkgserver, pkginst) != 0) {
695c51f124SMoriah Waterland quit(99);
705c51f124SMoriah Waterland }
715c51f124SMoriah Waterland
725c51f124SMoriah Waterland /* re-use any memory used to store pathnames */
735c51f124SMoriah Waterland (void) pathdup(NULL);
745c51f124SMoriah Waterland
755c51f124SMoriah Waterland if (eptlist != NULL)
765c51f124SMoriah Waterland free(eptlist);
775c51f124SMoriah Waterland eptlist = (struct cfent **)calloc(EPTMALLOC,
785c51f124SMoriah Waterland sizeof (struct cfent *));
795c51f124SMoriah Waterland if (eptlist == NULL) {
805c51f124SMoriah Waterland progerr(gettext(ERR_MEMORY), errno);
815c51f124SMoriah Waterland quit(99);
825c51f124SMoriah Waterland }
835c51f124SMoriah Waterland
845c51f124SMoriah Waterland ept = (struct cfent *)calloc(1,
855c51f124SMoriah Waterland (unsigned)sizeof (struct cfent));
865c51f124SMoriah Waterland if (!ept) {
875c51f124SMoriah Waterland progerr(gettext(ERR_MEMORY), errno);
885c51f124SMoriah Waterland quit(99);
895c51f124SMoriah Waterland }
905c51f124SMoriah Waterland
915c51f124SMoriah Waterland eptnum = 0;
92*62224350SCasper H.S. Dik while (n = srchcfile(ept, "*", *pkgserver)) {
935c51f124SMoriah Waterland if (n < 0) {
945c51f124SMoriah Waterland char *errstr = getErrstr();
955c51f124SMoriah Waterland progerr(gettext("bad read of contents file"));
965c51f124SMoriah Waterland progerr(gettext("pathname=%s"),
975c51f124SMoriah Waterland (ept->path && *ept->path) ? ept->path :
985c51f124SMoriah Waterland unknown);
995c51f124SMoriah Waterland progerr(gettext("problem=%s"),
1005c51f124SMoriah Waterland (errstr && *errstr) ? errstr : unknown);
1015c51f124SMoriah Waterland exit(99);
1025c51f124SMoriah Waterland }
1035c51f124SMoriah Waterland pinfo = eptstat(ept, pkginst, (flag ? '@' : '-'));
1045c51f124SMoriah Waterland if (ept->npkgs > 0) {
105*62224350SCasper H.S. Dik if (putcvfpfile(ept, *tmpfp)) {
1065c51f124SMoriah Waterland progerr(gettext(ERR_WRENT), errno);
1075c51f124SMoriah Waterland quit(99);
1085c51f124SMoriah Waterland }
109*62224350SCasper H.S. Dik } else if (ept->path != NULL) {
110*62224350SCasper H.S. Dik (void) vfpSetModified(*tmpfp);
111*62224350SCasper H.S. Dik /* add "-<path>" to the file */
112*62224350SCasper H.S. Dik vfpPutc(*tmpfp, '-');
113*62224350SCasper H.S. Dik vfpPuts(*tmpfp, ept->path);
114*62224350SCasper H.S. Dik vfpPutc(*tmpfp, '\n');
1155c51f124SMoriah Waterland }
1165c51f124SMoriah Waterland
1175c51f124SMoriah Waterland if (flag || (pinfo == NULL))
1185c51f124SMoriah Waterland continue;
1195c51f124SMoriah Waterland
1205c51f124SMoriah Waterland dbchg++;
1215c51f124SMoriah Waterland
1225c51f124SMoriah Waterland /*
1235c51f124SMoriah Waterland * If (otherstoo > 0), more than one package has an
1245c51f124SMoriah Waterland * interest in the ept entry in the database. Setting
1255c51f124SMoriah Waterland * ept->ftype = '\0' effectively marks the file as being
1265c51f124SMoriah Waterland * "shared", thus ensuring the ept entry will not
1275c51f124SMoriah Waterland * subsequently be removed. Shared editable files (ftype
1285c51f124SMoriah Waterland * 'e') are a special case: they should be passed to a
1295c51f124SMoriah Waterland * class action script if present. Setting ept->ftype =
1305c51f124SMoriah Waterland * '^' indicates this special case of shared editable
1315c51f124SMoriah Waterland * file, allowing the distinction to be made later.
1325c51f124SMoriah Waterland */
1335c51f124SMoriah Waterland if (!pinfo->editflag && otherstoo)
1345c51f124SMoriah Waterland ept->ftype = (ept->ftype == 'e') ? '^' : '\0';
1355c51f124SMoriah Waterland if (*pinfo->aclass)
1365c51f124SMoriah Waterland (void) strcpy(ept->pkg_class, pinfo->aclass);
1375c51f124SMoriah Waterland eptlist[eptnum] = ept;
1385c51f124SMoriah Waterland
1395c51f124SMoriah Waterland ept->path = pathdup(ept->path);
1405c51f124SMoriah Waterland if (ept->ainfo.local != NULL)
1415c51f124SMoriah Waterland ept->ainfo.local = pathdup(ept->ainfo.local);
1425c51f124SMoriah Waterland
1435c51f124SMoriah Waterland ept = (struct cfent *)calloc(1, sizeof (struct cfent));
1445c51f124SMoriah Waterland if ((++eptnum % EPTMALLOC) == 0) {
1455c51f124SMoriah Waterland eptlist = (struct cfent **)realloc(eptlist,
1465c51f124SMoriah Waterland (eptnum+EPTMALLOC)*sizeof (struct cfent *));
1475c51f124SMoriah Waterland if (eptlist == NULL) {
1485c51f124SMoriah Waterland progerr(gettext(ERR_MEMORY), errno);
1495c51f124SMoriah Waterland quit(99);
1505c51f124SMoriah Waterland }
1515c51f124SMoriah Waterland }
1525c51f124SMoriah Waterland }
1535c51f124SMoriah Waterland
1545c51f124SMoriah Waterland eptlist[eptnum] = (struct cfent *)NULL;
1555c51f124SMoriah Waterland
156*62224350SCasper H.S. Dik n = swapcfile(*pkgserver, tmpfp, pkginst, dbchg);
1575c51f124SMoriah Waterland if (n == RESULT_WRN) {
1585c51f124SMoriah Waterland warnflag++;
1595c51f124SMoriah Waterland } else if (n == RESULT_ERR) {
1605c51f124SMoriah Waterland quit(99);
1615c51f124SMoriah Waterland }
1625c51f124SMoriah Waterland
1635c51f124SMoriah Waterland return (0);
1645c51f124SMoriah Waterland }
165