10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 22*132Srobinson 230Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 24*132Srobinson /* All Rights Reserved */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 27*132Srobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 280Sstevel@tonic-gate * Use is subject to license terms. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include "uucp.h" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <unistd.h> 36*132Srobinson #include <string.h> 370Sstevel@tonic-gate #include "sysfiles.h" 380Sstevel@tonic-gate #include <sys/stropts.h> 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* 410Sstevel@tonic-gate * manage systems files (Systems, Devices, and Dialcodes families). 420Sstevel@tonic-gate * 430Sstevel@tonic-gate * also manage new file Devconfig, allows per-device setup. 440Sstevel@tonic-gate * present use is to specify what streams modules to push/pop for 450Sstevel@tonic-gate * AT&T TLI/streams network. 460Sstevel@tonic-gate * 470Sstevel@tonic-gate * TODO: 480Sstevel@tonic-gate * call bsfix()? 490Sstevel@tonic-gate * combine the 3 versions of everything (sys, dev, and dial) into one. 500Sstevel@tonic-gate * allow arbitrary classes of service. 510Sstevel@tonic-gate * need verifysys() for uucheck. 520Sstevel@tonic-gate * nameserver interface? 53*132Srobinson * pass sysname (or 0) to getsysline(). (might want reg. exp. or 54*132Srobinson * NS processing) 550Sstevel@tonic-gate */ 560Sstevel@tonic-gate 570Sstevel@tonic-gate /* private variables */ 58*132Srobinson static void tokenize(void); 59*132Srobinson static void nameparse(void); 60*132Srobinson static void setfile(char **, char *); 61*132Srobinson static void setioctl(char **, char *); 62*132Srobinson static void scansys(const char *); 63*132Srobinson static void scancfg(char *, char *); 64*132Srobinson static void setconfig(void); 65*132Srobinson static int namematch(const char *label, char *line, const char *name); 66*132Srobinson static int nextdialers(void); 67*132Srobinson static int nextdevices(void); 68*132Srobinson static int nextsystems(void); 69*132Srobinson static int getline(FILE *, char *); 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* pointer arrays might be dynamically allocated */ 720Sstevel@tonic-gate static char *Systems[64]; /* list of Systems files */ 730Sstevel@tonic-gate static char *Devices[64]; /* list of Devices files */ 740Sstevel@tonic-gate static char *Dialers[64]; /* list of Dialers files */ 750Sstevel@tonic-gate static char *Pops[64]; /* list of STREAMS modules to be popped */ 760Sstevel@tonic-gate static char *Pushes[64]; /* list of STREAMS modules to be pushed */ 770Sstevel@tonic-gate 780Sstevel@tonic-gate static int nsystems; /* index into list of Systems files */ 790Sstevel@tonic-gate static int ndevices; /* index into list of Devices files */ 800Sstevel@tonic-gate static int ndialers; /* index into list of Dialers files */ 810Sstevel@tonic-gate static int npops; /* index into list of STREAMS modules */ 82*132Srobinson /* to be popped */ 830Sstevel@tonic-gate static int npushes; /* index into list of STREAMS modules */ 84*132Srobinson /* to be pushed */ 850Sstevel@tonic-gate 86*132Srobinson static unsigned connecttime, expecttime; 870Sstevel@tonic-gate 880Sstevel@tonic-gate static FILE *fsystems; 890Sstevel@tonic-gate static FILE *fdevices; 900Sstevel@tonic-gate static FILE *fdialers; 910Sstevel@tonic-gate 920Sstevel@tonic-gate /* this might be dynamically allocated */ 93*132Srobinson #define NTOKENS 16 940Sstevel@tonic-gate static char *tokens[NTOKENS], **tokptr; 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* export these */ 97*132Srobinson static void setservice(const char *service); 98*132Srobinson static void sysreset(void); 99*132Srobinson static void devreset(void); 100*132Srobinson static void dialreset(void); 101*132Srobinson static void setdevcfg(char *, char *); 102*132Srobinson static void setservice(const char *); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* import these */ 105*132Srobinson extern char *strsave(const char *); 106*132Srobinson static int eaccess(char *, mode_t); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * setservice init's Systems, Devices, Dialers lists from Sysfiles 1100Sstevel@tonic-gate */ 111*132Srobinson static void 112*132Srobinson setservice(const char *service) 1130Sstevel@tonic-gate { 1140Sstevel@tonic-gate setconfig(); 1150Sstevel@tonic-gate scansys(service); 1160Sstevel@tonic-gate } 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1190Sstevel@tonic-gate * setdevcfg init's Pops, Pushes lists from Devconfig 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate 122*132Srobinson static void 123*132Srobinson setdevcfg(char *service, char *device) 1240Sstevel@tonic-gate { 1250Sstevel@tonic-gate scancfg(service, device); 1260Sstevel@tonic-gate } 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* administrative files access */ 129*132Srobinson static int 130*132Srobinson sysaccess(int type) 1310Sstevel@tonic-gate { 132*132Srobinson char errformat[BUFSIZ]; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate switch (type) { 1350Sstevel@tonic-gate case ACCESS_SYSTEMS: 1360Sstevel@tonic-gate return (access(Systems[nsystems], R_OK)); 1370Sstevel@tonic-gate case ACCESS_DEVICES: 1380Sstevel@tonic-gate return (access(Devices[ndevices], R_OK)); 1390Sstevel@tonic-gate case ACCESS_DIALERS: 1400Sstevel@tonic-gate return (access(Dialers[ndialers], R_OK)); 1410Sstevel@tonic-gate case EACCESS_SYSTEMS: 142*132Srobinson return (eaccess(Systems[nsystems], R_OK)); 1430Sstevel@tonic-gate case EACCESS_DEVICES: 144*132Srobinson return (eaccess(Devices[ndevices], R_OK)); 1450Sstevel@tonic-gate case EACCESS_DIALERS: 146*132Srobinson return (eaccess(Dialers[ndialers], R_OK)); 1470Sstevel@tonic-gate } 148*132Srobinson (void) sprintf(errformat, "bad access type %d", type); 149*132Srobinson logent(errformat, "sysaccess"); 150*132Srobinson return (FAIL); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * read Sysfiles, set up lists of Systems/Devices/Dialers file names. 1560Sstevel@tonic-gate * allow multiple entries for a given service, allow a service 1570Sstevel@tonic-gate * type to describe resources more than once, e.g., systems=foo:baz systems=bar. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate static void 160*132Srobinson scansys(const char *service) 1610Sstevel@tonic-gate { FILE *f; 1620Sstevel@tonic-gate char *tok, buf[BUFSIZ]; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate Systems[0] = Devices[0] = Dialers[0] = NULL; 1650Sstevel@tonic-gate if ((f = fopen(SYSFILES, "r")) != 0) { 166*132Srobinson while (getline(f, buf) > 0) { 1670Sstevel@tonic-gate /* got a (logical) line from Sysfiles */ 1680Sstevel@tonic-gate /* strtok's of this buf continue in tokenize() */ 1690Sstevel@tonic-gate tok = strtok(buf, " \t"); 1700Sstevel@tonic-gate if (namematch("service=", tok, service)) { 1710Sstevel@tonic-gate tokenize(); 1720Sstevel@tonic-gate nameparse(); 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate (void) fclose(f); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* if didn't find entries in Sysfiles, use defaults */ 1790Sstevel@tonic-gate if (Systems[0] == NULL) { 1800Sstevel@tonic-gate Systems[0] = strsave(SYSTEMS); 181*132Srobinson ASSERT(Systems[0] != NULL, "Ct_ALLOCATE", "scansys: Systems", 182*132Srobinson 0); 1830Sstevel@tonic-gate Systems[1] = NULL; 1840Sstevel@tonic-gate } 1850Sstevel@tonic-gate if (Devices[0] == NULL) { 1860Sstevel@tonic-gate Devices[0] = strsave(DEVICES); 187*132Srobinson ASSERT(Devices[0] != NULL, "Ct_ALLOCATE", "scansys: Devices", 188*132Srobinson 0); 1890Sstevel@tonic-gate Devices[1] = NULL; 1900Sstevel@tonic-gate } 1910Sstevel@tonic-gate if (Dialers[0] == NULL) { 1920Sstevel@tonic-gate Dialers[0] = strsave(DIALERS); 193*132Srobinson ASSERT(Dialers[0] != NULL, "Ct_ALLOCATE", "scansys: Dialers", 194*132Srobinson 0); 1950Sstevel@tonic-gate Dialers[1] = NULL; 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * read Devconfig. allow multiple entries for a given service, allow a service 2020Sstevel@tonic-gate * type to describe resources more than once, e.g., push=foo:baz push=bar. 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate static void 205*132Srobinson scancfg(char *service, char *device) 2060Sstevel@tonic-gate { FILE *f; 2070Sstevel@tonic-gate char *tok, buf[BUFSIZ]; 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* (re)initialize device-specific information */ 2100Sstevel@tonic-gate npops = npushes = 0; 2110Sstevel@tonic-gate Pops[0] = Pushes[0] = NULL; 2120Sstevel@tonic-gate connecttime = CONNECTTIME; 2130Sstevel@tonic-gate expecttime = EXPECTTIME; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate if ((f = fopen(DEVCONFIG, "r")) != 0) { 2160Sstevel@tonic-gate while (getline(f, buf) > 0) { 2170Sstevel@tonic-gate /* got a (logical) line from Devconfig */ 2180Sstevel@tonic-gate /* strtok's of this buf continue in tokenize() */ 2190Sstevel@tonic-gate tok = strtok(buf, " \t"); 2200Sstevel@tonic-gate if (namematch("service=", tok, service)) { 2210Sstevel@tonic-gate tok = strtok((char *)0, " \t"); 2220Sstevel@tonic-gate if (namematch("device=", tok, device)) { 2230Sstevel@tonic-gate tokenize(); 2240Sstevel@tonic-gate nameparse(); 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate (void) fclose(f); 2290Sstevel@tonic-gate } 2300Sstevel@tonic-gate return; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate /* 2350Sstevel@tonic-gate * given a file pointer and buffer, construct logical line in buffer 2360Sstevel@tonic-gate * (i.e., concatenate lines ending in '\'). return length of line 2370Sstevel@tonic-gate * ASSUMES that buffer is BUFSIZ long! 2380Sstevel@tonic-gate */ 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate static int 241*132Srobinson getline(FILE *f, char *line) 2420Sstevel@tonic-gate { char *lptr, *lend; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate lptr = line; 2450Sstevel@tonic-gate while (fgets(lptr, (line + BUFSIZ) - lptr, f) != NULL) { 2460Sstevel@tonic-gate lend = lptr + strlen(lptr); 247*132Srobinson if (lend == lptr || lend[-1] != '\n') 2480Sstevel@tonic-gate /* empty buf or line too long! */ 2490Sstevel@tonic-gate break; 2500Sstevel@tonic-gate *--lend = '\0'; /* lop off ending '\n' */ 2510Sstevel@tonic-gate if (lend == line) /* empty line - ignore */ 2520Sstevel@tonic-gate continue; 2530Sstevel@tonic-gate lptr = lend; 2540Sstevel@tonic-gate if (lend[-1] != '\\') 2550Sstevel@tonic-gate break; 2560Sstevel@tonic-gate /* continuation */ 2570Sstevel@tonic-gate lend[-1] = ' '; 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate return (lptr - line); 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * given a label (e.g., "service=", "device="), a name ("cu", "uucico"), 2640Sstevel@tonic-gate * and a line: if line begins with the label and if the name appears 2650Sstevel@tonic-gate * in a colon-separated list of names following the label, return true; 2660Sstevel@tonic-gate * else return false 2670Sstevel@tonic-gate */ 2680Sstevel@tonic-gate static int 269*132Srobinson namematch(const char *label, char *line, const char *name) 270*132Srobinson { 271*132Srobinson char *lend; 2720Sstevel@tonic-gate 273*132Srobinson if (strncmp(label, line, strlen(label)) != SAME) 2740Sstevel@tonic-gate return (FALSE); /* probably a comment line */ 2750Sstevel@tonic-gate line += strlen(label); 276*132Srobinson if (*line == '\0') 2770Sstevel@tonic-gate return (FALSE); 2780Sstevel@tonic-gate /* 2790Sstevel@tonic-gate * can't use strtok() in the following because scansys(), 2800Sstevel@tonic-gate * scancfg() do an initializing call to strtok() before 2810Sstevel@tonic-gate * coming here and then CONTINUE calling strtok() in tokenize(), 2820Sstevel@tonic-gate * after returning from namematch(). 2830Sstevel@tonic-gate */ 2840Sstevel@tonic-gate while ((lend = strchr(line, ':')) != NULL) { 2850Sstevel@tonic-gate *lend = '\0'; 286*132Srobinson if (strcmp(line, name) == SAME) 2870Sstevel@tonic-gate return (TRUE); 2880Sstevel@tonic-gate line = lend+1; 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate return (strcmp(line, name) == SAME); 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * tokenize() continues pulling tokens out of a buffer -- the 2950Sstevel@tonic-gate * initializing call to strtok must have been made before calling 2960Sstevel@tonic-gate * tokenize() -- and starts stuffing 'em into tokptr. 2970Sstevel@tonic-gate */ 2980Sstevel@tonic-gate static void 299*132Srobinson tokenize(void) 300*132Srobinson { 301*132Srobinson char *tok; 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate tokptr = tokens; 304*132Srobinson while ((tok = strtok(NULL, " \t")) != NULL) { 3050Sstevel@tonic-gate *tokptr++ = tok; 3060Sstevel@tonic-gate if (tokptr - tokens >= NTOKENS) 3070Sstevel@tonic-gate break; 3080Sstevel@tonic-gate } 3090Sstevel@tonic-gate *tokptr = NULL; 3100Sstevel@tonic-gate } 3110Sstevel@tonic-gate 3120Sstevel@tonic-gate /* 3130Sstevel@tonic-gate * look at top token in array: should be line of the form 3140Sstevel@tonic-gate * name=item1:item2:item3... 315*132Srobinson * if name is one we recognize, then call set[file|ioctl] to set up 3160Sstevel@tonic-gate * corresponding list. otherwise, log bad name. 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate static void 319*132Srobinson nameparse(void) 320*132Srobinson { 321*132Srobinson char **line, *equals; 3220Sstevel@tonic-gate int temp; 3230Sstevel@tonic-gate 324*132Srobinson #define setuint(a, b, c) a = (((temp = atoi(b)) <= 0) ? (c) : temp) 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate for (line = tokens; (line - tokens) < NTOKENS && *line; line++) { 3270Sstevel@tonic-gate equals = strchr(*line, '='); 3280Sstevel@tonic-gate if (equals == NULL) 3290Sstevel@tonic-gate continue; /* may be meaningful someday? */ 3300Sstevel@tonic-gate *equals = '\0'; 3310Sstevel@tonic-gate /* ignore entry with empty rhs */ 3320Sstevel@tonic-gate if (*++equals == '\0') 3330Sstevel@tonic-gate continue; 3340Sstevel@tonic-gate if (strcmp(*line, "systems") == SAME) 3350Sstevel@tonic-gate setfile(Systems, equals); 3360Sstevel@tonic-gate else if (strcmp(*line, "devices") == SAME) 3370Sstevel@tonic-gate setfile(Devices, equals); 3380Sstevel@tonic-gate else if (strcmp(*line, "dialers") == SAME) 3390Sstevel@tonic-gate setfile(Dialers, equals); 3400Sstevel@tonic-gate else if (strcmp(*line, "pop") == SAME) 3410Sstevel@tonic-gate setioctl(Pops, equals); 3420Sstevel@tonic-gate else if (strcmp(*line, "push") == SAME) 3430Sstevel@tonic-gate setioctl(Pushes, equals); 3440Sstevel@tonic-gate else if (strcmp(*line, "connecttime") == SAME) 3450Sstevel@tonic-gate setuint(connecttime, equals, CONNECTTIME); 3460Sstevel@tonic-gate else if (strcmp(*line, "expecttime") == SAME) 3470Sstevel@tonic-gate setuint(expecttime, equals, EXPECTTIME); 3480Sstevel@tonic-gate else if (strcmp(*line, "msgtime") == SAME) 349*132Srobinson continue; 3500Sstevel@tonic-gate else { 3510Sstevel@tonic-gate char errformat[BUFSIZ]; 3520Sstevel@tonic-gate 353*132Srobinson (void) snprintf(errformat, sizeof (errformat), 354*132Srobinson "unrecognized label %s", *line); 3550Sstevel@tonic-gate logent(errformat, "Sysfiles|Devconfig"); 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate } 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate /* 3610Sstevel@tonic-gate * given the list for a particular type (systems, devices,...) 3620Sstevel@tonic-gate * and a line of colon-separated files, add 'em to list 3630Sstevel@tonic-gate */ 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate static void 366*132Srobinson setfile(char **type, char *line) 367*132Srobinson { 368*132Srobinson char **tptr, *tok; 3690Sstevel@tonic-gate char expandpath[BUFSIZ]; 3700Sstevel@tonic-gate 371*132Srobinson if (*line == 0) 3720Sstevel@tonic-gate return; 3730Sstevel@tonic-gate tptr = type; 374*132Srobinson while (*tptr) /* skip over existing entries to */ 3750Sstevel@tonic-gate tptr++; /* concatenate multiple entries */ 3760Sstevel@tonic-gate 377*132Srobinson for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) { 3780Sstevel@tonic-gate expandpath[0] = '\0'; 3790Sstevel@tonic-gate if (*tok != '/') 3800Sstevel@tonic-gate /* by default, file names are relative to SYSDIR */ 381*132Srobinson (void) snprintf(expandpath, sizeof (expandpath), 382*132Srobinson "%s/", SYSDIR); 383*132Srobinson (void) strcat(expandpath, tok); 3840Sstevel@tonic-gate if (eaccess(expandpath, R_OK) != 0) 3850Sstevel@tonic-gate /* if we can't read it, no point in adding to list */ 3860Sstevel@tonic-gate continue; 3870Sstevel@tonic-gate *tptr = strsave(expandpath); 3880Sstevel@tonic-gate ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setfile: tptr", 0); 3890Sstevel@tonic-gate tptr++; 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate /* 3940Sstevel@tonic-gate * given the list for a particular ioctl (push, pop) 3950Sstevel@tonic-gate * and a line of colon-separated modules, add 'em to list 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate static void 399*132Srobinson setioctl(char **type, char *line) 400*132Srobinson { 401*132Srobinson char **tptr, *tok; 4020Sstevel@tonic-gate 403*132Srobinson if (*line == 0) 4040Sstevel@tonic-gate return; 4050Sstevel@tonic-gate tptr = type; 406*132Srobinson while (*tptr) /* skip over existing entries to */ 4070Sstevel@tonic-gate tptr++; /* concatenate multiple entries */ 408*132Srobinson for (tok = strtok(line, ":"); tok != NULL; tok = strtok(NULL, ":")) { 4090Sstevel@tonic-gate *tptr = strsave(tok); 4100Sstevel@tonic-gate ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setioctl: tptr", 0); 4110Sstevel@tonic-gate tptr++; 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /* 4160Sstevel@tonic-gate * reset Systems files 4170Sstevel@tonic-gate */ 418*132Srobinson static void 419*132Srobinson sysreset(void) 4200Sstevel@tonic-gate { 4210Sstevel@tonic-gate if (fsystems) 422*132Srobinson (void) fclose(fsystems); 4230Sstevel@tonic-gate fsystems = NULL; 4240Sstevel@tonic-gate nsystems = 0; 4250Sstevel@tonic-gate devreset(); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate /* 4290Sstevel@tonic-gate * reset Devices files 4300Sstevel@tonic-gate */ 431*132Srobinson static void 432*132Srobinson devreset(void) 4330Sstevel@tonic-gate { 4340Sstevel@tonic-gate if (fdevices) 435*132Srobinson (void) fclose(fdevices); 4360Sstevel@tonic-gate fdevices = NULL; 4370Sstevel@tonic-gate ndevices = 0; 4380Sstevel@tonic-gate dialreset(); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* 4420Sstevel@tonic-gate * reset Dialers files 4430Sstevel@tonic-gate */ 444*132Srobinson static void 445*132Srobinson dialreset(void) 4460Sstevel@tonic-gate { 4470Sstevel@tonic-gate if (fdialers) 448*132Srobinson (void) fclose(fdialers); 4490Sstevel@tonic-gate fdialers = NULL; 4500Sstevel@tonic-gate ndialers = 0; 4510Sstevel@tonic-gate } 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate /* 4540Sstevel@tonic-gate * get next line from Systems file 4550Sstevel@tonic-gate * return TRUE if successful, FALSE if not 4560Sstevel@tonic-gate */ 457*132Srobinson static int 4580Sstevel@tonic-gate getsysline(char *buf, int len) 4590Sstevel@tonic-gate { 4600Sstevel@tonic-gate if (Systems[0] == NULL) 4610Sstevel@tonic-gate /* not initialized via setservice() - use default */ 4620Sstevel@tonic-gate setservice("uucico"); 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* initialize devices and dialers whenever a new line is read */ 4650Sstevel@tonic-gate /* from systems */ 4660Sstevel@tonic-gate devreset(); 4670Sstevel@tonic-gate if (fsystems == NULL) 468*132Srobinson if (nextsystems() == FALSE) 4690Sstevel@tonic-gate return (FALSE); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate for (;;) { 4720Sstevel@tonic-gate while (fgets(buf, len, fsystems) != NULL) 4730Sstevel@tonic-gate if ((*buf != '#') && (*buf != ' ') && 474*132Srobinson (*buf != '\t') && (*buf != '\n')) 4750Sstevel@tonic-gate return (TRUE); 476*132Srobinson if (nextsystems() == FALSE) 4770Sstevel@tonic-gate return (FALSE); 4780Sstevel@tonic-gate } 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * move to next systems file. return TRUE if successful, FALSE if not 4830Sstevel@tonic-gate */ 4840Sstevel@tonic-gate static int 485*132Srobinson nextsystems(void) 4860Sstevel@tonic-gate { 4870Sstevel@tonic-gate devreset(); 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate if (fsystems != NULL) { 4900Sstevel@tonic-gate (void) fclose(fsystems); 4910Sstevel@tonic-gate nsystems++; 4920Sstevel@tonic-gate } else { 4930Sstevel@tonic-gate nsystems = 0; 4940Sstevel@tonic-gate } 4950Sstevel@tonic-gate for (; Systems[nsystems] != NULL; nsystems++) 496*132Srobinson if ((fsystems = fopen(Systems[nsystems], "r")) != NULL) 4970Sstevel@tonic-gate return (TRUE); 4980Sstevel@tonic-gate return (FALSE); 4990Sstevel@tonic-gate } 500*132Srobinson 5010Sstevel@tonic-gate /* 5020Sstevel@tonic-gate * get next line from Devices file 5030Sstevel@tonic-gate * return TRUE if successful, FALSE if not 5040Sstevel@tonic-gate */ 505*132Srobinson static int 5060Sstevel@tonic-gate getdevline(char *buf, int len) 5070Sstevel@tonic-gate { 5080Sstevel@tonic-gate if (Devices[0] == NULL) 5090Sstevel@tonic-gate /* not initialized via setservice() - use default */ 5100Sstevel@tonic-gate setservice("uucico"); 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate if (fdevices == NULL) 513*132Srobinson if (nextdevices() == FALSE) 5140Sstevel@tonic-gate return (FALSE); 5150Sstevel@tonic-gate for (;;) { 516*132Srobinson if (fgets(buf, len, fdevices) != NULL) 5170Sstevel@tonic-gate return (TRUE); 518*132Srobinson if (nextdevices() == FALSE) 5190Sstevel@tonic-gate return (FALSE); 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate /* 5240Sstevel@tonic-gate * move to next devices file. return TRUE if successful, FALSE if not 5250Sstevel@tonic-gate */ 5260Sstevel@tonic-gate static int 527*132Srobinson nextdevices(void) 5280Sstevel@tonic-gate { 5290Sstevel@tonic-gate if (fdevices != NULL) { 5300Sstevel@tonic-gate (void) fclose(fdevices); 5310Sstevel@tonic-gate ndevices++; 5320Sstevel@tonic-gate } else { 5330Sstevel@tonic-gate ndevices = 0; 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate for (; Devices[ndevices] != NULL; ndevices++) 536*132Srobinson if ((fdevices = fopen(Devices[ndevices], "r")) != NULL) 5370Sstevel@tonic-gate return (TRUE); 5380Sstevel@tonic-gate return (FALSE); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 541*132Srobinson 5420Sstevel@tonic-gate /* 5430Sstevel@tonic-gate * get next line from Dialers file 5440Sstevel@tonic-gate * return TRUE if successful, FALSE if not 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate 547*132Srobinson static int 5480Sstevel@tonic-gate getdialline(char *buf, int len) 5490Sstevel@tonic-gate { 5500Sstevel@tonic-gate if (Dialers[0] == NULL) 5510Sstevel@tonic-gate /* not initialized via setservice() - use default */ 5520Sstevel@tonic-gate setservice("uucico"); 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate if (fdialers == NULL) 555*132Srobinson if (nextdialers() == FALSE) 5560Sstevel@tonic-gate return (FALSE); 5570Sstevel@tonic-gate for (;;) { 558*132Srobinson if (fgets(buf, len, fdialers) != NULL) 5590Sstevel@tonic-gate return (TRUE); 560*132Srobinson if (nextdialers() == FALSE) 5610Sstevel@tonic-gate return (FALSE); 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate } 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate /* 5660Sstevel@tonic-gate * move to next dialers file. return TRUE if successful, FALSE if not 5670Sstevel@tonic-gate */ 5680Sstevel@tonic-gate static int 569*132Srobinson nextdialers(void) 5700Sstevel@tonic-gate { 5710Sstevel@tonic-gate if (fdialers) { 5720Sstevel@tonic-gate (void) fclose(fdialers); 5730Sstevel@tonic-gate ndialers++; 5740Sstevel@tonic-gate } else { 5750Sstevel@tonic-gate ndialers = 0; 5760Sstevel@tonic-gate } 577*132Srobinson 5780Sstevel@tonic-gate for (; Dialers[ndialers] != NULL; ndialers++) 579*132Srobinson if ((fdialers = fopen(Dialers[ndialers], "r")) != NULL) 5800Sstevel@tonic-gate return (TRUE); 5810Sstevel@tonic-gate return (FALSE); 5820Sstevel@tonic-gate } 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate /* 5850Sstevel@tonic-gate * get next module to be popped 5860Sstevel@tonic-gate * return TRUE if successful, FALSE if not 5870Sstevel@tonic-gate */ 5880Sstevel@tonic-gate static int 589*132Srobinson getpop(char *buf, size_t len, int *optional) 5900Sstevel@tonic-gate { 5910Sstevel@tonic-gate int slen; 5920Sstevel@tonic-gate 593*132Srobinson if (Pops[0] == NULL || Pops[npops] == NULL) 5940Sstevel@tonic-gate return (FALSE); 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate /* if the module name is enclosed in parentheses, */ 5970Sstevel@tonic-gate /* is optional. set flag & strip parens */ 5980Sstevel@tonic-gate slen = strlen(Pops[npops]) - 1; 599*132Srobinson if (Pops[npops][0] == '(' && Pops[npops][slen] == ')') { 6000Sstevel@tonic-gate *optional = 1; 6010Sstevel@tonic-gate len = (slen < len ? slen : len); 602*132Srobinson (void) strncpy(buf, &(Pops[npops++][1]), len); 6030Sstevel@tonic-gate } else { 6040Sstevel@tonic-gate *optional = 0; 605*132Srobinson (void) strncpy(buf, Pops[npops++], len); 6060Sstevel@tonic-gate } 6070Sstevel@tonic-gate buf[len-1] = '\0'; 6080Sstevel@tonic-gate return (TRUE); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate /* 6120Sstevel@tonic-gate * get next module to be pushed 6130Sstevel@tonic-gate * return TRUE if successful, FALSE if not 6140Sstevel@tonic-gate */ 6150Sstevel@tonic-gate static int 616*132Srobinson getpush(char *buf, size_t len) 6170Sstevel@tonic-gate { 618*132Srobinson if (Pushes[0] == NULL || Pushes[npushes] == NULL) 6190Sstevel@tonic-gate return (FALSE); 620*132Srobinson (void) strncpy(buf, Pushes[npushes++], len); 6210Sstevel@tonic-gate return (TRUE); 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate /* 6250Sstevel@tonic-gate * pop/push requested modules 6260Sstevel@tonic-gate * return TRUE if successful, FALSE if not 6270Sstevel@tonic-gate */ 628*132Srobinson static int 629*132Srobinson pop_push(int fd) 6300Sstevel@tonic-gate { 6310Sstevel@tonic-gate char strmod[FMNAMESZ], onstream[FMNAMESZ]; 6320Sstevel@tonic-gate int optional; 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate /* check for streams modules to pop */ 635*132Srobinson while (getpop(strmod, sizeof (strmod), &optional)) { 6360Sstevel@tonic-gate DEBUG(5, (optional ? 637*132Srobinson (const char *)"pop_push: optionally POPing %s\n" : 638*132Srobinson (const char *)"pop_push: POPing %s\n"), strmod); 6390Sstevel@tonic-gate if (ioctl(fd, I_LOOK, onstream) == -1) { 6400Sstevel@tonic-gate DEBUG(5, "pop_push: I_LOOK on fd %d failed ", fd); 6410Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 6420Sstevel@tonic-gate return (FALSE); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate if (strcmp(strmod, onstream) != SAME) { 6450Sstevel@tonic-gate if (optional) 6460Sstevel@tonic-gate continue; 6470Sstevel@tonic-gate DEBUG(5, "pop_push: I_POP: %s not there\n", strmod); 6480Sstevel@tonic-gate return (FALSE); 6490Sstevel@tonic-gate } 6500Sstevel@tonic-gate if (ioctl(fd, I_POP, 0) == -1) { 6510Sstevel@tonic-gate DEBUG(5, "pop_push: I_POP on fd %d failed ", fd); 6520Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 6530Sstevel@tonic-gate return (FALSE); 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate /* check for streams modules to push */ 658*132Srobinson while (getpush(strmod, sizeof (strmod))) { 6590Sstevel@tonic-gate DEBUG(5, "pop_push: PUSHing %s\n", strmod); 6600Sstevel@tonic-gate if (ioctl(fd, I_PUSH, strmod) == -1) { 6610Sstevel@tonic-gate DEBUG(5, "pop_push: I_PUSH on fd %d failed ", fd); 6620Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 6630Sstevel@tonic-gate return (FALSE); 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate } 6660Sstevel@tonic-gate return (TRUE); 6670Sstevel@tonic-gate } 6680Sstevel@tonic-gate 669*132Srobinson #ifndef SMALL 6700Sstevel@tonic-gate /* 671*132Srobinson * return name of currently open Systems file 6720Sstevel@tonic-gate */ 673*132Srobinson static char * 674*132Srobinson currsys(void) 6750Sstevel@tonic-gate { 6760Sstevel@tonic-gate return (Systems[nsystems]); 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate /* 680*132Srobinson * return name of currently open Devices file 6810Sstevel@tonic-gate */ 682*132Srobinson static char * 683*132Srobinson currdev(void) 6840Sstevel@tonic-gate { 6850Sstevel@tonic-gate return (Devices[ndevices]); 6860Sstevel@tonic-gate } 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate /* 689*132Srobinson * return name of currently open Dialers file 6900Sstevel@tonic-gate */ 691*132Srobinson static char * 692*132Srobinson currdial(void) 6930Sstevel@tonic-gate { 6940Sstevel@tonic-gate return (Dialers[ndialers]); 6950Sstevel@tonic-gate } 696*132Srobinson #endif 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate /* 6990Sstevel@tonic-gate * set configuration parameters provided in Config file 7000Sstevel@tonic-gate */ 7010Sstevel@tonic-gate static void 702*132Srobinson setconfig(void) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate FILE *f; 7050Sstevel@tonic-gate char buf[BUFSIZ]; 7060Sstevel@tonic-gate char *tok; 7070Sstevel@tonic-gate extern char _ProtoCfg[]; 7080Sstevel@tonic-gate 7090Sstevel@tonic-gate if ((f = fopen(CONFIG, "r")) != 0) { 710*132Srobinson while (getline(f, buf) > 0) { 7110Sstevel@tonic-gate /* got a (logical) line from Config file */ 7120Sstevel@tonic-gate tok = strtok(buf, " \t"); 7130Sstevel@tonic-gate if ((tok != NULL) && (*tok != '#')) { 7140Sstevel@tonic-gate /* got a token */ 715*132Srobinson /* 716*132Srobinson * this probably should be table driven when 717*132Srobinson * the list of configurable parameters grows. 718*132Srobinson */ 719*132Srobinson if (strncmp("Protocol=", tok, strlen("Protocol=")) == 720*132Srobinson SAME) { 7210Sstevel@tonic-gate tok += strlen("Protocol="); 7220Sstevel@tonic-gate if (*tok != '\0') { 7230Sstevel@tonic-gate if (_ProtoCfg[0] != '\0') { 7240Sstevel@tonic-gate /*EMPTY*/ 725*132Srobinson DEBUG(7, "Protocol string %s ", 726*132Srobinson tok); 727*132Srobinson DEBUG(7, "overrides %s\n", 728*132Srobinson _ProtoCfg); 7290Sstevel@tonic-gate } 730*132Srobinson (void) strcpy(_ProtoCfg, tok); 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate } else { 7330Sstevel@tonic-gate /*EMPTY*/ 734*132Srobinson DEBUG(7, "Unknown configuration parameter %s\n", 735*132Srobinson tok); 7360Sstevel@tonic-gate } 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate (void) fclose(f); 7400Sstevel@tonic-gate } 7410Sstevel@tonic-gate } 742