[NETAPI32]
[reactos.git] / reactos / dll / win32 / netapi32 / wksta_new.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: NetAPI DLL
4 * FILE: reactos/dll/win32/netapi32/wksta_new.c
5 * PURPOSE: Workstation service interface code
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include "netapi32.h"
13 #include "wkssvc_c.h"
14
15 WINE_DEFAULT_DEBUG_CHANNEL(netapi32);
16
17 /* FUNCTIONS *****************************************************************/
18
19 void __RPC_FAR * __RPC_USER midl_user_allocate(SIZE_T len)
20 {
21 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
22 }
23
24
25 void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
26 {
27 HeapFree(GetProcessHeap(), 0, ptr);
28 }
29
30
31 handle_t __RPC_USER
32 WKSSVC_IDENTIFY_HANDLE_bind(WKSSVC_IDENTIFY_HANDLE pszSystemName)
33 {
34 handle_t hBinding = NULL;
35 LPWSTR pszStringBinding;
36 RPC_STATUS status;
37
38 TRACE("WKSSVC_IDENTIFY_HANDLE_bind() called\n");
39
40 status = RpcStringBindingComposeW(NULL,
41 L"ncacn_np",
42 pszSystemName,
43 L"\\pipe\\wkssvc",
44 NULL,
45 &pszStringBinding);
46 if (status)
47 {
48 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
49 return NULL;
50 }
51
52 /* Set the binding handle that will be used to bind to the server. */
53 status = RpcBindingFromStringBindingW(pszStringBinding,
54 &hBinding);
55 if (status)
56 {
57 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
58 }
59
60 status = RpcStringFreeW(&pszStringBinding);
61 if (status)
62 {
63 // TRACE("RpcStringFree returned 0x%x\n", status);
64 }
65
66 return hBinding;
67 }
68
69
70 void __RPC_USER
71 WKSSVC_IDENTIFY_HANDLE_unbind(WKSSVC_IDENTIFY_HANDLE pszSystemName,
72 handle_t hBinding)
73 {
74 RPC_STATUS status;
75
76 TRACE("WKSSVC_IDENTIFY_HANDLE_unbind() called\n");
77
78 status = RpcBindingFree(&hBinding);
79 if (status)
80 {
81 TRACE("RpcBindingFree returned 0x%x\n", status);
82 }
83 }
84
85
86 handle_t __RPC_USER
87 WKSSVC_IMPERSONATE_HANDLE_bind(WKSSVC_IMPERSONATE_HANDLE pszSystemName)
88 {
89 handle_t hBinding = NULL;
90 LPWSTR pszStringBinding;
91 RPC_STATUS status;
92
93 TRACE("WKSSVC_IMPERSONATE_HANDLE_bind() called\n");
94
95 status = RpcStringBindingComposeW(NULL,
96 L"ncacn_np",
97 pszSystemName,
98 L"\\pipe\\wkssvc",
99 NULL,
100 &pszStringBinding);
101 if (status)
102 {
103 TRACE("RpcStringBindingCompose returned 0x%x\n", status);
104 return NULL;
105 }
106
107 /* Set the binding handle that will be used to bind to the server. */
108 status = RpcBindingFromStringBindingW(pszStringBinding,
109 &hBinding);
110 if (status)
111 {
112 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status);
113 }
114
115 status = RpcStringFreeW(&pszStringBinding);
116 if (status)
117 {
118 // TRACE("RpcStringFree returned 0x%x\n", status);
119 }
120
121 return hBinding;
122 }
123
124
125 void __RPC_USER
126 WKSSVC_IMPERSONATE_HANDLE_unbind(WKSSVC_IMPERSONATE_HANDLE pszSystemName,
127 handle_t hBinding)
128 {
129 RPC_STATUS status;
130
131 TRACE("WKSSVC_IMPERSONATE_HANDLE_unbind() called\n");
132
133 status = RpcBindingFree(&hBinding);
134 if (status)
135 {
136 TRACE("RpcBindingFree returned 0x%x\n", status);
137 }
138 }
139
140
141 NET_API_STATUS
142 NET_API_FUNCTION
143 NetGetJoinInformation(
144 LPCWSTR Server,
145 LPWSTR *Name,
146 PNETSETUP_JOIN_STATUS type)
147 {
148 NET_API_STATUS status;
149
150 TRACE("NetGetJoinInformation(%s %p %p)\n", debugstr_w(Server),
151 Name, type);
152
153 if (Name == NULL || type == NULL)
154 return ERROR_INVALID_PARAMETER;
155
156 RpcTryExcept
157 {
158 status = NetrGetJoinInformation((LPWSTR)Server,
159 Name,
160 type);
161 }
162 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
163 {
164 status = I_RpcMapWin32Status(RpcExceptionCode());
165 }
166 RpcEndExcept;
167
168 return status;
169 }
170
171
172 NET_API_STATUS
173 WINAPI
174 NetUseAdd(
175 LMSTR UncServerName,
176 DWORD Level,
177 LPBYTE Buf,
178 LPDWORD ParmError)
179 {
180 NET_API_STATUS status;
181
182 TRACE("NetUseAdd(%s %d %p %p)\n", debugstr_w(UncServerName),
183 Level, Buf, ParmError);
184
185 RpcTryExcept
186 {
187 status = NetrUseAdd(UncServerName,
188 Level,
189 (LPUSE_INFO)Buf,
190 ParmError);
191 }
192 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
193 {
194 status = I_RpcMapWin32Status(RpcExceptionCode());
195 }
196 RpcEndExcept;
197
198 return status;
199 }
200
201
202 NET_API_STATUS
203 WINAPI
204 NetUseDel(
205 LMSTR UncServerName,
206 LMSTR UseName,
207 DWORD ForceCond)
208 {
209 NET_API_STATUS status;
210
211 TRACE("NetUseDel(%s %s %d)\n", debugstr_w(UncServerName),
212 debugstr_w(UseName), ForceCond);
213
214 RpcTryExcept
215 {
216 status = NetrUseDel(UncServerName,
217 UseName,
218 ForceCond);
219 }
220 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
221 {
222 status = I_RpcMapWin32Status(RpcExceptionCode());
223 }
224 RpcEndExcept;
225
226 return status;
227 }
228
229
230 NET_API_STATUS
231 WINAPI
232 NetUseEnum(
233 LMSTR UncServerName,
234 DWORD Level,
235 LPBYTE *BufPtr,
236 DWORD PreferedMaximumSize,
237 LPDWORD EntriesRead,
238 LPDWORD TotalEntries,
239 LPDWORD ResumeHandle)
240 {
241 USE_ENUM_STRUCT UseEnumInfo;
242 USE_INFO_0_CONTAINER Container0;
243 USE_INFO_1_CONTAINER Container1;
244 USE_INFO_2_CONTAINER Container2;
245 NET_API_STATUS status;
246
247 TRACE("NetUseEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(UncServerName),
248 Level, BufPtr, PreferedMaximumSize, EntriesRead, TotalEntries, ResumeHandle);
249
250 UseEnumInfo.Level = Level;
251 switch (Level)
252 {
253 case 0:
254 UseEnumInfo.UseInfo.Level0 = &Container0;
255 Container0.EntriesRead = 0;
256 Container0.Buffer = NULL;
257 break;
258
259 case 1:
260 UseEnumInfo.UseInfo.Level1 = &Container1;
261 Container1.EntriesRead = 0;
262 Container1.Buffer = NULL;
263 break;
264
265 case 2:
266 UseEnumInfo.UseInfo.Level2 = &Container2;
267 Container2.EntriesRead = 0;
268 Container2.Buffer = NULL;
269 break;
270
271 default:
272 return ERROR_INVALID_PARAMETER;
273 }
274
275 RpcTryExcept
276 {
277 status = NetrUseEnum(UncServerName,
278 &UseEnumInfo,
279 PreferedMaximumSize,
280 TotalEntries,
281 ResumeHandle);
282 if (status == NERR_Success || status == ERROR_MORE_DATA)
283 {
284 switch (Level)
285 {
286 case 0:
287 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level0->Buffer;
288 *EntriesRead = UseEnumInfo.UseInfo.Level0->EntriesRead;
289 break;
290
291 case 1:
292 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level1->Buffer;
293 *EntriesRead = UseEnumInfo.UseInfo.Level1->EntriesRead;
294 break;
295
296 case 2:
297 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level2->Buffer;
298 *EntriesRead = UseEnumInfo.UseInfo.Level2->EntriesRead;
299 break;
300 }
301 }
302 }
303 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
304 {
305 status = I_RpcMapWin32Status(RpcExceptionCode());
306 }
307 RpcEndExcept;
308
309 return status;
310 }
311
312
313 NET_API_STATUS
314 WINAPI
315 NetUseGetInfo(
316 LMSTR UncServerName,
317 LMSTR UseName,
318 DWORD Level,
319 LPBYTE *BufPtr)
320 {
321 NET_API_STATUS status;
322
323 TRACE("NetUseGetInfo(%s, %s, %d, %p)\n", debugstr_w(UncServerName),
324 debugstr_w(UseName), Level, BufPtr);
325
326 *BufPtr = NULL;
327
328 RpcTryExcept
329 {
330 status = NetrUseGetInfo(UncServerName,
331 UseName,
332 Level,
333 (LPUSE_INFO)BufPtr);
334 }
335 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
336 {
337 status = I_RpcMapWin32Status(RpcExceptionCode());
338 }
339 RpcEndExcept;
340
341 return status;
342 }
343
344
345 NET_API_STATUS
346 WINAPI
347 NetWkstaGetInfo(
348 LPWSTR servername,
349 DWORD level,
350 LPBYTE *bufptr)
351 {
352 NET_API_STATUS status;
353
354 TRACE("NetWkstaGetInfo(%s, %d, %p)\n", debugstr_w(servername),
355 level, bufptr);
356
357 *bufptr = NULL;
358
359 RpcTryExcept
360 {
361 status = NetrWkstaGetInfo(servername,
362 level,
363 (LPWKSTA_INFO)bufptr);
364 }
365 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
366 {
367 status = I_RpcMapWin32Status(RpcExceptionCode());
368 }
369 RpcEndExcept;
370
371 return status;
372 }
373
374
375 NET_API_STATUS
376 WINAPI
377 NetWkstaSetInfo(
378 LPWSTR servername,
379 DWORD level,
380 LPBYTE buffer,
381 LPDWORD parm_err)
382 {
383 NET_API_STATUS status;
384
385 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(servername),
386 level, buffer, parm_err);
387
388 RpcTryExcept
389 {
390 status = NetrWkstaSetInfo(servername,
391 level,
392 (LPWKSTA_INFO)buffer,
393 parm_err);
394 }
395 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
396 {
397 status = I_RpcMapWin32Status(RpcExceptionCode());
398 }
399 RpcEndExcept;
400
401 return status;
402 }
403
404
405 NET_API_STATUS
406 WINAPI
407 NetWkstaTransportAdd(
408 LPWSTR servername,
409 DWORD level,
410 LPBYTE buf,
411 LPDWORD parm_err)
412 {
413 NET_API_STATUS status;
414
415 TRACE("NetWkstaTransportAdd(%s, %d, %p, %p)\n", debugstr_w(servername),
416 level, buf, parm_err);
417
418 RpcTryExcept
419 {
420 status = NetrWkstaTransportAdd(servername,
421 level,
422 (LPWKSTA_TRANSPORT_INFO_0)buf,
423 parm_err);
424 }
425 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
426 {
427 status = I_RpcMapWin32Status(RpcExceptionCode());
428 }
429 RpcEndExcept;
430
431 return status;
432 }
433
434
435 NET_API_STATUS
436 WINAPI
437 NetWkstaTransportDel(
438 LPWSTR servername,
439 LPWSTR transportname,
440 DWORD ucond)
441 {
442 NET_API_STATUS status;
443
444 TRACE("NetWkstaTransportDel(%s, %s, %d)\n", debugstr_w(servername),
445 debugstr_w(transportname), ucond);
446
447 RpcTryExcept
448 {
449 status = NetrWkstaTransportDel(servername,
450 transportname,
451 ucond);
452 }
453 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
454 {
455 status = I_RpcMapWin32Status(RpcExceptionCode());
456 }
457 RpcEndExcept;
458
459 return status;
460 }
461
462
463 NET_API_STATUS
464 WINAPI
465 NetWkstaTransportEnum(
466 LPWSTR servername,
467 DWORD level,
468 LPBYTE *bufptr,
469 DWORD prefmaxlen,
470 LPDWORD entriesread,
471 LPDWORD totalentries,
472 LPDWORD resumehandle)
473 {
474 WKSTA_TRANSPORT_ENUM_STRUCT TransportEnumInfo;
475 WKSTA_TRANSPORT_INFO_0_CONTAINER Container0;
476 NET_API_STATUS status;
477
478 TRACE("NetWkstaTransportEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
479 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
480
481 TransportEnumInfo.Level = level;
482 switch (level)
483 {
484 case 0:
485 TransportEnumInfo.WkstaTransportInfo.Level0 = &Container0;
486 Container0.EntriesRead = 0;
487 Container0.Buffer = NULL;
488 break;
489
490 default:
491 return ERROR_INVALID_PARAMETER;
492 }
493
494 RpcTryExcept
495 {
496 status = NetrWkstaTransportEnum(servername,
497 &TransportEnumInfo,
498 prefmaxlen,
499 totalentries,
500 resumehandle);
501 if (status == NERR_Success || status == ERROR_MORE_DATA)
502 {
503 switch (level)
504 {
505 case 0:
506 *bufptr = (LPBYTE)TransportEnumInfo.WkstaTransportInfo.Level0->Buffer;
507 *entriesread = TransportEnumInfo.WkstaTransportInfo.Level0->EntriesRead;
508 break;
509 }
510 }
511 }
512 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
513 {
514 status = I_RpcMapWin32Status(RpcExceptionCode());
515 }
516 RpcEndExcept;
517
518 return status;
519 }
520
521
522 NET_API_STATUS
523 WINAPI
524 NetWkstaUserEnum(
525 LPWSTR servername,
526 DWORD level,
527 LPBYTE *bufptr,
528 DWORD prefmaxlen,
529 LPDWORD entriesread,
530 LPDWORD totalentries,
531 LPDWORD resumehandle)
532 {
533 WKSTA_USER_ENUM_STRUCT UserEnumInfo;
534 WKSTA_USER_INFO_0_CONTAINER Container0;
535 WKSTA_USER_INFO_1_CONTAINER Container1;
536 NET_API_STATUS status;
537
538 TRACE("NetWkstaUserEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
539 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
540
541 UserEnumInfo.Level = level;
542 switch (level)
543 {
544 case 0:
545 UserEnumInfo.WkstaUserInfo.Level0 = &Container0;
546 Container0.EntriesRead = 0;
547 Container0.Buffer = NULL;
548 break;
549
550 case 1:
551 UserEnumInfo.WkstaUserInfo.Level1 = &Container1;
552 Container1.EntriesRead = 0;
553 Container1.Buffer = NULL;
554 break;
555
556 default:
557 return ERROR_INVALID_PARAMETER;
558 }
559
560 RpcTryExcept
561 {
562 status = NetrWkstaUserEnum(servername,
563 &UserEnumInfo,
564 prefmaxlen,
565 totalentries,
566 resumehandle);
567 if (status == NERR_Success || status == ERROR_MORE_DATA)
568 {
569 switch (level)
570 {
571 case 0:
572 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level0->Buffer;
573 *entriesread = UserEnumInfo.WkstaUserInfo.Level0->EntriesRead;
574 break;
575
576 case 1:
577 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level1->Buffer;
578 *entriesread = UserEnumInfo.WkstaUserInfo.Level1->EntriesRead;
579 break;
580 }
581 }
582 }
583 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
584 {
585 status = I_RpcMapWin32Status(RpcExceptionCode());
586 }
587 RpcEndExcept;
588
589 return status;
590 }
591
592
593 NET_API_STATUS
594 WINAPI
595 NetWkstaUserGetInfo(
596 LPWSTR reserved,
597 DWORD level,
598 PBYTE *bufptr)
599 {
600 NET_API_STATUS status;
601
602 TRACE("NetWkstaUserGetInfo(%s, %d, %p)\n", debugstr_w(reserved),
603 level, bufptr);
604
605 if (reserved != NULL)
606 return ERROR_INVALID_PARAMETER;
607
608 *bufptr = NULL;
609
610 RpcTryExcept
611 {
612 status = NetrWkstaUserGetInfo(NULL,
613 level,
614 (LPWKSTA_USER_INFO)bufptr);
615 }
616 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
617 {
618 status = I_RpcMapWin32Status(RpcExceptionCode());
619 }
620 RpcEndExcept;
621
622 return status;
623 }
624
625
626 NET_API_STATUS
627 WINAPI
628 NetWkstaUserSetInfo(
629 LPWSTR reserved,
630 DWORD level,
631 LPBYTE buf,
632 LPDWORD parm_err)
633 {
634 NET_API_STATUS status;
635
636 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(reserved),
637 level, buf, parm_err);
638
639 if (reserved != NULL)
640 return ERROR_INVALID_PARAMETER;
641
642 RpcTryExcept
643 {
644 status = NetrWkstaUserSetInfo(NULL,
645 level,
646 (LPWKSTA_USER_INFO)&buf,
647 parm_err);
648 }
649 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
650 {
651 status = I_RpcMapWin32Status(RpcExceptionCode());
652 }
653 RpcEndExcept;
654
655 return status;
656 }
657
658 /* EOF */