smb1ops.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * SMB1 (CIFS) version specific operations
  3. *
  4. * Copyright (c) 2012, Jeff Layton <jlayton@redhat.com>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License v2 as published
  8. * by the Free Software Foundation.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. * the GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "cifsglob.h"
  20. #include "cifsproto.h"
  21. #include "cifs_debug.h"
  22. #include "cifspdu.h"
  23. /*
  24. * An NT cancel request header looks just like the original request except:
  25. *
  26. * The Command is SMB_COM_NT_CANCEL
  27. * The WordCount is zeroed out
  28. * The ByteCount is zeroed out
  29. *
  30. * This function mangles an existing request buffer into a
  31. * SMB_COM_NT_CANCEL request and then sends it.
  32. */
  33. static int
  34. send_nt_cancel(struct TCP_Server_Info *server, void *buf,
  35. struct mid_q_entry *mid)
  36. {
  37. int rc = 0;
  38. struct smb_hdr *in_buf = (struct smb_hdr *)buf;
  39. /* -4 for RFC1001 length and +2 for BCC field */
  40. in_buf->smb_buf_length = cpu_to_be32(sizeof(struct smb_hdr) - 4 + 2);
  41. in_buf->Command = SMB_COM_NT_CANCEL;
  42. in_buf->WordCount = 0;
  43. put_bcc(0, in_buf);
  44. mutex_lock(&server->srv_mutex);
  45. rc = cifs_sign_smb(in_buf, server, &mid->sequence_number);
  46. if (rc) {
  47. mutex_unlock(&server->srv_mutex);
  48. return rc;
  49. }
  50. rc = smb_send(server, in_buf, be32_to_cpu(in_buf->smb_buf_length));
  51. mutex_unlock(&server->srv_mutex);
  52. cFYI(1, "issued NT_CANCEL for mid %u, rc = %d",
  53. in_buf->Mid, rc);
  54. return rc;
  55. }
  56. static bool
  57. cifs_compare_fids(struct cifsFileInfo *ob1, struct cifsFileInfo *ob2)
  58. {
  59. return ob1->netfid == ob2->netfid;
  60. }
  61. static unsigned int
  62. cifs_read_data_offset(char *buf)
  63. {
  64. READ_RSP *rsp = (READ_RSP *)buf;
  65. return le16_to_cpu(rsp->DataOffset);
  66. }
  67. static unsigned int
  68. cifs_read_data_length(char *buf)
  69. {
  70. READ_RSP *rsp = (READ_RSP *)buf;
  71. return (le16_to_cpu(rsp->DataLengthHigh) << 16) +
  72. le16_to_cpu(rsp->DataLength);
  73. }
  74. struct smb_version_operations smb1_operations = {
  75. .send_cancel = send_nt_cancel,
  76. .compare_fids = cifs_compare_fids,
  77. .setup_request = cifs_setup_request,
  78. .check_receive = cifs_check_receive,
  79. .read_data_offset = cifs_read_data_offset,
  80. .read_data_length = cifs_read_data_length,
  81. .map_error = map_smb_to_linux_error,
  82. };
  83. struct smb_version_values smb1_values = {
  84. .version_string = SMB1_VERSION_STRING,
  85. .large_lock_type = LOCKING_ANDX_LARGE_FILES,
  86. .exclusive_lock_type = 0,
  87. .shared_lock_type = LOCKING_ANDX_SHARED_LOCK,
  88. .unlock_lock_type = 0,
  89. .header_size = sizeof(struct smb_hdr),
  90. .max_header_size = MAX_CIFS_HDR_SIZE,
  91. .read_rsp_size = sizeof(READ_RSP),
  92. };