[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 #if 0
142 NET_API_STATUS
143 NET_API_FUNCTION
144 NetGetJoinInformation(
145 LPCWSTR Server,
146 LPWSTR *Name,
147 PNETSETUP_JOIN_STATUS type)
148 {
149 NET_API_STATUS status;
150
151 TRACE("NetGetJoinInformation(%s %p %p)\n", debugstr_w(Server),
152 Name, type);
153
154 if (Name == NULL || type == NULL)
155 return ERROR_INVALID_PARAMETER;
156
157 RpcTryExcept
158 {
159 status = NetrGetJoinInformation((LPWSTR)Server,
160 Name,
161 type);
162 }
163 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
164 {
165 status = I_RpcMapWin32Status(RpcExceptionCode());
166 }
167 RpcEndExcept;
168
169 return status;
170 }
171 #endif
172
173
174 NET_API_STATUS
175 WINAPI
176 NetUseAdd(
177 LMSTR UncServerName,
178 DWORD Level,
179 LPBYTE Buf,
180 LPDWORD ParmError)
181 {
182 NET_API_STATUS status;
183
184 TRACE("NetUseAdd(%s %d %p %p)\n", debugstr_w(UncServerName),
185 Level, Buf, ParmError);
186
187 RpcTryExcept
188 {
189 status = NetrUseAdd(UncServerName,
190 Level,
191 (LPUSE_INFO)Buf,
192 ParmError);
193 }
194 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
195 {
196 status = I_RpcMapWin32Status(RpcExceptionCode());
197 }
198 RpcEndExcept;
199
200 return status;
201 }
202
203
204 NET_API_STATUS
205 WINAPI
206 NetUseDel(
207 LMSTR UncServerName,
208 LMSTR UseName,
209 DWORD ForceCond)
210 {
211 NET_API_STATUS status;
212
213 TRACE("NetUseDel(%s %s %d)\n", debugstr_w(UncServerName),
214 debugstr_w(UseName), ForceCond);
215
216 RpcTryExcept
217 {
218 status = NetrUseDel(UncServerName,
219 UseName,
220 ForceCond);
221 }
222 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
223 {
224 status = I_RpcMapWin32Status(RpcExceptionCode());
225 }
226 RpcEndExcept;
227
228 return status;
229 }
230
231
232 NET_API_STATUS
233 WINAPI
234 NetUseEnum(
235 LMSTR UncServerName,
236 DWORD Level,
237 LPBYTE *BufPtr,
238 DWORD PreferedMaximumSize,
239 LPDWORD EntriesRead,
240 LPDWORD TotalEntries,
241 LPDWORD ResumeHandle)
242 {
243 USE_ENUM_STRUCT UseEnumInfo;
244 USE_INFO_0_CONTAINER Container0;
245 USE_INFO_1_CONTAINER Container1;
246 USE_INFO_2_CONTAINER Container2;
247 NET_API_STATUS status;
248
249 TRACE("NetUseEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(UncServerName),
250 Level, BufPtr, PreferedMaximumSize, EntriesRead, TotalEntries, ResumeHandle);
251
252 UseEnumInfo.Level = Level;
253 switch (Level)
254 {
255 case 0:
256 UseEnumInfo.UseInfo.Level0 = &Container0;
257 Container0.EntriesRead = 0;
258 Container0.Buffer = NULL;
259 break;
260
261 case 1:
262 UseEnumInfo.UseInfo.Level1 = &Container1;
263 Container1.EntriesRead = 0;
264 Container1.Buffer = NULL;
265 break;
266
267 case 2:
268 UseEnumInfo.UseInfo.Level2 = &Container2;
269 Container2.EntriesRead = 0;
270 Container2.Buffer = NULL;
271 break;
272
273 default:
274 return ERROR_INVALID_PARAMETER;
275 }
276
277 RpcTryExcept
278 {
279 status = NetrUseEnum(UncServerName,
280 &UseEnumInfo,
281 PreferedMaximumSize,
282 TotalEntries,
283 ResumeHandle);
284 if (status == NERR_Success || status == ERROR_MORE_DATA)
285 {
286 switch (Level)
287 {
288 case 0:
289 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level0->Buffer;
290 *EntriesRead = UseEnumInfo.UseInfo.Level0->EntriesRead;
291 break;
292
293 case 1:
294 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level1->Buffer;
295 *EntriesRead = UseEnumInfo.UseInfo.Level1->EntriesRead;
296 break;
297
298 case 2:
299 *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level2->Buffer;
300 *EntriesRead = UseEnumInfo.UseInfo.Level2->EntriesRead;
301 break;
302 }
303 }
304 }
305 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
306 {
307 status = I_RpcMapWin32Status(RpcExceptionCode());
308 }
309 RpcEndExcept;
310
311 return status;
312 }
313
314
315 NET_API_STATUS
316 WINAPI
317 NetUseGetInfo(
318 LMSTR UncServerName,
319 LMSTR UseName,
320 DWORD Level,
321 LPBYTE *BufPtr)
322 {
323 NET_API_STATUS status;
324
325 TRACE("NetUseGetInfo(%s, %s, %d, %p)\n", debugstr_w(UncServerName),
326 debugstr_w(UseName), Level, BufPtr);
327
328 *BufPtr = NULL;
329
330 RpcTryExcept
331 {
332 status = NetrUseGetInfo(UncServerName,
333 UseName,
334 Level,
335 (LPUSE_INFO)BufPtr);
336 }
337 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
338 {
339 status = I_RpcMapWin32Status(RpcExceptionCode());
340 }
341 RpcEndExcept;
342
343 return status;
344 }
345
346
347 #if 0
348 NET_API_STATUS
349 WINAPI
350 NetWkstaGetInfo(
351 LPWSTR servername,
352 DWORD level,
353 LPBYTE *bufptr)
354 {
355 NET_API_STATUS status;
356
357 TRACE("NetWkstaGetInfo(%s, %d, %p)\n", debugstr_w(servername),
358 level, bufptr);
359
360 if (bufptr == NULL)
361 return ERROR_INVALID_PARAMETER;
362
363 *bufptr = NULL;
364
365 RpcTryExcept
366 {
367 status = NetrWkstaGetInfo(servername,
368 level,
369 (LPWKSTA_INFO)bufptr);
370 }
371 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
372 {
373 status = I_RpcMapWin32Status(RpcExceptionCode());
374 }
375 RpcEndExcept;
376
377 return status;
378 }
379 #endif
380
381
382 NET_API_STATUS
383 WINAPI
384 NetWkstaSetInfo(
385 LPWSTR servername,
386 DWORD level,
387 LPBYTE buffer,
388 LPDWORD parm_err)
389 {
390 NET_API_STATUS status;
391
392 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(servername),
393 level, buffer, parm_err);
394
395 RpcTryExcept
396 {
397 status = NetrWkstaSetInfo(servername,
398 level,
399 (LPWKSTA_INFO)buffer,
400 parm_err);
401 }
402 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
403 {
404 status = I_RpcMapWin32Status(RpcExceptionCode());
405 }
406 RpcEndExcept;
407
408 return status;
409 }
410
411
412 NET_API_STATUS
413 WINAPI
414 NetWkstaTransportAdd(
415 LPWSTR servername,
416 DWORD level,
417 LPBYTE buf,
418 LPDWORD parm_err)
419 {
420 NET_API_STATUS status;
421
422 TRACE("NetWkstaTransportAdd(%s, %d, %p, %p)\n", debugstr_w(servername),
423 level, buf, parm_err);
424
425 RpcTryExcept
426 {
427 status = NetrWkstaTransportAdd(servername,
428 level,
429 (LPWKSTA_TRANSPORT_INFO_0)buf,
430 parm_err);
431 }
432 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
433 {
434 status = I_RpcMapWin32Status(RpcExceptionCode());
435 }
436 RpcEndExcept;
437
438 return status;
439 }
440
441
442 NET_API_STATUS
443 WINAPI
444 NetWkstaTransportDel(
445 LPWSTR servername,
446 LPWSTR transportname,
447 DWORD ucond)
448 {
449 NET_API_STATUS status;
450
451 TRACE("NetWkstaTransportDel(%s, %s, %d)\n", debugstr_w(servername),
452 debugstr_w(transportname), ucond);
453
454 RpcTryExcept
455 {
456 status = NetrWkstaTransportDel(servername,
457 transportname,
458 ucond);
459 }
460 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
461 {
462 status = I_RpcMapWin32Status(RpcExceptionCode());
463 }
464 RpcEndExcept;
465
466 return status;
467 }
468
469
470 #if 0
471 NET_API_STATUS
472 WINAPI
473 NetWkstaTransportEnum(
474 LPWSTR servername,
475 DWORD level,
476 LPBYTE *bufptr,
477 DWORD prefmaxlen,
478 LPDWORD entriesread,
479 LPDWORD totalentries,
480 LPDWORD resumehandle)
481 {
482 WKSTA_TRANSPORT_ENUM_STRUCT TransportEnumInfo;
483 WKSTA_TRANSPORT_INFO_0_CONTAINER Container0;
484 NET_API_STATUS status;
485
486 TRACE("NetWkstaTransportEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
487 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
488
489 TransportEnumInfo.Level = level;
490 switch (level)
491 {
492 case 0:
493 TransportEnumInfo.WkstaTransportInfo.Level0 = &Container0;
494 Container0.EntriesRead = 0;
495 Container0.Buffer = NULL;
496 break;
497
498 default:
499 return ERROR_INVALID_PARAMETER;
500 }
501
502 RpcTryExcept
503 {
504 status = NetrWkstaTransportEnum(servername,
505 &TransportEnumInfo,
506 prefmaxlen,
507 totalentries,
508 resumehandle);
509 if (status == NERR_Success || status == ERROR_MORE_DATA)
510 {
511 switch (level)
512 {
513 case 0:
514 *bufptr = (LPBYTE)TransportEnumInfo.WkstaTransportInfo.Level0->Buffer;
515 *entriesread = TransportEnumInfo.WkstaTransportInfo.Level0->EntriesRead;
516 break;
517 }
518 }
519 }
520 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
521 {
522 status = I_RpcMapWin32Status(RpcExceptionCode());
523 }
524 RpcEndExcept;
525
526 return status;
527 }
528
529
530 NET_API_STATUS
531 WINAPI
532 NetWkstaUserEnum(
533 LPWSTR servername,
534 DWORD level,
535 LPBYTE *bufptr,
536 DWORD prefmaxlen,
537 LPDWORD entriesread,
538 LPDWORD totalentries,
539 LPDWORD resumehandle)
540 {
541 WKSTA_USER_ENUM_STRUCT UserEnumInfo;
542 WKSTA_USER_INFO_0_CONTAINER Container0;
543 WKSTA_USER_INFO_1_CONTAINER Container1;
544 NET_API_STATUS status;
545
546 TRACE("NetWkstaUserEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
547 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
548
549 UserEnumInfo.Level = level;
550 switch (level)
551 {
552 case 0:
553 UserEnumInfo.WkstaUserInfo.Level0 = &Container0;
554 Container0.EntriesRead = 0;
555 Container0.Buffer = NULL;
556 break;
557
558 case 1:
559 UserEnumInfo.WkstaUserInfo.Level1 = &Container1;
560 Container1.EntriesRead = 0;
561 Container1.Buffer = NULL;
562 break;
563
564 default:
565 return ERROR_INVALID_PARAMETER;
566 }
567
568 RpcTryExcept
569 {
570 status = NetrWkstaUserEnum(servername,
571 &UserEnumInfo,
572 prefmaxlen,
573 totalentries,
574 resumehandle);
575 if (status == NERR_Success || status == ERROR_MORE_DATA)
576 {
577 switch (level)
578 {
579 case 0:
580 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level0->Buffer;
581 *entriesread = UserEnumInfo.WkstaUserInfo.Level0->EntriesRead;
582 break;
583
584 case 1:
585 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level1->Buffer;
586 *entriesread = UserEnumInfo.WkstaUserInfo.Level1->EntriesRead;
587 break;
588 }
589 }
590 }
591 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
592 {
593 status = I_RpcMapWin32Status(RpcExceptionCode());
594 }
595 RpcEndExcept;
596
597 return status;
598 }
599
600
601 NET_API_STATUS
602 WINAPI
603 NetWkstaUserGetInfo(
604 LPWSTR reserved,
605 DWORD level,
606 PBYTE *bufptr)
607 {
608 NET_API_STATUS status;
609
610 TRACE("NetWkstaUserGetInfo(%s, %d, %p)\n", debugstr_w(reserved),
611 level, bufptr);
612
613 if (reserved != NULL)
614 return ERROR_INVALID_PARAMETER;
615
616 *bufptr = NULL;
617
618 RpcTryExcept
619 {
620 status = NetrWkstaUserGetInfo(NULL,
621 level,
622 (LPWKSTA_USER_INFO)bufptr);
623 }
624 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
625 {
626 status = I_RpcMapWin32Status(RpcExceptionCode());
627 }
628 RpcEndExcept;
629
630 return status;
631 }
632 #endif
633
634
635 NET_API_STATUS
636 WINAPI
637 NetWkstaUserSetInfo(
638 LPWSTR reserved,
639 DWORD level,
640 LPBYTE buf,
641 LPDWORD parm_err)
642 {
643 NET_API_STATUS status;
644
645 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(reserved),
646 level, buf, parm_err);
647
648 if (reserved != NULL)
649 return ERROR_INVALID_PARAMETER;
650
651 RpcTryExcept
652 {
653 status = NetrWkstaUserSetInfo(NULL,
654 level,
655 (LPWKSTA_USER_INFO)&buf,
656 parm_err);
657 }
658 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
659 {
660 status = I_RpcMapWin32Status(RpcExceptionCode());
661 }
662 RpcEndExcept;
663
664 return status;
665 }
666
667 /* EOF */