LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Needing a CVI or Windows SDK function to authenticate a network user login to a Domain Controller to verify they are a valid user.

 
 Needing a CVI or Windows SDK function to authenticate a network user login to a Domain Controller to verify they are a valid user.
 A function that by passing username and password can get a response back that the network recognizes them as a valid user on
the network domain there logins would have been created for.
 
 Tried the Windows SDK function  logonuser (  ). I get a GPF every time on 4 different machines running, WIN2K and WIN XP.
  I have the SDK that came with CVI 6.0.
  Any chance anyone has tried this or has a better method.
  If you were successful with logonuser in SDK, can you forward your code snippet.?
 cvier
 
0 Kudos
Message 1 of 10
(5,577 Views)
Hey CVIer,

Unfortunately I don't have any experience with this, but I stumbled across an article on MSDN.com that may help you - it seems to speak about the logonuser function that you were referring to, and also gives some example code.  Perhaps it will help.  Furthermore, if you're not using it, MSDN could be a great resource on this.

The article is entitled "How to Validate User Credentials on Microsoft Operating Systems."  I hope this helps!
Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 2 of 10
(5,533 Views)
 
 Any chance you could try this on your machine and see if you get a GPF?
 I could very well not be using the SDK variables correctly in terms of integer type..within cvi..etc
 If you get it to work, could you pass along the code used in terms of the variable setup...
 Cvier
0 Kudos
Message 3 of 10
(5,528 Views)
Hi CVIer,

Would you be able to post your function call for logonuser( ), specifically what parameters you are passing?  Or could you post your CVI application so that I could troubleshoot on my end?  Thanks!


Matt S
National Instruments
Applications Engineer
0 Kudos
Message 4 of 10
(5,492 Views)

 

  Using the sample routine for whoami.prj in the samples directory to try this function. Need to add valid login name..etc obviously.  It very well maybe a SDK variable type as the issue? Please try to actually run it, I get a GPF.

 

 

/*---------------------------------------------------------------------------*/
/*                                                                           */
/* FILE:                                                            */
/*                                                                           */
/*                                                                           */
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/* Include files                                                             */
/*---------------------------------------------------------------------------*/
#include "windows.h"
#include <utility.h>
#include <ansi_c.h>
#include <userint.h>
#include "whoami.h"

/*---------------------------------------------------------------------------*/
/* Module-globals                                                            */
/*---------------------------------------------------------------------------*/
static OSVERSIONINFO verInfo = {0};
static HANDLE hProcess, hAccessToken;
static UCHAR InfoBuffer[1000],szAccountName[200], szDomainName[200], szPassWord[200];
static PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer;
static DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = 200;
static SID_NAME_USE snu;
static PTOKEN_GROUPS ptgGroups = (PTOKEN_GROUPS)InfoBuffer;
static PSID psidAdministrators;
static SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
static UINT x;
static PHANDLE phToken;
static UINT aszAccountName[200], aszDomainName[200], aszPassWord[200];
int status;


/*---------------------------------------------------------------------------*/
/* This is the application's entry-point.                                    */
/*---------------------------------------------------------------------------*/
int main (int argc, char *argv[])
{
    int hpanel;
   
    if (InitCVIRTE (0, argv, 0) == 0)
        return -1;
       
    /* Verify that we are on Windows NT */   
    verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    if ((GetVersionEx(&verInfo)==0)
        || (verInfo.dwPlatformId != VER_PLATFORM_WIN32_NT))
        {
        MessagePopup ("Wrong Windows version",
                      "These functions are only valid on Windows NT");
        return 0;
        }

    sprintf( szAccountName, "login" );
    sprintf( szDomainName, "Domain" );
    sprintf( szPassWord, "password" );


status = LogonUser(
  szAccountName,    // user name
  szDomainName,      // domain or server
  szPassWord,    // password
  LOGON32_LOGON_NETWORK,      // type of logon operation
  LOGON32_PROVIDER_DEFAULT,  // logon provider
  phToken         // receive tokens handle
);
   
   
   
   
    CloseCVIRTE ();
    return 0;
}

 

 

 

0 Kudos
Message 5 of 10
(5,459 Views)
Hi CVIer,

I'm getting the GPF on my machine too, so at least you can rest assured that the error you're experiencing isn't specific to just your machine. 

Sorry that I couldn't get it to work, otherwise I would've posted the correct changes for you.  Have you tried MSDN yet?  This is again probably the best resource for this issue, since this is in fact a Windows SDK function.  They also have a forum, and their help documents are quite thorough.

Best of luck, CVIer!
Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 6 of 10
(5,432 Views)
I won't pretend to know much about the window logon API functions, but the reason for the crash is pretty simple. Windows is expecting you to pass in a storage location for the last parameter (a non-NULL pointer to a handle). You are actually passing in a handle pointer object, which doesn't point to any handle.

Simply changing the declaration to

static HANDLE hToken;

and the call to

status = LogonUser(
  szAccountName,            // user name
  szDomainName,             // domain or server
  szPassWord,               // password
  LOGON32_LOGON_NETWORK,    // type of logon operation
  LOGON32_PROVIDER_DEFAULT, // logon provider
  &hToken                   // receive tokens handle
);

fixes the crash.

Regards,

-alex
Message 7 of 10
(5,419 Views)

 

 I suspected it probably was a variable issue. These are variable types I do not have any experience with.  Thank you for looking at this with an observant eye for the variables. I just tried it and it does indeed work for a valid login user and non valid user...

cvier

 

0 Kudos
Message 8 of 10
(5,404 Views)
Thanks, Alex D, for your insight! 
Derrick S.
Product Manager
NI DIAdem
National Instruments
0 Kudos
Message 9 of 10
(5,386 Views)
It would probably be useful to change that to read:
 
static HANDLE hToken = NULL;

status = LogonUser(
  szAccountName,            // user name
  szDomainName,             // domain or server
  szPassWord,               // password
  LOGON32_LOGON_NETWORK,    // type of logon operation
  LOGON32_PROVIDER_DEFAULT, // logon provider
  &hToken                   // receive tokens handle
);
and last but not least this function obviously returns a handle. If you do not close that handle after you don't need it anymore, you will leak some memory with each call.
 
Rolf Kalbermatter


Message Edited by rolfk on 12-10-2007 11:11 AM
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 10 of 10
(5,274 Views)