Thread View: borland.public.cppbuilder.nativeapi
1 messages
1 total messages
Started by Mike Collins
Sun, 22 Apr 2007 21:32
Getting computer sid, problems with LookupAccountName
Author: Mike Collins
Date: Sun, 22 Apr 2007 21:32
Date: Sun, 22 Apr 2007 21:32
83 lines
4370 bytes
4370 bytes
Hi all, got a really strange problem. Basically i have a piece of code that
i wrote last year that retrieves the Computer's SID. It is based on a
article written by Mark Russinovich of System Internals, and loosely based
on his psgetsid application.
The basic mechanics behind the code is that you get the computers name,
append a $ to the end, the call LookupAccountName - which will return the
SID for the account, beofre cponverting it to a string representation using
ConvertSidToString. The documentation about the appending of the $ is very
vauge and i had never seen it before reading this article. Anyway, the code
i use was written sometime last year and seemed to work perfectly, i get
exactly the same SID returned as i get with the psgetsid tool.
However, today i was working on something and started to walk throught the
code (shown below). I noticed that for some strange reason, the $ character
was not being appended to the end of the computer name. However, the code
still seemed to work without issue. I cannot for the life of me understand
why the $ is not being appended and have posted on the .vlc.components.using
newsgroup. However, if i hard code in the name of my computer, with the $
at the end, LookupAccountName fails and reports
"No mapping between account names and security IDs was done"
Can anyone tell me where i'm going wrong here. My code as it stands works -
but doesn't execute as documented, and if i modify it so that it does
conform, it fails to work.
Any help or pointers woudl be excellent.
{code snippet}
// Generate computer SID hash
AnsiString szComputerName;
szComputerName.SetLength(MAX_COMPUTERNAME_LENGTH + 1);
DWORD dwSize = szComputerName.Length();
if (GetComputerName(szComputerName.c_str(), &dwSize))
{
szComputerName = szComputerName + "$"; <- Never gets
appended...
PSID pSID = NULL;
DWORD dwSIDSize = 0;
TCHAR cDomain[1024] = {0};
DWORD dwDomainSize = 1024;
SID_NAME_USE AccountType;
LookupAccountName(NULL, szComputerName.c_str(), NULL,
&dwSIDSize, cDomain, &dwDomainSize, &AccountType);
if (dwSIDSize)
{
pSID = (PSID)GlobalAlloc(GPTR, dwSIDSize);
if (pSID)
{
if (LookupAccountName(NULL, szComputerName.c_str(), pSID,
&dwSIDSize, cDomain, &dwDomainSize, &AccountType))
{
char *cStringSID;
if (ConvertSidToStringSid(pSID, &cStringSID))
{
}
else
// ERROR: Calling ConvertSidToStringSid()");
LocalFree(cStringSID);
cStringSID = NULL;
}
else
// ERROR: Calling LookupAccountName() failed to
retrieve account SID");
}
else
// ERROR: Calling GlobalAlloc() failed to allocate SID");
GlobalFree(pSID);
pSID = NULL;
}
else
// ERROR: Calling LookupAccountName() failed to return
account size");
}
else
// ERROR: Calling GetComputerName() failed to return computer
name");
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads