xref: /titanic_41/usr/src/common/smbsrv/smb_token_xdr.c (revision ef287aad55c36c55e43651ee7ec7aa169b89408d)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * This file was originally generated using rpcgen.
28  */
29 
30 #ifndef _KERNEL
31 #include <stdlib.h>
32 #endif /* !_KERNEL */
33 #include <smbsrv/wintypes.h>
34 #include <smbsrv/smb_sid.h>
35 #include <smbsrv/smb_xdr.h>
36 #include <smbsrv/smb_token.h>
37 
38 static bool_t xdr_smb_privset_t(XDR *, smb_privset_t *);
39 static bool_t xdr_smb_sid_t(XDR *, smb_sid_t *);
40 
41 static bool_t
42 xdr_smb_privset_helper(xdrs, privs)
43 	XDR *xdrs;
44 	char **privs;
45 {
46 	uint32_t pos, len;
47 	uint32_t cnt;
48 	bool_t rc;
49 	smb_privset_t *p;
50 
51 	if (xdrs->x_op == XDR_DECODE) {
52 		pos = xdr_getpos(xdrs);
53 
54 		if (!xdr_bool(xdrs, &rc))
55 			return (FALSE);
56 
57 		if (!xdr_uint32_t(xdrs, &cnt))
58 			return (FALSE);
59 
60 		rc = xdr_setpos(xdrs, pos);
61 
62 		if (rc == FALSE)
63 			return (FALSE);
64 	} else {
65 		if (*privs == NULL)
66 			return (FALSE);
67 
68 		p = (smb_privset_t *)(uintptr_t)*privs;
69 		cnt = p->priv_cnt;
70 	}
71 
72 	len = sizeof (smb_privset_t)
73 	    - sizeof (smb_luid_attrs_t)
74 	    + (cnt * sizeof (smb_luid_attrs_t));
75 
76 	if (!xdr_pointer(xdrs, privs, len, (xdrproc_t)xdr_smb_privset_t))
77 		return (FALSE);
78 
79 	return (TRUE);
80 }
81 
82 static bool_t
83 xdr_smb_id_t(xdrs, objp)
84 	XDR *xdrs;
85 	smb_id_t *objp;
86 {
87 	uint8_t len;
88 
89 	if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_FREE))
90 		len = smb_sid_len(objp->i_sid);
91 
92 	if (!xdr_uint32_t(xdrs, &objp->i_attrs))
93 		return (FALSE);
94 
95 	if (!xdr_uint8_t(xdrs, &len))
96 		return (FALSE);
97 
98 	if (!xdr_pointer(xdrs, (char **)&objp->i_sid, len,
99 	    (xdrproc_t)xdr_smb_sid_t))
100 		return (FALSE);
101 
102 	if (!xdr_uint32_t(xdrs, (uint32_t *)&objp->i_id))
103 		return (FALSE);
104 
105 	return (TRUE);
106 }
107 
108 static bool_t
109 xdr_smb_ids_t(xdrs, objp)
110 	XDR *xdrs;
111 	smb_ids_t *objp;
112 {
113 	if (!xdr_array(xdrs, (char **)&objp->i_ids, (uint32_t *)&objp->i_cnt,
114 	    ~0, sizeof (smb_id_t), (xdrproc_t)xdr_smb_id_t))
115 		return (FALSE);
116 
117 	return (TRUE);
118 }
119 
120 static bool_t
121 xdr_smb_posix_grps_t(xdrs, objp)
122 	XDR *xdrs;
123 	smb_posix_grps_t *objp;
124 {
125 	if (!xdr_uint32_t(xdrs, &objp->pg_ngrps))
126 		return (FALSE);
127 	if (!xdr_vector(xdrs, (char *)objp->pg_grps, objp->pg_ngrps,
128 		sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
129 		return (FALSE);
130 	return (TRUE);
131 }
132 
133 static bool_t
134 xdr_smb_posix_grps_helper(xdrs, identity)
135 	XDR *xdrs;
136 	char **identity;
137 {
138 	uint32_t pos, len;
139 	uint32_t cnt;
140 	bool_t rc;
141 
142 	if (xdrs->x_op == XDR_DECODE) {
143 		pos = xdr_getpos(xdrs);
144 
145 		if (!xdr_bool(xdrs, &rc))
146 			return (FALSE);
147 
148 		if (!xdr_uint32_t(xdrs, &cnt))
149 			return (FALSE);
150 
151 		rc = xdr_setpos(xdrs, pos);
152 		if (rc == FALSE)
153 			return (FALSE);
154 	} else {
155 		if (*identity == NULL)
156 			return (FALSE);
157 		cnt = ((smb_posix_grps_t *)(uintptr_t)*identity)->pg_ngrps;
158 	}
159 
160 	len = SMB_POSIX_GRPS_SIZE(cnt);
161 
162 	if (!xdr_pointer(xdrs, identity, len, (xdrproc_t)xdr_smb_posix_grps_t))
163 		return (FALSE);
164 	return (TRUE);
165 }
166 
167 static bool_t
168 xdr_smb_session_key_t(xdrs, objp)
169 	XDR *xdrs;
170 	smb_session_key_t *objp;
171 {
172 	if (!xdr_vector(xdrs, (char *)objp->data, 16,
173 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
174 		return (FALSE);
175 	return (TRUE);
176 }
177 
178 bool_t
179 xdr_netr_client_t(xdrs, objp)
180 	XDR *xdrs;
181 	netr_client_t *objp;
182 {
183 	if (!xdr_uint16_t(xdrs, &objp->logon_level))
184 		return (FALSE);
185 	if (!xdr_string(xdrs, &objp->username, ~0))
186 		return (FALSE);
187 	if (!xdr_string(xdrs, &objp->domain, ~0))
188 		return (FALSE);
189 	if (!xdr_string(xdrs, &objp->real_username, ~0))
190 		return (FALSE);
191 	if (!xdr_string(xdrs, &objp->real_domain, ~0))
192 		return (FALSE);
193 	if (!xdr_string(xdrs, &objp->workstation, ~0))
194 		return (FALSE);
195 	if (!xdr_smb_inaddr_t(xdrs, &objp->ipaddr))
196 		return (FALSE);
197 	if (!xdr_array(xdrs, (char **)&objp->challenge_key.challenge_key_val,
198 	    (uint32_t *)&objp->challenge_key.challenge_key_len, ~0,
199 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
200 		return (FALSE);
201 	if (!xdr_array(xdrs, (char **)&objp->nt_password.nt_password_val,
202 	    (uint32_t *)&objp->nt_password.nt_password_len, ~0,
203 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
204 		return (FALSE);
205 	if (!xdr_array(xdrs, (char **)&objp->lm_password.lm_password_val,
206 	    (uint32_t *)&objp->lm_password.lm_password_len, ~0,
207 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
208 		return (FALSE);
209 	if (!xdr_uint32_t(xdrs, &objp->logon_id))
210 		return (FALSE);
211 	if (!xdr_int(xdrs, &objp->native_os))
212 		return (FALSE);
213 	if (!xdr_int(xdrs, &objp->native_lm))
214 		return (FALSE);
215 	if (!xdr_smb_inaddr_t(xdrs, &objp->local_ipaddr))
216 		return (FALSE);
217 	if (!xdr_uint16_t(xdrs, &objp->local_port))
218 		return (FALSE);
219 	return (TRUE);
220 }
221 
222 static bool_t
223 xdr_smb_sid_t(xdrs, objp)
224 	XDR *xdrs;
225 	smb_sid_t *objp;
226 {
227 	if (!xdr_uint8_t(xdrs, &objp->sid_revision))
228 		return (FALSE);
229 	if (!xdr_uint8_t(xdrs, &objp->sid_subauthcnt))
230 		return (FALSE);
231 	if (!xdr_vector(xdrs, (char *)objp->sid_authority, NT_SID_AUTH_MAX,
232 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
233 		return (FALSE);
234 	if (!xdr_vector(xdrs, (char *)objp->sid_subauth, objp->sid_subauthcnt,
235 	    sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
236 		return (FALSE);
237 	return (TRUE);
238 }
239 
240 static bool_t
241 xdr_smb_luid_t(xdrs, objp)
242 	XDR *xdrs;
243 	smb_luid_t *objp;
244 {
245 	if (!xdr_uint32_t(xdrs, &objp->lo_part))
246 		return (FALSE);
247 	if (!xdr_uint32_t(xdrs, &objp->hi_part))
248 		return (FALSE);
249 	return (TRUE);
250 }
251 
252 static bool_t
253 xdr_smb_luid_attrs_t(xdrs, objp)
254 	XDR *xdrs;
255 	smb_luid_attrs_t *objp;
256 {
257 	if (!xdr_smb_luid_t(xdrs, &objp->luid))
258 		return (FALSE);
259 	if (!xdr_uint32_t(xdrs, &objp->attrs))
260 		return (FALSE);
261 	return (TRUE);
262 }
263 
264 static bool_t
265 xdr_smb_privset_t(xdrs, objp)
266 	XDR *xdrs;
267 	smb_privset_t *objp;
268 {
269 	if (!xdr_uint32_t(xdrs, &objp->priv_cnt))
270 		return (FALSE);
271 	if (!xdr_uint32_t(xdrs, &objp->control))
272 		return (FALSE);
273 	if (!xdr_vector(xdrs, (char *)objp->priv, objp->priv_cnt,
274 	    sizeof (smb_luid_attrs_t),
275 	    (xdrproc_t)xdr_smb_luid_attrs_t))
276 		return (FALSE);
277 	return (TRUE);
278 }
279 
280 bool_t
281 xdr_smb_token_t(xdrs, objp)
282 	XDR *xdrs;
283 	smb_token_t *objp;
284 {
285 	if (!xdr_smb_id_t(xdrs, &objp->tkn_user))
286 		return (FALSE);
287 	if (!xdr_smb_id_t(xdrs, &objp->tkn_owner))
288 		return (FALSE);
289 	if (!xdr_smb_id_t(xdrs, &objp->tkn_primary_grp))
290 		return (FALSE);
291 	if (!xdr_smb_ids_t(xdrs, &objp->tkn_win_grps))
292 		return (FALSE);
293 	if (!xdr_smb_privset_helper(xdrs, (char **)&objp->tkn_privileges))
294 		return (FALSE);
295 	if (!xdr_string(xdrs, &objp->tkn_account_name, ~0))
296 		return (FALSE);
297 	if (!xdr_string(xdrs, &objp->tkn_domain_name, ~0))
298 		return (FALSE);
299 	if (!xdr_uint32_t(xdrs, &objp->tkn_flags))
300 		return (FALSE);
301 	if (!xdr_uint32_t(xdrs, &objp->tkn_audit_sid))
302 		return (FALSE);
303 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_session_key,
304 	    sizeof (smb_session_key_t), (xdrproc_t)xdr_smb_session_key_t))
305 		return (FALSE);
306 	if (!xdr_smb_posix_grps_helper(xdrs, (char **)&objp->tkn_posix_grps))
307 		return (FALSE);
308 	return (TRUE);
309 }
310