xref: /reactos/dll/win32/netapi32/browser.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         NetAPI DLL
4  * FILE:            dll/win32/netapi32/browser.c
5  * PURPOSE:         Computer Browser service interface code
6  * PROGRAMMERS:     Eric Kohl (eric.kohl@reactos.org)
7  */
8 
9 /* INCLUDES ******************************************************************/
10 
11 #include "netapi32.h"
12 
13 #include <rpc.h>
14 #include <lmbrowsr.h>
15 #include <lmserver.h>
16 #include "browser_c.h"
17 
18 
19 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
20 
21 /* FUNCTIONS *****************************************************************/
22 
23 handle_t __RPC_USER
BROWSER_IDENTIFY_HANDLE_bind(BROWSER_IDENTIFY_HANDLE pszSystemName)24 BROWSER_IDENTIFY_HANDLE_bind(BROWSER_IDENTIFY_HANDLE pszSystemName)
25 {
26     handle_t hBinding = NULL;
27     LPWSTR pszStringBinding;
28     RPC_STATUS status;
29 
30     TRACE("BROWSER_IDENTIFY_HANDLE_bind() called\n");
31 
32     status = RpcStringBindingComposeW(NULL,
33                                       L"ncacn_np",
34                                       pszSystemName,
35                                       L"\\pipe\\browser",
36                                       NULL,
37                                       &pszStringBinding);
38     if (status)
39     {
40         TRACE("RpcStringBindingCompose returned 0x%x\n", status);
41         return NULL;
42     }
43 
44     /* Set the binding handle that will be used to bind to the server. */
45     status = RpcBindingFromStringBindingW(pszStringBinding,
46                                           &hBinding);
47     if (status)
48     {
49         TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
50     }
51 
52     status = RpcStringFreeW(&pszStringBinding);
53     if (status)
54     {
55 //        TRACE("RpcStringFree returned 0x%x\n", status);
56     }
57 
58     return hBinding;
59 }
60 
61 
62 void __RPC_USER
BROWSER_IDENTIFY_HANDLE_unbind(BROWSER_IDENTIFY_HANDLE pszSystemName,handle_t hBinding)63 BROWSER_IDENTIFY_HANDLE_unbind(BROWSER_IDENTIFY_HANDLE pszSystemName,
64                                handle_t hBinding)
65 {
66     RPC_STATUS status;
67 
68     TRACE("BROWSER_IDENTIFY_HANDLE_unbind() called\n");
69 
70     status = RpcBindingFree(&hBinding);
71     if (status)
72     {
73         TRACE("RpcBindingFree returned 0x%x\n", status);
74     }
75 }
76 
77 
78 NET_API_STATUS
79 WINAPI
I_BrowserDebugTrace(_In_opt_ LPWSTR ServerName,_In_ PCHAR Buffer)80 I_BrowserDebugTrace(
81     _In_opt_ LPWSTR ServerName,
82     _In_ PCHAR Buffer)
83 {
84     NET_API_STATUS status;
85 
86     TRACE("I_BrowserDebugTrace(%s %s)\n",
87           debugstr_w(ServerName), Buffer);
88 
89     RpcTryExcept
90     {
91         status = I_BrowserrDebugTrace(ServerName,
92                                       Buffer);
93     }
94     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
95     {
96         status = I_RpcMapWin32Status(RpcExceptionCode());
97     }
98     RpcEndExcept;
99 
100     return status;
101 }
102 
103 
104 NET_API_STATUS
105 WINAPI
I_BrowserQueryEmulatedDomains(_In_opt_ LPWSTR ServerName,_Out_ PBROWSER_EMULATED_DOMAIN * EmulatedDomains,_Out_ LPDWORD EntriesRead)106 I_BrowserQueryEmulatedDomains(
107     _In_opt_ LPWSTR ServerName,
108     _Out_ PBROWSER_EMULATED_DOMAIN *EmulatedDomains,
109     _Out_ LPDWORD EntriesRead)
110 {
111     BROWSER_EMULATED_DOMAIN_CONTAINER Container = {0, NULL};
112     NET_API_STATUS status;
113 
114     TRACE("I_BrowserQueryEmulatedDomains(%s %p %p)\n",
115           debugstr_w(ServerName), EmulatedDomains, EntriesRead);
116 
117     *EmulatedDomains = NULL;
118     *EntriesRead = 0;
119 
120     RpcTryExcept
121     {
122         status = I_BrowserrQueryEmulatedDomains(ServerName,
123                                                 &Container);
124 
125         if (status == NERR_Success)
126         {
127             *EmulatedDomains = (PBROWSER_EMULATED_DOMAIN)Container.Buffer;
128             *EntriesRead = Container.EntriesRead;
129         }
130     }
131     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
132     {
133         status = I_RpcMapWin32Status(RpcExceptionCode());
134     }
135     RpcEndExcept;
136 
137     return status;
138 }
139 
140 
141 NET_API_STATUS
142 WINAPI
I_BrowserQueryOtherDomains(_In_opt_ LPCWSTR ServerName,_Out_ LPBYTE * BufPtr,_Out_ LPDWORD EntriesRead,_Out_ LPDWORD TotalEntries)143 I_BrowserQueryOtherDomains(
144     _In_opt_ LPCWSTR ServerName,
145     _Out_ LPBYTE *BufPtr,
146     _Out_ LPDWORD EntriesRead,
147     _Out_ LPDWORD TotalEntries)
148 {
149     SERVER_INFO_100_CONTAINER Level100Container = {0, NULL};
150     SERVER_ENUM_STRUCT EnumStruct;
151     NET_API_STATUS status;
152 
153     TRACE("I_BrowserQueryOtherDomains(%s %p %p %p)\n",
154           debugstr_w(ServerName), BufPtr, EntriesRead, TotalEntries);
155 
156     EnumStruct.Level = 100;
157     EnumStruct.ServerInfo.Level100 = &Level100Container;
158 
159     RpcTryExcept
160     {
161         status = I_BrowserrQueryOtherDomains((PWSTR)ServerName,
162                                              &EnumStruct,
163                                              TotalEntries);
164 
165         if (status == NERR_Success || status == ERROR_MORE_DATA)
166         {
167             *BufPtr = (LPBYTE)EnumStruct.ServerInfo.Level100->Buffer;
168             *EntriesRead = EnumStruct.ServerInfo.Level100->EntriesRead;
169         }
170     }
171     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
172     {
173         status = I_RpcMapWin32Status(RpcExceptionCode());
174     }
175     RpcEndExcept;
176 
177     return status;
178 }
179 
180 
181 NET_API_STATUS
182 WINAPI
I_BrowserServerEnum(_In_opt_ LPCWSTR ServerName,_In_opt_ LPCWSTR Transport,_In_opt_ LPCWSTR ClientName,_In_ DWORD Level,_Out_ LPBYTE * BufPtr,_In_ DWORD PrefMaxLen,_Out_ LPDWORD EntriesRead,_Out_ LPDWORD TotalEntries,_In_ DWORD ServerType,_In_opt_ LPCWSTR Domain,_Inout_opt_ LPDWORD ResumeHandle)183 I_BrowserServerEnum(
184     _In_opt_ LPCWSTR ServerName,
185     _In_opt_ LPCWSTR Transport,
186     _In_opt_ LPCWSTR ClientName,
187     _In_ DWORD Level,
188     _Out_ LPBYTE *BufPtr,
189     _In_ DWORD PrefMaxLen,
190     _Out_ LPDWORD EntriesRead,
191     _Out_ LPDWORD TotalEntries,
192     _In_ DWORD ServerType,
193     _In_opt_ LPCWSTR Domain,
194     _Inout_opt_ LPDWORD ResumeHandle)
195 {
196     SERVER_INFO_100_CONTAINER Level100Container = {0, NULL};
197     SERVER_ENUM_STRUCT EnumStruct;
198     NET_API_STATUS status;
199 
200     TRACE("I_BrowserServerEnum(%s %s %s %lu %p %lu %p %p %lu %s %p)\n",
201           debugstr_w(ServerName), debugstr_w(Transport), debugstr_w(ClientName),
202           Level, BufPtr, PrefMaxLen, EntriesRead, TotalEntries, ServerType,
203           debugstr_w(Domain), ResumeHandle);
204 
205     EnumStruct.Level = 100;
206     EnumStruct.ServerInfo.Level100 = &Level100Container;
207 
208     RpcTryExcept
209     {
210         status = I_BrowserrServerEnum((PWSTR)ServerName,
211                                       (PWSTR)Transport,
212                                       (PWSTR)ClientName,
213                                       &EnumStruct,
214                                       PrefMaxLen,
215                                       TotalEntries,
216                                       ServerType,
217                                       (PWSTR)Domain,
218                                       ResumeHandle);
219 
220         if (status == NERR_Success || status == ERROR_MORE_DATA)
221         {
222             *BufPtr = (LPBYTE)EnumStruct.ServerInfo.Level100->Buffer;
223             *EntriesRead = EnumStruct.ServerInfo.Level100->EntriesRead;
224         }
225     }
226     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
227     {
228         status = I_RpcMapWin32Status(RpcExceptionCode());
229     }
230     RpcEndExcept;
231 
232     return status;
233 }
234 
235 
236 NET_API_STATUS
237 WINAPI
I_BrowserQueryStatistics(_In_opt_ LPCWSTR ServerName,_Inout_ LPBROWSER_STATISTICS * Statistics)238 I_BrowserQueryStatistics(
239     _In_opt_ LPCWSTR ServerName,
240     _Inout_ LPBROWSER_STATISTICS *Statistics)
241 {
242     NET_API_STATUS status;
243 
244     TRACE("I_BrowserQueryStatistics(%s %p)\n",
245           debugstr_w(ServerName), Statistics);
246 
247     RpcTryExcept
248     {
249         status = I_BrowserrQueryStatistics((PWSTR)ServerName,
250                                            Statistics);
251     }
252     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
253     {
254         status = I_RpcMapWin32Status(RpcExceptionCode());
255     }
256     RpcEndExcept;
257 
258     return status;
259 }
260 
261 
262 NET_API_STATUS
263 WINAPI
I_BrowserResetStatistics(_In_opt_ LPCWSTR ServerName)264 I_BrowserResetStatistics(
265     _In_opt_ LPCWSTR ServerName)
266 {
267     NET_API_STATUS status;
268 
269     TRACE("I_BrowserResetStatistics(%s)\n",
270           debugstr_w(ServerName));
271 
272     RpcTryExcept
273     {
274         status = I_BrowserrResetStatistics((PWSTR)ServerName);
275     }
276     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
277     {
278         status = I_RpcMapWin32Status(RpcExceptionCode());
279     }
280     RpcEndExcept;
281 
282     return status;
283 }
284 
285 
286 NET_API_STATUS
287 WINAPI
I_BrowserResetNetlogonState(_In_ LPCWSTR ServerName)288 I_BrowserResetNetlogonState(
289     _In_ LPCWSTR ServerName)
290 {
291     NET_API_STATUS status;
292 
293     TRACE("I_BrowserResetNetlogonState(%s)\n",
294           debugstr_w(ServerName));
295 
296     RpcTryExcept
297     {
298         status = I_BrowserrResetNetlogonState((PWSTR)ServerName);
299     }
300     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
301     {
302         status = I_RpcMapWin32Status(RpcExceptionCode());
303     }
304     RpcEndExcept;
305 
306     return status;
307 }
308 
309 
310 NET_API_STATUS
311 WINAPI
I_BrowserSetNetlogonState(_In_ LPWSTR ServerName,_In_ LPWSTR DomainName,_In_ LPWSTR EmulatedServerName,_In_ DWORD Role)312 I_BrowserSetNetlogonState(
313     _In_ LPWSTR ServerName,
314     _In_ LPWSTR DomainName,
315     _In_ LPWSTR EmulatedServerName,
316     _In_ DWORD Role)
317 {
318     NET_API_STATUS status;
319 
320     TRACE("I_BrowserSetNetlogonState(%s %s %s %lu)\n",
321           debugstr_w(ServerName), debugstr_w(ServerName),
322           debugstr_w(EmulatedServerName), Role);
323 
324     RpcTryExcept
325     {
326         status = I_BrowserrSetNetlogonState(ServerName,
327                                             DomainName,
328                                             EmulatedServerName,
329                                             Role);
330     }
331     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
332     {
333         status = I_RpcMapWin32Status(RpcExceptionCode());
334     }
335     RpcEndExcept;
336 
337     return status;
338 }
339 
340 
341 NET_API_STATUS
342 WINAPI
NetBrowserStatisticsGet(_In_ LPWSTR ServerName,_In_ DWORD Level,_Out_ LPBYTE * Buffer)343 NetBrowserStatisticsGet(
344     _In_ LPWSTR ServerName,
345     _In_ DWORD Level,
346     _Out_ LPBYTE *Buffer)
347 {
348     BROWSER_STATISTICS_STRUCT StatisticsStruct;
349     BROWSER_STATISTICS_100_CONTAINER Level100Container = {0, NULL};
350     BROWSER_STATISTICS_101_CONTAINER Level101Container = {0, NULL};
351     NET_API_STATUS status;
352 
353     TRACE("NetBrowserStatisticsGet(%s %lu %p)\n",
354           debugstr_w(ServerName), Level, Buffer);
355 
356     if (Level != 100 && Level != 101)
357         return ERROR_INVALID_LEVEL;
358 
359     StatisticsStruct.Level = Level;
360     switch (Level)
361     {
362         case 100:
363             StatisticsStruct.Statistics.Level100 = &Level100Container;
364             break;
365 
366         case 101:
367             StatisticsStruct.Statistics.Level101 = &Level101Container;
368             break;
369     }
370 
371     RpcTryExcept
372     {
373         status = NetrBrowserStatisticsGet(ServerName,
374                                           Level,
375                                           &StatisticsStruct);
376 
377         switch (Level)
378         {
379             case 100:
380                 if (StatisticsStruct.Statistics.Level100->Buffer != NULL)
381                 {
382                     *Buffer = (LPBYTE)StatisticsStruct.Statistics.Level100->Buffer;
383                 }
384                 break;
385 
386             case 101:
387                 if (StatisticsStruct.Statistics.Level101->Buffer != NULL)
388                 {
389                     *Buffer = (LPBYTE)StatisticsStruct.Statistics.Level101->Buffer;
390                 }
391                 break;
392         }
393     }
394     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
395     {
396         status = I_RpcMapWin32Status(RpcExceptionCode());
397     }
398     RpcEndExcept;
399 
400     return status;
401 }
402 
403 
404 NET_API_STATUS
405 WINAPI
NetServerEnum(_In_opt_ LMCSTR servername,_In_ DWORD level,_Out_ LPBYTE * bufptr,_In_ DWORD prefmaxlen,_Out_ LPDWORD entriesread,_Out_ LPDWORD totalentries,_In_ DWORD servertype,_In_opt_ LMCSTR domain,_Inout_opt_ LPDWORD resume_handle)406 NetServerEnum(
407     _In_opt_ LMCSTR servername,
408     _In_ DWORD level,
409     _Out_ LPBYTE *bufptr,
410     _In_ DWORD prefmaxlen,
411     _Out_ LPDWORD entriesread,
412     _Out_ LPDWORD totalentries,
413     _In_ DWORD servertype,
414     _In_opt_ LMCSTR domain,
415     _Inout_opt_ LPDWORD resume_handle)
416 {
417     TRACE("NetServerEnum(%s %lu %p %lu %p %p %lu %s %p)\n",
418           debugstr_w(servername), level, bufptr, prefmaxlen, entriesread,
419           totalentries, servertype, debugstr_w(domain), resume_handle);
420 
421     if (resume_handle != NULL)
422         *resume_handle = 0;
423 
424     return NetServerEnumEx(servername,
425                            level,
426                            bufptr,
427                            prefmaxlen,
428                            entriesread,
429                            totalentries,
430                            servertype,
431                            domain,
432                            NULL);
433 }
434 
435 
436 NET_API_STATUS
437 WINAPI
NetServerEnumEx(_In_opt_ LMCSTR ServerName,_In_ DWORD Level,_Out_ LPBYTE * Bufptr,_In_ DWORD PrefMaxlen,_Out_ LPDWORD EntriesRead,_Out_ LPDWORD totalentries,_In_ DWORD servertype,_In_opt_ LMCSTR domain,_In_opt_ LMCSTR FirstNameToReturn)438 NetServerEnumEx(
439     _In_opt_ LMCSTR ServerName,
440     _In_ DWORD Level,
441     _Out_ LPBYTE *Bufptr,
442     _In_ DWORD PrefMaxlen,
443     _Out_ LPDWORD EntriesRead,
444     _Out_ LPDWORD totalentries,
445     _In_ DWORD servertype,
446     _In_opt_ LMCSTR domain,
447     _In_opt_ LMCSTR FirstNameToReturn)
448 {
449     FIXME("NetServerEnumEx(%s %lu %p %lu %p %p %lu %s %s)\n",
450            debugstr_w(ServerName), Level, Bufptr, PrefMaxlen, EntriesRead, totalentries,
451            servertype, debugstr_w(domain), debugstr_w(FirstNameToReturn));
452 
453     return ERROR_NO_BROWSER_SERVERS_FOUND;
454 }
455 
456 /* EOF */
457