ruby_smb 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.md +247 -7
  5. data/examples/anonymous_auth.rb +6 -3
  6. data/examples/append_file.rb +40 -0
  7. data/examples/authenticate.rb +12 -7
  8. data/examples/delete_file.rb +40 -0
  9. data/examples/list_directory.rb +45 -0
  10. data/examples/negotiate.rb +0 -1
  11. data/examples/negotiate_with_netbios_service.rb +36 -0
  12. data/examples/net_share_enum_all.rb +30 -0
  13. data/examples/read_file.rb +39 -0
  14. data/examples/rename_file.rb +41 -0
  15. data/examples/tree_connect.rb +2 -4
  16. data/examples/write_file.rb +40 -0
  17. data/lib/ruby_smb.rb +5 -0
  18. data/lib/ruby_smb/client.rb +196 -43
  19. data/lib/ruby_smb/client/authentication.rb +89 -48
  20. data/lib/ruby_smb/client/echo.rb +1 -4
  21. data/lib/ruby_smb/client/negotiation.rb +46 -45
  22. data/lib/ruby_smb/client/signing.rb +9 -16
  23. data/lib/ruby_smb/client/tree_connect.rb +8 -13
  24. data/lib/ruby_smb/client/utils.rb +79 -0
  25. data/lib/ruby_smb/dcerpc.rb +30 -0
  26. data/lib/ruby_smb/dcerpc/bind.rb +60 -0
  27. data/lib/ruby_smb/dcerpc/handle.rb +60 -0
  28. data/lib/ruby_smb/dcerpc/ndr.rb +41 -0
  29. data/lib/ruby_smb/dcerpc/request.rb +43 -0
  30. data/lib/ruby_smb/dcerpc/response.rb +46 -0
  31. data/lib/ruby_smb/dcerpc/srvsvc.rb +17 -0
  32. data/lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb +93 -0
  33. data/lib/ruby_smb/dcerpc/uuid.rb +28 -0
  34. data/lib/ruby_smb/dispatcher.rb +7 -3
  35. data/lib/ruby_smb/dispatcher/base.rb +23 -14
  36. data/lib/ruby_smb/dispatcher/socket.rb +71 -51
  37. data/lib/ruby_smb/dispositions.rb +32 -0
  38. data/lib/ruby_smb/error.rb +24 -18
  39. data/lib/ruby_smb/field.rb +5 -2
  40. data/lib/ruby_smb/field/extended_attribute_flag.rb +1 -1
  41. data/lib/ruby_smb/field/file_time.rb +3 -1
  42. data/lib/ruby_smb/field/security_descriptor.rb +6 -6
  43. data/lib/ruby_smb/field/smb2_fileid.rb +11 -0
  44. data/lib/ruby_smb/field/smb_fea.rb +3 -3
  45. data/lib/ruby_smb/field/smb_fea_list.rb +3 -3
  46. data/lib/ruby_smb/field/smb_gea.rb +12 -0
  47. data/lib/ruby_smb/field/smb_gea_list.rb +13 -0
  48. data/lib/ruby_smb/field/string16.rb +14 -0
  49. data/lib/ruby_smb/field/stringz16.rb +3 -7
  50. data/lib/ruby_smb/field/utime.rb +11 -10
  51. data/lib/ruby_smb/fscc.rb +12 -0
  52. data/lib/ruby_smb/fscc/control_codes.rb +26 -0
  53. data/lib/ruby_smb/{field → fscc}/ea_info_array.rb +12 -14
  54. data/lib/ruby_smb/fscc/file_attributes.rb +29 -0
  55. data/lib/ruby_smb/{field → fscc}/file_full_ea_info.rb +5 -5
  56. data/lib/ruby_smb/fscc/file_information.rb +60 -0
  57. data/lib/ruby_smb/fscc/file_information/file_both_directory_information.rb +29 -0
  58. data/lib/ruby_smb/fscc/file_information/file_directory_information.rb +25 -0
  59. data/lib/ruby_smb/fscc/file_information/file_disposition_information.rb +15 -0
  60. data/lib/ruby_smb/fscc/file_information/file_full_directory_information.rb +26 -0
  61. data/lib/ruby_smb/fscc/file_information/file_id_both_directory_information.rb +31 -0
  62. data/lib/ruby_smb/fscc/file_information/file_id_full_directory_information.rb +28 -0
  63. data/lib/ruby_smb/fscc/file_information/file_names_information.rb +18 -0
  64. data/lib/ruby_smb/fscc/file_information/file_rename_information.rb +44 -0
  65. data/lib/ruby_smb/generic_packet.rb +40 -18
  66. data/lib/ruby_smb/gss.rb +49 -56
  67. data/lib/ruby_smb/impersonation_levels.rb +7 -2
  68. data/lib/ruby_smb/nbss.rb +16 -0
  69. data/lib/ruby_smb/nbss/negative_session_response.rb +30 -0
  70. data/lib/ruby_smb/nbss/session_header.rb +13 -0
  71. data/lib/ruby_smb/nbss/session_request.rb +13 -0
  72. data/lib/ruby_smb/smb1.rb +20 -17
  73. data/lib/ruby_smb/smb1/bit_field.rb +3 -0
  74. data/lib/ruby_smb/smb1/bit_field/create_options.rb +5 -5
  75. data/lib/ruby_smb/smb1/bit_field/file_status_flags.rb +18 -0
  76. data/lib/ruby_smb/smb1/bit_field/open2_access_mode.rb +11 -11
  77. data/lib/ruby_smb/smb1/bit_field/open2_open_mode.rb +1 -1
  78. data/lib/ruby_smb/smb1/bit_field/optional_support.rb +0 -1
  79. data/lib/ruby_smb/smb1/bit_field/security_flags.rb +15 -0
  80. data/lib/ruby_smb/smb1/bit_field/share_access.rb +2 -3
  81. data/lib/ruby_smb/smb1/bit_field/smb_ext_file_attributes.rb +21 -24
  82. data/lib/ruby_smb/smb1/bit_field/smb_file_attributes.rb +1 -1
  83. data/lib/ruby_smb/smb1/commands.rb +5 -0
  84. data/lib/ruby_smb/smb1/create_actions.rb +3 -5
  85. data/lib/ruby_smb/smb1/file.rb +289 -0
  86. data/lib/ruby_smb/smb1/oplock_levels.rb +2 -4
  87. data/lib/ruby_smb/smb1/packet.rb +10 -0
  88. data/lib/ruby_smb/smb1/packet/close_request.rb +31 -0
  89. data/lib/ruby_smb/smb1/packet/close_response.rb +28 -0
  90. data/lib/ruby_smb/smb1/packet/echo_request.rb +5 -7
  91. data/lib/ruby_smb/smb1/packet/echo_response.rb +5 -7
  92. data/lib/ruby_smb/smb1/packet/empty_packet.rb +1 -2
  93. data/lib/ruby_smb/smb1/packet/logoff_request.rb +1 -4
  94. data/lib/ruby_smb/smb1/packet/logoff_response.rb +1 -4
  95. data/lib/ruby_smb/smb1/packet/negotiate_response.rb +22 -0
  96. data/lib/ruby_smb/smb1/packet/negotiate_response_extended.rb +22 -0
  97. data/lib/ruby_smb/smb1/packet/nt_create_andx_request.rb +62 -0
  98. data/lib/ruby_smb/smb1/packet/nt_create_andx_response.rb +66 -0
  99. data/lib/ruby_smb/smb1/packet/nt_trans.rb +1 -2
  100. data/lib/ruby_smb/smb1/packet/nt_trans/create_request.rb +19 -13
  101. data/lib/ruby_smb/smb1/packet/nt_trans/create_response.rb +8 -10
  102. data/lib/ruby_smb/smb1/packet/nt_trans/request.rb +11 -11
  103. data/lib/ruby_smb/smb1/packet/nt_trans/response.rb +10 -10
  104. data/lib/ruby_smb/smb1/packet/nt_trans/subcommands.rb +8 -1
  105. data/lib/ruby_smb/smb1/packet/read_andx_request.rb +84 -0
  106. data/lib/ruby_smb/smb1/packet/read_andx_response.rb +47 -0
  107. data/lib/ruby_smb/smb1/packet/session_setup_legacy_request.rb +2 -6
  108. data/lib/ruby_smb/smb1/packet/session_setup_legacy_response.rb +1 -4
  109. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +1 -6
  110. data/lib/ruby_smb/smb1/packet/session_setup_response.rb +2 -4
  111. data/lib/ruby_smb/smb1/packet/trans2.rb +8 -2
  112. data/lib/ruby_smb/smb1/packet/trans2/data_block.rb +6 -7
  113. data/lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb +77 -0
  114. data/lib/ruby_smb/smb1/packet/trans2/find_first2_response.rb +87 -0
  115. data/lib/ruby_smb/smb1/packet/trans2/find_information_level.rb +32 -0
  116. data/lib/ruby_smb/smb1/packet/trans2/find_information_level/find_file_full_directory_info.rb +45 -0
  117. data/lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb +77 -0
  118. data/lib/ruby_smb/smb1/packet/trans2/find_next2_response.rb +86 -0
  119. data/lib/ruby_smb/smb1/packet/trans2/open2_request.rb +10 -10
  120. data/lib/ruby_smb/smb1/packet/trans2/open2_response.rb +10 -12
  121. data/lib/ruby_smb/smb1/packet/trans2/request.rb +15 -17
  122. data/lib/ruby_smb/smb1/packet/trans2/request_secondary.rb +8 -10
  123. data/lib/ruby_smb/smb1/packet/trans2/response.rb +11 -13
  124. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_request.rb +66 -0
  125. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_response.rb +57 -0
  126. data/lib/ruby_smb/smb1/packet/trans2/subcommands.rb +5 -2
  127. data/lib/ruby_smb/smb1/packet/tree_connect_request.rb +4 -6
  128. data/lib/ruby_smb/smb1/packet/tree_connect_response.rb +5 -7
  129. data/lib/ruby_smb/smb1/packet/tree_disconnect_request.rb +2 -4
  130. data/lib/ruby_smb/smb1/packet/tree_disconnect_response.rb +2 -4
  131. data/lib/ruby_smb/smb1/packet/write_andx_request.rb +68 -0
  132. data/lib/ruby_smb/smb1/packet/write_andx_response.rb +35 -0
  133. data/lib/ruby_smb/smb1/resource_type.rb +18 -0
  134. data/lib/ruby_smb/smb1/tree.rb +188 -5
  135. data/lib/ruby_smb/smb2.rb +16 -11
  136. data/lib/ruby_smb/smb2/bit_field.rb +1 -0
  137. data/lib/ruby_smb/smb2/bit_field/file_access_mask.rb +1 -1
  138. data/lib/ruby_smb/smb2/bit_field/session_flags.rb +1 -2
  139. data/lib/ruby_smb/smb2/bit_field/share_flags.rb +4 -6
  140. data/lib/ruby_smb/smb2/create_context.rb +29 -0
  141. data/lib/ruby_smb/smb2/file.rb +251 -0
  142. data/lib/ruby_smb/smb2/info_type.rb +21 -0
  143. data/lib/ruby_smb/smb2/packet.rb +16 -0
  144. data/lib/ruby_smb/smb2/packet/close_request.rb +22 -0
  145. data/lib/ruby_smb/smb2/packet/close_response.rb +29 -0
  146. data/lib/ruby_smb/smb2/packet/create_request.rb +54 -0
  147. data/lib/ruby_smb/smb2/packet/create_response.rb +35 -0
  148. data/lib/ruby_smb/smb2/packet/echo_request.rb +1 -3
  149. data/lib/ruby_smb/smb2/packet/echo_response.rb +1 -3
  150. data/lib/ruby_smb/smb2/packet/error_packet.rb +1 -3
  151. data/lib/ruby_smb/smb2/packet/ioctl_request.rb +54 -0
  152. data/lib/ruby_smb/smb2/packet/ioctl_response.rb +39 -0
  153. data/lib/ruby_smb/smb2/packet/logoff_request.rb +1 -4
  154. data/lib/ruby_smb/smb2/packet/logoff_response.rb +1 -4
  155. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +1 -1
  156. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +1 -1
  157. data/lib/ruby_smb/smb2/packet/query_directory_request.rb +35 -0
  158. data/lib/ruby_smb/smb2/packet/query_directory_response.rb +45 -0
  159. data/lib/ruby_smb/smb2/packet/read_request.rb +30 -0
  160. data/lib/ruby_smb/smb2/packet/read_response.rb +26 -0
  161. data/lib/ruby_smb/smb2/packet/session_setup_request.rb +2 -5
  162. data/lib/ruby_smb/smb2/packet/session_setup_response.rb +4 -7
  163. data/lib/ruby_smb/smb2/packet/set_info_request.rb +58 -0
  164. data/lib/ruby_smb/smb2/packet/set_info_response.rb +20 -0
  165. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +3 -4
  166. data/lib/ruby_smb/smb2/packet/tree_connect_response.rb +5 -9
  167. data/lib/ruby_smb/smb2/packet/tree_disconnect_request.rb +1 -4
  168. data/lib/ruby_smb/smb2/packet/tree_disconnect_response.rb +1 -4
  169. data/lib/ruby_smb/smb2/packet/write_request.rb +29 -0
  170. data/lib/ruby_smb/smb2/packet/write_response.rb +26 -0
  171. data/lib/ruby_smb/smb2/tree.rb +163 -7
  172. data/lib/ruby_smb/version.rb +1 -1
  173. data/spec/lib/ruby_smb/client_spec.rb +459 -120
  174. data/spec/lib/ruby_smb/dcerpc/bind_spec.rb +14 -0
  175. data/spec/lib/ruby_smb/dcerpc/handle_spec.rb +31 -0
  176. data/spec/lib/ruby_smb/dcerpc/request_spec.rb +21 -0
  177. data/spec/lib/ruby_smb/dcerpc/response_spec.rb +15 -0
  178. data/spec/lib/ruby_smb/dcerpc/srvsvc_spec.rb +13 -0
  179. data/spec/lib/ruby_smb/dcerpc/uuid_spec.rb +12 -0
  180. data/spec/lib/ruby_smb/dispatcher/base_spec.rb +26 -0
  181. data/spec/lib/ruby_smb/dispatcher/socket_spec.rb +118 -18
  182. data/spec/lib/ruby_smb/field/extended_attribute_flag_spec.rb +0 -3
  183. data/spec/lib/ruby_smb/field/file_time_spec.rb +4 -2
  184. data/spec/lib/ruby_smb/field/security_descriptor.rb +0 -1
  185. data/spec/lib/ruby_smb/field/smb2_fileid_spec.rb +10 -0
  186. data/spec/lib/ruby_smb/field/smb_fea_list_spec.rb +3 -5
  187. data/spec/lib/ruby_smb/field/smb_gea_list_spec.rb +37 -0
  188. data/spec/lib/ruby_smb/field/smb_gea_spec.rb +22 -0
  189. data/spec/lib/ruby_smb/field/stringz16_spec.rb +7 -9
  190. data/spec/lib/ruby_smb/field/utime_spec.rb +4 -2
  191. data/spec/lib/ruby_smb/{field → fscc}/ea_info_array_spec.rb +7 -9
  192. data/spec/lib/ruby_smb/{field → fscc}/file_full_ea_info_spec.rb +2 -3
  193. data/spec/lib/ruby_smb/fscc/file_information/file_both_directory_information_spec.rb +71 -0
  194. data/spec/lib/ruby_smb/fscc/file_information/file_directory_information_spec.rb +68 -0
  195. data/spec/lib/ruby_smb/fscc/file_information/file_disposition_information_spec.rb +26 -0
  196. data/spec/lib/ruby_smb/fscc/file_information/file_full_directory_information_spec.rb +69 -0
  197. data/spec/lib/ruby_smb/fscc/file_information/file_id_both_directory_information_spec.rb +72 -0
  198. data/spec/lib/ruby_smb/fscc/file_information/file_id_full_directory_information_spec.rb +70 -0
  199. data/spec/lib/ruby_smb/fscc/file_information/file_names_information_spec.rb +41 -0
  200. data/spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb +133 -0
  201. data/spec/lib/ruby_smb/fscc/fscc_file_attributes_spec.rb +143 -0
  202. data/spec/lib/ruby_smb/generic_packet_spec.rb +46 -21
  203. data/spec/lib/ruby_smb/nbss/negative_session_response_spec.rb +29 -0
  204. data/spec/lib/ruby_smb/nbss/session_header_spec.rb +30 -0
  205. data/spec/lib/ruby_smb/nbss/session_request_spec.rb +30 -0
  206. data/spec/lib/ruby_smb/smb1/bit_field/create_options_spec.rb +9 -1
  207. data/spec/lib/ruby_smb/smb1/bit_field/directory_access_mask_spec.rb +0 -2
  208. data/spec/lib/ruby_smb/smb1/bit_field/file_access_mask_spec.rb +0 -2
  209. data/spec/lib/ruby_smb/smb1/bit_field/file_status_flags_spec.rb +35 -0
  210. data/spec/lib/ruby_smb/smb1/bit_field/open2_access_mode_spec.rb +1 -3
  211. data/spec/lib/ruby_smb/smb1/bit_field/open2_flags_spec.rb +0 -2
  212. data/spec/lib/ruby_smb/smb1/bit_field/open2_open_mode_spec.rb +0 -1
  213. data/spec/lib/ruby_smb/smb1/bit_field/optional_support_spec.rb +0 -1
  214. data/spec/lib/ruby_smb/smb1/bit_field/security_flags_spec.rb +26 -0
  215. data/spec/lib/ruby_smb/smb1/bit_field/share_access_spec.rb +0 -3
  216. data/spec/lib/ruby_smb/smb1/bit_field/smb_ext_file_attributes_spec.rb +20 -39
  217. data/spec/lib/ruby_smb/smb1/bit_field/smb_file_attributes_spec.rb +0 -6
  218. data/spec/lib/ruby_smb/smb1/bit_field/smb_nmpipe_status_spec.rb +0 -2
  219. data/spec/lib/ruby_smb/smb1/bit_field/trans2_flags_spec.rb +0 -2
  220. data/spec/lib/ruby_smb/smb1/bit_field/tree_connect_flags_spec.rb +0 -2
  221. data/spec/lib/ruby_smb/smb1/file_spec.rb +469 -0
  222. data/spec/lib/ruby_smb/smb1/packet/close_request_spec.rb +54 -0
  223. data/spec/lib/ruby_smb/smb1/packet/close_response_spec.rb +45 -0
  224. data/spec/lib/ruby_smb/smb1/packet/echo_request_spec.rb +1 -4
  225. data/spec/lib/ruby_smb/smb1/packet/echo_response_spec.rb +1 -4
  226. data/spec/lib/ruby_smb/smb1/packet/error_packet_spec.rb +1 -3
  227. data/spec/lib/ruby_smb/smb1/packet/logoff_request_spec.rb +1 -4
  228. data/spec/lib/ruby_smb/smb1/packet/logoff_response_spec.rb +1 -4
  229. data/spec/lib/ruby_smb/smb1/packet/negotiate_request_spec.rb +1 -1
  230. data/spec/lib/ruby_smb/smb1/packet/negotiate_response_extended_spec.rb +37 -0
  231. data/spec/lib/ruby_smb/smb1/packet/negotiate_response_spec.rb +37 -0
  232. data/spec/lib/ruby_smb/smb1/packet/nt_create_andx_request_spec.rb +151 -0
  233. data/spec/lib/ruby_smb/smb1/packet/nt_create_andx_response_spec.rb +157 -0
  234. data/spec/lib/ruby_smb/smb1/packet/nt_trans/create_request_spec.rb +13 -6
  235. data/spec/lib/ruby_smb/smb1/packet/nt_trans/create_response_spec.rb +1 -7
  236. data/spec/lib/ruby_smb/smb1/packet/nt_trans/request_spec.rb +1 -6
  237. data/spec/lib/ruby_smb/smb1/packet/nt_trans/response_spec.rb +1 -5
  238. data/spec/lib/ruby_smb/smb1/packet/read_andx_request_spec.rb +149 -0
  239. data/spec/lib/ruby_smb/smb1/packet/read_andx_response_spec.rb +93 -0
  240. data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_request_spec.rb +1 -5
  241. data/spec/lib/ruby_smb/smb1/packet/session_setup_legacy_response_spec.rb +1 -5
  242. data/spec/lib/ruby_smb/smb1/packet/session_setup_request_spec.rb +3 -8
  243. data/spec/lib/ruby_smb/smb1/packet/session_setup_response_spec.rb +2 -4
  244. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_request_spec.rb +180 -0
  245. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_response_spec.rb +104 -0
  246. data/spec/lib/ruby_smb/smb1/packet/trans2/find_information_level/find_file_full_directory_info_spec.rb +128 -0
  247. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_request_spec.rb +174 -0
  248. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_response_spec.rb +102 -0
  249. data/spec/lib/ruby_smb/smb1/packet/trans2/open2_request_spec.rb +1 -6
  250. data/spec/lib/ruby_smb/smb1/packet/trans2/open2_response_spec.rb +2 -7
  251. data/spec/lib/ruby_smb/smb1/packet/trans2/request_secondary_spec.rb +1 -5
  252. data/spec/lib/ruby_smb/smb1/packet/trans2/request_spec.rb +1 -5
  253. data/spec/lib/ruby_smb/smb1/packet/trans2/response_spec.rb +1 -4
  254. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_request_spec.rb +98 -0
  255. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_response_spec.rb +56 -0
  256. data/spec/lib/ruby_smb/smb1/packet/tree_connect_request_spec.rb +1 -5
  257. data/spec/lib/ruby_smb/smb1/packet/tree_connect_response_spec.rb +1 -6
  258. data/spec/lib/ruby_smb/smb1/packet/tree_disconnect_request_spec.rb +1 -4
  259. data/spec/lib/ruby_smb/smb1/packet/tree_disconnect_response_spec.rb +1 -4
  260. data/spec/lib/ruby_smb/smb1/packet/write_andx_request_spec.rb +148 -0
  261. data/spec/lib/ruby_smb/smb1/packet/write_andx_response_spec.rb +54 -0
  262. data/spec/lib/ruby_smb/smb1/tree_spec.rb +409 -7
  263. data/spec/lib/ruby_smb/smb2/bit_field/directory_access_mask_spec.rb +0 -2
  264. data/spec/lib/ruby_smb/smb2/bit_field/file_access_mask_spec.rb +0 -2
  265. data/spec/lib/ruby_smb/smb2/bit_field/session_flags_spec.rb +1 -1
  266. data/spec/lib/ruby_smb/smb2/bit_field/share_capabilities_spec.rb +0 -1
  267. data/spec/lib/ruby_smb/smb2/bit_field/share_flags_spec.rb +0 -2
  268. data/spec/lib/ruby_smb/smb2/create_context_spec.rb +42 -0
  269. data/spec/lib/ruby_smb/smb2/file_spec.rb +233 -0
  270. data/spec/lib/ruby_smb/smb2/packet/close_request_spec.rb +40 -0
  271. data/spec/lib/ruby_smb/smb2/packet/close_response_spec.rb +40 -0
  272. data/spec/lib/ruby_smb/smb2/packet/create_request_spec.rb +101 -0
  273. data/spec/lib/ruby_smb/smb2/packet/create_response_spec.rb +64 -0
  274. data/spec/lib/ruby_smb/smb2/packet/echo_request_spec.rb +1 -3
  275. data/spec/lib/ruby_smb/smb2/packet/echo_response_spec.rb +1 -3
  276. data/spec/lib/ruby_smb/smb2/packet/ioctl_request_spec.rb +48 -0
  277. data/spec/lib/ruby_smb/smb2/packet/logoff_request_spec.rb +1 -3
  278. data/spec/lib/ruby_smb/smb2/packet/logoff_response_spec.rb +1 -3
  279. data/spec/lib/ruby_smb/smb2/packet/query_directory_request_spec.rb +80 -0
  280. data/spec/lib/ruby_smb/smb2/packet/query_directory_response_spec.rb +64 -0
  281. data/spec/lib/ruby_smb/smb2/packet/read_request_spec.rb +43 -0
  282. data/spec/lib/ruby_smb/smb2/packet/read_response_spec.rb +50 -0
  283. data/spec/lib/ruby_smb/smb2/packet/session_setup_request_spec.rb +3 -4
  284. data/spec/lib/ruby_smb/smb2/packet/session_setup_response_spec.rb +2 -3
  285. data/spec/lib/ruby_smb/smb2/packet/set_info_request_spec.rb +205 -0
  286. data/spec/lib/ruby_smb/smb2/packet/set_info_response_spec.rb +32 -0
  287. data/spec/lib/ruby_smb/smb2/packet/tree_connect_request_spec.rb +3 -5
  288. data/spec/lib/ruby_smb/smb2/packet/tree_connect_response_spec.rb +1 -2
  289. data/spec/lib/ruby_smb/smb2/packet/tree_disconnect_request_spec.rb +1 -3
  290. data/spec/lib/ruby_smb/smb2/packet/tree_disconnect_response_spec.rb +1 -3
  291. data/spec/lib/ruby_smb/smb2/packet/write_request_spec.rb +51 -0
  292. data/spec/lib/ruby_smb/smb2/packet/write_response_spec.rb +38 -0
  293. data/spec/lib/ruby_smb/smb2/tree_spec.rb +191 -5
  294. data/spec/spec_helper.rb +1 -1
  295. metadata +195 -12
  296. metadata.gz.sig +0 -0
  297. data/lib/ruby_smb/smb1/dispositions.rb +0 -36
  298. data/spec/lib/ruby_smb/dispatcher/dispatcher_base_spec.rb +0 -22
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ include RubySMB::SMB1::Packet::Trans2::FindInformationLevel
4
+
5
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::FindNext2Response do
6
+ subject(:packet) { described_class.new }
7
+
8
+ describe '#smb_header' do
9
+ subject(:header) { packet.smb_header }
10
+
11
+ it 'is a standard SMB Header' do
12
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
13
+ end
14
+
15
+ it 'should have the command set to SMB_COM_NEGOTIATE' do
16
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
17
+ end
18
+
19
+ it 'should have the response flag set' do
20
+ expect(header.flags.reply).to eq 1
21
+ end
22
+ end
23
+
24
+ describe '#parameter_block' do
25
+ subject(:parameter_block) { packet.parameter_block }
26
+
27
+ it 'should have the setup set to the OPEN2 subcommand' do
28
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::FIND_NEXT2
29
+ end
30
+ end
31
+
32
+ describe '#data_block' do
33
+ subject(:data_block) { packet.data_block }
34
+
35
+ it { is_expected.to respond_to :name }
36
+ it { is_expected.to respond_to :trans2_parameters }
37
+ it { is_expected.to respond_to :trans2_data }
38
+
39
+ it 'should keep #trans2_parameters 4-byte aligned' do
40
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
41
+ end
42
+
43
+ it 'should keep #trans2_data 4-byte aligned' do
44
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
45
+ end
46
+
47
+ describe '#trans2_parameters' do
48
+ subject(:parameters) { data_block.trans2_parameters }
49
+
50
+ it { is_expected.to respond_to :search_count }
51
+ it { is_expected.to respond_to :eos }
52
+ it { is_expected.to respond_to :ea_error_offset }
53
+ it { is_expected.to respond_to :last_name_offset }
54
+ end
55
+
56
+ describe '#trans2_data' do
57
+ subject(:data) { data_block.trans2_data }
58
+
59
+ it { is_expected.to respond_to :buffer }
60
+ end
61
+ end
62
+
63
+ describe '#results' do
64
+ let(:names1) {
65
+ names = FindFileFullDirectoryInfo.new
66
+ names.file_name = 'test.txt'
67
+ names.next_offset = names.do_num_bytes
68
+ names
69
+ }
70
+
71
+ let(:names2) {
72
+ names = FindFileFullDirectoryInfo.new
73
+ names.file_name = '..'
74
+ names
75
+ }
76
+
77
+ let(:names_array) { [names1, names2] }
78
+
79
+ let(:names_blob) { names_array.collect(&:to_binary_s).join('') }
80
+
81
+ it 'returns an array of parsed FindFileFullDirectoryInfo structs' do
82
+ packet.data_block.trans2_data.buffer = names_blob
83
+ expect(packet.results(FindFileFullDirectoryInfo, unicode: false)).to eq names_array
84
+ end
85
+
86
+ it 'sets the FindFileFullDirectoryInfo unicode attribute when unicode argument is true' do
87
+ packet.data_block.trans2_data.buffer = names1.to_binary_s
88
+ find_info = FindFileFullDirectoryInfo.new
89
+ allow(FindFileFullDirectoryInfo).to receive(:new).and_return find_info
90
+ expect(find_info).to receive(:unicode=).with(true).once
91
+ packet.results(FindFileFullDirectoryInfo, unicode: true)
92
+ end
93
+
94
+ it 'does not set the FindFileFullDirectoryInfo unicode attribute when unicode argument is false' do
95
+ packet.data_block.trans2_data.buffer = names1.to_binary_s
96
+ find_info = FindFileFullDirectoryInfo.new
97
+ allow(FindFileFullDirectoryInfo).to receive(:new).and_return find_info
98
+ expect(find_info).to receive(:unicode=).with(false).once
99
+ packet.results(FindFileFullDirectoryInfo, unicode: false)
100
+ end
101
+ end
102
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Request do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -30,7 +29,6 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Request do
30
29
  it 'should have the setup set to the OPEN2 subcommand' do
