236c8a922af107031730e2f2c149049ddd88cafd
[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 DsDeregisterDnsHostRecordsA(
166 _In_opt_ LPSTR ServerName,
167 _In_opt_ LPSTR DnsDomainName,
168 _In_opt_ GUID *DomainGuid,
169 _In_opt_ GUID *DsaGuid,
170 _In_ LPSTR DnsHostName)
171 {
172 FIXME("DsDeregisterDnsHostRecordsA(%s, %s, %p, %p, %s)\n",
173 debugstr_a(ServerName), debugstr_a(DnsDomainName),
174 DomainGuid, DsaGuid, debugstr_a(DnsHostName));
175 return ERROR_CALL_NOT_IMPLEMENTED;
176 }
177
178
179 DWORD
180 WINAPI
181 DsDeregisterDnsHostRecordsW(
182 _In_opt_ LPWSTR ServerName,
183 _In_opt_ LPWSTR DnsDomainName,
184 _In_opt_ GUID *DomainGuid,
185 _In_opt_ GUID *DsaGuid,
186 _In_ LPWSTR DnsHostName)
187 {
188 NET_API_STATUS status;
189
190 TRACE("DsDeregisterDnsHostRecordsW(%s, %s, %p, %p, %s)\n",
191 debugstr_w(ServerName), debugstr_w(DnsDomainName),
192 DomainGuid, DsaGuid, debugstr_w(DnsHostName));
193
194 RpcTryExcept
195 {
196 status = DsrDeregisterDnsHostRecords(ServerName,
197 DnsDomainName,
198 DomainGuid,
199 DsaGuid,
200 DnsHostName);
201 }
202 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
203 {
204 status = I_RpcMapWin32Status(RpcExceptionCode());
205 }
206 RpcEndExcept;
207
208 return status;
209 }
210
211
212 DWORD
213 WINAPI
214 DsEnumerateDomainTrustsA(
215 _In_opt_ LPSTR ServerName,
216 _In_ ULONG Flags,
217 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
218 _Out_ PULONG DomainCount)
219 {
220 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
221 debugstr_a(ServerName), Flags, Domains, DomainCount);
222 return ERROR_CALL_NOT_IMPLEMENTED;
223 }
224
225
226 DWORD
227 WINAPI
228 DsEnumerateDomainTrustsW(
229 _In_opt_ LPWSTR ServerName,
230 _In_ ULONG Flags,
231 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
232 _Out_ PULONG DomainCount)
233 {
234 FIXME("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
235 debugstr_w(ServerName), Flags, Domains, DomainCount);
236 return ERROR_CALL_NOT_IMPLEMENTED;
237 }
238
239
240 DWORD
241 WINAPI
242 DsGetDcNameA(
243 _In_ LPCSTR ComputerName,
244 _In_ LPCSTR DomainName,
245 _In_ GUID *DomainGuid,
246 _In_ LPCSTR SiteName,
247 _In_ ULONG Flags,
248 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
249 {
250 FIXME("DsGetDcNameA(%s, %s, %s, %s, %08x, %p): stub\n",
251 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
252 debugstr_a(SiteName), Flags, DomainControllerInfo);
253 return ERROR_CALL_NOT_IMPLEMENTED;
254 }
255
256
257 DWORD
258 WINAPI
259 DsGetDcNameW(
260 _In_ LPCWSTR ComputerName,
261 _In_ LPCWSTR DomainName,
262 _In_ GUID *DomainGuid,
263 _In_ LPCWSTR SiteName,
264 _In_ ULONG Flags,
265 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
266 {
267 FIXME("DsGetDcNameW(%s, %s, %s, %s, %08x, %p)\n",
268 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
269 debugstr_w(SiteName), Flags, DomainControllerInfo);
270 return ERROR_CALL_NOT_IMPLEMENTED;
271 }
272
273
274 DWORD
275 WINAPI
276 DsGetDcSiteCoverageA(
277 _In_opt_ LPCSTR ServerName,
278 _Out_ PULONG EntryCount,
279 _Out_ LPSTR **SiteNames)
280 {
281 FIXME("DsGetDcSiteCoverageA(%s, %p, %p)\n",
282 debugstr_a(ServerName), EntryCount, SiteNames);
283 return ERROR_CALL_NOT_IMPLEMENTED;
284 }
285
286
287 DWORD
288 WINAPI
289 DsGetDcSiteCoverageW(
290 _In_opt_ LPCWSTR ServerName,
291 _Out_ PULONG EntryCount,
292 _Out_ LPWSTR **SiteNames)
293 {
294 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
295 PWSTR *SiteNamesBuffer = NULL, Ptr;
296 ULONG BufferSize, i;
297 NET_API_STATUS status;
298
299 TRACE("DsGetDcSiteCoverageW(%s, %p, %p)\n",
300 debugstr_w(ServerName), EntryCount, SiteNames);
301
302 *EntryCount = 0;
303 *SiteNames = NULL;
304
305 RpcTryExcept
306 {
307 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
308 &SiteNameArray);
309 if (status == NERR_Success)
310 {
311 if (SiteNameArray->EntryCount == 0)
312 {
313 status = ERROR_INVALID_PARAMETER;
314 }
315 else
316 {
317 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
318 for (i = 0; i < SiteNameArray->EntryCount; i++)
319 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
320
321 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
322 if (status == NERR_Success)
323 {
324 ZeroMemory(SiteNamesBuffer, BufferSize);
325
326 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
327 for (i = 0; i < SiteNameArray->EntryCount; i++)
328 {
329 SiteNamesBuffer[i] = Ptr;
330 CopyMemory(Ptr,
331 SiteNameArray->SiteNames[i].Buffer,
332 SiteNameArray->SiteNames[i].Length);
333
334 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
335 }
336
337 *EntryCount = SiteNameArray->EntryCount;
338 *SiteNames = SiteNamesBuffer;
339 }
340 }
341
342 MIDL_user_free(SiteNameArray);
343 }
344 }
345 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
346 {
347 status = I_RpcMapWin32Status(RpcExceptionCode());
348 }
349 RpcEndExcept;
350
351 return status;
352 }
353
354
355 DWORD
356 WINAPI
357 DsGetForestTrustInformationW(
358 _In_opt_ LPCWSTR ServerName,
359 _In_opt_ LPCWSTR TrustedDomainName,
360 _In_ DWORD Flags,
361 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
362 {
363 NET_API_STATUS status;
364
365 TRACE("DsGetForestTrustInformationW(%s, %s, 0x%08lx, %p)\n",
366 debugstr_w(ServerName), debugstr_w(TrustedDomainName),
367 Flags, ForestTrustInfo);
368
369 RpcTryExcept
370 {
371 status = DsrGetForestTrustInformation((PWSTR)ServerName,
372 (PWSTR)TrustedDomainName,
373 Flags,
374 ForestTrustInfo);
375 }
376 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
377 {
378 status = I_RpcMapWin32Status(RpcExceptionCode());
379 }
380 RpcEndExcept;
381
382 return status;
383 }
384
385
386 DWORD
387 WINAPI
388 DsGetSiteNameA(
389 _In_ LPCSTR ComputerName,
390 _Out_ LPSTR *SiteName)
391 {
392 FIXME("DsGetSiteNameA(%s, %p)\n",
393 debugstr_a(ComputerName), SiteName);
394 return ERROR_CALL_NOT_IMPLEMENTED;
395 }
396
397
398 DWORD
399 WINAPI
400 DsGetSiteNameW(
401 _In_ LPCWSTR ComputerName,
402 _Out_ LPWSTR *SiteName)
403 {
404 NET_API_STATUS status;
405
406 TRACE("DsGetSiteNameW(%s, %p)\n",
407 debugstr_w(ComputerName), SiteName);
408
409 RpcTryExcept
410 {
411 status = DsrGetSiteName((PWSTR)ComputerName,
412 SiteName);
413 }
414 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
415 {
416 status = I_RpcMapWin32Status(RpcExceptionCode());
417 }
418 RpcEndExcept;
419
420 return status;
421 }
422
423
424 DWORD
425 WINAPI
426 DsMergeForestTrustInformationW(
427 _In_ LPCWSTR DomainName,
428 _In_ PLSA_FOREST_TRUST_INFORMATION NewForestTrustInfo,
429 _In_opt_ PLSA_FOREST_TRUST_INFORMATION OldForestTrustInfo,
430 _Out_ PLSA_FOREST_TRUST_INFORMATION *ForestTrustInfo)
431 {
432 FIXME("DsMergeForestTrustInformationW(%s, %p, %p, %p)\n",
433 debugstr_w(DomainName), NewForestTrustInfo,
434 OldForestTrustInfo, ForestTrustInfo);
435 return ERROR_CALL_NOT_IMPLEMENTED;
436 }
437
438
439 VOID
440 WINAPI
441 DsRoleFreeMemory(
442 _In_ PVOID Buffer)
443 {
444 TRACE("DsRoleFreeMemory(%p)\n", Buffer);
445 HeapFree(GetProcessHeap(), 0, Buffer);
446 }
447
448
449 NTSTATUS
450 WINAPI
451 NetEnumerateTrustedDomains(
452 _In_ LPWSTR ServerName,
453 _Out_ LPWSTR *DomainNames)
454 {
455 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
456 NTSTATUS Status = 0;
457
458 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
459 debugstr_w(ServerName), DomainNames);
460
461 RpcTryExcept
462 {
463 Status = NetrEnumerateTrustedDomains(ServerName,
464 &DomainNameBuffer);
465 if (NT_SUCCESS(Status))
466 {
467 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
468 }
469 }
470 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
471 {
472 Status = I_RpcMapWin32Status(RpcExceptionCode());
473 } RpcEndExcept;
474
475 return Status;
476 }
477
478
479 NET_API_STATUS
480 WINAPI
481 NetGetAnyDCName(
482 _In_opt_ LPCWSTR ServerName,
483 _In_opt_ LPCWSTR DomainName,
484 _Out_ LPBYTE *BufPtr)
485 {
486 NET_API_STATUS status;
487
488 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
489 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
490
491 *BufPtr = NULL;
492
493 RpcTryExcept
494 {
495 status = NetrGetAnyDCName((PWSTR)ServerName,
496 (PWSTR)DomainName,
497 (PWSTR*)BufPtr);
498 }
499 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
500 {
501 status = I_RpcMapWin32Status(RpcExceptionCode());
502 }
503 RpcEndExcept;
504
505 return status;
506 }
507
508
509 NET_API_STATUS
510 WINAPI
511 NetGetDCName(
512 _In_ LPCWSTR servername,
513 _In_ LPCWSTR domainname,
514 _Out_ LPBYTE *bufptr)
515 {
516 FIXME("NetGetDCName(%s, %s, %p)\n",
517 debugstr_w(servername), debugstr_w(domainname), bufptr);
518
519 return NERR_DCNotFound;
520 }
521
522 /* EOF */