xref: /onnv-gate/usr/src/cmd/tip/cu.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*0Sstevel@tonic-gate  * Use is subject to license terms.
4*0Sstevel@tonic-gate  */
5*0Sstevel@tonic-gate /*
6*0Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
7*0Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
8*0Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
9*0Sstevel@tonic-gate  */
10*0Sstevel@tonic-gate 
11*0Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 5.2 1/13/86 */
12*0Sstevel@tonic-gate 
13*0Sstevel@tonic-gate #include "tip.h"
14*0Sstevel@tonic-gate 
15*0Sstevel@tonic-gate void	cleanup();
16*0Sstevel@tonic-gate void	timeout();
17*0Sstevel@tonic-gate 
18*0Sstevel@tonic-gate /*
19*0Sstevel@tonic-gate  * Botch the interface to look like cu's
20*0Sstevel@tonic-gate  */
21*0Sstevel@tonic-gate cumain(argc, argv)
22*0Sstevel@tonic-gate 	char *argv[];
23*0Sstevel@tonic-gate {
24*0Sstevel@tonic-gate 	register int i;
25*0Sstevel@tonic-gate 	static char sbuf[12];
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate 	if (argc < 2) {
28*0Sstevel@tonic-gate usage:
29*0Sstevel@tonic-gate 		fprintf(stderr,
30*0Sstevel@tonic-gate 		"usage: cu telno [-t] [-s speed] [-a acu] [-l line] [-#]\n");
31*0Sstevel@tonic-gate 		exit(8);
32*0Sstevel@tonic-gate 	}
33*0Sstevel@tonic-gate 	CU = DV = NOSTR;
34*0Sstevel@tonic-gate 	for (; argc > 1; argv++, argc--) {
35*0Sstevel@tonic-gate 		if (argv[1][0] != '-')
36*0Sstevel@tonic-gate 			PN = argv[1];
37*0Sstevel@tonic-gate 		else if (argv[1][1] != '\0' && argv[1][2] != '\0') {
38*0Sstevel@tonic-gate 			fprintf(stderr, "cu: extra characters after flag: %s\n",
39*0Sstevel@tonic-gate 				argv[1]);
40*0Sstevel@tonic-gate 			goto usage;
41*0Sstevel@tonic-gate 		} else switch (argv[1][1]) {
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate 		case 't':
44*0Sstevel@tonic-gate 			HW = 1, DU = -1;
45*0Sstevel@tonic-gate 			--argc;
46*0Sstevel@tonic-gate 			continue;
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 		case 'a':
49*0Sstevel@tonic-gate 			CU = argv[2]; ++argv; --argc;
50*0Sstevel@tonic-gate 			break;
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 		case 's':
53*0Sstevel@tonic-gate 			if (argc < 3)
54*0Sstevel@tonic-gate 				goto usage;
55*0Sstevel@tonic-gate 			if (speed(atoi(argv[2])) == 0) {
56*0Sstevel@tonic-gate 				fprintf(stderr, "cu: unsupported speed %s\n",
57*0Sstevel@tonic-gate 					argv[2]);
58*0Sstevel@tonic-gate 				exit(3);
59*0Sstevel@tonic-gate 			}
60*0Sstevel@tonic-gate 			BR = atoi(argv[2]); ++argv; --argc;
61*0Sstevel@tonic-gate 			break;
62*0Sstevel@tonic-gate 
63*0Sstevel@tonic-gate 		case 'l':
64*0Sstevel@tonic-gate 			DV = argv[2]; ++argv; --argc;
65*0Sstevel@tonic-gate 			break;
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 		case '0': case '1': case '2': case '3': case '4':
68*0Sstevel@tonic-gate 		case '5': case '6': case '7': case '8': case '9':
69*0Sstevel@tonic-gate 			if (CU)
70*0Sstevel@tonic-gate 				CU[strlen(CU)-1] = argv[1][1];
71*0Sstevel@tonic-gate 			if (DV)
72*0Sstevel@tonic-gate 				DV[strlen(DV)-1] = argv[1][1];
73*0Sstevel@tonic-gate 			break;
74*0Sstevel@tonic-gate 
75*0Sstevel@tonic-gate 		default:
76*0Sstevel@tonic-gate 			fprintf(stderr, "cu: bad flag %s\n", argv[1]);
77*0Sstevel@tonic-gate 			goto usage;
78*0Sstevel@tonic-gate 		}
79*0Sstevel@tonic-gate 	}
80*0Sstevel@tonic-gate 	signal(SIGINT, cleanup);
81*0Sstevel@tonic-gate 	signal(SIGQUIT, cleanup);
82*0Sstevel@tonic-gate 	signal(SIGHUP, cleanup);
83*0Sstevel@tonic-gate 	signal(SIGTERM, cleanup);
84*0Sstevel@tonic-gate 
85*0Sstevel@tonic-gate 	/*
86*0Sstevel@tonic-gate 	 * The "cu" host name is used to define the
87*0Sstevel@tonic-gate 	 * attributes of the generic dialer.
88*0Sstevel@tonic-gate 	 */
89*0Sstevel@tonic-gate 	sprintf(sbuf, "cu%d", BR);
90*0Sstevel@tonic-gate 	if ((i = hunt(sbuf)) == 0) {
91*0Sstevel@tonic-gate 		printf("all ports busy\n");
92*0Sstevel@tonic-gate 		exit(3);
93*0Sstevel@tonic-gate 	}
94*0Sstevel@tonic-gate 	if (i == -1) {
95*0Sstevel@tonic-gate 		printf("link down\n");
96*0Sstevel@tonic-gate 		delock(uucplock);
97*0Sstevel@tonic-gate 		exit(3);
98*0Sstevel@tonic-gate 	}
99*0Sstevel@tonic-gate 	setbuf(stdout, NULL);
100*0Sstevel@tonic-gate 	loginit();
101*0Sstevel@tonic-gate 	gid = getgid();
102*0Sstevel@tonic-gate 	egid = getegid();
103*0Sstevel@tonic-gate 	uid = getuid();
104*0Sstevel@tonic-gate 	euid = geteuid();
105*0Sstevel@tonic-gate 	userperm();
106*0Sstevel@tonic-gate 	vinit();
107*0Sstevel@tonic-gate 	setparity("none");
108*0Sstevel@tonic-gate 	boolean(value(VERBOSE)) = 0;
109*0Sstevel@tonic-gate 	if (HW)
110*0Sstevel@tonic-gate 		ttysetup(speed(BR));
111*0Sstevel@tonic-gate 	if (connect()) {
112*0Sstevel@tonic-gate 		printf("Connect failed\n");
113*0Sstevel@tonic-gate 		myperm();
114*0Sstevel@tonic-gate 		delock(uucplock);
115*0Sstevel@tonic-gate 		exit(1);
116*0Sstevel@tonic-gate 	}
117*0Sstevel@tonic-gate 	if (!HW)
118*0Sstevel@tonic-gate 		ttysetup(speed(BR));
119*0Sstevel@tonic-gate }
120