xref: /illumos-gate/usr/src/lib/libnsl/dial/sysfiles.c (revision 6a634c9d)
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
5004388ebScasper  * Common Development and Distribution License (the "License").
6004388ebScasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate /*
23*23a1cceaSRoger A. Faulkner  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*23a1cceaSRoger A. Faulkner /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*23a1cceaSRoger A. Faulkner /*	  All Rights Reserved	*/
28*23a1cceaSRoger A. Faulkner 
29e8031f0aSraf #include "mt.h"
307c478bd9Sstevel@tonic-gate #include "uucp.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <unistd.h>
3361961e0fSrobinson #include <string.h>
347c478bd9Sstevel@tonic-gate #include "sysfiles.h"
357c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * manage systems files (Systems, Devices, and Dialcodes families).
397c478bd9Sstevel@tonic-gate  *
407c478bd9Sstevel@tonic-gate  * also manage new file Devconfig, allows per-device setup.
417c478bd9Sstevel@tonic-gate  * present use is to specify what streams modules to push/pop for
427c478bd9Sstevel@tonic-gate  * AT&T TLI/streams network.
437c478bd9Sstevel@tonic-gate  *
447c478bd9Sstevel@tonic-gate  * TODO:
457c478bd9Sstevel@tonic-gate  *	call bsfix()?
467c478bd9Sstevel@tonic-gate  *	combine the 3 versions of everything (sys, dev, and dial) into one.
477c478bd9Sstevel@tonic-gate  *	allow arbitrary classes of service.
487c478bd9Sstevel@tonic-gate  *	need verifysys() for uucheck.
497c478bd9Sstevel@tonic-gate  *	nameserver interface?
5061961e0fSrobinson  *	pass sysname (or 0) to getsysline().  (might want reg. exp. or
5161961e0fSrobinson  *		NS processing)
527c478bd9Sstevel@tonic-gate  */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* private variables */
5561961e0fSrobinson static void tokenize(void);
5661961e0fSrobinson static void nameparse(void);
5761961e0fSrobinson static void setfile(char **, char *);
5861961e0fSrobinson static void setioctl(char **, char *);
5961961e0fSrobinson static void scansys(const char *);
6061961e0fSrobinson static void scancfg(char *, char *);
6161961e0fSrobinson static void setconfig(void);
6261961e0fSrobinson static int namematch(const char *label, char *line, const char *name);
6361961e0fSrobinson static int nextdialers(void);
6461961e0fSrobinson static int nextdevices(void);
6561961e0fSrobinson static int nextsystems(void);
66*23a1cceaSRoger A. Faulkner static int getaline(FILE *, char *);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /* pointer arrays might be dynamically allocated */
697c478bd9Sstevel@tonic-gate static char *Systems[64];	/* list of Systems files */
707c478bd9Sstevel@tonic-gate static char *Devices[64];	/* list of Devices files */
717c478bd9Sstevel@tonic-gate static char *Dialers[64];	/* list of Dialers files */
727c478bd9Sstevel@tonic-gate static char *Pops[64];		/* list of STREAMS modules to be popped */
737c478bd9Sstevel@tonic-gate static char *Pushes[64];	/* list of STREAMS modules to be pushed */
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static int nsystems;		/* index into list of Systems files */
767c478bd9Sstevel@tonic-gate static int ndevices;		/* index into list of Devices files */
777c478bd9Sstevel@tonic-gate static int ndialers;		/* index into list of Dialers files */
787c478bd9Sstevel@tonic-gate static int npops;		/* index into list of STREAMS modules */
7961961e0fSrobinson 							/* to be popped */
807c478bd9Sstevel@tonic-gate static int npushes;		/* index into list of STREAMS modules */
8161961e0fSrobinson 							/* to be pushed */
827c478bd9Sstevel@tonic-gate 
8361961e0fSrobinson static unsigned connecttime, expecttime;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate static FILE *fsystems;
867c478bd9Sstevel@tonic-gate static FILE *fdevices;
877c478bd9Sstevel@tonic-gate static FILE *fdialers;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* this might be dynamically allocated */
9061961e0fSrobinson #define	NTOKENS 16
917c478bd9Sstevel@tonic-gate static char *tokens[NTOKENS], **tokptr;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /* export these */
9461961e0fSrobinson static void setservice(const char *service);
9561961e0fSrobinson static void sysreset(void);
9661961e0fSrobinson static void devreset(void);
9761961e0fSrobinson static void dialreset(void);
9861961e0fSrobinson static void setdevcfg(char *, char *);
9961961e0fSrobinson static void setservice(const char *);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /* import these */
10261961e0fSrobinson extern char *strsave(const char *);
10361961e0fSrobinson static int eaccess(char *, mode_t);
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * setservice init's Systems, Devices, Dialers lists from Sysfiles
1077c478bd9Sstevel@tonic-gate  */
10861961e0fSrobinson static void
setservice(const char * service)10961961e0fSrobinson setservice(const char *service)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	setconfig();
1127c478bd9Sstevel@tonic-gate 	scansys(service);
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate /*
1167c478bd9Sstevel@tonic-gate  * setdevcfg init's Pops, Pushes lists from Devconfig
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate 
11961961e0fSrobinson static void
setdevcfg(char * service,char * device)12061961e0fSrobinson setdevcfg(char *service, char *device)
1217c478bd9Sstevel@tonic-gate {
1227c478bd9Sstevel@tonic-gate 	scancfg(service, device);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*	administrative files access */
12661961e0fSrobinson static int
sysaccess(int type)12761961e0fSrobinson sysaccess(int type)
1287c478bd9Sstevel@tonic-gate {
12961961e0fSrobinson 	char errformat[BUFSIZ];
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 	switch (type) {
1327c478bd9Sstevel@tonic-gate 	case ACCESS_SYSTEMS:
1337c478bd9Sstevel@tonic-gate 		return (access(Systems[nsystems], R_OK));
1347c478bd9Sstevel@tonic-gate 	case ACCESS_DEVICES:
1357c478bd9Sstevel@tonic-gate 		return (access(Devices[ndevices], R_OK));
1367c478bd9Sstevel@tonic-gate 	case ACCESS_DIALERS:
1377c478bd9Sstevel@tonic-gate 		return (access(Dialers[ndialers], R_OK));
1387c478bd9Sstevel@tonic-gate 	case EACCESS_SYSTEMS:
13961961e0fSrobinson 		return (eaccess(Systems[nsystems], R_OK));
1407c478bd9Sstevel@tonic-gate 	case EACCESS_DEVICES:
14161961e0fSrobinson 		return (eaccess(Devices[ndevices], R_OK));
1427c478bd9Sstevel@tonic-gate 	case EACCESS_DIALERS:
14361961e0fSrobinson 		return (eaccess(Dialers[ndialers], R_OK));
1447c478bd9Sstevel@tonic-gate 	}
14561961e0fSrobinson 	(void) sprintf(errformat, "bad access type %d", type);
14661961e0fSrobinson 	logent(errformat, "sysaccess");
14761961e0fSrobinson 	return (FAIL);
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * read Sysfiles, set up lists of Systems/Devices/Dialers file names.
1537c478bd9Sstevel@tonic-gate  * allow multiple entries for a given service, allow a service
1547c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., systems=foo:baz systems=bar.
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate static void
scansys(const char * service)15761961e0fSrobinson scansys(const char *service)
1587c478bd9Sstevel@tonic-gate {	FILE *f;
1597c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
16056295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	char **tptr;
16156295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 
16256295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	/*
16356295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	 * Release and Initialize previously allocated memory
16456295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	 * for Systems, Devices and Dialers.
16556295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	 */
16656295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	nsystems = 0;
16756295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	tptr = Systems;
16856295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	while (*tptr) {
16956295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		free(*tptr);
17056295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		*tptr = NULL;
17156295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		tptr++;
17256295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	}
17356295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 
17456295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	ndevices = 0;
17556295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	tptr = Devices;
17656295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	while (*tptr) {
17756295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		free(*tptr);
17856295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		*tptr = NULL;
17956295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		tptr++;
18056295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	}
18156295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 
18256295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	ndialers = 0;
18356295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	tptr = Dialers;
18456295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	while (*tptr) {
18556295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		free(*tptr);
18656295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		*tptr = NULL;
18756295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		tptr++;
18856295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	}
1897c478bd9Sstevel@tonic-gate 
190004388ebScasper 	if ((f = fopen(SYSFILES, "rF")) != 0) {
191*23a1cceaSRoger A. Faulkner 		while (getaline(f, buf) > 0) {
1927c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Sysfiles */
1937c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
1947c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
1957c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
1967c478bd9Sstevel@tonic-gate 				tokenize();
1977c478bd9Sstevel@tonic-gate 				nameparse();
1987c478bd9Sstevel@tonic-gate 			}
1997c478bd9Sstevel@tonic-gate 		}
2007c478bd9Sstevel@tonic-gate 		(void) fclose(f);
2017c478bd9Sstevel@tonic-gate 	}
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	/* if didn't find entries in Sysfiles, use defaults */
2047c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL) {
2057c478bd9Sstevel@tonic-gate 		Systems[0] = strsave(SYSTEMS);
20661961e0fSrobinson 		ASSERT(Systems[0] != NULL, "Ct_ALLOCATE", "scansys: Systems",
20761961e0fSrobinson 									0);
2087c478bd9Sstevel@tonic-gate 		Systems[1] = NULL;
2097c478bd9Sstevel@tonic-gate 	}
2107c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL) {
2117c478bd9Sstevel@tonic-gate 		Devices[0] = strsave(DEVICES);
21261961e0fSrobinson 		ASSERT(Devices[0] != NULL, "Ct_ALLOCATE", "scansys: Devices",
21361961e0fSrobinson 									0);
2147c478bd9Sstevel@tonic-gate 		Devices[1] = NULL;
2157c478bd9Sstevel@tonic-gate 	}
2167c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL) {
2177c478bd9Sstevel@tonic-gate 		Dialers[0] = strsave(DIALERS);
21861961e0fSrobinson 		ASSERT(Dialers[0] != NULL, "Ct_ALLOCATE", "scansys: Dialers",
21961961e0fSrobinson 									0);
2207c478bd9Sstevel@tonic-gate 		Dialers[1] = NULL;
2217c478bd9Sstevel@tonic-gate 	}
2227c478bd9Sstevel@tonic-gate }
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * read Devconfig.  allow multiple entries for a given service, allow a service
2277c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., push=foo:baz push=bar.
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate static void
scancfg(char * service,char * device)23061961e0fSrobinson scancfg(char *service, char *device)
2317c478bd9Sstevel@tonic-gate {	FILE *f;
2327c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 	/* (re)initialize device-specific information */
2357c478bd9Sstevel@tonic-gate 	npops = npushes = 0;
2367c478bd9Sstevel@tonic-gate 	Pops[0] = Pushes[0] = NULL;
2377c478bd9Sstevel@tonic-gate 	connecttime = CONNECTTIME;
2387c478bd9Sstevel@tonic-gate 	expecttime = EXPECTTIME;
2397c478bd9Sstevel@tonic-gate 
240004388ebScasper 	if ((f = fopen(DEVCONFIG, "rF")) != 0) {
241*23a1cceaSRoger A. Faulkner 		while (getaline(f, buf) > 0) {
2427c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Devconfig */
2437c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
2447c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
2457c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
2467c478bd9Sstevel@tonic-gate 				tok = strtok((char *)0, " \t");
2477c478bd9Sstevel@tonic-gate 				if (namematch("device=", tok, device)) {
2487c478bd9Sstevel@tonic-gate 					tokenize();
2497c478bd9Sstevel@tonic-gate 					nameparse();
2507c478bd9Sstevel@tonic-gate 				}
2517c478bd9Sstevel@tonic-gate 			}
2527c478bd9Sstevel@tonic-gate 		}
2537c478bd9Sstevel@tonic-gate 		(void) fclose(f);
2547c478bd9Sstevel@tonic-gate 	}
2557c478bd9Sstevel@tonic-gate 	return;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate /*
2607c478bd9Sstevel@tonic-gate  *  given a file pointer and buffer, construct logical line in buffer
2617c478bd9Sstevel@tonic-gate  *  (i.e., concatenate lines ending in '\').  return length of line
2627c478bd9Sstevel@tonic-gate  *  ASSUMES that buffer is BUFSIZ long!
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate static int
getaline(FILE * f,char * line)266*23a1cceaSRoger A. Faulkner getaline(FILE *f, char *line)
2677c478bd9Sstevel@tonic-gate {	char *lptr, *lend;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	lptr = line;
2707c478bd9Sstevel@tonic-gate 	while (fgets(lptr, (line + BUFSIZ) - lptr, f) != NULL) {
2717c478bd9Sstevel@tonic-gate 		lend = lptr + strlen(lptr);
27261961e0fSrobinson 		if (lend == lptr || lend[-1] != '\n')
2737c478bd9Sstevel@tonic-gate 			/* empty buf or line too long! */
2747c478bd9Sstevel@tonic-gate 			break;
2757c478bd9Sstevel@tonic-gate 		*--lend = '\0'; /* lop off ending '\n' */
2767c478bd9Sstevel@tonic-gate 		if (lend == line) /* empty line - ignore */
2777c478bd9Sstevel@tonic-gate 			continue;
2787c478bd9Sstevel@tonic-gate 		lptr = lend;
2797c478bd9Sstevel@tonic-gate 		if (lend[-1] != '\\')
2807c478bd9Sstevel@tonic-gate 			break;
2817c478bd9Sstevel@tonic-gate 		/* continuation */
2827c478bd9Sstevel@tonic-gate 		lend[-1] = ' ';
2837c478bd9Sstevel@tonic-gate 	}
2847c478bd9Sstevel@tonic-gate 	return (lptr - line);
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * given a label (e.g., "service=", "device="), a name ("cu", "uucico"),
2897c478bd9Sstevel@tonic-gate  *  and a line:  if line begins with the label and if the name appears
2907c478bd9Sstevel@tonic-gate  * in a colon-separated list of names following the label, return true;
2917c478bd9Sstevel@tonic-gate  * else return false
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate static int
namematch(const char * label,char * line,const char * name)29461961e0fSrobinson namematch(const char *label, char *line, const char *name)
29561961e0fSrobinson {
29661961e0fSrobinson 	char *lend;
2977c478bd9Sstevel@tonic-gate 
29861961e0fSrobinson 	if (strncmp(label, line, strlen(label)) != SAME)
2997c478bd9Sstevel@tonic-gate 		return (FALSE);	/* probably a comment line */
3007c478bd9Sstevel@tonic-gate 	line += strlen(label);
30161961e0fSrobinson 	if (*line == '\0')
3027c478bd9Sstevel@tonic-gate 		return (FALSE);
3037c478bd9Sstevel@tonic-gate 	/*
3047c478bd9Sstevel@tonic-gate 	 * can't use strtok() in the following because scansys(),
3057c478bd9Sstevel@tonic-gate 	 * scancfg() do an initializing call to strtok() before
3067c478bd9Sstevel@tonic-gate 	 * coming here and then CONTINUE calling strtok() in tokenize(),
3077c478bd9Sstevel@tonic-gate 	 * after returning from namematch().
3087c478bd9Sstevel@tonic-gate 	 */
3097c478bd9Sstevel@tonic-gate 	while ((lend = strchr(line, ':')) != NULL) {
3107c478bd9Sstevel@tonic-gate 		*lend = '\0';
31161961e0fSrobinson 		if (strcmp(line, name) == SAME)
3127c478bd9Sstevel@tonic-gate 			return (TRUE);
3137c478bd9Sstevel@tonic-gate 		line = lend+1;
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 	return (strcmp(line, name) == SAME);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate  * tokenize() continues pulling tokens out of a buffer -- the
3207c478bd9Sstevel@tonic-gate  * initializing call to strtok must have been made before calling
3217c478bd9Sstevel@tonic-gate  * tokenize() -- and starts stuffing 'em into tokptr.
3227c478bd9Sstevel@tonic-gate  */
3237c478bd9Sstevel@tonic-gate static void
tokenize(void)32461961e0fSrobinson tokenize(void)
32561961e0fSrobinson {
32661961e0fSrobinson 	char *tok;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	tokptr = tokens;
32961961e0fSrobinson 	while ((tok = strtok(NULL, " \t")) != NULL) {
3307c478bd9Sstevel@tonic-gate 		*tokptr++ = tok;
3317c478bd9Sstevel@tonic-gate 		if (tokptr - tokens >= NTOKENS)
3327c478bd9Sstevel@tonic-gate 			break;
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 	*tokptr = NULL;
3357c478bd9Sstevel@tonic-gate }
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * look at top token in array: should be line of the form
3397c478bd9Sstevel@tonic-gate  *	name=item1:item2:item3...
34061961e0fSrobinson  * if name is one we recognize, then call set[file|ioctl] to set up
3417c478bd9Sstevel@tonic-gate  * corresponding list.  otherwise, log bad name.
3427c478bd9Sstevel@tonic-gate  */
3437c478bd9Sstevel@tonic-gate static void
nameparse(void)34461961e0fSrobinson nameparse(void)
34561961e0fSrobinson {
34661961e0fSrobinson 	char **line, *equals;
3477c478bd9Sstevel@tonic-gate 	int temp;
3487c478bd9Sstevel@tonic-gate 
34961961e0fSrobinson #define	setuint(a, b, c) a = (((temp = atoi(b)) <= 0) ? (c) : temp)
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	for (line = tokens; (line - tokens) < NTOKENS && *line; line++) {
3527c478bd9Sstevel@tonic-gate 		equals = strchr(*line, '=');
3537c478bd9Sstevel@tonic-gate 		if (equals == NULL)
3547c478bd9Sstevel@tonic-gate 			continue;	/* may be meaningful someday? */
3557c478bd9Sstevel@tonic-gate 		*equals = '\0';
3567c478bd9Sstevel@tonic-gate 		/* ignore entry with empty rhs */
3577c478bd9Sstevel@tonic-gate 		if (*++equals == '\0')
3587c478bd9Sstevel@tonic-gate 			continue;
3597c478bd9Sstevel@tonic-gate 		if (strcmp(*line, "systems") == SAME)
3607c478bd9Sstevel@tonic-gate 			setfile(Systems, equals);
3617c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "devices") == SAME)
3627c478bd9Sstevel@tonic-gate 			setfile(Devices, equals);
3637c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "dialers") == SAME)
3647c478bd9Sstevel@tonic-gate 			setfile(Dialers, equals);
3657c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "pop") == SAME)
3667c478bd9Sstevel@tonic-gate 			setioctl(Pops, equals);
3677c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "push") == SAME)
3687c478bd9Sstevel@tonic-gate 			setioctl(Pushes, equals);
3697c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "connecttime") == SAME)
3707c478bd9Sstevel@tonic-gate 			setuint(connecttime, equals, CONNECTTIME);
3717c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "expecttime") == SAME)
3727c478bd9Sstevel@tonic-gate 			setuint(expecttime, equals, EXPECTTIME);
3737c478bd9Sstevel@tonic-gate 		else if (strcmp(*line, "msgtime") == SAME)
37461961e0fSrobinson 			continue;
3757c478bd9Sstevel@tonic-gate 		else {
3767c478bd9Sstevel@tonic-gate 			char errformat[BUFSIZ];
3777c478bd9Sstevel@tonic-gate 
37861961e0fSrobinson 			(void) snprintf(errformat, sizeof (errformat),
37956295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 			    "unrecognized label %s", *line);
3807c478bd9Sstevel@tonic-gate 			logent(errformat, "Sysfiles|Devconfig");
3817c478bd9Sstevel@tonic-gate 		}
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate /*
3867c478bd9Sstevel@tonic-gate  * given the list for a particular type (systems, devices,...)
3877c478bd9Sstevel@tonic-gate  * and a line of colon-separated files, add 'em to list
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate static void
setfile(char ** type,char * line)39161961e0fSrobinson setfile(char **type, char *line)
39261961e0fSrobinson {
39361961e0fSrobinson 	char **tptr, *tok;
3947c478bd9Sstevel@tonic-gate 	char expandpath[BUFSIZ];
3957c478bd9Sstevel@tonic-gate 
39661961e0fSrobinson 	if (*line == 0)
3977c478bd9Sstevel@tonic-gate 		return;
3987c478bd9Sstevel@tonic-gate 	tptr = type;
39961961e0fSrobinson 	while (*tptr)		/* skip over existing entries to */
4007c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
4017c478bd9Sstevel@tonic-gate 
40261961e0fSrobinson 	for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) {
4037c478bd9Sstevel@tonic-gate 		expandpath[0] = '\0';
4047c478bd9Sstevel@tonic-gate 		if (*tok != '/')
4057c478bd9Sstevel@tonic-gate 			/* by default, file names are relative to SYSDIR */
40661961e0fSrobinson 			(void) snprintf(expandpath, sizeof (expandpath),
40756295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 			    "%s/", SYSDIR);
40861961e0fSrobinson 		(void) strcat(expandpath, tok);
4097c478bd9Sstevel@tonic-gate 		if (eaccess(expandpath, R_OK) != 0)
4107c478bd9Sstevel@tonic-gate 			/* if we can't read it, no point in adding to list */
4117c478bd9Sstevel@tonic-gate 			continue;
4127c478bd9Sstevel@tonic-gate 		*tptr = strsave(expandpath);
4137c478bd9Sstevel@tonic-gate 		ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setfile: tptr", 0);
4147c478bd9Sstevel@tonic-gate 		tptr++;
4157c478bd9Sstevel@tonic-gate 	}
41656295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 	*tptr = NULL;
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate /*
4207c478bd9Sstevel@tonic-gate  * given the list for a particular ioctl (push, pop)
4217c478bd9Sstevel@tonic-gate  * and a line of colon-separated modules, add 'em to list
4227c478bd9Sstevel@tonic-gate  */
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate static void
setioctl(char ** type,char * line)42561961e0fSrobinson setioctl(char **type, char *line)
42661961e0fSrobinson {
42761961e0fSrobinson 	char **tptr, *tok;
4287c478bd9Sstevel@tonic-gate 
42961961e0fSrobinson 	if (*line == 0)
4307c478bd9Sstevel@tonic-gate 		return;
4317c478bd9Sstevel@tonic-gate 	tptr = type;
43261961e0fSrobinson 	while (*tptr)		/* skip over existing entries to */
4337c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
43461961e0fSrobinson 	for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) {
4357c478bd9Sstevel@tonic-gate 		*tptr = strsave(tok);
4367c478bd9Sstevel@tonic-gate 		ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setioctl: tptr", 0);
4377c478bd9Sstevel@tonic-gate 		tptr++;
4387c478bd9Sstevel@tonic-gate 	}
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate /*
4427c478bd9Sstevel@tonic-gate  * reset Systems files
4437c478bd9Sstevel@tonic-gate  */
44461961e0fSrobinson static void
sysreset(void)44561961e0fSrobinson sysreset(void)
4467c478bd9Sstevel@tonic-gate {
4477c478bd9Sstevel@tonic-gate 	if (fsystems)
44861961e0fSrobinson 		(void) fclose(fsystems);
4497c478bd9Sstevel@tonic-gate 	fsystems = NULL;
4507c478bd9Sstevel@tonic-gate 	nsystems = 0;
4517c478bd9Sstevel@tonic-gate 	devreset();
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate /*
4557c478bd9Sstevel@tonic-gate  * reset Devices files
4567c478bd9Sstevel@tonic-gate  */
45761961e0fSrobinson static void
devreset(void)45861961e0fSrobinson devreset(void)
4597c478bd9Sstevel@tonic-gate {
4607c478bd9Sstevel@tonic-gate 	if (fdevices)
46161961e0fSrobinson 		(void) fclose(fdevices);
4627c478bd9Sstevel@tonic-gate 	fdevices = NULL;
4637c478bd9Sstevel@tonic-gate 	ndevices = 0;
4647c478bd9Sstevel@tonic-gate 	dialreset();
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate /*
4687c478bd9Sstevel@tonic-gate  * reset Dialers files
4697c478bd9Sstevel@tonic-gate  */
47061961e0fSrobinson static void
dialreset(void)47161961e0fSrobinson dialreset(void)
4727c478bd9Sstevel@tonic-gate {
4737c478bd9Sstevel@tonic-gate 	if (fdialers)
47461961e0fSrobinson 		(void) fclose(fdialers);
4757c478bd9Sstevel@tonic-gate 	fdialers = NULL;
4767c478bd9Sstevel@tonic-gate 	ndialers = 0;
4777c478bd9Sstevel@tonic-gate }
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate /*
4807c478bd9Sstevel@tonic-gate  * get next line from Systems file
4817c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
4827c478bd9Sstevel@tonic-gate  */
48361961e0fSrobinson static int
getsysline(char * buf,int len)4847c478bd9Sstevel@tonic-gate getsysline(char *buf, int len)
4857c478bd9Sstevel@tonic-gate {
4867c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL)
4877c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
4887c478bd9Sstevel@tonic-gate 		setservice("uucico");
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	/* initialize devices and dialers whenever a new line is read */
4917c478bd9Sstevel@tonic-gate 	/* from systems */
4927c478bd9Sstevel@tonic-gate 	devreset();
4937c478bd9Sstevel@tonic-gate 	if (fsystems == NULL)
49461961e0fSrobinson 		if (nextsystems() == FALSE)
4957c478bd9Sstevel@tonic-gate 			return (FALSE);
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	for (;;) {
4987c478bd9Sstevel@tonic-gate 		while (fgets(buf, len, fsystems) != NULL)
4997c478bd9Sstevel@tonic-gate 			if ((*buf != '#') && (*buf != ' ') &&
50056295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 			    (*buf != '\t') && (*buf != '\n'))
5017c478bd9Sstevel@tonic-gate 			return (TRUE);
50261961e0fSrobinson 		if (nextsystems() == FALSE)
5037c478bd9Sstevel@tonic-gate 			return (FALSE);
5047c478bd9Sstevel@tonic-gate 	}
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate  * move to next systems file.  return TRUE if successful, FALSE if not
5097c478bd9Sstevel@tonic-gate  */
5107c478bd9Sstevel@tonic-gate static int
nextsystems(void)51161961e0fSrobinson nextsystems(void)
5127c478bd9Sstevel@tonic-gate {
5137c478bd9Sstevel@tonic-gate 	devreset();
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	if (fsystems != NULL) {
5167c478bd9Sstevel@tonic-gate 		(void) fclose(fsystems);
5177c478bd9Sstevel@tonic-gate 		nsystems++;
5187c478bd9Sstevel@tonic-gate 	} else {
5197c478bd9Sstevel@tonic-gate 		nsystems = 0;
5207c478bd9Sstevel@tonic-gate 	}
5217c478bd9Sstevel@tonic-gate 	for (; Systems[nsystems] != NULL; nsystems++)
522004388ebScasper 		if ((fsystems = fopen(Systems[nsystems], "rF")) != NULL)
5237c478bd9Sstevel@tonic-gate 			return (TRUE);
5247c478bd9Sstevel@tonic-gate 	return (FALSE);
5257c478bd9Sstevel@tonic-gate }
52661961e0fSrobinson 
5277c478bd9Sstevel@tonic-gate /*
5287c478bd9Sstevel@tonic-gate  * get next line from Devices file
5297c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5307c478bd9Sstevel@tonic-gate  */
53161961e0fSrobinson static int
getdevline(char * buf,int len)5327c478bd9Sstevel@tonic-gate getdevline(char *buf, int len)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL)
5357c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5367c478bd9Sstevel@tonic-gate 		setservice("uucico");
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate 	if (fdevices == NULL)
53961961e0fSrobinson 		if (nextdevices() == FALSE)
5407c478bd9Sstevel@tonic-gate 			return (FALSE);
5417c478bd9Sstevel@tonic-gate 	for (;;) {
54261961e0fSrobinson 		if (fgets(buf, len, fdevices) != NULL)
5437c478bd9Sstevel@tonic-gate 			return (TRUE);
54461961e0fSrobinson 		if (nextdevices() == FALSE)
5457c478bd9Sstevel@tonic-gate 			return (FALSE);
5467c478bd9Sstevel@tonic-gate 	}
5477c478bd9Sstevel@tonic-gate }
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate /*
5507c478bd9Sstevel@tonic-gate  * move to next devices file.  return TRUE if successful, FALSE if not
5517c478bd9Sstevel@tonic-gate  */
5527c478bd9Sstevel@tonic-gate static int
nextdevices(void)55361961e0fSrobinson nextdevices(void)
5547c478bd9Sstevel@tonic-gate {
5557c478bd9Sstevel@tonic-gate 	if (fdevices != NULL) {
5567c478bd9Sstevel@tonic-gate 		(void) fclose(fdevices);
5577c478bd9Sstevel@tonic-gate 		ndevices++;
5587c478bd9Sstevel@tonic-gate 	} else {
5597c478bd9Sstevel@tonic-gate 		ndevices = 0;
5607c478bd9Sstevel@tonic-gate 	}
5617c478bd9Sstevel@tonic-gate 	for (; Devices[ndevices] != NULL; ndevices++)
562004388ebScasper 		if ((fdevices = fopen(Devices[ndevices], "rF")) != NULL)
5637c478bd9Sstevel@tonic-gate 			return (TRUE);
5647c478bd9Sstevel@tonic-gate 	return (FALSE);
5657c478bd9Sstevel@tonic-gate }
5667c478bd9Sstevel@tonic-gate 
56761961e0fSrobinson 
5687c478bd9Sstevel@tonic-gate /*
5697c478bd9Sstevel@tonic-gate  * get next line from Dialers file
5707c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5717c478bd9Sstevel@tonic-gate  */
5727c478bd9Sstevel@tonic-gate 
57361961e0fSrobinson static int
getdialline(char * buf,int len)5747c478bd9Sstevel@tonic-gate getdialline(char *buf, int len)
5757c478bd9Sstevel@tonic-gate {
5767c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL)
5777c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5787c478bd9Sstevel@tonic-gate 		setservice("uucico");
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate 	if (fdialers == NULL)
58161961e0fSrobinson 		if (nextdialers() == FALSE)
5827c478bd9Sstevel@tonic-gate 			return (FALSE);
5837c478bd9Sstevel@tonic-gate 	for (;;) {
58461961e0fSrobinson 		if (fgets(buf, len, fdialers) != NULL)
5857c478bd9Sstevel@tonic-gate 			return (TRUE);
58661961e0fSrobinson 		if (nextdialers() == FALSE)
5877c478bd9Sstevel@tonic-gate 			return (FALSE);
5887c478bd9Sstevel@tonic-gate 	}
5897c478bd9Sstevel@tonic-gate }
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate /*
5927c478bd9Sstevel@tonic-gate  * move to next dialers file.  return TRUE if successful, FALSE if not
5937c478bd9Sstevel@tonic-gate  */
5947c478bd9Sstevel@tonic-gate static int
nextdialers(void)59561961e0fSrobinson nextdialers(void)
5967c478bd9Sstevel@tonic-gate {
5977c478bd9Sstevel@tonic-gate 	if (fdialers) {
5987c478bd9Sstevel@tonic-gate 		(void) fclose(fdialers);
5997c478bd9Sstevel@tonic-gate 		ndialers++;
6007c478bd9Sstevel@tonic-gate 	} else {
6017c478bd9Sstevel@tonic-gate 		ndialers = 0;
6027c478bd9Sstevel@tonic-gate 	}
60361961e0fSrobinson 
6047c478bd9Sstevel@tonic-gate 	for (; Dialers[ndialers] != NULL; ndialers++)
605004388ebScasper 		if ((fdialers = fopen(Dialers[ndialers], "rF")) != NULL)
6067c478bd9Sstevel@tonic-gate 			return (TRUE);
6077c478bd9Sstevel@tonic-gate 	return (FALSE);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*
6117c478bd9Sstevel@tonic-gate  * get next module to be popped
6127c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6137c478bd9Sstevel@tonic-gate  */
6147c478bd9Sstevel@tonic-gate static int
getpop(char * buf,size_t len,int * optional)61561961e0fSrobinson getpop(char *buf, size_t len, int *optional)
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate 	int slen;
6187c478bd9Sstevel@tonic-gate 
61961961e0fSrobinson 	if (Pops[0] == NULL || Pops[npops] == NULL)
6207c478bd9Sstevel@tonic-gate 		return (FALSE);
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	/*	if the module name is enclosed in parentheses,	*/
6237c478bd9Sstevel@tonic-gate 	/*	is optional. set flag & strip parens		*/
6247c478bd9Sstevel@tonic-gate 	slen = strlen(Pops[npops]) - 1;
62561961e0fSrobinson 	if (Pops[npops][0] == '(' && Pops[npops][slen] == ')') {
6267c478bd9Sstevel@tonic-gate 		*optional = 1;
6277c478bd9Sstevel@tonic-gate 		len = (slen < len ? slen : len);
62861961e0fSrobinson 		(void) strncpy(buf, &(Pops[npops++][1]), len);
6297c478bd9Sstevel@tonic-gate 	} else {
6307c478bd9Sstevel@tonic-gate 		*optional = 0;
63161961e0fSrobinson 		(void) strncpy(buf, Pops[npops++], len);
6327c478bd9Sstevel@tonic-gate 	}
6337c478bd9Sstevel@tonic-gate 	buf[len-1] = '\0';
6347c478bd9Sstevel@tonic-gate 	return (TRUE);
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate /*
6387c478bd9Sstevel@tonic-gate  * get next module to be pushed
6397c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6407c478bd9Sstevel@tonic-gate  */
6417c478bd9Sstevel@tonic-gate static int
getpush(char * buf,size_t len)64261961e0fSrobinson getpush(char *buf, size_t len)
6437c478bd9Sstevel@tonic-gate {
64461961e0fSrobinson 	if (Pushes[0] == NULL || Pushes[npushes] == NULL)
6457c478bd9Sstevel@tonic-gate 		return (FALSE);
64661961e0fSrobinson 	(void) strncpy(buf, Pushes[npushes++], len);
6477c478bd9Sstevel@tonic-gate 	return (TRUE);
6487c478bd9Sstevel@tonic-gate }
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate /*
6517c478bd9Sstevel@tonic-gate  * pop/push requested modules
6527c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6537c478bd9Sstevel@tonic-gate  */
65461961e0fSrobinson static int
pop_push(int fd)65561961e0fSrobinson pop_push(int fd)
6567c478bd9Sstevel@tonic-gate {
6577c478bd9Sstevel@tonic-gate 	char	strmod[FMNAMESZ], onstream[FMNAMESZ];
6587c478bd9Sstevel@tonic-gate 	int		optional;
6597c478bd9Sstevel@tonic-gate 
6607c478bd9Sstevel@tonic-gate 	/*	check for streams modules to pop	*/
66161961e0fSrobinson 	while (getpop(strmod, sizeof (strmod), &optional)) {
6627c478bd9Sstevel@tonic-gate 		DEBUG(5, (optional ?
66356295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		    (const char *)"pop_push: optionally POPing %s\n" :
66456295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 		    (const char *)"pop_push: POPing %s\n"), strmod);
6657c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_LOOK, onstream) == -1) {
6667c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_LOOK on fd %d failed ", fd);
6677c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6687c478bd9Sstevel@tonic-gate 			return (FALSE);
6697c478bd9Sstevel@tonic-gate 		}
6707c478bd9Sstevel@tonic-gate 		if (strcmp(strmod, onstream) != SAME) {
6717c478bd9Sstevel@tonic-gate 			if (optional)
6727c478bd9Sstevel@tonic-gate 				continue;
6737c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_POP: %s not there\n", strmod);
6747c478bd9Sstevel@tonic-gate 			return (FALSE);
6757c478bd9Sstevel@tonic-gate 		}
6767c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_POP, 0) == -1) {
6777c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_POP on fd %d failed ", fd);
6787c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6797c478bd9Sstevel@tonic-gate 			return (FALSE);
6807c478bd9Sstevel@tonic-gate 		}
6817c478bd9Sstevel@tonic-gate 	}
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	/*	check for streams modules to push	*/
68461961e0fSrobinson 	while (getpush(strmod, sizeof (strmod))) {
6857c478bd9Sstevel@tonic-gate 		DEBUG(5, "pop_push: PUSHing %s\n", strmod);
6867c478bd9Sstevel@tonic-gate 		if (ioctl(fd, I_PUSH, strmod) == -1) {
6877c478bd9Sstevel@tonic-gate 			DEBUG(5, "pop_push: I_PUSH on fd %d failed ", fd);
6887c478bd9Sstevel@tonic-gate 			DEBUG(5, "errno %d\n", errno);
6897c478bd9Sstevel@tonic-gate 			return (FALSE);
6907c478bd9Sstevel@tonic-gate 		}
6917c478bd9Sstevel@tonic-gate 	}
6927c478bd9Sstevel@tonic-gate 	return (TRUE);
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate 
69561961e0fSrobinson #ifndef SMALL
6967c478bd9Sstevel@tonic-gate /*
69761961e0fSrobinson  *	return name of currently open Systems file
6987c478bd9Sstevel@tonic-gate  */
69961961e0fSrobinson static char *
currsys(void)70061961e0fSrobinson currsys(void)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate 	return (Systems[nsystems]);
7037c478bd9Sstevel@tonic-gate }
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate /*
70661961e0fSrobinson  *	return name of currently open Devices file
7077c478bd9Sstevel@tonic-gate  */
70861961e0fSrobinson static char *
currdev(void)70961961e0fSrobinson currdev(void)
7107c478bd9Sstevel@tonic-gate {
7117c478bd9Sstevel@tonic-gate 	return (Devices[ndevices]);
7127c478bd9Sstevel@tonic-gate }
7137c478bd9Sstevel@tonic-gate 
7147c478bd9Sstevel@tonic-gate /*
71561961e0fSrobinson  *	return name of currently open Dialers file
7167c478bd9Sstevel@tonic-gate  */
71761961e0fSrobinson static char *
currdial(void)71861961e0fSrobinson currdial(void)
7197c478bd9Sstevel@tonic-gate {
7207c478bd9Sstevel@tonic-gate 	return (Dialers[ndialers]);
7217c478bd9Sstevel@tonic-gate }
72261961e0fSrobinson #endif
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate /*
7257c478bd9Sstevel@tonic-gate  * set configuration parameters provided in Config file
7267c478bd9Sstevel@tonic-gate  */
7277c478bd9Sstevel@tonic-gate static void
setconfig(void)72861961e0fSrobinson setconfig(void)
7297c478bd9Sstevel@tonic-gate {
7307c478bd9Sstevel@tonic-gate 	FILE *f;
7317c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ];
7327c478bd9Sstevel@tonic-gate 	char *tok;
7337c478bd9Sstevel@tonic-gate 	extern char _ProtoCfg[];
7347c478bd9Sstevel@tonic-gate 
735004388ebScasper 	if ((f = fopen(CONFIG, "rF")) != 0) {
736*23a1cceaSRoger A. Faulkner 	while (getaline(f, buf) > 0) {
7377c478bd9Sstevel@tonic-gate 		/* got a (logical) line from Config file */
7387c478bd9Sstevel@tonic-gate 		tok = strtok(buf, " \t");
7397c478bd9Sstevel@tonic-gate 		if ((tok != NULL) && (*tok != '#')) {
7407c478bd9Sstevel@tonic-gate 			/* got a token */
74161961e0fSrobinson 			/*
74261961e0fSrobinson 			 * this probably should be table driven when
74361961e0fSrobinson 			 * the list of configurable parameters grows.
74461961e0fSrobinson 			 */
74561961e0fSrobinson 			if (strncmp("Protocol=", tok, strlen("Protocol=")) ==
74656295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 			    SAME) {
7477c478bd9Sstevel@tonic-gate 				tok += strlen("Protocol=");
7487c478bd9Sstevel@tonic-gate 				if (*tok != '\0') {
7497c478bd9Sstevel@tonic-gate 					if (_ProtoCfg[0] != '\0') {
7507c478bd9Sstevel@tonic-gate 						/*EMPTY*/
75161961e0fSrobinson 						DEBUG(7, "Protocol string %s ",
75256295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 						    tok);
75361961e0fSrobinson 						DEBUG(7, "overrides %s\n",
75456295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 						    _ProtoCfg);
7557c478bd9Sstevel@tonic-gate 					}
75661961e0fSrobinson 					(void) strcpy(_ProtoCfg, tok);
7577c478bd9Sstevel@tonic-gate 				}
7587c478bd9Sstevel@tonic-gate 			} else {
7597c478bd9Sstevel@tonic-gate 				/*EMPTY*/
76061961e0fSrobinson 				DEBUG(7, "Unknown configuration parameter %s\n",
76156295bc8SSreedhar Chalamalasetti - Sun Microsystems - Bangalore India 				    tok);
7627c478bd9Sstevel@tonic-gate 			}
7637c478bd9Sstevel@tonic-gate 		}
7647c478bd9Sstevel@tonic-gate 	}
7657c478bd9Sstevel@tonic-gate 	(void) fclose(f);
7667c478bd9Sstevel@tonic-gate 	}
7677c478bd9Sstevel@tonic-gate }
768