aboutsummaryrefslogtreecommitdiffstats
path: root/fs/cifs/cifssmb.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/cifs/cifssmb.c')
-rw-r--r--fs/cifs/cifssmb.c923
1 files changed, 477 insertions, 446 deletions
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);