source: trunk/src/wnetap32/server.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 17.7 KB
RevLine 
[10492]1/* $Id: server.cpp,v 1.4 2004-02-27 20:15:44 sandervl Exp $ */
[6672]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>
[21916]29#include <string.h>
[6672]30#include <unicode.h>
31#include <heapstring.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
[6673]44//
45// The platform ID indicates the levels to use for platform-specific
46// information.
47//
[6672]48
[6673]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
[6672]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{
[10492]184#ifndef NETBIOS_ENABLED
185 return NERR_BASE;
186#else
[6672]187 // convert information modes!
188 ULONG ulOS2Level = dwLevel; // can be 100 and 101
189 switch (dwLevel)
190 {
191 case 100: ulOS2Level = 1; break;
192 case 101: ulOS2Level = 1; break;
193 default: ulOS2Level = 1; break;
194 }
195
196 // 2001-09-05 PH doc says the SV_TYPE_ definitions from
197 // LanMan and NT are identical.
198 int iOS2ServerType = dwServerType;
199
200 // Convert servername to ASCII
201 // Convert domain to ASCII
202 char *asciiServername = NULL;
203 char *asciiDomain = NULL;
204
205 if (lpServerName)
206 asciiServername = UnicodeToAsciiString(lpServerName);
207
208 if (lpDomain)
209 asciiDomain = UnicodeToAsciiString(lpDomain);
210
211 dprintf(("WNETAP32: NetServerEnum server=[%s], domain=[%s]\n",
212 asciiServername,
213 asciiDomain));
214
215 ULONG ulBytesAvailable;
216 DWORD rc;
217
218 // determine required size of buffer
219 char pOS2Buffer[8192];
220 ULONG ulBufferLength = sizeof(pOS2Buffer);
221 ULONG ulEntriesRead;
222 ULONG ulEntriesTotal;
223 rc = OSLibNetServerEnum((const unsigned char*)asciiServername,
224 ulOS2Level,
225 (unsigned char*)pOS2Buffer,
226 ulBufferLength,
227 &ulEntriesRead,
228 &ulEntriesTotal,
229 dwServerType,
230 (unsigned char*)asciiDomain);
231
232 if (asciiServername) FreeAsciiString(asciiServername);
233 if (asciiDomain) FreeAsciiString(asciiDomain);
[6673]234
235 if (!rc)
[6672]236 {
[6673]237 // pass on the total number of entries available
238 *lpdwTotalEntries = ulEntriesTotal;
239
240 // convert the structures
241 switch (dwLevel)
[6672]242 {
[6673]243 case 100:
244 {
245 PSERVER_INFO_100 psiw0;
246 struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
247 ULONG ulConvertedEntries = 0;
248 ULONG ulSpace = 0;
249 ULONG ulAllocated = 0;
250 ULONG ulEntriesConvertable = 0;
251 BOOLEAN flagMoreData = FALSE;
[6672]252
[6673]253 // allocate as much memory as required or
254 // the amount specified in "prefmaxlen"
255
256 // we need to calculate the overall size of all returned entries
257 for (ULONG i = 0;
258 i < ulEntriesRead;
259 i++)
260 {
261 ulSpace += sizeof(SERVER_INFO_100);
262 ulSpace += (strlen( (const char*) pOS2ssi1->sv1_name) + 1) * 2;
263
264 // count how many entries we can convert
265 if (ulSpace < prefmaxlen)
266 ulEntriesConvertable++;
267 else
268 flagMoreData = TRUE;
269 }
270 // ulSpace now contains the number of bytes required for the overall structure
271 // ulEntriesConvertable contains the number of entries that fit in the target buffer
272
273 ulAllocated = min(ulSpace, prefmaxlen);
274
275 // reset the structure pointer
276 pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
277
278 rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw0);
279 if (!rc)
280 {
281 // zero out the memory
282 memset(psiw0, 0, ulAllocated);
[6674]283 *bufptr = (LPBYTE)psiw0;
[6673]284
285 // set data pointer "behind" the converted entries
286 // that's where the strings are placed
287 PBYTE pbData = (PBYTE)psiw0 + ulEntriesConvertable * sizeof(SERVER_INFO_100);
288
289 for (;
290 ulConvertedEntries < ulEntriesConvertable;
291 ulConvertedEntries++)
292 {
293 // convert that single structure
294 psiw0->sv100_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
295 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name );
296 psiw0->sv100_name = (LPWSTR)pbData;
297
298 // advance to next free data slot
299 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
300
301 // skip to the next entry
302 pOS2ssi1++;
303 psiw0++;
304 }
305 }
306
307 // write back actual number of converted entries
308 // (as place fits in the target buffer)
309 *lpdwEntriesRead = ulConvertedEntries;
310
311 // check if there would have been more data
312 if (flagMoreData)
313 rc = ERROR_MORE_DATA_W;
314
315 break;
316 }
317
318
319 case 101:
320 {
321 PSERVER_INFO_101 psiw1;
322 struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
323 ULONG ulConvertedEntries = 0;
324 ULONG ulSpace = 0;
325 ULONG ulAllocated = 0;
326 ULONG ulEntriesConvertable = 0;
327 BOOLEAN flagMoreData = FALSE;
328
329 // allocate as much memory as required or
330 // the amount specified in "prefmaxlen"
331
332 // we need to calculate the overall size of all returned entries
333 for (ULONG i = 0;
334 i < ulEntriesRead;
335 i++)
336 {
337 ulSpace += sizeof(SERVER_INFO_101);
338 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
339 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
340
341 // count how many entries we can convert
342 if (ulSpace < prefmaxlen)
343 ulEntriesConvertable++;
344 else
345 flagMoreData = TRUE;
346 }
347 // ulSpace now contains the number of bytes required for the overall structure
348 // ulEntriesConvertable contains the number of entries that fit in the target buffer
349
350 ulAllocated = min(ulSpace, prefmaxlen);
351
352 // reset the structure pointer
353 pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
354
355 rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw1);
356 if (!rc)
357 {
358 // zero out the memory
359 memset(psiw1, 0, ulAllocated);
[6674]360 *bufptr = (LPBYTE)psiw1;
[6673]361
362 // set data pointer "behind" the converted entries
363 // that's where the strings are placed
364 PBYTE pbData = (PBYTE)psiw1 + ulEntriesConvertable * sizeof(SERVER_INFO_101);
365
366 for (;
367 ulConvertedEntries < ulEntriesConvertable;
368 ulConvertedEntries++)
369 {
370 // convert that single structure
371 psiw1->sv101_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
372 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name);
373 psiw1->sv101_name = (LPWSTR)pbData;
374 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
375
376 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_comment);
377 psiw1->sv101_comment = (LPWSTR)pbData;
378 pbData += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
379
380 psiw1->sv101_version_major = pOS2ssi1->sv1_version_major;
381 psiw1->sv101_version_minor = pOS2ssi1->sv1_version_minor;
382 psiw1->sv101_type = pOS2ssi1->sv1_type;
383
384 // skip to the next entry
385 pOS2ssi1++;
386 psiw1++;
387 }
388 }
389
390 // write back actual number of converted entries
391 // (as place fits in the target buffer)
392 *lpdwEntriesRead = ulConvertedEntries;
393
394 // check if there would have been more data
395 if (flagMoreData)
396 rc = ERROR_MORE_DATA_W;
397
398 break;
399 }
[6672]400 }
401 }
402
403 return (rc);
[10492]404#endif
[6672]405}
406
407
408/*****************************************************************************
409 * Name : NET_API_STATUS NetServerGetInfo
410 * Purpose :
411 * Parameters: LPWSTR servername
412 * DWORD level
413 * LPBYTE *bufptr
414 * Variables :
415 * Result :
416 * Remark :
417 * Status : UNTESTED STUB
418 *
419 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
420 *
421 * Author : Markus Montkowski [09.07.98 21:57:43]
422 *****************************************************************************/
423ODINFUNCTION3(NET_API_STATUS, OS2NetServerGetInfo,
424 LPWSTR, servername,
425 DWORD, level,
426 LPBYTE *, bufptr)
427
428{
429
430 dprintf(("NETAPI32: NetServerGetInfo(%s, %d, %08x) not implemented\n"
431 ,servername, level, *bufptr
432 ));
433
434 return (NERR_BASE);
435}
436
437/*****************************************************************************
438 * Name : NET_API_STATUS NetServerSetInfo
439 * Purpose :
440 * Parameters: LPWSTR servername
441 * DWORD level
442 * LPBYTE buf
443 * LPDWORD ParmError
444 * Variables :
445 * Result :
446 * Remark :
447 * Status : UNTESTED STUB
448 *
449 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
450 *
451 * Author : Markus Montkowski [09.07.98 21:58:14]
452 *****************************************************************************/
453ODINFUNCTION4(NET_API_STATUS, OS2NetServerSetInfo,
454 LPWSTR, servername,
455 DWORD, level,
456 LPBYTE, buf,
457 LPDWORD, ParmError)
458
459{
460
461 dprintf(("NETAPI32: NetServerSetInfo(%s, %d, %08x, %08x) not implemented\n"
462 ,servername, level, buf, ParmError
463 ));
464
465 return (NERR_BASE);
466}
467
468
469/*****************************************************************************
470 * Name : NET_API_STATUS NetServerTransportAdd
471 * Purpose :
472 * Parameters: LPWSTR servername
473 * DWORD level
474 * LPBYTE bufptr
475 * Variables :
476 * Result :
477 * Remark :
478 * Status : UNTESTED STUB
479 *
480 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
481 *
482 * Author : Markus Montkowski [09.07.98 21:58:34]
483 *****************************************************************************/
484ODINFUNCTION3(NET_API_STATUS, OS2NetServerTransportAdd,
485 LPWSTR, servername,
486 DWORD, level,
487 LPBYTE, bufptr)
488
489{
490
491 dprintf(("NETAPI32: NetServerTransportAdd(%s, %d, %08x) not implemented\n"
492 ,servername, level, bufptr
493 ));
494
495 return (NERR_BASE);
496}
497
498/*****************************************************************************
499 * Name : NET_API_STATUS NetServerTransportDel
500 * Purpose :
501 * Parameters: LPWSTR servername
502 * LPWSTR transportname
503 * Variables :
504 * Result :
505 * Remark :
506 * Status : UNTESTED STUB
507 *
508 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
509 *
510 * Author : Markus Montkowski [09.07.98 21:59:12]
511 *****************************************************************************/
512ODINFUNCTION2(NET_API_STATUS, OS2NetServerTransportDel,
513 LPWSTR, servername,
514 LPWSTR, transportname)
515
516{
517
518 dprintf(("NETAPI32: NetServerTransportDel(%08x, %08x) not implemented\n"
519 ,servername, transportname
520 ));
521
522 return (NERR_BASE);
523}
524
525/*****************************************************************************
526 * Name : NET_API_STATUS NetServerTransportEnum
527 * Purpose :
528 * Parameters: LPWSTR servername
529 * DWORD level
530 * LPBYTE *bufptr
531 * DWORD prefmaxlen
532 * LPDWORD entriesread
533 * LPDWORD totalentries
534 * LPDWORD resumehandle
535 * Variables :
536 * Result :
537 * Remark :
538 * Status : UNTESTED STUB
539 *
540 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
541 *
542 * Author : Markus Montkowski [09.07.98 21:59:37]
543 *****************************************************************************/
544ODINFUNCTION7(NET_API_STATUS, OS2NetServerTransportEnum,
545 LPWSTR, servername,
546 DWORD, level,
547 LPBYTE *, bufptr,
548 DWORD, prefmaxlen,
549 LPDWORD, entriesread,
550 LPDWORD, totalentries,
551 LPDWORD, resumehandle)
552
553{
554
555 dprintf(("NETAPI32: NetServerTransportEnum(%s, %d, %08x, %d, %08x, %08x, %08x) not implemented\n"
556 ,servername, level, *bufptr, prefmaxlen, entriesread, totalentries, resumehandle
557 ));
558
559 return (NERR_BASE);
560}
Note: See TracBrowser for help on using the repository browser.