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