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

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

.

File size: 17.6 KB
Line 
1/* $Id: server.cpp,v 1.2 2001-09-06 22:56: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
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
281 // set data pointer "behind" the converted entries
282 // that's where the strings are placed
283 PBYTE pbData = (PBYTE)psiw0 + ulEntriesConvertable * sizeof(SERVER_INFO_100);
284
285 for (;
286 ulConvertedEntries < ulEntriesConvertable;
287 ulConvertedEntries++)
288 {
289 // convert that single structure
290 psiw0->sv100_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
291 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name );
292 psiw0->sv100_name = (LPWSTR)pbData;
293
294 // advance to next free data slot
295 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
296
297 // skip to the next entry
298 pOS2ssi1++;
299 psiw0++;
300 }
301 }
302
303 // write back actual number of converted entries
304 // (as place fits in the target buffer)
305 *lpdwEntriesRead = ulConvertedEntries;
306
307 // check if there would have been more data
308 if (flagMoreData)
309 rc = ERROR_MORE_DATA_W;
310
311 break;
312 }
313
314
315 case 101:
316 {
317 PSERVER_INFO_101 psiw1;
318 struct server_info_1 *pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
319 ULONG ulConvertedEntries = 0;
320 ULONG ulSpace = 0;
321 ULONG ulAllocated = 0;
322 ULONG ulEntriesConvertable = 0;
323 BOOLEAN flagMoreData = FALSE;
324
325 // allocate as much memory as required or
326 // the amount specified in "prefmaxlen"
327
328 // we need to calculate the overall size of all returned entries
329 for (ULONG i = 0;
330 i < ulEntriesRead;
331 i++)
332 {
333 ulSpace += sizeof(SERVER_INFO_101);
334 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
335 ulSpace += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
336
337 // count how many entries we can convert
338 if (ulSpace < prefmaxlen)
339 ulEntriesConvertable++;
340 else
341 flagMoreData = TRUE;
342 }
343 // ulSpace now contains the number of bytes required for the overall structure
344 // ulEntriesConvertable contains the number of entries that fit in the target buffer
345
346 ulAllocated = min(ulSpace, prefmaxlen);
347
348 // reset the structure pointer
349 pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;
350
351 rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw1);
352 if (!rc)
353 {
354 // zero out the memory
355 memset(psiw1, 0, ulAllocated);
356
357 // set data pointer "behind" the converted entries
358 // that's where the strings are placed
359 PBYTE pbData = (PBYTE)psiw1 + ulEntriesConvertable * sizeof(SERVER_INFO_101);
360
361 for (;
362 ulConvertedEntries < ulEntriesConvertable;
363 ulConvertedEntries++)
364 {
365 // convert that single structure
366 psiw1->sv101_platform_id = mapServerTypeToPlatform(pOS2ssi1->sv1_type);
367 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_name);
368 psiw1->sv101_name = (LPWSTR)pbData;
369 pbData += (strlen( (const char*)pOS2ssi1->sv1_name ) + 1) * 2;
370
371 lstrcpyAtoW((LPWSTR)pbData, (LPCSTR)pOS2ssi1->sv1_comment);
372 psiw1->sv101_comment = (LPWSTR)pbData;
373 pbData += (strlen( (const char*)pOS2ssi1->sv1_comment ) + 1) * 2;
374
375 psiw1->sv101_version_major = pOS2ssi1->sv1_version_major;
376 psiw1->sv101_version_minor = pOS2ssi1->sv1_version_minor;
377 psiw1->sv101_type = pOS2ssi1->sv1_type;
378
379 // skip to the next entry
380 pOS2ssi1++;
381 psiw1++;
382 }
383 }
384
385 // write back actual number of converted entries
386 // (as place fits in the target buffer)
387 *lpdwEntriesRead = ulConvertedEntries;
388
389 // check if there would have been more data
390 if (flagMoreData)
391 rc = ERROR_MORE_DATA_W;
392
393 break;
394 }
395 }
396 }
397
398 return (rc);
399}
400
401
402/*****************************************************************************
403 * Name : NET_API_STATUS NetServerGetInfo
404 * Purpose :
405 * Parameters: LPWSTR servername
406 * DWORD level
407 * LPBYTE *bufptr
408 * Variables :
409 * Result :
410 * Remark :
411 * Status : UNTESTED STUB
412 *
413 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
414 *
415 * Author : Markus Montkowski [09.07.98 21:57:43]
416 *****************************************************************************/
417ODINFUNCTION3(NET_API_STATUS, OS2NetServerGetInfo,
418 LPWSTR, servername,
419 DWORD, level,
420 LPBYTE *, bufptr)
421
422{
423
424 dprintf(("NETAPI32: NetServerGetInfo(%s, %d, %08x) not implemented\n"
425 ,servername, level, *bufptr
426 ));
427
428 return (NERR_BASE);
429}
430
431/*****************************************************************************
432 * Name : NET_API_STATUS NetServerSetInfo
433 * Purpose :
434 * Parameters: LPWSTR servername
435 * DWORD level
436 * LPBYTE buf
437 * LPDWORD ParmError
438 * Variables :
439 * Result :
440 * Remark :
441 * Status : UNTESTED STUB
442 *
443 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
444 *
445 * Author : Markus Montkowski [09.07.98 21:58:14]
446 *****************************************************************************/
447ODINFUNCTION4(NET_API_STATUS, OS2NetServerSetInfo,
448 LPWSTR, servername,
449 DWORD, level,
450 LPBYTE, buf,
451 LPDWORD, ParmError)
452
453{
454
455 dprintf(("NETAPI32: NetServerSetInfo(%s, %d, %08x, %08x) not implemented\n"
456 ,servername, level, buf, ParmError
457 ));
458
459 return (NERR_BASE);
460}
461
462
463/*****************************************************************************
464 * Name : NET_API_STATUS NetServerTransportAdd
465 * Purpose :
466 * Parameters: LPWSTR servername
467 * DWORD level
468 * LPBYTE bufptr
469 * Variables :
470 * Result :
471 * Remark :
472 * Status : UNTESTED STUB
473 *
474 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
475 *
476 * Author : Markus Montkowski [09.07.98 21:58:34]
477 *****************************************************************************/
478ODINFUNCTION3(NET_API_STATUS, OS2NetServerTransportAdd,
479 LPWSTR, servername,
480 DWORD, level,
481 LPBYTE, bufptr)
482
483{
484
485 dprintf(("NETAPI32: NetServerTransportAdd(%s, %d, %08x) not implemented\n"
486 ,servername, level, bufptr
487 ));
488
489 return (NERR_BASE);
490}
491
492/*****************************************************************************
493 * Name : NET_API_STATUS NetServerTransportDel
494 * Purpose :
495 * Parameters: LPWSTR servername
496 * LPWSTR transportname
497 * Variables :
498 * Result :
499 * Remark :
500 * Status : UNTESTED STUB
501 *
502 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
503 *
504 * Author : Markus Montkowski [09.07.98 21:59:12]
505 *****************************************************************************/
506ODINFUNCTION2(NET_API_STATUS, OS2NetServerTransportDel,
507 LPWSTR, servername,
508 LPWSTR, transportname)
509
510{
511
512 dprintf(("NETAPI32: NetServerTransportDel(%08x, %08x) not implemented\n"
513 ,servername, transportname
514 ));
515
516 return (NERR_BASE);
517}
518
519/*****************************************************************************
520 * Name : NET_API_STATUS NetServerTransportEnum
521 * Purpose :
522 * Parameters: LPWSTR servername
523 * DWORD level
524 * LPBYTE *bufptr
525 * DWORD prefmaxlen
526 * LPDWORD entriesread
527 * LPDWORD totalentries
528 * LPDWORD resumehandle
529 * Variables :
530 * Result :
531 * Remark :
532 * Status : UNTESTED STUB
533 *
534 * Stub Generated through PE2LX Stubwizard 0.02 from Markus Montkowski
535 *
536 * Author : Markus Montkowski [09.07.98 21:59:37]
537 *****************************************************************************/
538ODINFUNCTION7(NET_API_STATUS, OS2NetServerTransportEnum,
539 LPWSTR, servername,
540 DWORD, level,
541 LPBYTE *, bufptr,
542 DWORD, prefmaxlen,
543 LPDWORD, entriesread,
544 LPDWORD, totalentries,
545 LPDWORD, resumehandle)
546
547{
548
549 dprintf(("NETAPI32: NetServerTransportEnum(%s, %d, %08x, %d, %08x, %08x, %08x) not implemented\n"
550 ,servername, level, *bufptr, prefmaxlen, entriesread, totalentries, resumehandle
551 ));
552
553 return (NERR_BASE);
554}
Note: See TracBrowser for help on using the repository browser.