xref: /onnv-gate/usr/src/cmd/rexd/rex.c (revision 620:70e88a3808c9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * rex_xdr - remote execution external data representations
240Sstevel@tonic-gate  *
25*620Ssm26363  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*620Ssm26363  * Use is subject to license terms.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
29*620Ssm26363 #pragma ident	"%Z%%M%	%I%	%E% SMI"
300Sstevel@tonic-gate 
310Sstevel@tonic-gate /* XXX - Bad, Bad, Bad.... Fix this. This isn't allowed in the base */
320Sstevel@tonic-gate #define	BSD_COMP
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <stdio.h>
350Sstevel@tonic-gate #include <rpc/rpc.h>
360Sstevel@tonic-gate #include <sys/errno.h>
370Sstevel@tonic-gate #include <sys/ttold.h>
380Sstevel@tonic-gate #include <stropts.h>
390Sstevel@tonic-gate #include <sys/stream.h>
400Sstevel@tonic-gate #include <sys/tty.h>
410Sstevel@tonic-gate #include <sys/ptyvar.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include "rex.h"
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * xdr_rex_start - process the command start structure
470Sstevel@tonic-gate  */
48*620Ssm26363 int
xdr_rex_start(XDR * xdrs,struct rex_start * rst)49*620Ssm26363 xdr_rex_start(XDR *xdrs,  struct rex_start *rst)
500Sstevel@tonic-gate {
510Sstevel@tonic-gate 	return
520Sstevel@tonic-gate 		xdr_argv(xdrs, &rst->rst_cmd) &&
530Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_host, 1024) &&
540Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_fsname, 1024) &&
550Sstevel@tonic-gate 		xdr_string(xdrs, &rst->rst_dirwithin, 1024) &&
560Sstevel@tonic-gate 		xdr_argv(xdrs, &rst->rst_env) &&
570Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port0) &&
580Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port1) &&
590Sstevel@tonic-gate 		xdr_u_short(xdrs, &rst->rst_port2) &&
600Sstevel@tonic-gate 		xdr_u_long(xdrs, &rst->rst_flags);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate 
63*620Ssm26363 int
xdr_argv(XDR * xdrs,char *** argvp)64*620Ssm26363 xdr_argv(XDR *xdrs, char ***argvp)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	register char **argv = *argvp;
670Sstevel@tonic-gate 	register char **ap;
680Sstevel@tonic-gate 	int i, count;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	/*
710Sstevel@tonic-gate 	 * find the number of args to encode or free
720Sstevel@tonic-gate 	 */
730Sstevel@tonic-gate 	if ((xdrs->x_op) != XDR_DECODE)
740Sstevel@tonic-gate 		for (count = 0, ap = argv; *ap != 0; ap++)
750Sstevel@tonic-gate 			count++;
760Sstevel@tonic-gate 	/* XDR the count */
770Sstevel@tonic-gate 	if (!xdr_u_int(xdrs, (unsigned *) &count))
780Sstevel@tonic-gate 		return (FALSE);
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	/*
810Sstevel@tonic-gate 	 * now deal with the strings
820Sstevel@tonic-gate 	 */
830Sstevel@tonic-gate 	if (xdrs->x_op == XDR_DECODE) {
840Sstevel@tonic-gate 		*argvp = argv = (char **)
850Sstevel@tonic-gate 			mem_alloc((unsigned)(count+1)*sizeof (char **));
860Sstevel@tonic-gate 		for (i = 0; i <= count; i++)	/* Note: <=, not < */
870Sstevel@tonic-gate 			argv[i] = 0;
880Sstevel@tonic-gate 	}
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	for (i = 0, ap = argv; i < count; i++, ap++)
910Sstevel@tonic-gate 		if (!xdr_string(xdrs, ap, 10240))
920Sstevel@tonic-gate 			return (FALSE);
930Sstevel@tonic-gate 
940Sstevel@tonic-gate 	if (xdrs->x_op == XDR_FREE && argv != NULL) {
950Sstevel@tonic-gate 		mem_free((char *) argv, (count+1)*sizeof (char **));
960Sstevel@tonic-gate 		*argvp = NULL;
970Sstevel@tonic-gate 	}
980Sstevel@tonic-gate 	return (TRUE);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate  * xdr_rex_result - process the result of a start or wait operation
1030Sstevel@tonic-gate  */
104*620Ssm26363 int
xdr_rex_result(XDR * xdrs,struct rex_result * result)105*620Ssm26363 xdr_rex_result(XDR *xdrs, struct rex_result *result)
1060Sstevel@tonic-gate {
1070Sstevel@tonic-gate 	return
1080Sstevel@tonic-gate 		xdr_int(xdrs, &result->rlt_stat) &&
1090Sstevel@tonic-gate 		xdr_string(xdrs, &result->rlt_message, 1024);
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate }
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * xdr_rex_ttymode - process the tty mode information
1150Sstevel@tonic-gate  */
116*620Ssm26363 int
xdr_rex_ttymode(XDR * xdrs,struct rex_ttymode * mode)117*620Ssm26363 xdr_rex_ttymode(XDR *xdrs, struct rex_ttymode *mode)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	u_int six = 6;
1200Sstevel@tonic-gate 	u_int four = 4;
1210Sstevel@tonic-gate 	char *speedp = NULL;
1220Sstevel@tonic-gate 	char *morep = NULL;
1230Sstevel@tonic-gate 	char *yetmorep = NULL;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	if (xdrs->x_op != XDR_FREE) {
1260Sstevel@tonic-gate 		speedp = &mode->basic.sg_ispeed;
1270Sstevel@tonic-gate 		morep = (char *)&mode->more;
1280Sstevel@tonic-gate 		yetmorep = (char *)&mode->yetmore;
1290Sstevel@tonic-gate 	}
1300Sstevel@tonic-gate 	return
1310Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &speedp, (u_int *)&four, 4) &&
1320Sstevel@tonic-gate 		xdr_short(xdrs, (short *) &mode->basic.sg_flags) &&
1330Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &morep, (u_int *)&six, 6) &&
1340Sstevel@tonic-gate 		xdr_bytes(xdrs, (char **) &yetmorep, (u_int *)&six, 6) &&
1350Sstevel@tonic-gate 		xdr_u_long(xdrs, &mode->andmore);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * xdr_rex_ttysize - process the tty size information
1410Sstevel@tonic-gate  */
142*620Ssm26363 int
xdr_rex_ttysize(XDR * xdrs,struct ttysize * size)143*620Ssm26363 xdr_rex_ttysize(XDR *xdrs, struct ttysize *size)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate 	return
1460Sstevel@tonic-gate 		xdr_int(xdrs, &size->ts_lines) &&
1470Sstevel@tonic-gate 		xdr_int(xdrs, &size->ts_cols);
1480Sstevel@tonic-gate }
149