|
-
February 28th, 2004, 11:43 PM
#1
How can I display the SID(Security Identifier)?
By make a call to LookupAccountName, I can get a SID in buffer, but I don't know the exact structure of SID, so I can not display it properly. Would you please give me some help? Thanks a lot!
-
February 29th, 2004, 12:42 AM
#2
On w2k and above you can use ConvertSidToStringSid,
on nt4 you can use this (From msdn):
Code:
BOOL GetTextualSid(
PSID pSid, // binary SID
LPTSTR TextualSid, // buffer for Textual representation of SID
LPDWORD lpdwBufferLen // required/provided TextualSid buffersize
)
{
PSID_IDENTIFIER_AUTHORITY psia;
DWORD dwSubAuthorities;
DWORD dwSidRev=SID_REVISION;
DWORD dwCounter;
DWORD dwSidSize;
// Validate the binary SID.
if(!IsValidSid(pSid)) return FALSE;
// Get the identifier authority value from the SID.
psia = GetSidIdentifierAuthority(pSid);
// Get the number of subauthorities in the SID.
dwSubAuthorities = *GetSidSubAuthorityCount(pSid);
// Compute the buffer length.
// S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL
dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
// Check input buffer length.
// If too small, indicate the proper size and set last error.
if (*lpdwBufferLen < dwSidSize)
{
*lpdwBufferLen = dwSidSize;
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
// Add 'S' prefix and revision number to the string.
dwSidSize=wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev );
// Add SID identifier authority to the string.
if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
{
dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),
TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
(USHORT)psia->Value[0],
(USHORT)psia->Value[1],
(USHORT)psia->Value[2],
(USHORT)psia->Value[3],
(USHORT)psia->Value[4],
(USHORT)psia->Value[5]);
}
else
{
dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid),
TEXT("%lu"),
(ULONG)(psia->Value[5] ) +
(ULONG)(psia->Value[4] << 8) +
(ULONG)(psia->Value[3] << 16) +
(ULONG)(psia->Value[2] << 24) );
}
// Add SID subauthorities to the string.
//
for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
{
dwSidSize+=wsprintf(TextualSid + dwSidSize, TEXT("-%lu"),
*GetSidSubAuthority(pSid, dwCounter) );
}
return TRUE;
}
-
February 29th, 2004, 03:07 AM
#3
Thank you, I found it on MSDN 2003
But I am wondering whether we can use ConvertSidToStringSid in Visual Studio 6.0 just by copy the needed Sddl.h and Advapi32.lib from Visual Studio .NET?
After "#define _WIN32_WINNT 0x0500" and "#include "Sddl.h""
in my source file and change the project's settings to link with "Advapi32.lib". The project compiled and linked without error.
But after execute, I get an error "Unhandled exception in SID.exe(ADVAPI32.DLL):0xC0000005: Access Violation."
What can I do?
-
February 29th, 2004, 05:42 AM
#4
Does ConvertSidToStringSid exists in Advapi32.dll ?
use depends.exe to check it out...
you better use dynamic linking (LoadLibrary and GetProcAddress)
to avoid any compatibility prb.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|