日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux smb 所有者,python-3.x - 在Linux上使用python从smb共享中获取文件的所有者。 - SO中文参考 - www.soinside.com...

發布時間:2023/12/31 linux 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux smb 所有者,python-3.x - 在Linux上使用python从smb共享中获取文件的所有者。 - SO中文参考 - www.soinside.com... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這簡直不是一件小事,可惜答案并不像我希望的那樣簡單。

如果以后有人會被這個同樣的問題困擾,我就把這個答案貼出來,但希望也許有人能早點貼出更好的解決方案來

為了找到主人,我用 本庫及其實例:from smb.SMBConnection import SMBConnection

conn = SMBConnection(username='', password='', domain=', my_name='', remote_name='')

conn.connect('')

sec_att = conn.getSecurity('', r'\some\file\path')

owner_sid = sec_att.owner

問題是 pysmb 包只能給你所有者的SID,而不是他的名字。為了得到他的名字,你需要 做一個ldap查詢,就像這個答案一樣。 (轉貼代碼)。from ldap3 import Server, Connection, ALL

from ldap3.utils.conv import escape_bytes

s = Server('my_server', get_info=ALL)

c = Connection(s, 'my_user', 'my_password')

c.bind()

binary_sid = b'....' # your sid must be in binary format

c.search('my_base', '(objectsid=' + escape_bytes(binary_sid) + ')', attributes=['objectsid', 'samaccountname'])

print(c.entries)

但當然沒有什么是容易的,我花了好幾個小時才找到一種方法 在python中把字符串SID轉換為二進制SID。最后這就解決了:# posting the needed functions and omitting the class part

def byte(strsid):

'''

Convert a SID into bytes

strdsid - SID to convert into bytes

'''

sid = str.split(strsid, '-')

ret = bytearray()

sid.remove('S')

for i in range(len(sid)):

sid[i] = int(sid[i])

sid.insert(1, len(sid)-2)

ret += longToByte(sid[0], size=1)

ret += longToByte(sid[1], size=1)

ret += longToByte(sid[2], False, 6)

for i in range(3, len(sid)):

ret += cls.longToByte(sid[i])

return ret

def byteToLong(byte, little_endian=True):

'''

Convert bytes into a Python integer

byte - bytes to convert

little_endian - True (default) or False for little or big endian

'''

if len(byte) > 8:

raise Exception('Bytes too long. Needs to be <= 8 or 64bit')

else:

if little_endian:

a = byte.ljust(8, b'\x00')

return struct.unpack('

else:

a = byte.rjust(8, b'\x00')

return struct.unpack('>q', a)[0]

... 最后你有完整的解決方案!享受:(

總結

以上是生活随笔為你收集整理的linux smb 所有者,python-3.x - 在Linux上使用python从smb共享中获取文件的所有者。 - SO中文参考 - www.soinside.com...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。