xref: /reactos/dll/win32/netapi32/wksta_new.c (revision 34593d93)
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 NetpBind(
143     LPCWSTR pszServerName,
144     handle_t *pBindingHandle)
145 {
146     handle_t hBinding = NULL;
147     LPWSTR pszStringBinding;
148     RPC_STATUS status;
149 
150     FIXME("NetpBind(%S)\n", pszServerName);
151 
152     *pBindingHandle = NULL;
153 
154     status = RpcStringBindingComposeW(NULL,
155                                       L"ncacn_np",
156                                       (LPWSTR)pszServerName,
157                                       L"\\pipe\\wkssvc",
158                                       NULL,
159                                       &pszStringBinding);
160     if (status)
161     {
162         FIXME("RpcStringBindingCompose returned 0x%x\n", status);
163         return NetpNtStatusToApiStatus(status);
164     }
165 
166     /* Set the binding handle that will be used to bind to the server. */
167     status = RpcBindingFromStringBindingW(pszStringBinding,
168                                           &hBinding);
169     if (status)
170     {
171         FIXME("RpcBindingFromStringBinding returned 0x%x\n", status);
172     }
173 
174     status = RpcStringFreeW(&pszStringBinding);
175     if (status)
176     {
177         FIXME("RpcStringFree returned 0x%x\n", status);
178     }
179 
180     *pBindingHandle = hBinding;
181 
182     return NetpNtStatusToApiStatus(status);
183 }
184 
185 
186 NET_API_STATUS
187 NetpUnbind(
188     handle_t BindingHandle)
189 {
190     RPC_STATUS status;
191 
192     FIXME("NetpUnbind(%p)\n", BindingHandle);
193 
194     status = RpcBindingFree(&wkssvc_hBinding);
195     if (status)
196     {
197         TRACE("RpcBindingFree returned 0x%x\n", status);
198         return NetpNtStatusToApiStatus(status);
199     }
200 
201     return NERR_Success;
202 }
203 
204 
205 NET_API_STATUS
206 WINAPI
207 NetAddAlternateComputerName(
208     _In_opt_ LPCWSTR Server,
209     _In_ LPCWSTR AlternateName,
210     _In_opt_ LPCWSTR DomainAccount,
211     _In_opt_ LPCWSTR DomainAccountPassword,
212     _In_ ULONG Reserved)
213 {
214     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
215     handle_t BindingHandle = NULL;
216     NET_API_STATUS status;
217 
218     TRACE("NetAddAlternateComputerName(%s %s %s %s 0x%lx)\n",
219           debugstr_w(Server), debugstr_w(AlternateName), debugstr_w(DomainAccount),
220           debugstr_w(DomainAccountPassword), Reserved);
221 
222     /* FIXME */
223 
224     status = NetpBind(Server,
225                       &BindingHandle);
226     if (status != NERR_Success)
227     {
228         ERR("NetpBind() failed (status 0x%lx)\n", status);
229         return status;
230     }
231 
232     RpcTryExcept
233     {
234         status = NetrAddAlternateComputerName(BindingHandle,
235                                               (PWSTR)Server,
236                                               (PWSTR)AlternateName,
237                                               (PWSTR)DomainAccount,
238                                               EncryptedPassword,
239                                               Reserved);
240     }
241     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
242     {
243         status = I_RpcMapWin32Status(RpcExceptionCode());
244     }
245     RpcEndExcept;
246 
247     NetpUnbind(BindingHandle);
248 
249     return status;
250 }
251 
252 
253 NET_API_STATUS
254 WINAPI
255 NetEnumerateComputerNames(
256     _In_opt_ LPCWSTR Server,
257     _In_ NET_COMPUTER_NAME_TYPE NameType,
258     _In_ ULONG Reserved,
259     _Out_ PDWORD EntryCount,
260     _Out_ LPWSTR **ComputerNames)
261 {
262     PNET_COMPUTER_NAME_ARRAY ComputerNameArray = NULL;
263     ULONG BufferSize, i;
264     PWSTR *NameBuffer = NULL, Ptr;
265     NET_API_STATUS status;
266 
267     TRACE("NetEnumerateComputerNames(%s %lu %lu %p %p)\n",
268           debugstr_w(Server), NameType, Reserved, EntryCount, ComputerNames);
269 
270     RpcTryExcept
271     {
272         status = NetrEnumerateComputerNames((PWSTR)Server,
273                                             NameType,
274                                             Reserved,
275                                             &ComputerNameArray);
276         if (status == NERR_Success)
277         {
278             *EntryCount = ComputerNameArray->EntryCount;
279 
280             BufferSize = 0;
281             for (i = 0; i < ComputerNameArray->EntryCount; i++)
282             {
283                 BufferSize += ComputerNameArray->ComputerNames[i].Length + sizeof(WCHAR) + sizeof(PWSTR);
284             }
285 
286             status = NetApiBufferAllocate(BufferSize, (PVOID*)&NameBuffer);
287             if (status == NERR_Success)
288             {
289                 ZeroMemory(NameBuffer, BufferSize);
290 
291                 Ptr = (PWSTR)((ULONG_PTR)NameBuffer + ComputerNameArray->EntryCount * sizeof(PWSTR));
292                 for (i = 0; i < ComputerNameArray->EntryCount; i++)
293                 {
294                     NameBuffer[i] = Ptr;
295                     CopyMemory(Ptr,
296                                ComputerNameArray->ComputerNames[i].Buffer,
297                                ComputerNameArray->ComputerNames[i].Length);
298                     Ptr = (PWSTR)((ULONG_PTR)Ptr + ComputerNameArray->ComputerNames[i].Length + sizeof(WCHAR));
299                 }
300 
301                 *ComputerNames = NameBuffer;
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 NetGetJoinInformation(
318     _In_ LPCWSTR lpServer,
319     _Out_ LPWSTR *lpNameBuffer,
320     _Out_ PNETSETUP_JOIN_STATUS BufferType)
321 {
322     NET_API_STATUS status;
323 
324     TRACE("NetGetJoinInformation(%s %p %p)\n",
325           debugstr_w(lpServer), lpNameBuffer, BufferType);
326 
327     if (lpNameBuffer == NULL || BufferType == NULL)
328         return ERROR_INVALID_PARAMETER;
329 
330     RpcTryExcept
331     {
332         status = NetrGetJoinInformation((LPWSTR)lpServer,
333                                         lpNameBuffer,
334                                         BufferType);
335     }
336     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
337     {
338         status = I_RpcMapWin32Status(RpcExceptionCode());
339     }
340     RpcEndExcept;
341 
342     return status;
343 }
344 
345 
346 NET_API_STATUS
347 WINAPI
348 NetGetJoinableOUs(
349     _In_opt_ LPCWSTR lpServer,
350     _In_ LPCWSTR lpDomain,
351     _In_opt_ LPCWSTR lpAccount,
352     _In_opt_ LPCWSTR lpPassword,
353     _Out_ DWORD *OUCount,
354     _Out_ LPWSTR **OUs)
355 {
356     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
357     handle_t BindingHandle = NULL;
358     NET_API_STATUS status;
359 
360     TRACE("NetGetJoinableOUs(%s %s %s %s %p %p)\n",
361           debugstr_w(lpServer), debugstr_w(lpDomain), debugstr_w(lpAccount),
362           debugstr_w(lpPassword), OUCount, OUs);
363 
364     /* FIXME */
365 
366     status = NetpBind(lpServer,
367                       &BindingHandle);
368     if (status != NERR_Success)
369     {
370         ERR("NetpBind() failed (status 0x%lx)\n", status);
371         return status;
372     }
373 
374     RpcTryExcept
375     {
376         status = NetrGetJoinableOUs2(BindingHandle,
377                                      (PWSTR)lpServer,
378                                      (PWSTR)lpDomain,
379                                      (PWSTR)lpAccount,
380                                      EncryptedPassword,
381                                      OUCount,
382                                      OUs);
383     }
384     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
385     {
386         status = I_RpcMapWin32Status(RpcExceptionCode());
387     }
388     RpcEndExcept;
389 
390     NetpUnbind(BindingHandle);
391 
392     return status;
393 }
394 
395 
396 NET_API_STATUS
397 WINAPI
398 NetJoinDomain(
399     _In_opt_ LPCWSTR lpServer,
400     _In_ LPCWSTR lpDomain,
401     _In_opt_ LPCWSTR lpAccountOU,
402     _In_opt_ LPCWSTR lpAccount,
403     _In_opt_ LPCWSTR lpPassword,
404     _In_ DWORD fJoinOptions)
405 {
406     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
407     handle_t BindingHandle = NULL;
408     NET_API_STATUS status;
409 
410     FIXME("NetJoinDomain(%s %s %s %s 0x%lx)\n",
411           debugstr_w(lpServer), debugstr_w(lpDomain), debugstr_w(lpAccountOU),
412           debugstr_w(lpAccount), debugstr_w(lpPassword), fJoinOptions);
413 
414     /* FIXME */
415 
416     status = NetpBind(lpServer,
417                       &BindingHandle);
418     if (status != NERR_Success)
419     {
420         ERR("NetpBind() failed (status 0x%lx)\n", status);
421         return status;
422     }
423 
424     RpcTryExcept
425     {
426         status = NetrJoinDomain2(BindingHandle,
427                                  (PWSTR)lpServer,
428                                  (PWSTR)lpDomain,
429                                  (PWSTR)lpAccountOU,
430                                  (PWSTR)lpAccount,
431                                  EncryptedPassword,
432                                  fJoinOptions);
433     }
434     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
435     {
436         RPC_STATUS rpcStatus = RpcExceptionCode();
437         FIXME("Exception 0x%lx\n", rpcStatus);
438         status = I_RpcMapWin32Status(rpcStatus);
439     }
440     RpcEndExcept;
441 
442     NetpUnbind(BindingHandle);
443 
444     return status;
445 }
446 
447 
448 NET_API_STATUS
449 WINAPI
450 NetRemoveAlternateComputerName(
451     _In_opt_ LPCWSTR Server,
452     _In_ LPCWSTR AlternateName,
453     _In_opt_ LPCWSTR DomainAccount,
454     _In_opt_ LPCWSTR DomainAccountPassword,
455     _In_ ULONG Reserved)
456 {
457     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
458     handle_t BindingHandle = NULL;
459     NET_API_STATUS status;
460 
461     TRACE("NetRemoveAlternateComputerName(%s %s %s %s 0x%lx)\n",
462           debugstr_w(Server), debugstr_w(AlternateName), debugstr_w(DomainAccount),
463           debugstr_w(DomainAccountPassword), Reserved);
464 
465     /* FIXME */
466 
467     status = NetpBind(Server,
468                       &BindingHandle);
469     if (status != NERR_Success)
470     {
471         ERR("NetpBind() failed (status 0x%lx)\n", status);
472         return status;
473     }
474 
475     RpcTryExcept
476     {
477         status = NetrRemoveAlternateComputerName(BindingHandle,
478                                                  (PWSTR)Server,
479                                                  (PWSTR)AlternateName,
480                                                  (PWSTR)DomainAccount,
481                                                  EncryptedPassword,
482                                                  Reserved);
483     }
484     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
485     {
486         status = I_RpcMapWin32Status(RpcExceptionCode());
487     }
488     RpcEndExcept;
489 
490     NetpUnbind(BindingHandle);
491 
492     return status;
493 }
494 
495 
496 NET_API_STATUS
497 WINAPI
498 NetRenameMachineInDomain(
499     _In_opt_ LPCWSTR lpServer,
500     _In_opt_ LPCWSTR lpNewMachineName,
501     _In_opt_ LPCWSTR lpAccount,
502     _In_opt_ LPCWSTR lpPassword,
503     _In_ DWORD fRenameOptions)
504 {
505     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
506     handle_t BindingHandle = NULL;
507     NET_API_STATUS status;
508 
509     TRACE("NetRenameMachineInDomain(%s %s %s %s 0x%lx)\n",
510           debugstr_w(lpServer), debugstr_w(lpNewMachineName), debugstr_w(lpAccount),
511           debugstr_w(lpPassword), fRenameOptions);
512 
513     /* FIXME */
514 
515     status = NetpBind(lpServer,
516                       &BindingHandle);
517     if (status != NERR_Success)
518     {
519         ERR("NetpBind() failed (status 0x%lx)\n", status);
520         return status;
521     }
522 
523     RpcTryExcept
524     {
525         status = NetrRenameMachineInDomain2(BindingHandle,
526                                             (PWSTR)lpServer,
527                                             (PWSTR)lpNewMachineName,
528                                             (PWSTR)lpAccount,
529                                             EncryptedPassword,
530                                             fRenameOptions);
531     }
532     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
533     {
534         status = I_RpcMapWin32Status(RpcExceptionCode());
535     }
536     RpcEndExcept;
537 
538     NetpUnbind(BindingHandle);
539 
540     return status;
541 }
542 
543 
544 NET_API_STATUS
545 WINAPI
546 NetSetPrimaryComputerName(
547     _In_opt_ LPCWSTR Server,
548     _In_ LPCWSTR PrimaryName,
549     _In_opt_ LPCWSTR DomainAccount,
550     _In_opt_ LPCWSTR DomainAccountPassword,
551     _In_ ULONG Reserved)
552 {
553     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
554     handle_t BindingHandle = NULL;
555     NET_API_STATUS status;
556 
557     TRACE("NetSetPrimaryComputerName(%s %s %s %s %lu)\n",
558           debugstr_w(Server), debugstr_w(PrimaryName), debugstr_w(DomainAccount),
559           debugstr_w(DomainAccountPassword), Reserved);
560 
561     /* FIXME */
562 
563     status = NetpBind(Server,
564                       &BindingHandle);
565     if (status != NERR_Success)
566     {
567         ERR("NetpBind() failed (status 0x%lx)\n", status);
568         return status;
569     }
570 
571     RpcTryExcept
572     {
573         status = NetrSetPrimaryComputerName(BindingHandle,
574                                             (PWSTR)Server,
575                                             (PWSTR)PrimaryName,
576                                             (PWSTR)DomainAccount,
577                                             EncryptedPassword,
578                                             Reserved);
579     }
580     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
581     {
582         status = I_RpcMapWin32Status(RpcExceptionCode());
583     }
584     RpcEndExcept;
585 
586     NetpUnbind(BindingHandle);
587 
588     return status;
589 }
590 
591 
592 NET_API_STATUS
593 WINAPI
594 NetUnjoinDomain(
595     _In_opt_ LPCWSTR lpServer,
596     _In_opt_ LPCWSTR lpAccount,
597     _In_opt_ LPCWSTR lpPassword,
598     _In_ DWORD fUnjoinOptions)
599 {
600     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
601     handle_t BindingHandle = NULL;
602     NET_API_STATUS status;
603 
604     TRACE("NetUnjoinDomain(%s %s %s %s 0x%lx)\n",
605           debugstr_w(lpServer), debugstr_w(lpAccount),
606           debugstr_w(lpPassword), fUnjoinOptions);
607 
608     /* FIXME */
609 
610     status = NetpBind(lpServer,
611                       &BindingHandle);
612     if (status != NERR_Success)
613     {
614         ERR("NetpBind() failed (status 0x%lx)\n", status);
615         return status;
616     }
617 
618     RpcTryExcept
619     {
620         status = NetrUnjoinDomain2(BindingHandle,
621                                    (PWSTR)lpServer,
622                                    (PWSTR)lpAccount,
623                                    EncryptedPassword,
624                                    fUnjoinOptions);
625     }
626     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
627     {
628         status = I_RpcMapWin32Status(RpcExceptionCode());
629     }
630     RpcEndExcept;
631 
632     NetpUnbind(BindingHandle);
633 
634     return status;
635 }
636 
637 
638 NET_API_STATUS
639 WINAPI
640 NetUseAdd(
641     _In_ LMSTR UncServerName,
642     _In_ DWORD Level,
643     _In_ LPBYTE Buf,
644     _Out_ LPDWORD ParmError)
645 {
646     NET_API_STATUS status;
647 
648     TRACE("NetUseAdd(%s %d %p %p)\n", debugstr_w(UncServerName),
649           Level, Buf, ParmError);
650 
651     RpcTryExcept
652     {
653         status = NetrUseAdd(UncServerName,
654                             Level,
655                             (LPUSE_INFO)Buf,
656                             ParmError);
657     }
658     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
659     {
660         status = I_RpcMapWin32Status(RpcExceptionCode());
661     }
662     RpcEndExcept;
663 
664     return status;
665 }
666 
667 
668 NET_API_STATUS
669 WINAPI
670 NetUseDel(
671     _In_ LMSTR UncServerName,
672     _In_ LMSTR UseName,
673     _In_ DWORD ForceCond)
674 {
675     NET_API_STATUS status;
676 
677     TRACE("NetUseDel(%s %s %d)\n", debugstr_w(UncServerName),
678           debugstr_w(UseName), ForceCond);
679 
680     RpcTryExcept
681     {
682         status = NetrUseDel(UncServerName,
683                             UseName,
684                             ForceCond);
685     }
686     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
687     {
688         status = I_RpcMapWin32Status(RpcExceptionCode());
689     }
690     RpcEndExcept;
691 
692     return status;
693 }
694 
695 
696 NET_API_STATUS
697 WINAPI
698 NetUseEnum(
699     _In_ LMSTR UncServerName,
700     _In_ DWORD Level,
701     _Out_ LPBYTE *BufPtr,
702     _In_ DWORD PreferedMaximumSize,
703     _Out_ LPDWORD EntriesRead,
704     _Out_ LPDWORD TotalEntries,
705     _Inout_ LPDWORD ResumeHandle)
706 {
707     USE_ENUM_STRUCT UseEnumInfo;
708     USE_INFO_0_CONTAINER Container0;
709     USE_INFO_1_CONTAINER Container1;
710     USE_INFO_2_CONTAINER Container2;
711     NET_API_STATUS status;
712 
713     TRACE("NetUseEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(UncServerName),
714           Level, BufPtr, PreferedMaximumSize, EntriesRead, TotalEntries, ResumeHandle);
715 
716     UseEnumInfo.Level = Level;
717     switch (Level)
718     {
719         case 0:
720             UseEnumInfo.UseInfo.Level0 = &Container0;
721             Container0.EntriesRead = 0;
722             Container0.Buffer = NULL;
723             break;
724 
725         case 1:
726             UseEnumInfo.UseInfo.Level1 = &Container1;
727             Container1.EntriesRead = 0;
728             Container1.Buffer = NULL;
729             break;
730 
731         case 2:
732             UseEnumInfo.UseInfo.Level2 = &Container2;
733             Container2.EntriesRead = 0;
734             Container2.Buffer = NULL;
735             break;
736 
737         default:
738             return ERROR_INVALID_PARAMETER;
739     }
740 
741     RpcTryExcept
742     {
743         status = NetrUseEnum(UncServerName,
744                              &UseEnumInfo,
745                              PreferedMaximumSize,
746                              TotalEntries,
747                              ResumeHandle);
748         if (status == NERR_Success || status == ERROR_MORE_DATA)
749         {
750             switch (Level)
751             {
752                 case 0:
753                     *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level0->Buffer;
754                     *EntriesRead = UseEnumInfo.UseInfo.Level0->EntriesRead;
755                     break;
756 
757                 case 1:
758                     *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level1->Buffer;
759                     *EntriesRead = UseEnumInfo.UseInfo.Level1->EntriesRead;
760                     break;
761 
762                 case 2:
763                     *BufPtr = (LPBYTE)UseEnumInfo.UseInfo.Level2->Buffer;
764                     *EntriesRead = UseEnumInfo.UseInfo.Level2->EntriesRead;
765                     break;
766             }
767         }
768     }
769     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
770     {
771         status = I_RpcMapWin32Status(RpcExceptionCode());
772     }
773     RpcEndExcept;
774 
775     return status;
776 }
777 
778 
779 NET_API_STATUS
780 WINAPI
781 NetUseGetInfo(
782     _In_ LMSTR UncServerName,
783     _In_ LMSTR UseName,
784     _In_ DWORD Level,
785     _Out_ LPBYTE *BufPtr)
786 {
787     NET_API_STATUS status;
788 
789     TRACE("NetUseGetInfo(%s, %s, %d, %p)\n", debugstr_w(UncServerName),
790           debugstr_w(UseName), Level, BufPtr);
791 
792     *BufPtr = NULL;
793 
794     RpcTryExcept
795     {
796         status = NetrUseGetInfo(UncServerName,
797                                 UseName,
798                                 Level,
799                                 (LPUSE_INFO)BufPtr);
800     }
801     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
802     {
803         status = I_RpcMapWin32Status(RpcExceptionCode());
804     }
805     RpcEndExcept;
806 
807     return status;
808 }
809 
810 
811 NET_API_STATUS
812 WINAPI
813 NetValidateName(
814     _In_opt_ LPCWSTR lpServer,
815     _In_ LPCWSTR lpName,
816     _In_opt_ LPCWSTR lpAccount,
817     _In_opt_ LPCWSTR lpPassword,
818     _In_ NETSETUP_NAME_TYPE NameType)
819 {
820     PJOINPR_ENCRYPTED_USER_PASSWORD EncryptedPassword = NULL;
821     handle_t BindingHandle = NULL;
822     NET_API_STATUS status;
823 
824     TRACE("NetValidateName(%s %s %s %s %u)\n",
825           debugstr_w(lpServer), debugstr_w(lpName), debugstr_w(lpAccount),
826           debugstr_w(lpPassword), NameType);
827 
828     /* FIXME */
829 
830     status = NetpBind(lpServer,
831                       &BindingHandle);
832     if (status != NERR_Success)
833     {
834         ERR("NetpBind() failed (status 0x%lx)\n", status);
835         return status;
836     }
837 
838     RpcTryExcept
839     {
840         status = NetrValidateName2(BindingHandle,
841                                    (PWSTR)lpServer,
842                                    (PWSTR)lpName,
843                                    (PWSTR)lpAccount,
844                                    EncryptedPassword,
845                                    NameType);
846     }
847     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
848     {
849         status = I_RpcMapWin32Status(RpcExceptionCode());
850     }
851     RpcEndExcept;
852 
853     NetpUnbind(BindingHandle);
854 
855     return status;
856 }
857 
858 
859 NET_API_STATUS
860 WINAPI
861 NetWkstaGetInfo(
862     _In_ LPWSTR servername,
863     _In_ DWORD level,
864     _Out_ LPBYTE *bufptr)
865 {
866     NET_API_STATUS status;
867 
868     TRACE("NetWkstaGetInfo(%s, %d, %p)\n",
869           debugstr_w(servername), level, bufptr);
870 
871     if (bufptr == NULL)
872         return ERROR_INVALID_PARAMETER;
873 
874     *bufptr = NULL;
875 
876     RpcTryExcept
877     {
878         status = NetrWkstaGetInfo(servername,
879                                   level,
880                                   (LPWKSTA_INFO*)bufptr);
881     }
882     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
883     {
884         status = I_RpcMapWin32Status(RpcExceptionCode());
885     }
886     RpcEndExcept;
887 
888     return status;
889 }
890 
891 
892 NET_API_STATUS
893 WINAPI
894 NetWkstaSetInfo(
895     _In_ LPWSTR servername,
896     _In_ DWORD level,
897     _In_ LPBYTE buffer,
898     _Out_ LPDWORD parm_err)
899 {
900     NET_API_STATUS status;
901 
902     TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n",
903           debugstr_w(servername), level, buffer, parm_err);
904 
905     RpcTryExcept
906     {
907         status = NetrWkstaSetInfo(servername,
908                                   level,
909                                   (LPWKSTA_INFO)buffer,
910                                   parm_err);
911     }
912     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
913     {
914         status = I_RpcMapWin32Status(RpcExceptionCode());
915     }
916     RpcEndExcept;
917 
918     return status;
919 }
920 
921 
922 NET_API_STATUS
923 WINAPI
924 NetWkstaTransportAdd(
925     _In_opt_ LPWSTR servername,
926     _In_ DWORD level,
927     _In_ LPBYTE buf,
928     _Out_ LPDWORD parm_err)
929 {
930     NET_API_STATUS status;
931 
932     TRACE("NetWkstaTransportAdd(%s, %d, %p, %p)\n", debugstr_w(servername),
933           level, buf, parm_err);
934 
935     RpcTryExcept
936     {
937         status = NetrWkstaTransportAdd(servername,
938                                        level,
939                                        (LPWKSTA_TRANSPORT_INFO_0)buf,
940                                        parm_err);
941     }
942     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
943     {
944         status = I_RpcMapWin32Status(RpcExceptionCode());
945     }
946     RpcEndExcept;
947 
948     return status;
949 }
950 
951 
952 NET_API_STATUS
953 WINAPI
954 NetWkstaTransportDel(
955     _In_opt_ LPWSTR servername,
956     _In_ LPWSTR transportname,
957     _In_ DWORD ucond)
958 {
959     NET_API_STATUS status;
960 
961     TRACE("NetWkstaTransportDel(%s, %s, %d)\n", debugstr_w(servername),
962           debugstr_w(transportname), ucond);
963 
964     RpcTryExcept
965     {
966         status = NetrWkstaTransportDel(servername,
967                                        transportname,
968                                        ucond);
969     }
970     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
971     {
972         status = I_RpcMapWin32Status(RpcExceptionCode());
973     }
974     RpcEndExcept;
975 
976     return status;
977 }
978 
979 
980 #if 0
981 NET_API_STATUS
982 WINAPI
983 NetWkstaTransportEnum(
984     _In_opt_ LPWSTR servername,
985     _In_ DWORD level,
986     _Out_ LPBYTE *bufptr,
987     _In_ DWORD prefmaxlen,
988     _Out_ LPDWORD entriesread,
989     _Out_ LPDWORD totalentries,
990     _Inout_ LPDWORD resumehandle)
991 {
992     WKSTA_TRANSPORT_ENUM_STRUCT TransportEnumInfo;
993     WKSTA_TRANSPORT_INFO_0_CONTAINER Container0;
994     NET_API_STATUS status;
995 
996     TRACE("NetWkstaTransportEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
997           level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
998 
999     TransportEnumInfo.Level = level;
1000     switch (level)
1001     {
1002         case 0:
1003             TransportEnumInfo.WkstaTransportInfo.Level0 = &Container0;
1004             Container0.EntriesRead = 0;
1005             Container0.Buffer = NULL;
1006             break;
1007 
1008         default:
1009             return ERROR_INVALID_PARAMETER;
1010     }
1011 
1012     RpcTryExcept
1013     {
1014         status = NetrWkstaTransportEnum(servername,
1015                                         &TransportEnumInfo,
1016                                         prefmaxlen,
1017                                         totalentries,
1018                                         resumehandle);
1019         if (status == NERR_Success || status == ERROR_MORE_DATA)
1020         {
1021             switch (level)
1022             {
1023                 case 0:
1024                     *bufptr = (LPBYTE)TransportEnumInfo.WkstaTransportInfo.Level0->Buffer;
1025                     *entriesread = TransportEnumInfo.WkstaTransportInfo.Level0->EntriesRead;
1026                     break;
1027             }
1028         }
1029     }
1030     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1031     {
1032         status = I_RpcMapWin32Status(RpcExceptionCode());
1033     }
1034     RpcEndExcept;
1035 
1036     return status;
1037 }
1038 #endif
1039 
1040 
1041 NET_API_STATUS
1042 WINAPI
1043 NetWkstaUserEnum(
1044     _In_ LPWSTR servername,
1045     _In_ DWORD level,
1046     _Out_ LPBYTE *bufptr,
1047     _In_ DWORD prefmaxlen,
1048     _Out_ LPDWORD entriesread,
1049     _Out_ LPDWORD totalentries,
1050     _Inout_ LPDWORD resumehandle)
1051 {
1052     WKSTA_USER_ENUM_STRUCT UserEnumInfo;
1053     WKSTA_USER_INFO_0_CONTAINER Container0;
1054     WKSTA_USER_INFO_1_CONTAINER Container1;
1055     NET_API_STATUS status;
1056 
1057     TRACE("NetWkstaUserEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
1058           level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
1059 
1060     UserEnumInfo.Level = level;
1061     switch (level)
1062     {
1063         case 0:
1064             UserEnumInfo.WkstaUserInfo.Level0 = &Container0;
1065             Container0.EntriesRead = 0;
1066             Container0.Buffer = NULL;
1067             break;
1068 
1069         case 1:
1070             UserEnumInfo.WkstaUserInfo.Level1 = &Container1;
1071             Container1.EntriesRead = 0;
1072             Container1.Buffer = NULL;
1073             break;
1074 
1075         default:
1076             return ERROR_INVALID_PARAMETER;
1077     }
1078 
1079     RpcTryExcept
1080     {
1081         status = NetrWkstaUserEnum(servername,
1082                                    &UserEnumInfo,
1083                                    prefmaxlen,
1084                                    totalentries,
1085                                    resumehandle);
1086         if (status == NERR_Success || status == ERROR_MORE_DATA)
1087         {
1088             switch (level)
1089             {
1090                 case 0:
1091                     *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level0->Buffer;
1092                     *entriesread = UserEnumInfo.WkstaUserInfo.Level0->EntriesRead;
1093                     break;
1094 
1095                 case 1:
1096                     *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level1->Buffer;
1097                     *entriesread = UserEnumInfo.WkstaUserInfo.Level1->EntriesRead;
1098                     break;
1099             }
1100         }
1101     }
1102     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1103     {
1104         status = I_RpcMapWin32Status(RpcExceptionCode());
1105     }
1106     RpcEndExcept;
1107 
1108     return status;
1109 }
1110 
1111 
1112 #if 0
1113 NET_API_STATUS
1114 WINAPI
1115 NetWkstaUserGetInfo(
1116     LPWSTR reserved,
1117     _In_ DWORD level,
1118     _Out_ PBYTE *bufptr)
1119 {
1120     NET_API_STATUS status;
1121 
1122     TRACE("NetWkstaUserGetInfo(%s, %d, %p)\n",
1123           debugstr_w(reserved), level, bufptr);
1124 
1125     if (reserved != NULL)
1126         return ERROR_INVALID_PARAMETER;
1127 
1128     *bufptr = NULL;
1129 
1130     RpcTryExcept
1131     {
1132         status = NetrWkstaUserGetInfo(NULL,
1133                                       level,
1134                                       (LPWKSTA_USER_INFO)bufptr);
1135     }
1136     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1137     {
1138         status = I_RpcMapWin32Status(RpcExceptionCode());
1139     }
1140     RpcEndExcept;
1141 
1142     return status;
1143 }
1144 #endif
1145 
1146 
1147 NET_API_STATUS
1148 WINAPI
1149 NetWkstaUserSetInfo(
1150     LPWSTR reserved,
1151     _In_ DWORD level,
1152     _In_ LPBYTE buf,
1153     _Out_ LPDWORD parm_err)
1154 {
1155     NET_API_STATUS status;
1156 
1157     TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n",
1158           debugstr_w(reserved), level, buf, parm_err);
1159 
1160     if (reserved != NULL)
1161         return ERROR_INVALID_PARAMETER;
1162 
1163     RpcTryExcept
1164     {
1165        status = NetrWkstaUserSetInfo(NULL,
1166                                      level,
1167                                      (LPWKSTA_USER_INFO)&buf,
1168                                      parm_err);
1169     }
1170     RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1171     {
1172         status = I_RpcMapWin32Status(RpcExceptionCode());
1173     }
1174     RpcEndExcept;
1175 
1176     return status;
1177 }
1178 
1179 /* EOF */
1180