AccountInfo.cpp revision 0c27b3fe77ac1d5094ba3521e8142d9e7973133f
/*
* Portions Copyright (C) 2001, 2002, 2004, 2007, 2009, 2013, 2016 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* $Id: AccountInfo.cpp,v 1.10 2009/09/29 23:48:04 tbox Exp $ */
/* Compiled with 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
*/
if (istatus == ISC_R_NOMEMORY)
return (RTN_NOMEMORY);
else if (istatus != ISC_R_SUCCESS)
return (RTN_ERROR);
(*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;
}
wchar_t AccountName[MAX_NAME_LENGTH];
wchar_t AccountPassword[MAX_NAME_LENGTH];
/*
* 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.
*/
&peUse))
{
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
/* reallocate memory */
GetProcessHeap(), 0, ReferencedDomain,
cbReferencedDomain)) == NULL)
}
else
}
} /* 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) {
return (RTN_NOMEMORY);
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. */
}
}