Converting binary sid's to a hex string

L

LittlePython

I am trying to create a hexstring of a NT4 user account sid which I can in
turn use to query an exchange 55 database. I believe I need to convert a
binary sid to a hex string. ADsSID com object will do this for me however it
is a little slow. Can anybody point me in the right direction to converting
a PySID to a hexstring.
Thx

import win32netcon
import win32net
import win32security
def report():
resume = 0
while 1:
filter = win32netcon.FILTER_NORMAL_ACCOUNT
data, total, resume = win32net.NetUserEnum('nt4pridc1', 20, filter,
resume)
for user in data:
MySid, string, int = win32security.LookupAccountName('nt4pridc1',
user['name'])
sString = win32security.ConvertSidToStringSid(MySid)
print MySid
print sString
if resume ==0:
break

report()
## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
## I need this , I believe this is a hex string of the SID
## 010500000000000515000000BB0B4815C33A022074381B7409050000
 
R

Roger Upole

You can use the binascii module to convert the raw
bytes of the sid to hex.

binascii.b2a_hex(buffer(MySid))

Roger

LittlePython said:
I am trying to create a hexstring of a NT4 user account sid which I can in
turn use to query an exchange 55 database. I believe I need to convert a
binary sid to a hex string. ADsSID com object will do this for me however it
is a little slow. Can anybody point me in the right direction to converting
a PySID to a hexstring.
Thx

import win32netcon
import win32net
import win32security
def report():
resume = 0
while 1:
filter = win32netcon.FILTER_NORMAL_ACCOUNT
data, total, resume = win32net.NetUserEnum('nt4pridc1', 20, filter,
resume)
for user in data:
MySid, string, int = win32security.LookupAccountName('nt4pridc1',
user['name'])
sString = win32security.ConvertSidToStringSid(MySid)
print MySid
print sString
if resume ==0:
break

report()
## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
## I need this , I believe this is a hex string of the SID
## 010500000000000515000000BB0B4815C33A022074381B7409050000
 
L

LittlePython

Thx Roger, I have been off line for a few days. I am sorry not to reply
earlier. I will try this, but I am not sure what "buffer" does ( I am a
newbie to python).


Roger Upole said:
You can use the binascii module to convert the raw
bytes of the sid to hex.

binascii.b2a_hex(buffer(MySid))

Roger

I am trying to create a hexstring of a NT4 user account sid which I can in
turn use to query an exchange 55 database. I believe I need to convert a
binary sid to a hex string. ADsSID com object will do this for me however it
is a little slow. Can anybody point me in the right direction to converting
a PySID to a hexstring.
Thx

import win32netcon
import win32net
import win32security
def report():
resume = 0
while 1:
filter = win32netcon.FILTER_NORMAL_ACCOUNT
data, total, resume = win32net.NetUserEnum('nt4pridc1', 20, filter,
resume)
for user in data:
MySid, string, int = win32security.LookupAccountName('nt4pridc1',
user['name'])
sString = win32security.ConvertSidToStringSid(MySid)
print MySid
print sString
if resume ==0:
break

report()
## sString prints = S-1-5-21-357043131-537017027-1947940980-1289
## MySid prints = PySID:S-1-5-21-357043131-537017027-1947940980-1289
## I need this , I believe this is a hex string of the SID
## 010500000000000515000000BB0B4815C33A022074381B7409050000




----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top