Sign in to follow this  

LookupAccountName

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
People 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 buffers
a = 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")



in header...

Share this post


Link to post
Share on other sites
Quote:
Original post by kSquared
I'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...

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this