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