xref: /titanic_51/usr/src/cmd/bnu/sysfiles.c (revision 23a1ccea6aac035f084a7a4cdc968687d1b02daf)
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
5*23a1cceaSRoger A. Faulkner  * Common Development and Distribution License (the "License").
6*23a1cceaSRoger A. Faulkner  * 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  */
21*23a1cceaSRoger A. Faulkner 
227c478bd9Sstevel@tonic-gate /*
23*23a1cceaSRoger A. Faulkner  * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include "uucp.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include "sysfiles.h"
337c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * manage systems files (Systems, Devices, and Dialcodes families).
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * also manage new file Devconfig, allows per-device setup.
397c478bd9Sstevel@tonic-gate  * present use is to specify what streams modules to push/pop for
407c478bd9Sstevel@tonic-gate  * AT&T TLI/streams network.
417c478bd9Sstevel@tonic-gate  *
427c478bd9Sstevel@tonic-gate  * TODO:
437c478bd9Sstevel@tonic-gate  *    call bsfix()?
447c478bd9Sstevel@tonic-gate  *    combine the 3 versions of everything (sys, dev, and dial) into one.
457c478bd9Sstevel@tonic-gate  *    allow arbitrary classes of service.
467c478bd9Sstevel@tonic-gate  *    need verifysys() for uucheck.
477c478bd9Sstevel@tonic-gate  *    nameserver interface?
487c478bd9Sstevel@tonic-gate  *    pass sysname (or 0) to getsysline().  (might want reg. exp. or NS processing
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /* private variables */
527c478bd9Sstevel@tonic-gate static void tokenize(), nameparse(), setfile(), setioctl(),
537c478bd9Sstevel@tonic-gate 	scansys(), scancfg(), setconfig();
54*23a1cceaSRoger A. Faulkner static int namematch(), nextdialers(), nextdevices(), nextsystems(), getaline();
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /* pointer arrays might be dynamically allocated */
577c478bd9Sstevel@tonic-gate static char *Systems[64] = {0};	/* list of Systems files */
587c478bd9Sstevel@tonic-gate static char *Devices[64] = {0};	/* list of Devices files */
597c478bd9Sstevel@tonic-gate static char *Dialers[64] = {0};	/* list of Dialers files */
607c478bd9Sstevel@tonic-gate static char *Pops[64] = {0};	/* list of STREAMS modules to be popped */
617c478bd9Sstevel@tonic-gate static char *Pushes[64] = {0};	/* list of STREAMS modules to be pushed */
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate static int nsystems;		/* index into list of Systems files */
647c478bd9Sstevel@tonic-gate static int ndevices;		/* index into list of Devices files */
657c478bd9Sstevel@tonic-gate static int ndialers;		/* index into list of Dialers files */
667c478bd9Sstevel@tonic-gate static int npops;		/* index into list of STREAMS modules */
677c478bd9Sstevel@tonic-gate 							/*to be popped */
687c478bd9Sstevel@tonic-gate static int npushes;		/* index into list of STREAMS modules */
697c478bd9Sstevel@tonic-gate 							/*to be pushed */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate GLOBAL unsigned connecttime = CONNECTTIME;
727c478bd9Sstevel@tonic-gate GLOBAL unsigned expecttime = EXPECTTIME;
737c478bd9Sstevel@tonic-gate GLOBAL unsigned msgtime = MSGTIME;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static FILE *fsystems;
767c478bd9Sstevel@tonic-gate static FILE *fdevices;
777c478bd9Sstevel@tonic-gate static FILE *fdialers;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static char errformat[BUFSIZ];
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate /* this might be dynamically allocated */
827c478bd9Sstevel@tonic-gate #define NTOKENS 16
837c478bd9Sstevel@tonic-gate static char *tokens[NTOKENS], **tokptr;
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /* export these */
867c478bd9Sstevel@tonic-gate EXTERN void sysreset(), devreset(), dialreset(), setdevcfg(), setservice();
877c478bd9Sstevel@tonic-gate EXTERN char *strsave();
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* import these */
907c478bd9Sstevel@tonic-gate extern char *strcpy(), *strtok(), *strchr(), *strsave();
917c478bd9Sstevel@tonic-gate EXTERN int eaccess();
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate /*
947c478bd9Sstevel@tonic-gate  * setservice init's Systems, Devices, Dialers lists from Sysfiles
957c478bd9Sstevel@tonic-gate  */
967c478bd9Sstevel@tonic-gate GLOBAL void
977c478bd9Sstevel@tonic-gate setservice(service)
987c478bd9Sstevel@tonic-gate char *service;
997c478bd9Sstevel@tonic-gate {
1007c478bd9Sstevel@tonic-gate 	char	*prev = _uu_setlocale(LC_ALL, "C");
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	setconfig();
1037c478bd9Sstevel@tonic-gate 	scansys(service);
1047c478bd9Sstevel@tonic-gate 	(void) _uu_resetlocale(LC_ALL, prev);
1057c478bd9Sstevel@tonic-gate 	return;
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate  * setdevcfg init's Pops, Pushes lists from Devconfig
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate GLOBAL void
1137c478bd9Sstevel@tonic-gate setdevcfg(service, device)
1147c478bd9Sstevel@tonic-gate char *service, *device;
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	char	*prev = _uu_setlocale(LC_ALL, "C");
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	scancfg(service, device);
1197c478bd9Sstevel@tonic-gate 	(void) _uu_resetlocale(LC_ALL, prev);
1207c478bd9Sstevel@tonic-gate 	return;
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*	administrative files access */
1247c478bd9Sstevel@tonic-gate GLOBAL int
1257c478bd9Sstevel@tonic-gate sysaccess(type)
1267c478bd9Sstevel@tonic-gate int type;
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate 	switch (type) {
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	case ACCESS_SYSTEMS:
1317c478bd9Sstevel@tonic-gate 		return(access(Systems[nsystems], R_OK));
1327c478bd9Sstevel@tonic-gate 	case ACCESS_DEVICES:
1337c478bd9Sstevel@tonic-gate 		return(access(Devices[ndevices], R_OK));
1347c478bd9Sstevel@tonic-gate 	case ACCESS_DIALERS:
1357c478bd9Sstevel@tonic-gate 		return(access(Dialers[ndialers], R_OK));
1367c478bd9Sstevel@tonic-gate 	case EACCESS_SYSTEMS:
1377c478bd9Sstevel@tonic-gate 		return(eaccess(Systems[nsystems], R_OK));
1387c478bd9Sstevel@tonic-gate 	case EACCESS_DEVICES:
1397c478bd9Sstevel@tonic-gate 		return(eaccess(Devices[ndevices], R_OK));
1407c478bd9Sstevel@tonic-gate 	case EACCESS_DIALERS:
1417c478bd9Sstevel@tonic-gate 		return(eaccess(Dialers[ndialers], R_OK));
1427c478bd9Sstevel@tonic-gate 	default:
1437c478bd9Sstevel@tonic-gate 		(void)sprintf(errformat, "bad access type %d", type);
1447c478bd9Sstevel@tonic-gate 		logent(errformat, "sysaccess");
1457c478bd9Sstevel@tonic-gate 		return(FAIL);
1467c478bd9Sstevel@tonic-gate 	}
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * read Sysfiles, set up lists of Systems/Devices/Dialers file names.
1527c478bd9Sstevel@tonic-gate  * allow multiple entries for a given service, allow a service
1537c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., systems=foo:baz systems=bar.
1547c478bd9Sstevel@tonic-gate  */
1557c478bd9Sstevel@tonic-gate static void
1567c478bd9Sstevel@tonic-gate scansys(service)
1577c478bd9Sstevel@tonic-gate char *service;
1587c478bd9Sstevel@tonic-gate {	FILE *f;
1597c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	Systems[0] = Devices[0] = Dialers[0] = NULL;
1627c478bd9Sstevel@tonic-gate 	if ((f = fopen(SYSFILES, "r")) != 0) {
163*23a1cceaSRoger A. Faulkner 		while (getaline(f, buf) > 0) {
1647c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Sysfiles */
1657c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
1667c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
1677c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
1687c478bd9Sstevel@tonic-gate 				tokenize();
1697c478bd9Sstevel@tonic-gate 				nameparse();
1707c478bd9Sstevel@tonic-gate 			}
1717c478bd9Sstevel@tonic-gate 		}
1727c478bd9Sstevel@tonic-gate 		(void) fclose(f);
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* if didn't find entries in Sysfiles, use defaults */
1767c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL) {
1777c478bd9Sstevel@tonic-gate 		Systems[0] = strsave(SYSTEMS);
1787c478bd9Sstevel@tonic-gate 		ASSERT(Systems[0] != NULL, Ct_ALLOCATE, "scansys: Systems", 0);
1797c478bd9Sstevel@tonic-gate 		Systems[1] = NULL;
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL) {
1827c478bd9Sstevel@tonic-gate 		Devices[0] = strsave(DEVICES);
1837c478bd9Sstevel@tonic-gate 		ASSERT(Devices[0] != NULL, Ct_ALLOCATE, "scansys: Devices", 0);
1847c478bd9Sstevel@tonic-gate 		Devices[1] = NULL;
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL) {
1877c478bd9Sstevel@tonic-gate 		Dialers[0] = strsave(DIALERS);
1887c478bd9Sstevel@tonic-gate 		ASSERT(Dialers[0] != NULL, Ct_ALLOCATE, "scansys: Dialers", 0);
1897c478bd9Sstevel@tonic-gate 		Dialers[1] = NULL;
1907c478bd9Sstevel@tonic-gate 	}
1917c478bd9Sstevel@tonic-gate 	return;
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate  * read Devconfig.  allow multiple entries for a given service, allow a service
1977c478bd9Sstevel@tonic-gate  * type to describe resources more than once, e.g., push=foo:baz push=bar.
1987c478bd9Sstevel@tonic-gate  */
1997c478bd9Sstevel@tonic-gate static void
2007c478bd9Sstevel@tonic-gate scancfg(service, device)
2017c478bd9Sstevel@tonic-gate char *service, *device;
2027c478bd9Sstevel@tonic-gate {	FILE *f;
2037c478bd9Sstevel@tonic-gate 	char *tok, buf[BUFSIZ];
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	/* (re)initialize device-specific information */
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	npops = npushes = 0;
2087c478bd9Sstevel@tonic-gate 	Pops[0] = Pushes[0] = NULL;
2097c478bd9Sstevel@tonic-gate 	connecttime = CONNECTTIME;
2107c478bd9Sstevel@tonic-gate 	expecttime = EXPECTTIME;
2117c478bd9Sstevel@tonic-gate 	msgtime = MSGTIME;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	if ((f = fopen(DEVCONFIG, "r")) != 0) {
214*23a1cceaSRoger A. Faulkner 		while (getaline(f, buf) > 0) {
2157c478bd9Sstevel@tonic-gate 			/* got a (logical) line from Devconfig */
2167c478bd9Sstevel@tonic-gate 			/* strtok's of this buf continue in tokenize() */
2177c478bd9Sstevel@tonic-gate 			tok = strtok(buf, " \t");
2187c478bd9Sstevel@tonic-gate 			if (namematch("service=", tok, service)) {
2197c478bd9Sstevel@tonic-gate 				tok = strtok((char *)0, " \t");
2207c478bd9Sstevel@tonic-gate 				if ( namematch("device=", tok, device)) {
2217c478bd9Sstevel@tonic-gate 					tokenize();
2227c478bd9Sstevel@tonic-gate 					nameparse();
2237c478bd9Sstevel@tonic-gate 				}
2247c478bd9Sstevel@tonic-gate 			}
2257c478bd9Sstevel@tonic-gate 		}
2267c478bd9Sstevel@tonic-gate 		(void) fclose(f);
2277c478bd9Sstevel@tonic-gate 	}
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	return;
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate }
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  *  given a file pointer and buffer, construct logical line in buffer
2357c478bd9Sstevel@tonic-gate  *  (i.e., concatenate lines ending in '\').  return length of line
2367c478bd9Sstevel@tonic-gate  *  ASSUMES that buffer is BUFSIZ long!
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate static int
240*23a1cceaSRoger A. Faulkner getaline(f, line)
2417c478bd9Sstevel@tonic-gate FILE *f;
2427c478bd9Sstevel@tonic-gate 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
2707c478bd9Sstevel@tonic-gate namematch(label, line, name)
2717c478bd9Sstevel@tonic-gate char *label, *line, *name;
2727c478bd9Sstevel@tonic-gate {	char *lend;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	if (strncmp(label, line, strlen(label)) != SAME) {
2757c478bd9Sstevel@tonic-gate 		return(FALSE);	/* probably a comment line */
2767c478bd9Sstevel@tonic-gate 	}
2777c478bd9Sstevel@tonic-gate 	line += strlen(label);
2787c478bd9Sstevel@tonic-gate 	if (*line == '\0')
2797c478bd9Sstevel@tonic-gate 		return(FALSE);
2807c478bd9Sstevel@tonic-gate 	/*
2817c478bd9Sstevel@tonic-gate 	 * can't use strtok() in the following because scansys(),
2827c478bd9Sstevel@tonic-gate 	 * scancfg() do an initializing call to strtok() before
2837c478bd9Sstevel@tonic-gate 	 * coming here and then CONTINUE calling strtok() in tokenize(),
2847c478bd9Sstevel@tonic-gate 	 * after returning from namematch().
2857c478bd9Sstevel@tonic-gate 	 */
2867c478bd9Sstevel@tonic-gate 	while ((lend = strchr(line, ':')) != NULL) {
2877c478bd9Sstevel@tonic-gate 		*lend = '\0';
2887c478bd9Sstevel@tonic-gate 		if (strcmp(line, name) == SAME)
2897c478bd9Sstevel@tonic-gate 			return(TRUE);
2907c478bd9Sstevel@tonic-gate 		line = lend+1;
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 	return(strcmp(line, name) == SAME);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * tokenize() continues pulling tokens out of a buffer -- the
2977c478bd9Sstevel@tonic-gate  * initializing call to strtok must have been made before calling
2987c478bd9Sstevel@tonic-gate  * tokenize() -- and starts stuffing 'em into tokptr.
2997c478bd9Sstevel@tonic-gate  */
3007c478bd9Sstevel@tonic-gate static void
3017c478bd9Sstevel@tonic-gate tokenize()
3027c478bd9Sstevel@tonic-gate {	char *tok;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	tokptr = tokens;
3057c478bd9Sstevel@tonic-gate 	while ((tok = strtok((char *) 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 	return;
3127c478bd9Sstevel@tonic-gate }
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate  * look at top token in array: should be line of the form
3167c478bd9Sstevel@tonic-gate  *	name=item1:item2:item3...
3177c478bd9Sstevel@tonic-gate  * if name is one we recognize, then call set[file|ioctl] to set up
3187c478bd9Sstevel@tonic-gate  * corresponding list.  otherwise, log bad name.
3197c478bd9Sstevel@tonic-gate  */
3207c478bd9Sstevel@tonic-gate static void
3217c478bd9Sstevel@tonic-gate nameparse()
3227c478bd9Sstevel@tonic-gate {	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)
3507c478bd9Sstevel@tonic-gate 			setuint(msgtime, equals, MSGTIME);
3517c478bd9Sstevel@tonic-gate 		else {
3527c478bd9Sstevel@tonic-gate 			(void)sprintf(errformat,"unrecognized label %s",*line);
3537c478bd9Sstevel@tonic-gate 			logent(errformat, "Sysfiles|Devconfig");
3547c478bd9Sstevel@tonic-gate 		}
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 	return;
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate /*
3607c478bd9Sstevel@tonic-gate  * given the list for a particular type (systems, devices,...)
3617c478bd9Sstevel@tonic-gate  * and a line of colon-separated files, add 'em to list
3627c478bd9Sstevel@tonic-gate  */
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate static void
3657c478bd9Sstevel@tonic-gate setfile(type, line)
3667c478bd9Sstevel@tonic-gate char **type, *line;
3677c478bd9Sstevel@tonic-gate {	char **tptr, *tok;
3687c478bd9Sstevel@tonic-gate 	char expandpath[BUFSIZ];
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	if (*line == 0)
3717c478bd9Sstevel@tonic-gate 		return;
3727c478bd9Sstevel@tonic-gate 	tptr = type;
3737c478bd9Sstevel@tonic-gate 	while (*tptr)		/* skip over existing entries to*/
3747c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
3757c478bd9Sstevel@tonic-gate 
3767c478bd9Sstevel@tonic-gate 	for (tok = strtok(line, ":"); tok != NULL;
3777c478bd9Sstevel@tonic-gate 	tok = strtok((char *) NULL, ":")) {
3787c478bd9Sstevel@tonic-gate 		expandpath[0] = '\0';
3797c478bd9Sstevel@tonic-gate 		if ( *tok != '/' )
3807c478bd9Sstevel@tonic-gate 			/* by default, file names are relative to SYSDIR */
3817c478bd9Sstevel@tonic-gate 			sprintf(expandpath, "%s/", SYSDIR);
3827c478bd9Sstevel@tonic-gate 		strcat(expandpath, tok);
3837c478bd9Sstevel@tonic-gate 		if (eaccess(expandpath, R_OK) != 0)
3847c478bd9Sstevel@tonic-gate 			/* if we can't read it, no point in adding to list */
3857c478bd9Sstevel@tonic-gate 			continue;
3867c478bd9Sstevel@tonic-gate 		*tptr = strsave(expandpath);
3877c478bd9Sstevel@tonic-gate 		ASSERT(*tptr != NULL, Ct_ALLOCATE, "setfile: tptr", 0);
3887c478bd9Sstevel@tonic-gate 		tptr++;
3897c478bd9Sstevel@tonic-gate 	}
3907c478bd9Sstevel@tonic-gate 	return;
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate /*
3947c478bd9Sstevel@tonic-gate  * given the list for a particular ioctl (push, pop)
3957c478bd9Sstevel@tonic-gate  * and a line of colon-separated modules, add 'em to list
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate static void
3997c478bd9Sstevel@tonic-gate setioctl(type, line)
4007c478bd9Sstevel@tonic-gate char **type, *line;
4017c478bd9Sstevel@tonic-gate {	char **tptr, *tok;
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	if (*line == 0)
4047c478bd9Sstevel@tonic-gate 		return;
4057c478bd9Sstevel@tonic-gate 	tptr = type;
4067c478bd9Sstevel@tonic-gate 	while (*tptr)		/* skip over existing entries to*/
4077c478bd9Sstevel@tonic-gate 		tptr++;		/* concatenate multiple entries */
4087c478bd9Sstevel@tonic-gate 	for (tok = strtok(line, ":"); tok != NULL;
4097c478bd9Sstevel@tonic-gate 	tok = strtok((char *) 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 	return;
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * reset Systems files
4197c478bd9Sstevel@tonic-gate  */
4207c478bd9Sstevel@tonic-gate GLOBAL void
4217c478bd9Sstevel@tonic-gate sysreset()
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate 	if (fsystems)
4247c478bd9Sstevel@tonic-gate 		fclose(fsystems);
4257c478bd9Sstevel@tonic-gate 	fsystems = NULL;
4267c478bd9Sstevel@tonic-gate 	nsystems = 0;
4277c478bd9Sstevel@tonic-gate 	devreset();
4287c478bd9Sstevel@tonic-gate 	return;
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate /*
4327c478bd9Sstevel@tonic-gate  * reset Devices files
4337c478bd9Sstevel@tonic-gate  */
4347c478bd9Sstevel@tonic-gate GLOBAL void
4357c478bd9Sstevel@tonic-gate devreset()
4367c478bd9Sstevel@tonic-gate {
4377c478bd9Sstevel@tonic-gate 	if (fdevices)
4387c478bd9Sstevel@tonic-gate 		fclose(fdevices);
4397c478bd9Sstevel@tonic-gate 	fdevices = NULL;
4407c478bd9Sstevel@tonic-gate 	ndevices = 0;
4417c478bd9Sstevel@tonic-gate 	dialreset();
4427c478bd9Sstevel@tonic-gate 	return;
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate /*
4467c478bd9Sstevel@tonic-gate  * reset Dialers files
4477c478bd9Sstevel@tonic-gate  */
4487c478bd9Sstevel@tonic-gate GLOBAL void
4497c478bd9Sstevel@tonic-gate dialreset()
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate 	if (fdialers)
4527c478bd9Sstevel@tonic-gate 		fclose(fdialers);
4537c478bd9Sstevel@tonic-gate 	fdialers = NULL;
4547c478bd9Sstevel@tonic-gate 	ndialers = 0;
4557c478bd9Sstevel@tonic-gate 	return;
4567c478bd9Sstevel@tonic-gate }
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate /*
4597c478bd9Sstevel@tonic-gate  * get next line from Systems file
4607c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
4617c478bd9Sstevel@tonic-gate  */
4627c478bd9Sstevel@tonic-gate GLOBAL int
4637c478bd9Sstevel@tonic-gate getsysline(buf, len)
4647c478bd9Sstevel@tonic-gate char *buf;
4657c478bd9Sstevel@tonic-gate {
4667c478bd9Sstevel@tonic-gate 	char	*prev = _uu_setlocale(LC_ALL, "C");
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate 	if (Systems[0] == NULL)
4697c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
4707c478bd9Sstevel@tonic-gate 		setservice("uucico");
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	/* initialize devices and dialers whenever a new line is read */
4737c478bd9Sstevel@tonic-gate 	/* from systems */
4747c478bd9Sstevel@tonic-gate 	devreset();
4757c478bd9Sstevel@tonic-gate 	if (fsystems == NULL)
4767c478bd9Sstevel@tonic-gate 		if (nextsystems() == FALSE) {
4777c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
4787c478bd9Sstevel@tonic-gate 			return(FALSE);
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate 	ASSERT(len >= BUFSIZ, "BUFFER TOO SMALL", "getsysline", 0);
4827c478bd9Sstevel@tonic-gate 	for(;;) {
483*23a1cceaSRoger A. Faulkner 		while (getaline(fsystems, buf) != NULL)
4847c478bd9Sstevel@tonic-gate 		    if ((*buf != '#') && (*buf != ' ') &&
4857c478bd9Sstevel@tonic-gate 			(*buf != '\t') && (*buf != '\n')) {
4867c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
4877c478bd9Sstevel@tonic-gate 			return(TRUE);
4887c478bd9Sstevel@tonic-gate 		}
4897c478bd9Sstevel@tonic-gate 		if (nextsystems() == FALSE) {
4907c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
4917c478bd9Sstevel@tonic-gate 			return(FALSE);
4927c478bd9Sstevel@tonic-gate 		}
4937c478bd9Sstevel@tonic-gate 	}
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate /*
4977c478bd9Sstevel@tonic-gate  * move to next systems file.  return TRUE if successful, FALSE if not
4987c478bd9Sstevel@tonic-gate  */
4997c478bd9Sstevel@tonic-gate static int
5007c478bd9Sstevel@tonic-gate nextsystems()
5017c478bd9Sstevel@tonic-gate {
5027c478bd9Sstevel@tonic-gate 	devreset();
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	if (fsystems != NULL) {
5057c478bd9Sstevel@tonic-gate 		(void) fclose(fsystems);
5067c478bd9Sstevel@tonic-gate 		nsystems++;
5077c478bd9Sstevel@tonic-gate 	} else {
5087c478bd9Sstevel@tonic-gate 		nsystems = 0;
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 	for ( ; Systems[nsystems] != NULL; nsystems++)
5117c478bd9Sstevel@tonic-gate 		if ((fsystems = fopen(Systems[nsystems], "r")) != NULL)
5127c478bd9Sstevel@tonic-gate 			return(TRUE);
5137c478bd9Sstevel@tonic-gate 	return(FALSE);
5147c478bd9Sstevel@tonic-gate }
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate /*
5177c478bd9Sstevel@tonic-gate  * get next line from Devices file
5187c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5197c478bd9Sstevel@tonic-gate  */
5207c478bd9Sstevel@tonic-gate GLOBAL int
5217c478bd9Sstevel@tonic-gate getdevline(buf, len)
5227c478bd9Sstevel@tonic-gate char *buf;
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate 	char	*prev = _uu_setlocale(LC_ALL, "C");
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	if (Devices[0] == NULL)
5277c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5287c478bd9Sstevel@tonic-gate 		setservice("uucico");
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	if (fdevices == NULL)
5317c478bd9Sstevel@tonic-gate 		if (nextdevices() == FALSE) {
5327c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5337c478bd9Sstevel@tonic-gate 			return(FALSE);
5347c478bd9Sstevel@tonic-gate 		}
5357c478bd9Sstevel@tonic-gate 	for(;;) {
5367c478bd9Sstevel@tonic-gate 		if (fgets(buf, len, fdevices) != NULL) {
5377c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5387c478bd9Sstevel@tonic-gate 			return(TRUE);
5397c478bd9Sstevel@tonic-gate 		}
5407c478bd9Sstevel@tonic-gate 		if (nextdevices() == FALSE) {
5417c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5427c478bd9Sstevel@tonic-gate 			return(FALSE);
5437c478bd9Sstevel@tonic-gate 		}
5447c478bd9Sstevel@tonic-gate 	}
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate  * move to next devices file.  return TRUE if successful, FALSE if not
5497c478bd9Sstevel@tonic-gate  */
5507c478bd9Sstevel@tonic-gate static int
5517c478bd9Sstevel@tonic-gate nextdevices()
5527c478bd9Sstevel@tonic-gate {
5537c478bd9Sstevel@tonic-gate 	if (fdevices != NULL) {
5547c478bd9Sstevel@tonic-gate 		(void) fclose(fdevices);
5557c478bd9Sstevel@tonic-gate 		ndevices++;
5567c478bd9Sstevel@tonic-gate 	} else {
5577c478bd9Sstevel@tonic-gate 		ndevices = 0;
5587c478bd9Sstevel@tonic-gate 	}
5597c478bd9Sstevel@tonic-gate 	for ( ; Devices[ndevices] != NULL; ndevices++)
5607c478bd9Sstevel@tonic-gate 		if ((fdevices = fopen(Devices[ndevices], "r")) != NULL)
5617c478bd9Sstevel@tonic-gate 			return(TRUE);
5627c478bd9Sstevel@tonic-gate 	return(FALSE);
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate  * get next line from Dialers file
5687c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
5697c478bd9Sstevel@tonic-gate  */
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate GLOBAL int
5727c478bd9Sstevel@tonic-gate getdialline(buf, len)
5737c478bd9Sstevel@tonic-gate char *buf;
5747c478bd9Sstevel@tonic-gate {
5757c478bd9Sstevel@tonic-gate 	char	*prev = _uu_setlocale(LC_ALL, "C");
5767c478bd9Sstevel@tonic-gate 
5777c478bd9Sstevel@tonic-gate 	if (Dialers[0] == NULL)
5787c478bd9Sstevel@tonic-gate 		/* not initialized via setservice() - use default */
5797c478bd9Sstevel@tonic-gate 		setservice("uucico");
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	if (fdialers == NULL)
5827c478bd9Sstevel@tonic-gate 		if (nextdialers() == FALSE) {
5837c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5847c478bd9Sstevel@tonic-gate 			return(FALSE);
5857c478bd9Sstevel@tonic-gate 		}
5867c478bd9Sstevel@tonic-gate 	for(;;) {
5877c478bd9Sstevel@tonic-gate 		if (fgets(buf, len, fdialers) != NULL) {
5887c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5897c478bd9Sstevel@tonic-gate 			return(TRUE);
5907c478bd9Sstevel@tonic-gate 		}
5917c478bd9Sstevel@tonic-gate 		if (nextdialers() == FALSE) {
5927c478bd9Sstevel@tonic-gate 			(void) _uu_resetlocale(LC_ALL, prev);
5937c478bd9Sstevel@tonic-gate 			return(FALSE);
5947c478bd9Sstevel@tonic-gate 		}
5957c478bd9Sstevel@tonic-gate 	}
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate /*
5997c478bd9Sstevel@tonic-gate  * move to next dialers file.  return TRUE if successful, FALSE if not
6007c478bd9Sstevel@tonic-gate  */
6017c478bd9Sstevel@tonic-gate static int
6027c478bd9Sstevel@tonic-gate nextdialers()
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate 	if (fdialers) {
6057c478bd9Sstevel@tonic-gate 		(void) fclose(fdialers);
6067c478bd9Sstevel@tonic-gate 		ndialers++;
6077c478bd9Sstevel@tonic-gate 	} else {
6087c478bd9Sstevel@tonic-gate 		ndialers = 0;
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate 	for ( ; Dialers[ndialers] != NULL; ndialers++)
6127c478bd9Sstevel@tonic-gate 		if ((fdialers = fopen(Dialers[ndialers], "r")) != NULL)
6137c478bd9Sstevel@tonic-gate 			return(TRUE);
6147c478bd9Sstevel@tonic-gate 	return(FALSE);
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate /*
6187c478bd9Sstevel@tonic-gate  * get next module to be popped
6197c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6207c478bd9Sstevel@tonic-gate  */
6217c478bd9Sstevel@tonic-gate static int
6227c478bd9Sstevel@tonic-gate getpop(buf, len, optional)
6237c478bd9Sstevel@tonic-gate char *buf;
6247c478bd9Sstevel@tonic-gate int len, *optional;
6257c478bd9Sstevel@tonic-gate {
6267c478bd9Sstevel@tonic-gate 	int slen;
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	if ( Pops[0] == NULL || Pops[npops] == NULL )
6297c478bd9Sstevel@tonic-gate 		return(FALSE);
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	/*	if the module name is enclosed in parentheses,	*/
6327c478bd9Sstevel@tonic-gate 	/*	is optional. set flag & strip parens		*/
6337c478bd9Sstevel@tonic-gate 	slen = strlen(Pops[npops]) - 1;
6347c478bd9Sstevel@tonic-gate 	if ( Pops[npops][0] == '('  && Pops[npops][slen] == ')' ) {
6357c478bd9Sstevel@tonic-gate 		*optional = 1;
6367c478bd9Sstevel@tonic-gate 		len = ( slen < len ? slen : len );
6377c478bd9Sstevel@tonic-gate 		strncpy(buf, &(Pops[npops++][1]), len);
6387c478bd9Sstevel@tonic-gate 	} else {
6397c478bd9Sstevel@tonic-gate 		*optional = 0;
6407c478bd9Sstevel@tonic-gate 		strncpy(buf, Pops[npops++], len);
6417c478bd9Sstevel@tonic-gate 	}
6427c478bd9Sstevel@tonic-gate 	buf[len-1] = '\0';
6437c478bd9Sstevel@tonic-gate 	return(TRUE);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate 
6467c478bd9Sstevel@tonic-gate /*
6477c478bd9Sstevel@tonic-gate  * get next module to be pushed
6487c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6497c478bd9Sstevel@tonic-gate  */
6507c478bd9Sstevel@tonic-gate static int
6517c478bd9Sstevel@tonic-gate getpush(buf, len)
6527c478bd9Sstevel@tonic-gate char *buf;
6537c478bd9Sstevel@tonic-gate int len;
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate 	if ( Pushes[0] == NULL || Pushes[npushes] == NULL )
6567c478bd9Sstevel@tonic-gate 		return(FALSE);
6577c478bd9Sstevel@tonic-gate 	strncpy(buf, Pushes[npushes++], len);
6587c478bd9Sstevel@tonic-gate 	return(TRUE);
6597c478bd9Sstevel@tonic-gate }
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate  * pop/push requested modules
6637c478bd9Sstevel@tonic-gate  * return TRUE if successful, FALSE if not
6647c478bd9Sstevel@tonic-gate  */
6657c478bd9Sstevel@tonic-gate GLOBAL int
6667c478bd9Sstevel@tonic-gate pop_push(fd)
6677c478bd9Sstevel@tonic-gate int fd;
6687c478bd9Sstevel@tonic-gate {
6697c478bd9Sstevel@tonic-gate     char	strmod[FMNAMESZ], onstream[FMNAMESZ];
6707c478bd9Sstevel@tonic-gate     int		optional;
6717c478bd9Sstevel@tonic-gate     char	*prev = _uu_setlocale(LC_ALL, "C");
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate     /*	check for streams modules to pop	*/
6747c478bd9Sstevel@tonic-gate     while ( getpop(strmod, sizeof(strmod), &optional) ) {
6757c478bd9Sstevel@tonic-gate 	DEBUG(5, (optional ? "pop_push: optionally POPing %s\n"
6767c478bd9Sstevel@tonic-gate 			   : "pop_push: POPing %s\n" ), strmod);
6777c478bd9Sstevel@tonic-gate 	if ( ioctl(fd, I_LOOK, onstream) == -1 ) {
6787c478bd9Sstevel@tonic-gate 	    DEBUG(5, "pop_push: I_LOOK on fd %d failed ", fd);
6797c478bd9Sstevel@tonic-gate 	    DEBUG(5, "errno %d\n", errno);
6807c478bd9Sstevel@tonic-gate 	    (void) _uu_resetlocale(LC_ALL, prev);
6817c478bd9Sstevel@tonic-gate 	    return(FALSE);
6827c478bd9Sstevel@tonic-gate 	}
6837c478bd9Sstevel@tonic-gate 	if ( strcmp(strmod, onstream) != SAME ) {
6847c478bd9Sstevel@tonic-gate 	    if ( optional )
6857c478bd9Sstevel@tonic-gate 		continue;
6867c478bd9Sstevel@tonic-gate 	    DEBUG(5, "pop_push: I_POP: %s not there\n", strmod);
6877c478bd9Sstevel@tonic-gate 	    (void) _uu_resetlocale(LC_ALL, prev);
6887c478bd9Sstevel@tonic-gate 	    return(FALSE);
6897c478bd9Sstevel@tonic-gate 	}
6907c478bd9Sstevel@tonic-gate 	if ( ioctl(fd, I_POP, 0) == -1 ) {
6917c478bd9Sstevel@tonic-gate 	    DEBUG(5, "pop_push: I_POP on fd %d failed ", fd);
6927c478bd9Sstevel@tonic-gate 	    DEBUG(5, "errno %d\n", errno);
6937c478bd9Sstevel@tonic-gate 	    (void) _uu_resetlocale(LC_ALL, prev);
6947c478bd9Sstevel@tonic-gate 	    return(FALSE);
6957c478bd9Sstevel@tonic-gate 	}
6967c478bd9Sstevel@tonic-gate     }
6977c478bd9Sstevel@tonic-gate 
6987c478bd9Sstevel@tonic-gate     /*	check for streams modules to push	*/
6997c478bd9Sstevel@tonic-gate     while ( getpush(strmod, sizeof(strmod)) ) {
7007c478bd9Sstevel@tonic-gate 	DEBUG(5, "pop_push: PUSHing %s\n", strmod);
7017c478bd9Sstevel@tonic-gate 	if ( ioctl(fd, I_PUSH, strmod) == -1 ) {
7027c478bd9Sstevel@tonic-gate 	    DEBUG(5, "pop_push: I_PUSH on fd %d failed ", fd);
7037c478bd9Sstevel@tonic-gate 	    DEBUG(5, "errno %d\n", errno);
7047c478bd9Sstevel@tonic-gate 	    (void) _uu_resetlocale(LC_ALL, prev);
7057c478bd9Sstevel@tonic-gate 	    return(FALSE);
7067c478bd9Sstevel@tonic-gate 	}
7077c478bd9Sstevel@tonic-gate     }
7087c478bd9Sstevel@tonic-gate     (void) _uu_resetlocale(LC_ALL, prev);
7097c478bd9Sstevel@tonic-gate     return(TRUE);
7107c478bd9Sstevel@tonic-gate }
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate /*
7137c478bd9Sstevel@tonic-gate  * 	return name of currently open Systems file
7147c478bd9Sstevel@tonic-gate  */
7157c478bd9Sstevel@tonic-gate GLOBAL char *
7167c478bd9Sstevel@tonic-gate currsys()
7177c478bd9Sstevel@tonic-gate {
7187c478bd9Sstevel@tonic-gate 	return(Systems[nsystems]);
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate /*
7227c478bd9Sstevel@tonic-gate  * 	return name of currently open Devices file
7237c478bd9Sstevel@tonic-gate  */
7247c478bd9Sstevel@tonic-gate GLOBAL char *
7257c478bd9Sstevel@tonic-gate currdev()
7267c478bd9Sstevel@tonic-gate {
7277c478bd9Sstevel@tonic-gate 	return(Devices[ndevices]);
7287c478bd9Sstevel@tonic-gate }
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate /*
7317c478bd9Sstevel@tonic-gate  * 	return name of currently open Dialers file
7327c478bd9Sstevel@tonic-gate  */
7337c478bd9Sstevel@tonic-gate GLOBAL char *
7347c478bd9Sstevel@tonic-gate currdial()
7357c478bd9Sstevel@tonic-gate {
7367c478bd9Sstevel@tonic-gate 	return(Dialers[ndialers]);
7377c478bd9Sstevel@tonic-gate }
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate /*
7407c478bd9Sstevel@tonic-gate  * set configuration parameters provided in Config file
7417c478bd9Sstevel@tonic-gate  */
7427c478bd9Sstevel@tonic-gate static void
7437c478bd9Sstevel@tonic-gate setconfig()
7447c478bd9Sstevel@tonic-gate {
7457c478bd9Sstevel@tonic-gate     FILE *f;
7467c478bd9Sstevel@tonic-gate     char buf[BUFSIZ];
7477c478bd9Sstevel@tonic-gate     char *tok;
7487c478bd9Sstevel@tonic-gate     extern char _ProtoCfg[];
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate     if ((f = fopen(CONFIG, "r")) != 0) {
751*23a1cceaSRoger A. Faulkner 	while (getaline(f, buf) > 0) {
7527c478bd9Sstevel@tonic-gate 	    /* got a (logical) line from Config file */
7537c478bd9Sstevel@tonic-gate 	    tok = strtok(buf, " \t");
7547c478bd9Sstevel@tonic-gate 	    if ( (tok != NULL) && (*tok != '#') ) {
7557c478bd9Sstevel@tonic-gate 		/* got a token */
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 		/* this probably should be table driven when
7587c478bd9Sstevel@tonic-gate 		 * the list of configurable parameters grows.
7597c478bd9Sstevel@tonic-gate 		 */
7607c478bd9Sstevel@tonic-gate 		if (strncmp("Protocol=", tok, strlen("Protocol=")) == SAME) {
7617c478bd9Sstevel@tonic-gate 		    tok += strlen("Protocol=");
7627c478bd9Sstevel@tonic-gate 		    if ( *tok != '\0' ) {
7637c478bd9Sstevel@tonic-gate 			if ( _ProtoCfg[0] != '\0' ) {
7647c478bd9Sstevel@tonic-gate 			    DEBUG(7, "Protocol string %s ", tok);
7657c478bd9Sstevel@tonic-gate 			    DEBUG(7, "overrides %s\n", _ProtoCfg);
7667c478bd9Sstevel@tonic-gate 		        }
7677c478bd9Sstevel@tonic-gate 		        strcpy(_ProtoCfg, tok);
7687c478bd9Sstevel@tonic-gate 		    }
7697c478bd9Sstevel@tonic-gate 	        } else {
7707c478bd9Sstevel@tonic-gate 		    DEBUG(7, "Unknown configuration parameter %s\n", tok);
7717c478bd9Sstevel@tonic-gate 	        }
7727c478bd9Sstevel@tonic-gate 	    }
7737c478bd9Sstevel@tonic-gate 	}
7747c478bd9Sstevel@tonic-gate     }
7757c478bd9Sstevel@tonic-gate }
776