forked from namjaejeon/ksmbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglob.h
293 lines (241 loc) · 6.91 KB
/
glob.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016 Namjae Jeon <[email protected]>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
#ifndef __CIFSD_GLOB_H
#define __CIFSD_GLOB_H
#include <linux/list.h>
#include <linux/spinlock_types.h>
#include <linux/slab.h>
#include <linux/netdevice.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <net/sock.h>
#include <net/tcp.h>
#include <net/inet_connection_sock.h>
#include <net/request_sock.h>
#include <linux/byteorder/generic.h>
#include <linux/string.h>
#include <linux/kthread.h>
#include <linux/module.h>
#include <linux/freezer.h>
#include <linux/workqueue.h>
#include <linux/ctype.h>
#include <linux/time.h>
#include <linux/nls.h>
#include <linux/unistd.h>
#include <linux/scatterlist.h>
#include <linux/statfs.h>
#include <linux/namei.h>
#include <linux/version.h>
#include <linux/fdtable.h>
#include <linux/vmalloc.h>
#include <uapi/linux/xattr.h>
#include <linux/hashtable.h>
#include "unicode.h"
#include "fh.h"
#include <crypto/hash.h>
#include "smberr.h"
/* @FIXME clean up this code */
extern int cifsd_debugging;
extern int cifsd_caseless_search;
extern bool oplocks_enable;
extern bool lease_enable;
extern bool durable_enable;
extern bool multi_channel_enable;
extern unsigned int alloc_roundup_size;
extern struct fidtable_desc global_fidtable;
extern char *netbios_name;
extern struct list_head global_lock_list;
#define NETLINK_CIFSD_MAX_PAYLOAD 4096
/* cifsd's Specific ERRNO */
#define ESHARE 50000
#define LOCKING_ANDX_SHARED_LOCK 0x01
#define LOCKING_ANDX_OPLOCK_RELEASE 0x02
#define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04
#define LOCKING_ANDX_CANCEL_LOCK 0x08
#define LOCKING_ANDX_LARGE_FILES 0x10
/*
* * Size of the ntlm client response
* */
#define CIFS_AUTH_RESP_SIZE (24)
#define CIFS_SMB1_SIGNATURE_SIZE (8)
#define CIFS_SMB1_SESSKEY_SIZE (16)
/*
* * Size of the session key (crypto key encrypted with the password
* */
#define SMB2_NTLMV2_SESSKEY_SIZE (16)
#define SMB2_SIGNATURE_SIZE (16)
#define SMB2_HMACSHA256_SIZE (32)
#define SMB2_CMACAES_SIZE (16)
/*
* * Size of the smb3 signing key
* */
#define SMB3_SIGN_KEY_SIZE (16)
#define CIFS_CLIENT_CHALLENGE_SIZE (8)
#define CIFS_SERVER_CHALLENGE_SIZE (8)
/* SMB2 Max Credits */
#define SMB2_MAX_CREDITS 8192
#define SMB2_CLIENT_GUID_SIZE 16
#define SMB2_CREATE_GUID_SIZE 16
/* SMB2 timeouts */
#define SMB_ECHO_INTERVAL (60*HZ) /* 60 msecs */
/* MAXIMUM KMEM DATA SIZE ORDER */
#define PAGE_ALLOC_KMEM_ORDER 2
#define DATA_STREAM 1
#define DIR_STREAM 2
struct cifsd_stats {
int open_files_count;
int request_served;
};
enum asyncEnum {
ASYNC_PROG = 1,
ASYNC_CANCEL,
ASYNC_CLOSE,
ASYNC_EXITING,
};
#define SYNC 1
#define ASYNC 2
#define WORK_STATE_ENCRYPTED 0x1
#define WORK_STATE_CANCELLED 0x2
#define WORK_STATE_CLOSED 0x3
struct cifsd_tcp_conn;
/* one of these for every pending CIFS request at the connection */
struct cifsd_work {
/* Server corresponding to this mid */
struct cifsd_tcp_conn *conn;
struct cifsd_session *sess;
struct cifsd_tree_connect *tcon;
/* Pointer to received SMB header */
char *request_buf;
/* Response buffer */
char *response_buf;
unsigned int response_sz;
/* Read data buffer */
char *aux_payload_buf;
/* Read data count */
unsigned int aux_payload_sz;
/* response smb header size */
unsigned int resp_hdr_sz;
/* Next cmd hdr in compound req buf*/
int next_smb2_rcv_hdr_off;
/* Next cmd hdr in compound rsp buf*/
int next_smb2_rsp_hdr_off;
/* Transform header buffer */
void *tr_buf;
int type;
/*
* Current Local FID assigned compound response if SMB2 CREATE
* command is present in compound request
*/
__u64 cur_local_fid;
__u64 cur_local_pfid;
__u64 cur_local_sess_id;
int state;
/* Multiple responses for one request e.g. SMB ECHO */
bool multiRsp:1;
/* Both received */
bool multiEnd:1;
/* No response for cancelled request */
bool send_no_response:1;
/* On the conn->requests list */
bool on_request_list:1;
/* Request is encrypted */
bool encrypted:1;
/* smb command code */
__le16 command;
/* List head at conn->requests */
struct list_head request_entry;
struct work_struct work;
/* cancel works */
uint64_t async_id;
void **cancel_argv;
void (*cancel_fn)(void **argv);
struct list_head fp_entry;
struct list_head interim_entry;
};
#define RESPONSE_BUF(w) (void *)((w)->response_buf)
#define RESPONSE_SZ(w) ((w)->response_sz)
#define REQUEST_BUF(w) (void *)((w)->request_buf)
#define INIT_AUX_PAYLOAD(w) ((w)->aux_payload_buf = NULL)
#define HAS_AUX_PAYLOAD(w) ((w)->aux_payload_sz != 0)
#define AUX_PAYLOAD(w) (void *)((w)->aux_payload_buf)
#define AUX_PAYLOAD_SIZE(w) ((w)->aux_payload_sz)
#define RESP_HDR_SIZE(w) ((w)->resp_hdr_sz)
#define HAS_TRANSFORM_BUF(w) ((w)->tr_buf != NULL)
#define TRANSFORM_BUF(w) (void *)((w)->tr_buf)
struct cifsd_dir_info {
char *name;
char *bufptr;
int out_buf_len;
int num_entry;
int data_count;
int last_entry_offset;
};
#define cifsd_debug(fmt, ...) \
do { \
if (cifsd_debugging) \
pr_err("kcifsd: %s:%d: " fmt, \
__func__, __LINE__, ##__VA_ARGS__); \
} while (0)
#define cifsd_info(fmt, ...) pr_info("kcifsd: " fmt, ##__VA_ARGS__)
#define cifsd_err(fmt, ...) pr_err("kcifsd: %s:%d: " fmt, \
__func__, __LINE__, ##__VA_ARGS__)
static inline unsigned int
get_rfc1002_length(void *buf)
{
return be32_to_cpu(*((__be32 *)buf)) & 0xffffff;
}
static inline void
inc_rfc1001_len(void *buf, int count)
{
be32_add_cpu((__be32 *)buf, count);
}
/* misc functions */
#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
#define UNICODE_LEN(x) ((x) * 2)
/* Convert the Unix UTC into NT UTC. */
static inline u64
cifs_UnixTimeToNT(struct timespec t)
{
/* Convert to 100ns intervals and then add the NTFS time offset. */
return (u64) t.tv_sec * 10000000 + t.tv_nsec/100 + NTFS_TIME_OFFSET;
}
static inline struct timespec
cifs_NTtimeToUnix(__le64 ntutc)
{
struct timespec ts;
/* Subtract the NTFS time offset, then convert to 1s intervals. */
u64 t;
t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
ts.tv_nsec = do_div(t, 10000000) * 100;
ts.tv_sec = t;
return ts;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 18, 0)
static inline struct timespec64 to_kern_timespec(struct timespec ts)
{
return timespec_to_timespec64(ts);
}
static inline struct timespec from_kern_timespec(struct timespec64 ts)
{
return timespec64_to_timespec(ts);
}
#else
#define to_kern_timespec(ts) (ts)
#define from_kern_timespec(ts) (ts)
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,20, 0)
#define CIFSD_TIME_TO_TM time64_to_tm
#else
#define CIFSD_TIME_TO_TM time_to_tm
#endif
/* @FIXME clean up this code */
/* @FIXME clean up this code */
/* @FIXME clean up this code */
/* cifsd misc functions */
extern void ntstatus_to_dos(__u32 ntstatus, __u8 *eclass, __u16 *ecode);
extern int smb_check_delete_pending(struct file *filp,
struct cifsd_file *curr_fp);
#endif /* __CIFSD_GLOB_H */