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