conn.c revision d67944fbe3fa0b31893a7116a09b0718eecf6078
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "mt.h"
#include "uucp.h"
static char _ProtoCfg[]; /* protocol string from Config file entry */
static unsigned expecttime;
static int Modemctrl;
static void alarmtr(int);
static void getProto(char *, char *);
static int finds(char *, char *[], int);
static int getto(char *[]); /* make this static when ct uses altconn() */
static int chat(int, char *[], int, char *, char *);
static int rddev(char *, char *[], char *, int);
static int expect(char *, int);
static int wrstr(int, char *, int, int);
static int wrchr(int, char *, int);
static int processdev(char *[], char *[]);
static int getdevline(char *, int);
static int getsysline(char *, int);
static int sysaccess(int);
static int clear_hup(int);
#ifndef SMALL
static char *currsys(void);
static char *currdev(void);
#endif
static int wait_for_hangup(int);
static int expect_str(char *, int);
static void sendthem(char *, int, char *, char *);
static void nap(unsigned int);
static int notin(char *, char *);
static int ifdate(char *);
static int classmatch(char *[], char *[]);
/*
* conn - place a telephone call to system and login, etc.
*
* return codes:
* FAIL - connection failed
* >0 - file no. - connect ok
* When a failure occurs, Uerror is set.
*/
static void sysreset(void);
static int
{
Uerror = 0;
if (fn < 0)
continue;
SUCCESS) {
sysreset();
return (fn); /* successful return */
}
/* login failed */
/*EMPTY*/
}
} else {
sysreset();
return (fn);
}
}
/* finds or getto failed */
sysreset();
return (FAIL);
}
static void devreset(void);
/*
* getto - connect to remote machine
*
* return codes:
* >0 - file number - ok
* FAIL - failed
*/
static int
{
int status;
int dcf = -1;
int reread = 0;
int tries = 0; /* count of call attempts - for limit purposes */
Uerror = 0;
FAIL) {
break;
devreset();
continue;
}
/* check class, check (and possibly set) speed */
continue;
}
break;
switch (Uerror) {
case SS_CANT_ACCESS_DEVICE:
case SS_DEVICE_FAILED:
case SS_LOCKED_DEVICE:
break;
default:
tries++;
break;
}
}
devreset(); /* reset devices file(s) */
}
return (dcf);
}
/*
* classmatch - process 'Any' in Devices and Systems and
* determine the correct speed, or match for ==
*/
static int
{
/* check class, check (and possibly set) speed */
return (SUCCESS);
return (SUCCESS);
return (SUCCESS);
else
return (FAIL);
}
/*
* rddev - find and unpack a line from device file for this caller type
* lines starting with whitespace of '#' are comments
*
* return codes:
* >0 - number of arguments in vector - succeeded
* FAIL - EOF
*/
static int
{
int na;
continue;
/* since cu (altconn()) strips off leading */
/* "/dev/", do the same here. */
}
/* may have ",M" subfield in D_LINE */
*commap = '\0';
}
/*
* D_TYPE field may have protocol subfield, which
* must be pulled off before comparing to desired type.
*/
*commap = '\0';
/* to force the requested device type to be used. */
continue;
/* to force the requested line to be used */
continue;
return (na);
}
}
return (FAIL);
}
/*
* finds - set system attribute vector
*
* input:
* fsys - open Systems file descriptor
* sysnam - system name to find
* output:
* flds - attibute vector from Systems file
* fldcount - number of fields in flds
* return codes:
* >0 - number of arguments in vector - succeeded
* FAIL - failed
* Uerror set:
* 0 - found a line in Systems file
* SS_BADSYSTEM - no line found in Systems file
* SS_TIME_WRONG - wrong time to call
*/
static int
{
static char *info; /* dynamically allocated BUFSIZ */
int na;
/*
* format of fields
* 0 name;
* 1 time
* 3 speed
* etc
*/
return (FAIL);
}
return (0);
}
}
continue;
/* check if requested Mytype device type */
continue;
} else {
/*EMPTY*/
}
/* OK if not uucico (ie. ct or cu) or the time is right */
/* found a good entry */
Uerror = 0;
return (na); /* FOUND OK LINE */
}
}
if (!Uerror)
return (FAIL);
}
/*
* getProto - get the protocol letters from the input string.
* input:
* a ',' delimits the protocol string
* e.g. ACU,g or DK,d
* output:
* str - the , (if present) will be replaced with NULLCHAR
*
* return: none
*/
static void
{
char *p;
*p = NULLCHAR;
}
}
/*
* chat - do conversation
* input:
* nf - number of fields in flds array
* flds - fields from Systems file
* fn - write file number
* phstr1 - phone number to replace \D
* phstr2 - phone number to replace \T
*
* return codes: 0 | FAIL
*/
static int
{
int k, ok;
for (k = 0; k < nf; k += 2) {
while (ok != 0) {
if (ok == 0)
break;
return (FAIL);
}
}
(void) sleep(2);
if (flds[k+1])
}
return (0);
}
#define MR 1000
/*
* expect(str, fn) look for expected string w/ possible special chars
* char *str;
*
* return codes:
* 0 - found
* FAIL - lost line or too many characters read
* some character - timed out
*/
static int
{
if (*sptr == '\\') {
switch (*++sptr) {
case 'H':
*bptr++ = '\0';
return (FAIL);
}
return (FAIL);
}
continue;
case '\\':
*bptr++ = '\\';
continue;
default:
*bptr++ = '\\';
continue;
}
} else
}
*bptr = '\0';
return (FAIL);
}
return (0);
}
/*
* expect_str(str, fn) look for expected string, w/ no special chars
*
* return codes:
* 0 - found
* FAIL - too many characters read
* some character - timed out
*/
static int
{
int kr, c;
char nextch;
*rp = 0;
if (kr < 040) {
/*EMPTY*/
} else {
/*EMPTY*/
}
return (0);
}
if (*str == '\0')
return (0);
return (FAIL);
(void) alarm(expecttime);
errno = 0;
if (kr <= 0) {
(void) alarm(0);
return (FAIL);
}
c = nextch & 0177;
rp++;
(void) alarm(0);
return (FAIL);
}
}
(void) alarm(0);
return (0);
}
/*
* alarmtr() - catch alarm routine for "expect".
*/
/*ARGSUSED*/
static void
{
}
/*
* wait_for_hangup() - wait for a hangup to occur on the given device
*/
int
wait_for_hangup(int dcf)
{
int rval;
;
if (rval < 0)
return (FAIL);
return (FAIL);
}
return (SUCCESS);
}
/*
* sendthem(str, fn, phstr1, phstr2) send line of chat sequence
* char *str, *phstr;
*
* return codes: none
*/
#define FLUSH() { \
goto err; \
}
static void
{
/* should be EQUALS, but previous versions had BREAK n for integer n */
/* send break */
return;
}
return;
}
str += 2;
}
if (*sptr == '\\') {
switch (*++sptr) {
/* adjust switches */
case 'c': /* no CR after string */
FLUSH();
sendcr = 0;
} else {
/*EMPTY*/
}
continue;
}
/* stash in buf and continue */
switch (*sptr) {
case 'D': /* raw phnum */
continue;
case 'T': /* translated phnum */
continue;
case 'N': /* null */
*bptr++ = 0;
continue;
case 's': /* space */
*bptr++ = ' ';
continue;
case '\\': /* backslash escapes itself */
continue;
default: /* send the backslash */
*bptr++ = '\\';
continue;
/* flush buf, perform action, and continue */
case 'E': /* echo check on */
FLUSH();
echocheck = 1;
continue;
case 'e': /* echo check off */
FLUSH();
echocheck = 0;
continue;
case 'd': /* sleep briefly */
FLUSH();
(void) sleep(2);
continue;
case 'p': /* pause momentarily */
FLUSH();
continue;
case 'K': /* inline break */
FLUSH();
continue;
case 'M': /* modem control - set CLOCAL */
case 'm': /* no modem control - clear CLOCAL */
FLUSH();
/*EMPTY*/
CDEBUG(5,
"ignored. TCGETA failed, errno %d",
errno);
} else {
if (*sptr == 'M')
else
/*EMPTY*/
CDEBUG(5,
"failed. TCSETAW failed, errno %d",
errno);
}
continue;
}
} else
}
if (sendcr)
*bptr++ = '\r';
err:
}
static int
{
int i;
if (echocheck)
if (Debug >= 5) {
if (sysaccess(ACCESS_SYSTEMS) == 0) {
/* Systems file access ok */
for (i = 0; i < len; i++) {
if (*dbptr < 040) {
*dbptr++ = '^';
}
dbptr++;
}
*dbptr = 0;
} else
}
return (FAIL);
return (SUCCESS);
}
static int
{
int i, saccess;
return (FAIL);
for (i = 0; i < len; i++) {
if (saccess) {
/*EMPTY*/
} else {
/*EMPTY*/
}
return (FAIL);
do {
(void) alarm(expecttime);
return (FAIL);
(void) alarm(0);
cin &= 0177;
if (saccess) {
/*EMPTY*/
} else {
/*EMPTY*/
}
}
return (SUCCESS);
}
/*
* notin(sh, lg) check for occurrence of substring "sh"
* char *sh, *lg;
*
* return codes:
* 0 - found the string
* 1 - not in the string
*/
static int
{
return (0);
else
lg++;
}
return (1);
}
/*
* ifdate(s)
* char *s;
*
* ifdate - this routine will check a string (s)
* like "MoTu0800-1730" to see if the present
* time is within the given limits.
* SIDE EFFECT - Retrytime is set to number following ";"
*
* String alternatives:
* Wk - Mo thru Fr
* zero or one time means all day
* Any - any day
*
* return codes:
* 0 - not within limits
* 1 - within limits
*/
static int
ifdate(char *s)
{
static char *days[] = {
"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", 0
};
int t__now;
char *p;
/*
* pick up retry time for failures
* global variable Retrytime is set here
*/
if (isdigit(p[1])) {
Retrytime *= 60;
*p = NULLCHAR;
}
while (*s) {
int i, dayok;
if (PREFIX("Any", s))
dayok = 1;
else if (PREFIX("Wk", s)) {
dayok = 1;
} else
for (i = 0; days[i]; i++)
dayok = 1;
}
if (dayok) {
while (isalpha(*s)) /* flush remaining day stuff */
s++;
return (1);
/* 0000 crossover? */
return (1);
return (1);
/* aim at next time slot */
break;
}
if (*s)
s++;
}
return (0);
}
/*
* char *
* fdig(cp) find first digit in string
*
* return - pointer to first digit in string or end of string
*/
static char *
{
char *c;
for (c = cp; *c; c++)
if (*c >= '0' && *c <= '9')
break;
return (c);
}
/* nap(n) -- sleep for 'n' ticks of 1/60th sec each. */
/* This version uses the select system call */
static void
nap(unsigned int n)
{
if (n == 0)
return;
}