cifsglob.h 39 KB

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