source: trunk/src/wnetap32/server.cpp@ 10366

Last change on this file since 10366 was 6674, checked in by phaller, 24 years ago

.

File size: 17.6 KB
Line 
1/* $Id: server.cpp,v 1.3 2001-09-06 23:14:53 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
37ODINDEBUGCHANNEL(WNETAP32-SERVER)
38
39
40/****************************************************************************
41 * Module Global Variables *
42 ****************************************************************************/
43
44//
45// The platform ID indicates the levels to use for platform-specific
46// information.
47//
48
49#define PLATFORM_ID_DOS 300
50#define PLATFORM_ID_OS2 400
51#define PLATFORM_ID_NT 500
52#define PLATFORM_ID_OSF 600
53#define PLATFORM_ID_VMS 700
54
55
56#define SV_TYPE_WORKSTATION 0x00000001
57#define SV_TYPE_SERVER 0x00000002
58#define SV_TYPE_SQLSERVER 0x00000004
59#define SV_TYPE_DOMAIN_CTRL 0x00000008
60#define SV_TYPE_DOMAIN_BAKCTRL 0x00000010
61#define SV_TYPE_TIME_SOURCE 0x00000020
62#define SV_TYPE_AFP 0x00000040
63#define SV_TYPE_NOVELL 0x00000080
64#define SV_TYPE_DOMAIN_MEMBER 0x00000100
65#define SV_TYPE_PRINTQ_SERVER 0x00000200
66#define SV_TYPE_DIALIN_SERVER 0x00000400
67#define SV_TYPE_XENIX_SERVER 0x00000800
68#define SV_TYPE_SERVER_UNIX SV_TYPE_XENIX_SERVER
69#define SV_TYPE_NT 0x00001000
70#define SV_TYPE_WFW 0x00002000
71#define SV_TYPE_SERVER_MFPN 0x00004000
72#define SV_TYPE_SERVER_NT 0x00008000
73#define SV_TYPE_POTENTIAL_BROWSER 0x00010000
74#define SV_TYPE_BACKUP_BROWSER 0x00020000
75#define SV_TYPE_MASTER_BROWSER 0x00040000
76#define SV_TYPE_DOMAIN_MASTER 0x00080000
77#define SV_TYPE_SERVER_OSF 0x00100000
78#define SV_TYPE_SERVER_VMS 0x00200000
79#define SV_TYPE_WINDOWS 0x00400000 /* Windows95 and above */
80#define SV_TYPE_DFS 0x00800000 /* Root of a DFS tree */
81#define SV_TYPE_CLUSTER_NT 0x01000000 /* NT Cluster */
82#define SV_TYPE_DCE 0x10000000 /* IBM DSS (Directory and Security Services) or equivalent */
83#define SV_TYPE_ALTERNATE_XPORT 0x20000000 /* return list for alternate transport */
84#define SV_TYPE_LOCAL_LIST_ONLY 0x40000000 /* Return local list only */
85#define SV_TYPE_DOMAIN_ENUM 0x80000000
86#define SV_TYPE_ALL 0xFFFFFFFF /* handy for NetServerEnum2 */
87
88
89static DWORD mapServerTypeToPlatform(DWORD dwServerType)
90{
91 switch(dwServerType)
92 {
93 case SV_TYPE_NT:
94 case SV_TYPE_SERVER_NT:
95 case SV_TYPE_POTENTIAL_BROWSER:
96 case SV_TYPE_BACKUP_BROWSER:
97 case SV_TYPE_MASTER_BROWSER:
98 case SV_TYPE_WINDOWS:
99 case SV_TYPE_CLUSTER_NT:
100 return PLATFORM_ID_NT;
101
102 case SV_TYPE_SERVER_OSF:
103 return PLATFORM_ID_OSF;
104
105 case SV_TYPE_SERVER_VMS:
106 return PLATFORM_ID_VMS;
107
108 default:
109 return PLATFORM_ID_OS2;
110 }
111
112 // who uses PLATFORM_ID_DOS these days ? :)
113}
114
115
116/*****************************************************************************
117 * Name : NET_API_STATUS NetServerDiskEnum
118 * Purpose :
119 * Parameters: LPWSTR servername
120 * DWORD level
121 * LPBYTE *bufptr
122 * DWORD prefmaxlen
123 * LPDWORD entriesread
124 * LPDWORD totalentries
125 * LPDWORD resume_handle
126 * Variables :
127 * Result :
128 * Remark :
129 * Status : UNTESTED STUB
130 *
131 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
132 *
133 * Author : Markus Montkowski [09.07.98 21:56:38]
134 *****************************************************************************/
135ODINFUNCTION7(NET_API_STATUS, OS2NetServerDiskEnum,
136 LPWSTR, servername,
137 DWORD, level,
138 LPBYTE *, bufptr,
139 DWORD, prefmaxlen,
140 LPDWORD, lpdwEntriesRead,
141 LPDWORD, lpdwTotalEntries,
142 LPDWORD, resume_handle)
143
144{
145
146 dprintf(("NETAPI32: NetServerDiskEnum(%s) not implemented\n",
147 servername));
148
149 return (NERR_BASE);
150}
151/*****************************************************************************
152 * Name : NET_API_STATUS NetServerEnum
153 * Purpose :
154 * Parameters: LPWSTR servername
155 * DWORD level
156 * LPBYTE *bufptr
157 * DWORD prefmaxlen
158 * LPDWORD entriesread
159 * LPDWORD totalentries
160 * DWORD servertype
161 * LPWSTR domain
162 * LPDWORD resume_handle
163 * Variables :
164 * Result :
165 * Remark :
166 * Status : UNTESTED STUB
167 *
168 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
169 *
170 * Author : Patrick Haller [2001-09-06]
171 *****************************************************************************/
172ODINFUNCTION9(NET_API_STATUS, OS2NetServerEnum,
173 LPWSTR, lpServerName,
174 DWORD, dwLevel,
175 LPBYTE *, bufptr,
176 DWORD, prefmaxlen,
177 LPDWORD, lpdwEntriesRead,
178 LPDWORD, lpdwTotalEntries,
179 DWORD, dwServerType,
180 LPWSTR, lpDomain,
181 LPDWORD, resume_handle)
182
183{
184 // convert information modes!
185 ULONG ulOS2Level = dwLevel; // can be 100 and 101
186 switch (dwLevel)
187 {
188 case 100: ulOS2Level = 1; break;
189 case 101: ulOS2Level = 1; break;
190 default: ulOS2Level = 1; break;
191 }
192
193 // 2001-09-05 PH doc says the SV_TYPE_ definitions from
194 // LanMan and NT are identical.
195 int iOS2ServerType = dwServerType;
196
197 // Convert servername to ASCII
198 // Convert domain to ASCII
199 char *asciiServername = NULL;
200 char *asciiDomain = NULL;
201
202 if (lpServerName)
203 asciiServername = UnicodeToAsciiString(lpServerName);
204
205 if (lpDomain)
206 asciiDomain = UnicodeToAsciiString(lpDomain);
207
208 dprintf(("WNETAP32: NetServerEnum server=[%s], domain=[%s]\n",
209 asciiServername,
210 asciiDomain));
211
212 ULONG ulBytesAvailable;
213 DWORD rc;
214
215 // determine required size of buffer
216 char pOS2Buffer[8192];
217 ULONG ulBufferLength = sizeof(pOS2Buffer);
218 ULONG ulEntriesRead;
219 ULONG ulEntriesTotal;
220 rc = OSLibNetServerEnum((const unsigned char*)asciiServername,
221 ulOS2Level,
222 (unsigned char*)pOS2Buffer,
223 ulBufferLength,
224 &ulEntriesRead,
225 &ulEntriesTotal,
226 dwServerType,
227 (unsigned char*)asciiDomain);
228
229 if (asciiServername) FreeAsciiString(asciiServername);
230 if (asciiDomain) FreeAsciiString(asciiDomain);
231
232 if (!rc)
233 {
234 // pass on the total number of entries available
235 *lpdwTotalEntries = ulEntriesTotal;
236
237 // convert the structures
238 switch (dwLevel)
239 {
240 case 100:
241 {
242 PSERVER_INFO_100 psiw0;
243 struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
244 ULONG ulConvertedEntries = 0;
245 ULONG ulSpace = 0;
246 ULONG ulAllocated = 0;
247 ULONG ulEntriesConvertable = 0;
248 BOOLEAN flagMoreData = FALSE;
249
250 // allocate as much memory as required or
251 // the amount specified in "prefmaxlen"
252
253 // we need to calculate the overall size of all returned entries
254 for (ULONG i = 0;
255 i < ulEntriesRead;
256 i++)
257 {
258 ulSpace += sizeof(SERVER_INFO_100);
259 ulSpace += (strlen( (const char*) pOS2ssi1->sv1_name) + 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*)&psiw0);
276 if (!rc)
277 {
278 // zero out the memory
279 memset(psiw0, 0, ulAllocated);
280 *bufptr = (LPBYTE)psiw0;
281
282 // set data pointer "behind" the converted entries
283 // that's where the strings are placed
284 PBYTE pbData = (PBYTE)psiw0 + ulEntriesConvertable * sizeof(SERVER_INFO_100);
285
286 for (;
287 ulConvertedEntries < ulEntriesConvertable;
288 ulConvertedEntries++)
289 {
290 // convert that single structure
291 psiw0->sv100_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
292 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name );
293 psiw0->sv100_name = (LPWSTR)pbData;
294
295 // advance to next free data slot
296 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
297
298 // skip to the next entry
299 pOS2ssi1++;
300 psiw0++;
301 }
302 }
303
304 // write back actual number of converted entries
305 // (as place fits in the target buffer)
306 *lpdwEntriesRead = ulConvertedEntries;
307
308 // check if there would have been more data
309 if (flagMoreData)
310 rc = ERROR_MORE_DATA_W;
311
312 break;
313 }
314
315
316 case 101:
317 {
318 PSERVER_INFO_101 psiw1;
319 struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
320 ULONG ulConvertedEntries = 0;
321 ULONG ulSpace = 0;
322 ULONG ulAllocated = 0;
323 ULONG ulEntriesConvertable = 0;
324 BOOLEAN flagMoreData = FALSE;
325
326 // allocate as much memory as required or
327 // the amount specified in "prefmaxlen"
328
329 // we need to calculate the overall size of all returned entries
330 for (ULONG i = 0;
331 i < ulEntriesRead;
332 i++)
333 {
334 ulSpace += sizeof(SERVER_INFO_101);
335 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
336 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
337
338 // count how many entries we can convert
339 if (ulSpace < prefmaxlen)
340 ulEntriesConvertable++;
341 else
342 flagMoreData = TRUE;
343 }
344 // ulSpace now contains the number of bytes required for the overall structure
345 // ulEntriesConvertable contains the number of entries that fit in the target buffer
346
347 ulAllocated = min(ulSpace, prefmaxlen);
348
349 // reset the structure pointer
350 pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
351
352 rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw1);
353 if (!rc)
354 {
355 // zero out the memory
356 memset(psiw1, 0, ulAllocated);
357 *bufptr = (LPBYTE)psiw1;
358
359 // set data pointer "behind" the converted entries
360 // that's where the strings are placed
361 PBYTE pbData = (PBYTE)psiw1 + ulEntriesConvertable * sizeof(SERVER_INFO_101);
362
363 for (;
364 ulConvertedEntries < ulEntriesConvertable;
365 ulConvertedEntries++)
366 {
367 // convert that single structure
368 psiw1->sv101_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
369 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name);
370 psiw1->sv101_name = (LPWSTR)pbData;
371 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
372
373 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_comment);
374 psiw1->sv101_comment = (LPWSTR)pbData;
375 pbData += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
376
377 psiw1->sv101_version_major = pOS2ssi1->sv1_version_major;
378 psiw1->sv101_version_minor = pOS2ssi1->sv1_version_minor;
379 psiw1->sv101_type = pOS2ssi1->sv1_type;
380
381 // skip to the next entry
382 pOS2ssi1++;
383 psiw1++;
384 }
385 }
386
387 // write back actual number of converted entries
388 // (as place fits in the target buffer)
389 *lpdwEntriesRead = ulConvertedEntries;
390
391 // check if there would have been more data
392 if (flagMoreData)
393 rc = ERROR_MORE_DATA_W;
394
395 break;
396 }
397 }
398 }
399
400 return (rc);
401}
402
403
404/*****************************************************************************
405 * Name : NET_API_STATUS NetServerGetInfo
406 * Purpose :
407 * Parameters: LPWSTR servername
408 * DWORD level
409 * LPBYTE *bufptr
410 * Variables :
411 * Result :
412 * Remark :
413 * Status : UNTESTED STUB
414 *
415 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
416 *
417 * Author : Markus Montkowski [09.07.98 21:57:43]
418 *****************************************************************************/
419ODINFUNCTION3(NET_API_STATUS, OS2NetServerGetInfo,
420 LPWSTR, servername,
421 DWORD, level,
422 LPBYTE *, bufptr)
423
424{
425
426 dprintf(("NETAPI32: NetServerGetInfo(%s, %d, %08x) not implemented\n"
427 ,servername, level, *bufptr
428 ));
429
430 return (NERR_BASE);
431}
432
433/*****************************************************************************
434 * Name : NET_API_STATUS NetServerSetInfo
435 * Purpose :
436 * Parameters: LPWSTR servername
437 * DWORD level
438 * LPBYTE buf
439 * LPDWORD ParmError
440 * Variables :
441 * Result :
442 * Remark :
443 * Status : UNTESTED STUB
444 *
445 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
446 *
447 * Author : Markus Montkowski [09.07.98 21:58:14]
448 *****************************************************************************/
449ODINFUNCTION4(NET_API_STATUS, OS2NetServerSetInfo,
450 LPWSTR, servername,
451 DWORD, level,
452 LPBYTE, buf,
453 LPDWORD, ParmError)
454
455{
456
457 dprintf(("NETAPI32: NetServerSetInfo(%s, %d, %08x, %08x) not implemented\n"
458 ,servername, level, buf, ParmError
459 ));
460
461 return (NERR_BASE);
462}
463
464
465/*****************************************************************************
466 * Name : NET_API_STATUS NetServerTransportAdd
467 * Purpose :
468 * Parameters: LPWSTR servername
469 * DWORD level
470 * LPBYTE bufptr
471 * Variables :
472 * Result :
473 * Remark :
474 * Status : UNTESTED STUB
475 *
476 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
477 *
478 * Author : Markus Montkowski [09.07.98 21:58:34]
479 *****************************************************************************/
480ODINFUNCTION3(NET_API_STATUS, OS2NetServerTransportAdd,
481 LPWSTR, servername,
482 DWORD, level,
483 LPBYTE, bufptr)
484
485{
486
487 dprintf(("NETAPI32: NetServerTransportAdd(%s, %d, %08x) not implemented\n"
488 ,servername, level, bufptr
489 ));
490
491 return (NERR_BASE);
492}
493
494/*****************************************************************************
495 * Name : NET_API_STATUS NetServerTransportDel
496 * Purpose :
497 * Parameters: LPWSTR servername
498 * LPWSTR transportname
499 * Variables :
500 * Result :
501 * Remark :
502 * Status : UNTESTED STUB
503 *
504 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
505 *
506 * Author : Markus Montkowski [09.07.98 21:59:12]
507 *****************************************************************************/
508ODINFUNCTION2(NET_API_STATUS, OS2NetServerTransportDel,
509 LPWSTR, servername,
510 LPWSTR, transportname)
511
512{
513
514 dprintf(("NETAPI32: NetServerTransportDel(%08x, %08x) not implemented\n"
515 ,servername, transportname
516 ));
517
518 return (NERR_BASE);
519}
520
521/*****************************************************************************
522 * Name : NET_API_STATUS NetServerTransportEnum
523 * Purpose :
524 * Parameters: LPWSTR servername
525 * DWORD level
526 * LPBYTE *bufptr
527 * DWORD prefmaxlen
528 * LPDWORD entriesread
529 * LPDWORD totalentries
530 * LPDWORD resumehandle
531 * Variables :
532 * Result :
533 * Remark :
534 * Status : UNTESTED STUB
535 *
536 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
537 *
538 * Author : Markus Montkowski [09.07.98 21:59:37]
539 *****************************************************************************/
540ODINFUNCTION7(NET_API_STATUS, OS2NetServerTransportEnum,
541 LPWSTR, servername,
542 DWORD, level,
543 LPBYTE *, bufptr,
544 DWORD, prefmaxlen,
545 LPDWORD, entriesread,
546 LPDWORD, totalentries,
547 LPDWORD, resumehandle)
548
549{
550
551 dprintf(("NETAPI32: NetServerTransportEnum(%s, %d, %08x, %d, %08x, %08x, %08x) not implemented\n"
552 ,servername, level, *bufptr, prefmaxlen, entriesread, totalentries, resumehandle
553 ));
554
555 return (NERR_BASE);
556}
Note: See TracBrowser for help on using the repository browser.