[NETAPI32] Implement DsGetDcSiteCoverageA
[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 FIXME("DsAddressToSiteNamesA(%s, %lu, %p, %p)\n",
116 debugstr_a(ComputerName), EntryCount, SocketAddresses, SiteNames);
117 return ERROR_CALL_NOT_IMPLEMENTED;
118 }
119
120
121 DWORD
122 WINAPI
123 DsAddressToSiteNamesW(
124 _In_opt_ LPCWSTR ComputerName,
125 _In_ DWORD EntryCount,
126 _In_ PSOCKET_ADDRESS SocketAddresses,
127 _Out_ LPWSTR **SiteNames)
128 {
129 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
130 PWSTR *SiteNamesBuffer = NULL, Ptr;
131 ULONG BufferSize, i;
132 NET_API_STATUS status;
133
134 TRACE("DsAddressToSiteNamesW(%s, %lu, %p, %p)\n",
135 debugstr_w(ComputerName), EntryCount, SocketAddresses, SiteNames);
136
137 if (EntryCount == 0)
138 return ERROR_INVALID_PARAMETER;
139
140 *SiteNames = NULL;
141
142 RpcTryExcept
143 {
144 status = DsrAddressToSiteNamesW((PWSTR)ComputerName,
145 EntryCount,
146 (PNL_SOCKET_ADDRESS)SocketAddresses,
147 &SiteNameArray);
148 if (status == NERR_Success)
149 {
150 if (SiteNameArray->EntryCount == 0)
151 {
152 status = ERROR_INVALID_PARAMETER;
153 }
154 else
155 {
156 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
157 for (i = 0; i < SiteNameArray->EntryCount; i++)
158 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
159
160 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
161 if (status == NERR_Success)
162 {
163 ZeroMemory(SiteNamesBuffer, BufferSize);
164
165 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
166 for (i = 0; i < SiteNameArray->EntryCount; i++)
167 {
168 SiteNamesBuffer[i] = Ptr;
169 CopyMemory(Ptr,
170 SiteNameArray->SiteNames[i].Buffer,
171 SiteNameArray->SiteNames[i].Length);
172
173 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
174 }
175
176 *SiteNames = SiteNamesBuffer;
177 }
178 }
179
180 MIDL_user_free(SiteNameArray);
181 }
182 }
183 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
184 {
185 status = I_RpcMapWin32Status(RpcExceptionCode());
186 }
187 RpcEndExcept;
188
189 return status;
190 }
191
192
193 DWORD
194 WINAPI
195 DsAddressToSiteNamesExA(
196 _In_opt_ LPCSTR ComputerName,
197 _In_ DWORD EntryCount,
198 _In_ PSOCKET_ADDRESS SocketAddresses,
199 _Out_ LPSTR **SiteNames,
200 _Out_ LPSTR **SubnetNames)
201 {
202 FIXME("DsAddressToSiteNamesExA(%s, %lu, %p, %p, %p)\n",
203 debugstr_a(ComputerName), EntryCount, SocketAddresses,
204 SiteNames, SubnetNames);
205 return ERROR_CALL_NOT_IMPLEMENTED;
206 }
207
208
209 DWORD
210 WINAPI
211 DsAddressToSiteNamesExW(
212 _In_opt_ LPCWSTR ComputerName,
213 _In_ DWORD EntryCount,
214 _In_ PSOCKET_ADDRESS SocketAddresses,
215 _Out_ LPWSTR **SiteNames,
216 _Out_ LPWSTR **SubnetNames)
217 {
218 PNL_SITE_NAME_EX_ARRAY SiteNameArray = NULL;
219 PWSTR *SiteNamesBuffer = NULL, *SubnetNamesBuffer = NULL, Ptr;
220 ULONG SiteNameBufferSize, SubnetNameBufferSize, i;
221 NET_API_STATUS status;
222
223 TRACE("DsAddressToSiteNamesExW(%s, %lu, %p, %p, %p)\n",
224 debugstr_w(ComputerName), EntryCount, SocketAddresses,
225 SiteNames, SubnetNames);
226
227 if (EntryCount == 0)
228 return ERROR_INVALID_PARAMETER;
229
230 *SiteNames = NULL;
231 *SubnetNames = NULL;
232
233 RpcTryExcept
234 {
235 status = DsrAddressToSiteNamesExW((PWSTR)ComputerName,
236 EntryCount,
237 (PNL_SOCKET_ADDRESS)SocketAddresses,
238 &SiteNameArray);
239 if (status == NERR_Success)
240 {
241 if (SiteNameArray->EntryCount == 0)
242 {
243 status = ERROR_INVALID_PARAMETER;
244 }
245 else
246 {
247 SiteNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
248 SubnetNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
249 for (i = 0; i < SiteNameArray->EntryCount; i++)
250 {
251 SiteNameBufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
252 SubnetNameBufferSize += SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR);
253 }
254
255 status = NetApiBufferAllocate(SiteNameBufferSize, (PVOID*)&SiteNamesBuffer);
256 if (status == NERR_Success)
257 {
258 ZeroMemory(SiteNamesBuffer, SiteNameBufferSize);
259
260 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
261 for (i = 0; i < SiteNameArray->EntryCount; i++)
262 {
263 SiteNamesBuffer[i] = Ptr;
264 CopyMemory(Ptr,
265 SiteNameArray->SiteNames[i].Buffer,
266 SiteNameArray->SiteNames[i].Length);
267
268 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
269 }
270
271 *SiteNames = SiteNamesBuffer;
272 }
273
274 status = NetApiBufferAllocate(SubnetNameBufferSize, (PVOID*)&SubnetNamesBuffer);
275 if (status == NERR_Success)
276 {
277 ZeroMemory(SubnetNamesBuffer, SubnetNameBufferSize);
278
279 Ptr = (PWSTR)((ULONG_PTR)SubnetNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
280 for (i = 0; i < SiteNameArray->EntryCount; i++)
281 {
282 SubnetNamesBuffer[i] = Ptr;
283 CopyMemory(Ptr,
284 SiteNameArray->SubnetNames[i].Buffer,
285 SiteNameArray->SubnetNames[i].Length);
286
287 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR));
288 }
289
290 *SubnetNames = SubnetNamesBuffer;
291 }
292 }
293
294 MIDL_user_free(SiteNameArray);
295 }
296 }
297 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
298 {
299 status = I_RpcMapWin32Status(RpcExceptionCode());
300 }
301 RpcEndExcept;
302
303 return status;
304 }
305
306
307 DWORD
308 WINAPI
309 DsDeregisterDnsHostRecordsA(
310 _In_opt_ LPSTR ServerName,
311 _In_opt_ LPSTR DnsDomainName,
312 _In_opt_ GUID *DomainGuid,
313 _In_opt_ GUID *DsaGuid,
314 _In_ LPSTR DnsHostName)
315 {
316 FIXME("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
317 debugstr_a(ServerName), debugstr_a(DnsDomainName),
318 DomainGuid, DsaGuid, debugstr_a(DnsHostName));
319 return ERROR_CALL_NOT_IMPLEMENTED;
320 }
321
322
323 DWORD
324 WINAPI
325 DsDeregisterDnsHostRecordsW(
326 _In_opt_ LPWSTR ServerName,
327 _In_opt_ LPWSTR DnsDomainName,
328 _In_opt_ GUID *DomainGuid,
329 _In_opt_ GUID *DsaGuid,
330 _In_ LPWSTR DnsHostName)
331 {
332 NET_API_STATUS status;
333
334 TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
335 debugstr_w(ServerName), debugstr_w(DnsDomainName),
336 DomainGuid, DsaGuid, debugstr_w(DnsHostName));
337
338 RpcTryExcept
339 {
340 status = DsrDeregisterDnsHostRecords(ServerName,
341 DnsDomainName,
342 DomainGuid,
343 DsaGuid,
344 DnsHostName);
345 }
346 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
347 {
348 status = I_RpcMapWin32Status(RpcExceptionCode());
349 }
350 RpcEndExcept;
351
352 return status;
353 }
354
355
356 DWORD
357 WINAPI
358 DsEnumerateDomainTrustsA(
359 _In_opt_ LPSTR ServerName,
360 _In_ ULONG Flags,
361 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
362 _Out_ PULONG DomainCount)
363 {
364 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
365 debugstr_a(ServerName), Flags, Domains, DomainCount);
366 return ERROR_CALL_NOT_IMPLEMENTED;
367 }
368
369
370 DWORD
371 WINAPI
372 DsEnumerateDomainTrustsW(
373 _In_opt_ LPWSTR ServerName,
374 _In_ ULONG Flags,
375 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
376 _Out_ PULONG DomainCount)
377 {
378 FIXME("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
379 debugstr_w(ServerName), Flags, Domains, DomainCount);
380 return ERROR_CALL_NOT_IMPLEMENTED;
381 }
382
383
384 DWORD
385 WINAPI
386 DsGetDcNameA(
387 _In_opt_ LPCSTR ComputerName,
388 _In_ LPCSTR DomainName,
389 _In_ GUID *DomainGuid,
390 _In_ LPCSTR SiteName,
391 _In_ ULONG Flags,
392 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
393 {
394 TRACE("DsGetDcNameA(%s, %s, %s, %s, %08lx, %p): stub\n",
395 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
396 debugstr_a(SiteName), Flags, DomainControllerInfo);
397 return DsGetDcNameWithAccountA(ComputerName,
398 NULL,
399 0,
400 DomainName,
401 DomainGuid,
402 SiteName,
403 Flags,
404 DomainControllerInfo);
405 }
406
407
408 DWORD
409 WINAPI
410 DsGetDcNameW(
411 _In_opt_ LPCWSTR ComputerName,
412 _In_ LPCWSTR DomainName,
413 _In_ GUID *DomainGuid,
414 _In_ LPCWSTR SiteName,
415 _In_ ULONG Flags,
416 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
417 {
418 TRACE("DsGetDcNameW(%s, %s, %s, %s, %08lx, %p)\n",
419 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
420 debugstr_w(SiteName), Flags, DomainControllerInfo);
421 return DsGetDcNameWithAccountW(ComputerName,
422 NULL,
423 0,
424 DomainName,
425 DomainGuid,
426 SiteName,
427 Flags,
428 DomainControllerInfo);
429 }
430
431
432 DWORD
433 WINAPI
434 DsGetDcNameWithAccountA(
435 _In_opt_ LPCSTR ComputerName,
436 _In_opt_ LPCSTR AccountName,
437 _In_ ULONG AccountControlBits,
438 _In_ LPCSTR DomainName,
439 _In_ GUID *DomainGuid,
440 _In_ LPCSTR SiteName,
441 _In_ ULONG Flags,
442 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
443 {
444 FIXME("DsGetDcNameWithAccountA(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
445 debugstr_a(ComputerName), debugstr_a(AccountName), AccountControlBits,
446 debugstr_a(DomainName), debugstr_guid(DomainGuid),
447 debugstr_a(SiteName), Flags, DomainControllerInfo);
448 return ERROR_CALL_NOT_IMPLEMENTED;
449 }
450
451
452 DWORD
453 WINAPI
454 DsGetDcNameWithAccountW(
455 _In_opt_ LPCWSTR ComputerName,
456 _In_opt_ LPCWSTR AccountName,
457 _In_ ULONG AccountControlBits,
458 _In_ LPCWSTR DomainName,
459 _In_ GUID *DomainGuid,
460 _In_ LPCWSTR SiteName,
461 _In_ ULONG Flags,
462 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
463 {
464 NET_API_STATUS status;
465
466 FIXME("DsGetDcNameWithAccountW(%s, %s, %08lx, %s, %s, %s, %08lx, %p): stub\n",
467 debugstr_w(ComputerName), debugstr_w(AccountName), AccountControlBits,
468 debugstr_w(DomainName), debugstr_guid(DomainGuid),
469 debugstr_w(SiteName), Flags, DomainControllerInfo);
470
471 RpcTryExcept
472 {
473 status = DsrGetDcNameEx2((PWSTR)ComputerName,
474 (PWSTR)AccountName,
475 AccountControlBits,
476 (PWSTR)DomainName,
477 DomainGuid,
478 (PWSTR)SiteName,
479 Flags,
480 DomainControllerInfo);
481 }
482 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
483 {
484 status = I_RpcMapWin32Status(RpcExceptionCode());
485 }
486 RpcEndExcept;
487
488 return status;
489 }
490
491
492 DWORD
493 WINAPI
494 DsGetDcSiteCoverageA(
495 _In_opt_ LPCSTR ServerName,
496 _Out_ PULONG EntryCount,
497 _Out_ LPSTR **SiteNames)
498 {
499 PWSTR pServerNameW = NULL;
500 PWSTR *pSiteNamesW = NULL;
501 PSTR *pSiteNamesA = NULL;
502 UNICODE_STRING UnicodeString;
503 ANSI_STRING AnsiString;
504 PSTR Ptr;
505 ULONG BufferSize, i;
506 NTSTATUS Status;
507 NET_API_STATUS status = ERROR_SUCCESS;
508
509 TRACE("DsGetDcSiteCoverageA(%s, %p, %p)\n",
510 debugstr_a(ServerName), EntryCount, SiteNames);
511
512 if (ServerName != NULL)
513 {
514 pServerNameW = NetpAllocWStrFromAnsiStr((PSTR)ServerName);
515 if (pServerNameW == NULL)
516 {
517 status = ERROR_NOT_ENOUGH_MEMORY;
518 goto done;
519 }
520 }
521
522 status = DsGetDcSiteCoverageW(pServerNameW,
523 EntryCount,
524 &pSiteNamesW);
525 if (status != ERROR_SUCCESS)
526 goto done;
527
528 BufferSize = *EntryCount * sizeof(PSTR);
529 for (i = 0; i < *EntryCount; i++)
530 {
531 RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
532 BufferSize += RtlUnicodeStringToAnsiSize(&UnicodeString);
533 }
534
535 status = NetApiBufferAllocate(BufferSize, (PVOID*)&pSiteNamesA);
536 if (status != NERR_Success)
537 goto done;
538
539 ZeroMemory(pSiteNamesA, BufferSize);
540
541 Ptr = (PSTR)((ULONG_PTR)pSiteNamesA + *EntryCount * sizeof(PSTR));
542 for (i = 0; i < *EntryCount; i++)
543 {
544 pSiteNamesA[i] = Ptr;
545
546 RtlInitUnicodeString(&UnicodeString, pSiteNamesW[i]);
547
548 AnsiString.Length = 0;
549 AnsiString.MaximumLength = BufferSize;
550 AnsiString.Buffer = Ptr;
551
552 Status = RtlUnicodeStringToAnsiString(&AnsiString,
553 &UnicodeString,
554 FALSE);
555 if (!NT_SUCCESS(Status))
556 {
557 status = RtlNtStatusToDosError(Status);
558 goto done;
559 }
560
561 Ptr = (PSTR)((ULONG_PTR)Ptr + AnsiString.Length + sizeof(CHAR));
562 BufferSize -= (AnsiString.Length + sizeof(CHAR));
563 }
564
565 *SiteNames = pSiteNamesA;
566 pSiteNamesA = NULL;
567
568 done:
569 if (status != NERR_Success && pSiteNamesA != NULL)
570 NetApiBufferFree(pSiteNamesA);
571
572 if (pSiteNamesW != NULL)
573 NetApiBufferFree(pSiteNamesW);
574
575 if (pServerNameW != NULL)
576 NetApiBufferFree(pServerNameW);
577
578 return status;
579 }
580
581
582 DWORD
583 WINAPI
584 DsGetDcSiteCoverageW(
585 _In_opt_ LPCWSTR ServerName,
586 _Out_ PULONG EntryCount,
587 _Out_ LPWSTR **SiteNames)
588 {
589 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
590 PWSTR *SiteNamesBuffer = NULL, Ptr;
591 ULONG BufferSize, i;
592 NET_API_STATUS status;
593
594 TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
595 debugstr_w(ServerName), EntryCount, SiteNames);
596
597 *EntryCount = 0;
598 *SiteNames = NULL;
599
600 RpcTryExcept
601 {
602 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
603 &SiteNameArray);
604 if (status == NERR_Success)
605 {
606 if (SiteNameArray->EntryCount == 0)
607 {
608 status = ERROR_INVALID_PARAMETER;
609 }
610 else
611 {
612 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
613 for (i = 0; i < SiteNameArray->EntryCount; i++)
614 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
615
616 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
617 if (status == NERR_Success)
618 {
619 ZeroMemory(SiteNamesBuffer, BufferSize);
620
621 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
622 for (i = 0; i < SiteNameArray->EntryCount; i++)
623 {
624 SiteNamesBuffer[i] = Ptr;
625 CopyMemory(Ptr,
626 SiteNameArray->SiteNames[i].Buffer,
627 SiteNameArray->SiteNames[i].Length);
628
629 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
630 }
631
632 *EntryCount = SiteNameArray->EntryCount;
633 *SiteNames = SiteNamesBuffer;
634 }
635 }
636
637 MIDL_user_free(SiteNameArray);
638 }
639 }
640 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
641 {
642 status = I_RpcMapWin32Status(RpcExceptionCode());
643 }
644 RpcEndExcept;
645
646 return status;
647 }
648
649
650 DWORD
651 WINAPI
652 DsGetForestTrustInformationW(
653 _In_opt_ LPCWSTR ServerName,
654 _In_opt_ LPCWSTR TrustedDomainName,
655 _In_ DWORD Flags,
656 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
657 {
658 NET_API_STATUS status;
659
660 TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
661 debugstr_w(ServerName), debugstr_w(TrustedDomainName),
662 Flags, ForestTrustInfo);
663
664 RpcTryExcept
665 {
666 status = DsrGetForestTrustInformation((PWSTR)ServerName,
667 (PWSTR)TrustedDomainName,
668 Flags,
669 ForestTrustInfo);
670 }
671 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
672 {
673 status = I_RpcMapWin32Status(RpcExceptionCode());
674 }
675 RpcEndExcept;
676
677 return status;
678 }
679
680
681 DWORD
682 WINAPI
683 DsGetSiteNameA(
684 _In_opt_ LPCSTR ComputerName,
685 _Out_ LPSTR *SiteName)
686 {
687 PWSTR pComputerNameW = NULL;
688 PWSTR pSiteNameW = NULL;
689 NET_API_STATUS status = ERROR_SUCCESS;
690
691 TRACE("DsGetSiteNameA(%s, %p)\n",
692 debugstr_a(ComputerName), SiteName);
693
694 if (ComputerName != NULL)
695 {
696 pComputerNameW = NetpAllocWStrFromAnsiStr((PSTR)ComputerName);
697 if (pComputerNameW == NULL)
698 {
699 status = ERROR_NOT_ENOUGH_MEMORY;
700 goto done;
701 }
702 }
703
704 status = DsGetSiteNameW(pComputerNameW,
705 &pSiteNameW);
706 if (status != ERROR_SUCCESS)
707 goto done;
708
709 *SiteName = NetpAllocAnsiStrFromWStr(pSiteNameW);
710 if (*SiteName == NULL)
711 {
712 status = ERROR_NOT_ENOUGH_MEMORY;
713 }
714
715 done:
716 if (pSiteNameW != NULL)
717 NetApiBufferFree(pSiteNameW);
718
719 if (pComputerNameW != NULL)
720 NetApiBufferFree(pComputerNameW);
721
722 return status;
723 }
724
725
726 DWORD
727 WINAPI
728 DsGetSiteNameW(
729 _In_opt_ LPCWSTR ComputerName,
730 _Out_ LPWSTR *SiteName)
731 {
732 NET_API_STATUS status;
733
734 TRACE("DsGetSiteNameW(%s, %p)\n",
735 debugstr_w(ComputerName), SiteName);
736
737 RpcTryExcept
738 {
739 status = DsrGetSiteName((PWSTR)ComputerName,
740 SiteName);
741 }
742 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
743 {
744 status = I_RpcMapWin32Status(RpcExceptionCode());
745 }
746 RpcEndExcept;
747
748 return status;
749 }
750
751
752 DWORD
753 WINAPI
754 DsMergeForestTrustInformationW(
755 _In_ LPCWSTR DomainName,
756 _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
757 _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
758 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
759 {
760 FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
761 debugstr_w(DomainName), NewForestTrustInfo,
762 OldForestTrustInfo, ForestTrustInfo);
763 return ERROR_CALL_NOT_IMPLEMENTED;
764 }
765
766
767 DWORD
768 WINAPI
769 DsValidateSubnetNameA(
770 _In_ LPCSTR SubnetName)
771 {
772 FIXME("DsValidateSubnetNameA(%s)\n",
773 debugstr_a(SubnetName));
774 return ERROR_CALL_NOT_IMPLEMENTED;
775 }
776
777
778 DWORD
779 WINAPI
780 DsValidateSubnetNameW(
781 _In_ LPCWSTR SubnetName)
782 {
783 FIXME("DsValidateSubnetNameW(%s)\n",
784 debugstr_w(SubnetName));
785 return ERROR_CALL_NOT_IMPLEMENTED;
786 }
787
788
789 NTSTATUS
790 WINAPI
791 NetEnumerateTrustedDomains(
792 _In_ LPWSTR ServerName,
793 _Out_ LPWSTR *DomainNames)
794 {
795 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
796 NTSTATUS Status = 0;
797
798 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
799 debugstr_w(ServerName), DomainNames);
800
801 RpcTryExcept
802 {
803 Status = NetrEnumerateTrustedDomains(ServerName,
804 &DomainNameBuffer);
805 if (NT_SUCCESS(Status))
806 {
807 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
808 }
809 }
810 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
811 {
812 Status = I_RpcMapWin32Status(RpcExceptionCode());
813 } RpcEndExcept;
814
815 return Status;
816 }
817
818
819 NET_API_STATUS
820 WINAPI
821 NetGetAnyDCName(
822 _In_opt_ LPCWSTR ServerName,
823 _In_opt_ LPCWSTR DomainName,
824 _Out_ LPBYTE *BufPtr)
825 {
826 NET_API_STATUS Status;
827
828 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
829 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
830
831 *BufPtr = NULL;
832
833 RpcTryExcept
834 {
835 Status = NetrGetAnyDCName((PWSTR)ServerName,
836 (PWSTR)DomainName,
837 (PWSTR*)BufPtr);
838 }
839 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
840 {
841 Status = I_RpcMapWin32Status(RpcExceptionCode());
842 }
843 RpcEndExcept;
844
845 return Status;
846 }
847
848
849 NET_API_STATUS
850 WINAPI
851 NetGetDCName(
852 _In_opt_ LPCWSTR ServerName,
853 _In_opt_ LPCWSTR DomainName,
854 _Out_ LPBYTE *BufPtr)
855 {
856 PDOMAIN_CONTROLLER_INFOW pDomainControllerInfo = NULL;
857 NET_API_STATUS Status;
858
859 FIXME("NetGetDCName(%s, %s, %p)\n",
860 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
861
862 if (ServerName == NULL || *ServerName == UNICODE_NULL)
863 {
864 Status = DsGetDcNameWithAccountW(NULL,
865 NULL,
866 0,
867 DomainName,
868 NULL,
869 NULL,
870 0, //???
871 &pDomainControllerInfo);
872 if (Status != NERR_Success)
873 goto done;
874
875 Status = NetApiBufferAllocate((wcslen(pDomainControllerInfo->DomainControllerName) + 1) * sizeof(WCHAR),
876 (PVOID*)BufPtr);
877 if (Status != NERR_Success)
878 goto done;
879
880 wcscpy((PWSTR)*BufPtr,
881 pDomainControllerInfo->DomainControllerName);
882 }
883 else
884 {
885 FIXME("Not implemented yet!\n");
886 Status = NERR_DCNotFound;
887 }
888
889 done:
890 if (pDomainControllerInfo != NULL)
891 NetApiBufferFree(pDomainControllerInfo);
892
893 return Status;
894 }
895
896
897 NET_API_STATUS
898 WINAPI
899 NetLogonGetTimeServiceParentDomain(
900 _In_ LPWSTR ServerName,
901 _Out_ LPWSTR *DomainName,
902 _Out_ LPBOOL PdcSameSite)
903 {
904 NET_API_STATUS Status;
905
906 TRACE("NetLogonGetTimeServiceParentDomain(%s, %p, %p)\n",
907 debugstr_w(ServerName), DomainName, PdcSameSite);
908
909 RpcTryExcept
910 {
911 Status = NetrLogonGetTimeServiceParentDomain(ServerName,
912 DomainName,
913 PdcSameSite);
914 }
915 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
916 {
917 Status = I_RpcMapWin32Status(RpcExceptionCode());
918 }
919 RpcEndExcept;
920
921 return Status;
922 }
923
924
925 NTSTATUS
926 WINAPI
927 NetLogonSetServiceBits(
928 _In_ LPWSTR ServerName,
929 _In_ DWORD ServiceBitsOfInterest,
930 _In_ DWORD ServiceBits)
931 {
932 NTSTATUS Status;
933
934 TRACE("NetLogonSetServiceBits(%s 0x%lx 0x%lx)\n",
935 debugstr_w(ServerName), ServiceBitsOfInterest, ServiceBits);
936
937 RpcTryExcept
938 {
939 Status = NetrLogonSetServiceBits(ServerName,
940 ServiceBitsOfInterest,
941 ServiceBits);
942 }
943 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
944 {
945 Status = RpcExceptionCode();
946 }
947 RpcEndExcept;
948
949 return Status;
950 }
951
952 /* EOF */