Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. import logging
  2.  
  3. logging.basicConfig(level=logging.DEBUG)
  4.  
  5. import collections
  6. import os
  7.  
  8. from smb.smb_constants import FILE_READ_DATA
  9. from smb.SMBConnection import SMBConnection, OperationFailure
  10. from smb.security_descriptors import (
  11. ACE_TYPE_ACCESS_ALLOWED, ACE_TYPE_ACCESS_DENIED,
  12. SID_CREATOR_OWNER, SID_CREATOR_GROUP,
  13. )
  14.  
  15.  
  16. SERVER_IP = '10.0.0.1'
  17. REMOTE_NAME = 'server'
  18. MY_NAME = 'client'
  19. USERNAME = 'username'
  20. PASSWORD = 'password'
  21.  
  22.  
  23. c = SMBConnection(USERNAME, PASSWORD, MY_NAME, REMOTE_NAME)
  24. if not c.connect(SERVER_IP):
  25. raise Exception("Connection failed")
  26.  
  27.  
  28. def traverse_path(service_name, path):
  29. q = collections.deque([path])
  30. while q:
  31. path = q.popleft()
  32. print('Traversing path %r...' % (path,))
  33. for f in c.listPath(service_name, path):
  34. if f.filename in ['.', '..']:
  35. continue
  36. fpath = os.path.join(path, f.filename)
  37. if f.isDirectory:
  38. q.append(fpath)
  39.  
  40. security_descriptor = c.getSecurity(service_name, fpath)
  41.  
  42. if security_descriptor.dacl:
  43. aces = security_descriptor.dacl.aces
  44. else:
  45. aces = []
  46. allowed_sids, denied_sids = set(), set()
  47. for ace in aces:
  48. if ace.isInheritOnly:
  49. # This ACE doesn't apply to this object.
  50. continue
  51. if not ace.mask & FILE_READ_DATA:
  52. continue
  53. sid = str(ace.sid)
  54. if sid == SID_CREATOR_OWNER:
  55. sid == str(security_descriptor.owner)
  56. elif sid == SID_CREATOR_GROUP:
  57. sid == str(security_descriptor.group)
  58. if ace.type == ACE_TYPE_ACCESS_ALLOWED:
  59. allowed_sids.add(sid)
  60. elif ace.type == ACE_TYPE_ACCESS_DENIED:
  61. denied_sids.add(sid)
  62.  
  63. yield fpath, allowed_sids, denied_sids
  64.  
  65. #list(traverse_path('pysmb-test', '/'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement