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 /*
235c51f124SMoriah Waterland * 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 <fcntl.h>
335c51f124SMoriah Waterland #include <ctype.h>
345c51f124SMoriah Waterland #include <errno.h>
355c51f124SMoriah Waterland #include <string.h>
365c51f124SMoriah Waterland #include <signal.h>
375c51f124SMoriah Waterland #include <stdlib.h>
385c51f124SMoriah Waterland #include <unistd.h>
395c51f124SMoriah Waterland #include <pkginfo.h>
405c51f124SMoriah Waterland #include <pkgstrct.h>
415c51f124SMoriah Waterland #include <pkglocs.h>
425c51f124SMoriah Waterland #include <locale.h>
435c51f124SMoriah Waterland #include <libintl.h>
445c51f124SMoriah Waterland #include <instzones_api.h>
455c51f124SMoriah Waterland #include <pkglib.h>
465c51f124SMoriah Waterland #include <install.h>
475c51f124SMoriah Waterland #include <libadm.h>
485c51f124SMoriah Waterland #include <libinst.h>
495c51f124SMoriah Waterland #include "installf.h"
505c51f124SMoriah Waterland
515c51f124SMoriah Waterland #define BASEDIR "/BASEDIR/"
525c51f124SMoriah Waterland
535c51f124SMoriah Waterland #define INSTALF (*prog == 'i')
545c51f124SMoriah Waterland #define REMOVEF (*prog == 'r')
555c51f124SMoriah Waterland
565c51f124SMoriah Waterland #define MSG_MANMOUNT "Assuming mounts were provided."
575c51f124SMoriah Waterland
585c51f124SMoriah Waterland #define ERR_PKGNAME_TOO_LONG \
595c51f124SMoriah Waterland "The package name specified on the command line\n" \
605c51f124SMoriah Waterland "exceeds the maximum package name length: a package name may contain a\n" \
615c51f124SMoriah Waterland "maximum of <%d> characters; however, the package name specified on\n" \
625c51f124SMoriah Waterland "the command line contains <%d> characters, which exceeds the maximum\n" \
635c51f124SMoriah Waterland "package name length by <%d> characters. Please specify a package name\n" \
645c51f124SMoriah Waterland "that contains no more than <%d> characters."
655c51f124SMoriah Waterland
665c51f124SMoriah Waterland #define ERR_DB_GET "unable to retrieve entries from the database."
675c51f124SMoriah Waterland #define ERR_DB_PUT "unable to update the package database."
685c51f124SMoriah Waterland #define ERR_ROOT_SET "Could not set install root from the environment."
695c51f124SMoriah Waterland #define ERR_ROOT_CMD "Command line install root contends with environment."
705c51f124SMoriah Waterland #define ERR_CLASSLONG "classname argument too long"
715c51f124SMoriah Waterland #define ERR_CLASSCHAR "bad character in classname"
725c51f124SMoriah Waterland #define ERR_INVAL "package instance <%s> is invalid"
735c51f124SMoriah Waterland #define ERR_NOTINST "package instance <%s> is not installed"
745c51f124SMoriah Waterland #define ERR_MERG "unable to merge contents file"
755c51f124SMoriah Waterland #define ERR_SORT "unable to sort contents file"
765c51f124SMoriah Waterland #define ERR_I_FAIL "installf did not complete successfully"
775c51f124SMoriah Waterland #define ERR_R_FAIL "removef did not complete successfully"
785c51f124SMoriah Waterland #define ERR_NOTROOT "You must be \"root\" for %s to execute properly."
795c51f124SMoriah Waterland #define ERR_USAGE0 "usage:\n" \
805c51f124SMoriah Waterland "\t%s [[-M|-A] -R host_path] [-V ...] pkginst path " \
815c51f124SMoriah Waterland "[path ...]\n" \
825c51f124SMoriah Waterland "\t%s [[-M|-A] -R host_path] [-V ...] pkginst path\n"
835c51f124SMoriah Waterland
845c51f124SMoriah Waterland #define ERR_USAGE1 "usage:\n" \
855c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] <pkginst> " \
865c51f124SMoriah Waterland "<path>\n" \
875c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] <pkginst> " \
885c51f124SMoriah Waterland "<path> <specs>\n" \
895c51f124SMoriah Waterland "\t where <specs> may be defined as:\n" \
905c51f124SMoriah Waterland "\t\tf <mode> <owner> <group>\n" \
915c51f124SMoriah Waterland "\t\tv <mode> <owner> <group>\n" \
925c51f124SMoriah Waterland "\t\te <mode> <owner> <group>\n" \
935c51f124SMoriah Waterland "\t\td <mode> <owner> <group>\n" \
945c51f124SMoriah Waterland "\t\tx <mode> <owner> <group>\n" \
955c51f124SMoriah Waterland "\t\tp <mode> <owner> <group>\n" \
965c51f124SMoriah Waterland "\t\tc <major> <minor> <mode> <owner> <group>\n" \
975c51f124SMoriah Waterland "\t\tb <major> <minor> <mode> <owner> <group>\n" \
985c51f124SMoriah Waterland "\t\ts <path>=<srcpath>\n" \
995c51f124SMoriah Waterland "\t\tl <path>=<srcpath>\n" \
1005c51f124SMoriah Waterland "\t%s [[-M] -R host_path] [-V ...] [-c class] -f pkginst\n"
1015c51f124SMoriah Waterland
1025c51f124SMoriah Waterland #define CMD_SORT "sort +0 -1"
1035c51f124SMoriah Waterland
1045c51f124SMoriah Waterland #define LINK 1
1055c51f124SMoriah Waterland
106*569041adSToomas Soome extern char dbst; /* libinst/pkgdbmerg.c */
1075c51f124SMoriah Waterland
1085c51f124SMoriah Waterland struct cfextra **extlist;
1095c51f124SMoriah Waterland struct pinfo **eptlist;
1105c51f124SMoriah Waterland
1115c51f124SMoriah Waterland char *classname = NULL;
1125c51f124SMoriah Waterland char *pkginst;
1135c51f124SMoriah Waterland char *uniTmp;
114*569041adSToomas Soome char *abi_sym_ptr;
115*569041adSToomas Soome char *ulim;
116*569041adSToomas Soome char *script;
1175c51f124SMoriah Waterland
1185c51f124SMoriah Waterland int nosetuid;
1195c51f124SMoriah Waterland int nocnflct;
1205c51f124SMoriah Waterland int warnflag = 0;
1215c51f124SMoriah Waterland
1225c51f124SMoriah Waterland /* libadm/pkgparam.c */
1235c51f124SMoriah Waterland extern void set_PKGADM(char *newpath);
1245c51f124SMoriah Waterland extern void set_PKGLOC(char *newpath);
1255c51f124SMoriah Waterland
1265c51f124SMoriah Waterland extern void set_limit(void);
1275c51f124SMoriah Waterland
1285c51f124SMoriah Waterland int
main(int argc,char ** argv)1295c51f124SMoriah Waterland main(int argc, char **argv)
1305c51f124SMoriah Waterland {
1315c51f124SMoriah Waterland VFP_T *cfTmpVfp;
13262224350SCasper H.S. Dik PKGserver pkgserver = NULL;
1335c51f124SMoriah Waterland char *tp;
1345c51f124SMoriah Waterland char *prog;
1355c51f124SMoriah Waterland char *pt;
1365c51f124SMoriah Waterland char *vfstab_file = NULL;
1379b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India char *temp_cl_basedir;
1385c51f124SMoriah Waterland char outbuf[PATH_MAX];
1395c51f124SMoriah Waterland int c;
1405c51f124SMoriah Waterland int dbchg;
1415c51f124SMoriah Waterland int err;
1425c51f124SMoriah Waterland int fflag = 0;
1435c51f124SMoriah Waterland int map_client = 1;
1445c51f124SMoriah Waterland int n;
1455c51f124SMoriah Waterland int pkgrmremote = 0; /* don't remove remote files */
1465c51f124SMoriah Waterland struct cfent *ept;
1475c51f124SMoriah Waterland
1485c51f124SMoriah Waterland /* hookup signals */
1495c51f124SMoriah Waterland
1505c51f124SMoriah Waterland (void) signal(SIGHUP, exit);
1515c51f124SMoriah Waterland (void) signal(SIGINT, exit);
1525c51f124SMoriah Waterland (void) signal(SIGQUIT, exit);
1535c51f124SMoriah Waterland
1545c51f124SMoriah Waterland /* initialize locale mechanism */
1555c51f124SMoriah Waterland
1565c51f124SMoriah Waterland (void) setlocale(LC_ALL, "");
1575c51f124SMoriah Waterland
1585c51f124SMoriah Waterland #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
1595c51f124SMoriah Waterland #define TEXT_DOMAIN "SYS_TEST"
1605c51f124SMoriah Waterland #endif /* !defined(TEXT_DOMAIN) */
1615c51f124SMoriah Waterland
1625c51f124SMoriah Waterland (void) textdomain(TEXT_DOMAIN);
1635c51f124SMoriah Waterland
1645c51f124SMoriah Waterland /* determine program name */
1655c51f124SMoriah Waterland
1665c51f124SMoriah Waterland prog = set_prog_name(argv[0]);
1675c51f124SMoriah Waterland
1685c51f124SMoriah Waterland /* tell instzones interface how to access package output functions */
1695c51f124SMoriah Waterland
1705c51f124SMoriah Waterland z_set_output_functions(echo, echoDebug, progerr);
1715c51f124SMoriah Waterland
1725c51f124SMoriah Waterland /* only allow root to run this program */
1735c51f124SMoriah Waterland
1745c51f124SMoriah Waterland if (getuid() != 0) {
1755c51f124SMoriah Waterland progerr(gettext(ERR_NOTROOT), prog);
1765c51f124SMoriah Waterland exit(1);
1775c51f124SMoriah Waterland }
1785c51f124SMoriah Waterland
1795c51f124SMoriah Waterland ulim = getenv("PKG_ULIMIT");
1805c51f124SMoriah Waterland script = getenv("PKG_PROC_SCRIPT");
1815c51f124SMoriah Waterland
1825c51f124SMoriah Waterland if (ulim && script) {
1835c51f124SMoriah Waterland set_limit();
1845c51f124SMoriah Waterland clr_ulimit();
1855c51f124SMoriah Waterland }
1865c51f124SMoriah Waterland
1875c51f124SMoriah Waterland /* bug id 4244631, not ABI compliant */
1885c51f124SMoriah Waterland abi_sym_ptr = getenv("PKG_NONABI_SYMLINKS");
1895c51f124SMoriah Waterland if (abi_sym_ptr && strncasecmp(abi_sym_ptr, "TRUE", 4) == 0)
1905c51f124SMoriah Waterland set_nonABI_symlinks();
1915c51f124SMoriah Waterland
1925c51f124SMoriah Waterland /* bugId 4012147 */
1935c51f124SMoriah Waterland if ((uniTmp = getenv("PKG_NO_UNIFIED")) != NULL)
1945c51f124SMoriah Waterland map_client = 0;
1955c51f124SMoriah Waterland if (!set_inst_root(getenv("PKG_INSTALL_ROOT"))) {
1965c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_SET));
1975c51f124SMoriah Waterland exit(1);
1985c51f124SMoriah Waterland }
1995c51f124SMoriah Waterland
2005c51f124SMoriah Waterland while ((c = getopt(argc, argv, "c:V:fAMR:?")) != EOF) {
2015c51f124SMoriah Waterland switch (c) {
2025c51f124SMoriah Waterland case 'f':
2035c51f124SMoriah Waterland fflag++;
2045c51f124SMoriah Waterland break;
2055c51f124SMoriah Waterland
2065c51f124SMoriah Waterland case 'c':
2075c51f124SMoriah Waterland classname = optarg;
2085c51f124SMoriah Waterland /* validate that classname is acceptable */
2095c51f124SMoriah Waterland if (strlen(classname) > (size_t)CLSSIZ) {
2105c51f124SMoriah Waterland progerr(gettext(ERR_CLASSLONG));
2115c51f124SMoriah Waterland exit(1);
2125c51f124SMoriah Waterland }
2135c51f124SMoriah Waterland for (pt = classname; *pt; pt++) {
2145c51f124SMoriah Waterland if (!isalpha(*pt) && !isdigit(*pt)) {
2155c51f124SMoriah Waterland progerr(gettext(ERR_CLASSCHAR));
2165c51f124SMoriah Waterland exit(1);
2175c51f124SMoriah Waterland }
2185c51f124SMoriah Waterland }
2195c51f124SMoriah Waterland break;
2205c51f124SMoriah Waterland
2215c51f124SMoriah Waterland /*
2225c51f124SMoriah Waterland * Don't map the client filesystem onto the server's. Assume
2235c51f124SMoriah Waterland * the mounts have been made for us.
2245c51f124SMoriah Waterland */
2255c51f124SMoriah Waterland case 'M':
2265c51f124SMoriah Waterland map_client = 0;
2275c51f124SMoriah Waterland break;
2285c51f124SMoriah Waterland
2295c51f124SMoriah Waterland /*
2305c51f124SMoriah Waterland * Allow admin to establish the client filesystem using a
2315c51f124SMoriah Waterland * vfstab-like file of stable format.
2325c51f124SMoriah Waterland */
2335c51f124SMoriah Waterland case 'V':
2345c51f124SMoriah Waterland vfstab_file = flex_device(optarg, 2);
2355c51f124SMoriah Waterland map_client = 1;
2365c51f124SMoriah Waterland break;
2375c51f124SMoriah Waterland
2385c51f124SMoriah Waterland case 'A':
2395c51f124SMoriah Waterland pkgrmremote++;
2405c51f124SMoriah Waterland break;
2415c51f124SMoriah Waterland
2425c51f124SMoriah Waterland case 'R': /* added for newroot option */
2435c51f124SMoriah Waterland if (!set_inst_root(optarg)) {
2445c51f124SMoriah Waterland progerr(gettext(ERR_ROOT_CMD));
2455c51f124SMoriah Waterland exit(1);
2465c51f124SMoriah Waterland }
2475c51f124SMoriah Waterland break;
2485c51f124SMoriah Waterland
2495c51f124SMoriah Waterland default:
2505c51f124SMoriah Waterland usage();
2515c51f124SMoriah Waterland /*NOTREACHED*/
2525c51f124SMoriah Waterland /*
2535c51f124SMoriah Waterland * Although usage() calls a noreturn function,
2545c51f124SMoriah Waterland * needed to add return (1); so that main() would
2555c51f124SMoriah Waterland * pass compilation checks. The statement below
2565c51f124SMoriah Waterland * should never be executed.
2575c51f124SMoriah Waterland */
2585c51f124SMoriah Waterland return (1);
2595c51f124SMoriah Waterland }
2605c51f124SMoriah Waterland }
2615c51f124SMoriah Waterland
2625c51f124SMoriah Waterland if (pkgrmremote && (!is_an_inst_root() || fflag || INSTALF)) {
2635c51f124SMoriah Waterland usage();
2645c51f124SMoriah Waterland /*NOTREACHED*/
2655c51f124SMoriah Waterland }
2665c51f124SMoriah Waterland
2675c51f124SMoriah Waterland /*
2685c51f124SMoriah Waterland * Get the mount table info and store internally.
2695c51f124SMoriah Waterland */
2705c51f124SMoriah Waterland if (get_mntinfo(map_client, vfstab_file))
2715c51f124SMoriah Waterland exit(1);
2725c51f124SMoriah Waterland
2735c51f124SMoriah Waterland /*
2745c51f124SMoriah Waterland * This function defines the standard /var/... directories used later
2755c51f124SMoriah Waterland * to construct the paths to the various databases.
2765c51f124SMoriah Waterland */
2775c51f124SMoriah Waterland (void) set_PKGpaths(get_inst_root());
2785c51f124SMoriah Waterland
2795c51f124SMoriah Waterland /*
2805c51f124SMoriah Waterland * If this is being installed on a client whose /var filesystem is
2815c51f124SMoriah Waterland * mounted in some odd way, remap the administrative paths to the
2825c51f124SMoriah Waterland * real filesystem. This could be avoided by simply mounting up the
2835c51f124SMoriah Waterland * client now; but we aren't yet to the point in the process where
2845c51f124SMoriah Waterland * modification of the filesystem is permitted.
2855c51f124SMoriah Waterland */
2865c51f124SMoriah Waterland if (is_an_inst_root()) {
2875c51f124SMoriah Waterland int fsys_value;
2885c51f124SMoriah Waterland
2895c51f124SMoriah Waterland fsys_value = fsys(get_PKGLOC());
2905c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value))
2915c51f124SMoriah Waterland set_PKGLOC(server_map(get_PKGLOC(), fsys_value));
2925c51f124SMoriah Waterland
2935c51f124SMoriah Waterland fsys_value = fsys(get_PKGADM());
2945c51f124SMoriah Waterland if (use_srvr_map_n(fsys_value))
2955c51f124SMoriah Waterland set_PKGADM(server_map(get_PKGADM(), fsys_value));
2965c51f124SMoriah Waterland }
2975c51f124SMoriah Waterland
2985c51f124SMoriah Waterland /*
2995c51f124SMoriah Waterland * get the package name and verify length is not too long
3005c51f124SMoriah Waterland */
3015c51f124SMoriah Waterland
3025c51f124SMoriah Waterland pkginst = argv[optind++];
3035c51f124SMoriah Waterland if (pkginst == NULL) {
3045c51f124SMoriah Waterland usage();
3055c51f124SMoriah Waterland /*NOTREACHED*/
3065c51f124SMoriah Waterland
3075c51f124SMoriah Waterland }
3085c51f124SMoriah Waterland
3095c51f124SMoriah Waterland n = strlen(pkginst);
3105c51f124SMoriah Waterland if (n > PKGSIZ) {
3115c51f124SMoriah Waterland progerr(gettext(ERR_PKGNAME_TOO_LONG), PKGSIZ, n, n-PKGSIZ,
3125c51f124SMoriah Waterland PKGSIZ);
3135c51f124SMoriah Waterland usage();
3145c51f124SMoriah Waterland /*NOTREACHED*/
3155c51f124SMoriah Waterland }
3165c51f124SMoriah Waterland
3175c51f124SMoriah Waterland /*
3185c51f124SMoriah Waterland * The following is used to setup the environment. Note that the
3195c51f124SMoriah Waterland * variable 'BASEDIR' is only meaningful for this utility if there
3205c51f124SMoriah Waterland * is an install root, recorded in PKG_INSTALL_ROOT. Otherwise, this
3215c51f124SMoriah Waterland * utility can create a file or directory anywhere unfettered by
3225c51f124SMoriah Waterland * the basedir associated with the package instance.
3235c51f124SMoriah Waterland */
3245c51f124SMoriah Waterland if ((err = set_basedirs(0, NULL, pkginst, 1)) != 0)
3255c51f124SMoriah Waterland exit(err);
3265c51f124SMoriah Waterland
3275c51f124SMoriah Waterland if (INSTALF)
3285c51f124SMoriah Waterland mkbasedir(0, get_basedir());
3295c51f124SMoriah Waterland
3305c51f124SMoriah Waterland if (fflag) {
3315c51f124SMoriah Waterland /* installf and removef must only have pkginst */
3325c51f124SMoriah Waterland if (optind != argc) {
3335c51f124SMoriah Waterland usage();
3345c51f124SMoriah Waterland /*NOTREACHED*/
3355c51f124SMoriah Waterland }
3365c51f124SMoriah Waterland } else {
3375c51f124SMoriah Waterland /*
3385c51f124SMoriah Waterland * installf and removef must have at minimum
3395c51f124SMoriah Waterland * pkginst & pathname specified on command line
3405c51f124SMoriah Waterland */
3415c51f124SMoriah Waterland if (optind >= argc) {
3425c51f124SMoriah Waterland usage();
3435c51f124SMoriah Waterland /*NOTREACHED*/
3445c51f124SMoriah Waterland }
3455c51f124SMoriah Waterland }
3465c51f124SMoriah Waterland if (REMOVEF) {
3475c51f124SMoriah Waterland if (classname) {
3485c51f124SMoriah Waterland usage();
3495c51f124SMoriah Waterland }
3505c51f124SMoriah Waterland }
3515c51f124SMoriah Waterland if (pkgnmchk(pkginst, "all", 0)) {
3525c51f124SMoriah Waterland progerr(gettext(ERR_INVAL), pkginst);
3535c51f124SMoriah Waterland exit(1);
3545c51f124SMoriah Waterland }
3555c51f124SMoriah Waterland if (fpkginst(pkginst, NULL, NULL) == NULL) {
3565c51f124SMoriah Waterland progerr(gettext(ERR_NOTINST), pkginst);
3575c51f124SMoriah Waterland exit(1);
3585c51f124SMoriah Waterland }
3595c51f124SMoriah Waterland
3605c51f124SMoriah Waterland /*
3615c51f124SMoriah Waterland * This maps the client filesystems into the server's space.
3625c51f124SMoriah Waterland */
3635c51f124SMoriah Waterland if (map_client && !mount_client())
3645c51f124SMoriah Waterland logerr(gettext(MSG_MANMOUNT));
3655c51f124SMoriah Waterland
3665c51f124SMoriah Waterland /* open the package database (contents) file */
3675c51f124SMoriah Waterland
36862224350SCasper H.S. Dik if (!ocfile(&pkgserver, &cfTmpVfp, 0L)) {
3695c51f124SMoriah Waterland quit(1);
3705c51f124SMoriah Waterland }
3715c51f124SMoriah Waterland
3725c51f124SMoriah Waterland if (fflag) {
37362224350SCasper H.S. Dik dbchg = dofinal(pkgserver, cfTmpVfp, REMOVEF, classname, prog);
3745c51f124SMoriah Waterland } else {
3755c51f124SMoriah Waterland if (INSTALF) {
3765c51f124SMoriah Waterland dbst = INST_RDY;
3775c51f124SMoriah Waterland if (installf(argc-optind, &argv[optind]))
3785c51f124SMoriah Waterland quit(1);
3795c51f124SMoriah Waterland } else {
3805c51f124SMoriah Waterland dbst = RM_RDY;
3815c51f124SMoriah Waterland removef(argc-optind, &argv[optind]);
3825c51f124SMoriah Waterland }
3835c51f124SMoriah Waterland
38462224350SCasper H.S. Dik dbchg = pkgdbmerg(pkgserver, cfTmpVfp, extlist);
3855c51f124SMoriah Waterland if (dbchg < 0) {
3865c51f124SMoriah Waterland progerr(gettext(ERR_MERG));
3875c51f124SMoriah Waterland quit(99);
3885c51f124SMoriah Waterland }
3895c51f124SMoriah Waterland }
3905c51f124SMoriah Waterland
3915c51f124SMoriah Waterland if (dbchg) {
39262224350SCasper H.S. Dik if ((n = swapcfile(pkgserver, &cfTmpVfp, pkginst, 1))
39362224350SCasper H.S. Dik == RESULT_WRN) {
39462224350SCasper H.S. Dik warnflag++;
3955c51f124SMoriah Waterland } else if (n == RESULT_ERR) {
39662224350SCasper H.S. Dik quit(99);
3975c51f124SMoriah Waterland }
3985c51f124SMoriah Waterland }
3995c51f124SMoriah Waterland
4005c51f124SMoriah Waterland relslock();
4015c51f124SMoriah Waterland
4025c51f124SMoriah Waterland if (REMOVEF && !fflag) {
4035c51f124SMoriah Waterland for (n = 0; extlist[n]; n++) {
4045c51f124SMoriah Waterland ept = &(extlist[n]->cf_ent);
4055c51f124SMoriah Waterland
4065c51f124SMoriah Waterland /* Skip duplicated paths */
4075c51f124SMoriah Waterland if ((n > 0) && (strncmp(ept->path,
4085c51f124SMoriah Waterland extlist[n-1]->cf_ent.path, PATH_MAX) == 0)) {
4095c51f124SMoriah Waterland continue;
4105c51f124SMoriah Waterland }
4115c51f124SMoriah Waterland
4125c51f124SMoriah Waterland if (!extlist[n]->mstat.shared) {
4135c51f124SMoriah Waterland /*
4145c51f124SMoriah Waterland * Only output paths that can be deleted.
4155c51f124SMoriah Waterland * so need to skip if the object is owned
4165c51f124SMoriah Waterland * by a remote server and removal is not
4175c51f124SMoriah Waterland * being forced.
4185c51f124SMoriah Waterland */
4195c51f124SMoriah Waterland if (ept->pinfo &&
4205c51f124SMoriah Waterland (ept->pinfo->status == SERVED_FILE) &&
4215c51f124SMoriah Waterland !pkgrmremote)
4225c51f124SMoriah Waterland continue;
4235c51f124SMoriah Waterland
4245c51f124SMoriah Waterland c = 0;
4255c51f124SMoriah Waterland if (is_a_cl_basedir() && !is_an_inst_root()) {
4269b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India /*
4279b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * A path in contents db might have
4289b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * other prefix than BASEDIR of the
4299b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India * package
4309b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India */
4319b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India temp_cl_basedir = get_client_basedir();
4329b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India if (strncmp(ept->path, temp_cl_basedir,
4339b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India strlen(temp_cl_basedir)) == 0) {
4349b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India c = strlen(temp_cl_basedir);
4359b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(outbuf,
4369b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India sizeof (outbuf), "%s/%s\n",
4379b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India get_basedir(),
4389b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India &(ept->path[c]));
4399b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India } else {
4409b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India (void) snprintf(outbuf,
4419b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India sizeof (outbuf),
4429b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India "%s\n", &(ept->path[c]));
4439b2055ccSphaniram rampura krishnamurthy - Sun Microsystems - Bangalore India }
4445c51f124SMoriah Waterland } else if (is_an_inst_root()) {
4455c51f124SMoriah Waterland (void) snprintf(outbuf, sizeof (outbuf),
44662224350SCasper H.S. Dik "%s/%s\n", get_inst_root(),
44762224350SCasper H.S. Dik &(ept->path[c]));
4485c51f124SMoriah Waterland } else {
4495c51f124SMoriah Waterland (void) snprintf(outbuf, sizeof (outbuf),
45062224350SCasper H.S. Dik "%s\n", &(ept->path[c]));
4515c51f124SMoriah Waterland }
4525c51f124SMoriah Waterland canonize(outbuf);
4535c51f124SMoriah Waterland (void) printf("%s", outbuf);
4545c51f124SMoriah Waterland }
4555c51f124SMoriah Waterland }
4565c51f124SMoriah Waterland } else if (INSTALF && !fflag) {
4575c51f124SMoriah Waterland for (n = 0; extlist[n]; n++) {
4585c51f124SMoriah Waterland ept = &(extlist[n]->cf_ent);
4595c51f124SMoriah Waterland
4605c51f124SMoriah Waterland if (strchr("dxcbp", ept->ftype)) {
4615c51f124SMoriah Waterland tp = fixpath(ept->path);
46262224350SCasper H.S. Dik (void) averify(1, &ept->ftype, tp, &ept->ainfo);
4635c51f124SMoriah Waterland }
4645c51f124SMoriah Waterland }
4655c51f124SMoriah Waterland }
4665c51f124SMoriah Waterland
46762224350SCasper H.S. Dik pkgcloseserver(pkgserver);
4685c51f124SMoriah Waterland
4695c51f124SMoriah Waterland z_destroyMountTable();
4705c51f124SMoriah Waterland
4715c51f124SMoriah Waterland quit(warnflag ? 1 : 0);
4725c51f124SMoriah Waterland /* LINTED: no return */
4735c51f124SMoriah Waterland }
4745c51f124SMoriah Waterland
4755c51f124SMoriah Waterland void
quit(int n)4765c51f124SMoriah Waterland quit(int n)
4775c51f124SMoriah Waterland {
4785c51f124SMoriah Waterland char *prog = get_prog_name();
4795c51f124SMoriah Waterland
4805c51f124SMoriah Waterland unmount_client();
4815c51f124SMoriah Waterland
4825c51f124SMoriah Waterland if (ulim && script) {
4835c51f124SMoriah Waterland if (REMOVEF) {
4845c51f124SMoriah Waterland set_ulimit(script, gettext(ERR_R_FAIL));
4855c51f124SMoriah Waterland } else {
4865c51f124SMoriah Waterland set_ulimit(script, gettext(ERR_I_FAIL));
4875c51f124SMoriah Waterland }
4885c51f124SMoriah Waterland }
4895c51f124SMoriah Waterland
4905c51f124SMoriah Waterland exit(n);
4915c51f124SMoriah Waterland }
4925c51f124SMoriah Waterland
4935c51f124SMoriah Waterland void
usage(void)4945c51f124SMoriah Waterland usage(void)
4955c51f124SMoriah Waterland {
4965c51f124SMoriah Waterland char *prog = get_prog_name();
4975c51f124SMoriah Waterland
4985c51f124SMoriah Waterland if (REMOVEF) {
4995c51f124SMoriah Waterland (void) fprintf(stderr, gettext(ERR_USAGE0), prog, prog);
5005c51f124SMoriah Waterland } else {
5015c51f124SMoriah Waterland (void) fprintf(stderr, gettext(ERR_USAGE1), prog, prog, prog);
5025c51f124SMoriah Waterland }
5035c51f124SMoriah Waterland exit(1);
5045c51f124SMoriah Waterland }
505