[NETAPI32]
authorEric Kohl <eric.kohl@reactos.org>
Wed, 26 Dec 2012 21:07:13 +0000 (21:07 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Wed, 26 Dec 2012 21:07:13 +0000 (21:07 +0000)
- Include a netapi32.h in most files and move the other includes into netapi32.h.
- Add functions to open account and builtin domains directly and use these functions.

svn path=/trunk/; revision=58017

reactos/dll/win32/netapi32/access.c
reactos/dll/win32/netapi32/apibuf.c
reactos/dll/win32/netapi32/browsr.c
reactos/dll/win32/netapi32/ds.c
reactos/dll/win32/netapi32/group.c
reactos/dll/win32/netapi32/local_group.c
reactos/dll/win32/netapi32/misc.c
reactos/dll/win32/netapi32/netapi32.h
reactos/dll/win32/netapi32/user.c

index 496f405..4aeea9f 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmaccess.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "lmuse.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
-#include "wine/list.h"
+#include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
 
index a88c6f4..4a241e2 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "lmcons.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "winerror.h"
-#include "wine/debug.h"
+#include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
 
index 8b0a5ed..80c4b8d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmbrowsr.h"
-#include "lmshare.h"
+#include "netapi32.h"
 
 /************************************************************
  *                I_BrowserSetNetlogonState  (NETAPI32.@)
index 386e222..0707737 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "dsrole.h"
-#include "dsgetdc.h"
+#include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(ds);
 
index ea87ee7..b7cd359 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmaccess.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "lmuse.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
-#include "wine/list.h"
+#include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
 
index d3606a2..cff46d1 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmaccess.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "winreg.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
-
-#define NTOS_MODE_USER
-#include <ndk/rtlfuncs.h>
-#include "ntsam.h"
 #include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
@@ -232,7 +213,6 @@ NetLocalGroupAdd(
     SAM_HANDLE ServerHandle = NULL;
     SAM_HANDLE DomainHandle = NULL;
     SAM_HANDLE AliasHandle = NULL;
-    PSID DomainSid = NULL;
     LPWSTR aliasname = NULL;
     LPWSTR aliascomment = NULL;
     ULONG RelativeId;
@@ -277,23 +257,13 @@ NetLocalGroupAdd(
         goto done;
     }
 
-    /* Get the Builtin Domain SID */
-    Status = GetBuiltinDomainSid(&DomainSid);
-    if (!NT_SUCCESS(Status))
-    {
-        ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
-        ApiStatus = NetpNtStatusToApiStatus(Status);
-        goto done;
-    }
-
     /* Open the Builtin Domain */
-    Status = SamOpenDomain(ServerHandle,
-                           DOMAIN_LOOKUP,
-                           DomainSid,
-                           &DomainHandle);
+    Status = OpenBuiltinDomain(ServerHandle,
+                               DOMAIN_LOOKUP,
+                               &DomainHandle);
     if (!NT_SUCCESS(Status))
     {
-        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+        ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
         ApiStatus = NetpNtStatusToApiStatus(Status);
         goto done;
     }
@@ -314,29 +284,15 @@ NetLocalGroupAdd(
 
     ApiStatus = NERR_Success;
 
-    /* Free the Builtin Domain SID */
-    RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-    DomainSid = NULL;
-
     /* Close the Builtin Domain */
     SamCloseHandle(DomainHandle);
     DomainHandle = NULL;
 
-    /* Get the account domain SID */
-    Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
-                                 &DomainSid);
-    if (!NT_SUCCESS(Status))
-    {
-        ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-        ApiStatus = NetpNtStatusToApiStatus(Status);
-        goto done;
-    }
-
     /* Open the account domain */
-    Status = SamOpenDomain(ServerHandle,
-                           DOMAIN_CREATE_ALIAS | DOMAIN_LOOKUP,
-                           DomainSid,
-                           &DomainHandle);
+    Status = OpenAccountDomain(ServerHandle,
+                               (servername != NULL) ? &ServerName : NULL,
+                               DOMAIN_CREATE_ALIAS | DOMAIN_LOOKUP,
+                               &DomainHandle);
     if (!NT_SUCCESS(Status))
     {
         ERR("SamOpenDomain failed (Status %08lx)\n", Status);
@@ -383,9 +339,6 @@ done:
     if (AliasHandle != NULL)
         SamCloseHandle(AliasHandle);
 
-    if (DomainSid != NULL)
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
     if (DomainHandle != NULL)
         SamCloseHandle(DomainHandle);
 
@@ -478,7 +431,6 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
     UNICODE_STRING ServerName;
     PSAM_RID_ENUMERATION CurrentAlias;
     PENUM_CONTEXT EnumContext = NULL;
-    PSID DomainSid = NULL;
     ULONG i;
     SAM_HANDLE AliasHandle = NULL;
     PALIAS_GENERAL_INFORMATION AliasInfo = NULL;
@@ -523,47 +475,23 @@ NET_API_STATUS WINAPI NetLocalGroupEnum(
             goto done;
         }
 
-        Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
-                                     &DomainSid);
+        Status = OpenAccountDomain(EnumContext->ServerHandle,
+                                   (servername != NULL) ? &ServerName : NULL,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->AccountDomainHandle);
         if (!NT_SUCCESS(Status))
         {
-            ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+            ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
             ApiStatus = NetpNtStatusToApiStatus(Status);
             goto done;
         }
 
-        Status = SamOpenDomain(EnumContext->ServerHandle,
-                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
-                               DomainSid,
-                               &EnumContext->AccountDomainHandle);
-
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
+        Status = OpenBuiltinDomain(EnumContext->ServerHandle,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->BuiltinDomainHandle);
         if (!NT_SUCCESS(Status))
         {
-            ERR("SamOpenDomain failed (Status %08lx)\n", Status);
-            ApiStatus = NetpNtStatusToApiStatus(Status);
-            goto done;
-        }
-
-        Status = GetBuiltinDomainSid(&DomainSid);
-        if (!NT_SUCCESS(Status))
-        {
-            ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-            ApiStatus = NetpNtStatusToApiStatus(Status);
-            goto done;
-        }
-
-        Status = SamOpenDomain(EnumContext->ServerHandle,
-                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
-                               DomainSid,
-                               &EnumContext->BuiltinDomainHandle);
-
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
-        if (!NT_SUCCESS(Status))
-        {
-            ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+            ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
             ApiStatus = NetpNtStatusToApiStatus(Status);
             goto done;
         }
@@ -732,7 +660,6 @@ NetLocalGroupGetInfo(
     SAM_HANDLE ServerHandle = NULL;
     SAM_HANDLE DomainHandle = NULL;
     SAM_HANDLE AliasHandle = NULL;
-    PSID DomainSid = NULL;
     PALIAS_GENERAL_INFORMATION AliasInfo = NULL;
     LPVOID Buffer = NULL;
     NET_API_STATUS ApiStatus = NERR_Success;
@@ -758,23 +685,13 @@ NetLocalGroupGetInfo(
         goto done;
     }
 
-    /* Get the Builtin Domain SID */
-    Status = GetBuiltinDomainSid(&DomainSid);
-    if (!NT_SUCCESS(Status))
-    {
-        ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
-        ApiStatus = NetpNtStatusToApiStatus(Status);
-        goto done;
-    }
-
     /* Open the Builtin Domain */
-    Status = SamOpenDomain(ServerHandle,
-                           DOMAIN_LOOKUP,
-                           DomainSid,
-                           &DomainHandle);
+    Status = OpenBuiltinDomain(ServerHandle,
+                               DOMAIN_LOOKUP,
+                               &DomainHandle);
     if (!NT_SUCCESS(Status))
     {
-        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+        ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
         ApiStatus = NetpNtStatusToApiStatus(Status);
         goto done;
     }
@@ -792,30 +709,17 @@ NetLocalGroupGetInfo(
 
     if (AliasHandle == NULL)
     {
-        if (DomainSid != NULL)
-            RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
         if (DomainHandle != NULL)
             SamCloseHandle(DomainHandle);
 
-        /* Get the Account Domain SID */
-        Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
-                                     &DomainSid);
-        if (!NT_SUCCESS(Status))
-        {
-            ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-            ApiStatus = NetpNtStatusToApiStatus(Status);
-            goto done;
-        }
-
         /* Open the Acount Domain */
-        Status = SamOpenDomain(ServerHandle,
-                               DOMAIN_LOOKUP,
-                               DomainSid,
-                               &DomainHandle);
+        Status = OpenAccountDomain(ServerHandle,
+                                   (servername != NULL) ? &ServerName : NULL,
+                                   DOMAIN_LOOKUP,
+                                   &DomainHandle);
         if (!NT_SUCCESS(Status))
         {
-            ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+            ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
             ApiStatus = NetpNtStatusToApiStatus(Status);
             goto done;
         }
@@ -855,9 +759,6 @@ done:
     if (AliasHandle != NULL)
         SamCloseHandle(AliasHandle);
 
-    if (DomainSid != NULL)
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
     if (DomainHandle != NULL)
         SamCloseHandle(DomainHandle);
 
index 612a090..8a23176 100644 (file)
@@ -9,20 +9,6 @@
 
 /* INCLUDES ******************************************************************/
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-
-#define NTOS_MODE_USER
-#include <ndk/rtlfuncs.h>
-#include "ntsam.h"
 #include "netapi32.h"
 
 
@@ -125,4 +111,68 @@ done:
     return Status;
 }
 
+
+NTSTATUS
+OpenAccountDomain(IN SAM_HANDLE ServerHandle,
+                  IN PUNICODE_STRING ServerName,
+                  IN ULONG DesiredAccess,
+                  OUT PSAM_HANDLE DomainHandle)
+{
+    PSID DomainSid = NULL;
+    NTSTATUS Status;
+
+    Status = GetAccountDomainSid(ServerName,
+                                 &DomainSid);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
+        return Status;
+    }
+
+    Status = SamOpenDomain(ServerHandle,
+                           DesiredAccess,
+                           DomainSid,
+                           DomainHandle);
+
+    RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
+
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+    }
+
+    return Status;
+}
+
+
+NTSTATUS
+OpenBuiltinDomain(IN SAM_HANDLE ServerHandle,
+                  IN ULONG DesiredAccess,
+                  OUT PSAM_HANDLE DomainHandle)
+{
+    PSID DomainSid = NULL;
+    NTSTATUS Status;
+
+    Status = GetBuiltinDomainSid(&DomainSid);
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("GetBuiltinDomainSid failed (Status %08lx)\n", Status);
+        return Status;
+    }
+
+    Status = SamOpenDomain(ServerHandle,
+                           DesiredAccess,
+                           DomainSid,
+                           DomainHandle);
+
+    RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
+
+    if (!NT_SUCCESS(Status))
+    {
+        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+    }
+
+    return Status;
+}
+
 /* EOF */
