Microsoft KB Archive/62561

= NetUserValidate2 Usage Sample Program =

Article ID: 62561

Article Last Modified on 9/30/2003

-

APPLIES TO


 * Microsoft LAN Manager 2.0 Standard Edition
 * Microsoft LAN Manager 2.1 Standard Edition
 * Microsoft LAN Manager 2.1a
 * Microsoft LAN Manager 2.2 Standard Edition

-



This article was previously published under Q62561



SUMMARY
The following program demonstrates the correct usage of the NetUserValidate2 function call: /* This program demonstrates the usage of NetUservalidate2.

Compile option: CL -C -W3 -Zi validat2.c     Link option: Link /CO validat2,,,os2+netapi; Usage: validate

The program fills in the workstation name by making a call to     NetWkstaGetInfo. A value of NULL in the workstation field will mean local workstation.

This software is provided for demonstration purposes only. Microsoft makes no warranty, either express or implied, as to its usability in any given situation.

*/

#define INCL_DOS #define INCL_NOPM #include 

#include   #include    #include    #include    #include 

#include   #include    #include    #include 

#define EXTRA_USER_INFO    200 #define EXTRA_WKSTA_INFO   70 #define TOTAL_DOMAIN_NMS   32

typedef struct user_info_1 USER_INFO_1; typedef struct wksta_info_10 WKSTA_INFO_10; typedef struct user_logon_req_1 User_Logon_Req_1; typedef struct user_logon_info_1 User_Logon_Info_1;

typedef char far       * CHFP; typedef char near      * CHNP; typedef unsigned short US;

void MtrCpy ( char *dest, char  far *src);

/* MtrCpy function will copy text from far buffer into near buffer. */

void MtrCpy ( char *dest, char  far *src) {      char  *pDest = dest; char far *pSrc = src;

// Copy from far buffer into near buffer.

while ( *pSrc) *pDest++ = *pSrc++; *pDest = '\0';

// Uppercase the text. Password must be uppercased.

pDest = dest; while (*pDest) { if ( isalpha( (int) *pDest)) *pDest = (char) toupper( (int) *pDest); pDest++;

}

return; }

void main(argc, argv) int argc; char *argv[]; {

char  *pUserInfo;          /* Pointer to user_info_10. */       WKSTA_INFO_10 *pWkstaInfo;  /* Pointer to wksta_info_10. */

User_Logon_Info_1 *pUserLogonInfo; User_Logon_Req_1 *pUserReq;

unsigned int netAPIStatus;        /* Status from LANMAN calls. */       unsigned short int returnedBuffSz; /* Size of buffer from LANMAN calls. */

if ( argc < 2 ) { puts(&quot;USAGE: username password&quot;); return; }

/* Allocate buffer for level 10 workstation information. */       if ( (pWkstaInfo = (WKSTA_INFO_10 *)calloc(1, sizeof(WKSTA_INFO_10)                                                  + EXTRA_WKSTA_INFO                                                  + TOTAL_DOMAIN_NMS))                                                  == NULL) {

puts(&quot;Error: Unable to allocate workstation info buffer&quot;); return; }

/* Get the workstation information. */       if ( netAPIStatus = NetWkstaGetInfo(NULL, 10, (CHFP) pWkstaInfo, (sizeof(WKSTA_INFO_10) +                                           EXTRA_WKSTA_INFO +                                            TOTAL_DOMAIN_NMS), &returnedBuffSz) ) {

printf(&quot;Error: NetWkstaGetInfo returned %u\n&quot;); free(pWkstaInfo); return; }

/* Allocate buffer for level 1 user logon information. */       if ( (pUserReq = (User_Logon_Req_1 *)calloc(1, sizeof(USER_INFO_1)                                                  + EXTRA_USER_INFO))                                                  == NULL) {

puts(&quot;Error: Unable to allocate user logon buffer&quot;); return; }

/* Initialize user information with user ID from workstation call. */

MtrCpy( pUserReq->usrreq1_name,  argv[1]);   // Username MtrCpy(pUserReq->usrreq1_password, argv[2]); // Password // Workstation Name pUserReq->usrreq1_workstation = pWkstaInfo->wki10_computername;

free(pWkstaInfo);         /* Information not needed anymore. */

printf(&quot;\nValidating user %s, password %s\n&quot;,             pUserReq->usrreq1_name, pUserReq->usrreq1_password);

/* Call LANMAN to validate ID and password. */       netAPIStatus = NetUserValidate2(NULL, 1, (CHFP) pUserReq,                                    (sizeof(USER_INFO_1) + EXTRA_USER_INFO)                                    (US) NULL, &returnedBuffSz); if ( netAPIStatus ) {             /* Report results of call. */           printf(&quot;\n\tError calling NetUserValidate, status = %u\n&quot;,                  netAPIStatus); }      else { /* While making the NetUserValidate2 call, the pointer pUserReq must point to a user_info_req_1 type structure and on a successful return, the same pointer now points to the user_logon_info_1 type structure. */           pUserLogonInfo = (User_Logon_Info_1 *) pUserReq; printf(&quot;Validatation Code: %d\n&quot;, pUserLogonInfo->usrlog1_code);

printf(&quot;\n\tUser %s validated, has privilege level&quot;,              pUserLogonInfo->usrlog1_eff_name);

switch ( pUserLogonInfo->usrlog1_priv ) {

case USER_PRIV_GUEST: puts(&quot; GUEST.&quot;); break;

case USER_PRIV_USER: puts(&quot; USER.&quot;); break;

case USER_PRIV_ADMIN: puts(&quot; ADMIN.&quot;); break;

default: printf(&quot; unknown privilege level = %d\n&quot;,                  pUserLogonInfo->usrlog1_priv); break;

}  /* End-switch on user privilege level. */

}  /* End-if on netAPIStatus. */

free(pUserInfo);       /* Information not needed anymore. */       return; }

Additional query words: prodlm 2.00 2.10 2.10a 2.20

Keywords: KB62561

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.