17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 22*61961e0fSrobinson 237c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 247c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 27*61961e0fSrobinson * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 287c478bd9Sstevel@tonic-gate * Use is subject to license terms. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include "uucp.h" 347c478bd9Sstevel@tonic-gate static char _ProtoSys[40]; /* protocol string from Systems file entry */ 357c478bd9Sstevel@tonic-gate static char _ProtoDev[40]; /* protocol string from Devices file entry */ 36*61961e0fSrobinson static char _ProtoCfg[]; /* protocol string from Config file entry */ 377c478bd9Sstevel@tonic-gate 38*61961e0fSrobinson static jmp_buf Sjbuf; 39*61961e0fSrobinson static unsigned expecttime; 407c478bd9Sstevel@tonic-gate 41*61961e0fSrobinson static int Modemctrl; 427c478bd9Sstevel@tonic-gate 43*61961e0fSrobinson static void alarmtr(int); 44*61961e0fSrobinson static void getProto(char *, char *); 45*61961e0fSrobinson static int finds(char *, char *[], int); 46*61961e0fSrobinson static int getto(char *[]); /* make this static when ct uses altconn() */ 47*61961e0fSrobinson static int chat(int, char *[], int, char *, char *); 48*61961e0fSrobinson static int rddev(char *, char *[], char *, int); 49*61961e0fSrobinson static int expect(char *, int); 50*61961e0fSrobinson static int wrstr(int, char *, int, int); 51*61961e0fSrobinson static int wrchr(int, char *, int); 52*61961e0fSrobinson static int processdev(char *[], char *[]); 53*61961e0fSrobinson static int getdevline(char *, int); 54*61961e0fSrobinson static int getsysline(char *, int); 55*61961e0fSrobinson static int sysaccess(int); 56*61961e0fSrobinson static int clear_hup(int); 57*61961e0fSrobinson #ifndef SMALL 58*61961e0fSrobinson static char *currsys(void); 59*61961e0fSrobinson static char *currdev(void); 60*61961e0fSrobinson #endif 61*61961e0fSrobinson static int wait_for_hangup(int); 62*61961e0fSrobinson static int expect_str(char *, int); 637c478bd9Sstevel@tonic-gate 64*61961e0fSrobinson static void sendthem(char *, int, char *, char *); 65*61961e0fSrobinson static void nap(unsigned int); 66*61961e0fSrobinson static int notin(char *, char *); 67*61961e0fSrobinson static int ifdate(char *); 68*61961e0fSrobinson static int classmatch(char *[], char *[]); 697c478bd9Sstevel@tonic-gate 70*61961e0fSrobinson static char *Myline = CNULL; /* to force which line will be used */ 71*61961e0fSrobinson static char *Mytype = CNULL; /* to force selection of specific device type */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * conn - place a telephone call to system and login, etc. 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * return codes: 777c478bd9Sstevel@tonic-gate * FAIL - connection failed 787c478bd9Sstevel@tonic-gate * >0 - file no. - connect ok 797c478bd9Sstevel@tonic-gate * When a failure occurs, Uerror is set. 807c478bd9Sstevel@tonic-gate */ 817c478bd9Sstevel@tonic-gate 82*61961e0fSrobinson static int 83*61961e0fSrobinson conn(char *system) 847c478bd9Sstevel@tonic-gate { 857c478bd9Sstevel@tonic-gate int nf, fn = FAIL; 867c478bd9Sstevel@tonic-gate char *flds[F_MAX+1]; 87*61961e0fSrobinson static void sysreset(void); 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate CDEBUG(4, "conn(%s)\n", system); 907c478bd9Sstevel@tonic-gate Uerror = 0; 917c478bd9Sstevel@tonic-gate while ((nf = finds(system, flds, F_MAX)) > 0) { 927c478bd9Sstevel@tonic-gate fn = getto(flds); 937c478bd9Sstevel@tonic-gate CDEBUG(4, "getto ret %d\n", fn); 947c478bd9Sstevel@tonic-gate if (fn < 0) 957c478bd9Sstevel@tonic-gate continue; 967c478bd9Sstevel@tonic-gate if (EQUALS(Progname, "uucico")) { 97*61961e0fSrobinson if (chat(nf - F_LOGIN, flds + F_LOGIN, fn, "", "") == 98*61961e0fSrobinson SUCCESS) { 997c478bd9Sstevel@tonic-gate sysreset(); 1007c478bd9Sstevel@tonic-gate return (fn); /* successful return */ 1017c478bd9Sstevel@tonic-gate } 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate /* login failed */ 1047c478bd9Sstevel@tonic-gate DEBUG(6, "close caller (%d)\n", fn); 1057c478bd9Sstevel@tonic-gate fd_rmlock(fn); 106*61961e0fSrobinson (void) close(fn); 1077c478bd9Sstevel@tonic-gate if (Dc[0] != NULLCHAR) { 1087c478bd9Sstevel@tonic-gate /*EMPTY*/ 1097c478bd9Sstevel@tonic-gate DEBUG(6, "delock line (%s)\n", Dc); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate } else { 1127c478bd9Sstevel@tonic-gate sysreset(); 1137c478bd9Sstevel@tonic-gate return (fn); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* finds or getto failed */ 1187c478bd9Sstevel@tonic-gate sysreset(); 1197c478bd9Sstevel@tonic-gate CDEBUG(1, "Call Failed: %s\n", UERRORTEXT); 1207c478bd9Sstevel@tonic-gate return (FAIL); 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * getto - connect to remote machine 1257c478bd9Sstevel@tonic-gate * 1267c478bd9Sstevel@tonic-gate * return codes: 1277c478bd9Sstevel@tonic-gate * >0 - file number - ok 1287c478bd9Sstevel@tonic-gate * FAIL - failed 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate 131*61961e0fSrobinson static int 132*61961e0fSrobinson getto(char *flds[]) 1337c478bd9Sstevel@tonic-gate { 1347c478bd9Sstevel@tonic-gate char *dev[D_MAX+2], devbuf[BUFSIZ]; 135*61961e0fSrobinson int status; 136*61961e0fSrobinson int dcf = -1; 1377c478bd9Sstevel@tonic-gate int reread = 0; 1387c478bd9Sstevel@tonic-gate int tries = 0; /* count of call attempts - for limit purposes */ 139*61961e0fSrobinson static void devreset(void); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate CDEBUG(1, "Device Type %s wanted\n", flds[F_TYPE]); 1427c478bd9Sstevel@tonic-gate Uerror = 0; 1437c478bd9Sstevel@tonic-gate while (tries < TRYCALLS) { 144*61961e0fSrobinson if ((status = rddev(flds[F_TYPE], dev, devbuf, D_MAX)) == 145*61961e0fSrobinson FAIL) { 1467c478bd9Sstevel@tonic-gate if (tries == 0 || ++reread >= TRYCALLS) 1477c478bd9Sstevel@tonic-gate break; 1487c478bd9Sstevel@tonic-gate devreset(); 1497c478bd9Sstevel@tonic-gate continue; 1507c478bd9Sstevel@tonic-gate } 1517c478bd9Sstevel@tonic-gate /* check class, check (and possibly set) speed */ 1527c478bd9Sstevel@tonic-gate if (classmatch(flds, dev) != SUCCESS) { 1537c478bd9Sstevel@tonic-gate DEBUG(7, "Skipping entry in '%s'", currdev()); 1547c478bd9Sstevel@tonic-gate DEBUG(7, " - class (%s) not wanted.\n", dev[D_CLASS]); 1557c478bd9Sstevel@tonic-gate continue; 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate DEBUG(5, "Trying device entry from '%s'.\n", currdev()); 1587c478bd9Sstevel@tonic-gate if ((dcf = processdev(flds, dev)) >= 0) 1597c478bd9Sstevel@tonic-gate break; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate switch (Uerror) { 1627c478bd9Sstevel@tonic-gate case SS_CANT_ACCESS_DEVICE: 1637c478bd9Sstevel@tonic-gate case SS_DEVICE_FAILED: 1647c478bd9Sstevel@tonic-gate case SS_LOCKED_DEVICE: 1657c478bd9Sstevel@tonic-gate break; 1667c478bd9Sstevel@tonic-gate default: 1677c478bd9Sstevel@tonic-gate tries++; 1687c478bd9Sstevel@tonic-gate break; 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate devreset(); /* reset devices file(s) */ 1727c478bd9Sstevel@tonic-gate if (status == FAIL && !Uerror) { 1737c478bd9Sstevel@tonic-gate CDEBUG(1, "Requested Device Type Not Found\n%s", ""); 1747c478bd9Sstevel@tonic-gate Uerror = SS_NO_DEVICE; 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate return (dcf); 1777c478bd9Sstevel@tonic-gate } 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * classmatch - process 'Any' in Devices and Systems and 1817c478bd9Sstevel@tonic-gate * determine the correct speed, or match for == 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate static int 185*61961e0fSrobinson classmatch(char *flds[], char *dev[]) 1867c478bd9Sstevel@tonic-gate { 1877c478bd9Sstevel@tonic-gate /* check class, check (and possibly set) speed */ 188*61961e0fSrobinson if (EQUALS(flds[F_CLASS], "Any") && EQUALS(dev[D_CLASS], "Any")) { 1897c478bd9Sstevel@tonic-gate dev[D_CLASS] = DEFAULT_BAUDRATE; 1907c478bd9Sstevel@tonic-gate return (SUCCESS); 1917c478bd9Sstevel@tonic-gate } else if (EQUALS(dev[D_CLASS], "Any")) { 1927c478bd9Sstevel@tonic-gate dev[D_CLASS] = flds[F_CLASS]; 1937c478bd9Sstevel@tonic-gate return (SUCCESS); 1947c478bd9Sstevel@tonic-gate } else if (EQUALS(flds[F_CLASS], "Any") || 195*61961e0fSrobinson EQUALS(flds[F_CLASS], dev[D_CLASS])) 1967c478bd9Sstevel@tonic-gate return (SUCCESS); 197*61961e0fSrobinson else 1987c478bd9Sstevel@tonic-gate return (FAIL); 1997c478bd9Sstevel@tonic-gate } 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate /* 2037c478bd9Sstevel@tonic-gate * rddev - find and unpack a line from device file for this caller type 2047c478bd9Sstevel@tonic-gate * lines starting with whitespace of '#' are comments 2057c478bd9Sstevel@tonic-gate * 2067c478bd9Sstevel@tonic-gate * return codes: 2077c478bd9Sstevel@tonic-gate * >0 - number of arguments in vector - succeeded 2087c478bd9Sstevel@tonic-gate * FAIL - EOF 2097c478bd9Sstevel@tonic-gate */ 2107c478bd9Sstevel@tonic-gate 211*61961e0fSrobinson static int 2127c478bd9Sstevel@tonic-gate rddev(char *type, char *dev[], char *buf, int devcount) 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate char *commap, d_type[BUFSIZ]; 2157c478bd9Sstevel@tonic-gate int na; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate while (getdevline(buf, BUFSIZ)) { 218*61961e0fSrobinson if (buf[0] == ' ' || buf[0] == '\t' || buf[0] == '\n' || 219*61961e0fSrobinson buf[0] == '\0' || buf[0] == '#') 2207c478bd9Sstevel@tonic-gate continue; 2217c478bd9Sstevel@tonic-gate na = getargs(buf, dev, devcount); 2227c478bd9Sstevel@tonic-gate ASSERT(na >= D_CALLER, "BAD LINE", buf, na); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate if (strncmp(dev[D_LINE], "/dev/", 5) == 0) { 2257c478bd9Sstevel@tonic-gate /* since cu (altconn()) strips off leading */ 2267c478bd9Sstevel@tonic-gate /* "/dev/", do the same here. */ 227*61961e0fSrobinson (void) strcpy(dev[D_LINE], &(dev[D_LINE][5])); 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate /* may have ",M" subfield in D_LINE */ 2317c478bd9Sstevel@tonic-gate Modemctrl = FALSE; 232*61961e0fSrobinson if ((commap = strchr(dev[D_LINE], ',')) != NULL) { 2337c478bd9Sstevel@tonic-gate if (strcmp(commap, ",M") == SAME) 2347c478bd9Sstevel@tonic-gate Modemctrl = TRUE; 2357c478bd9Sstevel@tonic-gate *commap = '\0'; 2367c478bd9Sstevel@tonic-gate } 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * D_TYPE field may have protocol subfield, which 2407c478bd9Sstevel@tonic-gate * must be pulled off before comparing to desired type. 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate (void) strcpy(d_type, dev[D_TYPE]); 243*61961e0fSrobinson if ((commap = strchr(d_type, ',')) != NULL) 2447c478bd9Sstevel@tonic-gate *commap = '\0'; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* to force the requested device type to be used. */ 2477c478bd9Sstevel@tonic-gate if ((Mytype != NULL) && (!EQUALS(Mytype, d_type))) 2487c478bd9Sstevel@tonic-gate continue; 2497c478bd9Sstevel@tonic-gate /* to force the requested line to be used */ 2507c478bd9Sstevel@tonic-gate if ((Myline != NULL) && (!EQUALS(Myline, dev[D_LINE]))) 2517c478bd9Sstevel@tonic-gate continue; 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate bsfix(dev); /* replace \X fields */ 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate if (EQUALS(d_type, type)) { 2567c478bd9Sstevel@tonic-gate getProto(_ProtoDev, dev[D_TYPE]); 2577c478bd9Sstevel@tonic-gate return (na); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate return (FAIL); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate /* 2657c478bd9Sstevel@tonic-gate * finds - set system attribute vector 2667c478bd9Sstevel@tonic-gate * 2677c478bd9Sstevel@tonic-gate * input: 2687c478bd9Sstevel@tonic-gate * fsys - open Systems file descriptor 2697c478bd9Sstevel@tonic-gate * sysnam - system name to find 2707c478bd9Sstevel@tonic-gate * output: 2717c478bd9Sstevel@tonic-gate * flds - attibute vector from Systems file 2727c478bd9Sstevel@tonic-gate * fldcount - number of fields in flds 2737c478bd9Sstevel@tonic-gate * return codes: 2747c478bd9Sstevel@tonic-gate * >0 - number of arguments in vector - succeeded 2757c478bd9Sstevel@tonic-gate * FAIL - failed 2767c478bd9Sstevel@tonic-gate * Uerror set: 2777c478bd9Sstevel@tonic-gate * 0 - found a line in Systems file 2787c478bd9Sstevel@tonic-gate * SS_BADSYSTEM - no line found in Systems file 2797c478bd9Sstevel@tonic-gate * SS_TIME_WRONG - wrong time to call 2807c478bd9Sstevel@tonic-gate */ 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate static int 2837c478bd9Sstevel@tonic-gate finds(char *sysnam, char *flds[], int fldcount) 2847c478bd9Sstevel@tonic-gate { 2857c478bd9Sstevel@tonic-gate static char *info; /* dynamically allocated BUFSIZ */ 2867c478bd9Sstevel@tonic-gate int na; 2877c478bd9Sstevel@tonic-gate 288*61961e0fSrobinson /* 289*61961e0fSrobinson * format of fields 2907c478bd9Sstevel@tonic-gate * 0 name; 2917c478bd9Sstevel@tonic-gate * 1 time 2927c478bd9Sstevel@tonic-gate * 2 acu/hardwired 2937c478bd9Sstevel@tonic-gate * 3 speed 2947c478bd9Sstevel@tonic-gate * etc 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate if (sysnam == 0 || *sysnam == 0) { 2987c478bd9Sstevel@tonic-gate Uerror = SS_BADSYSTEM; 2997c478bd9Sstevel@tonic-gate return (FAIL); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate if (info == NULL) { 303*61961e0fSrobinson info = malloc(BUFSIZ); 3047c478bd9Sstevel@tonic-gate if (info == NULL) { 3057c478bd9Sstevel@tonic-gate DEBUG(1, "malloc failed for info in finds\n", 0); 3067c478bd9Sstevel@tonic-gate return (0); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate while (getsysline(info, BUFSIZ)) { 3107c478bd9Sstevel@tonic-gate na = getargs(info, flds, fldcount); 3117c478bd9Sstevel@tonic-gate bsfix(flds); /* replace \X fields */ 3127c478bd9Sstevel@tonic-gate if (!EQUALSN(sysnam, flds[F_NAME], MAXBASENAME)) 3137c478bd9Sstevel@tonic-gate continue; 3147c478bd9Sstevel@tonic-gate /* check if requested Mytype device type */ 315*61961e0fSrobinson if ((Mytype != CNULL) && 316*61961e0fSrobinson (!EQUALSN(flds[F_TYPE], Mytype, strlen(Mytype)))) { 3177c478bd9Sstevel@tonic-gate DEBUG(7, "Skipping entry in '%s'", currsys()); 3187c478bd9Sstevel@tonic-gate DEBUG(7, " - type (%s) not wanted.\n", flds[F_TYPE]); 3197c478bd9Sstevel@tonic-gate continue; 3207c478bd9Sstevel@tonic-gate } else { 3217c478bd9Sstevel@tonic-gate /*EMPTY*/ 3227c478bd9Sstevel@tonic-gate DEBUG(5, "Trying entry from '%s'", currsys()); 3237c478bd9Sstevel@tonic-gate DEBUG(5, " - device type %s.\n", flds[F_TYPE]); 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate /* OK if not uucico (ie. ct or cu) or the time is right */ 3267c478bd9Sstevel@tonic-gate if (!EQUALS(Progname, "uucico") || ifdate(flds[F_TIME])) { 3277c478bd9Sstevel@tonic-gate /* found a good entry */ 3287c478bd9Sstevel@tonic-gate getProto(_ProtoSys, flds[F_TYPE]); 3297c478bd9Sstevel@tonic-gate Uerror = 0; 3307c478bd9Sstevel@tonic-gate return (na); /* FOUND OK LINE */ 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate CDEBUG(1, "Wrong Time To Call: %s\n", flds[F_TIME]); 3337c478bd9Sstevel@tonic-gate Uerror = SS_TIME_WRONG; 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate if (!Uerror) 3367c478bd9Sstevel@tonic-gate Uerror = SS_BADSYSTEM; 3377c478bd9Sstevel@tonic-gate return (FAIL); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * getProto - get the protocol letters from the input string. 3427c478bd9Sstevel@tonic-gate * input: 3437c478bd9Sstevel@tonic-gate * str - string from Systems/Devices/Config file, 3447c478bd9Sstevel@tonic-gate * a ',' delimits the protocol string 3457c478bd9Sstevel@tonic-gate * e.g. ACU,g or DK,d 3467c478bd9Sstevel@tonic-gate * output: 3477c478bd9Sstevel@tonic-gate * str - the , (if present) will be replaced with NULLCHAR 3487c478bd9Sstevel@tonic-gate * 3497c478bd9Sstevel@tonic-gate * return: none 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate static void 353*61961e0fSrobinson getProto(char *save, char *str) 3547c478bd9Sstevel@tonic-gate { 355*61961e0fSrobinson char *p; 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate *save = NULLCHAR; 3587c478bd9Sstevel@tonic-gate if ((p = strchr(str, ',')) != NULL) { 3597c478bd9Sstevel@tonic-gate *p = NULLCHAR; 3607c478bd9Sstevel@tonic-gate (void) strcpy(save, p+1); 3617c478bd9Sstevel@tonic-gate DEBUG(7, "Protocol = %s\n", save); 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * chat - do conversation 3677c478bd9Sstevel@tonic-gate * input: 3687c478bd9Sstevel@tonic-gate * nf - number of fields in flds array 3697c478bd9Sstevel@tonic-gate * flds - fields from Systems file 3707c478bd9Sstevel@tonic-gate * fn - write file number 3717c478bd9Sstevel@tonic-gate * phstr1 - phone number to replace \D 3727c478bd9Sstevel@tonic-gate * phstr2 - phone number to replace \T 3737c478bd9Sstevel@tonic-gate * 3747c478bd9Sstevel@tonic-gate * return codes: 0 | FAIL 3757c478bd9Sstevel@tonic-gate */ 3767c478bd9Sstevel@tonic-gate 377*61961e0fSrobinson static int 378*61961e0fSrobinson chat(int nf, char *flds[], int fn, char *phstr1, char *phstr2) 3797c478bd9Sstevel@tonic-gate { 3807c478bd9Sstevel@tonic-gate char *want, *altern; 3817c478bd9Sstevel@tonic-gate int k, ok; 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate for (k = 0; k < nf; k += 2) { 3847c478bd9Sstevel@tonic-gate want = flds[k]; 3857c478bd9Sstevel@tonic-gate ok = FAIL; 3867c478bd9Sstevel@tonic-gate while (ok != 0) { 3877c478bd9Sstevel@tonic-gate altern = index(want, '-'); 3887c478bd9Sstevel@tonic-gate if (altern != NULL) 3897c478bd9Sstevel@tonic-gate *altern++ = NULLCHAR; 3907c478bd9Sstevel@tonic-gate ok = expect(want, fn); 3917c478bd9Sstevel@tonic-gate if (ok == 0) 3927c478bd9Sstevel@tonic-gate break; 3937c478bd9Sstevel@tonic-gate if (altern == NULL) { 3947c478bd9Sstevel@tonic-gate Uerror = SS_LOGIN_FAILED; 3957c478bd9Sstevel@tonic-gate logent(UERRORTEXT, "FAILED"); 3967c478bd9Sstevel@tonic-gate return (FAIL); 3977c478bd9Sstevel@tonic-gate } 3987c478bd9Sstevel@tonic-gate want = index(altern, '-'); 3997c478bd9Sstevel@tonic-gate if (want != NULL) 4007c478bd9Sstevel@tonic-gate *want++ = NULLCHAR; 4017c478bd9Sstevel@tonic-gate sendthem(altern, fn, phstr1, phstr2); 4027c478bd9Sstevel@tonic-gate } 403*61961e0fSrobinson (void) sleep(2); 4047c478bd9Sstevel@tonic-gate if (flds[k+1]) 4057c478bd9Sstevel@tonic-gate sendthem(flds[k+1], fn, phstr1, phstr2); 4067c478bd9Sstevel@tonic-gate } 4077c478bd9Sstevel@tonic-gate return (0); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate #define MR 1000 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate /* 4137c478bd9Sstevel@tonic-gate * expect(str, fn) look for expected string w/ possible special chars 4147c478bd9Sstevel@tonic-gate * char *str; 4157c478bd9Sstevel@tonic-gate * 4167c478bd9Sstevel@tonic-gate * return codes: 4177c478bd9Sstevel@tonic-gate * 0 - found 4187c478bd9Sstevel@tonic-gate * FAIL - lost line or too many characters read 4197c478bd9Sstevel@tonic-gate * some character - timed out 4207c478bd9Sstevel@tonic-gate */ 4217c478bd9Sstevel@tonic-gate 422*61961e0fSrobinson static int 423*61961e0fSrobinson expect(char *str, int fn) 4247c478bd9Sstevel@tonic-gate { 425*61961e0fSrobinson char *bptr, *sptr; 4267c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate bptr = buf; 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate for (sptr = str; *sptr; sptr++) { 4317c478bd9Sstevel@tonic-gate if (*sptr == '\\') { 4327c478bd9Sstevel@tonic-gate switch (*++sptr) { 4337c478bd9Sstevel@tonic-gate case 'H': 4347c478bd9Sstevel@tonic-gate *bptr++ = '\0'; 4357c478bd9Sstevel@tonic-gate if (expect_str(buf, fn) == FAIL) { 4367c478bd9Sstevel@tonic-gate return (FAIL); 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate if (wait_for_hangup(fn) == FAIL) { 4397c478bd9Sstevel@tonic-gate return (FAIL); 4407c478bd9Sstevel@tonic-gate } 4417c478bd9Sstevel@tonic-gate bptr = buf; 4427c478bd9Sstevel@tonic-gate continue; 4437c478bd9Sstevel@tonic-gate case '\\': 4447c478bd9Sstevel@tonic-gate *bptr++ = '\\'; 4457c478bd9Sstevel@tonic-gate continue; 4467c478bd9Sstevel@tonic-gate default: 4477c478bd9Sstevel@tonic-gate *bptr++ = '\\'; 4487c478bd9Sstevel@tonic-gate *bptr++ = *sptr; 4497c478bd9Sstevel@tonic-gate continue; 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate } else 4527c478bd9Sstevel@tonic-gate *bptr++ = *sptr; 4537c478bd9Sstevel@tonic-gate } 4547c478bd9Sstevel@tonic-gate *bptr = '\0'; 4557c478bd9Sstevel@tonic-gate if (expect_str(buf, fn) == FAIL) { 4567c478bd9Sstevel@tonic-gate return (FAIL); 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate return (0); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate /* 4627c478bd9Sstevel@tonic-gate * expect_str(str, fn) look for expected string, w/ no special chars 4637c478bd9Sstevel@tonic-gate * 4647c478bd9Sstevel@tonic-gate * return codes: 4657c478bd9Sstevel@tonic-gate * 0 - found 4667c478bd9Sstevel@tonic-gate * FAIL - too many characters read 4677c478bd9Sstevel@tonic-gate * some character - timed out 4687c478bd9Sstevel@tonic-gate */ 4697c478bd9Sstevel@tonic-gate 470*61961e0fSrobinson static int 471*61961e0fSrobinson expect_str(char *str, int fn) 4727c478bd9Sstevel@tonic-gate { 4737c478bd9Sstevel@tonic-gate static char rdvec[MR]; 4747c478bd9Sstevel@tonic-gate char *rp = rdvec; 475*61961e0fSrobinson int kr, c; 4767c478bd9Sstevel@tonic-gate char nextch; 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate *rp = 0; 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate CDEBUG(4, "expect: (%s", ""); 4817c478bd9Sstevel@tonic-gate for (c = 0; (kr = str[c]) != 0; c++) 4827c478bd9Sstevel@tonic-gate if (kr < 040) { 4837c478bd9Sstevel@tonic-gate /*EMPTY*/ 4847c478bd9Sstevel@tonic-gate CDEBUG(4, "^%c", kr | 0100); 4857c478bd9Sstevel@tonic-gate } else { 4867c478bd9Sstevel@tonic-gate /*EMPTY*/ 4877c478bd9Sstevel@tonic-gate CDEBUG(4, "%c", kr); 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate CDEBUG(4, ")\n%s", ""); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate if (EQUALS(str, "\"\"")) { 4927c478bd9Sstevel@tonic-gate CDEBUG(4, "got it\n%s", ""); 4937c478bd9Sstevel@tonic-gate return (0); 4947c478bd9Sstevel@tonic-gate } 495*61961e0fSrobinson if (*str == '\0') 4967c478bd9Sstevel@tonic-gate return (0); 497*61961e0fSrobinson if (setjmp(Sjbuf)) 4987c478bd9Sstevel@tonic-gate return (FAIL); 4997c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 500*61961e0fSrobinson (void) alarm(expecttime); 5017c478bd9Sstevel@tonic-gate while (notin(str, rdvec)) { 5027c478bd9Sstevel@tonic-gate errno = 0; 5037c478bd9Sstevel@tonic-gate kr = (*Read)(fn, &nextch, 1); 5047c478bd9Sstevel@tonic-gate if (kr <= 0) { 505*61961e0fSrobinson (void) alarm(0); 5067c478bd9Sstevel@tonic-gate CDEBUG(4, "lost line errno - %d\n", errno); 5077c478bd9Sstevel@tonic-gate logent("LOGIN", "LOST LINE"); 5087c478bd9Sstevel@tonic-gate return (FAIL); 5097c478bd9Sstevel@tonic-gate } 5107c478bd9Sstevel@tonic-gate c = nextch & 0177; 5117c478bd9Sstevel@tonic-gate CDEBUG(4, "%s", c < 040 ? "^" : ""); 5127c478bd9Sstevel@tonic-gate CDEBUG(4, "%c", c < 040 ? c | 0100 : c); 5137c478bd9Sstevel@tonic-gate if ((*rp = nextch & 0177) != NULLCHAR) 5147c478bd9Sstevel@tonic-gate rp++; 5157c478bd9Sstevel@tonic-gate if (rp >= rdvec + MR) { 5167c478bd9Sstevel@tonic-gate CDEBUG(4, "enough already\n%s", ""); 517*61961e0fSrobinson (void) alarm(0); 5187c478bd9Sstevel@tonic-gate return (FAIL); 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate *rp = NULLCHAR; 5217c478bd9Sstevel@tonic-gate } 522*61961e0fSrobinson (void) alarm(0); 5237c478bd9Sstevel@tonic-gate CDEBUG(4, "got it\n%s", ""); 5247c478bd9Sstevel@tonic-gate return (0); 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate /* 5297c478bd9Sstevel@tonic-gate * alarmtr() - catch alarm routine for "expect". 5307c478bd9Sstevel@tonic-gate */ 5317c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 532*61961e0fSrobinson static void 533*61961e0fSrobinson alarmtr(int sig) 5347c478bd9Sstevel@tonic-gate { 5357c478bd9Sstevel@tonic-gate CDEBUG(6, "timed out\n%s", ""); 5367c478bd9Sstevel@tonic-gate longjmp(Sjbuf, 1); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * wait_for_hangup() - wait for a hangup to occur on the given device 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate int 543*61961e0fSrobinson wait_for_hangup(int dcf) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate int rval; 5467c478bd9Sstevel@tonic-gate char buff[BUFSIZ]; 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate CDEBUG(4, "Waiting for hangup\n%s", ""); 549*61961e0fSrobinson while ((rval = read(dcf, buff, BUFSIZ)) > 0) 550*61961e0fSrobinson ; 5517c478bd9Sstevel@tonic-gate 552*61961e0fSrobinson if (rval < 0) 5537c478bd9Sstevel@tonic-gate return (FAIL); 5547c478bd9Sstevel@tonic-gate CDEBUG(4, "Received hangup\n%s", ""); 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if (clear_hup(dcf) != SUCCESS) { 5577c478bd9Sstevel@tonic-gate CDEBUG(4, "Unable to clear hup on device\n%s", ""); 5587c478bd9Sstevel@tonic-gate return (FAIL); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate return (SUCCESS); 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate /* 5647c478bd9Sstevel@tonic-gate * sendthem(str, fn, phstr1, phstr2) send line of chat sequence 5657c478bd9Sstevel@tonic-gate * char *str, *phstr; 5667c478bd9Sstevel@tonic-gate * 5677c478bd9Sstevel@tonic-gate * return codes: none 5687c478bd9Sstevel@tonic-gate */ 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate #define FLUSH() { \ 5717c478bd9Sstevel@tonic-gate if ((bptr - buf) > 0) \ 5727c478bd9Sstevel@tonic-gate if (wrstr(fn, buf, bptr - buf, echocheck) != SUCCESS) \ 5737c478bd9Sstevel@tonic-gate goto err; \ 5747c478bd9Sstevel@tonic-gate bptr = buf; \ 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate 577*61961e0fSrobinson static void 578*61961e0fSrobinson sendthem(char *str, int fn, char *phstr1, char *phstr2) 5797c478bd9Sstevel@tonic-gate { 5807c478bd9Sstevel@tonic-gate int sendcr = 1, echocheck = 0; 581*61961e0fSrobinson char *sptr, *bptr; 5827c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 5837c478bd9Sstevel@tonic-gate struct termio ttybuf; 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate /* should be EQUALS, but previous versions had BREAK n for integer n */ 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate if (PREFIX("BREAK", str)) { 5887c478bd9Sstevel@tonic-gate /* send break */ 5897c478bd9Sstevel@tonic-gate CDEBUG(5, "BREAK\n%s", ""); 5907c478bd9Sstevel@tonic-gate (*genbrk)(fn); 5917c478bd9Sstevel@tonic-gate return; 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate 5947c478bd9Sstevel@tonic-gate if (EQUALS(str, "EOT")) { 5957c478bd9Sstevel@tonic-gate CDEBUG(5, "EOT\n%s", ""); 5967c478bd9Sstevel@tonic-gate (void) (*Write)(fn, EOTMSG, strlen(EOTMSG)); 5977c478bd9Sstevel@tonic-gate return; 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate if (EQUALS(str, "\"\"")) { 6017c478bd9Sstevel@tonic-gate CDEBUG(5, "\"\"\n%s", ""); 6027c478bd9Sstevel@tonic-gate str += 2; 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate 6057c478bd9Sstevel@tonic-gate bptr = buf; 6067c478bd9Sstevel@tonic-gate CDEBUG(5, "sendthem (%s", ""); 6077c478bd9Sstevel@tonic-gate for (sptr = str; *sptr; sptr++) { 6087c478bd9Sstevel@tonic-gate if (*sptr == '\\') { 6097c478bd9Sstevel@tonic-gate switch (*++sptr) { 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate /* adjust switches */ 6127c478bd9Sstevel@tonic-gate case 'c': /* no CR after string */ 6137c478bd9Sstevel@tonic-gate FLUSH(); 6147c478bd9Sstevel@tonic-gate if (sptr[1] == NULLCHAR) { 6157c478bd9Sstevel@tonic-gate CDEBUG(5, "<NO CR>%s", ""); 6167c478bd9Sstevel@tonic-gate sendcr = 0; 6177c478bd9Sstevel@tonic-gate } else { 6187c478bd9Sstevel@tonic-gate /*EMPTY*/ 6197c478bd9Sstevel@tonic-gate CDEBUG(5, "<NO CR IGNORED>\n%s", ""); 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate continue; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate /* stash in buf and continue */ 6257c478bd9Sstevel@tonic-gate switch (*sptr) { 6267c478bd9Sstevel@tonic-gate case 'D': /* raw phnum */ 627*61961e0fSrobinson (void) strcpy(bptr, phstr1); 6287c478bd9Sstevel@tonic-gate bptr += strlen(bptr); 6297c478bd9Sstevel@tonic-gate continue; 6307c478bd9Sstevel@tonic-gate case 'T': /* translated phnum */ 631*61961e0fSrobinson (void) strcpy(bptr, phstr2); 6327c478bd9Sstevel@tonic-gate bptr += strlen(bptr); 6337c478bd9Sstevel@tonic-gate continue; 6347c478bd9Sstevel@tonic-gate case 'N': /* null */ 6357c478bd9Sstevel@tonic-gate *bptr++ = 0; 6367c478bd9Sstevel@tonic-gate continue; 6377c478bd9Sstevel@tonic-gate case 's': /* space */ 6387c478bd9Sstevel@tonic-gate *bptr++ = ' '; 6397c478bd9Sstevel@tonic-gate continue; 6407c478bd9Sstevel@tonic-gate case '\\': /* backslash escapes itself */ 6417c478bd9Sstevel@tonic-gate *bptr++ = *sptr; 6427c478bd9Sstevel@tonic-gate continue; 6437c478bd9Sstevel@tonic-gate default: /* send the backslash */ 6447c478bd9Sstevel@tonic-gate *bptr++ = '\\'; 6457c478bd9Sstevel@tonic-gate *bptr++ = *sptr; 6467c478bd9Sstevel@tonic-gate continue; 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* flush buf, perform action, and continue */ 6497c478bd9Sstevel@tonic-gate case 'E': /* echo check on */ 6507c478bd9Sstevel@tonic-gate FLUSH(); 6517c478bd9Sstevel@tonic-gate CDEBUG(5, "ECHO CHECK ON\n%s", ""); 6527c478bd9Sstevel@tonic-gate echocheck = 1; 6537c478bd9Sstevel@tonic-gate continue; 6547c478bd9Sstevel@tonic-gate case 'e': /* echo check off */ 6557c478bd9Sstevel@tonic-gate FLUSH(); 6567c478bd9Sstevel@tonic-gate CDEBUG(5, "ECHO CHECK OFF\n%s", ""); 6577c478bd9Sstevel@tonic-gate echocheck = 0; 6587c478bd9Sstevel@tonic-gate continue; 6597c478bd9Sstevel@tonic-gate case 'd': /* sleep briefly */ 6607c478bd9Sstevel@tonic-gate FLUSH(); 6617c478bd9Sstevel@tonic-gate CDEBUG(5, "DELAY\n%s", ""); 662*61961e0fSrobinson (void) sleep(2); 6637c478bd9Sstevel@tonic-gate continue; 6647c478bd9Sstevel@tonic-gate case 'p': /* pause momentarily */ 6657c478bd9Sstevel@tonic-gate FLUSH(); 6667c478bd9Sstevel@tonic-gate CDEBUG(5, "PAUSE\n%s", ""); 6677c478bd9Sstevel@tonic-gate nap(HZ/4); /* approximately 1/4 second */ 6687c478bd9Sstevel@tonic-gate continue; 6697c478bd9Sstevel@tonic-gate case 'K': /* inline break */ 6707c478bd9Sstevel@tonic-gate FLUSH(); 6717c478bd9Sstevel@tonic-gate CDEBUG(5, "BREAK\n%s", ""); 6727c478bd9Sstevel@tonic-gate (*genbrk)(fn); 6737c478bd9Sstevel@tonic-gate continue; 6747c478bd9Sstevel@tonic-gate case 'M': /* modem control - set CLOCAL */ 6757c478bd9Sstevel@tonic-gate case 'm': /* no modem control - clear CLOCAL */ 6767c478bd9Sstevel@tonic-gate FLUSH(); 6777c478bd9Sstevel@tonic-gate CDEBUG(5, ")\n%s CLOCAL ", 6787c478bd9Sstevel@tonic-gate (*sptr == 'M' ? "set" : "clear")); 6797c478bd9Sstevel@tonic-gate if ((*Ioctl)(fn, TCGETA, &ttybuf) != 0) { 6807c478bd9Sstevel@tonic-gate /*EMPTY*/ 681*61961e0fSrobinson CDEBUG(5, 682*61961e0fSrobinson "ignored. TCGETA failed, errno %d", 683*61961e0fSrobinson errno); 6847c478bd9Sstevel@tonic-gate } else { 6857c478bd9Sstevel@tonic-gate if (*sptr == 'M') 6867c478bd9Sstevel@tonic-gate ttybuf.c_cflag |= CLOCAL; 6877c478bd9Sstevel@tonic-gate else 6887c478bd9Sstevel@tonic-gate ttybuf.c_cflag &= ~CLOCAL; 6897c478bd9Sstevel@tonic-gate if ((*Ioctl)(fn, TCSETAW, &ttybuf) != 0) 6907c478bd9Sstevel@tonic-gate /*EMPTY*/ 691*61961e0fSrobinson CDEBUG(5, 692*61961e0fSrobinson "failed. TCSETAW failed, errno %d", 693*61961e0fSrobinson errno); 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate CDEBUG(5, "\n%s", ""); 6967c478bd9Sstevel@tonic-gate continue; 6977c478bd9Sstevel@tonic-gate } 6987c478bd9Sstevel@tonic-gate } else 6997c478bd9Sstevel@tonic-gate *bptr++ = *sptr; 7007c478bd9Sstevel@tonic-gate } 7017c478bd9Sstevel@tonic-gate if (sendcr) 7027c478bd9Sstevel@tonic-gate *bptr++ = '\r'; 7037c478bd9Sstevel@tonic-gate if ((bptr - buf) > 0) 7047c478bd9Sstevel@tonic-gate (void) wrstr(fn, buf, bptr - buf, echocheck); 7057c478bd9Sstevel@tonic-gate 7067c478bd9Sstevel@tonic-gate err: 7077c478bd9Sstevel@tonic-gate CDEBUG(5, ")\n%s", ""); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate #undef FLUSH 7117c478bd9Sstevel@tonic-gate 712*61961e0fSrobinson static int 7137c478bd9Sstevel@tonic-gate wrstr(int fn, char *buf, int len, int echocheck) 7147c478bd9Sstevel@tonic-gate { 7157c478bd9Sstevel@tonic-gate int i; 7167c478bd9Sstevel@tonic-gate char dbuf[BUFSIZ], *dbptr = dbuf; 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate buf[len] = 0; 7197c478bd9Sstevel@tonic-gate 720*61961e0fSrobinson if (echocheck) 721*61961e0fSrobinson return (wrchr(fn, buf, len)); 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate if (Debug >= 5) { 724*61961e0fSrobinson if (sysaccess(ACCESS_SYSTEMS) == 0) { 725*61961e0fSrobinson /* Systems file access ok */ 7267c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) { 7277c478bd9Sstevel@tonic-gate *dbptr = buf[i]; 7287c478bd9Sstevel@tonic-gate if (*dbptr < 040) { 7297c478bd9Sstevel@tonic-gate *dbptr++ = '^'; 7307c478bd9Sstevel@tonic-gate *dbptr = buf[i] | 0100; 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate dbptr++; 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate *dbptr = 0; 7357c478bd9Sstevel@tonic-gate } else 736*61961e0fSrobinson (void) strcpy(dbuf, "????????"); 7377c478bd9Sstevel@tonic-gate CDEBUG(5, "%s", dbuf); 7387c478bd9Sstevel@tonic-gate } 739*61961e0fSrobinson if ((*Write)(fn, buf, len) != len) 7407c478bd9Sstevel@tonic-gate return (FAIL); 7417c478bd9Sstevel@tonic-gate return (SUCCESS); 7427c478bd9Sstevel@tonic-gate } 7437c478bd9Sstevel@tonic-gate 744*61961e0fSrobinson static int 7457c478bd9Sstevel@tonic-gate wrchr(int fn, char *buf, int len) 7467c478bd9Sstevel@tonic-gate { 7477c478bd9Sstevel@tonic-gate int i, saccess; 7487c478bd9Sstevel@tonic-gate char cin, cout; 7497c478bd9Sstevel@tonic-gate 7507c478bd9Sstevel@tonic-gate saccess = (sysaccess(ACCESS_SYSTEMS) == 0); /* protect Systems file */ 751*61961e0fSrobinson if (setjmp(Sjbuf)) 7527c478bd9Sstevel@tonic-gate return (FAIL); 7537c478bd9Sstevel@tonic-gate (void) signal(SIGALRM, alarmtr); 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) { 7567c478bd9Sstevel@tonic-gate cout = buf[i]; 7577c478bd9Sstevel@tonic-gate if (saccess) { 7587c478bd9Sstevel@tonic-gate /*EMPTY*/ 7597c478bd9Sstevel@tonic-gate CDEBUG(5, "%s", cout < 040 ? "^" : ""); 7607c478bd9Sstevel@tonic-gate CDEBUG(5, "%c", cout < 040 ? cout | 0100 : cout); 7617c478bd9Sstevel@tonic-gate } else { 7627c478bd9Sstevel@tonic-gate /*EMPTY*/ 7637c478bd9Sstevel@tonic-gate CDEBUG(5, "?%s", ""); 7647c478bd9Sstevel@tonic-gate } 765*61961e0fSrobinson if (((*Write)(fn, &cout, 1)) != 1) 7667c478bd9Sstevel@tonic-gate return (FAIL); 7677c478bd9Sstevel@tonic-gate do { 7687c478bd9Sstevel@tonic-gate (void) alarm(expecttime); 769*61961e0fSrobinson if ((*Read)(fn, &cin, 1) != 1) 7707c478bd9Sstevel@tonic-gate return (FAIL); 7717c478bd9Sstevel@tonic-gate (void) alarm(0); 7727c478bd9Sstevel@tonic-gate cin &= 0177; 7737c478bd9Sstevel@tonic-gate if (saccess) { 7747c478bd9Sstevel@tonic-gate /*EMPTY*/ 7757c478bd9Sstevel@tonic-gate CDEBUG(5, "%s", cin < 040 ? "^" : ""); 7767c478bd9Sstevel@tonic-gate CDEBUG(5, "%c", cin < 040 ? cin | 0100 : cin); 7777c478bd9Sstevel@tonic-gate } else { 7787c478bd9Sstevel@tonic-gate /*EMPTY*/ 7797c478bd9Sstevel@tonic-gate CDEBUG(5, "?%s", ""); 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate } while (cout != (cin & 0177)); 7827c478bd9Sstevel@tonic-gate } 7837c478bd9Sstevel@tonic-gate return (SUCCESS); 7847c478bd9Sstevel@tonic-gate } 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate 7877c478bd9Sstevel@tonic-gate /* 7887c478bd9Sstevel@tonic-gate * notin(sh, lg) check for occurrence of substring "sh" 7897c478bd9Sstevel@tonic-gate * char *sh, *lg; 7907c478bd9Sstevel@tonic-gate * 7917c478bd9Sstevel@tonic-gate * return codes: 7927c478bd9Sstevel@tonic-gate * 0 - found the string 7937c478bd9Sstevel@tonic-gate * 1 - not in the string 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate static int 797*61961e0fSrobinson notin(char *sh, char *lg) 7987c478bd9Sstevel@tonic-gate { 7997c478bd9Sstevel@tonic-gate while (*lg != NULLCHAR) { 800*61961e0fSrobinson if (PREFIX(sh, lg)) 8017c478bd9Sstevel@tonic-gate return (0); 8027c478bd9Sstevel@tonic-gate else 8037c478bd9Sstevel@tonic-gate lg++; 8047c478bd9Sstevel@tonic-gate } 8057c478bd9Sstevel@tonic-gate return (1); 8067c478bd9Sstevel@tonic-gate } 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate /* 8107c478bd9Sstevel@tonic-gate * ifdate(s) 8117c478bd9Sstevel@tonic-gate * char *s; 8127c478bd9Sstevel@tonic-gate * 8137c478bd9Sstevel@tonic-gate * ifdate - this routine will check a string (s) 8147c478bd9Sstevel@tonic-gate * like "MoTu0800-1730" to see if the present 8157c478bd9Sstevel@tonic-gate * time is within the given limits. 8167c478bd9Sstevel@tonic-gate * SIDE EFFECT - Retrytime is set to number following ";" 8177c478bd9Sstevel@tonic-gate * 8187c478bd9Sstevel@tonic-gate * String alternatives: 8197c478bd9Sstevel@tonic-gate * Wk - Mo thru Fr 8207c478bd9Sstevel@tonic-gate * zero or one time means all day 8217c478bd9Sstevel@tonic-gate * Any - any day 8227c478bd9Sstevel@tonic-gate * 8237c478bd9Sstevel@tonic-gate * return codes: 8247c478bd9Sstevel@tonic-gate * 0 - not within limits 8257c478bd9Sstevel@tonic-gate * 1 - within limits 8267c478bd9Sstevel@tonic-gate */ 8277c478bd9Sstevel@tonic-gate 8287c478bd9Sstevel@tonic-gate static int 829*61961e0fSrobinson ifdate(char *s) 8307c478bd9Sstevel@tonic-gate { 8317c478bd9Sstevel@tonic-gate static char *days[] = { 8327c478bd9Sstevel@tonic-gate "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", 0 8337c478bd9Sstevel@tonic-gate }; 8347c478bd9Sstevel@tonic-gate time_t clock; 8357c478bd9Sstevel@tonic-gate int t__now; 8367c478bd9Sstevel@tonic-gate char *p; 8377c478bd9Sstevel@tonic-gate struct tm *tp; 8387c478bd9Sstevel@tonic-gate 839*61961e0fSrobinson (void) time(&clock); 8407c478bd9Sstevel@tonic-gate tp = localtime(&clock); 8417c478bd9Sstevel@tonic-gate t__now = tp->tm_hour * 100 + tp->tm_min; /* "navy" time */ 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate /* 8447c478bd9Sstevel@tonic-gate * pick up retry time for failures 8457c478bd9Sstevel@tonic-gate * global variable Retrytime is set here 8467c478bd9Sstevel@tonic-gate */ 8477c478bd9Sstevel@tonic-gate if ((p = rindex(s, ';')) != NULL) 8487c478bd9Sstevel@tonic-gate if (isdigit(p[1])) { 8497c478bd9Sstevel@tonic-gate if (sscanf(p+1, "%ld", &Retrytime) < 1) 8507c478bd9Sstevel@tonic-gate Retrytime = 5; /* 5 minutes is error default */ 8517c478bd9Sstevel@tonic-gate Retrytime *= 60; 8527c478bd9Sstevel@tonic-gate *p = NULLCHAR; 8537c478bd9Sstevel@tonic-gate } 8547c478bd9Sstevel@tonic-gate 8557c478bd9Sstevel@tonic-gate while (*s) { 8567c478bd9Sstevel@tonic-gate int i, dayok; 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate for (dayok = 0; (!dayok) && isalpha(*s); s++) { 8597c478bd9Sstevel@tonic-gate if (PREFIX("Any", s)) 8607c478bd9Sstevel@tonic-gate dayok = 1; 8617c478bd9Sstevel@tonic-gate else if (PREFIX("Wk", s)) { 8627c478bd9Sstevel@tonic-gate if (tp->tm_wday >= 1 && tp->tm_wday <= 5) 8637c478bd9Sstevel@tonic-gate dayok = 1; 8647c478bd9Sstevel@tonic-gate } else 8657c478bd9Sstevel@tonic-gate for (i = 0; days[i]; i++) 8667c478bd9Sstevel@tonic-gate if (PREFIX(days[i], s)) 8677c478bd9Sstevel@tonic-gate if (tp->tm_wday == i) 8687c478bd9Sstevel@tonic-gate dayok = 1; 8697c478bd9Sstevel@tonic-gate } 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate if (dayok) { 8727c478bd9Sstevel@tonic-gate int t__low, t__high; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate while (isalpha(*s)) /* flush remaining day stuff */ 8757c478bd9Sstevel@tonic-gate s++; 8767c478bd9Sstevel@tonic-gate 877*61961e0fSrobinson if ((sscanf(s, "%d-%d", &t__low, &t__high) < 2) || 878*61961e0fSrobinson (t__low == t__high)) 8797c478bd9Sstevel@tonic-gate return (1); 8807c478bd9Sstevel@tonic-gate 8817c478bd9Sstevel@tonic-gate /* 0000 crossover? */ 8827c478bd9Sstevel@tonic-gate if (t__low < t__high) { 883*61961e0fSrobinson if (t__low <= t__now && t__now <= t__high) 8847c478bd9Sstevel@tonic-gate return (1); 885*61961e0fSrobinson } else if (t__low <= t__now || t__now <= t__high) 8867c478bd9Sstevel@tonic-gate return (1); 8877c478bd9Sstevel@tonic-gate 8887c478bd9Sstevel@tonic-gate /* aim at next time slot */ 8897c478bd9Sstevel@tonic-gate if ((s = index(s, ',')) == NULL) 8907c478bd9Sstevel@tonic-gate break; 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate if (*s) 8937c478bd9Sstevel@tonic-gate s++; 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate return (0); 8967c478bd9Sstevel@tonic-gate } 8977c478bd9Sstevel@tonic-gate 8987c478bd9Sstevel@tonic-gate /* 8997c478bd9Sstevel@tonic-gate * char * 9007c478bd9Sstevel@tonic-gate * fdig(cp) find first digit in string 9017c478bd9Sstevel@tonic-gate * 9027c478bd9Sstevel@tonic-gate * return - pointer to first digit in string or end of string 9037c478bd9Sstevel@tonic-gate */ 9047c478bd9Sstevel@tonic-gate 905*61961e0fSrobinson static char * 906*61961e0fSrobinson fdig(char *cp) 9077c478bd9Sstevel@tonic-gate { 9087c478bd9Sstevel@tonic-gate char *c; 9097c478bd9Sstevel@tonic-gate 9107c478bd9Sstevel@tonic-gate for (c = cp; *c; c++) 9117c478bd9Sstevel@tonic-gate if (*c >= '0' && *c <= '9') 9127c478bd9Sstevel@tonic-gate break; 9137c478bd9Sstevel@tonic-gate return (c); 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate /* nap(n) -- sleep for 'n' ticks of 1/60th sec each. */ 9177c478bd9Sstevel@tonic-gate /* This version uses the select system call */ 9187c478bd9Sstevel@tonic-gate 9197c478bd9Sstevel@tonic-gate 920*61961e0fSrobinson static void 921*61961e0fSrobinson nap(unsigned int n) 9227c478bd9Sstevel@tonic-gate { 9237c478bd9Sstevel@tonic-gate struct timeval tv; 9247c478bd9Sstevel@tonic-gate 925*61961e0fSrobinson if (n == 0) 9267c478bd9Sstevel@tonic-gate return; 9277c478bd9Sstevel@tonic-gate tv.tv_sec = n/60; 9287c478bd9Sstevel@tonic-gate tv.tv_usec = ((n%60)*1000000L)/60; 929*61961e0fSrobinson (void) select(32, 0, 0, 0, &tv); 9307c478bd9Sstevel@tonic-gate } 931