xref: /titanic_52/usr/src/uts/common/smbsrv/smb_xdr.h (revision fca4268092e9961ebb9b5e0098dcebc545023586)
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 <smbsrv/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 #include <smbsrv/wintypes.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 /* null-terminated string */
57 typedef struct smb_string {
58 	char *buf;
59 } smb_string_t;
60 
61 struct smb_buf32;
62 
63 /*
64  * Initial message on server named pipes.
65  * Followed by smb_netuserinfo
66  */
67 typedef struct smb_pipehdr {
68 	uint32_t ph_magic;
69 	uint32_t ph_uilen;
70 } smb_pipehdr_t;
71 
72 #define	SMB_PIPE_HDR_MAGIC	0x50495045	/* PIPE */
73 
74 /*
75  * Maximum message size for SMB named pipes.
76  * Should be less than PIPE_BUF (5120).
77  * Use the same value Windows does.
78  */
79 #define	SMB_PIPE_MAX_MSGSIZE	4280
80 
81 /*
82  * Door up-call stuff shared with smbd
83  */
84 
85 #define	SMB_DOOR_HDR_MAGIC	0x444F4F52	/* DOOR */
86 
87 /*
88  * Door header flags.
89  */
90 #define	SMB_DF_ASYNC		0x00000001	/* Asynchronous call */
91 #define	SMB_DF_SYSSPACE		0x00000002	/* Called from the kernel */
92 #define	SMB_DF_USERSPACE	0x00000004	/* Called from user space */
93 #define	SMB_DF_FAKE_KERNEL	0x00000008	/* Called from fake kernel */
94 
95 /*
96  * Header for door calls.  The op codes and return codes are defined
97  * in smb_door.h.  The header is here to make it available to XDR.
98  *
99  * fid		For opipe: the pipe identifier.
100  * op		The door operation being invoked.
101  * txid		Unique transaction id for the current door call.
102  * datalen	Bytes of data following the header (excludes the header).
103  * resid	For opipe: the number of bytes remaining in the server.
104  * door_rc	Return code provided by the door server.
105  * status	A pass-through status provided by the door operation.
106  */
107 typedef struct smb_doorhdr {
108 	uint32_t dh_magic;
109 	uint32_t dh_flags;
110 	uint32_t dh_fid;
111 	uint32_t dh_op;
112 	uint32_t dh_txid;
113 	uint32_t dh_datalen;
114 	uint32_t dh_resid;
115 	uint32_t dh_door_rc;
116 	uint32_t dh_status;
117 } smb_doorhdr_t;
118 
119 typedef struct smb_netuserinfo {
120 	uint64_t	ui_session_id;
121 	uint16_t	ui_smb_uid;
122 	uint16_t	ui_domain_len;
123 	char		*ui_domain;
124 	uint16_t	ui_account_len;
125 	char		*ui_account;
126 	uid_t		ui_posix_uid;
127 	uint16_t	ui_workstation_len;
128 	char		*ui_workstation;
129 	smb_inaddr_t	ui_ipaddr;
130 	int32_t		ui_native_os;
131 	int64_t		ui_logon_time;
132 	uint32_t	ui_numopens;
133 	uint32_t	ui_flags;
134 } smb_netuserinfo_t;
135 
136 typedef struct smb_opennum {
137 	uint32_t	open_users;
138 	uint32_t	open_trees;
139 	uint32_t	open_files;
140 	uint32_t	qualtype;
141 	char		qualifier[MAXNAMELEN];
142 } smb_opennum_t;
143 
144 typedef struct smb_netconnectinfo {
145 	uint32_t	ci_id;
146 	uint32_t	ci_type;
147 	uint32_t	ci_numopens;
148 	uint32_t	ci_numusers;
149 	uint32_t	ci_time;
150 	uint32_t	ci_namelen;
151 	uint32_t	ci_sharelen;
152 	char		*ci_username;
153 	char		*ci_share;
154 } smb_netconnectinfo_t;
155 
156 typedef struct smb_netfileinfo {
157 	uint16_t	fi_fid;
158 	uint32_t	fi_uniqid;
159 	uint32_t	fi_permissions;
160 	uint32_t	fi_numlocks;
161 	uint32_t	fi_pathlen;
162 	uint32_t	fi_namelen;
163 	char		*fi_path;
164 	char		*fi_username;
165 } smb_netfileinfo_t;
166 
167 typedef struct smb_netsvcitem {
168 	list_node_t	nsi_lnd;
169 	union {
170 		smb_netuserinfo_t	nsi_user;
171 		smb_netconnectinfo_t	nsi_tree;
172 		smb_netfileinfo_t	nsi_ofile;
173 	} nsi_un;
174 } smb_netsvcitem_t;
175 
176 typedef struct smb_netsvc {
177 	list_t			ns_list;
178 	smb_netsvcitem_t	*ns_items;
179 	smb_ioc_svcenum_t	*ns_ioc;
180 	uint32_t		ns_ioclen;
181 } smb_netsvc_t;
182 
183 
184 bool_t smb_buf32_xdr(XDR *, struct smb_buf32 *);
185 bool_t smb_string_xdr(XDR *, smb_string_t *);
186 bool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *);
187 
188 const char *smb_doorhdr_opname(uint32_t);
189 int smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t);
190 int smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t);
191 bool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp);
192 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
193 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
194 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *);
195 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
196     uint_t *);
197 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
198     uint_t *);
199 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *);
200 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
201 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
202 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *);
203 
204 typedef uint16_t sid_type_t;
205 
206 typedef struct lsa_account {
207 	ntstatus_t	a_status;
208 	sid_type_t	a_sidtype;
209 	char		a_domain[MAXNAMELEN];
210 	char		a_name[MAXNAMELEN];
211 	char		a_sid[SMB_SID_STRSZ];
212 } lsa_account_t;
213 
214 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t);
215 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t);
216 bool_t lsa_account_xdr(XDR *, lsa_account_t *);
217 
218 /*
219  * VSS Door Structures
220  */
221 #define	SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss")
222 
223 typedef struct smb_gmttoken_query {
224 	uint32_t	gtq_count;
225 	char		*gtq_path;
226 } smb_gmttoken_query_t;
227 
228 typedef char *smb_gmttoken_t;
229 
230 typedef struct smb_gmttoken_response {
231 	uint32_t gtr_count;
232 	struct {
233 		uint_t		gtr_gmttokens_len;
234 		smb_gmttoken_t	*gtr_gmttokens_val;
235 	} gtr_gmttokens;
236 } smb_gmttoken_response_t;
237 
238 typedef struct smb_gmttoken_snapname {
239 	char	*gts_path;
240 	char	*gts_gmttoken;
241 } smb_gmttoken_snapname_t;
242 
243 bool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *);
244 bool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *);
245 bool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *);
246 
247 /*
248  * User and Group Quotas
249  *
250  * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean
251  * No Limit. This maps to 0 (none) on ZFS.
252  */
253 #define	SMB_QUOTA_UNLIMITED		0xFFFFFFFFFFFFFFFF
254 
255 typedef struct smb_quota {
256 	list_node_t q_list_node;
257 	char q_sidstr[SMB_SID_STRSZ];
258 	uint32_t q_sidtype;
259 	uint64_t q_used;
260 	uint64_t q_thresh;
261 	uint64_t q_limit;
262 	avl_node_t q_avl_node;
263 } smb_quota_t;
264 
265 typedef struct smb_quota_sid {
266 	list_node_t qs_list_node;
267 	char qs_sidstr[SMB_SID_STRSZ];
268 } smb_quota_sid_t;
269 
270 typedef enum {
271 	SMB_QUOTA_QUERY_INVALID_OP,
272 	SMB_QUOTA_QUERY_SIDLIST,
273 	SMB_QUOTA_QUERY_STARTSID,
274 	SMB_QUOTA_QUERY_ALL
275 } smb_quota_query_op_t;
276 
277 typedef struct smb_quota_query {
278 	char *qq_root_path;
279 	uint32_t qq_query_op;	/* smb_quota_query_op_t */
280 	bool_t qq_single;
281 	bool_t qq_restart;
282 	uint32_t qq_max_quota;
283 	list_t qq_sid_list;	/* list of smb_quota_sid_t */
284 } smb_quota_query_t;
285 
286 typedef struct smb_quota_response {
287 	uint32_t qr_status;
288 	list_t qr_quota_list;	/* list of smb_quota_t */
289 } smb_quota_response_t;
290 
291 typedef struct smb_quota_set {
292 	char *qs_root_path;
293 	list_t qs_quota_list;	/* list of smb_quota_t */
294 } smb_quota_set_t;
295 
296 bool_t smb_quota_query_xdr(XDR *, smb_quota_query_t *);
297 bool_t smb_quota_response_xdr(XDR *, smb_quota_response_t *);
298 bool_t smb_quota_set_xdr(XDR *, smb_quota_set_t *);
299 
300 typedef struct dfs_referral_query {
301 	dfs_reftype_t	rq_type;
302 	char 		*rq_path;
303 } dfs_referral_query_t;
304 
305 typedef struct dfs_referral_response {
306 	dfs_info_t	rp_referrals;
307 	uint32_t	rp_status;
308 } dfs_referral_response_t;
309 
310 bool_t dfs_referral_query_xdr(XDR *, dfs_referral_query_t *);
311 bool_t dfs_referral_response_xdr(XDR *, dfs_referral_response_t *);
312 
313 typedef struct smb_shr_hostaccess_query {
314 	char		*shq_none;
315 	char		*shq_ro;
316 	char		*shq_rw;
317 	uint32_t	shq_flag;
318 	smb_inaddr_t	shq_ipaddr;
319 } smb_shr_hostaccess_query_t;
320 
321 bool_t smb_shr_hostaccess_query_xdr(XDR *, smb_shr_hostaccess_query_t *);
322 bool_t smb_shr_execinfo_xdr(XDR *, smb_shr_execinfo_t *);
323 
324 #ifdef	__cplusplus
325 }
326 #endif
327 
328 #endif	/* _SMBSRV_SMB_XDR_H */
329