AccountInfo.cpp revision 1ebeb6bbf3c25a710ed7b6fbd2608f3850fc7f8f
/*
* Copyright (C) 2001 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: AccountInfo.cpp,v 1.1 2001/09/25 01:46:22 mayer Exp $ */
#ifndef UNICODE
#define UNICODE
#endif // UNICODE
#include "stdafx.h"
#include <windows.h>
#include <lm.h>
#include <ntsecapi.h>
#include <isc/ntgroups.h>
#include "AccountInfo.h"
#define MAX_NAME_LENGTH 256
);
);
);
wchar_t **PrivList, /* Ptr to List of Privileges found */
unsigned int *PrivCount /* total number of Privileges in list */
);
);
void
);
void
);
void
);
#ifndef STATUS_SUCCESS
#endif
/*
* Note that this code only retrieves the list of privileges of the
* requested account or group. However, all accounts belong to the
* Everyone group even though that group is not returned by the
* calls to get the groups to which that account belongs.
* The Everyone group has two privileges associated with it:
* SeChangeNotifyPrivilege and SeNetworkLogonRight
* It is not advisable to disable or remove these privileges
* from the group nor can the account be removed from the Everyone
* group
* The None group has no privileges associated with it and is the group
* to which an account belongs if it is associated with no group.
*/
int
char **Accounts, unsigned int *totalAccounts,
int maxAccounts) {
unsigned int i;
/*
* Open the policy on the target machine.
*/
&PolicyHandle)) != STATUS_SUCCESS) {
return (RTN_ERROR);
}
/*
* Let's see if the account exists. Return if not
*/
return (RTN_NOACCOUNT);
}
/*
* Find out what groups the account belongs to
*/
(*totalAccounts)++;
/*
* Loop through each Account to get the list of privileges
*/
for(i = 0; i < *totalAccounts; i++) {
continue; /* Try the next one */
}
/* Get the Privileges allocated to this SID */
}
else {
continue; /* Try the next one */
}
}
/*
* Close the policy handle.
*/
(*totalAccounts)--; /* Correct for the number of groups */
return iRetVal;
}
sizeof(wchar_t));
sizeof(wchar_t));
/*
* Set up the USER_INFO_1 structure.
* USER_PRIV_USER: name is required here when creating an account
* rather than an administrator or a guest.
*/
/*
* Call the NetUserAdd function, specifying level 1.
*/
if (nStatus != NERR_Success) {
return (FALSE);
}
return (TRUE);
}
unsigned long err;
/*
* Open the policy on the target machine.
*/
!= STATUS_SUCCESS) {
return (RTN_ERROR);
}
/*
* Let's see if the account exists. Return if not
*/
return (RTN_NOACCOUNT);
}
if(err == ERROR_SUCCESS)
return (RTN_OK);
else
return (err);
}
void
LsaString->MaximumLength = 0;
return;
}
}
/*
* Always initialize the object attributes to all zeroes.
*/
if (ServerName != NULL) {
/*
* Make a LSA_UNICODE_STRING out of the LPWSTR passed in
*/
Server = &ServerString;
}
/*
* Attempt to open the policy.
*/
PolicyHandle));
}
__try {
/*
* initial memory allocations
*/
/*
* Obtain the SID of the specified account on the specified system.
*/
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
/* reallocate memory */
GetProcessHeap(), 0, ReferencedDomain,
cbReferencedDomain)) == NULL)
}
else __leave;
}
} // finally
/* Cleanup and indicate failure, if appropriate. */
if(!bSuccess) {
}
}
}
return (bSuccess);
}
/* Create a LSA_UNICODE_STRING for the privilege name. */
/* grant or revoke the privilege, accordingly */
if(bEnable) {
&PrivilegeString, 1));
}
else {
}
}
unsigned int retlen = 0;
DWORD i, j;
int found;
&UserRights, &CountOfRights);
/* Only continue if there is something */
return (Status);
for(i = 0; i < CountOfRights; i++) {
found = -1;
for(j = 0; j < *PrivCount; j++) {
retlen);
if(found == 0)
break;
}
if(found != 0) {
retlen);
(*PrivCount)++;
}
}
return (Status);
}
void
/* Convert the NTSTATUS to Winerror. Then call DisplayWinError(). */
}
void
/* Output message string on stderr. */
/* Free the buffer allocated by the system. */
}
}