31
30
  expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::OPEN2
32
31
  end
33
-
34
32
  end
35
33
 
36
34
  describe '#data_block' do
@@ -105,8 +103,5 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Request do
105
103
  end
106
104
  end
107
105
  end
108
-
109
106
  end
110
-
111
-
112
- end
107
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Response do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -49,8 +48,6 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Response do
49
48
  describe '#trans2_parameters' do
50
49
  subject(:parameters) { data_block.trans2_parameters }
51
50
 
52
- it { is_expected.to be_a RubySMB::SMB1::Packet::Trans2::Open2Response::Trans2Parameters }
53
-
54
51
  it { is_expected.to respond_to :fid }
55
52
  it { is_expected.to respond_to :file_attributes }
56
53
  it { is_expected.to respond_to :creation_time }
@@ -86,7 +83,7 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Response do
86
83
  end
87
84
 
88
85
  describe '#action_taken' do
89
- subject(:action) { parameters.action_taken}
86
+ subject(:action) { parameters.action_taken }
90
87
 
91
88
  it 'is 2-bytes' do
92
89
  expect(action.do_num_bytes).to eq 2
@@ -102,6 +99,4 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Open2Response do
102
99
  end
103
100
  end
104
101
  end
105
-
106
-
107
- end
102
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::Trans2::RequestSecondary do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -70,8 +69,5 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::RequestSecondary do
70
69
  it 'is a standard DataBlock' do
