Cover V06, I01
Article
Figure 1
Figure 2
Figure 3
Listing 1
Listing 2
Listing 3

jan97.tar


Listing 1:"dialer" shell script wrapper: dialer.c

#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <termio.h>
#include <string.h>
#include <errno.h>

#define BADCALL         -1

char *WHATIS = "@(#) dials a modem, executes a modem-script. Original by Brad Fennel, hacked by Jonathan Feldmonster 1996";

void
yuck(msg)
char *msg;
{ perror (msg); exit (2); }

main(argc,argv)
int argc;
char *argv[];
{
struct termio term;
int fd;
int ret;
static char mybuf[128];

if (argc!=3)
{
printf("%s: <port name> <modem-script>\n",argv[0]);
exit(1);
}
if ((fd=open(argv[1],O_RDWR|O_NDELAY))==BADCALL)
yuck("initial open failure on requested port!");

if ((ret=ioctl(fd, TCGETA, &term))==BADCALL)
yuck("Error getting ioctl port params!");

term.c_cflag &= ~(CBAUD | HUPCL );
term.c_iflag &= ~ICANON;
term.c_cflag |= CLOCAL|B9600|HUPCL;
term.c_lflag &= ~ECHO;
if ((ret=ioctl(fd, TCSETA, &term))==BADCALL)
yuck("Error setting ioctl port params!");

if ((fd=open(argv[1],O_RDWR))==BADCALL)
yuck ("Reopen of comm port failed!");


/* tie stdin and stdout to the device */
setpgrp();
if (close(0) == BADCALL) yuck ("Can't close stdin\n");
if (dup(fd)== BADCALL) yuck ("Can't dup fd to stdin\n");
if (close(1) == BADCALL) yuck ("Can't close stdout\n");
if (dup(fd)== BADCALL) yuck ("Can't dup fd to stdout\n");
/* we need to be suid to uucp-user to open port, */
/* go back to calling id for script */
setgid(getgid());
setuid(getuid());

if (execl("/bin/sh", "sh", "-c", argv[2], (char *) 0) == BADCALL )
yuck ("Can't call the script.");

}

/* End of File */