xref: /illumos-gate/usr/src/uts/common/smbsrv/smb_xdr.h (revision d8109ce4330e1b8ad6c29f9fccacec969066bb9d)
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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
24  */
25 
26 #ifndef	_SMBSRV_SMB_XDR_H
27 #define	_SMBSRV_SMB_XDR_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <rpc/xdr.h>
34 #include <sys/param.h>
35 #include <sys/avl.h>
36 #include <sys/list.h>
37 #include <smb/wintypes.h>
38 #include <smbsrv/smb_sid.h>
39 #include <smbsrv/smbinfo.h>
40 #include <smbsrv/smb_ioctl.h>
41 #include <smbsrv/smb_sid.h>
42 #include <smbsrv/smb_share.h>
43 #include <smbsrv/smb_dfs.h>
44 
45 #if defined(_KERNEL) || defined(_FAKE_KERNEL)
46 #include <sys/sysmacros.h>
47 #define	xdr_int8_t	xdr_char
48 #define	xdr_uint8_t	xdr_u_char
49 #define	xdr_int16_t	xdr_short
50 #define	xdr_uint16_t	xdr_u_short
51 #else /* _KERNEL */
52 #include <stddef.h>	/* offsetof */
53 #endif /* _KERNEL */
54 
55 /*
56  * null-terminated string
57  * See also: smb_string_xdr()
58  */
59 typedef struct smb_string {
60 	char *buf;
61 } smb_string_t;
62 
63 struct smb_buf32;
64 
65 /*
66  * Initial message on server named pipes.
67  * Followed by smb_netuserinfo
68  */
69 typedef struct smb_pipehdr {
70 	uint32_t ph_magic;
71 	uint32_t ph_uilen;
72 } smb_pipehdr_t;
73 
74 #define	SMB_PIPE_HDR_MAGIC	0x50495045	/* PIPE */
75 
76 /*
77  * Maximum message size for SMB named pipes.
78  * Should be less than PIPE_BUF (5120).
79  * Use the same value Windows does.
80  */
81 #define	SMB_PIPE_MAX_MSGSIZE	4280
82 
83 /*
84  * Door up-call stuff shared with smbd
85  */
86 
87 #define	SMB_DOOR_HDR_MAGIC	0x444F4F52	/* DOOR */
88 
89 /*
90  * Door header flags.
91  */
92 #define	SMB_DF_ASYNC		0x00000001	/* Asynchronous call */
93 #define	SMB_DF_SYSSPACE		0x00000002	/* Called from the kernel */
94 #define	SMB_DF_USERSPACE	0x00000004	/* Called from user space */
95 #define	SMB_DF_FAKE_KERNEL	0x00000008	/* Called from fake kernel */
96 
97 /*
98  * Header for door calls.  The op codes and return codes are defined
99  * in smb_door.h.  The header is here to make it available to XDR.
100  *
101  * fid		For opipe: the pipe identifier.
102  * op		The door operation being invoked.
103  * txid		Unique transaction id for the current door call.
104  * datalen	Bytes of data following the header (excludes the header).
105  * resid	For opipe: the number of bytes remaining in the server.
106  * door_rc	Return code provided by the door server.
107  * status	A pass-through status provided by the door operation.
108  *
109  * See also: smb_doorhdr_xdr()
110  */
111 typedef struct smb_doorhdr {
112 	uint32_t dh_magic;
113 	uint32_t dh_flags;
114 	uint32_t dh_fid;
115 	uint32_t dh_op;
116 	uint32_t dh_txid;
117 	uint32_t dh_datalen;
118 	uint32_t dh_resid;
119 	uint32_t dh_door_rc;
120 	uint32_t dh_status;
121 } smb_doorhdr_t;
122 
123 /*
124  * Information about the client of a named pipe, provided by smbsrv
125  * to the server side of the named pipe (the RPC service).
126  * See also: smb_netuserinfo_xdr()
127  */
128 typedef struct smb_netuserinfo {
129 	uint64_t	ui_session_id;
130 	uint16_t	ui_domain_len;
131 	char		*ui_domain;
132 	uint16_t	ui_account_len;
133 	char		*ui_account;
134 	uid_t		ui_posix_uid;
135 	uint16_t	ui_workstation_len;
136 	char		*ui_workstation;
137 	smb_inaddr_t	ui_ipaddr;
138 	int32_t		ui_native_os;
139 	int64_t		ui_logon_time;
140 	uint32_t	ui_numopens;
141 	uint32_t	ui_flags;
142 } smb_netuserinfo_t;
143 
144 typedef struct smb_opennum {
145 	uint32_t	open_users;
146 	uint32_t	open_trees;
147 	uint32_t	open_files;
148 	uint32_t	qualtype;
149 	char		qualifier[MAXNAMELEN];
150 } smb_opennum_t;
151 
152 /*
153  * SMB (internal) representation of a tree connection (etc.)
154  * See also: smb_netconnectinfo_xdr()
155  */
156 typedef struct smb_netconnectinfo {
157 	uint32_t	ci_id;
158 	uint32_t	ci_type;
159 	uint32_t	ci_numopens;
160 	uint32_t	ci_numusers;
161 	uint32_t	ci_time;
162 	uint32_t	ci_namelen;
163 	uint32_t	ci_sharelen;
164 	char		*ci_username;
165 	char		*ci_share;
166 } smb_netconnectinfo_t;
167 
168 /*
169  * SMB (internal) representation of an open file.
170  * See also: smb_netfileinfo_xdr()
171  */
172 typedef struct smb_netfileinfo {
173 	uint16_t	fi_fid;
174 	uint32_t	fi_uniqid;
175 	uint32_t	fi_permissions;
176 	uint32_t	fi_numlocks;
177 	uint32_t	fi_pathlen;
178 	uint32_t	fi_namelen;
179 	char		*fi_path;
180 	char		*fi_username;
181 } smb_netfileinfo_t;
182 
183 typedef struct smb_netsvcitem {
184 	list_node_t	nsi_lnd;
185 	union {
186 		smb_netuserinfo_t	nsi_user;
187 		smb_netconnectinfo_t	nsi_tree;
188 		smb_netfileinfo_t	nsi_ofile;
189 	} nsi_un;
190 } smb_netsvcitem_t;
191 
192 typedef struct smb_netsvc {
193 	list_t			ns_list;
194 	smb_netsvcitem_t	*ns_items;
195 	smb_ioc_svcenum_t	*ns_ioc;
196 	uint32_t		ns_ioclen;
197 } smb_netsvc_t;
198 
199 
200 bool_t smb_buf32_xdr(XDR *, struct smb_buf32 *);
201 bool_t smb_string_xdr(XDR *, smb_string_t *);
202 bool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *);
203 
204 const char *smb_doorhdr_opname(uint32_t);
205 int smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t);
206 int smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t);
207 bool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp);
208 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
209 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
210 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *);
211 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
212     uint_t *);
213 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
214     uint_t *);
215 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *);
216 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
217 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
218 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *);
219 
220 typedef uint16_t sid_type_t;
221 
222 typedef struct lsa_account {
223 	ntstatus_t	a_status;
224 	sid_type_t	a_sidtype;
225 	char		a_domain[MAXNAMELEN];
226 	char		a_name[MAXNAMELEN];
227 	char		a_sid[SMB_SID_STRSZ];
228 } lsa_account_t;
229 
230 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t);
231 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t);
232 bool_t lsa_account_xdr(XDR *, lsa_account_t *);
233 
234 /*
235  * VSS Door Structures
236  */
237 #define	SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss")
238 
239 /*
240  * Args for enumerating "previous versions".
241  * See also: smb_gmttoken_query_xdr()
242  */
243 typedef struct smb_gmttoken_query {
244 	uint32_t	gtq_count;
245 	char		*gtq_path;
246 } smb_gmttoken_query_t;
247 
248 /*
249  * Part of response for enumerating "previous versions".
250  * See also: smb_gmttoken_xdr()
251  */
252 typedef char *smb_gmttoken_t;
253 
254 /*
255  * Response for enumerating "previous versions".
256  * See also: smb_gmttoken_response_xdr()
257  */
258 typedef struct smb_gmttoken_response {
259 	uint32_t gtr_count;
260 	struct {
261 		uint_t		gtr_gmttokens_len;
262 		smb_gmttoken_t	*gtr_gmttokens_val;
263 	} gtr_gmttokens;
264 } smb_gmttoken_response_t;
265 
266 /*
267  * Args to lookup "previous versions" during open.
268  * See also: smb_gmttoken_snapname_xdr()
269  */
270 typedef struct smb_gmttoken_snapname {
271 	char	*gts_path;
272 	char	*gts_gmttoken;
273 	uint64_t gts_toktime; /* seconds */
274 } smb_gmttoken_snapname_t;
275 
276 bool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *);
277 bool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *);
278 bool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *);
279 
280 /*
281  * User and Group Quotas
282  *
283  * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean
284  * No Limit. This maps to 0 (none) on ZFS.
285  */
286 #define	SMB_QUOTA_UNLIMITED		0xFFFFFFFFFFFFFFFF
287 
288 /*
289  * SMB (internal) representation of a quota response
290  * See also: smb_quota_xdr()
291  */
292 typedef struct smb_quota {
293 	list_node_t q_list_node;
294 	char q_sidstr[SMB_SID_STRSZ];
295 	uint32_t q_sidtype;
296 	uint64_t q_used;
297 	uint64_t q_thresh;
298 	uint64_t q_limit;
299 	avl_node_t q_avl_node;
300 } smb_quota_t;
301 
302 /*
303  * Part of a quota response
304  * See also: smb_quota_sid_xdr()
305  */
306 typedef struct smb_quota_sid {
307 	list_node_t qs_list_node;
308 	char qs_sidstr[SMB_SID_STRSZ];
309 } smb_quota_sid_t;
310 
311 typedef enum {
312 	SMB_QUOTA_QUERY_INVALID_OP,
313 	SMB_QUOTA_QUERY_SIDLIST,
314 	SMB_QUOTA_QUERY_STARTSID,
315 	SMB_QUOTA_QUERY_ALL
316 } smb_quota_query_op_t;
317 
318 /*
319  * SMB (internal) form of a quota lookup
320  * See also: smb_quota_query_xdr()
321  */
322 typedef struct smb_quota_query {
323 	char *qq_root_path;
324 	uint32_t qq_query_op;	/* smb_quota_query_op_t */
325 	bool_t qq_single;
326 	bool_t qq_restart;
327 	uint32_t qq_max_quota;
328 	list_t qq_sid_list;	/* list of smb_quota_sid_t */
329 } smb_quota_query_t;
330 
331 /*
332  * The get quota response (list of quota records)
333  * See also: smb_quota_response_xdr()
334  */
335 typedef struct smb_quota_response {
336 	uint32_t qr_status;
337 	list_t qr_quota_list;	/* list of smb_quota_t */
338 } smb_quota_response_t;
339 
340 /*
341  * The set quota request (list of quota records)
342  * See also: smb_quota_set_xdr()
343  */
344 typedef struct smb_quota_set {
345 	char *qs_root_path;
346 	list_t qs_quota_list;	/* list of smb_quota_t */
347 } smb_quota_set_t;
348 
349 bool_t smb_quota_query_xdr(XDR *, smb_quota_query_t *);
350 bool_t smb_quota_response_xdr(XDR *, smb_quota_response_t *);
351 bool_t smb_quota_set_xdr(XDR *, smb_quota_set_t *);
352 
353 typedef struct dfs_referral_query {
354 	dfs_reftype_t	rq_type;
355 	char 		*rq_path;
356 } dfs_referral_query_t;
357 
358 typedef struct dfs_referral_response {
359 	dfs_info_t	rp_referrals;
360 	uint32_t	rp_status;
361 } dfs_referral_response_t;
362 
363 bool_t dfs_referral_query_xdr(XDR *, dfs_referral_query_t *);
364 bool_t dfs_referral_response_xdr(XDR *, dfs_referral_response_t *);
365 
366 typedef struct smb_shr_hostaccess_query {
367 	char		*shq_none;
368 	char		*shq_ro;
369 	char		*shq_rw;
370 	uint32_t	shq_flag;
371 	smb_inaddr_t	shq_ipaddr;
372 } smb_shr_hostaccess_query_t;
373 
374 bool_t smb_shr_hostaccess_query_xdr(XDR *, smb_shr_hostaccess_query_t *);
375 bool_t smb_shr_execinfo_xdr(XDR *, smb_shr_execinfo_t *);
376 
377 #ifdef	__cplusplus
378 }
379 #endif
380 
381 #endif	/* _SMBSRV_SMB_XDR_H */
382