xref: /illumos-gate/usr/src/cmd/bnu/conn.c (revision 3b296559)
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  */
227c478bd9Sstevel@tonic-gate /*
23462be471Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include "uucp.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate GLOBAL char _Protocol[40] = "";	/* working protocol string */
337c478bd9Sstevel@tonic-gate static char _ProtoSys[40] = "";	/* protocol string from Systems file entry */
347c478bd9Sstevel@tonic-gate static char _ProtoDev[40] = "";	/* protocol string from Devices file entry */
357c478bd9Sstevel@tonic-gate EXTERN char _ProtoCfg[];	/* protocol string from Config  file entry */
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate EXTERN jmp_buf Sjbuf;
387c478bd9Sstevel@tonic-gate EXTERN unsigned expecttime;
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate GLOBAL int	Modemctrl;
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* Parity control during login procedure */
437c478bd9Sstevel@tonic-gate #define	P_ZERO	0
447c478bd9Sstevel@tonic-gate #define	P_ONE	1
457c478bd9Sstevel@tonic-gate #define	P_EVEN	2
467c478bd9Sstevel@tonic-gate #define	P_ODD	3
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate static char	par_tab[128];
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate EXTERN void alarmtr();
517c478bd9Sstevel@tonic-gate static void addProto(), mergeProto(), removeProto();
52462be471Sceastha static void bld_partab();
537c478bd9Sstevel@tonic-gate static char *nextProto();
547c478bd9Sstevel@tonic-gate EXTERN char *findProto();
557c478bd9Sstevel@tonic-gate static void getProto();
567c478bd9Sstevel@tonic-gate EXTERN int getto();		/* make this static when ct uses altconn() */
577c478bd9Sstevel@tonic-gate EXTERN int chat(), rddev(), expect(), wrstr(), wrchr();
587c478bd9Sstevel@tonic-gate EXTERN int processdev(), getdevline(), getsysline(), sysaccess();
597c478bd9Sstevel@tonic-gate EXTERN int clear_hup();
607c478bd9Sstevel@tonic-gate EXTERN char *currsys(), *currdev();
617c478bd9Sstevel@tonic-gate static int finds();
627c478bd9Sstevel@tonic-gate static int wait_for_hangup(), expect_str();
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate EXTERN void sendthem(), nap();
657c478bd9Sstevel@tonic-gate static int notin(), ifdate(), checkdate(), checktime(), classmatch();
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate GLOBAL char *Myline = CNULL;	/* to force which line will be used */
687c478bd9Sstevel@tonic-gate GLOBAL char *Mytype = CNULL;	/* to force selection of specific device type */
6920af54a8SToomas Soome EXTERN int Dologin;		/* to force login chat sequence */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * conn - place a telephone call to system and login, etc.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * return codes:
757c478bd9Sstevel@tonic-gate  *	FAIL - connection failed
767c478bd9Sstevel@tonic-gate  *	>0  - file no.  -  connect ok
777c478bd9Sstevel@tonic-gate  * When a failure occurs, Uerror is set.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate GLOBAL int
conn(system)817c478bd9Sstevel@tonic-gate conn(system)
827c478bd9Sstevel@tonic-gate char *system;
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate 	int nf, fn;
857c478bd9Sstevel@tonic-gate 	char *flds[F_MAX+1];
867c478bd9Sstevel@tonic-gate 	EXTERN void sysreset();
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	CDEBUG(4, "conn(%s)\n", system);
897c478bd9Sstevel@tonic-gate 	Uerror = 0;
907c478bd9Sstevel@tonic-gate 	while ((nf = finds(system, flds, F_MAX)) > 0) {
917c478bd9Sstevel@tonic-gate 		fn = getto(flds);
927c478bd9Sstevel@tonic-gate 		CDEBUG(4, "getto ret %d\n", fn);
937c478bd9Sstevel@tonic-gate 		if (fn < 0)
947c478bd9Sstevel@tonic-gate 		    continue;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #ifdef TIOCSPGRP
977c478bd9Sstevel@tonic-gate 		{
987c478bd9Sstevel@tonic-gate #ifdef ATTSV
997c478bd9Sstevel@tonic-gate 		int pgrp = getpgrp();
1007c478bd9Sstevel@tonic-gate #else
1017c478bd9Sstevel@tonic-gate 		int pgrp = getpgrp(0);
1027c478bd9Sstevel@tonic-gate #endif
1037c478bd9Sstevel@tonic-gate 		ioctl(fn, TIOCSPGRP, &pgrp);
1047c478bd9Sstevel@tonic-gate 		}
1057c478bd9Sstevel@tonic-gate #endif
1067c478bd9Sstevel@tonic-gate 		if (Dologin || EQUALS(Progname, "uucico")) {
1077c478bd9Sstevel@tonic-gate 		    if (chat(nf - F_LOGIN, flds + F_LOGIN, fn,"","") == SUCCESS) {
1087c478bd9Sstevel@tonic-gate 			sysreset();
1097c478bd9Sstevel@tonic-gate 			return(fn); /* successful return */
1107c478bd9Sstevel@tonic-gate 		    }
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 		    /* login failed */
1137c478bd9Sstevel@tonic-gate 		    DEBUG(6, "close caller (%d)\n", fn);
1147c478bd9Sstevel@tonic-gate 		    fd_rmlock(fn);
1157c478bd9Sstevel@tonic-gate 		    close(fn);
1167c478bd9Sstevel@tonic-gate 		    if (Dc[0] != NULLCHAR) {
1177c478bd9Sstevel@tonic-gate 			DEBUG(6, "delock line (%s)\n", Dc);
1187c478bd9Sstevel@tonic-gate 		    }
1197c478bd9Sstevel@tonic-gate 		} else {
1207c478bd9Sstevel@tonic-gate 		    sysreset();
1217c478bd9Sstevel@tonic-gate 		    return(fn);
1227c478bd9Sstevel@tonic-gate 		}
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 	/* finds or getto failed */
1267c478bd9Sstevel@tonic-gate 	sysreset();
1277c478bd9Sstevel@tonic-gate 	CDEBUG(1, "Call Failed: %s\n", UERRORTEXT);
1287c478bd9Sstevel@tonic-gate 	return(FAIL);
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * getto - connect to remote machine
1337c478bd9Sstevel@tonic-gate  *
1347c478bd9Sstevel@tonic-gate  * return codes:
1357c478bd9Sstevel@tonic-gate  *	>0  -  file number - ok
1367c478bd9Sstevel@tonic-gate  *	FAIL  -  failed
1377c478bd9Sstevel@tonic-gate  */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate GLOBAL int
getto(flds)1407c478bd9Sstevel@tonic-gate getto(flds)
1417c478bd9Sstevel@tonic-gate char *flds[];
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	char *dev[D_MAX+2], devbuf[BUFSIZ];
144462be471Sceastha 	int status;
145462be471Sceastha 	int dcf = -1;
1467c478bd9Sstevel@tonic-gate 	int reread = 0;
1477c478bd9Sstevel@tonic-gate 	int tries = 0;	/* count of call attempts - for limit purposes */
1487c478bd9Sstevel@tonic-gate 	EXTERN void devreset();
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	CDEBUG(1, "Device Type %s wanted\n", flds[F_TYPE]);
1517c478bd9Sstevel@tonic-gate 	Uerror = 0;
1527c478bd9Sstevel@tonic-gate 	while (tries < TRYCALLS) {
1537c478bd9Sstevel@tonic-gate 		if ((status=rddev(flds[F_TYPE], dev, devbuf, D_MAX)) == FAIL) {
1547c478bd9Sstevel@tonic-gate 			if (tries == 0 || ++reread >= TRYCALLS)
1557c478bd9Sstevel@tonic-gate 				break;
1567c478bd9Sstevel@tonic-gate 			devreset();
1577c478bd9Sstevel@tonic-gate 			continue;
1587c478bd9Sstevel@tonic-gate 		}
1597c478bd9Sstevel@tonic-gate 		/* check class, check (and possibly set) speed */
1607c478bd9Sstevel@tonic-gate 		if (classmatch(flds, dev) != SUCCESS) {
1617c478bd9Sstevel@tonic-gate 		    DEBUG(7, "Skipping entry in '%s'", currdev());
1627c478bd9Sstevel@tonic-gate 		    DEBUG(7, " - class (%s) not wanted.\n", dev[D_CLASS]);
1637c478bd9Sstevel@tonic-gate 		    continue;
1647c478bd9Sstevel@tonic-gate 		}
1657c478bd9Sstevel@tonic-gate                 DEBUG(5, "Trying device entry '%s' ", dev[D_LINE]);
1667c478bd9Sstevel@tonic-gate 		DEBUG(5, "from '%s'.\n", currdev());
1677c478bd9Sstevel@tonic-gate 		if ((dcf = processdev(flds, dev)) >= 0)
1687c478bd9Sstevel@tonic-gate 			break;
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 		switch(Uerror) {
1717c478bd9Sstevel@tonic-gate 		case SS_CANT_ACCESS_DEVICE:
1727c478bd9Sstevel@tonic-gate 		case SS_DEVICE_FAILED:
1737c478bd9Sstevel@tonic-gate 		case SS_LOCKED_DEVICE:
1747c478bd9Sstevel@tonic-gate 		case SS_CHAT_FAILED:
1757c478bd9Sstevel@tonic-gate 			break;
1767c478bd9Sstevel@tonic-gate 		default:
1777c478bd9Sstevel@tonic-gate 			tries++;
1787c478bd9Sstevel@tonic-gate 			break;
1797c478bd9Sstevel@tonic-gate 		}
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 	devreset();	/* reset devices file(s) */
1827c478bd9Sstevel@tonic-gate 	if (status == FAIL && !Uerror) {
1837c478bd9Sstevel@tonic-gate 	    CDEBUG(1, "Requested Device Type Not Found\n%s", "");
1847c478bd9Sstevel@tonic-gate 	    Uerror = SS_NO_DEVICE;
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 	return(dcf);
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * classmatch - process 'Any' in Devices and Systems and
1917c478bd9Sstevel@tonic-gate  * 	determine the correct speed, or match for ==
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate static int
classmatch(flds,dev)1957c478bd9Sstevel@tonic-gate classmatch(flds, dev)
1967c478bd9Sstevel@tonic-gate char *flds[], *dev[];
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate 	/* check class, check (and possibly set) speed */
1997c478bd9Sstevel@tonic-gate 	if (EQUALS(flds[F_CLASS], "Any")
2007c478bd9Sstevel@tonic-gate 	   && EQUALS(dev[D_CLASS], "Any")) {
2017c478bd9Sstevel@tonic-gate 		dev[D_CLASS] = DEFAULT_BAUDRATE;
2027c478bd9Sstevel@tonic-gate 		return(SUCCESS);
2037c478bd9Sstevel@tonic-gate 	} else if (EQUALS(dev[D_CLASS], "Any")) {
2047c478bd9Sstevel@tonic-gate 		dev[D_CLASS] = flds[F_CLASS];
2057c478bd9Sstevel@tonic-gate 		return(SUCCESS);
2067c478bd9Sstevel@tonic-gate 	} else if (EQUALS(flds[F_CLASS], "Any") ||
2077c478bd9Sstevel@tonic-gate 	EQUALS(flds[F_CLASS], dev[D_CLASS]))
2087c478bd9Sstevel@tonic-gate 		return(SUCCESS);
2097c478bd9Sstevel@tonic-gate 	else
2107c478bd9Sstevel@tonic-gate 		return(FAIL);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate /*
21555fea89dSDan Cross  *	rddev - find and unpack a line from device file for this caller type
2167c478bd9Sstevel@tonic-gate  *	lines starting with whitespace of '#' are comments
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  *	return codes:
2197c478bd9Sstevel@tonic-gate  *		>0  -  number of arguments in vector - succeeded
2207c478bd9Sstevel@tonic-gate  *		FAIL - EOF
2217c478bd9Sstevel@tonic-gate  */
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate GLOBAL int
rddev(char * type,char * dev[],char * buf,int devcount)224*3b296559SToomas Soome rddev(char *type, char *dev[], char *buf, int devcount)
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate 	char *commap, d_type[BUFSIZ];
2277c478bd9Sstevel@tonic-gate 	int na;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	while (getdevline(buf, BUFSIZ)) {
2307c478bd9Sstevel@tonic-gate 		if (buf[0] == ' ' || buf[0] == '\t'
2317c478bd9Sstevel@tonic-gate 		    ||  buf[0] == '\n' || buf[0] == '\0' || buf[0] == '#')
2327c478bd9Sstevel@tonic-gate 			continue;
2337c478bd9Sstevel@tonic-gate 		na = getargs(buf, dev, devcount);
2347c478bd9Sstevel@tonic-gate 		ASSERT(na >= D_CALLER, "BAD LINE", buf, na);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 		if ( strncmp(dev[D_LINE],"/dev/",5) == 0 ) {
2377c478bd9Sstevel@tonic-gate 			/* since cu (altconn()) strips off leading */
2387c478bd9Sstevel@tonic-gate 			/* "/dev/",  do the same here.  */
2397c478bd9Sstevel@tonic-gate 			strcpy(dev[D_LINE], &(dev[D_LINE][5]) );
2407c478bd9Sstevel@tonic-gate 		}
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 		/* may have ",M" subfield in D_LINE */
2437c478bd9Sstevel@tonic-gate 		Modemctrl = FALSE;
2447c478bd9Sstevel@tonic-gate 		if ( (commap = strchr(dev[D_LINE], ',')) != (char *)NULL ) {
2457c478bd9Sstevel@tonic-gate 			if ( strcmp( commap, ",M") == SAME )
2467c478bd9Sstevel@tonic-gate 				Modemctrl = TRUE;
2477c478bd9Sstevel@tonic-gate 			*commap = '\0';
2487c478bd9Sstevel@tonic-gate 		}
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 		/*
2517c478bd9Sstevel@tonic-gate 		 * D_TYPE field may have protocol subfield, which
2527c478bd9Sstevel@tonic-gate 		 * must be pulled off before comparing to desired type.
2537c478bd9Sstevel@tonic-gate 		 */
2547c478bd9Sstevel@tonic-gate 		(void)strcpy(d_type, dev[D_TYPE]);
2557c478bd9Sstevel@tonic-gate 		if ((commap = strchr(d_type, ',')) != (char *)NULL )
2567c478bd9Sstevel@tonic-gate 			*commap = '\0';
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 		/* to force the requested device type to be used. */
2597c478bd9Sstevel@tonic-gate 		if ((Mytype != NULL) && (!EQUALS(Mytype, d_type)) )
2607c478bd9Sstevel@tonic-gate 		    continue;
2617c478bd9Sstevel@tonic-gate 		/* to force the requested line to be used */
2627c478bd9Sstevel@tonic-gate 		if ((Myline != NULL) && (!EQUALS(Myline, dev[D_LINE])) )
2637c478bd9Sstevel@tonic-gate 		    continue;
2647c478bd9Sstevel@tonic-gate 
2657c478bd9Sstevel@tonic-gate 		bsfix(dev);	/* replace \X fields */
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 		if (EQUALS(d_type, type)) {
2687c478bd9Sstevel@tonic-gate 			getProto( _ProtoDev, dev[D_TYPE] );
2697c478bd9Sstevel@tonic-gate 			return(na);
2707c478bd9Sstevel@tonic-gate 		}
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 	return(FAIL);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate  * finds	- set system attribute vector
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  * input:
2807c478bd9Sstevel@tonic-gate  *	fsys - open Systems file descriptor
2817c478bd9Sstevel@tonic-gate  *	sysnam - system name to find
2827c478bd9Sstevel@tonic-gate  * output:
2837c478bd9Sstevel@tonic-gate  *	flds - attibute vector from Systems file
2847c478bd9Sstevel@tonic-gate  *	fldcount - number of fields in flds
2857c478bd9Sstevel@tonic-gate  * return codes:
2867c478bd9Sstevel@tonic-gate  *	>0  -  number of arguments in vector - succeeded
2877c478bd9Sstevel@tonic-gate  *	FAIL - failed
2887c478bd9Sstevel@tonic-gate  * Uerror set:
2897c478bd9Sstevel@tonic-gate  *	0 - found a line in Systems file
2907c478bd9Sstevel@tonic-gate  *	SS_BADSYSTEM - no line found in Systems file
2917c478bd9Sstevel@tonic-gate  *	SS_TIME_WRONG - wrong time to call
2927c478bd9Sstevel@tonic-gate  */
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate static int
finds(char * sysnam,char * flds[],int fldcount)295*3b296559SToomas Soome finds(char *sysnam, char *flds[], int fldcount)
2967c478bd9Sstevel@tonic-gate {
2977c478bd9Sstevel@tonic-gate 	static char info[BUFSIZ];
2987c478bd9Sstevel@tonic-gate 	int na;
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	/* format of fields
3017c478bd9Sstevel@tonic-gate 	 *	0 name;
3027c478bd9Sstevel@tonic-gate 	 *	1 time
3037c478bd9Sstevel@tonic-gate 	 *	2 acu/hardwired
3047c478bd9Sstevel@tonic-gate 	 *	3 speed
3057c478bd9Sstevel@tonic-gate 	 *	etc
3067c478bd9Sstevel@tonic-gate 	 */
3077c478bd9Sstevel@tonic-gate 	if (sysnam == 0 || *sysnam == 0 ) {
3087c478bd9Sstevel@tonic-gate 		Uerror = SS_BADSYSTEM;
3097c478bd9Sstevel@tonic-gate 		return(FAIL);
3107c478bd9Sstevel@tonic-gate 	}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	while (getsysline(info, sizeof(info))) {
3137c478bd9Sstevel@tonic-gate 		na = getargs(info, flds, fldcount);
3147c478bd9Sstevel@tonic-gate 		bsfix(flds);	/* replace \X fields */
3157c478bd9Sstevel@tonic-gate 		if ( !EQUALSN(sysnam, flds[F_NAME], MAXBASENAME))
3167c478bd9Sstevel@tonic-gate 			continue;
3177c478bd9Sstevel@tonic-gate 		/* check if requested Mytype device type */
3187c478bd9Sstevel@tonic-gate 		if ((Mytype != CNULL) &&
3197c478bd9Sstevel@tonic-gate 		    (na <= F_TYPE ||
3207c478bd9Sstevel@tonic-gate 			!EQUALSN(flds[F_TYPE], Mytype, strlen(Mytype)))) {
3217c478bd9Sstevel@tonic-gate 		    DEBUG(7, "Skipping entry in '%s'", currsys());
3227c478bd9Sstevel@tonic-gate 		    DEBUG(7, " - type (%s) not wanted.\n", na > F_TYPE ?
3237c478bd9Sstevel@tonic-gate 			flds[F_TYPE] : "Missing type entry");
3247c478bd9Sstevel@tonic-gate 		    continue;
3257c478bd9Sstevel@tonic-gate 		} else {
3267c478bd9Sstevel@tonic-gate 		    DEBUG(5, "Trying entry from '%s'", currsys());
3277c478bd9Sstevel@tonic-gate 		    DEBUG(5, " - device type %s.\n", na > F_TYPE ?
3287c478bd9Sstevel@tonic-gate 			flds[F_TYPE] : "<Missing type entry>");
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 		/* OK if not uucico (ie. ct or cu) or the time is right */
3317c478bd9Sstevel@tonic-gate 		if (!EQUALS(Progname, "uucico") ||
3327c478bd9Sstevel@tonic-gate 		    (na > F_TIME && ifdate(flds[F_TIME]))) {
3337c478bd9Sstevel@tonic-gate 			/*  found a good entry  */
3347c478bd9Sstevel@tonic-gate 			if (na > F_TYPE) {
3357c478bd9Sstevel@tonic-gate 				getProto(_ProtoSys, flds[F_TYPE]);
3367c478bd9Sstevel@tonic-gate 				Uerror = 0;
3377c478bd9Sstevel@tonic-gate 				return(na);	/* FOUND OK LINE */
3387c478bd9Sstevel@tonic-gate 			}
3397c478bd9Sstevel@tonic-gate 			DEBUG(5, "Trying entry from '%s'", currsys());
3407c478bd9Sstevel@tonic-gate 			DEBUG(5, " - Missing type entry for <%s>.\n",
3417c478bd9Sstevel@tonic-gate 				flds[F_NAME]);
3427c478bd9Sstevel@tonic-gate 		} else {
3437c478bd9Sstevel@tonic-gate 			CDEBUG(1, "Wrong Time To Call: %s\n", na > F_TIME ?
3447c478bd9Sstevel@tonic-gate 			    flds[F_TIME] : "<Missing time entry>");
3457c478bd9Sstevel@tonic-gate 			if (!Uerror)
3467c478bd9Sstevel@tonic-gate 				Uerror = SS_TIME_WRONG;
3477c478bd9Sstevel@tonic-gate 		}
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 	if (!Uerror)
3507c478bd9Sstevel@tonic-gate 		Uerror = SS_BADSYSTEM;
3517c478bd9Sstevel@tonic-gate 	return(FAIL);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * getProto - get the protocol letters from the input string.
3567c478bd9Sstevel@tonic-gate  * input:
3577c478bd9Sstevel@tonic-gate  *	str - string from Systems/Devices/Config file,
3587c478bd9Sstevel@tonic-gate  *		a ',' delimits the protocol string
3597c478bd9Sstevel@tonic-gate  *		e.g. ACU,g or DK,d
3607c478bd9Sstevel@tonic-gate  * output:
3617c478bd9Sstevel@tonic-gate  *	str - the , (if present) will be replaced with NULLCHAR
3627c478bd9Sstevel@tonic-gate  *
3637c478bd9Sstevel@tonic-gate  * return:  none
3647c478bd9Sstevel@tonic-gate  */
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate static void
getProto(save,str)3677c478bd9Sstevel@tonic-gate getProto(save, str)
3687c478bd9Sstevel@tonic-gate char *save;
3697c478bd9Sstevel@tonic-gate char *str;
3707c478bd9Sstevel@tonic-gate {
371462be471Sceastha 	char *p;
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	*save = NULLCHAR;
3747c478bd9Sstevel@tonic-gate 	if ( (p=strchr(str, ',')) != NULL) {
3757c478bd9Sstevel@tonic-gate 		*p = NULLCHAR;
3767c478bd9Sstevel@tonic-gate 		(void) strcpy(save, p+1);
3777c478bd9Sstevel@tonic-gate 		DEBUG(7, "Protocol = %s\n", save);
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate 	return;
3807c478bd9Sstevel@tonic-gate }
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate /*
3837c478bd9Sstevel@tonic-gate  * check for a specified protocol selection string
3847c478bd9Sstevel@tonic-gate  * return:
3857c478bd9Sstevel@tonic-gate  *	protocol string pointer
3867c478bd9Sstevel@tonic-gate  *	NULL if none specified for LOGNAME
3877c478bd9Sstevel@tonic-gate  */
3887c478bd9Sstevel@tonic-gate GLOBAL char *
protoString(valid)3897c478bd9Sstevel@tonic-gate protoString(valid)
3907c478bd9Sstevel@tonic-gate char *valid;
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	char *save;
39355fea89dSDan Cross 
3947c478bd9Sstevel@tonic-gate 	save =strdup(valid);
3957c478bd9Sstevel@tonic-gate 	_Protocol[0] = '\0';
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	if ( _ProtoSys[0] != '\0' )
3987c478bd9Sstevel@tonic-gate 	    addProto(_ProtoSys, valid);
3997c478bd9Sstevel@tonic-gate 	if ( _ProtoDev[0] != '\0' )
4007c478bd9Sstevel@tonic-gate 	    addProto(_ProtoDev, valid);
4017c478bd9Sstevel@tonic-gate 	if ( _ProtoCfg[0] != '\0' )
4027c478bd9Sstevel@tonic-gate 	    addProto(_ProtoCfg, valid);
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	if ( _Protocol[0] == '\0' ) {
4057c478bd9Sstevel@tonic-gate 	    (void) strcpy(valid, save);
4067c478bd9Sstevel@tonic-gate 	    (void) strcpy(_Protocol, save);
4077c478bd9Sstevel@tonic-gate 	}
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	return(_Protocol[0] == NULLCHAR ? NULL : _Protocol);
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate /*
4137c478bd9Sstevel@tonic-gate  * addProto
4147c478bd9Sstevel@tonic-gate  *
4157c478bd9Sstevel@tonic-gate  * Verify that the desired protocols from the Systems and Devices file
4167c478bd9Sstevel@tonic-gate  * have been compiled into this application.
4177c478bd9Sstevel@tonic-gate  *
4187c478bd9Sstevel@tonic-gate  * 	desired -	list of desired protocols
4197c478bd9Sstevel@tonic-gate  *	valid -		list of protocols that are compiled in.
4207c478bd9Sstevel@tonic-gate  */
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate static void
addProto(desired,valid)4237c478bd9Sstevel@tonic-gate addProto (desired, valid)
4247c478bd9Sstevel@tonic-gate char *desired;
4257c478bd9Sstevel@tonic-gate char *valid;
4267c478bd9Sstevel@tonic-gate {
427462be471Sceastha 	char *protoPtr;
428462be471Sceastha 	char *wantPtr;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	if ( *desired == '\0' )
4317c478bd9Sstevel@tonic-gate 	    return;
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	if ( *(protoPtr = _Protocol) != NULLCHAR ) {
4347c478bd9Sstevel@tonic-gate 	    while ( *(protoPtr = nextProto(protoPtr)) != NULLCHAR ) {
4357c478bd9Sstevel@tonic-gate 		if ( *(wantPtr = findProto(desired, *protoPtr)) == NULLCHAR ) {
43655fea89dSDan Cross 		    removeProto(valid, *protoPtr);
43755fea89dSDan Cross 		    removeProto(protoPtr, *protoPtr);
4387c478bd9Sstevel@tonic-gate 		} else {
4397c478bd9Sstevel@tonic-gate 		    mergeProto(protoPtr, wantPtr);
4407c478bd9Sstevel@tonic-gate 		    protoPtr++;
4417c478bd9Sstevel@tonic-gate 		}
4427c478bd9Sstevel@tonic-gate 	    }
4437c478bd9Sstevel@tonic-gate 	} else {
4447c478bd9Sstevel@tonic-gate 	    wantPtr = desired;
4457c478bd9Sstevel@tonic-gate 	    while ( *(wantPtr = nextProto(wantPtr)) != NULLCHAR ) {
4467c478bd9Sstevel@tonic-gate 		if ( *(findProto(valid, *wantPtr)) != NULLCHAR ) {
4477c478bd9Sstevel@tonic-gate 		    mergeProto(protoPtr, wantPtr);
4487c478bd9Sstevel@tonic-gate 		}
4497c478bd9Sstevel@tonic-gate 		wantPtr++;
4507c478bd9Sstevel@tonic-gate 	    }
4517c478bd9Sstevel@tonic-gate 	}
4527c478bd9Sstevel@tonic-gate 	if ( *(protoPtr = _Protocol) != NULLCHAR ) {
4537c478bd9Sstevel@tonic-gate 	    while ( *(protoPtr = nextProto(protoPtr)) != NULLCHAR )
4547c478bd9Sstevel@tonic-gate 		*(valid++) = *(protoPtr++);
4557c478bd9Sstevel@tonic-gate 	    *valid = NULLCHAR;
4567c478bd9Sstevel@tonic-gate 	}
4577c478bd9Sstevel@tonic-gate 	return;
4587c478bd9Sstevel@tonic-gate }
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate /*
4617c478bd9Sstevel@tonic-gate  * mergeProto
4627c478bd9Sstevel@tonic-gate  *
4637c478bd9Sstevel@tonic-gate  * input
4647c478bd9Sstevel@tonic-gate  * 	char *tostring, *fromstring;
4657c478bd9Sstevel@tonic-gate  */
4667c478bd9Sstevel@tonic-gate static void
mergeProto(tostring,fromstring)4677c478bd9Sstevel@tonic-gate mergeProto(tostring, fromstring)
4687c478bd9Sstevel@tonic-gate char *tostring, *fromstring;
4697c478bd9Sstevel@tonic-gate {
4707c478bd9Sstevel@tonic-gate 	char buffer[BUFSIZ];
4717c478bd9Sstevel@tonic-gate 	int length;
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	while ( *(tostring = nextProto(tostring)) != NULLCHAR ) {
4747c478bd9Sstevel@tonic-gate 	    if ( *tostring == *fromstring )
4757c478bd9Sstevel@tonic-gate 		break;
4767c478bd9Sstevel@tonic-gate 	    else
4777c478bd9Sstevel@tonic-gate 		tostring++;
4787c478bd9Sstevel@tonic-gate 	}
47955fea89dSDan Cross 
4807c478bd9Sstevel@tonic-gate 	if ( *tostring == NULLCHAR ) {
4817c478bd9Sstevel@tonic-gate 	    length = nextProto(fromstring + 1) - fromstring;
4827c478bd9Sstevel@tonic-gate 	    (void) strncpy(tostring, fromstring, length);
4837c478bd9Sstevel@tonic-gate 	    *(tostring + length) = NULLCHAR;
4847c478bd9Sstevel@tonic-gate 	} else {
4857c478bd9Sstevel@tonic-gate 	    tostring++;
4867c478bd9Sstevel@tonic-gate 	    fromstring++;
4877c478bd9Sstevel@tonic-gate 	    if ( (*tostring !=  '(') && (*fromstring == '(') ) {
4887c478bd9Sstevel@tonic-gate 		(void) strcpy(buffer, tostring);
4897c478bd9Sstevel@tonic-gate 		length = nextProto(fromstring) - fromstring;
4907c478bd9Sstevel@tonic-gate 	        (void) strncpy(tostring, fromstring, length);
4917c478bd9Sstevel@tonic-gate 		(void) strcpy(tostring+length, buffer);
4927c478bd9Sstevel@tonic-gate 	    }
4937c478bd9Sstevel@tonic-gate 	}
4947c478bd9Sstevel@tonic-gate 	return;
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate /*
4987c478bd9Sstevel@tonic-gate  * removeProto
4997c478bd9Sstevel@tonic-gate  *
5007c478bd9Sstevel@tonic-gate  * char *old
5017c478bd9Sstevel@tonic-gate  * char letter
5027c478bd9Sstevel@tonic-gate  *
5037c478bd9Sstevel@tonic-gate  * return
5047c478bd9Sstevel@tonic-gate  *	none
5057c478bd9Sstevel@tonic-gate  */
5067c478bd9Sstevel@tonic-gate static void
removeProto(string,letter)5077c478bd9Sstevel@tonic-gate removeProto(string, letter)
5087c478bd9Sstevel@tonic-gate char *string, letter;
5097c478bd9Sstevel@tonic-gate {
5107c478bd9Sstevel@tonic-gate 	while ( *(string = nextProto(string)) != NULLCHAR ) {
5117c478bd9Sstevel@tonic-gate 	    if ( *string == letter )
5127c478bd9Sstevel@tonic-gate 		(void) strcpy(string, nextProto(string+1));
5137c478bd9Sstevel@tonic-gate 	    else
5147c478bd9Sstevel@tonic-gate 		string++;
5157c478bd9Sstevel@tonic-gate 	}
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate 
51855fea89dSDan Cross /*
5197c478bd9Sstevel@tonic-gate  * nextProto
5207c478bd9Sstevel@tonic-gate  *	char *string;
5217c478bd9Sstevel@tonic-gate  * return
5227c478bd9Sstevel@tonic-gate  *	char * to next non-parameter letter
5237c478bd9Sstevel@tonic-gate  */
5247c478bd9Sstevel@tonic-gate static char *
nextProto(string)5257c478bd9Sstevel@tonic-gate nextProto(string)
5267c478bd9Sstevel@tonic-gate char *string;
5277c478bd9Sstevel@tonic-gate {
5287c478bd9Sstevel@tonic-gate 	if ( *string == '(' )
5297c478bd9Sstevel@tonic-gate 	    while ( *string != NULLCHAR )
5307c478bd9Sstevel@tonic-gate 		if ( *(string++) == ')' )
5317c478bd9Sstevel@tonic-gate 		    break;
5327c478bd9Sstevel@tonic-gate 	return(string);
5337c478bd9Sstevel@tonic-gate }
5347c478bd9Sstevel@tonic-gate 
53555fea89dSDan Cross /*
5367c478bd9Sstevel@tonic-gate  * findProto
5377c478bd9Sstevel@tonic-gate  *	char *desired,
5387c478bd9Sstevel@tonic-gate  *	char protoPtr;
5397c478bd9Sstevel@tonic-gate  * return
5407c478bd9Sstevel@tonic-gate  *	char *pointer to found or string terminating NULLCHAR
5417c478bd9Sstevel@tonic-gate  */
5427c478bd9Sstevel@tonic-gate GLOBAL char *
findProto(string,letter)5437c478bd9Sstevel@tonic-gate findProto(string, letter)
5447c478bd9Sstevel@tonic-gate char *string;
5457c478bd9Sstevel@tonic-gate char letter;
5467c478bd9Sstevel@tonic-gate {
5477c478bd9Sstevel@tonic-gate 	while ( *(string = nextProto(string)) != NULLCHAR )
5487c478bd9Sstevel@tonic-gate 	    if ( *string == letter )
5497c478bd9Sstevel@tonic-gate 		break;
5507c478bd9Sstevel@tonic-gate 	    else
5517c478bd9Sstevel@tonic-gate 		string++;
5527c478bd9Sstevel@tonic-gate 	return(string);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate /*
5567c478bd9Sstevel@tonic-gate  * chat -	do conversation
5577c478bd9Sstevel@tonic-gate  * input:
5587c478bd9Sstevel@tonic-gate  *	nf - number of fields in flds array
5597c478bd9Sstevel@tonic-gate  *	flds - fields from Systems file
5607c478bd9Sstevel@tonic-gate  *	fn - write file number
5617c478bd9Sstevel@tonic-gate  *	phstr1 - phone number to replace \D
5627c478bd9Sstevel@tonic-gate  *	phstr2 - phone number to replace \T
5637c478bd9Sstevel@tonic-gate  *
5647c478bd9Sstevel@tonic-gate  *	return codes:  0  |  FAIL
5657c478bd9Sstevel@tonic-gate  */
5667c478bd9Sstevel@tonic-gate 
5677c478bd9Sstevel@tonic-gate GLOBAL int
chat(nf,flds,fn,phstr1,phstr2)5687c478bd9Sstevel@tonic-gate chat(nf, flds, fn, phstr1, phstr2)
5697c478bd9Sstevel@tonic-gate char *flds[], *phstr1, *phstr2;
5707c478bd9Sstevel@tonic-gate int nf, fn;
5717c478bd9Sstevel@tonic-gate {
5727c478bd9Sstevel@tonic-gate 	char *want, *altern;
5737c478bd9Sstevel@tonic-gate 	int k, ok;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	for (k = 0; k < nf; k += 2) {
5767c478bd9Sstevel@tonic-gate 		want = flds[k];
5777c478bd9Sstevel@tonic-gate 		ok = FAIL;
5787c478bd9Sstevel@tonic-gate 		while (ok != 0) {
5797c478bd9Sstevel@tonic-gate 			altern = index(want, '-');
5807c478bd9Sstevel@tonic-gate 			if (altern != NULL)
5817c478bd9Sstevel@tonic-gate 				*altern++ = NULLCHAR;
5827c478bd9Sstevel@tonic-gate 			ok = expect(want, fn);
5837c478bd9Sstevel@tonic-gate 			if (ok == 0)
5847c478bd9Sstevel@tonic-gate 				break;
5857c478bd9Sstevel@tonic-gate 			if (altern == NULL) {
5867c478bd9Sstevel@tonic-gate 				Uerror = SS_LOGIN_FAILED;
5877c478bd9Sstevel@tonic-gate 				logent(UERRORTEXT, "FAILED");
5887c478bd9Sstevel@tonic-gate 				return(FAIL);
5897c478bd9Sstevel@tonic-gate 			}
5907c478bd9Sstevel@tonic-gate 			want = index(altern, '-');
5917c478bd9Sstevel@tonic-gate 			if (want != NULL)
5927c478bd9Sstevel@tonic-gate 				*want++ = NULLCHAR;
5937c478bd9Sstevel@tonic-gate 			sendthem(altern, fn, phstr1, phstr2);
5947c478bd9Sstevel@tonic-gate 		}
5957c478bd9Sstevel@tonic-gate 		sleep(2);
5967c478bd9Sstevel@tonic-gate 		if (flds[k+1])
5977c478bd9Sstevel@tonic-gate 		    sendthem(flds[k+1], fn, phstr1, phstr2);
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 	return(0);
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate #define MR 1000
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate  *	expect(str, fn)	look for expected string w/ possible special chars
6067c478bd9Sstevel@tonic-gate  *
6077c478bd9Sstevel@tonic-gate  *	return codes:
6087c478bd9Sstevel@tonic-gate  *		0  -  found
6097c478bd9Sstevel@tonic-gate  *		FAIL  -  too many characters read
6107c478bd9Sstevel@tonic-gate  *		some character  -  timed out
6117c478bd9Sstevel@tonic-gate  */
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate GLOBAL int
expect(str,fn)6147c478bd9Sstevel@tonic-gate expect(str, fn)
6157c478bd9Sstevel@tonic-gate char *str;
6167c478bd9Sstevel@tonic-gate int fn;
6177c478bd9Sstevel@tonic-gate {
618462be471Sceastha 	char *bptr, *sptr;
6197c478bd9Sstevel@tonic-gate 	char    buf[BUFSIZ];
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	bptr = buf;
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	for (sptr = str; *sptr; sptr++) {
6247c478bd9Sstevel@tonic-gate 		if (*sptr == '\\') {
6257c478bd9Sstevel@tonic-gate 			switch (*++sptr) {
6267c478bd9Sstevel@tonic-gate 			case 'H':
6277c478bd9Sstevel@tonic-gate 				*bptr++ = '\0';
6287c478bd9Sstevel@tonic-gate 				if (expect_str(buf, fn) == FAIL) {
6297c478bd9Sstevel@tonic-gate 					return (FAIL);
6307c478bd9Sstevel@tonic-gate 				}
6317c478bd9Sstevel@tonic-gate 				if (wait_for_hangup(fn) == FAIL) {
6327c478bd9Sstevel@tonic-gate 					return (FAIL);
6337c478bd9Sstevel@tonic-gate 				}
6347c478bd9Sstevel@tonic-gate 				bptr = buf;
6357c478bd9Sstevel@tonic-gate 				continue;
6367c478bd9Sstevel@tonic-gate 			case '\\':
6377c478bd9Sstevel@tonic-gate 				*bptr++ = '\\';
6387c478bd9Sstevel@tonic-gate 				continue;
6397c478bd9Sstevel@tonic-gate 			default:
6407c478bd9Sstevel@tonic-gate 				*bptr++ = '\\';
6417c478bd9Sstevel@tonic-gate 				*bptr++ = *sptr;
6427c478bd9Sstevel@tonic-gate 				continue;
6437c478bd9Sstevel@tonic-gate 			}
6447c478bd9Sstevel@tonic-gate 		} else
6457c478bd9Sstevel@tonic-gate 			*bptr++ = *sptr;
6467c478bd9Sstevel@tonic-gate 	}
6477c478bd9Sstevel@tonic-gate 	*bptr = '\0';
6487c478bd9Sstevel@tonic-gate 	if (expect_str(buf, fn) == FAIL) {
6497c478bd9Sstevel@tonic-gate 		return (FAIL);
6507c478bd9Sstevel@tonic-gate 	}
6517c478bd9Sstevel@tonic-gate 	return (0);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate /*
6557c478bd9Sstevel@tonic-gate  *	expect_str(str, fn)	look for expected string, w/ no special chars
6567c478bd9Sstevel@tonic-gate  *
6577c478bd9Sstevel@tonic-gate  *	return codes:
6587c478bd9Sstevel@tonic-gate  *		0  -  found
6597c478bd9Sstevel@tonic-gate  *		FAIL  -  too many characters read
6607c478bd9Sstevel@tonic-gate  *		some character  -  timed out
6617c478bd9Sstevel@tonic-gate  */
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate GLOBAL int
expect_str(str,fn)6647c478bd9Sstevel@tonic-gate expect_str(str, fn)
6657c478bd9Sstevel@tonic-gate char *str;
6667c478bd9Sstevel@tonic-gate int fn;
6677c478bd9Sstevel@tonic-gate {
6687c478bd9Sstevel@tonic-gate 	static char rdvec[MR];
6697c478bd9Sstevel@tonic-gate 	char *rp = rdvec;
670462be471Sceastha 	int kr, c;
6717c478bd9Sstevel@tonic-gate 	char nextch;
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	*rp = 0;
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 	CDEBUG(4, "expect: (%s", "");
6767c478bd9Sstevel@tonic-gate 	for (c=0; (kr=str[c]) != 0 ; c++)
6777c478bd9Sstevel@tonic-gate 		if (kr < 040) {
6787c478bd9Sstevel@tonic-gate 			CDEBUG(4, "^%c", kr | 0100);
6797c478bd9Sstevel@tonic-gate 		} else
6807c478bd9Sstevel@tonic-gate 			CDEBUG(4, "%c", kr);
6817c478bd9Sstevel@tonic-gate 	CDEBUG(4, ")\n%s", "");
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "\"\"")) {
6847c478bd9Sstevel@tonic-gate 		CDEBUG(4, "got it\n%s", "");
6857c478bd9Sstevel@tonic-gate 		return(0);
6867c478bd9Sstevel@tonic-gate 	}
6877c478bd9Sstevel@tonic-gate 	if (*str== '\0') {
6887c478bd9Sstevel@tonic-gate 		return(0);
6897c478bd9Sstevel@tonic-gate 	}
6907c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf)) {
6917c478bd9Sstevel@tonic-gate 		return (FAIL);
6927c478bd9Sstevel@tonic-gate 	}
6937c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
6947c478bd9Sstevel@tonic-gate 	alarm(expecttime);
6957c478bd9Sstevel@tonic-gate 	while (notin(str, rdvec)) {
6967c478bd9Sstevel@tonic-gate 		errno = 0;
6977c478bd9Sstevel@tonic-gate 		kr = (*Read)(fn, &nextch, 1);
6987c478bd9Sstevel@tonic-gate 		if (kr <= 0) {
6997c478bd9Sstevel@tonic-gate 			alarm(0);
7007c478bd9Sstevel@tonic-gate 			CDEBUG(4, "lost line errno - %d\n", errno);
7017c478bd9Sstevel@tonic-gate 			logent("LOGIN", "LOST LINE");
7027c478bd9Sstevel@tonic-gate 			return(FAIL);
7037c478bd9Sstevel@tonic-gate 		}
7047c478bd9Sstevel@tonic-gate 		c = nextch & 0177;
7057c478bd9Sstevel@tonic-gate 		CDEBUG(4, "%s", c < 040 ? "^" : "");
7067c478bd9Sstevel@tonic-gate 		CDEBUG(4, "%c", c < 040 ? c | 0100 : c);
7077c478bd9Sstevel@tonic-gate 		if ((*rp = nextch & 0177) != NULLCHAR)
7087c478bd9Sstevel@tonic-gate 			rp++;
7097c478bd9Sstevel@tonic-gate 		if (rp >= rdvec + MR) {
7107c478bd9Sstevel@tonic-gate 			CDEBUG(4, "enough already\n%s", "");
7117c478bd9Sstevel@tonic-gate 			alarm(0);
7127c478bd9Sstevel@tonic-gate 			return(FAIL);
7137c478bd9Sstevel@tonic-gate 		}
7147c478bd9Sstevel@tonic-gate 		*rp = NULLCHAR;
7157c478bd9Sstevel@tonic-gate 	}
7167c478bd9Sstevel@tonic-gate 	alarm(0);
7177c478bd9Sstevel@tonic-gate 	CDEBUG(4, "got it\n%s", "");
7187c478bd9Sstevel@tonic-gate 	return(0);
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate /*
7217c478bd9Sstevel@tonic-gate  *	alarmtr()  -  catch alarm routine for "expect".
7227c478bd9Sstevel@tonic-gate  */
7237c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7247c478bd9Sstevel@tonic-gate GLOBAL void
alarmtr(sig)7257c478bd9Sstevel@tonic-gate alarmtr(sig)
7267c478bd9Sstevel@tonic-gate int sig;
7277c478bd9Sstevel@tonic-gate {
7287c478bd9Sstevel@tonic-gate 	CDEBUG(6, "timed out\n%s", "");
7297c478bd9Sstevel@tonic-gate 	longjmp(Sjbuf, 1);
7307c478bd9Sstevel@tonic-gate }
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate /*
7337c478bd9Sstevel@tonic-gate  *	wait_for_hangup() - wait for a hangup to occur on the given device
7347c478bd9Sstevel@tonic-gate  */
7357c478bd9Sstevel@tonic-gate int
wait_for_hangup(dcf)7367c478bd9Sstevel@tonic-gate wait_for_hangup(dcf)
7377c478bd9Sstevel@tonic-gate 	int dcf;
7387c478bd9Sstevel@tonic-gate {
7397c478bd9Sstevel@tonic-gate 	int rval;
7407c478bd9Sstevel@tonic-gate 	char buff[BUFSIZ];
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate 	CDEBUG(4, "Waiting for hangup\n%s", "");
7437c478bd9Sstevel@tonic-gate 	while((rval = read(dcf, buff, BUFSIZ)) > 0);
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	if (rval < 0) {
7467c478bd9Sstevel@tonic-gate 		return (FAIL);
7477c478bd9Sstevel@tonic-gate 	}
7487c478bd9Sstevel@tonic-gate 	CDEBUG(4, "Received hangup\n%s", "");
7497c478bd9Sstevel@tonic-gate 
7507c478bd9Sstevel@tonic-gate 	if (clear_hup(dcf) != SUCCESS) {
7517c478bd9Sstevel@tonic-gate 	    CDEBUG(4, "Unable to clear hup on device\n%s", "");
7527c478bd9Sstevel@tonic-gate 	    return (FAIL);
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate 	return (SUCCESS);
7557c478bd9Sstevel@tonic-gate }
75655fea89dSDan Cross 
7577c478bd9Sstevel@tonic-gate /*
7587c478bd9Sstevel@tonic-gate  *	sendthem(str, fn, phstr1, phstr2)	send line of chat sequence
7597c478bd9Sstevel@tonic-gate  *	char *str, *phstr;
7607c478bd9Sstevel@tonic-gate  *
7617c478bd9Sstevel@tonic-gate  *	return codes:  none
7627c478bd9Sstevel@tonic-gate  */
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate #define FLUSH() {\
7657c478bd9Sstevel@tonic-gate 	if ((bptr - buf) > 0)\
7667c478bd9Sstevel@tonic-gate 		if (wrstr(fn, buf, bptr - buf, echocheck) != SUCCESS)\
7677c478bd9Sstevel@tonic-gate 			goto err;\
7687c478bd9Sstevel@tonic-gate 	bptr = buf;\
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate 
7717c478bd9Sstevel@tonic-gate GLOBAL void
sendthem(str,fn,phstr1,phstr2)7727c478bd9Sstevel@tonic-gate sendthem(str, fn, phstr1, phstr2)
7737c478bd9Sstevel@tonic-gate char *str, *phstr1, *phstr2;
7747c478bd9Sstevel@tonic-gate int fn;
7757c478bd9Sstevel@tonic-gate {
7767c478bd9Sstevel@tonic-gate 	int sendcr = 1, echocheck = 0;
777462be471Sceastha 	char	*sptr, *bptr;
7787c478bd9Sstevel@tonic-gate 	char	buf[BUFSIZ];
7797c478bd9Sstevel@tonic-gate 	struct termio	ttybuf;
7807c478bd9Sstevel@tonic-gate 	static int p_init = 0;
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 	if (!p_init) {
7837c478bd9Sstevel@tonic-gate 		p_init++;
7847c478bd9Sstevel@tonic-gate 		bld_partab(P_EVEN);
7857c478bd9Sstevel@tonic-gate 	}
7867c478bd9Sstevel@tonic-gate 
7877c478bd9Sstevel@tonic-gate 	/* should be EQUALS, but previous versions had BREAK n for integer n */
7887c478bd9Sstevel@tonic-gate 	if (PREFIX("BREAK", str)) {
7897c478bd9Sstevel@tonic-gate 		/* send break */
7907c478bd9Sstevel@tonic-gate 		CDEBUG(5, "BREAK\n%s", "");
7917c478bd9Sstevel@tonic-gate 		(*genbrk)(fn);
7927c478bd9Sstevel@tonic-gate 		return;
7937c478bd9Sstevel@tonic-gate 	}
7947c478bd9Sstevel@tonic-gate 
7957c478bd9Sstevel@tonic-gate 	if (PREFIX("STTY=", str)) {
7967c478bd9Sstevel@tonic-gate 		CDEBUG(5, "STTY %s\n", str+5);
7977c478bd9Sstevel@tonic-gate 		setmode(str+5, fn);
7987c478bd9Sstevel@tonic-gate 		return;
7997c478bd9Sstevel@tonic-gate 	}
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "EOT")) {
8027c478bd9Sstevel@tonic-gate 		CDEBUG(5, "EOT\n%s", "");
8037c478bd9Sstevel@tonic-gate 		bptr = buf;
8047c478bd9Sstevel@tonic-gate 		for (sptr = EOTMSG; *sptr; sptr++)
8057c478bd9Sstevel@tonic-gate 			*bptr++ = par_tab[*sptr&0177];
8067c478bd9Sstevel@tonic-gate 		(void) (*Write)(fn, buf, bptr - buf);
8077c478bd9Sstevel@tonic-gate 		return;
8087c478bd9Sstevel@tonic-gate 	}
8097c478bd9Sstevel@tonic-gate 
8107c478bd9Sstevel@tonic-gate 	/* Set parity as needed */
8117c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "P_ZERO")) {
8127c478bd9Sstevel@tonic-gate 		bld_partab(P_ZERO);
8137c478bd9Sstevel@tonic-gate 		return;
8147c478bd9Sstevel@tonic-gate 	}
8157c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "P_ONE")) {
8167c478bd9Sstevel@tonic-gate 		bld_partab(P_ONE);
8177c478bd9Sstevel@tonic-gate 		return;
8187c478bd9Sstevel@tonic-gate 	}
8197c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "P_EVEN")) {
8207c478bd9Sstevel@tonic-gate 		bld_partab(P_EVEN);
8217c478bd9Sstevel@tonic-gate 		return;
8227c478bd9Sstevel@tonic-gate 	}
8237c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "P_ODD")) {
8247c478bd9Sstevel@tonic-gate 		bld_partab(P_ODD);
8257c478bd9Sstevel@tonic-gate 		return;
8267c478bd9Sstevel@tonic-gate 	}
8277c478bd9Sstevel@tonic-gate 
8287c478bd9Sstevel@tonic-gate 	if (EQUALS(str, "\"\"")) {
8297c478bd9Sstevel@tonic-gate 		CDEBUG(5, "\"\"\n%s", "");
8307c478bd9Sstevel@tonic-gate 		str += 2;
8317c478bd9Sstevel@tonic-gate 	}
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	bptr = buf;
8347c478bd9Sstevel@tonic-gate 	CDEBUG(5, "sendthem (%s", "");
8357c478bd9Sstevel@tonic-gate 	for (sptr = str; *sptr; sptr++) {
8367c478bd9Sstevel@tonic-gate 		if (*sptr == '\\') {
8377c478bd9Sstevel@tonic-gate 			switch(*++sptr) {
8387c478bd9Sstevel@tonic-gate 
8397c478bd9Sstevel@tonic-gate 			/* adjust switches */
8407c478bd9Sstevel@tonic-gate 			case 'c':	/* no CR after string */
8417c478bd9Sstevel@tonic-gate 				FLUSH();
8427c478bd9Sstevel@tonic-gate 				if (sptr[1] == NULLCHAR) {
8437c478bd9Sstevel@tonic-gate 					CDEBUG(5, "<NO CR>%s", "");
8447c478bd9Sstevel@tonic-gate 					sendcr = 0;
8457c478bd9Sstevel@tonic-gate 				} else
8467c478bd9Sstevel@tonic-gate 					CDEBUG(5, "<NO CR IGNORED>\n%s", "");
8477c478bd9Sstevel@tonic-gate 				continue;
8487c478bd9Sstevel@tonic-gate 
8497c478bd9Sstevel@tonic-gate 			/* stash in buf and continue */
8507c478bd9Sstevel@tonic-gate 			case 'D':	/* raw phnum */
8517c478bd9Sstevel@tonic-gate 				strcpy(bptr, phstr1);
8527c478bd9Sstevel@tonic-gate 				bptr += strlen(bptr);
8537c478bd9Sstevel@tonic-gate 				continue;
8547c478bd9Sstevel@tonic-gate 			case 'T':	/* translated phnum */
8557c478bd9Sstevel@tonic-gate 				strcpy(bptr, phstr2);
8567c478bd9Sstevel@tonic-gate 				bptr += strlen(bptr);
8577c478bd9Sstevel@tonic-gate 				continue;
8587c478bd9Sstevel@tonic-gate 			case 'N':	/* null */
8597c478bd9Sstevel@tonic-gate 				*bptr++ = 0;
8607c478bd9Sstevel@tonic-gate 				continue;
8617c478bd9Sstevel@tonic-gate 			case 's':	/* space */
8627c478bd9Sstevel@tonic-gate 				*bptr++ = ' ';
8637c478bd9Sstevel@tonic-gate 				continue;
8647c478bd9Sstevel@tonic-gate 			case '\\':	/* backslash escapes itself */
8657c478bd9Sstevel@tonic-gate 				*bptr++ = *sptr;
8667c478bd9Sstevel@tonic-gate 				continue;
8677c478bd9Sstevel@tonic-gate 			default:	/* send the backslash */
8687c478bd9Sstevel@tonic-gate 				*bptr++ = '\\';
86955fea89dSDan Cross 				*bptr++ = *sptr;
8707c478bd9Sstevel@tonic-gate 				continue;
8717c478bd9Sstevel@tonic-gate 
8727c478bd9Sstevel@tonic-gate 			/* flush buf, perform action, and continue */
8737c478bd9Sstevel@tonic-gate 			case 'E':	/* echo check on */
8747c478bd9Sstevel@tonic-gate 				FLUSH();
8757c478bd9Sstevel@tonic-gate 				CDEBUG(5, "ECHO CHECK ON\n%s", "");
8767c478bd9Sstevel@tonic-gate 				echocheck = 1;
8777c478bd9Sstevel@tonic-gate 				continue;
8787c478bd9Sstevel@tonic-gate 			case 'e':	/* echo check off */
8797c478bd9Sstevel@tonic-gate 				FLUSH();
8807c478bd9Sstevel@tonic-gate 				CDEBUG(5, "ECHO CHECK OFF\n%s", "");
8817c478bd9Sstevel@tonic-gate 				echocheck = 0;
8827c478bd9Sstevel@tonic-gate 				continue;
8837c478bd9Sstevel@tonic-gate 			case 'd':	/* sleep briefly */
8847c478bd9Sstevel@tonic-gate 				FLUSH();
8857c478bd9Sstevel@tonic-gate 				CDEBUG(5, "DELAY\n%s", "");
8867c478bd9Sstevel@tonic-gate 				sleep(2);
8877c478bd9Sstevel@tonic-gate 				continue;
8887c478bd9Sstevel@tonic-gate 			case 'p':	/* pause momentarily */
8897c478bd9Sstevel@tonic-gate 				FLUSH();
8907c478bd9Sstevel@tonic-gate 				CDEBUG(5, "PAUSE\n%s", "");
8917c478bd9Sstevel@tonic-gate 				nap(HZ/4);	/* approximately 1/4 second */
8927c478bd9Sstevel@tonic-gate 				continue;
8937c478bd9Sstevel@tonic-gate 			case 'K':	/* inline break */
8947c478bd9Sstevel@tonic-gate 				FLUSH();
8957c478bd9Sstevel@tonic-gate 				CDEBUG(5, "BREAK\n%s", "");
8967c478bd9Sstevel@tonic-gate 				(*genbrk)(fn);
8977c478bd9Sstevel@tonic-gate 				continue;
8987c478bd9Sstevel@tonic-gate 			case 'M':	/* modem control - set CLOCAL */
8997c478bd9Sstevel@tonic-gate 			case 'm':	/* no modem control - clear CLOCAL */
9007c478bd9Sstevel@tonic-gate 				FLUSH();
9017c478bd9Sstevel@tonic-gate 				CDEBUG(5, ")\n%s CLOCAL ",
9027c478bd9Sstevel@tonic-gate 					(*sptr == 'M' ? "set" : "clear"));
9037c478bd9Sstevel@tonic-gate #ifdef ATTSVTTY
9047c478bd9Sstevel@tonic-gate 				if ( (*Ioctl)(fn, TCGETA, &ttybuf) != 0  ) {
9057c478bd9Sstevel@tonic-gate 				    CDEBUG(5, "ignored. TCGETA failed, errno %d", errno);
9067c478bd9Sstevel@tonic-gate 				} else {
9077c478bd9Sstevel@tonic-gate 				    if (*sptr == 'M')
9087c478bd9Sstevel@tonic-gate 					ttybuf.c_cflag |= CLOCAL;
9097c478bd9Sstevel@tonic-gate 				    else
9107c478bd9Sstevel@tonic-gate 					ttybuf.c_cflag &= ~CLOCAL;
9117c478bd9Sstevel@tonic-gate 				    if ( (*Ioctl)(fn, TCSETAW, &ttybuf) != 0 )
9127c478bd9Sstevel@tonic-gate 					CDEBUG(5, "failed. TCSETAW failed, errno %d", errno);
9137c478bd9Sstevel@tonic-gate 				}
9147c478bd9Sstevel@tonic-gate #endif
9157c478bd9Sstevel@tonic-gate 				CDEBUG(5, "\n%s", "");
9167c478bd9Sstevel@tonic-gate 				continue;
9177c478bd9Sstevel@tonic-gate 			}
9187c478bd9Sstevel@tonic-gate 		} else
9197c478bd9Sstevel@tonic-gate 			*bptr++ = *sptr;
9207c478bd9Sstevel@tonic-gate 	}
9217c478bd9Sstevel@tonic-gate 	if (sendcr)
9227c478bd9Sstevel@tonic-gate 		*bptr++ = '\r';
9237c478bd9Sstevel@tonic-gate 	if ( (bptr - buf) > 0 )
9247c478bd9Sstevel@tonic-gate 		(void) wrstr(fn, buf, bptr - buf, echocheck);
9257c478bd9Sstevel@tonic-gate 
9267c478bd9Sstevel@tonic-gate err:
9277c478bd9Sstevel@tonic-gate 	CDEBUG(5, ")\n%s", "");
9287c478bd9Sstevel@tonic-gate 	return;
9297c478bd9Sstevel@tonic-gate }
9307c478bd9Sstevel@tonic-gate 
9317c478bd9Sstevel@tonic-gate /*
9327c478bd9Sstevel@tonic-gate  * generate parity table for use by sendthem.
9337c478bd9Sstevel@tonic-gate  */
934462be471Sceastha static void
bld_partab(type)9357c478bd9Sstevel@tonic-gate bld_partab(type)
9367c478bd9Sstevel@tonic-gate int type;
9377c478bd9Sstevel@tonic-gate {
938462be471Sceastha 	int i, j, n;
9397c478bd9Sstevel@tonic-gate 
9407c478bd9Sstevel@tonic-gate 	for (i = 0; i < 128; i++) {
9417c478bd9Sstevel@tonic-gate 		n = 0;
9427c478bd9Sstevel@tonic-gate 		for (j = i&0177; j; j = (j-1)&j)
9437c478bd9Sstevel@tonic-gate 			n++;
9447c478bd9Sstevel@tonic-gate 		par_tab[i] = i;
9457c478bd9Sstevel@tonic-gate 		if (type == P_ONE
9467c478bd9Sstevel@tonic-gate 		 || (type == P_EVEN && (n&01) != 0)
9477c478bd9Sstevel@tonic-gate 		 || (type == P_ODD && (n&01) == 0))
9487c478bd9Sstevel@tonic-gate 			par_tab[i] |= 0200;
9497c478bd9Sstevel@tonic-gate 	}
9507c478bd9Sstevel@tonic-gate }
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate #undef FLUSH
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate GLOBAL int
wrstr(int fn,char * buf,int len,int echocheck)955*3b296559SToomas Soome wrstr(int fn, char *buf, int len, int echocheck)
9567c478bd9Sstevel@tonic-gate {
9577c478bd9Sstevel@tonic-gate 	int 	i;
9587c478bd9Sstevel@tonic-gate 	char dbuf[BUFSIZ], *dbptr = dbuf;
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 	if (echocheck)
9617c478bd9Sstevel@tonic-gate 		return(wrchr(fn, buf, len));
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	if (Debug >= 5) {
9647c478bd9Sstevel@tonic-gate 		if (sysaccess(ACCESS_SYSTEMS) == 0) { /* Systems file access ok */
9657c478bd9Sstevel@tonic-gate 			for (i = 0; i < len; i++) {
9667c478bd9Sstevel@tonic-gate 				*dbptr = buf[i];
9677c478bd9Sstevel@tonic-gate 				if (*dbptr < 040) {
9687c478bd9Sstevel@tonic-gate 					*dbptr++ = '^';
9697c478bd9Sstevel@tonic-gate 					*dbptr = buf[i] | 0100;
9707c478bd9Sstevel@tonic-gate 				}
9717c478bd9Sstevel@tonic-gate 				dbptr++;
9727c478bd9Sstevel@tonic-gate 			}
9737c478bd9Sstevel@tonic-gate 			*dbptr = 0;
9747c478bd9Sstevel@tonic-gate 		} else
9757c478bd9Sstevel@tonic-gate 			strcpy(dbuf, "????????");
9767c478bd9Sstevel@tonic-gate 		CDEBUG(5, "%s", dbuf);
9777c478bd9Sstevel@tonic-gate 	}
9787c478bd9Sstevel@tonic-gate 	dbptr = dbuf;
9797c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; i++)
9807c478bd9Sstevel@tonic-gate 		*dbptr++ = par_tab[buf[i]&0177];
9817c478bd9Sstevel@tonic-gate 	if ((*Write)(fn, dbuf, len) != len)
9827c478bd9Sstevel@tonic-gate 		return(FAIL);
9837c478bd9Sstevel@tonic-gate 	return(SUCCESS);
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate GLOBAL int
wrchr(int fn,char * buf,int len)987*3b296559SToomas Soome wrchr(int fn, char *buf, int len)
9887c478bd9Sstevel@tonic-gate {
9897c478bd9Sstevel@tonic-gate 	int 	i, saccess;
9907c478bd9Sstevel@tonic-gate 	char	cin, cout;
9917c478bd9Sstevel@tonic-gate 
9927c478bd9Sstevel@tonic-gate 	saccess = (sysaccess(ACCESS_SYSTEMS) == 0); /* protect Systems file */
9937c478bd9Sstevel@tonic-gate 	if (setjmp(Sjbuf))
9947c478bd9Sstevel@tonic-gate 		return(FAIL);
9957c478bd9Sstevel@tonic-gate 	(void) signal(SIGALRM, alarmtr);
9967c478bd9Sstevel@tonic-gate 
9977c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; i++) {
9987c478bd9Sstevel@tonic-gate 		cout = buf[i]&0177;
9997c478bd9Sstevel@tonic-gate 		if (saccess) {
10007c478bd9Sstevel@tonic-gate 			CDEBUG(5, "%s", cout < 040 ? "^" : "");
10017c478bd9Sstevel@tonic-gate 			CDEBUG(5, "%c", cout < 040 ? cout | 0100 : cout);
10027c478bd9Sstevel@tonic-gate 		} else
10037c478bd9Sstevel@tonic-gate 			CDEBUG(5, "?%s", "");
10047c478bd9Sstevel@tonic-gate 		if (((*Write)(fn, &par_tab[cout], 1)) != 1)
10057c478bd9Sstevel@tonic-gate 			return(FAIL);
10067c478bd9Sstevel@tonic-gate 		do {
10077c478bd9Sstevel@tonic-gate 			(void) alarm(expecttime);
10087c478bd9Sstevel@tonic-gate 			if ((*Read)(fn, &cin, 1) != 1)
10097c478bd9Sstevel@tonic-gate 				return(FAIL);
10107c478bd9Sstevel@tonic-gate 			(void) alarm(0);
10117c478bd9Sstevel@tonic-gate 			cin &= 0177;
10127c478bd9Sstevel@tonic-gate 			if (saccess) {
10137c478bd9Sstevel@tonic-gate 				CDEBUG(5, "%s", cin < 040 ? "^" : "");
10147c478bd9Sstevel@tonic-gate 				CDEBUG(5, "%c", cin < 040 ? cin | 0100 : cin);
10157c478bd9Sstevel@tonic-gate 			} else
10167c478bd9Sstevel@tonic-gate 				CDEBUG(5, "?%s", "");
10177c478bd9Sstevel@tonic-gate 		} while (cout != cin);
10187c478bd9Sstevel@tonic-gate 	}
10197c478bd9Sstevel@tonic-gate 	return(SUCCESS);
10207c478bd9Sstevel@tonic-gate }
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate /*
10247c478bd9Sstevel@tonic-gate  *	notin(sh, lg)	check for occurrence of substring "sh"
10257c478bd9Sstevel@tonic-gate  *	char *sh, *lg;
10267c478bd9Sstevel@tonic-gate  *
10277c478bd9Sstevel@tonic-gate  *	return codes:
10287c478bd9Sstevel@tonic-gate  *		0  -  found the string
10297c478bd9Sstevel@tonic-gate  *		1  -  not in the string
10307c478bd9Sstevel@tonic-gate  */
10317c478bd9Sstevel@tonic-gate 
10327c478bd9Sstevel@tonic-gate static int
notin(sh,lg)10337c478bd9Sstevel@tonic-gate notin(sh, lg)
10347c478bd9Sstevel@tonic-gate char *sh, *lg;
10357c478bd9Sstevel@tonic-gate {
10367c478bd9Sstevel@tonic-gate 	while (*lg != NULLCHAR) {
10377c478bd9Sstevel@tonic-gate 		if (PREFIX(sh, lg))
10387c478bd9Sstevel@tonic-gate 			return(0);
10397c478bd9Sstevel@tonic-gate 		else
10407c478bd9Sstevel@tonic-gate 			lg++;
10417c478bd9Sstevel@tonic-gate 	}
10427c478bd9Sstevel@tonic-gate 	return(1);
10437c478bd9Sstevel@tonic-gate }
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate /*
10477c478bd9Sstevel@tonic-gate  *	ifdate(s)
10487c478bd9Sstevel@tonic-gate  *	char *s;
10497c478bd9Sstevel@tonic-gate  *
10507c478bd9Sstevel@tonic-gate  *	ifdate  -  this routine will check a string (s)
10517c478bd9Sstevel@tonic-gate  *	like "MoTu0800-1730" to see if the present
10527c478bd9Sstevel@tonic-gate  *	time is within the given limits.
10537c478bd9Sstevel@tonic-gate  *
10547c478bd9Sstevel@tonic-gate  *	SIDE EFFECT - Retrytime is set to number following ";"
10557c478bd9Sstevel@tonic-gate  *	SIDE EFFECT - MaxGrade is set to character following "/"
10567c478bd9Sstevel@tonic-gate  *
10577c478bd9Sstevel@tonic-gate  *	if a grade is specified, iswrk() is consulted, so that we don't
10587c478bd9Sstevel@tonic-gate  *	place calls when there's only low priority work.  this will appear
10597c478bd9Sstevel@tonic-gate  *	as a "wrong time to call" in the status file.  sorry.
10607c478bd9Sstevel@tonic-gate  *
10617c478bd9Sstevel@tonic-gate  *	String alternatives:
10627c478bd9Sstevel@tonic-gate  *		Wk - Mo thru Fr
10637c478bd9Sstevel@tonic-gate  *		zero or one time means all day
10647c478bd9Sstevel@tonic-gate  *		Any - any day
10657c478bd9Sstevel@tonic-gate  *
10667c478bd9Sstevel@tonic-gate  *	return codes:
10677c478bd9Sstevel@tonic-gate  *		0  -  not within limits, or grade too low
10687c478bd9Sstevel@tonic-gate  *		1  -  within limits
10697c478bd9Sstevel@tonic-gate  */
10707c478bd9Sstevel@tonic-gate 
10717c478bd9Sstevel@tonic-gate static int
ifdate(s)10727c478bd9Sstevel@tonic-gate ifdate(s)
10737c478bd9Sstevel@tonic-gate char *s;
10747c478bd9Sstevel@tonic-gate {
10757c478bd9Sstevel@tonic-gate 	char	*r;
10767c478bd9Sstevel@tonic-gate #ifdef MAXGRADE
10777c478bd9Sstevel@tonic-gate 	char	*m, grade;
10787c478bd9Sstevel@tonic-gate #endif
10797c478bd9Sstevel@tonic-gate 	struct tm	*tp;
10807c478bd9Sstevel@tonic-gate 	time_t	clock;
10817c478bd9Sstevel@tonic-gate 	int	t__now;
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate 	time(&clock);
10847c478bd9Sstevel@tonic-gate 	tp = localtime(&clock);
10857c478bd9Sstevel@tonic-gate 	t__now = tp->tm_hour * 100 + tp->tm_min;	/* "navy" time */
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	/*
10887c478bd9Sstevel@tonic-gate 	 *	pick up retry time for failures and max grade
10897c478bd9Sstevel@tonic-gate 	 *	global variables Retrytime and MaxGrade are set here
10907c478bd9Sstevel@tonic-gate 	 */
10917c478bd9Sstevel@tonic-gate 	r = strrchr(s, ';');
10927c478bd9Sstevel@tonic-gate 
10937c478bd9Sstevel@tonic-gate 	/* set retry time */
10947c478bd9Sstevel@tonic-gate 	if (r != NULL) {
10957c478bd9Sstevel@tonic-gate 	    if (isdigit(r[1])) {
10967c478bd9Sstevel@tonic-gate 		if (sscanf(r+1, "%ld", &Retrytime) < 1)
10977c478bd9Sstevel@tonic-gate 			Retrytime = 5;	/* 5 minutes is error default */
10987c478bd9Sstevel@tonic-gate 		DEBUG(5, "Retry time set to %d minutes\n", Retrytime);
10997c478bd9Sstevel@tonic-gate 		Retrytime *= 60;	/* convert to seconds */
11007c478bd9Sstevel@tonic-gate 		*r = NULLCHAR;		/* blow away retry time field */
11017c478bd9Sstevel@tonic-gate 	    }
11027c478bd9Sstevel@tonic-gate 	} else
11037c478bd9Sstevel@tonic-gate 	    Retrytime = 0;	/* use exponential backoff */
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate #ifdef MAXGRADE
11067c478bd9Sstevel@tonic-gate 	/* set grade */
11077c478bd9Sstevel@tonic-gate 	MaxGrade = NULLCHAR;			/* default */
11087c478bd9Sstevel@tonic-gate 	m = strrchr(s, '/');
11097c478bd9Sstevel@tonic-gate 	if (m != NULL) {
11107c478bd9Sstevel@tonic-gate 	    if (isalnum(m[1]))
11117c478bd9Sstevel@tonic-gate 		MaxGrade = m[1];	/* you asked for it! */
11127c478bd9Sstevel@tonic-gate 	    *m = NULLCHAR;		/* blow away max grade field */
11137c478bd9Sstevel@tonic-gate 	    DEBUG(5, "Max Grade set to %c\n", MaxGrade);
11147c478bd9Sstevel@tonic-gate 	}
11157c478bd9Sstevel@tonic-gate 
11167c478bd9Sstevel@tonic-gate 	/* test grade */
11177c478bd9Sstevel@tonic-gate 	if (MaxGrade != NULLCHAR) {
11187c478bd9Sstevel@tonic-gate 	    grade = iswrk(CNULL);
11197c478bd9Sstevel@tonic-gate 	    if (grade == NULLCHAR || MaxGrade < grade) {
11207c478bd9Sstevel@tonic-gate 		DEBUG(4, "No work of grade %c -- no call\n", MaxGrade);
11217c478bd9Sstevel@tonic-gate 		return(0);
11227c478bd9Sstevel@tonic-gate 	    }
11237c478bd9Sstevel@tonic-gate 	}
11247c478bd9Sstevel@tonic-gate #endif /* MAXGRADE */
11257c478bd9Sstevel@tonic-gate 
11267c478bd9Sstevel@tonic-gate 
11277c478bd9Sstevel@tonic-gate 	while (checkdate(s, tp, t__now) == 0) {
11287c478bd9Sstevel@tonic-gate 		s = strchr(s, ',');
11297c478bd9Sstevel@tonic-gate 		if (s == CNULL)
11307c478bd9Sstevel@tonic-gate 			return(0);
11317c478bd9Sstevel@tonic-gate 		s++;
11327c478bd9Sstevel@tonic-gate 	}
11337c478bd9Sstevel@tonic-gate 	return(1);
11347c478bd9Sstevel@tonic-gate }
11357c478bd9Sstevel@tonic-gate 
11367c478bd9Sstevel@tonic-gate /* worker function for ifdate() */
11377c478bd9Sstevel@tonic-gate static int
checkdate(s,tp,t__now)11387c478bd9Sstevel@tonic-gate checkdate(s, tp, t__now)
11397c478bd9Sstevel@tonic-gate char *s;
11407c478bd9Sstevel@tonic-gate struct tm	*tp;
11417c478bd9Sstevel@tonic-gate int	t__now;
11427c478bd9Sstevel@tonic-gate {
11437c478bd9Sstevel@tonic-gate 	static char *days[] = {
11447c478bd9Sstevel@tonic-gate 		"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", 0
11457c478bd9Sstevel@tonic-gate 	};
11467c478bd9Sstevel@tonic-gate 	int	i;
11477c478bd9Sstevel@tonic-gate 
11487c478bd9Sstevel@tonic-gate 	/*
11497c478bd9Sstevel@tonic-gate 	 * check day of week
11507c478bd9Sstevel@tonic-gate 	 */
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 	while (isalpha(*s)) {
11537c478bd9Sstevel@tonic-gate 		if (PREFIX("Any", s))
11547c478bd9Sstevel@tonic-gate 			return(checktime(s, t__now));
11557c478bd9Sstevel@tonic-gate 
11567c478bd9Sstevel@tonic-gate 		if (PREFIX("Wk", s) && tp->tm_wday >= 1 && tp->tm_wday <= 5)
11577c478bd9Sstevel@tonic-gate 			return(checktime(s, t__now));
11587c478bd9Sstevel@tonic-gate 
11597c478bd9Sstevel@tonic-gate 		for (i = 0; days[i]; i++)
11607c478bd9Sstevel@tonic-gate 			if (PREFIX(days[i], s) && tp->tm_wday == i)
11617c478bd9Sstevel@tonic-gate 				return(checktime(s, t__now));
11627c478bd9Sstevel@tonic-gate 		s++;
11637c478bd9Sstevel@tonic-gate 	}
11647c478bd9Sstevel@tonic-gate 
11657c478bd9Sstevel@tonic-gate 	return(0);	/* day match failed */
11667c478bd9Sstevel@tonic-gate }
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate /* day match ok -- check time */
11697c478bd9Sstevel@tonic-gate static int
checktime(s,t__now)11707c478bd9Sstevel@tonic-gate checktime(s, t__now)
11717c478bd9Sstevel@tonic-gate char *s;
11727c478bd9Sstevel@tonic-gate int	t__now;
11737c478bd9Sstevel@tonic-gate {
11747c478bd9Sstevel@tonic-gate 	int	t__low, t__high;
11757c478bd9Sstevel@tonic-gate 
11767c478bd9Sstevel@tonic-gate 	while (isalpha(*s))	/* flush day stuff */
11777c478bd9Sstevel@tonic-gate 		s++;
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	if ((sscanf(s, "%d-%d", &t__low, &t__high) < 2))
11807c478bd9Sstevel@tonic-gate 		return(1);	/* time match ok (default) */
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	if (t__low == t__high)
11837c478bd9Sstevel@tonic-gate 		return(1);
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	/* 0000 crossover? */
11867c478bd9Sstevel@tonic-gate 	if (t__low < t__high) {
11877c478bd9Sstevel@tonic-gate 		if (t__low <= t__now && t__now <= t__high)
11887c478bd9Sstevel@tonic-gate 			return(1);
11897c478bd9Sstevel@tonic-gate 	} else {
11907c478bd9Sstevel@tonic-gate 		if (t__low <= t__now || t__now <= t__high)
11917c478bd9Sstevel@tonic-gate 			return(1);
11927c478bd9Sstevel@tonic-gate 	}
11937c478bd9Sstevel@tonic-gate 
11947c478bd9Sstevel@tonic-gate 	return(0);
11957c478bd9Sstevel@tonic-gate }
11967c478bd9Sstevel@tonic-gate 
11977c478bd9Sstevel@tonic-gate /*
11987c478bd9Sstevel@tonic-gate  *	char *
11997c478bd9Sstevel@tonic-gate  *	fdig(cp)	find first digit in string
12007c478bd9Sstevel@tonic-gate  *
12017c478bd9Sstevel@tonic-gate  *	return - pointer to first digit in string or end of string
12027c478bd9Sstevel@tonic-gate  */
12037c478bd9Sstevel@tonic-gate 
12047c478bd9Sstevel@tonic-gate GLOBAL char *
fdig(cp)12057c478bd9Sstevel@tonic-gate fdig(cp)
12067c478bd9Sstevel@tonic-gate char *cp;
12077c478bd9Sstevel@tonic-gate {
12087c478bd9Sstevel@tonic-gate 	char *c;
12097c478bd9Sstevel@tonic-gate 
12107c478bd9Sstevel@tonic-gate 	for (c = cp; *c; c++)
12117c478bd9Sstevel@tonic-gate 		if (*c >= '0' && *c <= '9')
12127c478bd9Sstevel@tonic-gate 			break;
12137c478bd9Sstevel@tonic-gate 	return(c);
12147c478bd9Sstevel@tonic-gate }
12157c478bd9Sstevel@tonic-gate 
12167c478bd9Sstevel@tonic-gate 
12177c478bd9Sstevel@tonic-gate #ifdef FASTTIMER
12187c478bd9Sstevel@tonic-gate /*	Sleep in increments of 60ths of second.	*/
12197c478bd9Sstevel@tonic-gate GLOBAL void
nap(time)12207c478bd9Sstevel@tonic-gate nap (time)
1221462be471Sceastha int time;
12227c478bd9Sstevel@tonic-gate {
12237c478bd9Sstevel@tonic-gate 	static int fd;
12247c478bd9Sstevel@tonic-gate 
12257c478bd9Sstevel@tonic-gate 	if (fd == 0)
12267c478bd9Sstevel@tonic-gate 		fd = open (FASTTIMER, 0);
12277c478bd9Sstevel@tonic-gate 
12287c478bd9Sstevel@tonic-gate 	(void) (*Read)(fd, 0, time);
12297c478bd9Sstevel@tonic-gate 	return;
12307c478bd9Sstevel@tonic-gate }
12317c478bd9Sstevel@tonic-gate 
12327c478bd9Sstevel@tonic-gate #endif /* FASTTIMER */
12337c478bd9Sstevel@tonic-gate 
12347c478bd9Sstevel@tonic-gate #if defined(BSD4_2) || defined(ATTSVR4)
12357c478bd9Sstevel@tonic-gate 
12367c478bd9Sstevel@tonic-gate 	/* nap(n) -- sleep for 'n' ticks of 1/60th sec each. */
12377c478bd9Sstevel@tonic-gate 	/* This version uses the select system call */
12387c478bd9Sstevel@tonic-gate 
12397c478bd9Sstevel@tonic-gate 
12407c478bd9Sstevel@tonic-gate GLOBAL void
nap(n)12417c478bd9Sstevel@tonic-gate nap(n)
12427c478bd9Sstevel@tonic-gate unsigned n;
12437c478bd9Sstevel@tonic-gate {
12447c478bd9Sstevel@tonic-gate 	struct timeval tv;
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 	if (n==0)
12477c478bd9Sstevel@tonic-gate 		return;
12487c478bd9Sstevel@tonic-gate 	tv.tv_sec = n/60;
12497c478bd9Sstevel@tonic-gate 	tv.tv_usec = ((n%60)*1000000L)/60;
12507c478bd9Sstevel@tonic-gate 	(void) select(32, 0, 0, 0, &tv);
12517c478bd9Sstevel@tonic-gate 	return;
12527c478bd9Sstevel@tonic-gate }
12537c478bd9Sstevel@tonic-gate 
12547c478bd9Sstevel@tonic-gate #endif /* BSD4_2 || ATTSVR4 */
12557c478bd9Sstevel@tonic-gate 
12567c478bd9Sstevel@tonic-gate #ifdef NONAP
12577c478bd9Sstevel@tonic-gate 
12587c478bd9Sstevel@tonic-gate /*	nap(n) where n is ticks
12597c478bd9Sstevel@tonic-gate  *
12607c478bd9Sstevel@tonic-gate  *	loop using n/HZ part of a second
12617c478bd9Sstevel@tonic-gate  *	if n represents more than 1 second, then
12627c478bd9Sstevel@tonic-gate  *	use sleep(time) where time is the equivalent
12637c478bd9Sstevel@tonic-gate  *	seconds rounded off to full seconds
12647c478bd9Sstevel@tonic-gate  *	NOTE - this is a rough approximation and chews up
12657c478bd9Sstevel@tonic-gate  *	processor resource!
12667c478bd9Sstevel@tonic-gate  */
12677c478bd9Sstevel@tonic-gate 
12687c478bd9Sstevel@tonic-gate GLOBAL void
nap(n)12697c478bd9Sstevel@tonic-gate nap(n)
12707c478bd9Sstevel@tonic-gate unsigned n;
12717c478bd9Sstevel@tonic-gate {
12727c478bd9Sstevel@tonic-gate 	struct tms	tbuf;
12737c478bd9Sstevel@tonic-gate 	long endtime;
12747c478bd9Sstevel@tonic-gate 	int i;
12757c478bd9Sstevel@tonic-gate 
12767c478bd9Sstevel@tonic-gate 	if (n > HZ) {
12777c478bd9Sstevel@tonic-gate 		/* > second, use sleep, rounding time */
12787c478bd9Sstevel@tonic-gate 		sleep( (int) (((n)+HZ/2)/HZ) );
12797c478bd9Sstevel@tonic-gate 		return;
12807c478bd9Sstevel@tonic-gate 	}
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate 	/* use timing loop for < 1 second */
12837c478bd9Sstevel@tonic-gate 	endtime = times(&tbuf) + 3*n/4;	/* use 3/4 because of scheduler! */
12847c478bd9Sstevel@tonic-gate 	while (times(&tbuf) < endtime) {
12857c478bd9Sstevel@tonic-gate 	    for (i=0; i<1000; i++, (void) (i*i))
12867c478bd9Sstevel@tonic-gate 		;
12877c478bd9Sstevel@tonic-gate 	}
12887c478bd9Sstevel@tonic-gate 	return;
12897c478bd9Sstevel@tonic-gate }
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate #endif /* NONAP */
12927c478bd9Sstevel@tonic-gate 
12937c478bd9Sstevel@tonic-gate /*
12947c478bd9Sstevel@tonic-gate 
129555fea89dSDan Cross  * altconn - place a telephone call to system
12967c478bd9Sstevel@tonic-gate  * from cu when telephone number or direct line used
12977c478bd9Sstevel@tonic-gate  *
12987c478bd9Sstevel@tonic-gate  * return codes:
12997c478bd9Sstevel@tonic-gate  *	FAIL - connection failed
13007c478bd9Sstevel@tonic-gate  *	>0  - file no.  -  connect ok
13017c478bd9Sstevel@tonic-gate  * When a failure occurs, Uerror is set.
13027c478bd9Sstevel@tonic-gate  */
13037c478bd9Sstevel@tonic-gate GLOBAL int
altconn(call)13047c478bd9Sstevel@tonic-gate altconn(call)
13057c478bd9Sstevel@tonic-gate struct call *call;
13067c478bd9Sstevel@tonic-gate {
13077c478bd9Sstevel@tonic-gate 	int fn = FAIL;
13087c478bd9Sstevel@tonic-gate 	char *alt[7];
13097c478bd9Sstevel@tonic-gate 	EXTERN char *Myline;
13107c478bd9Sstevel@tonic-gate 
13117c478bd9Sstevel@tonic-gate 	alt[F_NAME] = "dummy";	/* to replace the Systems file fields  */
13127c478bd9Sstevel@tonic-gate 	alt[F_TIME] = "Any";	/* needed for getto(); [F_TYPE] and    */
13137c478bd9Sstevel@tonic-gate 	alt[F_TYPE] = "";	/* [F_PHONE] assignment below          */
13147c478bd9Sstevel@tonic-gate 	alt[F_CLASS] = call->speed;
13157c478bd9Sstevel@tonic-gate 	alt[F_PHONE] = "";
13167c478bd9Sstevel@tonic-gate 	alt[F_LOGIN] = "";
13177c478bd9Sstevel@tonic-gate 	alt[6] = NULL;
13187c478bd9Sstevel@tonic-gate 
13197c478bd9Sstevel@tonic-gate 	CDEBUG(4,"altconn called\r\n%s", "");
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 	/* cu -l dev ...					*/
13227c478bd9Sstevel@tonic-gate 	/* if is "/dev/device", strip off "/dev/" because must	*/
13237c478bd9Sstevel@tonic-gate 	/* exactly match entries in Devices file, which usually	*/
13247c478bd9Sstevel@tonic-gate 	/* omit the "/dev/".  if doesn't begin with "/dev/",	*/
13257c478bd9Sstevel@tonic-gate 	/* either they've omitted the "/dev/" or it's a non-	*/
13267c478bd9Sstevel@tonic-gate 	/* standard path name.  in either case, leave it as is	*/
13277c478bd9Sstevel@tonic-gate 
13287c478bd9Sstevel@tonic-gate 	if(call->line != NULL ) {
13297c478bd9Sstevel@tonic-gate 		if ( strncmp(call->line, "/dev/", 5) == 0 ) {
13307c478bd9Sstevel@tonic-gate 			Myline = (call->line + 5);
13317c478bd9Sstevel@tonic-gate 		} else {
13327c478bd9Sstevel@tonic-gate 			Myline = call->line;
13337c478bd9Sstevel@tonic-gate 		}
13347c478bd9Sstevel@tonic-gate 	}
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate 	/* cu  ... telno */
13377c478bd9Sstevel@tonic-gate 	if(call->telno != NULL) {
13387c478bd9Sstevel@tonic-gate 		alt[F_PHONE] = call->telno;
13397c478bd9Sstevel@tonic-gate 		alt[F_TYPE] = "ACU";
13407c478bd9Sstevel@tonic-gate 	} else {
13417c478bd9Sstevel@tonic-gate 	/* cu direct line */
13427c478bd9Sstevel@tonic-gate 		alt[F_TYPE] = "Direct";
13437c478bd9Sstevel@tonic-gate 	}
13447c478bd9Sstevel@tonic-gate 	if (call->type != NULL)
13457c478bd9Sstevel@tonic-gate 		alt[F_TYPE] = call->type;
13467c478bd9Sstevel@tonic-gate 	fn = getto(alt);
13477c478bd9Sstevel@tonic-gate 	CDEBUG(4, "getto ret %d\n", fn);
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	return(fn);
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate }
1352