Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if logged on windows account has been authenticated on domain [duplicate]

Possible Duplicate:
Authenticating users using Active Directory in Client-Server Application

I'm attempting a single sign-on approach in my program using unmanaged C++, and need to determine if the current windows user is authenticated in my domain. If I can find a way to know that the user has been authenticated, I'll allow him into my desktop application without requiring a password (usernames are the same in my app and on domain).

I can authenticate directly against Active Directory using ADsOpenObject(), but that requires username, password and privileges, I need to do it only with a username, and no input from the user himself.

With .net I could use something from System.DirectoryServices, like in this thread.

As far as I've found out, this task may involve analyzing Windows security kerberos tokens to do properly. This was thoroughly discussed in this thread and touched upon for Java in this thread. Though I do not need strict SSO, since my app does not try to access anything related to domain.

Is the SSPI ticket way the only way, or can I exploit some property of ADSI/WinLogon/CredentialsCache to make it work?

like image 508
petrobrush Avatar asked Oct 05 '11 15:10

petrobrush


1 Answers

This is a very simple way, but if you check the environment variables for the user :

On a Workgroup :

COMPUTERNAME=JPBHPP2
LOGONSERVER=\\JPBHPP2
USERDOMAIN=JPBHPP2

On a Domain

COMPUTERNAME=WM2008R2ENT
LOGONSERVER=\\WM2008R2ENT
USERDNSDOMAIN=DOM.FR
USERDOMAIN=DOM

Here it's not so evident because the user is loged on the server but the USERDOMAIN is different from COMPUTERNAME

There is also GetUserNameEx API that can do the job

BOOLEAN WINAPI GetUserNameEx(
  __in     EXTENDED_NAME_FORMAT NameFormat,
  __out    LPTSTR lpNameBuffer,
  __inout  PULONG lpnSize
);
like image 173
JPBlanc Avatar answered Oct 04 '22 20:10

JPBlanc