xref: /titanic_41/usr/src/common/smbsrv/smb_token_xdr.c (revision a18dc42fc967d11feba9b8be61c6727dc6c56b48)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * This file was originally generated using rpcgen.
30  */
31 
32 #ifndef _KERNEL
33 #include <stdlib.h>
34 #endif /* !_KERNEL */
35 #include <smbsrv/smb_vops.h>
36 #include <smbsrv/wintypes.h>
37 #include <smbsrv/smb_sid.h>
38 #include <smbsrv/smb_xdr.h>
39 #include <smbsrv/smb_token.h>
40 
41 static bool_t
42 xdr_sid_helper(xdrs, sid)
43 	XDR *xdrs;
44 	char **sid;
45 {
46 	uint32_t pos, len;
47 	uint8_t dummy, cnt;
48 	bool_t rc;
49 
50 	switch (xdrs->x_op) {
51 	case XDR_DECODE:
52 		/*
53 		 * chicken-and-egg: Can't use smb_sid_len() since it takes
54 		 * SID as its parameter while sid is yet to be decoded.
55 		 */
56 		pos = xdr_getpos(xdrs);
57 
58 		if (!xdr_bool(xdrs, &rc))
59 			return (FALSE);
60 
61 		if (!xdr_uint8_t(xdrs, &dummy))
62 			return (FALSE);
63 
64 		if (!xdr_uint8_t(xdrs, &cnt))
65 			return (FALSE);
66 
67 		rc = xdr_setpos(xdrs, pos);
68 
69 		if (rc == FALSE)
70 			return (FALSE);
71 
72 		len = sizeof (smb_sid_t) - sizeof (uint32_t) +
73 		    (cnt * sizeof (uint32_t));
74 
75 		if (!xdr_pointer(xdrs, sid, len, (xdrproc_t)xdr_smb_sid_t))
76 			return (FALSE);
77 		break;
78 
79 	case XDR_ENCODE:
80 	case XDR_FREE:
81 		if (*sid == NULL)
82 			return (FALSE);
83 
84 		len = smb_sid_len((smb_sid_t *)(uintptr_t)*sid);
85 		if (!xdr_pointer(xdrs, sid, len, (xdrproc_t)xdr_smb_sid_t))
86 			return (FALSE);
87 		break;
88 	}
89 
90 	return (TRUE);
91 }
92 
93 bool_t
94 xdr_smb_privset_helper(xdrs, privs)
95 	XDR *xdrs;
96 	char **privs;
97 {
98 	uint32_t pos, len;
99 	uint32_t cnt;
100 	bool_t rc;
101 	smb_privset_t *p;
102 
103 	if (xdrs->x_op == XDR_DECODE) {
104 		pos = xdr_getpos(xdrs);
105 
106 		if (!xdr_bool(xdrs, &rc))
107 			return (FALSE);
108 
109 		if (!xdr_uint32_t(xdrs, &cnt))
110 			return (FALSE);
111 
112 		rc = xdr_setpos(xdrs, pos);
113 
114 		if (rc == FALSE)
115 			return (FALSE);
116 	} else {
117 		if (*privs == NULL)
118 			return (FALSE);
119 
120 		p = (smb_privset_t *)(uintptr_t)*privs;
121 		cnt = p->priv_cnt;
122 	}
123 
124 	len = sizeof (smb_privset_t)
125 	    - sizeof (smb_luid_attrs_t)
126 	    + (cnt * sizeof (smb_luid_attrs_t));
127 
128 	if (!xdr_pointer(xdrs, privs, len, (xdrproc_t)xdr_smb_privset_t))
129 		return (FALSE);
130 
131 	return (TRUE);
132 }
133 
134 bool_t
135 xdr_smb_win_grps_helper(xdrs, grps)
136 	XDR *xdrs;
137 	char **grps;
138 {
139 	uint32_t pos, len;
140 	uint16_t cnt;
141 	bool_t rc;
142 
143 	if (xdrs->x_op == XDR_DECODE) {
144 		pos = xdr_getpos(xdrs);
145 
146 		if (!xdr_bool(xdrs, &rc))
147 			return (FALSE);
148 
149 		if (!xdr_uint16_t(xdrs, &cnt))
150 			return (FALSE);
151 
152 		rc = xdr_setpos(xdrs, pos);
153 		if (rc == FALSE)
154 			return (FALSE);
155 	} else {
156 		if (*grps == NULL)
157 			return (FALSE);
158 
159 		cnt = ((smb_win_grps_t *)(uintptr_t)*grps)->wg_count;
160 	}
161 
162 	len = cnt * sizeof (smb_id_t) + sizeof (smb_win_grps_t);
163 
164 	if (!xdr_pointer(xdrs, grps, len, (xdrproc_t)xdr_smb_win_grps_t))
165 		return (FALSE);
166 
167 	return (TRUE);
168 }
169 
170 bool_t
171 xdr_smb_id_t(xdrs, objp)
172 	XDR *xdrs;
173 	smb_id_t *objp;
174 {
175 	if (!xdr_smb_sid_attrs_t(xdrs, &objp->i_sidattr))
176 		return (FALSE);
177 	if (!xdr_uint32_t(xdrs, (uint32_t *)&objp->i_id))
178 		return (FALSE);
179 	return (TRUE);
180 }
181 
182 bool_t
183 xdr_smb_win_grps_t(xdrs, objp)
184 	XDR *xdrs;
185 	smb_win_grps_t *objp;
186 {
187 	if (!xdr_uint16_t(xdrs, &objp->wg_count))
188 		return (FALSE);
189 	if (!xdr_vector(xdrs, (char *)objp->wg_groups, objp->wg_count,
190 		sizeof (smb_id_t), (xdrproc_t)xdr_smb_id_t))
191 		return (FALSE);
192 	return (TRUE);
193 }
194 
195 bool_t
196 xdr_smb_posix_grps_t(xdrs, objp)
197 	XDR *xdrs;
198 	smb_posix_grps_t *objp;
199 {
200 	if (!xdr_uint32_t(xdrs, &objp->pg_ngrps))
201 		return (FALSE);
202 	if (!xdr_vector(xdrs, (char *)objp->pg_grps, objp->pg_ngrps,
203 		sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
204 		return (FALSE);
205 	return (TRUE);
206 }
207 
208 bool_t
209 xdr_smb_posix_grps_helper(xdrs, identity)
210 	XDR *xdrs;
211 	char **identity;
212 {
213 	uint32_t pos, len;
214 	uint32_t cnt;
215 	bool_t rc;
216 
217 	if (xdrs->x_op == XDR_DECODE) {
218 		pos = xdr_getpos(xdrs);
219 
220 		if (!xdr_bool(xdrs, &rc))
221 			return (FALSE);
222 
223 		if (!xdr_uint32_t(xdrs, &cnt))
224 			return (FALSE);
225 
226 		rc = xdr_setpos(xdrs, pos);
227 		if (rc == FALSE)
228 			return (FALSE);
229 	} else {
230 		if (*identity == NULL)
231 			return (FALSE);
232 		cnt = ((smb_posix_grps_t *)(uintptr_t)*identity)->pg_ngrps;
233 	}
234 
235 	len = SMB_POSIX_GRPS_SIZE(cnt);
236 
237 	if (!xdr_pointer(xdrs, identity, len, (xdrproc_t)xdr_smb_posix_grps_t))
238 		return (FALSE);
239 	return (TRUE);
240 }
241 
242 bool_t
243 xdr_smb_session_key_t(xdrs, objp)
244 	XDR *xdrs;
245 	smb_session_key_t *objp;
246 {
247 	if (!xdr_vector(xdrs, (char *)objp->data, 16,
248 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
249 		return (FALSE);
250 	return (TRUE);
251 }
252 
253 bool_t
254 xdr_netr_client_t(xdrs, objp)
255 	XDR *xdrs;
256 	netr_client_t *objp;
257 {
258 	if (!xdr_uint16_t(xdrs, &objp->logon_level))
259 		return (FALSE);
260 	if (!xdr_string(xdrs, &objp->username, ~0))
261 		return (FALSE);
262 	if (!xdr_string(xdrs, &objp->domain, ~0))
263 		return (FALSE);
264 	if (!xdr_string(xdrs, &objp->workstation, ~0))
265 		return (FALSE);
266 	if (!xdr_uint32_t(xdrs, &objp->ipaddr))
267 		return (FALSE);
268 	if (!xdr_array(xdrs, (char **)&objp->challenge_key.challenge_key_val,
269 	    (uint32_t *)&objp->challenge_key.challenge_key_len, ~0,
270 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
271 		return (FALSE);
272 	if (!xdr_array(xdrs, (char **)&objp->nt_password.nt_password_val,
273 	    (uint32_t *)&objp->nt_password.nt_password_len, ~0,
274 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
275 		return (FALSE);
276 	if (!xdr_array(xdrs, (char **)&objp->lm_password.lm_password_val,
277 	    (uint32_t *)&objp->lm_password.lm_password_len, ~0,
278 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
279 		return (FALSE);
280 	if (!xdr_uint32_t(xdrs, &objp->logon_id))
281 		return (FALSE);
282 	if (!xdr_int(xdrs, &objp->native_os))
283 		return (FALSE);
284 	if (!xdr_int(xdrs, &objp->native_lm))
285 		return (FALSE);
286 	if (!xdr_uint32_t(xdrs, &objp->local_ipaddr))
287 		return (FALSE);
288 	if (!xdr_uint16_t(xdrs, &objp->local_port))
289 		return (FALSE);
290 	if (!xdr_uint32_t(xdrs, &objp->flags))
291 		return (FALSE);
292 	return (TRUE);
293 }
294 
295 bool_t
296 xdr_smb_sid_t(xdrs, objp)
297 	XDR *xdrs;
298 	smb_sid_t *objp;
299 {
300 	if (!xdr_uint8_t(xdrs, &objp->sid_revision))
301 		return (FALSE);
302 	if (!xdr_uint8_t(xdrs, &objp->sid_subauthcnt))
303 		return (FALSE);
304 	if (!xdr_vector(xdrs, (char *)objp->sid_authority, NT_SID_AUTH_MAX,
305 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
306 		return (FALSE);
307 	if (!xdr_vector(xdrs, (char *)objp->sid_subauth, objp->sid_subauthcnt,
308 	    sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
309 		return (FALSE);
310 	return (TRUE);
311 }
312 
313 bool_t
314 xdr_smb_luid_t(xdrs, objp)
315 	XDR *xdrs;
316 	smb_luid_t *objp;
317 {
318 	if (!xdr_uint32_t(xdrs, &objp->lo_part))
319 		return (FALSE);
320 	if (!xdr_uint32_t(xdrs, &objp->hi_part))
321 		return (FALSE);
322 	return (TRUE);
323 }
324 
325 bool_t
326 xdr_smb_luid_attrs_t(xdrs, objp)
327 	XDR *xdrs;
328 	smb_luid_attrs_t *objp;
329 {
330 	if (!xdr_smb_luid_t(xdrs, &objp->luid))
331 		return (FALSE);
332 	if (!xdr_uint32_t(xdrs, &objp->attrs))
333 		return (FALSE);
334 	return (TRUE);
335 }
336 
337 bool_t
338 xdr_smb_privset_t(xdrs, objp)
339 	XDR *xdrs;
340 	smb_privset_t *objp;
341 {
342 	if (!xdr_uint32_t(xdrs, &objp->priv_cnt))
343 		return (FALSE);
344 	if (!xdr_uint32_t(xdrs, &objp->control))
345 		return (FALSE);
346 	if (!xdr_vector(xdrs, (char *)objp->priv, objp->priv_cnt,
347 	    sizeof (smb_luid_attrs_t),
348 	    (xdrproc_t)xdr_smb_luid_attrs_t))
349 		return (FALSE);
350 	return (TRUE);
351 }
352 
353 bool_t
354 xdr_smb_sid_attrs_t(xdrs, objp)
355 	XDR *xdrs;
356 	smb_sid_attrs_t *objp;
357 {
358 	if (!xdr_uint32_t(xdrs, &objp->attrs))
359 		return (FALSE);
360 	return (xdr_sid_helper(xdrs, (char **)&objp->sid));
361 }
362 
363 bool_t
364 xdr_smb_token_t(xdrs, objp)
365 	XDR *xdrs;
366 	smb_token_t *objp;
367 {
368 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_user,
369 	    sizeof (smb_id_t), (xdrproc_t)xdr_smb_id_t))
370 		return (FALSE);
371 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_owner,
372 	    sizeof (smb_id_t), (xdrproc_t)xdr_smb_id_t))
373 		return (FALSE);
374 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_primary_grp,
375 	    sizeof (smb_id_t), (xdrproc_t)xdr_smb_id_t))
376 		return (FALSE);
377 	if (!xdr_smb_win_grps_helper(xdrs, (char **)&objp->tkn_win_grps))
378 		return (FALSE);
379 	if (!xdr_smb_privset_helper(xdrs, (char **)&objp->tkn_privileges))
380 		return (FALSE);
381 	if (!xdr_string(xdrs, &objp->tkn_account_name, ~0))
382 		return (FALSE);
383 	if (!xdr_string(xdrs, &objp->tkn_domain_name, ~0))
384 		return (FALSE);
385 	if (!xdr_uint32_t(xdrs, &objp->tkn_flags))
386 		return (FALSE);
387 	if (!xdr_uint32_t(xdrs, &objp->tkn_audit_sid))
388 		return (FALSE);
389 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_session_key,
390 	    sizeof (smb_session_key_t), (xdrproc_t)xdr_smb_session_key_t))
391 		return (FALSE);
392 	if (!xdr_smb_posix_grps_helper(xdrs, (char **)&objp->tkn_posix_grps))
393 		return (FALSE);
394 	return (TRUE);
395 }
396