d9469ec874b31f75c5d9187cd1c3c145548a84b9
[reactos.git] / reactos / 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 /* FUNCTIONS *****************************************************************/
21
22 handle_t __RPC_USER
23 LOGONSRV_HANDLE_bind(LOGONSRV_HANDLE pszSystemName)
24 {
25 handle_t hBinding = NULL;
26 LPWSTR pszStringBinding;
27 RPC_STATUS status;
28
29 TRACE("LOGONSRV_HANDLE_bind() called\n");
30
31 status = RpcStringBindingComposeW(NULL,
32 L"ncacn_np",
33 pszSystemName,
34 L"\\pipe\\netlogon",
35 NULL,
36 &pszStringBinding);
37 if (status)
38 {
39 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
40 return NULL;
41 }
42
43 /* Set the binding handle that will be used to bind to the server. */
44 status = RpcBindingFromStringBindingW(pszStringBinding,
45 &hBinding);
46 if (status)
47 {
48 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
49 }
50
51 status = RpcStringFreeW(&pszStringBinding);
52 if (status)
53 {
54 // TRACE("RpcStringFree returned 0x%x\n", status);
55 }
56
57 return hBinding;
58 }
59
60
61 void __RPC_USER
62 LOGONSRV_HANDLE_unbind(LOGONSRV_HANDLE pszSystemName,
63 handle_t hBinding)
64 {
65 RPC_STATUS status;
66
67 TRACE("LOGONSRV_HANDLE_unbind() called\n");
68
69 status = RpcBindingFree(&hBinding);
70 if (status)
71 {
72 TRACE("RpcBindingFree returned 0x%x\n", status);
73 }
74 }
75
76
77 DWORD
78 WINAPI
79 DsAddressToSiteNamesA(
80 _In_opt_ LPCSTR ComputerName,
81 _In_ DWORD EntryCount,
82 _In_ PSOCKET_ADDRESS SocketAddresses,
83 _Out_ LPSTR **SiteNames)
84 {
85 FIXME("DsAddressToSiteNamesA(%s, %lu, %p, %p)\n",
86 debugstr_a(ComputerName), EntryCount, SocketAddresses, SiteNames);
87 return ERROR_CALL_NOT_IMPLEMENTED;
88 }
89
90
91 DWORD
92 WINAPI
93 DsAddressToSiteNamesW(
94 _In_opt_ LPCWSTR ComputerName,
95 _In_ DWORD EntryCount,
96 _In_ PSOCKET_ADDRESS SocketAddresses,
97 _Out_ LPWSTR **SiteNames)
98 {
99 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
100 PWSTR *SiteNamesBuffer = NULL, Ptr;
101 ULONG BufferSize, i;
102 NET_API_STATUS status;
103
104 TRACE("DsAddressToSiteNamesW(%s, %lu, %p, %p)\n",
105 debugstr_w(ComputerName), EntryCount, SocketAddresses, SiteNames);
106
107 if (EntryCount == 0)
108 return ERROR_INVALID_PARAMETER;
109
110 *SiteNames = NULL;
111
112 RpcTryExcept
113 {
114 status = DsrAddressToSiteNamesW((PWSTR)ComputerName,
115 EntryCount,
116 (PNL_SOCKET_ADDRESS)SocketAddresses,
117 &SiteNameArray);
118 if (status == NERR_Success)
119 {
120 if (SiteNameArray->EntryCount == 0)
121 {
122 status = ERROR_INVALID_PARAMETER;
123 }
124 else
125 {
126 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
127 for (i = 0; i < SiteNameArray->EntryCount; i++)
128 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
129
130 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
131 if (status == NERR_Success)
132 {
133 ZeroMemory(SiteNamesBuffer, BufferSize);
134
135 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
136 for (i = 0; i < SiteNameArray->EntryCount; i++)
137 {
138 SiteNamesBuffer[i] = Ptr;
139 CopyMemory(Ptr,
140 SiteNameArray->SiteNames[i].Buffer,
141 SiteNameArray->SiteNames[i].Length);
142
143 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
144 }
145
146 *SiteNames = SiteNamesBuffer;
147 }
148 }
149
150 MIDL_user_free(SiteNameArray);
151 }
152 }
153 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
154 {
155 status = I_RpcMapWin32Status(RpcExceptionCode());
156 }
157 RpcEndExcept;
158
159 return status;
160 }
161
162
163 DWORD
164 WINAPI
165 DsAddressToSiteNamesExA(
166 _In_opt_ LPCSTR ComputerName,
167 _In_ DWORD EntryCount,
168 _In_ PSOCKET_ADDRESS SocketAddresses,
169 _Out_ LPSTR **SiteNames,
170 _Out_ LPSTR **SubnetNames)
171 {
172 FIXME("DsAddressToSiteNamesExA(%s, %lu, %p, %p, %p)\n",
173 debugstr_a(ComputerName), EntryCount, SocketAddresses,
174 SiteNames, SubnetNames);
175 return ERROR_CALL_NOT_IMPLEMENTED;
176 }
177
178
179 DWORD
180 WINAPI
181 DsAddressToSiteNamesExW(
182 _In_opt_ LPCWSTR ComputerName,
183 _In_ DWORD EntryCount,
184 _In_ PSOCKET_ADDRESS SocketAddresses,
185 _Out_ LPWSTR **SiteNames,
186 _Out_ LPWSTR **SubnetNames)
187 {
188 PNL_SITE_NAME_EX_ARRAY SiteNameArray = NULL;
189 PWSTR *SiteNamesBuffer = NULL, *SubnetNamesBuffer = NULL, Ptr;
190 ULONG SiteNameBufferSize, SubnetNameBufferSize, i;
191 NET_API_STATUS status;
192
193 TRACE("DsAddressToSiteNamesExW(%s, %lu, %p, %p, %p)\n",
194 debugstr_w(ComputerName), EntryCount, SocketAddresses,
195 SiteNames, SubnetNames);
196
197 if (EntryCount == 0)
198 return ERROR_INVALID_PARAMETER;
199
200 *SiteNames = NULL;
201 *SubnetNames = NULL;
202
203 RpcTryExcept
204 {
205 status = DsrAddressToSiteNamesExW((PWSTR)ComputerName,
206 EntryCount,
207 (PNL_SOCKET_ADDRESS)SocketAddresses,
208 &SiteNameArray);
209 if (status == NERR_Success)
210 {
211 if (SiteNameArray->EntryCount == 0)
212 {
213 status = ERROR_INVALID_PARAMETER;
214 }
215 else
216 {
217 SiteNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
218 SubnetNameBufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
219 for (i = 0; i < SiteNameArray->EntryCount; i++)
220 {
221 SiteNameBufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
222 SubnetNameBufferSize += SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR);
223 }
224
225 status = NetApiBufferAllocate(SiteNameBufferSize, (PVOID*)&SiteNamesBuffer);
226 if (status == NERR_Success)
227 {
228 ZeroMemory(SiteNamesBuffer, SiteNameBufferSize);
229
230 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
231 for (i = 0; i < SiteNameArray->EntryCount; i++)
232 {
233 SiteNamesBuffer[i] = Ptr;
234 CopyMemory(Ptr,
235 SiteNameArray->SiteNames[i].Buffer,
236 SiteNameArray->SiteNames[i].Length);
237
238 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
239 }
240
241 *SiteNames = SiteNamesBuffer;
242 }
243
244 status = NetApiBufferAllocate(SubnetNameBufferSize, (PVOID*)&SubnetNamesBuffer);
245 if (status == NERR_Success)
246 {
247 ZeroMemory(SubnetNamesBuffer, SubnetNameBufferSize);
248
249 Ptr = (PWSTR)((ULONG_PTR)SubnetNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
250 for (i = 0; i < SiteNameArray->EntryCount; i++)
251 {
252 SubnetNamesBuffer[i] = Ptr;
253 CopyMemory(Ptr,
254 SiteNameArray->SubnetNames[i].Buffer,
255 SiteNameArray->SubnetNames[i].Length);
256
257 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SubnetNames[i].Length + sizeof(WCHAR));
258 }
259
260 *SubnetNames = SubnetNamesBuffer;
261 }
262 }
263
264 MIDL_user_free(SiteNameArray);
265 }
266 }
267 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
268 {
269 status = I_RpcMapWin32Status(RpcExceptionCode());
270 }
271 RpcEndExcept;
272
273 return status;
274 }
275
276
277 DWORD
278 WINAPI
279 DsDeregisterDnsHostRecordsA(
280 _In_opt_ LPSTR ServerName,
281 _In_opt_ LPSTR DnsDomainName,
282 _In_opt_ GUID *DomainGuid,
283 _In_opt_ GUID *DsaGuid,
284 _In_ LPSTR DnsHostName)
285 {
286 FIXME("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
287 debugstr_a(ServerName), debugstr_a(DnsDomainName),
288 DomainGuid, DsaGuid, debugstr_a(DnsHostName));
289 return ERROR_CALL_NOT_IMPLEMENTED;
290 }
291
292
293 DWORD
294 WINAPI
295 DsDeregisterDnsHostRecordsW(
296 _In_opt_ LPWSTR ServerName,
297 _In_opt_ LPWSTR DnsDomainName,
298 _In_opt_ GUID *DomainGuid,
299 _In_opt_ GUID *DsaGuid,
300 _In_ LPWSTR DnsHostName)
301 {
302 NET_API_STATUS status;
303
304 TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
305 debugstr_w(ServerName), debugstr_w(DnsDomainName),
306 DomainGuid, DsaGuid, debugstr_w(DnsHostName));
307
308 RpcTryExcept
309 {
310 status = DsrDeregisterDnsHostRecords(ServerName,
311 DnsDomainName,
312 DomainGuid,
313 DsaGuid,
314 DnsHostName);
315 }
316 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
317 {
318 status = I_RpcMapWin32Status(RpcExceptionCode());
319 }
320 RpcEndExcept;
321
322 return status;
323 }
324
325
326 DWORD
327 WINAPI
328 DsEnumerateDomainTrustsA(
329 _In_opt_ LPSTR ServerName,
330 _In_ ULONG Flags,
331 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
332 _Out_ PULONG DomainCount)
333 {
334 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
335 debugstr_a(ServerName), Flags, Domains, DomainCount);
336 return ERROR_CALL_NOT_IMPLEMENTED;
337 }
338
339
340 DWORD
341 WINAPI
342 DsEnumerateDomainTrustsW(
343 _In_opt_ LPWSTR ServerName,
344 _In_ ULONG Flags,
345 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
346 _Out_ PULONG DomainCount)
347 {
348 FIXME("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
349 debugstr_w(ServerName), Flags, Domains, DomainCount);
350 return ERROR_CALL_NOT_IMPLEMENTED;
351 }
352
353
354 DWORD
355 WINAPI
356 DsGetDcNameA(
357 _In_ LPCSTR ComputerName,
358 _In_ LPCSTR DomainName,
359 _In_ GUID *DomainGuid,
360 _In_ LPCSTR SiteName,
361 _In_ ULONG Flags,
362 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
363 {
364 FIXME("DsGetDcNameA(%s, %s, %s, %s, %08x, %p): stub\n",
365 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
366 debugstr_a(SiteName), Flags, DomainControllerInfo);
367 return ERROR_CALL_NOT_IMPLEMENTED;
368 }
369
370
371 DWORD
372 WINAPI
373 DsGetDcNameW(
374 _In_ LPCWSTR ComputerName,
375 _In_ LPCWSTR DomainName,
376 _In_ GUID *DomainGuid,
377 _In_ LPCWSTR SiteName,
378 _In_ ULONG Flags,
379 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
380 {
381 FIXME("DsGetDcNameW(%s, %s, %s, %s, %08x, %p)\n",
382 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
383 debugstr_w(SiteName), Flags, DomainControllerInfo);
384 return ERROR_CALL_NOT_IMPLEMENTED;
385 }
386
387
388 DWORD
389 WINAPI
390 DsGetDcSiteCoverageA(
391 _In_opt_ LPCSTR ServerName,
392 _Out_ PULONG EntryCount,
393 _Out_ LPSTR **SiteNames)
394 {
395 FIXME("DsGetDcSiteCoverageA(%s, %p, %p)\n",
396 debugstr_a(ServerName), EntryCount, SiteNames);
397 return ERROR_CALL_NOT_IMPLEMENTED;
398 }
399
400
401 DWORD
402 WINAPI
403 DsGetDcSiteCoverageW(
404 _In_opt_ LPCWSTR ServerName,
405 _Out_ PULONG EntryCount,
406 _Out_ LPWSTR **SiteNames)
407 {
408 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
409 PWSTR *SiteNamesBuffer = NULL, Ptr;
410 ULONG BufferSize, i;
411 NET_API_STATUS status;
412
413 TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
414 debugstr_w(ServerName), EntryCount, SiteNames);
415
416 *EntryCount = 0;
417 *SiteNames = NULL;
418
419 RpcTryExcept
420 {
421 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
422 &SiteNameArray);
423 if (status == NERR_Success)
424 {
425 if (SiteNameArray->EntryCount == 0)
426 {
427 status = ERROR_INVALID_PARAMETER;
428 }
429 else
430 {
431 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
432 for (i = 0; i < SiteNameArray->EntryCount; i++)
433 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
434
435 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
436 if (status == NERR_Success)
437 {
438 ZeroMemory(SiteNamesBuffer, BufferSize);
439
440 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
441 for (i = 0; i < SiteNameArray->EntryCount; i++)
442 {
443 SiteNamesBuffer[i] = Ptr;
444 CopyMemory(Ptr,
445 SiteNameArray->SiteNames[i].Buffer,
446 SiteNameArray->SiteNames[i].Length);
447
448 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
449 }
450
451 *EntryCount = SiteNameArray->EntryCount;
452 *SiteNames = SiteNamesBuffer;
453 }
454 }
455
456 MIDL_user_free(SiteNameArray);
457 }
458 }
459 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
460 {
461 status = I_RpcMapWin32Status(RpcExceptionCode());
462 }
463 RpcEndExcept;
464
465 return status;
466 }
467
468
469 DWORD
470 WINAPI
471 DsGetForestTrustInformationW(
472 _In_opt_ LPCWSTR ServerName,
473 _In_opt_ LPCWSTR TrustedDomainName,
474 _In_ DWORD Flags,
475 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
476 {
477 NET_API_STATUS status;
478
479 TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
480 debugstr_w(ServerName), debugstr_w(TrustedDomainName),
481 Flags, ForestTrustInfo);
482
483 RpcTryExcept
484 {
485 status = DsrGetForestTrustInformation((PWSTR)ServerName,
486 (PWSTR)TrustedDomainName,
487 Flags,
488 ForestTrustInfo);
489 }
490 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
491 {
492 status = I_RpcMapWin32Status(RpcExceptionCode());
493 }
494 RpcEndExcept;
495
496 return status;
497 }
498
499
500 DWORD
501 WINAPI
502 DsGetSiteNameA(
503 _In_ LPCSTR ComputerName,
504 _Out_ LPSTR *SiteName)
505 {
506 FIXME("DsGetSiteNameA(%s, %p)\n",
507 debugstr_a(ComputerName), SiteName);
508 return ERROR_CALL_NOT_IMPLEMENTED;
509 }
510
511
512 DWORD
513 WINAPI
514 DsGetSiteNameW(
515 _In_ LPCWSTR ComputerName,
516 _Out_ LPWSTR *SiteName)
517 {
518 NET_API_STATUS status;
519
520 TRACE("DsGetSiteNameW(%s, %p)\n",
521 debugstr_w(ComputerName), SiteName);
522
523 RpcTryExcept
524 {
525 status = DsrGetSiteName((PWSTR)ComputerName,
526 SiteName);
527 }
528 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
529 {
530 status = I_RpcMapWin32Status(RpcExceptionCode());
531 }
532 RpcEndExcept;
533
534 return status;
535 }
536
537
538 DWORD
539 WINAPI
540 DsMergeForestTrustInformationW(
541 _In_ LPCWSTR DomainName,
542 _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
543 _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
544 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
545 {
546 FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
547 debugstr_w(DomainName), NewForestTrustInfo,
548 OldForestTrustInfo, ForestTrustInfo);
549 return ERROR_CALL_NOT_IMPLEMENTED;
550 }
551
552
553 DWORD
554 WINAPI
555 DsValidateSubnetNameA(
556 _In_ LPCSTR SubnetName)
557 {
558 FIXME("DsValidateSubnetNameA(%s)\n",
559 debugstr_a(SubnetName));
560 return ERROR_CALL_NOT_IMPLEMENTED;
561 }
562
563
564 DWORD
565 WINAPI
566 DsValidateSubnetNameW(
567 _In_ LPCWSTR SubnetName)
568 {
569 FIXME("DsValidateSubnetNameW(%s)\n",
570 debugstr_w(SubnetName));
571 return ERROR_CALL_NOT_IMPLEMENTED;
572 }
573
574
575 NTSTATUS
576 WINAPI
577 NetEnumerateTrustedDomains(
578 _In_ LPWSTR ServerName,
579 _Out_ LPWSTR *DomainNames)
580 {
581 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
582 NTSTATUS Status = 0;
583
584 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
585 debugstr_w(ServerName), DomainNames);
586
587 RpcTryExcept
588 {
589 Status = NetrEnumerateTrustedDomains(ServerName,
590 &DomainNameBuffer);
591 if (NT_SUCCESS(Status))
592 {
593 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
594 }
595 }
596 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
597 {
598 Status = I_RpcMapWin32Status(RpcExceptionCode());
599 } RpcEndExcept;
600
601 return Status;
602 }
603
604
605 NET_API_STATUS
606 WINAPI
607 NetGetAnyDCName(
608 _In_opt_ LPCWSTR ServerName,
609 _In_opt_ LPCWSTR DomainName,
610 _Out_ LPBYTE *BufPtr)
611 {
612 NET_API_STATUS status;
613
614 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
615 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
616
617 *BufPtr = NULL;
618
619 RpcTryExcept
620 {
621 status = NetrGetAnyDCName((PWSTR)ServerName,
622 (PWSTR)DomainName,
623 (PWSTR*)BufPtr);
624 }
625 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
626 {
627 status = I_RpcMapWin32Status(RpcExceptionCode());
628 }
629 RpcEndExcept;
630
631 return status;
632 }
633
634
635 NET_API_STATUS
636 WINAPI
637 NetGetDCName(
638 _In_ LPCWSTR servername,
639 _In_ LPCWSTR domainname,
640 _Out_ LPBYTE *bufptr)
641 {
642 FIXME("NetGetDCName(%s, %s, %p)\n",
643 debugstr_w(servername), debugstr_w(domainname), bufptr);
644
645 return NERR_DCNotFound;
646 }
647
648 /* EOF */