[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 DsEnumerateDomainTrustsA(
166 _In_opt_ LPSTR ServerName,
167 _In_ ULONG Flags,
168 _Out_ PDS_DOMAIN_TRUSTSA *Domains,
169 _Out_ PULONG DomainCount)
170 {
171 FIXME("DsEnumerateDomainTrustsA(%s, %x, %p, %p)\n",
172 debugstr_a(ServerName), Flags, Domains, DomainCount);
173
174 return ERROR_NO_LOGON_SERVERS;
175 }
176
177
178 DWORD
179 WINAPI
180 DsEnumerateDomainTrustsW(
181 _In_opt_ LPWSTR ServerName,
182 _In_ ULONG Flags,
183 _Out_ PDS_DOMAIN_TRUSTSW *Domains,
184 _Out_ PULONG DomainCount)
185 {
186 FIXME("DsEnumerateDomainTrustsW(%s, %x, %p, %p)\n",
187 debugstr_w(ServerName), Flags, Domains, DomainCount);
188
189 return ERROR_NO_LOGON_SERVERS;
190 }
191
192
193 DWORD
194 WINAPI
195 DsGetDcNameA(
196 _In_ LPCSTR ComputerName,
197 _In_ LPCSTR DomainName,
198 _In_ GUID *DomainGuid,
199 _In_ LPCSTR SiteName,
200 _In_ ULONG Flags,
201 _Out_ PDOMAIN_CONTROLLER_INFOA *DomainControllerInfo)
202 {
203 FIXME("DsGetDcNameA(%s, %s, %s, %s, %08x, %p): stub\n",
204 debugstr_a(ComputerName), debugstr_a(DomainName), debugstr_guid(DomainGuid),
205 debugstr_a(SiteName), Flags, DomainControllerInfo);
206
207 return ERROR_CALL_NOT_IMPLEMENTED;
208 }
209
210
211 DWORD
212 WINAPI
213 DsGetDcNameW(
214 _In_ LPCWSTR ComputerName,
215 _In_ LPCWSTR DomainName,
216 _In_ GUID *DomainGuid,
217 _In_ LPCWSTR SiteName,
218 _In_ ULONG Flags,
219 _Out_ PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo)
220 {
221 FIXME("DsGetDcNameW(%s, %s, %s, %s, %08x, %p)\n",
222 debugstr_w(ComputerName), debugstr_w(DomainName), debugstr_guid(DomainGuid),
223 debugstr_w(SiteName), Flags, DomainControllerInfo);
224 return ERROR_CALL_NOT_IMPLEMENTED;
225 }
226
227
228 DWORD
229 WINAPI
230 DsGetDcSiteCoverageA(
231 _In_opt_ LPCSTR ServerName,
232 _Out_ PULONG EntryCount,
233 _Out_ LPSTR **SiteNames)
234 {
235 FIXME("DsGetDcSiteCoverageA(%s, %p, %p)\n",
236 debugstr_a(ServerName), EntryCount, SiteNames);
237 return ERROR_CALL_NOT_IMPLEMENTED;
238 }
239
240
241 DWORD
242 WINAPI
243 DsGetDcSiteCoverageW(
244 _In_opt_ LPCWSTR ServerName,
245 _Out_ PULONG EntryCount,
246 _Out_ LPWSTR **SiteNames)
247 {
248 PNL_SITE_NAME_ARRAY SiteNameArray = NULL;
249 PWSTR *SiteNamesBuffer = NULL, Ptr;
250 ULONG BufferSize, i;
251 NET_API_STATUS status;
252
253 TRACE("DsGetDcSiteCoverageA(%s, %p, %p)\n",
254 debugstr_w(ServerName), EntryCount, SiteNames);
255
256 *EntryCount = 0;
257 *SiteNames = NULL;
258
259 RpcTryExcept
260 {
261 status = DsrGetDcSiteCoverageW((PWSTR)ServerName,
262 &SiteNameArray);
263 if (status == NERR_Success)
264 {
265 if (SiteNameArray->EntryCount == 0)
266 {
267 status = ERROR_INVALID_PARAMETER;
268 }
269 else
270 {
271 BufferSize = SiteNameArray->EntryCount * sizeof(PWSTR);
272 for (i = 0; i < SiteNameArray->EntryCount; i++)
273 BufferSize += SiteNameArray->SiteNames[i].Length + sizeof(WCHAR);
274
275 status = NetApiBufferAllocate(BufferSize, (PVOID*)&SiteNamesBuffer);
276 if (status == NERR_Success)
277 {
278 ZeroMemory(SiteNamesBuffer, BufferSize);
279
280 Ptr = (PWSTR)((ULONG_PTR)SiteNamesBuffer + SiteNameArray->EntryCount * sizeof(PWSTR));
281 for (i = 0; i < SiteNameArray->EntryCount; i++)
282 {
283 SiteNamesBuffer[i] = Ptr;
284 CopyMemory(Ptr,
285 SiteNameArray->SiteNames[i].Buffer,
286 SiteNameArray->SiteNames[i].Length);
287
288 Ptr = (PWSTR)((ULONG_PTR)Ptr + SiteNameArray->SiteNames[i].Length + sizeof(WCHAR));
289 }
290
291 *EntryCount = SiteNameArray->EntryCount;
292 *SiteNames = SiteNamesBuffer;
293 }
294 }
295
296 MIDL_user_free(SiteNameArray);
297 }
298 }
299 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
300 {
301 status = I_RpcMapWin32Status(RpcExceptionCode());
302 }
303 RpcEndExcept;
304
305 return status;
306 }
307
308
309 DWORD
310 WINAPI
311 DsGetSiteNameA(
312 _In_ LPCSTR ComputerName,
313 _Out_ LPSTR *SiteName)
314 {
315 FIXME("DsGetSiteNameA(%s, %p)\n",
316 debugstr_a(ComputerName), SiteName);
317 return ERROR_CALL_NOT_IMPLEMENTED;
318 }
319
320
321 DWORD
322 WINAPI
323 DsGetSiteNameW(
324 _In_ LPCWSTR ComputerName,
325 _Out_ LPWSTR *SiteName)
326 {
327 NET_API_STATUS status;
328
329 TRACE("DsGetSiteNameW(%s, %p)\n",
330 debugstr_w(ComputerName), SiteName);
331
332 RpcTryExcept
333 {
334 status = DsrGetSiteName((PWSTR)ComputerName,
335 SiteName);
336 }
337 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
338 {
339 status = I_RpcMapWin32Status(RpcExceptionCode());
340 }
341 RpcEndExcept;
342
343 return status;
344 }
345
346
347 VOID
348 WINAPI
349 DsRoleFreeMemory(
350 _In_ PVOID Buffer)
351 {
352 TRACE("DsRoleFreeMemory(%p)\n", Buffer);
353 HeapFree(GetProcessHeap(), 0, Buffer);
354 }
355
356
357 NTSTATUS
358 WINAPI
359 NetEnumerateTrustedDomains(
360 _In_ LPWSTR ServerName,
361 _Out_ LPWSTR *DomainNames)
362 {
363 DOMAIN_NAME_BUFFER DomainNameBuffer = {0, NULL};
364 NTSTATUS Status = 0;
365
366 TRACE("NetEnumerateTrustedDomains(%s, %p)\n",
367 debugstr_w(ServerName), DomainNames);
368
369 RpcTryExcept
370 {
371 Status = NetrEnumerateTrustedDomains(ServerName,
372 &DomainNameBuffer);
373 if (NT_SUCCESS(Status))
374 {
375 *DomainNames = (LPWSTR)DomainNameBuffer.DomainNames;
376 }
377 }
378 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
379 {
380 Status = I_RpcMapWin32Status(RpcExceptionCode());
381 } RpcEndExcept;
382
383 return Status;
384 }
385
386
387 NET_API_STATUS
388 WINAPI
389 NetGetAnyDCName(
390 _In_opt_ LPCWSTR ServerName,
391 _In_opt_ LPCWSTR DomainName,
392 _Out_ LPBYTE *BufPtr)
393 {
394 NET_API_STATUS status;
395
396 TRACE("NetGetAnyDCName(%s, %s, %p)\n",
397 debugstr_w(ServerName), debugstr_w(DomainName), BufPtr);
398
399 *BufPtr = NULL;
400
401 RpcTryExcept
402 {
403 status = NetrGetAnyDCName((PWSTR)ServerName,
404 (PWSTR)DomainName,
405 (PWSTR*)BufPtr);
406 }
407 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
408 {
409 status = I_RpcMapWin32Status(RpcExceptionCode());
410 }
411 RpcEndExcept;
412
413 return status;
414 }
415
416
417 NET_API_STATUS
418 WINAPI
419 NetGetDCName(
420 _In_ LPCWSTR servername,
421 _In_ LPCWSTR domainname,
422 _Out_ LPBYTE *bufptr)
423 {
424 FIXME("NetGetDCName(%s, %s, %p)\n",
425 debugstr_w(servername), debugstr_w(domainname), bufptr);
426
427 return NERR_DCNotFound;
428 }
429
430 /* EOF */