xref: /reactos/dll/win32/netapi32/netlogon.c (revision 8571c26a)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * COPYRIGHT:       See COPYING in the top level directory
3c2c66affSColin Finck  * PROJECT:         NetAPI DLL
4c2c66affSColin Finck  * FILE:            dll/win32/netapi32/netlogon.c
5c2c66affSColin Finck  * PURPOSE:         Netlogon service interface code
6c2c66affSColin Finck  * PROGRAMMERS:     Eric Kohl (eric.kohl@reactos.org)
7c2c66affSColin Finck  */
8c2c66affSColin Finck 
9c2c66affSColin Finck /* INCLUDES ******************************************************************/
10c2c66affSColin Finck 
11c2c66affSColin Finck #include "netapi32.h"
12c2c66affSColin Finck #include <winsock2.h>
13c2c66affSColin Finck #include <rpc.h>
14c2c66affSColin Finck #include <dsrole.h>
15c2c66affSColin Finck #include <dsgetdc.h>
16c2c66affSColin Finck #include "netlogon_c.h"
17c2c66affSColin Finck 
18c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
19c2c66affSColin Finck 
2057d48a7fSEric Kohl DWORD
2157d48a7fSEric Kohl WINAPI
2257d48a7fSEric Kohl DsGetDcNameWithAccountA(
2357d48a7fSEric Kohl     _In_opt_ LPCSTR ComputerName,
2457d48a7fSEric Kohl     _In_opt_ LPCSTR AccountName,
2557d48a7fSEric Kohl     _In_ ULONG AccountControlBits,
2657d48a7fSEric Kohl     _In_ LPCSTR DomainName,
2757d48a7fSEric Kohl     _In_ GUID *DomainGuid,
2857d48a7fSEric Kohl     _In_ LPCSTR SiteName,
2957d48a7fSEric Kohl     _In_ ULONG Flags,
3057d48a7fSEric Kohl     _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo);
3157d48a7fSEric Kohl 
3257d48a7fSEric Kohl DWORD
3357d48a7fSEric Kohl WINAPI
3457d48a7fSEric Kohl DsGetDcNameWithAccountW(
35adceb380SEric Kohl     _In_opt_ LPCWSTR ComputerName,
3657d48a7fSEric Kohl     _In_opt_ LPCWSTR AccountName,
3757d48a7fSEric Kohl     _In_ ULONG AccountControlBits,
3857d48a7fSEric Kohl     _In_ LPCWSTR DomainName,
3957d48a7fSEric Kohl     _In_ GUID *DomainGuid,
4057d48a7fSEric Kohl     _In_ LPCWSTR SiteName,
4157d48a7fSEric Kohl     _In_ ULONG Flags,
4257d48a7fSEric Kohl     _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo);
4357d48a7fSEric Kohl 
44c2c66affSColin Finck /* FUNCTIONS *****************************************************************/
45c2c66affSColin Finck 
46c2c66affSColin Finck handle_t
47c2c66affSColin Finck __RPC_USER
LOGONSRV_HANDLE_bind(LOGONSRV_HANDLE pszSystemName)48c2c66affSColin Finck LOGONSRV_HANDLE_bind(
49c2c66affSColin Finck     LOGONSRV_HANDLE pszSystemName)
50c2c66affSColin Finck {
51c2c66affSColin Finck     handle_t hBinding = NULL;
52c2c66affSColin Finck     LPWSTR pszStringBinding;
53c2c66affSColin Finck     RPC_STATUS status;
54c2c66affSColin Finck 
55c2c66affSColin Finck     TRACE("LOGONSRV_HANDLE_bind() called\n");
56c2c66affSColin Finck 
57c2c66affSColin Finck     status = RpcStringBindingComposeW(NULL,
58c2c66affSColin Finck                                       L"ncacn_np",
59c2c66affSColin Finck                                       pszSystemName,
60c2c66affSColin Finck                                       L"\\pipe\\netlogon",
61c2c66affSColin Finck                                       NULL,
62c2c66affSColin Finck                                       &pszStringBinding);
63c2c66affSColin Finck     if (status)
64c2c66affSColin Finck     {
65c2c66affSColin Finck         TRACE("RpcStringBindingCompose returned 0x%x\n", status);
66c2c66affSColin Finck         return NULL;
67c2c66affSColin Finck     }
68c2c66affSColin Finck 
69c2c66affSColin Finck     /* Set the binding handle that will be used to bind to the server. */
70c2c66affSColin Finck     status = RpcBindingFromStringBindingW(pszStringBinding,
71c2c66affSColin Finck                                           &hBinding);
72c2c66affSColin Finck     if (status)
73c2c66affSColin Finck     {
74c2c66affSColin Finck         TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
75c2c66affSColin Finck     }
76c2c66affSColin Finck 
77c2c66affSColin Finck     status = RpcStringFreeW(&pszStringBinding);
78c2c66affSColin Finck     if (status)
79c2c66affSColin Finck     {
80c2c66affSColin Finck //        TRACE("RpcStringFree returned 0x%x\n", status);
81c2c66affSColin Finck     }
82c2c66affSColin Finck 
83c2c66affSColin Finck     return hBinding;
84c2c66affSColin Finck }
85c2c66affSColin Finck 
86c2c66affSColin Finck 
87c2c66affSColin Finck void
88c2c66affSColin Finck __RPC_USER
LOGONSRV_HANDLE_unbind(LOGONSRV_HANDLE pszSystemName,handle_t hBinding)89c2c66affSColin Finck LOGONSRV_HANDLE_unbind(
90c2c66affSColin Finck     LOGONSRV_HANDLE pszSystemName,
91c2c66affSColin Finck     handle_t hBinding)
92c2c66affSColin Finck {
93c2c66affSColin Finck     RPC_STATUS status;
94c2c66affSColin Finck 
95c2c66affSColin Finck     TRACE("LOGONSRV_HANDLE_unbind() called\n");
96c2c66affSColin Finck 
97c2c66affSColin Finck     status = RpcBindingFree(&hBinding);
98c2c66affSColin Finck     if (status)
99c2c66affSColin Finck     {
100c2c66affSColin Finck         TRACE("RpcBindingFree returned 0x%x\n", status);
101c2c66affSColin Finck     }
102c2c66affSColin Finck }
103c2c66affSColin Finck 
104c2c66affSColin Finck 
105c2c66affSColin Finck /* PUBLIC FUNCTIONS **********************************************************/
106c2c66affSColin Finck 
107c2c66affSColin Finck DWORD
108c2c66affSColin Finck WINAPI
DsAddressToSiteNamesA(_In_opt_ LPCSTR ComputerName,_In_ DWORD EntryCount,_In_ PSOCKET_ADDRESS SocketAddresses,_Out_ LPSTR ** SiteNames)109c2c66affSColin Finck DsAddressToSiteNamesA(
110c2c66affSColin Finck     _In_opt_ LPCSTR ComputerName,
111c2c66affSColin Finck     _In_ DWORD EntryCount,
112c2c66affSColin Finck     _In_ PSOCKET_ADDRESS SocketAddresses,
113c2c66affSColin Finck     _Out_ LPSTR **SiteNames)
114c2c66affSColin Finck {
115abeb3324SEric Kohl     PWSTR pComputerNameW = NULL, *pSiteNamesW = NULL;
116abeb3324SEric Kohl     PSTR *pSiteNamesA = NULL, Ptr;
117abeb3324SEric Kohl     UNICODE_STRING UnicodeString;
118abeb3324SEric Kohl     ANSI_STRING AnsiString;
119abeb3324SEric Kohl     ULONG BufferSize, i;
120abeb3324SEric Kohl     NTSTATUS Status;
121abeb3324SEric Kohl     NET_API_STATUS status = NERR_Success;
122abeb3324SEric Kohl 
123abeb3324SEric Kohl     TRACE("DsAddressToSiteNamesA(%s, %lu, %p, %p)\n",
124c2c66affSColin Finck           debugstr_a(ComputerName), EntryCount, SocketAddresses, SiteNames);
125abeb3324SEric Kohl 
126abeb3324SEric Kohl     if (EntryCount == 0)
127abeb3324SEric Kohl         return ERROR_INVALID_PARAMETER;
128abeb3324SEric Kohl 
129abeb3324SEric Kohl     if (ComputerName != NULL)
130abeb3324SEric Kohl     {
131abeb3324SEric Kohl         pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
132abeb3324SEric Kohl         if (pComputerNameW == NULL)
133abeb3324SEric Kohl         {
134abeb3324SEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
135abeb3324SEric Kohl             goto done;
136abeb3324SEric Kohl         }
137abeb3324SEric Kohl     }
138abeb3324SEric Kohl 
139abeb3324SEric Kohl     /* Call the Unicode function */
140abeb3324SEric Kohl     status = DsAddressToSiteNamesW(pComputerNameW,
141abeb3324SEric Kohl                                    EntryCount,
142abeb3324SEric Kohl                                    SocketAddresses,
143abeb3324SEric Kohl                                    &pSiteNamesW);
144abeb3324SEric Kohl     if (status != NERR_Success)
145abeb3324SEric Kohl         goto done;
146abeb3324SEric Kohl 
147abeb3324SEric Kohl     /* Calculate the required site names buffer size */
148abeb3324SEric Kohl     BufferSize = EntryCount * sizeof(PSTR);
149abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
150abeb3324SEric Kohl     {
151abeb3324SEric Kohl         if (pSiteNamesW[i] != NULL)
152abeb3324SEric Kohl         {
153abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
154abeb3324SEric Kohl                                  pSiteNamesW[i]);
155abeb3324SEric Kohl             BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
156abeb3324SEric Kohl         }
157abeb3324SEric Kohl     }
158abeb3324SEric Kohl 
159abeb3324SEric Kohl     /* Allocate the site names ANSI buffer */
160abeb3324SEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
161abeb3324SEric Kohl     if (status != NERR_Success)
162abeb3324SEric Kohl         goto done;
163abeb3324SEric Kohl 
164abeb3324SEric Kohl     /* Convert the site names */
165abeb3324SEric Kohl     Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + EntryCount * sizeof(PSTR));
166abeb3324SEric Kohl     BufferSize -= EntryCount * sizeof(PSTR);
167abeb3324SEric Kohl 
168abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
169abeb3324SEric Kohl     {
170abeb3324SEric Kohl         if (pSiteNamesW[i] != NULL)
171abeb3324SEric Kohl         {
172abeb3324SEric Kohl             pSiteNamesA[i] = Ptr;
173abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
174abeb3324SEric Kohl                                  pSiteNamesW[i]);
175abeb3324SEric Kohl             AnsiString.Length = 0;
176abeb3324SEric Kohl             AnsiString.MaximumLength = BufferSize;
177abeb3324SEric Kohl             AnsiString.Buffer = Ptr;
178abeb3324SEric Kohl 
179abeb3324SEric Kohl             Status = RtlUnicodeStringToAnsiString(&AnsiString,
180abeb3324SEric Kohl                                                   &UnicodeString,
181abeb3324SEric Kohl                                                   FALSE);
182abeb3324SEric Kohl             if (!NT_SUCCESS(Status))
183abeb3324SEric Kohl             {
184abeb3324SEric Kohl                 status = RtlNtStatusToDosError(Status);
185abeb3324SEric Kohl                 goto done;
186abeb3324SEric Kohl             }
187abeb3324SEric Kohl 
188abeb3324SEric Kohl             Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
189abeb3324SEric Kohl             BufferSize -= AnsiString.Length + sizeof(CHAR);
190abeb3324SEric Kohl         }
191abeb3324SEric Kohl     }
192abeb3324SEric Kohl 
193abeb3324SEric Kohl     *SiteNames = pSiteNamesA;
194abeb3324SEric Kohl     pSiteNamesA = NULL;
195abeb3324SEric Kohl 
196abeb3324SEric Kohl done:
197abeb3324SEric Kohl     if (pSiteNamesA != NULL)
198abeb3324SEric Kohl         NetApiBufferFree(pSiteNamesA);
199abeb3324SEric Kohl 
200abeb3324SEric Kohl     if (pSiteNamesW != NULL)
201abeb3324SEric Kohl         NetApiBufferFree(pSiteNamesW);
202abeb3324SEric Kohl 
203abeb3324SEric Kohl     if (pComputerNameW != NULL)
204abeb3324SEric Kohl         NetApiBufferFree(pComputerNameW);
205abeb3324SEric Kohl 
206abeb3324SEric Kohl     return status;
207c2c66affSColin Finck }
208c2c66affSColin Finck 
209c2c66affSColin Finck 
210c2c66affSColin Finck DWORD
211c2c66affSColin Finck WINAPI
DsAddressToSiteNamesW(_In_opt_ LPCWSTR ComputerName,_In_ DWORD EntryCount,_In_ PSOCKET_ADDRESS SocketAddresses,_Out_ LPWSTR ** SiteNames)212c2c66affSColin Finck DsAddressToSiteNamesW(
213c2c66affSColin Finck     _In_opt_ LPCWSTR ComputerName,
214c2c66affSColin Finck     _In_ DWORD EntryCount,
215c2c66affSColin Finck     _In_ PSOCKET_ADDRESS SocketAddresses,
216c2c66affSColin Finck     _Out_ LPWSTR **SiteNames)
217c2c66affSColin Finck {
218c2c66affSColin Finck     PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
219c2c66affSColin Finck     PWSTR *SiteNamesBuffer = NULL, Ptr;
220c2c66affSColin Finck     ULONG BufferSize, i;
221c2c66affSColin Finck     NET_API_STATUS status;
222c2c66affSColin Finck 
223c2c66affSColin Finck     TRACE("DsAddressToSiteNamesW(%s, %lu, %p, %p)\n",
224c2c66affSColin Finck           debugstr_w(ComputerName), EntryCount, SocketAddresses, SiteNames);
225c2c66affSColin Finck 
226c2c66affSColin Finck     if (EntryCount == 0)
227c2c66affSColin Finck         return ERROR_INVALID_PARAMETER;
228c2c66affSColin Finck 
229c2c66affSColin Finck     *SiteNames = NULL;
230c2c66affSColin Finck 
231c2c66affSColin Finck     RpcTryExcept
232c2c66affSColin Finck     {
233c2c66affSColin Finck         status = DsrAddressToSiteNamesW((PWSTR)ComputerName,
234c2c66affSColin Finck                                         EntryCount,
235c2c66affSColin Finck                                         (PNL_SOCKET_ADDRESS)SocketAddresses,
236c2c66affSColin Finck                                         &SiteNameArray);
237c2c66affSColin Finck         if (status == NERR_Success)
238c2c66affSColin Finck         {
239c2c66affSColin Finck             if (SiteNameArray->EntryCount == 0)
240c2c66affSColin Finck             {
241c2c66affSColin Finck                 status = ERROR_INVALID_PARAMETER;
242c2c66affSColin Finck             }
243c2c66affSColin Finck             else
244c2c66affSColin Finck             {
245c2c66affSColin Finck                 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
246c2c66affSColin Finck                 for (i = 0; i < SiteNameArray->EntryCount; i++)
247c2c66affSColin Finck                     BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
248c2c66affSColin Finck 
249c2c66affSColin Finck                 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
250c2c66affSColin Finck                 if (status == NERR_Success)
251c2c66affSColin Finck                 {
252c2c66affSColin Finck                     ZeroMemory(SiteNamesBuffer, BufferSize);
253c2c66affSColin Finck 
254c2c66affSColin Finck                     Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
255c2c66affSColin Finck                     for (i = 0; i < SiteNameArray->EntryCount; i++)
256c2c66affSColin Finck                     {
257c2c66affSColin Finck                         SiteNamesBuffer[i] = Ptr;
258c2c66affSColin Finck                         CopyMemory(Ptr,
259c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Buffer,
260c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Length);
261c2c66affSColin Finck 
262c2c66affSColin Finck                         Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
263c2c66affSColin Finck                     }
264c2c66affSColin Finck 
265c2c66affSColin Finck                     *SiteNames = SiteNamesBuffer;
266c2c66affSColin Finck                 }
267c2c66affSColin Finck             }
268c2c66affSColin Finck 
269c2c66affSColin Finck             MIDL_user_free(SiteNameArray);
270c2c66affSColin Finck         }
271c2c66affSColin Finck     }
272c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
273c2c66affSColin Finck     {
274c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
275c2c66affSColin Finck     }
276c2c66affSColin Finck     RpcEndExcept;
277c2c66affSColin Finck 
278c2c66affSColin Finck     return status;
279c2c66affSColin Finck }
280c2c66affSColin Finck 
281c2c66affSColin Finck 
282c2c66affSColin Finck DWORD
283c2c66affSColin Finck WINAPI
DsAddressToSiteNamesExA(_In_opt_ LPCSTR ComputerName,_In_ DWORD EntryCount,_In_ PSOCKET_ADDRESS SocketAddresses,_Out_ LPSTR ** SiteNames,_Out_ LPSTR ** SubnetNames)284c2c66affSColin Finck DsAddressToSiteNamesExA(
285c2c66affSColin Finck     _In_opt_ LPCSTR ComputerName,
286c2c66affSColin Finck     _In_ DWORD EntryCount,
287c2c66affSColin Finck     _In_ PSOCKET_ADDRESS SocketAddresses,
288c2c66affSColin Finck     _Out_ LPSTR **SiteNames,
289c2c66affSColin Finck     _Out_ LPSTR **SubnetNames)
290c2c66affSColin Finck {
291abeb3324SEric Kohl     PWSTR pComputerNameW = NULL, *pSiteNamesW = NULL;
292abeb3324SEric Kohl     PWSTR *pSubnetNamesW = NULL;
293abeb3324SEric Kohl     PSTR *pSiteNamesA = NULL, *pSubnetNamesA = NULL, Ptr;
294abeb3324SEric Kohl     UNICODE_STRING UnicodeString;
295abeb3324SEric Kohl     ANSI_STRING AnsiString;
296abeb3324SEric Kohl     ULONG BufferSize, i;
297abeb3324SEric Kohl     NTSTATUS Status;
298abeb3324SEric Kohl     NET_API_STATUS status = NERR_Success;
299abeb3324SEric Kohl 
300abeb3324SEric Kohl     TRACE("DsAddressToSiteNamesExA(%s, %lu, %p, %p, %p)\n",
301c2c66affSColin Finck           debugstr_a(ComputerName), EntryCount, SocketAddresses,
302c2c66affSColin Finck           SiteNames, SubnetNames);
303abeb3324SEric Kohl 
304abeb3324SEric Kohl     if (EntryCount == 0)
305abeb3324SEric Kohl         return ERROR_INVALID_PARAMETER;
306abeb3324SEric Kohl 
307abeb3324SEric Kohl     if (ComputerName != NULL)
308abeb3324SEric Kohl     {
309abeb3324SEric Kohl         pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
310abeb3324SEric Kohl         if (pComputerNameW == NULL)
311abeb3324SEric Kohl         {
312abeb3324SEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
313abeb3324SEric Kohl             goto done;
314abeb3324SEric Kohl         }
315abeb3324SEric Kohl     }
316abeb3324SEric Kohl 
317abeb3324SEric Kohl     /* Call the Unicode function */
318abeb3324SEric Kohl     status = DsAddressToSiteNamesExW(pComputerNameW,
319abeb3324SEric Kohl                                      EntryCount,
320abeb3324SEric Kohl                                      SocketAddresses,
321abeb3324SEric Kohl                                      &pSiteNamesW,
322abeb3324SEric Kohl                                      &pSubnetNamesW);
323abeb3324SEric Kohl     if (status != NERR_Success)
324abeb3324SEric Kohl         goto done;
325abeb3324SEric Kohl 
326abeb3324SEric Kohl     /* Calculate the required site names buffer size */
327abeb3324SEric Kohl     BufferSize = EntryCount * sizeof(PSTR);
328abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
329abeb3324SEric Kohl     {
330abeb3324SEric Kohl         if (pSiteNamesW[i] != NULL)
331abeb3324SEric Kohl         {
332abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
333abeb3324SEric Kohl                                  pSiteNamesW[i]);
334abeb3324SEric Kohl             BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
335abeb3324SEric Kohl         }
336abeb3324SEric Kohl     }
337abeb3324SEric Kohl 
338abeb3324SEric Kohl     /* Allocate the site names ANSI buffer */
339abeb3324SEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
340abeb3324SEric Kohl     if (status != NERR_Success)
341abeb3324SEric Kohl         goto done;
342abeb3324SEric Kohl 
343abeb3324SEric Kohl     /* Convert the site names */
344abeb3324SEric Kohl     Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + EntryCount * sizeof(PSTR));
345abeb3324SEric Kohl     BufferSize -= EntryCount * sizeof(PSTR);
346abeb3324SEric Kohl 
347abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
348abeb3324SEric Kohl     {
349abeb3324SEric Kohl         if (pSiteNamesW[i] != NULL)
350abeb3324SEric Kohl         {
351abeb3324SEric Kohl             pSiteNamesA[i] = Ptr;
352abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
353abeb3324SEric Kohl                                  pSiteNamesW[i]);
354abeb3324SEric Kohl             AnsiString.Length = 0;
355abeb3324SEric Kohl             AnsiString.MaximumLength = BufferSize;
356abeb3324SEric Kohl             AnsiString.Buffer = Ptr;
357abeb3324SEric Kohl 
358abeb3324SEric Kohl             Status = RtlUnicodeStringToAnsiString(&AnsiString,
359abeb3324SEric Kohl                                                   &UnicodeString,
360abeb3324SEric Kohl                                                   FALSE);
361abeb3324SEric Kohl             if (!NT_SUCCESS(Status))
362abeb3324SEric Kohl             {
363abeb3324SEric Kohl                 status = RtlNtStatusToDosError(Status);
364abeb3324SEric Kohl                 goto done;
365abeb3324SEric Kohl             }
366abeb3324SEric Kohl 
367abeb3324SEric Kohl             Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
368abeb3324SEric Kohl             BufferSize -= AnsiString.Length + sizeof(CHAR);
369abeb3324SEric Kohl         }
370abeb3324SEric Kohl     }
371abeb3324SEric Kohl 
372abeb3324SEric Kohl     /* Calculate the required subnet names buffer size */
373abeb3324SEric Kohl     BufferSize = EntryCount * sizeof(PSTR);
374abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
375abeb3324SEric Kohl     {
376abeb3324SEric Kohl         if (pSubnetNamesW[i] != NULL)
377abeb3324SEric Kohl         {
378abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
379abeb3324SEric Kohl                                  pSubnetNamesW[i]);
380abeb3324SEric Kohl             BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
381abeb3324SEric Kohl         }
382abeb3324SEric Kohl     }
383abeb3324SEric Kohl 
384abeb3324SEric Kohl     /* Allocate the subnet names ANSI buffer */
385abeb3324SEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSubnetNamesA);
386abeb3324SEric Kohl     if (status != NERR_Success)
387abeb3324SEric Kohl         goto done;
388abeb3324SEric Kohl 
389abeb3324SEric Kohl     /* Convert the subnet names */
390abeb3324SEric Kohl     Ptr = (PSTR)((ULONG_PTR)pSubnetNamesA + EntryCount * sizeof(PSTR));
391abeb3324SEric Kohl     BufferSize -= EntryCount * sizeof(PSTR);
392abeb3324SEric Kohl 
393abeb3324SEric Kohl     for (i = 0; i < EntryCount; i++)
394abeb3324SEric Kohl     {
395abeb3324SEric Kohl         if (pSubnetNamesW[i] != NULL)
396abeb3324SEric Kohl         {
397abeb3324SEric Kohl             pSubnetNamesA[i] = Ptr;
398abeb3324SEric Kohl             RtlInitUnicodeString(&UnicodeString,
399abeb3324SEric Kohl                                  pSubnetNamesW[i]);
400abeb3324SEric Kohl             AnsiString.Length = 0;
401abeb3324SEric Kohl             AnsiString.MaximumLength = BufferSize;
402abeb3324SEric Kohl             AnsiString.Buffer = Ptr;
403abeb3324SEric Kohl 
404abeb3324SEric Kohl             Status = RtlUnicodeStringToAnsiString(&AnsiString,
405abeb3324SEric Kohl                                                   &UnicodeString,
406abeb3324SEric Kohl                                                   FALSE);
407abeb3324SEric Kohl             if (!NT_SUCCESS(Status))
408abeb3324SEric Kohl             {
409abeb3324SEric Kohl                 status = RtlNtStatusToDosError(Status);
410abeb3324SEric Kohl                 goto done;
411abeb3324SEric Kohl             }
412abeb3324SEric Kohl 
413abeb3324SEric Kohl             Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
414abeb3324SEric Kohl             BufferSize -= AnsiString.Length + sizeof(CHAR);
415abeb3324SEric Kohl         }
416abeb3324SEric Kohl     }
417abeb3324SEric Kohl 
418abeb3324SEric Kohl     *SiteNames = pSiteNamesA;
419abeb3324SEric Kohl     *SubnetNames = pSubnetNamesA;
420abeb3324SEric Kohl     pSiteNamesA = NULL;
421abeb3324SEric Kohl     pSubnetNamesA = NULL;
422abeb3324SEric Kohl 
423abeb3324SEric Kohl done:
424abeb3324SEric Kohl     if (pSubnetNamesA != NULL)
425abeb3324SEric Kohl         NetApiBufferFree(pSubnetNamesA);
426abeb3324SEric Kohl 
427abeb3324SEric Kohl     if (pSiteNamesA != NULL)
428abeb3324SEric Kohl         NetApiBufferFree(pSiteNamesA);
429abeb3324SEric Kohl 
430abeb3324SEric Kohl     if (pSubnetNamesW != NULL)
431abeb3324SEric Kohl         NetApiBufferFree(pSubnetNamesW);
432abeb3324SEric Kohl 
433abeb3324SEric Kohl     if (pSiteNamesW != NULL)
434abeb3324SEric Kohl         NetApiBufferFree(pSiteNamesW);
435abeb3324SEric Kohl 
436abeb3324SEric Kohl     if (pComputerNameW != NULL)
437abeb3324SEric Kohl         NetApiBufferFree(pComputerNameW);
438abeb3324SEric Kohl 
439abeb3324SEric Kohl     return status;
440c2c66affSColin Finck }
441c2c66affSColin Finck 
442c2c66affSColin Finck 
443c2c66affSColin Finck DWORD
444c2c66affSColin Finck WINAPI
DsAddressToSiteNamesExW(_In_opt_ LPCWSTR ComputerName,_In_ DWORD EntryCount,_In_ PSOCKET_ADDRESS SocketAddresses,_Out_ LPWSTR ** SiteNames,_Out_ LPWSTR ** SubnetNames)445c2c66affSColin Finck DsAddressToSiteNamesExW(
446c2c66affSColin Finck     _In_opt_ LPCWSTR ComputerName,
447c2c66affSColin Finck     _In_ DWORD EntryCount,
448c2c66affSColin Finck     _In_ PSOCKET_ADDRESS SocketAddresses,
449c2c66affSColin Finck     _Out_ LPWSTR **SiteNames,
450c2c66affSColin Finck     _Out_ LPWSTR **SubnetNames)
451c2c66affSColin Finck {
452c2c66affSColin Finck     PNL_SITE_NAME_EX_ARRAY SiteNameArray = NULL;
453c2c66affSColin Finck     PWSTR *SiteNamesBuffer = NULL, *SubnetNamesBuffer = NULL, Ptr;
454c2c66affSColin Finck     ULONG SiteNameBufferSize, SubnetNameBufferSize, i;
455c2c66affSColin Finck     NET_API_STATUS status;
456c2c66affSColin Finck 
457c2c66affSColin Finck     TRACE("DsAddressToSiteNamesExW(%s, %lu, %p, %p, %p)\n",
458c2c66affSColin Finck           debugstr_w(ComputerName), EntryCount, SocketAddresses,
459c2c66affSColin Finck           SiteNames, SubnetNames);
460c2c66affSColin Finck 
461c2c66affSColin Finck     if (EntryCount == 0)
462c2c66affSColin Finck         return ERROR_INVALID_PARAMETER;
463c2c66affSColin Finck 
464c2c66affSColin Finck     *SiteNames = NULL;
465c2c66affSColin Finck     *SubnetNames = NULL;
466c2c66affSColin Finck 
467c2c66affSColin Finck     RpcTryExcept
468c2c66affSColin Finck     {
469c2c66affSColin Finck         status = DsrAddressToSiteNamesExW((PWSTR)ComputerName,
470c2c66affSColin Finck                                           EntryCount,
471c2c66affSColin Finck                                           (PNL_SOCKET_ADDRESS)SocketAddresses,
472c2c66affSColin Finck                                           &SiteNameArray);
473c2c66affSColin Finck         if (status == NERR_Success)
474c2c66affSColin Finck         {
475c2c66affSColin Finck             if (SiteNameArray->EntryCount == 0)
476c2c66affSColin Finck             {
477c2c66affSColin Finck                 status = ERROR_INVALID_PARAMETER;
478c2c66affSColin Finck             }
479c2c66affSColin Finck             else
480c2c66affSColin Finck             {
481c2c66affSColin Finck                 SiteNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
482c2c66affSColin Finck                 SubnetNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
483c2c66affSColin Finck                 for (i = 0; i < SiteNameArray->EntryCount; i++)
484c2c66affSColin Finck                 {
485c2c66affSColin Finck                     SiteNameBufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
486c2c66affSColin Finck                     SubnetNameBufferSize += SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR);
487c2c66affSColin Finck                 }
488c2c66affSColin Finck 
489c2c66affSColin Finck                 status = NetApiBufferAllocate(SiteNameBufferSize, (PVOID*)&SiteNamesBuffer);
490c2c66affSColin Finck                 if (status == NERR_Success)
491c2c66affSColin Finck                 {
492c2c66affSColin Finck                     ZeroMemory(SiteNamesBuffer, SiteNameBufferSize);
493c2c66affSColin Finck 
494c2c66affSColin Finck                     Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
495c2c66affSColin Finck                     for (i = 0; i < SiteNameArray->EntryCount; i++)
496c2c66affSColin Finck                     {
497c2c66affSColin Finck                         SiteNamesBuffer[i] = Ptr;
498c2c66affSColin Finck                         CopyMemory(Ptr,
499c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Buffer,
500c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Length);
501c2c66affSColin Finck 
502c2c66affSColin Finck                         Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
503c2c66affSColin Finck                     }
504c2c66affSColin Finck 
505c2c66affSColin Finck                     *SiteNames = SiteNamesBuffer;
506c2c66affSColin Finck                 }
507c2c66affSColin Finck 
508c2c66affSColin Finck                 status = NetApiBufferAllocate(SubnetNameBufferSize, (PVOID*)&SubnetNamesBuffer);
509c2c66affSColin Finck                 if (status == NERR_Success)
510c2c66affSColin Finck                 {
511c2c66affSColin Finck                     ZeroMemory(SubnetNamesBuffer, SubnetNameBufferSize);
512c2c66affSColin Finck 
513c2c66affSColin Finck                     Ptr = (PWSTR)((ULONG_PTR)SubnetNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
514c2c66affSColin Finck                     for (i = 0; i < SiteNameArray->EntryCount; i++)
515c2c66affSColin Finck                     {
516c2c66affSColin Finck                         SubnetNamesBuffer[i] = Ptr;
517c2c66affSColin Finck                         CopyMemory(Ptr,
518c2c66affSColin Finck                                    SiteNameArray->SubnetNames[i].Buffer,
519c2c66affSColin Finck                                    SiteNameArray->SubnetNames[i].Length);
520c2c66affSColin Finck 
521c2c66affSColin Finck                         Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR));
522c2c66affSColin Finck                     }
523c2c66affSColin Finck 
524c2c66affSColin Finck                     *SubnetNames = SubnetNamesBuffer;
525c2c66affSColin Finck                 }
526c2c66affSColin Finck             }
527c2c66affSColin Finck 
528c2c66affSColin Finck             MIDL_user_free(SiteNameArray);
529c2c66affSColin Finck         }
530c2c66affSColin Finck     }
531c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
532c2c66affSColin Finck     {
533c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
534c2c66affSColin Finck     }
535c2c66affSColin Finck     RpcEndExcept;
536c2c66affSColin Finck 
537c2c66affSColin Finck     return status;
538c2c66affSColin Finck }
539c2c66affSColin Finck 
540c2c66affSColin Finck 
541c2c66affSColin Finck DWORD
542c2c66affSColin Finck WINAPI
DsDeregisterDnsHostRecordsA(_In_opt_ LPSTR ServerName,_In_opt_ LPSTR DnsDomainName,_In_opt_ GUID * DomainGuid,_In_opt_ GUID * DsaGuid,_In_ LPSTR DnsHostName)543c2c66affSColin Finck DsDeregisterDnsHostRecordsA(
544c2c66affSColin Finck     _In_opt_ LPSTR ServerName,
545c2c66affSColin Finck     _In_opt_ LPSTR DnsDomainName,
546c2c66affSColin Finck     _In_opt_ GUID *DomainGuid,
547c2c66affSColin Finck     _In_opt_ GUID *DsaGuid,
548c2c66affSColin Finck     _In_ LPSTR DnsHostName)
549c2c66affSColin Finck {
550c9537b39SEric Kohl     PWSTR pServerNameW = NULL, pDnsDomainNameW = NULL;
551c9537b39SEric Kohl     PWSTR pDnsHostNameW = NULL;
552c9537b39SEric Kohl     NET_API_STATUS status = NERR_Success;
553c9537b39SEric Kohl 
554c9537b39SEric Kohl     TRACE("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
555c2c66affSColin Finck           debugstr_a(ServerName), debugstr_a(DnsDomainName),
556c2c66affSColin Finck           DomainGuid, DsaGuid, debugstr_a(DnsHostName));
557c9537b39SEric Kohl 
558c9537b39SEric Kohl     if (ServerName != NULL)
559c9537b39SEric Kohl     {
560c9537b39SEric Kohl         pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
561c9537b39SEric Kohl         if (pServerNameW == NULL)
562c9537b39SEric Kohl         {
563c9537b39SEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
564c9537b39SEric Kohl             goto done;
565c9537b39SEric Kohl         }
566c9537b39SEric Kohl     }
567c9537b39SEric Kohl 
568c9537b39SEric Kohl     if (DnsDomainName != NULL)
569c9537b39SEric Kohl     {
570c9537b39SEric Kohl         pDnsDomainNameW = NetpAllocWStrFromAnsiStr((PSTR)DnsDomainName);
571c9537b39SEric Kohl         if (pDnsDomainNameW == NULL)
572c9537b39SEric Kohl         {
573c9537b39SEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
574c9537b39SEric Kohl             goto done;
575c9537b39SEric Kohl         }
576c9537b39SEric Kohl     }
577c9537b39SEric Kohl 
578121f0a5cSEric Kohl     pDnsHostNameW = NetpAllocWStrFromAnsiStr((PSTR)DnsHostName);
579c9537b39SEric Kohl     if (pDnsHostNameW == NULL)
580c9537b39SEric Kohl     {
581c9537b39SEric Kohl         status = ERROR_NOT_ENOUGH_MEMORY;
582c9537b39SEric Kohl         goto done;
583c9537b39SEric Kohl     }
584c9537b39SEric Kohl 
585c9537b39SEric Kohl     status = DsDeregisterDnsHostRecordsW(pServerNameW,
586c9537b39SEric Kohl                                          pDnsDomainNameW,
587c9537b39SEric Kohl                                          DomainGuid,
588c9537b39SEric Kohl                                          DsaGuid,
589c9537b39SEric Kohl                                          pDnsHostNameW);
590c9537b39SEric Kohl 
591c9537b39SEric Kohl done:
592c9537b39SEric Kohl     if (pDnsHostNameW != NULL)
593c9537b39SEric Kohl         NetApiBufferFree(pDnsHostNameW);
594c9537b39SEric Kohl 
595c9537b39SEric Kohl     if (pDnsDomainNameW != NULL)
596c9537b39SEric Kohl         NetApiBufferFree(pDnsDomainNameW);
597c9537b39SEric Kohl 
598c9537b39SEric Kohl     if (pServerNameW != NULL)
599c9537b39SEric Kohl         NetApiBufferFree(pServerNameW);
600c9537b39SEric Kohl 
601c9537b39SEric Kohl     return status;
602c2c66affSColin Finck }
603c2c66affSColin Finck 
604c2c66affSColin Finck 
605c2c66affSColin Finck DWORD
606c2c66affSColin Finck WINAPI
DsDeregisterDnsHostRecordsW(_In_opt_ LPWSTR ServerName,_In_opt_ LPWSTR DnsDomainName,_In_opt_ GUID * DomainGuid,_In_opt_ GUID * DsaGuid,_In_ LPWSTR DnsHostName)607c2c66affSColin Finck DsDeregisterDnsHostRecordsW(
608c2c66affSColin Finck     _In_opt_ LPWSTR ServerName,
609c2c66affSColin Finck     _In_opt_ LPWSTR DnsDomainName,
610c2c66affSColin Finck     _In_opt_ GUID *DomainGuid,
611c2c66affSColin Finck     _In_opt_ GUID *DsaGuid,
612c2c66affSColin Finck     _In_ LPWSTR DnsHostName)
613c2c66affSColin Finck {
614c2c66affSColin Finck     NET_API_STATUS status;
615c2c66affSColin Finck 
616c2c66affSColin Finck     TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
617c2c66affSColin Finck           debugstr_w(ServerName), debugstr_w(DnsDomainName),
618c2c66affSColin Finck           DomainGuid, DsaGuid, debugstr_w(DnsHostName));
619c2c66affSColin Finck 
620c2c66affSColin Finck     RpcTryExcept
621c2c66affSColin Finck     {
622c2c66affSColin Finck         status = DsrDeregisterDnsHostRecords(ServerName,
623c2c66affSColin Finck                                              DnsDomainName,
624c2c66affSColin Finck                                              DomainGuid,
625c2c66affSColin Finck                                              DsaGuid,
626c2c66affSColin Finck                                              DnsHostName);
627c2c66affSColin Finck     }
628c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
629c2c66affSColin Finck     {
630c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
631c2c66affSColin Finck     }
632c2c66affSColin Finck     RpcEndExcept;
633c2c66affSColin Finck 
634c2c66affSColin Finck     return status;
635c2c66affSColin Finck }
636c2c66affSColin Finck 
637c2c66affSColin Finck 
638c2c66affSColin Finck DWORD
639c2c66affSColin Finck WINAPI
DsEnumerateDomainTrustsA(_In_opt_ LPSTR ServerName,_In_ ULONG Flags,_Out_ PDS_DOMAIN_TRUSTSA * Domains,_Out_ PULONG DomainCount)640c2c66affSColin Finck DsEnumerateDomainTrustsA(
641c2c66affSColin Finck     _In_opt_ LPSTR ServerName,
642c2c66affSColin Finck     _In_ ULONG Flags,
643c2c66affSColin Finck     _Out_ PDS_DOMAIN_TRUSTSA *Domains,
644c2c66affSColin Finck     _Out_ PULONG DomainCount)
645c2c66affSColin Finck {
646*8571c26aSEric Kohl     PWSTR pServerNameW = NULL;
647*8571c26aSEric Kohl     PDS_DOMAIN_TRUSTSW pDomainsW = NULL;
648*8571c26aSEric Kohl     PDS_DOMAIN_TRUSTSA pDomainsA = NULL;
649*8571c26aSEric Kohl     UNICODE_STRING UnicodeString;
650*8571c26aSEric Kohl     ANSI_STRING AnsiString;
651*8571c26aSEric Kohl     PSTR Ptr;
652*8571c26aSEric Kohl     ULONG i, BufferSize, SidLength;
653*8571c26aSEric Kohl     NTSTATUS Status;
654*8571c26aSEric Kohl     NET_API_STATUS status = NERR_Success;
655*8571c26aSEric Kohl 
656*8571c26aSEric Kohl     TRACE("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
657c2c66affSColin Finck           debugstr_a(ServerName), Flags, Domains, DomainCount);
658*8571c26aSEric Kohl 
659*8571c26aSEric Kohl     if (ServerName != NULL)
660*8571c26aSEric Kohl     {
661*8571c26aSEric Kohl         pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
662*8571c26aSEric Kohl         if (pServerNameW == NULL)
663*8571c26aSEric Kohl         {
664*8571c26aSEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
665*8571c26aSEric Kohl             goto done;
666*8571c26aSEric Kohl         }
667*8571c26aSEric Kohl     }
668*8571c26aSEric Kohl 
669*8571c26aSEric Kohl     status = DsEnumerateDomainTrustsW(pServerNameW,
670*8571c26aSEric Kohl                                       Flags,
671*8571c26aSEric Kohl                                       &pDomainsW,
672*8571c26aSEric Kohl                                       DomainCount);
673*8571c26aSEric Kohl     if (status != NERR_Success)
674*8571c26aSEric Kohl         goto done;
675*8571c26aSEric Kohl 
676*8571c26aSEric Kohl     BufferSize = *DomainCount * sizeof(DS_DOMAIN_TRUSTSA);
677*8571c26aSEric Kohl     for (i = 0; i < *DomainCount; i++)
678*8571c26aSEric Kohl     {
679*8571c26aSEric Kohl         RtlInitUnicodeString(&UnicodeString,
680*8571c26aSEric Kohl                              pDomainsW[i].NetbiosDomainName);
681*8571c26aSEric Kohl         BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
682*8571c26aSEric Kohl 
683*8571c26aSEric Kohl         if (pDomainsW[i].DnsDomainName != NULL)
684*8571c26aSEric Kohl         {
685*8571c26aSEric Kohl             RtlInitUnicodeString(&UnicodeString,
686*8571c26aSEric Kohl                                  pDomainsW[i].DnsDomainName);
687*8571c26aSEric Kohl             BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
688*8571c26aSEric Kohl         }
689*8571c26aSEric Kohl 
690*8571c26aSEric Kohl         BufferSize += RtlLengthSid(pDomainsW[i].DomainSid);
691*8571c26aSEric Kohl     }
692*8571c26aSEric Kohl 
693*8571c26aSEric Kohl     /* Allocate the ANSI buffer */
694*8571c26aSEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pDomainsA);
695*8571c26aSEric Kohl     if (status != NERR_Success)
696*8571c26aSEric Kohl         goto done;
697*8571c26aSEric Kohl 
698*8571c26aSEric Kohl     Ptr = (PSTR)((ULONG_PTR)pDomainsA + *DomainCount * sizeof(DS_DOMAIN_TRUSTSA));
699*8571c26aSEric Kohl     for (i = 0; i < *DomainCount; i++)
700*8571c26aSEric Kohl     {
701*8571c26aSEric Kohl         pDomainsA[i].NetbiosDomainName = Ptr;
702*8571c26aSEric Kohl         RtlInitUnicodeString(&UnicodeString,
703*8571c26aSEric Kohl                              pDomainsW[i].NetbiosDomainName);
704*8571c26aSEric Kohl         AnsiString.Length = 0;
705*8571c26aSEric Kohl         AnsiString.MaximumLength = BufferSize;
706*8571c26aSEric Kohl         AnsiString.Buffer = Ptr;
707*8571c26aSEric Kohl 
708*8571c26aSEric Kohl         Status = RtlUnicodeStringToAnsiString(&AnsiString,
709*8571c26aSEric Kohl                                               &UnicodeString,
710*8571c26aSEric Kohl                                               FALSE);
711*8571c26aSEric Kohl         if (!NT_SUCCESS(Status))
712*8571c26aSEric Kohl         {
713*8571c26aSEric Kohl             status = RtlNtStatusToDosError(Status);
714*8571c26aSEric Kohl             goto done;
715*8571c26aSEric Kohl         }
716*8571c26aSEric Kohl 
717*8571c26aSEric Kohl         Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
718*8571c26aSEric Kohl         BufferSize -= AnsiString.Length + sizeof(CHAR);
719*8571c26aSEric Kohl 
720*8571c26aSEric Kohl         if (pDomainsW[i].DnsDomainName != NULL)
721*8571c26aSEric Kohl         {
722*8571c26aSEric Kohl             pDomainsA[i].DnsDomainName = Ptr;
723*8571c26aSEric Kohl             RtlInitUnicodeString(&UnicodeString,
724*8571c26aSEric Kohl                                  pDomainsW[i].DnsDomainName);
725*8571c26aSEric Kohl             AnsiString.Length = 0;
726*8571c26aSEric Kohl             AnsiString.MaximumLength = BufferSize;
727*8571c26aSEric Kohl             AnsiString.Buffer = Ptr;
728*8571c26aSEric Kohl 
729*8571c26aSEric Kohl             Status = RtlUnicodeStringToAnsiString(&AnsiString,
730*8571c26aSEric Kohl                                                   &UnicodeString,
731*8571c26aSEric Kohl                                                   FALSE);
732*8571c26aSEric Kohl             if (!NT_SUCCESS(Status))
733*8571c26aSEric Kohl             {
734*8571c26aSEric Kohl                 status = RtlNtStatusToDosError(Status);
735*8571c26aSEric Kohl                 goto done;
736*8571c26aSEric Kohl             }
737*8571c26aSEric Kohl 
738*8571c26aSEric Kohl             Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
739*8571c26aSEric Kohl             BufferSize -= AnsiString.Length + sizeof(CHAR);
740*8571c26aSEric Kohl         }
741*8571c26aSEric Kohl 
742*8571c26aSEric Kohl         pDomainsA[i].Flags = pDomainsW[i].Flags;
743*8571c26aSEric Kohl         pDomainsA[i].ParentIndex = pDomainsW[i].ParentIndex;
744*8571c26aSEric Kohl         pDomainsA[i].TrustType = pDomainsW[i].TrustType;
745*8571c26aSEric Kohl         pDomainsA[i].TrustAttributes = pDomainsW[i].TrustAttributes;
746*8571c26aSEric Kohl 
747*8571c26aSEric Kohl         /* DomainSid */
748*8571c26aSEric Kohl         pDomainsA[i].DomainSid = (PSID)Ptr;
749*8571c26aSEric Kohl         SidLength = RtlLengthSid(pDomainsW[i].DomainSid);
750*8571c26aSEric Kohl         Status = RtlCopySid(SidLength,
751*8571c26aSEric Kohl                             (PSID)Ptr,
752*8571c26aSEric Kohl                             pDomainsW[i].DomainSid);
753*8571c26aSEric Kohl         if (!NT_SUCCESS(Status))
754*8571c26aSEric Kohl         {
755*8571c26aSEric Kohl             status = RtlNtStatusToDosError(Status);
756*8571c26aSEric Kohl             goto done;
757*8571c26aSEric Kohl         }
758*8571c26aSEric Kohl 
759*8571c26aSEric Kohl         Ptr = (PSTR)((ULONG_PTR)Ptr + SidLength);
760*8571c26aSEric Kohl         BufferSize -= SidLength;
761*8571c26aSEric Kohl 
762*8571c26aSEric Kohl         CopyMemory(&pDomainsA[i].DomainGuid,
763*8571c26aSEric Kohl                    &pDomainsW[i].DomainGuid,
764*8571c26aSEric Kohl                    sizeof(GUID));
765*8571c26aSEric Kohl     }
766*8571c26aSEric Kohl 
767*8571c26aSEric Kohl     *Domains = pDomainsA;
768*8571c26aSEric Kohl     pDomainsA = NULL;
769*8571c26aSEric Kohl 
770*8571c26aSEric Kohl done:
771*8571c26aSEric Kohl     if (pDomainsA != NULL)
772*8571c26aSEric Kohl         NetApiBufferFree(pDomainsA);
773*8571c26aSEric Kohl 
774*8571c26aSEric Kohl     if (pDomainsW != NULL)
775*8571c26aSEric Kohl         NetApiBufferFree(pDomainsW);
776*8571c26aSEric Kohl 
777*8571c26aSEric Kohl     if (pServerNameW != NULL)
778*8571c26aSEric Kohl         NetApiBufferFree(pServerNameW);
779*8571c26aSEric Kohl 
780*8571c26aSEric Kohl     return status;
781c2c66affSColin Finck }
782c2c66affSColin Finck 
783c2c66affSColin Finck 
784c2c66affSColin Finck DWORD
785c2c66affSColin Finck WINAPI
DsEnumerateDomainTrustsW(_In_opt_ LPWSTR ServerName,_In_ ULONG Flags,_Out_ PDS_DOMAIN_TRUSTSW * Domains,_Out_ PULONG DomainCount)786c2c66affSColin Finck DsEnumerateDomainTrustsW(
787c2c66affSColin Finck     _In_opt_ LPWSTR ServerName,
788c2c66affSColin Finck     _In_ ULONG Flags,
789c2c66affSColin Finck     _Out_ PDS_DOMAIN_TRUSTSW *Domains,
790c2c66affSColin Finck     _Out_ PULONG DomainCount)
791c2c66affSColin Finck {
792324afc25SEric Kohl     NETLOGON_TRUSTED_DOMAIN_ARRAY DomainsArray = {0, NULL};
793324afc25SEric Kohl     NET_API_STATUS status;
794324afc25SEric Kohl 
795324afc25SEric Kohl     TRACE("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
796c2c66affSColin Finck           debugstr_w(ServerName), Flags, Domains, DomainCount);
797324afc25SEric Kohl 
798324afc25SEric Kohl     RpcTryExcept
799324afc25SEric Kohl     {
800324afc25SEric Kohl         status = DsrEnumerateDomainTrusts(ServerName,
801324afc25SEric Kohl                                           Flags,
802324afc25SEric Kohl                                           &DomainsArray);
803324afc25SEric Kohl         if (status == NERR_Success)
804324afc25SEric Kohl         {
805324afc25SEric Kohl             *Domains = DomainsArray.Domains;
806324afc25SEric Kohl             *DomainCount = DomainsArray.DomainCount;
807324afc25SEric Kohl         }
808324afc25SEric Kohl     }
809324afc25SEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
810324afc25SEric Kohl     {
811324afc25SEric Kohl         status = I_RpcMapWin32Status(RpcExceptionCode());
812324afc25SEric Kohl     }
813324afc25SEric Kohl     RpcEndExcept;
814324afc25SEric Kohl 
815324afc25SEric Kohl     return status;
816c2c66affSColin Finck }
817c2c66affSColin Finck 
818c2c66affSColin Finck 
819c2c66affSColin Finck DWORD
820c2c66affSColin Finck WINAPI
DsGetDcNameA(_In_opt_ LPCSTR ComputerName,_In_ LPCSTR DomainName,_In_ GUID * DomainGuid,_In_ LPCSTR SiteName,_In_ ULONG Flags,_Out_ PDOMAIN_CONTROLLER_INFOA * DomainControllerInfo)821c2c66affSColin Finck DsGetDcNameA(
82257d48a7fSEric Kohl     _In_opt_ LPCSTR ComputerName,
823c2c66affSColin Finck     _In_ LPCSTR DomainName,
824c2c66affSColin Finck     _In_ GUID *DomainGuid,
825c2c66affSColin Finck     _In_ LPCSTR SiteName,
826c2c66affSColin Finck     _In_ ULONG Flags,
827c2c66affSColin Finck     _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
828c2c66affSColin Finck {
82957d48a7fSEric Kohl     TRACE("DsGetDcNameA(%s, %s, %s, %s, %08lx, %p): stub\n",
830c2c66affSColin Finck           debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
831c2c66affSColin Finck           debugstr_a(SiteName), Flags, DomainControllerInfo);
83257d48a7fSEric Kohl     return DsGetDcNameWithAccountA(ComputerName,
83357d48a7fSEric Kohl                                    NULL,
83457d48a7fSEric Kohl                                    0,
83557d48a7fSEric Kohl                                    DomainName,
83657d48a7fSEric Kohl                                    DomainGuid,
83757d48a7fSEric Kohl                                    SiteName,
83857d48a7fSEric Kohl                                    Flags,
83957d48a7fSEric Kohl                                    DomainControllerInfo);
84057d48a7fSEric Kohl }
84157d48a7fSEric Kohl 
84257d48a7fSEric Kohl 
84357d48a7fSEric Kohl DWORD
84457d48a7fSEric Kohl WINAPI
DsGetDcNameW(_In_opt_ LPCWSTR ComputerName,_In_ LPCWSTR DomainName,_In_ GUID * DomainGuid,_In_ LPCWSTR SiteName,_In_ ULONG Flags,_Out_ PDOMAIN_CONTROLLER_INFOW * DomainControllerInfo)84557d48a7fSEric Kohl DsGetDcNameW(
84657d48a7fSEric Kohl     _In_opt_ LPCWSTR ComputerName,
84757d48a7fSEric Kohl     _In_ LPCWSTR DomainName,
84857d48a7fSEric Kohl     _In_ GUID *DomainGuid,
84957d48a7fSEric Kohl     _In_ LPCWSTR SiteName,
85057d48a7fSEric Kohl     _In_ ULONG Flags,
85157d48a7fSEric Kohl     _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
85257d48a7fSEric Kohl {
85357d48a7fSEric Kohl     TRACE("DsGetDcNameW(%s, %s, %s, %s, %08lx, %p)\n",
85457d48a7fSEric Kohl           debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
85557d48a7fSEric Kohl           debugstr_w(SiteName), Flags, DomainControllerInfo);
85657d48a7fSEric Kohl     return DsGetDcNameWithAccountW(ComputerName,
85757d48a7fSEric Kohl                                    NULL,
85857d48a7fSEric Kohl                                    0,
85957d48a7fSEric Kohl                                    DomainName,
86057d48a7fSEric Kohl                                    DomainGuid,
86157d48a7fSEric Kohl                                    SiteName,
86257d48a7fSEric Kohl                                    Flags,
86357d48a7fSEric Kohl                                    DomainControllerInfo);
86457d48a7fSEric Kohl }
86557d48a7fSEric Kohl 
86657d48a7fSEric Kohl 
86757d48a7fSEric Kohl DWORD
86857d48a7fSEric Kohl WINAPI
DsGetDcNameWithAccountA(_In_opt_ LPCSTR ComputerName,_In_opt_ LPCSTR AccountName,_In_ ULONG AccountControlBits,_In_ LPCSTR DomainName,_In_ GUID * DomainGuid,_In_ LPCSTR SiteName,_In_ ULONG Flags,_Out_ PDOMAIN_CONTROLLER_INFOA * DomainControllerInfo)86957d48a7fSEric Kohl DsGetDcNameWithAccountA(
87057d48a7fSEric Kohl     _In_opt_ LPCSTR ComputerName,
87157d48a7fSEric Kohl     _In_opt_ LPCSTR AccountName,
87257d48a7fSEric Kohl     _In_ ULONG AccountControlBits,
87357d48a7fSEric Kohl     _In_ LPCSTR DomainName,
87457d48a7fSEric Kohl     _In_ GUID *DomainGuid,
87557d48a7fSEric Kohl     _In_ LPCSTR SiteName,
87657d48a7fSEric Kohl     _In_ ULONG Flags,
87757d48a7fSEric Kohl     _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
87857d48a7fSEric Kohl {
87947b749aaSEric Kohl     PWSTR pComputerNameW = NULL, pAccountNameW = NULL;
88047b749aaSEric Kohl     PWSTR pDomainNameW = NULL, pSiteNameW = NULL;
88147b749aaSEric Kohl     PDOMAIN_CONTROLLER_INFOW pDomainControllerInfoW = NULL;
88247b749aaSEric Kohl     PDOMAIN_CONTROLLER_INFOA pDomainControllerInfoA = NULL;
88347b749aaSEric Kohl     UNICODE_STRING UnicodeString;
88447b749aaSEric Kohl     ANSI_STRING AnsiString;
88547b749aaSEric Kohl     PSTR Ptr;
88647b749aaSEric Kohl     ULONG BufferSize;
88747b749aaSEric Kohl     NTSTATUS Status;
88847b749aaSEric Kohl     NET_API_STATUS status = NERR_Success;
88947b749aaSEric Kohl 
89047b749aaSEric Kohl     TRACE("DsGetDcNameWithAccountA(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
89157d48a7fSEric Kohl           debugstr_a(ComputerName), debugstr_a(AccountName), AccountControlBits,
89257d48a7fSEric Kohl           debugstr_a(DomainName), debugstr_guid(DomainGuid),
89357d48a7fSEric Kohl           debugstr_a(SiteName), Flags, DomainControllerInfo);
89447b749aaSEric Kohl 
89547b749aaSEric Kohl     if (ComputerName != NULL)
89647b749aaSEric Kohl     {
89747b749aaSEric Kohl         pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
89847b749aaSEric Kohl         if (pComputerNameW == NULL)
89947b749aaSEric Kohl         {
90047b749aaSEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
90147b749aaSEric Kohl             goto done;
90247b749aaSEric Kohl         }
90347b749aaSEric Kohl     }
90447b749aaSEric Kohl 
90547b749aaSEric Kohl     if (AccountName != NULL)
90647b749aaSEric Kohl     {
90747b749aaSEric Kohl         pAccountNameW = NetpAllocWStrFromAnsiStr((PSTR)AccountName);
90847b749aaSEric Kohl         if (pAccountNameW == NULL)
90947b749aaSEric Kohl         {
91047b749aaSEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
91147b749aaSEric Kohl             goto done;
91247b749aaSEric Kohl         }
91347b749aaSEric Kohl     }
91447b749aaSEric Kohl 
91547b749aaSEric Kohl     pDomainNameW = NetpAllocWStrFromAnsiStr((PSTR)DomainName);
91647b749aaSEric Kohl     if (pDomainNameW == NULL)
91747b749aaSEric Kohl     {
91847b749aaSEric Kohl         status = ERROR_NOT_ENOUGH_MEMORY;
91947b749aaSEric Kohl         goto done;
92047b749aaSEric Kohl     }
92147b749aaSEric Kohl 
92247b749aaSEric Kohl     pSiteNameW = NetpAllocWStrFromAnsiStr((PSTR)SiteName);
92347b749aaSEric Kohl     if (pSiteNameW == NULL)
92447b749aaSEric Kohl     {
92547b749aaSEric Kohl         status = ERROR_NOT_ENOUGH_MEMORY;
92647b749aaSEric Kohl         goto done;
92747b749aaSEric Kohl     }
92847b749aaSEric Kohl 
92947b749aaSEric Kohl     status = DsGetDcNameWithAccountW(pComputerNameW,
93047b749aaSEric Kohl                                      pAccountNameW,
93147b749aaSEric Kohl                                      AccountControlBits,
93247b749aaSEric Kohl                                      pDomainNameW,
93347b749aaSEric Kohl                                      DomainGuid,
93447b749aaSEric Kohl                                      pSiteNameW,
93547b749aaSEric Kohl                                      Flags,
93647b749aaSEric Kohl                                      &pDomainControllerInfoW);
93747b749aaSEric Kohl     if (status != NERR_Success)
93847b749aaSEric Kohl         goto done;
93947b749aaSEric Kohl 
94047b749aaSEric Kohl     BufferSize = sizeof(DOMAIN_CONTROLLER_INFOA);
94147b749aaSEric Kohl 
94247b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
94347b749aaSEric Kohl                          pDomainControllerInfoW->DomainControllerName);
94447b749aaSEric Kohl     BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
94547b749aaSEric Kohl 
94647b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
94747b749aaSEric Kohl                          pDomainControllerInfoW->DomainControllerAddress);
94847b749aaSEric Kohl     BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
94947b749aaSEric Kohl 
95047b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
95147b749aaSEric Kohl                          pDomainControllerInfoW->DomainName);
95247b749aaSEric Kohl     BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
95347b749aaSEric Kohl 
95447b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
95547b749aaSEric Kohl                          pDomainControllerInfoW->DnsForestName);
95647b749aaSEric Kohl     BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
95747b749aaSEric Kohl 
95847b749aaSEric Kohl     if (pDomainControllerInfoW->DcSiteName != NULL)
95947b749aaSEric Kohl     {
96047b749aaSEric Kohl         RtlInitUnicodeString(&UnicodeString,
96147b749aaSEric Kohl                              pDomainControllerInfoW->DcSiteName);
96247b749aaSEric Kohl         BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
96347b749aaSEric Kohl     }
96447b749aaSEric Kohl 
96547b749aaSEric Kohl     if (pDomainControllerInfoW->ClientSiteName != NULL)
96647b749aaSEric Kohl     {
96747b749aaSEric Kohl         RtlInitUnicodeString(&UnicodeString,
96847b749aaSEric Kohl                              pDomainControllerInfoW->ClientSiteName);
96947b749aaSEric Kohl         BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
97047b749aaSEric Kohl     }
97147b749aaSEric Kohl 
97247b749aaSEric Kohl     /* Allocate the ANSI buffer */
97347b749aaSEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pDomainControllerInfoA);
97447b749aaSEric Kohl     if (status != NERR_Success)
97547b749aaSEric Kohl         goto done;
97647b749aaSEric Kohl 
97747b749aaSEric Kohl     pDomainControllerInfoA->DomainControllerAddressType =
97847b749aaSEric Kohl         pDomainControllerInfoW->DomainControllerAddressType;
97947b749aaSEric Kohl 
98047b749aaSEric Kohl     pDomainControllerInfoA->Flags = pDomainControllerInfoW->Flags;
98147b749aaSEric Kohl 
98247b749aaSEric Kohl     CopyMemory(&pDomainControllerInfoA->DomainGuid,
98347b749aaSEric Kohl                &pDomainControllerInfoW->DomainGuid,
98447b749aaSEric Kohl                sizeof(GUID));
98547b749aaSEric Kohl 
98647b749aaSEric Kohl     Ptr = (PSTR)((ULONG_PTR)pDomainControllerInfoA + sizeof(DOMAIN_CONTROLLER_INFOA));
98747b749aaSEric Kohl     BufferSize -= sizeof(DOMAIN_CONTROLLER_INFOA);
98847b749aaSEric Kohl 
98947b749aaSEric Kohl     pDomainControllerInfoA->DomainControllerName = Ptr;
99047b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
99147b749aaSEric Kohl                          pDomainControllerInfoW->DomainControllerName);
99247b749aaSEric Kohl     AnsiString.Length = 0;
99347b749aaSEric Kohl     AnsiString.MaximumLength = BufferSize;
99447b749aaSEric Kohl     AnsiString.Buffer = Ptr;
99547b749aaSEric Kohl 
99647b749aaSEric Kohl     Status = RtlUnicodeStringToAnsiString(&AnsiString,
99747b749aaSEric Kohl                                           &UnicodeString,
99847b749aaSEric Kohl                                           FALSE);
99947b749aaSEric Kohl     if (!NT_SUCCESS(Status))
100047b749aaSEric Kohl     {
100147b749aaSEric Kohl         status = RtlNtStatusToDosError(Status);
100247b749aaSEric Kohl         goto done;
100347b749aaSEric Kohl     }
100447b749aaSEric Kohl 
100547b749aaSEric Kohl     Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
100647b749aaSEric Kohl     BufferSize -= AnsiString.Length + sizeof(CHAR);
100747b749aaSEric Kohl 
100847b749aaSEric Kohl     pDomainControllerInfoA->DomainControllerAddress = Ptr;
100947b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
101047b749aaSEric Kohl                          pDomainControllerInfoW->DomainControllerAddress);
101147b749aaSEric Kohl     AnsiString.Length = 0;
101247b749aaSEric Kohl     AnsiString.MaximumLength = BufferSize;
101347b749aaSEric Kohl     AnsiString.Buffer = Ptr;
101447b749aaSEric Kohl 
101547b749aaSEric Kohl     Status = RtlUnicodeStringToAnsiString(&AnsiString,
101647b749aaSEric Kohl                                           &UnicodeString,
101747b749aaSEric Kohl                                           FALSE);
101847b749aaSEric Kohl     if (!NT_SUCCESS(Status))
101947b749aaSEric Kohl     {
102047b749aaSEric Kohl         status = RtlNtStatusToDosError(Status);
102147b749aaSEric Kohl         goto done;
102247b749aaSEric Kohl     }
102347b749aaSEric Kohl 
102447b749aaSEric Kohl     Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
102547b749aaSEric Kohl     BufferSize -= AnsiString.Length + sizeof(CHAR);
102647b749aaSEric Kohl 
102747b749aaSEric Kohl     pDomainControllerInfoA->DomainName = Ptr;
102847b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
102947b749aaSEric Kohl                          pDomainControllerInfoW->DomainName);
103047b749aaSEric Kohl     AnsiString.Length = 0;
103147b749aaSEric Kohl     AnsiString.MaximumLength = BufferSize;
103247b749aaSEric Kohl     AnsiString.Buffer = Ptr;
103347b749aaSEric Kohl 
103447b749aaSEric Kohl     Status = RtlUnicodeStringToAnsiString(&AnsiString,
103547b749aaSEric Kohl                                           &UnicodeString,
103647b749aaSEric Kohl                                           FALSE);
103747b749aaSEric Kohl     if (!NT_SUCCESS(Status))
103847b749aaSEric Kohl     {
103947b749aaSEric Kohl         status = RtlNtStatusToDosError(Status);
104047b749aaSEric Kohl         goto done;
104147b749aaSEric Kohl     }
104247b749aaSEric Kohl 
104347b749aaSEric Kohl     Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
104447b749aaSEric Kohl     BufferSize -= AnsiString.Length + sizeof(CHAR);
104547b749aaSEric Kohl 
104647b749aaSEric Kohl     pDomainControllerInfoA->DnsForestName = Ptr;
104747b749aaSEric Kohl     RtlInitUnicodeString(&UnicodeString,
104847b749aaSEric Kohl                          pDomainControllerInfoW->DnsForestName);
104947b749aaSEric Kohl     AnsiString.Length = 0;
105047b749aaSEric Kohl     AnsiString.MaximumLength = BufferSize;
105147b749aaSEric Kohl     AnsiString.Buffer = Ptr;
105247b749aaSEric Kohl 
105347b749aaSEric Kohl     Status = RtlUnicodeStringToAnsiString(&AnsiString,
105447b749aaSEric Kohl                                           &UnicodeString,
105547b749aaSEric Kohl                                           FALSE);
105647b749aaSEric Kohl     if (!NT_SUCCESS(Status))
105747b749aaSEric Kohl     {
105847b749aaSEric Kohl         status = RtlNtStatusToDosError(Status);
105947b749aaSEric Kohl         goto done;
106047b749aaSEric Kohl     }
106147b749aaSEric Kohl 
106247b749aaSEric Kohl     Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
106347b749aaSEric Kohl     BufferSize -= AnsiString.Length + sizeof(CHAR);
106447b749aaSEric Kohl 
106547b749aaSEric Kohl     if (pDomainControllerInfoW->DcSiteName != NULL)
106647b749aaSEric Kohl     {
106747b749aaSEric Kohl         pDomainControllerInfoA->DcSiteName = Ptr;
106847b749aaSEric Kohl         RtlInitUnicodeString(&UnicodeString,
106947b749aaSEric Kohl                              pDomainControllerInfoW->DcSiteName);
107047b749aaSEric Kohl         AnsiString.Length = 0;
107147b749aaSEric Kohl         AnsiString.MaximumLength = BufferSize;
107247b749aaSEric Kohl         AnsiString.Buffer = Ptr;
107347b749aaSEric Kohl 
107447b749aaSEric Kohl         Status = RtlUnicodeStringToAnsiString(&AnsiString,
107547b749aaSEric Kohl                                               &UnicodeString,
107647b749aaSEric Kohl                                               FALSE);
107747b749aaSEric Kohl         if (!NT_SUCCESS(Status))
107847b749aaSEric Kohl         {
107947b749aaSEric Kohl             status = RtlNtStatusToDosError(Status);
108047b749aaSEric Kohl             goto done;
108147b749aaSEric Kohl         }
108247b749aaSEric Kohl 
108347b749aaSEric Kohl         Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
108447b749aaSEric Kohl         BufferSize -= AnsiString.Length + sizeof(CHAR);
108547b749aaSEric Kohl     }
108647b749aaSEric Kohl 
108747b749aaSEric Kohl     if (pDomainControllerInfoW->ClientSiteName != NULL)
108847b749aaSEric Kohl     {
108947b749aaSEric Kohl         pDomainControllerInfoA->ClientSiteName = Ptr;
109047b749aaSEric Kohl         RtlInitUnicodeString(&UnicodeString,
109147b749aaSEric Kohl                              pDomainControllerInfoW->ClientSiteName);
109247b749aaSEric Kohl         AnsiString.Length = 0;
109347b749aaSEric Kohl         AnsiString.MaximumLength = BufferSize;
109447b749aaSEric Kohl         AnsiString.Buffer = Ptr;
109547b749aaSEric Kohl 
109647b749aaSEric Kohl         Status = RtlUnicodeStringToAnsiString(&AnsiString,
109747b749aaSEric Kohl                                               &UnicodeString,
109847b749aaSEric Kohl                                               FALSE);
109947b749aaSEric Kohl         if (!NT_SUCCESS(Status))
110047b749aaSEric Kohl         {
110147b749aaSEric Kohl             status = RtlNtStatusToDosError(Status);
110247b749aaSEric Kohl             goto done;
110347b749aaSEric Kohl         }
110447b749aaSEric Kohl     }
110547b749aaSEric Kohl 
110647b749aaSEric Kohl     *DomainControllerInfo = pDomainControllerInfoA;
110747b749aaSEric Kohl     pDomainControllerInfoA = NULL;
110847b749aaSEric Kohl 
110947b749aaSEric Kohl done:
111047b749aaSEric Kohl     if (pDomainControllerInfoA != NULL)
111147b749aaSEric Kohl         NetApiBufferFree(pDomainControllerInfoA);
111247b749aaSEric Kohl 
111347b749aaSEric Kohl     if (pDomainControllerInfoW != NULL)
111447b749aaSEric Kohl         NetApiBufferFree(pDomainControllerInfoW);
111547b749aaSEric Kohl 
111647b749aaSEric Kohl     if (pSiteNameW != NULL)
111747b749aaSEric Kohl         NetApiBufferFree(pSiteNameW);
111847b749aaSEric Kohl 
111947b749aaSEric Kohl     if (pDomainNameW != NULL)
112047b749aaSEric Kohl         NetApiBufferFree(pDomainNameW);
112147b749aaSEric Kohl 
112247b749aaSEric Kohl     if (pAccountNameW != NULL)
112347b749aaSEric Kohl         NetApiBufferFree(pAccountNameW);
112447b749aaSEric Kohl 
112547b749aaSEric Kohl     if (pComputerNameW != NULL)
112647b749aaSEric Kohl         NetApiBufferFree(pComputerNameW);
112747b749aaSEric Kohl 
112847b749aaSEric Kohl     return status;
1129c2c66affSColin Finck }
1130c2c66affSColin Finck 
1131c2c66affSColin Finck 
1132c2c66affSColin Finck DWORD
1133c2c66affSColin Finck WINAPI
DsGetDcNameWithAccountW(_In_opt_ LPCWSTR ComputerName,_In_opt_ LPCWSTR AccountName,_In_ ULONG AccountControlBits,_In_ LPCWSTR DomainName,_In_ GUID * DomainGuid,_In_ LPCWSTR SiteName,_In_ ULONG Flags,_Out_ PDOMAIN_CONTROLLER_INFOW * DomainControllerInfo)113457d48a7fSEric Kohl DsGetDcNameWithAccountW(
113557d48a7fSEric Kohl     _In_opt_ LPCWSTR ComputerName,
113657d48a7fSEric Kohl     _In_opt_ LPCWSTR AccountName,
113757d48a7fSEric Kohl     _In_ ULONG AccountControlBits,
1138c2c66affSColin Finck     _In_ LPCWSTR DomainName,
1139c2c66affSColin Finck     _In_ GUID *DomainGuid,
1140c2c66affSColin Finck     _In_ LPCWSTR SiteName,
1141c2c66affSColin Finck     _In_ ULONG Flags,
1142c2c66affSColin Finck     _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
1143c2c66affSColin Finck {
114457d48a7fSEric Kohl     NET_API_STATUS status;
114557d48a7fSEric Kohl 
114647b749aaSEric Kohl     TRACE("DsGetDcNameWithAccountW(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
114757d48a7fSEric Kohl           debugstr_w(ComputerName), debugstr_w(AccountName), AccountControlBits,
114857d48a7fSEric Kohl           debugstr_w(DomainName), debugstr_guid(DomainGuid),
1149c2c66affSColin Finck           debugstr_w(SiteName), Flags, DomainControllerInfo);
115057d48a7fSEric Kohl 
115157d48a7fSEric Kohl     RpcTryExcept
115257d48a7fSEric Kohl     {
115357d48a7fSEric Kohl         status = DsrGetDcNameEx2((PWSTR)ComputerName,
115457d48a7fSEric Kohl                                  (PWSTR)AccountName,
115557d48a7fSEric Kohl                                  AccountControlBits,
115657d48a7fSEric Kohl                                  (PWSTR)DomainName,
115757d48a7fSEric Kohl                                  DomainGuid,
115857d48a7fSEric Kohl                                  (PWSTR)SiteName,
115957d48a7fSEric Kohl                                  Flags,
116057d48a7fSEric Kohl                                  DomainControllerInfo);
116157d48a7fSEric Kohl     }
116257d48a7fSEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
116357d48a7fSEric Kohl     {
116457d48a7fSEric Kohl         status = I_RpcMapWin32Status(RpcExceptionCode());
116557d48a7fSEric Kohl     }
116657d48a7fSEric Kohl     RpcEndExcept;
116757d48a7fSEric Kohl 
116857d48a7fSEric Kohl     return status;
1169c2c66affSColin Finck }
1170c2c66affSColin Finck 
1171c2c66affSColin Finck 
1172c2c66affSColin Finck DWORD
1173c2c66affSColin Finck WINAPI
DsGetDcSiteCoverageA(_In_opt_ LPCSTR ServerName,_Out_ PULONG EntryCount,_Out_ LPSTR ** SiteNames)1174c2c66affSColin Finck DsGetDcSiteCoverageA(
1175c2c66affSColin Finck     _In_opt_ LPCSTR ServerName,
1176c2c66affSColin Finck     _Out_ PULONG EntryCount,
1177c2c66affSColin Finck     _Out_ LPSTR **SiteNames)
1178c2c66affSColin Finck {
1179792d0f6bSEric Kohl     PWSTR pServerNameW = NULL;
1180792d0f6bSEric Kohl     PWSTR *pSiteNamesW = NULL;
1181792d0f6bSEric Kohl     PSTR *pSiteNamesA = NULL;
1182792d0f6bSEric Kohl     UNICODE_STRING UnicodeString;
1183792d0f6bSEric Kohl     ANSI_STRING AnsiString;
1184792d0f6bSEric Kohl     PSTR Ptr;
1185792d0f6bSEric Kohl     ULONG BufferSize, i;
1186792d0f6bSEric Kohl     NTSTATUS Status;
118747b749aaSEric Kohl     NET_API_STATUS status = NERR_Success;
1188792d0f6bSEric Kohl 
1189792d0f6bSEric Kohl     TRACE("DsGetDcSiteCoverageA(%s, %p, %p)\n",
1190c2c66affSColin Finck           debugstr_a(ServerName), EntryCount, SiteNames);
1191792d0f6bSEric Kohl 
1192792d0f6bSEric Kohl     if (ServerName != NULL)
1193792d0f6bSEric Kohl     {
1194792d0f6bSEric Kohl         pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
1195792d0f6bSEric Kohl         if (pServerNameW == NULL)
1196792d0f6bSEric Kohl         {
1197792d0f6bSEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
1198792d0f6bSEric Kohl             goto done;
1199792d0f6bSEric Kohl         }
1200792d0f6bSEric Kohl     }
1201792d0f6bSEric Kohl 
1202792d0f6bSEric Kohl     status = DsGetDcSiteCoverageW(pServerNameW,
1203792d0f6bSEric Kohl                                   EntryCount,
1204792d0f6bSEric Kohl                                   &pSiteNamesW);
1205792d0f6bSEric Kohl     if (status != ERROR_SUCCESS)
1206792d0f6bSEric Kohl         goto done;
1207792d0f6bSEric Kohl 
1208792d0f6bSEric Kohl     BufferSize = *EntryCount * sizeof(PSTR);
1209792d0f6bSEric Kohl     for (i = 0; i < *EntryCount; i++)
1210792d0f6bSEric Kohl     {
1211792d0f6bSEric Kohl         RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
1212792d0f6bSEric Kohl         BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
1213792d0f6bSEric Kohl     }
1214792d0f6bSEric Kohl 
1215792d0f6bSEric Kohl     status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
1216792d0f6bSEric Kohl     if (status != NERR_Success)
1217792d0f6bSEric Kohl         goto done;
1218792d0f6bSEric Kohl 
1219792d0f6bSEric Kohl     ZeroMemory(pSiteNamesA, BufferSize);
1220792d0f6bSEric Kohl 
1221792d0f6bSEric Kohl     Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + *EntryCount * sizeof(PSTR));
1222792d0f6bSEric Kohl     for (i = 0; i < *EntryCount; i++)
1223792d0f6bSEric Kohl     {
1224792d0f6bSEric Kohl         pSiteNamesA[i] = Ptr;
1225792d0f6bSEric Kohl 
1226792d0f6bSEric Kohl         RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
1227792d0f6bSEric Kohl 
1228792d0f6bSEric Kohl         AnsiString.Length = 0;
1229792d0f6bSEric Kohl         AnsiString.MaximumLength = BufferSize;
1230792d0f6bSEric Kohl         AnsiString.Buffer = Ptr;
1231792d0f6bSEric Kohl 
1232792d0f6bSEric Kohl         Status = RtlUnicodeStringToAnsiString(&AnsiString,
1233792d0f6bSEric Kohl                                               &UnicodeString,
1234792d0f6bSEric Kohl                                               FALSE);
1235792d0f6bSEric Kohl         if (!NT_SUCCESS(Status))
1236792d0f6bSEric Kohl         {
1237792d0f6bSEric Kohl             status = RtlNtStatusToDosError(Status);
1238792d0f6bSEric Kohl             goto done;
1239792d0f6bSEric Kohl         }
1240792d0f6bSEric Kohl 
1241792d0f6bSEric Kohl         Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
1242792d0f6bSEric Kohl         BufferSize -= (AnsiString.Length + sizeof(CHAR));
1243792d0f6bSEric Kohl     }
1244792d0f6bSEric Kohl 
1245792d0f6bSEric Kohl     *SiteNames = pSiteNamesA;
1246792d0f6bSEric Kohl     pSiteNamesA = NULL;
1247792d0f6bSEric Kohl 
1248792d0f6bSEric Kohl done:
1249792d0f6bSEric Kohl     if (status != NERR_Success && pSiteNamesA != NULL)
1250792d0f6bSEric Kohl         NetApiBufferFree(pSiteNamesA);
1251792d0f6bSEric Kohl 
1252792d0f6bSEric Kohl     if (pSiteNamesW != NULL)
1253792d0f6bSEric Kohl         NetApiBufferFree(pSiteNamesW);
1254792d0f6bSEric Kohl 
1255792d0f6bSEric Kohl     if (pServerNameW != NULL)
1256792d0f6bSEric Kohl         NetApiBufferFree(pServerNameW);
1257792d0f6bSEric Kohl 
1258792d0f6bSEric Kohl     return status;
1259c2c66affSColin Finck }
1260c2c66affSColin Finck 
1261c2c66affSColin Finck 
1262c2c66affSColin Finck DWORD
1263c2c66affSColin Finck WINAPI
DsGetDcSiteCoverageW(_In_opt_ LPCWSTR ServerName,_Out_ PULONG EntryCount,_Out_ LPWSTR ** SiteNames)1264c2c66affSColin Finck DsGetDcSiteCoverageW(
1265c2c66affSColin Finck     _In_opt_ LPCWSTR ServerName,
1266c2c66affSColin Finck     _Out_ PULONG EntryCount,
1267c2c66affSColin Finck     _Out_ LPWSTR **SiteNames)
1268c2c66affSColin Finck {
1269c2c66affSColin Finck     PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
1270c2c66affSColin Finck     PWSTR *SiteNamesBuffer = NULL, Ptr;
1271c2c66affSColin Finck     ULONG BufferSize, i;
1272c2c66affSColin Finck     NET_API_STATUS status;
1273c2c66affSColin Finck 
1274c2c66affSColin Finck     TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
1275c2c66affSColin Finck           debugstr_w(ServerName), EntryCount, SiteNames);
1276c2c66affSColin Finck 
1277c2c66affSColin Finck     *EntryCount = 0;
1278c2c66affSColin Finck     *SiteNames = NULL;
1279c2c66affSColin Finck 
1280c2c66affSColin Finck     RpcTryExcept
1281c2c66affSColin Finck     {
1282c2c66affSColin Finck         status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
1283c2c66affSColin Finck                                        &SiteNameArray);
1284c2c66affSColin Finck         if (status == NERR_Success)
1285c2c66affSColin Finck         {
1286c2c66affSColin Finck             if (SiteNameArray->EntryCount == 0)
1287c2c66affSColin Finck             {
1288c2c66affSColin Finck                 status = ERROR_INVALID_PARAMETER;
1289c2c66affSColin Finck             }
1290c2c66affSColin Finck             else
1291c2c66affSColin Finck             {
1292c2c66affSColin Finck                 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
1293c2c66affSColin Finck                 for (i = 0; i < SiteNameArray->EntryCount; i++)
1294c2c66affSColin Finck                     BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
1295c2c66affSColin Finck 
1296c2c66affSColin Finck                 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
1297c2c66affSColin Finck                 if (status == NERR_Success)
1298c2c66affSColin Finck                 {
1299c2c66affSColin Finck                     ZeroMemory(SiteNamesBuffer, BufferSize);
1300c2c66affSColin Finck 
1301c2c66affSColin Finck                     Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
1302c2c66affSColin Finck                     for (i = 0; i < SiteNameArray->EntryCount; i++)
1303c2c66affSColin Finck                     {
1304c2c66affSColin Finck                         SiteNamesBuffer[i] = Ptr;
1305c2c66affSColin Finck                         CopyMemory(Ptr,
1306c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Buffer,
1307c2c66affSColin Finck                                    SiteNameArray->SiteNames[i].Length);
1308c2c66affSColin Finck 
1309c2c66affSColin Finck                         Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
1310c2c66affSColin Finck                     }
1311c2c66affSColin Finck 
1312c2c66affSColin Finck                     *EntryCount = SiteNameArray->EntryCount;
1313c2c66affSColin Finck                     *SiteNames = SiteNamesBuffer;
1314c2c66affSColin Finck                 }
1315c2c66affSColin Finck             }
1316c2c66affSColin Finck 
1317c2c66affSColin Finck             MIDL_user_free(SiteNameArray);
1318c2c66affSColin Finck         }
1319c2c66affSColin Finck     }
1320c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1321c2c66affSColin Finck     {
1322c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
1323c2c66affSColin Finck     }
1324c2c66affSColin Finck     RpcEndExcept;
1325c2c66affSColin Finck 
1326c2c66affSColin Finck     return status;
1327c2c66affSColin Finck }
1328c2c66affSColin Finck 
1329c2c66affSColin Finck 
1330c2c66affSColin Finck DWORD
1331c2c66affSColin Finck WINAPI
DsGetForestTrustInformationW(_In_opt_ LPCWSTR ServerName,_In_opt_ LPCWSTR TrustedDomainName,_In_ DWORD Flags,_Out_ PLSA_FOREST_TRUST_INFORMATION * ForestTrustInfo)1332c2c66affSColin Finck DsGetForestTrustInformationW(
1333c2c66affSColin Finck     _In_opt_ LPCWSTR ServerName,
1334c2c66affSColin Finck     _In_opt_ LPCWSTR TrustedDomainName,
1335c2c66affSColin Finck     _In_ DWORD Flags,
1336c2c66affSColin Finck     _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
1337c2c66affSColin Finck {
1338c2c66affSColin Finck     NET_API_STATUS status;
1339c2c66affSColin Finck 
1340c2c66affSColin Finck     TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
1341c2c66affSColin Finck           debugstr_w(ServerName), debugstr_w(TrustedDomainName),
1342c2c66affSColin Finck           Flags, ForestTrustInfo);
1343c2c66affSColin Finck 
1344c2c66affSColin Finck     RpcTryExcept
1345c2c66affSColin Finck     {
1346c2c66affSColin Finck         status = DsrGetForestTrustInformation((PWSTR)ServerName,
1347c2c66affSColin Finck                                               (PWSTR)TrustedDomainName,
1348c2c66affSColin Finck                                               Flags,
1349c2c66affSColin Finck                                               ForestTrustInfo);
1350c2c66affSColin Finck     }
1351c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1352c2c66affSColin Finck     {
1353c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
1354c2c66affSColin Finck     }
1355c2c66affSColin Finck     RpcEndExcept;
1356c2c66affSColin Finck 
1357c2c66affSColin Finck     return status;
1358c2c66affSColin Finck }
1359c2c66affSColin Finck 
1360c2c66affSColin Finck 
1361c2c66affSColin Finck DWORD
1362c2c66affSColin Finck WINAPI
DsGetSiteNameA(_In_opt_ LPCSTR ComputerName,_Out_ LPSTR * SiteName)1363c2c66affSColin Finck DsGetSiteNameA(
13643d5c682cSEric Kohl     _In_opt_ LPCSTR ComputerName,
1365c2c66affSColin Finck     _Out_ LPSTR *SiteName)
1366c2c66affSColin Finck {
13673d5c682cSEric Kohl     PWSTR pComputerNameW = NULL;
13683d5c682cSEric Kohl     PWSTR pSiteNameW = NULL;
1369792d0f6bSEric Kohl     NET_API_STATUS status = ERROR_SUCCESS;
13703d5c682cSEric Kohl 
13713d5c682cSEric Kohl     TRACE("DsGetSiteNameA(%s, %p)\n",
1372c2c66affSColin Finck           debugstr_a(ComputerName), SiteName);
13733d5c682cSEric Kohl 
13743d5c682cSEric Kohl     if (ComputerName != NULL)
13753d5c682cSEric Kohl     {
13763d5c682cSEric Kohl         pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
13773d5c682cSEric Kohl         if (pComputerNameW == NULL)
13783d5c682cSEric Kohl         {
1379792d0f6bSEric Kohl             status = ERROR_NOT_ENOUGH_MEMORY;
13803d5c682cSEric Kohl             goto done;
13813d5c682cSEric Kohl         }
13823d5c682cSEric Kohl     }
13833d5c682cSEric Kohl 
1384792d0f6bSEric Kohl     status = DsGetSiteNameW(pComputerNameW,
13853d5c682cSEric Kohl                             &pSiteNameW);
1386792d0f6bSEric Kohl     if (status != ERROR_SUCCESS)
13873d5c682cSEric Kohl         goto done;
13883d5c682cSEric Kohl 
13893d5c682cSEric Kohl     *SiteName = NetpAllocAnsiStrFromWStr(pSiteNameW);
13903d5c682cSEric Kohl     if (*SiteName == NULL)
13913d5c682cSEric Kohl     {
1392792d0f6bSEric Kohl         status = ERROR_NOT_ENOUGH_MEMORY;
13933d5c682cSEric Kohl     }
13943d5c682cSEric Kohl 
13953d5c682cSEric Kohl done:
13963d5c682cSEric Kohl     if (pSiteNameW != NULL)
13973d5c682cSEric Kohl         NetApiBufferFree(pSiteNameW);
13983d5c682cSEric Kohl 
13993d5c682cSEric Kohl     if (pComputerNameW != NULL)
14003d5c682cSEric Kohl         NetApiBufferFree(pComputerNameW);
14013d5c682cSEric Kohl 
1402792d0f6bSEric Kohl     return status;
1403c2c66affSColin Finck }
1404c2c66affSColin Finck 
1405c2c66affSColin Finck 
1406c2c66affSColin Finck DWORD
1407c2c66affSColin Finck WINAPI
DsGetSiteNameW(_In_opt_ LPCWSTR ComputerName,_Out_ LPWSTR * SiteName)1408c2c66affSColin Finck DsGetSiteNameW(
14093d5c682cSEric Kohl     _In_opt_ LPCWSTR ComputerName,
1410c2c66affSColin Finck     _Out_ LPWSTR *SiteName)
1411c2c66affSColin Finck {
1412c2c66affSColin Finck     NET_API_STATUS status;
1413c2c66affSColin Finck 
1414c2c66affSColin Finck     TRACE("DsGetSiteNameW(%s, %p)\n",
1415c2c66affSColin Finck           debugstr_w(ComputerName), SiteName);
1416c2c66affSColin Finck 
1417c2c66affSColin Finck     RpcTryExcept
1418c2c66affSColin Finck     {
1419c2c66affSColin Finck         status = DsrGetSiteName((PWSTR)ComputerName,
1420c2c66affSColin Finck                                 SiteName);
1421c2c66affSColin Finck     }
1422c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1423c2c66affSColin Finck     {
1424c2c66affSColin Finck         status = I_RpcMapWin32Status(RpcExceptionCode());
1425c2c66affSColin Finck     }
1426c2c66affSColin Finck     RpcEndExcept;
1427c2c66affSColin Finck 
1428c2c66affSColin Finck     return status;
1429c2c66affSColin Finck }
1430c2c66affSColin Finck 
1431c2c66affSColin Finck 
1432c2c66affSColin Finck DWORD
1433c2c66affSColin Finck WINAPI
DsMergeForestTrustInformationW(_In_ LPCWSTR DomainName,_In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,_In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,_Out_ PLSA_FOREST_TRUST_INFORMATION * ForestTrustInfo)1434c2c66affSColin Finck DsMergeForestTrustInformationW(
1435c2c66affSColin Finck     _In_ LPCWSTR DomainName,
1436c2c66affSColin Finck     _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
1437c2c66affSColin Finck     _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
1438c2c66affSColin Finck     _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
1439c2c66affSColin Finck {
1440c2c66affSColin Finck     FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
1441c2c66affSColin Finck           debugstr_w(DomainName), NewForestTrustInfo,
1442c2c66affSColin Finck           OldForestTrustInfo, ForestTrustInfo);
1443c2c66affSColin Finck     return ERROR_CALL_NOT_IMPLEMENTED;
1444c2c66affSColin Finck }
1445c2c66affSColin Finck 
1446c2c66affSColin Finck 
1447c2c66affSColin Finck DWORD
1448c2c66affSColin Finck WINAPI
DsValidateSubnetNameA(_In_ LPCSTR SubnetName)1449c2c66affSColin Finck DsValidateSubnetNameA(
1450c2c66affSColin Finck     _In_ LPCSTR SubnetName)
1451c2c66affSColin Finck {
1452c2c66affSColin Finck     FIXME("DsValidateSubnetNameA(%s)\n",
1453c2c66affSColin Finck           debugstr_a(SubnetName));
1454c2c66affSColin Finck     return ERROR_CALL_NOT_IMPLEMENTED;
1455c2c66affSColin Finck }
1456c2c66affSColin Finck 
1457c2c66affSColin Finck 
1458c2c66affSColin Finck DWORD
1459c2c66affSColin Finck WINAPI
DsValidateSubnetNameW(_In_ LPCWSTR SubnetName)1460c2c66affSColin Finck DsValidateSubnetNameW(
1461c2c66affSColin Finck     _In_ LPCWSTR SubnetName)
1462c2c66affSColin Finck {
1463c2c66affSColin Finck     FIXME("DsValidateSubnetNameW(%s)\n",
1464c2c66affSColin Finck           debugstr_w(SubnetName));
1465c2c66affSColin Finck     return ERROR_CALL_NOT_IMPLEMENTED;
1466c2c66affSColin Finck }
1467c2c66affSColin Finck 
1468c2c66affSColin Finck 
1469c2c66affSColin Finck NTSTATUS
1470c2c66affSColin Finck WINAPI
NetEnumerateTrustedDomains(_In_ LPWSTR ServerName,_Out_ LPWSTR * DomainNames)1471c2c66affSColin Finck NetEnumerateTrustedDomains(
1472c2c66affSColin Finck     _In_ LPWSTR ServerName,
1473c2c66affSColin Finck     _Out_ LPWSTR *DomainNames)
1474c2c66affSColin Finck {
1475c2c66affSColin Finck     DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
1476c2c66affSColin Finck     NTSTATUS Status = 0;
1477c2c66affSColin Finck 
1478c2c66affSColin Finck     TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
1479c2c66affSColin Finck           debugstr_w(ServerName), DomainNames);
1480c2c66affSColin Finck 
1481c2c66affSColin Finck     RpcTryExcept
1482c2c66affSColin Finck     {
1483c2c66affSColin Finck         Status = NetrEnumerateTrustedDomains(ServerName,
1484c2c66affSColin Finck                                              &DomainNameBuffer);
1485c2c66affSColin Finck         if (NT_SUCCESS(Status))
1486c2c66affSColin Finck         {
1487c2c66affSColin Finck             *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
1488c2c66affSColin Finck         }
1489c2c66affSColin Finck     }
1490c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1491c2c66affSColin Finck     {
1492c2c66affSColin Finck         Status = I_RpcMapWin32Status(RpcExceptionCode());
1493c2c66affSColin Finck     } RpcEndExcept;
1494c2c66affSColin Finck 
1495c2c66affSColin Finck     return Status;
1496c2c66affSColin Finck }
1497c2c66affSColin Finck 
1498c2c66affSColin Finck 
1499c2c66affSColin Finck NET_API_STATUS
1500c2c66affSColin Finck WINAPI
NetGetAnyDCName(_In_opt_ LPCWSTR ServerName,_In_opt_ LPCWSTR DomainName,_Out_ LPBYTE * BufPtr)1501c2c66affSColin Finck NetGetAnyDCName(
1502c2c66affSColin Finck     _In_opt_ LPCWSTR ServerName,
1503c2c66affSColin Finck     _In_opt_ LPCWSTR DomainName,
1504c2c66affSColin Finck     _Out_ LPBYTE *BufPtr)
1505c2c66affSColin Finck {
1506adceb380SEric Kohl     NET_API_STATUS Status;
1507c2c66affSColin Finck 
1508c2c66affSColin Finck     TRACE("NetGetAnyDCName(%s, %s, %p)\n",
1509c2c66affSColin Finck           debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
1510c2c66affSColin Finck 
1511c2c66affSColin Finck     *BufPtr = NULL;
1512c2c66affSColin Finck 
1513c2c66affSColin Finck     RpcTryExcept
1514c2c66affSColin Finck     {
1515adceb380SEric Kohl         Status = NetrGetAnyDCName((PWSTR)ServerName,
1516c2c66affSColin Finck                                   (PWSTR)DomainName,
1517c2c66affSColin Finck                                   (PWSTR*)BufPtr);
1518c2c66affSColin Finck     }
1519c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1520c2c66affSColin Finck     {
1521adceb380SEric Kohl         Status = I_RpcMapWin32Status(RpcExceptionCode());
1522c2c66affSColin Finck     }
1523c2c66affSColin Finck     RpcEndExcept;
1524c2c66affSColin Finck 
1525adceb380SEric Kohl     return Status;
1526c2c66affSColin Finck }
1527c2c66affSColin Finck 
1528c2c66affSColin Finck 
1529c2c66affSColin Finck NET_API_STATUS
1530c2c66affSColin Finck WINAPI
NetGetDCName(_In_opt_ LPCWSTR ServerName,_In_opt_ LPCWSTR DomainName,_Out_ LPBYTE * BufPtr)1531c2c66affSColin Finck NetGetDCName(
1532adceb380SEric Kohl     _In_opt_ LPCWSTR ServerName,
1533adceb380SEric Kohl     _In_opt_ LPCWSTR DomainName,
1534adceb380SEric Kohl     _Out_ LPBYTE *BufPtr)
1535c2c66affSColin Finck {
1536adceb380SEric Kohl     PDOMAIN_CONTROLLER_INFOW pDomainControllerInfo = NULL;
1537adceb380SEric Kohl     NET_API_STATUS Status;
1538c2c66affSColin Finck 
1539adceb380SEric Kohl     FIXME("NetGetDCName(%s, %s, %p)\n",
1540adceb380SEric Kohl           debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
1541adceb380SEric Kohl 
1542adceb380SEric Kohl     if (ServerName == NULL || *ServerName == UNICODE_NULL)
1543adceb380SEric Kohl     {
1544adceb380SEric Kohl         Status = DsGetDcNameWithAccountW(NULL,
1545adceb380SEric Kohl                                          NULL,
1546adceb380SEric Kohl                                          0,
1547adceb380SEric Kohl                                          DomainName,
1548adceb380SEric Kohl                                          NULL,
1549adceb380SEric Kohl                                          NULL,
1550adceb380SEric Kohl                                          0, //???
1551adceb380SEric Kohl                                          &pDomainControllerInfo);
1552adceb380SEric Kohl         if (Status != NERR_Success)
1553adceb380SEric Kohl             goto done;
1554adceb380SEric Kohl 
1555adceb380SEric Kohl         Status = NetApiBufferAllocate((wcslen(pDomainControllerInfo->DomainControllerName) + 1) * sizeof(WCHAR),
1556adceb380SEric Kohl                                       (PVOID*)BufPtr);
1557adceb380SEric Kohl         if (Status != NERR_Success)
1558adceb380SEric Kohl             goto done;
1559adceb380SEric Kohl 
1560adceb380SEric Kohl         wcscpy((PWSTR)*BufPtr,
1561adceb380SEric Kohl                pDomainControllerInfo->DomainControllerName);
1562adceb380SEric Kohl     }
1563adceb380SEric Kohl     else
1564adceb380SEric Kohl     {
1565adceb380SEric Kohl         FIXME("Not implemented yet!\n");
1566adceb380SEric Kohl         Status = NERR_DCNotFound;
1567adceb380SEric Kohl     }
1568adceb380SEric Kohl 
1569adceb380SEric Kohl done:
1570adceb380SEric Kohl     if (pDomainControllerInfo != NULL)
1571adceb380SEric Kohl         NetApiBufferFree(pDomainControllerInfo);
1572adceb380SEric Kohl 
1573adceb380SEric Kohl     return Status;
1574c2c66affSColin Finck }
1575c2c66affSColin Finck 
1576c2c66affSColin Finck 
1577e0b50500SEric Kohl NET_API_STATUS
1578e0b50500SEric Kohl WINAPI
NetLogonGetTimeServiceParentDomain(_In_ LPWSTR ServerName,_Out_ LPWSTR * DomainName,_Out_ LPBOOL PdcSameSite)1579e0b50500SEric Kohl NetLogonGetTimeServiceParentDomain(
1580e0b50500SEric Kohl     _In_ LPWSTR ServerName,
1581e0b50500SEric Kohl     _Out_ LPWSTR *DomainName,
1582e0b50500SEric Kohl     _Out_ LPBOOL PdcSameSite)
1583e0b50500SEric Kohl {
1584e0b50500SEric Kohl     NET_API_STATUS Status;
1585e0b50500SEric Kohl 
1586e0b50500SEric Kohl     TRACE("NetLogonGetTimeServiceParentDomain(%s, %p, %p)\n",
1587e0b50500SEric Kohl           debugstr_w(ServerName), DomainName, PdcSameSite);
1588e0b50500SEric Kohl 
1589e0b50500SEric Kohl     RpcTryExcept
1590e0b50500SEric Kohl     {
1591e0b50500SEric Kohl         Status = NetrLogonGetTimeServiceParentDomain(ServerName,
1592e0b50500SEric Kohl                                                      DomainName,
1593e0b50500SEric Kohl                                                      PdcSameSite);
1594e0b50500SEric Kohl     }
1595e0b50500SEric Kohl     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1596e0b50500SEric Kohl     {
1597e0b50500SEric Kohl         Status = I_RpcMapWin32Status(RpcExceptionCode());
1598e0b50500SEric Kohl     }
1599e0b50500SEric Kohl     RpcEndExcept;
1600e0b50500SEric Kohl 
1601e0b50500SEric Kohl     return Status;
1602e0b50500SEric Kohl }
1603e0b50500SEric Kohl 
1604e0b50500SEric Kohl 
1605c2c66affSColin Finck NTSTATUS
1606c2c66affSColin Finck WINAPI
NetLogonSetServiceBits(_In_ LPWSTR ServerName,_In_ DWORD ServiceBitsOfInterest,_In_ DWORD ServiceBits)1607c2c66affSColin Finck NetLogonSetServiceBits(
1608c2c66affSColin Finck     _In_ LPWSTR ServerName,
1609c2c66affSColin Finck     _In_ DWORD ServiceBitsOfInterest,
1610c2c66affSColin Finck     _In_ DWORD ServiceBits)
1611c2c66affSColin Finck {
1612c2c66affSColin Finck     NTSTATUS Status;
1613c2c66affSColin Finck 
1614c2c66affSColin Finck     TRACE("NetLogonSetServiceBits(%s 0x%lx 0x%lx)\n",
1615c2c66affSColin Finck           debugstr_w(ServerName), ServiceBitsOfInterest, ServiceBits);
1616c2c66affSColin Finck 
1617c2c66affSColin Finck     RpcTryExcept
1618c2c66affSColin Finck     {
1619c2c66affSColin Finck         Status = NetrLogonSetServiceBits(ServerName,
1620c2c66affSColin Finck                                          ServiceBitsOfInterest,
1621c2c66affSColin Finck                                          ServiceBits);
1622c2c66affSColin Finck     }
1623c2c66affSColin Finck     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1624c2c66affSColin Finck     {
1625c2c66affSColin Finck         Status = RpcExceptionCode();
1626c2c66affSColin Finck     }
1627c2c66affSColin Finck     RpcEndExcept;
1628c2c66affSColin Finck 
1629c2c66affSColin Finck     return Status;
1630c2c66affSColin Finck }
1631c2c66affSColin Finck 
1632c2c66affSColin Finck /* EOF */
1633