[INCLUDE]
[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", wine_dbgstr_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 NetWkstaGetInfo(
175 LPWSTR servername,
176 DWORD level,
177 LPBYTE *bufptr)
178 {
179 NET_API_STATUS status;
180
181 TRACE("NetWkstaGetInfo(%s, %d, %p)\n", debugstr_w(servername),
182 level, bufptr);
183
184 *bufptr = NULL;
185
186 RpcTryExcept
187 {
188 status = NetrWkstaGetInfo(servername,
189 level,
190 (LPWKSTA_INFO)bufptr);
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 NetWkstaSetInfo(
205 LPWSTR servername,
206 DWORD level,
207 LPBYTE buffer,
208 LPDWORD parm_err)
209 {
210 NET_API_STATUS status;
211
212 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(servername),
213 level, buffer, parm_err);
214
215 RpcTryExcept
216 {
217 status = NetrWkstaSetInfo(servername,
218 level,
219 (LPWKSTA_INFO)buffer,
220 parm_err);
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 NetWkstaUserEnum(
235 LMSTR servername,
236 DWORD level,
237 LPBYTE *bufptr,
238 DWORD prefmaxlen,
239 LPDWORD entriesread,
240 LPDWORD totalentries,
241 LPDWORD resumehandle)
242 {
243 WKSTA_USER_ENUM_STRUCT UserEnumInfo;
244 WKSTA_USER_INFO_0_CONTAINER Level0;
245 WKSTA_USER_INFO_1_CONTAINER Level1;
246 NET_API_STATUS status;
247
248 TRACE("NetWkstaUserEnum(%s, %d, %p, %d, %p, %p, %p)\n", debugstr_w(servername),
249 level, bufptr, prefmaxlen, entriesread, totalentries, resumehandle);
250
251 UserEnumInfo.Level = level;
252 switch (level)
253 {
254 case 0:
255 UserEnumInfo.WkstaUserInfo.Level0 = &Level0;
256 UserEnumInfo.WkstaUserInfo.Level0->EntriesRead = 0;
257 UserEnumInfo.WkstaUserInfo.Level0->Buffer = NULL;
258 break;
259
260 case 1:
261 UserEnumInfo.WkstaUserInfo.Level1 = &Level1;
262 UserEnumInfo.WkstaUserInfo.Level1->EntriesRead = 0;
263 UserEnumInfo.WkstaUserInfo.Level1->Buffer = NULL;
264 break;
265
266 default:
267 return ERROR_INVALID_PARAMETER;
268 }
269
270 RpcTryExcept
271 {
272 status = NetrWkstaUserEnum(servername,
273 &UserEnumInfo,
274 prefmaxlen,
275 totalentries,
276 resumehandle);
277 if (status == NERR_Success || status == ERROR_MORE_DATA)
278 {
279 switch (level)
280 {
281 case 0:
282 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level0->Buffer;
283 *entriesread = UserEnumInfo.WkstaUserInfo.Level0->EntriesRead;
284 break;
285
286 case 1:
287 *bufptr = (LPBYTE)UserEnumInfo.WkstaUserInfo.Level1->Buffer;
288 *entriesread = UserEnumInfo.WkstaUserInfo.Level1->EntriesRead;
289 break;
290 }
291 }
292 }
293 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
294 {
295 status = I_RpcMapWin32Status(RpcExceptionCode());
296 }
297 RpcEndExcept;
298
299 return status;
300 }
301
302
303 NET_API_STATUS
304 WINAPI
305 NetWkstaUserGetInfo(
306 LPWSTR reserved,
307 DWORD level,
308 PBYTE *bufptr)
309 {
310 NET_API_STATUS status;
311
312 TRACE("NetWkstaUserGetInfo(%s, %d, %p)\n", debugstr_w(reserved),
313 level, bufptr);
314
315 if (reserved != NULL)
316 return ERROR_INVALID_PARAMETER;
317
318 *bufptr = NULL;
319
320 RpcTryExcept
321 {
322 status = NetrWkstaUserGetInfo(NULL,
323 level,
324 (LPWKSTA_USER_INFO)bufptr);
325 }
326 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
327 {
328 status = I_RpcMapWin32Status(RpcExceptionCode());
329 }
330 RpcEndExcept;
331
332 return status;
333 }
334
335
336 NET_API_STATUS
337 WINAPI
338 NetWkstaUserSetInfo(
339 LPWSTR reserved,
340 DWORD level,
341 LPBYTE buf,
342 LPDWORD parm_err)
343 {
344 NET_API_STATUS status;
345
346 TRACE("NetWkstaSetInfo(%s, %d, %p, %p)\n", debugstr_w(reserved),
347 level, buf, parm_err);
348
349 if (reserved != NULL)
350 return ERROR_INVALID_PARAMETER;
351
352 RpcTryExcept
353 {
354 status = NetrWkstaUserSetInfo(NULL,
355 level,
356 (LPWKSTA_USER_INFO)&buf,
357 parm_err);
358 }
359 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
360 {
361 status = I_RpcMapWin32Status(RpcExceptionCode());
362 }
363 RpcEndExcept;
364
365 return status;
366 }
367
368 /* EOF */