xref: /titanic_41/usr/src/uts/common/smbsrv/smb_xdr.h (revision 82629e3015252bf18319ba3815c773df23e21436)
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 2009 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 <smbsrv/wintypes.h>
36 #include <smbsrv/smb_sid.h>
37 #include <smbsrv/smbinfo.h>
38 #include <smbsrv/smb_ioctl.h>
39 
40 typedef struct smb_dr_kshare {
41 	int32_t k_op;
42 	char *k_path;
43 	char *k_sharename;
44 } smb_dr_kshare_t;
45 
46 #ifdef _KERNEL
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 
52 smb_dr_kshare_t *smb_share_mkabsolute(uint8_t *buf, uint32_t len);
53 #else
54 uint8_t *smb_kshare_mkselfrel(smb_dr_kshare_t *kshare, uint32_t *len);
55 #endif /* _KERNEL */
56 
57 /* null-terminated string buffer */
58 typedef struct smb_dr_string {
59 	char *buf;
60 } smb_dr_string_t;
61 
62 /* byte buffer (non-null terminated) */
63 typedef struct smb_dr_bytes {
64 	uint32_t bytes_len;
65 	uint8_t *bytes_val;
66 } smb_dr_bytes_t;
67 
68 #define	SMB_OPIPE_HDR_MAGIC	0x4F484452	/* OHDR */
69 #define	SMB_OPIPE_DOOR_BUFSIZE	(30 * 1024)
70 
71 /*
72  * Door operations for opipes.
73  */
74 typedef enum {
75 	SMB_OPIPE_NULL = 0,
76 	SMB_OPIPE_LOOKUP,
77 	SMB_OPIPE_OPEN,
78 	SMB_OPIPE_CLOSE,
79 	SMB_OPIPE_READ,
80 	SMB_OPIPE_WRITE,
81 	SMB_OPIPE_STAT
82 } smb_opipe_op_t;
83 
84 typedef struct smb_opipe_hdr {
85 	uint32_t oh_magic;
86 	uint32_t oh_fid;
87 	uint32_t oh_op;
88 	uint32_t oh_datalen;
89 	uint32_t oh_resid;
90 	uint32_t oh_status;
91 } smb_opipe_hdr_t;
92 
93 typedef struct smb_netuserinfo {
94 	uint64_t	ui_session_id;
95 	uint16_t	ui_uid;
96 	uint16_t	ui_domain_len;
97 	char		*ui_domain;
98 	uint16_t	ui_account_len;
99 	char		*ui_account;
100 	uint16_t	ui_workstation_len;
101 	char		*ui_workstation;
102 	smb_inaddr_t	ui_ipaddr;
103 	int32_t		ui_native_os;
104 	int64_t		ui_logon_time;
105 	uint32_t	ui_numopens;
106 	uint32_t	ui_flags;
107 } smb_netuserinfo_t;
108 
109 typedef struct smb_opennum {
110 	uint32_t	open_users;
111 	uint32_t	open_trees;
112 	uint32_t	open_files;
113 	uint32_t	qualtype;
114 	char		qualifier[MAXNAMELEN];
115 } smb_opennum_t;
116 
117 typedef struct smb_netconnectinfo {
118 	uint32_t	ci_id;
119 	uint32_t	ci_type;
120 	uint32_t	ci_numopens;
121 	uint32_t	ci_numusers;
122 	uint32_t	ci_time;
123 	uint32_t	ci_namelen;
124 	uint32_t	ci_sharelen;
125 	char		*ci_username;
126 	char		*ci_share;
127 } smb_netconnectinfo_t;
128 
129 typedef struct smb_netfileinfo {
130 	uint16_t	fi_fid;
131 	uint32_t	fi_uniqid;
132 	uint32_t	fi_permissions;
133 	uint32_t	fi_numlocks;
134 	uint32_t	fi_pathlen;
135 	uint32_t	fi_namelen;
136 	char		*fi_path;
137 	char		*fi_username;
138 } smb_netfileinfo_t;
139 
140 typedef struct smb_netsvcitem {
141 	list_node_t	nsi_lnd;
142 	union {
143 		smb_netuserinfo_t	nsi_user;
144 		smb_netconnectinfo_t	nsi_tree;
145 		smb_netfileinfo_t	nsi_ofile;
146 	} nsi_un;
147 } smb_netsvcitem_t;
148 
149 typedef struct smb_netsvc {
150 	list_t			ns_list;
151 	smb_netsvcitem_t	*ns_items;
152 	smb_ioc_svcenum_t	*ns_ioc;
153 	uint32_t		ns_ioclen;
154 } smb_netsvc_t;
155 
156 /* xdr routines for common door arguments/results */
157 extern bool_t xdr_smb_dr_string_t(XDR *, smb_dr_string_t *);
158 extern bool_t xdr_smb_dr_bytes_t(XDR *, smb_dr_bytes_t *);
159 extern bool_t xdr_smb_dr_kshare_t(XDR *, smb_dr_kshare_t *);
160 extern bool_t xdr_smb_inaddr_t(XDR *, smb_inaddr_t *);
161 
162 int smb_opipe_hdr_encode(smb_opipe_hdr_t *, uint8_t *, uint32_t);
163 int smb_opipe_hdr_decode(smb_opipe_hdr_t *, uint8_t *, uint32_t);
164 bool_t smb_opipe_hdr_xdr(XDR *xdrs, smb_opipe_hdr_t *objp);
165 int smb_netuserinfo_encode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
166 int smb_netuserinfo_decode(smb_netuserinfo_t *, uint8_t *, uint32_t, uint_t *);
167 bool_t smb_netuserinfo_xdr(XDR *, smb_netuserinfo_t *);
168 int smb_netconnectinfo_encode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
169     uint_t *);
170 int smb_netconnectinfo_decode(smb_netconnectinfo_t *, uint8_t *, uint32_t,
171     uint_t *);
172 bool_t smb_netconnectinfo_xdr(XDR *, smb_netconnectinfo_t *);
173 int smb_netfileinfo_encode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
174 int smb_netfileinfo_decode(smb_netfileinfo_t *, uint8_t *, uint32_t, uint_t *);
175 bool_t smb_netfileinfo_xdr(XDR *, smb_netfileinfo_t *);
176 
177 typedef uint16_t sid_type_t;
178 
179 typedef struct lsa_account {
180 	ntstatus_t	a_status;
181 	sid_type_t	a_sidtype;
182 	char		a_domain[MAXNAMELEN];
183 	char		a_name[MAXNAMELEN];
184 	char		a_sid[SMB_SID_STRSZ];
185 } lsa_account_t;
186 
187 int lsa_account_encode(lsa_account_t *, uint8_t *, uint32_t);
188 int lsa_account_decode(lsa_account_t *, uint8_t *, uint32_t);
189 bool_t lsa_account_xdr(XDR *, lsa_account_t *);
190 
191 /*
192  * VSS Door Structures
193  */
194 #define	SMB_VSS_GMT_SIZE sizeof ("@GMT-yyyy.mm.dd-hh.mm.ss")
195 
196 typedef struct smb_dr_get_gmttokens {
197 	uint32_t gg_count;
198 	char *gg_path;
199 } smb_dr_get_gmttokens_t;
200 
201 typedef char *gmttoken;
202 
203 typedef struct smb_dr_return_gmttokens {
204 	uint32_t rg_count;
205 	struct {
206 		uint_t rg_gmttokens_len;
207 		gmttoken *rg_gmttokens_val;
208 	} rg_gmttokens;
209 } smb_dr_return_gmttokens_t;
210 
211 typedef struct smb_dr_map_gmttoken {
212 	char *mg_path;
213 	char *mg_gmttoken;
214 } smb_dr_map_gmttoken_t;
215 
216 extern bool_t xdr_smb_dr_get_gmttokens_t(XDR *, smb_dr_get_gmttokens_t *);
217 extern bool_t xdr_gmttoken(XDR *, gmttoken *);
218 extern bool_t xdr_smb_dr_return_gmttokens_t(XDR *xdrs,
219     smb_dr_return_gmttokens_t *);
220 extern bool_t xdr_smb_dr_map_gmttoken_t(XDR *, smb_dr_map_gmttoken_t *);
221 
222 #ifdef	__cplusplus
223 }
224 #endif
225 
226 #endif	/* _SMBSRV_SMB_XDR_H */
227