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 /*
2362224350SCasper 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 <string.h>
335c51f124SMoriah Waterland #include <limits.h>
345c51f124SMoriah Waterland #include <errno.h>
355c51f124SMoriah Waterland #include <stdlib.h>
365c51f124SMoriah Waterland #include <unistd.h>
375c51f124SMoriah Waterland #include <dirent.h>
385c51f124SMoriah Waterland #include <sys/types.h>
395c51f124SMoriah Waterland #include <sys/stat.h>
405c51f124SMoriah Waterland #include <sys/param.h>
415c51f124SMoriah Waterland #include <sys/mman.h>
425c51f124SMoriah Waterland #include <pkgstrct.h>
435c51f124SMoriah Waterland #include <pkglocs.h>
445c51f124SMoriah Waterland #include <locale.h>
455c51f124SMoriah Waterland #include <libintl.h>
465c51f124SMoriah Waterland #include <pkglib.h>
475c51f124SMoriah Waterland #include "libadm.h"
485c51f124SMoriah Waterland #include "libinst.h"
495c51f124SMoriah Waterland 
505c51f124SMoriah Waterland extern int	qflag, lflag, Lflag, pkgcnt;
515c51f124SMoriah Waterland extern short	npaths;
525c51f124SMoriah Waterland 
535c51f124SMoriah Waterland extern char	*basedir, *pathlist[], *ppathlist[], **pkg, **environ;
545c51f124SMoriah Waterland 
555c51f124SMoriah Waterland extern short	used[];
565c51f124SMoriah Waterland extern struct cfent **eptlist;
575c51f124SMoriah Waterland 
585c51f124SMoriah Waterland /* ckentry.c */
5962224350SCasper H.S. Dik extern int	ckentry(int, int, struct cfent *, VFP_T *, PKGserver);
605c51f124SMoriah Waterland 
6162224350SCasper H.S. Dik #define	NXTENTRY(P, VFP, SRV) \
6262224350SCasper H.S. Dik 		(maptyp ? srchcfile((P), "*", (SRV)) : \
635c51f124SMoriah Waterland 		gpkgmapvfp((P), (VFP)))
645c51f124SMoriah Waterland 
655c51f124SMoriah Waterland #define	MSG_ARCHIVE	"NOTE: some pathnames are in private formats " \
665c51f124SMoriah Waterland 			    "and cannot be verified"
675c51f124SMoriah Waterland #define	WRN_NOPKG	"WARNING: no pathnames were associated with <%s>"
685c51f124SMoriah Waterland #define	WRN_NOPATH	"WARNING: no information associated with pathname <%s>"
695c51f124SMoriah Waterland #define	EMPTY_PKG "WARNING: Package <%s> is installed but empty"
705c51f124SMoriah Waterland #define	ERR_NOMEM	"unable to allocate dynamic memory, errno=%d"
715c51f124SMoriah Waterland #define	ERR_PKGMAP	"unable to open pkgmap file <%s>"
725c51f124SMoriah Waterland #define	ERR_ENVFILE	"unable to open environment file <%s>"
735c51f124SMoriah Waterland 
745c51f124SMoriah Waterland static struct cfent entry;
755c51f124SMoriah Waterland 
765c51f124SMoriah Waterland static int	shellmatch(char *, char *);
775c51f124SMoriah Waterland static int is_partial_path_in_DB(char *, char *);
785c51f124SMoriah Waterland 
795c51f124SMoriah Waterland int	selpath(char *, int);
805c51f124SMoriah Waterland int	selpkg(char *);
815c51f124SMoriah Waterland 
825c51f124SMoriah Waterland /*
835c51f124SMoriah Waterland  * This routine checks all files which are referenced in the pkgmap which is
845c51f124SMoriah Waterland  * identified by the mapfile arg. When the package is installed, the mapfile
855c51f124SMoriah Waterland  * may be the contents file or a separate pkgmap (maptyp tells the function
865c51f124SMoriah Waterland  * which it is). The variable uninst tells the function whether the package
875c51f124SMoriah Waterland  * is in the installed state or not. The envfile entry is usually a pkginfo
885c51f124SMoriah Waterland  * file, but it could be any environment parameter list.
895c51f124SMoriah Waterland  */
905c51f124SMoriah Waterland 
915c51f124SMoriah Waterland int
checkmap(int maptyp,int uninst,char * mapfile,char * envfile,char * pkginst,char * path,int pathtype)925c51f124SMoriah Waterland checkmap(int maptyp, int uninst, char *mapfile, char *envfile,
935c51f124SMoriah Waterland 		char *pkginst, char *path, int pathtype)
945c51f124SMoriah Waterland {
955c51f124SMoriah Waterland 	FILE		*fp;
965c51f124SMoriah Waterland 	char		*cl = NULL;
975c51f124SMoriah Waterland 	char		*value;
985c51f124SMoriah Waterland 	char		param[MAX_PKG_PARAM_LENGTH];
995c51f124SMoriah Waterland 	int		count;
1005c51f124SMoriah Waterland 	int		errflg;
1015c51f124SMoriah Waterland 	int		n;
1025c51f124SMoriah Waterland 	int		selected;
1035c51f124SMoriah Waterland 	struct pinfo	*pinfo;
1045c51f124SMoriah Waterland 	VFP_T		*vfp = (VFP_T *)NULL;
10562224350SCasper H.S. Dik 	PKGserver	server;
1065c51f124SMoriah Waterland 
1075c51f124SMoriah Waterland 	if (envfile != NULL) {
1085c51f124SMoriah Waterland 		if ((fp = fopen(envfile, "r")) == NULL) {
1095c51f124SMoriah Waterland 			progerr(gettext(ERR_ENVFILE), envfile);
1105c51f124SMoriah Waterland 			return (-1);
1115c51f124SMoriah Waterland 		}
1125c51f124SMoriah Waterland 		param[0] = '\0';
1135c51f124SMoriah Waterland 		while (value = fpkgparam(fp, param)) {
1145c51f124SMoriah Waterland 			if (strcmp("PATH", param) != 0) {
1155c51f124SMoriah Waterland 				/*
1165c51f124SMoriah Waterland 				 * If checking an uninstalled package, we
1175c51f124SMoriah Waterland 				 * only want two parameters. If we took all
1185c51f124SMoriah Waterland 				 * of them, including path definitions, we
1195c51f124SMoriah Waterland 				 * wouldn't be looking in the right places in
1205c51f124SMoriah Waterland 				 * the reloc and root directories.
1215c51f124SMoriah Waterland 				 */
1225c51f124SMoriah Waterland 				if (uninst) {
1235c51f124SMoriah Waterland 					if ((strncmp("PKG_SRC_NOVERIFY", param,
1245c51f124SMoriah Waterland 					    16) == 0) && value) {
1255c51f124SMoriah Waterland 						logerr(gettext(MSG_ARCHIVE));
1265c51f124SMoriah Waterland 						putparam(param, value);
1275c51f124SMoriah Waterland 					}
1285c51f124SMoriah Waterland 					if ((strncmp("CLASSES", param,
1295c51f124SMoriah Waterland 					    7) == 0) && value)
1305c51f124SMoriah Waterland 						putparam(param, value);
1315c51f124SMoriah Waterland 				} else
1325c51f124SMoriah Waterland 					putparam(param, value);
1335c51f124SMoriah Waterland 			}
1345c51f124SMoriah Waterland 
1355c51f124SMoriah Waterland 			free(value);
1365c51f124SMoriah Waterland 
1375c51f124SMoriah Waterland 			param[0] = '\0';
1385c51f124SMoriah Waterland 		}
1395c51f124SMoriah Waterland 		(void) fclose(fp);
1405c51f124SMoriah Waterland 		basedir = getenv("BASEDIR");
1415c51f124SMoriah Waterland 	}
1425c51f124SMoriah Waterland 
1435c51f124SMoriah Waterland 	/*
1445c51f124SMoriah Waterland 	 * If we are using a contents file for the map, this locks the
1455c51f124SMoriah Waterland 	 * contents file in order to freeze the database and assure it
1465c51f124SMoriah Waterland 	 * remains synchronized with the file system against which it is
1475c51f124SMoriah Waterland 	 * being compared. There is no practical way to lock another pkgmap
1485c51f124SMoriah Waterland 	 * on some unknown medium so we don't bother.
1495c51f124SMoriah Waterland 	 */
1505c51f124SMoriah Waterland 	if (maptyp) {	/* If this is the contents file */
15162224350SCasper H.S. Dik 		if (!socfile(&server, B_FALSE) ||
15262224350SCasper H.S. Dik 		    pkgopenfilter(server, pkgcnt == 1 ? pkginst : NULL) != 0) {
1535c51f124SMoriah Waterland 			progerr(gettext(ERR_PKGMAP), "contents");
1545c51f124SMoriah Waterland 			return (-1);
1555c51f124SMoriah Waterland 		}
1565c51f124SMoriah Waterland 	} else {
1575c51f124SMoriah Waterland 		if (vfpOpen(&vfp, mapfile, "r", VFP_NONE) != 0) {
1585c51f124SMoriah Waterland 			progerr(gettext(ERR_PKGMAP), mapfile);
1595c51f124SMoriah Waterland 			return (-1);
1605c51f124SMoriah Waterland 		}
1615c51f124SMoriah Waterland 	}
1625c51f124SMoriah Waterland 
1635c51f124SMoriah Waterland 	if ((cl = getenv("CLASSES")) != NULL)
1645c51f124SMoriah Waterland 		cl_sets(qstrdup(cl));
1655c51f124SMoriah Waterland 
1665c51f124SMoriah Waterland 	errflg = count = 0;
1675c51f124SMoriah Waterland 
1685c51f124SMoriah Waterland 	do {
16962224350SCasper H.S. Dik 		if ((n = NXTENTRY(&entry, vfp, server)) == 0) {
1705c51f124SMoriah Waterland 			break;
1715c51f124SMoriah Waterland 		}
1725c51f124SMoriah Waterland 		/*
1735c51f124SMoriah Waterland 		 * Search for partial paths in the ext DB.
1745c51f124SMoriah Waterland 		 */
1755c51f124SMoriah Waterland 		if (pathtype) {
1765c51f124SMoriah Waterland 			/* LINTED warning: statement has no consequent: if */
1775c51f124SMoriah Waterland 			if (is_partial_path_in_DB(entry.path, path)) {
1785c51f124SMoriah Waterland 				/* Check this entry */
1795c51f124SMoriah Waterland 				;
18062224350SCasper H.S. Dik 			} else if (entry.ftype == 's' || entry.ftype == 'l') {
1815c51f124SMoriah Waterland 				if (is_partial_path_in_DB(
1825c51f124SMoriah Waterland 				/* LINTED warning: statement has no consequen */
1835c51f124SMoriah Waterland 					entry.ainfo.local, path)) {
1845c51f124SMoriah Waterland 					/* Check this entry */
1855c51f124SMoriah Waterland 					;
1865c51f124SMoriah Waterland 				} else {
1875c51f124SMoriah Waterland 					continue;
1885c51f124SMoriah Waterland 				}
1895c51f124SMoriah Waterland 			} else {
1905c51f124SMoriah Waterland 				/* Skip to next DB entry */
1915c51f124SMoriah Waterland 				continue;
1925c51f124SMoriah Waterland 			}
1935c51f124SMoriah Waterland 		}
1945c51f124SMoriah Waterland 
1955c51f124SMoriah Waterland 		if (n < 0) {
1965c51f124SMoriah Waterland 			char	*errstr = getErrstr();
1975c51f124SMoriah Waterland 			logerr(gettext("ERROR: garbled entry"));
1985c51f124SMoriah Waterland 			logerr(gettext("pathname: %s"),
1995c51f124SMoriah Waterland 			    (entry.path && *entry.path) ? entry.path :
2005c51f124SMoriah Waterland 			    "Unknown");
2015c51f124SMoriah Waterland 			logerr(gettext("problem: %s"),
2025c51f124SMoriah Waterland 			    (errstr && *errstr) ? errstr : "Unknown");
2035c51f124SMoriah Waterland 			exit(99);
2045c51f124SMoriah Waterland 		}
2055c51f124SMoriah Waterland 		if (n == 0)
2065c51f124SMoriah Waterland 			break; /* done with file */
2075c51f124SMoriah Waterland 
2085c51f124SMoriah Waterland 		/*
2095c51f124SMoriah Waterland 		 * The class list may not be complete for good reason, so
2105c51f124SMoriah Waterland 		 * there's no complaining if this returns an index of -1.
2115c51f124SMoriah Waterland 		 */
2125c51f124SMoriah Waterland 		if (cl != NULL)
2135c51f124SMoriah Waterland 			entry.pkg_class_idx = cl_idx(entry.pkg_class);
2145c51f124SMoriah Waterland 
2155c51f124SMoriah Waterland 		if (maptyp && pkginst != NULL) {
2165c51f124SMoriah Waterland 			/*
2175c51f124SMoriah Waterland 			 * check to see if the entry we just read
2185c51f124SMoriah Waterland 			 * is associated with one of the packages
2195c51f124SMoriah Waterland 			 * we have listed on the command line
2205c51f124SMoriah Waterland 			 */
2215c51f124SMoriah Waterland 			selected = 0;
2225c51f124SMoriah Waterland 			pinfo = entry.pinfo;
2235c51f124SMoriah Waterland 			while (pinfo) {
2245c51f124SMoriah Waterland 				if (selpkg(pinfo->pkg)) {
2255c51f124SMoriah Waterland 					selected++;
2265c51f124SMoriah Waterland 					break;
2275c51f124SMoriah Waterland 				}
2285c51f124SMoriah Waterland 				pinfo = pinfo->next;
2295c51f124SMoriah Waterland 			}
2305c51f124SMoriah Waterland 			if (!selected)
2315c51f124SMoriah Waterland 				continue; /* not selected */
2325c51f124SMoriah Waterland 		}
2335c51f124SMoriah Waterland 
2345c51f124SMoriah Waterland 		/*
2355c51f124SMoriah Waterland 		 * Check to see if the pathname associated with the entry
2365c51f124SMoriah Waterland 		 * we just read is associated with the list of paths we
2375c51f124SMoriah Waterland 		 * supplied on the command line
2385c51f124SMoriah Waterland 		 */
2395c51f124SMoriah Waterland 		if (!selpath(entry.path, pathtype))
2405c51f124SMoriah Waterland 			continue; /* not selected */
2415c51f124SMoriah Waterland 
2425c51f124SMoriah Waterland 		/*
2435c51f124SMoriah Waterland 		 * Determine if this is a package object wanting
2445c51f124SMoriah Waterland 		 * verification. Metafiles are always checked, otherwise, we
2455c51f124SMoriah Waterland 		 * rely on the class to discriminate.
2465c51f124SMoriah Waterland 		 */
2475c51f124SMoriah Waterland 		if (entry.ftype != 'i')
2485c51f124SMoriah Waterland 			/* If there's no class list... */
2495c51f124SMoriah Waterland 			if (cl != NULL)
2505c51f124SMoriah Waterland 				/*
2515c51f124SMoriah Waterland 				 * ... or this entry isn't in that class list
2525c51f124SMoriah Waterland 				 * or it's in a private format, then don't
2535c51f124SMoriah Waterland 				 * check it.
2545c51f124SMoriah Waterland 				 */
2555c51f124SMoriah Waterland 				if (entry.pkg_class_idx == -1 ||
2565c51f124SMoriah Waterland 				    cl_svfy(entry.pkg_class_idx) == NOVERIFY)
2575c51f124SMoriah Waterland 					continue;
2585c51f124SMoriah Waterland 
2595c51f124SMoriah Waterland 		count++;
26062224350SCasper H.S. Dik 		if (ckentry((envfile ? 1 : 0), maptyp, &entry, vfp, server))
2615c51f124SMoriah Waterland 			errflg++;
2625c51f124SMoriah Waterland 	} while (n != 0);
2635c51f124SMoriah Waterland 
2645c51f124SMoriah Waterland 	if (maptyp)
2655c51f124SMoriah Waterland 		relslock();
26662224350SCasper H.S. Dik 	else
26762224350SCasper H.S. Dik 		(void) vfpClose(&vfp);
2685c51f124SMoriah Waterland 
2695c51f124SMoriah Waterland 	if (environ) {
2705c51f124SMoriah Waterland 		/* free up environment resources */
2715c51f124SMoriah Waterland 		for (n = 0; environ[n]; n++)
2725c51f124SMoriah Waterland 			free(environ[n]);
2735c51f124SMoriah Waterland 		free(environ);
2745c51f124SMoriah Waterland 		environ = NULL;
2755c51f124SMoriah Waterland 	}
2765c51f124SMoriah Waterland 
2775c51f124SMoriah Waterland 	if (maptyp) {
2785c51f124SMoriah Waterland 		/*
2795c51f124SMoriah Waterland 		 * make sure each listed package was associated with
2805c51f124SMoriah Waterland 		 * an entry from the prototype or pkgmap
2815c51f124SMoriah Waterland 		 */
2825c51f124SMoriah Waterland 		(void) selpkg(NULL);
2835c51f124SMoriah Waterland 	}
2845c51f124SMoriah Waterland 	if (!qflag && !lflag && !Lflag) {
2855c51f124SMoriah Waterland 		/*
2865c51f124SMoriah Waterland 		 * make sure each listed pathname was associated with an entry
2875c51f124SMoriah Waterland 		 * from the prototype or pkgmap
2885c51f124SMoriah Waterland 		 */
2895c51f124SMoriah Waterland 		(void) selpath(NULL, pathtype);
2905c51f124SMoriah Waterland 	}
2915c51f124SMoriah Waterland 	return (errflg);
2925c51f124SMoriah Waterland }
2935c51f124SMoriah Waterland 
2945c51f124SMoriah Waterland int
selpkg(char * p)2955c51f124SMoriah Waterland selpkg(char *p)
2965c51f124SMoriah Waterland {
2975c51f124SMoriah Waterland 	static char *selected;
2985c51f124SMoriah Waterland 	char buf[80];
2995c51f124SMoriah Waterland 	char *root;
3005c51f124SMoriah Waterland 	register int i;
3015c51f124SMoriah Waterland 
3025c51f124SMoriah Waterland 	if (p == NULL) {
3035c51f124SMoriah Waterland 		if (selected == NULL) {
3045c51f124SMoriah Waterland 			if (pkgcnt) {
3055c51f124SMoriah Waterland 				for (i = 0; i < pkgcnt; ++i) {
3065c51f124SMoriah Waterland 					/* bugid 1227628 */
3075c51f124SMoriah Waterland 					root = get_inst_root();
3085c51f124SMoriah Waterland 					if (root)
3095c51f124SMoriah Waterland 						(void) snprintf(buf,
3105c51f124SMoriah Waterland 						sizeof (buf),
3115c51f124SMoriah Waterland 						"%s/var/sadm/pkg/%s/pkginfo",
3125c51f124SMoriah Waterland 						root, pkg[i]);
3135c51f124SMoriah Waterland 					else
3145c51f124SMoriah Waterland 						(void) snprintf(buf,
3155c51f124SMoriah Waterland 						sizeof (buf),
3165c51f124SMoriah Waterland 						"/var/sadm/pkg/%s/pkginfo",
3175c51f124SMoriah Waterland 						pkg[i]);
3185c51f124SMoriah Waterland 
3195c51f124SMoriah Waterland 					if (access(buf, F_OK))
3205c51f124SMoriah Waterland 						logerr(gettext(WRN_NOPKG),
3215c51f124SMoriah Waterland 							pkg[i]);
3225c51f124SMoriah Waterland 					else
3235c51f124SMoriah Waterland 						logerr(gettext(EMPTY_PKG),
3245c51f124SMoriah Waterland 							pkg[i]);
3255c51f124SMoriah Waterland 				}
3265c51f124SMoriah Waterland 			}
3275c51f124SMoriah Waterland 		} else {
3285c51f124SMoriah Waterland 			for (i = 0; i < pkgcnt; ++i) {
329*c57b7750SToomas Soome 				if (selected[i] == '\0') {
3305c51f124SMoriah Waterland 					root = get_inst_root();
3315c51f124SMoriah Waterland 					if (root)
3325c51f124SMoriah Waterland 						(void) snprintf(buf,
3335c51f124SMoriah Waterland 						sizeof (buf),
3345c51f124SMoriah Waterland 						"%s/var/sadm/pkg/%s/pkginfo",
3355c51f124SMoriah Waterland 						root, pkg[i]);
3365c51f124SMoriah Waterland 					else
3375c51f124SMoriah Waterland 						(void) snprintf(buf,
3385c51f124SMoriah Waterland 						sizeof (buf),
3395c51f124SMoriah Waterland 						"/var/sadm/pkg/%s/pkginfo",
3405c51f124SMoriah Waterland 						pkg[i]);
3415c51f124SMoriah Waterland 
3425c51f124SMoriah Waterland 					if (access(buf, F_OK))
3435c51f124SMoriah Waterland 						logerr(gettext(WRN_NOPKG),
3445c51f124SMoriah Waterland 							pkg[i]);
3455c51f124SMoriah Waterland 					else
3465c51f124SMoriah Waterland 						logerr(gettext(EMPTY_PKG),
3475c51f124SMoriah Waterland 							pkg[i]);
3485c51f124SMoriah Waterland 				}
3495c51f124SMoriah Waterland 			}
3505c51f124SMoriah Waterland 		}
3515c51f124SMoriah Waterland 		return (0); /* return value not important */
3525c51f124SMoriah Waterland 	} else if (pkgcnt == 0)
3535c51f124SMoriah Waterland 		return (1);
3545c51f124SMoriah Waterland 	else if (selected == NULL) {
3555c51f124SMoriah Waterland 		selected =
3565c51f124SMoriah Waterland 		    (char *)calloc((unsigned)(pkgcnt+1), sizeof (char));
3575c51f124SMoriah Waterland 		if (selected == NULL) {
3585c51f124SMoriah Waterland 			progerr(gettext(ERR_NOMEM), errno);
3595c51f124SMoriah Waterland 			exit(99);
3605c51f124SMoriah Waterland 			/*NOTREACHED*/
3615c51f124SMoriah Waterland 		}
3625c51f124SMoriah Waterland 	}
3635c51f124SMoriah Waterland 
3645c51f124SMoriah Waterland 	for (i = 0; i < pkgcnt; ++i) {
3655c51f124SMoriah Waterland 		if (pkgnmchk(p, pkg[i], 0) == 0) {
3665c51f124SMoriah Waterland 			if (selected != NULL)
3675c51f124SMoriah Waterland 				selected[i] = 'b';
3685c51f124SMoriah Waterland 			return (1);
3695c51f124SMoriah Waterland 		}
3705c51f124SMoriah Waterland 	}
3715c51f124SMoriah Waterland 	return (0);
3725c51f124SMoriah Waterland }
3735c51f124SMoriah Waterland 
3745c51f124SMoriah Waterland int
selpath(char * path,int partial_path)3755c51f124SMoriah Waterland selpath(char *path, int partial_path)
3765c51f124SMoriah Waterland {
3775c51f124SMoriah Waterland 	int n;
3785c51f124SMoriah Waterland 
3795c51f124SMoriah Waterland 	if (!npaths)
3805c51f124SMoriah Waterland 		return (1); /* everything is selectable */
3815c51f124SMoriah Waterland 
3825c51f124SMoriah Waterland 	for (n = 0; n < npaths; n++) {
3835c51f124SMoriah Waterland 		if (path == NULL) {
3845c51f124SMoriah Waterland 			if (!used[n])
3855c51f124SMoriah Waterland 				logerr(gettext(WRN_NOPATH),
3865c51f124SMoriah Waterland 					partial_path ? ppathlist[n] :
3875c51f124SMoriah Waterland 					pathlist[n]);
3885c51f124SMoriah Waterland 		} else if (partial_path) {
3895c51f124SMoriah Waterland 			used[n] = 1;
3905c51f124SMoriah Waterland 			return (1);
3915c51f124SMoriah Waterland 		} else if (!shellmatch(pathlist[n], path)) {
3925c51f124SMoriah Waterland 			used[n] = 1;
3935c51f124SMoriah Waterland 			return (1);
3945c51f124SMoriah Waterland 		}
3955c51f124SMoriah Waterland 	}
3965c51f124SMoriah Waterland 	return (0); /* not selected */
3975c51f124SMoriah Waterland }
3985c51f124SMoriah Waterland 
3995c51f124SMoriah Waterland static int
shellmatch(char * spec,char * path)4005c51f124SMoriah Waterland shellmatch(char *spec, char *path)
4015c51f124SMoriah Waterland {
4025c51f124SMoriah Waterland 	/* Check if the value is NULL */
4035c51f124SMoriah Waterland 	if (spec == NULL || path == NULL)
4045c51f124SMoriah Waterland 		return (1);
4055c51f124SMoriah Waterland 
4065c51f124SMoriah Waterland 	while (*spec && (*spec == *path)) {
4075c51f124SMoriah Waterland 		spec++, path++;
4085c51f124SMoriah Waterland 	}
4095c51f124SMoriah Waterland 	if ((*spec == *path) || (*spec == '*'))
4105c51f124SMoriah Waterland 		return (0);
4115c51f124SMoriah Waterland 	return (1);
4125c51f124SMoriah Waterland }
4135c51f124SMoriah Waterland 
4145c51f124SMoriah Waterland static int
is_partial_path_in_DB(char * srcpath,char * trgtpath)4155c51f124SMoriah Waterland is_partial_path_in_DB(char *srcpath, char *trgtpath)
4165c51f124SMoriah Waterland {
4175c51f124SMoriah Waterland 	if (strstr(srcpath, trgtpath) == NULL) {
4185c51f124SMoriah Waterland 		return (0);
4195c51f124SMoriah Waterland 	} else {
4205c51f124SMoriah Waterland 		return (1);
4215c51f124SMoriah Waterland 	}
4225c51f124SMoriah Waterland }
423