1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#include <linux/in.h>
20#include <linux/in6.h>
21#include <linux/slow-work.h>
22#include "cifs_fs_sb.h"
23#include "cifsacl.h"
24
25
26
27#define MAX_UID_INFO 16
28#define MAX_SES_INFO 2
29#define MAX_TCON_INFO 4
30
31#define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
32#define MAX_SERVER_SIZE 15
33#define MAX_SHARE_SIZE 64
34#define MAX_USERNAME_SIZE 32
35
36#define MAX_PASSWORD_SIZE 16
37
38#define CIFS_MIN_RCV_POOL 4
39
40
41
42
43
44
45
46
47
48
49#define CIFS_MAX_REQ 50
50
51#define RFC1001_NAME_LEN 15
52#define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
53
54
55#define SERVER_NAME_LENGTH 40
56#define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
57
58
59
60
61#define MAX_NAME 514
62
63#include "cifspdu.h"
64
65#ifndef XATTR_DOS_ATTRIB
66#define XATTR_DOS_ATTRIB "user.DOSATTRIB"
67#endif
68
69
70
71
72
73
74enum statusEnum {
75 CifsNew = 0,
76 CifsGood,
77 CifsExiting,
78 CifsNeedReconnect
79};
80
81enum securityEnum {
82 PLAINTXT = 0,
83 LANMAN,
84 NTLM,
85 NTLMv2,
86 RawNTLMSSP,
87
88 Kerberos,
89 MSKerberos,
90};
91
92enum protocolEnum {
93 TCP = 0,
94 SCTP
95
96};
97
98struct mac_key {
99 unsigned int len;
100 union {
101 char ntlm[CIFS_SESS_KEY_SIZE + 16];
102 char krb5[CIFS_SESS_KEY_SIZE + 16];
103 struct {
104 char key[16];
105 struct ntlmv2_resp resp;
106 } ntlmv2;
107 } data;
108};
109
110struct cifs_cred {
111 int uid;
112 int gid;
113 int mode;
114 int cecount;
115 struct cifs_sid osid;
116 struct cifs_sid gsid;
117 struct cifs_ntace *ntaces;
118 struct cifs_ace *aces;
119};
120
121
122
123
124
125
126
127
128struct TCP_Server_Info {
129 struct list_head tcp_ses_list;
130 struct list_head smb_ses_list;
131 int srv_count;
132
133 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
134 char *hostname;
135 struct socket *ssocket;
136 union {
137 struct sockaddr_in sockAddr;
138 struct sockaddr_in6 sockAddr6;
139 } addr;
140 wait_queue_head_t response_q;
141 wait_queue_head_t request_q;
142 struct list_head pending_mid_q;
143 void *Server_NlsInfo;
144 unsigned short server_codepage;
145 unsigned long ip_address;
146 enum protocolEnum protocolType;
147 char versionMajor;
148 char versionMinor;
149 bool svlocal:1;
150 bool noblocksnd;
151 bool noautotune;
152 atomic_t inFlight;
153#ifdef CONFIG_CIFS_STATS2
154 atomic_t inSend;
155 atomic_t num_waiters;
156#endif
157 enum statusEnum tcpStatus;
158 struct mutex srv_mutex;
159 struct task_struct *tsk;
160 char server_GUID[16];
161 char secMode;
162 enum securityEnum secType;
163 unsigned int maxReq;
164
165
166 unsigned int maxBuf;
167
168 unsigned int max_rw;
169
170
171 unsigned int max_vcs;
172
173
174 char sessid[4];
175
176 int capabilities;
177 int timeAdj;
178 __u16 CurrentMid;
179 char cryptKey[CIFS_CRYPTO_KEY_SIZE];
180
181 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
182 __u32 sequence_number;
183 struct mac_key mac_signing_key;
184 char ntlmv2_hash[16];
185 unsigned long lstrp;
186};
187
188
189
190
191
192
193struct cifsUidInfo {
194 struct list_head userList;
195 struct list_head sessionList;
196 uid_t linux_uid;
197 char user[MAX_USERNAME_SIZE + 1];
198
199};
200
201
202
203
204struct cifsSesInfo {
205 struct list_head smb_ses_list;
206 struct list_head tcon_list;
207 struct semaphore sesSem;
208#if 0
209 struct cifsUidInfo *uidInfo;
210#endif
211 struct TCP_Server_Info *server;
212 int ses_count;
213 enum statusEnum status;
214 unsigned overrideSecFlg;
215 __u16 ipc_tid;
216 __u16 flags;
217 __u16 vcnum;
218 char *serverOS;
219 char *serverNOS;
220 char *serverDomain;
221 int Suid;
222 uid_t linux_uid;
223 int capabilities;
224 char serverName[SERVER_NAME_LEN_WITH_NULL * 2];
225
226 char userName[MAX_USERNAME_SIZE + 1];
227 char *domainName;
228 char *password;
229 bool need_reconnect:1;
230};
231
232#define CIFS_SES_NT4 1
233#define CIFS_SES_OS2 2
234#define CIFS_SES_W9X 4
235
236
237
238#define CIFS_SES_LANMAN 8
239
240
241
242
243struct cifsTconInfo {
244 struct list_head tcon_list;
245 int tc_count;
246 struct list_head openFileList;
247 struct cifsSesInfo *ses;
248 char treeName[MAX_TREE_SIZE + 1];
249 char *nativeFileSystem;
250 char *password;
251 __u16 tid;
252 __u16 Flags;
253 enum statusEnum tidStatus;
254#ifdef CONFIG_CIFS_STATS
255 atomic_t num_smbs_sent;
256 atomic_t num_writes;
257 atomic_t num_reads;
258 atomic_t num_flushes;
259 atomic_t num_oplock_brks;
260 atomic_t num_opens;
261 atomic_t num_closes;
262 atomic_t num_deletes;
263 atomic_t num_mkdirs;
264 atomic_t num_posixopens;
265 atomic_t num_posixmkdirs;
266 atomic_t num_rmdirs;
267 atomic_t num_renames;
268 atomic_t num_t2renames;
269 atomic_t num_ffirst;
270 atomic_t num_fnext;
271 atomic_t num_fclose;
272 atomic_t num_hardlinks;
273 atomic_t num_symlinks;
274 atomic_t num_locks;
275 atomic_t num_acl_get;
276 atomic_t num_acl_set;
277#ifdef CONFIG_CIFS_STATS2
278 unsigned long long time_writes;
279 unsigned long long time_reads;
280 unsigned long long time_opens;
281 unsigned long long time_deletes;
282 unsigned long long time_closes;
283 unsigned long long time_mkdirs;
284 unsigned long long time_rmdirs;
285 unsigned long long time_renames;
286 unsigned long long time_t2renames;
287 unsigned long long time_ffirst;
288 unsigned long long time_fnext;
289 unsigned long long time_fclose;
290#endif
291 __u64 bytes_read;
292 __u64 bytes_written;
293 spinlock_t stat_lock;
294#endif
295 FILE_SYSTEM_DEVICE_INFO fsDevInfo;
296 FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo;
297 FILE_SYSTEM_UNIX_INFO fsUnixInfo;
298 bool ipc:1;
299 bool retry:1;
300 bool nocase:1;
301 bool seal:1;
302 bool unix_ext:1;
303
304 bool local_lease:1;
305 bool broken_posix_open;
306 bool need_reconnect:1;
307
308};
309
310
311
312
313
314struct cifsLockInfo {
315 struct list_head llist;
316 __u64 offset;
317 __u64 length;
318 __u8 type;
319};
320
321
322
323
324struct cifs_search_info {
325 loff_t index_of_last_entry;
326 __u16 entries_in_buffer;
327 __u16 info_level;
328 __u32 resume_key;
329 char *ntwrk_buf_start;
330 char *srch_entries_start;
331 char *last_entry;
332 char *presume_name;
333 unsigned int resume_name_len;
334 bool endOfSearch:1;
335 bool emptyDir:1;
336 bool unicode:1;
337 bool smallBuf:1;
338};
339
340struct cifsFileInfo {
341 struct list_head tlist;
342 struct list_head flist;
343 unsigned int uid;
344 __u32 pid;
345 __u16 netfid;
346 ;
347
348 struct file *pfile;
349 struct inode *pInode;
350 struct vfsmount *mnt;
351 struct mutex lock_mutex;
352 struct list_head llist;
353 bool closePend:1;
354 bool invalidHandle:1;
355 bool oplock_break_cancelled:1;
356 atomic_t count;
357 struct mutex fh_mutex;
358 struct cifs_search_info srch_inf;
359 struct slow_work oplock_break;
360};
361
362
363static inline void cifsFileInfo_get(struct cifsFileInfo *cifs_file)
364{
365 atomic_inc(&cifs_file->count);
366}
367
368
369static inline void cifsFileInfo_put(struct cifsFileInfo *cifs_file)
370{
371 if (atomic_dec_and_test(&cifs_file->count)) {
372 iput(cifs_file->pInode);
373 kfree(cifs_file);
374 }
375}
376
377
378
379
380
381struct cifsInodeInfo {
382 struct list_head lockList;
383
384 struct list_head openFileList;
385 int write_behind_rc;
386 __u32 cifsAttrs;
387 unsigned long time;
388 bool clientCanCacheRead:1;
389 bool clientCanCacheAll:1;
390 bool delete_pending:1;
391 u64 server_eof;
392 u64 uniqueid;
393 struct inode vfs_inode;
394};
395
396static inline struct cifsInodeInfo *
397CIFS_I(struct inode *inode)
398{
399 return container_of(inode, struct cifsInodeInfo, vfs_inode);
400}
401
402static inline struct cifs_sb_info *
403CIFS_SB(struct super_block *sb)
404{
405 return sb->s_fs_info;
406}
407
408static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
409{
410 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
411 return '/';
412 else
413 return '\\';
414}
415
416#ifdef CONFIG_CIFS_STATS
417#define cifs_stats_inc atomic_inc
418
419static inline void cifs_stats_bytes_written(struct cifsTconInfo *tcon,
420 unsigned int bytes)
421{
422 if (bytes) {
423 spin_lock(&tcon->stat_lock);
424 tcon->bytes_written += bytes;
425 spin_unlock(&tcon->stat_lock);
426 }
427}
428
429static inline void cifs_stats_bytes_read(struct cifsTconInfo *tcon,
430 unsigned int bytes)
431{
432 spin_lock(&tcon->stat_lock);
433 tcon->bytes_read += bytes;
434 spin_unlock(&tcon->stat_lock);
435}
436#else
437
438#define cifs_stats_inc(field) do {} while (0)
439#define cifs_stats_bytes_written(tcon, bytes) do {} while (0)
440#define cifs_stats_bytes_read(tcon, bytes) do {} while (0)
441
442#endif
443
444
445struct mid_q_entry {
446 struct list_head qhead;
447 __u16 mid;
448 __u16 pid;
449 __u32 sequence_number;
450 unsigned long when_alloc;
451#ifdef CONFIG_CIFS_STATS2
452 unsigned long when_sent;
453 unsigned long when_received;
454#endif
455 struct task_struct *tsk;
456 struct smb_hdr *resp_buf;
457 int midState;
458 __u8 command;
459 bool largeBuf:1;
460 bool multiRsp:1;
461 bool multiEnd:1;
462};
463
464struct oplock_q_entry {
465 struct list_head qhead;
466 struct inode *pinode;
467 struct cifsTconInfo *tcon;
468 __u16 netfid;
469};
470
471
472struct dir_notify_req {
473 struct list_head lhead;
474 __le16 Pid;
475 __le16 PidHigh;
476 __u16 Mid;
477 __u16 Tid;
478 __u16 Uid;
479 __u16 netfid;
480 __u32 filter;
481 int multishot;
482 struct file *pfile;
483};
484
485struct dfs_info3_param {
486 int flags;
487 int path_consumed;
488 int server_type;
489 int ref_flag;
490 char *path_name;
491 char *node_name;
492};
493
494
495
496
497
498
499#define CIFS_FATTR_DFS_REFERRAL 0x1
500#define CIFS_FATTR_DELETE_PENDING 0x2
501#define CIFS_FATTR_NEED_REVAL 0x4
502
503struct cifs_fattr {
504 u32 cf_flags;
505 u32 cf_cifsattrs;
506 u64 cf_uniqueid;
507 u64 cf_eof;
508 u64 cf_bytes;
509 uid_t cf_uid;
510 gid_t cf_gid;
511 umode_t cf_mode;
512 dev_t cf_rdev;
513 unsigned int cf_nlink;
514 unsigned int cf_dtype;
515 struct timespec cf_atime;
516 struct timespec cf_mtime;
517 struct timespec cf_ctime;
518};
519
520static inline void free_dfs_info_param(struct dfs_info3_param *param)
521{
522 if (param) {
523 kfree(param->path_name);
524 kfree(param->node_name);
525 kfree(param);
526 }
527}
528
529static inline void free_dfs_info_array(struct dfs_info3_param *param,
530 int number_of_items)
531{
532 int i;
533 if ((number_of_items == 0) || (param == NULL))
534 return;
535 for (i = 0; i < number_of_items; i++) {
536 kfree(param[i].path_name);
537 kfree(param[i].node_name);
538 }
539 kfree(param);
540}
541
542#define MID_FREE 0
543#define MID_REQUEST_ALLOCATED 1
544#define MID_REQUEST_SUBMITTED 2
545#define MID_RESPONSE_RECEIVED 4
546#define MID_RETRY_NEEDED 8
547#define MID_NO_RESP_NEEDED 0x10
548
549
550#define CIFS_NO_BUFFER 0
551#define CIFS_SMALL_BUFFER 1
552#define CIFS_LARGE_BUFFER 2
553#define CIFS_IOVEC 4
554
555
556#define CIFS_STD_OP 0
557#define CIFS_LONG_OP 1
558#define CIFS_VLONG_OP 2
559#define CIFS_BLOCKING_OP 4
560#define CIFS_ASYNC_OP 8
561#define CIFS_TIMEOUT_MASK 0x00F
562#define CIFS_LOG_ERROR 0x010
563#define CIFS_LARGE_BUF_OP 0x020
564#define CIFS_NO_RESP 0x040
565
566
567#define CIFSSEC_MAY_SIGN 0x00001
568#define CIFSSEC_MAY_NTLM 0x00002
569#define CIFSSEC_MAY_NTLMV2 0x00004
570#define CIFSSEC_MAY_KRB5 0x00008
571#ifdef CONFIG_CIFS_WEAK_PW_HASH
572#define CIFSSEC_MAY_LANMAN 0x00010
573#define CIFSSEC_MAY_PLNTXT 0x00020
574#else
575#define CIFSSEC_MAY_LANMAN 0
576#define CIFSSEC_MAY_PLNTXT 0
577#endif
578#define CIFSSEC_MAY_SEAL 0x00040
579#define CIFSSEC_MAY_NTLMSSP 0x00080
580
581#define CIFSSEC_MUST_SIGN 0x01001
582
583
584
585#define CIFSSEC_MUST_NTLM 0x02002
586#define CIFSSEC_MUST_NTLMV2 0x04004
587#define CIFSSEC_MUST_KRB5 0x08008
588#ifdef CONFIG_CIFS_WEAK_PW_HASH
589#define CIFSSEC_MUST_LANMAN 0x10010
590#define CIFSSEC_MUST_PLNTXT 0x20020
591#ifdef CONFIG_CIFS_UPCALL
592#define CIFSSEC_MASK 0xBF0BF
593#else
594#define CIFSSEC_MASK 0xB70B7
595#endif
596#else
597#ifdef CONFIG_CIFS_UPCALL
598#define CIFSSEC_MASK 0x8F08F
599#else
600#define CIFSSEC_MASK 0x87087
601#endif
602#endif
603#define CIFSSEC_MUST_SEAL 0x40040
604#define CIFSSEC_MUST_NTLMSSP 0x80080
605
606#define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2)
607#define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
608#define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
609
610
611
612
613
614
615#define UID_HASH (16)
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644#ifdef DECLARE_GLOBALS_HERE
645#define GLOBAL_EXTERN
646#else
647#define GLOBAL_EXTERN extern
648#endif
649
650
651
652
653
654
655
656
657GLOBAL_EXTERN struct list_head cifs_tcp_ses_list;
658
659
660
661
662
663
664
665GLOBAL_EXTERN rwlock_t cifs_tcp_ses_lock;
666
667
668
669
670
671
672
673
674GLOBAL_EXTERN rwlock_t GlobalSMBSeslock;
675
676
677GLOBAL_EXTERN struct list_head GlobalDnotifyReqList;
678
679GLOBAL_EXTERN struct list_head GlobalDnotifyRsp_Q;
680
681
682
683
684GLOBAL_EXTERN unsigned int GlobalCurrentXid;
685GLOBAL_EXTERN unsigned int GlobalTotalActiveXid;
686GLOBAL_EXTERN unsigned int GlobalMaxActiveXid;
687GLOBAL_EXTERN spinlock_t GlobalMid_Lock;
688
689GLOBAL_EXTERN char Local_System_Name[15];
690
691
692
693
694GLOBAL_EXTERN atomic_t sesInfoAllocCount;
695GLOBAL_EXTERN atomic_t tconInfoAllocCount;
696GLOBAL_EXTERN atomic_t tcpSesAllocCount;
697GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
698GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
699
700
701GLOBAL_EXTERN atomic_t bufAllocCount;
702#ifdef CONFIG_CIFS_STATS2
703GLOBAL_EXTERN atomic_t totBufAllocCount;
704GLOBAL_EXTERN atomic_t totSmBufAllocCount;
705#endif
706GLOBAL_EXTERN atomic_t smBufAllocCount;
707GLOBAL_EXTERN atomic_t midCount;
708
709
710GLOBAL_EXTERN unsigned int multiuser_mount;
711
712
713
714GLOBAL_EXTERN unsigned int oplockEnabled;
715GLOBAL_EXTERN unsigned int experimEnabled;
716GLOBAL_EXTERN unsigned int lookupCacheEnabled;
717GLOBAL_EXTERN unsigned int extended_security;
718
719GLOBAL_EXTERN unsigned int sign_CIFS_PDUs;
720GLOBAL_EXTERN unsigned int linuxExtEnabled;
721GLOBAL_EXTERN unsigned int CIFSMaxBufSize;
722GLOBAL_EXTERN unsigned int cifs_min_rcv;
723GLOBAL_EXTERN unsigned int cifs_min_small;
724GLOBAL_EXTERN unsigned int cifs_max_pending;
725
726extern const struct slow_work_ops cifs_oplock_break_ops;
727