1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
5 * linux-ksmbd-devel@lists.sourceforge.net
8 #ifndef _LINUX_KSMBD_SERVER_H
9 #define _LINUX_KSMBD_SERVER_H
11 #include <linux/types.h>
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.
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.
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
29 * - KSMBD_EVENT_SHUTTING_DOWN(ksmbd_shutdown_request)
30 * This event is to shutdown ksmbd server.
32 * - KSMBD_EVENT_LOGIN_REQUEST/RESPONSE(ksmbd_login_request/response)
33 * This event is to get user account info to user IPC daemon.
35 * - KSMBD_EVENT_SHARE_CONFIG_REQUEST/RESPONSE(ksmbd_share_config_request/response)
36 * This event is to get net share configuration info.
38 * - KSMBD_EVENT_TREE_CONNECT_REQUEST/RESPONSE(ksmbd_tree_connect_request/response)
39 * This event is to get session and tree connect info.
41 * - KSMBD_EVENT_TREE_DISCONNECT_REQUEST(ksmbd_tree_disconnect_request)
42 * This event is to send tree disconnect info to user IPC daemon.
44 * - KSMBD_EVENT_LOGOUT_REQUEST(ksmbd_logout_request)
45 * This event is to send logout request to user IPC daemon.
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.
51 * - KSMBD_EVENT_SPNEGO_AUTHEN_REQUEST/RESPONSE(ksmbd_spnego_authen_request/response)
52 * This event is to make kerberos authentication to be processed in
56 #define KSMBD_GENL_NAME "SMBD_GENL"
57 #define KSMBD_GENL_VERSION 0x01
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
64 * IPC heartbeat frame to check whether user IPC daemon is alive.
66 struct ksmbd_heartbeat {
71 * Global config flags.
73 #define KSMBD_GLOBAL_FLAG_INVALID (0)
74 #define KSMBD_GLOBAL_FLAG_SMB2_LEASES BIT(0)
75 #define KSMBD_GLOBAL_FLAG_SMB2_ENCRYPTION BIT(1)
76 #define KSMBD_GLOBAL_FLAG_SMB3_MULTICHANNEL BIT(2)
79 * IPC request for ksmbd server startup
81 struct ksmbd_startup_request {
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 */
86 __s8 netbios_name[16];
87 __s8 work_group[64]; /* Workgroup */
88 __s8 server_string[64]; /* Server string */
89 __u16 tcp_port; /* tcp port */
91 * specifies the number of seconds
92 * server will wait for the userspace to
93 * reply to heartbeat frames.
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).
105 __u32 sub_auth[3]; /* Subauth value for Security ID */
106 __u32 ifc_list_sz; /* interfaces list size */
110 #define KSMBD_STARTUP_CONFIG_INTERFACES(s) ((s)->____payload)
113 * IPC request to shutdown ksmbd server.
115 struct ksmbd_shutdown_request {
120 * IPC user login request.
122 struct ksmbd_login_request {
124 __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */
128 * IPC user login response.
130 struct ksmbd_login_response {
132 __u32 gid; /* group id */
133 __u32 uid; /* user id */
134 __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */
136 __u16 hash_sz; /* hash size */
137 __s8 hash[KSMBD_REQ_MAX_HASH_SZ]; /* password hash */
141 * IPC request to fetch net share config.
143 struct ksmbd_share_config_request {
145 __s8 share_name[KSMBD_REQ_MAX_SHARE_NAME]; /* share name */
149 * IPC response to the net share config request.
151 struct ksmbd_share_config_response {
155 __u16 directory_mask;
156 __u16 force_create_mode;
157 __u16 force_directory_mode;
164 #define KSMBD_SHARE_CONFIG_VETO_LIST(s) ((s)->____payload)
167 ksmbd_share_config_path(struct ksmbd_share_config_response *sc)
169 char *p = sc->____payload;
171 if (sc->veto_list_sz)
172 p += sc->veto_list_sz + 1;
178 * IPC request for tree connection. This request include session and tree
179 * connect info from client.
181 struct ksmbd_tree_connect_request {
187 __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ];
188 __s8 share[KSMBD_REQ_MAX_SHARE_NAME];
193 * IPC Response structure for tree connection.
195 struct ksmbd_tree_connect_response {
198 __u16 connection_flags;
202 * IPC Request struture to disconnect tree connection.
204 struct ksmbd_tree_disconnect_request {
205 __u64 session_id; /* session id */
206 __u64 connect_id; /* tree connection id */
210 * IPC Response structure to logout user account.
212 struct ksmbd_logout_request {
213 __s8 account[KSMBD_REQ_MAX_ACCOUNT_NAME_SZ]; /* user account name */
217 * RPC command structure to send rpc request like srvsvc or wkssvc to
220 struct ksmbd_rpc_command {
228 * IPC Request Kerberos authentication
230 struct ksmbd_spnego_authen_request {
232 __u16 spnego_blob_len; /* the length of spnego_blob */
233 __u8 spnego_blob[0]; /*
234 * the GSS token from SecurityBuffer of
235 * SMB2 SESSION SETUP request
240 * Response data which includes the GSS token and the session key generated by
243 struct ksmbd_spnego_authen_response {
245 struct ksmbd_login_response login_response; /*
246 * the login response with
247 * a user identified by the
248 * GSS token from a client
250 __u16 session_key_len; /* the length of the session key */
251 __u16 spnego_blob_len; /*
252 * the length of the GSS token which will be
253 * stored in SecurityBuffer of SMB2 SESSION
256 __u8 payload[]; /* session key + AP_REP */
260 * This also used as NETLINK attribute type value.
263 * Response message type value should be equal to
264 * request message type value + 1.
267 KSMBD_EVENT_UNSPEC = 0,
268 KSMBD_EVENT_HEARTBEAT_REQUEST,
270 KSMBD_EVENT_STARTING_UP,
271 KSMBD_EVENT_SHUTTING_DOWN,
273 KSMBD_EVENT_LOGIN_REQUEST,
274 KSMBD_EVENT_LOGIN_RESPONSE = 5,
276 KSMBD_EVENT_SHARE_CONFIG_REQUEST,
277 KSMBD_EVENT_SHARE_CONFIG_RESPONSE,
279 KSMBD_EVENT_TREE_CONNECT_REQUEST,
280 KSMBD_EVENT_TREE_CONNECT_RESPONSE,
282 KSMBD_EVENT_TREE_DISCONNECT_REQUEST = 10,
284 KSMBD_EVENT_LOGOUT_REQUEST,
286 KSMBD_EVENT_RPC_REQUEST,
287 KSMBD_EVENT_RPC_RESPONSE,
289 KSMBD_EVENT_SPNEGO_AUTHEN_REQUEST,
290 KSMBD_EVENT_SPNEGO_AUTHEN_RESPONSE = 15,
296 * Enumeration for IPC tree connect status.
298 enum KSMBD_TREE_CONN_STATUS {
299 KSMBD_TREE_CONN_STATUS_OK = 0,
300 KSMBD_TREE_CONN_STATUS_NOMEM,
301 KSMBD_TREE_CONN_STATUS_NO_SHARE,
302 KSMBD_TREE_CONN_STATUS_NO_USER,
303 KSMBD_TREE_CONN_STATUS_INVALID_USER,
304 KSMBD_TREE_CONN_STATUS_HOST_DENIED = 5,
305 KSMBD_TREE_CONN_STATUS_CONN_EXIST,
306 KSMBD_TREE_CONN_STATUS_TOO_MANY_CONNS,
307 KSMBD_TREE_CONN_STATUS_TOO_MANY_SESSIONS,
308 KSMBD_TREE_CONN_STATUS_ERROR,
314 #define KSMBD_USER_FLAG_INVALID (0)
315 #define KSMBD_USER_FLAG_OK BIT(0)
316 #define KSMBD_USER_FLAG_BAD_PASSWORD BIT(1)
317 #define KSMBD_USER_FLAG_BAD_UID BIT(2)
318 #define KSMBD_USER_FLAG_BAD_USER BIT(3)
319 #define KSMBD_USER_FLAG_GUEST_ACCOUNT BIT(4)
322 * Share config flags.
324 #define KSMBD_SHARE_FLAG_INVALID (0)
325 #define KSMBD_SHARE_FLAG_AVAILABLE BIT(0)
326 #define KSMBD_SHARE_FLAG_BROWSEABLE BIT(1)
327 #define KSMBD_SHARE_FLAG_WRITEABLE BIT(2)
328 #define KSMBD_SHARE_FLAG_READONLY BIT(3)
329 #define KSMBD_SHARE_FLAG_GUEST_OK BIT(4)
330 #define KSMBD_SHARE_FLAG_GUEST_ONLY BIT(5)
331 #define KSMBD_SHARE_FLAG_STORE_DOS_ATTRS BIT(6)
332 #define KSMBD_SHARE_FLAG_OPLOCKS BIT(7)
333 #define KSMBD_SHARE_FLAG_PIPE BIT(8)
334 #define KSMBD_SHARE_FLAG_HIDE_DOT_FILES BIT(9)
335 #define KSMBD_SHARE_FLAG_INHERIT_OWNER BIT(10)
336 #define KSMBD_SHARE_FLAG_STREAMS BIT(11)
337 #define KSMBD_SHARE_FLAG_FOLLOW_SYMLINKS BIT(12)
338 #define KSMBD_SHARE_FLAG_ACL_XATTR BIT(13)
341 * Tree connect request flags.
343 #define KSMBD_TREE_CONN_FLAG_REQUEST_SMB1 (0)
344 #define KSMBD_TREE_CONN_FLAG_REQUEST_IPV6 BIT(0)
345 #define KSMBD_TREE_CONN_FLAG_REQUEST_SMB2 BIT(1)
348 * Tree connect flags.
350 #define KSMBD_TREE_CONN_FLAG_GUEST_ACCOUNT BIT(0)
351 #define KSMBD_TREE_CONN_FLAG_READ_ONLY BIT(1)
352 #define KSMBD_TREE_CONN_FLAG_WRITABLE BIT(2)
353 #define KSMBD_TREE_CONN_FLAG_ADMIN_ACCOUNT BIT(3)
358 #define KSMBD_RPC_METHOD_RETURN BIT(0)
359 #define KSMBD_RPC_SRVSVC_METHOD_INVOKE BIT(1)
360 #define KSMBD_RPC_SRVSVC_METHOD_RETURN (KSMBD_RPC_SRVSVC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN)
361 #define KSMBD_RPC_WKSSVC_METHOD_INVOKE BIT(2)
362 #define KSMBD_RPC_WKSSVC_METHOD_RETURN (KSMBD_RPC_WKSSVC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN)
363 #define KSMBD_RPC_IOCTL_METHOD (BIT(3) | KSMBD_RPC_METHOD_RETURN)
364 #define KSMBD_RPC_OPEN_METHOD BIT(4)
365 #define KSMBD_RPC_WRITE_METHOD BIT(5)
366 #define KSMBD_RPC_READ_METHOD (BIT(6) | KSMBD_RPC_METHOD_RETURN)
367 #define KSMBD_RPC_CLOSE_METHOD BIT(7)
368 #define KSMBD_RPC_RAP_METHOD (BIT(8) | KSMBD_RPC_METHOD_RETURN)
369 #define KSMBD_RPC_RESTRICTED_CONTEXT BIT(9)
370 #define KSMBD_RPC_SAMR_METHOD_INVOKE BIT(10)
371 #define KSMBD_RPC_SAMR_METHOD_RETURN (KSMBD_RPC_SAMR_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN)
372 #define KSMBD_RPC_LSARPC_METHOD_INVOKE BIT(11)
373 #define KSMBD_RPC_LSARPC_METHOD_RETURN (KSMBD_RPC_LSARPC_METHOD_INVOKE | KSMBD_RPC_METHOD_RETURN)
376 * RPC status definitions.
378 #define KSMBD_RPC_OK 0
379 #define KSMBD_RPC_EBAD_FUNC 0x00000001
380 #define KSMBD_RPC_EACCESS_DENIED 0x00000005
381 #define KSMBD_RPC_EBAD_FID 0x00000006
382 #define KSMBD_RPC_ENOMEM 0x00000008
383 #define KSMBD_RPC_EBAD_DATA 0x0000000D
384 #define KSMBD_RPC_ENOTIMPLEMENTED 0x00000040
385 #define KSMBD_RPC_EINVALID_PARAMETER 0x00000057
386 #define KSMBD_RPC_EMORE_DATA 0x000000EA
387 #define KSMBD_RPC_EINVALID_LEVEL 0x0000007C
388 #define KSMBD_RPC_SOME_NOT_MAPPED 0x00000107
390 #define KSMBD_CONFIG_OPT_DISABLED 0
391 #define KSMBD_CONFIG_OPT_ENABLED 1
392 #define KSMBD_CONFIG_OPT_AUTO 2
393 #define KSMBD_CONFIG_OPT_MANDATORY 3
395 #endif /* _LINUX_KSMBD_SERVER_H */