- Timestamp:
- Sep 7, 2001, 12:56:40 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wnetap32/server.cpp
r6672 r6673 1 /* $Id: server.cpp,v 1. 1 2001-09-06 22:23:40 phaller Exp $ */1 /* $Id: server.cpp,v 1.2 2001-09-06 22:56:40 phaller Exp $ */ 2 2 3 3 /* … … 41 41 * Module Global Variables * 42 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 89 static 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 } 43 114 44 115 … … 158 229 if (asciiServername) FreeAsciiString(asciiServername); 159 230 if (asciiDomain) FreeAsciiString(asciiDomain); 160 161 // convert the structures 162 switch (dwLevel) 231 232 if (!rc) 163 233 { 164 case 100: 234 // pass on the total number of entries available 235 *lpdwTotalEntries = ulEntriesTotal; 236 237 // convert the structures 238 switch (dwLevel) 165 239 { 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; 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 } 236 395 } 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 or250 // the amount specified in "prefmaxlen"251 252 // we need to calculate the overall size of all returned entries253 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 convert262 if (ulSpace < prefmaxlen)263 ulEntriesConvertable++;264 else265 flagMoreData = TRUE;266 }267 // ulSpace now contains the number of bytes required for the overall structure268 // ulEntriesConvertable contains the number of entries that fit in the target buffer269 270 ulAllocated = min(ulSpace, prefmaxlen);271 272 // reset the structure pointer273 pOS2ssi1 = (struct server_info_1 *)pOS2Buffer;274 275 rc = OS2NetApiBufferAllocate(ulAllocated, (LPVOID*)&psiw1);276 if (!rc)277 {278 // zero out the memory279 memset(psiw1, 0, ulAllocated);280 281 // set data pointer "behind" the converted entries282 // that's where the strings are placed283 PBYTE pbData = (PBYTE)psiw1 + ulEntriesConvertable * sizeof(PSERVER_INFO_101);284 285 for (;286 ulConvertedEntries < ulEntriesConvertable;287 ulConvertedEntries++)288 {289 // convert that single structure290 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 entry304 pOS2ssi1++;305 psiw1++;306 }307 }308 309 // write back actual number of converted entries310 // (as place fits in the target buffer)311 *lpdwEntriesRead = ulConvertedEntries;312 313 // check if there would have been more data314 if (flagMoreData)315 rc = ERROR_MORE_DATA_W;316 317 break;318 }319 320 321 396 } 322 397 323 398 return (rc); 324 325 399 } 326 400
Note:
See TracChangeset
for help on using the changeset viewer.