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