miketeo / pysmb

pysmb is an experimental SMB/CIFS library written in Python. It implements the client-side SMB/CIFS protocol (SMB1 and SMB2) which allows your Python application to access and transfer files to/from SMB/CIFS shared folders like your Windows file sharing and Samba folders.
Other
341 stars 94 forks source link

getAttributes returns incorrect values #7

Closed scfarley closed 10 years ago

scfarley commented 10 years ago

If I create a file on the test server, the values returned by getAttributes() are incorrect while the values returned for the same file by listPath are correct.

listPath is correct on everything but possibly not the short_name attribute. alloc_size seems big even for listPath. The file in question is 13 bytes and takes 2048 bytes (4 512-byte blocks) on disk. However, I do not know what Samba v3.6.24 is reporting. getAttributes does not return Unicode for the filename attribute.

Information retrieved by listPath: {'alloc_size': 1048576, 'create_time': 1405439522.0, 'file_attributes': 32, 'file_size': 13, 'filename': u'info.txt', 'last_access_time': 1405439522.0, 'last_attr_change_time': 1405439522.0, 'last_write_time': 1405439522.0, 'short_name': u'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}

getAttributes: {'alloc_size': 4503599627370496, 'create_time': 130499131220000000, 'file_attributes': 32, 'file_size': 55834574848, 'filename': 'info.txt', 'last_access_time': 130499131220000000, 'last_attr_change_time': 130499131220000000, 'last_write_time': 130499131220000000, 'short_name': 'info.txt'}

miketeo commented 10 years ago

Are you able to send me the tcpdump / wireshark capture when you run the listPath and the getAttributes test? It looks like that there is a packet decoding issue.

scfarley commented 10 years ago

I took dumps of a directory with only one file (info.txt): https://file.ac/AgVSYkwzd38/

Stat of the file: mode 33252 size 13 atime 1405440494 mtime 1405439522 ctime 1405439522 blksize 16384 blocks 4

miketeo commented 10 years ago

Hi, I have patched the code to fix a decoding bug. Can you help to test the new code to see if it works on your system?

http://pastebin.com/raw.php?i=hfVN1PdV Overwrite the base.py at pysmb/python2/smb with the contents of this pastebin.

Thank you.

scfarley commented 10 years ago

Found some time to test it. The changes fixed alloc_size and file_size.

Patched getAttributes:

{
  'alloc_size': 1048576,
  'create_time': 130513043780000000,
  'file_attributes': 32,
  'file_size': 13,
  'filename': u'info.txt',
  'isDirectory': False,
  'isReadOnly': False,
  'last_access_time': 130513043780000000,
  'last_attr_change_time': 130513043780000000,
  'last_write_time': 130513043780000000,
  'short_name': u'info.txt'
}
miketeo commented 10 years ago

Great. I will do another release for this patch once I have addressed another separate issue on pysmb. Thank you for helping out with the testing.

3lixy commented 7 years ago

Very nice library so far. Was quite easy to use.

I have across a similar issue.

I have used pysmb against two different hosts so far.

The host running the pysmb code is not running either of the 2 samba servers mentioned below.

using pysmb on host1 responds with an FLOAT e.g. 1493547711.0 for class smb.base.SharedFile last_attr_change_time/last_write_time. when the int is converted to datetime object it matches what windows/unix shows for the mod date time.

using pysmb on host2 responds with an INT e.g. 131484122757121460 for class smb.base.SharedFile last_attr_change_time/last_write_time. when the int is converted to datetime object python fails on ValueError: timestamp out of range for platform localtime()/gmtime() function.

below is the packet response from the smb host2 server pysmb_FreeNAS-8.3.1-RELEASE-p2-x64 _smb3.6.13.pcap.zip

host running pysmb Python 2.7.9 pysmb-1.1.20 Linux revo-vpn-74 3.16.0-4-amd64 #1 SMP Debian 3.16.39-1+deb8u1 (2017-02-22) x86_64 GNU/Linux PRETTY_NAME="Debian GNU/Linux 8 (jessie)" NAME="Debian GNU/Linux" VERSION_ID="8" VERSION="8 (jessie)" ID=debian HOME_URL="http://www.debian.org/" SUPPORT_URL="http://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

host2 serving samba share FreeNAS-8.3.1-RELEASE-p2-x64 smb3.6.13 nmb3.6.13

$ stat --printf="Change %z\nAccess %x\nModify %y\n" B Change 2017-08-28 17:44:35.712146000 +0100 Access 2013-08-03 09:42:31.000000000 +0100 Modify 2017-08-28 17:44:35.712146000 +0100

wireshark showing the correct values for packet. pysmb_freenas-8 3 1-release-p2-x64 _smb3 6 13 pcap

reponse from server for attributes 0000 45 00 00 c0 68 c9 40 00 3f 06 06 d1 c0 a8 00 12 0010 0a de 00 06 00 8b 8d 73 56 9b dc 03 60 a0 93 c4 0020 80 18 20 71 90 99 00 00 01 01 08 0a 23 8f 73 14 0030 ee 56 0c 54 00 00 00 88 ff 53 4d 42 32 00 00 00 0040 00 88 03 c8 00 00 00 00 00 00 00 00 00 00 00 00 0050 01 00 5d 70 64 00 06 00 0a 02 00 4c 00 00 00 02 0060 00 38 00 00 00 4c 00 3c 00 00 00 00 00 51 00 00 0070 00 00 00 00 96 f9 05 4a 33 90 ce 01 80 75 39 64 0080 25 90 ce 01 b4 c5 8a ee 1c 20 d3 01 b4 c5 8a ee 0090 1c 20 d3 01 10 00 00 00 00 00 00 00 00 00 00 00 00a0 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00b0 00 01 00 00 00 00 00 00 04 00 00 00 5c 00 42 00