17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * rex_xdr - remote execution external data representations
247c478bd9Sstevel@tonic-gate *
25*16ab6e0bSsm26363 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26*16ab6e0bSsm26363 * Use is subject to license terms.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
29*16ab6e0bSsm26363 #pragma ident "%Z%%M% %I% %E% SMI"
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /* XXX - Bad, Bad, Bad.... Fix this. This isn't allowed in the base */
327c478bd9Sstevel@tonic-gate #define BSD_COMP
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate #include <stdio.h>
357c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
367c478bd9Sstevel@tonic-gate #include <sys/errno.h>
377c478bd9Sstevel@tonic-gate #include <sys/ttold.h>
387c478bd9Sstevel@tonic-gate #include <stropts.h>
397c478bd9Sstevel@tonic-gate #include <sys/stream.h>
407c478bd9Sstevel@tonic-gate #include <sys/tty.h>
417c478bd9Sstevel@tonic-gate #include <sys/ptyvar.h>
427c478bd9Sstevel@tonic-gate
437c478bd9Sstevel@tonic-gate #include "rex.h"
447c478bd9Sstevel@tonic-gate
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate * xdr_rex_start - process the command start structure
477c478bd9Sstevel@tonic-gate */
48*16ab6e0bSsm26363 int
xdr_rex_start(XDR * xdrs,struct rex_start * rst)49*16ab6e0bSsm26363 xdr_rex_start(XDR *xdrs, struct rex_start *rst)
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate return
527c478bd9Sstevel@tonic-gate xdr_argv(xdrs, &rst->rst_cmd) &&
537c478bd9Sstevel@tonic-gate xdr_string(xdrs, &rst->rst_host, 1024) &&
547c478bd9Sstevel@tonic-gate xdr_string(xdrs, &rst->rst_fsname, 1024) &&
557c478bd9Sstevel@tonic-gate xdr_string(xdrs, &rst->rst_dirwithin, 1024) &&
567c478bd9Sstevel@tonic-gate xdr_argv(xdrs, &rst->rst_env) &&
577c478bd9Sstevel@tonic-gate xdr_u_short(xdrs, &rst->rst_port0) &&
587c478bd9Sstevel@tonic-gate xdr_u_short(xdrs, &rst->rst_port1) &&
597c478bd9Sstevel@tonic-gate xdr_u_short(xdrs, &rst->rst_port2) &&
607c478bd9Sstevel@tonic-gate xdr_u_long(xdrs, &rst->rst_flags);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate
63*16ab6e0bSsm26363 int
xdr_argv(XDR * xdrs,char *** argvp)64*16ab6e0bSsm26363 xdr_argv(XDR *xdrs, char ***argvp)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate register char **argv = *argvp;
677c478bd9Sstevel@tonic-gate register char **ap;
687c478bd9Sstevel@tonic-gate int i, count;
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * find the number of args to encode or free
727c478bd9Sstevel@tonic-gate */
737c478bd9Sstevel@tonic-gate if ((xdrs->x_op) != XDR_DECODE)
747c478bd9Sstevel@tonic-gate for (count = 0, ap = argv; *ap != 0; ap++)
757c478bd9Sstevel@tonic-gate count++;
767c478bd9Sstevel@tonic-gate /* XDR the count */
777c478bd9Sstevel@tonic-gate if (!xdr_u_int(xdrs, (unsigned *) &count))
787c478bd9Sstevel@tonic-gate return (FALSE);
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate * now deal with the strings
827c478bd9Sstevel@tonic-gate */
837c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_DECODE) {
847c478bd9Sstevel@tonic-gate *argvp = argv = (char **)
857c478bd9Sstevel@tonic-gate mem_alloc((unsigned)(count+1)*sizeof (char **));
867c478bd9Sstevel@tonic-gate for (i = 0; i <= count; i++) /* Note: <=, not < */
877c478bd9Sstevel@tonic-gate argv[i] = 0;
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate for (i = 0, ap = argv; i < count; i++, ap++)
917c478bd9Sstevel@tonic-gate if (!xdr_string(xdrs, ap, 10240))
927c478bd9Sstevel@tonic-gate return (FALSE);
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate if (xdrs->x_op == XDR_FREE && argv != NULL) {
957c478bd9Sstevel@tonic-gate mem_free((char *) argv, (count+1)*sizeof (char **));
967c478bd9Sstevel@tonic-gate *argvp = NULL;
977c478bd9Sstevel@tonic-gate }
987c478bd9Sstevel@tonic-gate return (TRUE);
997c478bd9Sstevel@tonic-gate }
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate * xdr_rex_result - process the result of a start or wait operation
1037c478bd9Sstevel@tonic-gate */
104*16ab6e0bSsm26363 int
xdr_rex_result(XDR * xdrs,struct rex_result * result)105*16ab6e0bSsm26363 xdr_rex_result(XDR *xdrs, struct rex_result *result)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate return
1087c478bd9Sstevel@tonic-gate xdr_int(xdrs, &result->rlt_stat) &&
1097c478bd9Sstevel@tonic-gate xdr_string(xdrs, &result->rlt_message, 1024);
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate * xdr_rex_ttymode - process the tty mode information
1157c478bd9Sstevel@tonic-gate */
116*16ab6e0bSsm26363 int
xdr_rex_ttymode(XDR * xdrs,struct rex_ttymode * mode)117*16ab6e0bSsm26363 xdr_rex_ttymode(XDR *xdrs, struct rex_ttymode *mode)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate u_int six = 6;
1207c478bd9Sstevel@tonic-gate u_int four = 4;
1217c478bd9Sstevel@tonic-gate char *speedp = NULL;
1227c478bd9Sstevel@tonic-gate char *morep = NULL;
1237c478bd9Sstevel@tonic-gate char *yetmorep = NULL;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate if (xdrs->x_op != XDR_FREE) {
1267c478bd9Sstevel@tonic-gate speedp = &mode->basic.sg_ispeed;
1277c478bd9Sstevel@tonic-gate morep = (char *)&mode->more;
1287c478bd9Sstevel@tonic-gate yetmorep = (char *)&mode->yetmore;
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate return
1317c478bd9Sstevel@tonic-gate xdr_bytes(xdrs, (char **) &speedp, (u_int *)&four, 4) &&
1327c478bd9Sstevel@tonic-gate xdr_short(xdrs, (short *) &mode->basic.sg_flags) &&
1337c478bd9Sstevel@tonic-gate xdr_bytes(xdrs, (char **) &morep, (u_int *)&six, 6) &&
1347c478bd9Sstevel@tonic-gate xdr_bytes(xdrs, (char **) &yetmorep, (u_int *)&six, 6) &&
1357c478bd9Sstevel@tonic-gate xdr_u_long(xdrs, &mode->andmore);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * xdr_rex_ttysize - process the tty size information
1417c478bd9Sstevel@tonic-gate */
142*16ab6e0bSsm26363 int
xdr_rex_ttysize(XDR * xdrs,struct ttysize * size)143*16ab6e0bSsm26363 xdr_rex_ttysize(XDR *xdrs, struct ttysize *size)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate return
1467c478bd9Sstevel@tonic-gate xdr_int(xdrs, &size->ts_lines) &&
1477c478bd9Sstevel@tonic-gate xdr_int(xdrs, &size->ts_cols);
1487c478bd9Sstevel@tonic-gate }
149