[NETAPI32]

Use servername in NetLocalGroupEnum and NetUserEnum.

svn path=/trunk/; revision=57994
This commit is contained in:
Eric Kohl 2012-12-24 12:48:39 +00:00
parent 9403cc412f
commit 4b858fe42a
4 changed files with 21 additions and 9 deletions

View file

@ -150,6 +150,7 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
LPDWORD totalentries, LPDWORD totalentries,
PDWORD_PTR resumehandle) PDWORD_PTR resumehandle)
{ {
UNICODE_STRING ServerName;
PSAM_RID_ENUMERATION CurrentAlias; PSAM_RID_ENUMERATION CurrentAlias;
PENUM_CONTEXT EnumContext = NULL; PENUM_CONTEXT EnumContext = NULL;
PSID DomainSid = NULL; PSID DomainSid = NULL;
@ -171,6 +172,9 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
*totalentries = 0; *totalentries = 0;
*bufptr = NULL; *bufptr = NULL;
if (servername != NULL)
RtlInitUnicodeString(&ServerName, servername);
if (resumehandle != NULL && *resumehandle != 0) if (resumehandle != NULL && *resumehandle != 0)
{ {
EnumContext = (PENUM_CONTEXT)*resumehandle; EnumContext = (PENUM_CONTEXT)*resumehandle;
@ -187,7 +191,7 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
EnumContext->Index = 0; EnumContext->Index = 0;
EnumContext->BuiltinDone = FALSE; EnumContext->BuiltinDone = FALSE;
Status = SamConnect(NULL, Status = SamConnect((servername != NULL) ? &ServerName : NULL,
&EnumContext->ServerHandle, &EnumContext->ServerHandle,
SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN, SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
NULL); NULL);
@ -198,7 +202,8 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
goto done; goto done;
} }
Status = GetAccountDomainSid(&DomainSid); Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
&DomainSid);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ERR("GetAccountDomainSid failed (Status %08lx)\n", Status); ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);

View file

@ -37,7 +37,8 @@ static SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
NTSTATUS NTSTATUS
GetAccountDomainSid(PSID *AccountDomainSid) GetAccountDomainSid(IN PUNICODE_STRING ServerName,
OUT PSID *AccountDomainSid)
{ {
PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL; PPOLICY_ACCOUNT_DOMAIN_INFO AccountDomainInfo = NULL;
LSA_OBJECT_ATTRIBUTES ObjectAttributes; LSA_OBJECT_ATTRIBUTES ObjectAttributes;
@ -47,7 +48,7 @@ GetAccountDomainSid(PSID *AccountDomainSid)
memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES)); memset(&ObjectAttributes, 0, sizeof(LSA_OBJECT_ATTRIBUTES));
Status = LsaOpenPolicy(NULL, Status = LsaOpenPolicy(ServerName,
&ObjectAttributes, &ObjectAttributes,
POLICY_VIEW_LOCAL_INFORMATION, POLICY_VIEW_LOCAL_INFORMATION,
&PolicyHandle); &PolicyHandle);
@ -89,7 +90,7 @@ done:
NTSTATUS NTSTATUS
GetBuiltinDomainSid(PSID *BuiltinDomainSid) GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid)
{ {
PSID Sid = NULL; PSID Sid = NULL;
PULONG Ptr; PULONG Ptr;

View file

@ -9,9 +9,10 @@ NetpNtStatusToApiStatus(NTSTATUS Status);
/* misc.c */ /* misc.c */
NTSTATUS NTSTATUS
GetAccountDomainSid(PSID *AccountDomainSid); GetAccountDomainSid(IN PUNICODE_STRING ServerName,
OUT PSID *AccountDomainSid);
NTSTATUS NTSTATUS
GetBuiltinDomainSid(PSID *BuiltinDomainSid); GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid);
#endif #endif

View file

@ -321,6 +321,7 @@ NetUserEnum(LPCWSTR servername,
LPDWORD totalentries, LPDWORD totalentries,
LPDWORD resume_handle) LPDWORD resume_handle)
{ {
UNICODE_STRING ServerName;
PSAM_RID_ENUMERATION CurrentUser; PSAM_RID_ENUMERATION CurrentUser;
PENUM_CONTEXT EnumContext = NULL; PENUM_CONTEXT EnumContext = NULL;
LPVOID Buffer = NULL; LPVOID Buffer = NULL;
@ -346,6 +347,9 @@ NetUserEnum(LPCWSTR servername,
*totalentries = 0; *totalentries = 0;
*bufptr = NULL; *bufptr = NULL;
if (servername != NULL)
RtlInitUnicodeString(&ServerName, servername);
if (resume_handle != NULL && *resume_handle != 0) if (resume_handle != NULL && *resume_handle != 0)
{ {
EnumContext = (PENUM_CONTEXT)*resume_handle; EnumContext = (PENUM_CONTEXT)*resume_handle;
@ -362,7 +366,7 @@ NetUserEnum(LPCWSTR servername,
EnumContext->Index = 0; EnumContext->Index = 0;
EnumContext->BuiltinDone = FALSE; EnumContext->BuiltinDone = FALSE;
Status = SamConnect(NULL, Status = SamConnect((servername != NULL) ? &ServerName : NULL,
&EnumContext->ServerHandle, &EnumContext->ServerHandle,
SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN, SAM_SERVER_CONNECT | SAM_SERVER_LOOKUP_DOMAIN,
NULL); NULL);
@ -373,7 +377,8 @@ NetUserEnum(LPCWSTR servername,
goto done; goto done;
} }
Status = GetAccountDomainSid(&DomainSid); Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
&DomainSid);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ERR("GetAccountDomainSid failed (Status %08lx)\n", Status); ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);