Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1546 lines
44 KiB

  1. /*++
  2. Copyright (C) 1999 Microsoft Corporation
  3. --*/
  4. #include "precomp.h"
  5. #include "strdefs.h"
  6. DWORD
  7. WinsDumpServer(IN LPCWSTR pwszServerIp,
  8. IN LPCWSTR pwszNetBiosName,
  9. IN handle_t hBind,
  10. IN WINSINTF_BIND_DATA_T BindData
  11. )
  12. {
  13. DWORD Status = NO_ERROR;
  14. HKEY hServer = NULL,
  15. hParameter = NULL,
  16. hDefaultPull = NULL,
  17. hDefaultPush = NULL,
  18. hPartner = NULL,
  19. hCheck = NULL,
  20. hPullPart = NULL,
  21. hPushPart = NULL;
  22. DWORD dwType = 0,
  23. dwSize = 1024*sizeof(WCHAR),
  24. dwData = 0;
  25. LPWSTR pwszData = NULL,
  26. pTemp = NULL;
  27. WCHAR wcData[1024] = {L'\0'};
  28. BOOL fBackDir = TRUE;
  29. Status = RegConnectRegistry(pwszNetBiosName,
  30. HKEY_LOCAL_MACHINE,
  31. &hServer);
  32. if( Status isnot NO_ERROR )
  33. {
  34. goto RETURN;
  35. }
  36. Status = RegOpenKeyEx(hServer,
  37. PARAMETER,
  38. 0,
  39. KEY_READ,//KEY_ALL_ACCESS,
  40. &hParameter);
  41. if( Status isnot NO_ERROR )
  42. goto RETURN;
  43. Status = RegOpenKeyEx(hServer,
  44. PARTNERROOT,
  45. 0,
  46. KEY_READ, //KEY_ALL_ACCESS,
  47. &hPartner);
  48. if( Status isnot NO_ERROR )
  49. goto RETURN;
  50. Status = RegOpenKeyEx(hServer,
  51. PULLROOT,
  52. 0,
  53. KEY_READ, //KEY_ALL_ACCESS,
  54. &hPullPart);
  55. if( Status isnot NO_ERROR )
  56. goto RETURN;
  57. Status = RegOpenKeyEx(hServer,
  58. PUSHROOT,
  59. 0,
  60. KEY_READ, //KEY_ALL_ACCESS,
  61. &hPushPart);
  62. if( Status isnot NO_ERROR )
  63. goto RETURN;
  64. Status = RegOpenKeyEx(hServer,
  65. DEFAULTPULL,
  66. 0,
  67. KEY_READ, //KEY_ALL_ACCESS,
  68. &hDefaultPull);
  69. if( Status isnot NO_ERROR )
  70. goto RETURN;
  71. Status = RegOpenKeyEx(hServer,
  72. DEFAULTPUSH,
  73. 0,
  74. KEY_READ, //KEY_ALL_ACCESS,
  75. &hDefaultPush);
  76. if( Status isnot NO_ERROR )
  77. goto RETURN;
  78. //Set Backuppath, Display only when Backup path is set.
  79. Status = NO_ERROR;
  80. Status = RegQueryValueEx(hParameter,
  81. WINSCNF_BACKUP_DIR_PATH_NM,
  82. NULL,
  83. &dwType,
  84. NULL,
  85. &dwSize);
  86. if( Status is NO_ERROR and
  87. dwSize >= sizeof(WCHAR) )
  88. {
  89. pwszData = WinsAllocateMemory(dwSize);
  90. if( pwszData is NULL )
  91. {
  92. Status = ERROR_NOT_ENOUGH_MEMORY;
  93. goto RETURN;
  94. }
  95. Status = NO_ERROR;
  96. Status = RegQueryValueEx(hParameter,
  97. WINSCNF_BACKUP_DIR_PATH_NM,
  98. NULL,
  99. &dwType,
  100. (LPBYTE)pwszData,
  101. &dwSize);
  102. if( Status isnot NO_ERROR )
  103. {
  104. if( pwszData )
  105. {
  106. WinsFreeMemory(pwszData);
  107. pwszData = NULL;
  108. }
  109. goto RETURN;
  110. }
  111. if( wcscmp(pwszData, L" ") is 0 or
  112. wcslen(pwszData) < 1 )
  113. {
  114. fBackDir = FALSE;
  115. }
  116. if( !ExpandEnvironmentStrings(pwszData, wcData, 1023) )
  117. {
  118. if( pwszData )
  119. {
  120. WinsFreeMemory(pwszData);
  121. pwszData = NULL;
  122. }
  123. Status = GetLastError();
  124. goto RETURN;
  125. }
  126. }
  127. else if( Status is ERROR_FILE_NOT_FOUND ||
  128. dwSize < sizeof(WCHAR) )
  129. {
  130. fBackDir = FALSE;
  131. }
  132. else if( Status isnot NO_ERROR )
  133. {
  134. goto RETURN;
  135. }
  136. else
  137. {
  138. fBackDir = FALSE;
  139. }
  140. dwSize = sizeof(DWORD);
  141. Status = NO_ERROR;
  142. Status = RegQueryValueEx(hParameter,
  143. WINSCNF_DO_BACKUP_ON_TERM_NM,
  144. NULL,
  145. &dwType,
  146. (LPBYTE)&dwData,
  147. &dwSize);
  148. if( Status isnot NO_ERROR )
  149. goto RETURN;
  150. if( dwData > 0 )
  151. dwData = 1;
  152. if( fBackDir )
  153. {
  154. DisplayMessage(g_hModule,
  155. DMP_SRVR_SET_BACKUPPATH,
  156. pwszServerIp,
  157. wcData,
  158. dwData);
  159. }
  160. else
  161. {
  162. DisplayMessage(g_hModule,
  163. DMP_SRVR_SET_BACKUPTERM,
  164. pwszServerIp,
  165. dwData);
  166. }
  167. memset(wcData, 0x00, 1024*sizeof(WCHAR));
  168. //Set Name record
  169. {
  170. WINSINTF_RESULTS_T Results = {0};
  171. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  172. BOOL fNew = TRUE;
  173. ResultsN.WinsStat.NoOfPnrs = 0;
  174. ResultsN.WinsStat.pRplPnrs = NULL;
  175. ResultsN.NoOfWorkerThds = 1;
  176. Status = WinsStatusNew(g_hBind,
  177. WINSINTF_E_CONFIG,
  178. &ResultsN);
  179. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  180. {
  181. //Try old API
  182. Results.WinsStat.NoOfPnrs = 0;
  183. Results.WinsStat.pRplPnrs = 0;
  184. Status = WinsStatus(g_hBind, WINSINTF_E_CONFIG, &Results);
  185. fNew = FALSE;
  186. }
  187. if( Status is NO_ERROR )
  188. {
  189. if( fNew )
  190. {
  191. DisplayMessage(g_hModule,
  192. DMP_SRVR_SET_NAMERECORD,
  193. pwszServerIp,
  194. ResultsN.RefreshInterval,
  195. ResultsN.TombstoneInterval,
  196. ResultsN.TombstoneTimeout,
  197. ResultsN.VerifyInterval);
  198. }
  199. else
  200. {
  201. DisplayMessage(g_hModule,
  202. DMP_SRVR_SET_NAMERECORD,
  203. pwszServerIp,
  204. Results.RefreshInterval,
  205. Results.TombstoneInterval,
  206. Results.TombstoneTimeout,
  207. Results.VerifyInterval);
  208. }
  209. }
  210. else
  211. {
  212. DisplayMessage(g_hModule,
  213. DMP_SRVR_SET_NAMERECORD,
  214. pwszServerIp,
  215. NAMERECORD_REFRESH_DEFAULT,
  216. NAMERECORD_EXINTVL_DEFAULT,
  217. NAMERECORD_EXTMOUT_DEFAULT,
  218. NAMERECORD_VERIFY_DEFAULT);
  219. }
  220. }
  221. //Set Periodic DB Checking
  222. {
  223. DWORD dwMaxRec = 30000,
  224. dwUseRpl = 0,
  225. dwTimeIntvl = 24,
  226. dwState = 0,
  227. dwStart = 2*60*60;
  228. LPWSTR pwcTemp = NULL;
  229. Status = NO_ERROR;
  230. Status = RegOpenKeyEx(hServer,
  231. CCROOT,
  232. 0,
  233. KEY_READ, //KEY_ALL_ACCESS,
  234. &hCheck);
  235. if( Status is NO_ERROR )
  236. {
  237. dwState = 1;
  238. dwData = 0;
  239. dwSize = sizeof(DWORD);
  240. Status = RegQueryValueEx(hCheck,
  241. WINSCNF_CC_MAX_RECS_AAT_NM,
  242. NULL,
  243. &dwType,
  244. (LPBYTE)&dwData,
  245. &dwSize);
  246. if( Status is NO_ERROR )
  247. dwMaxRec = dwData;
  248. dwData = 0;
  249. Status = RegQueryValueEx(hCheck,
  250. WINSCNF_CC_USE_RPL_PNRS_NM,
  251. NULL,
  252. &dwType,
  253. (LPBYTE)&dwData,
  254. &dwSize);
  255. if( Status is NO_ERROR )
  256. dwUseRpl = dwData;
  257. if( dwUseRpl > 1 )
  258. dwUseRpl = 1;
  259. dwData = 0;
  260. Status = RegQueryValueEx(hCheck,
  261. WINSCNF_CC_INTVL_NM,
  262. NULL,
  263. &dwType,
  264. (LPBYTE)&dwData,
  265. &dwSize);
  266. if( Status is NO_ERROR )
  267. {
  268. dwTimeIntvl = dwData/(60*60);
  269. }
  270. dwSize = 1024*sizeof(WCHAR);
  271. Status = RegQueryValueEx(hCheck,
  272. WINSCNF_SP_TIME_NM,
  273. NULL,
  274. &dwType,
  275. (LPBYTE)&wcData,
  276. &dwSize);
  277. if( Status is NO_ERROR )
  278. {
  279. WCHAR wcHr[3] = {L'\0'},
  280. wcMt[3] = {L'\0'},
  281. wcSc[3] = {L'\0'};
  282. wcsncpy(wcHr, wcData, 2);
  283. wcsncpy(wcMt, wcData+3, 2);
  284. wcsncpy(wcSc, wcData+6, 2);
  285. dwStart = wcstoul(wcHr, NULL, 10)*60*60 +
  286. wcstoul(wcMt, NULL, 10)*60 +
  287. wcstoul(wcSc, NULL, 10);
  288. }
  289. }
  290. DisplayMessage(g_hModule,
  291. DMP_SRVR_SET_PERIODICDBCHECKING,
  292. pwszServerIp,
  293. dwState,
  294. dwMaxRec,
  295. dwUseRpl,
  296. dwTimeIntvl,
  297. dwStart);
  298. if( hCheck )
  299. {
  300. RegCloseKey(hCheck);
  301. hCheck = NULL;
  302. }
  303. }
  304. //Set replicate flag
  305. dwSize = sizeof(DWORD);
  306. dwData = 0;
  307. Status = NO_ERROR;
  308. Status = RegQueryValueEx(hParameter,
  309. WINSCNF_RPL_ONLY_W_CNF_PNRS_NM,
  310. NULL,
  311. &dwType,
  312. (LPBYTE)&dwData,
  313. &dwSize);
  314. if( Status isnot NO_ERROR )
  315. {
  316. dwData = 0;
  317. }
  318. if( dwData > 1 )
  319. dwData = 1;
  320. DisplayMessage(g_hModule,
  321. DMP_SRVR_SET_REPLICATEFLAG,
  322. pwszServerIp,
  323. dwData);
  324. //Set Migrate flag
  325. dwSize = sizeof(DWORD);
  326. dwData = 0;
  327. Status = NO_ERROR;
  328. Status = RegQueryValueEx(hParameter,
  329. WINSCNF_MIGRATION_ON_NM,
  330. NULL,
  331. &dwType,
  332. (LPBYTE)&dwData,
  333. &dwSize);
  334. if( Status isnot NO_ERROR )
  335. {
  336. dwData = 0;
  337. }
  338. if( dwData > 1 )
  339. dwData = 1;
  340. DisplayMessage(g_hModule,
  341. DMP_SRVR_SET_MIGRATEFLAG,
  342. pwszServerIp,
  343. dwData);
  344. //Set PullParam
  345. {
  346. DWORD dwState = 0,
  347. dwStartUp = 0,
  348. dwStart = 0,
  349. dwRepIntvl = 0,
  350. dwRetry = 0;
  351. Status = NO_ERROR;
  352. dwSize = sizeof(DWORD);
  353. Status = RegQueryValueEx(hDefaultPull,
  354. WINSCNF_RPL_INTERVAL_NM,
  355. NULL,
  356. &dwType,
  357. (LPBYTE)&dwData,
  358. &dwSize);
  359. if( Status is NO_ERROR )
  360. dwRepIntvl = dwData;
  361. dwSize = 1024*sizeof(WCHAR);
  362. Status = RegQueryValueEx(hDefaultPull,
  363. WINSCNF_SP_TIME_NM,
  364. NULL,
  365. &dwType,
  366. (LPBYTE)wcData,
  367. &dwSize);
  368. if( Status is NO_ERROR )
  369. {
  370. WCHAR wcHr[3] = {L'\0'},
  371. wcMt[3] = {L'\0'},
  372. wcSc[3] = {L'\0'};
  373. wcsncpy(wcHr, wcData, 2);
  374. wcsncpy(wcMt, wcData+3, 2);
  375. wcsncpy(wcSc, wcData+6, 2);
  376. dwStart = wcstoul(wcHr, NULL, 10)*60*60 +
  377. wcstoul(wcMt, NULL, 10)*60 +
  378. wcstoul(wcSc, NULL, 10);
  379. }
  380. dwSize = sizeof(DWORD);
  381. dwData = 0;
  382. Status = RegQueryValueEx(hPullPart,
  383. PERSISTENCE,
  384. NULL,
  385. &dwType,
  386. (LPBYTE)&dwData,
  387. &dwSize);
  388. if( Status is NO_ERROR )
  389. {
  390. dwState = dwData;
  391. }
  392. if( dwState > 1 )
  393. dwState = 1;
  394. dwData = 0;
  395. dwSize = sizeof(DWORD);
  396. Status = RegQueryValueEx(hPullPart,
  397. WINSCNF_RETRY_COUNT_NM,
  398. NULL,
  399. &dwType,
  400. (LPBYTE)&dwData,
  401. &dwSize);
  402. if(Status is NO_ERROR )
  403. {
  404. dwRetry = dwData;
  405. }
  406. dwData = 0;
  407. dwSize = sizeof(DWORD);
  408. Status = RegQueryValueEx(hPullPart,
  409. WINSCNF_INIT_TIME_RPL_NM,
  410. NULL,
  411. &dwType,
  412. (LPBYTE)&dwData,
  413. &dwSize);
  414. if( Status is NO_ERROR )
  415. {
  416. dwStartUp = dwData;
  417. }
  418. if( dwStartUp > 1 )
  419. dwStartUp = 1;
  420. DisplayMessage(g_hModule,
  421. DMP_SRVR_SET_PULLPARAM,
  422. pwszServerIp,
  423. dwState,
  424. dwStartUp,
  425. dwStart,
  426. dwRepIntvl,
  427. dwRetry);
  428. }
  429. //Set PushParam
  430. {
  431. DWORD dwState = 0,
  432. dwAddChng = 0,
  433. dwStartUp = 0,
  434. dwUpdate = 0;
  435. dwData = 0;
  436. dwSize = sizeof(DWORD);
  437. Status = NO_ERROR;
  438. Status = RegQueryValueEx(hDefaultPush,
  439. WINSCNF_UPDATE_COUNT_NM,
  440. NULL,
  441. &dwType,
  442. (LPBYTE)&dwData,
  443. &dwSize);
  444. if( Status is NO_ERROR )
  445. dwUpdate = dwData;
  446. dwData = 0;
  447. dwSize = sizeof(DWORD);
  448. Status = RegQueryValueEx(hPushPart,
  449. WINSCNF_INIT_TIME_RPL_NM,
  450. NULL,
  451. &dwType,
  452. (LPBYTE)&dwData,
  453. &dwSize);
  454. if( Status is NO_ERROR )
  455. dwStartUp = dwData;
  456. if( dwStartUp > 1 )
  457. dwStartUp = 1;
  458. dwSize = sizeof(DWORD);
  459. dwData = 0;
  460. Status = RegQueryValueEx(hPushPart,
  461. PERSISTENCE,
  462. NULL,
  463. &dwType,
  464. (LPBYTE)&dwData,
  465. &dwSize);
  466. if( Status is NO_ERROR )
  467. {
  468. dwState = dwData;
  469. }
  470. if( dwState > 1 )
  471. dwState = 1;
  472. dwData = 0;
  473. dwSize = sizeof(DWORD);
  474. Status = RegQueryValueEx(hPushPart,
  475. WINSCNF_ADDCHG_TRIGGER_NM,
  476. NULL,
  477. &dwType,
  478. (LPBYTE)&dwData,
  479. &dwSize);
  480. if( Status is NO_ERROR )
  481. dwAddChng = dwData;
  482. if( dwAddChng > 1 )
  483. {
  484. dwAddChng = 1;
  485. }
  486. DisplayMessage(g_hModule,
  487. DMP_SRVR_SET_PUSHPARAM,
  488. pwszServerIp,
  489. dwState,
  490. dwStartUp,
  491. dwAddChng,
  492. dwUpdate);
  493. }
  494. //Add PNG Server List
  495. while( TRUE )
  496. {
  497. LPBYTE pbData = NULL;
  498. DWORD dwCount = 0,
  499. dw = 0;
  500. Status = NO_ERROR;
  501. Status = RegQueryValueEx(hPartner,
  502. WinsOemToUnicode(WINSCNF_PERSONA_NON_GRATA_NM, NULL),
  503. NULL,
  504. &dwType,
  505. pbData,
  506. &dwSize);
  507. if( Status isnot NO_ERROR )
  508. break;
  509. if( dwSize < 7 )
  510. break;
  511. pbData = WinsAllocateMemory(dwSize);
  512. if( pbData is NULL )
  513. break;
  514. Status = RegQueryValueEx(hPartner,
  515. WinsOemToUnicode(WINSCNF_PERSONA_NON_GRATA_NM, NULL),
  516. NULL,
  517. &dwType,
  518. pbData,
  519. &dwSize);
  520. if( Status isnot NO_ERROR )
  521. {
  522. WinsFreeMemory(pbData);
  523. pbData = NULL;
  524. break;
  525. }
  526. pTemp = (LPWSTR)pbData;
  527. for( dw=0; dw<dwSize/sizeof(WCHAR); dw++ )
  528. {
  529. if( pTemp[dw] is L'\0' and
  530. pTemp[dw+1] isnot L'\0' )
  531. {
  532. pTemp[dw] = L',';
  533. }
  534. }
  535. DisplayMessage(g_hModule,
  536. DMP_SRVR_SET_PGMODE,
  537. pwszServerIp,
  538. PERSMODE_NON_GRATA);
  539. DisplayMessage(g_hModule,
  540. DMP_SRVR_ADD_PNGSERVER,
  541. pwszServerIp,
  542. pTemp);
  543. WinsFreeMemory(pbData);
  544. pbData = NULL;
  545. break;
  546. }
  547. //Add PG Server List
  548. while( TRUE )
  549. {
  550. LPBYTE pbData = NULL;
  551. DWORD dwCount = 0,
  552. dw = 0;
  553. Status = NO_ERROR;
  554. Status = RegQueryValueEx(hPartner,
  555. WinsOemToUnicode(WINSCNF_PERSONA_GRATA_NM, NULL),
  556. NULL,
  557. &dwType,
  558. pbData,
  559. &dwSize);
  560. if( Status isnot NO_ERROR )
  561. break;
  562. if( dwSize < 7 )
  563. break;
  564. pbData = WinsAllocateMemory(dwSize);
  565. if( pbData is NULL )
  566. break;
  567. Status = RegQueryValueEx(hPartner,
  568. WinsOemToUnicode(WINSCNF_PERSONA_GRATA_NM, NULL),
  569. NULL,
  570. &dwType,
  571. pbData,
  572. &dwSize);
  573. if( Status isnot NO_ERROR )
  574. {
  575. WinsFreeMemory(pbData);
  576. pbData = NULL;
  577. break;
  578. }
  579. pTemp = (LPWSTR)pbData;
  580. for( dw=0; dw<dwSize/sizeof(WCHAR); dw++ )
  581. {
  582. if( pTemp[dw] is L'\0' and
  583. pTemp[dw+1] isnot L'\0' )
  584. {
  585. pTemp[dw] = L',';
  586. }
  587. }
  588. DisplayMessage(g_hModule,
  589. DMP_SRVR_SET_PGMODE,
  590. pwszServerIp,
  591. PERSMODE_GRATA);
  592. DisplayMessage(g_hModule,
  593. DMP_SRVR_ADD_PGSERVER,
  594. pwszServerIp,
  595. pTemp);
  596. WinsFreeMemory(pbData);
  597. pbData = NULL;
  598. break;
  599. }
  600. //Set the PGMode
  601. {
  602. DWORD dwPGMode = PERSMODE_NON_GRATA;
  603. Status = NO_ERROR;
  604. dwSize = sizeof(DWORD);
  605. Status = RegQueryValueEx(hPartner,
  606. WinsOemToUnicode(WINSCNF_PERSONA_MODE_NM, NULL),
  607. NULL,
  608. &dwType,
  609. (LPVOID)&dwPGMode,
  610. &dwSize);
  611. if (dwPGMode != PERSMODE_GRATA)
  612. DisplayMessage(g_hModule,
  613. DMP_SRVR_SET_PGMODE,
  614. pwszServerIp,
  615. dwPGMode);
  616. }
  617. //Set AutoPartner config
  618. {
  619. DWORD dwState = 0,
  620. dwInterval = 0,
  621. dwTTL = 2;
  622. dwData = 0;
  623. dwSize = sizeof(DWORD);
  624. Status = NO_ERROR;
  625. Status = RegQueryValueEx(hParameter,
  626. WINSCNF_USE_SELF_FND_PNRS_NM,
  627. NULL,
  628. &dwType,
  629. (LPBYTE)&dwData,
  630. &dwSize);
  631. if( Status is NO_ERROR )
  632. {
  633. dwState = dwData;
  634. }
  635. if( dwState > 1 )
  636. dwState = 0;
  637. dwData = 0;
  638. dwSize = sizeof(DWORD);
  639. Status = RegQueryValueEx(hParameter,
  640. WINSCNF_MCAST_TTL_NM,
  641. NULL,
  642. &dwType,
  643. (LPBYTE)&dwData,
  644. &dwSize);
  645. if( Status is NO_ERROR )
  646. dwTTL = dwData;
  647. dwData = 0;
  648. dwSize = sizeof(DWORD);
  649. Status = RegQueryValueEx(hParameter,
  650. WINSCNF_MCAST_INTVL_NM,
  651. NULL,
  652. &dwType,
  653. (LPBYTE)&dwData,
  654. &dwSize);
  655. if( Status is NO_ERROR )
  656. dwInterval = dwData;
  657. DisplayMessage(g_hModule,
  658. DMP_SRVR_SET_AUTOPARTNERCONFIG,
  659. pwszServerIp,
  660. dwState,
  661. dwInterval,
  662. dwTTL);
  663. }
  664. Status = NO_ERROR;
  665. //Set Burst Handling parameters
  666. {
  667. DWORD dwState = 0;
  668. dwType = REG_DWORD;
  669. dwSize = sizeof(DWORD);
  670. Status = RegQueryValueEx(hParameter,
  671. WINSCNF_BURST_HANDLING_NM,
  672. NULL,
  673. &dwType,
  674. (LPBYTE)&dwState,
  675. &dwSize);
  676. if( Status is NO_ERROR )
  677. {
  678. dwSize = sizeof(DWORD);
  679. Status = RegQueryValueEx(hParameter,
  680. WINSCNF_BURST_QUE_SIZE_NM,
  681. NULL,
  682. &dwType,
  683. (LPBYTE)&dwData,
  684. &dwSize);
  685. if( Status isnot NO_ERROR )
  686. {
  687. DisplayMessage(g_hModule,
  688. DMP_SRVR_SET_BURSTPARAM,
  689. pwszServerIp,
  690. dwState);
  691. }
  692. else
  693. {
  694. DisplayMessage(g_hModule,
  695. DMP_SRVR_SET_BURSTPARAM_ALL,
  696. pwszServerIp,
  697. dwState,
  698. dwData);
  699. }
  700. }
  701. else
  702. {
  703. DisplayMessage(g_hModule,
  704. DMP_SRVR_SET_BURSTPARAM,
  705. pwszServerIp,
  706. dwState);
  707. }
  708. }
  709. Status = NO_ERROR;
  710. //Set Log Parameter
  711. {
  712. DWORD dwLog = 0;
  713. dwType = REG_DWORD;
  714. dwSize = sizeof(DWORD);
  715. dwData = 0;
  716. Status = RegQueryValueEx(hParameter,
  717. WINSCNF_LOG_FLAG_NM,
  718. NULL,
  719. &dwType,
  720. (LPBYTE)&dwLog,
  721. &dwSize);
  722. dwSize = sizeof(DWORD);
  723. dwType = REG_DWORD;
  724. Status = RegQueryValueEx(hParameter,
  725. WINSCNF_LOG_DETAILED_EVTS_NM,
  726. NULL,
  727. &dwType,
  728. (LPBYTE)&dwData,
  729. &dwSize);
  730. DisplayMessage(g_hModule,
  731. DMP_SRVR_SET_LOGPARAM,
  732. pwszServerIp,
  733. dwLog,
  734. dwData);
  735. }
  736. Status = NO_ERROR;
  737. //Start Version count
  738. {
  739. DWORD dwHigh = 0;
  740. dwData = 0;
  741. dwType = REG_DWORD;
  742. dwSize = sizeof(DWORD);
  743. Status = RegQueryValueEx(hParameter,
  744. WINSCNF_INIT_VERSNO_VAL_HW_NM,
  745. NULL,
  746. &dwType,
  747. (LPBYTE)&dwHigh,
  748. &dwSize);
  749. if( Status isnot NO_ERROR )
  750. dwHigh = 0;
  751. dwType = REG_DWORD;
  752. dwSize = sizeof(DWORD);
  753. Status = RegQueryValueEx(hParameter,
  754. WINSCNF_INIT_VERSNO_VAL_LW_NM,
  755. NULL,
  756. &dwType,
  757. (LPBYTE)&dwData,
  758. &dwSize);
  759. if( Status isnot NO_ERROR )
  760. dwData = 0;
  761. DisplayMessage(g_hModule,
  762. DMP_SRVR_SET_STARTVERSION,
  763. pwszServerIp,
  764. dwHigh,
  765. dwData);
  766. }
  767. Status = NO_ERROR;
  768. //For all partners, set PullPersistentConnections
  769. {
  770. DWORD i, dwSubKey = 0;
  771. HKEY hKey = NULL;
  772. WCHAR wcIp[MAX_IP_STRING_LEN+1] = {L'\0'};
  773. DWORD dwBuffer = MAX_IP_STRING_LEN+1;
  774. Status = NO_ERROR;
  775. while( TRUE )
  776. {
  777. Status = RegQueryInfoKey(hPullPart,
  778. NULL,
  779. NULL,
  780. NULL,
  781. &dwSubKey,
  782. NULL,
  783. NULL,
  784. NULL,
  785. NULL,
  786. NULL,
  787. NULL,
  788. NULL);
  789. if( Status isnot NO_ERROR )
  790. break;
  791. if ( dwSubKey is 0 )
  792. break;
  793. for( i=0; i<dwSubKey; i++ )
  794. {
  795. DWORD dwState = 0,
  796. dwIntvl = 0,
  797. dwStart = 0;
  798. dwBuffer = MAX_IP_STRING_LEN+1;
  799. dwSize = sizeof(DWORD);
  800. dwData = 0;
  801. Status = RegEnumKeyEx(hPullPart,
  802. i,
  803. wcIp,
  804. &dwBuffer,
  805. NULL,
  806. NULL,
  807. NULL,
  808. NULL);
  809. if( Status isnot NO_ERROR )
  810. continue;
  811. DisplayMessage(g_hModule,
  812. DMP_SRVR_ADD_PARTNER,
  813. pwszServerIp,
  814. wcIp,
  815. 0);
  816. Status = RegOpenKeyEx(hPullPart,
  817. wcIp,
  818. 0,
  819. KEY_READ, //KEY_ALL_ACCESS,
  820. &hKey);
  821. if( Status isnot NO_ERROR )
  822. continue;
  823. Status = RegQueryValueEx(hKey,
  824. PERSISTENCE,
  825. NULL,
  826. &dwType,
  827. (LPBYTE)&dwData,
  828. &dwSize);
  829. if( Status isnot NO_ERROR )
  830. {
  831. Status = RegQueryValueEx(hPullPart,
  832. PERSISTENCE,
  833. NULL,
  834. &dwType,
  835. (LPBYTE)&dwData,
  836. &dwSize);
  837. }
  838. if( Status is NO_ERROR )
  839. {
  840. dwState = dwData;
  841. if( dwState > 1 )
  842. dwState = 1;
  843. }
  844. dwData = 0;
  845. dwSize = sizeof(DWORD);
  846. Status = RegQueryValueEx(hKey,
  847. WINSCNF_RPL_INTERVAL_NM,
  848. NULL,
  849. &dwType,
  850. (LPBYTE)&dwData,
  851. &dwSize);
  852. if( Status isnot NO_ERROR )
  853. {
  854. Status = RegQueryValueEx(hDefaultPull,
  855. WINSCNF_RPL_INTERVAL_NM,
  856. NULL,
  857. &dwType,
  858. (LPBYTE)&dwData,
  859. &dwSize);
  860. }
  861. if( Status is NO_ERROR )
  862. {
  863. dwIntvl = dwData;
  864. }
  865. dwSize = 1024*sizeof(WCHAR);
  866. Status = RegQueryValueEx(hKey,
  867. WINSCNF_SP_TIME_NM,
  868. NULL,
  869. &dwType,
  870. (LPBYTE)wcData,
  871. &dwSize);
  872. if( Status isnot NO_ERROR )
  873. {
  874. dwSize = 1024*sizeof(WCHAR);
  875. Status = RegQueryValueEx(hDefaultPull,
  876. WINSCNF_SP_TIME_NM,
  877. NULL,
  878. &dwType,
  879. (LPBYTE)wcData,
  880. &dwSize);
  881. }
  882. if( Status is NO_ERROR )
  883. {
  884. WCHAR wcHr[3] = {L'\0'},
  885. wcMt[3] = {L'\0'},
  886. wcSc[3] = {L'\0'};
  887. wcsncpy(wcHr, wcData, 2);
  888. wcsncpy(wcMt, wcData+3, 2);
  889. wcsncpy(wcSc, wcData+6, 2);
  890. dwStart = wcstoul(wcHr, NULL, 10)*60*60 +
  891. wcstoul(wcMt, NULL, 10)*60 +
  892. wcstoul(wcSc, NULL, 10);
  893. }
  894. DisplayMessage(g_hModule,
  895. DMP_SRVR_SET_PULLPERSISTENTCONNECTION,
  896. pwszServerIp,
  897. dwState,
  898. wcIp,
  899. dwStart,
  900. dwIntvl);
  901. RegCloseKey(hKey);
  902. hKey = NULL;
  903. }
  904. break;
  905. }
  906. }
  907. //Set PushPersistentConnection
  908. {
  909. DWORD i, dwSubKey = 0;
  910. HKEY hKey = NULL;
  911. WCHAR wcIp[MAX_IP_STRING_LEN+1] = {L'\0'};
  912. DWORD dwBuffer = MAX_IP_STRING_LEN+1;
  913. Status = NO_ERROR;
  914. while( TRUE )
  915. {
  916. Status = RegQueryInfoKey(hPushPart,
  917. NULL,
  918. NULL,
  919. NULL,
  920. &dwSubKey,
  921. NULL,
  922. NULL,
  923. NULL,
  924. NULL,
  925. NULL,
  926. NULL,
  927. NULL);
  928. if( Status isnot NO_ERROR )
  929. break;
  930. if ( dwSubKey is 0 )
  931. break;
  932. for( i=0; i<dwSubKey; i++ )
  933. {
  934. DWORD dwState = 0,
  935. dwUpdate = 0;
  936. dwBuffer = MAX_IP_STRING_LEN+1;
  937. dwSize = sizeof(DWORD);
  938. dwData = 0;
  939. Status = RegEnumKeyEx(hPushPart,
  940. i,
  941. wcIp,
  942. &dwBuffer,
  943. NULL,
  944. NULL,
  945. NULL,
  946. NULL);
  947. if( Status isnot NO_ERROR )
  948. continue;
  949. DisplayMessage(g_hModule,
  950. DMP_SRVR_ADD_PARTNER,
  951. pwszServerIp,
  952. wcIp,
  953. 1);
  954. Status = RegOpenKeyEx(hPushPart,
  955. wcIp,
  956. 0,
  957. KEY_READ, //KEY_ALL_ACCESS,
  958. &hKey);
  959. if( Status isnot NO_ERROR )
  960. continue;
  961. Status = RegQueryValueEx(hKey,
  962. PERSISTENCE,
  963. NULL,
  964. &dwType,
  965. (LPBYTE)&dwData,
  966. &dwSize);
  967. if( Status isnot NO_ERROR )
  968. {
  969. Status = RegQueryValueEx(hPushPart,
  970. PERSISTENCE,
  971. NULL,
  972. &dwType,
  973. (LPBYTE)&dwData,
  974. &dwSize);
  975. }
  976. if( Status is NO_ERROR )
  977. {
  978. dwState = dwData;
  979. if( dwState > 1 )
  980. dwState = 1;
  981. }
  982. dwData = 0;
  983. dwSize = sizeof(DWORD);
  984. Status = RegQueryValueEx(hKey,
  985. WINSCNF_UPDATE_COUNT_NM,
  986. NULL,
  987. &dwType,
  988. (LPBYTE)&dwData,
  989. &dwSize);
  990. if( Status isnot NO_ERROR )
  991. {
  992. Status = RegQueryValueEx(hDefaultPush,
  993. WINSCNF_UPDATE_COUNT_NM,
  994. NULL,
  995. &dwType,
  996. (LPBYTE)&dwData,
  997. &dwSize);
  998. }
  999. if( Status is NO_ERROR )
  1000. {
  1001. dwUpdate = dwData;
  1002. }
  1003. DisplayMessage(g_hModule,
  1004. DMP_SRVR_SET_PUSHPERSISTENTCONNECTION,
  1005. pwszServerIp,
  1006. dwState,
  1007. wcIp,
  1008. dwUpdate);
  1009. RegCloseKey(hKey);
  1010. hKey = NULL;
  1011. }
  1012. break;
  1013. }
  1014. if( Status is 2 )
  1015. Status = NO_ERROR;
  1016. }
  1017. RETURN:
  1018. if( pwszData )
  1019. {
  1020. WinsFreeMemory(pwszData);
  1021. pwszData = NULL;
  1022. }
  1023. if( hPushPart )
  1024. {
  1025. RegCloseKey(hPushPart);
  1026. hPushPart = NULL;
  1027. }
  1028. if( hPullPart )
  1029. {
  1030. RegCloseKey(hPullPart);
  1031. hPullPart = NULL;
  1032. }
  1033. if( hPartner )
  1034. {
  1035. RegCloseKey(hPartner);
  1036. hPartner = NULL;
  1037. }
  1038. if( hCheck )
  1039. {
  1040. RegCloseKey(hCheck);
  1041. hCheck = NULL;
  1042. }
  1043. if( hParameter )
  1044. {
  1045. RegCloseKey(hParameter);
  1046. hParameter = NULL;
  1047. }
  1048. if (hDefaultPull)
  1049. {
  1050. RegCloseKey(hDefaultPull);
  1051. hDefaultPull = NULL;
  1052. }
  1053. if (hDefaultPush)
  1054. {
  1055. RegCloseKey(hDefaultPush);
  1056. hDefaultPull = NULL;
  1057. }
  1058. if( hServer )
  1059. {
  1060. RegCloseKey(hServer);
  1061. hServer = NULL;
  1062. }
  1063. return Status;
  1064. }
  1065. DWORD
  1066. WINAPI
  1067. WinsDump(
  1068. IN LPCWSTR pwszRouter,
  1069. IN OUT LPWSTR *ppwcArguments,
  1070. IN DWORD dwArgCount,
  1071. IN LPCVOID pvData
  1072. )
  1073. {
  1074. DWORD Status = NO_ERROR;
  1075. WCHAR wcServerIp[MAX_IP_STRING_LEN+1] = {L'\0'};
  1076. CHAR cServerIp[MAX_IP_STRING_LEN+1] = {'\0'};
  1077. LPWSTR pwcServerName = NULL;
  1078. WCHAR wcNetBios[MAX_COMPUTER_NAME_LEN+1] = {L'\0'};
  1079. struct hostent * lpHostEnt = NULL;
  1080. handle_t hServer = NULL;
  1081. WINSINTF_BIND_DATA_T BindData={0};
  1082. LPWSTR pwszComputerName = NULL;
  1083. LPSTR pszComputerName = NULL,
  1084. pTemp = NULL,
  1085. pTemp1 = NULL;
  1086. DWORD dwComputerNameLen = 0,
  1087. dwTempLen = 0,
  1088. nLen = 0, i = 0;
  1089. BYTE pbAdd[4] = {0x00};
  1090. char szAdd[4] = {'\0'};
  1091. DWORD Access = 0;
  1092. wcNetBios[0] = L'\\';
  1093. wcNetBios[1] = L'\\';
  1094. if( !GetComputerNameEx(ComputerNameDnsFullyQualified,
  1095. NULL,
  1096. &dwComputerNameLen) )
  1097. {
  1098. pwszComputerName = WinsAllocateMemory((dwComputerNameLen+1)*sizeof(WCHAR));
  1099. if(pwszComputerName is NULL)
  1100. {
  1101. return FALSE;
  1102. }
  1103. dwComputerNameLen++;
  1104. if( !GetComputerNameEx(ComputerNameDnsFullyQualified,
  1105. pwszComputerName,
  1106. &dwComputerNameLen) )
  1107. {
  1108. WinsFreeMemory(pwszComputerName);
  1109. pwszComputerName = NULL;
  1110. return GetLastError();
  1111. }
  1112. }
  1113. else
  1114. {
  1115. return GetLastError();
  1116. }
  1117. //Now process the Computer name and convert it to ANSI because
  1118. //gethostbyname requires ANSI character string.
  1119. //pszComputerName = WinsUnicodeToOem(pwszComputerName, NULL);
  1120. pszComputerName = WinsUnicodeToAnsi(pwszComputerName, NULL);
  1121. if( pszComputerName is NULL )
  1122. return ERROR_NOT_ENOUGH_MEMORY;
  1123. //Now get the server IP Address
  1124. lpHostEnt = gethostbyname(pszComputerName);
  1125. //Not a valid server name
  1126. if( lpHostEnt is NULL )
  1127. {
  1128. DisplayMessage(g_hModule, EMSG_WINS_INVALID_COMPUTERNAME);
  1129. if( pszComputerName )
  1130. {
  1131. WinsFreeMemory(pszComputerName);
  1132. pszComputerName = NULL;
  1133. }
  1134. return WSAGetLastError();
  1135. }
  1136. //Get the IP Address from the returned struct...
  1137. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  1138. nLen = 0;
  1139. for( i=0; i<4; i++)
  1140. {
  1141. _itoa((int)pbAdd[i], szAdd, 10);
  1142. memcpy(cServerIp+nLen, szAdd, strlen(szAdd));
  1143. nLen += strlen(szAdd);
  1144. *(cServerIp+nLen) = '.';
  1145. nLen++;
  1146. }
  1147. *(cServerIp+nLen-1) = '\0';
  1148. {
  1149. LPWSTR pwstrServerIp;
  1150. pwstrServerIp = WinsAnsiToUnicode(cServerIp, NULL);
  1151. if (pwstrServerIp == NULL)
  1152. return ERROR_NOT_ENOUGH_MEMORY;
  1153. wcscpy(wcServerIp, pwstrServerIp);
  1154. wcscpy(wcNetBios+2, wcServerIp);
  1155. WinsFreeMemory(pwstrServerIp);
  1156. }
  1157. if(pTemp1)
  1158. {
  1159. WinsFreeMemory(pTemp1);
  1160. pTemp1 = NULL;
  1161. }
  1162. pwcServerName = WinsAllocateMemory((strlen(lpHostEnt->h_name) + 1)*sizeof(WCHAR));
  1163. if( pwcServerName is NULL )
  1164. {
  1165. if( pszComputerName )
  1166. {
  1167. WinsFreeMemory(pszComputerName);
  1168. pszComputerName = NULL;
  1169. }
  1170. if( pwszComputerName )
  1171. {
  1172. WinsFreeMemory(pwszComputerName);
  1173. pwszComputerName = NULL;
  1174. }
  1175. return ERROR_NOT_ENOUGH_MEMORY;
  1176. }
  1177. if( pszComputerName )
  1178. {
  1179. WinsFreeMemory(pszComputerName);
  1180. pszComputerName = NULL;
  1181. }
  1182. if( pwszComputerName )
  1183. {
  1184. WinsFreeMemory(pwszComputerName);
  1185. pwszComputerName = NULL;
  1186. }
  1187. wcscpy(pwcServerName, WinsOemToUnicode(lpHostEnt->h_name, NULL));
  1188. //Bind the server
  1189. BindData.fTcpIp = TRUE;
  1190. BindData.pServerAdd = (LPBYTE)wcServerIp;
  1191. BindData.pPipeName = (LPBYTE)pwcServerName;
  1192. hServer = WinsBind(&BindData);
  1193. if (hServer is NULL)
  1194. {
  1195. DisplayMessage(g_hModule,
  1196. EMSG_WINS_BIND_FAILED,
  1197. pwcServerName);
  1198. WinsFreeMemory(pwcServerName);
  1199. pwcServerName = NULL;
  1200. return ERROR_INVALID_PARAMETER;
  1201. }
  1202. //find out what type of access do we have
  1203. Access = WINS_NO_ACCESS;
  1204. Status = WinsCheckAccess(hServer, &Access);
  1205. if (WINSINTF_SUCCESS == Status)
  1206. {
  1207. if (Access != WINS_NO_ACCESS)
  1208. {
  1209. DisplayMessage(g_hModule,
  1210. Access == WINS_CONTROL_ACCESS ? MSG_WINS_RWACCESS : MSG_WINS_ROACCESS,
  1211. pwcServerName);
  1212. }
  1213. if( Access is WINS_NO_ACCESS )
  1214. {
  1215. DisplayMessage(g_hModule,
  1216. MSG_WINS_NOACCESS,
  1217. pwcServerName);
  1218. WinsUnbind(&BindData, hServer);
  1219. hServer = NULL;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. DisplayErrorMessage(EMSG_WINS_GETSTATUS_FAILED,
  1225. Status);
  1226. WinsFreeMemory(pwcServerName);
  1227. pwcServerName = NULL;
  1228. return Status;
  1229. }
  1230. //Now dump the configuration information for this server.
  1231. Status = WinsDumpServer(wcServerIp,
  1232. wcNetBios,
  1233. hServer,
  1234. BindData);
  1235. DisplayMessage(g_hModule,
  1236. WINS_FORMAT_LINE);
  1237. WinsFreeMemory(pwcServerName);
  1238. pwcServerName = NULL;
  1239. return Status;
  1240. }