• 12
• 12
• 9
• 10
• 13

# LookupAccountName

This topic is 4262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying for whole day to get SID from a user name, MSDN and bunch of other sites I googled up seems to give one answer - use LookupAccountName. The thing is that this function doesn't work, I get a ERROR_IO_PENDING as getlasterror and invalid SID. NOTHING on the web makes sense about this problem and I do want to finish the project. Does anyone have any experience in this matter? I am using single threaded app and this function doesnt have handles or anything to lock... Even more, it actually returns success although the SID is junk... I tried Sleeping for 5, 10 secs... same result... And afaik
while(GetLastError() == ERR_IO_JUNK)
{
SetLastError(0);
Sleep(a_lot);
}


is not doing anything, right, getlasterror is only set once after function call?

##### Share on other sites
Quote:
 Original post by SiCranePeople might be better equipped to help you if you showed your LookupAccountName() call.

Sorry

SECURITY_DESCRIPTOR SecDescr;if(!InitializeSecurityDescriptor(&SecDescr, SECURITY_DESCRIPTOR_REVISION))	MessageBeep(-1);char szUserBuff[512];DWORD dwUserBuffLen = sizeof(szUserBuff)/sizeof(szUserBuff[0]);		SetLastError(0);if(!GetUserNameEx(NameUserPrincipal, szUserBuff, &dwUserBuffLen))	MessageBeep(-1);DWORD a = GetLastError();PSID sidCurrentUsr = NULL;DWORD dwSidSize = 1024;DWORD dwDomainNameSize = 1024;char *szDomain = NULL;SID_NAME_USE enumNameUse;memset(&enumNameUse, 0, sizeof(SID_NAME_USE));//LookupAccountName(NULL, szUserBuff, sidCurrentUsr, &dwSidSize, szDomain, &dwDomainNameSize, &enumNameUse);//commented out to test with hardcoded allocated buffersa = GetLastError();SetLastError(0);sidCurrentUsr = (PSID)calloc(1, dwSidSize);szDomain = (char*)malloc(dwDomainNameSize);SetLastError(0);if(!LookupAccountName(NULL, szUserBuff, sidCurrentUsr, &dwSidSize, szDomain, &dwDomainNameSize, &enumNameUse))	MessageBeep(-1);a = GetLastError();SetLastError(0);if(IsValidSid(&sidCurrentUsr))	Sleep(1);a = GetLastError();SetLastError(0);Sleep(1);

you will probably need:

#define SECURITY_WIN32#include <security.h>#pragma comment(lib, "Secur32.lib")

##### Share on other sites
I'm not a Windows security expert, but have you tried checking out this article?

hope that helps,

##### Share on other sites
Quote:
 Original post by kSquaredI'm not a Windows security expert, but have you tried checking out this article?hope that helps,

Thanks for the answer, I'll try to run that code, but so far it seems to be 99% identic at the core... Then again it's usually obvious typos that make you go crazy...