1 | /* $Id: server.cpp,v 1.1 2001-09-06 22:23:40 phaller Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * NETAPI32 stubs
|
---|
10 | *
|
---|
11 | * Copyright 1998 Patrick Haller
|
---|
12 | *
|
---|
13 | * Note: functions that return structures/buffers seem to append strings
|
---|
14 | * at the end of the buffer. Currently, we just allocate the strings
|
---|
15 | * "normally". Therefore a caller that just does a NetApiBufferFree() on the
|
---|
16 | * returned buffer will leak all allocated strings.
|
---|
17 | *
|
---|
18 | */
|
---|
19 |
|
---|
20 |
|
---|
21 | /****************************************************************************
|
---|
22 | * Includes *
|
---|
23 | ****************************************************************************/
|
---|
24 |
|
---|
25 | #include <odin.h>
|
---|
26 | #include <odinwrap.h>
|
---|
27 | #include <os2win.h>
|
---|
28 | #include <misc.h>
|
---|
29 | #include <unicode.h>
|
---|
30 | #include <heapstring.h>
|
---|
31 | #include <string.h>
|
---|
32 | #include <winconst.h>
|
---|
33 |
|
---|
34 | #include "oslibnet.h"
|
---|
35 | #include "lanman.h"
|
---|
36 |
|
---|
37 | ODINDEBUGCHANNEL(WNETAP32-SERVER)
|
---|
38 |
|
---|
39 |
|
---|
40 | /****************************************************************************
|
---|
41 | * Module Global Variables *
|
---|
42 | ****************************************************************************/
|
---|
43 |
|
---|
44 |
|
---|
45 | /*****************************************************************************
|
---|
46 | * Name : NET_API_STATUS NetServerDiskEnum
|
---|
47 | * Purpose :
|
---|
48 | * Parameters: LPWSTR servername
|
---|
49 | * DWORD level
|
---|
50 | * LPBYTE *bufptr
|
---|
51 | * DWORD prefmaxlen
|
---|
52 | * LPDWORD entriesread
|
---|
53 | * LPDWORD totalentries
|
---|
54 | * LPDWORD resume_handle
|
---|
55 | * Variables :
|
---|
56 | * Result :
|
---|
57 | * Remark :
|
---|
58 | * Status : UNTESTED STUB
|
---|
59 | *
|
---|
60 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
61 | *
|
---|
62 | * Author : Markus Montkowski [09.07.98 21:56:38]
|
---|
63 | *****************************************************************************/
|
---|
64 | ODINFUNCTION7(NET_API_STATUS, OS2NetServerDiskEnum,
|
---|
65 | LPWSTR, servername,
|
---|
66 | DWORD, level,
|
---|
67 | LPBYTE *, bufptr,
|
---|
68 | DWORD, prefmaxlen,
|
---|
69 | LPDWORD, lpdwEntriesRead,
|
---|
70 | LPDWORD, lpdwTotalEntries,
|
---|
71 | LPDWORD, resume_handle)
|
---|
72 |
|
---|
73 | {
|
---|
74 |
|
---|
75 | dprintf(("NETAPI32: NetServerDiskEnum(%s) not implemented\n",
|
---|
76 | servername));
|
---|
77 |
|
---|
78 | return (NERR_BASE);
|
---|
79 | }
|
---|
80 | /*****************************************************************************
|
---|
81 | * Name : NET_API_STATUS NetServerEnum
|
---|
82 | * Purpose :
|
---|
83 | * Parameters: LPWSTR servername
|
---|
84 | * DWORD level
|
---|
85 | * LPBYTE *bufptr
|
---|
86 | * DWORD prefmaxlen
|
---|
87 | * LPDWORD entriesread
|
---|
88 | * LPDWORD totalentries
|
---|
89 | * DWORD servertype
|
---|
90 | * LPWSTR domain
|
---|
91 | * LPDWORD resume_handle
|
---|
92 | * Variables :
|
---|
93 | * Result :
|
---|
94 | * Remark :
|
---|
95 | * Status : UNTESTED STUB
|
---|
96 | *
|
---|
97 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
98 | *
|
---|
99 | * Author : Patrick Haller [2001-09-06]
|
---|
100 | *****************************************************************************/
|
---|
101 | ODINFUNCTION9(NET_API_STATUS, OS2NetServerEnum,
|
---|
102 | LPWSTR, lpServerName,
|
---|
103 | DWORD, dwLevel,
|
---|
104 | LPBYTE *, bufptr,
|
---|
105 | DWORD, prefmaxlen,
|
---|
106 | LPDWORD, lpdwEntriesRead,
|
---|
107 | LPDWORD, lpdwTotalEntries,
|
---|
108 | DWORD, dwServerType,
|
---|
109 | LPWSTR, lpDomain,
|
---|
110 | LPDWORD, resume_handle)
|
---|
111 |
|
---|
112 | {
|
---|
113 | // convert information modes!
|
---|
114 | ULONG ulOS2Level = dwLevel; // can be 100 and 101
|
---|
115 | switch (dwLevel)
|
---|
116 | {
|
---|
117 | case 100: ulOS2Level = 1; break;
|
---|
118 | case 101: ulOS2Level = 1; break;
|
---|
119 | default: ulOS2Level = 1; break;
|
---|
120 | }
|
---|
121 |
|
---|
122 | // 2001-09-05 PH doc says the SV_TYPE_ definitions from
|
---|
123 | // LanMan and NT are identical.
|
---|
124 | int iOS2ServerType = dwServerType;
|
---|
125 |
|
---|
126 | // Convert servername to ASCII
|
---|
127 | // Convert domain to ASCII
|
---|
128 | char *asciiServername = NULL;
|
---|
129 | char *asciiDomain = NULL;
|
---|
130 |
|
---|
131 | if (lpServerName)
|
---|
132 | asciiServername = UnicodeToAsciiString(lpServerName);
|
---|
133 |
|
---|
134 | if (lpDomain)
|
---|
135 | asciiDomain = UnicodeToAsciiString(lpDomain);
|
---|
136 |
|
---|
137 | dprintf(("WNETAP32: NetServerEnum server=[%s], domain=[%s]\n",
|
---|
138 | asciiServername,
|
---|
139 | asciiDomain));
|
---|
140 |
|
---|
141 | ULONG ulBytesAvailable;
|
---|
142 | DWORD rc;
|
---|
143 |
|
---|
144 | // determine required size of buffer
|
---|
145 | char pOS2Buffer[8192];
|
---|
146 | ULONG ulBufferLength = sizeof(pOS2Buffer);
|
---|
147 | ULONG ulEntriesRead;
|
---|
148 | ULONG ulEntriesTotal;
|
---|
149 | rc = OSLibNetServerEnum((const unsigned char*)asciiServername,
|
---|
150 | ulOS2Level,
|
---|
151 | (unsigned char*)pOS2Buffer,
|
---|
152 | ulBufferLength,
|
---|
153 | &ulEntriesRead,
|
---|
154 | &ulEntriesTotal,
|
---|
155 | dwServerType,
|
---|
156 | (unsigned char*)asciiDomain);
|
---|
157 |
|
---|
158 | if (asciiServername) FreeAsciiString(asciiServername);
|
---|
159 | if (asciiDomain) FreeAsciiString(asciiDomain);
|
---|
160 |
|
---|
161 | // convert the structures
|
---|
162 | switch (dwLevel)
|
---|
163 | {
|
---|
164 | case 100:
|
---|
165 | {
|
---|
166 | PSERVER_INFO_100 psiw0;
|
---|
167 | struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
|
---|
168 | ULONG ulConvertedEntries = 0;
|
---|
169 | ULONG ulSpace = 0;
|
---|
170 | ULONG ulAllocated = 0;
|
---|
171 | ULONG ulEntriesConvertable = 0;
|
---|
172 | BOOLEAN flagMoreData = FALSE;
|
---|
173 |
|
---|
174 | // allocate as much memory as required or
|
---|
175 | // the amount specified in "prefmaxlen"
|
---|
176 |
|
---|
177 | // we need to calculate the overall size of all returned entries
|
---|
178 | for (ULONG i = 0;
|
---|
179 | i < *lpdwEntriesRead;
|
---|
180 | i++)
|
---|
181 | {
|
---|
182 | ulSpace += sizeof(SERVER_INFO_100);
|
---|
183 | ulSpace += (strlen( (const char*) pOS2ssi1->sv1_name) + 1) * 2;
|
---|
184 |
|
---|
185 | // count how many entries we can convert
|
---|
186 | if (ulSpace < prefmaxlen)
|
---|
187 | ulEntriesConvertable++;
|
---|
188 | else
|
---|
189 | flagMoreData = TRUE;
|
---|
190 | }
|
---|
191 | // ulSpace now contains the number of bytes required for the overall structure
|
---|
192 | // ulEntriesConvertable contains the number of entries that fit in the target buffer
|
---|
193 |
|
---|
194 | ulAllocated = min(ulSpace, prefmaxlen);
|
---|
195 |
|
---|
196 | // reset the structure pointer
|
---|
197 | pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
|
---|
198 |
|
---|
199 | rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw0);
|
---|
200 | if (!rc)
|
---|
201 | {
|
---|
202 | // zero out the memory
|
---|
203 | memset(psiw0, 0, ulAllocated);
|
---|
204 |
|
---|
205 | // set data pointer "behind" the converted entries
|
---|
206 | // that's where the strings are placed
|
---|
207 | PBYTE pbData = (PBYTE)psiw0 + ulEntriesConvertable * sizeof(PSERVER_INFO_100);
|
---|
208 |
|
---|
209 | for (;
|
---|
210 | ulConvertedEntries < ulEntriesConvertable;
|
---|
211 | ulConvertedEntries++)
|
---|
212 | {
|
---|
213 | // convert that single structure
|
---|
214 | psiw0->sv100_platform_id = 0; // @@@PH unavailable?
|
---|
215 | lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name );
|
---|
216 | psiw0->sv100_name = (LPWSTR)pbData;
|
---|
217 |
|
---|
218 | // advance to next free data slot
|
---|
219 | pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
|
---|
220 |
|
---|
221 | // skip to the next entry
|
---|
222 | pOS2ssi1++;
|
---|
223 | psiw0++;
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | // write back actual number of converted entries
|
---|
228 | // (as place fits in the target buffer)
|
---|
229 | *lpdwEntriesRead = ulConvertedEntries;
|
---|
230 |
|
---|
231 | // check if there would have been more data
|
---|
232 | if (flagMoreData)
|
---|
233 | rc = ERROR_MORE_DATA_W;
|
---|
234 |
|
---|
235 | break;
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | case 101:
|
---|
240 | {
|
---|
241 | PSERVER_INFO_101 psiw1;
|
---|
242 | struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
|
---|
243 | ULONG ulConvertedEntries = 0;
|
---|
244 | ULONG ulSpace = 0;
|
---|
245 | ULONG ulAllocated = 0;
|
---|
246 | ULONG ulEntriesConvertable = 0;
|
---|
247 | BOOLEAN flagMoreData = FALSE;
|
---|
248 |
|
---|
249 | // allocate as much memory as required or
|
---|
250 | // the amount specified in "prefmaxlen"
|
---|
251 |
|
---|
252 | // we need to calculate the overall size of all returned entries
|
---|
253 | for (ULONG i = 0;
|
---|
254 | i < *lpdwEntriesRead;
|
---|
255 | i++)
|
---|
256 | {
|
---|
257 | ulSpace += sizeof(SERVER_INFO_101);
|
---|
258 | ulSpace += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
|
---|
259 | ulSpace += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
|
---|
260 |
|
---|
261 | // count how many entries we can convert
|
---|
262 | if (ulSpace < prefmaxlen)
|
---|
263 | ulEntriesConvertable++;
|
---|
264 | else
|
---|
265 | flagMoreData = TRUE;
|
---|
266 | }
|
---|
267 | // ulSpace now contains the number of bytes required for the overall structure
|
---|
268 | // ulEntriesConvertable contains the number of entries that fit in the target buffer
|
---|
269 |
|
---|
270 | ulAllocated = min(ulSpace, prefmaxlen);
|
---|
271 |
|
---|
272 | // reset the structure pointer
|
---|
273 | pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
|
---|
274 |
|
---|
275 | rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw1);
|
---|
276 | if (!rc)
|
---|
277 | {
|
---|
278 | // zero out the memory
|
---|
279 | memset(psiw1, 0, ulAllocated);
|
---|
280 |
|
---|
281 | // set data pointer "behind" the converted entries
|
---|
282 | // that's where the strings are placed
|
---|
283 | PBYTE pbData = (PBYTE)psiw1 + ulEntriesConvertable * sizeof(PSERVER_INFO_101);
|
---|
284 |
|
---|
285 | for (;
|
---|
286 | ulConvertedEntries < ulEntriesConvertable;
|
---|
287 | ulConvertedEntries++)
|
---|
288 | {
|
---|
289 | // convert that single structure
|
---|
290 | psiw1->sv101_platform_id = 0; // @@@PH unavailable?
|
---|
291 | lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name);
|
---|
292 | psiw1->sv101_name = (LPWSTR)pbData;
|
---|
293 | pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
|
---|
294 |
|
---|
295 | lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_comment);
|
---|
296 | psiw1->sv101_comment = (LPWSTR)pbData;
|
---|
297 | pbData += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
|
---|
298 |
|
---|
299 | psiw1->sv101_version_major = pOS2ssi1->sv1_version_major;
|
---|
300 | psiw1->sv101_version_minor = pOS2ssi1->sv1_version_minor;
|
---|
301 | psiw1->sv101_type = pOS2ssi1->sv1_type;
|
---|
302 |
|
---|
303 | // skip to the next entry
|
---|
304 | pOS2ssi1++;
|
---|
305 | psiw1++;
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | // write back actual number of converted entries
|
---|
310 | // (as place fits in the target buffer)
|
---|
311 | *lpdwEntriesRead = ulConvertedEntries;
|
---|
312 |
|
---|
313 | // check if there would have been more data
|
---|
314 | if (flagMoreData)
|
---|
315 | rc = ERROR_MORE_DATA_W;
|
---|
316 |
|
---|
317 | break;
|
---|
318 | }
|
---|
319 |
|
---|
320 |
|
---|
321 | }
|
---|
322 |
|
---|
323 | return (rc);
|
---|
324 |
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | /*****************************************************************************
|
---|
329 | * Name : NET_API_STATUS NetServerGetInfo
|
---|
330 | * Purpose :
|
---|
331 | * Parameters: LPWSTR servername
|
---|
332 | * DWORD level
|
---|
333 | * LPBYTE *bufptr
|
---|
334 | * Variables :
|
---|
335 | * Result :
|
---|
336 | * Remark :
|
---|
337 | * Status : UNTESTED STUB
|
---|
338 | *
|
---|
339 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
340 | *
|
---|
341 | * Author : Markus Montkowski [09.07.98 21:57:43]
|
---|
342 | *****************************************************************************/
|
---|
343 | ODINFUNCTION3(NET_API_STATUS, OS2NetServerGetInfo,
|
---|
344 | LPWSTR, servername,
|
---|
345 | DWORD, level,
|
---|
346 | LPBYTE *, bufptr)
|
---|
347 |
|
---|
348 | {
|
---|
349 |
|
---|
350 | dprintf(("NETAPI32: NetServerGetInfo(%s, %d, %08x) not implemented\n"
|
---|
351 | ,servername, level, *bufptr
|
---|
352 | ));
|
---|
353 |
|
---|
354 | return (NERR_BASE);
|
---|
355 | }
|
---|
356 |
|
---|
357 | /*****************************************************************************
|
---|
358 | * Name : NET_API_STATUS NetServerSetInfo
|
---|
359 | * Purpose :
|
---|
360 | * Parameters: LPWSTR servername
|
---|
361 | * DWORD level
|
---|
362 | * LPBYTE buf
|
---|
363 | * LPDWORD ParmError
|
---|
364 | * Variables :
|
---|
365 | * Result :
|
---|
366 | * Remark :
|
---|
367 | * Status : UNTESTED STUB
|
---|
368 | *
|
---|
369 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
370 | *
|
---|
371 | * Author : Markus Montkowski [09.07.98 21:58:14]
|
---|
372 | *****************************************************************************/
|
---|
373 | ODINFUNCTION4(NET_API_STATUS, OS2NetServerSetInfo,
|
---|
374 | LPWSTR, servername,
|
---|
375 | DWORD, level,
|
---|
376 | LPBYTE, buf,
|
---|
377 | LPDWORD, ParmError)
|
---|
378 |
|
---|
379 | {
|
---|
380 |
|
---|
381 | dprintf(("NETAPI32: NetServerSetInfo(%s, %d, %08x, %08x) not implemented\n"
|
---|
382 | ,servername, level, buf, ParmError
|
---|
383 | ));
|
---|
384 |
|
---|
385 | return (NERR_BASE);
|
---|
386 | }
|
---|
387 |
|
---|
388 |
|
---|
389 | /*****************************************************************************
|
---|
390 | * Name : NET_API_STATUS NetServerTransportAdd
|
---|
391 | * Purpose :
|
---|
392 | * Parameters: LPWSTR servername
|
---|
393 | * DWORD level
|
---|
394 | * LPBYTE bufptr
|
---|
395 | * Variables :
|
---|
396 | * Result :
|
---|
397 | * Remark :
|
---|
398 | * Status : UNTESTED STUB
|
---|
399 | *
|
---|
400 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
401 | *
|
---|
402 | * Author : Markus Montkowski [09.07.98 21:58:34]
|
---|
403 | *****************************************************************************/
|
---|
404 | ODINFUNCTION3(NET_API_STATUS, OS2NetServerTransportAdd,
|
---|
405 | LPWSTR, servername,
|
---|
406 | DWORD, level,
|
---|
407 | LPBYTE, bufptr)
|
---|
408 |
|
---|
409 | {
|
---|
410 |
|
---|
411 | dprintf(("NETAPI32: NetServerTransportAdd(%s, %d, %08x) not implemented\n"
|
---|
412 | ,servername, level, bufptr
|
---|
413 | ));
|
---|
414 |
|
---|
415 | return (NERR_BASE);
|
---|
416 | }
|
---|
417 |
|
---|
418 | /*****************************************************************************
|
---|
419 | * Name : NET_API_STATUS NetServerTransportDel
|
---|
420 | * Purpose :
|
---|
421 | * Parameters: LPWSTR servername
|
---|
422 | * LPWSTR transportname
|
---|
423 | * Variables :
|
---|
424 | * Result :
|
---|
425 | * Remark :
|
---|
426 | * Status : UNTESTED STUB
|
---|
427 | *
|
---|
428 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
429 | *
|
---|
430 | * Author : Markus Montkowski [09.07.98 21:59:12]
|
---|
431 | *****************************************************************************/
|
---|
432 | ODINFUNCTION2(NET_API_STATUS, OS2NetServerTransportDel,
|
---|
433 | LPWSTR, servername,
|
---|
434 | LPWSTR, transportname)
|
---|
435 |
|
---|
436 | {
|
---|
437 |
|
---|
438 | dprintf(("NETAPI32: NetServerTransportDel(%08x, %08x) not implemented\n"
|
---|
439 | ,servername, transportname
|
---|
440 | ));
|
---|
441 |
|
---|
442 | return (NERR_BASE);
|
---|
443 | }
|
---|
444 |
|
---|
445 | /*****************************************************************************
|
---|
446 | * Name : NET_API_STATUS NetServerTransportEnum
|
---|
447 | * Purpose :
|
---|
448 | * Parameters: LPWSTR servername
|
---|
449 | * DWORD level
|
---|
450 | * LPBYTE *bufptr
|
---|
451 | * DWORD prefmaxlen
|
---|
452 | * LPDWORD entriesread
|
---|
453 | * LPDWORD totalentries
|
---|
454 | * LPDWORD resumehandle
|
---|
455 | * Variables :
|
---|
456 | * Result :
|
---|
457 | * Remark :
|
---|
458 | * Status : UNTESTED STUB
|
---|
459 | *
|
---|
460 | * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
|
---|
461 | *
|
---|
462 | * Author : Markus Montkowski [09.07.98 21:59:37]
|
---|
463 | *****************************************************************************/
|
---|
464 | ODINFUNCTION7(NET_API_STATUS, OS2NetServerTransportEnum,
|
---|
465 | LPWSTR, servername,
|
---|
466 | DWORD, level,
|
---|
467 | LPBYTE *, bufptr,
|
---|
468 | DWORD, prefmaxlen,
|
---|
469 | LPDWORD, entriesread,
|
---|
470 | LPDWORD, totalentries,
|
---|
471 | LPDWORD, resumehandle)
|
---|
472 |
|
---|
473 | {
|
---|
474 |
|
---|
475 | dprintf(("NETAPI32: NetServerTransportEnum(%s, %d, %08x, %d, %08x, %08x, %08x) not implemented\n"
|
---|
476 | ,servername, level, *bufptr, prefmaxlen, entriesread, totalentries, resumehandle
|
---|
477 | ));
|
---|
478 |
|
---|
479 | return (NERR_BASE);
|
---|
480 | }
|
---|