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