71
70
  expect(data_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::DataBlock
72
71
  end
73
-
74
72
  end
75
-
76
-
77
- end
73
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::Trans2::Request do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -91,8 +90,5 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Request do
91
90
  data_block.trans2_parameters = 'a'
92
91
  expect(data_block.trans2_data.abs_offset % 4).to eq 0
93
92
  end
94
-
95
93
  end
96
-
97
-
98
- end
94
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::Trans2::Response do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -83,6 +82,4 @@ RSpec.describe RubySMB::SMB1::Packet::Trans2::Response do
83
82
  expect(data_block.trans2_data.abs_offset % 4).to eq 0
84
83
  end
85
84
  end
86
-
87
-
88
- end
85
+ end
@@ -0,0 +1,98 @@
1
+ include RubySMB::Fscc::FileInformation
2
+
3
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationRequest do
4
+ subject(:packet) { described_class.new }
5
+
6
+ describe '#smb_header' do
7
+ subject(:header) { packet.smb_header }
8
+
9
+ it 'is a standard SMB Header' do
10
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
11
+ end
12
+
13
+ it 'should have the command set to SMB_COM_TRANSACTION2' do
14
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
15
+ end
16
+
17
+ it 'should not have the response flag set' do
18
+ expect(header.flags.reply).to eq 0
19
+ end
20
+ end
21
+
22
+ describe '#parameter_block' do
23
+ subject(:parameter_block) { packet.parameter_block }
24
+
25
+ it 'is a standard ParameterBlock' do
26
+ expect(parameter_block).to be_a RubySMB::SMB1::Packet::Trans2::Request::ParameterBlock
27
+ end
28
+
29
+ it 'should have the setup set to the OPEN2 subcommand' do
30
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::SET_FILE_INFORMATION
31
+ end
32
+ end
33
+
34
+ describe '#data_block' do
35
+ subject(:data_block) { packet.data_block }
36
+
37
+ it 'is a standard DataBlock' do
38
+ expect(data_block).to be_a RubySMB::SMB1::DataBlock
39
+ end
40
+
41
+ it { is_expected.to respond_to :name }
42
+ it { is_expected.to respond_to :trans2_parameters }
43
+ it { is_expected.to respond_to :trans2_data }
44
+
45
+ it 'should keep #trans2_parameters 4-byte aligned' do
46
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
47
+ end
48
+
49
+ it 'should keep #trans2_data 4-byte aligned' do
50
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
51
+ end
52
+
53
+ describe '#trans2_parameters' do
54
+ subject(:parameters) { data_block.trans2_parameters }
55
+
56
+ it { is_expected.to respond_to :fid }
57
+ it { is_expected.to respond_to :information_level }
58
+
59
+ describe '#fid' do
60
+ it 'is a 16-bit field' do
61
+ expect(parameters.fid).to be_a BinData::Uint16le
62
+ end
63
+ end
64
+
65
+ describe '#information_level' do
66
+ it 'is a 16-bit field' do
67
+ expect(parameters.information_level).to be_a BinData::Uint16le
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#trans2_data' do
73
+ subject(:data) { data_block.trans2_data }
74
+
75
+ it { is_expected.to respond_to :info_level_struct }
76
+
77
+ describe '#info_level_struct' do
78
+ context 'when #information_level field is FILE_DISPOSITION_INFORMATION with the pass-through capability'
79
+ it 'is a FileDispositionInformation structure' do
80
+ info_level = FILE_DISPOSITION_INFORMATION + SMB_INFO_PASSTHROUGH
81
+ data_block.trans2_parameters.information_level = info_level
82
+ file_info = FileDispositionInformation.new
83
+ expect(data.info_level_struct).to eq file_info
84
+ end
85
+
86
+ context 'when #information_level field is FILE_RENAME_INFORMATION with the pass-through capability'
87
+ it 'is a FileRenameInformation structure' do
88
+ info_level = FILE_RENAME_INFORMATION + SMB_INFO_PASSTHROUGH
89
+ data_block.trans2_parameters.information_level = info_level
90
+ file_info = FileRenameInformation.new
91
+ expect(data.info_level_struct).to eq file_info
92
+ end
93
+ end
94
+ end
95
+
96
+ end
97
+ end
98
+
@@ -0,0 +1,56 @@
1
+ RSpec.describe RubySMB::SMB1::Packet::Trans2::SetFileInformationResponse do
2
+ subject(:packet) { described_class.new }
3
+
4
+ describe '#smb_header' do
5
+ subject(:header) { packet.smb_header }
6
+
7
+ it 'is a standard SMB Header' do
8
+ expect(header).to be_a RubySMB::SMB1::SMBHeader
9
+ end
10
+
11
+ it 'should have the command set to SMB_COM_NEGOTIATE' do
12
+ expect(header.command).to eq RubySMB::SMB1::Commands::SMB_COM_TRANSACTION2
13
+ end
14
+
15
+ it 'should have the response flag set' do
16
+ expect(header.flags.reply).to eq 1
17
+ end
18
+ end
19
+
20
+ describe '#parameter_block' do
21
+ subject(:parameter_block) { packet.parameter_block }
22
+
23
+ it 'should have the setup set to the OPEN2 subcommand' do
24
+ expect(parameter_block.setup).to include RubySMB::SMB1::Packet::Trans2::Subcommands::SET_FILE_INFORMATION
25
+ end
26
+ end
27
+
28
+ describe '#data_block' do
29
+ subject(:data_block) { packet.data_block }
30
+
31
+ it { is_expected.to respond_to :name }
32
+ it { is_expected.to respond_to :trans2_parameters }
33
+ it { is_expected.to respond_to :trans2_data }
34
+
35
+ it 'should keep #trans2_parameters 4-byte aligned' do
36
+ expect(data_block.trans2_parameters.abs_offset % 4).to eq 0
37
+ end
38
+
39
+ it 'should keep #trans2_data 4-byte aligned' do
40
+ expect(data_block.trans2_data.abs_offset % 4).to eq 0
41
+ end
42
+
43
+ describe '#trans2_parameters' do
44
+ subject(:parameters) { data_block.trans2_parameters }
45
+
46
+ it { is_expected.to respond_to :ea_error_offset }
47
+
48
+ describe '#ea_error_offset' do
49
+ it 'is a 16-bit field' do
50
+ expect(parameters.ea_error_offset).to be_a BinData::Uint16le
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::TreeConnectRequest do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -46,8 +45,5 @@ RSpec.describe RubySMB::SMB1::Packet::TreeConnectRequest do
46
45
  it { is_expected.to respond_to :password }
47
46
  it { is_expected.to respond_to :path }
48
47
  it { is_expected.to respond_to :service }
49
-
50
48
  end
51
-
52
-
53
- end
49
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::TreeConnectResponse do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -35,7 +34,6 @@ RSpec.describe RubySMB::SMB1::Packet::TreeConnectResponse do
35
34
  it 'has an AndXBlock' do
36
35
  expect(parameter_block.andx_block).to be_a RubySMB::SMB1::AndXBlock
37
36
  end
38
-
39
37
  end
40
38
 
41
39
  describe '#data_block' do
@@ -47,7 +45,6 @@ RSpec.describe RubySMB::SMB1::Packet::TreeConnectResponse do
47
45
 
48
46
  it { is_expected.to respond_to :service }
49
47
  it { is_expected.to respond_to :native_file_system }
50
-
51
48
  end
52
49
 
53
50
  context 'when the connect is to a directory' do
@@ -80,7 +77,5 @@ RSpec.describe RubySMB::SMB1::Packet::TreeConnectResponse do
80
77
  it 'returns a FileAccessMask from #guest_access_rights' do
81
78
  expect(file_response.guest_access_rights).to be_a RubySMB::SMB1::BitField::FileAccessMask
82
79
  end
83
-
84
80
  end
85
-
86
- end
81
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::TreeDisconnectRequest do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -35,6 +34,4 @@ RSpec.describe RubySMB::SMB1::Packet::TreeDisconnectRequest do
35
34
  expect(data_block).to be_a RubySMB::SMB1::DataBlock
36
35
  end
37
36
  end
38
-
39
-
40
- end
37
+ end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RubySMB::SMB1::Packet::TreeDisconnectResponse do
4
-
5
4
  subject(:packet) { described_class.new }
6
5
 
7
6
  describe '#smb_header' do
@@ -35,6 +34,4 @@ RSpec.describe RubySMB::SMB1::Packet::TreeDisconnectResponse do
35
34
  expect(data_block).to be_a RubySMB::SMB1::DataBlock
36
35
  end
37
36
  end
38
-
39
-
40
- end
37
+ end