xref: /onnv-gate/usr/src/cmd/svr4pkg/pkginstall/pkgenv.c (revision 9781:ccf49524d5dc)
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 <limits.h>
33*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
34*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
35*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
36*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
37*9781SMoriah.Waterland@Sun.COM #include <string.h>
38*9781SMoriah.Waterland@Sun.COM #include <locale.h>
39*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
40*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
41*9781SMoriah.Waterland@Sun.COM #include "install.h"
42*9781SMoriah.Waterland@Sun.COM #include "libadm.h"
43*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
44*9781SMoriah.Waterland@Sun.COM 
45*9781SMoriah.Waterland@Sun.COM #define	ERR_PKGINFO	"unable to access pkginfo file <%s>"
46*9781SMoriah.Waterland@Sun.COM #define	ERR_PKGMAP	"unable to access pkgmap file <%s>"
47*9781SMoriah.Waterland@Sun.COM #define	ERR_NOPARAM	"%s parameter is not defined in <%s>"
48*9781SMoriah.Waterland@Sun.COM #define	ERR_PKGBAD	"PKG parameter is invalid <%s>"
49*9781SMoriah.Waterland@Sun.COM #define	ERR_PKGMTCH	"PKG parameter <%s> does not match instance <%s>"
50*9781SMoriah.Waterland@Sun.COM 
51*9781SMoriah.Waterland@Sun.COM char	*pkgarch;
52*9781SMoriah.Waterland@Sun.COM char	*pkgvers;
53*9781SMoriah.Waterland@Sun.COM char	*pkgabrv;
54*9781SMoriah.Waterland@Sun.COM char	*pkgname;
55*9781SMoriah.Waterland@Sun.COM char	pkgwild[PKGSIZ+1];
56*9781SMoriah.Waterland@Sun.COM 
57*9781SMoriah.Waterland@Sun.COM /*
58*9781SMoriah.Waterland@Sun.COM  * This function confirms the presence of pkgmap and pkginfo and verifies
59*9781SMoriah.Waterland@Sun.COM  * that the mandatory parameters are available in the environment.
60*9781SMoriah.Waterland@Sun.COM  */
61*9781SMoriah.Waterland@Sun.COM int
pkgenv(char * pkginst,char * p_pkginfo,char * p_pkgmap)62*9781SMoriah.Waterland@Sun.COM pkgenv(char *pkginst, char *p_pkginfo, char *p_pkgmap)
63*9781SMoriah.Waterland@Sun.COM {
64*9781SMoriah.Waterland@Sun.COM 	FILE	*fp;
65*9781SMoriah.Waterland@Sun.COM 	char 	*value,
66*9781SMoriah.Waterland@Sun.COM 		path[PATH_MAX],
67*9781SMoriah.Waterland@Sun.COM 		param[MAX_PKG_PARAM_LENGTH];
68*9781SMoriah.Waterland@Sun.COM 	int	errflg;
69*9781SMoriah.Waterland@Sun.COM 
70*9781SMoriah.Waterland@Sun.COM 	errflg = 0;
71*9781SMoriah.Waterland@Sun.COM 	if (access(p_pkgmap, 0)) {
72*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PKGMAP), p_pkgmap);
73*9781SMoriah.Waterland@Sun.COM 		return (1);
74*9781SMoriah.Waterland@Sun.COM 	}
75*9781SMoriah.Waterland@Sun.COM 	if ((fp = fopen(p_pkginfo, "r")) == NULL) {
76*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PKGINFO), p_pkginfo);
77*9781SMoriah.Waterland@Sun.COM 		return (1);
78*9781SMoriah.Waterland@Sun.COM 	}
79*9781SMoriah.Waterland@Sun.COM 	param[0] = '\0';
80*9781SMoriah.Waterland@Sun.COM 	while (value = fpkgparam(fp, param)) {
81*9781SMoriah.Waterland@Sun.COM 		if (strcmp("PATH", param))
82*9781SMoriah.Waterland@Sun.COM 			putparam(param, value);
83*9781SMoriah.Waterland@Sun.COM 		free(value);
84*9781SMoriah.Waterland@Sun.COM 		param[0] = '\0';
85*9781SMoriah.Waterland@Sun.COM 	}
86*9781SMoriah.Waterland@Sun.COM 	(void) fclose(fp);
87*9781SMoriah.Waterland@Sun.COM 	/*
88*9781SMoriah.Waterland@Sun.COM 	 * verify that required parameters are now present in
89*9781SMoriah.Waterland@Sun.COM 	 * the environment
90*9781SMoriah.Waterland@Sun.COM 	 */
91*9781SMoriah.Waterland@Sun.COM 	if ((pkgabrv = getenv("PKG")) == NULL) {
92*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOPARAM), "PKG", path);
93*9781SMoriah.Waterland@Sun.COM 		errflg++;
94*9781SMoriah.Waterland@Sun.COM 	}
95*9781SMoriah.Waterland@Sun.COM 	if (pkgnmchk(pkgabrv, NULL, 0) || strchr(pkgabrv, '.')) {
96*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PKGBAD), pkgabrv);
97*9781SMoriah.Waterland@Sun.COM 		errflg++;
98*9781SMoriah.Waterland@Sun.COM 	}
99*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(pkgwild, sizeof (pkgwild), "%s.*", pkgabrv);
100*9781SMoriah.Waterland@Sun.COM 	if ((pkgname = getenv("NAME")) == NULL) {
101*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOPARAM), "NAME", path);
102*9781SMoriah.Waterland@Sun.COM 		errflg++;
103*9781SMoriah.Waterland@Sun.COM 	}
104*9781SMoriah.Waterland@Sun.COM 	if ((pkgarch = getenv("ARCH")) == NULL) {
105*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOPARAM), "ARCH", path);
106*9781SMoriah.Waterland@Sun.COM 		errflg++;
107*9781SMoriah.Waterland@Sun.COM 	}
108*9781SMoriah.Waterland@Sun.COM 	if ((pkgvers = getenv("VERSION")) == NULL) {
109*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOPARAM), "VERSION", path);
110*9781SMoriah.Waterland@Sun.COM 		errflg++;
111*9781SMoriah.Waterland@Sun.COM 	}
112*9781SMoriah.Waterland@Sun.COM 	if (getenv("CATEGORY") == NULL) {
113*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_NOPARAM), "CATEGORY", path);
114*9781SMoriah.Waterland@Sun.COM 		errflg++;
115*9781SMoriah.Waterland@Sun.COM 	}
116*9781SMoriah.Waterland@Sun.COM 	/*
117*9781SMoriah.Waterland@Sun.COM 	 * verify consistency between PKG parameter and pkginst that
118*9781SMoriah.Waterland@Sun.COM 	 * was determined from the directory structure
119*9781SMoriah.Waterland@Sun.COM 	 */
120*9781SMoriah.Waterland@Sun.COM 	(void) snprintf(param, sizeof (param), "%s.*", pkgabrv);
121*9781SMoriah.Waterland@Sun.COM 	if (pkgnmchk(pkginst, param, 0)) {
122*9781SMoriah.Waterland@Sun.COM 		progerr(gettext(ERR_PKGMTCH), pkgabrv, pkginst);
123*9781SMoriah.Waterland@Sun.COM 		errflg++;
124*9781SMoriah.Waterland@Sun.COM 	}
125*9781SMoriah.Waterland@Sun.COM 	return (errflg);
126*9781SMoriah.Waterland@Sun.COM }
127