xref: /titanic_53/usr/src/lib/libnsl/dial/sysfiles.c (revision e8031f0a8ed0e45c6d8847c5e09424e66fd34a4b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
2261961e0fSrobinson 
237c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
247c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
27*e8031f0aSraf  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
327c478bd9Sstevel@tonic-gate 
33*e8031f0aSraf #include "mt.h"
347c478bd9Sstevel@tonic-gate #include "uucp.h"
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <unistd.h>
3761961e0fSrobinson #include <string.h>
387c478bd9Sstevel@tonic-gate #include "sysfiles.h"
397c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * manage systems files (Systems, Devices, and Dialcodes families).
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * also manage new file Devconfig, allows per-device setup.
457c478bd9Sstevel@tonic-gate  * present use is to specify what streams modules to push/pop for
467c478bd9Sstevel@tonic-gate  * AT&T TLI/streams network.
477c478bd9Sstevel@tonic-gate  *
487c478bd9Sstevel@tonic-gate  * TODO:
497c478bd9Sstevel@tonic-gate  *	call bsfix()?
507c478bd9Sstevel@tonic-gate  *	combine the 3 versions of everything (sys, dev, and dial) into one.
517c478bd9Sstevel@tonic-gate  *	allow arbitrary classes of service.
527c478bd9Sstevel@tonic-gate  *	need verifysys() for uucheck.
537c478bd9Sstevel@tonic-gate  *	nameserver interface?
5461961e0fSrobinson  *	pass sysname (or 0) to getsysline().  (might want reg. exp. or
5561961e0fSrobinson  *		NS processing)
567c478bd9Sstevel@tonic-gate  */
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* private variables */
5961961e0fSrobinson static void tokenize(void);
6061961e0fSrobinson static void nameparse(void);
6161961e0fSrobinson static void setfile(char **, char *);
6261961e0fSrobinson static void setioctl(char **, char *);
6361961e0fSrobinson static void scansys(const char *);
6461961e0fSrobinson static void scancfg(char *, char *);
6561961e0fSrobinson static void setconfig(void);
6661961e0fSrobinson static int namematch(const char *label, char *line, const char *name);
6761961e0fSrobinson static int nextdialers(void);
6861961e0fSrobinson static int nextdevices(void);
6961961e0fSrobinson static int nextsystems(void);
7061961e0fSrobinson static int getline(FILE *, char *);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /* pointer arrays might be dynamically allocated */
737c478bd9Sstevel@tonic-gate static char *Systems[64];	/* list of Systems files */
747c478bd9Sstevel@tonic-gate static char *Devices[64];	/* list of Devices files */
757c478bd9Sstevel@tonic-gate static char *Dialers[64];	/* list of Dialers files */
767c478bd9Sstevel@tonic-gate static char *Pops[64];		/* list of STREAMS modules to be popped */
777c478bd9Sstevel@tonic-gate static char *Pushes[64];	/* list of STREAMS modules to be pushed */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static int nsystems;		/* index into list of Systems files */
807c478bd9Sstevel@tonic-gate static int ndevices;		/* index into list of Devices files */
817c478bd9Sstevel@tonic-gate static int ndialers;		/* index into list of Dialers files */
827c478bd9Sstevel@tonic-gate static int npops;		/* index into list of STREAMS modules */
837c478bd9Sstevel@tonic-gate 							/* to be popped */
847c478bd9Sstevel@tonic-gate static int npushes;		/* index into list of STREAMS modules */
857c478bd9Sstevel@tonic-gate 							/* to be pushed */
867c478bd9Sstevel@tonic-gate 
8761961e0fSrobinson static unsigned connecttime, expecttime;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate static FILE *fsystems;
907c478bd9Sstevel@tonic-gate static FILE *fdevices;
917c478bd9Sstevel@tonic-gate static FILE *fdialers;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* this might be dynamically allocated */
947c478bd9Sstevel@tonic-gate #define	NTOKENS 16
957c478bd9Sstevel@tonic-gate static char *tokens[NTOKENS], **tokptr;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /* export these */
9861961e0fSrobinson static void setservice(const char *service);
9961961e0fSrobinson static void sysreset(void);
10061961e0fSrobinson static void devreset(void);
10161961e0fSrobinson static void dialreset(void);
10261961e0fSrobinson static void setdevcfg(char *, char *);
10361961e0fSrobinson static void setservice(const char *);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /* import these */
10661961e0fSrobinson extern char *strsave(const char *);
10761961e0fSrobinson static int eaccess(char *, mode_t);
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * setservice init's Systems, Devices, Dialers lists from Sysfiles
1117c478bd9Sstevel@tonic-gate  */
11261961e0fSrobinson static void
11361961e0fSrobinson setservice(const char *service)
1147c478bd9Sstevel@tonic-gate {
1157c478bd9Sstevel@tonic-gate 	setconfig();
1167c478bd9Sstevel@tonic-gate 	scansys(service);
1177c478bd9Sstevel@tonic-gate }
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * setdevcfg init's Pops, Pushes lists from Devconfig
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate 
12361961e0fSrobinson static void
12461961e0fSrobinson setdevcfg(char *service, char *device)
1257c478bd9Sstevel@tonic-gate {
1267c478bd9Sstevel@tonic-gate 	scancfg(service, device);
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*	administrative files access */
13061961e0fSrobinson static int
13161961e0fSrobinson sysaccess(int type)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	char errformat[BUFSIZ];
1347c478bd9Sstevel@tonic-gate 
13561961e0fSrobinson 	switch (type) {
13661961e0fSrobinson 	case ACCESS_SYSTEMS:
13761961e0fSrobinson 		return (access(Systems[nsystems], R_OK));
13861961e0fSrobinson 	case ACCESS_DEVICES:
13961961e0fSrobinson 		return (access(Devices[ndevices], R_OK));
14061961e0fSrobinson 	case ACCESS_DIALERS:
14161961e0fSrobinson 		return (access(Dialers[ndialers], R_OK));
14261961e0fSrobinson 	case EACCESS_SYSTEMS:
14361961e0fSrobinson 		return (eaccess(Systems[nsystems], R_OK));
14461961e0fSrobinson 	case EACCESS_DEVICES:
14561961e0fSrobinson 		return (eaccess(Devices[ndevices], R_OK));
14661961e0fSrobinson 	case EACCESS_DIALERS:
14761961e0fSrobinson 		return (eaccess(Dialers[ndialers], R_OK));
14861961e0fSrobinson 	}
1497c478bd9Sstevel@tonic-gate 	(void) sprintf(errformat, "bad access type %d", type);
1507c478bd9Sstevel@tonic-gate 	logent(errformat, "sysaccess");
1517c478bd9Sstevel@tonic-gate 	return (FAIL);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * read Sysfiles, set up lists of Systems/Devices/Dialers file names.
1577c478bd9Sstevel@tonic-gate  * allow multiple entries for a given service, allow a service
1587c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., systems=foo:baz systems=bar.
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate static void
16161961e0fSrobinson scansys(const char *service)
1627c478bd9Sstevel@tonic-gate {	FILE *f;
1637c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	Systems[0] = Devices[0] = Dialers[0] = NULL;
1667c478bd9Sstevel@tonic-gate 	if ((f = fopen(SYSFILES, "r")) != 0) {
1677c478bd9Sstevel@tonic-gate 		while (getline(f, buf) > 0) {
1687c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Sysfiles */
1697c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
1707c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
1717c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
1727c478bd9Sstevel@tonic-gate 				tokenize();
1737c478bd9Sstevel@tonic-gate 				nameparse();
1747c478bd9Sstevel@tonic-gate 			}
1757c478bd9Sstevel@tonic-gate 		}
1767c478bd9Sstevel@tonic-gate 		(void) fclose(f);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	/* if didn't find entries in Sysfiles, use defaults */
1807c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL) {
1817c478bd9Sstevel@tonic-gate 		Systems[0] = strsave(SYSTEMS);
18261961e0fSrobinson 		ASSERT(Systems[0] != NULL, "Ct_ALLOCATE", "scansys: Systems",
18361961e0fSrobinson 									0);
1847c478bd9Sstevel@tonic-gate 		Systems[1] = NULL;
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL) {
1877c478bd9Sstevel@tonic-gate 		Devices[0] = strsave(DEVICES);
18861961e0fSrobinson 		ASSERT(Devices[0] != NULL, "Ct_ALLOCATE", "scansys: Devices",
18961961e0fSrobinson 									0);
1907c478bd9Sstevel@tonic-gate 		Devices[1] = NULL;
1917c478bd9Sstevel@tonic-gate 	}
1927c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL) {
1937c478bd9Sstevel@tonic-gate 		Dialers[0] = strsave(DIALERS);
19461961e0fSrobinson 		ASSERT(Dialers[0] != NULL, "Ct_ALLOCATE", "scansys: Dialers",
19561961e0fSrobinson 									0);
1967c478bd9Sstevel@tonic-gate 		Dialers[1] = NULL;
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * read Devconfig.  allow multiple entries for a given service, allow a service
2037c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., push=foo:baz push=bar.
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate static void
20661961e0fSrobinson scancfg(char *service, char *device)
2077c478bd9Sstevel@tonic-gate {	FILE *f;
2087c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	/* (re)initialize device-specific information */
2117c478bd9Sstevel@tonic-gate 	npops = npushes = 0;
2127c478bd9Sstevel@tonic-gate 	Pops[0] = Pushes[0] = NULL;
2137c478bd9Sstevel@tonic-gate 	connecttime = CONNECTTIME;
2147c478bd9Sstevel@tonic-gate 	expecttime = EXPECTTIME;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	if ((f = fopen(DEVCONFIG, "r")) != 0) {
2177c478bd9Sstevel@tonic-gate 		while (getline(f, buf) > 0) {
2187c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Devconfig */
2197c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
2207c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
2217c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
2227c478bd9Sstevel@tonic-gate 				tok = strtok((char *)0, " \t");
2237c478bd9Sstevel@tonic-gate 				if (namematch("device=", tok, device)) {
2247c478bd9Sstevel@tonic-gate 					tokenize();
2257c478bd9Sstevel@tonic-gate 					nameparse();
2267c478bd9Sstevel@tonic-gate 				}
2277c478bd9Sstevel@tonic-gate 			}
2287c478bd9Sstevel@tonic-gate 		}
2297c478bd9Sstevel@tonic-gate 		(void) fclose(f);
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 	return;
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate }
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  *  given a file pointer and buffer, construct logical line in buffer
2377c478bd9Sstevel@tonic-gate  *  (i.e., concatenate lines ending in '\').  return length of line
2387c478bd9Sstevel@tonic-gate  *  ASSUMES that buffer is BUFSIZ long!
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate static int
24261961e0fSrobinson getline(FILE *f, char *line)
2437c478bd9Sstevel@tonic-gate {	char *lptr, *lend;
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate 	lptr = line;
2467c478bd9Sstevel@tonic-gate 	while (fgets(lptr, (line + BUFSIZ) - lptr, f) != NULL) {
2477c478bd9Sstevel@tonic-gate 		lend = lptr + strlen(lptr);
2487c478bd9Sstevel@tonic-gate 		if (lend == lptr || lend[-1] != '\n')
2497c478bd9Sstevel@tonic-gate 			/* empty buf or line too long! */
2507c478bd9Sstevel@tonic-gate 			break;
2517c478bd9Sstevel@tonic-gate 		*--lend = '\0'; /* lop off ending '\n' */
2527c478bd9Sstevel@tonic-gate 		if (lend == line) /* empty line - ignore */
2537c478bd9Sstevel@tonic-gate 			continue;
2547c478bd9Sstevel@tonic-gate 		lptr = lend;
2557c478bd9Sstevel@tonic-gate 		if (lend[-1] != '\\')
2567c478bd9Sstevel@tonic-gate 			break;
2577c478bd9Sstevel@tonic-gate 		/* continuation */
2587c478bd9Sstevel@tonic-gate 		lend[-1] = ' ';
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 	return (lptr - line);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /*
2647c478bd9Sstevel@tonic-gate  * given a label (e.g., "service=", "device="), a name ("cu", "uucico"),
2657c478bd9Sstevel@tonic-gate  *  and a line:  if line begins with the label and if the name appears
2667c478bd9Sstevel@tonic-gate  * in a colon-separated list of names following the label, return true;
2677c478bd9Sstevel@tonic-gate  * else return false
2687c478bd9Sstevel@tonic-gate  */
2697c478bd9Sstevel@tonic-gate static int
27061961e0fSrobinson namematch(const char *label, char *line, const char *name)
27161961e0fSrobinson {
27261961e0fSrobinson 	char *lend;
2737c478bd9Sstevel@tonic-gate 
27461961e0fSrobinson 	if (strncmp(label, line, strlen(label)) != SAME)
2757c478bd9Sstevel@tonic-gate 		return (FALSE);	/* probably a comment line */
2767c478bd9Sstevel@tonic-gate 	line += strlen(label);
27761961e0fSrobinson 	if (*line == '\0')
2787c478bd9Sstevel@tonic-gate 		return (FALSE);
2797c478bd9Sstevel@tonic-gate 	/*
2807c478bd9Sstevel@tonic-gate 	 * can't use strtok() in the following because scansys(),
2817c478bd9Sstevel@tonic-gate 	 * scancfg() do an initializing call to strtok() before
2827c478bd9Sstevel@tonic-gate 	 * coming here and then CONTINUE calling strtok() in tokenize(),
2837c478bd9Sstevel@tonic-gate 	 * after returning from namematch().
2847c478bd9Sstevel@tonic-gate 	 */
2857c478bd9Sstevel@tonic-gate 	while ((lend = strchr(line, ':')) != NULL) {
2867c478bd9Sstevel@tonic-gate 		*lend = '\0';
28761961e0fSrobinson 		if (strcmp(line, name) == SAME)
2887c478bd9Sstevel@tonic-gate 			return (TRUE);
2897c478bd9Sstevel@tonic-gate 		line = lend+1;
2907c478bd9Sstevel@tonic-gate 	}
2917c478bd9Sstevel@tonic-gate 	return (strcmp(line, name) == SAME);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate  * tokenize() continues pulling tokens out of a buffer -- the
2967c478bd9Sstevel@tonic-gate  * initializing call to strtok must have been made before calling
2977c478bd9Sstevel@tonic-gate  * tokenize() -- and starts stuffing 'em into tokptr.
2987c478bd9Sstevel@tonic-gate  */
2997c478bd9Sstevel@tonic-gate static void
30061961e0fSrobinson tokenize(void)
30161961e0fSrobinson {
30261961e0fSrobinson 	char *tok;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	tokptr = tokens;
30561961e0fSrobinson 	while ((tok = strtok(NULL, " \t")) != NULL) {
3067c478bd9Sstevel@tonic-gate 		*tokptr++ = tok;
3077c478bd9Sstevel@tonic-gate 		if (tokptr - tokens >= NTOKENS)
3087c478bd9Sstevel@tonic-gate 			break;
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 	*tokptr = NULL;
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * look at top token in array: should be line of the form
3157c478bd9Sstevel@tonic-gate  *	name=item1:item2:item3...
3167c478bd9Sstevel@tonic-gate  * if name is one we recognize, then call set[file|ioctl] to set up
3177c478bd9Sstevel@tonic-gate  * corresponding list.  otherwise, log bad name.
3187c478bd9Sstevel@tonic-gate  */
3197c478bd9Sstevel@tonic-gate static void
32061961e0fSrobinson nameparse(void)
32161961e0fSrobinson {
32261961e0fSrobinson 	char **line, *equals;
3237c478bd9Sstevel@tonic-gate 	int temp;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate #define	setuint(a, b, c) a = (((temp = atoi(b)) <= 0) ? (c) : temp)
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	for (line = tokens; (line - tokens) < NTOKENS && *line; line++) {
3287c478bd9Sstevel@tonic-gate 		equals = strchr(*line, '=');
3297c478bd9Sstevel@tonic-gate 		if (equals == NULL)
3307c478bd9Sstevel@tonic-gate 			continue;	/* may be meaningful someday? */
3317c478bd9Sstevel@tonic-gate 		*equals = '\0';
3327c478bd9Sstevel@tonic-gate 		/* ignore entry with empty rhs */
3337c478bd9Sstevel@tonic-gate 		if (*++equals == '\0')
3347c478bd9Sstevel@tonic-gate 			continue;
3357c478bd9Sstevel@tonic-gate 		if (strcmp(*line, "systems") == SAME)
3367c478bd9Sstevel@tonic-gate 			setfile(Systems, equals);
3377c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "devices") == SAME)
3387c478bd9Sstevel@tonic-gate 			setfile(Devices, equals);
3397c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "dialers") == SAME)
3407c478bd9Sstevel@tonic-gate 			setfile(Dialers, equals);
3417c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "pop") == SAME)
3427c478bd9Sstevel@tonic-gate 			setioctl(Pops, equals);
3437c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "push") == SAME)
3447c478bd9Sstevel@tonic-gate 			setioctl(Pushes, equals);
3457c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "connecttime") == SAME)
3467c478bd9Sstevel@tonic-gate 			setuint(connecttime, equals, CONNECTTIME);
3477c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "expecttime") == SAME)
3487c478bd9Sstevel@tonic-gate 			setuint(expecttime, equals, EXPECTTIME);
3497c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "msgtime") == SAME)
35061961e0fSrobinson 			continue;
3517c478bd9Sstevel@tonic-gate 		else {
3527c478bd9Sstevel@tonic-gate 			char errformat[BUFSIZ];
3537c478bd9Sstevel@tonic-gate 
35461961e0fSrobinson 			(void) snprintf(errformat, sizeof (errformat),
35561961e0fSrobinson 						"unrecognized label %s", *line);
3567c478bd9Sstevel@tonic-gate 			logent(errformat, "Sysfiles|Devconfig");
3577c478bd9Sstevel@tonic-gate 		}
3587c478bd9Sstevel@tonic-gate 	}
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate  * given the list for a particular type (systems, devices,...)
3637c478bd9Sstevel@tonic-gate  * and a line of colon-separated files, add 'em to list
3647c478bd9Sstevel@tonic-gate  */
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate static void
36761961e0fSrobinson setfile(char **type, char *line)
36861961e0fSrobinson {
36961961e0fSrobinson 	char **tptr, *tok;
3707c478bd9Sstevel@tonic-gate 	char expandpath[BUFSIZ];
3717c478bd9Sstevel@tonic-gate 
37261961e0fSrobinson 	if (*line == 0)
3737c478bd9Sstevel@tonic-gate 		return;
3747c478bd9Sstevel@tonic-gate 	tptr = type;
3757c478bd9Sstevel@tonic-gate 	while (*tptr)		/* skip over existing entries to */
3767c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
3777c478bd9Sstevel@tonic-gate 
37861961e0fSrobinson 	for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) {
3797c478bd9Sstevel@tonic-gate 		expandpath[0] = '\0';
3807c478bd9Sstevel@tonic-gate 		if (*tok != '/')
3817c478bd9Sstevel@tonic-gate 			/* by default, file names are relative to SYSDIR */
38261961e0fSrobinson 			(void) snprintf(expandpath, sizeof (expandpath),
38361961e0fSrobinson 								"%s/", SYSDIR);
38461961e0fSrobinson 		(void) strcat(expandpath, tok);
3857c478bd9Sstevel@tonic-gate 		if (eaccess(expandpath, R_OK) != 0)
3867c478bd9Sstevel@tonic-gate 			/* if we can't read it, no point in adding to list */
3877c478bd9Sstevel@tonic-gate 			continue;
3887c478bd9Sstevel@tonic-gate 		*tptr = strsave(expandpath);
3897c478bd9Sstevel@tonic-gate 		ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setfile: tptr", 0);
3907c478bd9Sstevel@tonic-gate 		tptr++;
3917c478bd9Sstevel@tonic-gate 	}
3927c478bd9Sstevel@tonic-gate }
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate  * given the list for a particular ioctl (push, pop)
3967c478bd9Sstevel@tonic-gate  * and a line of colon-separated modules, add 'em to list
3977c478bd9Sstevel@tonic-gate  */
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate static void
40061961e0fSrobinson setioctl(char **type, char *line)
40161961e0fSrobinson {
40261961e0fSrobinson 	char **tptr, *tok;
4037c478bd9Sstevel@tonic-gate 
40461961e0fSrobinson 	if (*line == 0)
4057c478bd9Sstevel@tonic-gate 		return;
4067c478bd9Sstevel@tonic-gate 	tptr = type;
4077c478bd9Sstevel@tonic-gate 	while (*tptr)		/* skip over existing entries to */
4087c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
40961961e0fSrobinson 	for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) {
4107c478bd9Sstevel@tonic-gate 		*tptr = strsave(tok);
4117c478bd9Sstevel@tonic-gate 		ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setioctl: tptr", 0);
4127c478bd9Sstevel@tonic-gate 		tptr++;
4137c478bd9Sstevel@tonic-gate 	}
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /*
4177c478bd9Sstevel@tonic-gate  * reset Systems files
4187c478bd9Sstevel@tonic-gate  */
41961961e0fSrobinson static void
42061961e0fSrobinson sysreset(void)
4217c478bd9Sstevel@tonic-gate {
4227c478bd9Sstevel@tonic-gate 	if (fsystems)
42361961e0fSrobinson 		(void) fclose(fsystems);
4247c478bd9Sstevel@tonic-gate 	fsystems = NULL;
4257c478bd9Sstevel@tonic-gate 	nsystems = 0;
4267c478bd9Sstevel@tonic-gate 	devreset();
4277c478bd9Sstevel@tonic-gate }
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate /*
4307c478bd9Sstevel@tonic-gate  * reset Devices files
4317c478bd9Sstevel@tonic-gate  */
43261961e0fSrobinson static void
43361961e0fSrobinson devreset(void)
4347c478bd9Sstevel@tonic-gate {
4357c478bd9Sstevel@tonic-gate 	if (fdevices)
43661961e0fSrobinson 		(void) fclose(fdevices);
4377c478bd9Sstevel@tonic-gate 	fdevices = NULL;
4387c478bd9Sstevel@tonic-gate 	ndevices = 0;
4397c478bd9Sstevel@tonic-gate 	dialreset();
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate /*
4437c478bd9Sstevel@tonic-gate  * reset Dialers files
4447c478bd9Sstevel@tonic-gate  */
44561961e0fSrobinson static void
44661961e0fSrobinson dialreset(void)
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate 	if (fdialers)
44961961e0fSrobinson 		(void) fclose(fdialers);
4507c478bd9Sstevel@tonic-gate 	fdialers = NULL;
4517c478bd9Sstevel@tonic-gate 	ndialers = 0;
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate /*
4557c478bd9Sstevel@tonic-gate  * get next line from Systems file
4567c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
4577c478bd9Sstevel@tonic-gate  */
45861961e0fSrobinson static int
4597c478bd9Sstevel@tonic-gate getsysline(char *buf, int len)
4607c478bd9Sstevel@tonic-gate {
4617c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL)
4627c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
4637c478bd9Sstevel@tonic-gate 		setservice("uucico");
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	/* initialize devices and dialers whenever a new line is read */
4667c478bd9Sstevel@tonic-gate 	/* from systems */
4677c478bd9Sstevel@tonic-gate 	devreset();
4687c478bd9Sstevel@tonic-gate 	if (fsystems == NULL)
46961961e0fSrobinson 		if (nextsystems() == FALSE)
4707c478bd9Sstevel@tonic-gate 			return (FALSE);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	for (;;) {
4737c478bd9Sstevel@tonic-gate 		while (fgets(buf, len, fsystems) != NULL)
4747c478bd9Sstevel@tonic-gate 			if ((*buf != '#') && (*buf != ' ') &&
47561961e0fSrobinson 				(*buf != '\t') && (*buf != '\n'))
4767c478bd9Sstevel@tonic-gate 			return (TRUE);
47761961e0fSrobinson 		if (nextsystems() == FALSE)
4787c478bd9Sstevel@tonic-gate 			return (FALSE);
4797c478bd9Sstevel@tonic-gate 	}
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate /*
4837c478bd9Sstevel@tonic-gate  * move to next systems file.  return TRUE if successful, FALSE if not
4847c478bd9Sstevel@tonic-gate  */
4857c478bd9Sstevel@tonic-gate static int
48661961e0fSrobinson nextsystems(void)
4877c478bd9Sstevel@tonic-gate {
4887c478bd9Sstevel@tonic-gate 	devreset();
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	if (fsystems != NULL) {
4917c478bd9Sstevel@tonic-gate 		(void) fclose(fsystems);
4927c478bd9Sstevel@tonic-gate 		nsystems++;
4937c478bd9Sstevel@tonic-gate 	} else {
4947c478bd9Sstevel@tonic-gate 		nsystems = 0;
4957c478bd9Sstevel@tonic-gate 	}
4967c478bd9Sstevel@tonic-gate 	for (; Systems[nsystems] != NULL; nsystems++)
49761961e0fSrobinson 		if ((fsystems = fopen(Systems[nsystems], "r")) != NULL)
4987c478bd9Sstevel@tonic-gate 			return (TRUE);
4997c478bd9Sstevel@tonic-gate 	return (FALSE);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate /*
5037c478bd9Sstevel@tonic-gate  * get next line from Devices file
5047c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5057c478bd9Sstevel@tonic-gate  */
50661961e0fSrobinson static int
5077c478bd9Sstevel@tonic-gate getdevline(char *buf, int len)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL)
5107c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5117c478bd9Sstevel@tonic-gate 		setservice("uucico");
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	if (fdevices == NULL)
51461961e0fSrobinson 		if (nextdevices() == FALSE)
5157c478bd9Sstevel@tonic-gate 			return (FALSE);
5167c478bd9Sstevel@tonic-gate 	for (;;) {
51761961e0fSrobinson 		if (fgets(buf, len, fdevices) != NULL)
5187c478bd9Sstevel@tonic-gate 			return (TRUE);
51961961e0fSrobinson 		if (nextdevices() == FALSE)
5207c478bd9Sstevel@tonic-gate 			return (FALSE);
5217c478bd9Sstevel@tonic-gate 	}
5227c478bd9Sstevel@tonic-gate }
5237c478bd9Sstevel@tonic-gate 
5247c478bd9Sstevel@tonic-gate /*
5257c478bd9Sstevel@tonic-gate  * move to next devices file.  return TRUE if successful, FALSE if not
5267c478bd9Sstevel@tonic-gate  */
5277c478bd9Sstevel@tonic-gate static int
52861961e0fSrobinson nextdevices(void)
5297c478bd9Sstevel@tonic-gate {
5307c478bd9Sstevel@tonic-gate 	if (fdevices != NULL) {
5317c478bd9Sstevel@tonic-gate 		(void) fclose(fdevices);
5327c478bd9Sstevel@tonic-gate 		ndevices++;
5337c478bd9Sstevel@tonic-gate 	} else {
5347c478bd9Sstevel@tonic-gate 		ndevices = 0;
5357c478bd9Sstevel@tonic-gate 	}
5367c478bd9Sstevel@tonic-gate 	for (; Devices[ndevices] != NULL; ndevices++)
53761961e0fSrobinson 		if ((fdevices = fopen(Devices[ndevices], "r")) != NULL)
5387c478bd9Sstevel@tonic-gate 			return (TRUE);
5397c478bd9Sstevel@tonic-gate 	return (FALSE);
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate 
5437c478bd9Sstevel@tonic-gate /*
5447c478bd9Sstevel@tonic-gate  * get next line from Dialers file
5457c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5467c478bd9Sstevel@tonic-gate  */
5477c478bd9Sstevel@tonic-gate 
54861961e0fSrobinson static int
5497c478bd9Sstevel@tonic-gate getdialline(char *buf, int len)
5507c478bd9Sstevel@tonic-gate {
5517c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL)
5527c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5537c478bd9Sstevel@tonic-gate 		setservice("uucico");
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	if (fdialers == NULL)
55661961e0fSrobinson 		if (nextdialers() == FALSE)
5577c478bd9Sstevel@tonic-gate 			return (FALSE);
5587c478bd9Sstevel@tonic-gate 	for (;;) {
55961961e0fSrobinson 		if (fgets(buf, len, fdialers) != NULL)
5607c478bd9Sstevel@tonic-gate 			return (TRUE);
56161961e0fSrobinson 		if (nextdialers() == FALSE)
5627c478bd9Sstevel@tonic-gate 			return (FALSE);
5637c478bd9Sstevel@tonic-gate 	}
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate  * move to next dialers file.  return TRUE if successful, FALSE if not
5687c478bd9Sstevel@tonic-gate  */
5697c478bd9Sstevel@tonic-gate static int
57061961e0fSrobinson nextdialers(void)
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate 	if (fdialers) {
5737c478bd9Sstevel@tonic-gate 		(void) fclose(fdialers);
5747c478bd9Sstevel@tonic-gate 		ndialers++;
5757c478bd9Sstevel@tonic-gate 	} else {
5767c478bd9Sstevel@tonic-gate 		ndialers = 0;
5777c478bd9Sstevel@tonic-gate 	}
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate 	for (; Dialers[ndialers] != NULL; ndialers++)
58061961e0fSrobinson 		if ((fdialers = fopen(Dialers[ndialers], "r")) != NULL)
5817c478bd9Sstevel@tonic-gate 			return (TRUE);
5827c478bd9Sstevel@tonic-gate 	return (FALSE);
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate /*
5867c478bd9Sstevel@tonic-gate  * get next module to be popped
5877c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5887c478bd9Sstevel@tonic-gate  */
5897c478bd9Sstevel@tonic-gate static int
59061961e0fSrobinson getpop(char *buf, size_t len, int *optional)
5917c478bd9Sstevel@tonic-gate {
5927c478bd9Sstevel@tonic-gate 	int slen;
5937c478bd9Sstevel@tonic-gate 
59461961e0fSrobinson 	if (Pops[0] == NULL || Pops[npops] == NULL)
5957c478bd9Sstevel@tonic-gate 		return (FALSE);
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	/*	if the module name is enclosed in parentheses,	*/
5987c478bd9Sstevel@tonic-gate 	/*	is optional. set flag & strip parens		*/
5997c478bd9Sstevel@tonic-gate 	slen = strlen(Pops[npops]) - 1;
6007c478bd9Sstevel@tonic-gate 	if (Pops[npops][0] == '(' && Pops[npops][slen] == ')') {
6017c478bd9Sstevel@tonic-gate 		*optional = 1;
6027c478bd9Sstevel@tonic-gate 		len = (slen < len ? slen : len);
60361961e0fSrobinson 		(void) strncpy(buf, &(Pops[npops++][1]), len);
6047c478bd9Sstevel@tonic-gate 	} else {
6057c478bd9Sstevel@tonic-gate 		*optional = 0;
60661961e0fSrobinson 		(void) strncpy(buf, Pops[npops++], len);
6077c478bd9Sstevel@tonic-gate 	}
6087c478bd9Sstevel@tonic-gate 	buf[len-1] = '\0';
6097c478bd9Sstevel@tonic-gate 	return (TRUE);
6107c478bd9Sstevel@tonic-gate }
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate /*
6137c478bd9Sstevel@tonic-gate  * get next module to be pushed
6147c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6157c478bd9Sstevel@tonic-gate  */
6167c478bd9Sstevel@tonic-gate static int
61761961e0fSrobinson getpush(char *buf, size_t len)
6187c478bd9Sstevel@tonic-gate {
61961961e0fSrobinson 	if (Pushes[0] == NULL || Pushes[npushes] == NULL)
6207c478bd9Sstevel@tonic-gate 		return (FALSE);
62161961e0fSrobinson 	(void) strncpy(buf, Pushes[npushes++], len);
6227c478bd9Sstevel@tonic-gate 	return (TRUE);
6237c478bd9Sstevel@tonic-gate }
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate /*
6267c478bd9Sstevel@tonic-gate  * pop/push requested modules
6277c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6287c478bd9Sstevel@tonic-gate  */
62961961e0fSrobinson static int
63061961e0fSrobinson pop_push(int fd)
6317c478bd9Sstevel@tonic-gate {
6327c478bd9Sstevel@tonic-gate 	char	strmod[FMNAMESZ], onstream[FMNAMESZ];
6337c478bd9Sstevel@tonic-gate 	int		optional;
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	/*	check for streams modules to pop	*/
6367c478bd9Sstevel@tonic-gate 	while (getpop(strmod, sizeof (strmod), &optional)) {
6377c478bd9Sstevel@tonic-gate 		DEBUG(5, (optional ?
63861961e0fSrobinson 			(const char *)"pop_push: optionally POPing %s\n" :
63961961e0fSrobinson 			(const char *)"pop_push: POPing %s\n"), strmod);
6407c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_LOOK, onstream) == -1) {
6417c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_LOOK on fd %d failed ", fd);
6427c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6437c478bd9Sstevel@tonic-gate 			return (FALSE);
6447c478bd9Sstevel@tonic-gate 		}
6457c478bd9Sstevel@tonic-gate 		if (strcmp(strmod, onstream) != SAME) {
6467c478bd9Sstevel@tonic-gate 			if (optional)
6477c478bd9Sstevel@tonic-gate 				continue;
6487c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_POP: %s not there\n", strmod);
6497c478bd9Sstevel@tonic-gate 			return (FALSE);
6507c478bd9Sstevel@tonic-gate 		}
6517c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_POP, 0) == -1) {
6527c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_POP on fd %d failed ", fd);
6537c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6547c478bd9Sstevel@tonic-gate 			return (FALSE);
6557c478bd9Sstevel@tonic-gate 		}
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate 
6587c478bd9Sstevel@tonic-gate 	/*	check for streams modules to push	*/
6597c478bd9Sstevel@tonic-gate 	while (getpush(strmod, sizeof (strmod))) {
6607c478bd9Sstevel@tonic-gate 		DEBUG(5, "pop_push: PUSHing %s\n", strmod);
6617c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_PUSH, strmod) == -1) {
6627c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_PUSH on fd %d failed ", fd);
6637c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6647c478bd9Sstevel@tonic-gate 			return (FALSE);
6657c478bd9Sstevel@tonic-gate 		}
6667c478bd9Sstevel@tonic-gate 	}
6677c478bd9Sstevel@tonic-gate 	return (TRUE);
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate 
67061961e0fSrobinson #ifndef SMALL
6717c478bd9Sstevel@tonic-gate /*
6727c478bd9Sstevel@tonic-gate  *	return name of currently open Systems file
6737c478bd9Sstevel@tonic-gate  */
67461961e0fSrobinson static char *
67561961e0fSrobinson currsys(void)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate 	return (Systems[nsystems]);
6787c478bd9Sstevel@tonic-gate }
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate /*
6817c478bd9Sstevel@tonic-gate  *	return name of currently open Devices file
6827c478bd9Sstevel@tonic-gate  */
68361961e0fSrobinson static char *
68461961e0fSrobinson currdev(void)
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate 	return (Devices[ndevices]);
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate 
6897c478bd9Sstevel@tonic-gate /*
6907c478bd9Sstevel@tonic-gate  *	return name of currently open Dialers file
6917c478bd9Sstevel@tonic-gate  */
69261961e0fSrobinson static char *
69361961e0fSrobinson currdial(void)
6947c478bd9Sstevel@tonic-gate {
6957c478bd9Sstevel@tonic-gate 	return (Dialers[ndialers]);
6967c478bd9Sstevel@tonic-gate }
69761961e0fSrobinson #endif
6987c478bd9Sstevel@tonic-gate 
6997c478bd9Sstevel@tonic-gate /*
7007c478bd9Sstevel@tonic-gate  * set configuration parameters provided in Config file
7017c478bd9Sstevel@tonic-gate  */
7027c478bd9Sstevel@tonic-gate static void
70361961e0fSrobinson setconfig(void)
7047c478bd9Sstevel@tonic-gate {
7057c478bd9Sstevel@tonic-gate 	FILE *f;
7067c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
7077c478bd9Sstevel@tonic-gate 	char *tok;
7087c478bd9Sstevel@tonic-gate 	extern char _ProtoCfg[];
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate 	if ((f = fopen(CONFIG, "r")) != 0) {
7117c478bd9Sstevel@tonic-gate 	while (getline(f, buf) > 0) {
7127c478bd9Sstevel@tonic-gate 		/* got a (logical) line from Config file */
7137c478bd9Sstevel@tonic-gate 		tok = strtok(buf, " \t");
7147c478bd9Sstevel@tonic-gate 		if ((tok != NULL) && (*tok != '#')) {
7157c478bd9Sstevel@tonic-gate 			/* got a token */
71661961e0fSrobinson 			/*
71761961e0fSrobinson 			 * this probably should be table driven when
7187c478bd9Sstevel@tonic-gate 			 * the list of configurable parameters grows.
7197c478bd9Sstevel@tonic-gate 			 */
72061961e0fSrobinson 			if (strncmp("Protocol=", tok, strlen("Protocol=")) ==
72161961e0fSrobinson 								SAME) {
7227c478bd9Sstevel@tonic-gate 				tok += strlen("Protocol=");
7237c478bd9Sstevel@tonic-gate 				if (*tok != '\0') {
7247c478bd9Sstevel@tonic-gate 					if (_ProtoCfg[0] != '\0') {
7257c478bd9Sstevel@tonic-gate 						/*EMPTY*/
72661961e0fSrobinson 						DEBUG(7, "Protocol string %s ",
72761961e0fSrobinson 								tok);
72861961e0fSrobinson 						DEBUG(7, "overrides %s\n",
72961961e0fSrobinson 								_ProtoCfg);
7307c478bd9Sstevel@tonic-gate 					}
73161961e0fSrobinson 					(void) strcpy(_ProtoCfg, tok);
7327c478bd9Sstevel@tonic-gate 				}
7337c478bd9Sstevel@tonic-gate 			} else {
7347c478bd9Sstevel@tonic-gate 				/*EMPTY*/
73561961e0fSrobinson 				DEBUG(7, "Unknown configuration parameter %s\n",
73661961e0fSrobinson 								tok);
7377c478bd9Sstevel@tonic-gate 			}
7387c478bd9Sstevel@tonic-gate 		}
7397c478bd9Sstevel@tonic-gate 	}
7407c478bd9Sstevel@tonic-gate 	(void) fclose(f);
7417c478bd9Sstevel@tonic-gate 	}
7427c478bd9Sstevel@tonic-gate }
743