CIFS: Introduce SMB2 mounts as vers=2.1
[deliverable/linux.git] / fs / cifs / cifsglob.h
1 /*
2 * fs/cifs/cifsglob.h
3 *
4 * Copyright (C) International Business Machines Corp., 2002,2008
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 * Jeremy Allison (jra@samba.org)
7 *
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 * the GNU Lesser General Public License for more details.
17 *
18 */
19 #ifndef _CIFS_GLOB_H
20 #define _CIFS_GLOB_H
21
22 #include <linux/in.h>
23 #include <linux/in6.h>
24 #include <linux/slab.h>
25 #include <linux/workqueue.h>
26 #include "cifs_fs_sb.h"
27 #include "cifsacl.h"
28 #include <crypto/internal/hash.h>
29 #include <linux/scatterlist.h>
30
31 /*
32 * The sizes of various internal tables and strings
33 */
34 #define MAX_UID_INFO 16
35 #define MAX_SES_INFO 2
36 #define MAX_TCON_INFO 4
37
38 #define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1)
39 #define MAX_SERVER_SIZE 15
40 #define MAX_SHARE_SIZE 80
41 #define MAX_USERNAME_SIZE 256 /* reasonable maximum for current servers */
42 #define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */
43
44 #define CIFS_MIN_RCV_POOL 4
45
46 /*
47 * default attribute cache timeout (jiffies)
48 */
49 #define CIFS_DEF_ACTIMEO (1 * HZ)
50
51 /*
52 * max attribute cache timeout (jiffies) - 2^30
53 */
54 #define CIFS_MAX_ACTIMEO (1 << 30)
55
56 /*
57 * MAX_REQ is the maximum number of requests that WE will send
58 * on one socket concurrently.
59 */
60 #define CIFS_MAX_REQ 32767
61
62 #define RFC1001_NAME_LEN 15
63 #define RFC1001_NAME_LEN_WITH_NULL (RFC1001_NAME_LEN + 1)
64
65 /* currently length of NIP6_FMT */
66 #define SERVER_NAME_LENGTH 40
67 #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1)
68
69 /* used to define string lengths for reversing unicode strings */
70 /* (256+1)*2 = 514 */
71 /* (max path length + 1 for null) * 2 for unicode */
72 #define MAX_NAME 514
73
74 #include "cifspdu.h"
75
76 #ifndef XATTR_DOS_ATTRIB
77 #define XATTR_DOS_ATTRIB "user.DOSATTRIB"
78 #endif
79
80 /*
81 * CIFS vfs client Status information (based on what we know.)
82 */
83
84 /* associated with each tcp and smb session */
85 enum statusEnum {
86 CifsNew = 0,
87 CifsGood,
88 CifsExiting,
89 CifsNeedReconnect,
90 CifsNeedNegotiate
91 };
92
93 enum securityEnum {
94 LANMAN = 0, /* Legacy LANMAN auth */
95 NTLM, /* Legacy NTLM012 auth with NTLM hash */
96 NTLMv2, /* Legacy NTLM auth with NTLMv2 hash */
97 RawNTLMSSP, /* NTLMSSP without SPNEGO, NTLMv2 hash */
98 /* NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */
99 Kerberos, /* Kerberos via SPNEGO */
100 };
101
102 enum protocolEnum {
103 TCP = 0,
104 SCTP
105 /* Netbios frames protocol not supported at this time */
106 };
107
108 struct session_key {
109 unsigned int len;
110 char *response;
111 };
112
113 /* crypto security descriptor definition */
114 struct sdesc {
115 struct shash_desc shash;
116 char ctx[];
117 };
118
119 /* crypto hashing related structure/fields, not specific to a sec mech */
120 struct cifs_secmech {
121 struct crypto_shash *hmacmd5; /* hmac-md5 hash function */
122 struct crypto_shash *md5; /* md5 hash function */
123 struct sdesc *sdeschmacmd5; /* ctxt to generate ntlmv2 hash, CR1 */
124 struct sdesc *sdescmd5; /* ctxt to generate cifs/smb signature */
125 };
126
127 /* per smb session structure/fields */
128 struct ntlmssp_auth {
129 __u32 client_flags; /* sent by client in type 1 ntlmsssp exchange */
130 __u32 server_flags; /* sent by server in type 2 ntlmssp exchange */
131 unsigned char ciphertext[CIFS_CPHTXT_SIZE]; /* sent to server */
132 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlmssp */
133 };
134
135 struct cifs_cred {
136 int uid;
137 int gid;
138 int mode;
139 int cecount;
140 struct cifs_sid osid;
141 struct cifs_sid gsid;
142 struct cifs_ntace *ntaces;
143 struct cifs_ace *aces;
144 };
145
146 /*
147 *****************************************************************
148 * Except the CIFS PDUs themselves all the
149 * globally interesting structs should go here
150 *****************************************************************
151 */
152
153 enum smb_version {
154 Smb_1 = 1,
155 Smb_21,
156 };
157
158 struct mid_q_entry;
159 struct TCP_Server_Info;
160 struct cifsFileInfo;
161 struct cifs_ses;
162
163 struct smb_version_operations {
164 int (*send_cancel)(struct TCP_Server_Info *, void *,
165 struct mid_q_entry *);
166 bool (*compare_fids)(struct cifsFileInfo *, struct cifsFileInfo *);
167 /* setup request: allocate mid, sign message */
168 int (*setup_request)(struct cifs_ses *, struct kvec *, unsigned int,
169 struct mid_q_entry **);
170 /* check response: verify signature, map error */
171 int (*check_receive)(struct mid_q_entry *, struct TCP_Server_Info *,
172 bool);
173 void (*add_credits)(struct TCP_Server_Info *, const unsigned int);
174 void (*set_credits)(struct TCP_Server_Info *, const int);
175 int * (*get_credits_field)(struct TCP_Server_Info *);
176 /* data offset from read response message */
177 unsigned int (*read_data_offset)(char *);
178 /* data length from read response message */
179 unsigned int (*read_data_length)(char *);
180 /* map smb to linux error */
181 int (*map_error)(char *, bool);
182 /* find mid corresponding to the response message */
183 struct mid_q_entry * (*find_mid)(struct TCP_Server_Info *, char *);
184 void (*dump_detail)(void *);
185 /* verify the message */
186 int (*check_message)(char *, unsigned int);
187 bool (*is_oplock_break)(char *, struct TCP_Server_Info *);
188 };
189
190 struct smb_version_values {
191 char *version_string;
192 __u32 large_lock_type;
193 __u32 exclusive_lock_type;
194 __u32 shared_lock_type;
195 __u32 unlock_lock_type;
196 size_t header_size;
197 size_t max_header_size;
198 size_t read_rsp_size;
199 };
200
201 #define HEADER_SIZE(server) (server->vals->header_size)
202 #define MAX_HEADER_SIZE(server) (server->vals->max_header_size)
203
204 struct smb_vol {
205 char *username;
206 char *password;
207 char *domainname;
208 char *UNC;
209 char *UNCip;
210 char *iocharset; /* local code page for mapping to and from Unicode */
211 char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */
212 char target_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* srvr nb name */
213 uid_t cred_uid;
214 uid_t linux_uid;
215 gid_t linux_gid;
216 uid_t backupuid;
217 gid_t backupgid;
218 umode_t file_mode;
219 umode_t dir_mode;
220 unsigned secFlg;
221 bool retry:1;
222 bool intr:1;
223 bool setuids:1;
224 bool override_uid:1;
225 bool override_gid:1;
226 bool dynperm:1;
227 bool noperm:1;
228 bool no_psx_acl:1; /* set if posix acl support should be disabled */
229 bool cifs_acl:1;
230 bool backupuid_specified; /* mount option backupuid is specified */
231 bool backupgid_specified; /* mount option backupgid is specified */
232 bool no_xattr:1; /* set if xattr (EA) support should be disabled*/
233 bool server_ino:1; /* use inode numbers from server ie UniqueId */
234 bool direct_io:1;
235 bool strict_io:1; /* strict cache behavior */
236 bool remap:1; /* set to remap seven reserved chars in filenames */
237 bool posix_paths:1; /* unset to not ask for posix pathnames. */
238 bool no_linux_ext:1;
239 bool sfu_emul:1;
240 bool nullauth:1; /* attempt to authenticate with null user */
241 bool nocase:1; /* request case insensitive filenames */
242 bool nobrl:1; /* disable sending byte range locks to srv */
243 bool mand_lock:1; /* send mandatory not posix byte range lock reqs */
244 bool seal:1; /* request transport encryption on share */
245 bool nodfs:1; /* Do not request DFS, even if available */
246 bool local_lease:1; /* check leases only on local system, not remote */
247 bool noblocksnd:1;
248 bool noautotune:1;
249 bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
250 bool fsc:1; /* enable fscache */
251 bool mfsymlinks:1; /* use Minshall+French Symlinks */
252 bool multiuser:1;
253 bool rwpidforward:1; /* pid forward for read/write operations */
254 unsigned int rsize;
255 unsigned int wsize;
256 bool sockopt_tcp_nodelay:1;
257 unsigned short int port;
258 unsigned long actimeo; /* attribute cache timeout (jiffies) */
259 struct smb_version_operations *ops;
260 struct smb_version_values *vals;
261 char *prepath;
262 struct sockaddr_storage srcaddr; /* allow binding to a local IP */
263 struct nls_table *local_nls;
264 };
265
266 #define CIFS_MOUNT_MASK (CIFS_MOUNT_NO_PERM | CIFS_MOUNT_SET_UID | \
267 CIFS_MOUNT_SERVER_INUM | CIFS_MOUNT_DIRECT_IO | \
268 CIFS_MOUNT_NO_XATTR | CIFS_MOUNT_MAP_SPECIAL_CHR | \
269 CIFS_MOUNT_UNX_EMUL | CIFS_MOUNT_NO_BRL | \
270 CIFS_MOUNT_CIFS_ACL | CIFS_MOUNT_OVERR_UID | \
271 CIFS_MOUNT_OVERR_GID | CIFS_MOUNT_DYNPERM | \
272 CIFS_MOUNT_NOPOSIXBRL | CIFS_MOUNT_NOSSYNC | \
273 CIFS_MOUNT_FSCACHE | CIFS_MOUNT_MF_SYMLINKS | \
274 CIFS_MOUNT_MULTIUSER | CIFS_MOUNT_STRICT_IO | \
275 CIFS_MOUNT_CIFS_BACKUPUID | CIFS_MOUNT_CIFS_BACKUPGID)
276
277 #define CIFS_MS_MASK (MS_RDONLY | MS_MANDLOCK | MS_NOEXEC | MS_NOSUID | \
278 MS_NODEV | MS_SYNCHRONOUS)
279
280 struct cifs_mnt_data {
281 struct cifs_sb_info *cifs_sb;
282 struct smb_vol *vol;
283 int flags;
284 };
285
286 static inline unsigned int
287 get_rfc1002_length(void *buf)
288 {
289 return be32_to_cpu(*((__be32 *)buf));
290 }
291
292 struct TCP_Server_Info {
293 struct list_head tcp_ses_list;
294 struct list_head smb_ses_list;
295 int srv_count; /* reference counter */
296 /* 15 character server name + 0x20 16th byte indicating type = srv */
297 char server_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
298 struct smb_version_operations *ops;
299 struct smb_version_values *vals;
300 enum statusEnum tcpStatus; /* what we think the status is */
301 char *hostname; /* hostname portion of UNC string */
302 struct socket *ssocket;
303 struct sockaddr_storage dstaddr;
304 struct sockaddr_storage srcaddr; /* locally bind to this IP */
305 #ifdef CONFIG_NET_NS
306 struct net *net;
307 #endif
308 wait_queue_head_t response_q;
309 wait_queue_head_t request_q; /* if more than maxmpx to srvr must block*/
310 struct list_head pending_mid_q;
311 bool noblocksnd; /* use blocking sendmsg */
312 bool noautotune; /* do not autotune send buf sizes */
313 bool tcp_nodelay;
314 int credits; /* send no more requests at once */
315 unsigned int in_flight; /* number of requests on the wire to server */
316 spinlock_t req_lock; /* protect the two values above */
317 struct mutex srv_mutex;
318 struct task_struct *tsk;
319 char server_GUID[16];
320 char sec_mode;
321 bool session_estab; /* mark when very first sess is established */
322 u16 dialect; /* dialect index that server chose */
323 enum securityEnum secType;
324 bool oplocks:1; /* enable oplocks */
325 unsigned int maxReq; /* Clients should submit no more */
326 /* than maxReq distinct unanswered SMBs to the server when using */
327 /* multiplexed reads or writes */
328 unsigned int maxBuf; /* maxBuf specifies the maximum */
329 /* message size the server can send or receive for non-raw SMBs */
330 /* maxBuf is returned by SMB NegotiateProtocol so maxBuf is only 0 */
331 /* when socket is setup (and during reconnect) before NegProt sent */
332 unsigned int max_rw; /* maxRw specifies the maximum */
333 /* message size the server can send or receive for */
334 /* SMB_COM_WRITE_RAW or SMB_COM_READ_RAW. */
335 unsigned int max_vcs; /* maximum number of smb sessions, at least
336 those that can be specified uniquely with
337 vcnumbers */
338 int capabilities; /* allow selective disabling of caps by smb sess */
339 int timeAdj; /* Adjust for difference in server time zone in sec */
340 __u64 CurrentMid; /* multiplex id - rotating counter */
341 char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
342 /* 16th byte of RFC1001 workstation name is always null */
343 char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
344 __u32 sequence_number; /* for signing, protected by srv_mutex */
345 struct session_key session_key;
346 unsigned long lstrp; /* when we got last response from this server */
347 struct cifs_secmech secmech; /* crypto sec mech functs, descriptors */
348 /* extended security flavors that server supports */
349 bool sec_ntlmssp; /* supports NTLMSSP */
350 bool sec_kerberosu2u; /* supports U2U Kerberos */
351 bool sec_kerberos; /* supports plain Kerberos */
352 bool sec_mskerberos; /* supports legacy MS Kerberos */
353 bool large_buf; /* is current buffer large? */
354 struct delayed_work echo; /* echo ping workqueue job */
355 struct kvec *iov; /* reusable kvec array for receives */
356 unsigned int nr_iov; /* number of kvecs in array */
357 char *smallbuf; /* pointer to current "small" buffer */
358 char *bigbuf; /* pointer to current "big" buffer */
359 unsigned int total_read; /* total amount of data read in this pass */
360 #ifdef CONFIG_CIFS_FSCACHE
361 struct fscache_cookie *fscache; /* client index cache cookie */
362 #endif
363 #ifdef CONFIG_CIFS_STATS2
364 atomic_t in_send; /* requests trying to send */
365 atomic_t num_waiters; /* blocked waiting to get in sendrecv */
366 #endif
367 };
368
369 static inline unsigned int
370 in_flight(struct TCP_Server_Info *server)
371 {
372 unsigned int num;
373 spin_lock(&server->req_lock);
374 num = server->in_flight;
375 spin_unlock(&server->req_lock);
376 return num;
377 }
378
379 static inline bool
380 has_credits(struct TCP_Server_Info *server, int *credits)
381 {
382 int num;
383 spin_lock(&server->req_lock);
384 num = *credits;
385 spin_unlock(&server->req_lock);
386 return num > 0;
387 }
388
389 static inline void
390 add_credits(struct TCP_Server_Info *server, const unsigned int add)
391 {
392 server->ops->add_credits(server, add);
393 }
394
395 static inline void
396 set_credits(struct TCP_Server_Info *server, const int val)
397 {
398 server->ops->set_credits(server, val);
399 }
400
401 /*
402 * Macros to allow the TCP_Server_Info->net field and related code to drop out
403 * when CONFIG_NET_NS isn't set.
404 */
405
406 #ifdef CONFIG_NET_NS
407
408 static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
409 {
410 return srv->net;
411 }
412
413 static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
414 {
415 srv->net = net;
416 }
417
418 #else
419
420 static inline struct net *cifs_net_ns(struct TCP_Server_Info *srv)
421 {
422 return &init_net;
423 }
424
425 static inline void cifs_set_net_ns(struct TCP_Server_Info *srv, struct net *net)
426 {
427 }
428
429 #endif
430
431 /*
432 * Session structure. One of these for each uid session with a particular host
433 */
434 struct cifs_ses {
435 struct list_head smb_ses_list;
436 struct list_head tcon_list;
437 struct mutex session_mutex;
438 struct TCP_Server_Info *server; /* pointer to server info */
439 int ses_count; /* reference counter */
440 enum statusEnum status;
441 unsigned overrideSecFlg; /* if non-zero override global sec flags */
442 __u16 ipc_tid; /* special tid for connection to IPC share */
443 __u16 flags;
444 __u16 vcnum;
445 char *serverOS; /* name of operating system underlying server */
446 char *serverNOS; /* name of network operating system of server */
447 char *serverDomain; /* security realm of server */
448 int Suid; /* remote smb uid */
449 uid_t linux_uid; /* overriding owner of files on the mount */
450 uid_t cred_uid; /* owner of credentials */
451 int capabilities;
452 char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
453 TCP names - will ipv6 and sctp addresses fit? */
454 char *user_name; /* must not be null except during init of sess
455 and after mount option parsing we fill it */
456 char *domainName;
457 char *password;
458 struct session_key auth_key;
459 struct ntlmssp_auth *ntlmssp; /* ciphertext, flags, server challenge */
460 bool need_reconnect:1; /* connection reset, uid now invalid */
461 };
462 /* no more than one of the following three session flags may be set */
463 #define CIFS_SES_NT4 1
464 #define CIFS_SES_OS2 2
465 #define CIFS_SES_W9X 4
466 /* following flag is set for old servers such as OS2 (and Win95?)
467 which do not negotiate NTLM or POSIX dialects, but instead
468 negotiate one of the older LANMAN dialects */
469 #define CIFS_SES_LANMAN 8
470 /*
471 * there is one of these for each connection to a resource on a particular
472 * session
473 */
474 struct cifs_tcon {
475 struct list_head tcon_list;
476 int tc_count;
477 struct list_head openFileList;
478 struct cifs_ses *ses; /* pointer to session associated with */
479 char treeName[MAX_TREE_SIZE + 1]; /* UNC name of resource in ASCII */
480 char *nativeFileSystem;
481 char *password; /* for share-level security */
482 __u16 tid; /* The 2 byte tree id */
483 __u16 Flags; /* optional support bits */
484 enum statusEnum tidStatus;
485 #ifdef CONFIG_CIFS_STATS
486 atomic_t num_smbs_sent;
487 atomic_t num_writes;
488 atomic_t num_reads;
489 atomic_t num_flushes;
490 atomic_t num_oplock_brks;
491 atomic_t num_opens;
492 atomic_t num_closes;
493 atomic_t num_deletes;
494 atomic_t num_mkdirs;
495 atomic_t num_posixopens;
496 atomic_t num_posixmkdirs;
497 atomic_t num_rmdirs;
498 atomic_t num_renames;
499 atomic_t num_t2renames;
500 atomic_t num_ffirst;
501 atomic_t num_fnext;
502 atomic_t num_fclose;
503 atomic_t num_hardlinks;
504 atomic_t num_symlinks;
505 atomic_t num_locks;
506 atomic_t num_acl_get;
507 atomic_t num_acl_set;
508 #ifdef CONFIG_CIFS_STATS2
509 unsigned long long time_writes;
510 unsigned long long time_reads;
511 unsigned long long time_opens;
512 unsigned long long time_deletes;
513 unsigned long long time_closes;
514 unsigned long long time_mkdirs;
515 unsigned long long time_rmdirs;
516 unsigned long long time_renames;
517 unsigned long long time_t2renames;
518 unsigned long long time_ffirst;
519 unsigned long long time_fnext;
520 unsigned long long time_fclose;
521 #endif /* CONFIG_CIFS_STATS2 */
522 __u64 bytes_read;
523 __u64 bytes_written;
524 spinlock_t stat_lock;
525 #endif /* CONFIG_CIFS_STATS */
526 FILE_SYSTEM_DEVICE_INFO fsDevInfo;
527 FILE_SYSTEM_ATTRIBUTE_INFO fsAttrInfo; /* ok if fs name truncated */
528 FILE_SYSTEM_UNIX_INFO fsUnixInfo;
529 bool ipc:1; /* set if connection to IPC$ eg for RPC/PIPES */
530 bool retry:1;
531 bool nocase:1;
532 bool seal:1; /* transport encryption for this mounted share */
533 bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol
534 for this mount even if server would support */
535 bool local_lease:1; /* check leases (only) on local system not remote */
536 bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
537 bool need_reconnect:1; /* connection reset, tid now invalid */
538 #ifdef CONFIG_CIFS_FSCACHE
539 u64 resource_id; /* server resource id */
540 struct fscache_cookie *fscache; /* cookie for share */
541 #endif
542 /* BB add field for back pointer to sb struct(s)? */
543 };
544
545 /*
546 * This is a refcounted and timestamped container for a tcon pointer. The
547 * container holds a tcon reference. It is considered safe to free one of
548 * these when the tl_count goes to 0. The tl_time is the time of the last
549 * "get" on the container.
550 */
551 struct tcon_link {
552 struct rb_node tl_rbnode;
553 uid_t tl_uid;
554 unsigned long tl_flags;
555 #define TCON_LINK_MASTER 0
556 #define TCON_LINK_PENDING 1
557 #define TCON_LINK_IN_TREE 2
558 unsigned long tl_time;
559 atomic_t tl_count;
560 struct cifs_tcon *tl_tcon;
561 };
562
563 extern struct tcon_link *cifs_sb_tlink(struct cifs_sb_info *cifs_sb);
564
565 static inline struct cifs_tcon *
566 tlink_tcon(struct tcon_link *tlink)
567 {
568 return tlink->tl_tcon;
569 }
570
571 extern void cifs_put_tlink(struct tcon_link *tlink);
572
573 static inline struct tcon_link *
574 cifs_get_tlink(struct tcon_link *tlink)
575 {
576 if (tlink && !IS_ERR(tlink))
577 atomic_inc(&tlink->tl_count);
578 return tlink;
579 }
580
581 /* This function is always expected to succeed */
582 extern struct cifs_tcon *cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb);
583
584 /*
585 * This info hangs off the cifsFileInfo structure, pointed to by llist.
586 * This is used to track byte stream locks on the file
587 */
588 struct cifsLockInfo {
589 struct list_head llist; /* pointer to next cifsLockInfo */
590 struct list_head blist; /* pointer to locks blocked on this */
591 wait_queue_head_t block_q;
592 __u64 offset;
593 __u64 length;
594 __u32 pid;
595 __u32 type;
596 };
597
598 /*
599 * One of these for each open instance of a file
600 */
601 struct cifs_search_info {
602 loff_t index_of_last_entry;
603 __u16 entries_in_buffer;
604 __u16 info_level;
605 __u32 resume_key;
606 char *ntwrk_buf_start;
607 char *srch_entries_start;
608 char *last_entry;
609 const char *presume_name;
610 unsigned int resume_name_len;
611 bool endOfSearch:1;
612 bool emptyDir:1;
613 bool unicode:1;
614 bool smallBuf:1; /* so we know which buf_release function to call */
615 };
616
617 struct cifsFileInfo {
618 struct list_head tlist; /* pointer to next fid owned by tcon */
619 struct list_head flist; /* next fid (file instance) for this inode */
620 struct list_head llist; /*
621 * brlocks held by this fid, protected by
622 * lock_mutex from cifsInodeInfo structure
623 */
624 unsigned int uid; /* allows finding which FileInfo structure */
625 __u32 pid; /* process id who opened file */
626 __u16 netfid; /* file id from remote */
627 /* BB add lock scope info here if needed */ ;
628 /* lock scope id (0 if none) */
629 struct dentry *dentry;
630 unsigned int f_flags;
631 struct tcon_link *tlink;
632 bool invalidHandle:1; /* file closed via session abend */
633 bool oplock_break_cancelled:1;
634 int count; /* refcount protected by cifs_file_list_lock */
635 struct mutex fh_mutex; /* prevents reopen race after dead ses*/
636 struct cifs_search_info srch_inf;
637 struct work_struct oplock_break; /* work for oplock breaks */
638 };
639
640 struct cifs_io_parms {
641 __u16 netfid;
642 __u32 pid;
643 __u64 offset;
644 unsigned int length;
645 struct cifs_tcon *tcon;
646 };
647
648 /*
649 * Take a reference on the file private data. Must be called with
650 * cifs_file_list_lock held.
651 */
652 static inline
653 struct cifsFileInfo *cifsFileInfo_get(struct cifsFileInfo *cifs_file)
654 {
655 ++cifs_file->count;
656 return cifs_file;
657 }
658
659 void cifsFileInfo_put(struct cifsFileInfo *cifs_file);
660
661 /*
662 * One of these for each file inode
663 */
664
665 struct cifsInodeInfo {
666 bool can_cache_brlcks;
667 struct mutex lock_mutex; /*
668 * protect the field above and llist
669 * from every cifsFileInfo structure
670 * from openFileList
671 */
672 /* BB add in lists for dirty pages i.e. write caching info for oplock */
673 struct list_head openFileList;
674 __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */
675 bool clientCanCacheRead; /* read oplock */
676 bool clientCanCacheAll; /* read and writebehind oplock */
677 bool delete_pending; /* DELETE_ON_CLOSE is set */
678 bool invalid_mapping; /* pagecache is invalid */
679 unsigned long time; /* jiffies of last update of inode */
680 u64 server_eof; /* current file size on server -- protected by i_lock */
681 u64 uniqueid; /* server inode number */
682 u64 createtime; /* creation time on server */
683 #ifdef CONFIG_CIFS_FSCACHE
684 struct fscache_cookie *fscache;
685 #endif
686 struct inode vfs_inode;
687 };
688
689 static inline struct cifsInodeInfo *
690 CIFS_I(struct inode *inode)
691 {
692 return container_of(inode, struct cifsInodeInfo, vfs_inode);
693 }
694
695 static inline struct cifs_sb_info *
696 CIFS_SB(struct super_block *sb)
697 {
698 return sb->s_fs_info;
699 }
700
701 static inline char CIFS_DIR_SEP(const struct cifs_sb_info *cifs_sb)
702 {
703 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
704 return '/';
705 else
706 return '\\';
707 }
708
709 static inline void
710 convert_delimiter(char *path, char delim)
711 {
712 int i;
713 char old_delim;
714
715 if (path == NULL)
716 return;
717
718 if (delim == '/')
719 old_delim = '\\';
720 else
721 old_delim = '/';
722
723 for (i = 0; path[i] != '\0'; i++) {
724 if (path[i] == old_delim)
725 path[i] = delim;
726 }
727 }
728
729 #ifdef CONFIG_CIFS_STATS
730 #define cifs_stats_inc atomic_inc
731
732 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
733 unsigned int bytes)
734 {
735 if (bytes) {
736 spin_lock(&tcon->stat_lock);
737 tcon->bytes_written += bytes;
738 spin_unlock(&tcon->stat_lock);
739 }
740 }
741
742 static inline void cifs_stats_bytes_read(struct cifs_tcon *tcon,
743 unsigned int bytes)
744 {
745 spin_lock(&tcon->stat_lock);
746 tcon->bytes_read += bytes;
747 spin_unlock(&tcon->stat_lock);
748 }
749 #else
750
751 #define cifs_stats_inc(field) do {} while (0)
752 #define cifs_stats_bytes_written(tcon, bytes) do {} while (0)
753 #define cifs_stats_bytes_read(tcon, bytes) do {} while (0)
754
755 #endif
756
757
758 /*
759 * This is the prototype for the mid receive function. This function is for
760 * receiving the rest of the SMB frame, starting with the WordCount (which is
761 * just after the MID in struct smb_hdr). Note:
762 *
763 * - This will be called by cifsd, with no locks held.
764 * - The mid will still be on the pending_mid_q.
765 * - mid->resp_buf will point to the current buffer.
766 *
767 * Returns zero on a successful receive, or an error. The receive state in
768 * the TCP_Server_Info will also be updated.
769 */
770 typedef int (mid_receive_t)(struct TCP_Server_Info *server,
771 struct mid_q_entry *mid);
772
773 /*
774 * This is the prototype for the mid callback function. This is called once the
775 * mid has been received off of the socket. When creating one, take special
776 * care to avoid deadlocks. Things to bear in mind:
777 *
778 * - it will be called by cifsd, with no locks held
779 * - the mid will be removed from any lists
780 */
781 typedef void (mid_callback_t)(struct mid_q_entry *mid);
782
783 /* one of these for every pending CIFS request to the server */
784 struct mid_q_entry {
785 struct list_head qhead; /* mids waiting on reply from this server */
786 __u64 mid; /* multiplex id */
787 __u32 pid; /* process id */
788 __u32 sequence_number; /* for CIFS signing */
789 unsigned long when_alloc; /* when mid was created */
790 #ifdef CONFIG_CIFS_STATS2
791 unsigned long when_sent; /* time when smb send finished */
792 unsigned long when_received; /* when demux complete (taken off wire) */
793 #endif
794 mid_receive_t *receive; /* call receive callback */
795 mid_callback_t *callback; /* call completion callback */
796 void *callback_data; /* general purpose pointer for callback */
797 void *resp_buf; /* pointer to received SMB header */
798 int mid_state; /* wish this were enum but can not pass to wait_event */
799 __le16 command; /* smb command code */
800 bool large_buf:1; /* if valid response, is pointer to large buf */
801 bool multiRsp:1; /* multiple trans2 responses for one request */
802 bool multiEnd:1; /* both received */
803 };
804
805 /* Make code in transport.c a little cleaner by moving
806 update of optional stats into function below */
807 #ifdef CONFIG_CIFS_STATS2
808
809 static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
810 {
811 atomic_inc(&server->in_send);
812 }
813
814 static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
815 {
816 atomic_dec(&server->in_send);
817 }
818
819 static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
820 {
821 atomic_inc(&server->num_waiters);
822 }
823
824 static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
825 {
826 atomic_dec(&server->num_waiters);
827 }
828
829 static inline void cifs_save_when_sent(struct mid_q_entry *mid)
830 {
831 mid->when_sent = jiffies;
832 }
833 #else
834 static inline void cifs_in_send_inc(struct TCP_Server_Info *server)
835 {
836 }
837 static inline void cifs_in_send_dec(struct TCP_Server_Info *server)
838 {
839 }
840
841 static inline void cifs_num_waiters_inc(struct TCP_Server_Info *server)
842 {
843 }
844
845 static inline void cifs_num_waiters_dec(struct TCP_Server_Info *server)
846 {
847 }
848
849 static inline void cifs_save_when_sent(struct mid_q_entry *mid)
850 {
851 }
852 #endif
853
854 /* for pending dnotify requests */
855 struct dir_notify_req {
856 struct list_head lhead;
857 __le16 Pid;
858 __le16 PidHigh;
859 __u16 Mid;
860 __u16 Tid;
861 __u16 Uid;
862 __u16 netfid;
863 __u32 filter; /* CompletionFilter (for multishot) */
864 int multishot;
865 struct file *pfile;
866 };
867
868 struct dfs_info3_param {
869 int flags; /* DFSREF_REFERRAL_SERVER, DFSREF_STORAGE_SERVER*/
870 int path_consumed;
871 int server_type;
872 int ref_flag;
873 char *path_name;
874 char *node_name;
875 };
876
877 /*
878 * common struct for holding inode info when searching for or updating an
879 * inode with new info
880 */
881
882 #define CIFS_FATTR_DFS_REFERRAL 0x1
883 #define CIFS_FATTR_DELETE_PENDING 0x2
884 #define CIFS_FATTR_NEED_REVAL 0x4
885 #define CIFS_FATTR_INO_COLLISION 0x8
886
887 struct cifs_fattr {
888 u32 cf_flags;
889 u32 cf_cifsattrs;
890 u64 cf_uniqueid;
891 u64 cf_eof;
892 u64 cf_bytes;
893 u64 cf_createtime;
894 uid_t cf_uid;
895 gid_t cf_gid;
896 umode_t cf_mode;
897 dev_t cf_rdev;
898 unsigned int cf_nlink;
899 unsigned int cf_dtype;
900 struct timespec cf_atime;
901 struct timespec cf_mtime;
902 struct timespec cf_ctime;
903 };
904
905 static inline void free_dfs_info_param(struct dfs_info3_param *param)
906 {
907 if (param) {
908 kfree(param->path_name);
909 kfree(param->node_name);
910 kfree(param);
911 }
912 }
913
914 static inline void free_dfs_info_array(struct dfs_info3_param *param,
915 int number_of_items)
916 {
917 int i;
918 if ((number_of_items == 0) || (param == NULL))
919 return;
920 for (i = 0; i < number_of_items; i++) {
921 kfree(param[i].path_name);
922 kfree(param[i].node_name);
923 }
924 kfree(param);
925 }
926
927 #define MID_FREE 0
928 #define MID_REQUEST_ALLOCATED 1
929 #define MID_REQUEST_SUBMITTED 2
930 #define MID_RESPONSE_RECEIVED 4
931 #define MID_RETRY_NEEDED 8 /* session closed while this request out */
932 #define MID_RESPONSE_MALFORMED 0x10
933 #define MID_SHUTDOWN 0x20
934
935 /* Types of response buffer returned from SendReceive2 */
936 #define CIFS_NO_BUFFER 0 /* Response buffer not returned */
937 #define CIFS_SMALL_BUFFER 1
938 #define CIFS_LARGE_BUFFER 2
939 #define CIFS_IOVEC 4 /* array of response buffers */
940
941 /* Type of Request to SendReceive2 */
942 #define CIFS_BLOCKING_OP 1 /* operation can block */
943 #define CIFS_ASYNC_OP 2 /* do not wait for response */
944 #define CIFS_TIMEOUT_MASK 0x003 /* only one of above set in req */
945 #define CIFS_LOG_ERROR 0x010 /* log NT STATUS if non-zero */
946 #define CIFS_LARGE_BUF_OP 0x020 /* large request buffer */
947 #define CIFS_NO_RESP 0x040 /* no response buffer required */
948
949 /* Security Flags: indicate type of session setup needed */
950 #define CIFSSEC_MAY_SIGN 0x00001
951 #define CIFSSEC_MAY_NTLM 0x00002
952 #define CIFSSEC_MAY_NTLMV2 0x00004
953 #define CIFSSEC_MAY_KRB5 0x00008
954 #ifdef CONFIG_CIFS_WEAK_PW_HASH
955 #define CIFSSEC_MAY_LANMAN 0x00010
956 #define CIFSSEC_MAY_PLNTXT 0x00020
957 #else
958 #define CIFSSEC_MAY_LANMAN 0
959 #define CIFSSEC_MAY_PLNTXT 0
960 #endif /* weak passwords */
961 #define CIFSSEC_MAY_SEAL 0x00040 /* not supported yet */
962 #define CIFSSEC_MAY_NTLMSSP 0x00080 /* raw ntlmssp with ntlmv2 */
963
964 #define CIFSSEC_MUST_SIGN 0x01001
965 /* note that only one of the following can be set so the
966 result of setting MUST flags more than once will be to
967 require use of the stronger protocol */
968 #define CIFSSEC_MUST_NTLM 0x02002
969 #define CIFSSEC_MUST_NTLMV2 0x04004
970 #define CIFSSEC_MUST_KRB5 0x08008
971 #ifdef CONFIG_CIFS_WEAK_PW_HASH
972 #define CIFSSEC_MUST_LANMAN 0x10010
973 #define CIFSSEC_MUST_PLNTXT 0x20020
974 #ifdef CONFIG_CIFS_UPCALL
975 #define CIFSSEC_MASK 0xBF0BF /* allows weak security but also krb5 */
976 #else
977 #define CIFSSEC_MASK 0xB70B7 /* current flags supported if weak */
978 #endif /* UPCALL */
979 #else /* do not allow weak pw hash */
980 #define CIFSSEC_MUST_LANMAN 0
981 #define CIFSSEC_MUST_PLNTXT 0
982 #ifdef CONFIG_CIFS_UPCALL
983 #define CIFSSEC_MASK 0x8F08F /* flags supported if no weak allowed */
984 #else
985 #define CIFSSEC_MASK 0x87087 /* flags supported if no weak allowed */
986 #endif /* UPCALL */
987 #endif /* WEAK_PW_HASH */
988 #define CIFSSEC_MUST_SEAL 0x40040 /* not supported yet */
989 #define CIFSSEC_MUST_NTLMSSP 0x80080 /* raw ntlmssp with ntlmv2 */
990
991 #define CIFSSEC_DEF (CIFSSEC_MAY_SIGN | CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2)
992 #define CIFSSEC_MAX (CIFSSEC_MUST_SIGN | CIFSSEC_MUST_NTLMV2)
993 #define CIFSSEC_AUTH_MASK (CIFSSEC_MAY_NTLM | CIFSSEC_MAY_NTLMV2 | CIFSSEC_MAY_LANMAN | CIFSSEC_MAY_PLNTXT | CIFSSEC_MAY_KRB5 | CIFSSEC_MAY_NTLMSSP)
994 /*
995 *****************************************************************
996 * All constants go here
997 *****************************************************************
998 */
999
1000 #define UID_HASH (16)
1001
1002 /*
1003 * Note that ONE module should define _DECLARE_GLOBALS_HERE to cause the
1004 * following to be declared.
1005 */
1006
1007 /****************************************************************************
1008 * Locking notes. All updates to global variables and lists should be
1009 * protected by spinlocks or semaphores.
1010 *
1011 * Spinlocks
1012 * ---------
1013 * GlobalMid_Lock protects:
1014 * list operations on pending_mid_q and oplockQ
1015 * updates to XID counters, multiplex id and SMB sequence numbers
1016 * cifs_file_list_lock protects:
1017 * list operations on tcp and SMB session lists and tCon lists
1018 * f_owner.lock protects certain per file struct operations
1019 * mapping->page_lock protects certain per page operations
1020 *
1021 * Semaphores
1022 * ----------
1023 * sesSem operations on smb session
1024 * tconSem operations on tree connection
1025 * fh_sem file handle reconnection operations
1026 *
1027 ****************************************************************************/
1028
1029 #ifdef DECLARE_GLOBALS_HERE
1030 #define GLOBAL_EXTERN
1031 #else
1032 #define GLOBAL_EXTERN extern
1033 #endif
1034
1035 /*
1036 * the list of TCP_Server_Info structures, ie each of the sockets
1037 * connecting our client to a distinct server (ip address), is
1038 * chained together by cifs_tcp_ses_list. The list of all our SMB
1039 * sessions (and from that the tree connections) can be found
1040 * by iterating over cifs_tcp_ses_list
1041 */
1042 GLOBAL_EXTERN struct list_head cifs_tcp_ses_list;
1043
1044 /*
1045 * This lock protects the cifs_tcp_ses_list, the list of smb sessions per
1046 * tcp session, and the list of tcon's per smb session. It also protects
1047 * the reference counters for the server, smb session, and tcon. Finally,
1048 * changes to the tcon->tidStatus should be done while holding this lock.
1049 */
1050 GLOBAL_EXTERN spinlock_t cifs_tcp_ses_lock;
1051
1052 /*
1053 * This lock protects the cifs_file->llist and cifs_file->flist
1054 * list operations, and updates to some flags (cifs_file->invalidHandle)
1055 * It will be moved to either use the tcon->stat_lock or equivalent later.
1056 * If cifs_tcp_ses_lock and the lock below are both needed to be held, then
1057 * the cifs_tcp_ses_lock must be grabbed first and released last.
1058 */
1059 GLOBAL_EXTERN spinlock_t cifs_file_list_lock;
1060
1061 #ifdef CONFIG_CIFS_DNOTIFY_EXPERIMENTAL /* unused temporarily */
1062 /* Outstanding dir notify requests */
1063 GLOBAL_EXTERN struct list_head GlobalDnotifyReqList;
1064 /* DirNotify response queue */
1065 GLOBAL_EXTERN struct list_head GlobalDnotifyRsp_Q;
1066 #endif /* was needed for dnotify, and will be needed for inotify when VFS fix */
1067
1068 /*
1069 * Global transaction id (XID) information
1070 */
1071 GLOBAL_EXTERN unsigned int GlobalCurrentXid; /* protected by GlobalMid_Sem */
1072 GLOBAL_EXTERN unsigned int GlobalTotalActiveXid; /* prot by GlobalMid_Sem */
1073 GLOBAL_EXTERN unsigned int GlobalMaxActiveXid; /* prot by GlobalMid_Sem */
1074 GLOBAL_EXTERN spinlock_t GlobalMid_Lock; /* protects above & list operations */
1075 /* on midQ entries */
1076 /*
1077 * Global counters, updated atomically
1078 */
1079 GLOBAL_EXTERN atomic_t sesInfoAllocCount;
1080 GLOBAL_EXTERN atomic_t tconInfoAllocCount;
1081 GLOBAL_EXTERN atomic_t tcpSesAllocCount;
1082 GLOBAL_EXTERN atomic_t tcpSesReconnectCount;
1083 GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
1084
1085 /* Various Debug counters */
1086 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
1087 #ifdef CONFIG_CIFS_STATS2
1088 GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
1089 GLOBAL_EXTERN atomic_t totSmBufAllocCount;
1090 #endif
1091 GLOBAL_EXTERN atomic_t smBufAllocCount;
1092 GLOBAL_EXTERN atomic_t midCount;
1093
1094 /* Misc globals */
1095 GLOBAL_EXTERN bool enable_oplocks; /* enable or disable oplocks */
1096 GLOBAL_EXTERN unsigned int lookupCacheEnabled;
1097 GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent
1098 with more secure ntlmssp2 challenge/resp */
1099 GLOBAL_EXTERN unsigned int sign_CIFS_PDUs; /* enable smb packet signing */
1100 GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
1101 GLOBAL_EXTERN unsigned int CIFSMaxBufSize; /* max size not including hdr */
1102 GLOBAL_EXTERN unsigned int cifs_min_rcv; /* min size of big ntwrk buf pool */
1103 GLOBAL_EXTERN unsigned int cifs_min_small; /* min size of small buf pool */
1104 GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/
1105
1106 #ifdef CONFIG_CIFS_ACL
1107 GLOBAL_EXTERN struct rb_root uidtree;
1108 GLOBAL_EXTERN struct rb_root gidtree;
1109 GLOBAL_EXTERN spinlock_t siduidlock;
1110 GLOBAL_EXTERN spinlock_t sidgidlock;
1111 GLOBAL_EXTERN struct rb_root siduidtree;
1112 GLOBAL_EXTERN struct rb_root sidgidtree;
1113 GLOBAL_EXTERN spinlock_t uidsidlock;
1114 GLOBAL_EXTERN spinlock_t gidsidlock;
1115 #endif /* CONFIG_CIFS_ACL */
1116
1117 void cifs_oplock_break(struct work_struct *work);
1118
1119 extern const struct slow_work_ops cifs_oplock_break_ops;
1120 extern struct workqueue_struct *cifsiod_wq;
1121
1122 /* Operations for different SMB versions */
1123 #define SMB1_VERSION_STRING "1.0"
1124 extern struct smb_version_operations smb1_operations;
1125 extern struct smb_version_values smb1_values;
1126 #define SMB21_VERSION_STRING "2.1"
1127 extern struct smb_version_operations smb21_operations;
1128 extern struct smb_version_values smb21_values;
1129 #endif /* _CIFS_GLOB_H */
This page took 0.090696 seconds and 5 git commands to generate.