index 27e57f6..31dea80 100644 (file)
@@ -2,6 +2,32 @@
 #ifndef __WINE_NETAPI32_H__
 #define __WINE_NETAPI32_H__
 
+#include <stdarg.h>
+
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
+#include "windef.h"
+#include "winbase.h"
+#include "winerror.h"
+#include "lmcons.h"
+#include "lmaccess.h"
+#include "lmapibuf.h"
+#include "lmbrowsr.h"
+#include "lmerr.h"
+#include "lmshare.h"
+#include "lmuse.h"
+#include "ntsecapi.h"
+#include "dsrole.h"
+#include "dsgetdc.h"
+#include "wine/debug.h"
+#include "wine/unicode.h"
+#include "wine/list.h"
+
+#define NTOS_MODE_USER
+#include <ndk/rtlfuncs.h>
+#include "ntsam.h"
+
+
 NET_API_STATUS
 WINAPI
 NetpNtStatusToApiStatus(NTSTATUS Status);
@@ -15,4 +41,15 @@ GetAccountDomainSid(IN PUNICODE_STRING ServerName,
 NTSTATUS
 GetBuiltinDomainSid(OUT PSID *BuiltinDomainSid);
 
+NTSTATUS
+OpenAccountDomain(IN SAM_HANDLE ServerHandle,
+                  IN PUNICODE_STRING ServerName,
+                  IN ULONG DesiredAccess,
+                  OUT PSAM_HANDLE DomainHandle);
+
+NTSTATUS
+OpenBuiltinDomain(IN SAM_HANDLE ServerHandle,
+                  IN ULONG DesiredAccess,
+                  OUT SAM_HANDLE *DomainHandle);
+
 #endif
\ No newline at end of file
index 20482fa..3022cc3 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#include <stdarg.h>
-
-#include "ntstatus.h"
-#define WIN32_NO_STATUS
-#include "windef.h"
-#include "winbase.h"
-#include "winerror.h"
-#include "lmcons.h"
-#include "lmaccess.h"
-#include "lmapibuf.h"
-#include "lmerr.h"
-#include "lmuse.h"
-#include "ntsecapi.h"
-#include "wine/debug.h"
-#include "wine/unicode.h"
-#include "wine/list.h"
-
-#define NTOS_MODE_USER
-#include <ndk/rtlfuncs.h>
-#include "ntsam.h"
 #include "netapi32.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
@@ -177,7 +157,7 @@ BuildUserInfoBuffer(PUSER_ACCOUNT_INFORMATION UserInfo,
             if (UserInfo->AdminComment.Length > 0)
                 Size += UserInfo->AdminComment.Length + sizeof(WCHAR);
 
-            /* FIXME: Add user comment here */
+            /* FIXME: usri10_usr_comment */
 
             if (UserInfo->FullName.Length > 0)
                 Size += UserInfo->FullName.Length + sizeof(WCHAR);
@@ -239,9 +219,8 @@ BuildUserInfoBuffer(PUSER_ACCOUNT_INFORMATION UserInfo,
 
                 UserInfo1->usri1_password = NULL;
 
-                UserInfo1->usri1_password_age = 0; /* FIXME */
-
-                UserInfo1->usri1_priv = 0; /* FIXME */
+                /* FIXME: UserInfo1->usri1_password_age */
+                /* FIXME: UserInfo1->usri1_priv */
 
                 if (UserInfo->HomeDirectory.Length > 0)
                 {
@@ -310,7 +289,7 @@ BuildUserInfoBuffer(PUSER_ACCOUNT_INFORMATION UserInfo,
                 Ptr = (LPWSTR)((ULONG_PTR)Ptr + UserInfo->AdminComment.Length + sizeof(WCHAR));
             }
 
-            /* FIXME: Add user comment here */
+            /* FIXME: UserInfo10->usri10_usr_comment */
 
             if (UserInfo->FullName.Length > 0)
             {
@@ -323,7 +302,6 @@ BuildUserInfoBuffer(PUSER_ACCOUNT_INFORMATION UserInfo,
             }
             break;
 
-
 //        case 11:
 
         case 20:
@@ -592,10 +570,7 @@ NetUserEnum(LPCWSTR servername,
     PSAM_RID_ENUMERATION CurrentUser;
     PENUM_CONTEXT EnumContext = NULL;
     LPVOID Buffer = NULL;
-    PSID DomainSid = NULL;
-
     ULONG i;
-
     SAM_HANDLE UserHandle = NULL;
     PUSER_ACCOUNT_INFORMATION UserInfo = NULL;
 
@@ -639,47 +614,23 @@ NetUserEnum(LPCWSTR servername,
             goto done;
         }
 
-        Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
-                                     &DomainSid);
-        if (!NT_SUCCESS(Status))
-        {
-            ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-            ApiStatus = NetpNtStatusToApiStatus(Status);
-            goto done;
-        }
-
-        Status = SamOpenDomain(EnumContext->ServerHandle,
-                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
-                               DomainSid,
-                               &EnumContext->AccountDomainHandle);
-
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
+        Status = OpenAccountDomain(EnumContext->ServerHandle,
+                                   (servername != NULL) ? &ServerName : NULL,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->AccountDomainHandle);
         if (!NT_SUCCESS(Status))
         {
-            ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+            ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
             ApiStatus = NetpNtStatusToApiStatus(Status);
             goto done;
         }
 
-        Status = GetBuiltinDomainSid(&DomainSid);
+        Status = OpenBuiltinDomain(EnumContext->ServerHandle,
+                                   DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                                   &EnumContext->BuiltinDomainHandle);
         if (!NT_SUCCESS(Status))
         {
-            ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-            ApiStatus = NetpNtStatusToApiStatus(Status);
-            goto done;
-        }
-
-        Status = SamOpenDomain(EnumContext->ServerHandle,
-                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
-                               DomainSid,
-                               &EnumContext->BuiltinDomainHandle);
-
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
-        if (!NT_SUCCESS(Status))
-        {
-            ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+            ERR("OpenBuiltinDomain failed (Status %08lx)\n", Status);
             ApiStatus = NetpNtStatusToApiStatus(Status);
             goto done;
         }
@@ -871,7 +822,6 @@ NetUserGetInfo(LPCWSTR servername,
     SAM_HANDLE ServerHandle = NULL;
     SAM_HANDLE AccountDomainHandle = NULL;
     SAM_HANDLE UserHandle = NULL;
-    PSID DomainSid = NULL;
     PULONG RelativeIds = NULL;
     PSID_NAME_USE Use = NULL;
     PUSER_ACCOUNT_INFORMATION UserInfo = NULL;
@@ -899,24 +849,14 @@ NetUserGetInfo(LPCWSTR servername,
         goto done;
     }
 
-    /* Get the Account Domain SID */
-    Status = GetAccountDomainSid((servername != NULL) ? &ServerName : NULL,
-                                 &DomainSid);
-    if (!NT_SUCCESS(Status))
-    {
-        ERR("GetAccountDomainSid failed (Status %08lx)\n", Status);
-        ApiStatus = NetpNtStatusToApiStatus(Status);
-        goto done;
-    }
-
     /* Open the Account Domain */
-    Status = SamOpenDomain(ServerHandle,
-                           DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
-                           DomainSid,
-                           &AccountDomainHandle);
+    Status = OpenAccountDomain(ServerHandle,
+                               (servername != NULL) ? &ServerName : NULL,
+                               DOMAIN_LIST_ACCOUNTS | DOMAIN_LOOKUP,
+                               &AccountDomainHandle);
     if (!NT_SUCCESS(Status))
     {
-        ERR("SamOpenDomain failed (Status %08lx)\n", Status);
+        ERR("OpenAccountDomain failed (Status %08lx)\n", Status);
         ApiStatus = NetpNtStatusToApiStatus(Status);
         goto done;
     }
@@ -989,9 +929,6 @@ done:
     if (Use != NULL)
         SamFreeMemory(Use);
 
-    if (DomainSid != NULL)
-        RtlFreeHeap(RtlGetProcessHeap(), 0, DomainSid);
-
     if (AccountDomainHandle != NULL)
         SamCloseHandle(AccountDomainHandle);