[NETAPI32]
[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 return ERROR_CALL_NOT_IMPLEMENTED;
276 }
277
278
279 DWORD
280 WINAPI
281 DsDeregisterDnsHostRecordsA(
282 _In_opt_ LPSTR ServerName,
283 _In_opt_ LPSTR DnsDomainName,
284 _In_opt_ GUID *DomainGuid,
285 _In_opt_ GUID *DsaGuid,
286 _In_ LPSTR DnsHostName)
287 {
288 FIXME("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
289 debugstr_a(ServerName), debugstr_a(DnsDomainName),
290 DomainGuid, DsaGuid, debugstr_a(DnsHostName));
291 return ERROR_CALL_NOT_IMPLEMENTED;
292 }
293
294
295 DWORD
296 WINAPI
297 DsDeregisterDnsHostRecordsW(
298 _In_opt_ LPWSTR ServerName,
299 _In_opt_ LPWSTR DnsDomainName,
300 _In_opt_ GUID *DomainGuid,
301 _In_opt_ GUID *DsaGuid,
302 _In_ LPWSTR DnsHostName)
303 {
304 NET_API_STATUS status;
305
306 TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
307 debugstr_w(ServerName), debugstr_w(DnsDomainName),
308 DomainGuid, DsaGuid, debugstr_w(DnsHostName));
309
310 RpcTryExcept
311 {
312 status = DsrDeregisterDnsHostRecords(ServerName,
313 DnsDomainName,
314 DomainGuid,
315 DsaGuid,
316 DnsHostName);
317 }
318 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
319 {
320 status = I_RpcMapWin32Status(RpcExceptionCode());
321 }
322 RpcEndExcept;
323
324 return status;
325 }
326
327
328 DWORD
329 WINAPI
330 DsEnumerateDomainTrustsA(
331 _In_opt_ LPSTR ServerName,
332 _In_ ULONG Flags,
333 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
334 _Out_ PULONG DomainCount)
335 {
336 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
337 debugstr_a(ServerName), Flags, Domains, DomainCount);
338 return ERROR_CALL_NOT_IMPLEMENTED;
339 }
340
341
342 DWORD
343 WINAPI
344 DsEnumerateDomainTrustsW(
345 _In_opt_ LPWSTR ServerName,
346 _In_ ULONG Flags,
347 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
348 _Out_ PULONG DomainCount)
349 {
350 FIXME("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
351 debugstr_w(ServerName), Flags, Domains, DomainCount);
352 return ERROR_CALL_NOT_IMPLEMENTED;
353 }
354
355
356 DWORD
357 WINAPI
358 DsGetDcNameA(
359 _In_ LPCSTR ComputerName,
360 _In_ LPCSTR DomainName,
361 _In_ GUID *DomainGuid,
362 _In_ LPCSTR SiteName,
363 _In_ ULONG Flags,
364 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
365 {
366 FIXME("DsGetDcNameA(%s, %s, %s, %s, %08x, %p): stub\n",
367 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
368 debugstr_a(SiteName), Flags, DomainControllerInfo);
369 return ERROR_CALL_NOT_IMPLEMENTED;
370 }
371
372
373 DWORD
374 WINAPI
375 DsGetDcNameW(
376 _In_ LPCWSTR ComputerName,
377 _In_ LPCWSTR DomainName,
378 _In_ GUID *DomainGuid,
379 _In_ LPCWSTR SiteName,
380 _In_ ULONG Flags,
381 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
382 {
383 FIXME("DsGetDcNameW(%s, %s, %s, %s, %08x, %p)\n",
384 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
385 debugstr_w(SiteName), Flags, DomainControllerInfo);
386 return ERROR_CALL_NOT_IMPLEMENTED;
387 }
388
389
390 DWORD
391 WINAPI
392 DsGetDcSiteCoverageA(
393 _In_opt_ LPCSTR ServerName,
394 _Out_ PULONG EntryCount,
395 _Out_ LPSTR **SiteNames)
396 {
397 FIXME("DsGetDcSiteCoverageA(%s, %p, %p)\n",
398 debugstr_a(ServerName), EntryCount, SiteNames);
399 return ERROR_CALL_NOT_IMPLEMENTED;
400 }
401
402
403 DWORD
404 WINAPI
405 DsGetDcSiteCoverageW(
406 _In_opt_ LPCWSTR ServerName,
407 _Out_ PULONG EntryCount,
408 _Out_ LPWSTR **SiteNames)
409 {
410 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
411 PWSTR *SiteNamesBuffer = NULL, Ptr;
412 ULONG BufferSize, i;
413 NET_API_STATUS status;
414
415 TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
416 debugstr_w(ServerName), EntryCount, SiteNames);
417
418 *EntryCount = 0;
419 *SiteNames = NULL;
420
421 RpcTryExcept
422 {
423 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
424 &SiteNameArray);
425 if (status == NERR_Success)
426 {
427 if (SiteNameArray->EntryCount == 0)
428 {
429 status = ERROR_INVALID_PARAMETER;
430 }
431 else
432 {
433 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
434 for (i = 0; i < SiteNameArray->EntryCount; i++)
435 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
436
437 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
438 if (status == NERR_Success)
439 {
440 ZeroMemory(SiteNamesBuffer, BufferSize);
441
442 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
443 for (i = 0; i < SiteNameArray->EntryCount; i++)
444 {
445 SiteNamesBuffer[i] = Ptr;
446 CopyMemory(Ptr,
447 SiteNameArray->SiteNames[i].Buffer,
448 SiteNameArray->SiteNames[i].Length);
449
450 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
451 }
452
453 *EntryCount = SiteNameArray->EntryCount;
454 *SiteNames = SiteNamesBuffer;
455 }
456 }
457
458 MIDL_user_free(SiteNameArray);
459 }
460 }
461 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
462 {
463 status = I_RpcMapWin32Status(RpcExceptionCode());
464 }
465 RpcEndExcept;
466
467 return status;
468 }
469
470
471 DWORD
472 WINAPI
473 DsGetForestTrustInformationW(
474 _In_opt_ LPCWSTR ServerName,
475 _In_opt_ LPCWSTR TrustedDomainName,
476 _In_ DWORD Flags,
477 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
478 {
479 NET_API_STATUS status;
480
481 TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
482 debugstr_w(ServerName), debugstr_w(TrustedDomainName),
483 Flags, ForestTrustInfo);
484
485 RpcTryExcept
486 {
487 status = DsrGetForestTrustInformation((PWSTR)ServerName,
488 (PWSTR)TrustedDomainName,
489 Flags,
490 ForestTrustInfo);
491 }
492 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
493 {
494 status = I_RpcMapWin32Status(RpcExceptionCode());
495 }
496 RpcEndExcept;
497
498 return status;
499 }
500
501
502 DWORD
503 WINAPI
504 DsGetSiteNameA(
505 _In_ LPCSTR ComputerName,
506 _Out_ LPSTR *SiteName)
507 {
508 FIXME("DsGetSiteNameA(%s, %p)\n",
509 debugstr_a(ComputerName), SiteName);
510 return ERROR_CALL_NOT_IMPLEMENTED;
511 }
512
513
514 DWORD
515 WINAPI
516 DsGetSiteNameW(
517 _In_ LPCWSTR ComputerName,
518 _Out_ LPWSTR *SiteName)
519 {
520 NET_API_STATUS status;
521
522 TRACE("DsGetSiteNameW(%s, %p)\n",
523 debugstr_w(ComputerName), SiteName);
524
525 RpcTryExcept
526 {
527 status = DsrGetSiteName((PWSTR)ComputerName,
528 SiteName);
529 }
530 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
531 {
532 status = I_RpcMapWin32Status(RpcExceptionCode());
533 }
534 RpcEndExcept;
535
536 return status;
537 }
538
539
540 DWORD
541 WINAPI
542 DsMergeForestTrustInformationW(
543 _In_ LPCWSTR DomainName,
544 _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
545 _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
546 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
547 {
548 FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
549 debugstr_w(DomainName), NewForestTrustInfo,
550 OldForestTrustInfo, ForestTrustInfo);
551 return ERROR_CALL_NOT_IMPLEMENTED;
552 }
553
554
555 DWORD
556 WINAPI
557 DsValidateSubnetNameA(
558 _In_ LPCSTR SubnetName)
559 {
560 FIXME("DsValidateSubnetNameA(%s)\n",
561 debugstr_a(SubnetName));
562 return ERROR_CALL_NOT_IMPLEMENTED;
563 }
564
565
566 DWORD
567 WINAPI
568 DsValidateSubnetNameW(
569 _In_ LPCWSTR SubnetName)
570 {
571 FIXME("DsValidateSubnetNameW(%s)\n",
572 debugstr_w(SubnetName));
573 return ERROR_CALL_NOT_IMPLEMENTED;
574 }
575
576
577 NTSTATUS
578 WINAPI
579 NetEnumerateTrustedDomains(
580 _In_ LPWSTR ServerName,
581 _Out_ LPWSTR *DomainNames)
582 {
583 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
584 NTSTATUS Status = 0;
585
586 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
587 debugstr_w(ServerName), DomainNames);
588
589 RpcTryExcept
590 {
591 Status = NetrEnumerateTrustedDomains(ServerName,
592 &DomainNameBuffer);
593 if (NT_SUCCESS(Status))
594 {
595 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
596 }
597 }
598 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
599 {
600 Status = I_RpcMapWin32Status(RpcExceptionCode());
601 } RpcEndExcept;
602
603 return Status;
604 }
605
606
607 NET_API_STATUS
608 WINAPI
609 NetGetAnyDCName(
610 _In_opt_ LPCWSTR ServerName,
611 _In_opt_ LPCWSTR DomainName,
612 _Out_ LPBYTE *BufPtr)
613 {
614 NET_API_STATUS status;
615
616 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
617 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
618
619 *BufPtr = NULL;
620
621 RpcTryExcept
622 {
623 status = NetrGetAnyDCName((PWSTR)ServerName,
624 (PWSTR)DomainName,
625 (PWSTR*)BufPtr);
626 }
627 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
628 {
629 status = I_RpcMapWin32Status(RpcExceptionCode());
630 }
631 RpcEndExcept;
632
633 return status;
634 }
635
636
637 NET_API_STATUS
638 WINAPI
639 NetGetDCName(
640 _In_ LPCWSTR servername,
641 _In_ LPCWSTR domainname,
642 _Out_ LPBYTE *bufptr)
643 {
644 FIXME("NetGetDCName(%s, %s, %p)\n",
645 debugstr_w(servername), debugstr_w(domainname), bufptr);
646
647 return NERR_DCNotFound;
648 }
649
650 /* EOF */