[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 NetWkstaUserEnum(
408 LMSTR servername,
409 DWORD level,
410 LPBYTE *bufptr,
411 DWORD prefmaxlen,
412 LPDWORD entriesread,
413 LPDWORD totalentries,
414 LPDWORD resumehandle)
415 {
416 WKSTA_USER_ENUM_STRUCT UserEnumInfo;
417 WKSTA_USER_INFO_0_CONTAINER Container0;
418 WKSTA_USER_INFO_1_CONTAINER Container1;
419 NET_API_STATUS status;
420
421 TRACE("NetWkstaUserEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
422 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
423
424 UserEnumInfo.Level = level;
425 switch (level)
426 {
427 case 0:
428 UserEnumInfo.WkstaUserInfo.Level0 = &Container0;
429 Container0.EntriesRead = 0;
430 Container0.Buffer = NULL;
431 break;
432
433 case 1:
434 UserEnumInfo.WkstaUserInfo.Level1 = &Container1;
435 Container1.EntriesRead = 0;
436 Container1.Buffer = NULL;
437 break;
438
439 default:
440 return ERROR_INVALID_PARAMETER;
441 }
442
443 RpcTryExcept
444 {
445 status = NetrWkstaUserEnum(servername,
446 &UserEnumInfo,
447 prefmaxlen,
448 totalentries,
449 resumehandle);
450 if (status == NERR_Success || status == ERROR_MORE_DATA)
451 {
452 switch (level)
453 {
454 case 0:
455 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level0->Buffer;
456 *entriesread = UserEnumInfo.WkstaUserInfo.Level0->EntriesRead;
457 break;
458
459 case 1:
460 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level1->Buffer;
461 *entriesread = UserEnumInfo.WkstaUserInfo.Level1->EntriesRead;
462 break;
463 }
464 }
465 }
466 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
467 {
468 status = I_RpcMapWin32Status(RpcExceptionCode());
469 }
470 RpcEndExcept;
471
472 return status;
473 }
474
475
476 NET_API_STATUS
477 WINAPI
478 NetWkstaUserGetInfo(
479 LPWSTR reserved,
480 DWORD level,
481 PBYTE *bufptr)
482 {
483 NET_API_STATUS status;
484
485 TRACE("NetWkstaUserGetInfo(%s, %d, %p)\n", debugstr_w(reserved),
486 level, bufptr);
487
488 if (reserved != NULL)
489 return ERROR_INVALID_PARAMETER;
490
491 *bufptr = NULL;
492
493 RpcTryExcept
494 {
495 status = NetrWkstaUserGetInfo(NULL,
496 level,
497 (LPWKSTA_USER_INFO)bufptr);
498 }
499 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
500 {
501 status = I_RpcMapWin32Status(RpcExceptionCode());
502 }
503 RpcEndExcept;
504
505 return status;
506 }
507
508
509 NET_API_STATUS
510 WINAPI
511 NetWkstaUserSetInfo(
512 LPWSTR reserved,
513 DWORD level,
514 LPBYTE buf,
515 LPDWORD parm_err)
516 {
517 NET_API_STATUS status;
518
519 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(reserved),
520 level, buf, parm_err);
521
522 if (reserved != NULL)
523 return ERROR_INVALID_PARAMETER;
524
525 RpcTryExcept
526 {
527 status = NetrWkstaUserSetInfo(NULL,
528 level,
529 (LPWKSTA_USER_INFO)&buf,
530 parm_err);
531 }
532 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
533 {
534 status = I_RpcMapWin32Status(RpcExceptionCode());
535 }
536 RpcEndExcept;
537
538 return status;
539 }
540
541 /* EOF */