5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER START
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The contents of this file are subject to the terms of the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Common Development and Distribution License (the "License").
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You may not use this file except in compliance with the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or http://www.opensolaris.org/os/licensing.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * See the License for the specific language governing permissions
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * and limitations under the License.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If applicable, add the following below this CDDL HEADER, with the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * CDDL HEADER END
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Use is subject to license terms.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland/* All Rights Reserved */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern char *basedir, *pathlist[], *ppathlist[], **pkg, **environ;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandextern short used[];
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dikextern int ckentry(int, int, struct cfent *, VFP_T *, PKGserver);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define MSG_ARCHIVE "NOTE: some pathnames are in private formats " \
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland "and cannot be verified"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define WRN_NOPKG "WARNING: no pathnames were associated with <%s>"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define WRN_NOPATH "WARNING: no information associated with pathname <%s>"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define EMPTY_PKG "WARNING: Package <%s> is installed but empty"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_NOMEM "unable to allocate dynamic memory, errno=%d"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_PKGMAP "unable to open pkgmap file <%s>"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland#define ERR_ENVFILE "unable to open environment file <%s>"
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int shellmatch(char *, char *);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandstatic int is_partial_path_in_DB(char *, char *);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandint selpath(char *, int);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * This routine checks all files which are referenced in the pkgmap which is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * identified by the mapfile arg. When the package is installed, the mapfile
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * may be the contents file or a separate pkgmap (maptyp tells the function
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * which it is). The variable uninst tells the function whether the package
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is in the installed state or not. The envfile entry is usually a pkginfo
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * file, but it could be any environment parameter list.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterlandcheckmap(int maptyp, int uninst, char *mapfile, char *envfile,
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If checking an uninstalled package, we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * only want two parameters. If we took all
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * of them, including path definitions, we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * wouldn't be looking in the right places in
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * the reloc and root directories.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * If we are using a contents file for the map, this locks the
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * contents file in order to freeze the database and assure it
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * remains synchronized with the file system against which it is
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * being compared. There is no practical way to lock another pkgmap
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * on some unknown medium so we don't bother.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (maptyp) { /* If this is the contents file */
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik pkgopenfilter(server, pkgcnt == 1 ? pkginst : NULL) != 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (vfpOpen(&vfp, mapfile, "r", VFP_NONE) != 0) {
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik if ((n = NXTENTRY(&entry, vfp, server)) == 0) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Search for partial paths in the ext DB.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* LINTED warning: statement has no consequent: if */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland if (is_partial_path_in_DB(entry.path, path)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Check this entry */
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik } else if (entry.ftype == 's' || entry.ftype == 'l') {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* LINTED warning: statement has no consequen */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Check this entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Skip to next DB entry */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland break; /* done with file */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * The class list may not be complete for good reason, so
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * there's no complaining if this returns an index of -1.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland entry.pkg_class_idx = cl_idx(entry.pkg_class);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * check to see if the entry we just read
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * is associated with one of the packages
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we have listed on the command line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue; /* not selected */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Check to see if the pathname associated with the entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * we just read is associated with the list of paths we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * supplied on the command line
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland continue; /* not selected */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * Determine if this is a package object wanting
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * verification. Metafiles are always checked, otherwise, we
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * rely on the class to discriminate.
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* If there's no class list... */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * ... or this entry isn't in that class list
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * or it's in a private format, then don't
62224350e5355e6834f7deb9d8a7d062a50cb7c2Casper H.S. Dik if (ckentry((envfile ? 1 : 0), maptyp, &entry, vfp, server))
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } while (n != 0);
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* free up environment resources */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (n = 0; environ[n]; n++)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * make sure each listed package was associated with
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * an entry from the prototype or pkgmap
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * make sure each listed pathname was associated with an entry
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland * from the prototype or pkgmap
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland register int i;
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < pkgcnt; ++i) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* bugid 1227628 */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < pkgcnt; ++i) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* return value not important */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (pkgcnt == 0)
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland (char *)calloc((unsigned)(pkgcnt+1), sizeof (char));
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /*NOTREACHED*/
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (i = 0; i < pkgcnt; ++i) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland for (n = 0; n < npaths; n++) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland } else if (!shellmatch(pathlist[n], path)) {
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland return (0); /* not selected */
5c51f1241dbbdf2656d0e10011981411ed0c9673Moriah Waterland /* Check if the value is NULL */