//
// ChkLock.cpp
//
// Calls NetUserModalsGet and talks about the results
//
#include "ChkLock.h"
DWORD ChkLock( LPWSTR lpwszServerName )
{
PUSER_MODALS_INFO_3 lpInfo3;
PUSER_MODALS_INFO_2 lpInfo2;
PUSER_MODALS_INFO_1 lpInfo1;
PUSER_MODALS_INFO_0 lpInfo0;
NET_API_STATUS nasResult;
char *lpszName;
DWORD dwLength;
// Initialize variables
nasResult = 0;
dwLength = 0;
lpszName = NULL;
lpInfo3 = NULL;
lpInfo0 = NULL;
nasResult = NetApiBufferAllocate( (DWORD)sizeof( USER_MODALS_INFO_3 ), (LPVOID *)&lpInfo3 );
if (nasResult != NERR_Success)
{
return CL_RET_ALLOC;
} // (could we allocate buffers for API calls?)
nasResult = NetApiBufferAllocate( (DWORD)sizeof( USER_MODALS_INFO_2 ), (LPVOID *)&lpInfo2 );
if (nasResult != NERR_Success)
{
return CL_RET_ALLOC;
} // (could we allocate buffers for API calls?)
nasResult = NetApiBufferAllocate( (DWORD)sizeof( USER_MODALS_INFO_1 ), (LPVOID *)&lpInfo1 );
if (nasResult != NERR_Success)
{
return CL_RET_ALLOC;
} // (could we allocate buffers for API calls?)
nasResult = NetApiBufferAllocate( (DWORD)sizeof( USER_MODALS_INFO_0 ), (LPVOID *)&lpInfo0 );
if (nasResult != NERR_Success)
{
return CL_RET_ALLOC;
} // (could we allocate buffers for API calls?)
memset( lpInfo3, 0, sizeof( USER_MODALS_INFO_3 ) );
memset( lpInfo2, 0, sizeof( USER_MODALS_INFO_2 ) );
memset( lpInfo1, 0, sizeof( USER_MODALS_INFO_1 ) );
memset( lpInfo0, 0, sizeof( USER_MODALS_INFO_0 ) );
nasResult = NetUserModalsGet( lpwszServerName,
0,
(LPBYTE *)&lpInfo0 );
if (nasResult == NERR_Success)
{
// Parse the data
cout<<"Minimum Password Length: \t"<<lpInfo0->usrmod0_min_passwd_len<<" characters."<<endl;
cout<<"Maximum Password Age: \t\t";
if (lpInfo0->usrmod0_max_passwd_age == TIMEQ_FOREVER)
{
cout<<"passwords never expire."<<endl;
} else {
cout<<(lpInfo0->usrmod0_max_passwd_age / 86400)<<" days."<<endl;
} // (do passwords expire?)
cout<<"Minimum Password Age: \t\t";
if (lpInfo0->usrmod0_min_passwd_age == 0)
{
cout<<"passwords may be changed immediately."<<endl;
} else {
cout<<(lpInfo0->usrmod0_min_passwd_age / 86400)<<" days."<<endl;
} // (can we continuously change passwords?)
cout<<"Logoff Forced After:\t\t";
if (lpInfo0->usrmod0_force_logoff == TIMEQ_FOREVER)
{
cout<<"users are not forced to log off."<<endl;
} else {
cout<<lpInfo0->usrmod0_force_logoff<<endl;
} // (can people stay on?)
cout<<"Password Uniqueness Depth: \t";
if (lpInfo0->usrmod0_password_hist_len == 0)
{
cout<<"no password history is kept."<<endl;
} else {
cout<<lpInfo0->usrmod0_password_hist_len<<" passwords."<<endl;
} // (are we enforcing the use of unique passwords?)
nasResult = NetUserModalsGet( lpwszServerName,
3,
(LPBYTE *)&lpInfo3 );
if (nasResult == NERR_Success)
{
if (lpInfo3->usrmod3_lockout_duration == TIMEQ_FOREVER)
{
cout<<"Lockout Duration: \t\t"<<"administrator must unlock accounts."<<endl;
} else {
cout<<"Lockout Duration: \t\t"<<(lpInfo3->usrmod3_lockout_duration / 60)<<" minutes."<<endl;
}
cout<<"Lockout Reset Window: \t\t"<<(lpInfo3->usrmod3_lockout_observation_window / 60)<<" minutes."<<endl;
cout<<"Lockout Threhshold: \t\t";
if (lpInfo3->usrmod3_lockout_threshold == 0)
{
cout<<"account lockout is turned off."<<endl;
} else {
cout<<lpInfo3->usrmod3_lockout_threshold<<" attempts."<<endl;
}
nasResult = NetUserModalsGet( lpwszServerName,
1,
(LPBYTE *)&lpInfo1 );
if (nasResult == NERR_Success)
{
cout<<"This machine's logon role: \t";
switch (lpInfo1->usrmod1_role)
{
case UAS_ROLE_STANDALONE:
cout<<"standalone."<<endl;
break;
case UAS_ROLE_MEMBER:
cout<<"member server."<<endl;
break;
case UAS_ROLE_BACKUP:
cout<<"backup domain controller."<<endl;
break;
case UAS_ROLE_PRIMARY:
cout<<"primary domain controller."<<endl;
break;
default:
cout<<"undetermined."<<endl;
break;
} // (switch)
// Calculate length of name string
dwLength = ( wcslen( lpInfo1->usrmod1_primary ) * 2 ) + 1;
// Allocate and initialize such a buffer
lpszName = new char[ dwLength ];
memset( lpszName, 0, dwLength );
// Convert the name from Unicode
WideCharToMultiByte( CP_ACP,
0,
lpInfo1->usrmod1_primary,
-1,
lpszName,
dwLength,
NULL,
NULL );
cout<<"The name of the PDC is: \t"<<lpszName<<endl;
// Release the memory we allocated
delete lpszName;
} else {
ErrorHandler( "ChkLock", "NetUserModalsGet() at level 1", (DWORD)nasResult );
} // (could we get the level 1 data?)
nasResult = NetUserModalsGet( lpwszServerName,
2,
(LPBYTE *)&lpInfo2 );
if (nasResult == NERR_Success)
{
// Calculate length of domain name string
dwLength = ( wcslen( lpInfo2->usrmod2_domain_name ) * 2 ) + 1;
// Allocate and initialize such a buffer
lpszName = new char[ dwLength ];
memset( lpszName, 0, dwLength );
// Convert the name from Unicode
WideCharToMultiByte( CP_ACP,
0,
lpInfo2->usrmod2_domain_name,
-1,
lpszName,
dwLength,
NULL,
NULL );
cout<<"The name of the domain is: \t"<<lpszName<<endl;
// Release the memory we allocated
delete lpszName;
} else {
ErrorHandler( "ChkLock", "NetUserModalsGet() at level 2", (DWORD)nasResult );
} // (could we get the level 2 data?)
} else {
ErrorHandler( "ChkLock", "NetUserModalsGet() at level 3", (DWORD)nasResult );
} // (could we get the level 3 data?)
} else {
ErrorHandler( "ChkLock", "NetUserModalsGet() at level 0", (DWORD)nasResult );
} // (could we get the level 0 data?)
// Release resources
NetApiBufferFree( lpInfo3 );
NetApiBufferFree( lpInfo2 );
NetApiBufferFree( lpInfo1 );
NetApiBufferFree( lpInfo0 );
// All done
return( (DWORD)nasResult );
} // (ChkLock)
| Back to the ChkLock source code page |
This page is maintained by Peyton Engel.
Last updated 13 October 2000