xref: /titanic_44/usr/src/uts/common/smbsrv/smb_xdr.h (revision a31148363f598def767ac48c5d82e1572e44b935)
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 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
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 <smbsrv/wintypes.h>
37 #include <smbsrv/smb_sid.h>
38 #include <smbsrv/smbinfo.h>
39 #include <smbsrv/smb_ioctl.h>
40 #include <smbsrv/smb_sid.h>
41 #include <smbsrv/wintypes.h>
42 #include <smbsrv/smb_dfs.h>
43 
44 typedef struct smb_dr_kshare {
45 	int32_t k_op;
46 	char *k_path;
47 	char *k_sharename;
48 } smb_dr_kshare_t;
49 
50 #ifdef _KERNEL
51 #define	xdr_int8_t	xdr_char
52 #define	xdr_uint8_t	xdr_u_char
53 #define	xdr_int16_t	xdr_short
54 #define	xdr_uint16_t	xdr_u_short
55 
56 smb_dr_kshare_t *smb_share_mkabsolute(uint8_t *buf, uint32_t len);
57 #else
58 uint8_t *smb_kshare_mkselfrel(smb_dr_kshare_t *kshare, uint32_t *len);
59 #endif /* _KERNEL */
60 
61 /* null-terminated string */
62 typedef struct smb_string {
63 	char *buf;
64 } smb_string_t;
65 
66 /* 32-bit opaque buffer (non-null terminated strings) */
67 typedef struct smb_buf32 {
68 	uint32_t	len;
69 	uint8_t		*val;
70 } smb_buf32_t;
71 
72 #define	SMB_OPIPE_HDR_MAGIC	0x4F484452	/* OHDR */
73 #define	SMB_OPIPE_DOOR_BUFSIZE	(30 * 1024)
74 
75 /*
76  * Door operations for opipes.
77  */
78 typedef enum {
79 	SMB_OPIPE_NULL = 0,
80 	SMB_OPIPE_LOOKUP,
81 	SMB_OPIPE_OPEN,
82 	SMB_OPIPE_CLOSE,
83 	SMB_OPIPE_READ,
84 	SMB_OPIPE_WRITE,
85 	SMB_OPIPE_EXEC
86 } smb_opipe_op_t;
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 
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 typedef struct smb_doorhdr {
110 	uint32_t dh_magic;
111 	uint32_t dh_flags;
112 	uint32_t dh_fid;
113 	uint32_t dh_op;
114 	uint32_t dh_txid;
115 	uint32_t dh_datalen;
116 	uint32_t dh_resid;
117 	uint32_t dh_door_rc;
118 	uint32_t dh_status;
119 } smb_doorhdr_t;
120 
121 typedef struct smb_netuserinfo {
122 	uint64_t	ui_session_id;
123 	uint16_t	ui_uid;
124 	uint16_t	ui_domain_len;
125 	char		*ui_domain;
126 	uint16_t	ui_account_len;
127 	char		*ui_account;
128 	uint16_t	ui_workstation_len;
129 	char		*ui_workstation;
130 	smb_inaddr_t	ui_ipaddr;
131 	int32_t		ui_native_os;
132 	int64_t		ui_logon_time;
133 	uint32_t	ui_numopens;
134 	uint32_t	ui_flags;
135 } smb_netuserinfo_t;
136 
137 typedef struct smb_opennum {
138 	uint32_t	open_users;
139 	uint32_t	open_trees;
140 	uint32_t	open_files;
141 	uint32_t	qualtype;
142 	char		qualifier[MAXNAMELEN];
143 } smb_opennum_t;
144 
145 typedef struct smb_netconnectinfo {
146 	uint32_t	ci_id;
147 	uint32_t	ci_type;
148 	uint32_t	ci_numopens;
149 	uint32_t	ci_numusers;
150 	uint32_t	ci_time;
151 	uint32_t	ci_namelen;
152 	uint32_t	ci_sharelen;
153 	char		*ci_username;
154 	char		*ci_share;
155 } smb_netconnectinfo_t;
156 
157 typedef struct smb_netfileinfo {
158 	uint16_t	fi_fid;
159 	uint32_t	fi_uniqid;
160 	uint32_t	fi_permissions;
161 	uint32_t	fi_numlocks;
162 	uint32_t	fi_pathlen;
163 	uint32_t	fi_namelen;
164 	char		*fi_path;
165 	char		*fi_username;
166 } smb_netfileinfo_t;
167 
168 typedef struct smb_netsvcitem {
169 	list_node_t	nsi_lnd;
170 	union {
171 		smb_netuserinfo_t	nsi_user;
172 		smb_netconnectinfo_t	nsi_tree;
173 		smb_netfileinfo_t	nsi_ofile;
174 	} nsi_un;
175 } smb_netsvcitem_t;
176 
177 typedef struct smb_netsvc {
178 	list_t			ns_list;
179 	smb_netsvcitem_t	*ns_items;
180 	smb_ioc_svcenum_t	*ns_ioc;
181 	uint32_t		ns_ioclen;
182 } smb_netsvc_t;
183 
184 
185 bool_t smb_buf32_xdr(XDR *, smb_buf32_t *);
186 bool_t smb_string_xdr(XDR *, smb_string_t *);
187 bool_t smb_dr_kshare_xdr(XDR *, smb_dr_kshare_t *);
188 bool_t smb_inaddr_xdr(XDR *, smb_inaddr_t *);
189 
190 const char *smb_doorhdr_opname(uint32_t);
191 int smb_doorhdr_encode(smb_doorhdr_t *, uint8_t *, uint32_t);
192 int smb_doorhdr_decode(smb_doorhdr_t *, uint8_t *, uint32_t);
193 bool_t smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp);
194 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
195 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
196 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *);
197 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
198     uint_t *);
199 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
200     uint_t *);
201 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *);
202 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
203 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
204 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *);
205 
206 typedef uint16_t sid_type_t;
207 
208 typedef struct lsa_account {
209 	ntstatus_t	a_status;
210 	sid_type_t	a_sidtype;
211 	char		a_domain[MAXNAMELEN];
212 	char		a_name[MAXNAMELEN];
213 	char		a_sid[SMB_SID_STRSZ];
214 } lsa_account_t;
215 
216 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t);
217 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t);
218 bool_t lsa_account_xdr(XDR *, lsa_account_t *);
219 
220 /*
221  * VSS Door Structures
222  */
223 #define	SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss")
224 
225 typedef struct smb_gmttoken_query {
226 	uint32_t	gtq_count;
227 	char		*gtq_path;
228 } smb_gmttoken_query_t;
229 
230 typedef char *smb_gmttoken_t;
231 
232 typedef struct smb_gmttoken_response {
233 	uint32_t gtr_count;
234 	struct {
235 		uint_t		gtr_gmttokens_len;
236 		smb_gmttoken_t	*gtr_gmttokens_val;
237 	} gtr_gmttokens;
238 } smb_gmttoken_response_t;
239 
240 typedef struct smb_gmttoken_snapname {
241 	char	*gts_path;
242 	char	*gts_gmttoken;
243 } smb_gmttoken_snapname_t;
244 
245 bool_t smb_gmttoken_query_xdr(XDR *, smb_gmttoken_query_t *);
246 bool_t smb_gmttoken_response_xdr(XDR *, smb_gmttoken_response_t *);
247 bool_t smb_gmttoken_snapname_xdr(XDR *, smb_gmttoken_snapname_t *);
248 
249 /*
250  * User and Group Quotas
251  *
252  * SMB User and Group quota values of SMB_QUOTA_UNLIMITED mean
253  * No Limit. This maps to 0 (none) on ZFS.
254  */
255 #define	SMB_QUOTA_UNLIMITED		0xFFFFFFFFFFFFFFFF
256 
257 typedef struct smb_quota {
258 	list_node_t q_list_node;
259 	char q_sidstr[SMB_SID_STRSZ];
260 	uint32_t q_sidtype;
261 	uint64_t q_used;
262 	uint64_t q_thresh;
263 	uint64_t q_limit;
264 	avl_node_t q_avl_node;
265 } smb_quota_t;
266 
267 typedef struct smb_quota_sid {
268 	list_node_t qs_list_node;
269 	char qs_sidstr[SMB_SID_STRSZ];
270 } smb_quota_sid_t;
271 
272 typedef enum {
273 	SMB_QUOTA_QUERY_INVALID_OP,
274 	SMB_QUOTA_QUERY_SIDLIST,
275 	SMB_QUOTA_QUERY_STARTSID,
276 	SMB_QUOTA_QUERY_ALL
277 } smb_quota_query_op_t;
278 
279 typedef struct smb_quota_query {
280 	char *qq_root_path;
281 	uint32_t qq_query_op;	/* smb_quota_query_op_t */
282 	bool_t qq_single;
283 	bool_t qq_restart;
284 	uint32_t qq_max_quota;
285 	list_t qq_sid_list;	/* list of smb_quota_sid_t */
286 } smb_quota_query_t;
287 
288 typedef struct smb_quota_response {
289 	uint32_t qr_status;
290 	list_t qr_quota_list;	/* list of smb_quota_t */
291 } smb_quota_response_t;
292 
293 typedef struct smb_quota_set {
294 	char *qs_root_path;
295 	list_t qs_quota_list;	/* list of smb_quota_t */
296 } smb_quota_set_t;
297 
298 bool_t smb_quota_query_xdr(XDR *, smb_quota_query_t *);
299 bool_t smb_quota_response_xdr(XDR *, smb_quota_response_t *);
300 bool_t smb_quota_set_xdr(XDR *, smb_quota_set_t *);
301 
302 typedef struct dfs_referral_query {
303 	dfs_reftype_t	rq_type;
304 	char 		*rq_path;
305 } dfs_referral_query_t;
306 
307 typedef struct dfs_referral_response {
308 	dfs_info_t	rp_referrals;
309 	uint32_t	rp_status;
310 } dfs_referral_response_t;
311 
312 bool_t dfs_referral_query_xdr(XDR *, dfs_referral_query_t *);
313 bool_t dfs_referral_response_xdr(XDR *, dfs_referral_response_t *);
314 
315 #ifdef	__cplusplus
316 }
317 #endif
318 
319 #endif	/* _SMBSRV_SMB_XDR_H */
320