[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / browser.c
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
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
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
80 I_BrowserQueryEmulatedDomains(
81 _In_opt_ LPWSTR ServerName,
82 _Out_ PBROWSER_EMULATED_DOMAIN *EmulatedDomains,
83 _Out_ LPDWORD EntriesRead)
84 {
85 BROWSER_EMULATED_DOMAIN_CONTAINER Container = {0, NULL};
86 NET_API_STATUS status;
87
88 TRACE("I_BrowserQueryEmulatedDomains(%s %p %p)\n",
89 debugstr_w(ServerName), EmulatedDomains, EntriesRead);
90
91 *EmulatedDomains = NULL;
92 *EntriesRead = 0;
93
94 RpcTryExcept
95 {
96 status = I_BrowserrQueryEmulatedDomains(ServerName,
97 &Container);
98
99 if (status == NERR_Success)
100 {
101 *EmulatedDomains = (PBROWSER_EMULATED_DOMAIN)Container.Buffer;
102 *EntriesRead = Container.EntriesRead;
103 }
104 }
105 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
106 {
107 status = I_RpcMapWin32Status(RpcExceptionCode());
108 }
109 RpcEndExcept;
110
111 return status;
112 }
113
114
115 NET_API_STATUS
116 WINAPI
117 I_BrowserQueryOtherDomains(
118 _In_opt_ LPCWSTR ServerName,
119 _Out_ LPBYTE *BufPtr,
120 _Out_ LPDWORD EntriesRead,
121 _Out_ LPDWORD TotalEntries)
122 {
123 SERVER_INFO_100_CONTAINER Level100Container = {0, NULL};
124 SERVER_ENUM_STRUCT EnumStruct;
125 NET_API_STATUS status;
126
127 TRACE("I_BrowserQueryOtherDomains(%s %p %p %p)\n",
128 debugstr_w(ServerName), BufPtr, EntriesRead, TotalEntries);
129
130 EnumStruct.Level = 100;
131 EnumStruct.ServerInfo.Level100 = &Level100Container;
132
133 RpcTryExcept
134 {
135 status = I_BrowserrQueryOtherDomains((PWSTR)ServerName,
136 &EnumStruct,
137 TotalEntries);
138
139 if (status == NERR_Success || status == ERROR_MORE_DATA)
140 {
141 *BufPtr = (LPBYTE)EnumStruct.ServerInfo.Level100->Buffer;
142 *EntriesRead = EnumStruct.ServerInfo.Level100->EntriesRead;
143 }
144 }
145 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
146 {
147 status = I_RpcMapWin32Status(RpcExceptionCode());
148 }
149 RpcEndExcept;
150
151 return status;
152 }
153
154
155 NET_API_STATUS
156 WINAPI
157 I_BrowserQueryStatistics(
158 _In_opt_ LPCWSTR ServerName,
159 _Inout_ LPBROWSER_STATISTICS *Statistics)
160 {
161 NET_API_STATUS status;
162
163 TRACE("I_BrowserQueryStatistics(%s %p)\n",
164 debugstr_w(ServerName), Statistics);
165
166 RpcTryExcept
167 {
168 status = I_BrowserrQueryStatistics((PWSTR)ServerName,
169 Statistics);
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
183 I_BrowserResetStatistics(
184 _In_opt_ LPCWSTR ServerName)
185 {
186 NET_API_STATUS status;
187
188 TRACE("I_BrowserResetStatistics(%s)\n",
189 debugstr_w(ServerName));
190
191 RpcTryExcept
192 {
193 status = I_BrowserrResetStatistics((PWSTR)ServerName);
194 }
195 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
196 {
197 status = I_RpcMapWin32Status(RpcExceptionCode());
198 }
199 RpcEndExcept;
200
201 return status;
202 }
203
204
205 NET_API_STATUS
206 WINAPI
207 I_BrowserResetNetlogonState(
208 _In_ LPCWSTR ServerName)
209 {
210 NET_API_STATUS status;
211
212 TRACE("I_BrowserResetNetlogonState(%s)\n",
213 debugstr_w(ServerName));
214
215 RpcTryExcept
216 {
217 status = I_BrowserrResetNetlogonState((PWSTR)ServerName);
218 }
219 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
220 {
221 status = I_RpcMapWin32Status(RpcExceptionCode());
222 }
223 RpcEndExcept;
224
225 return status;
226 }
227
228
229 NET_API_STATUS
230 WINAPI
231 I_BrowserSetNetlogonState(
232 _In_ LPWSTR ServerName,
233 _In_ LPWSTR DomainName,
234 _In_ LPWSTR EmulatedServerName,
235 _In_ DWORD Role)
236 {
237 NET_API_STATUS status;
238
239 TRACE("I_BrowserSetNetlogonState(%s %s %s %lu)\n",
240 debugstr_w(ServerName), debugstr_w(ServerName),
241 debugstr_w(EmulatedServerName), Role);
242
243 RpcTryExcept
244 {
245 status = I_BrowserrSetNetlogonState(ServerName,
246 DomainName,
247 EmulatedServerName,
248 Role);
249 }
250 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
251 {
252 status = I_RpcMapWin32Status(RpcExceptionCode());
253 }
254 RpcEndExcept;
255
256 return status;
257 }
258
259
260 NET_API_STATUS
261 WINAPI
262 NetServerEnum(
263 _In_opt_ LMCSTR servername,
264 _In_ DWORD level,
265 _Out_ LPBYTE *bufptr,
266 _In_ DWORD prefmaxlen,
267 _Out_ LPDWORD entriesread,
268 _Out_ LPDWORD totalentries,
269 _In_ DWORD servertype,
270 _In_opt_ LMCSTR domain,
271 _Inout_opt_ LPDWORD resume_handle)
272 {
273 FIXME("NetServerEnum(%s %lu %p %lu %p %p %lu %s %p)\n",
274 debugstr_w(servername), level, bufptr, prefmaxlen, entriesread,
275 totalentries, servertype, debugstr_w(domain), resume_handle);
276
277 return ERROR_NO_BROWSER_SERVERS_FOUND;
278 }
279
280
281 NET_API_STATUS
282 WINAPI
283 NetServerEnumEx(
284 _In_opt_ LMCSTR ServerName,
285 _In_ DWORD Level,
286 _Out_ LPBYTE *Bufptr,
287 _In_ DWORD PrefMaxlen,
288 _Out_ LPDWORD EntriesRead,
289 _Out_ LPDWORD totalentries,
290 _In_ DWORD servertype,
291 _In_opt_ LMCSTR domain,
292 _In_opt_ LMCSTR FirstNameToReturn)
293 {
294 FIXME("NetServerEnumEx(%s %lu %p %lu %p %p %lu %s %s)\n",
295 debugstr_w(ServerName), Level, Bufptr, PrefMaxlen, EntriesRead, totalentries,
296 servertype, debugstr_w(domain), debugstr_w(FirstNameToReturn));
297
298 return ERROR_NO_BROWSER_SERVERS_FOUND;
299 }
300
301 /* EOF */