Commit | Line | Data |
---|---|---|
0626e664 NJ |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* | |
3 | * Copyright (C) 2018 Samsung Electronics Co., Ltd. | |
4 | * | |
5 | * linux-ksmbd-devel@lists.sourceforge.net | |
6 | */ | |
7 | ||
8 | #ifndef _LINUX_KSMBD_SERVER_H | |
9 | #define _LINUX_KSMBD_SERVER_H | |
10 | ||
11 | #include <linux/types.h> | |
12 | ||
8b758859 NJ |
13 | /* |
14 | * This is a userspace ABI to communicate data between ksmbd and user IPC | |
15 | * daemon using netlink. This is added to track and cache user account DB | |
16 | * and share configuration info from userspace. | |
17 | * | |
18 | * - KSMBD_EVENT_HEARTBEAT_REQUEST(ksmbd_heartbeat) | |
19 | * This event is to check whether user IPC daemon is alive. If user IPC | |
20 | * daemon is dead, ksmbd keep existing connection till disconnecting and | |
21 | * new connection will be denied. | |
22 | * | |
23 | * - KSMBD_EVENT_STARTING_UP(ksmbd_startup_request) | |
24 | * This event is to receive the information that initializes the ksmbd | |
25 | * server from the user IPC daemon and to start the server. The global | |
26 | * section parameters are given from smb.conf as initialization | |
27 | * information. | |
28 | * | |
29 | * - KSMBD_EVENT_SHUTTING_DOWN(ksmbd_shutdown_request) | |
30 | * This event is to shutdown ksmbd server. | |
31 | * | |
32 | * - KSMBD_EVENT_LOGIN_REQUEST/RESPONSE(ksmbd_login_request/response) | |
33 | * This event is to get user account info to user IPC daemon. | |
34 | * | |
35 | * - KSMBD_EVENT_SHARE_CONFIG_REQUEST/RESPONSE(ksmbd_share_config_request/response) | |
36 | * This event is to get net share configuration info. | |
37 | * | |
38 | * - KSMBD_EVENT_TREE_CONNECT_REQUEST/RESPONSE(ksmbd_tree_connect_request/response) | |
39 | * This event is to get session and tree connect info. | |
40 | * | |
41 | * - KSMBD_EVENT_TREE_DISCONNECT_REQUEST(ksmbd_tree_disconnect_request) | |
42 | * This event is to send tree disconnect info to user IPC daemon. | |
43 | * | |
44 | * - KSMBD_EVENT_LOGOUT_REQUEST(ksmbd_logout_request) | |
45 | * This event is to send logout request to user IPC daemon. | |
46 | * | |
47 | * - KSMBD_EVENT_RPC_REQUEST/RESPONSE(ksmbd_rpc_command) | |
48 | * This event is to make DCE/RPC request like srvsvc, wkssvc, lsarpc, | |
49 | * samr to be processed in userspace. | |
50 | * | |
51 | * - KSMBD_EVENT_SPNEGO_AUTHEN_REQUEST/RESPONSE(ksmbd_spnego_authen_request/response) | |
52 | * This event is to make kerberos authentication to be processed in | |
53 | * userspace. | |
54 | */ | |
55 | ||
0626e664 NJ |
56 | #define KSMBD_GENL_NAME "SMBD_GENL" |
57 | #define KSMBD_GENL_VERSION 0x01 | |
58 | ||
0626e664 NJ |
59 | #define KSMBD_REQ_MAX_ACCOUNT_NAME_SZ 48 |
60 | #define KSMBD_REQ_MAX_HASH_SZ 18 | |
61 | #define KSMBD_REQ_MAX_SHARE_NAME 64 | |
62 | ||
8b758859 NJ |
63 | /* |
64 | * IPC heartbeat frame to check whether user IPC daemon is alive. | |
65 | */ | |
0626e664 NJ |
66 | struct ksmbd_heartbeat { |
67 | __u32 handle; | |
68 | }; | |
69 | ||
70 | /* | |
71 | * Global config flags. | |
72 | */ | |
73 | #define KSMBD_GLOBAL_FLAG_INVALID (0) | |
64b39f4a | 74 | #define KSMBD_GLOBAL_FLAG_SMB2_LEASES BIT(0) |
c30f4eb8 NJ |
75 | #define KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION BIT(1) |
76 | #define KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL BIT(2) | |
0626e664 | 77 | |
8b758859 NJ |
78 | /* |
79 | * IPC request for ksmbd server startup | |
80 | */ | |
0626e664 | 81 | struct ksmbd_startup_request { |
8b758859 NJ |
82 | __u32 flags; /* Flags for global config */ |
83 | __s32 signing; /* Signing enabled */ | |
84 | __s8 min_prot[16]; /* The minimum SMB protocol version */ | |
85 | __s8 max_prot[16]; /* The maximum SMB protocol version */ | |
0626e664 | 86 | __s8 netbios_name[16]; |
8b758859 NJ |
87 | __s8 work_group[64]; /* Workgroup */ |
88 | __s8 server_string[64]; /* Server string */ | |
89 | __u16 tcp_port; /* tcp port */ | |
90 | __u16 ipc_timeout; /* | |
91 | * specifies the number of seconds | |
92 | * server will wait for the userspace to | |
93 | * reply to heartbeat frames. | |
94 | */ | |
95 | __u32 deadtime; /* Number of minutes of inactivity */ | |
96 | __u32 file_max; /* Limits the maximum number of open files */ | |
97 | __u32 smb2_max_write; /* MAX write size */ | |
98 | __u32 smb2_max_read; /* MAX read size */ | |
99 | __u32 smb2_max_trans; /* MAX trans size */ | |
100 | __u32 share_fake_fscaps; /* | |
101 | * Support some special application that | |
102 | * makes QFSINFO calls to check whether | |
103 | * we set the SPARSE_FILES bit (0x40). | |
104 | */ | |
105 | __u32 sub_auth[3]; /* Subauth value for Security ID */ | |
004443b3 | 106 | __u32 smb2_max_credits; /* MAX credits */ |
41dbda16 | 107 | __u32 reserved[128]; /* Reserved room */ |
8b758859 | 108 | __u32 ifc_list_sz; /* interfaces list size */ |
9f88af04 NJ |
109 | __s8 ____payload[]; |
110 | }; | |
0626e664 NJ |
111 | |
112 | #define KSMBD_STARTUP_CONFIG_INTERFACES(s) ((s)->____payload) | |
113 | ||
8b758859 NJ |
114 | /* |
115 | * IPC request to shutdown ksmbd server. | |
116 | */ | |
0626e664 | 117 | struct ksmbd_shutdown_request { |
41dbda16 | 118 | __s32 reserved[16]; |
9f88af04 | 119 | }; |
0626e664 | 120 | |
8b758859 NJ |
121 | /* |
122 | * IPC user login request. | |
123 | */ | |
0626e664 NJ |
124 | struct ksmbd_login_request { |
125 | __u32 handle; | |
8b758859 | 126 | __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */ |
41dbda16 | 127 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 128 | }; |
0626e664 | 129 | |
8b758859 NJ |
130 | /* |
131 | * IPC user login response. | |
132 | */ | |
0626e664 NJ |
133 | struct ksmbd_login_response { |
134 | __u32 handle; | |
8b758859 NJ |
135 | __u32 gid; /* group id */ |
136 | __u32 uid; /* user id */ | |
137 | __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */ | |
0626e664 | 138 | __u16 status; |
8b758859 NJ |
139 | __u16 hash_sz; /* hash size */ |
140 | __s8 hash[KSMBD_REQ_MAX_HASH_SZ]; /* password hash */ | |
41dbda16 | 141 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 142 | }; |
0626e664 | 143 | |
8b758859 NJ |
144 | /* |
145 | * IPC request to fetch net share config. | |
146 | */ | |
0626e664 NJ |
147 | struct ksmbd_share_config_request { |
148 | __u32 handle; | |
8b758859 | 149 | __s8 share_name[KSMBD_REQ_MAX_SHARE_NAME]; /* share name */ |
41dbda16 | 150 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 151 | }; |
0626e664 | 152 | |
8b758859 NJ |
153 | /* |
154 | * IPC response to the net share config request. | |
155 | */ | |
0626e664 NJ |
156 | struct ksmbd_share_config_response { |
157 | __u32 handle; | |
158 | __u32 flags; | |
159 | __u16 create_mask; | |
160 | __u16 directory_mask; | |
161 | __u16 force_create_mode; | |
162 | __u16 force_directory_mode; | |
163 | __u16 force_uid; | |
164 | __u16 force_gid; | |
41dbda16 | 165 | __u32 reserved[128]; /* Reserved room */ |
0626e664 | 166 | __u32 veto_list_sz; |
9f88af04 NJ |
167 | __s8 ____payload[]; |
168 | }; | |
0626e664 NJ |
169 | |
170 | #define KSMBD_SHARE_CONFIG_VETO_LIST(s) ((s)->____payload) | |
3fbe43c9 NJ |
171 | |
172 | static inline char * | |
173 | ksmbd_share_config_path(struct ksmbd_share_config_response *sc) | |
174 | { | |
175 | char *p = sc->____payload; | |
176 | ||
177 | if (sc->veto_list_sz) | |
178 | p += sc->veto_list_sz + 1; | |
179 | ||
180 | return p; | |
181 | } | |
0626e664 | 182 | |
8b758859 NJ |
183 | /* |
184 | * IPC request for tree connection. This request include session and tree | |
185 | * connect info from client. | |
186 | */ | |
0626e664 NJ |
187 | struct ksmbd_tree_connect_request { |
188 | __u32 handle; | |
189 | __u16 account_flags; | |
190 | __u16 flags; | |
191 | __u64 session_id; | |
192 | __u64 connect_id; | |
193 | __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; | |
194 | __s8 share[KSMBD_REQ_MAX_SHARE_NAME]; | |
195 | __s8 peer_addr[64]; | |
41dbda16 | 196 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 197 | }; |
0626e664 | 198 | |
8b758859 NJ |
199 | /* |
200 | * IPC Response structure for tree connection. | |
201 | */ | |
0626e664 NJ |
202 | struct ksmbd_tree_connect_response { |
203 | __u32 handle; | |
204 | __u16 status; | |
205 | __u16 connection_flags; | |
41dbda16 | 206 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 207 | }; |
0626e664 | 208 | |
8b758859 NJ |
209 | /* |
210 | * IPC Request struture to disconnect tree connection. | |
211 | */ | |
0626e664 | 212 | struct ksmbd_tree_disconnect_request { |
8b758859 NJ |
213 | __u64 session_id; /* session id */ |
214 | __u64 connect_id; /* tree connection id */ | |
41dbda16 | 215 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 216 | }; |
0626e664 | 217 | |
8b758859 NJ |
218 | /* |
219 | * IPC Response structure to logout user account. | |
220 | */ | |
0626e664 | 221 | struct ksmbd_logout_request { |
8b758859 | 222 | __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */ |
621be84a | 223 | __u32 account_flags; |
41dbda16 | 224 | __u32 reserved[16]; /* Reserved room */ |
9f88af04 | 225 | }; |
0626e664 | 226 | |
8b758859 NJ |
227 | /* |
228 | * RPC command structure to send rpc request like srvsvc or wkssvc to | |
229 | * IPC user daemon. | |
230 | */ | |
0626e664 NJ |
231 | struct ksmbd_rpc_command { |
232 | __u32 handle; | |
233 | __u32 flags; | |
234 | __u32 payload_sz; | |
9f88af04 NJ |
235 | __u8 payload[]; |
236 | }; | |
0626e664 | 237 | |
8b758859 NJ |
238 | /* |
239 | * IPC Request Kerberos authentication | |
240 | */ | |
0626e664 NJ |
241 | struct ksmbd_spnego_authen_request { |
242 | __u32 handle; | |
8b758859 | 243 | __u16 spnego_blob_len; /* the length of spnego_blob */ |
5224f790 | 244 | __u8 spnego_blob[]; /* |
8b758859 NJ |
245 | * the GSS token from SecurityBuffer of |
246 | * SMB2 SESSION SETUP request | |
247 | */ | |
9f88af04 | 248 | }; |
0626e664 | 249 | |
8b758859 NJ |
250 | /* |
251 | * Response data which includes the GSS token and the session key generated by | |
252 | * user daemon. | |
253 | */ | |
0626e664 NJ |
254 | struct ksmbd_spnego_authen_response { |
255 | __u32 handle; | |
8b758859 NJ |
256 | struct ksmbd_login_response login_response; /* |
257 | * the login response with | |
258 | * a user identified by the | |
259 | * GSS token from a client | |
260 | */ | |
261 | __u16 session_key_len; /* the length of the session key */ | |
262 | __u16 spnego_blob_len; /* | |
263 | * the length of the GSS token which will be | |
264 | * stored in SecurityBuffer of SMB2 SESSION | |
265 | * SETUP response | |
266 | */ | |
267 | __u8 payload[]; /* session key + AP_REP */ | |
9f88af04 | 268 | }; |
0626e664 NJ |
269 | |
270 | /* | |
271 | * This also used as NETLINK attribute type value. | |
272 | * | |
273 | * NOTE: | |
274 | * Response message type value should be equal to | |
275 | * request message type value + 1. | |
276 | */ | |
277 | enum ksmbd_event { | |
278 | KSMBD_EVENT_UNSPEC = 0, | |
279 | KSMBD_EVENT_HEARTBEAT_REQUEST, | |
280 | ||
281 | KSMBD_EVENT_STARTING_UP, | |
282 | KSMBD_EVENT_SHUTTING_DOWN, | |
283 | ||
284 | KSMBD_EVENT_LOGIN_REQUEST, | |
285 | KSMBD_EVENT_LOGIN_RESPONSE = 5, | |
286 | ||
287 | KSMBD_EVENT_SHARE_CONFIG_REQUEST, | |
288 | KSMBD_EVENT_SHARE_CONFIG_RESPONSE, | |
289 | ||
290 | KSMBD_EVENT_TREE_CONNECT_REQUEST, | |
291 | KSMBD_EVENT_TREE_CONNECT_RESPONSE, | |
292 | ||
293 | KSMBD_EVENT_TREE_DISCONNECT_REQUEST = 10, | |
294 | ||
295 | KSMBD_EVENT_LOGOUT_REQUEST, | |
296 | ||
297 | KSMBD_EVENT_RPC_REQUEST, | |
298 | KSMBD_EVENT_RPC_RESPONSE, | |
299 | ||
300 | KSMBD_EVENT_SPNEGO_AUTHEN_REQUEST, | |
301 | KSMBD_EVENT_SPNEGO_AUTHEN_RESPONSE = 15, | |
302 | ||
303 | KSMBD_EVENT_MAX | |
304 | }; | |
305 | ||
8b758859 NJ |
306 | /* |
307 | * Enumeration for IPC tree connect status. | |
308 | */ | |
0626e664 NJ |
309 | enum KSMBD_TREE_CONN_STATUS { |
310 | KSMBD_TREE_CONN_STATUS_OK = 0, | |
311 | KSMBD_TREE_CONN_STATUS_NOMEM, | |
312 | KSMBD_TREE_CONN_STATUS_NO_SHARE, | |
313 | KSMBD_TREE_CONN_STATUS_NO_USER, | |
314 | KSMBD_TREE_CONN_STATUS_INVALID_USER, | |
315 | KSMBD_TREE_CONN_STATUS_HOST_DENIED = 5, | |
316 | KSMBD_TREE_CONN_STATUS_CONN_EXIST, | |
317 | KSMBD_TREE_CONN_STATUS_TOO_MANY_CONNS, | |
318 | KSMBD_TREE_CONN_STATUS_TOO_MANY_SESSIONS, | |
319 | KSMBD_TREE_CONN_STATUS_ERROR, | |
320 | }; | |
321 | ||
322 | /* | |
323 | * User config flags. | |
324 | */ | |
325 | #define KSMBD_USER_FLAG_INVALID (0) | |
64b39f4a NJ |
326 | #define KSMBD_USER_FLAG_OK BIT(0) |
327 | #define KSMBD_USER_FLAG_BAD_PASSWORD BIT(1) | |
328 | #define KSMBD_USER_FLAG_BAD_UID BIT(2) | |
329 | #define KSMBD_USER_FLAG_BAD_USER BIT(3) | |
330 | #define KSMBD_USER_FLAG_GUEST_ACCOUNT BIT(4) | |
621be84a | 331 | #define KSMBD_USER_FLAG_DELAY_SESSION BIT(5) |
0626e664 NJ |
332 | |
333 | /* | |
334 | * Share config flags. | |
335 | */ | |
336 | #define KSMBD_SHARE_FLAG_INVALID (0) | |
64b39f4a NJ |
337 | #define KSMBD_SHARE_FLAG_AVAILABLE BIT(0) |
338 | #define KSMBD_SHARE_FLAG_BROWSEABLE BIT(1) | |
339 | #define KSMBD_SHARE_FLAG_WRITEABLE BIT(2) | |
340 | #define KSMBD_SHARE_FLAG_READONLY BIT(3) | |
341 | #define KSMBD_SHARE_FLAG_GUEST_OK BIT(4) | |
342 | #define KSMBD_SHARE_FLAG_GUEST_ONLY BIT(5) | |
343 | #define KSMBD_SHARE_FLAG_STORE_DOS_ATTRS BIT(6) | |
344 | #define KSMBD_SHARE_FLAG_OPLOCKS BIT(7) | |
345 | #define KSMBD_SHARE_FLAG_PIPE BIT(8) | |
346 | #define KSMBD_SHARE_FLAG_HIDE_DOT_FILES BIT(9) | |
d710f37c NJ |
347 | #define KSMBD_SHARE_FLAG_INHERIT_OWNER BIT(10) |
348 | #define KSMBD_SHARE_FLAG_STREAMS BIT(11) | |
349 | #define KSMBD_SHARE_FLAG_FOLLOW_SYMLINKS BIT(12) | |
350 | #define KSMBD_SHARE_FLAG_ACL_XATTR BIT(13) | |
0626e664 NJ |
351 | |
352 | /* | |
353 | * Tree connect request flags. | |
354 | */ | |
355 | #define KSMBD_TREE_CONN_FLAG_REQUEST_SMB1 (0) | |
64b39f4a NJ |
356 | #define KSMBD_TREE_CONN_FLAG_REQUEST_IPV6 BIT(0) |
357 | #define KSMBD_TREE_CONN_FLAG_REQUEST_SMB2 BIT(1) | |
0626e664 NJ |
358 | |
359 | /* | |
360 | * Tree connect flags. | |
361 | */ | |
64b39f4a NJ |
362 | #define KSMBD_TREE_CONN_FLAG_GUEST_ACCOUNT BIT(0) |
363 | #define KSMBD_TREE_CONN_FLAG_READ_ONLY BIT(1) | |
364 | #define KSMBD_TREE_CONN_FLAG_WRITABLE BIT(2) | |
365 | #define KSMBD_TREE_CONN_FLAG_ADMIN_ACCOUNT BIT(3) | |
0626e664 NJ |
366 | |
367 | /* | |
368 | * RPC over IPC. | |
369 | */ | |
64b39f4a NJ |
370 | #define KSMBD_RPC_METHOD_RETURN BIT(0) |
371 | #define KSMBD_RPC_SRVSVC_METHOD_INVOKE BIT(1) | |
372 | #define KSMBD_RPC_SRVSVC_METHOD_RETURN (KSMBD_RPC_SRVSVC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN) | |
373 | #define KSMBD_RPC_WKSSVC_METHOD_INVOKE BIT(2) | |
374 | #define KSMBD_RPC_WKSSVC_METHOD_RETURN (KSMBD_RPC_WKSSVC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN) | |
375 | #define KSMBD_RPC_IOCTL_METHOD (BIT(3) | KSMBD_RPC_METHOD_RETURN) | |
376 | #define KSMBD_RPC_OPEN_METHOD BIT(4) | |
377 | #define KSMBD_RPC_WRITE_METHOD BIT(5) | |
378 | #define KSMBD_RPC_READ_METHOD (BIT(6) | KSMBD_RPC_METHOD_RETURN) | |
379 | #define KSMBD_RPC_CLOSE_METHOD BIT(7) | |
380 | #define KSMBD_RPC_RAP_METHOD (BIT(8) | KSMBD_RPC_METHOD_RETURN) | |
381 | #define KSMBD_RPC_RESTRICTED_CONTEXT BIT(9) | |
382 | #define KSMBD_RPC_SAMR_METHOD_INVOKE BIT(10) | |
383 | #define KSMBD_RPC_SAMR_METHOD_RETURN (KSMBD_RPC_SAMR_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN) | |
384 | #define KSMBD_RPC_LSARPC_METHOD_INVOKE BIT(11) | |
385 | #define KSMBD_RPC_LSARPC_METHOD_RETURN (KSMBD_RPC_LSARPC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN) | |
0626e664 | 386 | |
8b758859 NJ |
387 | /* |
388 | * RPC status definitions. | |
389 | */ | |
0626e664 NJ |
390 | #define KSMBD_RPC_OK 0 |
391 | #define KSMBD_RPC_EBAD_FUNC 0x00000001 | |
392 | #define KSMBD_RPC_EACCESS_DENIED 0x00000005 | |
393 | #define KSMBD_RPC_EBAD_FID 0x00000006 | |
394 | #define KSMBD_RPC_ENOMEM 0x00000008 | |
395 | #define KSMBD_RPC_EBAD_DATA 0x0000000D | |
396 | #define KSMBD_RPC_ENOTIMPLEMENTED 0x00000040 | |
397 | #define KSMBD_RPC_EINVALID_PARAMETER 0x00000057 | |
398 | #define KSMBD_RPC_EMORE_DATA 0x000000EA | |
399 | #define KSMBD_RPC_EINVALID_LEVEL 0x0000007C | |
400 | #define KSMBD_RPC_SOME_NOT_MAPPED 0x00000107 | |
401 | ||
402 | #define KSMBD_CONFIG_OPT_DISABLED 0 | |
403 | #define KSMBD_CONFIG_OPT_ENABLED 1 | |
404 | #define KSMBD_CONFIG_OPT_AUTO 2 | |
405 | #define KSMBD_CONFIG_OPT_MANDATORY 3 | |
406 | ||
407 | #endif /* _LINUX_KSMBD_SERVER_H */ |