1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  *   Copyright (C) 2018 Samsung Electronics Co., Ltd.
4  */
5 
6 #ifndef __USER_SESSION_MANAGEMENT_H__
7 #define __USER_SESSION_MANAGEMENT_H__
8 
9 #include <linux/hashtable.h>
10 #include <linux/xarray.h>
11 
12 #include "../smb_common.h"
13 #include "../ntlmssp.h"
14 
15 #define CIFDS_SESSION_FLAG_SMB2		BIT(1)
16 
17 #define PREAUTH_HASHVALUE_SIZE		64
18 
19 struct ksmbd_file_table;
20 
21 struct channel {
22 	__u8			smb3signingkey[SMB3_SIGN_KEY_SIZE];
23 	struct ksmbd_conn	*conn;
24 	struct list_head	chann_list;
25 };
26 
27 struct preauth_session {
28 	__u8			Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
29 	u64			id;
30 	struct list_head	preauth_entry;
31 };
32 
33 struct ksmbd_session {
34 	u64				id;
35 
36 	struct ksmbd_user		*user;
37 	struct ksmbd_conn		*conn;
38 	unsigned int			sequence_number;
39 	unsigned int			flags;
40 
41 	bool				sign;
42 	bool				enc;
43 	bool				is_anonymous;
44 
45 	int				state;
46 	__u8				*Preauth_HashValue;
47 
48 	char				sess_key[CIFS_KEY_SIZE];
49 
50 	struct hlist_node		hlist;
51 	struct list_head		ksmbd_chann_list;
52 	struct xarray			tree_conns;
53 	struct ida			tree_conn_ida;
54 	struct list_head		rpc_handle_list;
55 
56 	__u8				smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
57 	__u8				smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];
58 	__u8				smb3signingkey[SMB3_SIGN_KEY_SIZE];
59 
60 	struct list_head		sessions_entry;
61 	struct ksmbd_file_table		file_table;
62 	atomic_t			refcnt;
63 };
64 
test_session_flag(struct ksmbd_session * sess,int bit)65 static inline int test_session_flag(struct ksmbd_session *sess, int bit)
66 {
67 	return sess->flags & bit;
68 }
69 
set_session_flag(struct ksmbd_session * sess,int bit)70 static inline void set_session_flag(struct ksmbd_session *sess, int bit)
71 {
72 	sess->flags |= bit;
73 }
74 
clear_session_flag(struct ksmbd_session * sess,int bit)75 static inline void clear_session_flag(struct ksmbd_session *sess, int bit)
76 {
77 	sess->flags &= ~bit;
78 }
79 
80 struct ksmbd_session *ksmbd_smb2_session_create(void);
81 
82 void ksmbd_session_destroy(struct ksmbd_session *sess);
83 
84 struct ksmbd_session *ksmbd_session_lookup_slowpath(unsigned long long id);
85 struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn,
86 					   unsigned long long id);
87 void ksmbd_session_register(struct ksmbd_conn *conn,
88 			    struct ksmbd_session *sess);
89 void ksmbd_sessions_deregister(struct ksmbd_conn *conn);
90 struct ksmbd_session *ksmbd_session_lookup_all(struct ksmbd_conn *conn,
91 					       unsigned long long id);
92 struct preauth_session *ksmbd_preauth_session_alloc(struct ksmbd_conn *conn,
93 						    u64 sess_id);
94 struct preauth_session *ksmbd_preauth_session_lookup(struct ksmbd_conn *conn,
95 						     unsigned long long id);
96 
97 int ksmbd_acquire_tree_conn_id(struct ksmbd_session *sess);
98 void ksmbd_release_tree_conn_id(struct ksmbd_session *sess, int id);
99 
100 int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name);
101 void ksmbd_session_rpc_close(struct ksmbd_session *sess, int id);
102 int ksmbd_session_rpc_method(struct ksmbd_session *sess, int id);
103 int get_session(struct ksmbd_session *sess);
104 void put_session(struct ksmbd_session *sess);
105 #endif /* __USER_SESSION_MANAGEMENT_H__ */
106