xref: /titanic_52/usr/src/lib/libnsl/rpc/key_prot.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
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 /*
24  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include "mt.h"
31 #include <rpc/rpc.h>
32 #include <rpc/key_prot.h>
33 
34 /*
35  * Originally ompiled from key_prot.x using rpcgen.
36  */
37 
38 bool_t
39 xdr_keystatus(XDR *xdrs, keystatus *objp)
40 {
41 	return (xdr_enum(xdrs, (enum_t *)objp));
42 }
43 
44 bool_t
45 xdr_keybuf(XDR *xdrs, keybuf objp)
46 {
47 	return (xdr_opaque(xdrs, objp, HEXKEYBYTES));
48 }
49 
50 bool_t
51 xdr_keybuf3(XDR *xdrs, keybuf3 *objp)
52 {
53 	return (xdr_bytes(xdrs, (char **)&objp->keybuf3_val,
54 					(uint_t *)&objp->keybuf3_len, ~0));
55 }
56 
57 bool_t
58 xdr_netnamestr(XDR *xdrs, netnamestr *objp)
59 {
60 	return (xdr_string(xdrs, objp, MAXNETNAMELEN));
61 }
62 
63 bool_t
64 xdr_keylen_t(XDR *xdrs, keylen_t *objp)
65 {
66 	return (xdr_int(xdrs, objp));
67 }
68 
69 bool_t
70 xdr_algtype_t(XDR *xdrs, algtype_t *objp)
71 {
72 	return (xdr_int(xdrs, objp));
73 }
74 
75 bool_t
76 xdr_mechtype(XDR *xdrs, mechtype *objp)
77 {
78 	if (!xdr_keylen_t(xdrs, &objp->keylen))
79 		return (FALSE);
80 	return (xdr_algtype_t(xdrs, &objp->algtype));
81 }
82 
83 bool_t
84 xdr_keynum_t(XDR *xdrs, keynum_t *objp)
85 {
86 	return (xdr_int(xdrs, objp));
87 }
88 
89 bool_t
90 xdr_deskeyarray(XDR *xdrs, deskeyarray *objp)
91 {
92 	return (xdr_array(xdrs, (char **)&objp->deskeyarray_val,
93 		(uint_t *)&objp->deskeyarray_len, ~0,
94 		sizeof (des_block), (xdrproc_t)xdr_des_block));
95 }
96 
97 bool_t
98 xdr_cryptkeyarg(XDR *xdrs, cryptkeyarg *objp)
99 {
100 	if (!xdr_netnamestr(xdrs, &objp->remotename))
101 		return (FALSE);
102 	return (xdr_des_block(xdrs, &objp->deskey));
103 }
104 
105 bool_t
106 xdr_cryptkeyarg2(XDR *xdrs, cryptkeyarg2 *objp)
107 {
108 	if (!xdr_netnamestr(xdrs, &objp->remotename))
109 		return (FALSE);
110 	if (!xdr_netobj(xdrs, &objp->remotekey))
111 		return (FALSE);
112 	return (xdr_des_block(xdrs, &objp->deskey));
113 }
114 
115 bool_t
116 xdr_cryptkeyarg3(XDR *xdrs, cryptkeyarg3 *objp)
117 {
118 	if (!xdr_netnamestr(xdrs, &objp->remotename))
119 		return (FALSE);
120 	if (!xdr_keybuf3(xdrs, &objp->remotekey))
121 		return (FALSE);
122 	if (!xdr_deskeyarray(xdrs, &objp->deskey))
123 		return (FALSE);
124 	if (!xdr_algtype_t(xdrs, &objp->algtype))
125 		return (FALSE);
126 	return (xdr_keylen_t(xdrs, &objp->keylen));
127 }
128 
129 bool_t
130 xdr_cryptkeyres(XDR *xdrs, cryptkeyres *objp)
131 {
132 	if (!xdr_keystatus(xdrs, &objp->status))
133 		return (FALSE);
134 	if (objp->status != KEY_SUCCESS)
135 		return (TRUE);
136 	return (xdr_des_block(xdrs, &objp->cryptkeyres_u.deskey));
137 }
138 
139 bool_t
140 xdr_cryptkeyres3(XDR *xdrs, cryptkeyres3 *objp)
141 {
142 	if (!xdr_keystatus(xdrs, &objp->status))
143 		return (FALSE);
144 	if (objp->status != KEY_SUCCESS)
145 		return (TRUE);
146 	return (xdr_deskeyarray(xdrs, &objp->cryptkeyres3_u.deskey));
147 }
148 
149 bool_t
150 xdr_unixcred(XDR *xdrs, unixcred *objp)
151 {
152 	if (!xdr_u_int(xdrs, &objp->uid))
153 		return (FALSE);
154 	if (!xdr_u_int(xdrs, &objp->gid))
155 		return (FALSE);
156 	return (xdr_array(xdrs, (char **)&objp->gids.gids_val,
157 		(uint_t *)&objp->gids.gids_len, MAXGIDS,
158 		sizeof (uint_t), (xdrproc_t)xdr_u_int));
159 }
160 
161 bool_t
162 xdr_unixcred3(XDR *xdrs, unixcred3 *objp)
163 {
164 	if (!xdr_u_int(xdrs, &objp->uid))
165 		return (FALSE);
166 	if (!xdr_u_int(xdrs, &objp->gid))
167 		return (FALSE);
168 	return (xdr_array(xdrs, (char **)&objp->gids.gids_val,
169 		(uint_t *)&objp->gids.gids_len, ~0,
170 		sizeof (uint_t), (xdrproc_t)xdr_u_int));
171 }
172 
173 bool_t
174 xdr_getcredres(XDR *xdrs, getcredres *objp)
175 {
176 	if (!xdr_keystatus(xdrs, &objp->status))
177 		return (FALSE);
178 	if (objp->status != KEY_SUCCESS)
179 		return (TRUE);
180 	return (xdr_unixcred(xdrs, &objp->getcredres_u.cred));
181 }
182 
183 bool_t
184 xdr_getcredres3(XDR *xdrs, getcredres3 *objp)
185 {
186 	if (!xdr_keystatus(xdrs, &objp->status))
187 		return (FALSE);
188 	if (objp->status != KEY_SUCCESS)
189 		return (TRUE);
190 	return (xdr_unixcred3(xdrs, &objp->getcredres3_u.cred));
191 }
192 
193 bool_t
194 xdr_key_netstarg(XDR *xdrs, key_netstarg *objp)
195 {
196 	if (!xdr_keybuf(xdrs, objp->st_priv_key))
197 		return (FALSE);
198 	if (!xdr_keybuf(xdrs, objp->st_pub_key))
199 		return (FALSE);
200 	return (xdr_netnamestr(xdrs, &objp->st_netname));
201 }
202 
203 bool_t
204 xdr_key_netstarg3(XDR *xdrs, key_netstarg3 *objp)
205 {
206 	if (!xdr_keybuf3(xdrs, &objp->st_priv_key))
207 		return (FALSE);
208 	if (!xdr_keybuf3(xdrs, &objp->st_pub_key))
209 		return (FALSE);
210 	if (!xdr_netnamestr(xdrs, &objp->st_netname))
211 		return (FALSE);
212 	if (!xdr_algtype_t(xdrs, &objp->algtype))
213 		return (FALSE);
214 	if (!xdr_keylen_t(xdrs, &objp->keylen))
215 		return (FALSE);
216 	return (xdr_des_block(xdrs, &objp->userkey));
217 }
218 
219 bool_t
220 xdr_key_netstres(XDR *xdrs, key_netstres *objp)
221 {
222 	if (!xdr_keystatus(xdrs, &objp->status))
223 		return (FALSE);
224 	switch (objp->status) {
225 	case KEY_SUCCESS:
226 		if (!xdr_key_netstarg(xdrs, &objp->key_netstres_u.knet))
227 			return (FALSE);
228 		break;
229 	}
230 	return (TRUE);
231 }
232 
233 bool_t
234 xdr_key_netstres3(XDR *xdrs, key_netstres3 *objp)
235 {
236 	if (!xdr_keystatus(xdrs, &objp->status))
237 		return (FALSE);
238 	if (objp->status != KEY_SUCCESS)
239 		return (TRUE);
240 	return (xdr_key_netstarg3(xdrs, &objp->key_netstres3_u.knet));
241 }
242 
243 bool_t
244 xdr_deskeyarg3(XDR *xdrs, deskeyarg3 *objp)
245 {
246 	if (!xdr_keybuf3(xdrs, &objp->pub_key))
247 		return (FALSE);
248 	if (!xdr_int(xdrs, &objp->nkeys))
249 		return (FALSE);
250 	if (!xdr_algtype_t(xdrs, &objp->algtype))
251 		return (FALSE);
252 	return (xdr_keylen_t(xdrs, &objp->keylen));
253 }
254 
255 bool_t
256 xdr_setkeyarg3(XDR *xdrs, setkeyarg3 *objp)
257 {
258 	if (!xdr_keybuf3(xdrs, &objp->key))
259 		return (FALSE);
260 	if (!xdr_des_block(xdrs, &objp->userkey))
261 		return (FALSE);
262 	if (!xdr_algtype_t(xdrs, &objp->algtype))
263 		return (FALSE);
264 	return (xdr_keylen_t(xdrs, &objp->keylen));
265 }
266