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 <string.h>
36*5c51f124SMoriah Waterland #include <errno.h>
37*5c51f124SMoriah Waterland #include <pkglocs.h>
38*5c51f124SMoriah Waterland #include <locale.h>
39*5c51f124SMoriah Waterland #include <libintl.h>
40*5c51f124SMoriah Waterland #include <pkglib.h>
41*5c51f124SMoriah Waterland #include <pkgerr.h>
42*5c51f124SMoriah Waterland #include <pkgweb.h>
43*5c51f124SMoriah Waterland #include <install.h>
44*5c51f124SMoriah Waterland #include <libinst.h>
45*5c51f124SMoriah Waterland #include <libadm.h>
46*5c51f124SMoriah Waterland #include <messages.h>
47*5c51f124SMoriah Waterland
48*5c51f124SMoriah Waterland #define DEFMAIL "root"
49*5c51f124SMoriah Waterland
50*5c51f124SMoriah Waterland extern struct admin adm; /* holds info about install admin */
51*5c51f124SMoriah Waterland extern int warnflag; /* != 0 non-fatal error occurred 2 */
52*5c51f124SMoriah Waterland
53*5c51f124SMoriah Waterland static struct {
54*5c51f124SMoriah Waterland char **memloc;
55*5c51f124SMoriah Waterland char *tag;
56*5c51f124SMoriah Waterland } admlist[] = {
57*5c51f124SMoriah Waterland &adm.action, "action",
58*5c51f124SMoriah Waterland &adm.authentication, "authentication",
59*5c51f124SMoriah Waterland &adm.basedir, "basedir",
60*5c51f124SMoriah Waterland &adm.conflict, "conflict",
61*5c51f124SMoriah Waterland &adm.idepend, "idepend",
62*5c51f124SMoriah Waterland &adm.instance, "instance",
63*5c51f124SMoriah Waterland &adm.keystore, "keystore",
64*5c51f124SMoriah Waterland &adm.mail, "mail",
65*5c51f124SMoriah Waterland &adm.networkretries, "networkretries",
66*5c51f124SMoriah Waterland &adm.networktimeout, "networktimeout",
67*5c51f124SMoriah Waterland &adm.partial, "partial",
68*5c51f124SMoriah Waterland &adm.proxy, "proxy",
69*5c51f124SMoriah Waterland &adm.rdepend, "rdepend",
70*5c51f124SMoriah Waterland &adm.RSCRIPTALT, RSCRIPTALT_KEYWORD,
71*5c51f124SMoriah Waterland &adm.runlevel, "runlevel",
72*5c51f124SMoriah Waterland &adm.setuid, "setuid",
73*5c51f124SMoriah Waterland &adm.space, "space",
74*5c51f124SMoriah Waterland /* MUST BE LAST ENTRY IN LIST */
75*5c51f124SMoriah Waterland (char **)NULL, (char *)NULL
76*5c51f124SMoriah Waterland };
77*5c51f124SMoriah Waterland
78*5c51f124SMoriah Waterland /*
79*5c51f124SMoriah Waterland * Name: setadminSetting
80*5c51f124SMoriah Waterland * Description: set one administration parameter setting
81*5c51f124SMoriah Waterland * Arguments: a_paramName - pointer to string representing the name of
82*5c51f124SMoriah Waterland * the administration parameter to set
83*5c51f124SMoriah Waterland * a_paramValue - pointer to string representing the value
84*5c51f124SMoriah Waterland * to set the specified administration parameter to
85*5c51f124SMoriah Waterland * Returns: char *
86*5c51f124SMoriah Waterland * - old value the parameter had before being set
87*5c51f124SMoriah Waterland * == NULL - the old paramter was not set
88*5c51f124SMoriah Waterland */
89*5c51f124SMoriah Waterland
90*5c51f124SMoriah Waterland char *
setadminSetting(char * a_paramName,char * a_paramValue)91*5c51f124SMoriah Waterland setadminSetting(char *a_paramName, char *a_paramValue)
92*5c51f124SMoriah Waterland {
93*5c51f124SMoriah Waterland char *oldValue = (char *)NULL;
94*5c51f124SMoriah Waterland int i;
95*5c51f124SMoriah Waterland
96*5c51f124SMoriah Waterland /* locate and update the specified admin setting */
97*5c51f124SMoriah Waterland
98*5c51f124SMoriah Waterland for (i = 0; admlist[i].memloc; i++) {
99*5c51f124SMoriah Waterland if (strcmp(a_paramName, admlist[i].tag) == 0) {
100*5c51f124SMoriah Waterland oldValue = *admlist[i].memloc;
101*5c51f124SMoriah Waterland *admlist[i].memloc = a_paramValue;
102*5c51f124SMoriah Waterland break;
103*5c51f124SMoriah Waterland }
104*5c51f124SMoriah Waterland }
105*5c51f124SMoriah Waterland
106*5c51f124SMoriah Waterland if (admlist[i].memloc == (char **)NULL) {
107*5c51f124SMoriah Waterland logerr(WRN_UNKNOWN_ADM_PARAM, a_paramName);
108*5c51f124SMoriah Waterland }
109*5c51f124SMoriah Waterland
110*5c51f124SMoriah Waterland return (oldValue);
111*5c51f124SMoriah Waterland }
112*5c51f124SMoriah Waterland
113*5c51f124SMoriah Waterland /*
114*5c51f124SMoriah Waterland * Name: setadminFile
115*5c51f124SMoriah Waterland * Description: read and remember settings from administration file
116*5c51f124SMoriah Waterland * Arguments: file - pointer to string representing the path to the
117*5c51f124SMoriah Waterland * administration file to read - if this is NULL
118*5c51f124SMoriah Waterland * then the name "default" is used - if this is
119*5c51f124SMoriah Waterland * the string "none" then the admin "basedir"
120*5c51f124SMoriah Waterland * setting is set to "ask" so that the location
121*5c51f124SMoriah Waterland * of the administration file will be interactively
122*5c51f124SMoriah Waterland * asked at the appropriate time
123*5c51f124SMoriah Waterland * Returns: void
124*5c51f124SMoriah Waterland */
125*5c51f124SMoriah Waterland
126*5c51f124SMoriah Waterland void
setadminFile(char * file)127*5c51f124SMoriah Waterland setadminFile(char *file)
128*5c51f124SMoriah Waterland {
129*5c51f124SMoriah Waterland FILE *fp;
130*5c51f124SMoriah Waterland int i;
131*5c51f124SMoriah Waterland char param[MAX_PKG_PARAM_LENGTH];
132*5c51f124SMoriah Waterland char *value;
133*5c51f124SMoriah Waterland char path[PATH_MAX];
134*5c51f124SMoriah Waterland int mail = 0;
135*5c51f124SMoriah Waterland
136*5c51f124SMoriah Waterland if (file == NULL)
137*5c51f124SMoriah Waterland file = "default";
138*5c51f124SMoriah Waterland else if (strcmp(file, "none") == 0) {
139*5c51f124SMoriah Waterland adm.basedir = "ask";
140*5c51f124SMoriah Waterland return;
141*5c51f124SMoriah Waterland }
142*5c51f124SMoriah Waterland
143*5c51f124SMoriah Waterland if (file[0] == '/')
144*5c51f124SMoriah Waterland (void) strcpy(path, file);
145*5c51f124SMoriah Waterland else {
146*5c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), "%s/admin/%s",
147*5c51f124SMoriah Waterland get_PKGADM(), file);
148*5c51f124SMoriah Waterland if (access(path, R_OK)) {
149*5c51f124SMoriah Waterland (void) snprintf(path, sizeof (path), "%s/admin/%s",
150*5c51f124SMoriah Waterland PKGADM, file);
151*5c51f124SMoriah Waterland }
152*5c51f124SMoriah Waterland }
153*5c51f124SMoriah Waterland
154*5c51f124SMoriah Waterland if ((fp = fopen(path, "r")) == NULL) {
155*5c51f124SMoriah Waterland progerr(ERR_OPEN_ADMIN_FILE, file, strerror(errno));
156*5c51f124SMoriah Waterland quit(99);
157*5c51f124SMoriah Waterland }
158*5c51f124SMoriah Waterland
159*5c51f124SMoriah Waterland param[0] = '\0';
160*5c51f124SMoriah Waterland while (value = fpkgparam(fp, param)) {
161*5c51f124SMoriah Waterland if (strcmp(param, "mail") == 0) {
162*5c51f124SMoriah Waterland mail = 1;
163*5c51f124SMoriah Waterland }
164*5c51f124SMoriah Waterland if (value[0] == '\0') {
165*5c51f124SMoriah Waterland param[0] = '\0';
166*5c51f124SMoriah Waterland continue; /* same as not being set at all */
167*5c51f124SMoriah Waterland }
168*5c51f124SMoriah Waterland for (i = 0; admlist[i].memloc; i++) {
169*5c51f124SMoriah Waterland if (strcmp(param, admlist[i].tag) == 0) {
170*5c51f124SMoriah Waterland *admlist[i].memloc = value;
171*5c51f124SMoriah Waterland break;
172*5c51f124SMoriah Waterland }
173*5c51f124SMoriah Waterland }
174*5c51f124SMoriah Waterland if (admlist[i].memloc == NULL) {
175*5c51f124SMoriah Waterland logerr(WRN_UNKNOWN_ADM_PARAM, param);
176*5c51f124SMoriah Waterland free(value);
177*5c51f124SMoriah Waterland }
178*5c51f124SMoriah Waterland param[0] = '\0';
179*5c51f124SMoriah Waterland }
180*5c51f124SMoriah Waterland
181*5c51f124SMoriah Waterland (void) fclose(fp);
182*5c51f124SMoriah Waterland
183*5c51f124SMoriah Waterland if (!mail) {
184*5c51f124SMoriah Waterland adm.mail = DEFMAIL; /* if we don't assign anything to it */
185*5c51f124SMoriah Waterland }
186*5c51f124SMoriah Waterland }
187*5c51f124SMoriah Waterland
188*5c51f124SMoriah Waterland
189*5c51f124SMoriah Waterland /*
190*5c51f124SMoriah Waterland * Function: web_ck_retries
191*5c51f124SMoriah Waterland * Description: Reads admin file setting for networkretries, or uses default
192*5c51f124SMoriah Waterland * Parameters: None
193*5c51f124SMoriah Waterland * Returns: admin file setting for networkretries, or the default if no
194*5c51f124SMoriah Waterland * admin file setting exists or if it is outside the
195*5c51f124SMoriah Waterland * allowable range.
196*5c51f124SMoriah Waterland */
197*5c51f124SMoriah Waterland int
web_ck_retries(void)198*5c51f124SMoriah Waterland web_ck_retries(void)
199*5c51f124SMoriah Waterland {
200*5c51f124SMoriah Waterland int retries = NET_RETRIES_DEFAULT;
201*5c51f124SMoriah Waterland
202*5c51f124SMoriah Waterland if (ADMSET(networkretries)) {
203*5c51f124SMoriah Waterland /* Make sure value is within valid range */
204*5c51f124SMoriah Waterland if ((retries = atoi(adm.networkretries)) == 0) {
205*5c51f124SMoriah Waterland return (NET_RETRIES_DEFAULT);
206*5c51f124SMoriah Waterland } else if (retries <= NET_RETRIES_MIN ||
207*5c51f124SMoriah Waterland retries > NET_RETRIES_MAX) {
208*5c51f124SMoriah Waterland return (NET_RETRIES_DEFAULT);
209*5c51f124SMoriah Waterland }
210*5c51f124SMoriah Waterland }
211*5c51f124SMoriah Waterland return (retries);
212*5c51f124SMoriah Waterland }
213*5c51f124SMoriah Waterland
214*5c51f124SMoriah Waterland /*
215*5c51f124SMoriah Waterland * Function: web_ck_authentication
216*5c51f124SMoriah Waterland * Description: Retrieves admin file setting for authentication
217*5c51f124SMoriah Waterland * Parameters: None
218*5c51f124SMoriah Waterland * Returns: admin file policy for authentication - AUTH_QUIT
219*5c51f124SMoriah Waterland * or AUTH_NOCHECK.
220*5c51f124SMoriah Waterland * non-zero failure
221*5c51f124SMoriah Waterland */
222*5c51f124SMoriah Waterland int
web_ck_authentication(void)223*5c51f124SMoriah Waterland web_ck_authentication(void)
224*5c51f124SMoriah Waterland {
225*5c51f124SMoriah Waterland if (ADM(authentication, "nocheck"))
226*5c51f124SMoriah Waterland return (AUTH_NOCHECK);
227*5c51f124SMoriah Waterland
228*5c51f124SMoriah Waterland return (AUTH_QUIT);
229*5c51f124SMoriah Waterland }
230*5c51f124SMoriah Waterland
231*5c51f124SMoriah Waterland /*
232*5c51f124SMoriah Waterland * Function: web_ck_timeout
233*5c51f124SMoriah Waterland * Description: Retrieves admin file policy for networktimeout's
234*5c51f124SMoriah Waterland * Parameters: NONE
235*5c51f124SMoriah Waterland * Returns: Admin file setting for networktimeout, or default
236*5c51f124SMoriah Waterland * timeout value if admin file does not specify one,
237*5c51f124SMoriah Waterland * or specifies one that is out of the allowable range.
238*5c51f124SMoriah Waterland */
239*5c51f124SMoriah Waterland int
web_ck_timeout(void)240*5c51f124SMoriah Waterland web_ck_timeout(void)
241*5c51f124SMoriah Waterland {
242*5c51f124SMoriah Waterland int timeout = NET_TIMEOUT_DEFAULT;
243*5c51f124SMoriah Waterland
244*5c51f124SMoriah Waterland if (ADMSET(networktimeout)) {
245*5c51f124SMoriah Waterland /* Make sure value is within valid range */
246*5c51f124SMoriah Waterland if ((timeout = atoi(adm.networktimeout)) == 0) {
247*5c51f124SMoriah Waterland return (NET_TIMEOUT_DEFAULT);
248*5c51f124SMoriah Waterland } else if (timeout <= NET_TIMEOUT_MIN ||
249*5c51f124SMoriah Waterland timeout > NET_TIMEOUT_MAX) {
250*5c51f124SMoriah Waterland return (NET_TIMEOUT_DEFAULT);
251*5c51f124SMoriah Waterland }
252*5c51f124SMoriah Waterland }
253*5c51f124SMoriah Waterland return (timeout);
254*5c51f124SMoriah Waterland }
255*5c51f124SMoriah Waterland
256*5c51f124SMoriah Waterland /*
257*5c51f124SMoriah Waterland * Function: check_keystore_admin
258*5c51f124SMoriah Waterland * Description: Retrieves security keystore setting from admin file,
259*5c51f124SMoriah Waterland * or validates user-supplied keystore policy.
260*5c51f124SMoriah Waterland * Parameters: keystore - Where to store resulting keystore policy
261*5c51f124SMoriah Waterland * Returns: B_TRUE - admin file contained valid keystore, or
262*5c51f124SMoriah Waterland * user-supplied keystore passed in "keystore" was
263*5c51f124SMoriah Waterland * valid. Resulting keystore stored in "keystore"
264*5c51f124SMoriah Waterland *
265*5c51f124SMoriah Waterland * B_FALSE - No location supplied to store result,
266*5c51f124SMoriah Waterland * or user-supplied keystore was not valid.
267*5c51f124SMoriah Waterland */
268*5c51f124SMoriah Waterland boolean_t
check_keystore_admin(char ** keystore)269*5c51f124SMoriah Waterland check_keystore_admin(char **keystore)
270*5c51f124SMoriah Waterland {
271*5c51f124SMoriah Waterland
272*5c51f124SMoriah Waterland if (!keystore) {
273*5c51f124SMoriah Waterland /* no location to store keystore */
274*5c51f124SMoriah Waterland return (B_FALSE);
275*5c51f124SMoriah Waterland }
276*5c51f124SMoriah Waterland
277*5c51f124SMoriah Waterland if (*keystore != NULL) {
278*5c51f124SMoriah Waterland if (!path_valid(*keystore)) {
279*5c51f124SMoriah Waterland /* the given keystore is invalid */
280*5c51f124SMoriah Waterland return (B_FALSE);
281*5c51f124SMoriah Waterland }
282*5c51f124SMoriah Waterland
283*5c51f124SMoriah Waterland /* the user-supplied keystore was valid */
284*5c51f124SMoriah Waterland return (B_TRUE);
285*5c51f124SMoriah Waterland }
286*5c51f124SMoriah Waterland
287*5c51f124SMoriah Waterland /* no user-supplied, so use default */
288*5c51f124SMoriah Waterland if ((*keystore = set_keystore_admin()) == NULL) {
289*5c51f124SMoriah Waterland *keystore = PKGSEC;
290*5c51f124SMoriah Waterland }
291*5c51f124SMoriah Waterland return (B_TRUE);
292*5c51f124SMoriah Waterland }
293*5c51f124SMoriah Waterland
294*5c51f124SMoriah Waterland /*
295*5c51f124SMoriah Waterland * Function: get_proxy_port_admin
296*5c51f124SMoriah Waterland * Description: Retrieves proxy setting from admin file
297*5c51f124SMoriah Waterland * Parameters: proxy - where to store resulting proxy (host:port or URL)
298*5c51f124SMoriah Waterland * port - Where to store resulting proxy port
299*5c51f124SMoriah Waterland * Returns: B_TRUE - admin file had a valid proxy setting,
300*5c51f124SMoriah Waterland * and it is stored in "proxy".
301*5c51f124SMoriah Waterland * B_FALSE - no proxy setting in admin file, or
302*5c51f124SMoriah Waterland * invalid setting in admin file.
303*5c51f124SMoriah Waterland */
304*5c51f124SMoriah Waterland boolean_t
get_proxy_port_admin(char ** proxy,ushort_t * port)305*5c51f124SMoriah Waterland get_proxy_port_admin(char **proxy, ushort_t *port)
306*5c51f124SMoriah Waterland {
307*5c51f124SMoriah Waterland if (ADMSET(proxy) && !path_valid(adm.proxy)) {
308*5c51f124SMoriah Waterland /* admin file has bad keystore */
309*5c51f124SMoriah Waterland return (B_FALSE);
310*5c51f124SMoriah Waterland } else if (ADMSET(proxy)) {
311*5c51f124SMoriah Waterland *proxy = strdup(adm.proxy);
312*5c51f124SMoriah Waterland *port = strip_port(adm.proxy);
313*5c51f124SMoriah Waterland }
314*5c51f124SMoriah Waterland return (B_TRUE);
315*5c51f124SMoriah Waterland }
316*5c51f124SMoriah Waterland
317*5c51f124SMoriah Waterland /*
318*5c51f124SMoriah Waterland * Function: set_keystore_admin
319*5c51f124SMoriah Waterland * Description: Retrieves security keystore setting from admin file,
320*5c51f124SMoriah Waterland * Parameters: NONE
321*5c51f124SMoriah Waterland * Returns: Keystore file policy from admin file, if set
322*5c51f124SMoriah Waterland * and valid. NULL otherwise.
323*5c51f124SMoriah Waterland */
324*5c51f124SMoriah Waterland char *
set_keystore_admin(void)325*5c51f124SMoriah Waterland set_keystore_admin(void)
326*5c51f124SMoriah Waterland {
327*5c51f124SMoriah Waterland if (ADMSET(keystore) && !path_valid(adm.keystore)) {
328*5c51f124SMoriah Waterland return (NULL);
329*5c51f124SMoriah Waterland }
330*5c51f124SMoriah Waterland
331*5c51f124SMoriah Waterland if (!ADMSET(keystore)) {
332*5c51f124SMoriah Waterland return (NULL);
333*5c51f124SMoriah Waterland }
334*5c51f124SMoriah Waterland
335*5c51f124SMoriah Waterland return (adm.keystore);
336*5c51f124SMoriah Waterland }
337