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