cu.c revision 7c478bd95313f5f23a4c958a745db2134aa0324
17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bdstevel@tonic-gate * Use is subject to license terms.
47c478bdstevel@tonic-gate */
57c478bdstevel@tonic-gate/*
67c478bdstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
77c478bdstevel@tonic-gate * All rights reserved.  The Berkeley software License Agreement
87c478bdstevel@tonic-gate * specifies the terms and conditions for redistribution.
97c478bdstevel@tonic-gate */
107c478bdstevel@tonic-gate
117c478bdstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 5.2 1/13/86 */
127c478bdstevel@tonic-gate
137c478bdstevel@tonic-gate#include "tip.h"
147c478bdstevel@tonic-gate
157c478bdstevel@tonic-gatevoid	cleanup();
167c478bdstevel@tonic-gatevoid	timeout();
177c478bdstevel@tonic-gate
187c478bdstevel@tonic-gate/*
197c478bdstevel@tonic-gate * Botch the interface to look like cu's
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gatecumain(argc, argv)
227c478bdstevel@tonic-gate	char *argv[];
237c478bdstevel@tonic-gate{
247c478bdstevel@tonic-gate	register int i;
257c478bdstevel@tonic-gate	static char sbuf[12];
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate	if (argc < 2) {
287c478bdstevel@tonic-gateusage:
297c478bdstevel@tonic-gate		fprintf(stderr,
307c478bdstevel@tonic-gate		"usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
317c478bdstevel@tonic-gate		exit(8);
327c478bdstevel@tonic-gate	}
337c478bdstevel@tonic-gate	CU = DV = NOSTR;
347c478bdstevel@tonic-gate	for (; argc > 1; argv++, argc--) {
357c478bdstevel@tonic-gate		if (argv[1][0] != '-')
367c478bdstevel@tonic-gate			PN = argv[1];
377c478bdstevel@tonic-gate		else if (argv[1][1] != '\0' && argv[1][2] != '\0') {
387c478bdstevel@tonic-gate			fprintf(stderr, "cu: extra characters after flag: %s\n",
397c478bdstevel@tonic-gate				argv[1]);
407c478bdstevel@tonic-gate			goto usage;
417c478bdstevel@tonic-gate		} else switch (argv[1][1]) {
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gate		case 't':
447c478bdstevel@tonic-gate			HW = 1, DU = -1;
457c478bdstevel@tonic-gate			--argc;
467c478bdstevel@tonic-gate			continue;
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate		case 'a':
497c478bdstevel@tonic-gate			CU = argv[2]; ++argv; --argc;
507c478bdstevel@tonic-gate			break;
517c478bdstevel@tonic-gate
527c478bdstevel@tonic-gate		case 's':
537c478bdstevel@tonic-gate			if (argc < 3)
547c478bdstevel@tonic-gate				goto usage;
557c478bdstevel@tonic-gate			if (speed(atoi(argv[2])) == 0) {
567c478bdstevel@tonic-gate				fprintf(stderr, "cu: unsupported speed %s\n",
577c478bdstevel@tonic-gate					argv[2]);
587c478bdstevel@tonic-gate				exit(3);
597c478bdstevel@tonic-gate			}
607c478bdstevel@tonic-gate			BR = atoi(argv[2]); ++argv; --argc;
617c478bdstevel@tonic-gate			break;
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate		case 'l':
647c478bdstevel@tonic-gate			DV = argv[2]; ++argv; --argc;
657c478bdstevel@tonic-gate			break;
667c478bdstevel@tonic-gate
677c478bdstevel@tonic-gate		case '0': case '1': case '2': case '3': case '4':
687c478bdstevel@tonic-gate		case '5': case '6': case '7': case '8': case '9':
697c478bdstevel@tonic-gate			if (CU)
707c478bdstevel@tonic-gate				CU[strlen(CU)-1] = argv[1][1];
717c478bdstevel@tonic-gate			if (DV)
727c478bdstevel@tonic-gate				DV[strlen(DV)-1] = argv[1][1];
737c478bdstevel@tonic-gate			break;
747c478bdstevel@tonic-gate
757c478bdstevel@tonic-gate		default:
767c478bdstevel@tonic-gate			fprintf(stderr, "cu: bad flag %s\n", argv[1]);
777c478bdstevel@tonic-gate			goto usage;
787c478bdstevel@tonic-gate		}
797c478bdstevel@tonic-gate	}
807c478bdstevel@tonic-gate	signal(SIGINT, cleanup);
817c478bdstevel@tonic-gate	signal(SIGQUIT, cleanup);
827c478bdstevel@tonic-gate	signal(SIGHUP, cleanup);
837c478bdstevel@tonic-gate	signal(SIGTERM, cleanup);
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gate	/*
867c478bdstevel@tonic-gate	 * The "cu" host name is used to define the
877c478bdstevel@tonic-gate	 * attributes of the generic dialer.
887c478bdstevel@tonic-gate	 */
897c478bdstevel@tonic-gate	sprintf(sbuf, "cu%d", BR);
907c478bdstevel@tonic-gate	if ((i = hunt(sbuf)) == 0) {
917c478bdstevel@tonic-gate		printf("all ports busy\n");
927c478bdstevel@tonic-gate		exit(3);
937c478bdstevel@tonic-gate	}
947c478bdstevel@tonic-gate	if (i == -1) {
957c478bdstevel@tonic-gate		printf("link down\n");
967c478bdstevel@tonic-gate		delock(uucplock);
977c478bdstevel@tonic-gate		exit(3);
987c478bdstevel@tonic-gate	}
997c478bdstevel@tonic-gate	setbuf(stdout, NULL);
1007c478bdstevel@tonic-gate	loginit();
1017c478bdstevel@tonic-gate	gid = getgid();
1027c478bdstevel@tonic-gate	egid = getegid();
1037c478bdstevel@tonic-gate	uid = getuid();
1047c478bdstevel@tonic-gate	euid = geteuid();
1057c478bdstevel@tonic-gate	userperm();
1067c478bdstevel@tonic-gate	vinit();
1077c478bdstevel@tonic-gate	setparity("none");
1087c478bdstevel@tonic-gate	boolean(value(VERBOSE)) = 0;
1097c478bdstevel@tonic-gate	if (HW)
1107c478bdstevel@tonic-gate		ttysetup(speed(BR));
1117c478bdstevel@tonic-gate	if (connect()) {
1127c478bdstevel@tonic-gate		printf("Connect failed\n");
1137c478bdstevel@tonic-gate		myperm();
1147c478bdstevel@tonic-gate		delock(uucplock);
1157c478bdstevel@tonic-gate		exit(1);
1167c478bdstevel@tonic-gate	}
1177c478bdstevel@tonic-gate	if (!HW)
1187c478bdstevel@tonic-gate		ttysetup(speed(BR));
1197c478bdstevel@tonic-gate}
120