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 <string.h> 33*9781SMoriah.Waterland@Sun.COM #include <limits.h> 34*9781SMoriah.Waterland@Sun.COM #include <errno.h> 35*9781SMoriah.Waterland@Sun.COM #include <stdlib.h> 36*9781SMoriah.Waterland@Sun.COM #include <unistd.h> 37*9781SMoriah.Waterland@Sun.COM #include <dirent.h> 38*9781SMoriah.Waterland@Sun.COM #include <sys/types.h> 39*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h> 40*9781SMoriah.Waterland@Sun.COM #include <sys/param.h> 41*9781SMoriah.Waterland@Sun.COM #include <sys/mman.h> 42*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h> 43*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h> 44*9781SMoriah.Waterland@Sun.COM #include <locale.h> 45*9781SMoriah.Waterland@Sun.COM #include <libintl.h> 46*9781SMoriah.Waterland@Sun.COM #include <pkglib.h> 47*9781SMoriah.Waterland@Sun.COM #include "libadm.h" 48*9781SMoriah.Waterland@Sun.COM #include "libinst.h" 49*9781SMoriah.Waterland@Sun.COM 50*9781SMoriah.Waterland@Sun.COM extern int qflag, lflag, Lflag, pkgcnt; 51*9781SMoriah.Waterland@Sun.COM extern short npaths; 52*9781SMoriah.Waterland@Sun.COM 53*9781SMoriah.Waterland@Sun.COM extern char *basedir, *pathlist[], *ppathlist[], **pkg, **environ; 54*9781SMoriah.Waterland@Sun.COM 55*9781SMoriah.Waterland@Sun.COM extern short used[]; 56*9781SMoriah.Waterland@Sun.COM extern struct cfent **eptlist; 57*9781SMoriah.Waterland@Sun.COM 58*9781SMoriah.Waterland@Sun.COM /* ocfile.c */ 59*9781SMoriah.Waterland@Sun.COM extern int socfile(VFP_T **vfp); /* simple open & lock of DB. */ 60*9781SMoriah.Waterland@Sun.COM extern int relslock(void); /* unlock the database. */ 61*9781SMoriah.Waterland@Sun.COM 62*9781SMoriah.Waterland@Sun.COM /* ckentry.c */ 63*9781SMoriah.Waterland@Sun.COM extern int ckentry(int envflag, int maptyp, struct cfent *ept, VFP_T *vfp); 64*9781SMoriah.Waterland@Sun.COM 65*9781SMoriah.Waterland@Sun.COM #define NXTENTRY(P, VFP) \ 66*9781SMoriah.Waterland@Sun.COM (maptyp ? srchcfile((P), "*", (VFP), (VFP_T *)NULL) : \ 67*9781SMoriah.Waterland@Sun.COM gpkgmapvfp((P), (VFP))) 68*9781SMoriah.Waterland@Sun.COM 69*9781SMoriah.Waterland@Sun.COM #define MSG_ARCHIVE "NOTE: some pathnames are in private formats " \ 70*9781SMoriah.Waterland@Sun.COM "and cannot be verified" 71*9781SMoriah.Waterland@Sun.COM #define WRN_NOPKG "WARNING: no pathnames were associated with <%s>" 72*9781SMoriah.Waterland@Sun.COM #define WRN_NOPATH "WARNING: no information associated with pathname <%s>" 73*9781SMoriah.Waterland@Sun.COM #define EMPTY_PKG "WARNING: Package <%s> is installed but empty" 74*9781SMoriah.Waterland@Sun.COM #define ERR_NOMEM "unable to allocate dynamic memory, errno=%d" 75*9781SMoriah.Waterland@Sun.COM #define ERR_PKGMAP "unable to open pkgmap file <%s>" 76*9781SMoriah.Waterland@Sun.COM #define ERR_ENVFILE "unable to open environment file <%s>" 77*9781SMoriah.Waterland@Sun.COM 78*9781SMoriah.Waterland@Sun.COM static struct cfent entry; 79*9781SMoriah.Waterland@Sun.COM 80*9781SMoriah.Waterland@Sun.COM static int shellmatch(char *, char *); 81*9781SMoriah.Waterland@Sun.COM static int is_partial_path_in_DB(char *, char *); 82*9781SMoriah.Waterland@Sun.COM 83*9781SMoriah.Waterland@Sun.COM int selpath(char *, int); 84*9781SMoriah.Waterland@Sun.COM int selpkg(char *); 85*9781SMoriah.Waterland@Sun.COM 86*9781SMoriah.Waterland@Sun.COM /* 87*9781SMoriah.Waterland@Sun.COM * This routine checks all files which are referenced in the pkgmap which is 88*9781SMoriah.Waterland@Sun.COM * identified by the mapfile arg. When the package is installed, the mapfile 89*9781SMoriah.Waterland@Sun.COM * may be the contents file or a separate pkgmap (maptyp tells the function 90*9781SMoriah.Waterland@Sun.COM * which it is). The variable uninst tells the function whether the package 91*9781SMoriah.Waterland@Sun.COM * is in the installed state or not. The envfile entry is usually a pkginfo 92*9781SMoriah.Waterland@Sun.COM * file, but it could be any environment parameter list. 93*9781SMoriah.Waterland@Sun.COM */ 94*9781SMoriah.Waterland@Sun.COM 95*9781SMoriah.Waterland@Sun.COM int 96*9781SMoriah.Waterland@Sun.COM checkmap(int maptyp, int uninst, char *mapfile, char *envfile, 97*9781SMoriah.Waterland@Sun.COM char *pkginst, char *path, int pathtype) 98*9781SMoriah.Waterland@Sun.COM { 99*9781SMoriah.Waterland@Sun.COM FILE *fp; 100*9781SMoriah.Waterland@Sun.COM char *cl = NULL; 101*9781SMoriah.Waterland@Sun.COM char *value; 102*9781SMoriah.Waterland@Sun.COM char param[MAX_PKG_PARAM_LENGTH]; 103*9781SMoriah.Waterland@Sun.COM int count; 104*9781SMoriah.Waterland@Sun.COM int errflg; 105*9781SMoriah.Waterland@Sun.COM int n; 106*9781SMoriah.Waterland@Sun.COM int selected; 107*9781SMoriah.Waterland@Sun.COM struct pinfo *pinfo; 108*9781SMoriah.Waterland@Sun.COM VFP_T *vfp = (VFP_T *)NULL; 109*9781SMoriah.Waterland@Sun.COM 110*9781SMoriah.Waterland@Sun.COM if (envfile != NULL) { 111*9781SMoriah.Waterland@Sun.COM if ((fp = fopen(envfile, "r")) == NULL) { 112*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_ENVFILE), envfile); 113*9781SMoriah.Waterland@Sun.COM return (-1); 114*9781SMoriah.Waterland@Sun.COM } 115*9781SMoriah.Waterland@Sun.COM param[0] = '\0'; 116*9781SMoriah.Waterland@Sun.COM while (value = fpkgparam(fp, param)) { 117*9781SMoriah.Waterland@Sun.COM if (strcmp("PATH", param) != 0) { 118*9781SMoriah.Waterland@Sun.COM /* 119*9781SMoriah.Waterland@Sun.COM * If checking an uninstalled package, we 120*9781SMoriah.Waterland@Sun.COM * only want two parameters. If we took all 121*9781SMoriah.Waterland@Sun.COM * of them, including path definitions, we 122*9781SMoriah.Waterland@Sun.COM * wouldn't be looking in the right places in 123*9781SMoriah.Waterland@Sun.COM * the reloc and root directories. 124*9781SMoriah.Waterland@Sun.COM */ 125*9781SMoriah.Waterland@Sun.COM if (uninst) { 126*9781SMoriah.Waterland@Sun.COM if ((strncmp("PKG_SRC_NOVERIFY", param, 127*9781SMoriah.Waterland@Sun.COM 16) == 0) && value) { 128*9781SMoriah.Waterland@Sun.COM logerr(gettext(MSG_ARCHIVE)); 129*9781SMoriah.Waterland@Sun.COM putparam(param, value); 130*9781SMoriah.Waterland@Sun.COM } 131*9781SMoriah.Waterland@Sun.COM if ((strncmp("CLASSES", param, 132*9781SMoriah.Waterland@Sun.COM 7) == 0) && value) 133*9781SMoriah.Waterland@Sun.COM putparam(param, value); 134*9781SMoriah.Waterland@Sun.COM } else 135*9781SMoriah.Waterland@Sun.COM putparam(param, value); 136*9781SMoriah.Waterland@Sun.COM } 137*9781SMoriah.Waterland@Sun.COM 138*9781SMoriah.Waterland@Sun.COM free(value); 139*9781SMoriah.Waterland@Sun.COM 140*9781SMoriah.Waterland@Sun.COM param[0] = '\0'; 141*9781SMoriah.Waterland@Sun.COM } 142*9781SMoriah.Waterland@Sun.COM (void) fclose(fp); 143*9781SMoriah.Waterland@Sun.COM basedir = getenv("BASEDIR"); 144*9781SMoriah.Waterland@Sun.COM } 145*9781SMoriah.Waterland@Sun.COM 146*9781SMoriah.Waterland@Sun.COM /* 147*9781SMoriah.Waterland@Sun.COM * If we are using a contents file for the map, this locks the 148*9781SMoriah.Waterland@Sun.COM * contents file in order to freeze the database and assure it 149*9781SMoriah.Waterland@Sun.COM * remains synchronized with the file system against which it is 150*9781SMoriah.Waterland@Sun.COM * being compared. There is no practical way to lock another pkgmap 151*9781SMoriah.Waterland@Sun.COM * on some unknown medium so we don't bother. 152*9781SMoriah.Waterland@Sun.COM */ 153*9781SMoriah.Waterland@Sun.COM if (maptyp) { /* If this is the contents file */ 154*9781SMoriah.Waterland@Sun.COM if (!socfile(&vfp)) { 155*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_PKGMAP), "contents"); 156*9781SMoriah.Waterland@Sun.COM return (-1); 157*9781SMoriah.Waterland@Sun.COM } 158*9781SMoriah.Waterland@Sun.COM } else { 159*9781SMoriah.Waterland@Sun.COM if (vfpOpen(&vfp, mapfile, "r", VFP_NONE) != 0) { 160*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_PKGMAP), mapfile); 161*9781SMoriah.Waterland@Sun.COM return (-1); 162*9781SMoriah.Waterland@Sun.COM } 163*9781SMoriah.Waterland@Sun.COM } 164*9781SMoriah.Waterland@Sun.COM 165*9781SMoriah.Waterland@Sun.COM if ((cl = getenv("CLASSES")) != NULL) 166*9781SMoriah.Waterland@Sun.COM cl_sets(qstrdup(cl)); 167*9781SMoriah.Waterland@Sun.COM 168*9781SMoriah.Waterland@Sun.COM errflg = count = 0; 169*9781SMoriah.Waterland@Sun.COM 170*9781SMoriah.Waterland@Sun.COM do { 171*9781SMoriah.Waterland@Sun.COM if ((n = NXTENTRY(&entry, vfp)) == 0) { 172*9781SMoriah.Waterland@Sun.COM break; 173*9781SMoriah.Waterland@Sun.COM } 174*9781SMoriah.Waterland@Sun.COM /* 175*9781SMoriah.Waterland@Sun.COM * Search for partial paths in the ext DB. 176*9781SMoriah.Waterland@Sun.COM */ 177*9781SMoriah.Waterland@Sun.COM if (pathtype) { 178*9781SMoriah.Waterland@Sun.COM /* LINTED warning: statement has no consequent: if */ 179*9781SMoriah.Waterland@Sun.COM if (is_partial_path_in_DB(entry.path, path)) { 180*9781SMoriah.Waterland@Sun.COM /* Check this entry */ 181*9781SMoriah.Waterland@Sun.COM ; 182*9781SMoriah.Waterland@Sun.COM } else if (entry.ftype == 's' || 183*9781SMoriah.Waterland@Sun.COM entry.ftype == 'l') { 184*9781SMoriah.Waterland@Sun.COM if (is_partial_path_in_DB( 185*9781SMoriah.Waterland@Sun.COM /* LINTED warning: statement has no consequen */ 186*9781SMoriah.Waterland@Sun.COM entry.ainfo.local, path)) { 187*9781SMoriah.Waterland@Sun.COM /* Check this entry */ 188*9781SMoriah.Waterland@Sun.COM ; 189*9781SMoriah.Waterland@Sun.COM } else { 190*9781SMoriah.Waterland@Sun.COM continue; 191*9781SMoriah.Waterland@Sun.COM } 192*9781SMoriah.Waterland@Sun.COM } else { 193*9781SMoriah.Waterland@Sun.COM /* Skip to next DB entry */ 194*9781SMoriah.Waterland@Sun.COM continue; 195*9781SMoriah.Waterland@Sun.COM } 196*9781SMoriah.Waterland@Sun.COM } 197*9781SMoriah.Waterland@Sun.COM 198*9781SMoriah.Waterland@Sun.COM if (n < 0) { 199*9781SMoriah.Waterland@Sun.COM char *errstr = getErrstr(); 200*9781SMoriah.Waterland@Sun.COM logerr(gettext("ERROR: garbled entry")); 201*9781SMoriah.Waterland@Sun.COM logerr(gettext("pathname: %s"), 202*9781SMoriah.Waterland@Sun.COM (entry.path && *entry.path) ? entry.path : 203*9781SMoriah.Waterland@Sun.COM "Unknown"); 204*9781SMoriah.Waterland@Sun.COM logerr(gettext("problem: %s"), 205*9781SMoriah.Waterland@Sun.COM (errstr && *errstr) ? errstr : "Unknown"); 206*9781SMoriah.Waterland@Sun.COM exit(99); 207*9781SMoriah.Waterland@Sun.COM } 208*9781SMoriah.Waterland@Sun.COM if (n == 0) 209*9781SMoriah.Waterland@Sun.COM break; /* done with file */ 210*9781SMoriah.Waterland@Sun.COM 211*9781SMoriah.Waterland@Sun.COM /* 212*9781SMoriah.Waterland@Sun.COM * The class list may not be complete for good reason, so 213*9781SMoriah.Waterland@Sun.COM * there's no complaining if this returns an index of -1. 214*9781SMoriah.Waterland@Sun.COM */ 215*9781SMoriah.Waterland@Sun.COM if (cl != NULL) 216*9781SMoriah.Waterland@Sun.COM entry.pkg_class_idx = cl_idx(entry.pkg_class); 217*9781SMoriah.Waterland@Sun.COM 218*9781SMoriah.Waterland@Sun.COM if (maptyp && pkginst != NULL) { 219*9781SMoriah.Waterland@Sun.COM /* 220*9781SMoriah.Waterland@Sun.COM * check to see if the entry we just read 221*9781SMoriah.Waterland@Sun.COM * is associated with one of the packages 222*9781SMoriah.Waterland@Sun.COM * we have listed on the command line 223*9781SMoriah.Waterland@Sun.COM */ 224*9781SMoriah.Waterland@Sun.COM selected = 0; 225*9781SMoriah.Waterland@Sun.COM pinfo = entry.pinfo; 226*9781SMoriah.Waterland@Sun.COM while (pinfo) { 227*9781SMoriah.Waterland@Sun.COM if (selpkg(pinfo->pkg)) { 228*9781SMoriah.Waterland@Sun.COM selected++; 229*9781SMoriah.Waterland@Sun.COM break; 230*9781SMoriah.Waterland@Sun.COM } 231*9781SMoriah.Waterland@Sun.COM pinfo = pinfo->next; 232*9781SMoriah.Waterland@Sun.COM } 233*9781SMoriah.Waterland@Sun.COM if (!selected) 234*9781SMoriah.Waterland@Sun.COM continue; /* not selected */ 235*9781SMoriah.Waterland@Sun.COM } 236*9781SMoriah.Waterland@Sun.COM 237*9781SMoriah.Waterland@Sun.COM /* 238*9781SMoriah.Waterland@Sun.COM * Check to see if the pathname associated with the entry 239*9781SMoriah.Waterland@Sun.COM * we just read is associated with the list of paths we 240*9781SMoriah.Waterland@Sun.COM * supplied on the command line 241*9781SMoriah.Waterland@Sun.COM */ 242*9781SMoriah.Waterland@Sun.COM if (!selpath(entry.path, pathtype)) 243*9781SMoriah.Waterland@Sun.COM continue; /* not selected */ 244*9781SMoriah.Waterland@Sun.COM 245*9781SMoriah.Waterland@Sun.COM /* 246*9781SMoriah.Waterland@Sun.COM * Determine if this is a package object wanting 247*9781SMoriah.Waterland@Sun.COM * verification. Metafiles are always checked, otherwise, we 248*9781SMoriah.Waterland@Sun.COM * rely on the class to discriminate. 249*9781SMoriah.Waterland@Sun.COM */ 250*9781SMoriah.Waterland@Sun.COM if (entry.ftype != 'i') 251*9781SMoriah.Waterland@Sun.COM /* If there's no class list... */ 252*9781SMoriah.Waterland@Sun.COM if (cl != NULL) 253*9781SMoriah.Waterland@Sun.COM /* 254*9781SMoriah.Waterland@Sun.COM * ... or this entry isn't in that class list 255*9781SMoriah.Waterland@Sun.COM * or it's in a private format, then don't 256*9781SMoriah.Waterland@Sun.COM * check it. 257*9781SMoriah.Waterland@Sun.COM */ 258*9781SMoriah.Waterland@Sun.COM if (entry.pkg_class_idx == -1 || 259*9781SMoriah.Waterland@Sun.COM cl_svfy(entry.pkg_class_idx) == NOVERIFY) 260*9781SMoriah.Waterland@Sun.COM continue; 261*9781SMoriah.Waterland@Sun.COM 262*9781SMoriah.Waterland@Sun.COM count++; 263*9781SMoriah.Waterland@Sun.COM if (ckentry((envfile ? 1 : 0), maptyp, &entry, vfp)) 264*9781SMoriah.Waterland@Sun.COM errflg++; 265*9781SMoriah.Waterland@Sun.COM } while (n != 0); 266*9781SMoriah.Waterland@Sun.COM 267*9781SMoriah.Waterland@Sun.COM (void) vfpClose(&vfp); 268*9781SMoriah.Waterland@Sun.COM 269*9781SMoriah.Waterland@Sun.COM if (maptyp) 270*9781SMoriah.Waterland@Sun.COM relslock(); 271*9781SMoriah.Waterland@Sun.COM 272*9781SMoriah.Waterland@Sun.COM if (environ) { 273*9781SMoriah.Waterland@Sun.COM /* free up environment resources */ 274*9781SMoriah.Waterland@Sun.COM for (n = 0; environ[n]; n++) 275*9781SMoriah.Waterland@Sun.COM free(environ[n]); 276*9781SMoriah.Waterland@Sun.COM free(environ); 277*9781SMoriah.Waterland@Sun.COM environ = NULL; 278*9781SMoriah.Waterland@Sun.COM } 279*9781SMoriah.Waterland@Sun.COM 280*9781SMoriah.Waterland@Sun.COM if (maptyp) { 281*9781SMoriah.Waterland@Sun.COM /* 282*9781SMoriah.Waterland@Sun.COM * make sure each listed package was associated with 283*9781SMoriah.Waterland@Sun.COM * an entry from the prototype or pkgmap 284*9781SMoriah.Waterland@Sun.COM */ 285*9781SMoriah.Waterland@Sun.COM (void) selpkg(NULL); 286*9781SMoriah.Waterland@Sun.COM } 287*9781SMoriah.Waterland@Sun.COM if (!qflag && !lflag && !Lflag) { 288*9781SMoriah.Waterland@Sun.COM /* 289*9781SMoriah.Waterland@Sun.COM * make sure each listed pathname was associated with an entry 290*9781SMoriah.Waterland@Sun.COM * from the prototype or pkgmap 291*9781SMoriah.Waterland@Sun.COM */ 292*9781SMoriah.Waterland@Sun.COM (void) selpath(NULL, pathtype); 293*9781SMoriah.Waterland@Sun.COM } 294*9781SMoriah.Waterland@Sun.COM return (errflg); 295*9781SMoriah.Waterland@Sun.COM } 296*9781SMoriah.Waterland@Sun.COM 297*9781SMoriah.Waterland@Sun.COM int 298*9781SMoriah.Waterland@Sun.COM selpkg(char *p) 299*9781SMoriah.Waterland@Sun.COM { 300*9781SMoriah.Waterland@Sun.COM static char *selected; 301*9781SMoriah.Waterland@Sun.COM char buf[80]; 302*9781SMoriah.Waterland@Sun.COM char *root; 303*9781SMoriah.Waterland@Sun.COM register int i; 304*9781SMoriah.Waterland@Sun.COM 305*9781SMoriah.Waterland@Sun.COM if (p == NULL) { 306*9781SMoriah.Waterland@Sun.COM if (selected == NULL) { 307*9781SMoriah.Waterland@Sun.COM if (pkgcnt) { 308*9781SMoriah.Waterland@Sun.COM for (i = 0; i < pkgcnt; ++i) { 309*9781SMoriah.Waterland@Sun.COM /* bugid 1227628 */ 310*9781SMoriah.Waterland@Sun.COM root = get_inst_root(); 311*9781SMoriah.Waterland@Sun.COM if (root) 312*9781SMoriah.Waterland@Sun.COM (void) snprintf(buf, 313*9781SMoriah.Waterland@Sun.COM sizeof (buf), 314*9781SMoriah.Waterland@Sun.COM "%s/var/sadm/pkg/%s/pkginfo", 315*9781SMoriah.Waterland@Sun.COM root, pkg[i]); 316*9781SMoriah.Waterland@Sun.COM else 317*9781SMoriah.Waterland@Sun.COM (void) snprintf(buf, 318*9781SMoriah.Waterland@Sun.COM sizeof (buf), 319*9781SMoriah.Waterland@Sun.COM "/var/sadm/pkg/%s/pkginfo", 320*9781SMoriah.Waterland@Sun.COM pkg[i]); 321*9781SMoriah.Waterland@Sun.COM 322*9781SMoriah.Waterland@Sun.COM if (access(buf, F_OK)) 323*9781SMoriah.Waterland@Sun.COM logerr(gettext(WRN_NOPKG), 324*9781SMoriah.Waterland@Sun.COM pkg[i]); 325*9781SMoriah.Waterland@Sun.COM else 326*9781SMoriah.Waterland@Sun.COM logerr(gettext(EMPTY_PKG), 327*9781SMoriah.Waterland@Sun.COM pkg[i]); 328*9781SMoriah.Waterland@Sun.COM } 329*9781SMoriah.Waterland@Sun.COM } 330*9781SMoriah.Waterland@Sun.COM } else { 331*9781SMoriah.Waterland@Sun.COM for (i = 0; i < pkgcnt; ++i) { 332*9781SMoriah.Waterland@Sun.COM if (selected[i] == NULL) { 333*9781SMoriah.Waterland@Sun.COM root = get_inst_root(); 334*9781SMoriah.Waterland@Sun.COM if (root) 335*9781SMoriah.Waterland@Sun.COM (void) snprintf(buf, 336*9781SMoriah.Waterland@Sun.COM sizeof (buf), 337*9781SMoriah.Waterland@Sun.COM "%s/var/sadm/pkg/%s/pkginfo", 338*9781SMoriah.Waterland@Sun.COM root, pkg[i]); 339*9781SMoriah.Waterland@Sun.COM else 340*9781SMoriah.Waterland@Sun.COM (void) snprintf(buf, 341*9781SMoriah.Waterland@Sun.COM sizeof (buf), 342*9781SMoriah.Waterland@Sun.COM "/var/sadm/pkg/%s/pkginfo", 343*9781SMoriah.Waterland@Sun.COM pkg[i]); 344*9781SMoriah.Waterland@Sun.COM 345*9781SMoriah.Waterland@Sun.COM if (access(buf, F_OK)) 346*9781SMoriah.Waterland@Sun.COM logerr(gettext(WRN_NOPKG), 347*9781SMoriah.Waterland@Sun.COM pkg[i]); 348*9781SMoriah.Waterland@Sun.COM else 349*9781SMoriah.Waterland@Sun.COM logerr(gettext(EMPTY_PKG), 350*9781SMoriah.Waterland@Sun.COM pkg[i]); 351*9781SMoriah.Waterland@Sun.COM } 352*9781SMoriah.Waterland@Sun.COM } 353*9781SMoriah.Waterland@Sun.COM } 354*9781SMoriah.Waterland@Sun.COM return (0); /* return value not important */ 355*9781SMoriah.Waterland@Sun.COM } else if (pkgcnt == 0) 356*9781SMoriah.Waterland@Sun.COM return (1); 357*9781SMoriah.Waterland@Sun.COM else if (selected == NULL) { 358*9781SMoriah.Waterland@Sun.COM selected = 359*9781SMoriah.Waterland@Sun.COM (char *)calloc((unsigned)(pkgcnt+1), sizeof (char)); 360*9781SMoriah.Waterland@Sun.COM if (selected == NULL) { 361*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_NOMEM), errno); 362*9781SMoriah.Waterland@Sun.COM exit(99); 363*9781SMoriah.Waterland@Sun.COM /*NOTREACHED*/ 364*9781SMoriah.Waterland@Sun.COM } 365*9781SMoriah.Waterland@Sun.COM } 366*9781SMoriah.Waterland@Sun.COM 367*9781SMoriah.Waterland@Sun.COM for (i = 0; i < pkgcnt; ++i) { 368*9781SMoriah.Waterland@Sun.COM if (pkgnmchk(p, pkg[i], 0) == 0) { 369*9781SMoriah.Waterland@Sun.COM if (selected != NULL) 370*9781SMoriah.Waterland@Sun.COM selected[i] = 'b'; 371*9781SMoriah.Waterland@Sun.COM return (1); 372*9781SMoriah.Waterland@Sun.COM } 373*9781SMoriah.Waterland@Sun.COM } 374*9781SMoriah.Waterland@Sun.COM return (0); 375*9781SMoriah.Waterland@Sun.COM } 376*9781SMoriah.Waterland@Sun.COM 377*9781SMoriah.Waterland@Sun.COM int 378*9781SMoriah.Waterland@Sun.COM selpath(char *path, int partial_path) 379*9781SMoriah.Waterland@Sun.COM { 380*9781SMoriah.Waterland@Sun.COM int n; 381*9781SMoriah.Waterland@Sun.COM 382*9781SMoriah.Waterland@Sun.COM if (!npaths) 383*9781SMoriah.Waterland@Sun.COM return (1); /* everything is selectable */ 384*9781SMoriah.Waterland@Sun.COM 385*9781SMoriah.Waterland@Sun.COM for (n = 0; n < npaths; n++) { 386*9781SMoriah.Waterland@Sun.COM if (path == NULL) { 387*9781SMoriah.Waterland@Sun.COM if (!used[n]) 388*9781SMoriah.Waterland@Sun.COM logerr(gettext(WRN_NOPATH), 389*9781SMoriah.Waterland@Sun.COM partial_path ? ppathlist[n] : 390*9781SMoriah.Waterland@Sun.COM pathlist[n]); 391*9781SMoriah.Waterland@Sun.COM } else if (partial_path) { 392*9781SMoriah.Waterland@Sun.COM used[n] = 1; 393*9781SMoriah.Waterland@Sun.COM return (1); 394*9781SMoriah.Waterland@Sun.COM } else if (!shellmatch(pathlist[n], path)) { 395*9781SMoriah.Waterland@Sun.COM used[n] = 1; 396*9781SMoriah.Waterland@Sun.COM return (1); 397*9781SMoriah.Waterland@Sun.COM } 398*9781SMoriah.Waterland@Sun.COM } 399*9781SMoriah.Waterland@Sun.COM return (0); /* not selected */ 400*9781SMoriah.Waterland@Sun.COM } 401*9781SMoriah.Waterland@Sun.COM 402*9781SMoriah.Waterland@Sun.COM static int 403*9781SMoriah.Waterland@Sun.COM shellmatch(char *spec, char *path) 404*9781SMoriah.Waterland@Sun.COM { 405*9781SMoriah.Waterland@Sun.COM /* Check if the value is NULL */ 406*9781SMoriah.Waterland@Sun.COM if (spec == NULL || path == NULL) 407*9781SMoriah.Waterland@Sun.COM return (1); 408*9781SMoriah.Waterland@Sun.COM 409*9781SMoriah.Waterland@Sun.COM while (*spec && (*spec == *path)) { 410*9781SMoriah.Waterland@Sun.COM spec++, path++; 411*9781SMoriah.Waterland@Sun.COM } 412*9781SMoriah.Waterland@Sun.COM if ((*spec == *path) || (*spec == '*')) 413*9781SMoriah.Waterland@Sun.COM return (0); 414*9781SMoriah.Waterland@Sun.COM return (1); 415*9781SMoriah.Waterland@Sun.COM } 416*9781SMoriah.Waterland@Sun.COM 417*9781SMoriah.Waterland@Sun.COM static int 418*9781SMoriah.Waterland@Sun.COM is_partial_path_in_DB(char *srcpath, char *trgtpath) 419*9781SMoriah.Waterland@Sun.COM { 420*9781SMoriah.Waterland@Sun.COM if (strstr(srcpath, trgtpath) == NULL) { 421*9781SMoriah.Waterland@Sun.COM return (0); 422*9781SMoriah.Waterland@Sun.COM } else { 423*9781SMoriah.Waterland@Sun.COM return (1); 424*9781SMoriah.Waterland@Sun.COM } 425*9781SMoriah.Waterland@Sun.COM } 426