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 "install.h"
435c51f124SMoriah Waterland #include "libinst.h"
445c51f124SMoriah Waterland #include "libadm.h"
455c51f124SMoriah Waterland
465c51f124SMoriah Waterland extern struct cfextra **extlist;
475c51f124SMoriah Waterland extern struct cfent **eptlist;
485c51f124SMoriah Waterland
495c51f124SMoriah Waterland extern char *pkginst;
505c51f124SMoriah Waterland
515c51f124SMoriah Waterland #define ERR_WRITE "write of intermediate contents file failed"
525c51f124SMoriah Waterland
535c51f124SMoriah Waterland static char *check_db_entry(VFP_T *, struct cfextra *, int, char *, int *);
545c51f124SMoriah Waterland
555c51f124SMoriah Waterland /*ARGSUSED*/
565c51f124SMoriah Waterland int
dofinal(PKGserver server,VFP_T * vfpo,int rmflag,char * myclass,char * prog)57*62224350SCasper H.S. Dik dofinal(PKGserver server, VFP_T *vfpo, int rmflag, char *myclass, char *prog)
585c51f124SMoriah Waterland {
595c51f124SMoriah Waterland struct cfextra entry;
605c51f124SMoriah Waterland int n, indx, dbchg;
615c51f124SMoriah Waterland char *save_path = NULL;
625c51f124SMoriah Waterland
635c51f124SMoriah Waterland entry.cf_ent.pinfo = NULL;
645c51f124SMoriah Waterland entry.fsys_value = BADFSYS;
655c51f124SMoriah Waterland entry.fsys_base = BADFSYS;
665c51f124SMoriah Waterland indx = 0;
675c51f124SMoriah Waterland
685c51f124SMoriah Waterland while (extlist && extlist[indx] && (extlist[indx]->cf_ent.ftype == 'i'))
695c51f124SMoriah Waterland indx++;
705c51f124SMoriah Waterland
715c51f124SMoriah Waterland dbchg = 0;
725c51f124SMoriah Waterland
73*62224350SCasper H.S. Dik if (pkgopenfilter(server, pkginst) != 0)
74*62224350SCasper H.S. Dik quit(99);
75*62224350SCasper H.S. Dik
76*62224350SCasper H.S. Dik while (n = srchcfile(&(entry.cf_ent), "*", server)) {
775c51f124SMoriah Waterland if (n < 0) {
785c51f124SMoriah Waterland char *errstr = getErrstr();
79*62224350SCasper H.S. Dik progerr(gettext("bad entry read in contents file"));
80*62224350SCasper H.S. Dik logerr(gettext("pathname=%s"),
81*62224350SCasper H.S. Dik (entry.cf_ent.path && *(entry.cf_ent.path)) ?
82*62224350SCasper H.S. Dik entry.cf_ent.path : "Unknown");
835c51f124SMoriah Waterland logerr(gettext("problem=%s"),
84*62224350SCasper H.S. Dik (errstr && *errstr) ? errstr : "Unknown");
855c51f124SMoriah Waterland quit(99);
865c51f124SMoriah Waterland }
87*62224350SCasper H.S. Dik save_path = check_db_entry(vfpo, &entry, rmflag, myclass,
88*62224350SCasper H.S. Dik &dbchg);
895c51f124SMoriah Waterland
905c51f124SMoriah Waterland /* Restore original server-relative path, if needed */
915c51f124SMoriah Waterland if (save_path != NULL) {
925c51f124SMoriah Waterland entry.cf_ent.path = save_path;
935c51f124SMoriah Waterland save_path = NULL;
945c51f124SMoriah Waterland }
955c51f124SMoriah Waterland }
965c51f124SMoriah Waterland
97*62224350SCasper H.S. Dik pkgclosefilter(server);
98*62224350SCasper H.S. Dik
995c51f124SMoriah Waterland return (dbchg);
1005c51f124SMoriah Waterland }
1015c51f124SMoriah Waterland
1025c51f124SMoriah Waterland static char *
check_db_entry(VFP_T * vfpo,struct cfextra * entry,int rmflag,char * myclass,int * dbchg)1035c51f124SMoriah Waterland check_db_entry(VFP_T *vfpo, struct cfextra *entry, int rmflag, char *myclass,
1045c51f124SMoriah Waterland int *dbchg)
1055c51f124SMoriah Waterland {
1065c51f124SMoriah Waterland struct pinfo *pinfo;
1075c51f124SMoriah Waterland int fs_entry;
1085c51f124SMoriah Waterland char *save_path = NULL;
1095c51f124SMoriah Waterland char *tp;
1105c51f124SMoriah Waterland
1115c51f124SMoriah Waterland if (myclass && strcmp(myclass, entry->cf_ent.pkg_class)) {
112*62224350SCasper H.S. Dik /*
113*62224350SCasper H.S. Dik * We already have it in the database we don't want
114*62224350SCasper H.S. Dik * to modify it.
115*62224350SCasper H.S. Dik */
1165c51f124SMoriah Waterland return (NULL);
1175c51f124SMoriah Waterland }
1185c51f124SMoriah Waterland
1195c51f124SMoriah Waterland /*
1205c51f124SMoriah Waterland * Now scan each package instance holding this file or
1215c51f124SMoriah Waterland * directory and see if it matches the package we are
1225c51f124SMoriah Waterland * updating here.
1235c51f124SMoriah Waterland */
1245c51f124SMoriah Waterland pinfo = entry->cf_ent.pinfo;
1255c51f124SMoriah Waterland while (pinfo) {
1265c51f124SMoriah Waterland if (strcmp(pkginst, pinfo->pkg) == 0)
1275c51f124SMoriah Waterland break;
1285c51f124SMoriah Waterland pinfo = pinfo->next;
1295c51f124SMoriah Waterland }
1305c51f124SMoriah Waterland
1315c51f124SMoriah Waterland /*
1325c51f124SMoriah Waterland * If pinfo == NULL at this point, then this file or
1335c51f124SMoriah Waterland * directory isn't part of the package of interest.
134*62224350SCasper H.S. Dik * So the code below executes only on files in the package
1355c51f124SMoriah Waterland * of interest.
1365c51f124SMoriah Waterland */
1375c51f124SMoriah Waterland
138*62224350SCasper H.S. Dik if (pinfo == NULL)
139*62224350SCasper H.S. Dik return (NULL);
1405c51f124SMoriah Waterland
141*62224350SCasper H.S. Dik if (rmflag && (pinfo->status == RM_RDY)) {
142*62224350SCasper H.S. Dik *dbchg = 1;
1435c51f124SMoriah Waterland
144*62224350SCasper H.S. Dik (void) eptstat(&(entry->cf_ent), pkginst, '@');
1455c51f124SMoriah Waterland
146*62224350SCasper H.S. Dik if (entry->cf_ent.npkgs) {
147*62224350SCasper H.S. Dik if (putcvfpfile(&(entry->cf_ent), vfpo)) {
148*62224350SCasper H.S. Dik progerr(gettext(ERR_WRITE));
149*62224350SCasper H.S. Dik quit(99);
1505c51f124SMoriah Waterland }
151*62224350SCasper H.S. Dik } else if (entry->cf_ent.path != NULL) {
152*62224350SCasper H.S. Dik (void) vfpSetModified(vfpo);
153*62224350SCasper H.S. Dik /* add "-<path>" to the file */
154*62224350SCasper H.S. Dik vfpPutc(vfpo, '-');
155*62224350SCasper H.S. Dik vfpPuts(vfpo, entry->cf_ent.path);
156*62224350SCasper H.S. Dik vfpPutc(vfpo, '\n');
157*62224350SCasper H.S. Dik }
158*62224350SCasper H.S. Dik return (NULL);
1595c51f124SMoriah Waterland
160*62224350SCasper H.S. Dik } else if (!rmflag && (pinfo->status == INST_RDY)) {
161*62224350SCasper H.S. Dik *dbchg = 1;
162*62224350SCasper H.S. Dik
163*62224350SCasper H.S. Dik /* tp is the server-relative path */
164*62224350SCasper H.S. Dik tp = fixpath(entry->cf_ent.path);
165*62224350SCasper H.S. Dik /* save_path is the cmd line path */
166*62224350SCasper H.S. Dik save_path = entry->cf_ent.path;
167*62224350SCasper H.S. Dik /* entry has the server-relative path */
168*62224350SCasper H.S. Dik entry->cf_ent.path = tp;
169*62224350SCasper H.S. Dik
170*62224350SCasper H.S. Dik /*
171*62224350SCasper H.S. Dik * The next if statement figures out how
172*62224350SCasper H.S. Dik * the contents file entry should be
173*62224350SCasper H.S. Dik * annotated.
174*62224350SCasper H.S. Dik *
175*62224350SCasper H.S. Dik * Don't install or verify objects for
176*62224350SCasper H.S. Dik * remote, read-only filesystems. We
177*62224350SCasper H.S. Dik * need only verify their presence and
178*62224350SCasper H.S. Dik * flag them appropriately from some
179*62224350SCasper H.S. Dik * server. Otherwise, ok to do final
180*62224350SCasper H.S. Dik * check.
181*62224350SCasper H.S. Dik */
182*62224350SCasper H.S. Dik fs_entry = fsys(entry->cf_ent.path);
183*62224350SCasper H.S. Dik
184*62224350SCasper H.S. Dik if (is_remote_fs_n(fs_entry) && !is_fs_writeable_n(fs_entry)) {
185*62224350SCasper H.S. Dik /*
186*62224350SCasper H.S. Dik * Mark it shared whether it's present
187*62224350SCasper H.S. Dik * or not. life's too funny for me
188*62224350SCasper H.S. Dik * to explain.
189*62224350SCasper H.S. Dik */
190*62224350SCasper H.S. Dik pinfo->status = SERVED_FILE;
1915c51f124SMoriah Waterland
1925c51f124SMoriah Waterland /*
193*62224350SCasper H.S. Dik * restore for now. This may
194*62224350SCasper H.S. Dik * chg soon.
1955c51f124SMoriah Waterland */
196*62224350SCasper H.S. Dik entry->cf_ent.path = save_path;
197*62224350SCasper H.S. Dik } else {
198*62224350SCasper H.S. Dik /*
199*62224350SCasper H.S. Dik * If the object is accessible, check
200*62224350SCasper H.S. Dik * the new entry for existence and
201*62224350SCasper H.S. Dik * attributes. If there's a problem,
202*62224350SCasper H.S. Dik * mark it NOT_FND; otherwise,
203*62224350SCasper H.S. Dik * ENTRY_OK.
204*62224350SCasper H.S. Dik */
205*62224350SCasper H.S. Dik if (is_mounted_n(fs_entry)) {
206*62224350SCasper H.S. Dik int n;
2075c51f124SMoriah Waterland
208*62224350SCasper H.S. Dik n = finalck((&entry->cf_ent), 1, 1, B_FALSE);
2095c51f124SMoriah Waterland
210*62224350SCasper H.S. Dik pinfo->status = ENTRY_OK;
211*62224350SCasper H.S. Dik if (n != 0) {
212*62224350SCasper H.S. Dik pinfo->status = NOT_FND;
213*62224350SCasper H.S. Dik }
2145c51f124SMoriah Waterland }
215*62224350SCasper H.S. Dik
216*62224350SCasper H.S. Dik /*
217*62224350SCasper H.S. Dik * It's not remote, read-only but it
218*62224350SCasper H.S. Dik * may look that way to the client.
219*62224350SCasper H.S. Dik * If it does, overwrite the above
220*62224350SCasper H.S. Dik * result - mark it shared.
221*62224350SCasper H.S. Dik */
222*62224350SCasper H.S. Dik if (is_served_n(fs_entry))
223*62224350SCasper H.S. Dik pinfo->status = SERVED_FILE;
224*62224350SCasper H.S. Dik
225*62224350SCasper H.S. Dik /* restore original path */
226*62224350SCasper H.S. Dik entry->cf_ent.path = save_path;
227*62224350SCasper H.S. Dik /* and clear save_path */
228*62224350SCasper H.S. Dik save_path = NULL;
2295c51f124SMoriah Waterland }
2305c51f124SMoriah Waterland }
2315c51f124SMoriah Waterland
2325c51f124SMoriah Waterland /* Output entry to contents file. */
2335c51f124SMoriah Waterland if (putcvfpfile(&(entry->cf_ent), vfpo)) {
2345c51f124SMoriah Waterland progerr(gettext(ERR_WRITE));
2355c51f124SMoriah Waterland quit(99);
2365c51f124SMoriah Waterland }
2375c51f124SMoriah Waterland
2385c51f124SMoriah Waterland return (save_path);
2395c51f124SMoriah Waterland }
240