xref: /titanic_52/usr/src/cmd/tip/remote.c (revision 8d489c7a815fcac696803219572e95aa01532b0f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
5*8d489c7aSmuffin 
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 
12*8d489c7aSmuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include "tip.h"
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate /*
177c478bd9Sstevel@tonic-gate  * Attributes to be gleened from remote host description
187c478bd9Sstevel@tonic-gate  *   data base.
197c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate static char **caps[] = {
217c478bd9Sstevel@tonic-gate 	&AT, &DV, &CM, &CU, &EL, &IE, &OE, &PN, &PR, &DI,
227c478bd9Sstevel@tonic-gate 	&ES, &EX, &FO, &RC, &RE, &PA
237c478bd9Sstevel@tonic-gate };
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate static char *capstrings[] = {
267c478bd9Sstevel@tonic-gate 	"at", "dv", "cm", "cu", "el", "ie", "oe", "pn", "pr",
277c478bd9Sstevel@tonic-gate 	"di", "es", "ex", "fo", "rc", "re", "pa", 0
287c478bd9Sstevel@tonic-gate };
297c478bd9Sstevel@tonic-gate 
30*8d489c7aSmuffin extern char *rgetstr(char *, char **);
317c478bd9Sstevel@tonic-gate 
32*8d489c7aSmuffin static void
33*8d489c7aSmuffin getremcap(char *host)
347c478bd9Sstevel@tonic-gate {
357c478bd9Sstevel@tonic-gate 	int stat;
367c478bd9Sstevel@tonic-gate 	char tbuf[BUFSIZ];
377c478bd9Sstevel@tonic-gate 	static char buf[BUFSIZ/2];
387c478bd9Sstevel@tonic-gate 	char *bp = buf;
39*8d489c7aSmuffin 	char **p, ***q;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate 	if ((stat = rgetent(tbuf, host, sizeof (tbuf))) <= 0) {
427c478bd9Sstevel@tonic-gate 		if (DV ||
437c478bd9Sstevel@tonic-gate 		    host[0] == '/' && access(DV = host, R_OK | W_OK) == 0) {
447c478bd9Sstevel@tonic-gate 			/*
457c478bd9Sstevel@tonic-gate 			 * If the user specifies a device on the commandline,
467c478bd9Sstevel@tonic-gate 			 * don't trust it.
477c478bd9Sstevel@tonic-gate 			 */
487c478bd9Sstevel@tonic-gate 			if (host[0] == '/')
497c478bd9Sstevel@tonic-gate 				trusted_device = 0;
507c478bd9Sstevel@tonic-gate 			CU = DV;
517c478bd9Sstevel@tonic-gate 			HO = host;
527c478bd9Sstevel@tonic-gate 			HW = 1;
537c478bd9Sstevel@tonic-gate 			DU = 0;
547c478bd9Sstevel@tonic-gate 			if (!BR)
557c478bd9Sstevel@tonic-gate 				BR = DEFBR;
567c478bd9Sstevel@tonic-gate 			FS = DEFFS;
577c478bd9Sstevel@tonic-gate 			RE = (char *)"tip.record";
587c478bd9Sstevel@tonic-gate 			EX = (char *)"\t\n\b\f";
597c478bd9Sstevel@tonic-gate 			DL = 0;
607c478bd9Sstevel@tonic-gate 			CL = 0;
617c478bd9Sstevel@tonic-gate 			ET = 10;
627c478bd9Sstevel@tonic-gate 			return;
637c478bd9Sstevel@tonic-gate 		}
64*8d489c7aSmuffin 		(void) fprintf(stderr, stat == 0 ?
657c478bd9Sstevel@tonic-gate 		    "tip: unknown host %s\n" :
667c478bd9Sstevel@tonic-gate 		    "tip: can't open host description file\n", host);
677c478bd9Sstevel@tonic-gate 		exit(3);
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	for (p = capstrings, q = caps; *p != NULL; p++, q++)
717c478bd9Sstevel@tonic-gate 		if (**q == NULL)
727c478bd9Sstevel@tonic-gate 			**q = rgetstr(*p, &bp);
737c478bd9Sstevel@tonic-gate 	if (!BR && (BR = rgetnum("br")) < 0)
747c478bd9Sstevel@tonic-gate 		BR = DEFBR;
757c478bd9Sstevel@tonic-gate 	if ((FS = rgetnum("fs")) < 0)
767c478bd9Sstevel@tonic-gate 		FS = DEFFS;
777c478bd9Sstevel@tonic-gate 	if (DU < 0)
787c478bd9Sstevel@tonic-gate 		DU = 0;
797c478bd9Sstevel@tonic-gate 	else
807c478bd9Sstevel@tonic-gate 		DU = rgetflag("du");
817c478bd9Sstevel@tonic-gate 	if (DV == NOSTR) {
82*8d489c7aSmuffin 		(void) fprintf(stderr, "%s: missing device spec\n", host);
837c478bd9Sstevel@tonic-gate 		exit(3);
847c478bd9Sstevel@tonic-gate 	}
857c478bd9Sstevel@tonic-gate 	if (DU && CU == NOSTR)
867c478bd9Sstevel@tonic-gate 		CU = DV;
877c478bd9Sstevel@tonic-gate 	if (DU && PN == NOSTR) {
88*8d489c7aSmuffin 		(void) fprintf(stderr, "%s: missing phone number\n", host);
897c478bd9Sstevel@tonic-gate 		exit(3);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 	DB = rgetflag("db");
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	/*
947c478bd9Sstevel@tonic-gate 	 * This effectively eliminates the "hw" attribute
957c478bd9Sstevel@tonic-gate 	 *   from the description file
967c478bd9Sstevel@tonic-gate 	 */
977c478bd9Sstevel@tonic-gate 	if (!HW)
987c478bd9Sstevel@tonic-gate 		HW = (CU == NOSTR) || (DU && equal(DV, CU));
997c478bd9Sstevel@tonic-gate 	HO = host;
1007c478bd9Sstevel@tonic-gate 	/*
1017c478bd9Sstevel@tonic-gate 	 * see if uppercase mode should be turned on initially
1027c478bd9Sstevel@tonic-gate 	 */
1037c478bd9Sstevel@tonic-gate 	if (rgetflag("ra"))
1047c478bd9Sstevel@tonic-gate 		boolean(value(RAISE)) = 1;
1057c478bd9Sstevel@tonic-gate 	if (rgetflag("ec"))
1067c478bd9Sstevel@tonic-gate 		boolean(value(ECHOCHECK)) = 1;
1077c478bd9Sstevel@tonic-gate 	if (rgetflag("be"))
1087c478bd9Sstevel@tonic-gate 		boolean(value(BEAUTIFY)) = 1;
1097c478bd9Sstevel@tonic-gate 	if (rgetflag("nb"))
1107c478bd9Sstevel@tonic-gate 		boolean(value(BEAUTIFY)) = 0;
1117c478bd9Sstevel@tonic-gate 	if (rgetflag("sc"))
1127c478bd9Sstevel@tonic-gate 		boolean(value(SCRIPT)) = 1;
1137c478bd9Sstevel@tonic-gate 	if (rgetflag("tb"))
1147c478bd9Sstevel@tonic-gate 		boolean(value(TABEXPAND)) = 1;
1157c478bd9Sstevel@tonic-gate 	if (rgetflag("vb"))
1167c478bd9Sstevel@tonic-gate 		boolean(value(VERBOSE)) = 1;
1177c478bd9Sstevel@tonic-gate 	if (rgetflag("nv"))
1187c478bd9Sstevel@tonic-gate 		boolean(value(VERBOSE)) = 0;
1197c478bd9Sstevel@tonic-gate 	if (rgetflag("ta"))
1207c478bd9Sstevel@tonic-gate 		boolean(value(TAND)) = 1;
1217c478bd9Sstevel@tonic-gate 	if (rgetflag("nt"))
1227c478bd9Sstevel@tonic-gate 		boolean(value(TAND)) = 0;
1237c478bd9Sstevel@tonic-gate 	if (rgetflag("rw"))
1247c478bd9Sstevel@tonic-gate 		boolean(value(RAWFTP)) = 1;
1257c478bd9Sstevel@tonic-gate 	if (rgetflag("hd"))
1267c478bd9Sstevel@tonic-gate 		boolean(value(HALFDUPLEX)) = 1;
1277c478bd9Sstevel@tonic-gate 	if (rgetflag("hf"))
1287c478bd9Sstevel@tonic-gate 		boolean(value(HARDWAREFLOW)) = 1;
1297c478bd9Sstevel@tonic-gate 	if (RE == NULL)
1307c478bd9Sstevel@tonic-gate 		RE = (char *)"tip.record";
1317c478bd9Sstevel@tonic-gate 	if (EX == NULL)
1327c478bd9Sstevel@tonic-gate 		EX = (char *)"\t\n\b\f";
1337c478bd9Sstevel@tonic-gate 	if (ES != NOSTR)
134*8d489c7aSmuffin 		(void) vstring("es", ES);
1357c478bd9Sstevel@tonic-gate 	if (FO != NOSTR)
136*8d489c7aSmuffin 		(void) vstring("fo", FO);
1377c478bd9Sstevel@tonic-gate 	if (PR != NOSTR)
138*8d489c7aSmuffin 		(void) vstring("pr", PR);
1397c478bd9Sstevel@tonic-gate 	if (RC != NOSTR)
140*8d489c7aSmuffin 		(void) vstring("rc", RC);
1417c478bd9Sstevel@tonic-gate 	if ((DL = rgetnum("dl")) < 0)
1427c478bd9Sstevel@tonic-gate 		DL = 0;
1437c478bd9Sstevel@tonic-gate 	if ((CL = rgetnum("cl")) < 0)
1447c478bd9Sstevel@tonic-gate 		CL = 0;
1457c478bd9Sstevel@tonic-gate 	if ((ET = rgetnum("et")) < 0)
1467c478bd9Sstevel@tonic-gate 		ET = 10;
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate char *
150*8d489c7aSmuffin getremote(char *host)
1517c478bd9Sstevel@tonic-gate {
152*8d489c7aSmuffin 	char *cp;
1537c478bd9Sstevel@tonic-gate 	static char *next;
1547c478bd9Sstevel@tonic-gate 	static int lookedup = 0;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if (!lookedup) {
1577c478bd9Sstevel@tonic-gate 		if (host == NOSTR && (host = getenv("HOST")) == NOSTR) {
158*8d489c7aSmuffin 			(void) fprintf(stderr, "tip: no host specified\n");
1597c478bd9Sstevel@tonic-gate 			exit(3);
1607c478bd9Sstevel@tonic-gate 		}
1617c478bd9Sstevel@tonic-gate 		getremcap(host);
1627c478bd9Sstevel@tonic-gate 		next = DV;
1637c478bd9Sstevel@tonic-gate 		lookedup++;
1647c478bd9Sstevel@tonic-gate 	}
1657c478bd9Sstevel@tonic-gate 	/*
1667c478bd9Sstevel@tonic-gate 	 * We return a new device each time we're called (to allow
1677c478bd9Sstevel@tonic-gate 	 *   a rotary action to be simulated)
1687c478bd9Sstevel@tonic-gate 	 */
1697c478bd9Sstevel@tonic-gate 	if (next == NOSTR)
1707c478bd9Sstevel@tonic-gate 		return (NOSTR);
1717c478bd9Sstevel@tonic-gate 	if ((cp = strchr(next, ',')) == NULL) {
1727c478bd9Sstevel@tonic-gate 		DV = next;
1737c478bd9Sstevel@tonic-gate 		next = NOSTR;
1747c478bd9Sstevel@tonic-gate 	} else {
1757c478bd9Sstevel@tonic-gate 		*cp++ = '\0';
1767c478bd9Sstevel@tonic-gate 		DV = next;
1777c478bd9Sstevel@tonic-gate 		next = cp;
1787c478bd9Sstevel@tonic-gate 	}
1797c478bd9Sstevel@tonic-gate 	return (DV);
1807c478bd9Sstevel@tonic-gate }
181