17c478bdstevel@tonic-gate/*
294e1761sn * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
37c478bdstevel@tonic-gate * Use is subject to license terms.
47c478bdstevel@tonic-gate */
58d489c7muffin
67c478bdstevel@tonic-gate/*
77c478bdstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
87c478bdstevel@tonic-gate * All rights reserved.  The Berkeley software License Agreement
97c478bdstevel@tonic-gate * specifies the terms and conditions for redistribution.
107c478bdstevel@tonic-gate */
117c478bdstevel@tonic-gate
128d489c7muffin#pragma ident	"%Z%%M%	%I%	%E% SMI"
137c478bdstevel@tonic-gate
147c478bdstevel@tonic-gate#include "tip.h"
157c478bdstevel@tonic-gate
168d489c7muffinvoid	cleanup(void);
178d489c7muffinvoid	timeout(void);
187c478bdstevel@tonic-gate
197c478bdstevel@tonic-gate/*
207c478bdstevel@tonic-gate * Botch the interface to look like cu's
217c478bdstevel@tonic-gate */
228d489c7muffinvoid
238d489c7muffincumain(int argc, char *argv[])
247c478bdstevel@tonic-gate{
258d489c7muffin	int i;
2694e1761sn	static char sbuf[14];
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate	if (argc < 2) {
297c478bdstevel@tonic-gateusage:
308d489c7muffin		(void) fprintf(stderr,
318d489c7muffin	"usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
327c478bdstevel@tonic-gate		exit(8);
337c478bdstevel@tonic-gate	}
347c478bdstevel@tonic-gate	CU = DV = NOSTR;
357c478bdstevel@tonic-gate	for (; argc > 1; argv++, argc--) {
367c478bdstevel@tonic-gate		if (argv[1][0] != '-')
377c478bdstevel@tonic-gate			PN = argv[1];
387c478bdstevel@tonic-gate		else if (argv[1][1] != '\0' && argv[1][2] != '\0') {
398d489c7muffin			(void) fprintf(stderr,
408d489c7muffin			    "cu: extra characters after flag: %s\n",
418d489c7muffin			    argv[1]);
427c478bdstevel@tonic-gate			goto usage;
437c478bdstevel@tonic-gate		} else switch (argv[1][1]) {
447c478bdstevel@tonic-gate
457c478bdstevel@tonic-gate		case 't':
467c478bdstevel@tonic-gate			HW = 1, DU = -1;
477c478bdstevel@tonic-gate			--argc;
487c478bdstevel@tonic-gate			continue;
497c478bdstevel@tonic-gate
507c478bdstevel@tonic-gate		case 'a':
517c478bdstevel@tonic-gate			CU = argv[2]; ++argv; --argc;
527c478bdstevel@tonic-gate			break;
537c478bdstevel@tonic-gate
547c478bdstevel@tonic-gate		case 's':
557c478bdstevel@tonic-gate			if (argc < 3)
567c478bdstevel@tonic-gate				goto usage;
577c478bdstevel@tonic-gate			if (speed(atoi(argv[2])) == 0) {
588d489c7muffin				(void) fprintf(stderr,
598d489c7muffin				    "cu: unsupported speed %s\n",
608d489c7muffin				    argv[2]);
617c478bdstevel@tonic-gate				exit(3);
627c478bdstevel@tonic-gate			}
637c478bdstevel@tonic-gate			BR = atoi(argv[2]); ++argv; --argc;
647c478bdstevel@tonic-gate			break;
657c478bdstevel@tonic-gate
667c478bdstevel@tonic-gate		case 'l':
677c478bdstevel@tonic-gate			DV = argv[2]; ++argv; --argc;
687c478bdstevel@tonic-gate			break;
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate		case '0': case '1': case '2': case '3': case '4':
717c478bdstevel@tonic-gate		case '5': case '6': case '7': case '8': case '9':
727c478bdstevel@tonic-gate			if (CU)
737c478bdstevel@tonic-gate				CU[strlen(CU)-1] = argv[1][1];
747c478bdstevel@tonic-gate			if (DV)
757c478bdstevel@tonic-gate				DV[strlen(DV)-1] = argv[1][1];
767c478bdstevel@tonic-gate			break;
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate		default:
798d489c7muffin			(void) fprintf(stderr, "cu: bad flag %s\n", argv[1]);
807c478bdstevel@tonic-gate			goto usage;
817c478bdstevel@tonic-gate		}
827c478bdstevel@tonic-gate	}
838d489c7muffin	(void) signal(SIGINT, (sig_handler_t)cleanup);
848d489c7muffin	(void) signal(SIGQUIT, (sig_handler_t)cleanup);
858d489c7muffin	(void) signal(SIGHUP, (sig_handler_t)cleanup);
868d489c7muffin	(void) signal(SIGTERM, (sig_handler_t)cleanup);
877c478bdstevel@tonic-gate
887c478bdstevel@tonic-gate	/*
897c478bdstevel@tonic-gate	 * The "cu" host name is used to define the
907c478bdstevel@tonic-gate	 * attributes of the generic dialer.
917c478bdstevel@tonic-gate	 */
9294e1761sn	(void) snprintf(sbuf, sizeof (sbuf), "cu%d", BR);
937c478bdstevel@tonic-gate	if ((i = hunt(sbuf)) == 0) {
948d489c7muffin		(void) printf("all ports busy\n");
957c478bdstevel@tonic-gate		exit(3);
967c478bdstevel@tonic-gate	}
977c478bdstevel@tonic-gate	if (i == -1) {
988d489c7muffin		(void) printf("link down\n");
997c478bdstevel@tonic-gate		delock(uucplock);
1007c478bdstevel@tonic-gate		exit(3);
1017c478bdstevel@tonic-gate	}
1027c478bdstevel@tonic-gate	setbuf(stdout, NULL);
1037c478bdstevel@tonic-gate	loginit();
1047c478bdstevel@tonic-gate	gid = getgid();
1057c478bdstevel@tonic-gate	egid = getegid();
1067c478bdstevel@tonic-gate	uid = getuid();
1077c478bdstevel@tonic-gate	euid = geteuid();
1087c478bdstevel@tonic-gate	userperm();
1097c478bdstevel@tonic-gate	vinit();
1107c478bdstevel@tonic-gate	setparity("none");
1117c478bdstevel@tonic-gate	boolean(value(VERBOSE)) = 0;
1127c478bdstevel@tonic-gate	if (HW)
1137c478bdstevel@tonic-gate		ttysetup(speed(BR));
1147c478bdstevel@tonic-gate	if (connect()) {
1158d489c7muffin		(void) printf("Connect failed\n");
1167c478bdstevel@tonic-gate		myperm();
1177c478bdstevel@tonic-gate		delock(uucplock);
1187c478bdstevel@tonic-gate		exit(1);
1197c478bdstevel@tonic-gate	}
1207c478bdstevel@tonic-gate	if (!HW)
1217c478bdstevel@tonic-gate		ttysetup(speed(BR));
1227c478bdstevel@tonic-gate}
123