blob: 82289c3cbd2bc24cc7ec85d9818468e1e2f5e931 [file] [log] [blame]
Namjae Jeone2f34482021-03-16 10:49:09 +09001/* 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>
Namjae Jeon02b68b22021-04-01 17:45:33 +090010#include <linux/xarray.h>
Namjae Jeone2f34482021-03-16 10:49:09 +090011
12#include "../smb_common.h"
13#include "../ntlmssp.h"
14
Namjae Jeon97d7f3d2021-06-01 13:18:44 +090015#define CIFDS_SESSION_FLAG_SMB2 BIT(1)
Namjae Jeone2f34482021-03-16 10:49:09 +090016
17#define PREAUTH_HASHVALUE_SIZE 64
18
Namjae Jeone2f34482021-03-16 10:49:09 +090019struct ksmbd_file_table;
20
21struct channel {
22 __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
23 struct ksmbd_conn *conn;
24 struct list_head chann_list;
25};
26
27struct preauth_session {
28 __u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
Namjae Jeonf5a544e2021-06-18 10:04:19 +090029 u64 id;
30 struct list_head preauth_entry;
Namjae Jeone2f34482021-03-16 10:49:09 +090031};
32
33struct ksmbd_session {
Namjae Jeon64b39f42021-03-30 14:25:35 +090034 u64 id;
Namjae Jeone2f34482021-03-16 10:49:09 +090035
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 struct ntlmssp_auth ntlmssp;
49 char sess_key[CIFS_KEY_SIZE];
50
51 struct hlist_node hlist;
52 struct list_head ksmbd_chann_list;
Namjae Jeon02b68b22021-04-01 17:45:33 +090053 struct xarray tree_conns;
Namjae Jeond40012a2021-04-13 13:06:30 +090054 struct ida tree_conn_ida;
Namjae Jeone2f34482021-03-16 10:49:09 +090055 struct list_head rpc_handle_list;
56
Namjae Jeon5a0ca772021-05-06 11:43:37 +090057 __u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
58 __u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];
Namjae Jeone2f34482021-03-16 10:49:09 +090059 __u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
60
61 struct list_head sessions_entry;
62 struct ksmbd_file_table file_table;
63 atomic_t refcnt;
64};
65
66static inline int test_session_flag(struct ksmbd_session *sess, int bit)
67{
68 return sess->flags & bit;
69}
70
71static inline void set_session_flag(struct ksmbd_session *sess, int bit)
72{
73 sess->flags |= bit;
74}
75
76static inline void clear_session_flag(struct ksmbd_session *sess, int bit)
77{
78 sess->flags &= ~bit;
79}
80
81struct ksmbd_session *ksmbd_smb2_session_create(void);
82
83void ksmbd_session_destroy(struct ksmbd_session *sess);
84
Namjae Jeone2f34482021-03-16 10:49:09 +090085struct ksmbd_session *ksmbd_session_lookup_slowpath(unsigned long long id);
86struct ksmbd_session *ksmbd_session_lookup(struct ksmbd_conn *conn,
87 unsigned long long id);
88void ksmbd_session_register(struct ksmbd_conn *conn,
89 struct ksmbd_session *sess);
90void ksmbd_sessions_deregister(struct ksmbd_conn *conn);
Namjae Jeonf5a544e2021-06-18 10:04:19 +090091struct ksmbd_session *ksmbd_session_lookup_all(struct ksmbd_conn *conn,
92 unsigned long long id);
93struct preauth_session *ksmbd_preauth_session_alloc(struct ksmbd_conn *conn,
94 u64 sess_id);
95struct preauth_session *ksmbd_preauth_session_lookup(struct ksmbd_conn *conn,
96 unsigned long long id);
Namjae Jeone2f34482021-03-16 10:49:09 +090097
98int ksmbd_acquire_tree_conn_id(struct ksmbd_session *sess);
99void ksmbd_release_tree_conn_id(struct ksmbd_session *sess, int id);
100
101int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name);
102void ksmbd_session_rpc_close(struct ksmbd_session *sess, int id);
103int ksmbd_session_rpc_method(struct ksmbd_session *sess, int id);
104int get_session(struct ksmbd_session *sess);
105void put_session(struct ksmbd_session *sess);
Namjae Jeone2f34482021-03-16 10:49:09 +0900106#endif /* __USER_SESSION_MANAGEMENT_H__ */