xref: /illumos-gate/usr/src/lib/libsasl/lib/config.c (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
6*7c478bd9Sstevel@tonic-gate 
7*7c478bd9Sstevel@tonic-gate /* SASL Config file API
8*7c478bd9Sstevel@tonic-gate  * Rob Siemborski
9*7c478bd9Sstevel@tonic-gate  * Tim Martin (originally in Cyrus distribution)
10*7c478bd9Sstevel@tonic-gate  * $Id: config.c,v 1.13 2003/02/13 19:55:54 rjs3 Exp $
11*7c478bd9Sstevel@tonic-gate  */
12*7c478bd9Sstevel@tonic-gate /*
13*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2003 Carnegie Mellon University.  All rights reserved.
14*7c478bd9Sstevel@tonic-gate  *
15*7c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms, with or without
16*7c478bd9Sstevel@tonic-gate  * modification, are permitted provided that the following conditions
17*7c478bd9Sstevel@tonic-gate  * are met:
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * 1. Redistributions of source code must retain the above copyright
20*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer.
21*7c478bd9Sstevel@tonic-gate  *
22*7c478bd9Sstevel@tonic-gate  * 2. Redistributions in binary form must reproduce the above copyright
23*7c478bd9Sstevel@tonic-gate  *    notice, this list of conditions and the following disclaimer in
24*7c478bd9Sstevel@tonic-gate  *    the documentation and/or other materials provided with the
25*7c478bd9Sstevel@tonic-gate  *    distribution.
26*7c478bd9Sstevel@tonic-gate  *
27*7c478bd9Sstevel@tonic-gate  * 3. The name "Carnegie Mellon University" must not be used to
28*7c478bd9Sstevel@tonic-gate  *    endorse or promote products derived from this software without
29*7c478bd9Sstevel@tonic-gate  *    prior written permission. For permission or any other legal
30*7c478bd9Sstevel@tonic-gate  *    details, please contact
31*7c478bd9Sstevel@tonic-gate  *      Office of Technology Transfer
32*7c478bd9Sstevel@tonic-gate  *      Carnegie Mellon University
33*7c478bd9Sstevel@tonic-gate  *      5000 Forbes Avenue
34*7c478bd9Sstevel@tonic-gate  *      Pittsburgh, PA  15213-3890
35*7c478bd9Sstevel@tonic-gate  *      (412) 268-4387, fax: (412) 268-7395
36*7c478bd9Sstevel@tonic-gate  *      tech-transfer@andrew.cmu.edu
37*7c478bd9Sstevel@tonic-gate  *
38*7c478bd9Sstevel@tonic-gate  * 4. Redistributions of any form whatsoever must retain the following
39*7c478bd9Sstevel@tonic-gate  *    acknowledgment:
40*7c478bd9Sstevel@tonic-gate  *    "This product includes software developed by Computing Services
41*7c478bd9Sstevel@tonic-gate  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
42*7c478bd9Sstevel@tonic-gate  *
43*7c478bd9Sstevel@tonic-gate  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
44*7c478bd9Sstevel@tonic-gate  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
45*7c478bd9Sstevel@tonic-gate  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
46*7c478bd9Sstevel@tonic-gate  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
47*7c478bd9Sstevel@tonic-gate  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
48*7c478bd9Sstevel@tonic-gate  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
49*7c478bd9Sstevel@tonic-gate  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
50*7c478bd9Sstevel@tonic-gate  */
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate /*
53*7c478bd9Sstevel@tonic-gate  * Current Valid keys:
54*7c478bd9Sstevel@tonic-gate  *
55*7c478bd9Sstevel@tonic-gate  * canon_user_plugin: <string>
56*7c478bd9Sstevel@tonic-gate  * pwcheck_method: <string>
57*7c478bd9Sstevel@tonic-gate  * auto_transition: <boolean>
58*7c478bd9Sstevel@tonic-gate  * plugin_list: <string>
59*7c478bd9Sstevel@tonic-gate  *
60*7c478bd9Sstevel@tonic-gate  * srvtab: <string>
61*7c478bd9Sstevel@tonic-gate  */
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #include "sasl.h"
65*7c478bd9Sstevel@tonic-gate #include "saslint.h"
66*7c478bd9Sstevel@tonic-gate 
67*7c478bd9Sstevel@tonic-gate #include <stdio.h>
68*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
69*7c478bd9Sstevel@tonic-gate #include <ctype.h>
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #include "config.h"	/* _SUN_SDK_ */
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate struct configlist {
74*7c478bd9Sstevel@tonic-gate     char *key;
75*7c478bd9Sstevel@tonic-gate     char *value;
76*7c478bd9Sstevel@tonic-gate };
77*7c478bd9Sstevel@tonic-gate 
78*7c478bd9Sstevel@tonic-gate #ifndef _SUN_SDK_
79*7c478bd9Sstevel@tonic-gate static struct configlist *configlist;
80*7c478bd9Sstevel@tonic-gate static int nconfiglist;
81*7c478bd9Sstevel@tonic-gate #endif /* !_SUN_SDK_ */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate #define CONFIGLISTGROWSIZE 100
84*7c478bd9Sstevel@tonic-gate 
85*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
86*7c478bd9Sstevel@tonic-gate int sasl_config_init(_sasl_global_context_t *gctx, const char *filename)
87*7c478bd9Sstevel@tonic-gate #else
88*7c478bd9Sstevel@tonic-gate int sasl_config_init(const char *filename)
89*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
90*7c478bd9Sstevel@tonic-gate {
91*7c478bd9Sstevel@tonic-gate     FILE *infile;
92*7c478bd9Sstevel@tonic-gate     int lineno = 0;
93*7c478bd9Sstevel@tonic-gate     int alloced = 0;
94*7c478bd9Sstevel@tonic-gate     char buf[4096];
95*7c478bd9Sstevel@tonic-gate     char *p, *key;
96*7c478bd9Sstevel@tonic-gate     int result;
97*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
98*7c478bd9Sstevel@tonic-gate     int invalid_line = 0;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate     gctx->nconfiglist=0;
101*7c478bd9Sstevel@tonic-gate #else
102*7c478bd9Sstevel@tonic-gate     nconfiglist=0;
103*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate     infile = fopen(filename, "r");
106*7c478bd9Sstevel@tonic-gate     if (!infile) {
107*7c478bd9Sstevel@tonic-gate       return SASL_CONTINUE;
108*7c478bd9Sstevel@tonic-gate     }
109*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
110*7c478bd9Sstevel@tonic-gate     result = _sasl_strdup(filename, &gctx->config_path, NULL);
111*7c478bd9Sstevel@tonic-gate     if (result != SASL_OK)
112*7c478bd9Sstevel@tonic-gate 	goto done;
113*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate     while (fgets(buf, sizeof(buf), infile)) {
116*7c478bd9Sstevel@tonic-gate 	lineno++;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 	if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
119*7c478bd9Sstevel@tonic-gate 	for (p = buf; *p && isspace((int) *p); p++);
120*7c478bd9Sstevel@tonic-gate 	if (!*p || *p == '#') continue;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate 	key = p;
123*7c478bd9Sstevel@tonic-gate 	while (*p && (isalnum((int) *p) || *p == '-' || *p == '_')) {
124*7c478bd9Sstevel@tonic-gate 	    if (isupper((int) *p)) *p = tolower(*p);
125*7c478bd9Sstevel@tonic-gate 	    p++;
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 	if (*p != ':') {
128*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
129*7c478bd9Sstevel@tonic-gate 	  invalid_line = 1;
130*7c478bd9Sstevel@tonic-gate 	  goto done;
131*7c478bd9Sstevel@tonic-gate #else
132*7c478bd9Sstevel@tonic-gate 	  return SASL_FAIL;
133*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 	*p++ = '\0';
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	while (*p && isspace((int) *p)) p++;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 	if (!*p) {
140*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
141*7c478bd9Sstevel@tonic-gate 	  invalid_line = 1;
142*7c478bd9Sstevel@tonic-gate 	  goto done;
143*7c478bd9Sstevel@tonic-gate #else
144*7c478bd9Sstevel@tonic-gate 	  return SASL_FAIL;
145*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
146*7c478bd9Sstevel@tonic-gate 	}
147*7c478bd9Sstevel@tonic-gate 
148*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
149*7c478bd9Sstevel@tonic-gate 	if (gctx->nconfiglist == alloced) {
150*7c478bd9Sstevel@tonic-gate #else
151*7c478bd9Sstevel@tonic-gate 	if (nconfiglist == alloced) {
152*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
153*7c478bd9Sstevel@tonic-gate 	    alloced += CONFIGLISTGROWSIZE;
154*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
155*7c478bd9Sstevel@tonic-gate 	    gctx->configlist=sasl_REALLOC((char *)gctx->configlist,
156*7c478bd9Sstevel@tonic-gate 				    alloced * sizeof(struct configlist));
157*7c478bd9Sstevel@tonic-gate 	    if (gctx->configlist==NULL) {
158*7c478bd9Sstevel@tonic-gate 		result = SASL_NOMEM;
159*7c478bd9Sstevel@tonic-gate 		goto done;
160*7c478bd9Sstevel@tonic-gate 	    }
161*7c478bd9Sstevel@tonic-gate #else
162*7c478bd9Sstevel@tonic-gate 	    configlist=sasl_REALLOC((char *)configlist,
163*7c478bd9Sstevel@tonic-gate 				    alloced * sizeof(struct configlist));
164*7c478bd9Sstevel@tonic-gate 	    if (configlist==NULL) return SASL_NOMEM;
165*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
166*7c478bd9Sstevel@tonic-gate 	}
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
171*7c478bd9Sstevel@tonic-gate 	result = _sasl_strdup(key,
172*7c478bd9Sstevel@tonic-gate 			      &(((struct configlist *)(gctx->configlist))
173*7c478bd9Sstevel@tonic-gate 				[gctx->nconfiglist].key),
174*7c478bd9Sstevel@tonic-gate 			      NULL);
175*7c478bd9Sstevel@tonic-gate 	if (result!=SASL_OK)
176*7c478bd9Sstevel@tonic-gate 	  goto done;
177*7c478bd9Sstevel@tonic-gate #else
178*7c478bd9Sstevel@tonic-gate 	result = _sasl_strdup(key,
179*7c478bd9Sstevel@tonic-gate 			      &(configlist[nconfiglist].key),
180*7c478bd9Sstevel@tonic-gate 			      NULL);
181*7c478bd9Sstevel@tonic-gate 	if (result!=SASL_OK) return result;
182*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
183*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
184*7c478bd9Sstevel@tonic-gate 	result = _sasl_strdup(p,
185*7c478bd9Sstevel@tonic-gate 			      &(((struct configlist *)(gctx->configlist))
186*7c478bd9Sstevel@tonic-gate 				[gctx->nconfiglist].value),
187*7c478bd9Sstevel@tonic-gate 			      NULL);
188*7c478bd9Sstevel@tonic-gate 	if (result!=SASL_OK) {
189*7c478bd9Sstevel@tonic-gate 	    sasl_FREE(((struct configlist *)(gctx->configlist))
190*7c478bd9Sstevel@tonic-gate 				[gctx->nconfiglist].key);
191*7c478bd9Sstevel@tonic-gate 	    goto done;
192*7c478bd9Sstevel@tonic-gate 	}
193*7c478bd9Sstevel@tonic-gate #else
194*7c478bd9Sstevel@tonic-gate 	result = _sasl_strdup(p,
195*7c478bd9Sstevel@tonic-gate 			      &(configlist[nconfiglist].value),
196*7c478bd9Sstevel@tonic-gate 			      NULL);
197*7c478bd9Sstevel@tonic-gate 	if (result!=SASL_OK) return result;
198*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
201*7c478bd9Sstevel@tonic-gate 	(gctx->nconfiglist)++;
202*7c478bd9Sstevel@tonic-gate #else
203*7c478bd9Sstevel@tonic-gate 	nconfiglist++;
204*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
205*7c478bd9Sstevel@tonic-gate     }
206*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
207*7c478bd9Sstevel@tonic-gate     result = SASL_OK;
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate done:
210*7c478bd9Sstevel@tonic-gate     fclose(infile);
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate     if (invalid_line) {
213*7c478bd9Sstevel@tonic-gate 	__sasl_log(gctx, gctx->server_global_callbacks.callbacks,
214*7c478bd9Sstevel@tonic-gate 		   SASL_LOG_ERR, "%s: bad config line: '%s'", filename, buf);
215*7c478bd9Sstevel@tonic-gate 	result = SASL_FAIL;
216*7c478bd9Sstevel@tonic-gate     }
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate     return result;
219*7c478bd9Sstevel@tonic-gate #else
220*7c478bd9Sstevel@tonic-gate     fclose(infile);
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate     return SASL_OK;
223*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
224*7c478bd9Sstevel@tonic-gate }
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
227*7c478bd9Sstevel@tonic-gate /* Releases the resources acquired in sasl_config_init() */
228*7c478bd9Sstevel@tonic-gate void sasl_config_free(_sasl_global_context_t *gctx)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate     int i;
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate     if (gctx->config_path != NULL)
233*7c478bd9Sstevel@tonic-gate 	sasl_FREE(gctx->config_path);
234*7c478bd9Sstevel@tonic-gate     gctx->config_path = NULL;
235*7c478bd9Sstevel@tonic-gate     if (gctx->configlist == NULL)
236*7c478bd9Sstevel@tonic-gate 	return;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate     for (i = 0; i < gctx->nconfiglist; i++) {
239*7c478bd9Sstevel@tonic-gate 	if ((((struct configlist *)gctx->configlist))[i].key)
240*7c478bd9Sstevel@tonic-gate 	    sasl_FREE(((struct configlist *)gctx->configlist)[i].key);
241*7c478bd9Sstevel@tonic-gate 	if (((struct configlist *)gctx->configlist)[i].value)
242*7c478bd9Sstevel@tonic-gate 	    sasl_FREE(((struct configlist *)gctx->configlist)[i].value);
243*7c478bd9Sstevel@tonic-gate     }
244*7c478bd9Sstevel@tonic-gate     sasl_FREE(gctx->configlist);
245*7c478bd9Sstevel@tonic-gate     gctx->configlist = NULL;
246*7c478bd9Sstevel@tonic-gate     gctx->nconfiglist = 0;
247*7c478bd9Sstevel@tonic-gate }
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate const char *sasl_config_getstring(_sasl_global_context_t *gctx,
250*7c478bd9Sstevel@tonic-gate 	const char *key, const char *def)
251*7c478bd9Sstevel@tonic-gate {
252*7c478bd9Sstevel@tonic-gate     int opt;
253*7c478bd9Sstevel@tonic-gate     struct configlist *clist = (struct configlist *)gctx->configlist;
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate     for (opt = 0; opt < gctx->nconfiglist; opt++) {
256*7c478bd9Sstevel@tonic-gate 	if (*key == clist[opt].key[0] &&
257*7c478bd9Sstevel@tonic-gate 	    !strcmp(key, clist[opt].key))
258*7c478bd9Sstevel@tonic-gate 	  return clist[opt].value;
259*7c478bd9Sstevel@tonic-gate     }
260*7c478bd9Sstevel@tonic-gate     return def;
261*7c478bd9Sstevel@tonic-gate }
262*7c478bd9Sstevel@tonic-gate #else
263*7c478bd9Sstevel@tonic-gate const char *sasl_config_getstring(const char *key,const char *def)
264*7c478bd9Sstevel@tonic-gate {
265*7c478bd9Sstevel@tonic-gate     int opt;
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate     for (opt = 0; opt < nconfiglist; opt++) {
268*7c478bd9Sstevel@tonic-gate 	if (*key == configlist[opt].key[0] &&
269*7c478bd9Sstevel@tonic-gate 	    !strcmp(key, configlist[opt].key))
270*7c478bd9Sstevel@tonic-gate 	  return configlist[opt].value;
271*7c478bd9Sstevel@tonic-gate     }
272*7c478bd9Sstevel@tonic-gate     return def;
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
277*7c478bd9Sstevel@tonic-gate int sasl_config_getint(_sasl_global_context_t *gctx, const char *key,int def)
278*7c478bd9Sstevel@tonic-gate #else
279*7c478bd9Sstevel@tonic-gate int sasl_config_getint(const char *key,int def)
280*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
281*7c478bd9Sstevel@tonic-gate {
282*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
283*7c478bd9Sstevel@tonic-gate     const char *val = sasl_config_getstring(gctx, key, (char *)0);
284*7c478bd9Sstevel@tonic-gate #else
285*7c478bd9Sstevel@tonic-gate     const char *val = sasl_config_getstring(key, (char *)0);
286*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
287*7c478bd9Sstevel@tonic-gate 
288*7c478bd9Sstevel@tonic-gate     if (!val) return def;
289*7c478bd9Sstevel@tonic-gate     if (!isdigit((int) *val) && (*val != '-' || !isdigit((int) val[1]))) return def;
290*7c478bd9Sstevel@tonic-gate     return atoi(val);
291*7c478bd9Sstevel@tonic-gate }
292*7c478bd9Sstevel@tonic-gate 
293*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
294*7c478bd9Sstevel@tonic-gate int sasl_config_getswitch(_sasl_global_context_t *gctx,const char *key,int def)
295*7c478bd9Sstevel@tonic-gate #else
296*7c478bd9Sstevel@tonic-gate int sasl_config_getswitch(const char *key,int def)
297*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
298*7c478bd9Sstevel@tonic-gate {
299*7c478bd9Sstevel@tonic-gate #ifdef _SUN_SDK_
300*7c478bd9Sstevel@tonic-gate     const char *val = sasl_config_getstring(gctx, key, (char *)0);
301*7c478bd9Sstevel@tonic-gate #else
302*7c478bd9Sstevel@tonic-gate     const char *val = sasl_config_getstring(key, (char *)0);
303*7c478bd9Sstevel@tonic-gate #endif /* _SUN_SDK_ */
304*7c478bd9Sstevel@tonic-gate 
305*7c478bd9Sstevel@tonic-gate     if (!val) return def;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate     if (*val == '0' || *val == 'n' ||
308*7c478bd9Sstevel@tonic-gate 	(*val == 'o' && val[1] == 'f') || *val == 'f') {
309*7c478bd9Sstevel@tonic-gate 	return 0;
310*7c478bd9Sstevel@tonic-gate     }
311*7c478bd9Sstevel@tonic-gate     else if (*val == '1' || *val == 'y' ||
312*7c478bd9Sstevel@tonic-gate 	     (*val == 'o' && val[1] == 'n') || *val == 't') {
313*7c478bd9Sstevel@tonic-gate 	return 1;
314*7c478bd9Sstevel@tonic-gate     }
315*7c478bd9Sstevel@tonic-gate     return def;
316*7c478bd9Sstevel@tonic-gate }
317*7c478bd9Sstevel@tonic-gate 
318