563a5f47fb8b9cd67d05a15b660bb2cb84476958
[reactos.git] / reactos / dll / win32 / netapi32 / srvsvc.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: NetAPI DLL
4 * FILE: reactos/dll/win32/netapi32/srvsvc.c
5 * PURPOSE: Server service interface code
6 * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "netapi32.h"
12 #include "srvsvc_c.h"
13
14 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
15
16 /* FUNCTIONS *****************************************************************/
17
18 handle_t __RPC_USER
19 SRVSVC_HANDLE_bind(SRVSVC_HANDLE pszSystemName)
20 {
21 handle_t hBinding = NULL;
22 LPWSTR pszStringBinding;
23 RPC_STATUS status;
24
25 TRACE("SRVSVC_HANDLE_bind() called\n");
26
27 status = RpcStringBindingComposeW(NULL,
28 L"ncacn_np",
29 (RPC_WSTR)pszSystemName,
30 L"\\pipe\\srvsvc",
31 NULL,
32 &pszStringBinding);
33 if (status)
34 {
35 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
36 return NULL;
37 }
38
39 /* Set the binding handle that will be used to bind to the server. */
40 status = RpcBindingFromStringBindingW(pszStringBinding,
41 &hBinding);
42 if (status)
43 {
44 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
45 }
46
47 status = RpcStringFreeW(&pszStringBinding);
48 if (status)
49 {
50 // TRACE("RpcStringFree returned 0x%x\n", status);
51 }
52
53 return hBinding;
54 }
55
56
57 void __RPC_USER
58 SRVSVC_HANDLE_unbind(SRVSVC_HANDLE pszSystemName,
59 handle_t hBinding)
60 {
61 RPC_STATUS status;
62
63 TRACE("SRVSVC_HANDLE_unbind() called\n");
64
65 status = RpcBindingFree(&hBinding);
66 if (status)
67 {
68 TRACE("RpcBindingFree returned 0x%x\n", status);
69 }
70 }
71
72
73 NET_API_STATUS
74 WINAPI
75 NetRemoteTOD(
76 _In_ LPCWSTR UncServerName,
77 _Out_ LPBYTE *BufferPtr)
78 {
79 NET_API_STATUS status;
80
81 TRACE("NetRemoteTOD(%s, %p)\n", debugstr_w(UncServerName),
82 BufferPtr);
83
84 *BufferPtr = NULL;
85
86 RpcTryExcept
87 {
88 status = NetrRemoteTOD((SRVSVC_HANDLE)UncServerName,
89 (LPTIME_OF_DAY_INFO *)BufferPtr);
90 }
91 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
92 {
93 status = I_RpcMapWin32Status(RpcExceptionCode());
94 }
95 RpcEndExcept;
96
97 return status;
98 }
99
100
101 NET_API_STATUS
102 WINAPI
103 NetShareAdd(
104 _In_ LMSTR servername,
105 _In_ DWORD level,
106 _In_ LPBYTE buf,
107 _Out_ LPDWORD parm_err)
108 {
109 NET_API_STATUS status;
110
111 TRACE("NetShareAdd(%s %lu %p %p)\n",
112 debugstr_w(servername), level, buf, parm_err);
113
114 if (level != 2 && level != 502 && level != 503)
115 return ERROR_INVALID_LEVEL;
116
117 RpcTryExcept
118 {
119 status = NetrShareAdd(servername,
120 level,
121 (LPSHARE_INFO)&buf,
122 parm_err);
123 }
124 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
125 {
126 status = I_RpcMapWin32Status(RpcExceptionCode());
127 }
128 RpcEndExcept;
129
130 return status;
131 }
132
133
134 NET_API_STATUS
135 WINAPI
136 NetShareCheck(
137 _In_ LMSTR servername,
138 _In_ LMSTR device,
139 _Out_ LPDWORD type)
140 {
141 NET_API_STATUS status;
142
143 TRACE("NetShareCheck(%s %s %p)\n",
144 debugstr_w(servername), debugstr_w(device), type);
145
146 RpcTryExcept
147 {
148 status = NetrShareCheck(servername,
149 device,
150 type);
151 }
152 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
153 {
154 status = I_RpcMapWin32Status(RpcExceptionCode());
155 }
156 RpcEndExcept;
157
158 return status;
159
160 }
161
162
163 NET_API_STATUS
164 WINAPI
165 NetShareDel(
166 _In_ LMSTR servername,
167 _In_ LMSTR netname,
168 _In_ DWORD reserved)
169 {
170 NET_API_STATUS status;
171
172 TRACE("NetShareDel(%s %s %lu)\n",
173 debugstr_w(servername), debugstr_w(netname), reserved);
174
175 if (netname == NULL || (*netname == 0) || reserved != 0)
176 return ERROR_INVALID_PARAMETER;
177
178 RpcTryExcept
179 {
180 status = NetrShareDel(servername,
181 netname,
182 reserved);
183 }
184 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
185 {
186 status = I_RpcMapWin32Status(RpcExceptionCode());
187 }
188 RpcEndExcept;
189
190 return status;
191 }
192
193
194 NET_API_STATUS
195 WINAPI
196 NetShareDelSticky(
197 _In_ LMSTR servername,
198 _In_ LMSTR netname,
199 _In_ DWORD reserved)
200 {
201 NET_API_STATUS status;
202
203 TRACE("NetShareDelSticky(%s %s %lu)\n",
204 debugstr_w(servername), debugstr_w(netname), reserved);
205
206 if (netname == NULL || (*netname == 0) || reserved != 0)
207 return ERROR_INVALID_PARAMETER;
208
209 RpcTryExcept
210 {
211 status = NetrShareDelSticky(servername,
212 netname,
213 reserved);
214 }
215 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
216 {
217 status = I_RpcMapWin32Status(RpcExceptionCode());
218 }
219 RpcEndExcept;
220
221 return status;
222 }
223
224
225 NET_API_STATUS
226 WINAPI
227 NetShareEnum(
228 _In_ LMSTR servername,
229 _In_ DWORD level,
230 _Out_ LPBYTE *bufptr,
231 _In_ DWORD prefmaxlen,
232 _Out_ LPDWORD entriesread,
233 _Out_ LPDWORD totalentries,
234 _Inout_ LPDWORD resume_handle)
235 {
236 SHARE_ENUM_STRUCT EnumStruct;
237 SHARE_INFO_0_CONTAINER Level0Container = {0, NULL};
238 SHARE_INFO_1_CONTAINER Level1Container = {0, NULL};
239 SHARE_INFO_2_CONTAINER Level2Container = {0, NULL};
240 SHARE_INFO_502_CONTAINER Level502Container = {0, NULL};
241 NET_API_STATUS status;
242
243 TRACE("NetShareEnum(%s %lu %p %lu %p %p %p)\n",
244 debugstr_w(servername), level, bufptr, prefmaxlen,
245 entriesread, totalentries, resume_handle);
246
247 if (level > 2 && level != 502)
248 return ERROR_INVALID_LEVEL;
249
250 *bufptr = NULL;
251 *entriesread = 0;
252 *totalentries = 0;
253
254 EnumStruct.Level = level;
255 switch (level)
256 {
257 case 0:
258 EnumStruct.ShareInfo.Level0 = &Level0Container;
259 break;
260
261 case 1:
262 EnumStruct.ShareInfo.Level1 = &Level1Container;
263 break;
264
265 case 2:
266 EnumStruct.ShareInfo.Level2 = &Level2Container;
267 break;
268
269 case 502:
270 EnumStruct.ShareInfo.Level502 = &Level502Container;
271 break;
272 }
273
274 RpcTryExcept
275 {
276 status = NetrShareEnum(servername,
277 &EnumStruct,
278 prefmaxlen,
279 totalentries,
280 resume_handle);
281
282 switch (level)
283 {
284 case 0:
285 if (EnumStruct.ShareInfo.Level0->Buffer != NULL)
286 {
287 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level0->Buffer;
288 *entriesread = EnumStruct.ShareInfo.Level0->EntriesRead;
289 }
290 break;
291
292 case 1:
293 if (EnumStruct.ShareInfo.Level1->Buffer != NULL)
294 {
295 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level1->Buffer;
296 *entriesread = EnumStruct.ShareInfo.Level1->EntriesRead;
297 }
298 break;
299
300 case 2:
301 if (EnumStruct.ShareInfo.Level2->Buffer != NULL)
302 {
303 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level2->Buffer;
304 *entriesread = EnumStruct.ShareInfo.Level2->EntriesRead;
305 }
306 break;
307
308 case 502:
309 if (EnumStruct.ShareInfo.Level502->Buffer != NULL)
310 {
311 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level502->Buffer;
312 *entriesread = EnumStruct.ShareInfo.Level502->EntriesRead;
313 }
314 break;
315 }
316 }
317 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
318 {
319 status = I_RpcMapWin32Status(RpcExceptionCode());
320 }
321 RpcEndExcept;
322
323 return status;
324 }
325
326
327 NET_API_STATUS
328 WINAPI
329 NetShareEnumSticky(
330 _In_ LMSTR servername,
331 _In_ DWORD level,
332 _Out_ LPBYTE *bufptr,
333 _In_ DWORD prefmaxlen,
334 _Out_ LPDWORD entriesread,
335 _Out_ LPDWORD totalentries,
336 _Inout_ LPDWORD resume_handle)
337 {
338 SHARE_ENUM_STRUCT EnumStruct;
339 SHARE_INFO_0_CONTAINER Level0Container = {0, NULL};
340 SHARE_INFO_1_CONTAINER Level1Container = {0, NULL};
341 SHARE_INFO_2_CONTAINER Level2Container = {0, NULL};
342 SHARE_INFO_502_CONTAINER Level502Container = {0, NULL};
343 NET_API_STATUS status;
344
345 TRACE("NetShareEnumSticky(%s %lu %p %lu %p %p %p)\n",
346 debugstr_w(servername), level, bufptr, prefmaxlen,
347 entriesread, totalentries, resume_handle);
348
349 if (level > 2 && level != 502)
350 return ERROR_INVALID_LEVEL;
351
352 *bufptr = NULL;
353 *entriesread = 0;
354 *totalentries = 0;
355
356 EnumStruct.Level = level;
357 switch (level)
358 {
359 case 0:
360 EnumStruct.ShareInfo.Level0 = &Level0Container;
361 break;
362
363 case 1:
364 EnumStruct.ShareInfo.Level1 = &Level1Container;
365 break;
366
367 case 2:
368 EnumStruct.ShareInfo.Level2 = &Level2Container;
369 break;
370
371 case 502:
372 EnumStruct.ShareInfo.Level502 = &Level502Container;
373 break;
374 }
375
376 RpcTryExcept
377 {
378 status = NetrShareEnum(servername,
379 (LPSHARE_ENUM_STRUCT)&EnumStruct,
380 prefmaxlen,
381 totalentries,
382 resume_handle);
383
384 switch (level)
385 {
386 case 0:
387 if (EnumStruct.ShareInfo.Level0->Buffer != NULL)
388 {
389 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level0->Buffer;
390 *entriesread = EnumStruct.ShareInfo.Level0->EntriesRead;
391 }
392 break;
393
394 case 1:
395 if (EnumStruct.ShareInfo.Level1->Buffer != NULL)
396 {
397 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level1->Buffer;
398 *entriesread = EnumStruct.ShareInfo.Level1->EntriesRead;
399 }
400 break;
401
402 case 2:
403 if (EnumStruct.ShareInfo.Level2->Buffer != NULL)
404 {
405 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level2->Buffer;
406 *entriesread = EnumStruct.ShareInfo.Level2->EntriesRead;
407 }
408 break;
409
410 case 502:
411 if (EnumStruct.ShareInfo.Level502->Buffer != NULL)
412 {
413 *bufptr = (LPBYTE)EnumStruct.ShareInfo.Level502->Buffer;
414 *entriesread = EnumStruct.ShareInfo.Level502->EntriesRead;
415 }
416 break;
417 }
418 }
419 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
420 {
421 status = I_RpcMapWin32Status(RpcExceptionCode());
422 }
423 RpcEndExcept;
424
425 return status;
426 }
427
428
429 NET_API_STATUS
430 WINAPI
431 NetShareGetInfo(
432 _In_ LMSTR servername,
433 _In_ LMSTR netname,
434 _In_ DWORD level,
435 _Out_ LPBYTE *bufptr)
436 {
437 NET_API_STATUS status;
438
439 TRACE("NetShareGetInfo(%s %s %lu %p)\n",
440 debugstr_w(servername), debugstr_w(netname), level, bufptr);
441
442 if (level > 2 && level != 502 && level != 1005)
443 return ERROR_INVALID_LEVEL;
444
445 if (netname == NULL || *netname == 0)
446 return ERROR_INVALID_PARAMETER;
447
448 *bufptr = NULL;
449
450 RpcTryExcept
451 {
452 status = NetrShareGetInfo(servername,
453 netname,
454 level,
455 (LPSHARE_INFO)bufptr);
456 }
457 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
458 {
459 status = I_RpcMapWin32Status(RpcExceptionCode());
460 }
461 RpcEndExcept;
462
463 return status;
464 }
465
466
467 NET_API_STATUS
468 WINAPI
469 NetShareSetInfo(
470 _In_ LPWSTR servername,
471 _In_ LPWSTR netname,
472 _In_ DWORD level,
473 _In_ LPBYTE buf,
474 _Out_ LPDWORD parm_err)
475 {
476 NET_API_STATUS status;
477
478 TRACE("NetShareSetInfo(%s %s %lu %p %p)\n",
479 debugstr_w(servername), debugstr_w(netname), level, buf, parm_err);
480
481 if (level != 2 && level != 502 && level != 503 && level != 1004 &&
482 level != 1005 && level != 1006 && level != 1501)
483 return ERROR_INVALID_LEVEL;
484
485 RpcTryExcept
486 {
487 status = NetrShareSetInfo(servername,
488 netname,
489 level,
490 (LPSHARE_INFO)&buf,
491 parm_err);
492 }
493 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
494 {
495 status = I_RpcMapWin32Status(RpcExceptionCode());
496 }
497 RpcEndExcept;
498
499 return status;
500 }
501
502 /* EOF */