[NETAPI32] Implement DsEnumerateDomainTrustsW
[reactos.git] / dll / win32 / netapi32 / netlogon.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: NetAPI DLL
4 * FILE: dll/win32/netapi32/netlogon.c
5 * PURPOSE: Netlogon service interface code
6 * PROGRAMMERS: Eric Kohl (eric.kohl@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "netapi32.h"
12 #include <winsock2.h>
13 #include <rpc.h>
14 #include <dsrole.h>
15 #include <dsgetdc.h>
16 #include "netlogon_c.h"
17
18 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
19
20 DWORD
21 WINAPI
22 DsGetDcNameWithAccountA(
23 _In_opt_ LPCSTR ComputerName,
24 _In_opt_ LPCSTR AccountName,
25 _In_ ULONG AccountControlBits,
26 _In_ LPCSTR DomainName,
27 _In_ GUID *DomainGuid,
28 _In_ LPCSTR SiteName,
29 _In_ ULONG Flags,
30 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo);
31
32 DWORD
33 WINAPI
34 DsGetDcNameWithAccountW(
35 _In_opt_ LPCWSTR ComputerName,
36 _In_opt_ LPCWSTR AccountName,
37 _In_ ULONG AccountControlBits,
38 _In_ LPCWSTR DomainName,
39 _In_ GUID *DomainGuid,
40 _In_ LPCWSTR SiteName,
41 _In_ ULONG Flags,
42 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo);
43
44 /* FUNCTIONS *****************************************************************/
45
46 handle_t
47 __RPC_USER
48 LOGONSRV_HANDLE_bind(
49 LOGONSRV_HANDLE pszSystemName)
50 {
51 handle_t hBinding = NULL;
52 LPWSTR pszStringBinding;
53 RPC_STATUS status;
54
55 TRACE("LOGONSRV_HANDLE_bind() called\n");
56
57 status = RpcStringBindingComposeW(NULL,
58 L"ncacn_np",
59 pszSystemName,
60 L"\\pipe\\netlogon",
61 NULL,
62 &pszStringBinding);
63 if (status)
64 {
65 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
66 return NULL;
67 }
68
69 /* Set the binding handle that will be used to bind to the server. */
70 status = RpcBindingFromStringBindingW(pszStringBinding,
71 &hBinding);
72 if (status)
73 {
74 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
75 }
76
77 status = RpcStringFreeW(&pszStringBinding);
78 if (status)
79 {
80 // TRACE("RpcStringFree returned 0x%x\n", status);
81 }
82
83 return hBinding;
84 }
85
86
87 void
88 __RPC_USER
89 LOGONSRV_HANDLE_unbind(
90 LOGONSRV_HANDLE pszSystemName,
91 handle_t hBinding)
92 {
93 RPC_STATUS status;
94
95 TRACE("LOGONSRV_HANDLE_unbind() called\n");
96
97 status = RpcBindingFree(&hBinding);
98 if (status)
99 {
100 TRACE("RpcBindingFree returned 0x%x\n", status);
101 }
102 }
103
104
105 /* PUBLIC FUNCTIONS **********************************************************/
106
107 DWORD
108 WINAPI
109 DsAddressToSiteNamesA(
110 _In_opt_ LPCSTR ComputerName,
111 _In_ DWORD EntryCount,
112 _In_ PSOCKET_ADDRESS SocketAddresses,
113 _Out_ LPSTR **SiteNames)
114 {
115 PWSTR pComputerNameW = NULL, *pSiteNamesW = NULL;
116 PSTR *pSiteNamesA = NULL, Ptr;
117 UNICODE_STRING UnicodeString;
118 ANSI_STRING AnsiString;
119 ULONG BufferSize, i;
120 NTSTATUS Status;
121 NET_API_STATUS status = NERR_Success;
122
123 TRACE("DsAddressToSiteNamesA(%s, %lu, %p, %p)\n",
124 debugstr_a(ComputerName), EntryCount, SocketAddresses, SiteNames);
125
126 if (EntryCount == 0)
127 return ERROR_INVALID_PARAMETER;
128
129 if (ComputerName != NULL)
130 {
131 pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
132 if (pComputerNameW == NULL)
133 {
134 status = ERROR_NOT_ENOUGH_MEMORY;
135 goto done;
136 }
137 }
138
139 /* Call the Unicode function */
140 status = DsAddressToSiteNamesW(pComputerNameW,
141 EntryCount,
142 SocketAddresses,
143 &pSiteNamesW);
144 if (status != NERR_Success)
145 goto done;
146
147 /* Calculate the required site names buffer size */
148 BufferSize = EntryCount * sizeof(PSTR);
149 for (i = 0; i < EntryCount; i++)
150 {
151 if (pSiteNamesW[i] != NULL)
152 {
153 RtlInitUnicodeString(&UnicodeString,
154 pSiteNamesW[i]);
155 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
156 }
157 }
158
159 /* Allocate the site names ANSI buffer */
160 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
161 if (status != NERR_Success)
162 goto done;
163
164 /* Convert the site names */
165 Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + EntryCount * sizeof(PSTR));
166 BufferSize -= EntryCount * sizeof(PSTR);
167
168 for (i = 0; i < EntryCount; i++)
169 {
170 if (pSiteNamesW[i] != NULL)
171 {
172 pSiteNamesA[i] = Ptr;
173 RtlInitUnicodeString(&UnicodeString,
174 pSiteNamesW[i]);
175 AnsiString.Length = 0;
176 AnsiString.MaximumLength = BufferSize;
177 AnsiString.Buffer = Ptr;
178
179 Status = RtlUnicodeStringToAnsiString(&AnsiString,
180 &UnicodeString,
181 FALSE);
182 if (!NT_SUCCESS(Status))
183 {
184 status = RtlNtStatusToDosError(Status);
185 goto done;
186 }
187
188 Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
189 BufferSize -= AnsiString.Length + sizeof(CHAR);
190 }
191 }
192
193 *SiteNames = pSiteNamesA;
194 pSiteNamesA = NULL;
195
196 done:
197 if (pSiteNamesA != NULL)
198 NetApiBufferFree(pSiteNamesA);
199
200 if (pSiteNamesW != NULL)
201 NetApiBufferFree(pSiteNamesW);
202
203 if (pComputerNameW != NULL)
204 NetApiBufferFree(pComputerNameW);
205
206 return status;
207 }
208
209
210 DWORD
211 WINAPI
212 DsAddressToSiteNamesW(
213 _In_opt_ LPCWSTR ComputerName,
214 _In_ DWORD EntryCount,
215 _In_ PSOCKET_ADDRESS SocketAddresses,
216 _Out_ LPWSTR **SiteNames)
217 {
218 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
219 PWSTR *SiteNamesBuffer = NULL, Ptr;
220 ULONG BufferSize, i;
221 NET_API_STATUS status;
222
223 TRACE("DsAddressToSiteNamesW(%s, %lu, %p, %p)\n",
224 debugstr_w(ComputerName), EntryCount, SocketAddresses, SiteNames);
225
226 if (EntryCount == 0)
227 return ERROR_INVALID_PARAMETER;
228
229 *SiteNames = NULL;
230
231 RpcTryExcept
232 {
233 status = DsrAddressToSiteNamesW((PWSTR)ComputerName,
234 EntryCount,
235 (PNL_SOCKET_ADDRESS)SocketAddresses,
236 &SiteNameArray);
237 if (status == NERR_Success)
238 {
239 if (SiteNameArray->EntryCount == 0)
240 {
241 status = ERROR_INVALID_PARAMETER;
242 }
243 else
244 {
245 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
246 for (i = 0; i < SiteNameArray->EntryCount; i++)
247 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
248
249 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
250 if (status == NERR_Success)
251 {
252 ZeroMemory(SiteNamesBuffer, BufferSize);
253
254 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
255 for (i = 0; i < SiteNameArray->EntryCount; i++)
256 {
257 SiteNamesBuffer[i] = Ptr;
258 CopyMemory(Ptr,
259 SiteNameArray->SiteNames[i].Buffer,
260 SiteNameArray->SiteNames[i].Length);
261
262 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
263 }
264
265 *SiteNames = SiteNamesBuffer;
266 }
267 }
268
269 MIDL_user_free(SiteNameArray);
270 }
271 }
272 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
273 {
274 status = I_RpcMapWin32Status(RpcExceptionCode());
275 }
276 RpcEndExcept;
277
278 return status;
279 }
280
281
282 DWORD
283 WINAPI
284 DsAddressToSiteNamesExA(
285 _In_opt_ LPCSTR ComputerName,
286 _In_ DWORD EntryCount,
287 _In_ PSOCKET_ADDRESS SocketAddresses,
288 _Out_ LPSTR **SiteNames,
289 _Out_ LPSTR **SubnetNames)
290 {
291 PWSTR pComputerNameW = NULL, *pSiteNamesW = NULL;
292 PWSTR *pSubnetNamesW = NULL;
293 PSTR *pSiteNamesA = NULL, *pSubnetNamesA = NULL, Ptr;
294 UNICODE_STRING UnicodeString;
295 ANSI_STRING AnsiString;
296 ULONG BufferSize, i;
297 NTSTATUS Status;
298 NET_API_STATUS status = NERR_Success;
299
300 TRACE("DsAddressToSiteNamesExA(%s, %lu, %p, %p, %p)\n",
301 debugstr_a(ComputerName), EntryCount, SocketAddresses,
302 SiteNames, SubnetNames);
303
304 if (EntryCount == 0)
305 return ERROR_INVALID_PARAMETER;
306
307 if (ComputerName != NULL)
308 {
309 pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
310 if (pComputerNameW == NULL)
311 {
312 status = ERROR_NOT_ENOUGH_MEMORY;
313 goto done;
314 }
315 }
316
317 /* Call the Unicode function */
318 status = DsAddressToSiteNamesExW(pComputerNameW,
319 EntryCount,
320 SocketAddresses,
321 &pSiteNamesW,
322 &pSubnetNamesW);
323 if (status != NERR_Success)
324 goto done;
325
326 /* Calculate the required site names buffer size */
327 BufferSize = EntryCount * sizeof(PSTR);
328 for (i = 0; i < EntryCount; i++)
329 {
330 if (pSiteNamesW[i] != NULL)
331 {
332 RtlInitUnicodeString(&UnicodeString,
333 pSiteNamesW[i]);
334 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
335 }
336 }
337
338 /* Allocate the site names ANSI buffer */
339 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
340 if (status != NERR_Success)
341 goto done;
342
343 /* Convert the site names */
344 Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + EntryCount * sizeof(PSTR));
345 BufferSize -= EntryCount * sizeof(PSTR);
346
347 for (i = 0; i < EntryCount; i++)
348 {
349 if (pSiteNamesW[i] != NULL)
350 {
351 pSiteNamesA[i] = Ptr;
352 RtlInitUnicodeString(&UnicodeString,
353 pSiteNamesW[i]);
354 AnsiString.Length = 0;
355 AnsiString.MaximumLength = BufferSize;
356 AnsiString.Buffer = Ptr;
357
358 Status = RtlUnicodeStringToAnsiString(&AnsiString,
359 &UnicodeString,
360 FALSE);
361 if (!NT_SUCCESS(Status))
362 {
363 status = RtlNtStatusToDosError(Status);
364 goto done;
365 }
366
367 Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
368 BufferSize -= AnsiString.Length + sizeof(CHAR);
369 }
370 }
371
372 /* Calculate the required subnet names buffer size */
373 BufferSize = EntryCount * sizeof(PSTR);
374 for (i = 0; i < EntryCount; i++)
375 {
376 if (pSubnetNamesW[i] != NULL)
377 {
378 RtlInitUnicodeString(&UnicodeString,
379 pSubnetNamesW[i]);
380 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
381 }
382 }
383
384 /* Allocate the subnet names ANSI buffer */
385 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSubnetNamesA);
386 if (status != NERR_Success)
387 goto done;
388
389 /* Convert the subnet names */
390 Ptr = (PSTR)((ULONG_PTR)pSubnetNamesA + EntryCount * sizeof(PSTR));
391 BufferSize -= EntryCount * sizeof(PSTR);
392
393 for (i = 0; i < EntryCount; i++)
394 {
395 if (pSubnetNamesW[i] != NULL)
396 {
397 pSubnetNamesA[i] = Ptr;
398 RtlInitUnicodeString(&UnicodeString,
399 pSubnetNamesW[i]);
400 AnsiString.Length = 0;
401 AnsiString.MaximumLength = BufferSize;
402 AnsiString.Buffer = Ptr;
403
404 Status = RtlUnicodeStringToAnsiString(&AnsiString,
405 &UnicodeString,
406 FALSE);
407 if (!NT_SUCCESS(Status))
408 {
409 status = RtlNtStatusToDosError(Status);
410 goto done;
411 }
412
413 Ptr = Ptr + AnsiString.Length + sizeof(CHAR);
414 BufferSize -= AnsiString.Length + sizeof(CHAR);
415 }
416 }
417
418 *SiteNames = pSiteNamesA;
419 *SubnetNames = pSubnetNamesA;
420 pSiteNamesA = NULL;
421 pSubnetNamesA = NULL;
422
423 done:
424 if (pSubnetNamesA != NULL)
425 NetApiBufferFree(pSubnetNamesA);
426
427 if (pSiteNamesA != NULL)
428 NetApiBufferFree(pSiteNamesA);
429
430 if (pSubnetNamesW != NULL)
431 NetApiBufferFree(pSubnetNamesW);
432
433 if (pSiteNamesW != NULL)
434 NetApiBufferFree(pSiteNamesW);
435
436 if (pComputerNameW != NULL)
437 NetApiBufferFree(pComputerNameW);
438
439 return status;
440 }
441
442
443 DWORD
444 WINAPI
445 DsAddressToSiteNamesExW(
446 _In_opt_ LPCWSTR ComputerName,
447 _In_ DWORD EntryCount,
448 _In_ PSOCKET_ADDRESS SocketAddresses,
449 _Out_ LPWSTR **SiteNames,
450 _Out_ LPWSTR **SubnetNames)
451 {
452 PNL_SITE_NAME_EX_ARRAY SiteNameArray = NULL;
453 PWSTR *SiteNamesBuffer = NULL, *SubnetNamesBuffer = NULL, Ptr;
454 ULONG SiteNameBufferSize, SubnetNameBufferSize, i;
455 NET_API_STATUS status;
456
457 TRACE("DsAddressToSiteNamesExW(%s, %lu, %p, %p, %p)\n",
458 debugstr_w(ComputerName), EntryCount, SocketAddresses,
459 SiteNames, SubnetNames);
460
461 if (EntryCount == 0)
462 return ERROR_INVALID_PARAMETER;
463
464 *SiteNames = NULL;
465 *SubnetNames = NULL;
466
467 RpcTryExcept
468 {
469 status = DsrAddressToSiteNamesExW((PWSTR)ComputerName,
470 EntryCount,
471 (PNL_SOCKET_ADDRESS)SocketAddresses,
472 &SiteNameArray);
473 if (status == NERR_Success)
474 {
475 if (SiteNameArray->EntryCount == 0)
476 {
477 status = ERROR_INVALID_PARAMETER;
478 }
479 else
480 {
481 SiteNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
482 SubnetNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
483 for (i = 0; i < SiteNameArray->EntryCount; i++)
484 {
485 SiteNameBufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
486 SubnetNameBufferSize += SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR);
487 }
488
489 status = NetApiBufferAllocate(SiteNameBufferSize, (PVOID*)&SiteNamesBuffer);
490 if (status == NERR_Success)
491 {
492 ZeroMemory(SiteNamesBuffer, SiteNameBufferSize);
493
494 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
495 for (i = 0; i < SiteNameArray->EntryCount; i++)
496 {
497 SiteNamesBuffer[i] = Ptr;
498 CopyMemory(Ptr,
499 SiteNameArray->SiteNames[i].Buffer,
500 SiteNameArray->SiteNames[i].Length);
501
502 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
503 }
504
505 *SiteNames = SiteNamesBuffer;
506 }
507
508 status = NetApiBufferAllocate(SubnetNameBufferSize, (PVOID*)&SubnetNamesBuffer);
509 if (status == NERR_Success)
510 {
511 ZeroMemory(SubnetNamesBuffer, SubnetNameBufferSize);
512
513 Ptr = (PWSTR)((ULONG_PTR)SubnetNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
514 for (i = 0; i < SiteNameArray->EntryCount; i++)
515 {
516 SubnetNamesBuffer[i] = Ptr;
517 CopyMemory(Ptr,
518 SiteNameArray->SubnetNames[i].Buffer,
519 SiteNameArray->SubnetNames[i].Length);
520
521 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR));
522 }
523
524 *SubnetNames = SubnetNamesBuffer;
525 }
526 }
527
528 MIDL_user_free(SiteNameArray);
529 }
530 }
531 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
532 {
533 status = I_RpcMapWin32Status(RpcExceptionCode());
534 }
535 RpcEndExcept;
536
537 return status;
538 }
539
540
541 DWORD
542 WINAPI
543 DsDeregisterDnsHostRecordsA(
544 _In_opt_ LPSTR ServerName,
545 _In_opt_ LPSTR DnsDomainName,
546 _In_opt_ GUID *DomainGuid,
547 _In_opt_ GUID *DsaGuid,
548 _In_ LPSTR DnsHostName)
549 {
550 PWSTR pServerNameW = NULL, pDnsDomainNameW = NULL;
551 PWSTR pDnsHostNameW = NULL;
552 NET_API_STATUS status = NERR_Success;
553
554 TRACE("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
555 debugstr_a(ServerName), debugstr_a(DnsDomainName),
556 DomainGuid, DsaGuid, debugstr_a(DnsHostName));
557
558 if (ServerName != NULL)
559 {
560 pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
561 if (pServerNameW == NULL)
562 {
563 status = ERROR_NOT_ENOUGH_MEMORY;
564 goto done;
565 }
566 }
567
568 if (DnsDomainName != NULL)
569 {
570 pDnsDomainNameW = NetpAllocWStrFromAnsiStr((PSTR)DnsDomainName);
571 if (pDnsDomainNameW == NULL)
572 {
573 status = ERROR_NOT_ENOUGH_MEMORY;
574 goto done;
575 }
576 }
577
578 pDnsHostNameW = NetpAllocWStrFromAnsiStr((PSTR)DnsHostName);
579 if (pDnsHostNameW == NULL)
580 {
581 status = ERROR_NOT_ENOUGH_MEMORY;
582 goto done;
583 }
584
585 status = DsDeregisterDnsHostRecordsW(pServerNameW,
586 pDnsDomainNameW,
587 DomainGuid,
588 DsaGuid,
589 pDnsHostNameW);
590
591 done:
592 if (pDnsHostNameW != NULL)
593 NetApiBufferFree(pDnsHostNameW);
594
595 if (pDnsDomainNameW != NULL)
596 NetApiBufferFree(pDnsDomainNameW);
597
598 if (pServerNameW != NULL)
599 NetApiBufferFree(pServerNameW);
600
601 return status;
602 }
603
604
605 DWORD
606 WINAPI
607 DsDeregisterDnsHostRecordsW(
608 _In_opt_ LPWSTR ServerName,
609 _In_opt_ LPWSTR DnsDomainName,
610 _In_opt_ GUID *DomainGuid,
611 _In_opt_ GUID *DsaGuid,
612 _In_ LPWSTR DnsHostName)
613 {
614 NET_API_STATUS status;
615
616 TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
617 debugstr_w(ServerName), debugstr_w(DnsDomainName),
618 DomainGuid, DsaGuid, debugstr_w(DnsHostName));
619
620 RpcTryExcept
621 {
622 status = DsrDeregisterDnsHostRecords(ServerName,
623 DnsDomainName,
624 DomainGuid,
625 DsaGuid,
626 DnsHostName);
627 }
628 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
629 {
630 status = I_RpcMapWin32Status(RpcExceptionCode());
631 }
632 RpcEndExcept;
633
634 return status;
635 }
636
637
638 DWORD
639 WINAPI
640 DsEnumerateDomainTrustsA(
641 _In_opt_ LPSTR ServerName,
642 _In_ ULONG Flags,
643 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
644 _Out_ PULONG DomainCount)
645 {
646 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
647 debugstr_a(ServerName), Flags, Domains, DomainCount);
648 return ERROR_CALL_NOT_IMPLEMENTED;
649 }
650
651
652 DWORD
653 WINAPI
654 DsEnumerateDomainTrustsW(
655 _In_opt_ LPWSTR ServerName,
656 _In_ ULONG Flags,
657 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
658 _Out_ PULONG DomainCount)
659 {
660 NETLOGON_TRUSTED_DOMAIN_ARRAY DomainsArray = {0, NULL};
661 NET_API_STATUS status;
662
663 TRACE("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
664 debugstr_w(ServerName), Flags, Domains, DomainCount);
665
666 RpcTryExcept
667 {
668 status = DsrEnumerateDomainTrusts(ServerName,
669 Flags,
670 &DomainsArray);
671 if (status == NERR_Success)
672 {
673 *Domains = DomainsArray.Domains;
674 *DomainCount = DomainsArray.DomainCount;
675 }
676 }
677 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
678 {
679 status = I_RpcMapWin32Status(RpcExceptionCode());
680 }
681 RpcEndExcept;
682
683 return status;
684 }
685
686
687 DWORD
688 WINAPI
689 DsGetDcNameA(
690 _In_opt_ LPCSTR ComputerName,
691 _In_ LPCSTR DomainName,
692 _In_ GUID *DomainGuid,
693 _In_ LPCSTR SiteName,
694 _In_ ULONG Flags,
695 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
696 {
697 TRACE("DsGetDcNameA(%s, %s, %s, %s, %08lx, %p): stub\n",
698 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
699 debugstr_a(SiteName), Flags, DomainControllerInfo);
700 return DsGetDcNameWithAccountA(ComputerName,
701 NULL,
702 0,
703 DomainName,
704 DomainGuid,
705 SiteName,
706 Flags,
707 DomainControllerInfo);
708 }
709
710
711 DWORD
712 WINAPI
713 DsGetDcNameW(
714 _In_opt_ LPCWSTR ComputerName,
715 _In_ LPCWSTR DomainName,
716 _In_ GUID *DomainGuid,
717 _In_ LPCWSTR SiteName,
718 _In_ ULONG Flags,
719 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
720 {
721 TRACE("DsGetDcNameW(%s, %s, %s, %s, %08lx, %p)\n",
722 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
723 debugstr_w(SiteName), Flags, DomainControllerInfo);
724 return DsGetDcNameWithAccountW(ComputerName,
725 NULL,
726 0,
727 DomainName,
728 DomainGuid,
729 SiteName,
730 Flags,
731 DomainControllerInfo);
732 }
733
734
735 DWORD
736 WINAPI
737 DsGetDcNameWithAccountA(
738 _In_opt_ LPCSTR ComputerName,
739 _In_opt_ LPCSTR AccountName,
740 _In_ ULONG AccountControlBits,
741 _In_ LPCSTR DomainName,
742 _In_ GUID *DomainGuid,
743 _In_ LPCSTR SiteName,
744 _In_ ULONG Flags,
745 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
746 {
747 PWSTR pComputerNameW = NULL, pAccountNameW = NULL;
748 PWSTR pDomainNameW = NULL, pSiteNameW = NULL;
749 PDOMAIN_CONTROLLER_INFOW pDomainControllerInfoW = NULL;
750 PDOMAIN_CONTROLLER_INFOA pDomainControllerInfoA = NULL;
751 UNICODE_STRING UnicodeString;
752 ANSI_STRING AnsiString;
753 PSTR Ptr;
754 ULONG BufferSize;
755 NTSTATUS Status;
756 NET_API_STATUS status = NERR_Success;
757
758 TRACE("DsGetDcNameWithAccountA(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
759 debugstr_a(ComputerName), debugstr_a(AccountName), AccountControlBits,
760 debugstr_a(DomainName), debugstr_guid(DomainGuid),
761 debugstr_a(SiteName), Flags, DomainControllerInfo);
762
763 if (ComputerName != NULL)
764 {
765 pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
766 if (pComputerNameW == NULL)
767 {
768 status = ERROR_NOT_ENOUGH_MEMORY;
769 goto done;
770 }
771 }
772
773 if (AccountName != NULL)
774 {
775 pAccountNameW = NetpAllocWStrFromAnsiStr((PSTR)AccountName);
776 if (pAccountNameW == NULL)
777 {
778 status = ERROR_NOT_ENOUGH_MEMORY;
779 goto done;
780 }
781 }
782
783 pDomainNameW = NetpAllocWStrFromAnsiStr((PSTR)DomainName);
784 if (pDomainNameW == NULL)
785 {
786 status = ERROR_NOT_ENOUGH_MEMORY;
787 goto done;
788 }
789
790 pSiteNameW = NetpAllocWStrFromAnsiStr((PSTR)SiteName);
791 if (pSiteNameW == NULL)
792 {
793 status = ERROR_NOT_ENOUGH_MEMORY;
794 goto done;
795 }
796
797 status = DsGetDcNameWithAccountW(pComputerNameW,
798 pAccountNameW,
799 AccountControlBits,
800 pDomainNameW,
801 DomainGuid,
802 pSiteNameW,
803 Flags,
804 &pDomainControllerInfoW);
805 if (status != NERR_Success)
806 goto done;
807
808 BufferSize = sizeof(DOMAIN_CONTROLLER_INFOA);
809
810 RtlInitUnicodeString(&UnicodeString,
811 pDomainControllerInfoW->DomainControllerName);
812 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
813
814 RtlInitUnicodeString(&UnicodeString,
815 pDomainControllerInfoW->DomainControllerAddress);
816 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
817
818 RtlInitUnicodeString(&UnicodeString,
819 pDomainControllerInfoW->DomainName);
820 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
821
822 RtlInitUnicodeString(&UnicodeString,
823 pDomainControllerInfoW->DnsForestName);
824 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
825
826 if (pDomainControllerInfoW->DcSiteName != NULL)
827 {
828 RtlInitUnicodeString(&UnicodeString,
829 pDomainControllerInfoW->DcSiteName);
830 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
831 }
832
833 if (pDomainControllerInfoW->ClientSiteName != NULL)
834 {
835 RtlInitUnicodeString(&UnicodeString,
836 pDomainControllerInfoW->ClientSiteName);
837 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
838 }
839
840 /* Allocate the ANSI buffer */
841 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pDomainControllerInfoA);
842 if (status != NERR_Success)
843 goto done;
844
845 pDomainControllerInfoA->DomainControllerAddressType =
846 pDomainControllerInfoW->DomainControllerAddressType;
847
848 pDomainControllerInfoA->Flags = pDomainControllerInfoW->Flags;
849
850 CopyMemory(&pDomainControllerInfoA->DomainGuid,
851 &pDomainControllerInfoW->DomainGuid,
852 sizeof(GUID));
853
854 Ptr = (PSTR)((ULONG_PTR)pDomainControllerInfoA + sizeof(DOMAIN_CONTROLLER_INFOA));
855 BufferSize -= sizeof(DOMAIN_CONTROLLER_INFOA);
856
857 pDomainControllerInfoA->DomainControllerName = Ptr;
858 RtlInitUnicodeString(&UnicodeString,
859 pDomainControllerInfoW->DomainControllerName);
860 AnsiString.Length = 0;
861 AnsiString.MaximumLength = BufferSize;
862 AnsiString.Buffer = Ptr;
863
864 Status = RtlUnicodeStringToAnsiString(&AnsiString,
865 &UnicodeString,
866 FALSE);
867 if (!NT_SUCCESS(Status))
868 {
869 status = RtlNtStatusToDosError(Status);
870 goto done;
871 }
872
873 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
874 BufferSize -= AnsiString.Length + sizeof(CHAR);
875
876 pDomainControllerInfoA->DomainControllerAddress = Ptr;
877 RtlInitUnicodeString(&UnicodeString,
878 pDomainControllerInfoW->DomainControllerAddress);
879 AnsiString.Length = 0;
880 AnsiString.MaximumLength = BufferSize;
881 AnsiString.Buffer = Ptr;
882
883 Status = RtlUnicodeStringToAnsiString(&AnsiString,
884 &UnicodeString,
885 FALSE);
886 if (!NT_SUCCESS(Status))
887 {
888 status = RtlNtStatusToDosError(Status);
889 goto done;
890 }
891
892 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
893 BufferSize -= AnsiString.Length + sizeof(CHAR);
894
895 pDomainControllerInfoA->DomainName = Ptr;
896 RtlInitUnicodeString(&UnicodeString,
897 pDomainControllerInfoW->DomainName);
898 AnsiString.Length = 0;
899 AnsiString.MaximumLength = BufferSize;
900 AnsiString.Buffer = Ptr;
901
902 Status = RtlUnicodeStringToAnsiString(&AnsiString,
903 &UnicodeString,
904 FALSE);
905 if (!NT_SUCCESS(Status))
906 {
907 status = RtlNtStatusToDosError(Status);
908 goto done;
909 }
910
911 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
912 BufferSize -= AnsiString.Length + sizeof(CHAR);
913
914 pDomainControllerInfoA->DnsForestName = Ptr;
915 RtlInitUnicodeString(&UnicodeString,
916 pDomainControllerInfoW->DnsForestName);
917 AnsiString.Length = 0;
918 AnsiString.MaximumLength = BufferSize;
919 AnsiString.Buffer = Ptr;
920
921 Status = RtlUnicodeStringToAnsiString(&AnsiString,
922 &UnicodeString,
923 FALSE);
924 if (!NT_SUCCESS(Status))
925 {
926 status = RtlNtStatusToDosError(Status);
927 goto done;
928 }
929
930 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
931 BufferSize -= AnsiString.Length + sizeof(CHAR);
932
933 if (pDomainControllerInfoW->DcSiteName != NULL)
934 {
935 pDomainControllerInfoA->DcSiteName = Ptr;
936 RtlInitUnicodeString(&UnicodeString,
937 pDomainControllerInfoW->DcSiteName);
938 AnsiString.Length = 0;
939 AnsiString.MaximumLength = BufferSize;
940 AnsiString.Buffer = Ptr;
941
942 Status = RtlUnicodeStringToAnsiString(&AnsiString,
943 &UnicodeString,
944 FALSE);
945 if (!NT_SUCCESS(Status))
946 {
947 status = RtlNtStatusToDosError(Status);
948 goto done;
949 }
950
951 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
952 BufferSize -= AnsiString.Length + sizeof(CHAR);
953 }
954
955 if (pDomainControllerInfoW->ClientSiteName != NULL)
956 {
957 pDomainControllerInfoA->ClientSiteName = Ptr;
958 RtlInitUnicodeString(&UnicodeString,
959 pDomainControllerInfoW->ClientSiteName);
960 AnsiString.Length = 0;
961 AnsiString.MaximumLength = BufferSize;
962 AnsiString.Buffer = Ptr;
963
964 Status = RtlUnicodeStringToAnsiString(&AnsiString,
965 &UnicodeString,
966 FALSE);
967 if (!NT_SUCCESS(Status))
968 {
969 status = RtlNtStatusToDosError(Status);
970 goto done;
971 }
972 }
973
974 *DomainControllerInfo = pDomainControllerInfoA;
975 pDomainControllerInfoA = NULL;
976
977 done:
978 if (pDomainControllerInfoA != NULL)
979 NetApiBufferFree(pDomainControllerInfoA);
980
981 if (pDomainControllerInfoW != NULL)
982 NetApiBufferFree(pDomainControllerInfoW);
983
984 if (pSiteNameW != NULL)
985 NetApiBufferFree(pSiteNameW);
986
987 if (pDomainNameW != NULL)
988 NetApiBufferFree(pDomainNameW);
989
990 if (pAccountNameW != NULL)
991 NetApiBufferFree(pAccountNameW);
992
993 if (pComputerNameW != NULL)
994 NetApiBufferFree(pComputerNameW);
995
996 return status;
997 }
998
999
1000 DWORD
1001 WINAPI
1002 DsGetDcNameWithAccountW(
1003 _In_opt_ LPCWSTR ComputerName,
1004 _In_opt_ LPCWSTR AccountName,
1005 _In_ ULONG AccountControlBits,
1006 _In_ LPCWSTR DomainName,
1007 _In_ GUID *DomainGuid,
1008 _In_ LPCWSTR SiteName,
1009 _In_ ULONG Flags,
1010 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
1011 {
1012 NET_API_STATUS status;
1013
1014 TRACE("DsGetDcNameWithAccountW(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
1015 debugstr_w(ComputerName), debugstr_w(AccountName), AccountControlBits,
1016 debugstr_w(DomainName), debugstr_guid(DomainGuid),
1017 debugstr_w(SiteName), Flags, DomainControllerInfo);
1018
1019 RpcTryExcept
1020 {
1021 status = DsrGetDcNameEx2((PWSTR)ComputerName,
1022 (PWSTR)AccountName,
1023 AccountControlBits,
1024 (PWSTR)DomainName,
1025 DomainGuid,
1026 (PWSTR)SiteName,
1027 Flags,
1028 DomainControllerInfo);
1029 }
1030 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1031 {
1032 status = I_RpcMapWin32Status(RpcExceptionCode());
1033 }
1034 RpcEndExcept;
1035
1036 return status;
1037 }
1038
1039
1040 DWORD
1041 WINAPI
1042 DsGetDcSiteCoverageA(
1043 _In_opt_ LPCSTR ServerName,
1044 _Out_ PULONG EntryCount,
1045 _Out_ LPSTR **SiteNames)
1046 {
1047 PWSTR pServerNameW = NULL;
1048 PWSTR *pSiteNamesW = NULL;
1049 PSTR *pSiteNamesA = NULL;
1050 UNICODE_STRING UnicodeString;
1051 ANSI_STRING AnsiString;
1052 PSTR Ptr;
1053 ULONG BufferSize, i;
1054 NTSTATUS Status;
1055 NET_API_STATUS status = NERR_Success;
1056
1057 TRACE("DsGetDcSiteCoverageA(%s, %p, %p)\n",
1058 debugstr_a(ServerName), EntryCount, SiteNames);
1059
1060 if (ServerName != NULL)
1061 {
1062 pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
1063 if (pServerNameW == NULL)
1064 {
1065 status = ERROR_NOT_ENOUGH_MEMORY;
1066 goto done;
1067 }
1068 }
1069
1070 status = DsGetDcSiteCoverageW(pServerNameW,
1071 EntryCount,
1072 &pSiteNamesW);
1073 if (status != ERROR_SUCCESS)
1074 goto done;
1075
1076 BufferSize = *EntryCount * sizeof(PSTR);
1077 for (i = 0; i < *EntryCount; i++)
1078 {
1079 RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
1080 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
1081 }
1082
1083 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
1084 if (status != NERR_Success)
1085 goto done;
1086
1087 ZeroMemory(pSiteNamesA, BufferSize);
1088
1089 Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + *EntryCount * sizeof(PSTR));
1090 for (i = 0; i < *EntryCount; i++)
1091 {
1092 pSiteNamesA[i] = Ptr;
1093
1094 RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
1095
1096 AnsiString.Length = 0;
1097 AnsiString.MaximumLength = BufferSize;
1098 AnsiString.Buffer = Ptr;
1099
1100 Status = RtlUnicodeStringToAnsiString(&AnsiString,
1101 &UnicodeString,
1102 FALSE);
1103 if (!NT_SUCCESS(Status))
1104 {
1105 status = RtlNtStatusToDosError(Status);
1106 goto done;
1107 }
1108
1109 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
1110 BufferSize -= (AnsiString.Length + sizeof(CHAR));
1111 }
1112
1113 *SiteNames = pSiteNamesA;
1114 pSiteNamesA = NULL;
1115
1116 done:
1117 if (status != NERR_Success && pSiteNamesA != NULL)
1118 NetApiBufferFree(pSiteNamesA);
1119
1120 if (pSiteNamesW != NULL)
1121 NetApiBufferFree(pSiteNamesW);
1122
1123 if (pServerNameW != NULL)
1124 NetApiBufferFree(pServerNameW);
1125
1126 return status;
1127 }
1128
1129
1130 DWORD
1131 WINAPI
1132 DsGetDcSiteCoverageW(
1133 _In_opt_ LPCWSTR ServerName,
1134 _Out_ PULONG EntryCount,
1135 _Out_ LPWSTR **SiteNames)
1136 {
1137 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
1138 PWSTR *SiteNamesBuffer = NULL, Ptr;
1139 ULONG BufferSize, i;
1140 NET_API_STATUS status;
1141
1142 TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
1143 debugstr_w(ServerName), EntryCount, SiteNames);
1144
1145 *EntryCount = 0;
1146 *SiteNames = NULL;
1147
1148 RpcTryExcept
1149 {
1150 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
1151 &SiteNameArray);
1152 if (status == NERR_Success)
1153 {
1154 if (SiteNameArray->EntryCount == 0)
1155 {
1156 status = ERROR_INVALID_PARAMETER;
1157 }
1158 else
1159 {
1160 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
1161 for (i = 0; i < SiteNameArray->EntryCount; i++)
1162 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
1163
1164 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
1165 if (status == NERR_Success)
1166 {
1167 ZeroMemory(SiteNamesBuffer, BufferSize);
1168
1169 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
1170 for (i = 0; i < SiteNameArray->EntryCount; i++)
1171 {
1172 SiteNamesBuffer[i] = Ptr;
1173 CopyMemory(Ptr,
1174 SiteNameArray->SiteNames[i].Buffer,
1175 SiteNameArray->SiteNames[i].Length);
1176
1177 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
1178 }
1179
1180 *EntryCount = SiteNameArray->EntryCount;
1181 *SiteNames = SiteNamesBuffer;
1182 }
1183 }
1184
1185 MIDL_user_free(SiteNameArray);
1186 }
1187 }
1188 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1189 {
1190 status = I_RpcMapWin32Status(RpcExceptionCode());
1191 }
1192 RpcEndExcept;
1193
1194 return status;
1195 }
1196
1197
1198 DWORD
1199 WINAPI
1200 DsGetForestTrustInformationW(
1201 _In_opt_ LPCWSTR ServerName,
1202 _In_opt_ LPCWSTR TrustedDomainName,
1203 _In_ DWORD Flags,
1204 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
1205 {
1206 NET_API_STATUS status;
1207
1208 TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
1209 debugstr_w(ServerName), debugstr_w(TrustedDomainName),
1210 Flags, ForestTrustInfo);
1211
1212 RpcTryExcept
1213 {
1214 status = DsrGetForestTrustInformation((PWSTR)ServerName,
1215 (PWSTR)TrustedDomainName,
1216 Flags,
1217 ForestTrustInfo);
1218 }
1219 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1220 {
1221 status = I_RpcMapWin32Status(RpcExceptionCode());
1222 }
1223 RpcEndExcept;
1224
1225 return status;
1226 }
1227
1228
1229 DWORD
1230 WINAPI
1231 DsGetSiteNameA(
1232 _In_opt_ LPCSTR ComputerName,
1233 _Out_ LPSTR *SiteName)
1234 {
1235 PWSTR pComputerNameW = NULL;
1236 PWSTR pSiteNameW = NULL;
1237 NET_API_STATUS status = ERROR_SUCCESS;
1238
1239 TRACE("DsGetSiteNameA(%s, %p)\n",
1240 debugstr_a(ComputerName), SiteName);
1241
1242 if (ComputerName != NULL)
1243 {
1244 pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
1245 if (pComputerNameW == NULL)
1246 {
1247 status = ERROR_NOT_ENOUGH_MEMORY;
1248 goto done;
1249 }
1250 }
1251
1252 status = DsGetSiteNameW(pComputerNameW,
1253 &pSiteNameW);
1254 if (status != ERROR_SUCCESS)
1255 goto done;
1256
1257 *SiteName = NetpAllocAnsiStrFromWStr(pSiteNameW);
1258 if (*SiteName == NULL)
1259 {
1260 status = ERROR_NOT_ENOUGH_MEMORY;
1261 }
1262
1263 done:
1264 if (pSiteNameW != NULL)
1265 NetApiBufferFree(pSiteNameW);
1266
1267 if (pComputerNameW != NULL)
1268 NetApiBufferFree(pComputerNameW);
1269
1270 return status;
1271 }
1272
1273
1274 DWORD
1275 WINAPI
1276 DsGetSiteNameW(
1277 _In_opt_ LPCWSTR ComputerName,
1278 _Out_ LPWSTR *SiteName)
1279 {
1280 NET_API_STATUS status;
1281
1282 TRACE("DsGetSiteNameW(%s, %p)\n",
1283 debugstr_w(ComputerName), SiteName);
1284
1285 RpcTryExcept
1286 {
1287 status = DsrGetSiteName((PWSTR)ComputerName,
1288 SiteName);
1289 }
1290 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1291 {
1292 status = I_RpcMapWin32Status(RpcExceptionCode());
1293 }
1294 RpcEndExcept;
1295
1296 return status;
1297 }
1298
1299
1300 DWORD
1301 WINAPI
1302 DsMergeForestTrustInformationW(
1303 _In_ LPCWSTR DomainName,
1304 _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
1305 _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
1306 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
1307 {
1308 FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
1309 debugstr_w(DomainName), NewForestTrustInfo,
1310 OldForestTrustInfo, ForestTrustInfo);
1311 return ERROR_CALL_NOT_IMPLEMENTED;
1312 }
1313
1314
1315 DWORD
1316 WINAPI
1317 DsValidateSubnetNameA(
1318 _In_ LPCSTR SubnetName)
1319 {
1320 FIXME("DsValidateSubnetNameA(%s)\n",
1321 debugstr_a(SubnetName));
1322 return ERROR_CALL_NOT_IMPLEMENTED;
1323 }
1324
1325
1326 DWORD
1327 WINAPI
1328 DsValidateSubnetNameW(
1329 _In_ LPCWSTR SubnetName)
1330 {
1331 FIXME("DsValidateSubnetNameW(%s)\n",
1332 debugstr_w(SubnetName));
1333 return ERROR_CALL_NOT_IMPLEMENTED;
1334 }
1335
1336
1337 NTSTATUS
1338 WINAPI
1339 NetEnumerateTrustedDomains(
1340 _In_ LPWSTR ServerName,
1341 _Out_ LPWSTR *DomainNames)
1342 {
1343 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
1344 NTSTATUS Status = 0;
1345
1346 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
1347 debugstr_w(ServerName), DomainNames);
1348
1349 RpcTryExcept
1350 {
1351 Status = NetrEnumerateTrustedDomains(ServerName,
1352 &DomainNameBuffer);
1353 if (NT_SUCCESS(Status))
1354 {
1355 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
1356 }
1357 }
1358 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1359 {
1360 Status = I_RpcMapWin32Status(RpcExceptionCode());
1361 } RpcEndExcept;
1362
1363 return Status;
1364 }
1365
1366
1367 NET_API_STATUS
1368 WINAPI
1369 NetGetAnyDCName(
1370 _In_opt_ LPCWSTR ServerName,
1371 _In_opt_ LPCWSTR DomainName,
1372 _Out_ LPBYTE *BufPtr)
1373 {
1374 NET_API_STATUS Status;
1375
1376 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
1377 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
1378
1379 *BufPtr = NULL;
1380
1381 RpcTryExcept
1382 {
1383 Status = NetrGetAnyDCName((PWSTR)ServerName,
1384 (PWSTR)DomainName,
1385 (PWSTR*)BufPtr);
1386 }
1387 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1388 {
1389 Status = I_RpcMapWin32Status(RpcExceptionCode());
1390 }
1391 RpcEndExcept;
1392
1393 return Status;
1394 }
1395
1396
1397 NET_API_STATUS
1398 WINAPI
1399 NetGetDCName(
1400 _In_opt_ LPCWSTR ServerName,
1401 _In_opt_ LPCWSTR DomainName,
1402 _Out_ LPBYTE *BufPtr)
1403 {
1404 PDOMAIN_CONTROLLER_INFOW pDomainControllerInfo = NULL;
1405 NET_API_STATUS Status;
1406
1407 FIXME("NetGetDCName(%s, %s, %p)\n",
1408 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
1409
1410 if (ServerName == NULL || *ServerName == UNICODE_NULL)
1411 {
1412 Status = DsGetDcNameWithAccountW(NULL,
1413 NULL,
1414 0,
1415 DomainName,
1416 NULL,
1417 NULL,
1418 0, //???
1419 &pDomainControllerInfo);
1420 if (Status != NERR_Success)
1421 goto done;
1422
1423 Status = NetApiBufferAllocate((wcslen(pDomainControllerInfo->DomainControllerName) + 1) * sizeof(WCHAR),
1424 (PVOID*)BufPtr);
1425 if (Status != NERR_Success)
1426 goto done;
1427
1428 wcscpy((PWSTR)*BufPtr,
1429 pDomainControllerInfo->DomainControllerName);
1430 }
1431 else
1432 {
1433 FIXME("Not implemented yet!\n");
1434 Status = NERR_DCNotFound;
1435 }
1436
1437 done:
1438 if (pDomainControllerInfo != NULL)
1439 NetApiBufferFree(pDomainControllerInfo);
1440
1441 return Status;
1442 }
1443
1444
1445 NET_API_STATUS
1446 WINAPI
1447 NetLogonGetTimeServiceParentDomain(
1448 _In_ LPWSTR ServerName,
1449 _Out_ LPWSTR *DomainName,
1450 _Out_ LPBOOL PdcSameSite)
1451 {
1452 NET_API_STATUS Status;
1453
1454 TRACE("NetLogonGetTimeServiceParentDomain(%s, %p, %p)\n",
1455 debugstr_w(ServerName), DomainName, PdcSameSite);
1456
1457 RpcTryExcept
1458 {
1459 Status = NetrLogonGetTimeServiceParentDomain(ServerName,
1460 DomainName,
1461 PdcSameSite);
1462 }
1463 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1464 {
1465 Status = I_RpcMapWin32Status(RpcExceptionCode());
1466 }
1467 RpcEndExcept;
1468
1469 return Status;
1470 }
1471
1472
1473 NTSTATUS
1474 WINAPI
1475 NetLogonSetServiceBits(
1476 _In_ LPWSTR ServerName,
1477 _In_ DWORD ServiceBitsOfInterest,
1478 _In_ DWORD ServiceBits)
1479 {
1480 NTSTATUS Status;
1481
1482 TRACE("NetLogonSetServiceBits(%s 0x%lx 0x%lx)\n",
1483 debugstr_w(ServerName), ServiceBitsOfInterest, ServiceBits);
1484
1485 RpcTryExcept
1486 {
1487 Status = NetrLogonSetServiceBits(ServerName,
1488 ServiceBitsOfInterest,
1489 ServiceBits);
1490 }
1491 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1492 {
1493 Status = RpcExceptionCode();
1494 }
1495 RpcEndExcept;
1496
1497 return Status;
1498 }
1499
1500 /* EOF */