5917 User-mode SMB server
[unleashed.git] / usr / src / common / smbsrv / smb_token_xdr.c
blob6b44899768336f925943e634b7e4238486cb234d
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * This file was originally generated using rpcgen.
30 #if !defined(_KERNEL) && !defined(_FAKE_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>
38 static bool_t smb_privset_xdr(XDR *, smb_privset_t *);
39 static bool_t smb_sid_xdr(XDR *, smb_sid_t *);
41 static bool_t
42 smb_privset_helper_xdr(XDR *xdrs, char **privs)
44 uint32_t pos, len;
45 uint32_t cnt;
46 bool_t rc;
47 smb_privset_t *p;
49 if (xdrs->x_op == XDR_DECODE) {
50 pos = xdr_getpos(xdrs);
52 if (!xdr_bool(xdrs, &rc))
53 return (FALSE);
55 if (!xdr_uint32_t(xdrs, &cnt))
56 return (FALSE);
58 rc = xdr_setpos(xdrs, pos);
60 if (rc == FALSE)
61 return (FALSE);
62 } else {
63 if (*privs == NULL)
64 return (FALSE);
66 p = (smb_privset_t *)(uintptr_t)*privs;
67 cnt = p->priv_cnt;
70 len = sizeof (smb_privset_t)
71 - sizeof (smb_luid_attrs_t)
72 + (cnt * sizeof (smb_luid_attrs_t));
74 if (!xdr_pointer(xdrs, privs, len, (xdrproc_t)smb_privset_xdr))
75 return (FALSE);
77 return (TRUE);
80 static bool_t
81 smb_id_xdr(XDR *xdrs, smb_id_t *objp)
83 uint8_t len;
85 if ((xdrs->x_op == XDR_ENCODE) || (xdrs->x_op == XDR_FREE))
86 len = smb_sid_len(objp->i_sid);
88 if (!xdr_uint32_t(xdrs, &objp->i_attrs))
89 return (FALSE);
91 if (!xdr_uint8_t(xdrs, &len))
92 return (FALSE);
94 if (!xdr_pointer(xdrs, (char **)&objp->i_sid, len,
95 (xdrproc_t)smb_sid_xdr))
96 return (FALSE);
98 if (!xdr_uint32_t(xdrs, (uint32_t *)&objp->i_id))
99 return (FALSE);
101 return (TRUE);
104 static bool_t
105 smb_ids_xdr(XDR *xdrs, smb_ids_t *objp)
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);
111 return (TRUE);
114 static bool_t
115 smb_posix_grps_xdr(XDR *xdrs, smb_posix_grps_t *objp)
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);
125 static bool_t
126 smb_posix_grps_helper_xdr(XDR *xdrs, char **identity)
128 uint32_t pos, len;
129 uint32_t cnt;
130 bool_t rc;
132 if (xdrs->x_op == XDR_DECODE) {
133 pos = xdr_getpos(xdrs);
135 if (!xdr_bool(xdrs, &rc))
136 return (FALSE);
138 if (!xdr_uint32_t(xdrs, &cnt))
139 return (FALSE);
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;
150 len = SMB_POSIX_GRPS_SIZE(cnt);
152 if (!xdr_pointer(xdrs, identity, len, (xdrproc_t)smb_posix_grps_xdr))
153 return (FALSE);
154 return (TRUE);
157 static bool_t
158 smb_session_key_xdr(XDR *xdrs, smb_session_key_t *objp)
160 if (!xdr_vector(xdrs, (char *)objp->data, 16,
161 sizeof (uint8_t), (xdrproc_t)xdr_uint8_t))
162 return (FALSE);
163 return (TRUE);
166 bool_t
167 smb_logon_xdr(XDR *xdrs, smb_logon_t *objp)
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);
210 static bool_t
211 smb_sid_xdr(XDR *xdrs, smb_sid_t *objp)
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);
226 static bool_t
227 smb_luid_xdr(XDR *xdrs, smb_luid_t *objp)
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);
236 static bool_t
237 smb_luid_attrs_xdr(XDR *xdrs, smb_luid_attrs_t *objp)
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);
246 static bool_t
247 smb_privset_xdr(XDR *xdrs, smb_privset_t *objp)
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);
260 bool_t
261 smb_token_xdr(XDR *xdrs, smb_token_t *objp)
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);