ct.c revision f48205be61a214698b763ff550ab9e657525104c
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* ct [-h] [-v] [-w n] [-x n] [-s speed] telno ...
*
* dials the given telephone number, waits for the
* modem to answer, and initiates a login process.
*
* ct uses several routines from uucp:
* - getto(flds) takes a vector of fields needed to make
* a connection and returns a file descriptor or -1
* - rddev( ... ) takes several arguments and returns lines
* (in ct the type will be ACU)
* - fdig(string) takes a string that is zero or more
* alphabetic characters follow by a number (baud rate)
* and returns a pointer to the first digit in the string.
* - fn_cklock(dev) takes a device name [/dev/]term/11 and
* checks whether the appropriate lock file exists. It returns
* FAIL if it does.
* - rmlock(pointer) removes the lock file. In ct pointer is
* always CNULL (a null pointer) causing rmlock to remove
* all lock files associated with this execution of ct.
*/
#include "uucp.h"
#include "sysfiles.h"
#include <pwd.h>
#include <utmpx.h>
#ifdef DATAKIT
#include <dk.h>
extern int dkminor();
#endif
#define ROOT 0
#define SYS 3
#define DEV "/dev/"
#define LEGAL "0123456789-*#="
#define USAGE "[-h] [-v] [-w n] [-x n] [-s speed] telno ..."
#define TRUE 1
#define FALSE 0
static
int _Status; /* exit status of child */
static
static
char
static
char
*_Num, /* pointer to a phone number */
static
static
extern int optind;
extern void cleanup();
/*
* These two dummy routines are needed because the uucp routines
* used by ct reference them, but they will never be
* called when executing from ct
*/
/*VARARGS*/
/*ARGSUSED*/
void
{ } /* for ASSERT in gnamef.c */
/*ARGSUSED*/
void
{ } /* so we can load ulockf() */
int
int argc;
char *argv[];
{
int c;
int found = 0,
errors = 0,
int count,
logprocflag, /* is there a login process on the line */
minutes = 0; /* number of minutes to wait for dialer */
int fdl;
typedef void (*save_sig)();
extern void setservice(), devreset();
extern int sysaccess();
setservice("cu");
if ( sysaccess(EACCESS_DEVICES) != 0 ) {
cleanup(101);
}
/* Set up the _Flds vector as if finds() [from uucico] built it */
switch (c) {
case 'h':
hangup = 0;
break;
case 'v':
Verbose = 1;
break;
case 'w':
if (minutes < 1) {
optarg);
cleanup(101);
}
break;
case 's':
break;
case 'x':
optarg);
cleanup(101);
}
break;
case '?':
cleanup(101);
/* NOTREACHED */
}
}
cleanup(101);
}
/* check for valid phone number(s) */
++errors;
}
++errors;
}
}
if (errors)
cleanup(101);
/************************************************************/
/* Begin Loop: Find an available Dialer */
/************************************************************/
* time through the loop.
* break will be used exit loop.
*/
break;
}
else if (found == 0) { /* no dialers of that on system */
cleanup(101);
}
if (!first) { /* not the first time in loop */
sleep(60);
continue;
}
/* This is the end of the loop - no time left */
break;
}
/**************************************************************/
/* First time through loop - get wait minutes if no -w option */
/**************************************************************/
if (minutes) { /* -w already set wait minutes */
sleep(60);
continue;
}
if (!isatty(0) ) { /* not a terminal - get out */
cleanup(101);
}
cleanup(101);
;
;
if (minutes <= 0)
cleanup(101);
sleep(60);
continue;
}
/************************************************************/
/* End Loop: Find an available Dialer */
/************************************************************/
/* check why loop terminated */
if (found < 0) { /* no dialer found - get out */
cleanup(101);
}
/* found a dialer. now try to call */
if (!isatty(0))
hangup = 0;
if (hangup) { /* -h option not specified */
do {
case EOF:
case 'n':
cleanup(101);
break;
case 'y':
break;
default:
while ( c != EOF && c != '\n' )
c=getchar();
break;
}
} while (c != 'y');
/* close stderr if it is not redirected */
if ( isatty(2) ) {
Verbose = 0;
Debug = 0;
(void) close (2);
}
(void) sleep (5);
}
(void) close(0);
(void) close(1);
/* Try each phone number until a connection is made, or non work */
/* call getto routine to make connection */
devreset();
if (fdl >= 0) {
/*
* If there is a login process on the line, get rid
* of the lock file quickly so that when the process
* reads the first character, the lock file will be gone
* indicating that the process should handle the data.
*/
/* NOTE: Dc is set in the caller routines */
break;
}
}
/* check why the loop ended (connected or no more numbers to try) */
cleanup(101);
/****** Successfully made connection ******/
#ifdef DATAKIT
cleanup(101);
}
}
#endif
/* ignore some signals if they were ignored upon invocation of ct */
/* or else, have them go to graceful disconnect */
else
else
else
/*
* if there is a login process on this line,
* tell the user to hit a carriage return to make
* the waiting process get past the inital read,
* Then exit.
*/
if (logprocflag) { /* there is a login process on the line */
exit(0);
}
for (;;) {
case -1: /* fork failed */
cleanup(101);
/*NOTREACHED*/
case 0: /* child process */
startat ();
(void) close(2);
/* ttymon will use open fd 0 for connection */
if ( fdl != 0 ) {
(void) close(0);
}
/* exec failed */
cleanup(101);
/*NOTREACHED*/
default: /* parent process */
break;
}
/* Parent process */
cleanup(101);
}
if ((_Status & 0xff00) < 0) {
if (!hangup)
cleanup(101);
}
(void) alarm (20);
disconnect (0); /* normal disconnect */
;
(void) alarm (0);
}
}
static void
{
(void) alarm(0);
/* For normal disconnect or timeout on "Reconnect?" message,
we already cleaned up above */
}
/*
* clean and exit with "code" status
*/
void
int code;
{
if (*_Tty != '\0') {
}
}
}
if (_Pid) { /* kill the child process */
}
}
/* gdev()
* Find an available line with a dialer on it.
* Set a temporary lock file for the line.
* Return:
* >0 - got a dialer
* <0 - failed - return the number of possible dialers
* 0 - not dialers of requested class on the system.
*/
static int
char *flds[];
{
int count = 0;
extern void devreset();
devreset();
/* check caller type */
continue;
/* check class, check (and possibly set) speed */
continue;
count++;
continue;
/* found available dialer and set temporary lock */
return (count);
}
return (- count);
}
/*
* Check if there is a login process active on this line.
* Return:
* 0 - there is no login process on this line
* 1 - found a login process on this line
*/
static int
char *line;
{
struct utmpx *u;
if (u->ut_type == LOGIN_PROCESS
/* see if the process is still active */
return(1);
}
}
}
return(0);
}
/*
* Create an entry in utmpx file if one does not already exist.
*/
static void
startat ()
{
int fd;
/* Set up the prototype for the utmpx structure we want to write. */
u = &utmpxbuf;
/* Fill in the various fields of the utmpx structure. */
u -> ut_id[0] = 'c';
u -> ut_exit.e_termination = 0;
u -> ut_type = INIT_PROCESS;
setutxent (); /* Start at beginning of utmpx file. */
/* For INIT_PROCESSes put in the name of the program in the */
/* "ut_user" field. */
/* Write out the updated entry to utmpx file. */
pututxline (u);
/* Now attempt to add to the end of the wtmpx file. Do not create */
/* if it doesn't already exist. Do not overwrite any info already */
/* in file. */
}
endutxent ();
return;
}
/*
* Change utmpx file entry to "dead".
* Make entry in ct log.
*/
static void
char *num;
{
int fd;
/* Set up the prototype for the utmpx structure we want to write. */
setutxent();
u = &utmpxbuf;
/* Fill in the various fields of the utmpx structure. */
u -> ut_id[0] = 'c';
u -> ut_type = USER_PROCESS;
/* Find the old entry in the utmpx file with the user name and */
/* copy it back. */
if (u = getutxid (u)) {
utmpxbuf = *u;
u = &utmpxbuf;
}
u -> ut_type = DEAD_PROCESS;
/* Write out the updated entry to utmpx file. */
pututxline (u);
/* Now attempt to add to the end of the wtmpx file. Do not create */
/* if it doesn't already exist. Do not overwrite any info already */
/* in file. */
}
endutxent ();
/* Do the log accounting */
char *aptr;
int hrs,
mins,
secs;
/* ignore user set TZ for logfile purposes */
*aptr = '\0';
if (hrs)
else
}
return;
}
static int
char *file;
{
return (0);
return (1);
}
static void
char *adr;
int size;
{
while (size--)
*adr++ = '\0';
return;
}