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 }; 25 26 struct preauth_session { 27 __u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE]; 28 u64 id; 29 struct list_head preauth_entry; 30 }; 31 32 struct ksmbd_session { 33 u64 id; 34 35 __u16 dialect; 36 char ClientGUID[SMB2_CLIENT_GUID_SIZE]; 37 38 struct ksmbd_user *user; 39 unsigned int sequence_number; 40 unsigned int flags; 41 42 bool sign; 43 bool enc; 44 bool is_anonymous; 45 46 int state; 47 __u8 *Preauth_HashValue; 48 49 char sess_key[CIFS_KEY_SIZE]; 50 51 struct hlist_node hlist; 52 struct xarray ksmbd_chann_list; 53 struct xarray tree_conns; 54 struct ida tree_conn_ida; 55 struct xarray rpc_handle_list; 56 57 __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE]; 58 __u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE]; 59 __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE]; 60 61 struct ksmbd_file_table file_table; 62 unsigned long last_active; 63 rwlock_t tree_conns_lock; 64 65 atomic_t refcnt; 66 }; 67 68 static inline int test_session_flag(struct ksmbd_session *sess, int bit) 69 { 70 return sess->flags & bit; 71 } 72 73 static inline void set_session_flag(struct ksmbd_session *sess, int bit) 74 { 75 sess->flags |= bit; 76 } 77 78 static inline void clear_session_flag(struct ksmbd_session *sess, int bit) 79 { 80 sess->flags &= ~bit; 81 } 82 83 struct ksmbd_session *ksmbd_smb2_session_create(void); 84 85 void ksmbd_session_destroy(struct ksmbd_session *sess); 86 87 struct ksmbd_session *ksmbd_session_lookup_slowpath(unsigned long long id); 88 struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn, 89 unsigned long long id); 90 int ksmbd_session_register(struct ksmbd_conn *conn, 91 struct ksmbd_session *sess); 92 void ksmbd_sessions_deregister(struct ksmbd_conn *conn); 93 struct ksmbd_session *__session_lookup(unsigned long long id); 94 struct ksmbd_session *ksmbd_session_lookup_all(struct ksmbd_conn *conn, 95 unsigned long long id); 96 void destroy_previous_session(struct ksmbd_conn *conn, 97 struct ksmbd_user *user, u64 id); 98 struct preauth_session *ksmbd_preauth_session_alloc(struct ksmbd_conn *conn, 99 u64 sess_id); 100 struct preauth_session *ksmbd_preauth_session_lookup(struct ksmbd_conn *conn, 101 unsigned long long id); 102 103 int ksmbd_acquire_tree_conn_id(struct ksmbd_session *sess); 104 void ksmbd_release_tree_conn_id(struct ksmbd_session *sess, int id); 105 106 int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name); 107 void ksmbd_session_rpc_close(struct ksmbd_session *sess, int id); 108 int ksmbd_session_rpc_method(struct ksmbd_session *sess, int id); 109 void ksmbd_user_session_get(struct ksmbd_session *sess); 110 void ksmbd_user_session_put(struct ksmbd_session *sess); 111 #endif /* __USER_SESSION_MANAGEMENT_H__ */ 112