xref: /titanic_50/usr/src/cmd/rexd/rex.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * rex_xdr - remote execution external data representations
24*7c478bd9Sstevel@tonic-gate  *
25*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1985 Sun Microsystems, Inc.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /* XXX - Bad, Bad, Bad.... Fix this. This isn't allowed in the base */
31*7c478bd9Sstevel@tonic-gate #define	BSD_COMP
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdio.h>
34*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/errno.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/ttold.h>
37*7c478bd9Sstevel@tonic-gate #include <stropts.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/stream.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/tty.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h>
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include "rex.h"
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate /*
45*7c478bd9Sstevel@tonic-gate  * xdr_rex_start - process the command start structure
46*7c478bd9Sstevel@tonic-gate  */
47*7c478bd9Sstevel@tonic-gate xdr_rex_start(xdrs, rst)
48*7c478bd9Sstevel@tonic-gate 	XDR *xdrs;
49*7c478bd9Sstevel@tonic-gate 	struct rex_start *rst;
50*7c478bd9Sstevel@tonic-gate {
51*7c478bd9Sstevel@tonic-gate 	return
52*7c478bd9Sstevel@tonic-gate 		xdr_argv(xdrs, &rst->rst_cmd) &&
53*7c478bd9Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_host, 1024) &&
54*7c478bd9Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_fsname, 1024) &&
55*7c478bd9Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_dirwithin, 1024) &&
56*7c478bd9Sstevel@tonic-gate 		xdr_argv(xdrs, &rst->rst_env) &&
57*7c478bd9Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port0) &&
58*7c478bd9Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port1) &&
59*7c478bd9Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port2) &&
60*7c478bd9Sstevel@tonic-gate 		xdr_u_long(xdrs, &rst->rst_flags);
61*7c478bd9Sstevel@tonic-gate }
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate xdr_argv(xdrs, argvp)
64*7c478bd9Sstevel@tonic-gate 	XDR *xdrs;
65*7c478bd9Sstevel@tonic-gate 	char ***argvp;
66*7c478bd9Sstevel@tonic-gate {
67*7c478bd9Sstevel@tonic-gate 	register char **argv = *argvp;
68*7c478bd9Sstevel@tonic-gate 	register char **ap;
69*7c478bd9Sstevel@tonic-gate 	int i, count;
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate 	/*
72*7c478bd9Sstevel@tonic-gate 	 * find the number of args to encode or free
73*7c478bd9Sstevel@tonic-gate 	 */
74*7c478bd9Sstevel@tonic-gate 	if ((xdrs->x_op) != XDR_DECODE)
75*7c478bd9Sstevel@tonic-gate 		for (count = 0, ap = argv; *ap != 0; ap++)
76*7c478bd9Sstevel@tonic-gate 			count++;
77*7c478bd9Sstevel@tonic-gate 	/* XDR the count */
78*7c478bd9Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, (unsigned *) &count))
79*7c478bd9Sstevel@tonic-gate 		return (FALSE);
80*7c478bd9Sstevel@tonic-gate 
81*7c478bd9Sstevel@tonic-gate 	/*
82*7c478bd9Sstevel@tonic-gate 	 * now deal with the strings
83*7c478bd9Sstevel@tonic-gate 	 */
84*7c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE) {
85*7c478bd9Sstevel@tonic-gate 		*argvp = argv = (char **)
86*7c478bd9Sstevel@tonic-gate 			mem_alloc((unsigned)(count+1)*sizeof (char **));
87*7c478bd9Sstevel@tonic-gate 		for (i = 0; i <= count; i++)	/* Note: <=, not < */
88*7c478bd9Sstevel@tonic-gate 			argv[i] = 0;
89*7c478bd9Sstevel@tonic-gate 	}
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate 	for (i = 0, ap = argv; i < count; i++, ap++)
92*7c478bd9Sstevel@tonic-gate 		if (!xdr_string(xdrs, ap, 10240))
93*7c478bd9Sstevel@tonic-gate 			return (FALSE);
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 	if (xdrs->x_op == XDR_FREE && argv != NULL) {
96*7c478bd9Sstevel@tonic-gate 		mem_free((char *) argv, (count+1)*sizeof (char **));
97*7c478bd9Sstevel@tonic-gate 		*argvp = NULL;
98*7c478bd9Sstevel@tonic-gate 	}
99*7c478bd9Sstevel@tonic-gate 	return (TRUE);
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate /*
103*7c478bd9Sstevel@tonic-gate  * xdr_rex_result - process the result of a start or wait operation
104*7c478bd9Sstevel@tonic-gate  */
105*7c478bd9Sstevel@tonic-gate xdr_rex_result(xdrs, result)
106*7c478bd9Sstevel@tonic-gate 	XDR *xdrs;
107*7c478bd9Sstevel@tonic-gate 	struct rex_result *result;
108*7c478bd9Sstevel@tonic-gate {
109*7c478bd9Sstevel@tonic-gate 	return
110*7c478bd9Sstevel@tonic-gate 		xdr_int(xdrs, &result->rlt_stat) &&
111*7c478bd9Sstevel@tonic-gate 		xdr_string(xdrs, &result->rlt_message, 1024);
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate }
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate /*
116*7c478bd9Sstevel@tonic-gate  * xdr_rex_ttymode - process the tty mode information
117*7c478bd9Sstevel@tonic-gate  */
118*7c478bd9Sstevel@tonic-gate xdr_rex_ttymode(xdrs, mode)
119*7c478bd9Sstevel@tonic-gate 	XDR *xdrs;
120*7c478bd9Sstevel@tonic-gate 	struct rex_ttymode *mode;
121*7c478bd9Sstevel@tonic-gate {
122*7c478bd9Sstevel@tonic-gate 	u_int six = 6;
123*7c478bd9Sstevel@tonic-gate 	u_int four = 4;
124*7c478bd9Sstevel@tonic-gate 	char *speedp = NULL;
125*7c478bd9Sstevel@tonic-gate 	char *morep = NULL;
126*7c478bd9Sstevel@tonic-gate 	char *yetmorep = NULL;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (xdrs->x_op != XDR_FREE) {
129*7c478bd9Sstevel@tonic-gate 		speedp = &mode->basic.sg_ispeed;
130*7c478bd9Sstevel@tonic-gate 		morep = (char *)&mode->more;
131*7c478bd9Sstevel@tonic-gate 		yetmorep = (char *)&mode->yetmore;
132*7c478bd9Sstevel@tonic-gate 	}
133*7c478bd9Sstevel@tonic-gate 	return
134*7c478bd9Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &speedp, (u_int *)&four, 4) &&
135*7c478bd9Sstevel@tonic-gate 		xdr_short(xdrs, (short *) &mode->basic.sg_flags) &&
136*7c478bd9Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &morep, (u_int *)&six, 6) &&
137*7c478bd9Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &yetmorep, (u_int *)&six, 6) &&
138*7c478bd9Sstevel@tonic-gate 		xdr_u_long(xdrs, &mode->andmore);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate  * xdr_rex_ttysize - process the tty size information
144*7c478bd9Sstevel@tonic-gate  */
145*7c478bd9Sstevel@tonic-gate xdr_rex_ttysize(xdrs, size)
146*7c478bd9Sstevel@tonic-gate 	XDR *xdrs;
147*7c478bd9Sstevel@tonic-gate 	struct ttysize *size;
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate 	return
150*7c478bd9Sstevel@tonic-gate 		xdr_int(xdrs, &size->ts_lines) &&
151*7c478bd9Sstevel@tonic-gate 		xdr_int(xdrs, &size->ts_cols);
152*7c478bd9Sstevel@tonic-gate }
153