1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland * CDDL HEADER START
3*5c51f124SMoriah Waterland *
4*5c51f124SMoriah Waterland * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland *
8*5c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland * and limitations under the License.
12*5c51f124SMoriah Waterland *
13*5c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland *
19*5c51f124SMoriah Waterland * CDDL HEADER END
20*5c51f124SMoriah Waterland */
21*5c51f124SMoriah Waterland
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*5c51f124SMoriah Waterland * Use is subject to license terms.
25*5c51f124SMoriah Waterland */
26*5c51f124SMoriah Waterland
27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*5c51f124SMoriah Waterland /* All Rights Reserved */
29*5c51f124SMoriah Waterland
30*5c51f124SMoriah Waterland
31*5c51f124SMoriah Waterland #include <stdio.h>
32*5c51f124SMoriah Waterland #include <limits.h>
33*5c51f124SMoriah Waterland #include <stdlib.h>
34*5c51f124SMoriah Waterland #include <unistd.h>
35*5c51f124SMoriah Waterland #include <sys/types.h>
36*5c51f124SMoriah Waterland #include <pkgstrct.h>
37*5c51f124SMoriah Waterland #include <string.h>
38*5c51f124SMoriah Waterland #include <locale.h>
39*5c51f124SMoriah Waterland #include <libintl.h>
40*5c51f124SMoriah Waterland #include <pkglib.h>
41*5c51f124SMoriah Waterland #include "install.h"
42*5c51f124SMoriah Waterland #include "libadm.h"
43*5c51f124SMoriah Waterland #include "libinst.h"
44*5c51f124SMoriah Waterland
45*5c51f124SMoriah Waterland #define ERR_PKGINFO "unable to access pkginfo file <%s>"
46*5c51f124SMoriah Waterland #define ERR_PKGMAP "unable to access pkgmap file <%s>"
47*5c51f124SMoriah Waterland #define ERR_NOPARAM "%s parameter is not defined in <%s>"
48*5c51f124SMoriah Waterland #define ERR_PKGBAD "PKG parameter is invalid <%s>"
49*5c51f124SMoriah Waterland #define ERR_PKGMTCH "PKG parameter <%s> does not match instance <%s>"
50*5c51f124SMoriah Waterland
51*5c51f124SMoriah Waterland char *pkgarch;
52*5c51f124SMoriah Waterland char *pkgvers;
53*5c51f124SMoriah Waterland char *pkgabrv;
54*5c51f124SMoriah Waterland char *pkgname;
55*5c51f124SMoriah Waterland char pkgwild[PKGSIZ+1];
56*5c51f124SMoriah Waterland
57*5c51f124SMoriah Waterland /*
58*5c51f124SMoriah Waterland * This function confirms the presence of pkgmap and pkginfo and verifies
59*5c51f124SMoriah Waterland * that the mandatory parameters are available in the environment.
60*5c51f124SMoriah Waterland */
61*5c51f124SMoriah Waterland int
pkgenv(char * pkginst,char * p_pkginfo,char * p_pkgmap)62*5c51f124SMoriah Waterland pkgenv(char *pkginst, char *p_pkginfo, char *p_pkgmap)
63*5c51f124SMoriah Waterland {
64*5c51f124SMoriah Waterland FILE *fp;
65*5c51f124SMoriah Waterland char *value,
66*5c51f124SMoriah Waterland path[PATH_MAX],
67*5c51f124SMoriah Waterland param[MAX_PKG_PARAM_LENGTH];
68*5c51f124SMoriah Waterland int errflg;
69*5c51f124SMoriah Waterland
70*5c51f124SMoriah Waterland errflg = 0;
71*5c51f124SMoriah Waterland if (access(p_pkgmap, 0)) {
72*5c51f124SMoriah Waterland progerr(gettext(ERR_PKGMAP), p_pkgmap);
73*5c51f124SMoriah Waterland return (1);
74*5c51f124SMoriah Waterland }
75*5c51f124SMoriah Waterland if ((fp = fopen(p_pkginfo, "r")) == NULL) {
76*5c51f124SMoriah Waterland progerr(gettext(ERR_PKGINFO), p_pkginfo);
77*5c51f124SMoriah Waterland return (1);
78*5c51f124SMoriah Waterland }
79*5c51f124SMoriah Waterland param[0] = '\0';
80*5c51f124SMoriah Waterland while (value = fpkgparam(fp, param)) {
81*5c51f124SMoriah Waterland if (strcmp("PATH", param))
82*5c51f124SMoriah Waterland putparam(param, value);
83*5c51f124SMoriah Waterland free(value);
84*5c51f124SMoriah Waterland param[0] = '\0';
85*5c51f124SMoriah Waterland }
86*5c51f124SMoriah Waterland (void) fclose(fp);
87*5c51f124SMoriah Waterland /*
88*5c51f124SMoriah Waterland * verify that required parameters are now present in
89*5c51f124SMoriah Waterland * the environment
90*5c51f124SMoriah Waterland */
91*5c51f124SMoriah Waterland if ((pkgabrv = getenv("PKG")) == NULL) {
92*5c51f124SMoriah Waterland progerr(gettext(ERR_NOPARAM), "PKG", path);
93*5c51f124SMoriah Waterland errflg++;
94*5c51f124SMoriah Waterland }
95*5c51f124SMoriah Waterland if (pkgnmchk(pkgabrv, NULL, 0) || strchr(pkgabrv, '.')) {
96*5c51f124SMoriah Waterland progerr(gettext(ERR_PKGBAD), pkgabrv);
97*5c51f124SMoriah Waterland errflg++;
98*5c51f124SMoriah Waterland }
99*5c51f124SMoriah Waterland (void) snprintf(pkgwild, sizeof (pkgwild), "%s.*", pkgabrv);
100*5c51f124SMoriah Waterland if ((pkgname = getenv("NAME")) == NULL) {
101*5c51f124SMoriah Waterland progerr(gettext(ERR_NOPARAM), "NAME", path);
102*5c51f124SMoriah Waterland errflg++;
103*5c51f124SMoriah Waterland }
104*5c51f124SMoriah Waterland if ((pkgarch = getenv("ARCH")) == NULL) {
105*5c51f124SMoriah Waterland progerr(gettext(ERR_NOPARAM), "ARCH", path);
106*5c51f124SMoriah Waterland errflg++;
107*5c51f124SMoriah Waterland }
108*5c51f124SMoriah Waterland if ((pkgvers = getenv("VERSION")) == NULL) {
109*5c51f124SMoriah Waterland progerr(gettext(ERR_NOPARAM), "VERSION", path);
110*5c51f124SMoriah Waterland errflg++;
111*5c51f124SMoriah Waterland }
112*5c51f124SMoriah Waterland if (getenv("CATEGORY") == NULL) {
113*5c51f124SMoriah Waterland progerr(gettext(ERR_NOPARAM), "CATEGORY", path);
114*5c51f124SMoriah Waterland errflg++;
115*5c51f124SMoriah Waterland }
116*5c51f124SMoriah Waterland /*
117*5c51f124SMoriah Waterland * verify consistency between PKG parameter and pkginst that
118*5c51f124SMoriah Waterland * was determined from the directory structure
119*5c51f124SMoriah Waterland */
120*5c51f124SMoriah Waterland (void) snprintf(param, sizeof (param), "%s.*", pkgabrv);
121*5c51f124SMoriah Waterland if (pkgnmchk(pkginst, param, 0)) {
122*5c51f124SMoriah Waterland progerr(gettext(ERR_PKGMTCH), pkgabrv, pkginst);
123*5c51f124SMoriah Waterland errflg++;
124*5c51f124SMoriah Waterland }
125*5c51f124SMoriah Waterland return (errflg);
126*5c51f124SMoriah Waterland }
127