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