1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 24*7c478bd9Sstevel@tonic-gate 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* 27*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 29*7c478bd9Sstevel@tonic-gate */ 30*7c478bd9Sstevel@tonic-gate 31*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include "uucp.h" 34*7c478bd9Sstevel@tonic-gate #include <rpc/trace.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <unistd.h> 37*7c478bd9Sstevel@tonic-gate #include "sysfiles.h" 38*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * manage systems files (Systems, Devices, and Dialcodes families). 42*7c478bd9Sstevel@tonic-gate * 43*7c478bd9Sstevel@tonic-gate * also manage new file Devconfig, allows per-device setup. 44*7c478bd9Sstevel@tonic-gate * present use is to specify what streams modules to push/pop for 45*7c478bd9Sstevel@tonic-gate * AT&T TLI/streams network. 46*7c478bd9Sstevel@tonic-gate * 47*7c478bd9Sstevel@tonic-gate * TODO: 48*7c478bd9Sstevel@tonic-gate * call bsfix()? 49*7c478bd9Sstevel@tonic-gate * combine the 3 versions of everything (sys, dev, and dial) into one. 50*7c478bd9Sstevel@tonic-gate * allow arbitrary classes of service. 51*7c478bd9Sstevel@tonic-gate * need verifysys() for uucheck. 52*7c478bd9Sstevel@tonic-gate * nameserver interface? 53*7c478bd9Sstevel@tonic-gate * pass sysname (or 0) to getsysline(). (might want reg. exp. or NS processing 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate /* private variables */ 57*7c478bd9Sstevel@tonic-gate static void tokenize(), nameparse(), setfile(), setioctl(), 58*7c478bd9Sstevel@tonic-gate scansys(), scancfg(), setconfig(); 59*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 60*7c478bd9Sstevel@tonic-gate static int namematch(const char *label, char *line, char *name); 61*7c478bd9Sstevel@tonic-gate #else 62*7c478bd9Sstevel@tonic-gate static int namematch(); 63*7c478bd9Sstevel@tonic-gate #endif 64*7c478bd9Sstevel@tonic-gate static int nextdialers(), nextdevices(), nextsystems(), getline(); 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate /* pointer arrays might be dynamically allocated */ 67*7c478bd9Sstevel@tonic-gate static char *Systems[64]; /* list of Systems files */ 68*7c478bd9Sstevel@tonic-gate static char *Devices[64]; /* list of Devices files */ 69*7c478bd9Sstevel@tonic-gate static char *Dialers[64]; /* list of Dialers files */ 70*7c478bd9Sstevel@tonic-gate static char *Pops[64]; /* list of STREAMS modules to be popped */ 71*7c478bd9Sstevel@tonic-gate static char *Pushes[64]; /* list of STREAMS modules to be pushed */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate static int nsystems; /* index into list of Systems files */ 74*7c478bd9Sstevel@tonic-gate static int ndevices; /* index into list of Devices files */ 75*7c478bd9Sstevel@tonic-gate static int ndialers; /* index into list of Dialers files */ 76*7c478bd9Sstevel@tonic-gate static int npops; /* index into list of STREAMS modules */ 77*7c478bd9Sstevel@tonic-gate /*to be popped */ 78*7c478bd9Sstevel@tonic-gate static int npushes; /* index into list of STREAMS modules */ 79*7c478bd9Sstevel@tonic-gate /*to be pushed */ 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate GLOBAL unsigned connecttime, expecttime, msgtime; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate static FILE *fsystems; 84*7c478bd9Sstevel@tonic-gate static FILE *fdevices; 85*7c478bd9Sstevel@tonic-gate static FILE *fdialers; 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate /* this might be dynamically allocated */ 88*7c478bd9Sstevel@tonic-gate #define NTOKENS 16 89*7c478bd9Sstevel@tonic-gate static char *tokens[NTOKENS], **tokptr; 90*7c478bd9Sstevel@tonic-gate 91*7c478bd9Sstevel@tonic-gate /* export these */ 92*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 93*7c478bd9Sstevel@tonic-gate EXTERN void setservice(const char *service); 94*7c478bd9Sstevel@tonic-gate #else 95*7c478bd9Sstevel@tonic-gate EXTERN void setservice(); 96*7c478bd9Sstevel@tonic-gate #endif 97*7c478bd9Sstevel@tonic-gate EXTERN void sysreset(), devreset(), dialreset(), setdevcfg(), setservice(); 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate /* import these */ 100*7c478bd9Sstevel@tonic-gate extern char *strcpy(), *strtok(), *strchr(), *strsave(); 101*7c478bd9Sstevel@tonic-gate EXTERN int eaccess(); 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate /* 104*7c478bd9Sstevel@tonic-gate * setservice init's Systems, Devices, Dialers lists from Sysfiles 105*7c478bd9Sstevel@tonic-gate */ 106*7c478bd9Sstevel@tonic-gate GLOBAL void 107*7c478bd9Sstevel@tonic-gate setservice(service) 108*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 109*7c478bd9Sstevel@tonic-gate const char *service; 110*7c478bd9Sstevel@tonic-gate #else 111*7c478bd9Sstevel@tonic-gate char *service; 112*7c478bd9Sstevel@tonic-gate #endif 113*7c478bd9Sstevel@tonic-gate { 114*7c478bd9Sstevel@tonic-gate trace1(TR_setservice, 0); 115*7c478bd9Sstevel@tonic-gate setconfig(); 116*7c478bd9Sstevel@tonic-gate scansys(service); 117*7c478bd9Sstevel@tonic-gate trace1(TR_setservice, 1); 118*7c478bd9Sstevel@tonic-gate return; 119*7c478bd9Sstevel@tonic-gate } 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * setdevcfg init's Pops, Pushes lists from Devconfig 123*7c478bd9Sstevel@tonic-gate */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate GLOBAL void 126*7c478bd9Sstevel@tonic-gate setdevcfg(service, device) 127*7c478bd9Sstevel@tonic-gate char *service, *device; 128*7c478bd9Sstevel@tonic-gate { 129*7c478bd9Sstevel@tonic-gate trace1(TR_setdevcfg, 0); 130*7c478bd9Sstevel@tonic-gate scancfg(service, device); 131*7c478bd9Sstevel@tonic-gate trace1(TR_setdevcfg, 1); 132*7c478bd9Sstevel@tonic-gate return; 133*7c478bd9Sstevel@tonic-gate } 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate /* administrative files access */ 136*7c478bd9Sstevel@tonic-gate GLOBAL int 137*7c478bd9Sstevel@tonic-gate sysaccess(type) 138*7c478bd9Sstevel@tonic-gate int type; 139*7c478bd9Sstevel@tonic-gate { 140*7c478bd9Sstevel@tonic-gate int dummy; 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate trace2(TR_sysaccess, 0, type); 143*7c478bd9Sstevel@tonic-gate switch (type) { 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate case ACCESS_SYSTEMS: 146*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 147*7c478bd9Sstevel@tonic-gate return (access(Systems[nsystems], R_OK)); 148*7c478bd9Sstevel@tonic-gate case ACCESS_DEVICES: 149*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 150*7c478bd9Sstevel@tonic-gate return (access(Devices[ndevices], R_OK)); 151*7c478bd9Sstevel@tonic-gate case ACCESS_DIALERS: 152*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 153*7c478bd9Sstevel@tonic-gate return (access(Dialers[ndialers], R_OK)); 154*7c478bd9Sstevel@tonic-gate case EACCESS_SYSTEMS: 155*7c478bd9Sstevel@tonic-gate dummy = eaccess(Systems[nsystems], R_OK); 156*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 157*7c478bd9Sstevel@tonic-gate return (dummy); 158*7c478bd9Sstevel@tonic-gate case EACCESS_DEVICES: 159*7c478bd9Sstevel@tonic-gate dummy = eaccess(Devices[ndevices], R_OK); 160*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 161*7c478bd9Sstevel@tonic-gate return (dummy); 162*7c478bd9Sstevel@tonic-gate case EACCESS_DIALERS: 163*7c478bd9Sstevel@tonic-gate dummy = eaccess(Dialers[ndialers], R_OK); 164*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 165*7c478bd9Sstevel@tonic-gate return (dummy); 166*7c478bd9Sstevel@tonic-gate default: { 167*7c478bd9Sstevel@tonic-gate char errformat[BUFSIZ]; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate (void) sprintf(errformat, "bad access type %d", type); 170*7c478bd9Sstevel@tonic-gate logent(errformat, "sysaccess"); 171*7c478bd9Sstevel@tonic-gate trace1(TR_sysaccess, 1); 172*7c478bd9Sstevel@tonic-gate return (FAIL); 173*7c478bd9Sstevel@tonic-gate } 174*7c478bd9Sstevel@tonic-gate } 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate /* 179*7c478bd9Sstevel@tonic-gate * read Sysfiles, set up lists of Systems/Devices/Dialers file names. 180*7c478bd9Sstevel@tonic-gate * allow multiple entries for a given service, allow a service 181*7c478bd9Sstevel@tonic-gate * type to describe resources more than once, e.g., systems=foo:baz systems=bar. 182*7c478bd9Sstevel@tonic-gate */ 183*7c478bd9Sstevel@tonic-gate static void 184*7c478bd9Sstevel@tonic-gate scansys(service) 185*7c478bd9Sstevel@tonic-gate char *service; 186*7c478bd9Sstevel@tonic-gate { FILE *f; 187*7c478bd9Sstevel@tonic-gate char *tok, buf[BUFSIZ]; 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate trace1(TR_scansys, 0); 190*7c478bd9Sstevel@tonic-gate Systems[0] = Devices[0] = Dialers[0] = NULL; 191*7c478bd9Sstevel@tonic-gate if ((f = fopen(SYSFILES, "r")) != 0) { 192*7c478bd9Sstevel@tonic-gate while (getline(f, buf) > 0) { 193*7c478bd9Sstevel@tonic-gate /* got a (logical) line from Sysfiles */ 194*7c478bd9Sstevel@tonic-gate /* strtok's of this buf continue in tokenize() */ 195*7c478bd9Sstevel@tonic-gate tok = strtok(buf, " \t"); 196*7c478bd9Sstevel@tonic-gate if (namematch("service=", tok, service)) { 197*7c478bd9Sstevel@tonic-gate tokenize(); 198*7c478bd9Sstevel@tonic-gate nameparse(); 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate } 201*7c478bd9Sstevel@tonic-gate (void) fclose(f); 202*7c478bd9Sstevel@tonic-gate } 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate /* if didn't find entries in Sysfiles, use defaults */ 205*7c478bd9Sstevel@tonic-gate if (Systems[0] == NULL) { 206*7c478bd9Sstevel@tonic-gate Systems[0] = strsave(SYSTEMS); 207*7c478bd9Sstevel@tonic-gate ASSERT(Systems[0] != NULL, "Ct_ALLOCATE", "scansys: Systems", 0); 208*7c478bd9Sstevel@tonic-gate Systems[1] = NULL; 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate if (Devices[0] == NULL) { 211*7c478bd9Sstevel@tonic-gate Devices[0] = strsave(DEVICES); 212*7c478bd9Sstevel@tonic-gate ASSERT(Devices[0] != NULL, "Ct_ALLOCATE", "scansys: Devices", 0); 213*7c478bd9Sstevel@tonic-gate Devices[1] = NULL; 214*7c478bd9Sstevel@tonic-gate } 215*7c478bd9Sstevel@tonic-gate if (Dialers[0] == NULL) { 216*7c478bd9Sstevel@tonic-gate Dialers[0] = strsave(DIALERS); 217*7c478bd9Sstevel@tonic-gate ASSERT(Dialers[0] != NULL, "Ct_ALLOCATE", "scansys: Dialers", 0); 218*7c478bd9Sstevel@tonic-gate Dialers[1] = NULL; 219*7c478bd9Sstevel@tonic-gate } 220*7c478bd9Sstevel@tonic-gate trace1(TR_scansys, 1); 221*7c478bd9Sstevel@tonic-gate return; 222*7c478bd9Sstevel@tonic-gate } 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate /* 226*7c478bd9Sstevel@tonic-gate * read Devconfig. allow multiple entries for a given service, allow a service 227*7c478bd9Sstevel@tonic-gate * type to describe resources more than once, e.g., push=foo:baz push=bar. 228*7c478bd9Sstevel@tonic-gate */ 229*7c478bd9Sstevel@tonic-gate static void 230*7c478bd9Sstevel@tonic-gate scancfg(service, device) 231*7c478bd9Sstevel@tonic-gate char *service, *device; 232*7c478bd9Sstevel@tonic-gate { FILE *f; 233*7c478bd9Sstevel@tonic-gate char *tok, buf[BUFSIZ]; 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate /* (re)initialize device-specific information */ 236*7c478bd9Sstevel@tonic-gate trace1(TR_scancfg, 0); 237*7c478bd9Sstevel@tonic-gate npops = npushes = 0; 238*7c478bd9Sstevel@tonic-gate Pops[0] = Pushes[0] = NULL; 239*7c478bd9Sstevel@tonic-gate connecttime = CONNECTTIME; 240*7c478bd9Sstevel@tonic-gate expecttime = EXPECTTIME; 241*7c478bd9Sstevel@tonic-gate msgtime = MSGTIME; 242*7c478bd9Sstevel@tonic-gate 243*7c478bd9Sstevel@tonic-gate if ((f = fopen(DEVCONFIG, "r")) != 0) { 244*7c478bd9Sstevel@tonic-gate while (getline(f, buf) > 0) { 245*7c478bd9Sstevel@tonic-gate /* got a (logical) line from Devconfig */ 246*7c478bd9Sstevel@tonic-gate /* strtok's of this buf continue in tokenize() */ 247*7c478bd9Sstevel@tonic-gate tok = strtok(buf, " \t"); 248*7c478bd9Sstevel@tonic-gate if (namematch("service=", tok, service)) { 249*7c478bd9Sstevel@tonic-gate tok = strtok((char *)0, " \t"); 250*7c478bd9Sstevel@tonic-gate if (namematch("device=", tok, device)) { 251*7c478bd9Sstevel@tonic-gate tokenize(); 252*7c478bd9Sstevel@tonic-gate nameparse(); 253*7c478bd9Sstevel@tonic-gate } 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate (void) fclose(f); 257*7c478bd9Sstevel@tonic-gate } 258*7c478bd9Sstevel@tonic-gate trace1(TR_scancfg, 1); 259*7c478bd9Sstevel@tonic-gate return; 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate } 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate /* 264*7c478bd9Sstevel@tonic-gate * given a file pointer and buffer, construct logical line in buffer 265*7c478bd9Sstevel@tonic-gate * (i.e., concatenate lines ending in '\'). return length of line 266*7c478bd9Sstevel@tonic-gate * ASSUMES that buffer is BUFSIZ long! 267*7c478bd9Sstevel@tonic-gate */ 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate static int 270*7c478bd9Sstevel@tonic-gate getline(f, line) 271*7c478bd9Sstevel@tonic-gate FILE *f; 272*7c478bd9Sstevel@tonic-gate char *line; 273*7c478bd9Sstevel@tonic-gate { char *lptr, *lend; 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate trace1(TR_getline, 0); 276*7c478bd9Sstevel@tonic-gate lptr = line; 277*7c478bd9Sstevel@tonic-gate while (fgets(lptr, (line + BUFSIZ) - lptr, f) != NULL) { 278*7c478bd9Sstevel@tonic-gate lend = lptr + strlen(lptr); 279*7c478bd9Sstevel@tonic-gate if (lend == lptr || lend[-1] != '\n') 280*7c478bd9Sstevel@tonic-gate /* empty buf or line too long! */ 281*7c478bd9Sstevel@tonic-gate break; 282*7c478bd9Sstevel@tonic-gate *--lend = '\0'; /* lop off ending '\n' */ 283*7c478bd9Sstevel@tonic-gate if (lend == line) /* empty line - ignore */ 284*7c478bd9Sstevel@tonic-gate continue; 285*7c478bd9Sstevel@tonic-gate lptr = lend; 286*7c478bd9Sstevel@tonic-gate if (lend[-1] != '\\') 287*7c478bd9Sstevel@tonic-gate break; 288*7c478bd9Sstevel@tonic-gate /* continuation */ 289*7c478bd9Sstevel@tonic-gate lend[-1] = ' '; 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate trace1(TR_getline, 1); 292*7c478bd9Sstevel@tonic-gate return (lptr - line); 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate 295*7c478bd9Sstevel@tonic-gate /* 296*7c478bd9Sstevel@tonic-gate * given a label (e.g., "service=", "device="), a name ("cu", "uucico"), 297*7c478bd9Sstevel@tonic-gate * and a line: if line begins with the label and if the name appears 298*7c478bd9Sstevel@tonic-gate * in a colon-separated list of names following the label, return true; 299*7c478bd9Sstevel@tonic-gate * else return false 300*7c478bd9Sstevel@tonic-gate */ 301*7c478bd9Sstevel@tonic-gate #if defined(__STDC__) 302*7c478bd9Sstevel@tonic-gate static int 303*7c478bd9Sstevel@tonic-gate namematch(const char *label, char *line, char *name) 304*7c478bd9Sstevel@tonic-gate #else 305*7c478bd9Sstevel@tonic-gate static int 306*7c478bd9Sstevel@tonic-gate namematch(label, line, name) 307*7c478bd9Sstevel@tonic-gate char *label, *line, *name; 308*7c478bd9Sstevel@tonic-gate #endif 309*7c478bd9Sstevel@tonic-gate { char *lend; 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate trace1(TR_namematch, 0); 312*7c478bd9Sstevel@tonic-gate if (strncmp(label, line, strlen(label)) != SAME) { 313*7c478bd9Sstevel@tonic-gate trace1(TR_namematch, 1); 314*7c478bd9Sstevel@tonic-gate return (FALSE); /* probably a comment line */ 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate line += strlen(label); 317*7c478bd9Sstevel@tonic-gate if (*line == '\0') { 318*7c478bd9Sstevel@tonic-gate trace1(TR_namematch, 1); 319*7c478bd9Sstevel@tonic-gate return (FALSE); 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate /* 322*7c478bd9Sstevel@tonic-gate * can't use strtok() in the following because scansys(), 323*7c478bd9Sstevel@tonic-gate * scancfg() do an initializing call to strtok() before 324*7c478bd9Sstevel@tonic-gate * coming here and then CONTINUE calling strtok() in tokenize(), 325*7c478bd9Sstevel@tonic-gate * after returning from namematch(). 326*7c478bd9Sstevel@tonic-gate */ 327*7c478bd9Sstevel@tonic-gate while ((lend = strchr(line, ':')) != NULL) { 328*7c478bd9Sstevel@tonic-gate *lend = '\0'; 329*7c478bd9Sstevel@tonic-gate if (strcmp(line, name) == SAME) { 330*7c478bd9Sstevel@tonic-gate trace1(TR_namematch, 1); 331*7c478bd9Sstevel@tonic-gate return (TRUE); 332*7c478bd9Sstevel@tonic-gate } 333*7c478bd9Sstevel@tonic-gate line = lend+1; 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate trace1(TR_namematch, 1); 336*7c478bd9Sstevel@tonic-gate return (strcmp(line, name) == SAME); 337*7c478bd9Sstevel@tonic-gate } 338*7c478bd9Sstevel@tonic-gate 339*7c478bd9Sstevel@tonic-gate /* 340*7c478bd9Sstevel@tonic-gate * tokenize() continues pulling tokens out of a buffer -- the 341*7c478bd9Sstevel@tonic-gate * initializing call to strtok must have been made before calling 342*7c478bd9Sstevel@tonic-gate * tokenize() -- and starts stuffing 'em into tokptr. 343*7c478bd9Sstevel@tonic-gate */ 344*7c478bd9Sstevel@tonic-gate static void 345*7c478bd9Sstevel@tonic-gate tokenize() 346*7c478bd9Sstevel@tonic-gate { char *tok; 347*7c478bd9Sstevel@tonic-gate 348*7c478bd9Sstevel@tonic-gate trace1(TR_tokenize, 0); 349*7c478bd9Sstevel@tonic-gate tokptr = tokens; 350*7c478bd9Sstevel@tonic-gate while ((tok = strtok((char *) NULL, " \t")) != NULL) { 351*7c478bd9Sstevel@tonic-gate *tokptr++ = tok; 352*7c478bd9Sstevel@tonic-gate if (tokptr - tokens >= NTOKENS) 353*7c478bd9Sstevel@tonic-gate break; 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate *tokptr = NULL; 356*7c478bd9Sstevel@tonic-gate trace1(TR_tokenize, 1); 357*7c478bd9Sstevel@tonic-gate return; 358*7c478bd9Sstevel@tonic-gate } 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate /* 361*7c478bd9Sstevel@tonic-gate * look at top token in array: should be line of the form 362*7c478bd9Sstevel@tonic-gate * name=item1:item2:item3... 363*7c478bd9Sstevel@tonic-gate * if name is one we recognize, then call set[file|ioctl] to set up 364*7c478bd9Sstevel@tonic-gate * corresponding list. otherwise, log bad name. 365*7c478bd9Sstevel@tonic-gate */ 366*7c478bd9Sstevel@tonic-gate static void 367*7c478bd9Sstevel@tonic-gate nameparse() 368*7c478bd9Sstevel@tonic-gate { char **line, *equals; 369*7c478bd9Sstevel@tonic-gate int temp; 370*7c478bd9Sstevel@tonic-gate 371*7c478bd9Sstevel@tonic-gate #define setuint(a,b,c) a = (((temp = atoi(b)) <= 0) ? (c) : temp) 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate trace1(TR_nameparse, 0); 374*7c478bd9Sstevel@tonic-gate for (line = tokens; (line - tokens) < NTOKENS && *line; line++) { 375*7c478bd9Sstevel@tonic-gate equals = strchr(*line, '='); 376*7c478bd9Sstevel@tonic-gate if (equals == NULL) 377*7c478bd9Sstevel@tonic-gate continue; /* may be meaningful someday? */ 378*7c478bd9Sstevel@tonic-gate *equals = '\0'; 379*7c478bd9Sstevel@tonic-gate /* ignore entry with empty rhs */ 380*7c478bd9Sstevel@tonic-gate if (*++equals == '\0') 381*7c478bd9Sstevel@tonic-gate continue; 382*7c478bd9Sstevel@tonic-gate if (strcmp(*line, "systems") == SAME) 383*7c478bd9Sstevel@tonic-gate setfile(Systems, equals); 384*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "devices") == SAME) 385*7c478bd9Sstevel@tonic-gate setfile(Devices, equals); 386*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "dialers") == SAME) 387*7c478bd9Sstevel@tonic-gate setfile(Dialers, equals); 388*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "pop") == SAME) 389*7c478bd9Sstevel@tonic-gate setioctl(Pops, equals); 390*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "push") == SAME) 391*7c478bd9Sstevel@tonic-gate setioctl(Pushes, equals); 392*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "connecttime") == SAME) 393*7c478bd9Sstevel@tonic-gate setuint(connecttime, equals, CONNECTTIME); 394*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "expecttime") == SAME) 395*7c478bd9Sstevel@tonic-gate setuint(expecttime, equals, EXPECTTIME); 396*7c478bd9Sstevel@tonic-gate else if (strcmp(*line, "msgtime") == SAME) 397*7c478bd9Sstevel@tonic-gate setuint(msgtime, equals, MSGTIME); 398*7c478bd9Sstevel@tonic-gate else { 399*7c478bd9Sstevel@tonic-gate char errformat[BUFSIZ]; 400*7c478bd9Sstevel@tonic-gate 401*7c478bd9Sstevel@tonic-gate (void) sprintf(errformat,"unrecognized label %s",*line); 402*7c478bd9Sstevel@tonic-gate logent(errformat, "Sysfiles|Devconfig"); 403*7c478bd9Sstevel@tonic-gate } 404*7c478bd9Sstevel@tonic-gate } 405*7c478bd9Sstevel@tonic-gate trace1(TR_nameparse, 1); 406*7c478bd9Sstevel@tonic-gate return; 407*7c478bd9Sstevel@tonic-gate } 408*7c478bd9Sstevel@tonic-gate 409*7c478bd9Sstevel@tonic-gate /* 410*7c478bd9Sstevel@tonic-gate * given the list for a particular type (systems, devices,...) 411*7c478bd9Sstevel@tonic-gate * and a line of colon-separated files, add 'em to list 412*7c478bd9Sstevel@tonic-gate */ 413*7c478bd9Sstevel@tonic-gate 414*7c478bd9Sstevel@tonic-gate static void 415*7c478bd9Sstevel@tonic-gate setfile(type, line) 416*7c478bd9Sstevel@tonic-gate char **type, *line; 417*7c478bd9Sstevel@tonic-gate { char **tptr, *tok; 418*7c478bd9Sstevel@tonic-gate char expandpath[BUFSIZ]; 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate trace1(TR_setfile, 0); 421*7c478bd9Sstevel@tonic-gate if (*line == 0) { 422*7c478bd9Sstevel@tonic-gate trace1(TR_setfile, 1); 423*7c478bd9Sstevel@tonic-gate return; 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate tptr = type; 426*7c478bd9Sstevel@tonic-gate while (*tptr) /* skip over existing entries to*/ 427*7c478bd9Sstevel@tonic-gate tptr++; /* concatenate multiple entries */ 428*7c478bd9Sstevel@tonic-gate 429*7c478bd9Sstevel@tonic-gate for (tok = strtok(line, ":"); tok != NULL; 430*7c478bd9Sstevel@tonic-gate tok = strtok((char *) NULL, ":")) { 431*7c478bd9Sstevel@tonic-gate expandpath[0] = '\0'; 432*7c478bd9Sstevel@tonic-gate if (*tok != '/') 433*7c478bd9Sstevel@tonic-gate /* by default, file names are relative to SYSDIR */ 434*7c478bd9Sstevel@tonic-gate sprintf(expandpath, "%s/", SYSDIR); 435*7c478bd9Sstevel@tonic-gate strcat(expandpath, tok); 436*7c478bd9Sstevel@tonic-gate if (eaccess(expandpath, R_OK) != 0) 437*7c478bd9Sstevel@tonic-gate /* if we can't read it, no point in adding to list */ 438*7c478bd9Sstevel@tonic-gate continue; 439*7c478bd9Sstevel@tonic-gate *tptr = strsave(expandpath); 440*7c478bd9Sstevel@tonic-gate ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setfile: tptr", 0); 441*7c478bd9Sstevel@tonic-gate tptr++; 442*7c478bd9Sstevel@tonic-gate } 443*7c478bd9Sstevel@tonic-gate trace1(TR_setfile, 1); 444*7c478bd9Sstevel@tonic-gate return; 445*7c478bd9Sstevel@tonic-gate } 446*7c478bd9Sstevel@tonic-gate 447*7c478bd9Sstevel@tonic-gate /* 448*7c478bd9Sstevel@tonic-gate * given the list for a particular ioctl (push, pop) 449*7c478bd9Sstevel@tonic-gate * and a line of colon-separated modules, add 'em to list 450*7c478bd9Sstevel@tonic-gate */ 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate static void 453*7c478bd9Sstevel@tonic-gate setioctl(type, line) 454*7c478bd9Sstevel@tonic-gate char **type, *line; 455*7c478bd9Sstevel@tonic-gate { char **tptr, *tok; 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate trace1(TR_setioctl, 0); 458*7c478bd9Sstevel@tonic-gate if (*line == 0) { 459*7c478bd9Sstevel@tonic-gate trace1(TR_setioctl, 1); 460*7c478bd9Sstevel@tonic-gate return; 461*7c478bd9Sstevel@tonic-gate } 462*7c478bd9Sstevel@tonic-gate tptr = type; 463*7c478bd9Sstevel@tonic-gate while (*tptr) /* skip over existing entries to*/ 464*7c478bd9Sstevel@tonic-gate tptr++; /* concatenate multiple entries */ 465*7c478bd9Sstevel@tonic-gate for (tok = strtok(line, ":"); tok != NULL; 466*7c478bd9Sstevel@tonic-gate tok = strtok((char *) NULL, ":")) { 467*7c478bd9Sstevel@tonic-gate *tptr = strsave(tok); 468*7c478bd9Sstevel@tonic-gate ASSERT(*tptr != NULL, "Ct_ALLOCATE", "setioctl: tptr", 0); 469*7c478bd9Sstevel@tonic-gate tptr++; 470*7c478bd9Sstevel@tonic-gate } 471*7c478bd9Sstevel@tonic-gate trace1(TR_setioctl, 1); 472*7c478bd9Sstevel@tonic-gate return; 473*7c478bd9Sstevel@tonic-gate } 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate /* 476*7c478bd9Sstevel@tonic-gate * reset Systems files 477*7c478bd9Sstevel@tonic-gate */ 478*7c478bd9Sstevel@tonic-gate GLOBAL void 479*7c478bd9Sstevel@tonic-gate sysreset() 480*7c478bd9Sstevel@tonic-gate { 481*7c478bd9Sstevel@tonic-gate trace1(TR_sysreset, 0); 482*7c478bd9Sstevel@tonic-gate if (fsystems) 483*7c478bd9Sstevel@tonic-gate fclose(fsystems); 484*7c478bd9Sstevel@tonic-gate fsystems = NULL; 485*7c478bd9Sstevel@tonic-gate nsystems = 0; 486*7c478bd9Sstevel@tonic-gate devreset(); 487*7c478bd9Sstevel@tonic-gate trace1(TR_sysreset, 1); 488*7c478bd9Sstevel@tonic-gate return; 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate /* 492*7c478bd9Sstevel@tonic-gate * reset Devices files 493*7c478bd9Sstevel@tonic-gate */ 494*7c478bd9Sstevel@tonic-gate GLOBAL void 495*7c478bd9Sstevel@tonic-gate devreset() 496*7c478bd9Sstevel@tonic-gate { 497*7c478bd9Sstevel@tonic-gate trace1(TR_devreset, 0); 498*7c478bd9Sstevel@tonic-gate if (fdevices) 499*7c478bd9Sstevel@tonic-gate fclose(fdevices); 500*7c478bd9Sstevel@tonic-gate fdevices = NULL; 501*7c478bd9Sstevel@tonic-gate ndevices = 0; 502*7c478bd9Sstevel@tonic-gate dialreset(); 503*7c478bd9Sstevel@tonic-gate trace1(TR_devreset, 1); 504*7c478bd9Sstevel@tonic-gate return; 505*7c478bd9Sstevel@tonic-gate } 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate /* 508*7c478bd9Sstevel@tonic-gate * reset Dialers files 509*7c478bd9Sstevel@tonic-gate */ 510*7c478bd9Sstevel@tonic-gate GLOBAL void 511*7c478bd9Sstevel@tonic-gate dialreset() 512*7c478bd9Sstevel@tonic-gate { 513*7c478bd9Sstevel@tonic-gate trace1(TR_dialreset, 0); 514*7c478bd9Sstevel@tonic-gate if (fdialers) 515*7c478bd9Sstevel@tonic-gate fclose(fdialers); 516*7c478bd9Sstevel@tonic-gate fdialers = NULL; 517*7c478bd9Sstevel@tonic-gate ndialers = 0; 518*7c478bd9Sstevel@tonic-gate trace1(TR_dialreset, 1); 519*7c478bd9Sstevel@tonic-gate return; 520*7c478bd9Sstevel@tonic-gate } 521*7c478bd9Sstevel@tonic-gate 522*7c478bd9Sstevel@tonic-gate /* 523*7c478bd9Sstevel@tonic-gate * get next line from Systems file 524*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 525*7c478bd9Sstevel@tonic-gate */ 526*7c478bd9Sstevel@tonic-gate GLOBAL int 527*7c478bd9Sstevel@tonic-gate getsysline(char *buf, int len) 528*7c478bd9Sstevel@tonic-gate { 529*7c478bd9Sstevel@tonic-gate trace2(TR_getsysline, 0, len); 530*7c478bd9Sstevel@tonic-gate if (Systems[0] == NULL) 531*7c478bd9Sstevel@tonic-gate /* not initialized via setservice() - use default */ 532*7c478bd9Sstevel@tonic-gate setservice("uucico"); 533*7c478bd9Sstevel@tonic-gate 534*7c478bd9Sstevel@tonic-gate /* initialize devices and dialers whenever a new line is read */ 535*7c478bd9Sstevel@tonic-gate /* from systems */ 536*7c478bd9Sstevel@tonic-gate devreset(); 537*7c478bd9Sstevel@tonic-gate if (fsystems == NULL) 538*7c478bd9Sstevel@tonic-gate if (nextsystems() == FALSE) { 539*7c478bd9Sstevel@tonic-gate trace1(TR_getsysline, 1); 540*7c478bd9Sstevel@tonic-gate return (FALSE); 541*7c478bd9Sstevel@tonic-gate } 542*7c478bd9Sstevel@tonic-gate 543*7c478bd9Sstevel@tonic-gate for (;;) { 544*7c478bd9Sstevel@tonic-gate while (fgets(buf, len, fsystems) != NULL) 545*7c478bd9Sstevel@tonic-gate if ((*buf != '#') && (*buf != ' ') && 546*7c478bd9Sstevel@tonic-gate (*buf != '\t') && (*buf != '\n')) { 547*7c478bd9Sstevel@tonic-gate trace1(TR_getsysline, 1); 548*7c478bd9Sstevel@tonic-gate return (TRUE); 549*7c478bd9Sstevel@tonic-gate } 550*7c478bd9Sstevel@tonic-gate if (nextsystems() == FALSE) { 551*7c478bd9Sstevel@tonic-gate trace1(TR_getsysline, 1); 552*7c478bd9Sstevel@tonic-gate return (FALSE); 553*7c478bd9Sstevel@tonic-gate } 554*7c478bd9Sstevel@tonic-gate } 555*7c478bd9Sstevel@tonic-gate } 556*7c478bd9Sstevel@tonic-gate 557*7c478bd9Sstevel@tonic-gate /* 558*7c478bd9Sstevel@tonic-gate * move to next systems file. return TRUE if successful, FALSE if not 559*7c478bd9Sstevel@tonic-gate */ 560*7c478bd9Sstevel@tonic-gate static int 561*7c478bd9Sstevel@tonic-gate nextsystems() 562*7c478bd9Sstevel@tonic-gate { 563*7c478bd9Sstevel@tonic-gate trace1(TR_nextsystems, 0); 564*7c478bd9Sstevel@tonic-gate devreset(); 565*7c478bd9Sstevel@tonic-gate 566*7c478bd9Sstevel@tonic-gate if (fsystems != NULL) { 567*7c478bd9Sstevel@tonic-gate (void) fclose(fsystems); 568*7c478bd9Sstevel@tonic-gate nsystems++; 569*7c478bd9Sstevel@tonic-gate } else { 570*7c478bd9Sstevel@tonic-gate nsystems = 0; 571*7c478bd9Sstevel@tonic-gate } 572*7c478bd9Sstevel@tonic-gate for (; Systems[nsystems] != NULL; nsystems++) 573*7c478bd9Sstevel@tonic-gate if ((fsystems = fopen(Systems[nsystems], "r")) != NULL) { 574*7c478bd9Sstevel@tonic-gate trace1(TR_nextsystems, 1); 575*7c478bd9Sstevel@tonic-gate return (TRUE); 576*7c478bd9Sstevel@tonic-gate } 577*7c478bd9Sstevel@tonic-gate trace1(TR_nextsystems, 1); 578*7c478bd9Sstevel@tonic-gate return (FALSE); 579*7c478bd9Sstevel@tonic-gate } 580*7c478bd9Sstevel@tonic-gate 581*7c478bd9Sstevel@tonic-gate /* 582*7c478bd9Sstevel@tonic-gate * get next line from Devices file 583*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 584*7c478bd9Sstevel@tonic-gate */ 585*7c478bd9Sstevel@tonic-gate GLOBAL int 586*7c478bd9Sstevel@tonic-gate getdevline(char *buf, int len) 587*7c478bd9Sstevel@tonic-gate { 588*7c478bd9Sstevel@tonic-gate trace2(TR_getdevline, 0, len); 589*7c478bd9Sstevel@tonic-gate if (Devices[0] == NULL) 590*7c478bd9Sstevel@tonic-gate /* not initialized via setservice() - use default */ 591*7c478bd9Sstevel@tonic-gate setservice("uucico"); 592*7c478bd9Sstevel@tonic-gate 593*7c478bd9Sstevel@tonic-gate if (fdevices == NULL) 594*7c478bd9Sstevel@tonic-gate if (nextdevices() == FALSE) { 595*7c478bd9Sstevel@tonic-gate trace1(TR_getdevline, 1); 596*7c478bd9Sstevel@tonic-gate return (FALSE); 597*7c478bd9Sstevel@tonic-gate } 598*7c478bd9Sstevel@tonic-gate for (;;) { 599*7c478bd9Sstevel@tonic-gate if (fgets(buf, len, fdevices) != NULL) { 600*7c478bd9Sstevel@tonic-gate trace1(TR_getdevline, 1); 601*7c478bd9Sstevel@tonic-gate return (TRUE); 602*7c478bd9Sstevel@tonic-gate } 603*7c478bd9Sstevel@tonic-gate if (nextdevices() == FALSE) { 604*7c478bd9Sstevel@tonic-gate trace1(TR_getdevline, 1); 605*7c478bd9Sstevel@tonic-gate return (FALSE); 606*7c478bd9Sstevel@tonic-gate } 607*7c478bd9Sstevel@tonic-gate } 608*7c478bd9Sstevel@tonic-gate } 609*7c478bd9Sstevel@tonic-gate 610*7c478bd9Sstevel@tonic-gate /* 611*7c478bd9Sstevel@tonic-gate * move to next devices file. return TRUE if successful, FALSE if not 612*7c478bd9Sstevel@tonic-gate */ 613*7c478bd9Sstevel@tonic-gate static int 614*7c478bd9Sstevel@tonic-gate nextdevices() 615*7c478bd9Sstevel@tonic-gate { 616*7c478bd9Sstevel@tonic-gate trace1(TR_nextdevices, 0); 617*7c478bd9Sstevel@tonic-gate if (fdevices != NULL) { 618*7c478bd9Sstevel@tonic-gate (void) fclose(fdevices); 619*7c478bd9Sstevel@tonic-gate ndevices++; 620*7c478bd9Sstevel@tonic-gate } else { 621*7c478bd9Sstevel@tonic-gate ndevices = 0; 622*7c478bd9Sstevel@tonic-gate } 623*7c478bd9Sstevel@tonic-gate for (; Devices[ndevices] != NULL; ndevices++) 624*7c478bd9Sstevel@tonic-gate if ((fdevices = fopen(Devices[ndevices], "r")) != NULL) { 625*7c478bd9Sstevel@tonic-gate trace1(TR_nextdevices, 1); 626*7c478bd9Sstevel@tonic-gate return (TRUE); 627*7c478bd9Sstevel@tonic-gate } 628*7c478bd9Sstevel@tonic-gate trace1(TR_nextdevices, 1); 629*7c478bd9Sstevel@tonic-gate return (FALSE); 630*7c478bd9Sstevel@tonic-gate } 631*7c478bd9Sstevel@tonic-gate 632*7c478bd9Sstevel@tonic-gate 633*7c478bd9Sstevel@tonic-gate /* 634*7c478bd9Sstevel@tonic-gate * get next line from Dialers file 635*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 636*7c478bd9Sstevel@tonic-gate */ 637*7c478bd9Sstevel@tonic-gate 638*7c478bd9Sstevel@tonic-gate GLOBAL int 639*7c478bd9Sstevel@tonic-gate getdialline(char *buf, int len) 640*7c478bd9Sstevel@tonic-gate { 641*7c478bd9Sstevel@tonic-gate trace2(TR_getdialline, 0, len); 642*7c478bd9Sstevel@tonic-gate if (Dialers[0] == NULL) 643*7c478bd9Sstevel@tonic-gate /* not initialized via setservice() - use default */ 644*7c478bd9Sstevel@tonic-gate setservice("uucico"); 645*7c478bd9Sstevel@tonic-gate 646*7c478bd9Sstevel@tonic-gate if (fdialers == NULL) 647*7c478bd9Sstevel@tonic-gate if (nextdialers() == FALSE) { 648*7c478bd9Sstevel@tonic-gate trace1(TR_getdialline, 1); 649*7c478bd9Sstevel@tonic-gate return (FALSE); 650*7c478bd9Sstevel@tonic-gate } 651*7c478bd9Sstevel@tonic-gate for (;;) { 652*7c478bd9Sstevel@tonic-gate if (fgets(buf, len, fdialers) != NULL) { 653*7c478bd9Sstevel@tonic-gate trace1(TR_getdialline, 1); 654*7c478bd9Sstevel@tonic-gate return (TRUE); 655*7c478bd9Sstevel@tonic-gate } 656*7c478bd9Sstevel@tonic-gate if (nextdialers() == FALSE) { 657*7c478bd9Sstevel@tonic-gate trace1(TR_getdialline, 1); 658*7c478bd9Sstevel@tonic-gate return (FALSE); 659*7c478bd9Sstevel@tonic-gate } 660*7c478bd9Sstevel@tonic-gate } 661*7c478bd9Sstevel@tonic-gate } 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate /* 664*7c478bd9Sstevel@tonic-gate * move to next dialers file. return TRUE if successful, FALSE if not 665*7c478bd9Sstevel@tonic-gate */ 666*7c478bd9Sstevel@tonic-gate static int 667*7c478bd9Sstevel@tonic-gate nextdialers() 668*7c478bd9Sstevel@tonic-gate { 669*7c478bd9Sstevel@tonic-gate trace1(TR_nextdialers, 0); 670*7c478bd9Sstevel@tonic-gate if (fdialers) { 671*7c478bd9Sstevel@tonic-gate (void) fclose(fdialers); 672*7c478bd9Sstevel@tonic-gate ndialers++; 673*7c478bd9Sstevel@tonic-gate } else { 674*7c478bd9Sstevel@tonic-gate ndialers = 0; 675*7c478bd9Sstevel@tonic-gate } 676*7c478bd9Sstevel@tonic-gate 677*7c478bd9Sstevel@tonic-gate for (; Dialers[ndialers] != NULL; ndialers++) 678*7c478bd9Sstevel@tonic-gate if ((fdialers = fopen(Dialers[ndialers], "r")) != NULL) { 679*7c478bd9Sstevel@tonic-gate trace1(TR_nextdialers, 1); 680*7c478bd9Sstevel@tonic-gate return (TRUE); 681*7c478bd9Sstevel@tonic-gate } 682*7c478bd9Sstevel@tonic-gate trace1(TR_nextdialers, 1); 683*7c478bd9Sstevel@tonic-gate return (FALSE); 684*7c478bd9Sstevel@tonic-gate } 685*7c478bd9Sstevel@tonic-gate 686*7c478bd9Sstevel@tonic-gate /* 687*7c478bd9Sstevel@tonic-gate * get next module to be popped 688*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 689*7c478bd9Sstevel@tonic-gate */ 690*7c478bd9Sstevel@tonic-gate static int 691*7c478bd9Sstevel@tonic-gate getpop(buf, len, optional) 692*7c478bd9Sstevel@tonic-gate char *buf; 693*7c478bd9Sstevel@tonic-gate size_t len; 694*7c478bd9Sstevel@tonic-gate int *optional; 695*7c478bd9Sstevel@tonic-gate { 696*7c478bd9Sstevel@tonic-gate int slen; 697*7c478bd9Sstevel@tonic-gate 698*7c478bd9Sstevel@tonic-gate trace2(TR_getpop, 0, len); 699*7c478bd9Sstevel@tonic-gate if (Pops[0] == NULL || Pops[npops] == NULL) { 700*7c478bd9Sstevel@tonic-gate trace1(TR_getpop, 1); 701*7c478bd9Sstevel@tonic-gate return (FALSE); 702*7c478bd9Sstevel@tonic-gate } 703*7c478bd9Sstevel@tonic-gate 704*7c478bd9Sstevel@tonic-gate /* if the module name is enclosed in parentheses, */ 705*7c478bd9Sstevel@tonic-gate /* is optional. set flag & strip parens */ 706*7c478bd9Sstevel@tonic-gate slen = strlen(Pops[npops]) - 1; 707*7c478bd9Sstevel@tonic-gate if (Pops[npops][0] == '(' && Pops[npops][slen] == ')') { 708*7c478bd9Sstevel@tonic-gate *optional = 1; 709*7c478bd9Sstevel@tonic-gate len = (slen < len ? slen : len); 710*7c478bd9Sstevel@tonic-gate strncpy(buf, &(Pops[npops++][1]), len); 711*7c478bd9Sstevel@tonic-gate } else { 712*7c478bd9Sstevel@tonic-gate *optional = 0; 713*7c478bd9Sstevel@tonic-gate strncpy(buf, Pops[npops++], len); 714*7c478bd9Sstevel@tonic-gate } 715*7c478bd9Sstevel@tonic-gate buf[len-1] = '\0'; 716*7c478bd9Sstevel@tonic-gate trace1(TR_getpop, 1); 717*7c478bd9Sstevel@tonic-gate return (TRUE); 718*7c478bd9Sstevel@tonic-gate } 719*7c478bd9Sstevel@tonic-gate 720*7c478bd9Sstevel@tonic-gate /* 721*7c478bd9Sstevel@tonic-gate * get next module to be pushed 722*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 723*7c478bd9Sstevel@tonic-gate */ 724*7c478bd9Sstevel@tonic-gate static int 725*7c478bd9Sstevel@tonic-gate getpush(buf, len) 726*7c478bd9Sstevel@tonic-gate char *buf; 727*7c478bd9Sstevel@tonic-gate size_t len; 728*7c478bd9Sstevel@tonic-gate { 729*7c478bd9Sstevel@tonic-gate trace2(TR_getpush, 0, len); 730*7c478bd9Sstevel@tonic-gate if (Pushes[0] == NULL || Pushes[npushes] == NULL) { 731*7c478bd9Sstevel@tonic-gate trace1(TR_getpush, 1); 732*7c478bd9Sstevel@tonic-gate return (FALSE); 733*7c478bd9Sstevel@tonic-gate } 734*7c478bd9Sstevel@tonic-gate strncpy(buf, Pushes[npushes++], len); 735*7c478bd9Sstevel@tonic-gate trace1(TR_getpush, 1); 736*7c478bd9Sstevel@tonic-gate return (TRUE); 737*7c478bd9Sstevel@tonic-gate } 738*7c478bd9Sstevel@tonic-gate 739*7c478bd9Sstevel@tonic-gate /* 740*7c478bd9Sstevel@tonic-gate * pop/push requested modules 741*7c478bd9Sstevel@tonic-gate * return TRUE if successful, FALSE if not 742*7c478bd9Sstevel@tonic-gate */ 743*7c478bd9Sstevel@tonic-gate GLOBAL int 744*7c478bd9Sstevel@tonic-gate pop_push(fd) 745*7c478bd9Sstevel@tonic-gate int fd; 746*7c478bd9Sstevel@tonic-gate { 747*7c478bd9Sstevel@tonic-gate char strmod[FMNAMESZ], onstream[FMNAMESZ]; 748*7c478bd9Sstevel@tonic-gate int optional; 749*7c478bd9Sstevel@tonic-gate 750*7c478bd9Sstevel@tonic-gate trace2(TR_pop_push, 0, fd); 751*7c478bd9Sstevel@tonic-gate /* check for streams modules to pop */ 752*7c478bd9Sstevel@tonic-gate while (getpop(strmod, sizeof(strmod), &optional)) { 753*7c478bd9Sstevel@tonic-gate DEBUG(5, (optional ? 754*7c478bd9Sstevel@tonic-gate (const char *)"pop_push: optionally POPing %s\n" 755*7c478bd9Sstevel@tonic-gate : (const char *)"pop_push: POPing %s\n"), strmod); 756*7c478bd9Sstevel@tonic-gate if (ioctl(fd, I_LOOK, onstream) == -1) { 757*7c478bd9Sstevel@tonic-gate DEBUG(5, "pop_push: I_LOOK on fd %d failed ", fd); 758*7c478bd9Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 759*7c478bd9Sstevel@tonic-gate trace1(TR_pop_push, 1); 760*7c478bd9Sstevel@tonic-gate return (FALSE); 761*7c478bd9Sstevel@tonic-gate } 762*7c478bd9Sstevel@tonic-gate if (strcmp(strmod, onstream) != SAME) { 763*7c478bd9Sstevel@tonic-gate if (optional) 764*7c478bd9Sstevel@tonic-gate continue; 765*7c478bd9Sstevel@tonic-gate DEBUG(5, "pop_push: I_POP: %s not there\n", strmod); 766*7c478bd9Sstevel@tonic-gate trace1(TR_pop_push, 1); 767*7c478bd9Sstevel@tonic-gate return (FALSE); 768*7c478bd9Sstevel@tonic-gate } 769*7c478bd9Sstevel@tonic-gate if (ioctl(fd, I_POP, 0) == -1) { 770*7c478bd9Sstevel@tonic-gate DEBUG(5, "pop_push: I_POP on fd %d failed ", fd); 771*7c478bd9Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 772*7c478bd9Sstevel@tonic-gate trace1(TR_pop_push, 1); 773*7c478bd9Sstevel@tonic-gate return (FALSE); 774*7c478bd9Sstevel@tonic-gate } 775*7c478bd9Sstevel@tonic-gate } 776*7c478bd9Sstevel@tonic-gate 777*7c478bd9Sstevel@tonic-gate /* check for streams modules to push */ 778*7c478bd9Sstevel@tonic-gate while (getpush(strmod, sizeof(strmod))) { 779*7c478bd9Sstevel@tonic-gate DEBUG(5, "pop_push: PUSHing %s\n", strmod); 780*7c478bd9Sstevel@tonic-gate if (ioctl(fd, I_PUSH, strmod) == -1) { 781*7c478bd9Sstevel@tonic-gate DEBUG(5, "pop_push: I_PUSH on fd %d failed ", fd); 782*7c478bd9Sstevel@tonic-gate DEBUG(5, "errno %d\n", errno); 783*7c478bd9Sstevel@tonic-gate trace1(TR_pop_push, 1); 784*7c478bd9Sstevel@tonic-gate return (FALSE); 785*7c478bd9Sstevel@tonic-gate } 786*7c478bd9Sstevel@tonic-gate } 787*7c478bd9Sstevel@tonic-gate trace1(TR_pop_push, 1); 788*7c478bd9Sstevel@tonic-gate return (TRUE); 789*7c478bd9Sstevel@tonic-gate } 790*7c478bd9Sstevel@tonic-gate 791*7c478bd9Sstevel@tonic-gate /* 792*7c478bd9Sstevel@tonic-gate * return name of currently open Systems file 793*7c478bd9Sstevel@tonic-gate */ 794*7c478bd9Sstevel@tonic-gate GLOBAL char * 795*7c478bd9Sstevel@tonic-gate currsys() 796*7c478bd9Sstevel@tonic-gate { 797*7c478bd9Sstevel@tonic-gate trace1(TR_currsys, 0); 798*7c478bd9Sstevel@tonic-gate trace1(TR_currsys, 1); 799*7c478bd9Sstevel@tonic-gate return (Systems[nsystems]); 800*7c478bd9Sstevel@tonic-gate } 801*7c478bd9Sstevel@tonic-gate 802*7c478bd9Sstevel@tonic-gate /* 803*7c478bd9Sstevel@tonic-gate * return name of currently open Devices file 804*7c478bd9Sstevel@tonic-gate */ 805*7c478bd9Sstevel@tonic-gate GLOBAL char * 806*7c478bd9Sstevel@tonic-gate currdev() 807*7c478bd9Sstevel@tonic-gate { 808*7c478bd9Sstevel@tonic-gate trace1(TR_currdev, 0); 809*7c478bd9Sstevel@tonic-gate trace1(TR_currdev, 1); 810*7c478bd9Sstevel@tonic-gate return (Devices[ndevices]); 811*7c478bd9Sstevel@tonic-gate } 812*7c478bd9Sstevel@tonic-gate 813*7c478bd9Sstevel@tonic-gate /* 814*7c478bd9Sstevel@tonic-gate * return name of currently open Dialers file 815*7c478bd9Sstevel@tonic-gate */ 816*7c478bd9Sstevel@tonic-gate GLOBAL char * 817*7c478bd9Sstevel@tonic-gate currdial() 818*7c478bd9Sstevel@tonic-gate { 819*7c478bd9Sstevel@tonic-gate trace1(TR_currdial, 0); 820*7c478bd9Sstevel@tonic-gate trace1(TR_currdial, 1); 821*7c478bd9Sstevel@tonic-gate return (Dialers[ndialers]); 822*7c478bd9Sstevel@tonic-gate } 823*7c478bd9Sstevel@tonic-gate 824*7c478bd9Sstevel@tonic-gate /* 825*7c478bd9Sstevel@tonic-gate * set configuration parameters provided in Config file 826*7c478bd9Sstevel@tonic-gate */ 827*7c478bd9Sstevel@tonic-gate static void 828*7c478bd9Sstevel@tonic-gate setconfig() 829*7c478bd9Sstevel@tonic-gate { 830*7c478bd9Sstevel@tonic-gate FILE *f; 831*7c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 832*7c478bd9Sstevel@tonic-gate char *tok; 833*7c478bd9Sstevel@tonic-gate extern char _ProtoCfg[]; 834*7c478bd9Sstevel@tonic-gate 835*7c478bd9Sstevel@tonic-gate trace1(TR_setconfig, 0); 836*7c478bd9Sstevel@tonic-gate if ((f = fopen(CONFIG, "r")) != 0) { 837*7c478bd9Sstevel@tonic-gate while (getline(f, buf) > 0) { 838*7c478bd9Sstevel@tonic-gate /* got a (logical) line from Config file */ 839*7c478bd9Sstevel@tonic-gate tok = strtok(buf, " \t"); 840*7c478bd9Sstevel@tonic-gate if ((tok != NULL) && (*tok != '#')) { 841*7c478bd9Sstevel@tonic-gate /* got a token */ 842*7c478bd9Sstevel@tonic-gate 843*7c478bd9Sstevel@tonic-gate /* this probably should be table driven when 844*7c478bd9Sstevel@tonic-gate * the list of configurable parameters grows. 845*7c478bd9Sstevel@tonic-gate */ 846*7c478bd9Sstevel@tonic-gate if (strncmp("Protocol=", tok, strlen("Protocol=")) == SAME) { 847*7c478bd9Sstevel@tonic-gate tok += strlen("Protocol="); 848*7c478bd9Sstevel@tonic-gate if (*tok != '\0') { 849*7c478bd9Sstevel@tonic-gate if (_ProtoCfg[0] != '\0') { 850*7c478bd9Sstevel@tonic-gate /*EMPTY*/ 851*7c478bd9Sstevel@tonic-gate DEBUG(7, "Protocol string %s ", tok); 852*7c478bd9Sstevel@tonic-gate DEBUG(7, "overrides %s\n", _ProtoCfg); 853*7c478bd9Sstevel@tonic-gate } 854*7c478bd9Sstevel@tonic-gate strcpy(_ProtoCfg, tok); 855*7c478bd9Sstevel@tonic-gate } 856*7c478bd9Sstevel@tonic-gate } else { 857*7c478bd9Sstevel@tonic-gate /*EMPTY*/ 858*7c478bd9Sstevel@tonic-gate DEBUG(7, "Unknown configuration parameter %s\n", tok); 859*7c478bd9Sstevel@tonic-gate } 860*7c478bd9Sstevel@tonic-gate } 861*7c478bd9Sstevel@tonic-gate } 862*7c478bd9Sstevel@tonic-gate (void) fclose(f); 863*7c478bd9Sstevel@tonic-gate } 864*7c478bd9Sstevel@tonic-gate trace1(TR_setconfig, 1); 865*7c478bd9Sstevel@tonic-gate } 866