Jump to content
  • Advertisement
Sign in to follow this  
_Madman_

LookupAccountName

This topic is 4380 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
Advertisement
People might be better equipped to help you if you showed your LookupAccountName() 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!