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