aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/cifs/asn1.c57
-rw-r--r--fs/cifs/cifs_debug.c1
-rw-r--r--fs/cifs/cifs_fs_sb.h2
-rw-r--r--fs/cifs/cifs_unicode.c2
-rw-r--r--fs/cifs/cifs_unicode.h28
-rw-r--r--fs/cifs/cifs_uniupr.h6
-rw-r--r--fs/cifs/cifsencrypt.c122
-rw-r--r--fs/cifs/cifsfs.c91
-rw-r--r--fs/cifs/cifsfs.h6
-rw-r--r--fs/cifs/cifspdu.h284
-rw-r--r--fs/cifs/cifsproto.h12
-rw-r--r--fs/cifs/cifssmb.c923
-rw-r--r--fs/cifs/connect.c755
-rw-r--r--fs/cifs/export.c12
-rw-r--r--fs/cifs/file.c21
-rw-r--r--fs/cifs/inode.c28
-rw-r--r--fs/cifs/link.c5
-rw-r--r--fs/cifs/md4.c6
-rw-r--r--fs/cifs/misc.c12
-rw-r--r--fs/cifs/netmisc.c2
-rw-r--r--fs/cifs/nterr.h6
-rw-r--r--fs/cifs/readdir.c16
-rw-r--r--fs/cifs/sess.c10
-rw-r--r--fs/cifs/smbdes.c6
-rw-r--r--fs/cifs/smbencrypt.c14
-rw-r--r--fs/cifs/transport.c16
-rw-r--r--fs/cifs/xattr.c2
27 files changed, 1285 insertions, 1160 deletions
diff --git a/fs/cifs/asn1.c b/fs/cifs/asn1.c
index 2e75883b7f54..f50a88d58f78 100644
--- a/fs/cifs/asn1.c
+++ b/fs/cifs/asn1.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * The ASB.1/BER parsing code is derived from ip_nat_snmp_basic.c which was in 2 * The ASB.1/BER parsing code is derived from ip_nat_snmp_basic.c which was in
3 * turn derived from the gxsnmp package by Gregory McLean & Jochen Friedrich 3 * turn derived from the gxsnmp package by Gregory McLean & Jochen Friedrich
4 * 4 *
5 * Copyright (c) 2000 RP Internet (www.rpi.net.au). 5 * Copyright (c) 2000 RP Internet (www.rpi.net.au).
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -80,7 +80,7 @@
80static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 }; 80static unsigned long SPNEGO_OID[7] = { 1, 3, 6, 1, 5, 5, 2 };
81static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 }; 81static unsigned long NTLMSSP_OID[10] = { 1, 3, 6, 1, 4, 1, 311, 2, 2, 10 };
82 82
83/* 83/*
84 * ASN.1 context. 84 * ASN.1 context.
85 */ 85 */
86struct asn1_ctx { 86struct asn1_ctx {
@@ -190,7 +190,7 @@ asn1_header_decode(struct asn1_ctx *ctx,
190 unsigned char **eoc, 190 unsigned char **eoc,
191 unsigned int *cls, unsigned int *con, unsigned int *tag) 191 unsigned int *cls, unsigned int *con, unsigned int *tag)
192{ 192{
193 unsigned int def = 0; 193 unsigned int def = 0;
194 unsigned int len = 0; 194 unsigned int len = 0;
195 195
196 if (!asn1_id_decode(ctx, cls, con, tag)) 196 if (!asn1_id_decode(ctx, cls, con, tag))
@@ -331,7 +331,7 @@ static unsigned char asn1_ulong_decode(struct asn1_ctx *ctx,
331 *integer |= ch; 331 *integer |= ch;
332 } 332 }
333 return 1; 333 return 1;
334} 334}
335 335
336static unsigned char 336static unsigned char
337asn1_octets_decode(struct asn1_ctx *ctx, 337asn1_octets_decode(struct asn1_ctx *ctx,
@@ -376,7 +376,7 @@ asn1_subid_decode(struct asn1_ctx *ctx, unsigned long *subid)
376 return 1; 376 return 1;
377} 377}
378 378
379static int 379static int
380asn1_oid_decode(struct asn1_ctx *ctx, 380asn1_oid_decode(struct asn1_ctx *ctx,
381 unsigned char *eoc, unsigned long **oid, unsigned int *len) 381 unsigned char *eoc, unsigned long **oid, unsigned int *len)
382{ 382{
@@ -459,7 +459,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
459 unsigned int cls, con, tag, oidlen, rc; 459 unsigned int cls, con, tag, oidlen, rc;
460 int use_ntlmssp = FALSE; 460 int use_ntlmssp = FALSE;
461 461
462 *secType = NTLM; /* BB eventually make Kerberos or NLTMSSP the default */ 462 *secType = NTLM; /* BB eventually make Kerberos or NLTMSSP the default*/
463 463
464 /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */ 464 /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */
465 465
@@ -498,7 +498,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
498 return 0; 498 return 0;
499 } else if ((cls != ASN1_CTX) || (con != ASN1_CON) 499 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)
500 || (tag != ASN1_EOC)) { 500 || (tag != ASN1_EOC)) {
501 cFYI(1,("cls = %d con = %d tag = %d end = %p (%d) exit 0", 501 cFYI(1,
502 ("cls = %d con = %d tag = %d end = %p (%d) exit 0",
502 cls, con, tag, end, *end)); 503 cls, con, tag, end, *end));
503 return 0; 504 return 0;
504 } 505 }
@@ -508,7 +509,8 @@ decode_negTokenInit(unsigned char *security_blob, int length,
508 return 0; 509 return 0;
509 } else if ((cls != ASN1_UNI) || (con != ASN1_CON) 510 } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
510 || (tag != ASN1_SEQ)) { 511 || (tag != ASN1_SEQ)) {
511 cFYI(1,("cls = %d con = %d tag = %d end = %p (%d) exit 1", 512 cFYI(1,
513 ("cls = %d con = %d tag = %d end = %p (%d) exit 1",
512 cls, con, tag, end, *end)); 514 cls, con, tag, end, *end));
513 return 0; 515 return 0;
514 } 516 }
@@ -540,32 +542,34 @@ decode_negTokenInit(unsigned char *security_blob, int length,
540 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag); 542 rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
541 if (!rc) { 543 if (!rc) {
542 cFYI(1, 544 cFYI(1,
543 ("Error 1 decoding negTokenInit header exit 2")); 545 ("Error decoding negTokenInit hdr exit2"));
544 return 0; 546 return 0;
545 } 547 }
546 if ((tag == ASN1_OJI) && (con == ASN1_PRI)) { 548 if ((tag == ASN1_OJI) && (con == ASN1_PRI)) {
547 rc = asn1_oid_decode(&ctx, end, &oid, &oidlen); 549 rc = asn1_oid_decode(&ctx, end, &oid, &oidlen);
548 if(rc) { 550 if (rc) {
549 cFYI(1, 551 cFYI(1,
550 ("OID len = %d oid = 0x%lx 0x%lx 0x%lx 0x%lx", 552 ("OID len = %d oid = 0x%lx 0x%lx "
551 oidlen, *oid, *(oid + 1), *(oid + 2), 553 "0x%lx 0x%lx",
552 *(oid + 3))); 554 oidlen, *oid, *(oid + 1),
553 rc = compare_oid(oid, oidlen, NTLMSSP_OID, 555 *(oid + 2), *(oid + 3)));
554 NTLMSSP_OID_LEN); 556 rc = compare_oid(oid, oidlen,
557 NTLMSSP_OID, NTLMSSP_OID_LEN);
555 kfree(oid); 558 kfree(oid);
556 if (rc) 559 if (rc)
557 use_ntlmssp = TRUE; 560 use_ntlmssp = TRUE;
558 } 561 }
559 } else { 562 } else {
560 cFYI(1,("This should be an oid what is going on? ")); 563 cFYI(1, ("Should be an oid what is going on?"));
561 } 564 }
562 } 565 }
563 566
564 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 567 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
565 cFYI(1, 568 cFYI(1,
566 ("Error decoding last part of negTokenInit exit 3")); 569 ("Error decoding last part negTokenInit exit3"));
567 return 0; 570 return 0;
568 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { /* tag = 3 indicating mechListMIC */ 571 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
572 /* tag = 3 indicating mechListMIC */
569 cFYI(1, 573 cFYI(1,
570 ("Exit 4 cls = %d con = %d tag = %d end = %p (%d)", 574 ("Exit 4 cls = %d con = %d tag = %d end = %p (%d)",
571 cls, con, tag, end, *end)); 575 cls, con, tag, end, *end));
@@ -573,7 +577,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
573 } 577 }
574 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 578 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
575 cFYI(1, 579 cFYI(1,
576 ("Error decoding last part of negTokenInit exit 5")); 580 ("Error decoding last part negTokenInit exit5"));
577 return 0; 581 return 0;
578 } else if ((cls != ASN1_UNI) || (con != ASN1_CON) 582 } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
579 || (tag != ASN1_SEQ)) { 583 || (tag != ASN1_SEQ)) {
@@ -584,7 +588,7 @@ decode_negTokenInit(unsigned char *security_blob, int length,
584 588
585 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 589 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
586 cFYI(1, 590 cFYI(1,
587 ("Error decoding last part of negTokenInit exit 7")); 591 ("Error decoding last part negTokenInit exit 7"));
588 return 0; 592 return 0;
589 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) { 593 } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
590 cFYI(1, 594 cFYI(1,
@@ -594,20 +598,21 @@ decode_negTokenInit(unsigned char *security_blob, int length,
594 } 598 }
595 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) { 599 if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
596 cFYI(1, 600 cFYI(1,
597 ("Error decoding last part of negTokenInit exit 9")); 601 ("Error decoding last part negTokenInit exit9"));
598 return 0; 602 return 0;
599 } else if ((cls != ASN1_UNI) || (con != ASN1_PRI) 603 } else if ((cls != ASN1_UNI) || (con != ASN1_PRI)
600 || (tag != ASN1_GENSTR)) { 604 || (tag != ASN1_GENSTR)) {
601 cFYI(1, 605 cFYI(1,
602 ("Exit 10 cls = %d con = %d tag = %d end = %p (%d)", 606 ("Exit10 cls = %d con = %d tag = %d end = %p (%d)",
603 cls, con, tag, end, *end)); 607 cls, con, tag, end, *end));
604 return 0; 608 return 0;
605 } 609 }
606 cFYI(1, ("Need to call asn1_octets_decode() function for this %s", ctx.pointer)); /* is this UTF-8 or ASCII? */ 610 cFYI(1, ("Need to call asn1_octets_decode() function for %s",
611 ctx.pointer)); /* is this UTF-8 or ASCII? */
607 } 612 }
608 613
609 /* if (use_kerberos) 614 /* if (use_kerberos)
610 *secType = Kerberos 615 *secType = Kerberos
611 else */ 616 else */
612 if (use_ntlmssp) { 617 if (use_ntlmssp) {
613 *secType = NTLMSSP; 618 *secType = NTLMSSP;
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 42fafa144f40..1bf8cf522ad6 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -145,7 +145,6 @@ cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
145 (ses->serverNOS == NULL)) { 145 (ses->serverNOS == NULL)) {
146 buf += sprintf(buf, "\nentry for %s not fully " 146 buf += sprintf(buf, "\nentry for %s not fully "
147 "displayed\n\t", ses->serverName); 147 "displayed\n\t", ses->serverName);
148
149 } else { 148 } else {
150 length = 149 length =
151 sprintf(buf, 150 sprintf(buf,
diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h
index 4cc2012e9322..34af556cdd8d 100644
--- a/fs/cifs/cifs_fs_sb.h
+++ b/fs/cifs/cifs_fs_sb.h
@@ -43,6 +43,6 @@ struct cifs_sb_info {
43 mode_t mnt_dir_mode; 43 mode_t mnt_dir_mode;
44 int mnt_cifs_flags; 44 int mnt_cifs_flags;
45 int prepathlen; 45 int prepathlen;
46 char * prepath; 46 char *prepath;
47}; 47};
48#endif /* _CIFS_FS_SB_H */ 48#endif /* _CIFS_FS_SB_H */
diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c
index 701e9a9185f2..b5903b89250d 100644
--- a/fs/cifs/cifs_unicode.c
+++ b/fs/cifs/cifs_unicode.c
@@ -66,7 +66,7 @@ cifs_strtoUCS(__le16 * to, const char *from, int len,
66{ 66{
67 int charlen; 67 int charlen;
68 int i; 68 int i;
69 wchar_t * wchar_to = (wchar_t *)to; /* needed to quiet sparse */ 69 wchar_t *wchar_to = (wchar_t *)to; /* needed to quiet sparse */
70 70
71 for (i = 0; len && *from; i++, from += charlen, len -= charlen) { 71 for (i = 0; len && *from; i++, from += charlen, len -= charlen) {
72 72
diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h
index 274e412ec17c..614c11fcdcb6 100644
--- a/fs/cifs/cifs_unicode.h
+++ b/fs/cifs/cifs_unicode.h
@@ -70,7 +70,7 @@ int cifs_strtoUCS(__le16 *, const char *, int, const struct nls_table *);
70 * Address of the first string 70 * Address of the first string
71 */ 71 */
72static inline wchar_t * 72static inline wchar_t *
73UniStrcat(wchar_t * ucs1, const wchar_t * ucs2) 73UniStrcat(wchar_t *ucs1, const wchar_t *ucs2)
74{ 74{
75 wchar_t *anchor = ucs1; /* save a pointer to start of ucs1 */ 75 wchar_t *anchor = ucs1; /* save a pointer to start of ucs1 */
76 76
@@ -88,7 +88,7 @@ UniStrcat(wchar_t * ucs1, const wchar_t * ucs2)
88 * or NULL if the character is not in the string 88 * or NULL if the character is not in the string
89 */ 89 */
90static inline wchar_t * 90static inline wchar_t *
91UniStrchr(const wchar_t * ucs, wchar_t uc) 91UniStrchr(const wchar_t *ucs, wchar_t uc)
92{ 92{
93 while ((*ucs != uc) && *ucs) 93 while ((*ucs != uc) && *ucs)
94 ucs++; 94 ucs++;
@@ -107,7 +107,7 @@ UniStrchr(const wchar_t * ucs, wchar_t uc)
107 * > 0: First string is greater than second 107 * > 0: First string is greater than second
108 */ 108 */
109static inline int 109static inline int
110UniStrcmp(const wchar_t * ucs1, const wchar_t * ucs2) 110UniStrcmp(const wchar_t *ucs1, const wchar_t *ucs2)
111{ 111{
112 while ((*ucs1 == *ucs2) && *ucs1) { 112 while ((*ucs1 == *ucs2) && *ucs1) {
113 ucs1++; 113 ucs1++;
@@ -120,7 +120,7 @@ UniStrcmp(const wchar_t * ucs1, const wchar_t * ucs2)
120 * UniStrcpy: Copy a string 120 * UniStrcpy: Copy a string
121 */ 121 */
122static inline wchar_t * 122static inline wchar_t *
123UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2) 123UniStrcpy(wchar_t *ucs1, const wchar_t *ucs2)
124{ 124{
125 wchar_t *anchor = ucs1; /* save the start of result string */ 125 wchar_t *anchor = ucs1; /* save the start of result string */
126 126
@@ -132,7 +132,7 @@ UniStrcpy(wchar_t * ucs1, const wchar_t * ucs2)
132 * UniStrlen: Return the length of a string (in 16 bit Unicode chars not bytes) 132 * UniStrlen: Return the length of a string (in 16 bit Unicode chars not bytes)
133 */ 133 */
134static inline size_t 134static inline size_t
135UniStrlen(const wchar_t * ucs1) 135UniStrlen(const wchar_t *ucs1)
136{ 136{
137 int i = 0; 137 int i = 0;
138 138
@@ -146,7 +146,7 @@ UniStrlen(const wchar_t * ucs1)
146 * string (length limited) 146 * string (length limited)
147 */ 147 */
148static inline size_t 148static inline size_t
149UniStrnlen(const wchar_t * ucs1, int maxlen) 149UniStrnlen(const wchar_t *ucs1, int maxlen)
150{ 150{
151 int i = 0; 151 int i = 0;
152 152
@@ -162,7 +162,7 @@ UniStrnlen(const wchar_t * ucs1, int maxlen)
162 * UniStrncat: Concatenate length limited string 162 * UniStrncat: Concatenate length limited string
163 */ 163 */
164static inline wchar_t * 164static inline wchar_t *
165UniStrncat(wchar_t * ucs1, const wchar_t * ucs2, size_t n) 165UniStrncat(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
166{ 166{
167 wchar_t *anchor = ucs1; /* save pointer to string 1 */ 167 wchar_t *anchor = ucs1; /* save pointer to string 1 */
168 168
@@ -180,7 +180,7 @@ UniStrncat(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
180 * UniStrncmp: Compare length limited string 180 * UniStrncmp: Compare length limited string
181 */ 181 */
182static inline int 182static inline int
183UniStrncmp(const wchar_t * ucs1, const wchar_t * ucs2, size_t n) 183UniStrncmp(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
184{ 184{
185 if (!n) 185 if (!n)
186 return 0; /* Null strings are equal */ 186 return 0; /* Null strings are equal */
@@ -195,7 +195,7 @@ UniStrncmp(const wchar_t * ucs1, const wchar_t * ucs2, size_t n)
195 * UniStrncmp_le: Compare length limited string - native to little-endian 195 * UniStrncmp_le: Compare length limited string - native to little-endian
196 */ 196 */
197static inline int 197static inline int
198UniStrncmp_le(const wchar_t * ucs1, const wchar_t * ucs2, size_t n) 198UniStrncmp_le(const wchar_t *ucs1, const wchar_t *ucs2, size_t n)
199{ 199{
200 if (!n) 200 if (!n)
201 return 0; /* Null strings are equal */ 201 return 0; /* Null strings are equal */
@@ -210,7 +210,7 @@ UniStrncmp_le(const wchar_t * ucs1, const wchar_t * ucs2, size_t n)
210 * UniStrncpy: Copy length limited string with pad 210 * UniStrncpy: Copy length limited string with pad
211 */ 211 */
212static inline wchar_t * 212static inline wchar_t *
213UniStrncpy(wchar_t * ucs1, const wchar_t * ucs2, size_t n) 213UniStrncpy(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
214{ 214{
215 wchar_t *anchor = ucs1; 215 wchar_t *anchor = ucs1;
216 216
@@ -227,7 +227,7 @@ UniStrncpy(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
227 * UniStrncpy_le: Copy length limited string with pad to little-endian 227 * UniStrncpy_le: Copy length limited string with pad to little-endian
228 */ 228 */
229static inline wchar_t * 229static inline wchar_t *
230UniStrncpy_le(wchar_t * ucs1, const wchar_t * ucs2, size_t n) 230UniStrncpy_le(wchar_t *ucs1, const wchar_t *ucs2, size_t n)
231{ 231{
232 wchar_t *anchor = ucs1; 232 wchar_t *anchor = ucs1;
233 233
@@ -248,7 +248,7 @@ UniStrncpy_le(wchar_t * ucs1, const wchar_t * ucs2, size_t n)
248 * NULL if no matching string is found 248 * NULL if no matching string is found
249 */ 249 */
250static inline wchar_t * 250static inline wchar_t *
251UniStrstr(const wchar_t * ucs1, const wchar_t * ucs2) 251UniStrstr(const wchar_t *ucs1, const wchar_t *ucs2)
252{ 252{
253 const wchar_t *anchor1 = ucs1; 253 const wchar_t *anchor1 = ucs1;
254 const wchar_t *anchor2 = ucs2; 254 const wchar_t *anchor2 = ucs2;
@@ -298,7 +298,7 @@ UniToupper(register wchar_t uc)
298 * UniStrupr: Upper case a unicode string 298 * UniStrupr: Upper case a unicode string
299 */ 299 */
300static inline wchar_t * 300static inline wchar_t *
301UniStrupr(register wchar_t * upin) 301UniStrupr(register wchar_t *upin)
302{ 302{
303 register wchar_t *up; 303 register wchar_t *up;
304 304
@@ -339,7 +339,7 @@ UniTolower(wchar_t uc)
339 * UniStrlwr: Lower case a unicode string 339 * UniStrlwr: Lower case a unicode string
340 */ 340 */
341static inline wchar_t * 341static inline wchar_t *
342UniStrlwr(register wchar_t * upin) 342UniStrlwr(register wchar_t *upin)
343{ 343{
344 register wchar_t *up; 344 register wchar_t *up;
345 345
diff --git a/fs/cifs/cifs_uniupr.h b/fs/cifs/cifs_uniupr.h
index ac622e77e7e6..18a9d978e519 100644
--- a/fs/cifs/cifs_uniupr.h
+++ b/fs/cifs/cifs_uniupr.h
@@ -5,14 +5,14 @@
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or 6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. 7 * (at your option) any later version.
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details. 12 * the GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 17 *
18 * uniupr.h - Unicode compressed case ranges 18 * uniupr.h - Unicode compressed case ranges
@@ -53,7 +53,7 @@ signed char CifsUniUpperTable[512] = {
53 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, /* 1a0-1af */ 53 0, -1, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, /* 1a0-1af */
54 -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, /* 1b0-1bf */ 54 -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, 0, -1, 0, 0, /* 1b0-1bf */
55 0, 0, 0, 0, 0, -1, -2, 0, -1, -2, 0, -1, -2, 0, -1, 0, /* 1c0-1cf */ 55 0, 0, 0, 0, 0, -1, -2, 0, -1, -2, 0, -1, -2, 0, -1, 0, /* 1c0-1cf */
56 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -79, 0, -1, /* 1d0-1df */ 56 -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, -79, 0, -1, /* 1d0-1df */
57 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e0-1ef */ 57 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, 0, -1, /* 1e0-1ef */
58 0, 0, -1, -2, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, /* 1f0-1ff */ 58 0, 0, -1, -2, 0, -1, 0, 0, 0, -1, 0, -1, 0, -1, 0, -1, /* 1f0-1ff */
59}; 59};
diff --git a/fs/cifs/cifsencrypt.c b/fs/cifs/cifsencrypt.c
index 860dc49ba79c..be012a17278a 100644
--- a/fs/cifs/cifsencrypt.c
+++ b/fs/cifs/cifsencrypt.c
@@ -39,7 +39,7 @@ extern void mdfour(unsigned char *out, unsigned char *in, int n);
39extern void E_md4hash(const unsigned char *passwd, unsigned char *p16); 39extern void E_md4hash(const unsigned char *passwd, unsigned char *p16);
40extern void SMBencrypt(unsigned char *passwd, unsigned char *c8, 40extern void SMBencrypt(unsigned char *passwd, unsigned char *c8,
41 unsigned char *p24); 41 unsigned char *p24);
42 42
43static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, 43static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu,
44 const struct mac_key *key, char *signature) 44 const struct mac_key *key, char *signature)
45{ 45{
@@ -69,10 +69,10 @@ int cifs_sign_smb(struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server,
69 return rc; 69 return rc;
70 70
71 spin_lock(&GlobalMid_Lock); 71 spin_lock(&GlobalMid_Lock);
72 cifs_pdu->Signature.Sequence.SequenceNumber = 72 cifs_pdu->Signature.Sequence.SequenceNumber =
73 cpu_to_le32(server->sequence_number); 73 cpu_to_le32(server->sequence_number);
74 cifs_pdu->Signature.Sequence.Reserved = 0; 74 cifs_pdu->Signature.Sequence.Reserved = 0;
75 75
76 *pexpected_response_sequence_number = server->sequence_number++; 76 *pexpected_response_sequence_number = server->sequence_number++;
77 server->sequence_number++; 77 server->sequence_number++;
78 spin_unlock(&GlobalMid_Lock); 78 spin_unlock(&GlobalMid_Lock);
@@ -98,9 +98,9 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
98 98
99 MD5Init(&context); 99 MD5Init(&context);
100 MD5Update(&context, (char *)&key->data, key->len); 100 MD5Update(&context, (char *)&key->data, key->len);
101 for (i=0;i<n_vec;i++) { 101 for (i = 0; i < n_vec; i++) {
102 if (iov[i].iov_base == NULL) { 102 if (iov[i].iov_base == NULL) {
103 cERROR(1 ,("null iovec entry")); 103 cERROR(1, ("null iovec entry"));
104 return -EIO; 104 return -EIO;
105 } else if (iov[i].iov_len == 0) 105 } else if (iov[i].iov_len == 0)
106 break; /* bail out if we are sent nothing to sign */ 106 break; /* bail out if we are sent nothing to sign */
@@ -167,36 +167,38 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
167 return 0; 167 return 0;
168 168
169 if (cifs_pdu->Command == SMB_COM_LOCKING_ANDX) { 169 if (cifs_pdu->Command == SMB_COM_LOCKING_ANDX) {
170 struct smb_com_lock_req * pSMB = 170 struct smb_com_lock_req *pSMB =
171 (struct smb_com_lock_req *)cifs_pdu; 171 (struct smb_com_lock_req *)cifs_pdu;
172 if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE) 172 if (pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE)
173 return 0; 173 return 0;
174 } 174 }
175 175
176 /* BB what if signatures are supposed to be on for session but server does not 176 /* BB what if signatures are supposed to be on for session but
177 send one? BB */ 177 server does not send one? BB */
178 178
179 /* Do not need to verify session setups with signature "BSRSPYL " */ 179 /* Do not need to verify session setups with signature "BSRSPYL " */
180 if(memcmp(cifs_pdu->Signature.SecuritySignature,"BSRSPYL ",8)==0) 180 if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0)
181 cFYI(1,("dummy signature received for smb command 0x%x",cifs_pdu->Command)); 181 cFYI(1, ("dummy signature received for smb command 0x%x",
182 cifs_pdu->Command));
182 183
183 /* save off the origiginal signature so we can modify the smb and check 184 /* save off the origiginal signature so we can modify the smb and check
184 its signature against what the server sent */ 185 its signature against what the server sent */
185 memcpy(server_response_sig,cifs_pdu->Signature.SecuritySignature,8); 186 memcpy(server_response_sig, cifs_pdu->Signature.SecuritySignature, 8);
186 187
187 cifs_pdu->Signature.Sequence.SequenceNumber = cpu_to_le32(expected_sequence_number); 188 cifs_pdu->Signature.Sequence.SequenceNumber =
189 cpu_to_le32(expected_sequence_number);
188 cifs_pdu->Signature.Sequence.Reserved = 0; 190 cifs_pdu->Signature.Sequence.Reserved = 0;
189 191
190 rc = cifs_calculate_signature(cifs_pdu, mac_key, 192 rc = cifs_calculate_signature(cifs_pdu, mac_key,
191 what_we_think_sig_should_be); 193 what_we_think_sig_should_be);
192 194
193 if(rc) 195 if (rc)
194 return rc; 196 return rc;
195 197
196 198/* cifs_dump_mem("what we think it should be: ",
197/* cifs_dump_mem("what we think it should be: ",what_we_think_sig_should_be,16); */ 199 what_we_think_sig_should_be, 16); */
198 200
199 if(memcmp(server_response_sig, what_we_think_sig_should_be, 8)) 201 if (memcmp(server_response_sig, what_we_think_sig_should_be, 8))
200 return -EACCES; 202 return -EACCES;
201 else 203 else
202 return 0; 204 return 0;
@@ -218,30 +220,30 @@ int cifs_calculate_mac_key(struct mac_key *key, const char *rn,
218 return 0; 220 return 0;
219} 221}
220 222
221int CalcNTLMv2_partial_mac_key(struct cifsSesInfo * ses, 223int CalcNTLMv2_partial_mac_key(struct cifsSesInfo *ses,
222 const struct nls_table * nls_info) 224 const struct nls_table *nls_info)
223{ 225{
224 char temp_hash[16]; 226 char temp_hash[16];
225 struct HMACMD5Context ctx; 227 struct HMACMD5Context ctx;
226 char * ucase_buf; 228 char *ucase_buf;
227 __le16 * unicode_buf; 229 __le16 *unicode_buf;
228 unsigned int i,user_name_len,dom_name_len; 230 unsigned int i, user_name_len, dom_name_len;
229 231
230 if(ses == NULL) 232 if (ses == NULL)
231 return -EINVAL; 233 return -EINVAL;
232 234
233 E_md4hash(ses->password, temp_hash); 235 E_md4hash(ses->password, temp_hash);
234 236
235 hmac_md5_init_limK_to_64(temp_hash, 16, &ctx); 237 hmac_md5_init_limK_to_64(temp_hash, 16, &ctx);
236 user_name_len = strlen(ses->userName); 238 user_name_len = strlen(ses->userName);
237 if(user_name_len > MAX_USERNAME_SIZE) 239 if (user_name_len > MAX_USERNAME_SIZE)
238 return -EINVAL; 240 return -EINVAL;
239 if(ses->domainName == NULL) 241 if (ses->domainName == NULL)
240 return -EINVAL; /* BB should we use CIFS_LINUX_DOM */ 242 return -EINVAL; /* BB should we use CIFS_LINUX_DOM */
241 dom_name_len = strlen(ses->domainName); 243 dom_name_len = strlen(ses->domainName);
242 if (dom_name_len > MAX_USERNAME_SIZE) 244 if (dom_name_len > MAX_USERNAME_SIZE)
243 return -EINVAL; 245 return -EINVAL;
244 246
245 ucase_buf = kmalloc((MAX_USERNAME_SIZE+1), GFP_KERNEL); 247 ucase_buf = kmalloc((MAX_USERNAME_SIZE+1), GFP_KERNEL);
246 if (ucase_buf == NULL) 248 if (ucase_buf == NULL)
247 return -ENOMEM; 249 return -ENOMEM;
@@ -250,18 +252,20 @@ int CalcNTLMv2_partial_mac_key(struct cifsSesInfo * ses,
250 kfree(ucase_buf); 252 kfree(ucase_buf);
251 return -ENOMEM; 253 return -ENOMEM;
252 } 254 }
253 255
254 for (i = 0;i < user_name_len; i++) 256 for (i = 0; i < user_name_len; i++)
255 ucase_buf[i] = nls_info->charset2upper[(int)ses->userName[i]]; 257 ucase_buf[i] = nls_info->charset2upper[(int)ses->userName[i]];
256 ucase_buf[i] = 0; 258 ucase_buf[i] = 0;
257 user_name_len = cifs_strtoUCS(unicode_buf, ucase_buf, MAX_USERNAME_SIZE*2, nls_info); 259 user_name_len = cifs_strtoUCS(unicode_buf, ucase_buf,
260 MAX_USERNAME_SIZE*2, nls_info);
258 unicode_buf[user_name_len] = 0; 261 unicode_buf[user_name_len] = 0;
259 user_name_len++; 262 user_name_len++;
260 263
261 for (i = 0; i < dom_name_len; i++) 264 for (i = 0; i < dom_name_len; i++)
262 ucase_buf[i] = nls_info->charset2upper[(int)ses->domainName[i]]; 265 ucase_buf[i] = nls_info->charset2upper[(int)ses->domainName[i]];
263 ucase_buf[i] = 0; 266 ucase_buf[i] = 0;
264 dom_name_len = cifs_strtoUCS(unicode_buf+user_name_len, ucase_buf, MAX_USERNAME_SIZE*2, nls_info); 267 dom_name_len = cifs_strtoUCS(unicode_buf+user_name_len, ucase_buf,
268 MAX_USERNAME_SIZE*2, nls_info);
265 269
266 unicode_buf[user_name_len + dom_name_len] = 0; 270 unicode_buf[user_name_len + dom_name_len] = 0;
267 hmac_md5_update((const unsigned char *) unicode_buf, 271 hmac_md5_update((const unsigned char *) unicode_buf,
@@ -274,21 +278,22 @@ int CalcNTLMv2_partial_mac_key(struct cifsSesInfo * ses,
274} 278}
275 279
276#ifdef CONFIG_CIFS_WEAK_PW_HASH 280#ifdef CONFIG_CIFS_WEAK_PW_HASH
277void calc_lanman_hash(struct cifsSesInfo * ses, char * lnm_session_key) 281void calc_lanman_hash(struct cifsSesInfo *ses, char *lnm_session_key)
278{ 282{
279 int i; 283 int i;
280 char password_with_pad[CIFS_ENCPWD_SIZE]; 284 char password_with_pad[CIFS_ENCPWD_SIZE];
281 285
282 if(ses->server == NULL) 286 if (ses->server == NULL)
283 return; 287 return;
284 288
285 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE); 289 memset(password_with_pad, 0, CIFS_ENCPWD_SIZE);
286 if(ses->password) 290 if (ses->password)
287 strncpy(password_with_pad, ses->password, CIFS_ENCPWD_SIZE); 291 strncpy(password_with_pad, ses->password, CIFS_ENCPWD_SIZE);
288 292
289 if((ses->server->secMode & SECMODE_PW_ENCRYPT) == 0) 293 if ((ses->server->secMode & SECMODE_PW_ENCRYPT) == 0)
290 if(extended_security & CIFSSEC_MAY_PLNTXT) { 294 if (extended_security & CIFSSEC_MAY_PLNTXT) {
291 memcpy(lnm_session_key, password_with_pad, CIFS_ENCPWD_SIZE); 295 memcpy(lnm_session_key, password_with_pad,
296 CIFS_ENCPWD_SIZE);
292 return; 297 return;
293 } 298 }
294 299
@@ -303,7 +308,7 @@ void calc_lanman_hash(struct cifsSesInfo * ses, char * lnm_session_key)
303 utf8 and other multibyte codepages each need their own strupper 308 utf8 and other multibyte codepages each need their own strupper
304 function since a byte at a time will ont work. */ 309 function since a byte at a time will ont work. */
305 310
306 for(i = 0; i < CIFS_ENCPWD_SIZE; i++) { 311 for (i = 0; i < CIFS_ENCPWD_SIZE; i++) {
307 password_with_pad[i] = toupper(password_with_pad[i]); 312 password_with_pad[i] = toupper(password_with_pad[i]);
308 } 313 }
309 314
@@ -313,19 +318,19 @@ void calc_lanman_hash(struct cifsSesInfo * ses, char * lnm_session_key)
313} 318}
314#endif /* CIFS_WEAK_PW_HASH */ 319#endif /* CIFS_WEAK_PW_HASH */
315 320
316static int calc_ntlmv2_hash(struct cifsSesInfo *ses, 321static int calc_ntlmv2_hash(struct cifsSesInfo *ses,
317 const struct nls_table * nls_cp) 322 const struct nls_table *nls_cp)
318{ 323{
319 int rc = 0; 324 int rc = 0;
320 int len; 325 int len;
321 char nt_hash[16]; 326 char nt_hash[16];
322 struct HMACMD5Context * pctxt; 327 struct HMACMD5Context *pctxt;
323 wchar_t * user; 328 wchar_t *user;
324 wchar_t * domain; 329 wchar_t *domain;
325 330
326 pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL); 331 pctxt = kmalloc(sizeof(struct HMACMD5Context), GFP_KERNEL);
327 332
328 if(pctxt == NULL) 333 if (pctxt == NULL)
329 return -ENOMEM; 334 return -ENOMEM;
330 335
331 /* calculate md4 hash of password */ 336 /* calculate md4 hash of password */
@@ -337,18 +342,18 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses,
337 /* convert ses->userName to unicode and uppercase */ 342 /* convert ses->userName to unicode and uppercase */
338 len = strlen(ses->userName); 343 len = strlen(ses->userName);
339 user = kmalloc(2 + (len * 2), GFP_KERNEL); 344 user = kmalloc(2 + (len * 2), GFP_KERNEL);
340 if(user == NULL) 345 if (user == NULL)
341 goto calc_exit_2; 346 goto calc_exit_2;
342 len = cifs_strtoUCS(user, ses->userName, len, nls_cp); 347 len = cifs_strtoUCS(user, ses->userName, len, nls_cp);
343 UniStrupr(user); 348 UniStrupr(user);
344 hmac_md5_update((char *)user, 2*len, pctxt); 349 hmac_md5_update((char *)user, 2*len, pctxt);
345 350
346 /* convert ses->domainName to unicode and uppercase */ 351 /* convert ses->domainName to unicode and uppercase */
347 if(ses->domainName) { 352 if (ses->domainName) {
348 len = strlen(ses->domainName); 353 len = strlen(ses->domainName);
349 354
350 domain = kmalloc(2 + (len * 2), GFP_KERNEL); 355 domain = kmalloc(2 + (len * 2), GFP_KERNEL);
351 if(domain == NULL) 356 if (domain == NULL)
352 goto calc_exit_1; 357 goto calc_exit_1;
353 len = cifs_strtoUCS(domain, ses->domainName, len, nls_cp); 358 len = cifs_strtoUCS(domain, ses->domainName, len, nls_cp);
354 /* the following line was removed since it didn't work well 359 /* the following line was removed since it didn't work well
@@ -357,24 +362,24 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses,
357 /* UniStrupr(domain); */ 362 /* UniStrupr(domain); */
358 363
359 hmac_md5_update((char *)domain, 2*len, pctxt); 364 hmac_md5_update((char *)domain, 2*len, pctxt);
360 365
361 kfree(domain); 366 kfree(domain);
362 } 367 }
363calc_exit_1: 368calc_exit_1:
364 kfree(user); 369 kfree(user);
365calc_exit_2: 370calc_exit_2:
366 /* BB FIXME what about bytes 24 through 40 of the signing key? 371 /* BB FIXME what about bytes 24 through 40 of the signing key?
367 compare with the NTLM example */ 372 compare with the NTLM example */
368 hmac_md5_final(ses->server->ntlmv2_hash, pctxt); 373 hmac_md5_final(ses->server->ntlmv2_hash, pctxt);
369 374
370 return rc; 375 return rc;
371} 376}
372 377
373void setup_ntlmv2_rsp(struct cifsSesInfo * ses, char * resp_buf, 378void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,
374 const struct nls_table * nls_cp) 379 const struct nls_table *nls_cp)
375{ 380{
376 int rc; 381 int rc;
377 struct ntlmv2_resp * buf = (struct ntlmv2_resp *)resp_buf; 382 struct ntlmv2_resp *buf = (struct ntlmv2_resp *)resp_buf;
378 struct HMACMD5Context context; 383 struct HMACMD5Context context;
379 384
380 buf->blob_signature = cpu_to_le32(0x00000101); 385 buf->blob_signature = cpu_to_le32(0x00000101);
@@ -389,8 +394,8 @@ void setup_ntlmv2_rsp(struct cifsSesInfo * ses, char * resp_buf,
389 394
390 /* calculate buf->ntlmv2_hash */ 395 /* calculate buf->ntlmv2_hash */
391 rc = calc_ntlmv2_hash(ses, nls_cp); 396 rc = calc_ntlmv2_hash(ses, nls_cp);
392 if(rc) 397 if (rc)
393 cERROR(1,("could not get v2 hash rc %d",rc)); 398 cERROR(1, ("could not get v2 hash rc %d", rc));
394 CalcNTLMv2_response(ses, resp_buf); 399 CalcNTLMv2_response(ses, resp_buf);
395 400
396 /* now calculate the MAC key for NTLMv2 */ 401 /* now calculate the MAC key for NTLMv2 */
@@ -403,16 +408,17 @@ void setup_ntlmv2_rsp(struct cifsSesInfo * ses, char * resp_buf,
403 ses->server->mac_signing_key.len = 16 + sizeof(struct ntlmv2_resp); 408 ses->server->mac_signing_key.len = 16 + sizeof(struct ntlmv2_resp);
404} 409}
405 410
406void CalcNTLMv2_response(const struct cifsSesInfo * ses, char * v2_session_response) 411void CalcNTLMv2_response(const struct cifsSesInfo *ses,
412 char *v2_session_response)
407{ 413{
408 struct HMACMD5Context context; 414 struct HMACMD5Context context;
409 /* rest of v2 struct already generated */ 415 /* rest of v2 struct already generated */
410 memcpy(v2_session_response + 8, ses->server->cryptKey,8); 416 memcpy(v2_session_response + 8, ses->server->cryptKey, 8);
411 hmac_md5_init_limK_to_64(ses->server->ntlmv2_hash, 16, &context); 417 hmac_md5_init_limK_to_64(ses->server->ntlmv2_hash, 16, &context);
412 418
413 hmac_md5_update(v2_session_response+8, 419 hmac_md5_update(v2_session_response+8,
414 sizeof(struct ntlmv2_resp) - 8, &context); 420 sizeof(struct ntlmv2_resp) - 8, &context);
415 421
416 hmac_md5_final(v2_session_response,&context); 422 hmac_md5_final(v2_session_response, &context);
417/* cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); */ 423/* cifs_dump_mem("v2_sess_rsp: ", v2_session_response, 32); */
418} 424}
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 40f35f0263ac..8ebd887205bb 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -95,7 +95,7 @@ cifs_read_super(struct super_block *sb, void *data,
95 struct inode *inode; 95 struct inode *inode;
96 struct cifs_sb_info *cifs_sb; 96 struct cifs_sb_info *cifs_sb;
97 int rc = 0; 97 int rc = 0;
98 98
99 /* BB should we make this contingent on mount parm? */ 99 /* BB should we make this contingent on mount parm? */
100 sb->s_flags |= MS_NODIRATIME | MS_NOATIME; 100 sb->s_flags |= MS_NODIRATIME | MS_NOATIME;
101 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL); 101 sb->s_fs_info = kzalloc(sizeof(struct cifs_sb_info), GFP_KERNEL);
@@ -135,7 +135,7 @@ cifs_read_super(struct super_block *sb, void *data,
135 rc = -ENOMEM; 135 rc = -ENOMEM;
136 goto out_no_root; 136 goto out_no_root;
137 } 137 }
138 138
139#ifdef CONFIG_CIFS_EXPERIMENTAL 139#ifdef CONFIG_CIFS_EXPERIMENTAL
140 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) { 140 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
141 cFYI(1, ("export ops supported")); 141 cFYI(1, ("export ops supported"));
@@ -153,7 +153,7 @@ out_no_root:
153out_mount_failed: 153out_mount_failed:
154 if (cifs_sb) { 154 if (cifs_sb) {
155 if (cifs_sb->local_nls) 155 if (cifs_sb->local_nls)
156 unload_nls(cifs_sb->local_nls); 156 unload_nls(cifs_sb->local_nls);
157 kfree(cifs_sb); 157 kfree(cifs_sb);
158 } 158 }
159 return rc; 159 return rc;
@@ -230,7 +230,7 @@ cifs_statfs(struct dentry *dentry, struct kstatfs *buf)
230 longer available? */ 230 longer available? */
231} 231}
232 232
233static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd) 233static int cifs_permission(struct inode *inode, int mask, struct nameidata *nd)
234{ 234{
235 struct cifs_sb_info *cifs_sb; 235 struct cifs_sb_info *cifs_sb;
236 236
@@ -238,10 +238,10 @@ static int cifs_permission(struct inode * inode, int mask, struct nameidata *nd)
238 238
239 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) { 239 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) {
240 return 0; 240 return 0;
241 } else /* file mode might have been restricted at mount time 241 } else /* file mode might have been restricted at mount time
242 on the client (above and beyond ACL on servers) for 242 on the client (above and beyond ACL on servers) for
243 servers which do not support setting and viewing mode bits, 243 servers which do not support setting and viewing mode bits,
244 so allowing client to check permissions is useful */ 244 so allowing client to check permissions is useful */
245 return generic_permission(inode, mask, NULL); 245 return generic_permission(inode, mask, NULL);
246} 246}
247 247
@@ -270,7 +270,7 @@ cifs_alloc_inode(struct super_block *sb)
270 cifs_inode->clientCanCacheRead = FALSE; 270 cifs_inode->clientCanCacheRead = FALSE;
271 cifs_inode->clientCanCacheAll = FALSE; 271 cifs_inode->clientCanCacheAll = FALSE;
272 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ 272 cifs_inode->vfs_inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
273 273
274 /* Can not set i_flags here - they get immediately overwritten 274 /* Can not set i_flags here - they get immediately overwritten
275 to zero by the VFS */ 275 to zero by the VFS */
276/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/ 276/* cifs_inode->vfs_inode.i_flags = S_NOATIME | S_NOCMTIME;*/
@@ -317,21 +317,21 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
317 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) || 317 if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID) ||
318 !(cifs_sb->tcon->ses->capabilities & CAP_UNIX)) 318 !(cifs_sb->tcon->ses->capabilities & CAP_UNIX))
319 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid); 319 seq_printf(s, ",gid=%d", cifs_sb->mnt_gid);
320 seq_printf(s, ",rsize=%d",cifs_sb->rsize); 320 seq_printf(s, ",rsize=%d", cifs_sb->rsize);
321 seq_printf(s, ",wsize=%d",cifs_sb->wsize); 321 seq_printf(s, ",wsize=%d", cifs_sb->wsize);
322 } 322 }
323 return 0; 323 return 0;
324} 324}
325 325
326#ifdef CONFIG_CIFS_QUOTA 326#ifdef CONFIG_CIFS_QUOTA
327int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid, 327int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
328 struct fs_disk_quota * pdquota) 328 struct fs_disk_quota *pdquota)
329{ 329{
330 int xid; 330 int xid;
331 int rc = 0; 331 int rc = 0;
332 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 332 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
333 struct cifsTconInfo *pTcon; 333 struct cifsTconInfo *pTcon;
334 334
335 if (cifs_sb) 335 if (cifs_sb)
336 pTcon = cifs_sb->tcon; 336 pTcon = cifs_sb->tcon;
337 else 337 else
@@ -340,7 +340,7 @@ int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
340 340
341 xid = GetXid(); 341 xid = GetXid();
342 if (pTcon) { 342 if (pTcon) {
343 cFYI(1,("set type: 0x%x id: %d",quota_type,qid)); 343 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
344 } else { 344 } else {
345 return -EIO; 345 return -EIO;
346 } 346 }
@@ -349,8 +349,8 @@ int cifs_xquota_set(struct super_block * sb, int quota_type, qid_t qid,
349 return rc; 349 return rc;
350} 350}
351 351
352int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid, 352int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
353 struct fs_disk_quota * pdquota) 353 struct fs_disk_quota *pdquota)
354{ 354{
355 int xid; 355 int xid;
356 int rc = 0; 356 int rc = 0;
@@ -364,7 +364,7 @@ int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
364 364
365 xid = GetXid(); 365 xid = GetXid();
366 if (pTcon) { 366 if (pTcon) {
367 cFYI(1,("set type: 0x%x id: %d",quota_type,qid)); 367 cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
368 } else { 368 } else {
369 rc = -EIO; 369 rc = -EIO;
370 } 370 }
@@ -373,9 +373,9 @@ int cifs_xquota_get(struct super_block * sb, int quota_type, qid_t qid,
373 return rc; 373 return rc;
374} 374}
375 375
376int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation) 376int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
377{ 377{
378 int xid; 378 int xid;
379 int rc = 0; 379 int rc = 0;
380 struct cifs_sb_info *cifs_sb = CIFS_SB(sb); 380 struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
381 struct cifsTconInfo *pTcon; 381 struct cifsTconInfo *pTcon;
@@ -387,7 +387,7 @@ int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
387 387
388 xid = GetXid(); 388 xid = GetXid();
389 if (pTcon) { 389 if (pTcon) {
390 cFYI(1,("flags: 0x%x operation: 0x%x",flags,operation)); 390 cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
391 } else { 391 } else {
392 rc = -EIO; 392 rc = -EIO;
393 } 393 }
@@ -396,7 +396,7 @@ int cifs_xstate_set(struct super_block * sb, unsigned int flags, int operation)
396 return rc; 396 return rc;
397} 397}
398 398
399int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats) 399int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
400{ 400{
401 int xid; 401 int xid;
402 int rc = 0; 402 int rc = 0;
@@ -410,7 +410,7 @@ int cifs_xstate_get(struct super_block * sb, struct fs_quota_stat *qstats)
410 } 410 }
411 xid = GetXid(); 411 xid = GetXid();
412 if (pTcon) { 412 if (pTcon) {
413 cFYI(1,("pqstats %p",qstats)); 413 cFYI(1, ("pqstats %p", qstats));
414 } else { 414 } else {
415 rc = -EIO; 415 rc = -EIO;
416 } 416 }
@@ -427,10 +427,10 @@ static struct quotactl_ops cifs_quotactl_ops = {
427}; 427};
428#endif 428#endif
429 429
430static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags) 430static void cifs_umount_begin(struct vfsmount *vfsmnt, int flags)
431{ 431{
432 struct cifs_sb_info *cifs_sb; 432 struct cifs_sb_info *cifs_sb;
433 struct cifsTconInfo * tcon; 433 struct cifsTconInfo *tcon;
434 434
435 if (!(flags & MNT_FORCE)) 435 if (!(flags & MNT_FORCE))
436 return; 436 return;
@@ -448,9 +448,8 @@ static void cifs_umount_begin(struct vfsmount * vfsmnt, int flags)
448 448
449 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */ 449 /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
450 /* cancel_notify_requests(tcon); */ 450 /* cancel_notify_requests(tcon); */
451 if (tcon->ses && tcon->ses->server) 451 if (tcon->ses && tcon->ses->server) {
452 { 452 cFYI(1, ("wake up tasks now - umount begin not complete"));
453 cFYI(1,("wake up tasks now - umount begin not complete"));
454 wake_up_all(&tcon->ses->server->request_q); 453 wake_up_all(&tcon->ses->server->request_q);
455 wake_up_all(&tcon->ses->server->response_q); 454 wake_up_all(&tcon->ses->server->response_q);
456 msleep(1); /* yield */ 455 msleep(1); /* yield */
@@ -483,10 +482,11 @@ static const struct super_operations cifs_super_ops = {
483 .statfs = cifs_statfs, 482 .statfs = cifs_statfs,
484 .alloc_inode = cifs_alloc_inode, 483 .alloc_inode = cifs_alloc_inode,
485 .destroy_inode = cifs_destroy_inode, 484 .destroy_inode = cifs_destroy_inode,
486/* .drop_inode = generic_delete_inode, 485/* .drop_inode = generic_delete_inode,
487 .delete_inode = cifs_delete_inode, *//* Do not need the above two functions 486 .delete_inode = cifs_delete_inode, */ /* Do not need above two
488 unless later we add lazy close of inodes or unless the kernel forgets to call 487 functions unless later we add lazy close of inodes or unless the
489 us with the same number of releases (closes) as opens */ 488 kernel forgets to call us with the same number of releases (closes)
489 as opens */
490 .show_options = cifs_show_options, 490 .show_options = cifs_show_options,
491 .umount_begin = cifs_umount_begin, 491 .umount_begin = cifs_umount_begin,
492 .remount_fs = cifs_remount, 492 .remount_fs = cifs_remount,
@@ -589,11 +589,11 @@ const struct inode_operations cifs_file_inode_ops = {
589 .getxattr = cifs_getxattr, 589 .getxattr = cifs_getxattr,
590 .listxattr = cifs_listxattr, 590 .listxattr = cifs_listxattr,
591 .removexattr = cifs_removexattr, 591 .removexattr = cifs_removexattr,
592#endif 592#endif
593}; 593};
594 594
595const struct inode_operations cifs_symlink_inode_ops = { 595const struct inode_operations cifs_symlink_inode_ops = {
596 .readlink = generic_readlink, 596 .readlink = generic_readlink,
597 .follow_link = cifs_follow_link, 597 .follow_link = cifs_follow_link,
598 .put_link = cifs_put_link, 598 .put_link = cifs_put_link,
599 .permission = cifs_permission, 599 .permission = cifs_permission,
@@ -605,7 +605,7 @@ const struct inode_operations cifs_symlink_inode_ops = {
605 .getxattr = cifs_getxattr, 605 .getxattr = cifs_getxattr,
606 .listxattr = cifs_listxattr, 606 .listxattr = cifs_listxattr,
607 .removexattr = cifs_removexattr, 607 .removexattr = cifs_removexattr,
608#endif 608#endif
609}; 609};
610 610
611const struct file_operations cifs_file_ops = { 611const struct file_operations cifs_file_ops = {
@@ -631,7 +631,7 @@ const struct file_operations cifs_file_ops = {
631}; 631};
632 632
633const struct file_operations cifs_file_direct_ops = { 633const struct file_operations cifs_file_direct_ops = {
634 /* no mmap, no aio, no readv - 634 /* no mmap, no aio, no readv -
635 BB reevaluate whether they can be done with directio, no cache */ 635 BB reevaluate whether they can be done with directio, no cache */
636 .read = cifs_user_read, 636 .read = cifs_user_read,
637 .write = cifs_user_write, 637 .write = cifs_user_write,
@@ -671,7 +671,7 @@ const struct file_operations cifs_file_nobrl_ops = {
671}; 671};
672 672
673const struct file_operations cifs_file_direct_nobrl_ops = { 673const struct file_operations cifs_file_direct_nobrl_ops = {
674 /* no mmap, no aio, no readv - 674 /* no mmap, no aio, no readv -
675 BB reevaluate whether they can be done with directio, no cache */ 675 BB reevaluate whether they can be done with directio, no cache */
676 .read = cifs_user_read, 676 .read = cifs_user_read,
677 .write = cifs_user_write, 677 .write = cifs_user_write,
@@ -696,11 +696,11 @@ const struct file_operations cifs_dir_ops = {
696#ifdef CONFIG_CIFS_EXPERIMENTAL 696#ifdef CONFIG_CIFS_EXPERIMENTAL
697 .dir_notify = cifs_dir_notify, 697 .dir_notify = cifs_dir_notify,
698#endif /* CONFIG_CIFS_EXPERIMENTAL */ 698#endif /* CONFIG_CIFS_EXPERIMENTAL */
699 .ioctl = cifs_ioctl, 699 .ioctl = cifs_ioctl,
700}; 700};
701 701
702static void 702static void
703cifs_init_once(void *inode, struct kmem_cache * cachep, unsigned long flags) 703cifs_init_once(void *inode, struct kmem_cache *cachep, unsigned long flags)
704{ 704{
705 struct cifsInodeInfo *cifsi = inode; 705 struct cifsInodeInfo *cifsi = inode;
706 706
@@ -752,7 +752,7 @@ cifs_init_request_bufs(void)
752 cifs_min_rcv = 1; 752 cifs_min_rcv = 1;
753 else if (cifs_min_rcv > 64) { 753 else if (cifs_min_rcv > 64) {
754 cifs_min_rcv = 64; 754 cifs_min_rcv = 64;
755 cERROR(1,("cifs_min_rcv set to maximum (64)")); 755 cERROR(1, ("cifs_min_rcv set to maximum (64)"));
756 } 756 }
757 757
758 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv, 758 cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
@@ -765,7 +765,7 @@ cifs_init_request_bufs(void)
765 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and 765 /* MAX_CIFS_SMALL_BUFFER_SIZE bytes is enough for most SMB responses and
766 almost all handle based requests (but not write response, nor is it 766 almost all handle based requests (but not write response, nor is it
767 sufficient for path based requests). A smaller size would have 767 sufficient for path based requests). A smaller size would have
768 been more efficient (compacting multiple slab items on one 4k page) 768 been more efficient (compacting multiple slab items on one 4k page)
769 for the case in which debug was on, but this larger size allows 769 for the case in which debug was on, but this larger size allows
770 more SMBs to use small buffer alloc and is still much more 770 more SMBs to use small buffer alloc and is still much more
771 efficient to alloc 1 per page off the slab compared to 17K (5page) 771 efficient to alloc 1 per page off the slab compared to 17K (5page)
@@ -844,7 +844,7 @@ cifs_destroy_mids(void)
844 kmem_cache_destroy(cifs_oplock_cachep); 844 kmem_cache_destroy(cifs_oplock_cachep);
845} 845}
846 846
847static int cifs_oplock_thread(void * dummyarg) 847static int cifs_oplock_thread(void *dummyarg)
848{ 848{
849 struct oplock_q_entry *oplock_item; 849 struct oplock_q_entry *oplock_item;
850 struct cifsTconInfo *pTcon; 850 struct cifsTconInfo *pTcon;
@@ -855,7 +855,7 @@ static int cifs_oplock_thread(void * dummyarg)
855 do { 855 do {
856 if (try_to_freeze()) 856 if (try_to_freeze())
857 continue; 857 continue;
858 858
859 spin_lock(&GlobalMid_Lock); 859 spin_lock(&GlobalMid_Lock);
860 if (list_empty(&GlobalOplock_Q)) { 860 if (list_empty(&GlobalOplock_Q)) {
861 spin_unlock(&GlobalMid_Lock); 861 spin_unlock(&GlobalMid_Lock);
@@ -865,7 +865,7 @@ static int cifs_oplock_thread(void * dummyarg)
865 oplock_item = list_entry(GlobalOplock_Q.next, 865 oplock_item = list_entry(GlobalOplock_Q.next,
866 struct oplock_q_entry, qhead); 866 struct oplock_q_entry, qhead);
867 if (oplock_item) { 867 if (oplock_item) {
868 cFYI(1,("found oplock item to write out")); 868 cFYI(1, ("found oplock item to write out"));
869 pTcon = oplock_item->tcon; 869 pTcon = oplock_item->tcon;
870 inode = oplock_item->pinode; 870 inode = oplock_item->pinode;
871 netfid = oplock_item->netfid; 871 netfid = oplock_item->netfid;
@@ -878,7 +878,8 @@ static int cifs_oplock_thread(void * dummyarg)
878 /* mutex_lock(&inode->i_mutex);*/ 878 /* mutex_lock(&inode->i_mutex);*/
879 if (S_ISREG(inode->i_mode)) { 879 if (S_ISREG(inode->i_mode)) {
880 rc = filemap_fdatawrite(inode->i_mapping); 880 rc = filemap_fdatawrite(inode->i_mapping);
881 if (CIFS_I(inode)->clientCanCacheRead == 0) { 881 if (CIFS_I(inode)->clientCanCacheRead
882 == 0) {
882 filemap_fdatawait(inode->i_mapping); 883 filemap_fdatawait(inode->i_mapping);
883 invalidate_remote_inode(inode); 884 invalidate_remote_inode(inode);
884 } 885 }
@@ -913,7 +914,7 @@ static int cifs_oplock_thread(void * dummyarg)
913 return 0; 914 return 0;
914} 915}
915 916
916static int cifs_dnotify_thread(void * dummyarg) 917static int cifs_dnotify_thread(void *dummyarg)
917{ 918{
918 struct list_head *tmp; 919 struct list_head *tmp;
919 struct cifsSesInfo *ses; 920 struct cifsSesInfo *ses;
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index ee8ab87f27aa..a20de77a3856 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -45,7 +45,7 @@ extern void cifs_read_inode(struct inode *);
45extern const struct inode_operations cifs_dir_inode_ops; 45extern const struct inode_operations cifs_dir_inode_ops;
46extern int cifs_create(struct inode *, struct dentry *, int, 46extern int cifs_create(struct inode *, struct dentry *, int,
47 struct nameidata *); 47 struct nameidata *);
48extern struct dentry * cifs_lookup(struct inode *, struct dentry *, 48extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
49 struct nameidata *); 49 struct nameidata *);
50extern int cifs_unlink(struct inode *, struct dentry *); 50extern int cifs_unlink(struct inode *, struct dentry *);
51extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *); 51extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *);
@@ -70,9 +70,9 @@ extern int cifs_open(struct inode *inode, struct file *file);
70extern int cifs_close(struct inode *inode, struct file *file); 70extern int cifs_close(struct inode *inode, struct file *file);
71extern int cifs_closedir(struct inode *inode, struct file *file); 71extern int cifs_closedir(struct inode *inode, struct file *file);
72extern ssize_t cifs_user_read(struct file *file, char __user *read_data, 72extern ssize_t cifs_user_read(struct file *file, char __user *read_data,
73 size_t read_size, loff_t * poffset); 73 size_t read_size, loff_t *poffset);
74extern ssize_t cifs_user_write(struct file *file, const char __user *write_data, 74extern ssize_t cifs_user_write(struct file *file, const char __user *write_data,
75 size_t write_size, loff_t * poffset); 75 size_t write_size, loff_t *poffset);
76extern int cifs_lock(struct file *, int, struct file_lock *); 76extern int cifs_lock(struct file *, int, struct file_lock *);
77extern int cifs_fsync(struct file *, struct dentry *, int); 77extern int cifs_fsync(struct file *, struct dentry *, int);
78extern int cifs_flush(struct file *, fl_owner_t id); 78extern int cifs_flush(struct file *, fl_owner_t id);
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index 802d27d98e2d..9044d9886f0d 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -144,7 +144,7 @@
144#define SMBOPEN_OAPPEND 0x0001 144#define SMBOPEN_OAPPEND 0x0001
145 145
146/* 146/*
147 * SMB flag definitions 147 * SMB flag definitions
148 */ 148 */
149#define SMBFLG_EXTD_LOCK 0x01 /* server supports lock-read write-unlock smb */ 149#define SMBFLG_EXTD_LOCK 0x01 /* server supports lock-read write-unlock smb */
150#define SMBFLG_RCV_POSTED 0x02 /* obsolete */ 150#define SMBFLG_RCV_POSTED 0x02 /* obsolete */
@@ -157,9 +157,9 @@
157#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */ 157#define SMBFLG_RESPONSE 0x80 /* this PDU is a response from server */
158 158
159/* 159/*
160 * SMB flag2 definitions 160 * SMB flag2 definitions
161 */ 161 */
162#define SMBFLG2_KNOWS_LONG_NAMES cpu_to_le16(1) /* can send long (non-8.3) 162#define SMBFLG2_KNOWS_LONG_NAMES cpu_to_le16(1) /* can send long (non-8.3)
163 path names in response */ 163 path names in response */
164#define SMBFLG2_KNOWS_EAS cpu_to_le16(2) 164#define SMBFLG2_KNOWS_EAS cpu_to_le16(2)
165#define SMBFLG2_SECURITY_SIGNATURE cpu_to_le16(4) 165#define SMBFLG2_SECURITY_SIGNATURE cpu_to_le16(4)
@@ -260,7 +260,7 @@
260#define ATTR_SPARSE 0x0200 260#define ATTR_SPARSE 0x0200
261#define ATTR_REPARSE 0x0400 261#define ATTR_REPARSE 0x0400
262#define ATTR_COMPRESSED 0x0800 262#define ATTR_COMPRESSED 0x0800
263#define ATTR_OFFLINE 0x1000 /* ie file not immediately available - 263#define ATTR_OFFLINE 0x1000 /* ie file not immediately available -
264 on offline storage */ 264 on offline storage */
265#define ATTR_NOT_CONTENT_INDEXED 0x2000 265#define ATTR_NOT_CONTENT_INDEXED 0x2000
266#define ATTR_ENCRYPTED 0x4000 266#define ATTR_ENCRYPTED 0x4000
@@ -300,7 +300,7 @@
300#define CREATE_DELETE_ON_CLOSE 0x00001000 300#define CREATE_DELETE_ON_CLOSE 0x00001000
301#define CREATE_OPEN_BY_ID 0x00002000 301#define CREATE_OPEN_BY_ID 0x00002000
302#define OPEN_REPARSE_POINT 0x00200000 302#define OPEN_REPARSE_POINT 0x00200000
303#define CREATE_OPTIONS_MASK 0x007FFFFF 303#define CREATE_OPTIONS_MASK 0x007FFFFF
304#define CREATE_OPTION_SPECIAL 0x20000000 /* system. NB not sent over wire */ 304#define CREATE_OPTION_SPECIAL 0x20000000 /* system. NB not sent over wire */
305 305
306/* ImpersonationLevel flags */ 306/* ImpersonationLevel flags */
@@ -366,17 +366,19 @@ struct smb_hdr {
366#define pByteArea(smb_var) ((unsigned char *)smb_var + sizeof(struct smb_hdr) + (2* smb_var->WordCount) + 2 ) 366#define pByteArea(smb_var) ((unsigned char *)smb_var + sizeof(struct smb_hdr) + (2* smb_var->WordCount) + 2 )
367 367
368/* 368/*
369 * Computer Name Length 369 * Computer Name Length (since Netbios name was length 16 with last byte 0x20)
370 * No longer as important, now that TCP names are more commonly used to
371 * resolve hosts.
370 */ 372 */
371#define CNLEN 15 373#define CNLEN 15
372 374
373/* 375/*
374 * Share Name Length @S8A 376 * Share Name Length (SNLEN)
375 * Note: This length is limited by the SMB used to get @S8A 377 * Note: This length was limited by the SMB used to get
376 * the Share info. NetShareEnum only returns 13 @S8A 378 * the Share info. NetShareEnum only returned 13
377 * chars, including the null termination. @S8A 379 * chars, including the null termination.
380 * This was removed because it no longer is limiting.
378 */ 381 */
379#define SNLEN 12 /*@S8A */
380 382
381/* 383/*
382 * Comment Length 384 * Comment Length
@@ -394,8 +396,8 @@ struct smb_hdr {
394 * 396 *
395 * The Naming convention is the lower case version of the 397 * The Naming convention is the lower case version of the
396 * smb command code name for the struct and this is typedef to the 398 * smb command code name for the struct and this is typedef to the
397 * uppercase version of the same name with the prefix SMB_ removed 399 * uppercase version of the same name with the prefix SMB_ removed
398 * for brevity. Although typedefs are not commonly used for 400 * for brevity. Although typedefs are not commonly used for
399 * structure definitions in the Linux kernel, their use in the 401 * structure definitions in the Linux kernel, their use in the
400 * CIFS standards document, which this code is based on, may 402 * CIFS standards document, which this code is based on, may
401 * make this one of the cases where typedefs for structures make 403 * make this one of the cases where typedefs for structures make
@@ -403,7 +405,7 @@ struct smb_hdr {
403 * Typedefs can always be removed later if they are too distracting 405 * Typedefs can always be removed later if they are too distracting
404 * and they are only used for the CIFSs PDUs themselves, not 406 * and they are only used for the CIFSs PDUs themselves, not
405 * internal cifs vfs structures 407 * internal cifs vfs structures
406 * 408 *
407 */ 409 */
408 410
409typedef struct negotiate_req { 411typedef struct negotiate_req {
@@ -511,7 +513,7 @@ typedef union smb_com_session_setup_andx {
511 unsigned char SecurityBlob[1]; /* followed by */ 513 unsigned char SecurityBlob[1]; /* followed by */
512 /* STRING NativeOS */ 514 /* STRING NativeOS */
513 /* STRING NativeLanMan */ 515 /* STRING NativeLanMan */
514 } __attribute__((packed)) req; /* NTLM request format (with 516 } __attribute__((packed)) req; /* NTLM request format (with
515 extended security */ 517 extended security */
516 518
517 struct { /* request format */ 519 struct { /* request format */
@@ -549,7 +551,7 @@ typedef union smb_com_session_setup_andx {
549/* unsigned char * NativeOS; */ 551/* unsigned char * NativeOS; */
550/* unsigned char * NativeLanMan; */ 552/* unsigned char * NativeLanMan; */
551/* unsigned char * PrimaryDomain; */ 553/* unsigned char * PrimaryDomain; */
552 } __attribute__((packed)) resp; /* NTLM response 554 } __attribute__((packed)) resp; /* NTLM response
553 (with or without extended sec) */ 555 (with or without extended sec) */
554 556
555 struct { /* request format */ 557 struct { /* request format */
@@ -618,7 +620,7 @@ struct ntlmv2_resp {
618#define CAP_NT_SMBS 0x00000010 620#define CAP_NT_SMBS 0x00000010
619#define CAP_STATUS32 0x00000040 621#define CAP_STATUS32 0x00000040
620#define CAP_LEVEL_II_OPLOCKS 0x00000080 622#define CAP_LEVEL_II_OPLOCKS 0x00000080
621#define CAP_NT_FIND 0x00000200 /* reserved should be zero 623#define CAP_NT_FIND 0x00000200 /* reserved should be zero
622 (because NT_SMBs implies the same thing?) */ 624 (because NT_SMBs implies the same thing?) */
623#define CAP_BULK_TRANSFER 0x20000000 625#define CAP_BULK_TRANSFER 0x20000000
624#define CAP_EXTENDED_SECURITY 0x80000000 626#define CAP_EXTENDED_SECURITY 0x80000000
@@ -676,7 +678,7 @@ typedef struct smb_com_logoff_andx_rsp {
676 __u16 ByteCount; 678 __u16 ByteCount;
677} __attribute__((packed)) LOGOFF_ANDX_RSP; 679} __attribute__((packed)) LOGOFF_ANDX_RSP;
678 680
679typedef union smb_com_tree_disconnect { /* as an altetnative can use flag on 681typedef union smb_com_tree_disconnect { /* as an altetnative can use flag on
680 tree_connect PDU to effect disconnect */ 682 tree_connect PDU to effect disconnect */
681 /* tdis is probably simplest SMB PDU */ 683 /* tdis is probably simplest SMB PDU */
682 struct { 684 struct {
@@ -800,27 +802,28 @@ typedef struct smb_com_openx_rsp {
800 __u32 FileId; 802 __u32 FileId;
801 __u16 Reserved; 803 __u16 Reserved;
802 __u16 ByteCount; 804 __u16 ByteCount;
803} __attribute__((packed)) OPENX_RSP; 805} __attribute__((packed)) OPENX_RSP;
804 806
805/* For encoding of POSIX Open Request - see trans2 function 0x209 data struct */ 807/* For encoding of POSIX Open Request - see trans2 function 0x209 data struct */
806 808
807/* Legacy write request for older servers */ 809/* Legacy write request for older servers */
808typedef struct smb_com_writex_req { 810typedef struct smb_com_writex_req {
809 struct smb_hdr hdr; /* wct = 12 */ 811 struct smb_hdr hdr; /* wct = 12 */
810 __u8 AndXCommand; 812 __u8 AndXCommand;
811 __u8 AndXReserved; 813 __u8 AndXReserved;
812 __le16 AndXOffset; 814 __le16 AndXOffset;
813 __u16 Fid; 815 __u16 Fid;
814 __le32 OffsetLow; 816 __le32 OffsetLow;
815 __u32 Reserved; /* Timeout */ 817 __u32 Reserved; /* Timeout */
816 __le16 WriteMode; /* 1 = write through */ 818 __le16 WriteMode; /* 1 = write through */
817 __le16 Remaining; 819 __le16 Remaining;
818 __le16 Reserved2; 820 __le16 Reserved2;
819 __le16 DataLengthLow; 821 __le16 DataLengthLow;
820 __le16 DataOffset; 822 __le16 DataOffset;
821 __le16 ByteCount; 823 __le16 ByteCount;
822 __u8 Pad; /* BB check for whether padded to DWORD boundary and optimum performance here */ 824 __u8 Pad; /* BB check for whether padded to DWORD
823 char Data[0]; 825 boundary and optimum performance here */
826 char Data[0];
824} __attribute__((packed)) WRITEX_REQ; 827} __attribute__((packed)) WRITEX_REQ;
825 828
826typedef struct smb_com_write_req { 829typedef struct smb_com_write_req {
@@ -838,7 +841,8 @@ typedef struct smb_com_write_req {
838 __le16 DataOffset; 841 __le16 DataOffset;
839 __le32 OffsetHigh; 842 __le32 OffsetHigh;
840 __le16 ByteCount; 843 __le16 ByteCount;
841 __u8 Pad; /* BB check for whether padded to DWORD boundary and optimum performance here */ 844 __u8 Pad; /* BB check for whether padded to DWORD
845 boundary and optimum performance here */
842 char Data[0]; 846 char Data[0];
843} __attribute__((packed)) WRITE_REQ; 847} __attribute__((packed)) WRITE_REQ;
844 848
@@ -856,17 +860,17 @@ typedef struct smb_com_write_rsp {
856 860
857/* legacy read request for older servers */ 861/* legacy read request for older servers */
858typedef struct smb_com_readx_req { 862typedef struct smb_com_readx_req {
859 struct smb_hdr hdr; /* wct = 10 */ 863 struct smb_hdr hdr; /* wct = 10 */
860 __u8 AndXCommand; 864 __u8 AndXCommand;
861 __u8 AndXReserved; 865 __u8 AndXReserved;
862 __le16 AndXOffset; 866 __le16 AndXOffset;
863 __u16 Fid; 867 __u16 Fid;
864 __le32 OffsetLow; 868 __le32 OffsetLow;
865 __le16 MaxCount; 869 __le16 MaxCount;
866 __le16 MinCount; /* obsolete */ 870 __le16 MinCount; /* obsolete */
867 __le32 Reserved; 871 __le32 Reserved;
868 __le16 Remaining; 872 __le16 Remaining;
869 __le16 ByteCount; 873 __le16 ByteCount;
870} __attribute__((packed)) READX_REQ; 874} __attribute__((packed)) READX_REQ;
871 875
872typedef struct smb_com_read_req { 876typedef struct smb_com_read_req {
@@ -897,7 +901,8 @@ typedef struct smb_com_read_rsp {
897 __le16 DataLengthHigh; 901 __le16 DataLengthHigh;
898 __u64 Reserved2; 902 __u64 Reserved2;
899 __u16 ByteCount; 903 __u16 ByteCount;
900 __u8 Pad; /* BB check for whether padded to DWORD boundary and optimum performance here */ 904 __u8 Pad; /* BB check for whether padded to DWORD
905 boundary and optimum performance here */
901 char Data[1]; 906 char Data[1];
902} __attribute__((packed)) READ_RSP; 907} __attribute__((packed)) READ_RSP;
903 908
@@ -968,7 +973,7 @@ typedef struct smb_com_rename_req {
968#define COPY_TARGET_MODE_ASCII 0x0004 /* if not set, binary */ 973#define COPY_TARGET_MODE_ASCII 0x0004 /* if not set, binary */
969#define COPY_SOURCE_MODE_ASCII 0x0008 /* if not set, binary */ 974#define COPY_SOURCE_MODE_ASCII 0x0008 /* if not set, binary */
970#define COPY_VERIFY_WRITES 0x0010 975#define COPY_VERIFY_WRITES 0x0010
971#define COPY_TREE 0x0020 976#define COPY_TREE 0x0020
972 977
973typedef struct smb_com_copy_req { 978typedef struct smb_com_copy_req {
974 struct smb_hdr hdr; /* wct = 3 */ 979 struct smb_hdr hdr; /* wct = 3 */
@@ -976,7 +981,7 @@ typedef struct smb_com_copy_req {
976 __le16 OpenFunction; 981 __le16 OpenFunction;
977 __le16 Flags; 982 __le16 Flags;
978 __le16 ByteCount; 983 __le16 ByteCount;
979 __u8 BufferFormat; /* 4 = ASCII or Unicode */ 984 __u8 BufferFormat; /* 4 = ASCII or Unicode */
980 unsigned char OldFileName[1]; 985 unsigned char OldFileName[1];
981 /* followed by __u8 BufferFormat2 */ 986 /* followed by __u8 BufferFormat2 */
982 /* followed by NewFileName string */ 987 /* followed by NewFileName string */
@@ -1084,28 +1089,28 @@ typedef struct smb_com_setattr_rsp {
1084 1089
1085/*******************************************************/ 1090/*******************************************************/
1086/* NT Transact structure defintions follow */ 1091/* NT Transact structure defintions follow */
1087/* Currently only ioctl, acl (get security descriptor) */ 1092/* Currently only ioctl, acl (get security descriptor) */
1088/* and notify are implemented */ 1093/* and notify are implemented */
1089/*******************************************************/ 1094/*******************************************************/
1090typedef struct smb_com_ntransact_req { 1095typedef struct smb_com_ntransact_req {
1091 struct smb_hdr hdr; /* wct >= 19 */ 1096 struct smb_hdr hdr; /* wct >= 19 */
1092 __u8 MaxSetupCount; 1097 __u8 MaxSetupCount;
1093 __u16 Reserved; 1098 __u16 Reserved;
1094 __le32 TotalParameterCount; 1099 __le32 TotalParameterCount;
1095 __le32 TotalDataCount; 1100 __le32 TotalDataCount;
1096 __le32 MaxParameterCount; 1101 __le32 MaxParameterCount;
1097 __le32 MaxDataCount; 1102 __le32 MaxDataCount;
1098 __le32 ParameterCount; 1103 __le32 ParameterCount;
1099 __le32 ParameterOffset; 1104 __le32 ParameterOffset;
1100 __le32 DataCount; 1105 __le32 DataCount;
1101 __le32 DataOffset; 1106 __le32 DataOffset;
1102 __u8 SetupCount; /* four setup words follow subcommand */ 1107 __u8 SetupCount; /* four setup words follow subcommand */
1103 /* SNIA spec incorrectly included spurious pad here */ 1108 /* SNIA spec incorrectly included spurious pad here */
1104 __le16 SubCommand; /* 2 = IOCTL/FSCTL */ 1109 __le16 SubCommand; /* 2 = IOCTL/FSCTL */
1105 /* SetupCount words follow then */ 1110 /* SetupCount words follow then */
1106 __le16 ByteCount; 1111 __le16 ByteCount;
1107 __u8 Pad[3]; 1112 __u8 Pad[3];
1108 __u8 Parms[0]; 1113 __u8 Parms[0];
1109} __attribute__((packed)) NTRANSACT_REQ; 1114} __attribute__((packed)) NTRANSACT_REQ;
1110 1115
1111typedef struct smb_com_ntransact_rsp { 1116typedef struct smb_com_ntransact_rsp {
@@ -1121,7 +1126,7 @@ typedef struct smb_com_ntransact_rsp {
1121 __le32 DataDisplacement; 1126 __le32 DataDisplacement;
1122 __u8 SetupCount; /* 0 */ 1127 __u8 SetupCount; /* 0 */
1123 __u16 ByteCount; 1128 __u16 ByteCount;
1124 /* __u8 Pad[3]; */ 1129 /* __u8 Pad[3]; */
1125 /* parms and data follow */ 1130 /* parms and data follow */
1126} __attribute__((packed)) NTRANSACT_RSP; 1131} __attribute__((packed)) NTRANSACT_RSP;
1127 1132
@@ -1216,7 +1221,7 @@ typedef struct smb_com_transaction_change_notify_req {
1216/* __u8 Data[1];*/ 1221/* __u8 Data[1];*/
1217} __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_REQ; 1222} __attribute__((packed)) TRANSACT_CHANGE_NOTIFY_REQ;
1218 1223
1219/* BB eventually change to use generic ntransact rsp struct 1224/* BB eventually change to use generic ntransact rsp struct
1220 and validation routine */ 1225 and validation routine */
1221typedef struct smb_com_transaction_change_notify_rsp { 1226typedef struct smb_com_transaction_change_notify_rsp {
1222 struct smb_hdr hdr; /* wct = 18 */ 1227 struct smb_hdr hdr; /* wct = 18 */
@@ -1263,7 +1268,7 @@ struct file_notify_information {
1263 __le32 Action; 1268 __le32 Action;
1264 __le32 FileNameLength; 1269 __le32 FileNameLength;
1265 __u8 FileName[0]; 1270 __u8 FileName[0];
1266} __attribute__((packed)); 1271} __attribute__((packed));
1267 1272
1268struct reparse_data { 1273struct reparse_data {
1269 __u32 ReparseTag; 1274 __u32 ReparseTag;
@@ -1332,7 +1337,7 @@ struct trans2_resp {
1332 __u8 Reserved1; 1337 __u8 Reserved1;
1333 /* SetupWords[SetupCount]; 1338 /* SetupWords[SetupCount];
1334 __u16 ByteCount; 1339 __u16 ByteCount;
1335 __u16 Reserved2;*/ 1340 __u16 Reserved2;*/
1336 /* data area follows */ 1341 /* data area follows */
1337} __attribute__((packed)); 1342} __attribute__((packed));
1338 1343
@@ -1371,9 +1376,9 @@ struct smb_t2_rsp {
1371#define SMB_QUERY_FILE_INTERNAL_INFO 0x3ee 1376#define SMB_QUERY_FILE_INTERNAL_INFO 0x3ee
1372#define SMB_QUERY_FILE_ACCESS_INFO 0x3f0 1377#define SMB_QUERY_FILE_ACCESS_INFO 0x3f0
1373#define SMB_QUERY_FILE_NAME_INFO2 0x3f1 /* 0x30 bytes */ 1378#define SMB_QUERY_FILE_NAME_INFO2 0x3f1 /* 0x30 bytes */
1374#define SMB_QUERY_FILE_POSITION_INFO 0x3f6 1379#define SMB_QUERY_FILE_POSITION_INFO 0x3f6
1375#define SMB_QUERY_FILE_MODE_INFO 0x3f8 1380#define SMB_QUERY_FILE_MODE_INFO 0x3f8
1376#define SMB_QUERY_FILE_ALGN_INFO 0x3f9 1381#define SMB_QUERY_FILE_ALGN_INFO 0x3f9
1377 1382
1378 1383
1379#define SMB_SET_FILE_BASIC_INFO 0x101 1384#define SMB_SET_FILE_BASIC_INFO 0x101
@@ -1507,35 +1512,35 @@ struct smb_com_transaction2_sfi_req {
1507 __u16 Pad1; 1512 __u16 Pad1;
1508 __u16 Fid; 1513 __u16 Fid;
1509 __le16 InformationLevel; 1514 __le16 InformationLevel;
1510 __u16 Reserved4; 1515 __u16 Reserved4;
1511} __attribute__((packed)); 1516} __attribute__((packed));
1512 1517
1513struct smb_com_transaction2_sfi_rsp { 1518struct smb_com_transaction2_sfi_rsp {
1514 struct smb_hdr hdr; /* wct = 10 + SetupCount */ 1519 struct smb_hdr hdr; /* wct = 10 + SetupCount */
1515 struct trans2_resp t2; 1520 struct trans2_resp t2;
1516 __u16 ByteCount; 1521 __u16 ByteCount;
1517 __u16 Reserved2; /* parameter word reserved - 1522 __u16 Reserved2; /* parameter word reserved -
1518 present for infolevels > 100 */ 1523 present for infolevels > 100 */
1519} __attribute__((packed)); 1524} __attribute__((packed));
1520 1525
1521struct smb_t2_qfi_req { 1526struct smb_t2_qfi_req {
1522 struct smb_hdr hdr; 1527 struct smb_hdr hdr;
1523 struct trans2_req t2; 1528 struct trans2_req t2;
1524 __u8 Pad; 1529 __u8 Pad;
1525 __u16 Fid; 1530 __u16 Fid;
1526 __le16 InformationLevel; 1531 __le16 InformationLevel;
1527} __attribute__((packed)); 1532} __attribute__((packed));
1528 1533
1529struct smb_t2_qfi_rsp { 1534struct smb_t2_qfi_rsp {
1530 struct smb_hdr hdr; /* wct = 10 + SetupCount */ 1535 struct smb_hdr hdr; /* wct = 10 + SetupCount */
1531 struct trans2_resp t2; 1536 struct trans2_resp t2;
1532 __u16 ByteCount; 1537 __u16 ByteCount;
1533 __u16 Reserved2; /* parameter word reserved - 1538 __u16 Reserved2; /* parameter word reserved -
1534 present for infolevels > 100 */ 1539 present for infolevels > 100 */
1535} __attribute__((packed)); 1540} __attribute__((packed));
1536 1541
1537/* 1542/*
1538 * Flags on T2 FINDFIRST and FINDNEXT 1543 * Flags on T2 FINDFIRST and FINDNEXT
1539 */ 1544 */
1540#define CIFS_SEARCH_CLOSE_ALWAYS 0x0001 1545#define CIFS_SEARCH_CLOSE_ALWAYS 0x0001
1541#define CIFS_SEARCH_CLOSE_AT_END 0x0002 1546#define CIFS_SEARCH_CLOSE_AT_END 0x0002
@@ -1744,7 +1749,9 @@ typedef struct smb_com_transaction2_get_dfs_refer_req {
1744 __u8 Reserved3; 1749 __u8 Reserved3;
1745 __le16 SubCommand; /* one setup word */ 1750 __le16 SubCommand; /* one setup word */
1746 __le16 ByteCount; 1751 __le16 ByteCount;
1747 __u8 Pad[3]; /* Win2K has sent 0x0F01 (max resp length perhaps?) followed by one byte pad - doesn't seem to matter though */ 1752 __u8 Pad[3]; /* Win2K has sent 0x0F01 (max response length
1753 perhaps?) followed by one byte pad - doesn't
1754 seem to matter though */
1748 __le16 MaxReferralLevel; 1755 __le16 MaxReferralLevel;
1749 char RequestFileName[1]; 1756 char RequestFileName[1];
1750} __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_REQ; 1757} __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_REQ;
@@ -1753,7 +1760,10 @@ typedef struct dfs_referral_level_3 {
1753 __le16 VersionNumber; 1760 __le16 VersionNumber;
1754 __le16 ReferralSize; 1761 __le16 ReferralSize;
1755 __le16 ServerType; /* 0x0001 = CIFS server */ 1762 __le16 ServerType; /* 0x0001 = CIFS server */
1756 __le16 ReferralFlags; /* or proximity - not clear which since always set to zero - SNIA spec says 0x01 means strip off PathConsumed chars before submitting RequestFileName to remote node */ 1763 __le16 ReferralFlags; /* or proximity - not clear which since it is
1764 always set to zero - SNIA spec says 0x01
1765 means strip off PathConsumed chars before
1766 submitting RequestFileName to remote node */
1757 __le16 TimeToLive; 1767 __le16 TimeToLive;
1758 __le16 Proximity; 1768 __le16 Proximity;
1759 __le16 DfsPathOffset; 1769 __le16 DfsPathOffset;
@@ -1779,11 +1789,13 @@ typedef struct smb_com_transaction_get_dfs_refer_rsp {
1779#define DFSREF_STORAGE_SERVER 0x0002 1789#define DFSREF_STORAGE_SERVER 0x0002
1780 1790
1781/* IOCTL information */ 1791/* IOCTL information */
1782/* List of ioctl function codes that look to be of interest to remote clients like this. */ 1792/*
1783/* Need to do some experimentation to make sure they all work remotely. */ 1793 * List of ioctl function codes that look to be of interest to remote clients
1784/* Some of the following such as the encryption/compression ones would be */ 1794 * like this one. Need to do some experimentation to make sure they all work
1785/* invoked from tools via a specialized hook into the VFS rather than via the */ 1795 * remotely. Some of the following, such as the encryption/compression ones
1786/* standard vfs entry points */ 1796 * would be invoked from tools via a specialized hook into the VFS rather
1797 * than via the standard vfs entry points
1798 */
1787#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000 1799#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
1788#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004 1800#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
1789#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008 1801#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008
@@ -1812,7 +1824,7 @@ typedef struct smb_com_transaction_get_dfs_refer_rsp {
1812/* 1824/*
1813 ************************************************************************ 1825 ************************************************************************
1814 * All structs for everything above the SMB PDUs themselves 1826 * All structs for everything above the SMB PDUs themselves
1815 * (such as the T2 level specific data) go here 1827 * (such as the T2 level specific data) go here
1816 ************************************************************************ 1828 ************************************************************************
1817 */ 1829 */
1818 1830
@@ -1858,7 +1870,7 @@ typedef struct {
1858 __le64 FreeAllocationUnits; 1870 __le64 FreeAllocationUnits;
1859 __le32 SectorsPerAllocationUnit; 1871 __le32 SectorsPerAllocationUnit;
1860 __le32 BytesPerSector; 1872 __le32 BytesPerSector;
1861} __attribute__((packed)) FILE_SYSTEM_INFO; /* size info, level 0x103 */ 1873} __attribute__((packed)) FILE_SYSTEM_INFO; /* size info, level 0x103 */
1862 1874
1863typedef struct { 1875typedef struct {
1864 __le32 fsid; 1876 __le32 fsid;
@@ -1872,7 +1884,7 @@ typedef struct {
1872 __le16 MajorVersionNumber; 1884 __le16 MajorVersionNumber;
1873 __le16 MinorVersionNumber; 1885 __le16 MinorVersionNumber;
1874 __le64 Capability; 1886 __le64 Capability;
1875} __attribute__((packed)) FILE_SYSTEM_UNIX_INFO; /* Unix extensions info, level 0x200 */ 1887} __attribute__((packed)) FILE_SYSTEM_UNIX_INFO; /* Unix extension level 0x200*/
1876 1888
1877/* Version numbers for CIFS UNIX major and minor. */ 1889/* Version numbers for CIFS UNIX major and minor. */
1878#define CIFS_UNIX_MAJOR_VERSION 1 1890#define CIFS_UNIX_MAJOR_VERSION 1
@@ -1888,7 +1900,7 @@ typedef struct {
1888 calls including posix open 1900 calls including posix open
1889 and posix unlink */ 1901 and posix unlink */
1890#define CIFS_UNIX_LARGE_READ_CAP 0x00000040 /* support reads >128K (up 1902#define CIFS_UNIX_LARGE_READ_CAP 0x00000040 /* support reads >128K (up
1891 to 0xFFFF00 */ 1903 to 0xFFFF00 */
1892#define CIFS_UNIX_LARGE_WRITE_CAP 0x00000080 1904#define CIFS_UNIX_LARGE_WRITE_CAP 0x00000080
1893 1905
1894#ifdef CONFIG_CIFS_POSIX 1906#ifdef CONFIG_CIFS_POSIX
@@ -1898,8 +1910,8 @@ typedef struct {
1898 as non-posix handles (can affect write behavior with byte range locks. 1910 as non-posix handles (can affect write behavior with byte range locks.
1899 We can add back in POSIX_PATH_OPS cap when Posix Create/Mkdir finished */ 1911 We can add back in POSIX_PATH_OPS cap when Posix Create/Mkdir finished */
1900/* #define CIFS_UNIX_CAP_MASK 0x000000fb */ 1912/* #define CIFS_UNIX_CAP_MASK 0x000000fb */
1901#define CIFS_UNIX_CAP_MASK 0x000000db 1913#define CIFS_UNIX_CAP_MASK 0x000000db
1902#else 1914#else
1903#define CIFS_UNIX_CAP_MASK 0x00000013 1915#define CIFS_UNIX_CAP_MASK 0x00000013
1904#endif /* CONFIG_CIFS_POSIX */ 1916#endif /* CONFIG_CIFS_POSIX */
1905 1917
@@ -1909,10 +1921,10 @@ typedef struct {
1909typedef struct { 1921typedef struct {
1910 /* For undefined recommended transfer size return -1 in that field */ 1922 /* For undefined recommended transfer size return -1 in that field */
1911 __le32 OptimalTransferSize; /* bsize on some os, iosize on other os */ 1923 __le32 OptimalTransferSize; /* bsize on some os, iosize on other os */
1912 __le32 BlockSize; 1924 __le32 BlockSize;
1913 /* The next three fields are in terms of the block size. 1925 /* The next three fields are in terms of the block size.
1914 (above). If block size is unknown, 4096 would be a 1926 (above). If block size is unknown, 4096 would be a
1915 reasonable block size for a server to report. 1927 reasonable block size for a server to report.
1916 Note that returning the blocks/blocksavail removes need 1928 Note that returning the blocks/blocksavail removes need
1917 to make a second call (to QFSInfo level 0x103 to get this info. 1929 to make a second call (to QFSInfo level 0x103 to get this info.
1918 UserBlockAvail is typically less than or equal to BlocksAvail, 1930 UserBlockAvail is typically less than or equal to BlocksAvail,
@@ -2067,9 +2079,9 @@ struct file_alt_name_info {
2067 2079
2068struct file_stream_info { 2080struct file_stream_info {
2069 __le32 number_of_streams; /* BB check sizes and verify location */ 2081 __le32 number_of_streams; /* BB check sizes and verify location */
2070 /* followed by info on streams themselves 2082 /* followed by info on streams themselves
2071 u64 size; 2083 u64 size;
2072 u64 allocation_size 2084 u64 allocation_size
2073 stream info */ 2085 stream info */
2074}; /* level 0x109 */ 2086}; /* level 0x109 */
2075 2087
@@ -2088,7 +2100,7 @@ struct cifs_posix_ace { /* access control entry (ACE) */
2088 __u8 cifs_e_tag; 2100 __u8 cifs_e_tag;
2089 __u8 cifs_e_perm; 2101 __u8 cifs_e_perm;
2090 __le64 cifs_uid; /* or gid */ 2102 __le64 cifs_uid; /* or gid */
2091} __attribute__((packed)); 2103} __attribute__((packed));
2092 2104
2093struct cifs_posix_acl { /* access conrol list (ACL) */ 2105struct cifs_posix_acl { /* access conrol list (ACL) */
2094 __le16 version; 2106 __le16 version;
@@ -2159,7 +2171,7 @@ struct file_attrib_tag {
2159 2171
2160 2172
2161/********************************************************/ 2173/********************************************************/
2162/* FindFirst/FindNext transact2 data buffer formats */ 2174/* FindFirst/FindNext transact2 data buffer formats */
2163/********************************************************/ 2175/********************************************************/
2164 2176
2165typedef struct { 2177typedef struct {
@@ -2237,7 +2249,7 @@ typedef struct {
2237 __le64 EndOfFile; 2249 __le64 EndOfFile;
2238 __le64 AllocationSize; 2250 __le64 AllocationSize;
2239 __le32 ExtFileAttributes; 2251 __le32 ExtFileAttributes;
2240 __le32 FileNameLength; 2252 __le32 FileNameLength;
2241 __le32 EaSize; /* length of the xattrs */ 2253 __le32 EaSize; /* length of the xattrs */
2242 __u8 ShortNameLength; 2254 __u8 ShortNameLength;
2243 __u8 Reserved; 2255 __u8 Reserved;
@@ -2264,7 +2276,7 @@ typedef struct {
2264struct win_dev { 2276struct win_dev {
2265 unsigned char type[8]; /* IntxCHR or IntxBLK */ 2277 unsigned char type[8]; /* IntxCHR or IntxBLK */
2266 __le64 major; 2278 __le64 major;
2267 __le64 minor; 2279 __le64 minor;
2268} __attribute__((packed)); 2280} __attribute__((packed));
2269 2281
2270struct gea { 2282struct gea {
@@ -2296,36 +2308,36 @@ struct fealist {
2296struct data_blob { 2308struct data_blob {
2297 __u8 *data; 2309 __u8 *data;
2298 size_t length; 2310 size_t length;
2299 void (*free) (struct data_blob * data_blob); 2311 void (*free) (struct data_blob *data_blob);
2300} __attribute__((packed)); 2312} __attribute__((packed));
2301 2313
2302 2314
2303#ifdef CONFIG_CIFS_POSIX 2315#ifdef CONFIG_CIFS_POSIX
2304/* 2316/*
2305 For better POSIX semantics from Linux client, (even better 2317 For better POSIX semantics from Linux client, (even better
2306 than the existing CIFS Unix Extensions) we need updated PDUs for: 2318 than the existing CIFS Unix Extensions) we need updated PDUs for:
2307 2319
2308 1) PosixCreateX - to set and return the mode, inode#, device info and 2320 1) PosixCreateX - to set and return the mode, inode#, device info and
2309 perhaps add a CreateDevice - to create Pipes and other special .inodes 2321 perhaps add a CreateDevice - to create Pipes and other special .inodes
2310 Also note POSIX open flags 2322 Also note POSIX open flags
2311 2) Close - to return the last write time to do cache across close 2323 2) Close - to return the last write time to do cache across close
2312 more safely 2324 more safely
2313 3) FindFirst return unique inode number - what about resume key, two 2325 3) FindFirst return unique inode number - what about resume key, two
2314 forms short (matches readdir) and full (enough info to cache inodes) 2326 forms short (matches readdir) and full (enough info to cache inodes)
2315 4) Mkdir - set mode 2327 4) Mkdir - set mode
2316 2328
2317 And under consideration: 2329 And under consideration:
2318 5) FindClose2 (return nanosecond timestamp ??) 2330 5) FindClose2 (return nanosecond timestamp ??)
2319 6) Use nanosecond timestamps throughout all time fields if 2331 6) Use nanosecond timestamps throughout all time fields if
2320 corresponding attribute flag is set 2332 corresponding attribute flag is set
2321 7) sendfile - handle based copy 2333 7) sendfile - handle based copy
2322 8) Direct i/o 2334 8) Direct i/o
2323 9) Misc fcntls? 2335 9) Misc fcntls?
2324 2336
2325 what about fixing 64 bit alignment 2337 what about fixing 64 bit alignment
2326 2338
2327 There are also various legacy SMB/CIFS requests used as is 2339 There are also various legacy SMB/CIFS requests used as is
2328 2340
2329 From existing Lanman and NTLM dialects: 2341 From existing Lanman and NTLM dialects:
2330 -------------------------------------- 2342 --------------------------------------
2331 NEGOTIATE 2343 NEGOTIATE
@@ -2346,48 +2358,48 @@ struct data_blob {
2346 (BB verify that never need to set allocation size) 2358 (BB verify that never need to set allocation size)
2347 SMB_SET_FILE_BASIC_INFO2 (setting times - BB can it be done via 2359 SMB_SET_FILE_BASIC_INFO2 (setting times - BB can it be done via
2348 Unix ext?) 2360 Unix ext?)
2349 2361
2350 COPY (note support for copy across directories) - FUTURE, OPTIONAL 2362 COPY (note support for copy across directories) - FUTURE, OPTIONAL
2351 setting/getting OS/2 EAs - FUTURE (BB can this handle 2363 setting/getting OS/2 EAs - FUTURE (BB can this handle
2352 setting Linux xattrs perfectly) - OPTIONAL 2364 setting Linux xattrs perfectly) - OPTIONAL
2353 dnotify - FUTURE, OPTIONAL 2365 dnotify - FUTURE, OPTIONAL
2354 quota - FUTURE, OPTIONAL 2366 quota - FUTURE, OPTIONAL
2355 2367
2356 Note that various requests implemented for NT interop such as 2368 Note that various requests implemented for NT interop such as
2357 NT_TRANSACT (IOCTL) QueryReparseInfo 2369 NT_TRANSACT (IOCTL) QueryReparseInfo
2358 are unneeded to servers compliant with the CIFS POSIX extensions 2370 are unneeded to servers compliant with the CIFS POSIX extensions
2359 2371
2360 From CIFS Unix Extensions: 2372 From CIFS Unix Extensions:
2361 ------------------------- 2373 -------------------------
2362 T2 SET_PATH_INFO (SMB_SET_FILE_UNIX_LINK) for symlinks 2374 T2 SET_PATH_INFO (SMB_SET_FILE_UNIX_LINK) for symlinks
2363 T2 SET_PATH_INFO (SMB_SET_FILE_BASIC_INFO2) 2375 T2 SET_PATH_INFO (SMB_SET_FILE_BASIC_INFO2)
2364 T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_LINK) 2376 T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_LINK)
2365 T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_BASIC) - BB check for missing inode fields 2377 T2 QUERY_PATH_INFO (SMB_QUERY_FILE_UNIX_BASIC) BB check for missing
2366 Actually need QUERY_FILE_UNIX_INFO since has inode num 2378 inode fields
2367 BB what about a) blksize/blkbits/blocks 2379 Actually a need QUERY_FILE_UNIX_INFO
2380 since has inode num
2381 BB what about a) blksize/blkbits/blocks
2368 b) i_version 2382 b) i_version
2369 c) i_rdev 2383 c) i_rdev
2370 d) notify mask? 2384 d) notify mask?
2371 e) generation 2385 e) generation
2372 f) size_seqcount 2386 f) size_seqcount
2373 T2 FIND_FIRST/FIND_NEXT FIND_FILE_UNIX 2387 T2 FIND_FIRST/FIND_NEXT FIND_FILE_UNIX
2374 TRANS2_GET_DFS_REFERRAL - OPTIONAL but recommended 2388 TRANS2_GET_DFS_REFERRAL - OPTIONAL but recommended
2375 T2_QFS_INFO QueryDevice/AttributeInfo - OPTIONAL 2389 T2_QFS_INFO QueryDevice/AttributeInfo - OPTIONAL
2376
2377
2378 */ 2390 */
2379 2391
2380/* xsymlink is a symlink format (used by MacOS) that can be used 2392/* xsymlink is a symlink format (used by MacOS) that can be used
2381 to save symlink info in a regular file when 2393 to save symlink info in a regular file when
2382 mounted to operating systems that do not 2394 mounted to operating systems that do not
2383 support the cifs Unix extensions or EAs (for xattr 2395 support the cifs Unix extensions or EAs (for xattr
2384 based symlinks). For such a file to be recognized 2396 based symlinks). For such a file to be recognized
2385 as containing symlink data: 2397 as containing symlink data:
2386 2398
2387 1) file size must be 1067, 2399 1) file size must be 1067,
2388 2) signature must begin file data, 2400 2) signature must begin file data,
2389 3) length field must be set to ASCII representation 2401 3) length field must be set to ASCII representation
2390 of a number which is less than or equal to 1024, 2402 of a number which is less than or equal to 1024,
2391 4) md5 must match that of the path data */ 2403 4) md5 must match that of the path data */
2392 2404
2393struct xsymlink { 2405struct xsymlink {
@@ -2398,10 +2410,10 @@ struct xsymlink {
2398 char length[4]; 2410 char length[4];
2399 char cr1; /* \n */ 2411 char cr1; /* \n */
2400/* md5 of valid subset of path ie path[0] through path[length-1] */ 2412/* md5 of valid subset of path ie path[0] through path[length-1] */
2401 __u8 md5[32]; 2413 __u8 md5[32];
2402 char cr2; /* \n */ 2414 char cr2; /* \n */
2403/* if room left, then end with \n then 0x20s by convention but not required */ 2415/* if room left, then end with \n then 0x20s by convention but not required */
2404 char path[1024]; 2416 char path[1024];
2405} __attribute__((packed)); 2417} __attribute__((packed));
2406 2418
2407typedef struct file_xattr_info { 2419typedef struct file_xattr_info {
@@ -2410,7 +2422,8 @@ typedef struct file_xattr_info {
2410 __u32 xattr_value_len; 2422 __u32 xattr_value_len;
2411 char xattr_name[0]; 2423 char xattr_name[0];
2412 /* followed by xattr_value[xattr_value_len], no pad */ 2424 /* followed by xattr_value[xattr_value_len], no pad */
2413} __attribute__((packed)) FILE_XATTR_INFO; /* extended attribute, info level 0x205 */ 2425} __attribute__((packed)) FILE_XATTR_INFO; /* extended attribute info
2426 level 0x205 */
2414 2427
2415 2428
2416/* flags for chattr command */ 2429/* flags for chattr command */
@@ -2436,8 +2449,9 @@ typedef struct file_xattr_info {
2436typedef struct file_chattr_info { 2449typedef struct file_chattr_info {
2437 __le64 mask; /* list of all possible attribute bits */ 2450 __le64 mask; /* list of all possible attribute bits */
2438 __le64 mode; /* list of actual attribute bits on this inode */ 2451 __le64 mode; /* list of actual attribute bits on this inode */
2439} __attribute__((packed)) FILE_CHATTR_INFO; /* ext attributes (chattr, chflags) level 0x206 */ 2452} __attribute__((packed)) FILE_CHATTR_INFO; /* ext attributes
2453 (chattr, chflags) level 0x206 */
2440 2454
2441#endif 2455#endif
2442 2456
2443#endif /* _CIFSPDU_H */ 2457#endif /* _CIFSPDU_H */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 6a6e3f9f3f8b..3a76c72f3c89 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -71,12 +71,12 @@ extern void header_assemble(struct smb_hdr *, char /* command */ ,
71 fixed section (word count) in two byte units */); 71 fixed section (word count) in two byte units */);
72extern int small_smb_init_no_tc(const int smb_cmd, const int wct, 72extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
73 struct cifsSesInfo *ses, 73 struct cifsSesInfo *ses,
74 void ** request_buf); 74 void **request_buf);
75extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, 75extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
76 const int stage, 76 const int stage,
77 const struct nls_table *nls_cp); 77 const struct nls_table *nls_cp);
78extern __u16 GetNextMid(struct TCP_Server_Info *server); 78extern __u16 GetNextMid(struct TCP_Server_Info *server);
79extern struct oplock_q_entry * AllocOplockQEntry(struct inode *, u16, 79extern struct oplock_q_entry *AllocOplockQEntry(struct inode *, u16,
80 struct cifsTconInfo *); 80 struct cifsTconInfo *);
81extern void DeleteOplockQEntry(struct oplock_q_entry *); 81extern void DeleteOplockQEntry(struct oplock_q_entry *);
82extern struct timespec cifs_NTtimeToUnix(u64 /* utc nanoseconds since 1601 */ ); 82extern struct timespec cifs_NTtimeToUnix(u64 /* utc nanoseconds since 1601 */ );
@@ -146,7 +146,7 @@ extern int get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
146 const char *old_path, 146 const char *old_path,
147 const struct nls_table *nls_codepage, 147 const struct nls_table *nls_codepage,
148 unsigned int *pnum_referrals, 148 unsigned int *pnum_referrals,
149 unsigned char ** preferrals, 149 unsigned char **preferrals,
150 int remap); 150 int remap);
151extern void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon, 151extern void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
152 struct super_block *sb, struct smb_vol *vol); 152 struct super_block *sb, struct smb_vol *vol);
@@ -312,9 +312,9 @@ extern int CIFSSMBCopy(int xid,
312 const char *fromName, 312 const char *fromName,
313 const __u16 target_tid, 313 const __u16 target_tid,
314 const char *toName, const int flags, 314 const char *toName, const int flags,
315 const struct nls_table *nls_codepage, 315 const struct nls_table *nls_codepage,
316 int remap_special_chars); 316 int remap_special_chars);
317extern int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, 317extern int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
318 const int notify_subdirs, const __u16 netfid, 318 const int notify_subdirs, const __u16 netfid,
319 __u32 filter, struct file *file, int multishot, 319 __u32 filter, struct file *file, int multishot,
320 const struct nls_table *nls_codepage); 320 const struct nls_table *nls_codepage);
@@ -323,7 +323,7 @@ extern ssize_t CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
323 size_t bufsize, const struct nls_table *nls_codepage, 323 size_t bufsize, const struct nls_table *nls_codepage,
324 int remap_special_chars); 324 int remap_special_chars);
325extern ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon, 325extern ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon,
326 const unsigned char * searchName, const unsigned char *ea_name, 326 const unsigned char *searchName, const unsigned char *ea_name,
327 unsigned char *ea_value, size_t buf_size, 327 unsigned char *ea_value, size_t buf_size,
328 const struct nls_table *nls_codepage, int remap_special_chars); 328 const struct nls_table *nls_codepage, int remap_special_chars);
329extern int CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, 329extern int CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 5b19ce2e4351..3ab78b776977 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -48,7 +48,7 @@ static struct {
48 {LANMAN_PROT, "\2LM1.2X002"}, 48 {LANMAN_PROT, "\2LM1.2X002"},
49 {LANMAN2_PROT, "\2LANMAN2.1"}, 49 {LANMAN2_PROT, "\2LANMAN2.1"},
50#endif /* weak password hashing for legacy clients */ 50#endif /* weak password hashing for legacy clients */
51 {CIFS_PROT, "\2NT LM 0.12"}, 51 {CIFS_PROT, "\2NT LM 0.12"},
52 {POSIX_PROT, "\2POSIX 2"}, 52 {POSIX_PROT, "\2POSIX 2"},
53 {BAD_PROT, "\2"} 53 {BAD_PROT, "\2"}
54}; 54};
@@ -119,7 +119,7 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
119 (and ulogoff which does not have tcon) 119 (and ulogoff which does not have tcon)
120 are allowed as we start force umount */ 120 are allowed as we start force umount */
121 if ((smb_command != SMB_COM_WRITE_ANDX) && 121 if ((smb_command != SMB_COM_WRITE_ANDX) &&
122 (smb_command != SMB_COM_OPEN_ANDX) && 122 (smb_command != SMB_COM_OPEN_ANDX) &&
123 (smb_command != SMB_COM_TREE_DISCONNECT)) { 123 (smb_command != SMB_COM_TREE_DISCONNECT)) {
124 cFYI(1, ("can not send cmd %d while umounting", 124 cFYI(1, ("can not send cmd %d while umounting",
125 smb_command)); 125 smb_command));
@@ -127,9 +127,9 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
127 } 127 }
128 } 128 }
129 if ((tcon->ses) && (tcon->ses->status != CifsExiting) && 129 if ((tcon->ses) && (tcon->ses->status != CifsExiting) &&
130 (tcon->ses->server)){ 130 (tcon->ses->server)) {
131 struct nls_table *nls_codepage; 131 struct nls_table *nls_codepage;
132 /* Give Demultiplex thread up to 10 seconds to 132 /* Give Demultiplex thread up to 10 seconds to
133 reconnect, should be greater than cifs socket 133 reconnect, should be greater than cifs socket
134 timeout which is 7 seconds */ 134 timeout which is 7 seconds */
135 while(tcon->ses->server->tcpStatus == CifsNeedReconnect) { 135 while(tcon->ses->server->tcpStatus == CifsNeedReconnect) {
@@ -139,34 +139,34 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
139 /* on "soft" mounts we wait once */ 139 /* on "soft" mounts we wait once */
140 if ((tcon->retry == FALSE) || 140 if ((tcon->retry == FALSE) ||
141 (tcon->ses->status == CifsExiting)) { 141 (tcon->ses->status == CifsExiting)) {
142 cFYI(1,("gave up waiting on reconnect in smb_init")); 142 cFYI(1, ("gave up waiting on "
143 "reconnect in smb_init"));
143 return -EHOSTDOWN; 144 return -EHOSTDOWN;
144 } /* else "hard" mount - keep retrying 145 } /* else "hard" mount - keep retrying
145 until process is killed or server 146 until process is killed or server
146 comes back on-line */ 147 comes back on-line */
147 } else /* TCP session is reestablished now */ 148 } else /* TCP session is reestablished now */
148 break; 149 break;
149
150 } 150 }
151 151
152 nls_codepage = load_nls_default(); 152 nls_codepage = load_nls_default();
153 /* need to prevent multiple threads trying to 153 /* need to prevent multiple threads trying to
154 simultaneously reconnect the same SMB session */ 154 simultaneously reconnect the same SMB session */
155 down(&tcon->ses->sesSem); 155 down(&tcon->ses->sesSem);
156 if (tcon->ses->status == CifsNeedReconnect) 156 if (tcon->ses->status == CifsNeedReconnect)
157 rc = cifs_setup_session(0, tcon->ses, 157 rc = cifs_setup_session(0, tcon->ses,
158 nls_codepage); 158 nls_codepage);
159 if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { 159 if (!rc && (tcon->tidStatus == CifsNeedReconnect)) {
160 mark_open_files_invalid(tcon); 160 mark_open_files_invalid(tcon);
161 rc = CIFSTCon(0, tcon->ses, tcon->treeName, 161 rc = CIFSTCon(0, tcon->ses, tcon->treeName,
162 tcon, nls_codepage); 162 tcon, nls_codepage);
163 up(&tcon->ses->sesSem); 163 up(&tcon->ses->sesSem);
164 /* tell server which Unix caps we support */ 164 /* tell server which Unix caps we support */
165 if (tcon->ses->capabilities & CAP_UNIX) 165 if (tcon->ses->capabilities & CAP_UNIX)
166 reset_cifs_unix_caps(0 /* no xid */, 166 reset_cifs_unix_caps(0 /* no xid */,
167 tcon, 167 tcon,
168 NULL /* we do not know sb */, 168 NULL /* we do not know sb */,
169 NULL /* no vol info */); 169 NULL /* no vol info */);
170 /* BB FIXME add code to check if wsize needs 170 /* BB FIXME add code to check if wsize needs
171 update due to negotiated smb buffer size 171 update due to negotiated smb buffer size
172 shrinking */ 172 shrinking */
@@ -174,14 +174,14 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
174 atomic_inc(&tconInfoReconnectCount); 174 atomic_inc(&tconInfoReconnectCount);
175 175
176 cFYI(1, ("reconnect tcon rc = %d", rc)); 176 cFYI(1, ("reconnect tcon rc = %d", rc));
177 /* Removed call to reopen open files here - 177 /* Removed call to reopen open files here.
178 it is safer (and faster) to reopen files 178 It is safer (and faster) to reopen files
179 one at a time as needed in read and write */ 179 one at a time as needed in read and write */
180 180
181 /* Check if handle based operation so we 181 /* Check if handle based operation so we
182 know whether we can continue or not without 182 know whether we can continue or not without
183 returning to caller to reset file handle */ 183 returning to caller to reset file handle */
184 switch(smb_command) { 184 switch (smb_command) {
185 case SMB_COM_READ_ANDX: 185 case SMB_COM_READ_ANDX:
186 case SMB_COM_WRITE_ANDX: 186 case SMB_COM_WRITE_ANDX:
187 case SMB_COM_CLOSE: 187 case SMB_COM_CLOSE:
@@ -218,11 +218,11 @@ small_smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
218} 218}
219 219
220int 220int
221small_smb_init_no_tc(const int smb_command, const int wct, 221small_smb_init_no_tc(const int smb_command, const int wct,
222 struct cifsSesInfo *ses, void **request_buf) 222 struct cifsSesInfo *ses, void **request_buf)
223{ 223{
224 int rc; 224 int rc;
225 struct smb_hdr * buffer; 225 struct smb_hdr *buffer;
226 226
227 rc = small_smb_init(smb_command, wct, NULL, request_buf); 227 rc = small_smb_init(smb_command, wct, NULL, request_buf);
228 if (rc) 228 if (rc)
@@ -237,7 +237,7 @@ small_smb_init_no_tc(const int smb_command, const int wct,
237 237
238 /* uid, tid can stay at zero as set in header assemble */ 238 /* uid, tid can stay at zero as set in header assemble */
239 239
240 /* BB add support for turning on the signing when 240 /* BB add support for turning on the signing when
241 this function is used after 1st of session setup requests */ 241 this function is used after 1st of session setup requests */
242 242
243 return rc; 243 return rc;
@@ -269,7 +269,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
269 } 269 }
270 270
271 if ((tcon->ses) && (tcon->ses->status != CifsExiting) && 271 if ((tcon->ses) && (tcon->ses->status != CifsExiting) &&
272 (tcon->ses->server)){ 272 (tcon->ses->server)) {
273 struct nls_table *nls_codepage; 273 struct nls_table *nls_codepage;
274 /* Give Demultiplex thread up to 10 seconds to 274 /* Give Demultiplex thread up to 10 seconds to
275 reconnect, should be greater than cifs socket 275 reconnect, should be greater than cifs socket
@@ -282,22 +282,21 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
282 /* on "soft" mounts we wait once */ 282 /* on "soft" mounts we wait once */
283 if ((tcon->retry == FALSE) || 283 if ((tcon->retry == FALSE) ||
284 (tcon->ses->status == CifsExiting)) { 284 (tcon->ses->status == CifsExiting)) {
285 cFYI(1,("gave up waiting on reconnect in smb_init")); 285 cFYI(1, ("gave up waiting on "
286 "reconnect in smb_init"));
286 return -EHOSTDOWN; 287 return -EHOSTDOWN;
287 } /* else "hard" mount - keep retrying 288 } /* else "hard" mount - keep retrying
288 until process is killed or server 289 until process is killed or server
289 comes on-line */ 290 comes on-line */
290 } else /* TCP session is reestablished now */ 291 } else /* TCP session is reestablished now */
291 break; 292 break;
292
293 } 293 }
294
295 nls_codepage = load_nls_default(); 294 nls_codepage = load_nls_default();
296 /* need to prevent multiple threads trying to 295 /* need to prevent multiple threads trying to
297 simultaneously reconnect the same SMB session */ 296 simultaneously reconnect the same SMB session */
298 down(&tcon->ses->sesSem); 297 down(&tcon->ses->sesSem);
299 if (tcon->ses->status == CifsNeedReconnect) 298 if (tcon->ses->status == CifsNeedReconnect)
300 rc = cifs_setup_session(0, tcon->ses, 299 rc = cifs_setup_session(0, tcon->ses,
301 nls_codepage); 300 nls_codepage);
302 if (!rc && (tcon->tidStatus == CifsNeedReconnect)) { 301 if (!rc && (tcon->tidStatus == CifsNeedReconnect)) {
303 mark_open_files_invalid(tcon); 302 mark_open_files_invalid(tcon);
@@ -307,7 +306,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
307 /* tell server which Unix caps we support */ 306 /* tell server which Unix caps we support */
308 if (tcon->ses->capabilities & CAP_UNIX) 307 if (tcon->ses->capabilities & CAP_UNIX)
309 reset_cifs_unix_caps(0 /* no xid */, 308 reset_cifs_unix_caps(0 /* no xid */,
310 tcon, 309 tcon,
311 NULL /* do not know sb */, 310 NULL /* do not know sb */,
312 NULL /* no vol info */); 311 NULL /* no vol info */);
313 /* BB FIXME add code to check if wsize needs 312 /* BB FIXME add code to check if wsize needs
@@ -317,14 +316,14 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
317 atomic_inc(&tconInfoReconnectCount); 316 atomic_inc(&tconInfoReconnectCount);
318 317
319 cFYI(1, ("reconnect tcon rc = %d", rc)); 318 cFYI(1, ("reconnect tcon rc = %d", rc));
320 /* Removed call to reopen open files here - 319 /* Removed call to reopen open files here.
321 it is safer (and faster) to reopen files 320 It is safer (and faster) to reopen files
322 one at a time as needed in read and write */ 321 one at a time as needed in read and write */
323 322
324 /* Check if handle based operation so we 323 /* Check if handle based operation so we
325 know whether we can continue or not without 324 know whether we can continue or not without
326 returning to caller to reset file handle */ 325 returning to caller to reset file handle */
327 switch(smb_command) { 326 switch (smb_command) {
328 case SMB_COM_READ_ANDX: 327 case SMB_COM_READ_ANDX:
329 case SMB_COM_WRITE_ANDX: 328 case SMB_COM_WRITE_ANDX:
330 case SMB_COM_CLOSE: 329 case SMB_COM_CLOSE:
@@ -356,7 +355,7 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
356 /* from the mid flags when the request buffer can be resent without */ 355 /* from the mid flags when the request buffer can be resent without */
357 /* having to use a second distinct buffer for the response */ 356 /* having to use a second distinct buffer for the response */
358 if (response_buf) 357 if (response_buf)
359 *response_buf = *request_buf; 358 *response_buf = *request_buf;
360 359
361 header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon, 360 header_assemble((struct smb_hdr *) *request_buf, smb_command, tcon,
362 wct /*wct */ ); 361 wct /*wct */ );
@@ -367,11 +366,11 @@ smb_init(int smb_command, int wct, struct cifsTconInfo *tcon,
367 return rc; 366 return rc;
368} 367}
369 368
370static int validate_t2(struct smb_t2_rsp * pSMB) 369static int validate_t2(struct smb_t2_rsp *pSMB)
371{ 370{
372 int rc = -EINVAL; 371 int rc = -EINVAL;
373 int total_size; 372 int total_size;
374 char * pBCC; 373 char *pBCC;
375 374
376 /* check for plausible wct, bcc and t2 data and parm sizes */ 375 /* check for plausible wct, bcc and t2 data and parm sizes */
377 /* check for parm and data offset going beyond end of smb */ 376 /* check for parm and data offset going beyond end of smb */
@@ -384,19 +383,18 @@ static int validate_t2(struct smb_t2_rsp * pSMB)
384 if (total_size < 512) { 383 if (total_size < 512) {
385 total_size+=le16_to_cpu(pSMB->t2_rsp.DataCount); 384 total_size+=le16_to_cpu(pSMB->t2_rsp.DataCount);
386 /* BCC le converted in SendReceive */ 385 /* BCC le converted in SendReceive */
387 pBCC = (pSMB->hdr.WordCount * 2) + 386 pBCC = (pSMB->hdr.WordCount * 2) +
388 sizeof(struct smb_hdr) + 387 sizeof(struct smb_hdr) +
389 (char *)pSMB; 388 (char *)pSMB;
390 if ((total_size <= (*(u16 *)pBCC)) && 389 if ((total_size <= (*(u16 *)pBCC)) &&
391 (total_size < 390 (total_size <
392 CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) { 391 CIFSMaxBufSize+MAX_CIFS_HDR_SIZE)) {
393 return 0; 392 return 0;
394 } 393 }
395
396 } 394 }
397 } 395 }
398 } 396 }
399 cifs_dump_mem("Invalid transact2 SMB: ",(char *)pSMB, 397 cifs_dump_mem("Invalid transact2 SMB: ", (char *)pSMB,
400 sizeof(struct smb_t2_rsp) + 16); 398 sizeof(struct smb_t2_rsp) + 16);
401 return rc; 399 return rc;
402} 400}
@@ -408,7 +406,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
408 int rc = 0; 406 int rc = 0;
409 int bytes_returned; 407 int bytes_returned;
410 int i; 408 int i;
411 struct TCP_Server_Info * server; 409 struct TCP_Server_Info *server;
412 u16 count; 410 u16 count;
413 unsigned int secFlags; 411 unsigned int secFlags;
414 u16 dialect; 412 u16 dialect;
@@ -436,9 +434,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
436 pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS); 434 pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS);
437 if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5) 435 if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
438 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC; 436 pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
439 437
440 count = 0; 438 count = 0;
441 for(i=0;i<CIFS_NUM_PROT;i++) { 439 for (i = 0; i < CIFS_NUM_PROT; i++) {
442 strncpy(pSMB->DialectsArray+count, protocols[i].name, 16); 440 strncpy(pSMB->DialectsArray+count, protocols[i].name, 16);
443 count += strlen(protocols[i].name) + 1; 441 count += strlen(protocols[i].name) + 1;
444 /* null at end of source and target buffers anyway */ 442 /* null at end of source and target buffers anyway */
@@ -448,7 +446,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
448 446
449 rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB, 447 rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB,
450 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 448 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
451 if (rc != 0) 449 if (rc != 0)
452 goto neg_err_exit; 450 goto neg_err_exit;
453 451
454 dialect = le16_to_cpu(pSMBr->DialectIndex); 452 dialect = le16_to_cpu(pSMBr->DialectIndex);
@@ -456,16 +454,16 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
456 /* Check wct = 1 error case */ 454 /* Check wct = 1 error case */
457 if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) { 455 if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) {
458 /* core returns wct = 1, but we do not ask for core - otherwise 456 /* core returns wct = 1, but we do not ask for core - otherwise
459 small wct just comes when dialect index is -1 indicating we 457 small wct just comes when dialect index is -1 indicating we
460 could not negotiate a common dialect */ 458 could not negotiate a common dialect */
461 rc = -EOPNOTSUPP; 459 rc = -EOPNOTSUPP;
462 goto neg_err_exit; 460 goto neg_err_exit;
463#ifdef CONFIG_CIFS_WEAK_PW_HASH 461#ifdef CONFIG_CIFS_WEAK_PW_HASH
464 } else if ((pSMBr->hdr.WordCount == 13) 462 } else if ((pSMBr->hdr.WordCount == 13)
465 && ((dialect == LANMAN_PROT) 463 && ((dialect == LANMAN_PROT)
466 || (dialect == LANMAN2_PROT))) { 464 || (dialect == LANMAN2_PROT))) {
467 __s16 tmp; 465 __s16 tmp;
468 struct lanman_neg_rsp * rsp = (struct lanman_neg_rsp *)pSMBr; 466 struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr;
469 467
470 if ((secFlags & CIFSSEC_MAY_LANMAN) || 468 if ((secFlags & CIFSSEC_MAY_LANMAN) ||
471 (secFlags & CIFSSEC_MAY_PLNTXT)) 469 (secFlags & CIFSSEC_MAY_PLNTXT))
@@ -475,7 +473,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
475 " in /proc/fs/cifs/SecurityFlags")); 473 " in /proc/fs/cifs/SecurityFlags"));
476 rc = -EOPNOTSUPP; 474 rc = -EOPNOTSUPP;
477 goto neg_err_exit; 475 goto neg_err_exit;
478 } 476 }
479 server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode); 477 server->secMode = (__u8)le16_to_cpu(rsp->SecurityMode);
480 server->maxReq = le16_to_cpu(rsp->MaxMpxCount); 478 server->maxReq = le16_to_cpu(rsp->MaxMpxCount);
481 server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize), 479 server->maxBuf = min((__u32)le16_to_cpu(rsp->MaxBufSize),
@@ -504,8 +502,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
504 utc = CURRENT_TIME; 502 utc = CURRENT_TIME;
505 ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date), 503 ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date),
506 le16_to_cpu(rsp->SrvTime.Time)); 504 le16_to_cpu(rsp->SrvTime.Time));
507 cFYI(1,("SrvTime: %d sec since 1970 (utc: %d) diff: %d", 505 cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d",
508 (int)ts.tv_sec, (int)utc.tv_sec, 506 (int)ts.tv_sec, (int)utc.tv_sec,
509 (int)(utc.tv_sec - ts.tv_sec))); 507 (int)(utc.tv_sec - ts.tv_sec)));
510 val = (int)(utc.tv_sec - ts.tv_sec); 508 val = (int)(utc.tv_sec - ts.tv_sec);
511 seconds = val < 0 ? -val : val; 509 seconds = val < 0 ? -val : val;
@@ -524,9 +522,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
524 522
525 523
526 /* BB get server time for time conversions and add 524 /* BB get server time for time conversions and add
527 code to use it and timezone since this is not UTC */ 525 code to use it and timezone since this is not UTC */
528 526
529 if (rsp->EncryptionKeyLength == 527 if (rsp->EncryptionKeyLength ==
530 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) { 528 cpu_to_le16(CIFS_CRYPTO_KEY_SIZE)) {
531 memcpy(server->cryptKey, rsp->EncryptionKey, 529 memcpy(server->cryptKey, rsp->EncryptionKey,
532 CIFS_CRYPTO_KEY_SIZE); 530 CIFS_CRYPTO_KEY_SIZE);
@@ -541,7 +539,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
541 goto signing_check; 539 goto signing_check;
542#else /* weak security disabled */ 540#else /* weak security disabled */
543 } else if (pSMBr->hdr.WordCount == 13) { 541 } else if (pSMBr->hdr.WordCount == 13) {
544 cERROR(1,("mount failed, cifs module not built " 542 cERROR(1, ("mount failed, cifs module not built "
545 "with CIFS_WEAK_PW_HASH support")); 543 "with CIFS_WEAK_PW_HASH support"));
546 rc = -EOPNOTSUPP; 544 rc = -EOPNOTSUPP;
547#endif /* WEAK_PW_HASH */ 545#endif /* WEAK_PW_HASH */
@@ -560,7 +558,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
560#ifdef CONFIG_CIFS_WEAK_PW_HASH 558#ifdef CONFIG_CIFS_WEAK_PW_HASH
561 if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0) 559 if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0)
562#endif /* CIFS_WEAK_PW_HASH */ 560#endif /* CIFS_WEAK_PW_HASH */
563 cERROR(1,("Server requests plain text password" 561 cERROR(1, ("Server requests plain text password"
564 " but client support disabled")); 562 " but client support disabled"));
565 563
566 if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2) 564 if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
@@ -596,7 +594,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
596 594
597 /* BB might be helpful to save off the domain of server here */ 595 /* BB might be helpful to save off the domain of server here */
598 596
599 if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) && 597 if ((pSMBr->hdr.Flags2 & SMBFLG2_EXT_SEC) &&
600 (server->capabilities & CAP_EXTENDED_SECURITY)) { 598 (server->capabilities & CAP_EXTENDED_SECURITY)) {
601 count = pSMBr->ByteCount; 599 count = pSMBr->ByteCount;
602 if (count < 16) 600 if (count < 16)
@@ -641,7 +639,7 @@ signing_check:
641 cERROR(1, ("Server requires " 639 cERROR(1, ("Server requires "
642 "/proc/fs/cifs/PacketSigningEnabled " 640 "/proc/fs/cifs/PacketSigningEnabled "
643 "to be on")); 641 "to be on"));
644 server->secMode &= 642 server->secMode &=
645 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); 643 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
646 } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) { 644 } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) {
647 /* signing required */ 645 /* signing required */
@@ -656,11 +654,11 @@ signing_check:
656 } else { 654 } else {
657 /* signing optional ie CIFSSEC_MAY_SIGN */ 655 /* signing optional ie CIFSSEC_MAY_SIGN */
658 if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0) 656 if ((server->secMode & SECMODE_SIGN_REQUIRED) == 0)
659 server->secMode &= 657 server->secMode &=
660 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED); 658 ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
661 } 659 }
662 660
663neg_err_exit: 661neg_err_exit:
664 cifs_buf_release(pSMB); 662 cifs_buf_release(pSMB);
665 663
666 cFYI(1, ("negprot rc %d", rc)); 664 cFYI(1, ("negprot rc %d", rc));
@@ -680,7 +678,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
680 * If last user of the connection and 678 * If last user of the connection and
681 * connection alive - disconnect it 679 * connection alive - disconnect it
682 * If this is the last connection on the server session disconnect it 680 * If this is the last connection on the server session disconnect it
683 * (and inside session disconnect we should check if tcp socket needs 681 * (and inside session disconnect we should check if tcp socket needs
684 * to be freed and kernel thread woken up). 682 * to be freed and kernel thread woken up).
685 */ 683 */
686 if (tcon) 684 if (tcon)
@@ -694,18 +692,18 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
694 return -EBUSY; 692 return -EBUSY;
695 } 693 }
696 694
697 /* No need to return error on this operation if tid invalidated and 695 /* No need to return error on this operation if tid invalidated and
698 closed on server already e.g. due to tcp session crashing */ 696 closed on server already e.g. due to tcp session crashing */
699 if (tcon->tidStatus == CifsNeedReconnect) { 697 if (tcon->tidStatus == CifsNeedReconnect) {
700 up(&tcon->tconSem); 698 up(&tcon->tconSem);
701 return 0; 699 return 0;
702 } 700 }
703 701
704 if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) { 702 if ((tcon->ses == NULL) || (tcon->ses->server == NULL)) {
705 up(&tcon->tconSem); 703 up(&tcon->tconSem);
706 return -EIO; 704 return -EIO;
707 } 705 }
708 rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon, 706 rc = small_smb_init(SMB_COM_TREE_DISCONNECT, 0, tcon,
709 (void **)&smb_buffer); 707 (void **)&smb_buffer);
710 if (rc) { 708 if (rc) {
711 up(&tcon->tconSem); 709 up(&tcon->tconSem);
@@ -722,7 +720,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
722 cifs_small_buf_release(smb_buffer); 720 cifs_small_buf_release(smb_buffer);
723 up(&tcon->tconSem); 721 up(&tcon->tconSem);
724 722
725 /* No need to return error on this operation if tid invalidated and 723 /* No need to return error on this operation if tid invalidated and
726 closed on server already e.g. due to tcp session crashing */ 724 closed on server already e.g. due to tcp session crashing */
727 if (rc == -EAGAIN) 725 if (rc == -EAGAIN)
728 rc = 0; 726 rc = 0;
@@ -756,7 +754,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
756 } 754 }
757 755
758 smb_buffer_response = (struct smb_hdr *)pSMB; /* BB removeme BB */ 756 smb_buffer_response = (struct smb_hdr *)pSMB; /* BB removeme BB */
759 757
760 if (ses->server) { 758 if (ses->server) {
761 pSMB->hdr.Mid = GetNextMid(ses->server); 759 pSMB->hdr.Mid = GetNextMid(ses->server);
762 760
@@ -783,7 +781,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
783 cifs_small_buf_release(pSMB); 781 cifs_small_buf_release(pSMB);
784 782
785 /* if session dead then we do not need to do ulogoff, 783 /* if session dead then we do not need to do ulogoff,
786 since server closed smb session, no sense reporting 784 since server closed smb session, no sense reporting
787 error */ 785 error */
788 if (rc == -EAGAIN) 786 if (rc == -EAGAIN)
789 rc = 0; 787 rc = 0;
@@ -808,7 +806,7 @@ DelFileRetry:
808 806
809 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 807 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
810 name_len = 808 name_len =
811 cifsConvertToUCS((__le16 *) pSMB->fileName, fileName, 809 cifsConvertToUCS((__le16 *) pSMB->fileName, fileName,
812 PATH_MAX, nls_codepage, remap); 810 PATH_MAX, nls_codepage, remap);
813 name_len++; /* trailing null */ 811 name_len++; /* trailing null */
814 name_len *= 2; 812 name_len *= 2;
@@ -827,7 +825,7 @@ DelFileRetry:
827 cifs_stats_inc(&tcon->num_deletes); 825 cifs_stats_inc(&tcon->num_deletes);
828 if (rc) { 826 if (rc) {
829 cFYI(1, ("Error in RMFile = %d", rc)); 827 cFYI(1, ("Error in RMFile = %d", rc));
830 } 828 }
831 829
832 cifs_buf_release(pSMB); 830 cifs_buf_release(pSMB);
833 if (rc == -EAGAIN) 831 if (rc == -EAGAIN)
@@ -837,7 +835,7 @@ DelFileRetry:
837} 835}
838 836
839int 837int
840CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName, 838CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName,
841 const struct nls_table *nls_codepage, int remap) 839 const struct nls_table *nls_codepage, int remap)
842{ 840{
843 DELETE_DIRECTORY_REQ *pSMB = NULL; 841 DELETE_DIRECTORY_REQ *pSMB = NULL;
@@ -898,7 +896,7 @@ MkDirRetry:
898 return rc; 896 return rc;
899 897
900 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 898 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
901 name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name, 899 name_len = cifsConvertToUCS((__le16 *) pSMB->DirName, name,
902 PATH_MAX, nls_codepage, remap); 900 PATH_MAX, nls_codepage, remap);
903 name_len++; /* trailing null */ 901 name_len++; /* trailing null */
904 name_len *= 2; 902 name_len *= 2;
@@ -927,7 +925,7 @@ MkDirRetry:
927int 925int
928CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags, 926CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags,
929 __u64 mode, __u16 * netfid, FILE_UNIX_BASIC_INFO *pRetData, 927 __u64 mode, __u16 * netfid, FILE_UNIX_BASIC_INFO *pRetData,
930 __u32 *pOplock, const char *name, 928 __u32 *pOplock, const char *name,
931 const struct nls_table *nls_codepage, int remap) 929 const struct nls_table *nls_codepage, int remap)
932{ 930{
933 TRANSACTION2_SPI_REQ *pSMB = NULL; 931 TRANSACTION2_SPI_REQ *pSMB = NULL;
@@ -969,13 +967,13 @@ PsxCreat:
969 pSMB->Timeout = 0; 967 pSMB->Timeout = 0;
970 pSMB->Reserved2 = 0; 968 pSMB->Reserved2 = 0;
971 param_offset = offsetof(struct smb_com_transaction2_spi_req, 969 param_offset = offsetof(struct smb_com_transaction2_spi_req,
972 InformationLevel) - 4; 970 InformationLevel) - 4;
973 offset = param_offset + params; 971 offset = param_offset + params;
974 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 972 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
975 pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset); 973 pdata = (OPEN_PSX_REQ *)(((char *)&pSMB->hdr.Protocol) + offset);
976 pdata->Level = SMB_QUERY_FILE_UNIX_BASIC; 974 pdata->Level = SMB_QUERY_FILE_UNIX_BASIC;
977 pdata->Permissions = cpu_to_le64(mode); 975 pdata->Permissions = cpu_to_le64(mode);
978 pdata->PosixOpenFlags = cpu_to_le32(posix_flags); 976 pdata->PosixOpenFlags = cpu_to_le32(posix_flags);
979 pdata->OpenFlags = cpu_to_le32(*pOplock); 977 pdata->OpenFlags = cpu_to_le32(*pOplock);
980 pSMB->ParameterOffset = cpu_to_le16(param_offset); 978 pSMB->ParameterOffset = cpu_to_le16(param_offset);
981 pSMB->DataOffset = cpu_to_le16(offset); 979 pSMB->DataOffset = cpu_to_le16(offset);
@@ -990,7 +988,7 @@ PsxCreat:
990 pSMB->TotalParameterCount = pSMB->ParameterCount; 988 pSMB->TotalParameterCount = pSMB->ParameterCount;
991 pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN); 989 pSMB->InformationLevel = cpu_to_le16(SMB_POSIX_OPEN);
992 pSMB->Reserved4 = 0; 990 pSMB->Reserved4 = 0;
993 pSMB->hdr.smb_buf_length += byte_count; 991 pSMB->hdr.smb_buf_length += byte_count;
994 pSMB->ByteCount = cpu_to_le16(byte_count); 992 pSMB->ByteCount = cpu_to_le16(byte_count);
995 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 993 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
996 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 994 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
@@ -1008,9 +1006,9 @@ PsxCreat:
1008 } 1006 }
1009 1007
1010 /* copy return information to pRetData */ 1008 /* copy return information to pRetData */
1011 psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol 1009 psx_rsp = (OPEN_PSX_RSP *)((char *) &pSMBr->hdr.Protocol
1012 + le16_to_cpu(pSMBr->t2.DataOffset)); 1010 + le16_to_cpu(pSMBr->t2.DataOffset));
1013 1011
1014 *pOplock = le16_to_cpu(psx_rsp->OplockFlags); 1012 *pOplock = le16_to_cpu(psx_rsp->OplockFlags);
1015 if (netfid) 1013 if (netfid)
1016 *netfid = psx_rsp->Fid; /* cifs fid stays in le */ 1014 *netfid = psx_rsp->Fid; /* cifs fid stays in le */
@@ -1027,15 +1025,14 @@ PsxCreat:
1027 } else { 1025 } else {
1028 if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP) 1026 if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP)
1029 + sizeof(FILE_UNIX_BASIC_INFO)) { 1027 + sizeof(FILE_UNIX_BASIC_INFO)) {
1030 cERROR(1,("Open response data too small")); 1028 cERROR(1, ("Open response data too small"));
1031 pRetData->Type = -1; 1029 pRetData->Type = -1;
1032 goto psx_create_err; 1030 goto psx_create_err;
1033 } 1031 }
1034 memcpy((char *) pRetData, 1032 memcpy((char *) pRetData,
1035 (char *)psx_rsp + sizeof(OPEN_PSX_RSP), 1033 (char *)psx_rsp + sizeof(OPEN_PSX_RSP),
1036 sizeof (FILE_UNIX_BASIC_INFO)); 1034 sizeof (FILE_UNIX_BASIC_INFO));
1037 } 1035 }
1038
1039 1036
1040psx_create_err: 1037psx_create_err:
1041 cifs_buf_release(pSMB); 1038 cifs_buf_release(pSMB);
@@ -1045,7 +1042,7 @@ psx_create_err:
1045 if (rc == -EAGAIN) 1042 if (rc == -EAGAIN)
1046 goto PsxCreat; 1043 goto PsxCreat;
1047 1044
1048 return rc; 1045 return rc;
1049} 1046}
1050 1047
1051static __u16 convert_disposition(int disposition) 1048static __u16 convert_disposition(int disposition)
@@ -1082,7 +1079,7 @@ int
1082SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon, 1079SMBLegacyOpen(const int xid, struct cifsTconInfo *tcon,
1083 const char *fileName, const int openDisposition, 1080 const char *fileName, const int openDisposition,
1084 const int access_flags, const int create_options, __u16 * netfid, 1081 const int access_flags, const int create_options, __u16 * netfid,
1085 int *pOplock, FILE_ALL_INFO * pfile_info, 1082 int *pOplock, FILE_ALL_INFO * pfile_info,
1086 const struct nls_table *nls_codepage, int remap) 1083 const struct nls_table *nls_codepage, int remap)
1087{ 1084{
1088 int rc = -EACCES; 1085 int rc = -EACCES;
@@ -1124,7 +1121,7 @@ OldOpenRetry:
1124 1 = write 1121 1 = write
1125 2 = rw 1122 2 = rw
1126 3 = execute 1123 3 = execute
1127 */ 1124 */
1128 pSMB->Mode = cpu_to_le16(2); 1125 pSMB->Mode = cpu_to_le16(2);
1129 pSMB->Mode |= cpu_to_le16(0x40); /* deny none */ 1126 pSMB->Mode |= cpu_to_le16(0x40); /* deny none */
1130 /* set file as system file if special file such 1127 /* set file as system file if special file such
@@ -1143,7 +1140,8 @@ OldOpenRetry:
1143 being created */ 1140 being created */
1144 1141
1145 /* BB FIXME BB */ 1142 /* BB FIXME BB */
1146/* pSMB->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK); */ 1143/* pSMB->CreateOptions = cpu_to_le32(create_options &
1144 CREATE_OPTIONS_MASK); */
1147 /* BB FIXME END BB */ 1145 /* BB FIXME END BB */
1148 1146
1149 pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY); 1147 pSMB->Sattr = cpu_to_le16(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY);
@@ -1154,7 +1152,7 @@ OldOpenRetry:
1154 pSMB->ByteCount = cpu_to_le16(count); 1152 pSMB->ByteCount = cpu_to_le16(count);
1155 /* long_op set to 1 to allow for oplock break timeouts */ 1153 /* long_op set to 1 to allow for oplock break timeouts */
1156 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 1154 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
1157 (struct smb_hdr *) pSMBr, &bytes_returned, 1); 1155 (struct smb_hdr *) pSMBr, &bytes_returned, 1);
1158 cifs_stats_inc(&tcon->num_opens); 1156 cifs_stats_inc(&tcon->num_opens);
1159 if (rc) { 1157 if (rc) {
1160 cFYI(1, ("Error in Open = %d", rc)); 1158 cFYI(1, ("Error in Open = %d", rc));
@@ -1177,7 +1175,7 @@ OldOpenRetry:
1177 pfile_info->LastWriteTime = 0; /* BB fixme */ 1175 pfile_info->LastWriteTime = 0; /* BB fixme */
1178 pfile_info->ChangeTime = 0; /* BB fixme */ 1176 pfile_info->ChangeTime = 0; /* BB fixme */
1179 pfile_info->Attributes = 1177 pfile_info->Attributes =
1180 cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes)); 1178 cpu_to_le32(le16_to_cpu(pSMBr->FileAttributes));
1181 /* the file_info buf is endian converted by caller */ 1179 /* the file_info buf is endian converted by caller */
1182 pfile_info->AllocationSize = 1180 pfile_info->AllocationSize =
1183 cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile)); 1181 cpu_to_le64(le32_to_cpu(pSMBr->EndOfFile));
@@ -1196,7 +1194,7 @@ int
1196CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon, 1194CIFSSMBOpen(const int xid, struct cifsTconInfo *tcon,
1197 const char *fileName, const int openDisposition, 1195 const char *fileName, const int openDisposition,
1198 const int access_flags, const int create_options, __u16 * netfid, 1196 const int access_flags, const int create_options, __u16 * netfid,
1199 int *pOplock, FILE_ALL_INFO * pfile_info, 1197 int *pOplock, FILE_ALL_INFO * pfile_info,
1200 const struct nls_table *nls_codepage, int remap) 1198 const struct nls_table *nls_codepage, int remap)
1201{ 1199{
1202 int rc = -EACCES; 1200 int rc = -EACCES;
@@ -1278,9 +1276,9 @@ openRetry:
1278 /* Let caller know file was created so we can set the mode. */ 1276 /* Let caller know file was created so we can set the mode. */
1279 /* Do we care about the CreateAction in any other cases? */ 1277 /* Do we care about the CreateAction in any other cases? */
1280 if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction) 1278 if (cpu_to_le32(FILE_CREATE) == pSMBr->CreateAction)
1281 *pOplock |= CIFS_CREATE_ACTION; 1279 *pOplock |= CIFS_CREATE_ACTION;
1282 if (pfile_info) { 1280 if (pfile_info) {
1283 memcpy((char *)pfile_info,(char *)&pSMBr->CreationTime, 1281 memcpy((char *)pfile_info, (char *)&pSMBr->CreationTime,
1284 36 /* CreationTime to Attributes */); 1282 36 /* CreationTime to Attributes */);
1285 /* the file_info buf is endian converted by caller */ 1283 /* the file_info buf is endian converted by caller */
1286 pfile_info->AllocationSize = pSMBr->AllocationSize; 1284 pfile_info->AllocationSize = pSMBr->AllocationSize;
@@ -1296,10 +1294,9 @@ openRetry:
1296} 1294}
1297 1295
1298int 1296int
1299CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, 1297CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
1300 const int netfid, const unsigned int count, 1298 const unsigned int count, const __u64 lseek, unsigned int *nbytes,
1301 const __u64 lseek, unsigned int *nbytes, char **buf, 1299 char **buf, int *pbuf_type)
1302 int * pbuf_type)
1303{ 1300{
1304 int rc = -EACCES; 1301 int rc = -EACCES;
1305 READ_REQ *pSMB = NULL; 1302 READ_REQ *pSMB = NULL;
@@ -1339,16 +1336,16 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon,
1339 pSMB->ByteCount = 0; /* no need to do le conversion since 0 */ 1336 pSMB->ByteCount = 0; /* no need to do le conversion since 0 */
1340 else { 1337 else {
1341 /* old style read */ 1338 /* old style read */
1342 struct smb_com_readx_req * pSMBW = 1339 struct smb_com_readx_req *pSMBW =
1343 (struct smb_com_readx_req *)pSMB; 1340 (struct smb_com_readx_req *)pSMB;
1344 pSMBW->ByteCount = 0; 1341 pSMBW->ByteCount = 0;
1345 } 1342 }
1346 1343
1347 iov[0].iov_base = (char *)pSMB; 1344 iov[0].iov_base = (char *)pSMB;
1348 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4; 1345 iov[0].iov_len = pSMB->hdr.smb_buf_length + 4;
1349 rc = SendReceive2(xid, tcon->ses, iov, 1346 rc = SendReceive2(xid, tcon->ses, iov,
1350 1 /* num iovecs */, 1347 1 /* num iovecs */,
1351 &resp_buf_type, 0); 1348 &resp_buf_type, 0);
1352 cifs_stats_inc(&tcon->num_reads); 1349 cifs_stats_inc(&tcon->num_reads);
1353 pSMBr = (READ_RSP *)iov[0].iov_base; 1350 pSMBr = (READ_RSP *)iov[0].iov_base;
1354 if (rc) { 1351 if (rc) {
@@ -1362,18 +1359,19 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon,
1362 /*check that DataLength would not go beyond end of SMB */ 1359 /*check that DataLength would not go beyond end of SMB */
1363 if ((data_length > CIFSMaxBufSize) 1360 if ((data_length > CIFSMaxBufSize)
1364 || (data_length > count)) { 1361 || (data_length > count)) {
1365 cFYI(1,("bad length %d for count %d",data_length,count)); 1362 cFYI(1, ("bad length %d for count %d",
1363 data_length, count));
1366 rc = -EIO; 1364 rc = -EIO;
1367 *nbytes = 0; 1365 *nbytes = 0;
1368 } else { 1366 } else {
1369 pReadData = (char *) (&pSMBr->hdr.Protocol) + 1367 pReadData = (char *) (&pSMBr->hdr.Protocol) +
1370 le16_to_cpu(pSMBr->DataOffset); 1368 le16_to_cpu(pSMBr->DataOffset);
1371/* if (rc = copy_to_user(buf, pReadData, data_length)) { 1369/* if (rc = copy_to_user(buf, pReadData, data_length)) {
1372 cERROR(1,("Faulting on read rc = %d",rc)); 1370 cERROR(1,("Faulting on read rc = %d",rc));
1373 rc = -EFAULT; 1371 rc = -EFAULT;
1374 }*/ /* can not use copy_to_user when using page cache*/ 1372 }*/ /* can not use copy_to_user when using page cache*/
1375 if (*buf) 1373 if (*buf)
1376 memcpy(*buf,pReadData,data_length); 1374 memcpy(*buf, pReadData, data_length);
1377 } 1375 }
1378 } 1376 }
1379 1377
@@ -1384,8 +1382,8 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon,
1384 else if (resp_buf_type == CIFS_LARGE_BUFFER) 1382 else if (resp_buf_type == CIFS_LARGE_BUFFER)
1385 cifs_buf_release(iov[0].iov_base); 1383 cifs_buf_release(iov[0].iov_base);
1386 } else if (resp_buf_type != CIFS_NO_BUFFER) { 1384 } else if (resp_buf_type != CIFS_NO_BUFFER) {
1387 /* return buffer to caller to free */ 1385 /* return buffer to caller to free */
1388 *buf = iov[0].iov_base; 1386 *buf = iov[0].iov_base;
1389 if (resp_buf_type == CIFS_SMALL_BUFFER) 1387 if (resp_buf_type == CIFS_SMALL_BUFFER)
1390 *pbuf_type = CIFS_SMALL_BUFFER; 1388 *pbuf_type = CIFS_SMALL_BUFFER;
1391 else if (resp_buf_type == CIFS_LARGE_BUFFER) 1389 else if (resp_buf_type == CIFS_LARGE_BUFFER)
@@ -1402,7 +1400,7 @@ int
1402CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon, 1400CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
1403 const int netfid, const unsigned int count, 1401 const int netfid, const unsigned int count,
1404 const __u64 offset, unsigned int *nbytes, const char *buf, 1402 const __u64 offset, unsigned int *nbytes, const char *buf,
1405 const char __user * ubuf, const int long_op) 1403 const char __user *ubuf, const int long_op)
1406{ 1404{
1407 int rc = -EACCES; 1405 int rc = -EACCES;
1408 WRITE_REQ *pSMB = NULL; 1406 WRITE_REQ *pSMB = NULL;
@@ -1435,12 +1433,12 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
1435 pSMB->OffsetHigh = cpu_to_le32(offset >> 32); 1433 pSMB->OffsetHigh = cpu_to_le32(offset >> 32);
1436 else if ((offset >> 32) > 0) /* can not handle big offset for old srv */ 1434 else if ((offset >> 32) > 0) /* can not handle big offset for old srv */
1437 return -EIO; 1435 return -EIO;
1438 1436
1439 pSMB->Reserved = 0xFFFFFFFF; 1437 pSMB->Reserved = 0xFFFFFFFF;
1440 pSMB->WriteMode = 0; 1438 pSMB->WriteMode = 0;
1441 pSMB->Remaining = 0; 1439 pSMB->Remaining = 0;
1442 1440
1443 /* Can increase buffer size if buffer is big enough in some cases - ie we 1441 /* Can increase buffer size if buffer is big enough in some cases ie we
1444 can send more if LARGE_WRITE_X capability returned by the server and if 1442 can send more if LARGE_WRITE_X capability returned by the server and if
1445 our buffer is big enough or if we convert to iovecs on socket writes 1443 our buffer is big enough or if we convert to iovecs on socket writes
1446 and eliminate the copy to the CIFS buffer */ 1444 and eliminate the copy to the CIFS buffer */
@@ -1454,9 +1452,9 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
1454 if (bytes_sent > count) 1452 if (bytes_sent > count)
1455 bytes_sent = count; 1453 bytes_sent = count;
1456 pSMB->DataOffset = 1454 pSMB->DataOffset =
1457 cpu_to_le16(offsetof(struct smb_com_write_req,Data) - 4); 1455 cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4);
1458 if (buf) 1456 if (buf)
1459 memcpy(pSMB->Data,buf,bytes_sent); 1457 memcpy(pSMB->Data, buf, bytes_sent);
1460 else if (ubuf) { 1458 else if (ubuf) {
1461 if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) { 1459 if (copy_from_user(pSMB->Data, ubuf, bytes_sent)) {
1462 cifs_buf_release(pSMB); 1460 cifs_buf_release(pSMB);
@@ -1478,8 +1476,9 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
1478 1476
1479 if (wct == 14) 1477 if (wct == 14)
1480 pSMB->ByteCount = cpu_to_le16(byte_count); 1478 pSMB->ByteCount = cpu_to_le16(byte_count);
1481 else { /* old style write has byte count 4 bytes earlier so 4 bytes pad */ 1479 else { /* old style write has byte count 4 bytes earlier
1482 struct smb_com_writex_req * pSMBW = 1480 so 4 bytes pad */
1481 struct smb_com_writex_req *pSMBW =
1483 (struct smb_com_writex_req *)pSMB; 1482 (struct smb_com_writex_req *)pSMB;
1484 pSMBW->ByteCount = cpu_to_le16(byte_count); 1483 pSMBW->ByteCount = cpu_to_le16(byte_count);
1485 } 1484 }
@@ -1498,7 +1497,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
1498 1497
1499 cifs_buf_release(pSMB); 1498 cifs_buf_release(pSMB);
1500 1499
1501 /* Note: On -EAGAIN error only caller can retry on handle based calls 1500 /* Note: On -EAGAIN error only caller can retry on handle based calls
1502 since file handle passed in no longer valid */ 1501 since file handle passed in no longer valid */
1503 1502
1504 return rc; 1503 return rc;
@@ -1541,7 +1540,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1541 pSMB->Remaining = 0; 1540 pSMB->Remaining = 0;
1542 1541
1543 pSMB->DataOffset = 1542 pSMB->DataOffset =
1544 cpu_to_le16(offsetof(struct smb_com_write_req,Data) - 4); 1543 cpu_to_le16(offsetof(struct smb_com_write_req, Data) - 4);
1545 1544
1546 pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF); 1545 pSMB->DataLengthLow = cpu_to_le16(count & 0xFFFF);
1547 pSMB->DataLengthHigh = cpu_to_le16(count >> 16); 1546 pSMB->DataLengthHigh = cpu_to_le16(count >> 16);
@@ -1553,7 +1552,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1553 if (wct == 14) 1552 if (wct == 14)
1554 pSMB->ByteCount = cpu_to_le16(count + 1); 1553 pSMB->ByteCount = cpu_to_le16(count + 1);
1555 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ { 1554 else /* wct == 12 */ /* bigger pad, smaller smb hdr, keep offset ok */ {
1556 struct smb_com_writex_req * pSMBW = 1555 struct smb_com_writex_req *pSMBW =
1557 (struct smb_com_writex_req *)pSMB; 1556 (struct smb_com_writex_req *)pSMB;
1558 pSMBW->ByteCount = cpu_to_le16(count + 5); 1557 pSMBW->ByteCount = cpu_to_le16(count + 5);
1559 } 1558 }
@@ -1562,7 +1561,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1562 iov[0].iov_len = smb_hdr_len + 4; 1561 iov[0].iov_len = smb_hdr_len + 4;
1563 else /* wct == 12 pad bigger by four bytes */ 1562 else /* wct == 12 pad bigger by four bytes */
1564 iov[0].iov_len = smb_hdr_len + 8; 1563 iov[0].iov_len = smb_hdr_len + 8;
1565 1564
1566 1565
1567 rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type, 1566 rc = SendReceive2(xid, tcon->ses, iov, n_vec + 1, &resp_buf_type,
1568 long_op); 1567 long_op);
@@ -1579,7 +1578,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1579 *nbytes = le16_to_cpu(pSMBr->CountHigh); 1578 *nbytes = le16_to_cpu(pSMBr->CountHigh);
1580 *nbytes = (*nbytes) << 16; 1579 *nbytes = (*nbytes) << 16;
1581 *nbytes += le16_to_cpu(pSMBr->Count); 1580 *nbytes += le16_to_cpu(pSMBr->Count);
1582 } 1581 }
1583 1582
1584/* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */ 1583/* cifs_small_buf_release(pSMB); */ /* Freed earlier now in SendReceive2 */
1585 if (resp_buf_type == CIFS_SMALL_BUFFER) 1584 if (resp_buf_type == CIFS_SMALL_BUFFER)
@@ -1587,7 +1586,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
1587 else if (resp_buf_type == CIFS_LARGE_BUFFER) 1586 else if (resp_buf_type == CIFS_LARGE_BUFFER)
1588 cifs_buf_release(iov[0].iov_base); 1587 cifs_buf_release(iov[0].iov_base);
1589 1588
1590 /* Note: On -EAGAIN error only caller can retry on handle based calls 1589 /* Note: On -EAGAIN error only caller can retry on handle based calls
1591 since file handle passed in no longer valid */ 1590 since file handle passed in no longer valid */
1592 1591
1593 return rc; 1592 return rc;
@@ -1607,7 +1606,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
1607 int timeout = 0; 1606 int timeout = 0;
1608 __u16 count; 1607 __u16 count;
1609 1608
1610 cFYI(1, ("In CIFSSMBLock - timeout %d numLock %d",waitFlag,numLock)); 1609 cFYI(1, ("In CIFSSMBLock - timeout %d numLock %d", waitFlag, numLock));
1611 rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB); 1610 rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB);
1612 1611
1613 if (rc) 1612 if (rc)
@@ -1659,7 +1658,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
1659 } 1658 }
1660 cifs_small_buf_release(pSMB); 1659 cifs_small_buf_release(pSMB);
1661 1660
1662 /* Note: On -EAGAIN error only caller can retry on handle based calls 1661 /* Note: On -EAGAIN error only caller can retry on handle based calls
1663 since file handle passed in no longer valid */ 1662 since file handle passed in no longer valid */
1664 return rc; 1663 return rc;
1665} 1664}
@@ -1667,7 +1666,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
1667int 1666int
1668CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, 1667CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1669 const __u16 smb_file_id, const int get_flag, const __u64 len, 1668 const __u16 smb_file_id, const int get_flag, const __u64 len,
1670 struct file_lock *pLockData, const __u16 lock_type, 1669 struct file_lock *pLockData, const __u16 lock_type,
1671 const int waitFlag) 1670 const int waitFlag)
1672{ 1671{
1673 struct smb_com_transaction2_sfi_req *pSMB = NULL; 1672 struct smb_com_transaction2_sfi_req *pSMB = NULL;
@@ -1691,7 +1690,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1691 1690
1692 pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB; 1691 pSMBr = (struct smb_com_transaction2_sfi_rsp *)pSMB;
1693 1692
1694 params = 6; 1693 params = 6;
1695 pSMB->MaxSetupCount = 0; 1694 pSMB->MaxSetupCount = 0;
1696 pSMB->Reserved = 0; 1695 pSMB->Reserved = 0;
1697 pSMB->Flags = 0; 1696 pSMB->Flags = 0;
@@ -1716,7 +1715,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1716 pSMB->TotalDataCount = pSMB->DataCount; 1715 pSMB->TotalDataCount = pSMB->DataCount;
1717 pSMB->TotalParameterCount = pSMB->ParameterCount; 1716 pSMB->TotalParameterCount = pSMB->ParameterCount;
1718 pSMB->ParameterOffset = cpu_to_le16(param_offset); 1717 pSMB->ParameterOffset = cpu_to_le16(param_offset);
1719 parm_data = (struct cifs_posix_lock *) 1718 parm_data = (struct cifs_posix_lock *)
1720 (((char *) &pSMB->hdr.Protocol) + offset); 1719 (((char *) &pSMB->hdr.Protocol) + offset);
1721 1720
1722 parm_data->lock_type = cpu_to_le16(lock_type); 1721 parm_data->lock_type = cpu_to_le16(lock_type);
@@ -1772,7 +1771,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
1772 if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK)) 1771 if (parm_data->lock_type == cpu_to_le16(CIFS_UNLCK))
1773 pLockData->fl_type = F_UNLCK; 1772 pLockData->fl_type = F_UNLCK;
1774 } 1773 }
1775 1774
1776plk_err_exit: 1775plk_err_exit:
1777 if (pSMB) 1776 if (pSMB)
1778 cifs_small_buf_release(pSMB); 1777 cifs_small_buf_release(pSMB);
@@ -1850,7 +1849,7 @@ renameRetry:
1850 1849
1851 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 1850 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
1852 name_len = 1851 name_len =
1853 cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName, 1852 cifsConvertToUCS((__le16 *) pSMB->OldFileName, fromName,
1854 PATH_MAX, nls_codepage, remap); 1853 PATH_MAX, nls_codepage, remap);
1855 name_len++; /* trailing null */ 1854 name_len++; /* trailing null */
1856 name_len *= 2; 1855 name_len *= 2;
@@ -1862,7 +1861,7 @@ renameRetry:
1862 toName, PATH_MAX, nls_codepage, remap); 1861 toName, PATH_MAX, nls_codepage, remap);
1863 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 1862 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
1864 name_len2 *= 2; /* convert to bytes */ 1863 name_len2 *= 2; /* convert to bytes */
1865 } else { /* BB improve the check for buffer overruns BB */ 1864 } else { /* BB improve the check for buffer overruns BB */
1866 name_len = strnlen(fromName, PATH_MAX); 1865 name_len = strnlen(fromName, PATH_MAX);
1867 name_len++; /* trailing null */ 1866 name_len++; /* trailing null */
1868 strncpy(pSMB->OldFileName, fromName, name_len); 1867 strncpy(pSMB->OldFileName, fromName, name_len);
@@ -1883,7 +1882,7 @@ renameRetry:
1883 cifs_stats_inc(&tcon->num_renames); 1882 cifs_stats_inc(&tcon->num_renames);
1884 if (rc) { 1883 if (rc) {
1885 cFYI(1, ("Send error in rename = %d", rc)); 1884 cFYI(1, ("Send error in rename = %d", rc));
1886 } 1885 }
1887 1886
1888 cifs_buf_release(pSMB); 1887 cifs_buf_release(pSMB);
1889 1888
@@ -1893,13 +1892,13 @@ renameRetry:
1893 return rc; 1892 return rc;
1894} 1893}
1895 1894
1896int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon, 1895int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon,
1897 int netfid, char * target_name, 1896 int netfid, char *target_name,
1898 const struct nls_table * nls_codepage, int remap) 1897 const struct nls_table *nls_codepage, int remap)
1899{ 1898{
1900 struct smb_com_transaction2_sfi_req *pSMB = NULL; 1899 struct smb_com_transaction2_sfi_req *pSMB = NULL;
1901 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; 1900 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;
1902 struct set_file_rename * rename_info; 1901 struct set_file_rename *rename_info;
1903 char *data_offset; 1902 char *data_offset;
1904 char dummy_string[30]; 1903 char dummy_string[30];
1905 int rc = 0; 1904 int rc = 0;
@@ -1939,12 +1938,13 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon,
1939 rename_info->root_fid = 0; 1938 rename_info->root_fid = 0;
1940 /* unicode only call */ 1939 /* unicode only call */
1941 if (target_name == NULL) { 1940 if (target_name == NULL) {
1942 sprintf(dummy_string,"cifs%x",pSMB->hdr.Mid); 1941 sprintf(dummy_string, "cifs%x", pSMB->hdr.Mid);
1943 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, 1942 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
1944 dummy_string, 24, nls_codepage, remap); 1943 dummy_string, 24, nls_codepage, remap);
1945 } else { 1944 } else {
1946 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name, 1945 len_of_str = cifsConvertToUCS((__le16 *)rename_info->target_name,
1947 target_name, PATH_MAX, nls_codepage, remap); 1946 target_name, PATH_MAX, nls_codepage,
1947 remap);
1948 } 1948 }
1949 rename_info->target_name_len = cpu_to_le32(2 * len_of_str); 1949 rename_info->target_name_len = cpu_to_le32(2 * len_of_str);
1950 count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str) + 2; 1950 count = 12 /* sizeof(struct set_file_rename) */ + (2 * len_of_str) + 2;
@@ -1958,7 +1958,7 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon,
1958 pSMB->hdr.smb_buf_length += byte_count; 1958 pSMB->hdr.smb_buf_length += byte_count;
1959 pSMB->ByteCount = cpu_to_le16(byte_count); 1959 pSMB->ByteCount = cpu_to_le16(byte_count);
1960 rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB, 1960 rc = SendReceive(xid, pTcon->ses, (struct smb_hdr *) pSMB,
1961 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 1961 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
1962 cifs_stats_inc(&pTcon->num_t2renames); 1962 cifs_stats_inc(&pTcon->num_t2renames);
1963 if (rc) { 1963 if (rc) {
1964 cFYI(1, ("Send error in Rename (by file handle) = %d", rc)); 1964 cFYI(1, ("Send error in Rename (by file handle) = %d", rc));
@@ -1973,9 +1973,9 @@ int CIFSSMBRenameOpenFile(const int xid,struct cifsTconInfo *pTcon,
1973} 1973}
1974 1974
1975int 1975int
1976CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char * fromName, 1976CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName,
1977 const __u16 target_tid, const char *toName, const int flags, 1977 const __u16 target_tid, const char *toName, const int flags,
1978 const struct nls_table *nls_codepage, int remap) 1978 const struct nls_table *nls_codepage, int remap)
1979{ 1979{
1980 int rc = 0; 1980 int rc = 0;
1981 COPY_REQ *pSMB = NULL; 1981 COPY_REQ *pSMB = NULL;
@@ -1997,7 +1997,7 @@ copyRetry:
1997 pSMB->Flags = cpu_to_le16(flags & COPY_TREE); 1997 pSMB->Flags = cpu_to_le16(flags & COPY_TREE);
1998 1998
1999 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 1999 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2000 name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName, 2000 name_len = cifsConvertToUCS((__le16 *) pSMB->OldFileName,
2001 fromName, PATH_MAX, nls_codepage, 2001 fromName, PATH_MAX, nls_codepage,
2002 remap); 2002 remap);
2003 name_len++; /* trailing null */ 2003 name_len++; /* trailing null */
@@ -2005,11 +2005,12 @@ copyRetry:
2005 pSMB->OldFileName[name_len] = 0x04; /* pad */ 2005 pSMB->OldFileName[name_len] = 0x04; /* pad */
2006 /* protocol requires ASCII signature byte on Unicode string */ 2006 /* protocol requires ASCII signature byte on Unicode string */
2007 pSMB->OldFileName[name_len + 1] = 0x00; 2007 pSMB->OldFileName[name_len + 1] = 0x00;
2008 name_len2 = cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], 2008 name_len2 =
2009 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2009 toName, PATH_MAX, nls_codepage, remap); 2010 toName, PATH_MAX, nls_codepage, remap);
2010 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 2011 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
2011 name_len2 *= 2; /* convert to bytes */ 2012 name_len2 *= 2; /* convert to bytes */
2012 } else { /* BB improve the check for buffer overruns BB */ 2013 } else { /* BB improve the check for buffer overruns BB */
2013 name_len = strnlen(fromName, PATH_MAX); 2014 name_len = strnlen(fromName, PATH_MAX);
2014 name_len++; /* trailing null */ 2015 name_len++; /* trailing null */
2015 strncpy(pSMB->OldFileName, fromName, name_len); 2016 strncpy(pSMB->OldFileName, fromName, name_len);
@@ -2069,7 +2070,7 @@ createSymLinkRetry:
2069 name_len++; /* trailing null */ 2070 name_len++; /* trailing null */
2070 name_len *= 2; 2071 name_len *= 2;
2071 2072
2072 } else { /* BB improve the check for buffer overruns BB */ 2073 } else { /* BB improve the check for buffer overruns BB */
2073 name_len = strnlen(fromName, PATH_MAX); 2074 name_len = strnlen(fromName, PATH_MAX);
2074 name_len++; /* trailing null */ 2075 name_len++; /* trailing null */
2075 strncpy(pSMB->FileName, fromName, name_len); 2076 strncpy(pSMB->FileName, fromName, name_len);
@@ -2081,7 +2082,7 @@ createSymLinkRetry:
2081 pSMB->Timeout = 0; 2082 pSMB->Timeout = 0;
2082 pSMB->Reserved2 = 0; 2083 pSMB->Reserved2 = 0;
2083 param_offset = offsetof(struct smb_com_transaction2_spi_req, 2084 param_offset = offsetof(struct smb_com_transaction2_spi_req,
2084 InformationLevel) - 4; 2085 InformationLevel) - 4;
2085 offset = param_offset + params; 2086 offset = param_offset + params;
2086 2087
2087 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 2088 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
@@ -2092,7 +2093,7 @@ createSymLinkRetry:
2092 , nls_codepage); 2093 , nls_codepage);
2093 name_len_target++; /* trailing null */ 2094 name_len_target++; /* trailing null */
2094 name_len_target *= 2; 2095 name_len_target *= 2;
2095 } else { /* BB improve the check for buffer overruns BB */ 2096 } else { /* BB improve the check for buffer overruns BB */
2096 name_len_target = strnlen(toName, PATH_MAX); 2097 name_len_target = strnlen(toName, PATH_MAX);
2097 name_len_target++; /* trailing null */ 2098 name_len_target++; /* trailing null */
2098 strncpy(data_offset, toName, name_len_target); 2099 strncpy(data_offset, toName, name_len_target);
@@ -2160,7 +2161,7 @@ createHardLinkRetry:
2160 name_len++; /* trailing null */ 2161 name_len++; /* trailing null */
2161 name_len *= 2; 2162 name_len *= 2;
2162 2163
2163 } else { /* BB improve the check for buffer overruns BB */ 2164 } else { /* BB improve the check for buffer overruns BB */
2164 name_len = strnlen(toName, PATH_MAX); 2165 name_len = strnlen(toName, PATH_MAX);
2165 name_len++; /* trailing null */ 2166 name_len++; /* trailing null */
2166 strncpy(pSMB->FileName, toName, name_len); 2167 strncpy(pSMB->FileName, toName, name_len);
@@ -2172,7 +2173,7 @@ createHardLinkRetry:
2172 pSMB->Timeout = 0; 2173 pSMB->Timeout = 0;
2173 pSMB->Reserved2 = 0; 2174 pSMB->Reserved2 = 0;
2174 param_offset = offsetof(struct smb_com_transaction2_spi_req, 2175 param_offset = offsetof(struct smb_com_transaction2_spi_req,
2175 InformationLevel) - 4; 2176 InformationLevel) - 4;
2176 offset = param_offset + params; 2177 offset = param_offset + params;
2177 2178
2178 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 2179 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
@@ -2182,7 +2183,7 @@ createHardLinkRetry:
2182 nls_codepage, remap); 2183 nls_codepage, remap);
2183 name_len_target++; /* trailing null */ 2184 name_len_target++; /* trailing null */
2184 name_len_target *= 2; 2185 name_len_target *= 2;
2185 } else { /* BB improve the check for buffer overruns BB */ 2186 } else { /* BB improve the check for buffer overruns BB */
2186 name_len_target = strnlen(fromName, PATH_MAX); 2187 name_len_target = strnlen(fromName, PATH_MAX);
2187 name_len_target++; /* trailing null */ 2188 name_len_target++; /* trailing null */
2188 strncpy(data_offset, fromName, name_len_target); 2189 strncpy(data_offset, fromName, name_len_target);
@@ -2254,13 +2255,13 @@ winCreateHardLinkRetry:
2254 name_len++; /* trailing null */ 2255 name_len++; /* trailing null */
2255 name_len *= 2; 2256 name_len *= 2;
2256 pSMB->OldFileName[name_len] = 0; /* pad */ 2257 pSMB->OldFileName[name_len] = 0; /* pad */
2257 pSMB->OldFileName[name_len + 1] = 0x04; 2258 pSMB->OldFileName[name_len + 1] = 0x04;
2258 name_len2 = 2259 name_len2 =
2259 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], 2260 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2260 toName, PATH_MAX, nls_codepage, remap); 2261 toName, PATH_MAX, nls_codepage, remap);
2261 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ; 2262 name_len2 += 1 /* trailing null */ + 1 /* Signature word */ ;
2262 name_len2 *= 2; /* convert to bytes */ 2263 name_len2 *= 2; /* convert to bytes */
2263 } else { /* BB improve the check for buffer overruns BB */ 2264 } else { /* BB improve the check for buffer overruns BB */
2264 name_len = strnlen(fromName, PATH_MAX); 2265 name_len = strnlen(fromName, PATH_MAX);
2265 name_len++; /* trailing null */ 2266 name_len++; /* trailing null */
2266 strncpy(pSMB->OldFileName, fromName, name_len); 2267 strncpy(pSMB->OldFileName, fromName, name_len);
@@ -2313,12 +2314,11 @@ querySymLinkRetry:
2313 2314
2314 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2315 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2315 name_len = 2316 name_len =
2316 cifs_strtoUCS((__le16 *) pSMB->FileName, searchName, PATH_MAX 2317 cifs_strtoUCS((__le16 *) pSMB->FileName, searchName,
2317 /* find define for this maxpathcomponent */ 2318 PATH_MAX, nls_codepage);
2318 , nls_codepage);
2319 name_len++; /* trailing null */ 2319 name_len++; /* trailing null */
2320 name_len *= 2; 2320 name_len *= 2;
2321 } else { /* BB improve the check for buffer overruns BB */ 2321 } else { /* BB improve the check for buffer overruns BB */
2322 name_len = strnlen(searchName, PATH_MAX); 2322 name_len = strnlen(searchName, PATH_MAX);
2323 name_len++; /* trailing null */ 2323 name_len++; /* trailing null */
2324 strncpy(pSMB->FileName, searchName, name_len); 2324 strncpy(pSMB->FileName, searchName, name_len);
@@ -2335,7 +2335,7 @@ querySymLinkRetry:
2335 pSMB->Timeout = 0; 2335 pSMB->Timeout = 0;
2336 pSMB->Reserved2 = 0; 2336 pSMB->Reserved2 = 0;
2337 pSMB->ParameterOffset = cpu_to_le16(offsetof( 2337 pSMB->ParameterOffset = cpu_to_le16(offsetof(
2338 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 2338 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
2339 pSMB->DataCount = 0; 2339 pSMB->DataCount = 0;
2340 pSMB->DataOffset = 0; 2340 pSMB->DataOffset = 0;
2341 pSMB->SetupCount = 1; 2341 pSMB->SetupCount = 1;
@@ -2366,16 +2366,16 @@ querySymLinkRetry:
2366 2366
2367 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { 2367 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
2368 name_len = UniStrnlen((wchar_t *) ((char *) 2368 name_len = UniStrnlen((wchar_t *) ((char *)
2369 &pSMBr->hdr.Protocol +data_offset), 2369 &pSMBr->hdr.Protocol + data_offset),
2370 min_t(const int, buflen,count) / 2); 2370 min_t(const int, buflen, count) / 2);
2371 /* BB FIXME investigate remapping reserved chars here */ 2371 /* BB FIXME investigate remapping reserved chars here */
2372 cifs_strfromUCS_le(symlinkinfo, 2372 cifs_strfromUCS_le(symlinkinfo,
2373 (__le16 *) ((char *)&pSMBr->hdr.Protocol + 2373 (__le16 *) ((char *)&pSMBr->hdr.Protocol
2374 data_offset), 2374 + data_offset),
2375 name_len, nls_codepage); 2375 name_len, nls_codepage);
2376 } else { 2376 } else {
2377 strncpy(symlinkinfo, 2377 strncpy(symlinkinfo,
2378 (char *) &pSMBr->hdr.Protocol + 2378 (char *) &pSMBr->hdr.Protocol +
2379 data_offset, 2379 data_offset,
2380 min_t(const int, buflen, count)); 2380 min_t(const int, buflen, count));
2381 } 2381 }
@@ -2396,14 +2396,14 @@ querySymLinkRetry:
2396 Setup words themselves and ByteCount 2396 Setup words themselves and ByteCount
2397 MaxSetupCount (size of returned setup area) and 2397 MaxSetupCount (size of returned setup area) and
2398 MaxParameterCount (returned parms size) must be set by caller */ 2398 MaxParameterCount (returned parms size) must be set by caller */
2399static int 2399static int
2400smb_init_ntransact(const __u16 sub_command, const int setup_count, 2400smb_init_ntransact(const __u16 sub_command, const int setup_count,
2401 const int parm_len, struct cifsTconInfo *tcon, 2401 const int parm_len, struct cifsTconInfo *tcon,
2402 void ** ret_buf) 2402 void **ret_buf)
2403{ 2403{
2404 int rc; 2404 int rc;
2405 __u32 temp_offset; 2405 __u32 temp_offset;
2406 struct smb_com_ntransact_req * pSMB; 2406 struct smb_com_ntransact_req *pSMB;
2407 2407
2408 rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon, 2408 rc = small_smb_init(SMB_COM_NT_TRANSACT, 19 + setup_count, tcon,
2409 (void **)&pSMB); 2409 (void **)&pSMB);
@@ -2427,12 +2427,12 @@ smb_init_ntransact(const __u16 sub_command, const int setup_count,
2427} 2427}
2428 2428
2429static int 2429static int
2430validate_ntransact(char * buf, char ** ppparm, char ** ppdata, 2430validate_ntransact(char *buf, char **ppparm, char **ppdata,
2431 int * pdatalen, int * pparmlen) 2431 int *pdatalen, int *pparmlen)
2432{ 2432{
2433 char * end_of_smb; 2433 char *end_of_smb;
2434 __u32 data_count, data_offset, parm_count, parm_offset; 2434 __u32 data_count, data_offset, parm_count, parm_offset;
2435 struct smb_com_ntransact_rsp * pSMBr; 2435 struct smb_com_ntransact_rsp *pSMBr;
2436 2436
2437 if (buf == NULL) 2437 if (buf == NULL)
2438 return -EINVAL; 2438 return -EINVAL;
@@ -2440,13 +2440,12 @@ validate_ntransact(char * buf, char ** ppparm, char ** ppdata,
2440 pSMBr = (struct smb_com_ntransact_rsp *)buf; 2440 pSMBr = (struct smb_com_ntransact_rsp *)buf;
2441 2441
2442 /* ByteCount was converted from little endian in SendReceive */ 2442 /* ByteCount was converted from little endian in SendReceive */
2443 end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount + 2443 end_of_smb = 2 /* sizeof byte count */ + pSMBr->ByteCount +
2444 (char *)&pSMBr->ByteCount; 2444 (char *)&pSMBr->ByteCount;
2445 2445
2446
2447 data_offset = le32_to_cpu(pSMBr->DataOffset); 2446 data_offset = le32_to_cpu(pSMBr->DataOffset);
2448 data_count = le32_to_cpu(pSMBr->DataCount); 2447 data_count = le32_to_cpu(pSMBr->DataCount);
2449 parm_offset = le32_to_cpu(pSMBr->ParameterOffset); 2448 parm_offset = le32_to_cpu(pSMBr->ParameterOffset);
2450 parm_count = le32_to_cpu(pSMBr->ParameterCount); 2449 parm_count = le32_to_cpu(pSMBr->ParameterCount);
2451 2450
2452 *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset; 2451 *ppparm = (char *)&pSMBr->hdr.Protocol + parm_offset;
@@ -2464,7 +2463,8 @@ validate_ntransact(char * buf, char ** ppparm, char ** ppdata,
2464 return -EINVAL; 2463 return -EINVAL;
2465 } else if (data_count + *ppdata > end_of_smb) { 2464 } else if (data_count + *ppdata > end_of_smb) {
2466 cFYI(1,("data %p + count %d (%p) ends after end of smb %p start %p", 2465 cFYI(1,("data %p + count %d (%p) ends after end of smb %p start %p",
2467 *ppdata, data_count, (data_count + *ppdata), end_of_smb, pSMBr)); /* BB FIXME */ 2466 *ppdata, data_count, (data_count + *ppdata),
2467 end_of_smb, pSMBr));
2468 return -EINVAL; 2468 return -EINVAL;
2469 } else if (parm_count + data_count > pSMBr->ByteCount) { 2469 } else if (parm_count + data_count > pSMBr->ByteCount) {
2470 cFYI(1, ("parm count and data count larger than SMB")); 2470 cFYI(1, ("parm count and data count larger than SMB"));
@@ -2476,14 +2476,14 @@ validate_ntransact(char * buf, char ** ppparm, char ** ppdata,
2476int 2476int
2477CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon, 2477CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2478 const unsigned char *searchName, 2478 const unsigned char *searchName,
2479 char *symlinkinfo, const int buflen,__u16 fid, 2479 char *symlinkinfo, const int buflen, __u16 fid,
2480 const struct nls_table *nls_codepage) 2480 const struct nls_table *nls_codepage)
2481{ 2481{
2482 int rc = 0; 2482 int rc = 0;
2483 int bytes_returned; 2483 int bytes_returned;
2484 int name_len; 2484 int name_len;
2485 struct smb_com_transaction_ioctl_req * pSMB; 2485 struct smb_com_transaction_ioctl_req *pSMB;
2486 struct smb_com_transaction_ioctl_rsp * pSMBr; 2486 struct smb_com_transaction_ioctl_rsp *pSMBr;
2487 2487
2488 cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName)); 2488 cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName));
2489 rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, 2489 rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
@@ -2523,12 +2523,14 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2523 rc = -EIO; /* bad smb */ 2523 rc = -EIO; /* bad smb */
2524 else { 2524 else {
2525 if (data_count && (data_count < 2048)) { 2525 if (data_count && (data_count < 2048)) {
2526 char * end_of_smb = 2 /* sizeof byte count */ + 2526 char *end_of_smb = 2 /* sizeof byte count */ +
2527 pSMBr->ByteCount + 2527 pSMBr->ByteCount +
2528 (char *)&pSMBr->ByteCount; 2528 (char *)&pSMBr->ByteCount;
2529 2529
2530 struct reparse_data * reparse_buf = (struct reparse_data *) 2530 struct reparse_data *reparse_buf =
2531 ((char *)&pSMBr->hdr.Protocol + data_offset); 2531 (struct reparse_data *)
2532 ((char *)&pSMBr->hdr.Protocol
2533 + data_offset);
2532 if ((char *)reparse_buf >= end_of_smb) { 2534 if ((char *)reparse_buf >= end_of_smb) {
2533 rc = -EIO; 2535 rc = -EIO;
2534 goto qreparse_out; 2536 goto qreparse_out;
@@ -2541,20 +2543,23 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2541 rc = -EIO; 2543 rc = -EIO;
2542 goto qreparse_out; 2544 goto qreparse_out;
2543 } 2545 }
2544 2546
2545 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { 2547 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
2546 name_len = UniStrnlen((wchar_t *) 2548 name_len = UniStrnlen((wchar_t *)
2547 (reparse_buf->LinkNamesBuf + 2549 (reparse_buf->LinkNamesBuf +
2548 reparse_buf->TargetNameOffset), 2550 reparse_buf->TargetNameOffset),
2549 min(buflen/2, reparse_buf->TargetNameLen / 2)); 2551 min(buflen/2,
2552 reparse_buf->TargetNameLen / 2));
2550 cifs_strfromUCS_le(symlinkinfo, 2553 cifs_strfromUCS_le(symlinkinfo,
2551 (__le16 *) (reparse_buf->LinkNamesBuf + 2554 (__le16 *) (reparse_buf->LinkNamesBuf +
2552 reparse_buf->TargetNameOffset), 2555 reparse_buf->TargetNameOffset),
2553 name_len, nls_codepage); 2556 name_len, nls_codepage);
2554 } else { /* ASCII names */ 2557 } else { /* ASCII names */
2555 strncpy(symlinkinfo,reparse_buf->LinkNamesBuf + 2558 strncpy(symlinkinfo,
2556 reparse_buf->TargetNameOffset, 2559 reparse_buf->LinkNamesBuf +
2557 min_t(const int, buflen, reparse_buf->TargetNameLen)); 2560 reparse_buf->TargetNameOffset,
2561 min_t(const int, buflen,
2562 reparse_buf->TargetNameLen));
2558 } 2563 }
2559 } else { 2564 } else {
2560 rc = -EIO; 2565 rc = -EIO;
@@ -2562,7 +2567,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
2562 } 2567 }
2563 symlinkinfo[buflen] = 0; /* just in case so the caller 2568 symlinkinfo[buflen] = 0; /* just in case so the caller
2564 does not go off the end of the buffer */ 2569 does not go off the end of the buffer */
2565 cFYI(1,("readlink result - %s",symlinkinfo)); 2570 cFYI(1, ("readlink result - %s", symlinkinfo));
2566 } 2571 }
2567 } 2572 }
2568qreparse_out: 2573qreparse_out:
@@ -2577,7 +2582,8 @@ qreparse_out:
2577#ifdef CONFIG_CIFS_POSIX 2582#ifdef CONFIG_CIFS_POSIX
2578 2583
2579/*Convert an Access Control Entry from wire format to local POSIX xattr format*/ 2584/*Convert an Access Control Entry from wire format to local POSIX xattr format*/
2580static void cifs_convert_ace(posix_acl_xattr_entry * ace, struct cifs_posix_ace * cifs_ace) 2585static void cifs_convert_ace(posix_acl_xattr_entry *ace,
2586 struct cifs_posix_ace *cifs_ace)
2581{ 2587{
2582 /* u8 cifs fields do not need le conversion */ 2588 /* u8 cifs fields do not need le conversion */
2583 ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm); 2589 ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm);
@@ -2589,15 +2595,15 @@ static void cifs_convert_ace(posix_acl_xattr_entry * ace, struct cifs_posix_ace
2589} 2595}
2590 2596
2591/* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */ 2597/* Convert ACL from CIFS POSIX wire format to local Linux POSIX ACL xattr */
2592static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen, 2598static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen,
2593 const int acl_type,const int size_of_data_area) 2599 const int acl_type, const int size_of_data_area)
2594{ 2600{
2595 int size = 0; 2601 int size = 0;
2596 int i; 2602 int i;
2597 __u16 count; 2603 __u16 count;
2598 struct cifs_posix_ace * pACE; 2604 struct cifs_posix_ace *pACE;
2599 struct cifs_posix_acl * cifs_acl = (struct cifs_posix_acl *)src; 2605 struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)src;
2600 posix_acl_xattr_header * local_acl = (posix_acl_xattr_header *)trgt; 2606 posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)trgt;
2601 2607
2602 if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION) 2608 if (le16_to_cpu(cifs_acl->version) != CIFS_ACL_VERSION)
2603 return -EOPNOTSUPP; 2609 return -EOPNOTSUPP;
@@ -2609,7 +2615,8 @@ static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen,
2609 size += sizeof(struct cifs_posix_ace) * count; 2615 size += sizeof(struct cifs_posix_ace) * count;
2610 /* check if we would go beyond end of SMB */ 2616 /* check if we would go beyond end of SMB */
2611 if (size_of_data_area < size) { 2617 if (size_of_data_area < size) {
2612 cFYI(1,("bad CIFS POSIX ACL size %d vs. %d",size_of_data_area,size)); 2618 cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d",
2619 size_of_data_area, size));
2613 return -EINVAL; 2620 return -EINVAL;
2614 } 2621 }
2615 } else if (acl_type & ACL_TYPE_DEFAULT) { 2622 } else if (acl_type & ACL_TYPE_DEFAULT) {
@@ -2630,21 +2637,21 @@ static int cifs_copy_posix_acl(char * trgt,char * src, const int buflen,
2630 2637
2631 size = posix_acl_xattr_size(count); 2638 size = posix_acl_xattr_size(count);
2632 if ((buflen == 0) || (local_acl == NULL)) { 2639 if ((buflen == 0) || (local_acl == NULL)) {
2633 /* used to query ACL EA size */ 2640 /* used to query ACL EA size */
2634 } else if (size > buflen) { 2641 } else if (size > buflen) {
2635 return -ERANGE; 2642 return -ERANGE;
2636 } else /* buffer big enough */ { 2643 } else /* buffer big enough */ {
2637 local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION); 2644 local_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
2638 for(i = 0;i < count ;i++) { 2645 for (i = 0; i < count ; i++) {
2639 cifs_convert_ace(&local_acl->a_entries[i],pACE); 2646 cifs_convert_ace(&local_acl->a_entries[i], pACE);
2640 pACE ++; 2647 pACE++;
2641 } 2648 }
2642 } 2649 }
2643 return size; 2650 return size;
2644} 2651}
2645 2652
2646static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace * cifs_ace, 2653static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace,
2647 const posix_acl_xattr_entry * local_ace) 2654 const posix_acl_xattr_entry *local_ace)
2648{ 2655{
2649 __u16 rc = 0; /* 0 = ACL converted ok */ 2656 __u16 rc = 0; /* 0 = ACL converted ok */
2650 2657
@@ -2654,19 +2661,19 @@ static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace * cifs_ace,
2654 if (local_ace->e_id == cpu_to_le32(-1)) { 2661 if (local_ace->e_id == cpu_to_le32(-1)) {
2655 /* Probably no need to le convert -1 on any arch but can not hurt */ 2662 /* Probably no need to le convert -1 on any arch but can not hurt */
2656 cifs_ace->cifs_uid = cpu_to_le64(-1); 2663 cifs_ace->cifs_uid = cpu_to_le64(-1);
2657 } else 2664 } else
2658 cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id)); 2665 cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id));
2659 /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/ 2666 /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/
2660 return rc; 2667 return rc;
2661} 2668}
2662 2669
2663/* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */ 2670/* Convert ACL from local Linux POSIX xattr to CIFS POSIX ACL wire format */
2664static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int buflen, 2671static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL,
2665 const int acl_type) 2672 const int buflen, const int acl_type)
2666{ 2673{
2667 __u16 rc = 0; 2674 __u16 rc = 0;
2668 struct cifs_posix_acl * cifs_acl = (struct cifs_posix_acl *)parm_data; 2675 struct cifs_posix_acl *cifs_acl = (struct cifs_posix_acl *)parm_data;
2669 posix_acl_xattr_header * local_acl = (posix_acl_xattr_header *)pACL; 2676 posix_acl_xattr_header *local_acl = (posix_acl_xattr_header *)pACL;
2670 int count; 2677 int count;
2671 int i; 2678 int i;
2672 2679
@@ -2677,7 +2684,7 @@ static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int bufl
2677 cFYI(1,("setting acl with %d entries from buf of length %d and version of %d", 2684 cFYI(1,("setting acl with %d entries from buf of length %d and version of %d",
2678 count, buflen, le32_to_cpu(local_acl->a_version))); 2685 count, buflen, le32_to_cpu(local_acl->a_version)));
2679 if (le32_to_cpu(local_acl->a_version) != 2) { 2686 if (le32_to_cpu(local_acl->a_version) != 2) {
2680 cFYI(1,("unknown POSIX ACL version %d", 2687 cFYI(1, ("unknown POSIX ACL version %d",
2681 le32_to_cpu(local_acl->a_version))); 2688 le32_to_cpu(local_acl->a_version)));
2682 return 0; 2689 return 0;
2683 } 2690 }
@@ -2687,10 +2694,10 @@ static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int bufl
2687 else if (acl_type == ACL_TYPE_DEFAULT) 2694 else if (acl_type == ACL_TYPE_DEFAULT)
2688 cifs_acl->default_entry_count = cpu_to_le16(count); 2695 cifs_acl->default_entry_count = cpu_to_le16(count);
2689 else { 2696 else {
2690 cFYI(1,("unknown ACL type %d",acl_type)); 2697 cFYI(1, ("unknown ACL type %d", acl_type));
2691 return 0; 2698 return 0;
2692 } 2699 }
2693 for(i=0;i<count;i++) { 2700 for (i = 0; i < count; i++) {
2694 rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i], 2701 rc = convert_ace_to_cifs_ace(&cifs_acl->ace_array[i],
2695 &local_acl->a_entries[i]); 2702 &local_acl->a_entries[i]);
2696 if (rc != 0) { 2703 if (rc != 0) {
@@ -2708,9 +2715,9 @@ static __u16 ACL_to_cifs_posix(char * parm_data,const char * pACL,const int bufl
2708 2715
2709int 2716int
2710CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon, 2717CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon,
2711 const unsigned char *searchName, 2718 const unsigned char *searchName,
2712 char *acl_inf, const int buflen, const int acl_type, 2719 char *acl_inf, const int buflen, const int acl_type,
2713 const struct nls_table *nls_codepage, int remap) 2720 const struct nls_table *nls_codepage, int remap)
2714{ 2721{
2715/* SMB_QUERY_POSIX_ACL */ 2722/* SMB_QUERY_POSIX_ACL */
2716 TRANSACTION2_QPI_REQ *pSMB = NULL; 2723 TRANSACTION2_QPI_REQ *pSMB = NULL;
@@ -2719,7 +2726,7 @@ CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon,
2719 int bytes_returned; 2726 int bytes_returned;
2720 int name_len; 2727 int name_len;
2721 __u16 params, byte_count; 2728 __u16 params, byte_count;
2722 2729
2723 cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName)); 2730 cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName));
2724 2731
2725queryAclRetry: 2732queryAclRetry:
@@ -2727,16 +2734,16 @@ queryAclRetry:
2727 (void **) &pSMBr); 2734 (void **) &pSMBr);
2728 if (rc) 2735 if (rc)
2729 return rc; 2736 return rc;
2730 2737
2731 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2738 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2732 name_len = 2739 name_len =
2733 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 2740 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
2734 PATH_MAX, nls_codepage, remap); 2741 PATH_MAX, nls_codepage, remap);
2735 name_len++; /* trailing null */ 2742 name_len++; /* trailing null */
2736 name_len *= 2; 2743 name_len *= 2;
2737 pSMB->FileName[name_len] = 0; 2744 pSMB->FileName[name_len] = 0;
2738 pSMB->FileName[name_len+1] = 0; 2745 pSMB->FileName[name_len+1] = 0;
2739 } else { /* BB improve the check for buffer overruns BB */ 2746 } else { /* BB improve the check for buffer overruns BB */
2740 name_len = strnlen(searchName, PATH_MAX); 2747 name_len = strnlen(searchName, PATH_MAX);
2741 name_len++; /* trailing null */ 2748 name_len++; /* trailing null */
2742 strncpy(pSMB->FileName, searchName, name_len); 2749 strncpy(pSMB->FileName, searchName, name_len);
@@ -2745,7 +2752,7 @@ queryAclRetry:
2745 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; 2752 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ;
2746 pSMB->TotalDataCount = 0; 2753 pSMB->TotalDataCount = 0;
2747 pSMB->MaxParameterCount = cpu_to_le16(2); 2754 pSMB->MaxParameterCount = cpu_to_le16(2);
2748 /* BB find exact max data count below from sess structure BB */ 2755 /* BB find exact max data count below from sess structure BB */
2749 pSMB->MaxDataCount = cpu_to_le16(4000); 2756 pSMB->MaxDataCount = cpu_to_le16(4000);
2750 pSMB->MaxSetupCount = 0; 2757 pSMB->MaxSetupCount = 0;
2751 pSMB->Reserved = 0; 2758 pSMB->Reserved = 0;
@@ -2753,7 +2760,8 @@ queryAclRetry:
2753 pSMB->Timeout = 0; 2760 pSMB->Timeout = 0;
2754 pSMB->Reserved2 = 0; 2761 pSMB->Reserved2 = 0;
2755 pSMB->ParameterOffset = cpu_to_le16( 2762 pSMB->ParameterOffset = cpu_to_le16(
2756 offsetof(struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 2763 offsetof(struct smb_com_transaction2_qpi_req,
2764 InformationLevel) - 4);
2757 pSMB->DataCount = 0; 2765 pSMB->DataCount = 0;
2758 pSMB->DataOffset = 0; 2766 pSMB->DataOffset = 0;
2759 pSMB->SetupCount = 1; 2767 pSMB->SetupCount = 1;
@@ -2774,7 +2782,7 @@ queryAclRetry:
2774 cFYI(1, ("Send error in Query POSIX ACL = %d", rc)); 2782 cFYI(1, ("Send error in Query POSIX ACL = %d", rc));
2775 } else { 2783 } else {
2776 /* decode response */ 2784 /* decode response */
2777 2785
2778 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 2786 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
2779 if (rc || (pSMBr->ByteCount < 2)) 2787 if (rc || (pSMBr->ByteCount < 2))
2780 /* BB also check enough total bytes returned */ 2788 /* BB also check enough total bytes returned */
@@ -2784,7 +2792,7 @@ queryAclRetry:
2784 __u16 count = le16_to_cpu(pSMBr->t2.DataCount); 2792 __u16 count = le16_to_cpu(pSMBr->t2.DataCount);
2785 rc = cifs_copy_posix_acl(acl_inf, 2793 rc = cifs_copy_posix_acl(acl_inf,
2786 (char *)&pSMBr->hdr.Protocol+data_offset, 2794 (char *)&pSMBr->hdr.Protocol+data_offset,
2787 buflen,acl_type,count); 2795 buflen, acl_type, count);
2788 } 2796 }
2789 } 2797 }
2790 cifs_buf_release(pSMB); 2798 cifs_buf_release(pSMB);
@@ -2795,10 +2803,10 @@ queryAclRetry:
2795 2803
2796int 2804int
2797CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon, 2805CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon,
2798 const unsigned char *fileName, 2806 const unsigned char *fileName,
2799 const char *local_acl, const int buflen, 2807 const char *local_acl, const int buflen,
2800 const int acl_type, 2808 const int acl_type,
2801 const struct nls_table *nls_codepage, int remap) 2809 const struct nls_table *nls_codepage, int remap)
2802{ 2810{
2803 struct smb_com_transaction2_spi_req *pSMB = NULL; 2811 struct smb_com_transaction2_spi_req *pSMB = NULL;
2804 struct smb_com_transaction2_spi_rsp *pSMBr = NULL; 2812 struct smb_com_transaction2_spi_rsp *pSMBr = NULL;
@@ -2811,16 +2819,16 @@ CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon,
2811 cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName)); 2819 cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName));
2812setAclRetry: 2820setAclRetry:
2813 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, 2821 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
2814 (void **) &pSMBr); 2822 (void **) &pSMBr);
2815 if (rc) 2823 if (rc)
2816 return rc; 2824 return rc;
2817 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 2825 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
2818 name_len = 2826 name_len =
2819 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, 2827 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
2820 PATH_MAX, nls_codepage, remap); 2828 PATH_MAX, nls_codepage, remap);
2821 name_len++; /* trailing null */ 2829 name_len++; /* trailing null */
2822 name_len *= 2; 2830 name_len *= 2;
2823 } else { /* BB improve the check for buffer overruns BB */ 2831 } else { /* BB improve the check for buffer overruns BB */
2824 name_len = strnlen(fileName, PATH_MAX); 2832 name_len = strnlen(fileName, PATH_MAX);
2825 name_len++; /* trailing null */ 2833 name_len++; /* trailing null */
2826 strncpy(pSMB->FileName, fileName, name_len); 2834 strncpy(pSMB->FileName, fileName, name_len);
@@ -2834,13 +2842,13 @@ setAclRetry:
2834 pSMB->Timeout = 0; 2842 pSMB->Timeout = 0;
2835 pSMB->Reserved2 = 0; 2843 pSMB->Reserved2 = 0;
2836 param_offset = offsetof(struct smb_com_transaction2_spi_req, 2844 param_offset = offsetof(struct smb_com_transaction2_spi_req,
2837 InformationLevel) - 4; 2845 InformationLevel) - 4;
2838 offset = param_offset + params; 2846 offset = param_offset + params;
2839 parm_data = ((char *) &pSMB->hdr.Protocol) + offset; 2847 parm_data = ((char *) &pSMB->hdr.Protocol) + offset;
2840 pSMB->ParameterOffset = cpu_to_le16(param_offset); 2848 pSMB->ParameterOffset = cpu_to_le16(param_offset);
2841 2849
2842 /* convert to on the wire format for POSIX ACL */ 2850 /* convert to on the wire format for POSIX ACL */
2843 data_count = ACL_to_cifs_posix(parm_data,local_acl,buflen,acl_type); 2851 data_count = ACL_to_cifs_posix(parm_data, local_acl, buflen, acl_type);
2844 2852
2845 if (data_count == 0) { 2853 if (data_count == 0) {
2846 rc = -EOPNOTSUPP; 2854 rc = -EOPNOTSUPP;
@@ -2860,7 +2868,7 @@ setAclRetry:
2860 pSMB->hdr.smb_buf_length += byte_count; 2868 pSMB->hdr.smb_buf_length += byte_count;
2861 pSMB->ByteCount = cpu_to_le16(byte_count); 2869 pSMB->ByteCount = cpu_to_le16(byte_count);
2862 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 2870 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
2863 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 2871 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
2864 if (rc) { 2872 if (rc) {
2865 cFYI(1, ("Set POSIX ACL returned %d", rc)); 2873 cFYI(1, ("Set POSIX ACL returned %d", rc));
2866 } 2874 }
@@ -2875,13 +2883,13 @@ setACLerrorExit:
2875/* BB fix tabs in this function FIXME BB */ 2883/* BB fix tabs in this function FIXME BB */
2876int 2884int
2877CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon, 2885CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon,
2878 const int netfid, __u64 * pExtAttrBits, __u64 *pMask) 2886 const int netfid, __u64 * pExtAttrBits, __u64 *pMask)
2879{ 2887{
2880 int rc = 0; 2888 int rc = 0;
2881 struct smb_t2_qfi_req *pSMB = NULL; 2889 struct smb_t2_qfi_req *pSMB = NULL;
2882 struct smb_t2_qfi_rsp *pSMBr = NULL; 2890 struct smb_t2_qfi_rsp *pSMBr = NULL;
2883 int bytes_returned; 2891 int bytes_returned;
2884 __u16 params, byte_count; 2892 __u16 params, byte_count;
2885 2893
2886 cFYI(1, ("In GetExtAttr")); 2894 cFYI(1, ("In GetExtAttr"));
2887 if (tcon == NULL) 2895 if (tcon == NULL)
@@ -2965,7 +2973,7 @@ static const struct cifs_sid sid_user =
2965 {1, 2 , {0, 0, 0, 0, 0, 5}, {32, 545, 0, 0}}; 2973 {1, 2 , {0, 0, 0, 0, 0, 5}, {32, 545, 0, 0}};
2966 2974
2967/* Convert CIFS ACL to POSIX form */ 2975/* Convert CIFS ACL to POSIX form */
2968static int parse_sec_desc(struct cifs_sid * psec_desc, int acl_len) 2976static int parse_sec_desc(struct cifs_sid *psec_desc, int acl_len)
2969{ 2977{
2970 return 0; 2978 return 0;
2971} 2979}
@@ -2973,7 +2981,7 @@ static int parse_sec_desc(struct cifs_sid * psec_desc, int acl_len)
2973/* Get Security Descriptor (by handle) from remote server for a file or dir */ 2981/* Get Security Descriptor (by handle) from remote server for a file or dir */
2974int 2982int
2975CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid, 2983CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
2976 /* BB fix up return info */ char *acl_inf, const int buflen, 2984 /* BB fix up return info */ char *acl_inf, const int buflen,
2977 const int acl_type /* ACCESS/DEFAULT not sure implication */) 2985 const int acl_type /* ACCESS/DEFAULT not sure implication */)
2978{ 2986{
2979 int rc = 0; 2987 int rc = 0;
@@ -2983,7 +2991,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
2983 2991
2984 cFYI(1, ("GetCifsACL")); 2992 cFYI(1, ("GetCifsACL"));
2985 2993
2986 rc = smb_init_ntransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0, 2994 rc = smb_init_ntransact(NT_TRANSACT_QUERY_SECURITY_DESC, 0,
2987 8 /* parm len */, tcon, (void **) &pSMB); 2995 8 /* parm len */, tcon, (void **) &pSMB);
2988 if (rc) 2996 if (rc)
2989 return rc; 2997 return rc;
@@ -3004,23 +3012,23 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
3004 if (rc) { 3012 if (rc) {
3005 cFYI(1, ("Send error in QuerySecDesc = %d", rc)); 3013 cFYI(1, ("Send error in QuerySecDesc = %d", rc));
3006 } else { /* decode response */ 3014 } else { /* decode response */
3007 struct cifs_sid * psec_desc; 3015 struct cifs_sid *psec_desc;
3008 __le32 * parm; 3016 __le32 * parm;
3009 int parm_len; 3017 int parm_len;
3010 int data_len; 3018 int data_len;
3011 int acl_len; 3019 int acl_len;
3012 struct smb_com_ntransact_rsp * pSMBr; 3020 struct smb_com_ntransact_rsp *pSMBr;
3013 3021
3014/* validate_nttransact */ 3022/* validate_nttransact */
3015 rc = validate_ntransact(iov[0].iov_base, (char **)&parm, 3023 rc = validate_ntransact(iov[0].iov_base, (char **)&parm,
3016 (char **)&psec_desc, 3024 (char **)&psec_desc,
3017 &parm_len, &data_len); 3025 &parm_len, &data_len);
3018
3019 if (rc) 3026 if (rc)
3020 goto qsec_out; 3027 goto qsec_out;
3021 pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base; 3028 pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base;
3022 3029
3023 cERROR(1,("smb %p parm %p data %p",pSMBr,parm,psec_desc)); /* BB removeme BB */ 3030 cERROR(1, ("smb %p parm %p data %p",
3031 pSMBr, parm, psec_desc)); /* BB removeme BB */
3024 3032
3025 if (le32_to_cpu(pSMBr->ParameterCount) != 4) { 3033 if (le32_to_cpu(pSMBr->ParameterCount) != 4) {
3026 rc = -EIO; /* bad smb */ 3034 rc = -EIO; /* bad smb */
@@ -3046,9 +3054,9 @@ qsec_out:
3046/* Legacy Query Path Information call for lookup to old servers such 3054/* Legacy Query Path Information call for lookup to old servers such
3047 as Win9x/WinME */ 3055 as Win9x/WinME */
3048int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon, 3056int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon,
3049 const unsigned char *searchName, 3057 const unsigned char *searchName,
3050 FILE_ALL_INFO * pFinfo, 3058 FILE_ALL_INFO *pFinfo,
3051 const struct nls_table *nls_codepage, int remap) 3059 const struct nls_table *nls_codepage, int remap)
3052{ 3060{
3053 QUERY_INFORMATION_REQ * pSMB; 3061 QUERY_INFORMATION_REQ * pSMB;
3054 QUERY_INFORMATION_RSP * pSMBr; 3062 QUERY_INFORMATION_RSP * pSMBr;
@@ -3056,31 +3064,31 @@ int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon,
3056 int bytes_returned; 3064 int bytes_returned;
3057 int name_len; 3065 int name_len;
3058 3066
3059 cFYI(1, ("In SMBQPath path %s", searchName)); 3067 cFYI(1, ("In SMBQPath path %s", searchName));
3060QInfRetry: 3068QInfRetry:
3061 rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB, 3069 rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB,
3062 (void **) &pSMBr); 3070 (void **) &pSMBr);
3063 if (rc) 3071 if (rc)
3064 return rc; 3072 return rc;
3065 3073
3066 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3074 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3067 name_len = 3075 name_len =
3068 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 3076 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3069 PATH_MAX, nls_codepage, remap); 3077 PATH_MAX, nls_codepage, remap);
3070 name_len++; /* trailing null */ 3078 name_len++; /* trailing null */
3071 name_len *= 2; 3079 name_len *= 2;
3072 } else { 3080 } else {
3073 name_len = strnlen(searchName, PATH_MAX); 3081 name_len = strnlen(searchName, PATH_MAX);
3074 name_len++; /* trailing null */ 3082 name_len++; /* trailing null */
3075 strncpy(pSMB->FileName, searchName, name_len); 3083 strncpy(pSMB->FileName, searchName, name_len);
3076 } 3084 }
3077 pSMB->BufferFormat = 0x04; 3085 pSMB->BufferFormat = 0x04;
3078 name_len++; /* account for buffer type byte */ 3086 name_len++; /* account for buffer type byte */
3079 pSMB->hdr.smb_buf_length += (__u16) name_len; 3087 pSMB->hdr.smb_buf_length += (__u16) name_len;
3080 pSMB->ByteCount = cpu_to_le16(name_len); 3088 pSMB->ByteCount = cpu_to_le16(name_len);
3081 3089
3082 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 3090 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
3083 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 3091 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
3084 if (rc) { 3092 if (rc) {
3085 cFYI(1, ("Send error in QueryInfo = %d", rc)); 3093 cFYI(1, ("Send error in QueryInfo = %d", rc));
3086 } else if (pFinfo) { /* decode response */ 3094 } else if (pFinfo) { /* decode response */
@@ -3137,17 +3145,17 @@ QPathInfoRetry:
3137 3145
3138 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3146 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3139 name_len = 3147 name_len =
3140 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 3148 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3141 PATH_MAX, nls_codepage, remap); 3149 PATH_MAX, nls_codepage, remap);
3142 name_len++; /* trailing null */ 3150 name_len++; /* trailing null */
3143 name_len *= 2; 3151 name_len *= 2;
3144 } else { /* BB improve the check for buffer overruns BB */ 3152 } else { /* BB improve the check for buffer overruns BB */
3145 name_len = strnlen(searchName, PATH_MAX); 3153 name_len = strnlen(searchName, PATH_MAX);
3146 name_len++; /* trailing null */ 3154 name_len++; /* trailing null */
3147 strncpy(pSMB->FileName, searchName, name_len); 3155 strncpy(pSMB->FileName, searchName, name_len);
3148 } 3156 }
3149 3157
3150 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; 3158 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
3151 pSMB->TotalDataCount = 0; 3159 pSMB->TotalDataCount = 0;
3152 pSMB->MaxParameterCount = cpu_to_le16(2); 3160 pSMB->MaxParameterCount = cpu_to_le16(2);
3153 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ 3161 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
@@ -3157,7 +3165,7 @@ QPathInfoRetry:
3157 pSMB->Timeout = 0; 3165 pSMB->Timeout = 0;
3158 pSMB->Reserved2 = 0; 3166 pSMB->Reserved2 = 0;
3159 pSMB->ParameterOffset = cpu_to_le16(offsetof( 3167 pSMB->ParameterOffset = cpu_to_le16(offsetof(
3160 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 3168 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
3161 pSMB->DataCount = 0; 3169 pSMB->DataCount = 0;
3162 pSMB->DataOffset = 0; 3170 pSMB->DataOffset = 0;
3163 pSMB->SetupCount = 1; 3171 pSMB->SetupCount = 1;
@@ -3183,11 +3191,12 @@ QPathInfoRetry:
3183 3191
3184 if (rc) /* BB add auto retry on EOPNOTSUPP? */ 3192 if (rc) /* BB add auto retry on EOPNOTSUPP? */
3185 rc = -EIO; 3193 rc = -EIO;
3186 else if (!legacy && (pSMBr->ByteCount < 40)) 3194 else if (!legacy && (pSMBr->ByteCount < 40))
3187 rc = -EIO; /* bad smb */ 3195 rc = -EIO; /* bad smb */
3188 else if (legacy && (pSMBr->ByteCount < 24)) 3196 else if (legacy && (pSMBr->ByteCount < 24))
3189 rc = -EIO; /* 24 or 26 expected but we do not read last field */ 3197 rc = -EIO; /* 24 or 26 expected but we do not read
3190 else if (pFindData){ 3198 last field */
3199 else if (pFindData) {
3191 int size; 3200 int size;
3192 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 3201 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
3193 if (legacy) /* we do not read the last field, EAsize, 3202 if (legacy) /* we do not read the last field, EAsize,
@@ -3237,24 +3246,24 @@ UnixQPathInfoRetry:
3237 PATH_MAX, nls_codepage, remap); 3246 PATH_MAX, nls_codepage, remap);
3238 name_len++; /* trailing null */ 3247 name_len++; /* trailing null */
3239 name_len *= 2; 3248 name_len *= 2;
3240 } else { /* BB improve the check for buffer overruns BB */ 3249 } else { /* BB improve the check for buffer overruns BB */
3241 name_len = strnlen(searchName, PATH_MAX); 3250 name_len = strnlen(searchName, PATH_MAX);
3242 name_len++; /* trailing null */ 3251 name_len++; /* trailing null */
3243 strncpy(pSMB->FileName, searchName, name_len); 3252 strncpy(pSMB->FileName, searchName, name_len);
3244 } 3253 }
3245 3254
3246 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; 3255 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
3247 pSMB->TotalDataCount = 0; 3256 pSMB->TotalDataCount = 0;
3248 pSMB->MaxParameterCount = cpu_to_le16(2); 3257 pSMB->MaxParameterCount = cpu_to_le16(2);
3249 /* BB find exact max SMB PDU from sess structure BB */ 3258 /* BB find exact max SMB PDU from sess structure BB */
3250 pSMB->MaxDataCount = cpu_to_le16(4000); 3259 pSMB->MaxDataCount = cpu_to_le16(4000);
3251 pSMB->MaxSetupCount = 0; 3260 pSMB->MaxSetupCount = 0;
3252 pSMB->Reserved = 0; 3261 pSMB->Reserved = 0;
3253 pSMB->Flags = 0; 3262 pSMB->Flags = 0;
3254 pSMB->Timeout = 0; 3263 pSMB->Timeout = 0;
3255 pSMB->Reserved2 = 0; 3264 pSMB->Reserved2 = 0;
3256 pSMB->ParameterOffset = cpu_to_le16(offsetof( 3265 pSMB->ParameterOffset = cpu_to_le16(offsetof(
3257 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 3266 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
3258 pSMB->DataCount = 0; 3267 pSMB->DataCount = 0;
3259 pSMB->DataOffset = 0; 3268 pSMB->DataOffset = 0;
3260 pSMB->SetupCount = 1; 3269 pSMB->SetupCount = 1;
@@ -3314,12 +3323,11 @@ findUniqueRetry:
3314 3323
3315 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3324 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3316 name_len = 3325 name_len =
3317 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, PATH_MAX 3326 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3318 /* find define for this maxpathcomponent */ 3327 PATH_MAX, nls_codepage);
3319 , nls_codepage);
3320 name_len++; /* trailing null */ 3328 name_len++; /* trailing null */
3321 name_len *= 2; 3329 name_len *= 2;
3322 } else { /* BB improve the check for buffer overruns BB */ 3330 } else { /* BB improve the check for buffer overruns BB */
3323 name_len = strnlen(searchName, PATH_MAX); 3331 name_len = strnlen(searchName, PATH_MAX);
3324 name_len++; /* trailing null */ 3332 name_len++; /* trailing null */
3325 strncpy(pSMB->FileName, searchName, name_len); 3333 strncpy(pSMB->FileName, searchName, name_len);
@@ -3335,7 +3343,7 @@ findUniqueRetry:
3335 pSMB->Timeout = 0; 3343 pSMB->Timeout = 0;
3336 pSMB->Reserved2 = 0; 3344 pSMB->Reserved2 = 0;
3337 pSMB->ParameterOffset = cpu_to_le16( 3345 pSMB->ParameterOffset = cpu_to_le16(
3338 offsetof(struct smb_com_transaction2_ffirst_req,InformationLevel) - 4); 3346 offsetof(struct smb_com_transaction2_ffirst_req, InformationLevel)-4);
3339 pSMB->DataCount = 0; 3347 pSMB->DataCount = 0;
3340 pSMB->DataOffset = 0; 3348 pSMB->DataOffset = 0;
3341 pSMB->SetupCount = 1; /* one byte, no need to le convert */ 3349 pSMB->SetupCount = 1; /* one byte, no need to le convert */
@@ -3375,10 +3383,10 @@ findUniqueRetry:
3375/* xid, tcon, searchName and codepage are input parms, rest are returned */ 3383/* xid, tcon, searchName and codepage are input parms, rest are returned */
3376int 3384int
3377CIFSFindFirst(const int xid, struct cifsTconInfo *tcon, 3385CIFSFindFirst(const int xid, struct cifsTconInfo *tcon,
3378 const char *searchName, 3386 const char *searchName,
3379 const struct nls_table *nls_codepage, 3387 const struct nls_table *nls_codepage,
3380 __u16 * pnetfid, 3388 __u16 *pnetfid,
3381 struct cifs_search_info * psrch_inf, int remap, const char dirsep) 3389 struct cifs_search_info *psrch_inf, int remap, const char dirsep)
3382{ 3390{
3383/* level 257 SMB_ */ 3391/* level 257 SMB_ */
3384 TRANSACTION2_FFIRST_REQ *pSMB = NULL; 3392 TRANSACTION2_FFIRST_REQ *pSMB = NULL;
@@ -3389,7 +3397,7 @@ CIFSFindFirst(const int xid, struct cifsTconInfo *tcon,
3389 int name_len; 3397 int name_len;
3390 __u16 params, byte_count; 3398 __u16 params, byte_count;
3391 3399
3392 cFYI(1, ("In FindFirst for %s",searchName)); 3400 cFYI(1, ("In FindFirst for %s", searchName));
3393 3401
3394findFirstRetry: 3402findFirstRetry:
3395 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, 3403 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -3399,7 +3407,7 @@ findFirstRetry:
3399 3407
3400 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3408 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3401 name_len = 3409 name_len =
3402 cifsConvertToUCS((__le16 *) pSMB->FileName,searchName, 3410 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3403 PATH_MAX, nls_codepage, remap); 3411 PATH_MAX, nls_codepage, remap);
3404 /* We can not add the asterik earlier in case 3412 /* We can not add the asterik earlier in case
3405 it got remapped to 0xF03A as if it were part of the 3413 it got remapped to 0xF03A as if it were part of the
@@ -3449,8 +3457,8 @@ findFirstRetry:
3449 pSMB->SearchAttributes = 3457 pSMB->SearchAttributes =
3450 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | 3458 cpu_to_le16(ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM |
3451 ATTR_DIRECTORY); 3459 ATTR_DIRECTORY);
3452 pSMB->SearchCount= cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO)); 3460 pSMB->SearchCount = cpu_to_le16(CIFSMaxBufSize/sizeof(FILE_UNIX_INFO));
3453 pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END | 3461 pSMB->SearchFlags = cpu_to_le16(CIFS_SEARCH_CLOSE_AT_END |
3454 CIFS_SEARCH_RETURN_RESUME); 3462 CIFS_SEARCH_RETURN_RESUME);
3455 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level); 3463 pSMB->InformationLevel = cpu_to_le16(psrch_inf->info_level);
3456 3464
@@ -3485,8 +3493,8 @@ findFirstRetry:
3485 3493
3486 psrch_inf->ntwrk_buf_start = (char *)pSMBr; 3494 psrch_inf->ntwrk_buf_start = (char *)pSMBr;
3487 psrch_inf->smallBuf = 0; 3495 psrch_inf->smallBuf = 0;
3488 psrch_inf->srch_entries_start = 3496 psrch_inf->srch_entries_start =
3489 (char *) &pSMBr->hdr.Protocol + 3497 (char *) &pSMBr->hdr.Protocol +
3490 le16_to_cpu(pSMBr->t2.DataOffset); 3498 le16_to_cpu(pSMBr->t2.DataOffset);
3491 parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol + 3499 parms = (T2_FFIRST_RSP_PARMS *)((char *) &pSMBr->hdr.Protocol +
3492 le16_to_cpu(pSMBr->t2.ParameterOffset)); 3500 le16_to_cpu(pSMBr->t2.ParameterOffset));
@@ -3496,7 +3504,8 @@ findFirstRetry:
3496 else 3504 else
3497 psrch_inf->endOfSearch = FALSE; 3505 psrch_inf->endOfSearch = FALSE;
3498 3506
3499 psrch_inf->entries_in_buffer = le16_to_cpu(parms->SearchCount); 3507 psrch_inf->entries_in_buffer =
3508 le16_to_cpu(parms->SearchCount);
3500 psrch_inf->index_of_last_entry = 2 /* skip . and .. */ + 3509 psrch_inf->index_of_last_entry = 2 /* skip . and .. */ +
3501 psrch_inf->entries_in_buffer; 3510 psrch_inf->entries_in_buffer;
3502 *pnetfid = parms->SearchHandle; 3511 *pnetfid = parms->SearchHandle;
@@ -3509,7 +3518,7 @@ findFirstRetry:
3509} 3518}
3510 3519
3511int CIFSFindNext(const int xid, struct cifsTconInfo *tcon, 3520int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
3512 __u16 searchHandle, struct cifs_search_info * psrch_inf) 3521 __u16 searchHandle, struct cifs_search_info *psrch_inf)
3513{ 3522{
3514 TRANSACTION2_FNEXT_REQ *pSMB = NULL; 3523 TRANSACTION2_FNEXT_REQ *pSMB = NULL;
3515 TRANSACTION2_FNEXT_RSP *pSMBr = NULL; 3524 TRANSACTION2_FNEXT_RSP *pSMBr = NULL;
@@ -3529,12 +3538,13 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
3529 if (rc) 3538 if (rc)
3530 return rc; 3539 return rc;
3531 3540
3532 params = 14; /* includes 2 bytes of null string, converted to LE below */ 3541 params = 14; /* includes 2 bytes of null string, converted to LE below*/
3533 byte_count = 0; 3542 byte_count = 0;
3534 pSMB->TotalDataCount = 0; /* no EAs */ 3543 pSMB->TotalDataCount = 0; /* no EAs */
3535 pSMB->MaxParameterCount = cpu_to_le16(8); 3544 pSMB->MaxParameterCount = cpu_to_le16(8);
3536 pSMB->MaxDataCount = 3545 pSMB->MaxDataCount =
3537 cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) & 0xFFFFFF00); 3546 cpu_to_le16((tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE) &
3547 0xFFFFFF00);
3538 pSMB->MaxSetupCount = 0; 3548 pSMB->MaxSetupCount = 0;
3539 pSMB->Reserved = 0; 3549 pSMB->Reserved = 0;
3540 pSMB->Flags = 0; 3550 pSMB->Flags = 0;
@@ -3581,19 +3591,19 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
3581 pSMB->ParameterCount = pSMB->TotalParameterCount; 3591 pSMB->ParameterCount = pSMB->TotalParameterCount;
3582 pSMB->hdr.smb_buf_length += byte_count; 3592 pSMB->hdr.smb_buf_length += byte_count;
3583 pSMB->ByteCount = cpu_to_le16(byte_count); 3593 pSMB->ByteCount = cpu_to_le16(byte_count);
3584 3594
3585 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 3595 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
3586 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 3596 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
3587 cifs_stats_inc(&tcon->num_fnext); 3597 cifs_stats_inc(&tcon->num_fnext);
3588 if (rc) { 3598 if (rc) {
3589 if (rc == -EBADF) { 3599 if (rc == -EBADF) {
3590 psrch_inf->endOfSearch = TRUE; 3600 psrch_inf->endOfSearch = TRUE;
3591 rc = 0; /* search probably was closed at end of search above */ 3601 rc = 0; /* search probably was closed at end of search*/
3592 } else 3602 } else
3593 cFYI(1, ("FindNext returned = %d", rc)); 3603 cFYI(1, ("FindNext returned = %d", rc));
3594 } else { /* decode response */ 3604 } else { /* decode response */
3595 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3605 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
3596 3606
3597 if (rc == 0) { 3607 if (rc == 0) {
3598 /* BB fixme add lock for file (srch_info) struct here */ 3608 /* BB fixme add lock for file (srch_info) struct here */
3599 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) 3609 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE)
@@ -3617,11 +3627,12 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
3617 psrch_inf->endOfSearch = TRUE; 3627 psrch_inf->endOfSearch = TRUE;
3618 else 3628 else
3619 psrch_inf->endOfSearch = FALSE; 3629 psrch_inf->endOfSearch = FALSE;
3620 3630 psrch_inf->entries_in_buffer =
3621 psrch_inf->entries_in_buffer = le16_to_cpu(parms->SearchCount); 3631 le16_to_cpu(parms->SearchCount);
3622 psrch_inf->index_of_last_entry += 3632 psrch_inf->index_of_last_entry +=
3623 psrch_inf->entries_in_buffer; 3633 psrch_inf->entries_in_buffer;
3624/* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",psrch_inf->entries_in_buffer,psrch_inf->index_of_last_entry)); */ 3634/* cFYI(1,("fnxt2 entries in buf %d index_of_last %d",
3635 psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */
3625 3636
3626 /* BB fixme add unlock here */ 3637 /* BB fixme add unlock here */
3627 } 3638 }
@@ -3636,12 +3647,12 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
3636FNext2_err_exit: 3647FNext2_err_exit:
3637 if (rc != 0) 3648 if (rc != 0)
3638 cifs_buf_release(pSMB); 3649 cifs_buf_release(pSMB);
3639
3640 return rc; 3650 return rc;
3641} 3651}
3642 3652
3643int 3653int
3644CIFSFindClose(const int xid, struct cifsTconInfo *tcon, const __u16 searchHandle) 3654CIFSFindClose(const int xid, struct cifsTconInfo *tcon,
3655 const __u16 searchHandle)
3645{ 3656{
3646 int rc = 0; 3657 int rc = 0;
3647 FINDCLOSE_REQ *pSMB = NULL; 3658 FINDCLOSE_REQ *pSMB = NULL;
@@ -3678,9 +3689,9 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon, const __u16 searchHandle
3678 3689
3679int 3690int
3680CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon, 3691CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon,
3681 const unsigned char *searchName, 3692 const unsigned char *searchName,
3682 __u64 * inode_number, 3693 __u64 * inode_number,
3683 const struct nls_table *nls_codepage, int remap) 3694 const struct nls_table *nls_codepage, int remap)
3684{ 3695{
3685 int rc = 0; 3696 int rc = 0;
3686 TRANSACTION2_QPI_REQ *pSMB = NULL; 3697 TRANSACTION2_QPI_REQ *pSMB = NULL;
@@ -3688,24 +3699,23 @@ CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon,
3688 int name_len, bytes_returned; 3699 int name_len, bytes_returned;
3689 __u16 params, byte_count; 3700 __u16 params, byte_count;
3690 3701
3691 cFYI(1,("In GetSrvInodeNum for %s",searchName)); 3702 cFYI(1, ("In GetSrvInodeNum for %s", searchName));
3692 if (tcon == NULL) 3703 if (tcon == NULL)
3693 return -ENODEV; 3704 return -ENODEV;
3694 3705
3695GetInodeNumberRetry: 3706GetInodeNumberRetry:
3696 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB, 3707 rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
3697 (void **) &pSMBr); 3708 (void **) &pSMBr);
3698 if (rc) 3709 if (rc)
3699 return rc; 3710 return rc;
3700 3711
3701
3702 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 3712 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
3703 name_len = 3713 name_len =
3704 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 3714 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
3705 PATH_MAX,nls_codepage, remap); 3715 PATH_MAX, nls_codepage, remap);
3706 name_len++; /* trailing null */ 3716 name_len++; /* trailing null */
3707 name_len *= 2; 3717 name_len *= 2;
3708 } else { /* BB improve the check for buffer overruns BB */ 3718 } else { /* BB improve the check for buffer overruns BB */
3709 name_len = strnlen(searchName, PATH_MAX); 3719 name_len = strnlen(searchName, PATH_MAX);
3710 name_len++; /* trailing null */ 3720 name_len++; /* trailing null */
3711 strncpy(pSMB->FileName, searchName, name_len); 3721 strncpy(pSMB->FileName, searchName, name_len);
@@ -3722,7 +3732,7 @@ GetInodeNumberRetry:
3722 pSMB->Timeout = 0; 3732 pSMB->Timeout = 0;
3723 pSMB->Reserved2 = 0; 3733 pSMB->Reserved2 = 0;
3724 pSMB->ParameterOffset = cpu_to_le16(offsetof( 3734 pSMB->ParameterOffset = cpu_to_le16(offsetof(
3725 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 3735 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
3726 pSMB->DataCount = 0; 3736 pSMB->DataCount = 0;
3727 pSMB->DataOffset = 0; 3737 pSMB->DataOffset = 0;
3728 pSMB->SetupCount = 1; 3738 pSMB->SetupCount = 1;
@@ -3748,10 +3758,10 @@ GetInodeNumberRetry:
3748 /* If rc should we check for EOPNOSUPP and 3758 /* If rc should we check for EOPNOSUPP and
3749 disable the srvino flag? or in caller? */ 3759 disable the srvino flag? or in caller? */
3750 rc = -EIO; /* bad smb */ 3760 rc = -EIO; /* bad smb */
3751 else { 3761 else {
3752 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 3762 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
3753 __u16 count = le16_to_cpu(pSMBr->t2.DataCount); 3763 __u16 count = le16_to_cpu(pSMBr->t2.DataCount);
3754 struct file_internal_info * pfinfo; 3764 struct file_internal_info *pfinfo;
3755 /* BB Do we need a cast or hash here ? */ 3765 /* BB Do we need a cast or hash here ? */
3756 if (count < 8) { 3766 if (count < 8) {
3757 cFYI(1, ("Illegal size ret in QryIntrnlInf")); 3767 cFYI(1, ("Illegal size ret in QryIntrnlInf"));
@@ -3780,12 +3790,12 @@ CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses,
3780/* TRANS2_GET_DFS_REFERRAL */ 3790/* TRANS2_GET_DFS_REFERRAL */
3781 TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL; 3791 TRANSACTION2_GET_DFS_REFER_REQ *pSMB = NULL;
3782 TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL; 3792 TRANSACTION2_GET_DFS_REFER_RSP *pSMBr = NULL;
3783 struct dfs_referral_level_3 * referrals = NULL; 3793 struct dfs_referral_level_3 *referrals = NULL;
3784 int rc = 0; 3794 int rc = 0;
3785 int bytes_returned; 3795 int bytes_returned;
3786 int name_len; 3796 int name_len;
3787 unsigned int i; 3797 unsigned int i;
3788 char * temp; 3798 char *temp;
3789 __u16 params, byte_count; 3799 __u16 params, byte_count;
3790 *number_of_UNC_in_array = 0; 3800 *number_of_UNC_in_array = 0;
3791 *targetUNCs = NULL; 3801 *targetUNCs = NULL;
@@ -3798,8 +3808,8 @@ getDFSRetry:
3798 (void **) &pSMBr); 3808 (void **) &pSMBr);
3799 if (rc) 3809 if (rc)
3800 return rc; 3810 return rc;
3801 3811
3802 /* server pointer checked in called function, 3812 /* server pointer checked in called function,
3803 but should never be null here anyway */ 3813 but should never be null here anyway */
3804 pSMB->hdr.Mid = GetNextMid(ses->server); 3814 pSMB->hdr.Mid = GetNextMid(ses->server);
3805 pSMB->hdr.Tid = ses->ipc_tid; 3815 pSMB->hdr.Tid = ses->ipc_tid;
@@ -3818,7 +3828,7 @@ getDFSRetry:
3818 searchName, PATH_MAX, nls_codepage, remap); 3828 searchName, PATH_MAX, nls_codepage, remap);
3819 name_len++; /* trailing null */ 3829 name_len++; /* trailing null */
3820 name_len *= 2; 3830 name_len *= 2;
3821 } else { /* BB improve the check for buffer overruns BB */ 3831 } else { /* BB improve the check for buffer overruns BB */
3822 name_len = strnlen(searchName, PATH_MAX); 3832 name_len = strnlen(searchName, PATH_MAX);
3823 name_len++; /* trailing null */ 3833 name_len++; /* trailing null */
3824 strncpy(pSMB->RequestFileName, searchName, name_len); 3834 strncpy(pSMB->RequestFileName, searchName, name_len);
@@ -3830,7 +3840,7 @@ getDFSRetry:
3830 pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE; 3840 pSMB->hdr.Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
3831 } 3841 }
3832 3842
3833 pSMB->hdr.Uid = ses->Suid; 3843 pSMB->hdr.Uid = ses->Suid;
3834 3844
3835 params = 2 /* level */ + name_len /*includes null */ ; 3845 params = 2 /* level */ + name_len /*includes null */ ;
3836 pSMB->TotalDataCount = 0; 3846 pSMB->TotalDataCount = 0;
@@ -3844,7 +3854,7 @@ getDFSRetry:
3844 pSMB->Timeout = 0; 3854 pSMB->Timeout = 0;
3845 pSMB->Reserved2 = 0; 3855 pSMB->Reserved2 = 0;
3846 pSMB->ParameterOffset = cpu_to_le16(offsetof( 3856 pSMB->ParameterOffset = cpu_to_le16(offsetof(
3847 struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4); 3857 struct smb_com_transaction2_get_dfs_refer_req, MaxReferralLevel) - 4);
3848 pSMB->SetupCount = 1; 3858 pSMB->SetupCount = 1;
3849 pSMB->Reserved3 = 0; 3859 pSMB->Reserved3 = 0;
3850 pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL); 3860 pSMB->SubCommand = cpu_to_le16(TRANS2_GET_DFS_REFERRAL);
@@ -3863,26 +3873,33 @@ getDFSRetry:
3863/* BB Add logic to parse referrals here */ 3873/* BB Add logic to parse referrals here */
3864 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 3874 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
3865 3875
3866 if (rc || (pSMBr->ByteCount < 17)) /* BB also check enough total bytes returned */ 3876 /* BB Also check if enough total bytes returned? */
3877 if (rc || (pSMBr->ByteCount < 17))
3867 rc = -EIO; /* bad smb */ 3878 rc = -EIO; /* bad smb */
3868 else { 3879 else {
3869 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 3880 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
3870 __u16 data_count = le16_to_cpu(pSMBr->t2.DataCount); 3881 __u16 data_count = le16_to_cpu(pSMBr->t2.DataCount);
3871 3882
3872 cFYI(1, 3883 cFYI(1,
3873 ("Decoding GetDFSRefer response. BCC: %d Offset %d", 3884 ("Decoding GetDFSRefer response BCC: %d Offset %d",
3874 pSMBr->ByteCount, data_offset)); 3885 pSMBr->ByteCount, data_offset));
3875 referrals = 3886 referrals =
3876 (struct dfs_referral_level_3 *) 3887 (struct dfs_referral_level_3 *)
3877 (8 /* sizeof start of data block */ + 3888 (8 /* sizeof start of data block */ +
3878 data_offset + 3889 data_offset +
3879 (char *) &pSMBr->hdr.Protocol); 3890 (char *) &pSMBr->hdr.Protocol);
3880 cFYI(1,("num_referrals: %d dfs flags: 0x%x ... \nfor referral one refer size: 0x%x srv type: 0x%x refer flags: 0x%x ttl: 0x%x", 3891 cFYI(1,("num_referrals: %d dfs flags: 0x%x ... \nfor referral one refer size: 0x%x srv type: 0x%x refer flags: 0x%x ttl: 0x%x",
3881 le16_to_cpu(pSMBr->NumberOfReferrals),le16_to_cpu(pSMBr->DFSFlags), le16_to_cpu(referrals->ReferralSize),le16_to_cpu(referrals->ServerType),le16_to_cpu(referrals->ReferralFlags),le16_to_cpu(referrals->TimeToLive))); 3892 le16_to_cpu(pSMBr->NumberOfReferrals),
3893 le16_to_cpu(pSMBr->DFSFlags),
3894 le16_to_cpu(referrals->ReferralSize),
3895 le16_to_cpu(referrals->ServerType),
3896 le16_to_cpu(referrals->ReferralFlags),
3897 le16_to_cpu(referrals->TimeToLive)));
3882 /* BB This field is actually two bytes in from start of 3898 /* BB This field is actually two bytes in from start of
3883 data block so we could do safety check that DataBlock 3899 data block so we could do safety check that DataBlock
3884 begins at address of pSMBr->NumberOfReferrals */ 3900 begins at address of pSMBr->NumberOfReferrals */
3885 *number_of_UNC_in_array = le16_to_cpu(pSMBr->NumberOfReferrals); 3901 *number_of_UNC_in_array =
3902 le16_to_cpu(pSMBr->NumberOfReferrals);
3886 3903
3887 /* BB Fix below so can return more than one referral */ 3904 /* BB Fix below so can return more than one referral */
3888 if (*number_of_UNC_in_array > 1) 3905 if (*number_of_UNC_in_array > 1)
@@ -3890,47 +3907,51 @@ getDFSRetry:
3890 3907
3891 /* get the length of the strings describing refs */ 3908 /* get the length of the strings describing refs */
3892 name_len = 0; 3909 name_len = 0;
3893 for(i=0;i<*number_of_UNC_in_array;i++) { 3910 for (i = 0; i < *number_of_UNC_in_array; i++) {
3894 /* make sure that DfsPathOffset not past end */ 3911 /* make sure that DfsPathOffset not past end */
3895 __u16 offset = le16_to_cpu(referrals->DfsPathOffset); 3912 __u16 offset =
3913 le16_to_cpu(referrals->DfsPathOffset);
3896 if (offset > data_count) { 3914 if (offset > data_count) {
3897 /* if invalid referral, stop here and do 3915 /* if invalid referral, stop here and do
3898 not try to copy any more */ 3916 not try to copy any more */
3899 *number_of_UNC_in_array = i; 3917 *number_of_UNC_in_array = i;
3900 break; 3918 break;
3901 } 3919 }
3902 temp = ((char *)referrals) + offset; 3920 temp = ((char *)referrals) + offset;
3903 3921
3904 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { 3922 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
3905 name_len += UniStrnlen((wchar_t *)temp,data_count); 3923 name_len += UniStrnlen((wchar_t *)temp,
3924 data_count);
3906 } else { 3925 } else {
3907 name_len += strnlen(temp,data_count); 3926 name_len += strnlen(temp, data_count);
3908 } 3927 }
3909 referrals++; 3928 referrals++;
3910 /* BB add check that referral pointer does not fall off end PDU */ 3929 /* BB add check that referral pointer does
3911 3930 not fall off end PDU */
3912 } 3931 }
3913 /* BB add check for name_len bigger than bcc */ 3932 /* BB add check for name_len bigger than bcc */
3914 *targetUNCs = 3933 *targetUNCs =
3915 kmalloc(name_len+1+ (*number_of_UNC_in_array),GFP_KERNEL); 3934 kmalloc(name_len+1+(*number_of_UNC_in_array),
3935 GFP_KERNEL);
3916 if (*targetUNCs == NULL) { 3936 if (*targetUNCs == NULL) {
3917 rc = -ENOMEM; 3937 rc = -ENOMEM;
3918 goto GetDFSRefExit; 3938 goto GetDFSRefExit;
3919 } 3939 }
3920 /* copy the ref strings */ 3940 /* copy the ref strings */
3921 referrals = 3941 referrals = (struct dfs_referral_level_3 *)
3922 (struct dfs_referral_level_3 *) 3942 (8 /* sizeof data hdr */ + data_offset +
3923 (8 /* sizeof data hdr */ +
3924 data_offset +
3925 (char *) &pSMBr->hdr.Protocol); 3943 (char *) &pSMBr->hdr.Protocol);
3926 3944
3927 for(i=0;i<*number_of_UNC_in_array;i++) { 3945 for (i = 0; i < *number_of_UNC_in_array; i++) {
3928 temp = ((char *)referrals) + le16_to_cpu(referrals->DfsPathOffset); 3946 temp = ((char *)referrals) +
3947 le16_to_cpu(referrals->DfsPathOffset);
3929 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) { 3948 if (pSMBr->hdr.Flags2 & SMBFLG2_UNICODE) {
3930 cifs_strfromUCS_le(*targetUNCs, 3949 cifs_strfromUCS_le(*targetUNCs,
3931 (__le16 *) temp, name_len, nls_codepage); 3950 (__le16 *) temp,
3951 name_len,
3952 nls_codepage);
3932 } else { 3953 } else {
3933 strncpy(*targetUNCs,temp,name_len); 3954 strncpy(*targetUNCs, temp, name_len);
3934 } 3955 }
3935 /* BB update target_uncs pointers */ 3956 /* BB update target_uncs pointers */
3936 referrals++; 3957 referrals++;
@@ -4007,18 +4028,17 @@ oldQFSInfoRetry:
4007 rc = -EIO; /* bad smb */ 4028 rc = -EIO; /* bad smb */
4008 else { 4029 else {
4009 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4030 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
4010 cFYI(1,("qfsinf resp BCC: %d Offset %d", 4031 cFYI(1, ("qfsinf resp BCC: %d Offset %d",
4011 pSMBr->ByteCount, data_offset)); 4032 pSMBr->ByteCount, data_offset));
4012 4033
4013 response_data = 4034 response_data = (FILE_SYSTEM_ALLOC_INFO *)
4014 (FILE_SYSTEM_ALLOC_INFO *)
4015 (((char *) &pSMBr->hdr.Protocol) + data_offset); 4035 (((char *) &pSMBr->hdr.Protocol) + data_offset);
4016 FSData->f_bsize = 4036 FSData->f_bsize =
4017 le16_to_cpu(response_data->BytesPerSector) * 4037 le16_to_cpu(response_data->BytesPerSector) *
4018 le32_to_cpu(response_data-> 4038 le32_to_cpu(response_data->
4019 SectorsPerAllocationUnit); 4039 SectorsPerAllocationUnit);
4020 FSData->f_blocks = 4040 FSData->f_blocks =
4021 le32_to_cpu(response_data->TotalAllocationUnits); 4041 le32_to_cpu(response_data->TotalAllocationUnits);
4022 FSData->f_bfree = FSData->f_bavail = 4042 FSData->f_bfree = FSData->f_bavail =
4023 le32_to_cpu(response_data->FreeAllocationUnits); 4043 le32_to_cpu(response_data->FreeAllocationUnits);
4024 cFYI(1, 4044 cFYI(1,
@@ -4067,7 +4087,7 @@ QFSInfoRetry:
4067 pSMB->TotalParameterCount = cpu_to_le16(params); 4087 pSMB->TotalParameterCount = cpu_to_le16(params);
4068 pSMB->ParameterCount = pSMB->TotalParameterCount; 4088 pSMB->ParameterCount = pSMB->TotalParameterCount;
4069 pSMB->ParameterOffset = cpu_to_le16(offsetof( 4089 pSMB->ParameterOffset = cpu_to_le16(offsetof(
4070 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); 4090 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4);
4071 pSMB->DataCount = 0; 4091 pSMB->DataCount = 0;
4072 pSMB->DataOffset = 0; 4092 pSMB->DataOffset = 0;
4073 pSMB->SetupCount = 1; 4093 pSMB->SetupCount = 1;
@@ -4082,7 +4102,7 @@ QFSInfoRetry:
4082 if (rc) { 4102 if (rc) {
4083 cFYI(1, ("Send error in QFSInfo = %d", rc)); 4103 cFYI(1, ("Send error in QFSInfo = %d", rc));
4084 } else { /* decode response */ 4104 } else { /* decode response */
4085 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4105 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4086 4106
4087 if (rc || (pSMBr->ByteCount < 24)) 4107 if (rc || (pSMBr->ByteCount < 24))
4088 rc = -EIO; /* bad smb */ 4108 rc = -EIO; /* bad smb */
@@ -4147,7 +4167,7 @@ QFSAttributeRetry:
4147 pSMB->TotalParameterCount = cpu_to_le16(params); 4167 pSMB->TotalParameterCount = cpu_to_le16(params);
4148 pSMB->ParameterCount = pSMB->TotalParameterCount; 4168 pSMB->ParameterCount = pSMB->TotalParameterCount;
4149 pSMB->ParameterOffset = cpu_to_le16(offsetof( 4169 pSMB->ParameterOffset = cpu_to_le16(offsetof(
4150 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); 4170 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4);
4151 pSMB->DataCount = 0; 4171 pSMB->DataCount = 0;
4152 pSMB->DataOffset = 0; 4172 pSMB->DataOffset = 0;
4153 pSMB->SetupCount = 1; 4173 pSMB->SetupCount = 1;
@@ -4164,7 +4184,8 @@ QFSAttributeRetry:
4164 } else { /* decode response */ 4184 } else { /* decode response */
4165 rc = validate_t2((struct smb_t2_rsp *)pSMBr); 4185 rc = validate_t2((struct smb_t2_rsp *)pSMBr);
4166 4186
4167 if (rc || (pSMBr->ByteCount < 13)) { /* BB also check enough bytes returned */ 4187 if (rc || (pSMBr->ByteCount < 13)) {
4188 /* BB also check if enough bytes returned */
4168 rc = -EIO; /* bad smb */ 4189 rc = -EIO; /* bad smb */
4169 } else { 4190 } else {
4170 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 4191 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -4215,7 +4236,7 @@ QFSDeviceRetry:
4215 pSMB->TotalParameterCount = cpu_to_le16(params); 4236 pSMB->TotalParameterCount = cpu_to_le16(params);
4216 pSMB->ParameterCount = pSMB->TotalParameterCount; 4237 pSMB->ParameterCount = pSMB->TotalParameterCount;
4217 pSMB->ParameterOffset = cpu_to_le16(offsetof( 4238 pSMB->ParameterOffset = cpu_to_le16(offsetof(
4218 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4); 4239 struct smb_com_transaction2_qfsi_req, InformationLevel) - 4);
4219 4240
4220 pSMB->DataCount = 0; 4241 pSMB->DataCount = 0;
4221 pSMB->DataOffset = 0; 4242 pSMB->DataOffset = 0;
@@ -4285,8 +4306,8 @@ QFSUnixRetry:
4285 byte_count = params + 1 /* pad */ ; 4306 byte_count = params + 1 /* pad */ ;
4286 pSMB->ParameterCount = cpu_to_le16(params); 4307 pSMB->ParameterCount = cpu_to_le16(params);
4287 pSMB->TotalParameterCount = pSMB->ParameterCount; 4308 pSMB->TotalParameterCount = pSMB->ParameterCount;
4288 pSMB->ParameterOffset = cpu_to_le16(offsetof(struct 4309 pSMB->ParameterOffset = cpu_to_le16(offsetof(struct
4289 smb_com_transaction2_qfsi_req, InformationLevel) - 4); 4310 smb_com_transaction2_qfsi_req, InformationLevel) - 4);
4290 pSMB->SetupCount = 1; 4311 pSMB->SetupCount = 1;
4291 pSMB->Reserved3 = 0; 4312 pSMB->Reserved3 = 0;
4292 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); 4313 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
@@ -4346,7 +4367,8 @@ SETFSUnixRetry:
4346 pSMB->Flags = 0; 4367 pSMB->Flags = 0;
4347 pSMB->Timeout = 0; 4368 pSMB->Timeout = 0;
4348 pSMB->Reserved2 = 0; 4369 pSMB->Reserved2 = 0;
4349 param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum) - 4; 4370 param_offset = offsetof(struct smb_com_transaction2_setfsi_req, FileNum)
4371 - 4;
4350 offset = param_offset + params; 4372 offset = param_offset + params;
4351 4373
4352 pSMB->MaxParameterCount = cpu_to_le16(4); 4374 pSMB->MaxParameterCount = cpu_to_le16(4);
@@ -4428,8 +4450,8 @@ QFSPosixRetry:
4428 byte_count = params + 1 /* pad */ ; 4450 byte_count = params + 1 /* pad */ ;
4429 pSMB->ParameterCount = cpu_to_le16(params); 4451 pSMB->ParameterCount = cpu_to_le16(params);
4430 pSMB->TotalParameterCount = pSMB->ParameterCount; 4452 pSMB->TotalParameterCount = pSMB->ParameterCount;
4431 pSMB->ParameterOffset = cpu_to_le16(offsetof(struct 4453 pSMB->ParameterOffset = cpu_to_le16(offsetof(struct
4432 smb_com_transaction2_qfsi_req, InformationLevel) - 4); 4454 smb_com_transaction2_qfsi_req, InformationLevel) - 4);
4433 pSMB->SetupCount = 1; 4455 pSMB->SetupCount = 1;
4434 pSMB->Reserved3 = 0; 4456 pSMB->Reserved3 = 0;
4435 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION); 4457 pSMB->SubCommand = cpu_to_le16(TRANS2_QUERY_FS_INFORMATION);
@@ -4462,14 +4484,14 @@ QFSPosixRetry:
4462 FSData->f_bavail = FSData->f_bfree; 4484 FSData->f_bavail = FSData->f_bfree;
4463 } else { 4485 } else {
4464 FSData->f_bavail = 4486 FSData->f_bavail =
4465 le64_to_cpu(response_data->UserBlocksAvail); 4487 le64_to_cpu(response_data->UserBlocksAvail);
4466 } 4488 }
4467 if (response_data->TotalFileNodes != cpu_to_le64(-1)) 4489 if (response_data->TotalFileNodes != cpu_to_le64(-1))
4468 FSData->f_files = 4490 FSData->f_files =
4469 le64_to_cpu(response_data->TotalFileNodes); 4491 le64_to_cpu(response_data->TotalFileNodes);
4470 if (response_data->FreeFileNodes != cpu_to_le64(-1)) 4492 if (response_data->FreeFileNodes != cpu_to_le64(-1))
4471 FSData->f_ffree = 4493 FSData->f_ffree =
4472 le64_to_cpu(response_data->FreeFileNodes); 4494 le64_to_cpu(response_data->FreeFileNodes);
4473 } 4495 }
4474 } 4496 }
4475 cifs_buf_release(pSMB); 4497 cifs_buf_release(pSMB);
@@ -4481,15 +4503,15 @@ QFSPosixRetry:
4481} 4503}
4482 4504
4483 4505
4484/* We can not use write of zero bytes trick to 4506/* We can not use write of zero bytes trick to
4485 set file size due to need for large file support. Also note that 4507 set file size due to need for large file support. Also note that
4486 this SetPathInfo is preferred to SetFileInfo based method in next 4508 this SetPathInfo is preferred to SetFileInfo based method in next
4487 routine which is only needed to work around a sharing violation bug 4509 routine which is only needed to work around a sharing violation bug
4488 in Samba which this routine can run into */ 4510 in Samba which this routine can run into */
4489 4511
4490int 4512int
4491CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName, 4513CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName,
4492 __u64 size, int SetAllocation, 4514 __u64 size, int SetAllocation,
4493 const struct nls_table *nls_codepage, int remap) 4515 const struct nls_table *nls_codepage, int remap)
4494{ 4516{
4495 struct smb_com_transaction2_spi_req *pSMB = NULL; 4517 struct smb_com_transaction2_spi_req *pSMB = NULL;
@@ -4528,22 +4550,22 @@ SetEOFRetry:
4528 pSMB->Timeout = 0; 4550 pSMB->Timeout = 0;
4529 pSMB->Reserved2 = 0; 4551 pSMB->Reserved2 = 0;
4530 param_offset = offsetof(struct smb_com_transaction2_spi_req, 4552 param_offset = offsetof(struct smb_com_transaction2_spi_req,
4531 InformationLevel) - 4; 4553 InformationLevel) - 4;
4532 offset = param_offset + params; 4554 offset = param_offset + params;
4533 if (SetAllocation) { 4555 if (SetAllocation) {
4534 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) 4556 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
4535 pSMB->InformationLevel = 4557 pSMB->InformationLevel =
4536 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2); 4558 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO2);
4537 else 4559 else
4538 pSMB->InformationLevel = 4560 pSMB->InformationLevel =
4539 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); 4561 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO);
4540 } else /* Set File Size */ { 4562 } else /* Set File Size */ {
4541 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) 4563 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
4542 pSMB->InformationLevel = 4564 pSMB->InformationLevel =
4543 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); 4565 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2);
4544 else 4566 else
4545 pSMB->InformationLevel = 4567 pSMB->InformationLevel =
4546 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); 4568 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO);
4547 } 4569 }
4548 4570
4549 parm_data = 4571 parm_data =
@@ -4578,8 +4600,8 @@ SetEOFRetry:
4578} 4600}
4579 4601
4580int 4602int
4581CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size, 4603CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4582 __u16 fid, __u32 pid_of_opener, int SetAllocation) 4604 __u16 fid, __u32 pid_of_opener, int SetAllocation)
4583{ 4605{
4584 struct smb_com_transaction2_sfi_req *pSMB = NULL; 4606 struct smb_com_transaction2_sfi_req *pSMB = NULL;
4585 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; 4607 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;
@@ -4600,7 +4622,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4600 4622
4601 pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); 4623 pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener);
4602 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16)); 4624 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));
4603 4625
4604 params = 6; 4626 params = 6;
4605 pSMB->MaxSetupCount = 0; 4627 pSMB->MaxSetupCount = 0;
4606 pSMB->Reserved = 0; 4628 pSMB->Reserved = 0;
@@ -4610,7 +4632,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4610 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 4632 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
4611 offset = param_offset + params; 4633 offset = param_offset + params;
4612 4634
4613 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 4635 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
4614 4636
4615 count = sizeof(struct file_end_of_file_info); 4637 count = sizeof(struct file_end_of_file_info);
4616 pSMB->MaxParameterCount = cpu_to_le16(2); 4638 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -4625,8 +4647,8 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4625 pSMB->TotalParameterCount = pSMB->ParameterCount; 4647 pSMB->TotalParameterCount = pSMB->ParameterCount;
4626 pSMB->ParameterOffset = cpu_to_le16(param_offset); 4648 pSMB->ParameterOffset = cpu_to_le16(param_offset);
4627 parm_data = 4649 parm_data =
4628 (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol) + 4650 (struct file_end_of_file_info *) (((char *) &pSMB->hdr.Protocol)
4629 offset); 4651 + offset);
4630 pSMB->DataOffset = cpu_to_le16(offset); 4652 pSMB->DataOffset = cpu_to_le16(offset);
4631 parm_data->FileSize = cpu_to_le64(size); 4653 parm_data->FileSize = cpu_to_le64(size);
4632 pSMB->Fid = fid; 4654 pSMB->Fid = fid;
@@ -4637,13 +4659,13 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4637 else 4659 else
4638 pSMB->InformationLevel = 4660 pSMB->InformationLevel =
4639 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO); 4661 cpu_to_le16(SMB_SET_FILE_ALLOCATION_INFO);
4640 } else /* Set File Size */ { 4662 } else /* Set File Size */ {
4641 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU) 4663 if (tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)
4642 pSMB->InformationLevel = 4664 pSMB->InformationLevel =
4643 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2); 4665 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO2);
4644 else 4666 else
4645 pSMB->InformationLevel = 4667 pSMB->InformationLevel =
4646 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO); 4668 cpu_to_le16(SMB_SET_FILE_END_OF_FILE_INFO);
4647 } 4669 }
4648 pSMB->Reserved4 = 0; 4670 pSMB->Reserved4 = 0;
4649 pSMB->hdr.smb_buf_length += byte_count; 4671 pSMB->hdr.smb_buf_length += byte_count;
@@ -4659,21 +4681,21 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
4659 if (pSMB) 4681 if (pSMB)
4660 cifs_small_buf_release(pSMB); 4682 cifs_small_buf_release(pSMB);
4661 4683
4662 /* Note: On -EAGAIN error only caller can retry on handle based calls 4684 /* Note: On -EAGAIN error only caller can retry on handle based calls
4663 since file handle passed in no longer valid */ 4685 since file handle passed in no longer valid */
4664 4686
4665 return rc; 4687 return rc;
4666} 4688}
4667 4689
4668/* Some legacy servers such as NT4 require that the file times be set on 4690/* Some legacy servers such as NT4 require that the file times be set on
4669 an open handle, rather than by pathname - this is awkward due to 4691 an open handle, rather than by pathname - this is awkward due to
4670 potential access conflicts on the open, but it is unavoidable for these 4692 potential access conflicts on the open, but it is unavoidable for these
4671 old servers since the only other choice is to go from 100 nanosecond DCE 4693 old servers since the only other choice is to go from 100 nanosecond DCE
4672 time and resort to the original setpathinfo level which takes the ancient 4694 time and resort to the original setpathinfo level which takes the ancient
4673 DOS time format with 2 second granularity */ 4695 DOS time format with 2 second granularity */
4674int 4696int
4675CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_INFO * data, 4697CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon,
4676 __u16 fid) 4698 const FILE_BASIC_INFO *data, __u16 fid)
4677{ 4699{
4678 struct smb_com_transaction2_sfi_req *pSMB = NULL; 4700 struct smb_com_transaction2_sfi_req *pSMB = NULL;
4679 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL; 4701 struct smb_com_transaction2_sfi_rsp *pSMBr = NULL;
@@ -4695,7 +4717,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I
4695 use an existing handle (rather than opening one on the fly) */ 4717 use an existing handle (rather than opening one on the fly) */
4696 /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener); 4718 /* pSMB->hdr.Pid = cpu_to_le16((__u16)pid_of_opener);
4697 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/ 4719 pSMB->hdr.PidHigh = cpu_to_le16((__u16)(pid_of_opener >> 16));*/
4698 4720
4699 params = 6; 4721 params = 6;
4700 pSMB->MaxSetupCount = 0; 4722 pSMB->MaxSetupCount = 0;
4701 pSMB->Reserved = 0; 4723 pSMB->Reserved = 0;
@@ -4705,7 +4727,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I
4705 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4; 4727 param_offset = offsetof(struct smb_com_transaction2_sfi_req, Fid) - 4;
4706 offset = param_offset + params; 4728 offset = param_offset + params;
4707 4729
4708 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 4730 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
4709 4731
4710 count = sizeof (FILE_BASIC_INFO); 4732 count = sizeof (FILE_BASIC_INFO);
4711 pSMB->MaxParameterCount = cpu_to_le16(2); 4733 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -4728,16 +4750,16 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I
4728 pSMB->Reserved4 = 0; 4750 pSMB->Reserved4 = 0;
4729 pSMB->hdr.smb_buf_length += byte_count; 4751 pSMB->hdr.smb_buf_length += byte_count;
4730 pSMB->ByteCount = cpu_to_le16(byte_count); 4752 pSMB->ByteCount = cpu_to_le16(byte_count);
4731 memcpy(data_offset,data,sizeof(FILE_BASIC_INFO)); 4753 memcpy(data_offset, data, sizeof(FILE_BASIC_INFO));
4732 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB, 4754 rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
4733 (struct smb_hdr *) pSMBr, &bytes_returned, 0); 4755 (struct smb_hdr *) pSMBr, &bytes_returned, 0);
4734 if (rc) { 4756 if (rc) {
4735 cFYI(1,("Send error in Set Time (SetFileInfo) = %d",rc)); 4757 cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc));
4736 } 4758 }
4737 4759
4738 cifs_small_buf_release(pSMB); 4760 cifs_small_buf_release(pSMB);
4739 4761
4740 /* Note: On -EAGAIN error only caller can retry on handle based calls 4762 /* Note: On -EAGAIN error only caller can retry on handle based calls
4741 since file handle passed in no longer valid */ 4763 since file handle passed in no longer valid */
4742 4764
4743 return rc; 4765 return rc;
@@ -4746,7 +4768,7 @@ CIFSSMBSetFileTimes(const int xid, struct cifsTconInfo *tcon, const FILE_BASIC_I
4746 4768
4747int 4769int
4748CIFSSMBSetTimes(const int xid, struct cifsTconInfo *tcon, const char *fileName, 4770CIFSSMBSetTimes(const int xid, struct cifsTconInfo *tcon, const char *fileName,
4749 const FILE_BASIC_INFO * data, 4771 const FILE_BASIC_INFO *data,
4750 const struct nls_table *nls_codepage, int remap) 4772 const struct nls_table *nls_codepage, int remap)
4751{ 4773{
4752 TRANSACTION2_SPI_REQ *pSMB = NULL; 4774 TRANSACTION2_SPI_REQ *pSMB = NULL;
@@ -4771,7 +4793,7 @@ SetTimesRetry:
4771 PATH_MAX, nls_codepage, remap); 4793 PATH_MAX, nls_codepage, remap);
4772 name_len++; /* trailing null */ 4794 name_len++; /* trailing null */
4773 name_len *= 2; 4795 name_len *= 2;
4774 } else { /* BB improve the check for buffer overruns BB */ 4796 } else { /* BB improve the check for buffer overruns BB */
4775 name_len = strnlen(fileName, PATH_MAX); 4797 name_len = strnlen(fileName, PATH_MAX);
4776 name_len++; /* trailing null */ 4798 name_len++; /* trailing null */
4777 strncpy(pSMB->FileName, fileName, name_len); 4799 strncpy(pSMB->FileName, fileName, name_len);
@@ -4787,7 +4809,7 @@ SetTimesRetry:
4787 pSMB->Timeout = 0; 4809 pSMB->Timeout = 0;
4788 pSMB->Reserved2 = 0; 4810 pSMB->Reserved2 = 0;
4789 param_offset = offsetof(struct smb_com_transaction2_spi_req, 4811 param_offset = offsetof(struct smb_com_transaction2_spi_req,
4790 InformationLevel) - 4; 4812 InformationLevel) - 4;
4791 offset = param_offset + params; 4813 offset = param_offset + params;
4792 data_offset = (char *) (&pSMB->hdr.Protocol) + offset; 4814 data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
4793 pSMB->ParameterOffset = cpu_to_le16(param_offset); 4815 pSMB->ParameterOffset = cpu_to_le16(param_offset);
@@ -4848,11 +4870,11 @@ SetAttrLgcyRetry:
4848 4870
4849 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 4871 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
4850 name_len = 4872 name_len =
4851 ConvertToUCS((__le16 *) pSMB->fileName, fileName, 4873 ConvertToUCS((__le16 *) pSMB->fileName, fileName,
4852 PATH_MAX, nls_codepage); 4874 PATH_MAX, nls_codepage);
4853 name_len++; /* trailing null */ 4875 name_len++; /* trailing null */
4854 name_len *= 2; 4876 name_len *= 2;
4855 } else { /* BB improve the check for buffer overruns BB */ 4877 } else { /* BB improve the check for buffer overruns BB */
4856 name_len = strnlen(fileName, PATH_MAX); 4878 name_len = strnlen(fileName, PATH_MAX);
4857 name_len++; /* trailing null */ 4879 name_len++; /* trailing null */
4858 strncpy(pSMB->fileName, fileName, name_len); 4880 strncpy(pSMB->fileName, fileName, name_len);
@@ -4878,8 +4900,8 @@ SetAttrLgcyRetry:
4878 4900
4879int 4901int
4880CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *tcon, 4902CIFSSMBUnixSetPerms(const int xid, struct cifsTconInfo *tcon,
4881 char *fileName, __u64 mode, __u64 uid, __u64 gid, 4903 char *fileName, __u64 mode, __u64 uid, __u64 gid,
4882 dev_t device, const struct nls_table *nls_codepage, 4904 dev_t device, const struct nls_table *nls_codepage,
4883 int remap) 4905 int remap)
4884{ 4906{
4885 TRANSACTION2_SPI_REQ *pSMB = NULL; 4907 TRANSACTION2_SPI_REQ *pSMB = NULL;
@@ -4899,7 +4921,7 @@ setPermsRetry:
4899 4921
4900 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 4922 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
4901 name_len = 4923 name_len =
4902 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, 4924 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
4903 PATH_MAX, nls_codepage, remap); 4925 PATH_MAX, nls_codepage, remap);
4904 name_len++; /* trailing null */ 4926 name_len++; /* trailing null */
4905 name_len *= 2; 4927 name_len *= 2;
@@ -4919,7 +4941,7 @@ setPermsRetry:
4919 pSMB->Timeout = 0; 4941 pSMB->Timeout = 0;
4920 pSMB->Reserved2 = 0; 4942 pSMB->Reserved2 = 0;
4921 param_offset = offsetof(struct smb_com_transaction2_spi_req, 4943 param_offset = offsetof(struct smb_com_transaction2_spi_req,
4922 InformationLevel) - 4; 4944 InformationLevel) - 4;
4923 offset = param_offset + params; 4945 offset = param_offset + params;
4924 data_offset = 4946 data_offset =
4925 (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol + 4947 (FILE_UNIX_BASIC_INFO *) ((char *) &pSMB->hdr.Protocol +
@@ -4942,7 +4964,7 @@ setPermsRetry:
4942 older clients, but we should be precise - we use SetFileSize to 4964 older clients, but we should be precise - we use SetFileSize to
4943 set file size and do not want to truncate file size to zero 4965 set file size and do not want to truncate file size to zero
4944 accidently as happened on one Samba server beta by putting 4966 accidently as happened on one Samba server beta by putting
4945 zero instead of -1 here */ 4967 zero instead of -1 here */
4946 data_offset->EndOfFile = NO_CHANGE_64; 4968 data_offset->EndOfFile = NO_CHANGE_64;
4947 data_offset->NumOfBytes = NO_CHANGE_64; 4969 data_offset->NumOfBytes = NO_CHANGE_64;
4948 data_offset->LastStatusChange = NO_CHANGE_64; 4970 data_offset->LastStatusChange = NO_CHANGE_64;
@@ -4954,7 +4976,7 @@ setPermsRetry:
4954 data_offset->DevMajor = cpu_to_le64(MAJOR(device)); 4976 data_offset->DevMajor = cpu_to_le64(MAJOR(device));
4955 data_offset->DevMinor = cpu_to_le64(MINOR(device)); 4977 data_offset->DevMinor = cpu_to_le64(MINOR(device));
4956 data_offset->Permissions = cpu_to_le64(mode); 4978 data_offset->Permissions = cpu_to_le64(mode);
4957 4979
4958 if (S_ISREG(mode)) 4980 if (S_ISREG(mode))
4959 data_offset->Type = cpu_to_le32(UNIX_FILE); 4981 data_offset->Type = cpu_to_le32(UNIX_FILE);
4960 else if (S_ISDIR(mode)) 4982 else if (S_ISDIR(mode))
@@ -4985,20 +5007,20 @@ setPermsRetry:
4985 return rc; 5007 return rc;
4986} 5008}
4987 5009
4988int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon, 5010int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
4989 const int notify_subdirs, const __u16 netfid, 5011 const int notify_subdirs, const __u16 netfid,
4990 __u32 filter, struct file * pfile, int multishot, 5012 __u32 filter, struct file *pfile, int multishot,
4991 const struct nls_table *nls_codepage) 5013 const struct nls_table *nls_codepage)
4992{ 5014{
4993 int rc = 0; 5015 int rc = 0;
4994 struct smb_com_transaction_change_notify_req * pSMB = NULL; 5016 struct smb_com_transaction_change_notify_req *pSMB = NULL;
4995 struct smb_com_ntransaction_change_notify_rsp * pSMBr = NULL; 5017 struct smb_com_ntransaction_change_notify_rsp *pSMBr = NULL;
4996 struct dir_notify_req *dnotify_req; 5018 struct dir_notify_req *dnotify_req;
4997 int bytes_returned; 5019 int bytes_returned;
4998 5020
4999 cFYI(1, ("In CIFSSMBNotify for file handle %d",(int)netfid)); 5021 cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid));
5000 rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB, 5022 rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
5001 (void **) &pSMBr); 5023 (void **) &pSMBr);
5002 if (rc) 5024 if (rc)
5003 return rc; 5025 return rc;
5004 5026
@@ -5032,7 +5054,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
5032 cFYI(1, ("Error in Notify = %d", rc)); 5054 cFYI(1, ("Error in Notify = %d", rc));
5033 } else { 5055 } else {
5034 /* Add file to outstanding requests */ 5056 /* Add file to outstanding requests */
5035 /* BB change to kmem cache alloc */ 5057 /* BB change to kmem cache alloc */
5036 dnotify_req = kmalloc( 5058 dnotify_req = kmalloc(
5037 sizeof(struct dir_notify_req), 5059 sizeof(struct dir_notify_req),
5038 GFP_KERNEL); 5060 GFP_KERNEL);
@@ -5047,20 +5069,20 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
5047 dnotify_req->filter = filter; 5069 dnotify_req->filter = filter;
5048 dnotify_req->multishot = multishot; 5070 dnotify_req->multishot = multishot;
5049 spin_lock(&GlobalMid_Lock); 5071 spin_lock(&GlobalMid_Lock);
5050 list_add_tail(&dnotify_req->lhead, 5072 list_add_tail(&dnotify_req->lhead,
5051 &GlobalDnotifyReqList); 5073 &GlobalDnotifyReqList);
5052 spin_unlock(&GlobalMid_Lock); 5074 spin_unlock(&GlobalMid_Lock);
5053 } else 5075 } else
5054 rc = -ENOMEM; 5076 rc = -ENOMEM;
5055 } 5077 }
5056 cifs_buf_release(pSMB); 5078 cifs_buf_release(pSMB);
5057 return rc; 5079 return rc;
5058} 5080}
5059#ifdef CONFIG_CIFS_XATTR 5081#ifdef CONFIG_CIFS_XATTR
5060ssize_t 5082ssize_t
5061CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon, 5083CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
5062 const unsigned char *searchName, 5084 const unsigned char *searchName,
5063 char * EAData, size_t buf_size, 5085 char *EAData, size_t buf_size,
5064 const struct nls_table *nls_codepage, int remap) 5086 const struct nls_table *nls_codepage, int remap)
5065{ 5087{
5066 /* BB assumes one setup word */ 5088 /* BB assumes one setup word */
@@ -5069,8 +5091,8 @@ CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
5069 int rc = 0; 5091 int rc = 0;
5070 int bytes_returned; 5092 int bytes_returned;
5071 int name_len; 5093 int name_len;
5072 struct fea * temp_fea; 5094 struct fea *temp_fea;
5073 char * temp_ptr; 5095 char *temp_ptr;
5074 __u16 params, byte_count; 5096 __u16 params, byte_count;
5075 5097
5076 cFYI(1, ("In Query All EAs path %s", searchName)); 5098 cFYI(1, ("In Query All EAs path %s", searchName));
@@ -5082,7 +5104,7 @@ QAllEAsRetry:
5082 5104
5083 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5105 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5084 name_len = 5106 name_len =
5085 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 5107 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
5086 PATH_MAX, nls_codepage, remap); 5108 PATH_MAX, nls_codepage, remap);
5087 name_len++; /* trailing null */ 5109 name_len++; /* trailing null */
5088 name_len *= 2; 5110 name_len *= 2;
@@ -5092,7 +5114,7 @@ QAllEAsRetry:
5092 strncpy(pSMB->FileName, searchName, name_len); 5114 strncpy(pSMB->FileName, searchName, name_len);
5093 } 5115 }
5094 5116
5095 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; 5117 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
5096 pSMB->TotalDataCount = 0; 5118 pSMB->TotalDataCount = 0;
5097 pSMB->MaxParameterCount = cpu_to_le16(2); 5119 pSMB->MaxParameterCount = cpu_to_le16(2);
5098 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ 5120 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
@@ -5102,7 +5124,7 @@ QAllEAsRetry:
5102 pSMB->Timeout = 0; 5124 pSMB->Timeout = 0;
5103 pSMB->Reserved2 = 0; 5125 pSMB->Reserved2 = 0;
5104 pSMB->ParameterOffset = cpu_to_le16(offsetof( 5126 pSMB->ParameterOffset = cpu_to_le16(offsetof(
5105 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 5127 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
5106 pSMB->DataCount = 0; 5128 pSMB->DataCount = 0;
5107 pSMB->DataOffset = 0; 5129 pSMB->DataOffset = 0;
5108 pSMB->SetupCount = 1; 5130 pSMB->SetupCount = 1;
@@ -5126,7 +5148,7 @@ QAllEAsRetry:
5126 /* BB also check enough total bytes returned */ 5148 /* BB also check enough total bytes returned */
5127 /* BB we need to improve the validity checking 5149 /* BB we need to improve the validity checking
5128 of these trans2 responses */ 5150 of these trans2 responses */
5129 if (rc || (pSMBr->ByteCount < 4)) 5151 if (rc || (pSMBr->ByteCount < 4))
5130 rc = -EIO; /* bad smb */ 5152 rc = -EIO; /* bad smb */
5131 /* else if (pFindData){ 5153 /* else if (pFindData){
5132 memcpy((char *) pFindData, 5154 memcpy((char *) pFindData,
@@ -5139,7 +5161,7 @@ QAllEAsRetry:
5139 /* check that each element of each entry does not 5161 /* check that each element of each entry does not
5140 go beyond end of list */ 5162 go beyond end of list */
5141 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 5163 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
5142 struct fealist * ea_response_data; 5164 struct fealist *ea_response_data;
5143 rc = 0; 5165 rc = 0;
5144 /* validate_trans2_offsets() */ 5166 /* validate_trans2_offsets() */
5145 /* BB check if start of smb + data_offset > &bcc+ bcc */ 5167 /* BB check if start of smb + data_offset > &bcc+ bcc */
@@ -5147,16 +5169,16 @@ QAllEAsRetry:
5147 (((char *) &pSMBr->hdr.Protocol) + 5169 (((char *) &pSMBr->hdr.Protocol) +
5148 data_offset); 5170 data_offset);
5149 name_len = le32_to_cpu(ea_response_data->list_len); 5171 name_len = le32_to_cpu(ea_response_data->list_len);
5150 cFYI(1,("ea length %d", name_len)); 5172 cFYI(1, ("ea length %d", name_len));
5151 if (name_len <= 8) { 5173 if (name_len <= 8) {
5152 /* returned EA size zeroed at top of function */ 5174 /* returned EA size zeroed at top of function */
5153 cFYI(1,("empty EA list returned from server")); 5175 cFYI(1, ("empty EA list returned from server"));
5154 } else { 5176 } else {
5155 /* account for ea list len */ 5177 /* account for ea list len */
5156 name_len -= 4; 5178 name_len -= 4;
5157 temp_fea = ea_response_data->list; 5179 temp_fea = ea_response_data->list;
5158 temp_ptr = (char *)temp_fea; 5180 temp_ptr = (char *)temp_fea;
5159 while(name_len > 0) { 5181 while (name_len > 0) {
5160 __u16 value_len; 5182 __u16 value_len;
5161 name_len -= 4; 5183 name_len -= 4;
5162 temp_ptr += 4; 5184 temp_ptr += 4;
@@ -5164,10 +5186,11 @@ QAllEAsRetry:
5164 /* account for prefix user. and trailing null */ 5186 /* account for prefix user. and trailing null */
5165 rc = rc + 5 + 1; 5187 rc = rc + 5 + 1;
5166 if (rc < (int)buf_size) { 5188 if (rc < (int)buf_size) {
5167 memcpy(EAData,"user.",5); 5189 memcpy(EAData, "user.", 5);
5168 EAData+=5; 5190 EAData += 5;
5169 memcpy(EAData,temp_ptr,temp_fea->name_len); 5191 memcpy(EAData, temp_ptr,
5170 EAData+=temp_fea->name_len; 5192 temp_fea->name_len);
5193 EAData += temp_fea->name_len;
5171 /* null terminate name */ 5194 /* null terminate name */
5172 *EAData = 0; 5195 *EAData = 0;
5173 EAData = EAData + 1; 5196 EAData = EAData + 1;
@@ -5183,11 +5206,15 @@ QAllEAsRetry:
5183 /* account for trailing null */ 5206 /* account for trailing null */
5184 name_len--; 5207 name_len--;
5185 temp_ptr++; 5208 temp_ptr++;
5186 value_len = le16_to_cpu(temp_fea->value_len); 5209 value_len =
5210 le16_to_cpu(temp_fea->value_len);
5187 name_len -= value_len; 5211 name_len -= value_len;
5188 temp_ptr += value_len; 5212 temp_ptr += value_len;
5189 /* BB check that temp_ptr is still within smb BB*/ 5213 /* BB check that temp_ptr is still
5190 /* no trailing null to account for in value len */ 5214 within the SMB BB*/
5215
5216 /* no trailing null to account for
5217 in value len */
5191 /* go on to next EA */ 5218 /* go on to next EA */
5192 temp_fea = (struct fea *)temp_ptr; 5219 temp_fea = (struct fea *)temp_ptr;
5193 } 5220 }
@@ -5202,9 +5229,9 @@ QAllEAsRetry:
5202 return (ssize_t)rc; 5229 return (ssize_t)rc;
5203} 5230}
5204 5231
5205ssize_t CIFSSMBQueryEA(const int xid,struct cifsTconInfo * tcon, 5232ssize_t CIFSSMBQueryEA(const int xid, struct cifsTconInfo *tcon,
5206 const unsigned char * searchName,const unsigned char * ea_name, 5233 const unsigned char *searchName, const unsigned char *ea_name,
5207 unsigned char * ea_value, size_t buf_size, 5234 unsigned char *ea_value, size_t buf_size,
5208 const struct nls_table *nls_codepage, int remap) 5235 const struct nls_table *nls_codepage, int remap)
5209{ 5236{
5210 TRANSACTION2_QPI_REQ *pSMB = NULL; 5237 TRANSACTION2_QPI_REQ *pSMB = NULL;
@@ -5212,8 +5239,8 @@ ssize_t CIFSSMBQueryEA(const int xid,struct cifsTconInfo * tcon,
5212 int rc = 0; 5239 int rc = 0;
5213 int bytes_returned; 5240 int bytes_returned;
5214 int name_len; 5241 int name_len;
5215 struct fea * temp_fea; 5242 struct fea *temp_fea;
5216 char * temp_ptr; 5243 char *temp_ptr;
5217 __u16 params, byte_count; 5244 __u16 params, byte_count;
5218 5245
5219 cFYI(1, ("In Query EA path %s", searchName)); 5246 cFYI(1, ("In Query EA path %s", searchName));
@@ -5225,7 +5252,7 @@ QEARetry:
5225 5252
5226 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5253 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5227 name_len = 5254 name_len =
5228 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName, 5255 cifsConvertToUCS((__le16 *) pSMB->FileName, searchName,
5229 PATH_MAX, nls_codepage, remap); 5256 PATH_MAX, nls_codepage, remap);
5230 name_len++; /* trailing null */ 5257 name_len++; /* trailing null */
5231 name_len *= 2; 5258 name_len *= 2;
@@ -5235,7 +5262,7 @@ QEARetry:
5235 strncpy(pSMB->FileName, searchName, name_len); 5262 strncpy(pSMB->FileName, searchName, name_len);
5236 } 5263 }
5237 5264
5238 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */ ; 5265 params = 2 /* level */ + 4 /* reserved */ + name_len /* includes NUL */;
5239 pSMB->TotalDataCount = 0; 5266 pSMB->TotalDataCount = 0;
5240 pSMB->MaxParameterCount = cpu_to_le16(2); 5267 pSMB->MaxParameterCount = cpu_to_le16(2);
5241 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */ 5268 pSMB->MaxDataCount = cpu_to_le16(4000); /* BB find exact max SMB PDU from sess structure BB */
@@ -5245,7 +5272,7 @@ QEARetry:
5245 pSMB->Timeout = 0; 5272 pSMB->Timeout = 0;
5246 pSMB->Reserved2 = 0; 5273 pSMB->Reserved2 = 0;
5247 pSMB->ParameterOffset = cpu_to_le16(offsetof( 5274 pSMB->ParameterOffset = cpu_to_le16(offsetof(
5248 struct smb_com_transaction2_qpi_req ,InformationLevel) - 4); 5275 struct smb_com_transaction2_qpi_req, InformationLevel) - 4);
5249 pSMB->DataCount = 0; 5276 pSMB->DataCount = 0;
5250 pSMB->DataOffset = 0; 5277 pSMB->DataOffset = 0;
5251 pSMB->SetupCount = 1; 5278 pSMB->SetupCount = 1;
@@ -5269,7 +5296,7 @@ QEARetry:
5269 /* BB also check enough total bytes returned */ 5296 /* BB also check enough total bytes returned */
5270 /* BB we need to improve the validity checking 5297 /* BB we need to improve the validity checking
5271 of these trans2 responses */ 5298 of these trans2 responses */
5272 if (rc || (pSMBr->ByteCount < 4)) 5299 if (rc || (pSMBr->ByteCount < 4))
5273 rc = -EIO; /* bad smb */ 5300 rc = -EIO; /* bad smb */
5274 /* else if (pFindData){ 5301 /* else if (pFindData){
5275 memcpy((char *) pFindData, 5302 memcpy((char *) pFindData,
@@ -5282,7 +5309,7 @@ QEARetry:
5282 /* check that each element of each entry does not 5309 /* check that each element of each entry does not
5283 go beyond end of list */ 5310 go beyond end of list */
5284 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset); 5311 __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
5285 struct fealist * ea_response_data; 5312 struct fealist *ea_response_data;
5286 rc = -ENODATA; 5313 rc = -ENODATA;
5287 /* validate_trans2_offsets() */ 5314 /* validate_trans2_offsets() */
5288 /* BB check if start of smb + data_offset > &bcc+ bcc*/ 5315 /* BB check if start of smb + data_offset > &bcc+ bcc*/
@@ -5290,10 +5317,10 @@ QEARetry:
5290 (((char *) &pSMBr->hdr.Protocol) + 5317 (((char *) &pSMBr->hdr.Protocol) +
5291 data_offset); 5318 data_offset);
5292 name_len = le32_to_cpu(ea_response_data->list_len); 5319 name_len = le32_to_cpu(ea_response_data->list_len);
5293 cFYI(1,("ea length %d", name_len)); 5320 cFYI(1, ("ea length %d", name_len));
5294 if (name_len <= 8) { 5321 if (name_len <= 8) {
5295 /* returned EA size zeroed at top of function */ 5322 /* returned EA size zeroed at top of function */
5296 cFYI(1,("empty EA list returned from server")); 5323 cFYI(1, ("empty EA list returned from server"));
5297 } else { 5324 } else {
5298 /* account for ea list len */ 5325 /* account for ea list len */
5299 name_len -= 4; 5326 name_len -= 4;
@@ -5301,13 +5328,14 @@ QEARetry:
5301 temp_ptr = (char *)temp_fea; 5328 temp_ptr = (char *)temp_fea;
5302 /* loop through checking if we have a matching 5329 /* loop through checking if we have a matching
5303 name and then return the associated value */ 5330 name and then return the associated value */
5304 while(name_len > 0) { 5331 while (name_len > 0) {
5305 __u16 value_len; 5332 __u16 value_len;
5306 name_len -= 4; 5333 name_len -= 4;
5307 temp_ptr += 4; 5334 temp_ptr += 4;
5308 value_len = le16_to_cpu(temp_fea->value_len); 5335 value_len =
5309 /* BB validate that value_len falls within SMB, 5336 le16_to_cpu(temp_fea->value_len);
5310 even though maximum for name_len is 255 */ 5337 /* BB validate that value_len falls within SMB,
5338 even though maximum for name_len is 255 */
5311 if (memcmp(temp_fea->name, ea_name, 5339 if (memcmp(temp_fea->name, ea_name,
5312 temp_fea->name_len) == 0) { 5340 temp_fea->name_len) == 0) {
5313 /* found a match */ 5341 /* found a match */
@@ -5317,12 +5345,13 @@ QEARetry:
5317 memcpy(ea_value, 5345 memcpy(ea_value,
5318 temp_fea->name+temp_fea->name_len+1, 5346 temp_fea->name+temp_fea->name_len+1,
5319 rc); 5347 rc);
5320 /* ea values, unlike ea names, 5348 /* ea values, unlike ea
5321 are not null terminated */ 5349 names, are not null
5350 terminated */
5322 } else if (buf_size == 0) { 5351 } else if (buf_size == 0) {
5323 /* skip copy - calc size only */ 5352 /* skip copy - calc size only */
5324 } else { 5353 } else {
5325 /* stop before overrun buffer */ 5354 /* stop before overrun buffer */
5326 rc = -ERANGE; 5355 rc = -ERANGE;
5327 } 5356 }
5328 break; 5357 break;
@@ -5334,11 +5363,11 @@ QEARetry:
5334 temp_ptr++; 5363 temp_ptr++;
5335 name_len -= value_len; 5364 name_len -= value_len;
5336 temp_ptr += value_len; 5365 temp_ptr += value_len;
5337 /* no trailing null to account for in value len */ 5366 /* No trailing null to account for in
5338 /* go on to next EA */ 5367 value_len. Go on to next EA */
5339 temp_fea = (struct fea *)temp_ptr; 5368 temp_fea = (struct fea *)temp_ptr;
5340 } 5369 }
5341 } 5370 }
5342 } 5371 }
5343 } 5372 }
5344 if (pSMB) 5373 if (pSMB)
@@ -5351,9 +5380,9 @@ QEARetry:
5351 5380
5352int 5381int
5353CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName, 5382CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName,
5354 const char * ea_name, const void * ea_value, 5383 const char *ea_name, const void *ea_value,
5355 const __u16 ea_value_len, const struct nls_table *nls_codepage, 5384 const __u16 ea_value_len, const struct nls_table *nls_codepage,
5356 int remap) 5385 int remap)
5357{ 5386{
5358 struct smb_com_transaction2_spi_req *pSMB = NULL; 5387 struct smb_com_transaction2_spi_req *pSMB = NULL;
5359 struct smb_com_transaction2_spi_rsp *pSMBr = NULL; 5388 struct smb_com_transaction2_spi_rsp *pSMBr = NULL;
@@ -5372,11 +5401,11 @@ SetEARetry:
5372 5401
5373 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) { 5402 if (pSMB->hdr.Flags2 & SMBFLG2_UNICODE) {
5374 name_len = 5403 name_len =
5375 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName, 5404 cifsConvertToUCS((__le16 *) pSMB->FileName, fileName,
5376 PATH_MAX, nls_codepage, remap); 5405 PATH_MAX, nls_codepage, remap);
5377 name_len++; /* trailing null */ 5406 name_len++; /* trailing null */
5378 name_len *= 2; 5407 name_len *= 2;
5379 } else { /* BB improve the check for buffer overruns BB */ 5408 } else { /* BB improve the check for buffer overruns BB */
5380 name_len = strnlen(fileName, PATH_MAX); 5409 name_len = strnlen(fileName, PATH_MAX);
5381 name_len++; /* trailing null */ 5410 name_len++; /* trailing null */
5382 strncpy(pSMB->FileName, fileName, name_len); 5411 strncpy(pSMB->FileName, fileName, name_len);
@@ -5390,7 +5419,7 @@ SetEARetry:
5390 if (ea_name == NULL) 5419 if (ea_name == NULL)
5391 name_len = 0; 5420 name_len = 0;
5392 else 5421 else
5393 name_len = strnlen(ea_name,255); 5422 name_len = strnlen(ea_name, 255);
5394 5423
5395 count = sizeof(*parm_data) + ea_value_len + name_len + 1; 5424 count = sizeof(*parm_data) + ea_value_len + name_len + 1;
5396 pSMB->MaxParameterCount = cpu_to_le16(2); 5425 pSMB->MaxParameterCount = cpu_to_le16(2);
@@ -5401,7 +5430,7 @@ SetEARetry:
5401 pSMB->Timeout = 0; 5430 pSMB->Timeout = 0;
5402 pSMB->Reserved2 = 0; 5431 pSMB->Reserved2 = 0;
5403 param_offset = offsetof(struct smb_com_transaction2_spi_req, 5432 param_offset = offsetof(struct smb_com_transaction2_spi_req,
5404 InformationLevel) - 4; 5433 InformationLevel) - 4;
5405 offset = param_offset + params; 5434 offset = param_offset + params;
5406 pSMB->InformationLevel = 5435 pSMB->InformationLevel =
5407 cpu_to_le16(SMB_SET_FILE_EA); 5436 cpu_to_le16(SMB_SET_FILE_EA);
@@ -5422,16 +5451,18 @@ SetEARetry:
5422 parm_data->list[0].name_len = (__u8)name_len; 5451 parm_data->list[0].name_len = (__u8)name_len;
5423 /* EA names are always ASCII */ 5452 /* EA names are always ASCII */
5424 if (ea_name) 5453 if (ea_name)
5425 strncpy(parm_data->list[0].name,ea_name,name_len); 5454 strncpy(parm_data->list[0].name, ea_name, name_len);
5426 parm_data->list[0].name[name_len] = 0; 5455 parm_data->list[0].name[name_len] = 0;
5427 parm_data->list[0].value_len = cpu_to_le16(ea_value_len); 5456 parm_data->list[0].value_len = cpu_to_le16(ea_value_len);
5428 /* caller ensures that ea_value_len is less than 64K but 5457 /* caller ensures that ea_value_len is less than 64K but
5429 we need to ensure that it fits within the smb */ 5458 we need to ensure that it fits within the smb */
5430 5459
5431 /*BB add length check that it would fit in negotiated SMB buffer size BB */ 5460 /*BB add length check to see if it would fit in
5461 negotiated SMB buffer size BB */
5432 /* if (ea_value_len > buffer_size - 512 (enough for header)) */ 5462 /* if (ea_value_len > buffer_size - 512 (enough for header)) */
5433 if (ea_value_len) 5463 if (ea_value_len)
5434 memcpy(parm_data->list[0].name+name_len+1,ea_value,ea_value_len); 5464 memcpy(parm_data->list[0].name+name_len+1,
5465 ea_value, ea_value_len);
5435 5466
5436 pSMB->TotalDataCount = pSMB->DataCount; 5467 pSMB->TotalDataCount = pSMB->DataCount;
5437 pSMB->ParameterCount = cpu_to_le16(params); 5468 pSMB->ParameterCount = cpu_to_le16(params);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index ef10c3717fb5..9d6d9a09d973 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -121,7 +121,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
121 struct cifsSesInfo *ses; 121 struct cifsSesInfo *ses;
122 struct cifsTconInfo *tcon; 122 struct cifsTconInfo *tcon;
123 struct mid_q_entry *mid_entry; 123 struct mid_q_entry *mid_entry;
124 124
125 spin_lock(&GlobalMid_Lock); 125 spin_lock(&GlobalMid_Lock);
126 if ( kthread_should_stop() ) { 126 if ( kthread_should_stop() ) {
127 /* the demux thread will exit normally 127 /* the demux thread will exit normally
@@ -284,13 +284,13 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
284 total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount); 284 total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount);
285 285
286 remaining = total_data_size - total_in_buf; 286 remaining = total_data_size - total_in_buf;
287 287
288 if (remaining < 0) 288 if (remaining < 0)
289 return -EINVAL; 289 return -EINVAL;
290 290
291 if (remaining == 0) /* nothing to do, ignore */ 291 if (remaining == 0) /* nothing to do, ignore */
292 return 0; 292 return 0;
293 293
294 total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount); 294 total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount);
295 if (remaining < total_in_buf2) { 295 if (remaining < total_in_buf2) {
296 cFYI(1, ("transact2 2nd response contains too much data")); 296 cFYI(1, ("transact2 2nd response contains too much data"));
@@ -318,7 +318,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
318 byte_count += total_in_buf2; 318 byte_count += total_in_buf2;
319 319
320 /* BB also add check that we are not beyond maximum buffer size */ 320 /* BB also add check that we are not beyond maximum buffer size */
321 321
322 pTargetSMB->smb_buf_length = byte_count; 322 pTargetSMB->smb_buf_length = byte_count;
323 323
324 if (remaining == total_in_buf2) { 324 if (remaining == total_in_buf2) {
@@ -560,7 +560,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
560 continue; 560 continue;
561 561
562 length += 4; /* account for rfc1002 hdr */ 562 length += 4; /* account for rfc1002 hdr */
563 563
564 564
565 dump_smb(smb_buffer, length); 565 dump_smb(smb_buffer, length);
566 if (checkSMB(smb_buffer, smb_buffer->Mid, total_read+4)) { 566 if (checkSMB(smb_buffer, smb_buffer->Mid, total_read+4)) {
@@ -574,7 +574,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
574 list_for_each(tmp, &server->pending_mid_q) { 574 list_for_each(tmp, &server->pending_mid_q) {
575 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 575 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
576 576
577 if ((mid_entry->mid == smb_buffer->Mid) && 577 if ((mid_entry->mid == smb_buffer->Mid) &&
578 (mid_entry->midState == MID_REQUEST_SUBMITTED) && 578 (mid_entry->midState == MID_REQUEST_SUBMITTED) &&
579 (mid_entry->command == smb_buffer->Command)) { 579 (mid_entry->command == smb_buffer->Command)) {
580 if (check2ndT2(smb_buffer,server->maxBuf) > 0) { 580 if (check2ndT2(smb_buffer,server->maxBuf) > 0) {
@@ -582,20 +582,20 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
582 isMultiRsp = TRUE; 582 isMultiRsp = TRUE;
583 if (mid_entry->resp_buf) { 583 if (mid_entry->resp_buf) {
584 /* merge response - fix up 1st*/ 584 /* merge response - fix up 1st*/
585 if (coalesce_t2(smb_buffer, 585 if (coalesce_t2(smb_buffer,
586 mid_entry->resp_buf)) { 586 mid_entry->resp_buf)) {
587 mid_entry->multiRsp = 1; 587 mid_entry->multiRsp = 1;
588 break; 588 break;
589 } else { 589 } else {
590 /* all parts received */ 590 /* all parts received */
591 mid_entry->multiEnd = 1; 591 mid_entry->multiEnd = 1;
592 goto multi_t2_fnd; 592 goto multi_t2_fnd;
593 } 593 }
594 } else { 594 } else {
595 if (!isLargeBuf) { 595 if (!isLargeBuf) {
596 cERROR(1,("1st trans2 resp needs bigbuf")); 596 cERROR(1,("1st trans2 resp needs bigbuf"));
597 /* BB maybe we can fix this up, switch 597 /* BB maybe we can fix this up, switch
598 to already allocated large buffer? */ 598 to already allocated large buffer? */
599 } else { 599 } else {
600 /* Have first buffer */ 600 /* Have first buffer */
601 mid_entry->resp_buf = 601 mid_entry->resp_buf =
@@ -605,7 +605,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
605 } 605 }
606 } 606 }
607 break; 607 break;
608 } 608 }
609 mid_entry->resp_buf = smb_buffer; 609 mid_entry->resp_buf = smb_buffer;
610 if (isLargeBuf) 610 if (isLargeBuf)
611 mid_entry->largeBuf = 1; 611 mid_entry->largeBuf = 1;
@@ -636,15 +636,16 @@ multi_t2_fnd:
636 } 636 }
637 wake_up_process(task_to_wake); 637 wake_up_process(task_to_wake);
638 } else if ((is_valid_oplock_break(smb_buffer, server) == FALSE) 638 } else if ((is_valid_oplock_break(smb_buffer, server) == FALSE)
639 && (isMultiRsp == FALSE)) { 639 && (isMultiRsp == FALSE)) {
640 cERROR(1, ("No task to wake, unknown frame rcvd! NumMids %d", midCount.counter)); 640 cERROR(1, ("No task to wake, unknown frame received! "
641 cifs_dump_mem("Received Data is: ",(char *)smb_buffer, 641 "NumMids %d", midCount.counter));
642 cifs_dump_mem("Received Data is: ", (char *)smb_buffer,
642 sizeof(struct smb_hdr)); 643 sizeof(struct smb_hdr));
643#ifdef CONFIG_CIFS_DEBUG2 644#ifdef CONFIG_CIFS_DEBUG2
644 cifs_dump_detail(smb_buffer); 645 cifs_dump_detail(smb_buffer);
645 cifs_dump_mids(server); 646 cifs_dump_mids(server);
646#endif /* CIFS_DEBUG2 */ 647#endif /* CIFS_DEBUG2 */
647 648
648 } 649 }
649 } /* end while !EXITING */ 650 } /* end while !EXITING */
650 651
@@ -659,7 +660,7 @@ multi_t2_fnd:
659 /* We do not want to set the max_pending too low or we 660 /* We do not want to set the max_pending too low or we
660 could end up with the counter going negative */ 661 could end up with the counter going negative */
661 spin_unlock(&GlobalMid_Lock); 662 spin_unlock(&GlobalMid_Lock);
662 /* Although there should not be any requests blocked on 663 /* Although there should not be any requests blocked on
663 this queue it can not hurt to be paranoid and try to wake up requests 664 this queue it can not hurt to be paranoid and try to wake up requests
664 that may haven been blocked when more than 50 at time were on the wire 665 that may haven been blocked when more than 50 at time were on the wire
665 to the same server - they now will see the session is in exit state 666 to the same server - they now will see the session is in exit state
@@ -667,7 +668,7 @@ multi_t2_fnd:
667 wake_up_all(&server->request_q); 668 wake_up_all(&server->request_q);
668 /* give those requests time to exit */ 669 /* give those requests time to exit */
669 msleep(125); 670 msleep(125);
670 671
671 if (server->ssocket) { 672 if (server->ssocket) {
672 sock_release(csocket); 673 sock_release(csocket);
673 server->ssocket = NULL; 674 server->ssocket = NULL;
@@ -708,8 +709,8 @@ multi_t2_fnd:
708 list_for_each(tmp, &server->pending_mid_q) { 709 list_for_each(tmp, &server->pending_mid_q) {
709 mid_entry = list_entry(tmp, struct mid_q_entry, qhead); 710 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
710 if (mid_entry->midState == MID_REQUEST_SUBMITTED) { 711 if (mid_entry->midState == MID_REQUEST_SUBMITTED) {
711 cFYI(1, 712 cFYI(1, ("Clearing Mid 0x%x - waking up ",
712 ("Clearing Mid 0x%x - waking up ",mid_entry->mid)); 713 mid_entry->mid));
713 task_to_wake = mid_entry->tsk; 714 task_to_wake = mid_entry->tsk;
714 if (task_to_wake) { 715 if (task_to_wake) {
715 wake_up_process(task_to_wake); 716 wake_up_process(task_to_wake);
@@ -723,7 +724,7 @@ multi_t2_fnd:
723 } 724 }
724 725
725 if (!list_empty(&server->pending_mid_q)) { 726 if (!list_empty(&server->pending_mid_q)) {
726 /* mpx threads have not exited yet give them 727 /* mpx threads have not exited yet give them
727 at least the smb send timeout time for long ops */ 728 at least the smb send timeout time for long ops */
728 /* due to delays on oplock break requests, we need 729 /* due to delays on oplock break requests, we need
729 to wait at least 45 seconds before giving up 730 to wait at least 45 seconds before giving up
@@ -741,7 +742,7 @@ multi_t2_fnd:
741 742
742 /* last chance to mark ses pointers invalid 743 /* last chance to mark ses pointers invalid
743 if there are any pointing to this (e.g 744 if there are any pointing to this (e.g
744 if a crazy root user tried to kill cifsd 745 if a crazy root user tried to kill cifsd
745 kernel thread explicitly this might happen) */ 746 kernel thread explicitly this might happen) */
746 list_for_each(tmp, &GlobalSMBSessionList) { 747 list_for_each(tmp, &GlobalSMBSessionList) {
747 ses = list_entry(tmp, struct cifsSesInfo, 748 ses = list_entry(tmp, struct cifsSesInfo,
@@ -758,12 +759,13 @@ multi_t2_fnd:
758 length + cifs_min_rcv, 759 length + cifs_min_rcv,
759 GFP_KERNEL); 760 GFP_KERNEL);
760 } 761 }
761 762
762 return 0; 763 return 0;
763} 764}
764 765
765static int 766static int
766cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol) 767cifs_parse_mount_options(char *options, const char *devname,
768 struct smb_vol *vol)
767{ 769{
768 char *value; 770 char *value;
769 char *data; 771 char *data;
@@ -771,15 +773,15 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
771 char separator[2]; 773 char separator[2];
772 774
773 separator[0] = ','; 775 separator[0] = ',';
774 separator[1] = 0; 776 separator[1] = 0;
775 777
776 if (Local_System_Name[0] != 0) 778 if (Local_System_Name[0] != 0)
777 memcpy(vol->source_rfc1001_name, Local_System_Name,15); 779 memcpy(vol->source_rfc1001_name, Local_System_Name, 15);
778 else { 780 else {
779 char *nodename = utsname()->nodename; 781 char *nodename = utsname()->nodename;
780 int n = strnlen(nodename,15); 782 int n = strnlen(nodename, 15);
781 memset(vol->source_rfc1001_name,0x20,15); 783 memset(vol->source_rfc1001_name, 0x20, 15);
782 for(i=0 ; i < n ; i++) { 784 for (i = 0; i < n; i++) {
783 /* does not have to be perfect mapping since field is 785 /* does not have to be perfect mapping since field is
784 informational, only used for servers that do not support 786 informational, only used for servers that do not support
785 port 445 and it can be overridden at mount time */ 787 port 445 and it can be overridden at mount time */
@@ -804,7 +806,7 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
804 if (!options) 806 if (!options)
805 return 1; 807 return 1;
806 808
807 if (strncmp(options,"sep=",4) == 0) { 809 if (strncmp(options, "sep=", 4) == 0) {
808 if (options[4] != 0) { 810 if (options[4] != 0) {
809 separator[0] = options[4]; 811 separator[0] = options[4];
810 options += 5; 812 options += 5;
@@ -812,16 +814,17 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
812 cFYI(1, ("Null separator not allowed")); 814 cFYI(1, ("Null separator not allowed"));
813 } 815 }
814 } 816 }
815 817
816 while ((data = strsep(&options, separator)) != NULL) { 818 while ((data = strsep(&options, separator)) != NULL) {
817 if (!*data) 819 if (!*data)
818 continue; 820 continue;
819 if ((value = strchr(data, '=')) != NULL) 821 if ((value = strchr(data, '=')) != NULL)
820 *value++ = '\0'; 822 *value++ = '\0';
821 823
822 if (strnicmp(data, "user_xattr",10) == 0) {/*parse before user*/ 824 /* Have to parse this before we parse for "user" */
825 if (strnicmp(data, "user_xattr", 10) == 0) {
823 vol->no_xattr = 0; 826 vol->no_xattr = 0;
824 } else if (strnicmp(data, "nouser_xattr",12) == 0) { 827 } else if (strnicmp(data, "nouser_xattr", 12) == 0) {
825 vol->no_xattr = 1; 828 vol->no_xattr = 1;
826 } else if (strnicmp(data, "user", 4) == 0) { 829 } else if (strnicmp(data, "user", 4) == 0) {
827 if (!value) { 830 if (!value) {
@@ -856,7 +859,7 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
856 /* removed password length check, NTLM passwords 859 /* removed password length check, NTLM passwords
857 can be arbitrarily long */ 860 can be arbitrarily long */
858 861
859 /* if comma in password, the string will be 862 /* if comma in password, the string will be
860 prematurely null terminated. Commas in password are 863 prematurely null terminated. Commas in password are
861 specified across the cifs mount interface by a double 864 specified across the cifs mount interface by a double
862 comma ie ,, and a comma used as in other cases ie ',' 865 comma ie ,, and a comma used as in other cases ie ','
@@ -866,18 +869,18 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
866 /* NB: password legally can have multiple commas and 869 /* NB: password legally can have multiple commas and
867 the only illegal character in a password is null */ 870 the only illegal character in a password is null */
868 871
869 if ((value[temp_len] == 0) && 872 if ((value[temp_len] == 0) &&
870 (value[temp_len+1] == separator[0])) { 873 (value[temp_len+1] == separator[0])) {
871 /* reinsert comma */ 874 /* reinsert comma */
872 value[temp_len] = separator[0]; 875 value[temp_len] = separator[0];
873 temp_len+=2; /* move after the second comma */ 876 temp_len += 2; /* move after second comma */
874 while(value[temp_len] != 0) { 877 while (value[temp_len] != 0) {
875 if (value[temp_len] == separator[0]) { 878 if (value[temp_len] == separator[0]) {
876 if (value[temp_len+1] == 879 if (value[temp_len+1] ==
877 separator[0]) { 880 separator[0]) {
878 /* skip second comma */ 881 /* skip second comma */
879 temp_len++; 882 temp_len++;
880 } else { 883 } else {
881 /* single comma indicating start 884 /* single comma indicating start
882 of next parm */ 885 of next parm */
883 break; 886 break;
@@ -892,15 +895,16 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
892 /* point option to start of next parm */ 895 /* point option to start of next parm */
893 options = value + temp_len + 1; 896 options = value + temp_len + 1;
894 } 897 }
895 /* go from value to value + temp_len condensing 898 /* go from value to value + temp_len condensing
896 double commas to singles. Note that this ends up 899 double commas to singles. Note that this ends up
897 allocating a few bytes too many, which is ok */ 900 allocating a few bytes too many, which is ok */
898 vol->password = kzalloc(temp_len, GFP_KERNEL); 901 vol->password = kzalloc(temp_len, GFP_KERNEL);
899 if (vol->password == NULL) { 902 if (vol->password == NULL) {
900 printk("CIFS: no memory for pass\n"); 903 printk(KERN_WARNING "CIFS: no memory "
904 "for password\n");
901 return 1; 905 return 1;
902 } 906 }
903 for(i=0,j=0;i<temp_len;i++,j++) { 907 for (i = 0, j = 0; i < temp_len; i++, j++) {
904 vol->password[j] = value[i]; 908 vol->password[j] = value[i];
905 if (value[i] == separator[0] 909 if (value[i] == separator[0]
906 && value[i+1] == separator[0]) { 910 && value[i+1] == separator[0]) {
@@ -912,7 +916,8 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
912 } else { 916 } else {
913 vol->password = kzalloc(temp_len+1, GFP_KERNEL); 917 vol->password = kzalloc(temp_len+1, GFP_KERNEL);
914 if (vol->password == NULL) { 918 if (vol->password == NULL) {
915 printk("CIFS: no memory for pass\n"); 919 printk(KERN_WARNING "CIFS: no memory "
920 "for password\n");
916 return 1; 921 return 1;
917 } 922 }
918 strcpy(vol->password, value); 923 strcpy(vol->password, value);
@@ -923,20 +928,21 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
923 } else if (strnlen(value, 35) < 35) { 928 } else if (strnlen(value, 35) < 35) {
924 vol->UNCip = value; 929 vol->UNCip = value;
925 } else { 930 } else {
926 printk(KERN_WARNING "CIFS: ip address too long\n"); 931 printk(KERN_WARNING "CIFS: ip address "
932 "too long\n");
927 return 1; 933 return 1;
928 } 934 }
929 } else if (strnicmp(data, "sec", 3) == 0) { 935 } else if (strnicmp(data, "sec", 3) == 0) {
930 if (!value || !*value) { 936 if (!value || !*value) {
931 cERROR(1,("no security value specified")); 937 cERROR(1, ("no security value specified"));
932 continue; 938 continue;
933 } else if (strnicmp(value, "krb5i", 5) == 0) { 939 } else if (strnicmp(value, "krb5i", 5) == 0) {
934 vol->secFlg |= CIFSSEC_MAY_KRB5 | 940 vol->secFlg |= CIFSSEC_MAY_KRB5 |
935 CIFSSEC_MUST_SIGN; 941 CIFSSEC_MUST_SIGN;
936 } else if (strnicmp(value, "krb5p", 5) == 0) { 942 } else if (strnicmp(value, "krb5p", 5) == 0) {
937 /* vol->secFlg |= CIFSSEC_MUST_SEAL | 943 /* vol->secFlg |= CIFSSEC_MUST_SEAL |
938 CIFSSEC_MAY_KRB5; */ 944 CIFSSEC_MAY_KRB5; */
939 cERROR(1,("Krb5 cifs privacy not supported")); 945 cERROR(1, ("Krb5 cifs privacy not supported"));
940 return 1; 946 return 1;
941 } else if (strnicmp(value, "krb5", 4) == 0) { 947 } else if (strnicmp(value, "krb5", 4) == 0) {
942 vol->secFlg |= CIFSSEC_MAY_KRB5; 948 vol->secFlg |= CIFSSEC_MAY_KRB5;
@@ -956,33 +962,34 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
956 vol->secFlg |= CIFSSEC_MAY_NTLMV2; 962 vol->secFlg |= CIFSSEC_MAY_NTLMV2;
957#ifdef CONFIG_CIFS_WEAK_PW_HASH 963#ifdef CONFIG_CIFS_WEAK_PW_HASH
958 } else if (strnicmp(value, "lanman", 6) == 0) { 964 } else if (strnicmp(value, "lanman", 6) == 0) {
959 vol->secFlg |= CIFSSEC_MAY_LANMAN; 965 vol->secFlg |= CIFSSEC_MAY_LANMAN;
960#endif 966#endif
961 } else if (strnicmp(value, "none", 4) == 0) { 967 } else if (strnicmp(value, "none", 4) == 0) {
962 vol->nullauth = 1; 968 vol->nullauth = 1;
963 } else { 969 } else {
964 cERROR(1,("bad security option: %s", value)); 970 cERROR(1, ("bad security option: %s", value));
965 return 1; 971 return 1;
966 } 972 }
967 } else if ((strnicmp(data, "unc", 3) == 0) 973 } else if ((strnicmp(data, "unc", 3) == 0)
968 || (strnicmp(data, "target", 6) == 0) 974 || (strnicmp(data, "target", 6) == 0)
969 || (strnicmp(data, "path", 4) == 0)) { 975 || (strnicmp(data, "path", 4) == 0)) {
970 if (!value || !*value) { 976 if (!value || !*value) {
971 printk(KERN_WARNING 977 printk(KERN_WARNING "CIFS: invalid path to "
972 "CIFS: invalid path to network resource\n"); 978 "network resource\n");
973 return 1; /* needs_arg; */ 979 return 1; /* needs_arg; */
974 } 980 }
975 if ((temp_len = strnlen(value, 300)) < 300) { 981 if ((temp_len = strnlen(value, 300)) < 300) {
976 vol->UNC = kmalloc(temp_len+1,GFP_KERNEL); 982 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
977 if (vol->UNC == NULL) 983 if (vol->UNC == NULL)
978 return 1; 984 return 1;
979 strcpy(vol->UNC,value); 985 strcpy(vol->UNC, value);
980 if (strncmp(vol->UNC, "//", 2) == 0) { 986 if (strncmp(vol->UNC, "//", 2) == 0) {
981 vol->UNC[0] = '\\'; 987 vol->UNC[0] = '\\';
982 vol->UNC[1] = '\\'; 988 vol->UNC[1] = '\\';
983 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) { 989 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
984 printk(KERN_WARNING 990 printk(KERN_WARNING
985 "CIFS: UNC Path does not begin with // or \\\\ \n"); 991 "CIFS: UNC Path does not begin "
992 "with // or \\\\ \n");
986 return 1; 993 return 1;
987 } 994 }
988 } else { 995 } else {
@@ -1001,41 +1008,43 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1001 vol->domainname = value; 1008 vol->domainname = value;
1002 cFYI(1, ("Domain name set")); 1009 cFYI(1, ("Domain name set"));
1003 } else { 1010 } else {
1004 printk(KERN_WARNING "CIFS: domain name too long\n"); 1011 printk(KERN_WARNING "CIFS: domain name too "
1012 "long\n");
1005 return 1; 1013 return 1;
1006 } 1014 }
1007 } else if (strnicmp(data, "prefixpath", 10) == 0) { 1015 } else if (strnicmp(data, "prefixpath", 10) == 0) {
1008 if (!value || !*value) { 1016 if (!value || !*value) {
1009 printk(KERN_WARNING 1017 printk(KERN_WARNING
1010 "CIFS: invalid path prefix\n"); 1018 "CIFS: invalid path prefix\n");
1011 return 1; /* needs_arg; */ 1019 return 1; /* needs_argument */
1012 } 1020 }
1013 if ((temp_len = strnlen(value, 1024)) < 1024) { 1021 if ((temp_len = strnlen(value, 1024)) < 1024) {
1014 if (value[0] != '/') 1022 if (value[0] != '/')
1015 temp_len++; /* missing leading slash */ 1023 temp_len++; /* missing leading slash */
1016 vol->prepath = kmalloc(temp_len+1,GFP_KERNEL); 1024 vol->prepath = kmalloc(temp_len+1, GFP_KERNEL);
1017 if (vol->prepath == NULL) 1025 if (vol->prepath == NULL)
1018 return 1; 1026 return 1;
1019 if (value[0] != '/') { 1027 if (value[0] != '/') {
1020 vol->prepath[0] = '/'; 1028 vol->prepath[0] = '/';
1021 strcpy(vol->prepath+1,value); 1029 strcpy(vol->prepath+1, value);
1022 } else 1030 } else
1023 strcpy(vol->prepath,value); 1031 strcpy(vol->prepath, value);
1024 cFYI(1, ("prefix path %s",vol->prepath)); 1032 cFYI(1, ("prefix path %s", vol->prepath));
1025 } else { 1033 } else {
1026 printk(KERN_WARNING "CIFS: prefix too long\n"); 1034 printk(KERN_WARNING "CIFS: prefix too long\n");
1027 return 1; 1035 return 1;
1028 } 1036 }
1029 } else if (strnicmp(data, "iocharset", 9) == 0) { 1037 } else if (strnicmp(data, "iocharset", 9) == 0) {
1030 if (!value || !*value) { 1038 if (!value || !*value) {
1031 printk(KERN_WARNING "CIFS: invalid iocharset specified\n"); 1039 printk(KERN_WARNING "CIFS: invalid iocharset specified\n");
1032 return 1; /* needs_arg; */ 1040 return 1; /* needs_arg; */
1033 } 1041 }
1034 if (strnlen(value, 65) < 65) { 1042 if (strnlen(value, 65) < 65) {
1035 if (strnicmp(value,"default",7)) 1043 if (strnicmp(value, "default", 7))
1036 vol->iocharset = value; 1044 vol->iocharset = value;
1037 /* if iocharset not set load_nls_default used by caller */ 1045 /* if iocharset not set then load_nls_default
1038 cFYI(1, ("iocharset set to %s",value)); 1046 is used by caller */
1047 cFYI(1, ("iocharset set to %s", value));
1039 } else { 1048 } else {
1040 printk(KERN_WARNING "CIFS: iocharset name too long.\n"); 1049 printk(KERN_WARNING "CIFS: iocharset name too long.\n");
1041 return 1; 1050 return 1;
@@ -1091,22 +1100,24 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1091 if (!value || !*value || (*value == ' ')) { 1100 if (!value || !*value || (*value == ' ')) {
1092 cFYI(1, ("invalid (empty) netbiosname specified")); 1101 cFYI(1, ("invalid (empty) netbiosname specified"));
1093 } else { 1102 } else {
1094 memset(vol->source_rfc1001_name,0x20,15); 1103 memset(vol->source_rfc1001_name, 0x20, 15);
1095 for(i=0;i<15;i++) { 1104 for (i = 0; i < 15; i++) {
1096 /* BB are there cases in which a comma can be 1105 /* BB are there cases in which a comma can be
1097 valid in this workstation netbios name (and need 1106 valid in this workstation netbios name (and need
1098 special handling)? */ 1107 special handling)? */
1099 1108
1100 /* We do not uppercase netbiosname for user */ 1109 /* We do not uppercase netbiosname for user */
1101 if (value[i]==0) 1110 if (value[i] == 0)
1102 break; 1111 break;
1103 else 1112 else
1104 vol->source_rfc1001_name[i] = value[i]; 1113 vol->source_rfc1001_name[i] =
1114 value[i];
1105 } 1115 }
1106 /* The string has 16th byte zero still from 1116 /* The string has 16th byte zero still from
1107 set at top of the function */ 1117 set at top of the function */
1108 if ((i==15) && (value[i] != 0)) 1118 if ((i == 15) && (value[i] != 0))
1109 printk(KERN_WARNING "CIFS: netbiosname longer than 15 truncated.\n"); 1119 printk(KERN_WARNING "CIFS: netbiosname"
1120 " longer than 15 truncated.\n");
1110 } 1121 }
1111 } else if (strnicmp(data, "servern", 7) == 0) { 1122 } else if (strnicmp(data, "servern", 7) == 0) {
1112 /* servernetbiosname specified override *SMBSERVER */ 1123 /* servernetbiosname specified override *SMBSERVER */
@@ -1114,29 +1125,32 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1114 cFYI(1, ("empty server netbiosname specified")); 1125 cFYI(1, ("empty server netbiosname specified"));
1115 } else { 1126 } else {
1116 /* last byte, type, is 0x20 for servr type */ 1127 /* last byte, type, is 0x20 for servr type */
1117 memset(vol->target_rfc1001_name,0x20,16); 1128 memset(vol->target_rfc1001_name, 0x20, 16);
1118 1129
1119 for(i=0;i<15;i++) { 1130 for (i = 0; i < 15; i++) {
1120 /* BB are there cases in which a comma can be 1131 /* BB are there cases in which a comma can be
1121 valid in this workstation netbios name (and need 1132 valid in this workstation netbios name
1122 special handling)? */ 1133 (and need special handling)? */
1123 1134
1124 /* user or mount helper must uppercase netbiosname */ 1135 /* user or mount helper must uppercase
1125 if (value[i]==0) 1136 the netbiosname */
1137 if (value[i] == 0)
1126 break; 1138 break;
1127 else 1139 else
1128 vol->target_rfc1001_name[i] = value[i]; 1140 vol->target_rfc1001_name[i] =
1141 value[i];
1129 } 1142 }
1130 /* The string has 16th byte zero still from 1143 /* The string has 16th byte zero still from
1131 set at top of the function */ 1144 set at top of the function */
1132 if ((i==15) && (value[i] != 0)) 1145 if ((i == 15) && (value[i] != 0))
1133 printk(KERN_WARNING "CIFS: server netbiosname longer than 15 truncated.\n"); 1146 printk(KERN_WARNING "CIFS: server net"
1147 "biosname longer than 15 truncated.\n");
1134 } 1148 }
1135 } else if (strnicmp(data, "credentials", 4) == 0) { 1149 } else if (strnicmp(data, "credentials", 4) == 0) {
1136 /* ignore */ 1150 /* ignore */
1137 } else if (strnicmp(data, "version", 3) == 0) { 1151 } else if (strnicmp(data, "version", 3) == 0) {
1138 /* ignore */ 1152 /* ignore */
1139 } else if (strnicmp(data, "guest",5) == 0) { 1153 } else if (strnicmp(data, "guest", 5) == 0) {
1140 /* ignore */ 1154 /* ignore */
1141 } else if (strnicmp(data, "rw", 2) == 0) { 1155 } else if (strnicmp(data, "rw", 2) == 0) {
1142 vol->rw = TRUE; 1156 vol->rw = TRUE;
@@ -1148,11 +1162,11 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1148 (strnicmp(data, "noauto", 6) == 0) || 1162 (strnicmp(data, "noauto", 6) == 0) ||
1149 (strnicmp(data, "dev", 3) == 0)) { 1163 (strnicmp(data, "dev", 3) == 0)) {
1150 /* The mount tool or mount.cifs helper (if present) 1164 /* The mount tool or mount.cifs helper (if present)
1151 uses these opts to set flags, and the flags are read 1165 uses these opts to set flags, and the flags are read
1152 by the kernel vfs layer before we get here (ie 1166 by the kernel vfs layer before we get here (ie
1153 before read super) so there is no point trying to 1167 before read super) so there is no point trying to
1154 parse these options again and set anything and it 1168 parse these options again and set anything and it
1155 is ok to just ignore them */ 1169 is ok to just ignore them */
1156 continue; 1170 continue;
1157 } else if (strnicmp(data, "ro", 2) == 0) { 1171 } else if (strnicmp(data, "ro", 2) == 0) {
1158 vol->rw = FALSE; 1172 vol->rw = FALSE;
@@ -1168,26 +1182,27 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1168 vol->remap = 1; 1182 vol->remap = 1;
1169 } else if (strnicmp(data, "nomapchars", 10) == 0) { 1183 } else if (strnicmp(data, "nomapchars", 10) == 0) {
1170 vol->remap = 0; 1184 vol->remap = 0;
1171 } else if (strnicmp(data, "sfu", 3) == 0) { 1185 } else if (strnicmp(data, "sfu", 3) == 0) {
1172 vol->sfu_emul = 1; 1186 vol->sfu_emul = 1;
1173 } else if (strnicmp(data, "nosfu", 5) == 0) { 1187 } else if (strnicmp(data, "nosfu", 5) == 0) {
1174 vol->sfu_emul = 0; 1188 vol->sfu_emul = 0;
1175 } else if (strnicmp(data, "posixpaths", 10) == 0) { 1189 } else if (strnicmp(data, "posixpaths", 10) == 0) {
1176 vol->posix_paths = 1; 1190 vol->posix_paths = 1;
1177 } else if (strnicmp(data, "noposixpaths", 12) == 0) { 1191 } else if (strnicmp(data, "noposixpaths", 12) == 0) {
1178 vol->posix_paths = 0; 1192 vol->posix_paths = 0;
1179 } else if ((strnicmp(data, "nocase", 6) == 0) || 1193 } else if ((strnicmp(data, "nocase", 6) == 0) ||
1180 (strnicmp(data, "ignorecase", 10) == 0)) { 1194 (strnicmp(data, "ignorecase", 10) == 0)) {
1181 vol->nocase = 1; 1195 vol->nocase = 1;
1182 } else if (strnicmp(data, "brl", 3) == 0) { 1196 } else if (strnicmp(data, "brl", 3) == 0) {
1183 vol->nobrl = 0; 1197 vol->nobrl = 0;
1184 } else if ((strnicmp(data, "nobrl", 5) == 0) || 1198 } else if ((strnicmp(data, "nobrl", 5) == 0) ||
1185 (strnicmp(data, "nolock", 6) == 0)) { 1199 (strnicmp(data, "nolock", 6) == 0)) {
1186 vol->nobrl = 1; 1200 vol->nobrl = 1;
1187 /* turn off mandatory locking in mode 1201 /* turn off mandatory locking in mode
1188 if remote locking is turned off since the 1202 if remote locking is turned off since the
1189 local vfs will do advisory */ 1203 local vfs will do advisory */
1190 if (vol->file_mode == (S_IALLUGO & ~(S_ISUID | S_IXGRP))) 1204 if (vol->file_mode ==
1205 (S_IALLUGO & ~(S_ISUID | S_IXGRP)))
1191 vol->file_mode = S_IALLUGO; 1206 vol->file_mode = S_IALLUGO;
1192 } else if (strnicmp(data, "setuids", 7) == 0) { 1207 } else if (strnicmp(data, "setuids", 7) == 0) {
1193 vol->setuids = 1; 1208 vol->setuids = 1;
@@ -1201,55 +1216,61 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1201 vol->intr = 0; 1216 vol->intr = 0;
1202 } else if (strnicmp(data, "intr", 4) == 0) { 1217 } else if (strnicmp(data, "intr", 4) == 0) {
1203 vol->intr = 1; 1218 vol->intr = 1;
1204 } else if (strnicmp(data, "serverino",7) == 0) { 1219 } else if (strnicmp(data, "serverino", 7) == 0) {
1205 vol->server_ino = 1; 1220 vol->server_ino = 1;
1206 } else if (strnicmp(data, "noserverino",9) == 0) { 1221 } else if (strnicmp(data, "noserverino", 9) == 0) {
1207 vol->server_ino = 0; 1222 vol->server_ino = 0;
1208 } else if (strnicmp(data, "cifsacl",7) == 0) { 1223 } else if (strnicmp(data, "cifsacl", 7) == 0) {
1209 vol->cifs_acl = 1; 1224 vol->cifs_acl = 1;
1210 } else if (strnicmp(data, "nocifsacl", 9) == 0) { 1225 } else if (strnicmp(data, "nocifsacl", 9) == 0) {
1211 vol->cifs_acl = 0; 1226 vol->cifs_acl = 0;
1212 } else if (strnicmp(data, "acl",3) == 0) { 1227 } else if (strnicmp(data, "acl", 3) == 0) {
1213 vol->no_psx_acl = 0; 1228 vol->no_psx_acl = 0;
1214 } else if (strnicmp(data, "noacl",5) == 0) { 1229 } else if (strnicmp(data, "noacl", 5) == 0) {
1215 vol->no_psx_acl = 1; 1230 vol->no_psx_acl = 1;
1216 } else if (strnicmp(data, "sign",4) == 0) { 1231 } else if (strnicmp(data, "sign", 4) == 0) {
1217 vol->secFlg |= CIFSSEC_MUST_SIGN; 1232 vol->secFlg |= CIFSSEC_MUST_SIGN;
1218/* } else if (strnicmp(data, "seal",4) == 0) { 1233/* } else if (strnicmp(data, "seal",4) == 0) {
1219 vol->secFlg |= CIFSSEC_MUST_SEAL; */ 1234 vol->secFlg |= CIFSSEC_MUST_SEAL; */
1220 } else if (strnicmp(data, "direct",6) == 0) { 1235 } else if (strnicmp(data, "direct", 6) == 0) {
1221 vol->direct_io = 1; 1236 vol->direct_io = 1;
1222 } else if (strnicmp(data, "forcedirectio",13) == 0) { 1237 } else if (strnicmp(data, "forcedirectio", 13) == 0) {
1223 vol->direct_io = 1; 1238 vol->direct_io = 1;
1224 } else if (strnicmp(data, "in6_addr",8) == 0) { 1239 } else if (strnicmp(data, "in6_addr", 8) == 0) {
1225 if (!value || !*value) { 1240 if (!value || !*value) {
1226 vol->in6_addr = NULL; 1241 vol->in6_addr = NULL;
1227 } else if (strnlen(value, 49) == 48) { 1242 } else if (strnlen(value, 49) == 48) {
1228 vol->in6_addr = value; 1243 vol->in6_addr = value;
1229 } else { 1244 } else {
1230 printk(KERN_WARNING "CIFS: ip v6 address not 48 characters long\n"); 1245 printk(KERN_WARNING "CIFS: ip v6 address not "
1246 "48 characters long\n");
1231 return 1; 1247 return 1;
1232 } 1248 }
1233 } else if (strnicmp(data, "noac", 4) == 0) { 1249 } else if (strnicmp(data, "noac", 4) == 0) {
1234 printk(KERN_WARNING "CIFS: Mount option noac not supported. Instead set /proc/fs/cifs/LookupCacheEnabled to 0\n"); 1250 printk(KERN_WARNING "CIFS: Mount option noac not "
1251 "supported. Instead set "
1252 "/proc/fs/cifs/LookupCacheEnabled to 0\n");
1235 } else 1253 } else
1236 printk(KERN_WARNING "CIFS: Unknown mount option %s\n",data); 1254 printk(KERN_WARNING "CIFS: Unknown mount option %s\n",
1255 data);
1237 } 1256 }
1238 if (vol->UNC == NULL) { 1257 if (vol->UNC == NULL) {
1239 if (devname == NULL) { 1258 if (devname == NULL) {
1240 printk(KERN_WARNING "CIFS: Missing UNC name for mount target\n"); 1259 printk(KERN_WARNING "CIFS: Missing UNC name for mount "
1260 "target\n");
1241 return 1; 1261 return 1;
1242 } 1262 }
1243 if ((temp_len = strnlen(devname, 300)) < 300) { 1263 if ((temp_len = strnlen(devname, 300)) < 300) {
1244 vol->UNC = kmalloc(temp_len+1,GFP_KERNEL); 1264 vol->UNC = kmalloc(temp_len+1, GFP_KERNEL);
1245 if (vol->UNC == NULL) 1265 if (vol->UNC == NULL)
1246 return 1; 1266 return 1;
1247 strcpy(vol->UNC,devname); 1267 strcpy(vol->UNC, devname);
1248 if (strncmp(vol->UNC, "//", 2) == 0) { 1268 if (strncmp(vol->UNC, "//", 2) == 0) {
1249 vol->UNC[0] = '\\'; 1269 vol->UNC[0] = '\\';
1250 vol->UNC[1] = '\\'; 1270 vol->UNC[1] = '\\';
1251 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) { 1271 } else if (strncmp(vol->UNC, "\\\\", 2) != 0) {
1252 printk(KERN_WARNING "CIFS: UNC Path does not begin with // or \\\\ \n"); 1272 printk(KERN_WARNING "CIFS: UNC Path does not "
1273 "begin with // or \\\\ \n");
1253 return 1; 1274 return 1;
1254 } 1275 }
1255 } else { 1276 } else {
@@ -1264,7 +1285,7 @@ cifs_parse_mount_options(char *options, const char *devname,struct smb_vol *vol)
1264} 1285}
1265 1286
1266static struct cifsSesInfo * 1287static struct cifsSesInfo *
1267cifs_find_tcp_session(struct in_addr * target_ip_addr, 1288cifs_find_tcp_session(struct in_addr *target_ip_addr,
1268 struct in6_addr *target_ip6_addr, 1289 struct in6_addr *target_ip6_addr,
1269 char *userName, struct TCP_Server_Info **psrvTcp) 1290 char *userName, struct TCP_Server_Info **psrvTcp)
1270{ 1291{
@@ -1276,19 +1297,25 @@ cifs_find_tcp_session(struct in_addr * target_ip_addr,
1276 list_for_each(tmp, &GlobalSMBSessionList) { 1297 list_for_each(tmp, &GlobalSMBSessionList) {
1277 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList); 1298 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
1278 if (ses->server) { 1299 if (ses->server) {
1279 if ((target_ip_addr && 1300 if ((target_ip_addr &&
1280 (ses->server->addr.sockAddr.sin_addr.s_addr 1301 (ses->server->addr.sockAddr.sin_addr.s_addr
1281 == target_ip_addr->s_addr)) || (target_ip6_addr 1302 == target_ip_addr->s_addr)) || (target_ip6_addr
1282 && memcmp(&ses->server->addr.sockAddr6.sin6_addr, 1303 && memcmp(&ses->server->addr.sockAddr6.sin6_addr,
1283 target_ip6_addr,sizeof(*target_ip6_addr)))){ 1304 target_ip6_addr, sizeof(*target_ip6_addr)))) {
1284 /* BB lock server and tcp session and increment use count here?? */ 1305 /* BB lock server and tcp session and increment
1285 *psrvTcp = ses->server; /* found a match on the TCP session */ 1306 use count here?? */
1307
1308 /* found a match on the TCP session */
1309 *psrvTcp = ses->server;
1310
1286 /* BB check if reconnection needed */ 1311 /* BB check if reconnection needed */
1287 if (strncmp 1312 if (strncmp
1288 (ses->userName, userName, 1313 (ses->userName, userName,
1289 MAX_USERNAME_SIZE) == 0){ 1314 MAX_USERNAME_SIZE) == 0){
1290 read_unlock(&GlobalSMBSeslock); 1315 read_unlock(&GlobalSMBSeslock);
1291 return ses; /* found exact match on both tcp and SMB sessions */ 1316 /* Found exact match on both TCP and
1317 SMB sessions */
1318 return ses;
1292 } 1319 }
1293 } 1320 }
1294 } 1321 }
@@ -1319,7 +1346,8 @@ find_unc(__be32 new_target_ip_addr, char *uncName, char *userName)
1319 /* BB lock tcon, server and tcp session and increment use count here? */ 1346 /* BB lock tcon, server and tcp session and increment use count here? */
1320 /* found a match on the TCP session */ 1347 /* found a match on the TCP session */
1321 /* BB check if reconnection needed */ 1348 /* BB check if reconnection needed */
1322 cFYI(1, ("IP match, old UNC: %s new: %s", 1349 cFYI(1,
1350 ("IP match, old UNC: %s new: %s",
1323 tcon->treeName, uncName)); 1351 tcon->treeName, uncName));
1324 if (strncmp 1352 if (strncmp
1325 (tcon->treeName, uncName, 1353 (tcon->treeName, uncName,
@@ -1354,11 +1382,11 @@ connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1354 unsigned int num_referrals; 1382 unsigned int num_referrals;
1355 int rc = 0; 1383 int rc = 0;
1356 1384
1357 rc = get_dfs_path(xid, pSesInfo,old_path, nls_codepage, 1385 rc = get_dfs_path(xid, pSesInfo, old_path, nls_codepage,
1358 &num_referrals, &referrals, remap); 1386 &num_referrals, &referrals, remap);
1359 1387
1360 /* BB Add in code to: if valid refrl, if not ip address contact 1388 /* BB Add in code to: if valid refrl, if not ip address contact
1361 the helper that resolves tcp names, mount to it, try to 1389 the helper that resolves tcp names, mount to it, try to
1362 tcon to it unmount it if fail */ 1390 tcon to it unmount it if fail */
1363 1391
1364 kfree(referrals); 1392 kfree(referrals);
@@ -1367,10 +1395,9 @@ connect_to_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1367} 1395}
1368 1396
1369int 1397int
1370get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, 1398get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
1371 const char *old_path, const struct nls_table *nls_codepage, 1399 const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
1372 unsigned int *pnum_referrals, 1400 unsigned char **preferrals, int remap)
1373 unsigned char ** preferrals, int remap)
1374{ 1401{
1375 char *temp_unc; 1402 char *temp_unc;
1376 int rc = 0; 1403 int rc = 0;
@@ -1379,7 +1406,8 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1379 1406
1380 if (pSesInfo->ipc_tid == 0) { 1407 if (pSesInfo->ipc_tid == 0) {
1381 temp_unc = kmalloc(2 /* for slashes */ + 1408 temp_unc = kmalloc(2 /* for slashes */ +
1382 strnlen(pSesInfo->serverName,SERVER_NAME_LEN_WITH_NULL * 2) 1409 strnlen(pSesInfo->serverName,
1410 SERVER_NAME_LEN_WITH_NULL * 2)
1383 + 1 + 4 /* slash IPC$ */ + 2, 1411 + 1 + 4 /* slash IPC$ */ + 2,
1384 GFP_KERNEL); 1412 GFP_KERNEL);
1385 if (temp_unc == NULL) 1413 if (temp_unc == NULL)
@@ -1390,7 +1418,7 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1390 strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$"); 1418 strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$");
1391 rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage); 1419 rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage);
1392 cFYI(1, 1420 cFYI(1,
1393 ("CIFS Tcon rc = %d ipc_tid = %d", rc,pSesInfo->ipc_tid)); 1421 ("CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid));
1394 kfree(temp_unc); 1422 kfree(temp_unc);
1395 } 1423 }
1396 if (rc == 0) 1424 if (rc == 0)
@@ -1401,38 +1429,39 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo,
1401} 1429}
1402 1430
1403/* See RFC1001 section 14 on representation of Netbios names */ 1431/* See RFC1001 section 14 on representation of Netbios names */
1404static void rfc1002mangle(char * target,char * source, unsigned int length) 1432static void rfc1002mangle(char *target, char *source, unsigned int length)
1405{ 1433{
1406 unsigned int i,j; 1434 unsigned int i, j;
1407 1435
1408 for(i=0,j=0;i<(length);i++) { 1436 for (i = 0, j = 0; i < (length); i++) {
1409 /* mask a nibble at a time and encode */ 1437 /* mask a nibble at a time and encode */
1410 target[j] = 'A' + (0x0F & (source[i] >> 4)); 1438 target[j] = 'A' + (0x0F & (source[i] >> 4));
1411 target[j+1] = 'A' + (0x0F & source[i]); 1439 target[j+1] = 'A' + (0x0F & source[i]);
1412 j+=2; 1440 j += 2;
1413 } 1441 }
1414 1442
1415} 1443}
1416 1444
1417 1445
1418static int 1446static int
1419ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket, 1447ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1420 char * netbios_name, char * target_name) 1448 char *netbios_name, char *target_name)
1421{ 1449{
1422 int rc = 0; 1450 int rc = 0;
1423 int connected = 0; 1451 int connected = 0;
1424 __be16 orig_port = 0; 1452 __be16 orig_port = 0;
1425 1453
1426 if (*csocket == NULL) { 1454 if (*csocket == NULL) {
1427 rc = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, csocket); 1455 rc = sock_create_kern(PF_INET, SOCK_STREAM,
1456 IPPROTO_TCP, csocket);
1428 if (rc < 0) { 1457 if (rc < 0) {
1429 cERROR(1, ("Error %d creating socket",rc)); 1458 cERROR(1, ("Error %d creating socket", rc));
1430 *csocket = NULL; 1459 *csocket = NULL;
1431 return rc; 1460 return rc;
1432 } else { 1461 } else {
1433 /* BB other socket options to set KEEPALIVE, NODELAY? */ 1462 /* BB other socket options to set KEEPALIVE, NODELAY? */
1434 cFYI(1, ("Socket created")); 1463 cFYI(1, ("Socket created"));
1435 (*csocket)->sk->sk_allocation = GFP_NOFS; 1464 (*csocket)->sk->sk_allocation = GFP_NOFS;
1436 } 1465 }
1437 } 1466 }
1438 1467
@@ -1440,13 +1469,13 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1440 if (psin_server->sin_port) { /* user overrode default port */ 1469 if (psin_server->sin_port) { /* user overrode default port */
1441 rc = (*csocket)->ops->connect(*csocket, 1470 rc = (*csocket)->ops->connect(*csocket,
1442 (struct sockaddr *) psin_server, 1471 (struct sockaddr *) psin_server,
1443 sizeof (struct sockaddr_in),0); 1472 sizeof (struct sockaddr_in), 0);
1444 if (rc >= 0) 1473 if (rc >= 0)
1445 connected = 1; 1474 connected = 1;
1446 } 1475 }
1447 1476
1448 if (!connected) { 1477 if (!connected) {
1449 /* save original port so we can retry user specified port 1478 /* save original port so we can retry user specified port
1450 later if fall back ports fail this time */ 1479 later if fall back ports fail this time */
1451 orig_port = psin_server->sin_port; 1480 orig_port = psin_server->sin_port;
1452 1481
@@ -1456,7 +1485,7 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1456 1485
1457 rc = (*csocket)->ops->connect(*csocket, 1486 rc = (*csocket)->ops->connect(*csocket,
1458 (struct sockaddr *) psin_server, 1487 (struct sockaddr *) psin_server,
1459 sizeof (struct sockaddr_in),0); 1488 sizeof (struct sockaddr_in), 0);
1460 if (rc >= 0) 1489 if (rc >= 0)
1461 connected = 1; 1490 connected = 1;
1462 } 1491 }
@@ -1464,8 +1493,9 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1464 if (!connected) { 1493 if (!connected) {
1465 psin_server->sin_port = htons(RFC1001_PORT); 1494 psin_server->sin_port = htons(RFC1001_PORT);
1466 rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *) 1495 rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
1467 psin_server, sizeof (struct sockaddr_in),0); 1496 psin_server,
1468 if (rc >= 0) 1497 sizeof (struct sockaddr_in), 0);
1498 if (rc >= 0)
1469 connected = 1; 1499 connected = 1;
1470 } 1500 }
1471 1501
@@ -1474,15 +1504,16 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1474 if (!connected) { 1504 if (!connected) {
1475 if (orig_port) 1505 if (orig_port)
1476 psin_server->sin_port = orig_port; 1506 psin_server->sin_port = orig_port;
1477 cFYI(1, ("Error %d connecting to server via ipv4",rc)); 1507 cFYI(1, ("Error %d connecting to server via ipv4", rc));
1478 sock_release(*csocket); 1508 sock_release(*csocket);
1479 *csocket = NULL; 1509 *csocket = NULL;
1480 return rc; 1510 return rc;
1481 } 1511 }
1482 /* Eventually check for other socket options to change from 1512 /* Eventually check for other socket options to change from
1483 the default. sock_setsockopt not used because it expects 1513 the default. sock_setsockopt not used because it expects
1484 user space buffer */ 1514 user space buffer */
1485 cFYI(1, ("sndbuf %d rcvbuf %d rcvtimeo 0x%lx",(*csocket)->sk->sk_sndbuf, 1515 cFYI(1, ("sndbuf %d rcvbuf %d rcvtimeo 0x%lx",
1516 (*csocket)->sk->sk_sndbuf,
1486 (*csocket)->sk->sk_rcvbuf, (*csocket)->sk->sk_rcvtimeo)); 1517 (*csocket)->sk->sk_rcvbuf, (*csocket)->sk->sk_rcvtimeo));
1487 (*csocket)->sk->sk_rcvtimeo = 7 * HZ; 1518 (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
1488 /* make the bufsizes depend on wsize/rsize and max requests */ 1519 /* make the bufsizes depend on wsize/rsize and max requests */
@@ -1494,11 +1525,12 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1494 /* send RFC1001 sessinit */ 1525 /* send RFC1001 sessinit */
1495 if (psin_server->sin_port == htons(RFC1001_PORT)) { 1526 if (psin_server->sin_port == htons(RFC1001_PORT)) {
1496 /* some servers require RFC1001 sessinit before sending 1527 /* some servers require RFC1001 sessinit before sending
1497 negprot - BB check reconnection in case where second 1528 negprot - BB check reconnection in case where second
1498 sessinit is sent but no second negprot */ 1529 sessinit is sent but no second negprot */
1499 struct rfc1002_session_packet * ses_init_buf; 1530 struct rfc1002_session_packet *ses_init_buf;
1500 struct smb_hdr * smb_buf; 1531 struct smb_hdr *smb_buf;
1501 ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet), GFP_KERNEL); 1532 ses_init_buf = kzalloc(sizeof(struct rfc1002_session_packet),
1533 GFP_KERNEL);
1502 if (ses_init_buf) { 1534 if (ses_init_buf) {
1503 ses_init_buf->trailer.session_req.called_len = 32; 1535 ses_init_buf->trailer.session_req.called_len = 32;
1504 if (target_name && (target_name[0] != 0)) { 1536 if (target_name && (target_name[0] != 0)) {
@@ -1506,18 +1538,18 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1506 target_name, 16); 1538 target_name, 16);
1507 } else { 1539 } else {
1508 rfc1002mangle(ses_init_buf->trailer.session_req.called_name, 1540 rfc1002mangle(ses_init_buf->trailer.session_req.called_name,
1509 DEFAULT_CIFS_CALLED_NAME,16); 1541 DEFAULT_CIFS_CALLED_NAME, 16);
1510 } 1542 }
1511 1543
1512 ses_init_buf->trailer.session_req.calling_len = 32; 1544 ses_init_buf->trailer.session_req.calling_len = 32;
1513 /* calling name ends in null (byte 16) from old smb 1545 /* calling name ends in null (byte 16) from old smb
1514 convention. */ 1546 convention. */
1515 if (netbios_name && (netbios_name[0] !=0)) { 1547 if (netbios_name && (netbios_name[0] != 0)) {
1516 rfc1002mangle(ses_init_buf->trailer.session_req.calling_name, 1548 rfc1002mangle(ses_init_buf->trailer.session_req.calling_name,
1517 netbios_name,16); 1549 netbios_name, 16);
1518 } else { 1550 } else {
1519 rfc1002mangle(ses_init_buf->trailer.session_req.calling_name, 1551 rfc1002mangle(ses_init_buf->trailer.session_req.calling_name,
1520 "LINUX_CIFS_CLNT",16); 1552 "LINUX_CIFS_CLNT", 16);
1521 } 1553 }
1522 ses_init_buf->trailer.session_req.scope1 = 0; 1554 ses_init_buf->trailer.session_req.scope1 = 0;
1523 ses_init_buf->trailer.session_req.scope2 = 0; 1555 ses_init_buf->trailer.session_req.scope2 = 0;
@@ -1527,20 +1559,20 @@ ipv4_connect(struct sockaddr_in *psin_server, struct socket **csocket,
1527 rc = smb_send(*csocket, smb_buf, 0x44, 1559 rc = smb_send(*csocket, smb_buf, 0x44,
1528 (struct sockaddr *)psin_server); 1560 (struct sockaddr *)psin_server);
1529 kfree(ses_init_buf); 1561 kfree(ses_init_buf);
1530 msleep(1); /* RFC1001 layer in at least one server 1562 msleep(1); /* RFC1001 layer in at least one server
1531 requires very short break before negprot 1563 requires very short break before negprot
1532 presumably because not expecting negprot 1564 presumably because not expecting negprot
1533 to follow so fast. This is a simple 1565 to follow so fast. This is a simple
1534 solution that works without 1566 solution that works without
1535 complicating the code and causes no 1567 complicating the code and causes no
1536 significant slowing down on mount 1568 significant slowing down on mount
1537 for everyone else */ 1569 for everyone else */
1538 } 1570 }
1539 /* else the negprot may still work without this 1571 /* else the negprot may still work without this
1540 even though malloc failed */ 1572 even though malloc failed */
1541 1573
1542 } 1574 }
1543 1575
1544 return rc; 1576 return rc;
1545} 1577}
1546 1578
@@ -1552,9 +1584,10 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
1552 __be16 orig_port = 0; 1584 __be16 orig_port = 0;
1553 1585
1554 if (*csocket == NULL) { 1586 if (*csocket == NULL) {
1555 rc = sock_create_kern(PF_INET6, SOCK_STREAM, IPPROTO_TCP, csocket); 1587 rc = sock_create_kern(PF_INET6, SOCK_STREAM,
1588 IPPROTO_TCP, csocket);
1556 if (rc < 0) { 1589 if (rc < 0) {
1557 cERROR(1, ("Error %d creating ipv6 socket",rc)); 1590 cERROR(1, ("Error %d creating ipv6 socket", rc));
1558 *csocket = NULL; 1591 *csocket = NULL;
1559 return rc; 1592 return rc;
1560 } else { 1593 } else {
@@ -1569,13 +1602,13 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
1569 if (psin_server->sin6_port) { /* user overrode default port */ 1602 if (psin_server->sin6_port) { /* user overrode default port */
1570 rc = (*csocket)->ops->connect(*csocket, 1603 rc = (*csocket)->ops->connect(*csocket,
1571 (struct sockaddr *) psin_server, 1604 (struct sockaddr *) psin_server,
1572 sizeof (struct sockaddr_in6),0); 1605 sizeof (struct sockaddr_in6), 0);
1573 if (rc >= 0) 1606 if (rc >= 0)
1574 connected = 1; 1607 connected = 1;
1575 } 1608 }
1576 1609
1577 if (!connected) { 1610 if (!connected) {
1578 /* save original port so we can retry user specified port 1611 /* save original port so we can retry user specified port
1579 later if fall back ports fail this time */ 1612 later if fall back ports fail this time */
1580 1613
1581 orig_port = psin_server->sin6_port; 1614 orig_port = psin_server->sin6_port;
@@ -1585,7 +1618,7 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
1585 1618
1586 rc = (*csocket)->ops->connect(*csocket, 1619 rc = (*csocket)->ops->connect(*csocket,
1587 (struct sockaddr *) psin_server, 1620 (struct sockaddr *) psin_server,
1588 sizeof (struct sockaddr_in6),0); 1621 sizeof (struct sockaddr_in6), 0);
1589 if (rc >= 0) 1622 if (rc >= 0)
1590 connected = 1; 1623 connected = 1;
1591 } 1624 }
@@ -1593,8 +1626,8 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
1593 if (!connected) { 1626 if (!connected) {
1594 psin_server->sin6_port = htons(RFC1001_PORT); 1627 psin_server->sin6_port = htons(RFC1001_PORT);
1595 rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *) 1628 rc = (*csocket)->ops->connect(*csocket, (struct sockaddr *)
1596 psin_server, sizeof (struct sockaddr_in6),0); 1629 psin_server, sizeof (struct sockaddr_in6), 0);
1597 if (rc >= 0) 1630 if (rc >= 0)
1598 connected = 1; 1631 connected = 1;
1599 } 1632 }
1600 1633
@@ -1603,21 +1636,21 @@ ipv6_connect(struct sockaddr_in6 *psin_server, struct socket **csocket)
1603 if (!connected) { 1636 if (!connected) {
1604 if (orig_port) 1637 if (orig_port)
1605 psin_server->sin6_port = orig_port; 1638 psin_server->sin6_port = orig_port;
1606 cFYI(1, ("Error %d connecting to server via ipv6",rc)); 1639 cFYI(1, ("Error %d connecting to server via ipv6", rc));
1607 sock_release(*csocket); 1640 sock_release(*csocket);
1608 *csocket = NULL; 1641 *csocket = NULL;
1609 return rc; 1642 return rc;
1610 } 1643 }
1611 /* Eventually check for other socket options to change from 1644 /* Eventually check for other socket options to change from
1612 the default. sock_setsockopt not used because it expects 1645 the default. sock_setsockopt not used because it expects
1613 user space buffer */ 1646 user space buffer */
1614 (*csocket)->sk->sk_rcvtimeo = 7 * HZ; 1647 (*csocket)->sk->sk_rcvtimeo = 7 * HZ;
1615 1648
1616 return rc; 1649 return rc;
1617} 1650}
1618 1651
1619void reset_cifs_unix_caps(int xid, struct cifsTconInfo * tcon, 1652void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
1620 struct super_block * sb, struct smb_vol * vol_info) 1653 struct super_block *sb, struct smb_vol *vol_info)
1621{ 1654{
1622 /* if we are reconnecting then should we check to see if 1655 /* if we are reconnecting then should we check to see if
1623 * any requested capabilities changed locally e.g. via 1656 * any requested capabilities changed locally e.g. via
@@ -1629,26 +1662,26 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo * tcon,
1629 * What if we wanted to mount the server share twice once with 1662 * What if we wanted to mount the server share twice once with
1630 * and once without posixacls or posix paths? */ 1663 * and once without posixacls or posix paths? */
1631 __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability); 1664 __u64 saved_cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
1632 1665
1633 1666
1634 if (!CIFSSMBQFSUnixInfo(xid, tcon)) { 1667 if (!CIFSSMBQFSUnixInfo(xid, tcon)) {
1635 __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability); 1668 __u64 cap = le64_to_cpu(tcon->fsUnixInfo.Capability);
1636 1669
1637 /* check for reconnect case in which we do not 1670 /* check for reconnect case in which we do not
1638 want to change the mount behavior if we can avoid it */ 1671 want to change the mount behavior if we can avoid it */
1639 if (vol_info == NULL) { 1672 if (vol_info == NULL) {
1640 /* turn off POSIX ACL and PATHNAMES if not set 1673 /* turn off POSIX ACL and PATHNAMES if not set
1641 originally at mount time */ 1674 originally at mount time */
1642 if ((saved_cap & CIFS_UNIX_POSIX_ACL_CAP) == 0) 1675 if ((saved_cap & CIFS_UNIX_POSIX_ACL_CAP) == 0)
1643 cap &= ~CIFS_UNIX_POSIX_ACL_CAP; 1676 cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
1644 if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) 1677 if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0)
1645 cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP; 1678 cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
1646
1647 1679
1648 1680
1649 1681
1682
1650 } 1683 }
1651 1684
1652 cap &= CIFS_UNIX_CAP_MASK; 1685 cap &= CIFS_UNIX_CAP_MASK;
1653 if (vol_info && vol_info->no_psx_acl) 1686 if (vol_info && vol_info->no_psx_acl)
1654 cap &= ~CIFS_UNIX_POSIX_ACL_CAP; 1687 cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
@@ -1663,13 +1696,13 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo * tcon,
1663 else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) { 1696 else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
1664 cFYI(1, ("negotiate posix pathnames")); 1697 cFYI(1, ("negotiate posix pathnames"));
1665 if (sb) 1698 if (sb)
1666 CIFS_SB(sb)->mnt_cifs_flags |= 1699 CIFS_SB(sb)->mnt_cifs_flags |=
1667 CIFS_MOUNT_POSIX_PATHS; 1700 CIFS_MOUNT_POSIX_PATHS;
1668 } 1701 }
1669 1702
1670 /* We might be setting the path sep back to a different 1703 /* We might be setting the path sep back to a different
1671 form if we are reconnecting and the server switched its 1704 form if we are reconnecting and the server switched its
1672 posix path capability for this share */ 1705 posix path capability for this share */
1673 if (sb && (CIFS_SB(sb)->prepathlen > 0)) 1706 if (sb && (CIFS_SB(sb)->prepathlen > 0))
1674 CIFS_SB(sb)->prepath[0] = CIFS_DIR_SEP(CIFS_SB(sb)); 1707 CIFS_SB(sb)->prepath[0] = CIFS_DIR_SEP(CIFS_SB(sb));
1675 1708
@@ -1681,9 +1714,9 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo * tcon,
1681#endif 1714#endif
1682 } 1715 }
1683 } 1716 }
1684 1717
1685 1718
1686 cFYI(1, ("Negotiate caps 0x%x",(int)cap)); 1719 cFYI(1, ("Negotiate caps 0x%x", (int)cap));
1687#ifdef CONFIG_CIFS_DEBUG2 1720#ifdef CONFIG_CIFS_DEBUG2
1688 if (cap & CIFS_UNIX_FCNTL_CAP) 1721 if (cap & CIFS_UNIX_FCNTL_CAP)
1689 cFYI(1, ("FCNTL cap")); 1722 cFYI(1, ("FCNTL cap"));
@@ -1725,8 +1758,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1725 xid = GetXid(); 1758 xid = GetXid();
1726 1759
1727/* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */ 1760/* cFYI(1, ("Entering cifs_mount. Xid: %d with: %s", xid, mount_data)); */
1728 1761
1729 memset(&volume_info,0,sizeof(struct smb_vol)); 1762 memset(&volume_info, 0, sizeof(struct smb_vol));
1730 if (cifs_parse_mount_options(mount_data, devname, &volume_info)) { 1763 if (cifs_parse_mount_options(mount_data, devname, &volume_info)) {
1731 kfree(volume_info.UNC); 1764 kfree(volume_info.UNC);
1732 kfree(volume_info.password); 1765 kfree(volume_info.password);
@@ -1743,8 +1776,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1743 cFYI(1, ("Username: %s", volume_info.username)); 1776 cFYI(1, ("Username: %s", volume_info.username));
1744 } else { 1777 } else {
1745 cifserror("No username specified"); 1778 cifserror("No username specified");
1746 /* In userspace mount helper we can get user name from alternate 1779 /* In userspace mount helper we can get user name from alternate
1747 locations such as env variables and files on disk */ 1780 locations such as env variables and files on disk */
1748 kfree(volume_info.UNC); 1781 kfree(volume_info.UNC);
1749 kfree(volume_info.password); 1782 kfree(volume_info.password);
1750 kfree(volume_info.prepath); 1783 kfree(volume_info.prepath);
@@ -1753,17 +1786,19 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1753 } 1786 }
1754 1787
1755 if (volume_info.UNCip && volume_info.UNC) { 1788 if (volume_info.UNCip && volume_info.UNC) {
1756 rc = cifs_inet_pton(AF_INET, volume_info.UNCip,&sin_server.sin_addr.s_addr); 1789 rc = cifs_inet_pton(AF_INET, volume_info.UNCip,
1790 &sin_server.sin_addr.s_addr);
1757 1791
1758 if (rc <= 0) { 1792 if (rc <= 0) {
1759 /* not ipv4 address, try ipv6 */ 1793 /* not ipv4 address, try ipv6 */
1760 rc = cifs_inet_pton(AF_INET6,volume_info.UNCip,&sin_server6.sin6_addr.in6_u); 1794 rc = cifs_inet_pton(AF_INET6, volume_info.UNCip,
1795 &sin_server6.sin6_addr.in6_u);
1761 if (rc > 0) 1796 if (rc > 0)
1762 address_type = AF_INET6; 1797 address_type = AF_INET6;
1763 } else { 1798 } else {
1764 address_type = AF_INET; 1799 address_type = AF_INET;
1765 } 1800 }
1766 1801
1767 if (rc <= 0) { 1802 if (rc <= 0) {
1768 /* we failed translating address */ 1803 /* we failed translating address */
1769 kfree(volume_info.UNC); 1804 kfree(volume_info.UNC);
@@ -1776,9 +1811,10 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1776 cFYI(1, ("UNC: %s ip: %s", volume_info.UNC, volume_info.UNCip)); 1811 cFYI(1, ("UNC: %s ip: %s", volume_info.UNC, volume_info.UNCip));
1777 /* success */ 1812 /* success */
1778 rc = 0; 1813 rc = 0;
1779 } else if (volume_info.UNCip){ 1814 } else if (volume_info.UNCip) {
1780 /* BB using ip addr as server name connect to the DFS root below */ 1815 /* BB using ip addr as server name to connect to the
1781 cERROR(1,("Connecting to DFS root not implemented yet")); 1816 DFS root below */
1817 cERROR(1, ("Connecting to DFS root not implemented yet"));
1782 kfree(volume_info.UNC); 1818 kfree(volume_info.UNC);
1783 kfree(volume_info.password); 1819 kfree(volume_info.password);
1784 kfree(volume_info.prepath); 1820 kfree(volume_info.prepath);
@@ -1786,7 +1822,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1786 return -EINVAL; 1822 return -EINVAL;
1787 } else /* which servers DFS root would we conect to */ { 1823 } else /* which servers DFS root would we conect to */ {
1788 cERROR(1, 1824 cERROR(1,
1789 ("CIFS mount error: No UNC path (e.g. -o unc=//192.168.1.100/public) specified")); 1825 ("CIFS mount error: No UNC path (e.g. -o "
1826 "unc=//192.168.1.100/public) specified"));
1790 kfree(volume_info.UNC); 1827 kfree(volume_info.UNC);
1791 kfree(volume_info.password); 1828 kfree(volume_info.password);
1792 kfree(volume_info.prepath); 1829 kfree(volume_info.prepath);
@@ -1801,7 +1838,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1801 } else { 1838 } else {
1802 cifs_sb->local_nls = load_nls(volume_info.iocharset); 1839 cifs_sb->local_nls = load_nls(volume_info.iocharset);
1803 if (cifs_sb->local_nls == NULL) { 1840 if (cifs_sb->local_nls == NULL) {
1804 cERROR(1,("CIFS mount error: iocharset %s not found",volume_info.iocharset)); 1841 cERROR(1, ("CIFS mount error: iocharset %s not found",
1842 volume_info.iocharset));
1805 kfree(volume_info.UNC); 1843 kfree(volume_info.UNC);
1806 kfree(volume_info.password); 1844 kfree(volume_info.password);
1807 kfree(volume_info.prepath); 1845 kfree(volume_info.prepath);
@@ -1827,9 +1865,8 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1827 return -EINVAL; 1865 return -EINVAL;
1828 } 1866 }
1829 1867
1830
1831 if (srvTcp) { 1868 if (srvTcp) {
1832 cFYI(1, ("Existing tcp session with server found")); 1869 cFYI(1, ("Existing tcp session with server found"));
1833 } else { /* create socket */ 1870 } else { /* create socket */
1834 if (volume_info.port) 1871 if (volume_info.port)
1835 sin_server.sin_port = htons(volume_info.port); 1872 sin_server.sin_port = htons(volume_info.port);
@@ -1839,14 +1876,14 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1839 cFYI(1, ("attempting ipv6 connect")); 1876 cFYI(1, ("attempting ipv6 connect"));
1840 /* BB should we allow ipv6 on port 139? */ 1877 /* BB should we allow ipv6 on port 139? */
1841 /* other OS never observed in Wild doing 139 with v6 */ 1878 /* other OS never observed in Wild doing 139 with v6 */
1842 rc = ipv6_connect(&sin_server6,&csocket); 1879 rc = ipv6_connect(&sin_server6, &csocket);
1843 } else 1880 } else
1844 rc = ipv4_connect(&sin_server,&csocket, 1881 rc = ipv4_connect(&sin_server, &csocket,
1845 volume_info.source_rfc1001_name, 1882 volume_info.source_rfc1001_name,
1846 volume_info.target_rfc1001_name); 1883 volume_info.target_rfc1001_name);
1847 if (rc < 0) { 1884 if (rc < 0) {
1848 cERROR(1, 1885 cERROR(1, ("Error connecting to IPv4 socket. "
1849 ("Error connecting to IPv4 socket. Aborting operation")); 1886 "Aborting operation"));
1850 if (csocket != NULL) 1887 if (csocket != NULL)
1851 sock_release(csocket); 1888 sock_release(csocket);
1852 kfree(volume_info.UNC); 1889 kfree(volume_info.UNC);
@@ -1867,8 +1904,9 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1867 return rc; 1904 return rc;
1868 } else { 1905 } else {
1869 memset(srvTcp, 0, sizeof (struct TCP_Server_Info)); 1906 memset(srvTcp, 0, sizeof (struct TCP_Server_Info));
1870 memcpy(&srvTcp->addr.sockAddr, &sin_server, sizeof (struct sockaddr_in)); 1907 memcpy(&srvTcp->addr.sockAddr, &sin_server,
1871 atomic_set(&srvTcp->inFlight,0); 1908 sizeof (struct sockaddr_in));
1909 atomic_set(&srvTcp->inFlight, 0);
1872 /* BB Add code for ipv6 case too */ 1910 /* BB Add code for ipv6 case too */
1873 srvTcp->ssocket = csocket; 1911 srvTcp->ssocket = csocket;
1874 srvTcp->protocolType = IPV4; 1912 srvTcp->protocolType = IPV4;
@@ -1883,7 +1921,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1883 srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd"); 1921 srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd");
1884 if ( IS_ERR(srvTcp->tsk) ) { 1922 if ( IS_ERR(srvTcp->tsk) ) {
1885 rc = PTR_ERR(srvTcp->tsk); 1923 rc = PTR_ERR(srvTcp->tsk);
1886 cERROR(1,("error %d create cifsd thread", rc)); 1924 cERROR(1, ("error %d create cifsd thread", rc));
1887 srvTcp->tsk = NULL; 1925 srvTcp->tsk = NULL;
1888 sock_release(csocket); 1926 sock_release(csocket);
1889 kfree(volume_info.UNC); 1927 kfree(volume_info.UNC);
@@ -1894,8 +1932,10 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1894 } 1932 }
1895 wait_for_completion(&cifsd_complete); 1933 wait_for_completion(&cifsd_complete);
1896 rc = 0; 1934 rc = 0;
1897 memcpy(srvTcp->workstation_RFC1001_name, volume_info.source_rfc1001_name,16); 1935 memcpy(srvTcp->workstation_RFC1001_name,
1898 memcpy(srvTcp->server_RFC1001_name, volume_info.target_rfc1001_name,16); 1936 volume_info.source_rfc1001_name, 16);
1937 memcpy(srvTcp->server_RFC1001_name,
1938 volume_info.target_rfc1001_name, 16);
1899 srvTcp->sequence_number = 0; 1939 srvTcp->sequence_number = 0;
1900 } 1940 }
1901 } 1941 }
@@ -1916,16 +1956,17 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1916 NIPQUAD(sin_server.sin_addr.s_addr)); 1956 NIPQUAD(sin_server.sin_addr.s_addr));
1917 } 1957 }
1918 1958
1919 if (!rc){ 1959 if (!rc) {
1920 /* volume_info.password freed at unmount */ 1960 /* volume_info.password freed at unmount */
1921 if (volume_info.password) 1961 if (volume_info.password)
1922 pSesInfo->password = volume_info.password; 1962 pSesInfo->password = volume_info.password;
1923 if (volume_info.username) 1963 if (volume_info.username)
1924 strncpy(pSesInfo->userName, 1964 strncpy(pSesInfo->userName,
1925 volume_info.username,MAX_USERNAME_SIZE); 1965 volume_info.username,
1966 MAX_USERNAME_SIZE);
1926 if (volume_info.domainname) { 1967 if (volume_info.domainname) {
1927 int len = strlen(volume_info.domainname); 1968 int len = strlen(volume_info.domainname);
1928 pSesInfo->domainName = 1969 pSesInfo->domainName =
1929 kmalloc(len + 1, GFP_KERNEL); 1970 kmalloc(len + 1, GFP_KERNEL);
1930 if (pSesInfo->domainName) 1971 if (pSesInfo->domainName)
1931 strcpy(pSesInfo->domainName, 1972 strcpy(pSesInfo->domainName,
@@ -1935,18 +1976,19 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1935 pSesInfo->overrideSecFlg = volume_info.secFlg; 1976 pSesInfo->overrideSecFlg = volume_info.secFlg;
1936 down(&pSesInfo->sesSem); 1977 down(&pSesInfo->sesSem);
1937 /* BB FIXME need to pass vol->secFlgs BB */ 1978 /* BB FIXME need to pass vol->secFlgs BB */
1938 rc = cifs_setup_session(xid,pSesInfo, cifs_sb->local_nls); 1979 rc = cifs_setup_session(xid, pSesInfo,
1980 cifs_sb->local_nls);
1939 up(&pSesInfo->sesSem); 1981 up(&pSesInfo->sesSem);
1940 if (!rc) 1982 if (!rc)
1941 atomic_inc(&srvTcp->socketUseCount); 1983 atomic_inc(&srvTcp->socketUseCount);
1942 } else 1984 } else
1943 kfree(volume_info.password); 1985 kfree(volume_info.password);
1944 } 1986 }
1945 1987
1946 /* search for existing tcon to this server share */ 1988 /* search for existing tcon to this server share */
1947 if (!rc) { 1989 if (!rc) {
1948 if (volume_info.rsize > CIFSMaxBufSize) { 1990 if (volume_info.rsize > CIFSMaxBufSize) {
1949 cERROR(1,("rsize %d too large, using MaxBufSize", 1991 cERROR(1, ("rsize %d too large, using MaxBufSize",
1950 volume_info.rsize)); 1992 volume_info.rsize));
1951 cifs_sb->rsize = CIFSMaxBufSize; 1993 cifs_sb->rsize = CIFSMaxBufSize;
1952 } else if ((volume_info.rsize) && 1994 } else if ((volume_info.rsize) &&
@@ -1956,24 +1998,24 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1956 cifs_sb->rsize = CIFSMaxBufSize; 1998 cifs_sb->rsize = CIFSMaxBufSize;
1957 1999
1958 if (volume_info.wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) { 2000 if (volume_info.wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
1959 cERROR(1,("wsize %d too large, using 4096 instead", 2001 cERROR(1, ("wsize %d too large, using 4096 instead",
1960 volume_info.wsize)); 2002 volume_info.wsize));
1961 cifs_sb->wsize = 4096; 2003 cifs_sb->wsize = 4096;
1962 } else if (volume_info.wsize) 2004 } else if (volume_info.wsize)
1963 cifs_sb->wsize = volume_info.wsize; 2005 cifs_sb->wsize = volume_info.wsize;
1964 else 2006 else
1965 cifs_sb->wsize = 2007 cifs_sb->wsize =
1966 min_t(const int, PAGEVEC_SIZE * PAGE_CACHE_SIZE, 2008 min_t(const int, PAGEVEC_SIZE * PAGE_CACHE_SIZE,
1967 127*1024); 2009 127*1024);
1968 /* old default of CIFSMaxBufSize was too small now 2010 /* old default of CIFSMaxBufSize was too small now
1969 that SMB Write2 can send multiple pages in kvec. 2011 that SMB Write2 can send multiple pages in kvec.
1970 RFC1001 does not describe what happens when frame 2012 RFC1001 does not describe what happens when frame
1971 bigger than 128K is sent so use that as max in 2013 bigger than 128K is sent so use that as max in
1972 conjunction with 52K kvec constraint on arch with 4K 2014 conjunction with 52K kvec constraint on arch with 4K
1973 page size */ 2015 page size */
1974 2016
1975 if (cifs_sb->rsize < 2048) { 2017 if (cifs_sb->rsize < 2048) {
1976 cifs_sb->rsize = 2048; 2018 cifs_sb->rsize = 2048;
1977 /* Windows ME may prefer this */ 2019 /* Windows ME may prefer this */
1978 cFYI(1, ("readsize set to minimum: 2048")); 2020 cFYI(1, ("readsize set to minimum: 2048"));
1979 } 2021 }
@@ -1983,7 +2025,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
1983 cifs_sb->prepathlen = strlen(cifs_sb->prepath); 2025 cifs_sb->prepathlen = strlen(cifs_sb->prepath);
1984 cifs_sb->prepath[0] = CIFS_DIR_SEP(cifs_sb); 2026 cifs_sb->prepath[0] = CIFS_DIR_SEP(cifs_sb);
1985 volume_info.prepath = NULL; 2027 volume_info.prepath = NULL;
1986 } else 2028 } else
1987 cifs_sb->prepathlen = 0; 2029 cifs_sb->prepathlen = 0;
1988 cifs_sb->mnt_uid = volume_info.linux_uid; 2030 cifs_sb->mnt_uid = volume_info.linux_uid;
1989 cifs_sb->mnt_gid = volume_info.linux_gid; 2031 cifs_sb->mnt_gid = volume_info.linux_gid;
@@ -2024,7 +2066,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2024 cFYI(1, ("Found match on UNC path")); 2066 cFYI(1, ("Found match on UNC path"));
2025 /* we can have only one retry value for a connection 2067 /* we can have only one retry value for a connection
2026 to a share so for resources mounted more than once 2068 to a share so for resources mounted more than once
2027 to the same server share the last value passed in 2069 to the same server share the last value passed in
2028 for the retry flag is used */ 2070 for the retry flag is used */
2029 tcon->retry = volume_info.retry; 2071 tcon->retry = volume_info.retry;
2030 tcon->nocase = volume_info.nocase; 2072 tcon->nocase = volume_info.nocase;
@@ -2033,17 +2075,17 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2033 if (tcon == NULL) 2075 if (tcon == NULL)
2034 rc = -ENOMEM; 2076 rc = -ENOMEM;
2035 else { 2077 else {
2036 /* check for null share name ie connecting to 2078 /* check for null share name ie connecting to
2037 * dfs root */ 2079 * dfs root */
2038 2080
2039 /* BB check if this works for exactly length 2081 /* BB check if this works for exactly length
2040 * three strings */ 2082 * three strings */
2041 if ((strchr(volume_info.UNC + 3, '\\') == NULL) 2083 if ((strchr(volume_info.UNC + 3, '\\') == NULL)
2042 && (strchr(volume_info.UNC + 3, '/') == 2084 && (strchr(volume_info.UNC + 3, '/') ==
2043 NULL)) { 2085 NULL)) {
2044 rc = connect_to_dfs_path(xid, pSesInfo, 2086 rc = connect_to_dfs_path(xid, pSesInfo,
2045 "", cifs_sb->local_nls, 2087 "", cifs_sb->local_nls,
2046 cifs_sb->mnt_cifs_flags & 2088 cifs_sb->mnt_cifs_flags &
2047 CIFS_MOUNT_MAP_SPECIAL_CHR); 2089 CIFS_MOUNT_MAP_SPECIAL_CHR);
2048 kfree(volume_info.UNC); 2090 kfree(volume_info.UNC);
2049 FreeXid(xid); 2091 FreeXid(xid);
@@ -2052,7 +2094,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2052 /* BB Do we need to wrap sesSem around 2094 /* BB Do we need to wrap sesSem around
2053 * this TCon call and Unix SetFS as 2095 * this TCon call and Unix SetFS as
2054 * we do on SessSetup and reconnect? */ 2096 * we do on SessSetup and reconnect? */
2055 rc = CIFSTCon(xid, pSesInfo, 2097 rc = CIFSTCon(xid, pSesInfo,
2056 volume_info.UNC, 2098 volume_info.UNC,
2057 tcon, cifs_sb->local_nls); 2099 tcon, cifs_sb->local_nls);
2058 cFYI(1, ("CIFS Tcon rc = %d", rc)); 2100 cFYI(1, ("CIFS Tcon rc = %d", rc));
@@ -2089,7 +2131,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2089 always wake up processes blocked in 2131 always wake up processes blocked in
2090 tcp in recv_mesg then we could remove the 2132 tcp in recv_mesg then we could remove the
2091 send_sig call */ 2133 send_sig call */
2092 force_sig(SIGKILL,srvTcp->tsk); 2134 force_sig(SIGKILL, srvTcp->tsk);
2093 tsk = srvTcp->tsk; 2135 tsk = srvTcp->tsk;
2094 if (tsk) 2136 if (tsk)
2095 kthread_stop(tsk); 2137 kthread_stop(tsk);
@@ -2100,13 +2142,13 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2100 tconInfoFree(tcon); 2142 tconInfoFree(tcon);
2101 if (existingCifsSes == NULL) { 2143 if (existingCifsSes == NULL) {
2102 if (pSesInfo) { 2144 if (pSesInfo) {
2103 if ((pSesInfo->server) && 2145 if ((pSesInfo->server) &&
2104 (pSesInfo->status == CifsGood)) { 2146 (pSesInfo->status == CifsGood)) {
2105 int temp_rc; 2147 int temp_rc;
2106 temp_rc = CIFSSMBLogoff(xid, pSesInfo); 2148 temp_rc = CIFSSMBLogoff(xid, pSesInfo);
2107 /* if the socketUseCount is now zero */ 2149 /* if the socketUseCount is now zero */
2108 if ((temp_rc == -ESHUTDOWN) && 2150 if ((temp_rc == -ESHUTDOWN) &&
2109 (pSesInfo->server) && 2151 (pSesInfo->server) &&
2110 (pSesInfo->server->tsk)) { 2152 (pSesInfo->server->tsk)) {
2111 struct task_struct *tsk; 2153 struct task_struct *tsk;
2112 force_sig(SIGKILL, 2154 force_sig(SIGKILL,
@@ -2129,7 +2171,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2129 /* do not care if following two calls succeed - informational */ 2171 /* do not care if following two calls succeed - informational */
2130 CIFSSMBQFSDeviceInfo(xid, tcon); 2172 CIFSSMBQFSDeviceInfo(xid, tcon);
2131 CIFSSMBQFSAttributeInfo(xid, tcon); 2173 CIFSSMBQFSAttributeInfo(xid, tcon);
2132 2174
2133 /* tell server which Unix caps we support */ 2175 /* tell server which Unix caps we support */
2134 if (tcon->ses->capabilities & CAP_UNIX) 2176 if (tcon->ses->capabilities & CAP_UNIX)
2135 reset_cifs_unix_caps(xid, tcon, sb, &volume_info); 2177 reset_cifs_unix_caps(xid, tcon, sb, &volume_info);
@@ -2138,16 +2180,16 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
2138#ifdef CONFIG_CIFS_DEBUG2 2180#ifdef CONFIG_CIFS_DEBUG2
2139 cFYI(1, ("no very large read support, rsize 127K")); 2181 cFYI(1, ("no very large read support, rsize 127K"));
2140#endif 2182#endif
2141 2183
2142 } 2184 }
2143 if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X)) 2185 if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
2144 cifs_sb->wsize = min(cifs_sb->wsize, 2186 cifs_sb->wsize = min(cifs_sb->wsize,
2145 (tcon->ses->server->maxBuf - 2187 (tcon->ses->server->maxBuf -
2146 MAX_CIFS_HDR_SIZE)); 2188 MAX_CIFS_HDR_SIZE));
2147 if (!(tcon->ses->capabilities & CAP_LARGE_READ_X)) 2189 if (!(tcon->ses->capabilities & CAP_LARGE_READ_X))
2148 cifs_sb->rsize = min(cifs_sb->rsize, 2190 cifs_sb->rsize = min(cifs_sb->rsize,
2149 (tcon->ses->server->maxBuf - 2191 (tcon->ses->server->maxBuf -
2150 MAX_CIFS_HDR_SIZE)); 2192 MAX_CIFS_HDR_SIZE));
2151 } 2193 }
2152 2194
2153 /* volume_info.password is freed above when existing session found 2195 /* volume_info.password is freed above when existing session found
@@ -2200,7 +2242,8 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2200 pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->server->maxBuf); 2242 pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
2201 pSMB->req_no_secext.MaxMpxCount = cpu_to_le16(ses->server->maxReq); 2243 pSMB->req_no_secext.MaxMpxCount = cpu_to_le16(ses->server->maxReq);
2202 2244
2203 if (ses->server->secMode & (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) 2245 if (ses->server->secMode &
2246 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
2204 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; 2247 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
2205 2248
2206 capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | 2249 capabilities = CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS |
@@ -2219,7 +2262,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2219 } 2262 }
2220 pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities); 2263 pSMB->req_no_secext.Capabilities = cpu_to_le32(capabilities);
2221 2264
2222 pSMB->req_no_secext.CaseInsensitivePasswordLength = 2265 pSMB->req_no_secext.CaseInsensitivePasswordLength =
2223 cpu_to_le16(CIFS_SESS_KEY_SIZE); 2266 cpu_to_le16(CIFS_SESS_KEY_SIZE);
2224 2267
2225 pSMB->req_no_secext.CaseSensitivePasswordLength = 2268 pSMB->req_no_secext.CaseSensitivePasswordLength =
@@ -2237,9 +2280,9 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2237 } 2280 }
2238 if (user == NULL) 2281 if (user == NULL)
2239 bytes_returned = 0; /* skip null user */ 2282 bytes_returned = 0; /* skip null user */
2240 else 2283 else
2241 bytes_returned = 2284 bytes_returned =
2242 cifs_strtoUCS((__le16 *) bcc_ptr, user, 100, 2285 cifs_strtoUCS((__le16 *) bcc_ptr, user, 100,
2243 nls_codepage); 2286 nls_codepage);
2244 /* convert number of 16 bit words to bytes */ 2287 /* convert number of 16 bit words to bytes */
2245 bcc_ptr += 2 * bytes_returned; 2288 bcc_ptr += 2 * bytes_returned;
@@ -2269,7 +2312,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2269 bcc_ptr += 2 * bytes_returned; 2312 bcc_ptr += 2 * bytes_returned;
2270 bcc_ptr += 2; 2313 bcc_ptr += 2;
2271 } else { 2314 } else {
2272 if (user != NULL) { 2315 if (user != NULL) {
2273 strncpy(bcc_ptr, user, 200); 2316 strncpy(bcc_ptr, user, 200);
2274 bcc_ptr += strnlen(user, 200); 2317 bcc_ptr += strnlen(user, 200);
2275 } 2318 }
@@ -2304,11 +2347,12 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2304 __u16 action = le16_to_cpu(pSMBr->resp.Action); 2347 __u16 action = le16_to_cpu(pSMBr->resp.Action);
2305 __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength); 2348 __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength);
2306 if (action & GUEST_LOGIN) 2349 if (action & GUEST_LOGIN)
2307 cFYI(1, (" Guest login")); /* do we want to mark SesInfo struct ? */ 2350 cFYI(1, (" Guest login")); /* BB mark SesInfo struct? */
2308 ses->Suid = smb_buffer_response->Uid; /* UID left in wire format (le) */ 2351 ses->Suid = smb_buffer_response->Uid; /* UID left in wire format
2352 (little endian) */
2309 cFYI(1, ("UID = %d ", ses->Suid)); 2353 cFYI(1, ("UID = %d ", ses->Suid));
2310 /* response can have either 3 or 4 word count - Samba sends 3 */ 2354 /* response can have either 3 or 4 word count - Samba sends 3 */
2311 bcc_ptr = pByteArea(smb_buffer_response); 2355 bcc_ptr = pByteArea(smb_buffer_response);
2312 if ((pSMBr->resp.hdr.WordCount == 3) 2356 if ((pSMBr->resp.hdr.WordCount == 3)
2313 || ((pSMBr->resp.hdr.WordCount == 4) 2357 || ((pSMBr->resp.hdr.WordCount == 4)
2314 && (blob_len < pSMBr->resp.ByteCount))) { 2358 && (blob_len < pSMBr->resp.ByteCount))) {
@@ -2318,8 +2362,10 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2318 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { 2362 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
2319 if ((long) (bcc_ptr) % 2) { 2363 if ((long) (bcc_ptr) % 2) {
2320 remaining_words = 2364 remaining_words =
2321 (BCC(smb_buffer_response) - 1) /2; 2365 (BCC(smb_buffer_response) - 1) / 2;
2322 bcc_ptr++; /* Unicode strings must be word aligned */ 2366 /* Unicode strings must be word
2367 aligned */
2368 bcc_ptr++;
2323 } else { 2369 } else {
2324 remaining_words = 2370 remaining_words =
2325 BCC(smb_buffer_response) / 2; 2371 BCC(smb_buffer_response) / 2;
@@ -2332,11 +2378,13 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2332 terminating last Unicode string in response */ 2378 terminating last Unicode string in response */
2333 if (ses->serverOS) 2379 if (ses->serverOS)
2334 kfree(ses->serverOS); 2380 kfree(ses->serverOS);
2335 ses->serverOS = kzalloc(2 * (len + 1), GFP_KERNEL); 2381 ses->serverOS = kzalloc(2 * (len + 1),
2382 GFP_KERNEL);
2336 if (ses->serverOS == NULL) 2383 if (ses->serverOS == NULL)
2337 goto sesssetup_nomem; 2384 goto sesssetup_nomem;
2338 cifs_strfromUCS_le(ses->serverOS, 2385 cifs_strfromUCS_le(ses->serverOS,
2339 (__le16 *)bcc_ptr, len,nls_codepage); 2386 (__le16 *)bcc_ptr,
2387 len, nls_codepage);
2340 bcc_ptr += 2 * (len + 1); 2388 bcc_ptr += 2 * (len + 1);
2341 remaining_words -= len + 1; 2389 remaining_words -= len + 1;
2342 ses->serverOS[2 * len] = 0; 2390 ses->serverOS[2 * len] = 0;
@@ -2345,42 +2393,49 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2345 len = UniStrnlen((wchar_t *)bcc_ptr, 2393 len = UniStrnlen((wchar_t *)bcc_ptr,
2346 remaining_words-1); 2394 remaining_words-1);
2347 kfree(ses->serverNOS); 2395 kfree(ses->serverNOS);
2348 ses->serverNOS = kzalloc(2 * (len + 1),GFP_KERNEL); 2396 ses->serverNOS = kzalloc(2 * (len + 1),
2397 GFP_KERNEL);
2349 if (ses->serverNOS == NULL) 2398 if (ses->serverNOS == NULL)
2350 goto sesssetup_nomem; 2399 goto sesssetup_nomem;
2351 cifs_strfromUCS_le(ses->serverNOS, 2400 cifs_strfromUCS_le(ses->serverNOS,
2352 (__le16 *)bcc_ptr,len,nls_codepage); 2401 (__le16 *)bcc_ptr,
2402 len, nls_codepage);
2353 bcc_ptr += 2 * (len + 1); 2403 bcc_ptr += 2 * (len + 1);
2354 ses->serverNOS[2 * len] = 0; 2404 ses->serverNOS[2 * len] = 0;
2355 ses->serverNOS[1 + (2 * len)] = 0; 2405 ses->serverNOS[1 + (2 * len)] = 0;
2356 if (strncmp(ses->serverNOS, 2406 if (strncmp(ses->serverNOS,
2357 "NT LAN Manager 4",16) == 0) { 2407 "NT LAN Manager 4", 16) == 0) {
2358 cFYI(1, ("NT4 server")); 2408 cFYI(1, ("NT4 server"));
2359 ses->flags |= CIFS_SES_NT4; 2409 ses->flags |= CIFS_SES_NT4;
2360 } 2410 }
2361 remaining_words -= len + 1; 2411 remaining_words -= len + 1;
2362 if (remaining_words > 0) { 2412 if (remaining_words > 0) {
2363 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); 2413 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
2364 /* last string is not always null terminated (for e.g. for Windows XP & 2000) */ 2414 /* last string is not always null terminated
2415 (for e.g. for Windows XP & 2000) */
2365 if (ses->serverDomain) 2416 if (ses->serverDomain)
2366 kfree(ses->serverDomain); 2417 kfree(ses->serverDomain);
2367 ses->serverDomain = 2418 ses->serverDomain =
2368 kzalloc(2*(len+1),GFP_KERNEL); 2419 kzalloc(2*(len+1),
2420 GFP_KERNEL);
2369 if (ses->serverDomain == NULL) 2421 if (ses->serverDomain == NULL)
2370 goto sesssetup_nomem; 2422 goto sesssetup_nomem;
2371 cifs_strfromUCS_le(ses->serverDomain, 2423 cifs_strfromUCS_le(ses->serverDomain,
2372 (__le16 *)bcc_ptr,len,nls_codepage); 2424 (__le16 *)bcc_ptr,
2425 len, nls_codepage);
2373 bcc_ptr += 2 * (len + 1); 2426 bcc_ptr += 2 * (len + 1);
2374 ses->serverDomain[2*len] = 0; 2427 ses->serverDomain[2*len] = 0;
2375 ses->serverDomain[1+(2*len)] = 0; 2428 ses->serverDomain[1+(2*len)] = 0;
2376 } /* else no more room so create dummy domain string */ 2429 } else { /* else no more room so create
2377 else { 2430 dummy domain string */
2378 if (ses->serverDomain) 2431 if (ses->serverDomain)
2379 kfree(ses->serverDomain); 2432 kfree(ses->serverDomain);
2380 ses->serverDomain = 2433 ses->serverDomain =
2381 kzalloc(2, GFP_KERNEL); 2434 kzalloc(2, GFP_KERNEL);
2382 } 2435 }
2383 } else { /* no room so create dummy domain and NOS string */ 2436 } else { /* no room so create dummy domain
2437 and NOS string */
2438
2384 /* if these kcallocs fail not much we 2439 /* if these kcallocs fail not much we
2385 can do, but better to not fail the 2440 can do, but better to not fail the
2386 sesssetup itself */ 2441 sesssetup itself */
@@ -2397,18 +2452,21 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2397 pByteArea(smb_buffer_response) 2452 pByteArea(smb_buffer_response)
2398 <= BCC(smb_buffer_response)) { 2453 <= BCC(smb_buffer_response)) {
2399 kfree(ses->serverOS); 2454 kfree(ses->serverOS);
2400 ses->serverOS = kzalloc(len + 1,GFP_KERNEL); 2455 ses->serverOS = kzalloc(len + 1,
2456 GFP_KERNEL);
2401 if (ses->serverOS == NULL) 2457 if (ses->serverOS == NULL)
2402 goto sesssetup_nomem; 2458 goto sesssetup_nomem;
2403 strncpy(ses->serverOS,bcc_ptr, len); 2459 strncpy(ses->serverOS, bcc_ptr, len);
2404 2460
2405 bcc_ptr += len; 2461 bcc_ptr += len;
2406 bcc_ptr[0] = 0; /* null terminate the string */ 2462 /* null terminate the string */
2463 bcc_ptr[0] = 0;
2407 bcc_ptr++; 2464 bcc_ptr++;
2408 2465
2409 len = strnlen(bcc_ptr, 1024); 2466 len = strnlen(bcc_ptr, 1024);
2410 kfree(ses->serverNOS); 2467 kfree(ses->serverNOS);
2411 ses->serverNOS = kzalloc(len + 1,GFP_KERNEL); 2468 ses->serverNOS = kzalloc(len + 1,
2469 GFP_KERNEL);
2412 if (ses->serverNOS == NULL) 2470 if (ses->serverNOS == NULL)
2413 goto sesssetup_nomem; 2471 goto sesssetup_nomem;
2414 strncpy(ses->serverNOS, bcc_ptr, len); 2472 strncpy(ses->serverNOS, bcc_ptr, len);
@@ -2419,21 +2477,25 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2419 len = strnlen(bcc_ptr, 1024); 2477 len = strnlen(bcc_ptr, 1024);
2420 if (ses->serverDomain) 2478 if (ses->serverDomain)
2421 kfree(ses->serverDomain); 2479 kfree(ses->serverDomain);
2422 ses->serverDomain = kzalloc(len + 1,GFP_KERNEL); 2480 ses->serverDomain = kzalloc(len + 1,
2481 GFP_KERNEL);
2423 if (ses->serverDomain == NULL) 2482 if (ses->serverDomain == NULL)
2424 goto sesssetup_nomem; 2483 goto sesssetup_nomem;
2425 strncpy(ses->serverDomain, bcc_ptr, len); 2484 strncpy(ses->serverDomain, bcc_ptr,
2485 len);
2426 bcc_ptr += len; 2486 bcc_ptr += len;
2427 bcc_ptr[0] = 0; 2487 bcc_ptr[0] = 0;
2428 bcc_ptr++; 2488 bcc_ptr++;
2429 } else 2489 } else
2430 cFYI(1, 2490 cFYI(1,
2431 ("Variable field of length %d extends beyond end of smb ", 2491 ("Variable field of length %d "
2492 "extends beyond end of smb ",
2432 len)); 2493 len));
2433 } 2494 }
2434 } else { 2495 } else {
2435 cERROR(1, 2496 cERROR(1,
2436 (" Security Blob Length extends beyond end of SMB")); 2497 (" Security Blob Length extends beyond "
2498 "end of SMB"));
2437 } 2499 }
2438 } else { 2500 } else {
2439 cERROR(1, 2501 cERROR(1,
@@ -2452,7 +2514,7 @@ sesssetup_nomem: /* do not return an error on nomem for the info strings,
2452 2514
2453static int 2515static int
2454CIFSNTLMSSPNegotiateSessSetup(unsigned int xid, 2516CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2455 struct cifsSesInfo *ses, int * pNTLMv2_flag, 2517 struct cifsSesInfo *ses, int *pNTLMv2_flag,
2456 const struct nls_table *nls_codepage) 2518 const struct nls_table *nls_codepage)
2457{ 2519{
2458 struct smb_hdr *smb_buffer; 2520 struct smb_hdr *smb_buffer;
@@ -2596,11 +2658,11 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2596 __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength); 2658 __u16 blob_len = le16_to_cpu(pSMBr->resp.SecurityBlobLength);
2597 2659
2598 if (action & GUEST_LOGIN) 2660 if (action & GUEST_LOGIN)
2599 cFYI(1, (" Guest login")); 2661 cFYI(1, (" Guest login"));
2600 /* Do we want to set anything in SesInfo struct when guest login? */ 2662 /* Do we want to set anything in SesInfo struct when guest login? */
2601 2663
2602 bcc_ptr = pByteArea(smb_buffer_response); 2664 bcc_ptr = pByteArea(smb_buffer_response);
2603 /* response can have either 3 or 4 word count - Samba sends 3 */ 2665 /* response can have either 3 or 4 word count - Samba sends 3 */
2604 2666
2605 SecurityBlob2 = (PCHALLENGE_MESSAGE) bcc_ptr; 2667 SecurityBlob2 = (PCHALLENGE_MESSAGE) bcc_ptr;
2606 if (SecurityBlob2->MessageType != NtLmChallenge) { 2668 if (SecurityBlob2->MessageType != NtLmChallenge) {
@@ -2608,7 +2670,7 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2608 ("Unexpected NTLMSSP message type received %d", 2670 ("Unexpected NTLMSSP message type received %d",
2609 SecurityBlob2->MessageType)); 2671 SecurityBlob2->MessageType));
2610 } else if (ses) { 2672 } else if (ses) {
2611 ses->Suid = smb_buffer_response->Uid; /* UID left in le format */ 2673 ses->Suid = smb_buffer_response->Uid; /* UID left in le format */
2612 cFYI(1, ("UID = %d", ses->Suid)); 2674 cFYI(1, ("UID = %d", ses->Suid));
2613 if ((pSMBr->resp.hdr.WordCount == 3) 2675 if ((pSMBr->resp.hdr.WordCount == 3)
2614 || ((pSMBr->resp.hdr.WordCount == 4) 2676 || ((pSMBr->resp.hdr.WordCount == 4)
@@ -2626,18 +2688,18 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2626 memcpy(ses->server->cryptKey, 2688 memcpy(ses->server->cryptKey,
2627 SecurityBlob2->Challenge, 2689 SecurityBlob2->Challenge,
2628 CIFS_CRYPTO_KEY_SIZE); 2690 CIFS_CRYPTO_KEY_SIZE);
2629 if (SecurityBlob2->NegotiateFlags & 2691 if (SecurityBlob2->NegotiateFlags &
2630 cpu_to_le32(NTLMSSP_NEGOTIATE_NTLMV2)) 2692 cpu_to_le32(NTLMSSP_NEGOTIATE_NTLMV2))
2631 *pNTLMv2_flag = TRUE; 2693 *pNTLMv2_flag = TRUE;
2632 2694
2633 if ((SecurityBlob2->NegotiateFlags & 2695 if ((SecurityBlob2->NegotiateFlags &
2634 cpu_to_le32(NTLMSSP_NEGOTIATE_ALWAYS_SIGN)) 2696 cpu_to_le32(NTLMSSP_NEGOTIATE_ALWAYS_SIGN))
2635 || (sign_CIFS_PDUs > 1)) 2697 || (sign_CIFS_PDUs > 1))
2636 ses->server->secMode |= 2698 ses->server->secMode |=
2637 SECMODE_SIGN_REQUIRED; 2699 SECMODE_SIGN_REQUIRED;
2638 if ((SecurityBlob2->NegotiateFlags & 2700 if ((SecurityBlob2->NegotiateFlags &
2639 cpu_to_le32(NTLMSSP_NEGOTIATE_SIGN)) && (sign_CIFS_PDUs)) 2701 cpu_to_le32(NTLMSSP_NEGOTIATE_SIGN)) && (sign_CIFS_PDUs))
2640 ses->server->secMode |= 2702 ses->server->secMode |=
2641 SECMODE_SIGN_ENABLED; 2703 SECMODE_SIGN_ENABLED;
2642 2704
2643 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { 2705 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
@@ -2645,7 +2707,8 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2645 remaining_words = 2707 remaining_words =
2646 (BCC(smb_buffer_response) 2708 (BCC(smb_buffer_response)
2647 - 1) / 2; 2709 - 1) / 2;
2648 bcc_ptr++; /* Unicode strings must be word aligned */ 2710 /* Must word align unicode strings */
2711 bcc_ptr++;
2649 } else { 2712 } else {
2650 remaining_words = 2713 remaining_words =
2651 BCC 2714 BCC
@@ -2690,8 +2753,9 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2690 (2 * len)] = 0; 2753 (2 * len)] = 0;
2691 remaining_words -= len + 1; 2754 remaining_words -= len + 1;
2692 if (remaining_words > 0) { 2755 if (remaining_words > 0) {
2693 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); 2756 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
2694 /* last string is not always null terminated (for e.g. for Windows XP & 2000) */ 2757 /* last string not always null terminated
2758 (for e.g. for Windows XP & 2000) */
2695 kfree(ses->serverDomain); 2759 kfree(ses->serverDomain);
2696 ses->serverDomain = 2760 ses->serverDomain =
2697 kzalloc(2 * 2761 kzalloc(2 *
@@ -2756,7 +2820,8 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2756 ses->serverDomain = 2820 ses->serverDomain =
2757 kzalloc(len + 1, 2821 kzalloc(len + 1,
2758 GFP_KERNEL); 2822 GFP_KERNEL);
2759 strncpy(ses->serverDomain, bcc_ptr, len); 2823 strncpy(ses->serverDomain,
2824 bcc_ptr, len);
2760 bcc_ptr += len; 2825 bcc_ptr += len;
2761 bcc_ptr[0] = 0; 2826 bcc_ptr[0] = 0;
2762 bcc_ptr++; 2827 bcc_ptr++;
@@ -2766,8 +2831,8 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
2766 len)); 2831 len));
2767 } 2832 }
2768 } else { 2833 } else {
2769 cERROR(1, 2834 cERROR(1, ("Security Blob Length extends beyond"
2770 (" Security Blob Length extends beyond end of SMB")); 2835 " end of SMB"));
2771 } 2836 }
2772 } else { 2837 } else {
2773 cERROR(1, ("No session structure passed in.")); 2838 cERROR(1, ("No session structure passed in."));
@@ -2855,7 +2920,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
2855 strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8); 2920 strncpy(SecurityBlob->Signature, NTLMSSP_SIGNATURE, 8);
2856 SecurityBlob->MessageType = NtLmAuthenticate; 2921 SecurityBlob->MessageType = NtLmAuthenticate;
2857 bcc_ptr += SecurityBlobLength; 2922 bcc_ptr += SecurityBlobLength;
2858 negotiate_flags = 2923 negotiate_flags =
2859 NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET | 2924 NTLMSSP_NEGOTIATE_UNICODE | NTLMSSP_REQUEST_TARGET |
2860 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO | 2925 NTLMSSP_NEGOTIATE_NTLM | NTLMSSP_NEGOTIATE_TARGET_INFO |
2861 0x80000000 | NTLMSSP_NEGOTIATE_128; 2926 0x80000000 | NTLMSSP_NEGOTIATE_128;
@@ -3017,17 +3082,20 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
3017 __u16 blob_len = 3082 __u16 blob_len =
3018 le16_to_cpu(pSMBr->resp.SecurityBlobLength); 3083 le16_to_cpu(pSMBr->resp.SecurityBlobLength);
3019 if (action & GUEST_LOGIN) 3084 if (action & GUEST_LOGIN)
3020 cFYI(1, (" Guest login")); /* BB do we want to set anything in SesInfo struct ? */ 3085 cFYI(1, (" Guest login")); /* BB Should we set anything
3021/* if (SecurityBlob2->MessageType != NtLm??){ 3086 in SesInfo struct ? */
3022 cFYI("Unexpected message type on auth response is %d ")); 3087/* if (SecurityBlob2->MessageType != NtLm??) {
3023 } */ 3088 cFYI("Unexpected message type on auth response is %d"));
3089 } */
3090
3024 if (ses) { 3091 if (ses) {
3025 cFYI(1, 3092 cFYI(1,
3026 ("Does UID on challenge %d match auth response UID %d ", 3093 ("Check challenge UID %d vs auth response UID %d",
3027 ses->Suid, smb_buffer_response->Uid)); 3094 ses->Suid, smb_buffer_response->Uid));
3028 ses->Suid = smb_buffer_response->Uid; /* UID left in wire format */ 3095 /* UID left in wire format */
3029 bcc_ptr = pByteArea(smb_buffer_response); 3096 ses->Suid = smb_buffer_response->Uid;
3030 /* response can have either 3 or 4 word count - Samba sends 3 */ 3097 bcc_ptr = pByteArea(smb_buffer_response);
3098 /* response can have either 3 or 4 word count - Samba sends 3 */
3031 if ((pSMBr->resp.hdr.WordCount == 3) 3099 if ((pSMBr->resp.hdr.WordCount == 3)
3032 || ((pSMBr->resp.hdr.WordCount == 4) 3100 || ((pSMBr->resp.hdr.WordCount == 4)
3033 && (blob_len < 3101 && (blob_len <
@@ -3089,7 +3157,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
3089 ses->serverNOS[1+(2*len)] = 0; 3157 ses->serverNOS[1+(2*len)] = 0;
3090 remaining_words -= len + 1; 3158 remaining_words -= len + 1;
3091 if (remaining_words > 0) { 3159 if (remaining_words > 0) {
3092 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words); 3160 len = UniStrnlen((wchar_t *) bcc_ptr, remaining_words);
3093 /* last string not always null terminated (e.g. for Windows XP & 2000) */ 3161 /* last string not always null terminated (e.g. for Windows XP & 2000) */
3094 if (ses->serverDomain) 3162 if (ses->serverDomain)
3095 kfree(ses->serverDomain); 3163 kfree(ses->serverDomain);
@@ -3132,8 +3200,8 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
3132 } 3200 }
3133 } else { /* ASCII */ 3201 } else { /* ASCII */
3134 len = strnlen(bcc_ptr, 1024); 3202 len = strnlen(bcc_ptr, 1024);
3135 if (((long) bcc_ptr + len) - 3203 if (((long) bcc_ptr + len) -
3136 (long) pByteArea(smb_buffer_response) 3204 (long) pByteArea(smb_buffer_response)
3137 <= BCC(smb_buffer_response)) { 3205 <= BCC(smb_buffer_response)) {
3138 if (ses->serverOS) 3206 if (ses->serverOS)
3139 kfree(ses->serverOS); 3207 kfree(ses->serverOS);
@@ -3146,8 +3214,9 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
3146 3214
3147 len = strnlen(bcc_ptr, 1024); 3215 len = strnlen(bcc_ptr, 1024);
3148 kfree(ses->serverNOS); 3216 kfree(ses->serverNOS);
3149 ses->serverNOS = kzalloc(len+1,GFP_KERNEL); 3217 ses->serverNOS = kzalloc(len+1,
3150 strncpy(ses->serverNOS, bcc_ptr, len); 3218 GFP_KERNEL);
3219 strncpy(ses->serverNOS, bcc_ptr, len);
3151 bcc_ptr += len; 3220 bcc_ptr += len;
3152 bcc_ptr[0] = 0; 3221 bcc_ptr[0] = 0;
3153 bcc_ptr++; 3222 bcc_ptr++;
@@ -3233,7 +3302,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3233 by Samba (not sure whether other servers allow 3302 by Samba (not sure whether other servers allow
3234 NTLMv2 password here) */ 3303 NTLMv2 password here) */
3235#ifdef CONFIG_CIFS_WEAK_PW_HASH 3304#ifdef CONFIG_CIFS_WEAK_PW_HASH
3236 if ((extended_security & CIFSSEC_MAY_LANMAN) && 3305 if ((extended_security & CIFSSEC_MAY_LANMAN) &&
3237 (ses->server->secType == LANMAN)) 3306 (ses->server->secType == LANMAN))
3238 calc_lanman_hash(ses, bcc_ptr); 3307 calc_lanman_hash(ses, bcc_ptr);
3239 else 3308 else
@@ -3250,7 +3319,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3250 } 3319 }
3251 } 3320 }
3252 3321
3253 if (ses->server->secMode & 3322 if (ses->server->secMode &
3254 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) 3323 (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED))
3255 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE; 3324 smb_buffer->Flags2 |= SMBFLG2_SECURITY_SIGNATURE;
3256 3325
@@ -3263,8 +3332,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3263 if (ses->capabilities & CAP_UNICODE) { 3332 if (ses->capabilities & CAP_UNICODE) {
3264 smb_buffer->Flags2 |= SMBFLG2_UNICODE; 3333 smb_buffer->Flags2 |= SMBFLG2_UNICODE;
3265 length = 3334 length =
3266 cifs_strtoUCS((__le16 *) bcc_ptr, tree, 3335 cifs_strtoUCS((__le16 *) bcc_ptr, tree,
3267 6 /* max utf8 char length in bytes */ * 3336 6 /* max utf8 char length in bytes */ *
3268 (/* server len*/ + 256 /* share len */), nls_codepage); 3337 (/* server len*/ + 256 /* share len */), nls_codepage);
3269 bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */ 3338 bcc_ptr += 2 * length; /* convert num 16 bit words to bytes */
3270 bcc_ptr += 2; /* skip trailing null */ 3339 bcc_ptr += 2; /* skip trailing null */
@@ -3288,8 +3357,8 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3288 tcon->tid = smb_buffer_response->Tid; 3357 tcon->tid = smb_buffer_response->Tid;
3289 bcc_ptr = pByteArea(smb_buffer_response); 3358 bcc_ptr = pByteArea(smb_buffer_response);
3290 length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2); 3359 length = strnlen(bcc_ptr, BCC(smb_buffer_response) - 2);
3291 /* skip service field (NB: this field is always ASCII) */ 3360 /* skip service field (NB: this field is always ASCII) */
3292 bcc_ptr += length + 1; 3361 bcc_ptr += length + 1;
3293 strncpy(tcon->treeName, tree, MAX_TREE_SIZE); 3362 strncpy(tcon->treeName, tree, MAX_TREE_SIZE);
3294 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) { 3363 if (smb_buffer->Flags2 & SMBFLG2_UNICODE) {
3295 length = UniStrnlen((wchar_t *) bcc_ptr, 512); 3364 length = UniStrnlen((wchar_t *) bcc_ptr, 512);
@@ -3307,7 +3376,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3307 bcc_ptr[1] = 0; 3376 bcc_ptr[1] = 0;
3308 bcc_ptr += 2; 3377 bcc_ptr += 2;
3309 } 3378 }
3310 /* else do not bother copying these informational fields */ 3379 /* else do not bother copying these information fields*/
3311 } else { 3380 } else {
3312 length = strnlen(bcc_ptr, 1024); 3381 length = strnlen(bcc_ptr, 1024);
3313 if ((bcc_ptr + length) - 3382 if ((bcc_ptr + length) -
@@ -3319,7 +3388,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3319 strncpy(tcon->nativeFileSystem, bcc_ptr, 3388 strncpy(tcon->nativeFileSystem, bcc_ptr,
3320 length); 3389 length);
3321 } 3390 }
3322 /* else do not bother copying these informational fields */ 3391 /* else do not bother copying these information fields*/
3323 } 3392 }
3324 if ((smb_buffer_response->WordCount == 3) || 3393 if ((smb_buffer_response->WordCount == 3) ||
3325 (smb_buffer_response->WordCount == 7)) 3394 (smb_buffer_response->WordCount == 7))
@@ -3329,7 +3398,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3329 tcon->Flags = 0; 3398 tcon->Flags = 0;
3330 cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags)); 3399 cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags));
3331 } else if ((rc == 0) && tcon == NULL) { 3400 } else if ((rc == 0) && tcon == NULL) {
3332 /* all we need to save for IPC$ connection */ 3401 /* all we need to save for IPC$ connection */
3333 ses->ipc_tid = smb_buffer_response->Tid; 3402 ses->ipc_tid = smb_buffer_response->Tid;
3334 } 3403 }
3335 3404
@@ -3345,7 +3414,7 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3345 int xid; 3414 int xid;
3346 struct cifsSesInfo *ses = NULL; 3415 struct cifsSesInfo *ses = NULL;
3347 struct task_struct *cifsd_task; 3416 struct task_struct *cifsd_task;
3348 char * tmp; 3417 char *tmp;
3349 3418
3350 xid = GetXid(); 3419 xid = GetXid();
3351 3420
@@ -3368,7 +3437,7 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3368 } else if (rc == -ESHUTDOWN) { 3437 } else if (rc == -ESHUTDOWN) {
3369 cFYI(1, ("Waking up socket by sending signal")); 3438 cFYI(1, ("Waking up socket by sending signal"));
3370 if (cifsd_task) { 3439 if (cifsd_task) {
3371 force_sig(SIGKILL,cifsd_task); 3440 force_sig(SIGKILL, cifsd_task);
3372 kthread_stop(cifsd_task); 3441 kthread_stop(cifsd_task);
3373 } 3442 }
3374 rc = 0; 3443 rc = 0;
@@ -3377,7 +3446,7 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3377 } else 3446 } else
3378 cFYI(1, ("No session or bad tcon")); 3447 cFYI(1, ("No session or bad tcon"));
3379 } 3448 }
3380 3449
3381 cifs_sb->tcon = NULL; 3450 cifs_sb->tcon = NULL;
3382 tmp = cifs_sb->prepath; 3451 tmp = cifs_sb->prepath;
3383 cifs_sb->prepathlen = 0; 3452 cifs_sb->prepathlen = 0;
@@ -3389,11 +3458,11 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
3389 sesInfoFree(ses); 3458 sesInfoFree(ses);
3390 3459
3391 FreeXid(xid); 3460 FreeXid(xid);
3392 return rc; /* BB check if we should always return zero here */ 3461 return rc; /* BB check if we should always return zero here */
3393} 3462}
3394 3463
3395int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo, 3464int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
3396 struct nls_table * nls_info) 3465 struct nls_table *nls_info)
3397{ 3466{
3398 int rc = 0; 3467 int rc = 0;
3399 char ntlm_session_key[CIFS_SESS_KEY_SIZE]; 3468 char ntlm_session_key[CIFS_SESS_KEY_SIZE];
@@ -3405,7 +3474,7 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
3405 rc = CIFSSMBNegotiate(xid, pSesInfo); 3474 rc = CIFSSMBNegotiate(xid, pSesInfo);
3406 if (rc == -EAGAIN) /* retry only once on 1st time connection */ { 3475 if (rc == -EAGAIN) /* retry only once on 1st time connection */ {
3407 rc = CIFSSMBNegotiate(xid, pSesInfo); 3476 rc = CIFSSMBNegotiate(xid, pSesInfo);
3408 if (rc == -EAGAIN) 3477 if (rc == -EAGAIN)
3409 rc = -EHOSTDOWN; 3478 rc = -EHOSTDOWN;
3410 } 3479 }
3411 if (rc == 0) { 3480 if (rc == 0) {
@@ -3425,7 +3494,8 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
3425 if (linuxExtEnabled == 0) 3494 if (linuxExtEnabled == 0)
3426 pSesInfo->capabilities &= (~CAP_UNIX); 3495 pSesInfo->capabilities &= (~CAP_UNIX);
3427 /* pSesInfo->sequence_number = 0;*/ 3496 /* pSesInfo->sequence_number = 0;*/
3428 cFYI(1, ("Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d", 3497 cFYI(1,
3498 ("Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
3429 pSesInfo->server->secMode, 3499 pSesInfo->server->secMode,
3430 pSesInfo->server->capabilities, 3500 pSesInfo->server->capabilities,
3431 pSesInfo->server->timeAdj)); 3501 pSesInfo->server->timeAdj));
@@ -3433,7 +3503,7 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
3433 rc = CIFS_SessSetup(xid, pSesInfo, 3503 rc = CIFS_SessSetup(xid, pSesInfo,
3434 first_time, nls_info); 3504 first_time, nls_info);
3435 else if (extended_security 3505 else if (extended_security
3436 && (pSesInfo->capabilities 3506 && (pSesInfo->capabilities
3437 & CAP_EXTENDED_SECURITY) 3507 & CAP_EXTENDED_SECURITY)
3438 && (pSesInfo->server->secType == NTLMSSP)) { 3508 && (pSesInfo->server->secType == NTLMSSP)) {
3439 rc = -EOPNOTSUPP; 3509 rc = -EOPNOTSUPP;
@@ -3447,20 +3517,21 @@ int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
3447 nls_info); 3517 nls_info);
3448 if (!rc) { 3518 if (!rc) {
3449 if (ntlmv2_flag) { 3519 if (ntlmv2_flag) {
3450 char * v2_response; 3520 char *v2_response;
3451 cFYI(1, ("more secure NTLM ver2 hash")); 3521 cFYI(1, ("more secure NTLM ver2 hash"));
3452 if (CalcNTLMv2_partial_mac_key(pSesInfo, 3522 if (CalcNTLMv2_partial_mac_key(pSesInfo,
3453 nls_info)) { 3523 nls_info)) {
3454 rc = -ENOMEM; 3524 rc = -ENOMEM;
3455 goto ss_err_exit; 3525 goto ss_err_exit;
3456 } else 3526 } else
3457 v2_response = kmalloc(16 + 64 /* blob */, GFP_KERNEL); 3527 v2_response = kmalloc(16 + 64 /* blob */, GFP_KERNEL);
3458 if (v2_response) { 3528 if (v2_response) {
3459 CalcNTLMv2_response(pSesInfo,v2_response); 3529 CalcNTLMv2_response(pSesInfo,
3530 v2_response);
3460 /* if (first_time) 3531 /* if (first_time)
3461 cifs_calculate_ntlmv2_mac_key( 3532 cifs_calculate_ntlmv2_mac_key(
3462 pSesInfo->server->mac_signing_key, 3533 pSesInfo->server->mac_signing_key,
3463 response, ntlm_session_key, */ 3534 response, ntlm_session_key,*/
3464 kfree(v2_response); 3535 kfree(v2_response);
3465 /* BB Put dummy sig in SessSetup PDU? */ 3536 /* BB Put dummy sig in SessSetup PDU? */
3466 } else { 3537 } else {
diff --git a/fs/cifs/export.c b/fs/cifs/export.c
index 6e66bc19f0ae..1570cc6dedd7 100644
--- a/fs/cifs/export.c
+++ b/fs/cifs/export.c
@@ -22,7 +22,7 @@
22 * along with this library; if not, write to the Free Software 22 * along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 25
26 /* 26 /*
27 * See Documentation/filesystems/Exporting 27 * See Documentation/filesystems/Exporting
28 * and examples in fs/exportfs 28 * and examples in fs/exportfs
@@ -43,16 +43,16 @@
43#include "cifsglob.h" 43#include "cifsglob.h"
44#include "cifs_debug.h" 44#include "cifs_debug.h"
45 45
46 46
47#ifdef CONFIG_CIFS_EXPERIMENTAL 47#ifdef CONFIG_CIFS_EXPERIMENTAL
48 48
49static struct dentry *cifs_get_parent(struct dentry *dentry) 49static struct dentry *cifs_get_parent(struct dentry *dentry)
50{ 50{
51 /* BB need to add code here eventually to enable export via NFSD */ 51 /* BB need to add code here eventually to enable export via NFSD */
52 cFYI(1, ("get parent for %p", dentry)); 52 cFYI(1, ("get parent for %p", dentry));
53 return ERR_PTR(-EACCES); 53 return ERR_PTR(-EACCES);
54} 54}
55 55
56struct export_operations cifs_export_ops = { 56struct export_operations cifs_export_ops = {
57 .get_parent = cifs_get_parent, 57 .get_parent = cifs_get_parent,
58/* Following five export operations are unneeded so far and can default: 58/* Following five export operations are unneeded so far and can default:
@@ -62,6 +62,6 @@ struct export_operations cifs_export_ops = {
62 .decode_fh = 62 .decode_fh =
63 .encode_fs = */ 63 .encode_fs = */
64}; 64};
65 65
66#endif /* EXPERIMENTAL */ 66#endif /* EXPERIMENTAL */
67 67
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index d83eca4231e7..b67f1da020be 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -189,7 +189,7 @@ int cifs_open(struct inode *inode, struct file *file)
189 189
190 /* needed for writepage */ 190 /* needed for writepage */
191 pCifsFile->pfile = file; 191 pCifsFile->pfile = file;
192 192
193 file->private_data = pCifsFile; 193 file->private_data = pCifsFile;
194 break; 194 break;
195 } 195 }
@@ -378,7 +378,7 @@ static int cifs_reopen_file(struct file *file, int can_flush)
378 rc = -EBADF; 378 rc = -EBADF;
379 goto reopen_error_exit; 379 goto reopen_error_exit;
380 } 380 }
381 381
382 cifs_sb = CIFS_SB(inode->i_sb); 382 cifs_sb = CIFS_SB(inode->i_sb);
383 pTcon = cifs_sb->tcon; 383 pTcon = cifs_sb->tcon;
384 384
@@ -735,7 +735,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
735 posix_lock_type = CIFS_RDLCK; 735 posix_lock_type = CIFS_RDLCK;
736 else 736 else
737 posix_lock_type = CIFS_WRLCK; 737 posix_lock_type = CIFS_WRLCK;
738 738
739 if (numUnlock == 1) 739 if (numUnlock == 1)
740 posix_lock_type = CIFS_UNLCK; 740 posix_lock_type = CIFS_UNLCK;
741 741
@@ -810,7 +810,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
810 if (file->private_data == NULL) 810 if (file->private_data == NULL)
811 return -EBADF; 811 return -EBADF;
812 open_file = (struct cifsFileInfo *) file->private_data; 812 open_file = (struct cifsFileInfo *) file->private_data;
813 813
814 xid = GetXid(); 814 xid = GetXid();
815 815
816 if (*poffset > file->f_path.dentry->d_inode->i_size) 816 if (*poffset > file->f_path.dentry->d_inode->i_size)
@@ -909,7 +909,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
909 if (file->private_data == NULL) 909 if (file->private_data == NULL)
910 return -EBADF; 910 return -EBADF;
911 open_file = (struct cifsFileInfo *)file->private_data; 911 open_file = (struct cifsFileInfo *)file->private_data;
912 912
913 xid = GetXid(); 913 xid = GetXid();
914 914
915 if (*poffset > file->f_path.dentry->d_inode->i_size) 915 if (*poffset > file->f_path.dentry->d_inode->i_size)
@@ -1035,7 +1035,8 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode)
1035 /* if it fails, try another handle - might be */ 1035 /* if it fails, try another handle - might be */
1036 /* dangerous to hold up writepages with retry */ 1036 /* dangerous to hold up writepages with retry */
1037 if (rc) { 1037 if (rc) {
1038 cFYI(1, ("failed on reopen file in wp")); 1038 cFYI(1,
1039 ("failed on reopen file in wp"));
1039 read_lock(&GlobalSMBSeslock); 1040 read_lock(&GlobalSMBSeslock);
1040 /* can not use this handle, no write 1041 /* can not use this handle, no write
1041 pending on this one after all */ 1042 pending on this one after all */
@@ -1136,7 +1137,7 @@ static int cifs_writepages(struct address_space *mapping,
1136 int xid; 1137 int xid;
1137 1138
1138 cifs_sb = CIFS_SB(mapping->host->i_sb); 1139 cifs_sb = CIFS_SB(mapping->host->i_sb);
1139 1140
1140 /* 1141 /*
1141 * If wsize is smaller that the page cache size, default to writing 1142 * If wsize is smaller that the page cache size, default to writing
1142 * one page at a time via cifs_writepage 1143 * one page at a time via cifs_writepage
@@ -1419,7 +1420,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
1419 1420
1420 cFYI(1, ("Sync file - name: %s datasync: 0x%x", 1421 cFYI(1, ("Sync file - name: %s datasync: 0x%x",
1421 dentry->d_name.name, datasync)); 1422 dentry->d_name.name, datasync));
1422 1423
1423 rc = filemap_fdatawrite(inode->i_mapping); 1424 rc = filemap_fdatawrite(inode->i_mapping);
1424 if (rc == 0) 1425 if (rc == 0)
1425 CIFS_I(inode)->write_behind_rc = 0; 1426 CIFS_I(inode)->write_behind_rc = 0;
@@ -1476,7 +1477,7 @@ int cifs_flush(struct file *file, fl_owner_t id)
1476 rc = filemap_fdatawrite(inode->i_mapping); 1477 rc = filemap_fdatawrite(inode->i_mapping);
1477 if (!rc) /* reset wb rc if we were able to write out dirty pages */ 1478 if (!rc) /* reset wb rc if we were able to write out dirty pages */
1478 CIFS_I(inode)->write_behind_rc = 0; 1479 CIFS_I(inode)->write_behind_rc = 0;
1479 1480
1480 cFYI(1, ("Flush inode %p file %p rc %d", inode, file, rc)); 1481 cFYI(1, ("Flush inode %p file %p rc %d", inode, file, rc));
1481 1482
1482 return rc; 1483 return rc;
@@ -1914,7 +1915,7 @@ int is_size_safe_to_change(struct cifsInodeInfo *cifsInode, __u64 end_of_file)
1914 1915
1915 if (cifsInode) 1916 if (cifsInode)
1916 open_file = find_writable_file(cifsInode); 1917 open_file = find_writable_file(cifsInode);
1917 1918
1918 if (open_file) { 1919 if (open_file) {
1919 struct cifs_sb_info *cifs_sb; 1920 struct cifs_sb_info *cifs_sb;
1920 1921
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index d8ae20f1a47a..a1ca55650505 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -92,7 +92,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
92 } /* note ino incremented to unique num in new_inode */ 92 } /* note ino incremented to unique num in new_inode */
93 if (sb->s_flags & MS_NOATIME) 93 if (sb->s_flags & MS_NOATIME)
94 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME; 94 (*pinode)->i_flags |= S_NOATIME | S_NOCMTIME;
95 95
96 insert_inode_hash(*pinode); 96 insert_inode_hash(*pinode);
97 } 97 }
98 98
@@ -139,7 +139,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
139 inode->i_mode |= S_IFREG; 139 inode->i_mode |= S_IFREG;
140 cFYI(1, ("unknown type %d", type)); 140 cFYI(1, ("unknown type %d", type));
141 } 141 }
142 142
143 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID) 143 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)
144 inode->i_uid = cifs_sb->mnt_uid; 144 inode->i_uid = cifs_sb->mnt_uid;
145 else 145 else
@@ -149,7 +149,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
149 inode->i_gid = cifs_sb->mnt_gid; 149 inode->i_gid = cifs_sb->mnt_gid;
150 else 150 else
151 inode->i_gid = le64_to_cpu(findData.Gid); 151 inode->i_gid = le64_to_cpu(findData.Gid);
152 152
153 inode->i_nlink = le64_to_cpu(findData.Nlinks); 153 inode->i_nlink = le64_to_cpu(findData.Nlinks);
154 154
155 spin_lock(&inode->i_lock); 155 spin_lock(&inode->i_lock);
@@ -235,7 +235,7 @@ static int decode_sfu_inode(struct inode *inode, __u64 size,
235 } else if (size < 8) { 235 } else if (size < 8) {
236 return -EINVAL; /* EOPNOTSUPP? */ 236 return -EINVAL; /* EOPNOTSUPP? */
237 } 237 }
238 238
239 rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ, 239 rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ,
240 CREATE_NOT_DIR, &netfid, &oplock, NULL, 240 CREATE_NOT_DIR, &netfid, &oplock, NULL,
241 cifs_sb->local_nls, 241 cifs_sb->local_nls,
@@ -285,7 +285,6 @@ static int decode_sfu_inode(struct inode *inode, __u64 size,
285 CIFSSMBClose(xid, pTcon, netfid); 285 CIFSSMBClose(xid, pTcon, netfid);
286 } 286 }
287 return rc; 287 return rc;
288
289} 288}
290 289
291#define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */ 290#define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
@@ -317,8 +316,6 @@ static int get_sfu_uid_mode(struct inode *inode,
317#else 316#else
318 return -EOPNOTSUPP; 317 return -EOPNOTSUPP;
319#endif 318#endif
320
321
322} 319}
323 320
324int cifs_get_inode_info(struct inode **pinode, 321int cifs_get_inode_info(struct inode **pinode,
@@ -364,7 +361,6 @@ int cifs_get_inode_info(struct inode **pinode,
364 CIFS_MOUNT_MAP_SPECIAL_CHR); 361 CIFS_MOUNT_MAP_SPECIAL_CHR);
365 adjustTZ = TRUE; 362 adjustTZ = TRUE;
366 } 363 }
367
368 } 364 }
369 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */ 365 /* dump_mem("\nQPathInfo return data",&findData, sizeof(findData)); */
370 if (rc) { 366 if (rc) {
@@ -513,7 +509,7 @@ int cifs_get_inode_info(struct inode **pinode,
513 /* BB add code here - 509 /* BB add code here -
514 validate if device or weird share or device type? */ 510 validate if device or weird share or device type? */
515 } 511 }
516 512
517 spin_lock(&inode->i_lock); 513 spin_lock(&inode->i_lock);
518 if (is_size_safe_to_change(cifsInfo, le64_to_cpu(pfindData->EndOfFile))) { 514 if (is_size_safe_to_change(cifsInfo, le64_to_cpu(pfindData->EndOfFile))) {
519 /* can not safely shrink the file size here if the 515 /* can not safely shrink the file size here if the
@@ -836,7 +832,7 @@ static void posix_fill_in_inode(struct inode *tmp_inode,
836 tmp_inode->i_fop = &cifs_file_direct_nobrl_ops; 832 tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
837 else 833 else
838 tmp_inode->i_fop = &cifs_file_direct_ops; 834 tmp_inode->i_fop = &cifs_file_direct_ops;
839 835
840 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) 836 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
841 tmp_inode->i_fop = &cifs_file_nobrl_ops; 837 tmp_inode->i_fop = &cifs_file_nobrl_ops;
842 else 838 else
@@ -898,7 +894,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
898 FreeXid(xid); 894 FreeXid(xid);
899 return -ENOMEM; 895 return -ENOMEM;
900 } 896 }
901 897
902 if ((pTcon->ses->capabilities & CAP_UNIX) && 898 if ((pTcon->ses->capabilities & CAP_UNIX) &&
903 (CIFS_UNIX_POSIX_PATH_OPS_CAP & 899 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
904 le64_to_cpu(pTcon->fsUnixInfo.Capability))) { 900 le64_to_cpu(pTcon->fsUnixInfo.Capability))) {
@@ -909,7 +905,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
909 rc = -ENOMEM; 905 rc = -ENOMEM;
910 goto mkdir_out; 906 goto mkdir_out;
911 } 907 }
912 908
913 rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT, 909 rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
914 mode, NULL /* netfid */, pInfo, &oplock, 910 mode, NULL /* netfid */, pInfo, &oplock,
915 full_path, cifs_sb->local_nls, 911 full_path, cifs_sb->local_nls,
@@ -963,7 +959,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
963 kfree(pInfo); 959 kfree(pInfo);
964 goto mkdir_out; 960 goto mkdir_out;
965 } 961 }
966 962
967 /* BB add setting the equivalent of mode via CreateX w/ACLs */ 963 /* BB add setting the equivalent of mode via CreateX w/ACLs */
968 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls, 964 rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
969 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR); 965 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -1316,7 +1312,7 @@ int cifs_revalidate(struct dentry *direntry)
1316 } 1312 }
1317 } 1313 }
1318/* mutex_unlock(&direntry->d_inode->i_mutex); */ 1314/* mutex_unlock(&direntry->d_inode->i_mutex); */
1319 1315
1320 kfree(full_path); 1316 kfree(full_path);
1321 FreeXid(xid); 1317 FreeXid(xid);
1322 return rc; 1318 return rc;
@@ -1433,7 +1429,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1433 } else 1429 } else
1434 rc = 0; 1430 rc = 0;
1435 } 1431 }
1436 1432
1437 full_path = build_path_from_dentry(direntry); 1433 full_path = build_path_from_dentry(direntry);
1438 if (full_path == NULL) { 1434 if (full_path == NULL) {
1439 FreeXid(xid); 1435 FreeXid(xid);
@@ -1588,7 +1584,7 @@ int cifs_setattr(struct dentry *direntry, struct iattr *attrs)
1588 stamps are changed explicitly (i.e. by utime() 1584 stamps are changed explicitly (i.e. by utime()
1589 since we would then have a mix of client and 1585 since we would then have a mix of client and
1590 server times */ 1586 server times */
1591 1587
1592 if (set_time && (attrs->ia_valid & ATTR_CTIME)) { 1588 if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
1593 set_time = TRUE; 1589 set_time = TRUE;
1594 /* Although Samba throws this field away 1590 /* Although Samba throws this field away
diff --git a/fs/cifs/link.c b/fs/cifs/link.c
index 41f657ced7ec..e79b1c3e5f39 100644
--- a/fs/cifs/link.c
+++ b/fs/cifs/link.c
@@ -274,7 +274,6 @@ cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
274 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { 274 else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
275 cERROR(1, ("SFU style symlinks not implemented yet")); 275 cERROR(1, ("SFU style symlinks not implemented yet"));
276 /* add open and read as in fs/cifs/inode.c */ 276 /* add open and read as in fs/cifs/inode.c */
277
278 } else { 277 } else {
279 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, GENERIC_READ, 278 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, GENERIC_READ,
280 OPEN_REPARSE_POINT, &fid, &oplock, NULL, 279 OPEN_REPARSE_POINT, &fid, &oplock, NULL,
@@ -315,7 +314,9 @@ cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
315 num_referrals)); 314 num_referrals));
316 if (referrals) { 315 if (referrals) {
317 cFYI(1,("referral string: %s", referrals)); 316 cFYI(1,("referral string: %s", referrals));
318 strncpy(tmpbuffer, referrals, len-1); 317 strncpy(tmpbuffer,
318 referrals,
319 len-1);
319 } 320 }
320 } 321 }
321 kfree(referrals); 322 kfree(referrals);
diff --git a/fs/cifs/md4.c b/fs/cifs/md4.c
index b828a2e7d667..a2415c1a14db 100644
--- a/fs/cifs/md4.c
+++ b/fs/cifs/md4.c
@@ -4,17 +4,17 @@
4 a implementation of MD4 designed for use in the SMB authentication protocol 4 a implementation of MD4 designed for use in the SMB authentication protocol
5 Copyright (C) Andrew Tridgell 1997-1998. 5 Copyright (C) Andrew Tridgell 1997-1998.
6 Modified by Steve French (sfrench@us.ibm.com) 2002-2003 6 Modified by Steve French (sfrench@us.ibm.com) 2002-2003
7 7
8 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 (at your option) any later version.
12 12
13 This program is distributed in the hope that it will be useful, 13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
index 7590fd3d958c..21a2c46334e1 100644
--- a/fs/cifs/misc.c
+++ b/fs/cifs/misc.c
@@ -47,8 +47,10 @@ _GetXid(void)
47 47
48 spin_lock(&GlobalMid_Lock); 48 spin_lock(&GlobalMid_Lock);
49 GlobalTotalActiveXid++; 49 GlobalTotalActiveXid++;
50
51 /* keep high water mark for number of simultaneous ops in filesystem */
50 if (GlobalTotalActiveXid > GlobalMaxActiveXid) 52 if (GlobalTotalActiveXid > GlobalMaxActiveXid)
51 GlobalMaxActiveXid = GlobalTotalActiveXid; /* keep high water mark for number of simultaneous vfs ops in our filesystem */ 53 GlobalMaxActiveXid = GlobalTotalActiveXid;
52 if (GlobalTotalActiveXid > 65000) 54 if (GlobalTotalActiveXid > 65000)
53 cFYI(1, ("warning: more than 65000 requests active")); 55 cFYI(1, ("warning: more than 65000 requests active"));
54 xid = GlobalCurrentXid++; 56 xid = GlobalCurrentXid++;
@@ -148,8 +150,8 @@ cifs_buf_get(void)
148 but it may be more efficient to always alloc same size 150 but it may be more efficient to always alloc same size
149 albeit slightly larger than necessary and maxbuffersize 151 albeit slightly larger than necessary and maxbuffersize
150 defaults to this and can not be bigger */ 152 defaults to this and can not be bigger */
151 ret_buf = 153 ret_buf = (struct smb_hdr *) mempool_alloc(cifs_req_poolp,
152 (struct smb_hdr *) mempool_alloc(cifs_req_poolp, GFP_KERNEL | GFP_NOFS); 154 GFP_KERNEL | GFP_NOFS);
153 155
154 /* clear the first few header bytes */ 156 /* clear the first few header bytes */
155 /* for most paths, more is cleared in header_assemble */ 157 /* for most paths, more is cleared in header_assemble */
@@ -187,8 +189,8 @@ cifs_small_buf_get(void)
187 but it may be more efficient to always alloc same size 189 but it may be more efficient to always alloc same size
188 albeit slightly larger than necessary and maxbuffersize 190 albeit slightly larger than necessary and maxbuffersize
189 defaults to this and can not be bigger */ 191 defaults to this and can not be bigger */
190 ret_buf = 192 ret_buf = (struct smb_hdr *) mempool_alloc(cifs_sm_req_poolp,
191 (struct smb_hdr *) mempool_alloc(cifs_sm_req_poolp, GFP_KERNEL | GFP_NOFS); 193 GFP_KERNEL | GFP_NOFS);
192 if (ret_buf) { 194 if (ret_buf) {
193 /* No need to clear memory here, cleared in header assemble */ 195 /* No need to clear memory here, cleared in header assemble */
194 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/ 196 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index 40ed5c9caad3..ef9c98145850 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -816,7 +816,7 @@ map_smb_to_linux_error(struct smb_hdr *smb)
816 cFYI(1, (" !!Mapping smb error code %d to POSIX err %d !!", 816 cFYI(1, (" !!Mapping smb error code %d to POSIX err %d !!",
817 smberrcode, rc)); 817 smberrcode, rc));
818 818
819 /* generic corrective action e.g. reconnect SMB session on 819 /* generic corrective action e.g. reconnect SMB session on
820 * ERRbaduid could be added */ 820 * ERRbaduid could be added */
821 821
822 return rc; 822 return rc;
diff --git a/fs/cifs/nterr.h b/fs/cifs/nterr.h
index 02a25fd84635..588abbb9d08c 100644
--- a/fs/cifs/nterr.h
+++ b/fs/cifs/nterr.h
@@ -6,17 +6,17 @@
6 Copyright (C) John H Terpstra 1996-2000 6 Copyright (C) John H Terpstra 1996-2000
7 Copyright (C) Luke Kenneth Casson Leighton 1996-2000 7 Copyright (C) Luke Kenneth Casson Leighton 1996-2000
8 Copyright (C) Paul Ashton 1998-2000 8 Copyright (C) Paul Ashton 1998-2000
9 9
10 This program is free software; you can redistribute it and/or modify 10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by 11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or 12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version. 13 (at your option) any later version.
14 14
15 This program is distributed in the hope that it will be useful, 15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details. 18 GNU General Public License for more details.
19 19
20 You should have received a copy of the GNU General Public License 20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software 21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index f519e1910191..07f92531f74f 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -51,7 +51,6 @@ static void dump_cifs_file_struct(struct file *file, char *label)
51 if (cf->srch_inf.emptyDir) { 51 if (cf->srch_inf.emptyDir) {
52 cFYI(1, ("empty dir")); 52 cFYI(1, ("empty dir"));
53 } 53 }
54
55 } 54 }
56} 55}
57#endif /* DEBUG2 */ 56#endif /* DEBUG2 */
@@ -255,7 +254,6 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
255 tmp_inode->i_fop = &cifs_file_direct_nobrl_ops; 254 tmp_inode->i_fop = &cifs_file_direct_nobrl_ops;
256 else 255 else
257 tmp_inode->i_fop = &cifs_file_direct_ops; 256 tmp_inode->i_fop = &cifs_file_direct_ops;
258
259 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) 257 } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
260 tmp_inode->i_fop = &cifs_file_nobrl_ops; 258 tmp_inode->i_fop = &cifs_file_nobrl_ops;
261 else 259 else
@@ -644,11 +642,11 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
644 loff_t index_to_find = file->f_pos; 642 loff_t index_to_find = file->f_pos;
645 struct cifsFileInfo *cifsFile = file->private_data; 643 struct cifsFileInfo *cifsFile = file->private_data;
646 /* check if index in the buffer */ 644 /* check if index in the buffer */
647 645
648 if ((cifsFile == NULL) || (ppCurrentEntry == NULL) || 646 if ((cifsFile == NULL) || (ppCurrentEntry == NULL) ||
649 (num_to_ret == NULL)) 647 (num_to_ret == NULL))
650 return -ENOENT; 648 return -ENOENT;
651 649
652 *ppCurrentEntry = NULL; 650 *ppCurrentEntry = NULL;
653 first_entry_in_buffer = 651 first_entry_in_buffer =
654 cifsFile->srch_inf.index_of_last_entry - 652 cifsFile->srch_inf.index_of_last_entry -
@@ -712,7 +710,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
712 pos_in_buf = index_to_find - first_entry_in_buffer; 710 pos_in_buf = index_to_find - first_entry_in_buffer;
713 cFYI(1, ("found entry - pos_in_buf %d", pos_in_buf)); 711 cFYI(1, ("found entry - pos_in_buf %d", pos_in_buf));
714 712
715 for (i=0;(i<(pos_in_buf)) && (current_entry != NULL);i++) { 713 for (i=0; (i < (pos_in_buf)) && (current_entry != NULL); i++) {
716 /* go entry by entry figuring out which is first */ 714 /* go entry by entry figuring out which is first */
717 current_entry = nxt_dir_entry(current_entry, end_of_smb, 715 current_entry = nxt_dir_entry(current_entry, end_of_smb,
718 cifsFile->srch_inf.info_level); 716 cifsFile->srch_inf.info_level);
@@ -839,7 +837,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
839 return -EINVAL; 837 return -EINVAL;
840 838
841 pCifsF = file->private_data; 839 pCifsF = file->private_data;
842 840
843 if ((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL)) 841 if ((scratch_buf == NULL) || (pfindEntry == NULL) || (pCifsF == NULL))
844 return -ENOENT; 842 return -ENOENT;
845 843
@@ -892,7 +890,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file,
892 if (rc == 2) 890 if (rc == 2)
893 d_rehash(tmp_dentry); 891 d_rehash(tmp_dentry);
894 } 892 }
895 893
896 894
897 rc = filldir(direntry, qstring.name, qstring.len, file->f_pos, 895 rc = filldir(direntry, qstring.name, qstring.len, file->f_pos,
898 tmp_inode->i_ino, obj_type); 896 tmp_inode->i_ino, obj_type);
@@ -951,7 +949,7 @@ static int cifs_save_resume_key(const char *current_entry,
951 len = le32_to_cpu(pFindData->FileNameLength); 949 len = le32_to_cpu(pFindData->FileNameLength);
952 cifsFile->srch_inf.resume_key = pFindData->FileIndex; 950 cifsFile->srch_inf.resume_key = pFindData->FileIndex;
953 } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) { 951 } else if (level == SMB_FIND_FILE_BOTH_DIRECTORY_INFO) {
954 FILE_BOTH_DIRECTORY_INFO *pFindData = 952 FILE_BOTH_DIRECTORY_INFO *pFindData =
955 (FILE_BOTH_DIRECTORY_INFO *)current_entry; 953 (FILE_BOTH_DIRECTORY_INFO *)current_entry;
956 filename = &pFindData->FileName[0]; 954 filename = &pFindData->FileName[0];
957 len = le32_to_cpu(pFindData->FileNameLength); 955 len = le32_to_cpu(pFindData->FileNameLength);
@@ -982,7 +980,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
982 char *current_entry; 980 char *current_entry;
983 int num_to_fill = 0; 981 int num_to_fill = 0;
984 char *tmp_buf = NULL; 982 char *tmp_buf = NULL;
985 char * end_of_smb; 983 char *end_of_smb;
986 int max_len; 984 int max_len;
987 985
988 xid = GetXid(); 986 xid = GetXid();
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c
index f45c4730e92e..a1e6f7f45b13 100644
--- a/fs/cifs/sess.c
+++ b/fs/cifs/sess.c
@@ -191,7 +191,7 @@ static int decode_unicode_ssetup(char **pbcc_area, int bleft,
191 their final Unicode string - in which case we 191 their final Unicode string - in which case we
192 now will not attempt to decode the byte of junk 192 now will not attempt to decode the byte of junk
193 which follows it */ 193 which follows it */
194 194
195 words_left = bleft / 2; 195 words_left = bleft / 2;
196 196
197 /* save off server operating system */ 197 /* save off server operating system */
@@ -266,11 +266,11 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft,
266 char *bcc_ptr = *pbcc_area; 266 char *bcc_ptr = *pbcc_area;
267 267
268 cFYI(1, ("decode sessetup ascii. bleft %d", bleft)); 268 cFYI(1, ("decode sessetup ascii. bleft %d", bleft));
269 269
270 len = strnlen(bcc_ptr, bleft); 270 len = strnlen(bcc_ptr, bleft);
271 if (len >= bleft) 271 if (len >= bleft)
272 return rc; 272 return rc;
273 273
274 if (ses->serverOS) 274 if (ses->serverOS)
275 kfree(ses->serverOS); 275 kfree(ses->serverOS);
276 276
@@ -412,7 +412,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
412 cpu_to_le16(CIFS_SESS_KEY_SIZE); 412 cpu_to_le16(CIFS_SESS_KEY_SIZE);
413 pSMB->req_no_secext.CaseSensitivePasswordLength = 413 pSMB->req_no_secext.CaseSensitivePasswordLength =
414 cpu_to_le16(CIFS_SESS_KEY_SIZE); 414 cpu_to_le16(CIFS_SESS_KEY_SIZE);
415 415
416 /* calculate session key */ 416 /* calculate session key */
417 SMBNTencrypt(ses->password, ses->server->cryptKey, 417 SMBNTencrypt(ses->password, ses->server->cryptKey,
418 ntlm_session_key); 418 ntlm_session_key);
@@ -536,7 +536,7 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
536 ses, nls_cp); 536 ses, nls_cp);
537 else 537 else
538 rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,nls_cp); 538 rc = decode_ascii_ssetup(&bcc_ptr, bytes_remaining, ses,nls_cp);
539 539
540ssetup_exit: 540ssetup_exit:
541 kfree(str_area); 541 kfree(str_area);
542 if (resp_buf_type == CIFS_SMALL_BUFFER) { 542 if (resp_buf_type == CIFS_SMALL_BUFFER) {
diff --git a/fs/cifs/smbdes.c b/fs/cifs/smbdes.c
index 1e92559cb8cf..cfa6d21fb4e8 100644
--- a/fs/cifs/smbdes.c
+++ b/fs/cifs/smbdes.c
@@ -7,17 +7,17 @@
7 7
8 Copyright (C) Andrew Tridgell 1998 8 Copyright (C) Andrew Tridgell 1998
9 Modified by Steve French (sfrench@us.ibm.com) 2002,2004 9 Modified by Steve French (sfrench@us.ibm.com) 2002,2004
10 10
11 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 (at your option) any later version.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20 20
21 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software 22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
diff --git a/fs/cifs/smbencrypt.c b/fs/cifs/smbencrypt.c
index 1966adaf0b29..90542a39be17 100644
--- a/fs/cifs/smbencrypt.c
+++ b/fs/cifs/smbencrypt.c
@@ -7,17 +7,17 @@
7 Modified by Jeremy Allison 1995. 7 Modified by Jeremy Allison 1995.
8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003 8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2002-2003
9 Modified by Steve French (sfrench@us.ibm.com) 2002-2003 9 Modified by Steve French (sfrench@us.ibm.com) 2002-2003
10 10
11 This program is free software; you can redistribute it and/or modify 11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by 12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or 13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version. 14 (at your option) any later version.
15 15
16 This program is distributed in the hope that it will be useful, 16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20 20
21 You should have received a copy of the GNU General Public License 21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software 22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
@@ -73,7 +73,7 @@ SMBencrypt(unsigned char *passwd, unsigned char *c8, unsigned char *p24)
73 E_P16(p14, p21); 73 E_P16(p14, p21);
74 74
75 SMBOWFencrypt(p21, c8, p24); 75 SMBOWFencrypt(p21, c8, p24);
76 76
77 memset(p14, 0, 15); 77 memset(p14, 0, 15);
78 memset(p21, 0, 21); 78 memset(p21, 0, 21);
79} 79}
@@ -178,8 +178,8 @@ ntv2_owf_gen(const unsigned char owf[16], const char *user_n,
178 const char *domain_n, unsigned char kr_buf[16], 178 const char *domain_n, unsigned char kr_buf[16],
179 const struct nls_table *nls_codepage) 179 const struct nls_table *nls_codepage)
180{ 180{
181 wchar_t * user_u; 181 wchar_t *user_u;
182 wchar_t * dom_u; 182 wchar_t *dom_u;
183 int user_l, domain_l; 183 int user_l, domain_l;
184 struct HMACMD5Context ctx; 184 struct HMACMD5Context ctx;
185 185
@@ -188,7 +188,7 @@ ntv2_owf_gen(const unsigned char owf[16], const char *user_n,
188 if (user_u == NULL) 188 if (user_u == NULL)
189 return; 189 return;
190 dom_u = user_u + 1024; 190 dom_u = user_u + 1024;
191 191
192 /* push_ucs2(NULL, user_u, user_n, (user_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER); 192 /* push_ucs2(NULL, user_u, user_n, (user_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER);
193 push_ucs2(NULL, dom_u, domain_n, (domain_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER); */ 193 push_ucs2(NULL, dom_u, domain_n, (domain_l+1)*2, STR_UNICODE|STR_NOALIGN|STR_TERMINATE|STR_UPPER); */
194 194
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
index f9ebe70ecc4d..746bc9405db1 100644
--- a/fs/cifs/transport.c
+++ b/fs/cifs/transport.c
@@ -32,7 +32,7 @@
32#include "cifsglob.h" 32#include "cifsglob.h"
33#include "cifsproto.h" 33#include "cifsproto.h"
34#include "cifs_debug.h" 34#include "cifs_debug.h"
35 35
36extern mempool_t *cifs_mid_poolp; 36extern mempool_t *cifs_mid_poolp;
37extern struct kmem_cache *cifs_oplock_cachep; 37extern struct kmem_cache *cifs_oplock_cachep;
38 38
@@ -49,7 +49,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct cifsSesInfo *ses)
49 cERROR(1, ("Null TCP session in AllocMidQEntry")); 49 cERROR(1, ("Null TCP session in AllocMidQEntry"));
50 return NULL; 50 return NULL;
51 } 51 }
52 52
53 temp = (struct mid_q_entry *) mempool_alloc(cifs_mid_poolp, 53 temp = (struct mid_q_entry *) mempool_alloc(cifs_mid_poolp,
54 GFP_KERNEL | GFP_NOFS); 54 GFP_KERNEL | GFP_NOFS);
55 if (temp == NULL) 55 if (temp == NULL)
@@ -223,7 +223,7 @@ smb_send2(struct socket *ssocket, struct kvec *iov, int n_vec,
223 unsigned int total_len; 223 unsigned int total_len;
224 int first_vec = 0; 224 int first_vec = 0;
225 unsigned int smb_buf_length = smb_buffer->smb_buf_length; 225 unsigned int smb_buf_length = smb_buffer->smb_buf_length;
226 226
227 if (ssocket == NULL) 227 if (ssocket == NULL)
228 return -ENOTSOCK; /* BB eventually add reconnect code here */ 228 return -ENOTSOCK; /* BB eventually add reconnect code here */
229 229
@@ -335,7 +335,7 @@ static int wait_for_free_request(struct cifsSesInfo *ses, const int long_op)
335 335
336 /* can not count locking commands against total 336 /* can not count locking commands against total
337 as they are allowed to block on server */ 337 as they are allowed to block on server */
338 338
339 /* update # of requests on the wire to server */ 339 /* update # of requests on the wire to server */
340 if (long_op < 3) 340 if (long_op < 3)
341 atomic_inc(&ses->server->inFlight); 341 atomic_inc(&ses->server->inFlight);
@@ -426,7 +426,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
426 unsigned long timeout; 426 unsigned long timeout;
427 struct mid_q_entry *midQ; 427 struct mid_q_entry *midQ;
428 struct smb_hdr *in_buf = iov[0].iov_base; 428 struct smb_hdr *in_buf = iov[0].iov_base;
429 429
430 *pRespBufType = CIFS_NO_BUFFER; /* no response buf yet */ 430 *pRespBufType = CIFS_NO_BUFFER; /* no response buf yet */
431 431
432 if ((ses == NULL) || (ses->server == NULL)) { 432 if ((ses == NULL) || (ses->server == NULL)) {
@@ -537,7 +537,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
537 wake_up(&ses->server->request_q); 537 wake_up(&ses->server->request_q);
538 return rc; 538 return rc;
539 } 539 }
540 540
541 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 541 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
542 cERROR(1, ("Frame too large received. Length: %d Xid: %d", 542 cERROR(1, ("Frame too large received. Length: %d Xid: %d",
543 receive_len, xid)); 543 receive_len, xid));
@@ -718,7 +718,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
718 wake_up(&ses->server->request_q); 718 wake_up(&ses->server->request_q);
719 return rc; 719 return rc;
720 } 720 }
721 721
722 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 722 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
723 cERROR(1, ("Frame too large received. Length: %d Xid: %d", 723 cERROR(1, ("Frame too large received. Length: %d Xid: %d",
724 receive_len, xid)); 724 receive_len, xid));
@@ -962,7 +962,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
962 DeleteMidQEntry(midQ); 962 DeleteMidQEntry(midQ);
963 return rc; 963 return rc;
964 } 964 }
965 965
966 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) { 966 if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
967 cERROR(1, ("Frame too large received. Length: %d Xid: %d", 967 cERROR(1, ("Frame too large received. Length: %d Xid: %d",
968 receive_len, xid)); 968 receive_len, xid));
diff --git a/fs/cifs/xattr.c b/fs/cifs/xattr.c
index 5c4cf2926849..836c39e7c09a 100644
--- a/fs/cifs/xattr.c
+++ b/fs/cifs/xattr.c
@@ -37,7 +37,7 @@
37#define XATTR_TRUSTED_PREFIX_LEN 8 37#define XATTR_TRUSTED_PREFIX_LEN 8
38#define XATTR_SECURITY_PREFIX_LEN 9 38#define XATTR_SECURITY_PREFIX_LEN 9
39/* BB need to add server (Samba e.g) support for security and trusted prefix */ 39/* BB need to add server (Samba e.g) support for security and trusted prefix */
40 40
41 41
42 42
43int cifs_removexattr(struct dentry *direntry, const char *ea_name) 43int cifs_removexattr(struct dentry *direntry, const char *ea_name)