1*9781SMoriah.Waterland@Sun.COM /* 2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START 3*9781SMoriah.Waterland@Sun.COM * 4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the 5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License"). 6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License. 7*9781SMoriah.Waterland@Sun.COM * 8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions 11*9781SMoriah.Waterland@Sun.COM * and limitations under the License. 12*9781SMoriah.Waterland@Sun.COM * 13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*9781SMoriah.Waterland@Sun.COM * 19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END 20*9781SMoriah.Waterland@Sun.COM */ 21*9781SMoriah.Waterland@Sun.COM 22*9781SMoriah.Waterland@Sun.COM /* 23*9781SMoriah.Waterland@Sun.COM * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms. 25*9781SMoriah.Waterland@Sun.COM */ 26*9781SMoriah.Waterland@Sun.COM 27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */ 29*9781SMoriah.Waterland@Sun.COM 30*9781SMoriah.Waterland@Sun.COM 31*9781SMoriah.Waterland@Sun.COM #include <stdio.h> 32*9781SMoriah.Waterland@Sun.COM #include <errno.h> 33*9781SMoriah.Waterland@Sun.COM #include <string.h> 34*9781SMoriah.Waterland@Sun.COM #include <limits.h> 35*9781SMoriah.Waterland@Sun.COM #include <stdlib.h> 36*9781SMoriah.Waterland@Sun.COM #include <unistd.h> 37*9781SMoriah.Waterland@Sun.COM #include <sys/types.h> 38*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h> 39*9781SMoriah.Waterland@Sun.COM #include <locale.h> 40*9781SMoriah.Waterland@Sun.COM #include <libintl.h> 41*9781SMoriah.Waterland@Sun.COM #include <pkglib.h> 42*9781SMoriah.Waterland@Sun.COM #include "install.h" 43*9781SMoriah.Waterland@Sun.COM #include "libinst.h" 44*9781SMoriah.Waterland@Sun.COM #include "libadm.h" 45*9781SMoriah.Waterland@Sun.COM 46*9781SMoriah.Waterland@Sun.COM extern struct cfextra **extlist; 47*9781SMoriah.Waterland@Sun.COM extern struct cfent **eptlist; 48*9781SMoriah.Waterland@Sun.COM 49*9781SMoriah.Waterland@Sun.COM extern char *pkginst; 50*9781SMoriah.Waterland@Sun.COM 51*9781SMoriah.Waterland@Sun.COM #define ERR_WRITE "write of intermediate contents file failed" 52*9781SMoriah.Waterland@Sun.COM 53*9781SMoriah.Waterland@Sun.COM static char *check_db_entry(VFP_T *, struct cfextra *, int, char *, int *); 54*9781SMoriah.Waterland@Sun.COM 55*9781SMoriah.Waterland@Sun.COM /*ARGSUSED*/ 56*9781SMoriah.Waterland@Sun.COM int 57*9781SMoriah.Waterland@Sun.COM dofinal(VFP_T *vfp, VFP_T *vfpo, int rmflag, char *myclass, char *prog) 58*9781SMoriah.Waterland@Sun.COM { 59*9781SMoriah.Waterland@Sun.COM struct cfextra entry; 60*9781SMoriah.Waterland@Sun.COM int n, indx, dbchg; 61*9781SMoriah.Waterland@Sun.COM char *save_path = NULL; 62*9781SMoriah.Waterland@Sun.COM 63*9781SMoriah.Waterland@Sun.COM entry.cf_ent.pinfo = NULL; 64*9781SMoriah.Waterland@Sun.COM entry.fsys_value = BADFSYS; 65*9781SMoriah.Waterland@Sun.COM entry.fsys_base = BADFSYS; 66*9781SMoriah.Waterland@Sun.COM indx = 0; 67*9781SMoriah.Waterland@Sun.COM 68*9781SMoriah.Waterland@Sun.COM while (extlist && extlist[indx] && (extlist[indx]->cf_ent.ftype == 'i')) 69*9781SMoriah.Waterland@Sun.COM indx++; 70*9781SMoriah.Waterland@Sun.COM 71*9781SMoriah.Waterland@Sun.COM dbchg = 0; 72*9781SMoriah.Waterland@Sun.COM 73*9781SMoriah.Waterland@Sun.COM while (n = srchcfile(&(entry.cf_ent), "*", vfp, vfpo)) { 74*9781SMoriah.Waterland@Sun.COM if (n < 0) { 75*9781SMoriah.Waterland@Sun.COM char *errstr = getErrstr(); 76*9781SMoriah.Waterland@Sun.COM progerr(gettext 77*9781SMoriah.Waterland@Sun.COM ("bad entry read in contents file")); 78*9781SMoriah.Waterland@Sun.COM logerr(gettext("pathname=%s"), 79*9781SMoriah.Waterland@Sun.COM (entry.cf_ent.path && 80*9781SMoriah.Waterland@Sun.COM *(entry.cf_ent.path)) ? 81*9781SMoriah.Waterland@Sun.COM entry.cf_ent.path : "Unknown"); 82*9781SMoriah.Waterland@Sun.COM logerr(gettext("problem=%s"), 83*9781SMoriah.Waterland@Sun.COM (errstr && *errstr) ? errstr : 84*9781SMoriah.Waterland@Sun.COM "Unknown"); 85*9781SMoriah.Waterland@Sun.COM quit(99); 86*9781SMoriah.Waterland@Sun.COM } 87*9781SMoriah.Waterland@Sun.COM save_path = check_db_entry( 88*9781SMoriah.Waterland@Sun.COM vfpo, &entry, rmflag, myclass, &dbchg); 89*9781SMoriah.Waterland@Sun.COM 90*9781SMoriah.Waterland@Sun.COM /* Restore original server-relative path, if needed */ 91*9781SMoriah.Waterland@Sun.COM if (save_path != NULL) { 92*9781SMoriah.Waterland@Sun.COM entry.cf_ent.path = save_path; 93*9781SMoriah.Waterland@Sun.COM save_path = NULL; 94*9781SMoriah.Waterland@Sun.COM } 95*9781SMoriah.Waterland@Sun.COM } 96*9781SMoriah.Waterland@Sun.COM 97*9781SMoriah.Waterland@Sun.COM return (dbchg); 98*9781SMoriah.Waterland@Sun.COM } 99*9781SMoriah.Waterland@Sun.COM 100*9781SMoriah.Waterland@Sun.COM static char * 101*9781SMoriah.Waterland@Sun.COM check_db_entry(VFP_T *vfpo, struct cfextra *entry, int rmflag, char *myclass, 102*9781SMoriah.Waterland@Sun.COM int *dbchg) 103*9781SMoriah.Waterland@Sun.COM { 104*9781SMoriah.Waterland@Sun.COM struct pinfo *pinfo; 105*9781SMoriah.Waterland@Sun.COM int fs_entry; 106*9781SMoriah.Waterland@Sun.COM char *save_path = NULL; 107*9781SMoriah.Waterland@Sun.COM char *tp; 108*9781SMoriah.Waterland@Sun.COM 109*9781SMoriah.Waterland@Sun.COM /* write this entry to the contents file */ 110*9781SMoriah.Waterland@Sun.COM 111*9781SMoriah.Waterland@Sun.COM if (myclass && strcmp(myclass, entry->cf_ent.pkg_class)) { 112*9781SMoriah.Waterland@Sun.COM if (putcvfpfile(&entry->cf_ent, vfpo)) { 113*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_WRITE)); 114*9781SMoriah.Waterland@Sun.COM quit(99); 115*9781SMoriah.Waterland@Sun.COM } 116*9781SMoriah.Waterland@Sun.COM return (NULL); 117*9781SMoriah.Waterland@Sun.COM } 118*9781SMoriah.Waterland@Sun.COM 119*9781SMoriah.Waterland@Sun.COM /* 120*9781SMoriah.Waterland@Sun.COM * Now scan each package instance holding this file or 121*9781SMoriah.Waterland@Sun.COM * directory and see if it matches the package we are 122*9781SMoriah.Waterland@Sun.COM * updating here. 123*9781SMoriah.Waterland@Sun.COM */ 124*9781SMoriah.Waterland@Sun.COM pinfo = entry->cf_ent.pinfo; 125*9781SMoriah.Waterland@Sun.COM while (pinfo) { 126*9781SMoriah.Waterland@Sun.COM if (strcmp(pkginst, pinfo->pkg) == 0) 127*9781SMoriah.Waterland@Sun.COM break; 128*9781SMoriah.Waterland@Sun.COM pinfo = pinfo->next; 129*9781SMoriah.Waterland@Sun.COM } 130*9781SMoriah.Waterland@Sun.COM 131*9781SMoriah.Waterland@Sun.COM /* 132*9781SMoriah.Waterland@Sun.COM * If pinfo == NULL at this point, then this file or 133*9781SMoriah.Waterland@Sun.COM * directory isn't part of the package of interest. 134*9781SMoriah.Waterland@Sun.COM * So the loop below executes only on files in the package 135*9781SMoriah.Waterland@Sun.COM * of interest. 136*9781SMoriah.Waterland@Sun.COM */ 137*9781SMoriah.Waterland@Sun.COM 138*9781SMoriah.Waterland@Sun.COM save_path = NULL; 139*9781SMoriah.Waterland@Sun.COM 140*9781SMoriah.Waterland@Sun.COM if (pinfo) { 141*9781SMoriah.Waterland@Sun.COM if (rmflag && (pinfo->status == RM_RDY)) { 142*9781SMoriah.Waterland@Sun.COM *dbchg = 1; 143*9781SMoriah.Waterland@Sun.COM 144*9781SMoriah.Waterland@Sun.COM (void) eptstat(&(entry->cf_ent), pkginst, '@'); 145*9781SMoriah.Waterland@Sun.COM 146*9781SMoriah.Waterland@Sun.COM if (entry->cf_ent.npkgs) { 147*9781SMoriah.Waterland@Sun.COM if (putcvfpfile(&(entry->cf_ent), vfpo)) { 148*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_WRITE)); 149*9781SMoriah.Waterland@Sun.COM quit(99); 150*9781SMoriah.Waterland@Sun.COM } 151*9781SMoriah.Waterland@Sun.COM } 152*9781SMoriah.Waterland@Sun.COM return (NULL); 153*9781SMoriah.Waterland@Sun.COM 154*9781SMoriah.Waterland@Sun.COM } else if (!rmflag && (pinfo->status == INST_RDY)) { 155*9781SMoriah.Waterland@Sun.COM *dbchg = 1; 156*9781SMoriah.Waterland@Sun.COM 157*9781SMoriah.Waterland@Sun.COM /* tp is the server-relative path */ 158*9781SMoriah.Waterland@Sun.COM tp = fixpath(entry->cf_ent.path); 159*9781SMoriah.Waterland@Sun.COM /* save_path is the cmd line path */ 160*9781SMoriah.Waterland@Sun.COM save_path = entry->cf_ent.path; 161*9781SMoriah.Waterland@Sun.COM /* entry has the server-relative path */ 162*9781SMoriah.Waterland@Sun.COM entry->cf_ent.path = tp; 163*9781SMoriah.Waterland@Sun.COM 164*9781SMoriah.Waterland@Sun.COM /* 165*9781SMoriah.Waterland@Sun.COM * The next if statement figures out how 166*9781SMoriah.Waterland@Sun.COM * the contents file entry should be 167*9781SMoriah.Waterland@Sun.COM * annotated. 168*9781SMoriah.Waterland@Sun.COM * 169*9781SMoriah.Waterland@Sun.COM * Don't install or verify objects for 170*9781SMoriah.Waterland@Sun.COM * remote, read-only filesystems. We 171*9781SMoriah.Waterland@Sun.COM * need only verify their presence and 172*9781SMoriah.Waterland@Sun.COM * flag them appropriately from some 173*9781SMoriah.Waterland@Sun.COM * server. Otherwise, ok to do final 174*9781SMoriah.Waterland@Sun.COM * check. 175*9781SMoriah.Waterland@Sun.COM */ 176*9781SMoriah.Waterland@Sun.COM fs_entry = fsys(entry->cf_ent.path); 177*9781SMoriah.Waterland@Sun.COM 178*9781SMoriah.Waterland@Sun.COM if (is_remote_fs_n(fs_entry) && 179*9781SMoriah.Waterland@Sun.COM !is_fs_writeable_n(fs_entry)) { 180*9781SMoriah.Waterland@Sun.COM /* 181*9781SMoriah.Waterland@Sun.COM * Mark it shared whether it's present 182*9781SMoriah.Waterland@Sun.COM * or not. life's too funny for me 183*9781SMoriah.Waterland@Sun.COM * to explain. 184*9781SMoriah.Waterland@Sun.COM */ 185*9781SMoriah.Waterland@Sun.COM pinfo->status = SERVED_FILE; 186*9781SMoriah.Waterland@Sun.COM 187*9781SMoriah.Waterland@Sun.COM /* 188*9781SMoriah.Waterland@Sun.COM * restore for now. This may 189*9781SMoriah.Waterland@Sun.COM * chg soon. 190*9781SMoriah.Waterland@Sun.COM */ 191*9781SMoriah.Waterland@Sun.COM entry->cf_ent.path = save_path; 192*9781SMoriah.Waterland@Sun.COM } else { 193*9781SMoriah.Waterland@Sun.COM /* 194*9781SMoriah.Waterland@Sun.COM * If the object is accessible, check 195*9781SMoriah.Waterland@Sun.COM * the new entry for existence and 196*9781SMoriah.Waterland@Sun.COM * attributes. If there's a problem, 197*9781SMoriah.Waterland@Sun.COM * mark it NOT_FND; otherwise, 198*9781SMoriah.Waterland@Sun.COM * ENTRY_OK. 199*9781SMoriah.Waterland@Sun.COM */ 200*9781SMoriah.Waterland@Sun.COM if (is_mounted_n(fs_entry)) { 201*9781SMoriah.Waterland@Sun.COM int n; 202*9781SMoriah.Waterland@Sun.COM 203*9781SMoriah.Waterland@Sun.COM n = finalck((&entry->cf_ent), 1, 1, 204*9781SMoriah.Waterland@Sun.COM B_FALSE); 205*9781SMoriah.Waterland@Sun.COM 206*9781SMoriah.Waterland@Sun.COM pinfo->status = ENTRY_OK; 207*9781SMoriah.Waterland@Sun.COM if (n != 0) { 208*9781SMoriah.Waterland@Sun.COM pinfo->status = NOT_FND; 209*9781SMoriah.Waterland@Sun.COM } 210*9781SMoriah.Waterland@Sun.COM } 211*9781SMoriah.Waterland@Sun.COM 212*9781SMoriah.Waterland@Sun.COM /* 213*9781SMoriah.Waterland@Sun.COM * It's not remote, read-only but it 214*9781SMoriah.Waterland@Sun.COM * may look that way to the client. 215*9781SMoriah.Waterland@Sun.COM * If it does, overwrite the above 216*9781SMoriah.Waterland@Sun.COM * result - mark it shared. 217*9781SMoriah.Waterland@Sun.COM */ 218*9781SMoriah.Waterland@Sun.COM if (is_served_n(fs_entry)) 219*9781SMoriah.Waterland@Sun.COM pinfo->status = SERVED_FILE; 220*9781SMoriah.Waterland@Sun.COM 221*9781SMoriah.Waterland@Sun.COM /* restore original path */ 222*9781SMoriah.Waterland@Sun.COM entry->cf_ent.path = save_path; 223*9781SMoriah.Waterland@Sun.COM /* and clear save_path */ 224*9781SMoriah.Waterland@Sun.COM save_path = NULL; 225*9781SMoriah.Waterland@Sun.COM } 226*9781SMoriah.Waterland@Sun.COM } 227*9781SMoriah.Waterland@Sun.COM } 228*9781SMoriah.Waterland@Sun.COM 229*9781SMoriah.Waterland@Sun.COM /* Output entry to contents file. */ 230*9781SMoriah.Waterland@Sun.COM if (putcvfpfile(&(entry->cf_ent), vfpo)) { 231*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_WRITE)); 232*9781SMoriah.Waterland@Sun.COM quit(99); 233*9781SMoriah.Waterland@Sun.COM } 234*9781SMoriah.Waterland@Sun.COM 235*9781SMoriah.Waterland@Sun.COM return (save_path); 236*9781SMoriah.Waterland@Sun.COM } 237