xref: /titanic_50/usr/src/common/smbsrv/smb_token_xdr.c (revision 494f7e12a62129ef191a15f9dfde6b7abe3bf510)
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 2010 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 smb_privset_xdr(XDR *, smb_privset_t *);
39 static bool_t smb_sid_xdr(XDR *, smb_sid_t *);
40 
41 static bool_t
42 smb_privset_helper_xdr(XDR *xdrs, char **privs)
43 {
44 	uint32_t pos, len;
45 	uint32_t cnt;
46 	bool_t rc;
47 	smb_privset_t *p;
48 
49 	if (xdrs->x_op == XDR_DECODE) {
50 		pos = xdr_getpos(xdrs);
51 
52 		if (!xdr_bool(xdrs, &rc))
53 			return (FALSE);
54 
55 		if (!xdr_uint32_t(xdrs, &cnt))
56 			return (FALSE);
57 
58 		rc = xdr_setpos(xdrs, pos);
59 
60 		if (rc == FALSE)
61 			return (FALSE);
62 	} else {
63 		if (*privs == NULL)
64 			return (FALSE);
65 
66 		p = (smb_privset_t *)(uintptr_t)*privs;
67 		cnt = p->priv_cnt;
68 	}
69 
70 	len = sizeof (smb_privset_t)
71 	    - sizeof (smb_luid_attrs_t)
72 	    + (cnt * sizeof (smb_luid_attrs_t));
73 
74 	if (!xdr_pointer(xdrs, privs, len, (xdrproc_t)smb_privset_xdr))
75 		return (FALSE);
76 
77 	return (TRUE);
78 }
79 
80 static bool_t
81 smb_id_xdr(XDR *xdrs, smb_id_t *objp)
82 {
83 	uint8_t len;
84 
85 	if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_FREE))
86 		len = smb_sid_len(objp->i_sid);
87 
88 	if (!xdr_uint32_t(xdrs, &objp->i_attrs))
89 		return (FALSE);
90 
91 	if (!xdr_uint8_t(xdrs, &len))
92 		return (FALSE);
93 
94 	if (!xdr_pointer(xdrs, (char **)&objp->i_sid, len,
95 	    (xdrproc_t)smb_sid_xdr))
96 		return (FALSE);
97 
98 	if (!xdr_uint32_t(xdrs, (uint32_t *)&objp->i_id))
99 		return (FALSE);
100 
101 	return (TRUE);
102 }
103 
104 static bool_t
105 smb_ids_xdr(XDR *xdrs, smb_ids_t *objp)
106 {
107 	if (!xdr_array(xdrs, (char **)&objp->i_ids, (uint32_t *)&objp->i_cnt,
108 	    ~0, sizeof (smb_id_t), (xdrproc_t)smb_id_xdr))
109 		return (FALSE);
110 
111 	return (TRUE);
112 }
113 
114 static bool_t
115 smb_posix_grps_xdr(XDR *xdrs, smb_posix_grps_t *objp)
116 {
117 	if (!xdr_uint32_t(xdrs, &objp->pg_ngrps))
118 		return (FALSE);
119 	if (!xdr_vector(xdrs, (char *)objp->pg_grps, objp->pg_ngrps,
120 	    sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
121 		return (FALSE);
122 	return (TRUE);
123 }
124 
125 static bool_t
126 smb_posix_grps_helper_xdr(XDR *xdrs, char **identity)
127 {
128 	uint32_t pos, len;
129 	uint32_t cnt;
130 	bool_t rc;
131 
132 	if (xdrs->x_op == XDR_DECODE) {
133 		pos = xdr_getpos(xdrs);
134 
135 		if (!xdr_bool(xdrs, &rc))
136 			return (FALSE);
137 
138 		if (!xdr_uint32_t(xdrs, &cnt))
139 			return (FALSE);
140 
141 		rc = xdr_setpos(xdrs, pos);
142 		if (rc == FALSE)
143 			return (FALSE);
144 	} else {
145 		if (*identity == NULL)
146 			return (FALSE);
147 		cnt = ((smb_posix_grps_t *)(uintptr_t)*identity)->pg_ngrps;
148 	}
149 
150 	len = SMB_POSIX_GRPS_SIZE(cnt);
151 
152 	if (!xdr_pointer(xdrs, identity, len, (xdrproc_t)smb_posix_grps_xdr))
153 		return (FALSE);
154 	return (TRUE);
155 }
156 
157 static bool_t
158 smb_session_key_xdr(XDR *xdrs, smb_session_key_t *objp)
159 {
160 	if (!xdr_vector(xdrs, (char *)objp->data, 16,
161 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
162 		return (FALSE);
163 	return (TRUE);
164 }
165 
166 bool_t
167 smb_logon_xdr(XDR *xdrs, smb_logon_t *objp)
168 {
169 	if (!xdr_uint16_t(xdrs, &objp->lg_level))
170 		return (FALSE);
171 	if (!xdr_string(xdrs, &objp->lg_username, ~0))
172 		return (FALSE);
173 	if (!xdr_string(xdrs, &objp->lg_domain, ~0))
174 		return (FALSE);
175 	if (!xdr_string(xdrs, &objp->lg_e_username, ~0))
176 		return (FALSE);
177 	if (!xdr_string(xdrs, &objp->lg_e_domain, ~0))
178 		return (FALSE);
179 	if (!xdr_string(xdrs, &objp->lg_workstation, ~0))
180 		return (FALSE);
181 	if (!smb_inaddr_xdr(xdrs, &objp->lg_clnt_ipaddr))
182 		return (FALSE);
183 	if (!smb_inaddr_xdr(xdrs, &objp->lg_local_ipaddr))
184 		return (FALSE);
185 	if (!xdr_uint16_t(xdrs, &objp->lg_local_port))
186 		return (FALSE);
187 	if (!smb_buf32_xdr(xdrs, &objp->lg_challenge_key))
188 		return (FALSE);
189 	if (!smb_buf32_xdr(xdrs, &objp->lg_nt_password))
190 		return (FALSE);
191 	if (!smb_buf32_xdr(xdrs, &objp->lg_lm_password))
192 		return (FALSE);
193 	if (!xdr_int(xdrs, &objp->lg_native_os))
194 		return (FALSE);
195 	if (!xdr_int(xdrs, &objp->lg_native_lm))
196 		return (FALSE);
197 	if (!xdr_uint32_t(xdrs, &objp->lg_flags))
198 		return (FALSE);
199 	if (!xdr_uint32_t(xdrs, &objp->lg_logon_id))
200 		return (FALSE);
201 	if (!xdr_uint32_t(xdrs, &objp->lg_domain_type))
202 		return (FALSE);
203 	if (!xdr_uint32_t(xdrs, &objp->lg_secmode))
204 		return (FALSE);
205 	if (!xdr_uint32_t(xdrs, &objp->lg_status))
206 		return (FALSE);
207 	return (TRUE);
208 }
209 
210 static bool_t
211 smb_sid_xdr(XDR *xdrs, smb_sid_t *objp)
212 {
213 	if (!xdr_uint8_t(xdrs, &objp->sid_revision))
214 		return (FALSE);
215 	if (!xdr_uint8_t(xdrs, &objp->sid_subauthcnt))
216 		return (FALSE);
217 	if (!xdr_vector(xdrs, (char *)objp->sid_authority, NT_SID_AUTH_MAX,
218 	    sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
219 		return (FALSE);
220 	if (!xdr_vector(xdrs, (char *)objp->sid_subauth, objp->sid_subauthcnt,
221 	    sizeof (uint32_t), (xdrproc_t)xdr_uint32_t))
222 		return (FALSE);
223 	return (TRUE);
224 }
225 
226 static bool_t
227 smb_luid_xdr(XDR *xdrs, smb_luid_t *objp)
228 {
229 	if (!xdr_uint32_t(xdrs, &objp->lo_part))
230 		return (FALSE);
231 	if (!xdr_uint32_t(xdrs, &objp->hi_part))
232 		return (FALSE);
233 	return (TRUE);
234 }
235 
236 static bool_t
237 smb_luid_attrs_xdr(XDR *xdrs, smb_luid_attrs_t *objp)
238 {
239 	if (!smb_luid_xdr(xdrs, &objp->luid))
240 		return (FALSE);
241 	if (!xdr_uint32_t(xdrs, &objp->attrs))
242 		return (FALSE);
243 	return (TRUE);
244 }
245 
246 static bool_t
247 smb_privset_xdr(XDR *xdrs, smb_privset_t *objp)
248 {
249 	if (!xdr_uint32_t(xdrs, &objp->priv_cnt))
250 		return (FALSE);
251 	if (!xdr_uint32_t(xdrs, &objp->control))
252 		return (FALSE);
253 	if (!xdr_vector(xdrs, (char *)objp->priv, objp->priv_cnt,
254 	    sizeof (smb_luid_attrs_t),
255 	    (xdrproc_t)smb_luid_attrs_xdr))
256 		return (FALSE);
257 	return (TRUE);
258 }
259 
260 bool_t
261 smb_token_xdr(XDR *xdrs, smb_token_t *objp)
262 {
263 	if (!smb_id_xdr(xdrs, &objp->tkn_user))
264 		return (FALSE);
265 	if (!smb_id_xdr(xdrs, &objp->tkn_owner))
266 		return (FALSE);
267 	if (!smb_id_xdr(xdrs, &objp->tkn_primary_grp))
268 		return (FALSE);
269 	if (!smb_ids_xdr(xdrs, &objp->tkn_win_grps))
270 		return (FALSE);
271 	if (!smb_privset_helper_xdr(xdrs, (char **)&objp->tkn_privileges))
272 		return (FALSE);
273 	if (!xdr_string(xdrs, &objp->tkn_account_name, ~0))
274 		return (FALSE);
275 	if (!xdr_string(xdrs, &objp->tkn_domain_name, ~0))
276 		return (FALSE);
277 	if (!xdr_uint32_t(xdrs, &objp->tkn_flags))
278 		return (FALSE);
279 	if (!xdr_uint32_t(xdrs, &objp->tkn_audit_sid))
280 		return (FALSE);
281 	if (!xdr_pointer(xdrs, (char **)&objp->tkn_session_key,
282 	    sizeof (smb_session_key_t), (xdrproc_t)smb_session_key_xdr))
283 		return (FALSE);
284 	if (!smb_posix_grps_helper_xdr(xdrs, (char **)&objp->tkn_posix_grps))
285 		return (FALSE);
286 	return (TRUE);
287 }
288