Source code of Windows XP (NT5)
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.

17950 lines
522 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. Routing\Netsh\wins\srvrhndl.c
  5. Abstract:
  6. WINS Command dispatcher.
  7. Created by:
  8. Shubho Bhattacharya(a-sbhatt) on 12/10/98
  9. --*/
  10. #include "precomp.h"
  11. extern ULONG g_ulSrvrNumTopCmds;
  12. extern ULONG g_ulSrvrNumGroups;
  13. extern CMD_GROUP_ENTRY g_SrvrCmdGroups[];
  14. extern CMD_ENTRY g_SrvrCmds[];
  15. DWORD g_dwSearchCount = 0;
  16. BOOL g_fHeader = FALSE;
  17. WCHAR **LA_Table = NULL;
  18. LARGE_INTEGER **SO_Table = NULL;
  19. u_char **NBNames = NULL;
  20. WINSERVERS * WinServers = NULL;
  21. LPWSTR
  22. GetDateTimeString(DWORD_PTR TimeStamp,
  23. BOOL fShort,
  24. int *piType);
  25. DWORD
  26. HandleSrvrDump(
  27. IN LPCWSTR pwszMachine,
  28. IN OUT LPWSTR *ppwcArguments,
  29. IN DWORD dwCurrentIndex,
  30. IN DWORD dwArgCount,
  31. IN DWORD dwFlags,
  32. IN LPCVOID pvData,
  33. OUT BOOL *pbDone
  34. )
  35. /*++
  36. Routine Description :
  37. Dumps the current configuration of the Wins Server.
  38. Arguments :
  39. Does not take any arguments.
  40. Return Value:
  41. Returns the status of the operation.
  42. --*/
  43. {
  44. DWORD Status = NO_ERROR;
  45. if( dwArgCount > dwCurrentIndex )
  46. {
  47. if( IsHelpToken(ppwcArguments[dwCurrentIndex]) is TRUE )
  48. {
  49. DisplayMessage(g_hModule,
  50. HLP_WINS_DUMP_EX);
  51. }
  52. }
  53. Status = WinsDumpServer(g_ServerIpAddressUnicodeString,
  54. g_ServerNetBiosName,
  55. g_hBind,
  56. g_BindData);
  57. if( Status is NO_ERROR )
  58. {
  59. DisplayMessage(g_hModule,
  60. EMSG_WINS_ERROR_SUCCESS);
  61. }
  62. else if( Status is ERROR_FILE_NOT_FOUND )
  63. {
  64. DisplayMessage(g_hModule,
  65. EMSG_WINS_NOT_CONFIGURED);
  66. }
  67. else
  68. {
  69. DisplayErrorMessage(EMSG_SRVR_DUMP,
  70. Status);
  71. }
  72. return Status;
  73. }
  74. DWORD
  75. HandleSrvrHelp(
  76. IN LPCWSTR pwszMachine,
  77. IN OUT LPWSTR *ppwcArguments,
  78. IN DWORD dwCurrentIndex,
  79. IN DWORD dwArgCount,
  80. IN DWORD dwFlags,
  81. IN LPCVOID pvData,
  82. OUT BOOL *pbDone
  83. )
  84. /*++
  85. Routine Description :
  86. Displays the help for Wins Server context.
  87. Arguments :
  88. Does not take any arguments.
  89. Return Value:
  90. Returns the status of the operation. NO_ERROR always.
  91. --*/
  92. {
  93. DWORD i, j;
  94. for(i = 0; i < g_ulSrvrNumTopCmds -2; i++)
  95. {
  96. if ((g_SrvrCmds[i].dwCmdHlpToken == WINS_MSG_NULL)
  97. || !g_SrvrCmds[i].pwszCmdToken[0] )
  98. {
  99. continue;
  100. }
  101. DisplayMessage(g_hModule,
  102. g_SrvrCmds[i].dwShortCmdHelpToken);
  103. }
  104. for(i = 0; i < g_ulSrvrNumGroups; i++)
  105. {
  106. if ((g_SrvrCmdGroups[i].dwShortCmdHelpToken == WINS_MSG_NULL)
  107. || !g_SrvrCmdGroups[i].pwszCmdGroupToken[0] )
  108. {
  109. continue;
  110. }
  111. DisplayMessage(g_hModule, g_SrvrCmdGroups[i].dwShortCmdHelpToken);
  112. }
  113. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  114. return NO_ERROR;
  115. }
  116. DWORD
  117. HandleSrvrAddName(
  118. IN LPCWSTR pwszMachine,
  119. IN OUT LPWSTR *ppwcArguments,
  120. IN DWORD dwCurrentIndex,
  121. IN DWORD dwArgCount,
  122. IN DWORD dwFlags,
  123. IN LPCVOID pvData,
  124. OUT BOOL *pbDone
  125. )
  126. /*++
  127. Routine Description :
  128. Adds and registers a name record to the WINS server
  129. Arguments :
  130. All aguments are passes as array of wide char strings in ppwcArguments.
  131. Compulsory, Record Name and Ip Address
  132. Optional, Endchar, Scope, RecordType, NodeType, GroupType
  133. Note : GroupType is ignored if EndChar is specified.
  134. Return Value:
  135. Returns the status of the operation.
  136. --*/
  137. {
  138. DWORD Status = NO_ERROR;
  139. DWORD i, j, dwNumArgs, dwTagCount = 0;
  140. TAG_TYPE pttTags[] = {
  141. {WINS_TOKEN_NAME, TRUE, FALSE},
  142. {WINS_TOKEN_ENDCHAR, FALSE, FALSE},
  143. {WINS_TOKEN_SCOPE, FALSE, FALSE},
  144. {WINS_TOKEN_RECORDTYPE, FALSE, FALSE},
  145. {WINS_TOKEN_GROUP, FALSE, FALSE},
  146. {WINS_TOKEN_NODE, FALSE, FALSE},
  147. {WINS_TOKEN_IP, TRUE, FALSE},
  148. };
  149. PDWORD pdwTagNum = NULL,
  150. pdwTagType = NULL;
  151. WCHAR wszName[MAX_STRING_LEN+1] = {L'\0'};
  152. BOOL fEndChar = FALSE;
  153. BOOL fDomain = FALSE;
  154. CHAR ch16thChar = 0x00;
  155. BOOL fScope = FALSE;
  156. WCHAR wszScope[MAX_STRING_LEN] = {L'\0'};
  157. BOOL fStatic = TRUE;
  158. DWORD dwRecType = WINSINTF_E_UNIQUE;
  159. BYTE rgbNodeType = WINSINTF_E_PNODE;
  160. PDWORD pdwIpAddress = NULL;
  161. DWORD dwIpCount = 0;
  162. DWORD dwStrLen = 0;
  163. LPWSTR pwszTemp = NULL;
  164. WINSINTF_RECORD_ACTION_T RecAction = {0};
  165. PWINSINTF_RECORD_ACTION_T pRecAction = NULL;
  166. LPSTR pszTempName = NULL;
  167. memset(&RecAction, 0x00, sizeof(WINSINTF_RECORD_ACTION_T));
  168. RecAction.fStatic = fStatic;
  169. //We need at least Name and Ip for the record.
  170. if( dwArgCount < dwCurrentIndex + 2 )
  171. {
  172. DisplayMessage(g_hModule, HLP_SRVR_ADD_NAME_EX);
  173. Status = ERROR_INVALID_PARAMETER;
  174. goto ErrorReturn;
  175. }
  176. //Start processing the arguments passed by ppwcArguments and dwArgCount
  177. dwNumArgs = dwArgCount - dwCurrentIndex;
  178. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  179. if( pdwTagNum is NULL )
  180. {
  181. Status = ERROR_NOT_ENOUGH_MEMORY;
  182. goto ErrorReturn;
  183. }
  184. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  185. if( pdwTagType is NULL )
  186. {
  187. Status = ERROR_NOT_ENOUGH_MEMORY;
  188. goto ErrorReturn;
  189. }
  190. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  191. Status = PreProcessCommand(ppwcArguments,
  192. dwArgCount,
  193. dwCurrentIndex,
  194. pttTags,
  195. &dwTagCount,
  196. pdwTagType,
  197. pdwTagNum);
  198. if( Status isnot NO_ERROR )
  199. goto ErrorReturn;
  200. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  201. {
  202. if( pttTags[i].dwRequired is TRUE and
  203. pttTags[i].bPresent is FALSE
  204. )
  205. {
  206. Status = ERROR_INVALID_PARAMETER;
  207. goto ErrorReturn;
  208. }
  209. }
  210. i = dwTagCount;
  211. for( j=0; j<i; j++ )
  212. {
  213. switch(pdwTagType[j])
  214. {
  215. //Name of the record ( Compulsory )
  216. case 0:
  217. {
  218. DWORD dwLen = 0;
  219. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  220. if( dwLen is 0 )
  221. {
  222. Status = ERROR_INVALID_PARAMETER;
  223. goto ErrorReturn;
  224. }
  225. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  226. memcpy(wszName,
  227. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  228. dwLen*sizeof(WCHAR));
  229. wszName[dwLen] = L'\0';
  230. break;
  231. }
  232. //End Char or 16th Character( Optional )
  233. case 1:
  234. {
  235. DWORD dwLen = 0, k=0;
  236. fEndChar = TRUE;
  237. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  238. if( dwLen > 2 )
  239. {
  240. Status = ERROR_INVALID_PARAMETER;
  241. goto ErrorReturn;
  242. }
  243. for( k=0; k<dwLen; k++ )
  244. {
  245. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  246. if( towlower(wc) >= L'a' and
  247. towlower(wc) <= L'z' )
  248. {
  249. if( towlower(wc) > L'f' )
  250. {
  251. Status = ERROR_INVALID_PARAMETER;
  252. goto ErrorReturn;
  253. }
  254. }
  255. }
  256. ch16thChar = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  257. break;
  258. }
  259. //Scope ( Optional )
  260. case 2:
  261. {
  262. DWORD dwLen;
  263. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  264. fScope = TRUE;
  265. if( dwLen is 0 )
  266. {
  267. Status = ERROR_INVALID_PARAMETER;
  268. goto ErrorReturn;
  269. }
  270. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  271. memcpy(wszScope,
  272. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  273. dwLen*sizeof(WCHAR));
  274. wszScope[dwLen] = L'\0';
  275. break;
  276. }
  277. //Record Type ie Static or Dynamic ( Optional )
  278. case 3:
  279. {
  280. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 1 )
  281. {
  282. Status = ERROR_INVALID_PARAMETER;
  283. goto ErrorReturn;
  284. }
  285. else
  286. {
  287. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  288. if( wc is L'1' )
  289. fStatic = FALSE;
  290. else if( wc is L'0' )
  291. fStatic = TRUE;
  292. else
  293. {
  294. Status = ERROR_INVALID_PARAMETER;
  295. goto ErrorReturn;
  296. }
  297. }
  298. break;
  299. }
  300. // Group Type ( Optional )
  301. case 4:
  302. {
  303. DWORD dw = 0;
  304. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  305. {
  306. Status = ERROR_INVALID_PARAMETER;
  307. goto ErrorReturn;
  308. }
  309. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  310. switch(dw)
  311. {
  312. case 0:
  313. {
  314. dwRecType = WINSINTF_E_UNIQUE;
  315. break;
  316. }
  317. case 1:
  318. {
  319. dwRecType = WINSINTF_E_NORM_GROUP;
  320. break;
  321. }
  322. case 2:
  323. {
  324. dwRecType = WINSINTF_E_SPEC_GROUP;
  325. break;
  326. }
  327. case 3:
  328. {
  329. dwRecType = WINSINTF_E_MULTIHOMED;
  330. break;
  331. }
  332. case 4:
  333. {
  334. fDomain = TRUE;
  335. dwRecType = WINSINTF_E_SPEC_GROUP;
  336. break;
  337. }
  338. default:
  339. {
  340. Status = ERROR_INVALID_PARAMETER;
  341. goto ErrorReturn;
  342. }
  343. }
  344. break;
  345. }
  346. //Node Type( Optional )
  347. case 5:
  348. {
  349. DWORD dw = 0;
  350. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  351. {
  352. Status = ERROR_INVALID_PARAMETER;
  353. goto ErrorReturn;
  354. }
  355. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  356. switch(dw)
  357. {
  358. case 0:
  359. {
  360. rgbNodeType = WINSINTF_E_BNODE;
  361. break;
  362. }
  363. case 1:
  364. {
  365. rgbNodeType = WINSINTF_E_PNODE;
  366. break;
  367. }
  368. case 3:
  369. {
  370. rgbNodeType = WINSINTF_E_HNODE;
  371. break;
  372. }
  373. default:
  374. {
  375. Status = ERROR_INVALID_PARAMETER;
  376. goto ErrorReturn;
  377. }
  378. }
  379. break;
  380. }
  381. //IP Address corresponding to the record( Compulsory )
  382. case 6:
  383. {
  384. LPWSTR pszIps = NULL;
  385. DWORD dwIpLen = 0;
  386. LPWSTR pTemp = NULL;
  387. dwIpCount = 0;
  388. dwIpLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  389. if( dwIpLen is 0 )
  390. {
  391. break;
  392. }
  393. pszIps = WinsAllocateMemory((dwIpLen+1)*sizeof(WCHAR));
  394. if( pszIps is NULL )
  395. {
  396. Status = ERROR_NOT_ENOUGH_MEMORY;
  397. goto ErrorReturn;
  398. }
  399. wcscpy(pszIps, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  400. if( pszIps[0] isnot L'{' or
  401. pszIps[dwIpLen-1] isnot L'}')
  402. {
  403. Status = ERROR_INVALID_PARAMETER;
  404. goto ErrorReturn;
  405. }
  406. pTemp = pszIps+1;
  407. pszIps[dwIpLen-1] = L'\0';
  408. pTemp = wcstok(pTemp, L",");
  409. while(( pTemp isnot NULL ) && (dwIpCount < WINSINTF_MAX_MEM ) )
  410. {
  411. PDWORD pdwTemp = NULL;
  412. if( IsIpAddress(pTemp) is FALSE )
  413. {
  414. Status = ERROR_INVALID_PARAMETER;
  415. goto ErrorReturn;
  416. }
  417. dwIpCount++;
  418. pdwTemp = WinsAllocateMemory(dwIpCount*sizeof(DWORD));
  419. if( pdwTemp is NULL )
  420. {
  421. Status = ERROR_NOT_ENOUGH_MEMORY;
  422. goto ErrorReturn;
  423. }
  424. if( pdwIpAddress )
  425. {
  426. memcpy(pdwTemp, pdwIpAddress, (dwIpCount-1)*sizeof(DWORD));
  427. WinsFreeMemory(pdwIpAddress);
  428. pdwIpAddress = NULL;
  429. }
  430. pdwTemp[dwIpCount-1] = StringToIpAddress(pTemp);
  431. pdwIpAddress = pdwTemp;
  432. pTemp = wcstok(NULL, L",");
  433. }
  434. WinsFreeMemory(pszIps);
  435. pszIps = NULL;
  436. break;
  437. }
  438. default:
  439. {
  440. Status = ERROR_INVALID_PARAMETER;
  441. goto ErrorReturn;
  442. }
  443. }
  444. }
  445. //Process Name, Scope and Endchar if specified.
  446. _wcsupr(wszName);
  447. _wcsupr(wszScope);
  448. RecAction.pName = WinsAllocateMemory(273);
  449. if( RecAction.pName is NULL )
  450. {
  451. Status = ERROR_NOT_ENOUGH_MEMORY;
  452. goto ErrorReturn;
  453. }
  454. pszTempName = WinsUnicodeToOem(wszName, NULL);
  455. if( pszTempName is NULL )
  456. {
  457. Status = ERROR_NOT_ENOUGH_MEMORY;
  458. goto ErrorReturn;
  459. }
  460. dwStrLen = strlen(pszTempName);
  461. if( dwStrLen >= 16 )
  462. {
  463. DisplayMessage(g_hModule,
  464. EMSG_SRVR_INVALID_NETBIOS_NAME);
  465. Status = ERROR_INVALID_PARAMETER;
  466. WinsFreeMemory(pszTempName);
  467. pszTempName = NULL;
  468. goto ErrorReturn;
  469. }
  470. strncpy(RecAction.pName, pszTempName, ( 16 > dwStrLen ) ? dwStrLen : 16);
  471. WinsFreeMemory(pszTempName);
  472. pszTempName = NULL;
  473. if( fDomain is TRUE &&
  474. fEndChar is FALSE )
  475. {
  476. ch16thChar = StringToHexA(L"1C");
  477. fEndChar = TRUE;
  478. }
  479. for( j=dwStrLen; j<16; j++ )
  480. {
  481. RecAction.pName[j] = ' ';
  482. }
  483. if( fEndChar is TRUE )
  484. {
  485. RecAction.pName[15] = (CHAR)ch16thChar;
  486. }
  487. RecAction.pName[16] = '\0';
  488. dwStrLen = 16;
  489. if( fScope )
  490. {
  491. DWORD dwLen;
  492. RecAction.pName[dwStrLen] = '.';
  493. pszTempName = WinsUnicodeToOem(wszScope, NULL);
  494. if( pszTempName is NULL )
  495. {
  496. Status = ERROR_NOT_ENOUGH_MEMORY;
  497. goto ErrorReturn;
  498. }
  499. dwLen = strlen(pszTempName);
  500. dwLen = ( 255 - dwStrLen < dwLen ) ? 255 - dwStrLen : dwLen;
  501. strncpy(RecAction.pName+dwStrLen+1, pszTempName, dwLen);
  502. WinsFreeMemory(pszTempName);
  503. pszTempName = NULL;
  504. RecAction.pName[dwStrLen+dwLen+1] = '\0';
  505. dwStrLen = strlen(RecAction.pName);
  506. if( fEndChar and
  507. ch16thChar is 0x00 )
  508. dwStrLen++;
  509. }
  510. RecAction.NameLen = dwStrLen;
  511. RecAction.Cmd_e = WINSINTF_E_INSERT;
  512. RecAction.fStatic = fStatic;
  513. if( pdwIpAddress is NULL )
  514. {
  515. Status = ERROR_INVALID_PARAMETER;
  516. goto ErrorReturn;
  517. }
  518. if( dwRecType isnot WINSINTF_E_NORM_GROUP and
  519. dwRecType isnot WINSINTF_E_SPEC_GROUP)
  520. {
  521. RecAction.NodeTyp = rgbNodeType;
  522. }
  523. //Treat each of the rectype when no endchar is specified specially.
  524. //This part of the code needs to be cleaned up after Beta3
  525. if( fEndChar is FALSE )
  526. {
  527. if( dwRecType is WINSINTF_E_SPEC_GROUP or
  528. dwRecType is WINSINTF_E_MULTIHOMED )
  529. {
  530. RecAction.pAdd = WinsAllocateMemory(dwIpCount*sizeof(WINSINTF_ADD_T));
  531. if( RecAction.pAdd is NULL )
  532. {
  533. Status = ERROR_NOT_ENOUGH_MEMORY;
  534. goto ErrorReturn;
  535. }
  536. for( j=0; j<dwIpCount; j++ )
  537. {
  538. (RecAction.pAdd+j)->IPAdd = pdwIpAddress[j];
  539. (RecAction.pAdd+j)->Type = 0;
  540. (RecAction.pAdd+j)->Len = 4;
  541. }
  542. RecAction.NoOfAdds = dwIpCount;
  543. }
  544. else
  545. {
  546. RecAction.Add.IPAdd = pdwIpAddress[0];
  547. RecAction.Add.Type = 0;
  548. RecAction.Add.Len = 4;
  549. }
  550. switch(dwRecType)
  551. {
  552. case WINSINTF_E_UNIQUE:
  553. {
  554. CHAR Type[]={0x03, 0x20, 0x00};
  555. for( i=0; i<3; i++ )
  556. {
  557. *(RecAction.pName + 15) = Type[i];
  558. if( Type[i] is 0x00 )
  559. {
  560. RecAction.pName[16] = '\0';
  561. RecAction.NameLen = 16;
  562. }
  563. RecAction.TypOfRec_e = dwRecType;
  564. pRecAction = &RecAction;
  565. Status = WinsRecordAction(g_hBind, &pRecAction);
  566. if( Status isnot NO_ERROR )
  567. goto ErrorReturn;
  568. }
  569. break;
  570. }
  571. case WINSINTF_E_NORM_GROUP:
  572. {
  573. RecAction.pName[15] = (CHAR)0x1E;
  574. pRecAction = &RecAction;
  575. RecAction.TypOfRec_e = dwRecType;
  576. Status = WinsRecordAction(g_hBind, &pRecAction);
  577. if( Status isnot NO_ERROR )
  578. goto ErrorReturn;
  579. break;
  580. }
  581. case WINSINTF_E_SPEC_GROUP:
  582. {
  583. RecAction.pName[15] = (CHAR)0x20;
  584. pRecAction = &RecAction;
  585. RecAction.TypOfRec_e = dwRecType;
  586. Status = WinsRecordAction(g_hBind, &pRecAction);
  587. if( Status isnot NO_ERROR )
  588. goto ErrorReturn;
  589. break;
  590. }
  591. case WINSINTF_E_MULTIHOMED:
  592. {
  593. CHAR Type[]={0x03, 0x20, 0x00};
  594. for( i=0; i<3; i++ )
  595. {
  596. *(RecAction.pName + 15) = Type[i];
  597. if( Type[i] is 0x00 )
  598. {
  599. *(RecAction.pName+16) = '\0';
  600. RecAction.NameLen = 16;
  601. }
  602. RecAction.TypOfRec_e = dwRecType;
  603. pRecAction = &RecAction;
  604. RecAction.NodeTyp = WINSINTF_E_PNODE;
  605. Status = WinsRecordAction(g_hBind, &pRecAction);
  606. if( Status isnot NO_ERROR )
  607. goto ErrorReturn;
  608. }
  609. break;
  610. }
  611. }
  612. }
  613. //Otherwise when Endchar is specified
  614. else
  615. {
  616. //if endchar is 0x00, ignore the scope if spcefied
  617. if( RecAction.pName[15] is 0x00 )
  618. {
  619. RecAction.NameLen = 16;
  620. }
  621. //If endchar is 0x1C
  622. if( RecAction.pName[15] is 0x1C )
  623. {
  624. RecAction.TypOfRec_e = WINSINTF_E_SPEC_GROUP;
  625. RecAction.NodeTyp = 0;
  626. }
  627. //else if EndChar is 0x1E or 0x1D
  628. else if( RecAction.pName[15] is 0x1E or
  629. RecAction.pName[15] is 0x1D )
  630. {
  631. RecAction.TypOfRec_e = WINSINTF_E_NORM_GROUP;
  632. RecAction.NodeTyp = 0;
  633. }
  634. if( RecAction.TypOfRec_e is WINSINTF_E_SPEC_GROUP )
  635. {
  636. RecAction.pAdd = WinsAllocateMemory(dwIpCount*sizeof(WINSINTF_ADD_T));
  637. if( RecAction.pAdd is NULL )
  638. {
  639. Status = ERROR_NOT_ENOUGH_MEMORY;
  640. goto ErrorReturn;
  641. }
  642. for( j=0; j<dwIpCount; j++ )
  643. {
  644. (RecAction.pAdd+j)->IPAdd = pdwIpAddress[j];
  645. (RecAction.pAdd+j)->Type = 0;
  646. (RecAction.pAdd+j)->Len = 4;
  647. }
  648. RecAction.NoOfAdds = dwIpCount;
  649. }
  650. else
  651. {
  652. RecAction.Add.IPAdd = pdwIpAddress[0];
  653. RecAction.Add.Type = 0;
  654. RecAction.Add.Len = 4;
  655. }
  656. pRecAction = &RecAction;
  657. Status = WinsRecordAction(g_hBind, &pRecAction );
  658. if( Status isnot NO_ERROR )
  659. goto ErrorReturn;
  660. }
  661. CommonReturn:
  662. if( Status is NO_ERROR )
  663. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  664. if( pszTempName )
  665. {
  666. WinsFreeMemory(pszTempName);
  667. pszTempName = NULL;
  668. }
  669. if( pdwTagNum )
  670. {
  671. WinsFreeMemory(pdwTagNum);
  672. pdwTagNum = NULL;
  673. }
  674. if( pdwTagType )
  675. {
  676. WinsFreeMemory(pdwTagType);
  677. pdwTagType = NULL;
  678. }
  679. if( RecAction.pName )
  680. {
  681. WinsFreeMemory(RecAction.pName);
  682. RecAction.pName = NULL;
  683. }
  684. if( RecAction.pAdd )
  685. {
  686. WinsFreeMemory(RecAction.pAdd);
  687. RecAction.pAdd = NULL;
  688. }
  689. if( pdwIpAddress )
  690. {
  691. WinsFreeMemory(pdwIpAddress);
  692. pdwIpAddress = NULL;
  693. }
  694. return Status;
  695. ErrorReturn:
  696. DisplayErrorMessage(EMSG_SRVR_ADD_NAME, Status);
  697. goto CommonReturn;
  698. }
  699. DWORD
  700. HandleSrvrAddPartner(
  701. IN LPCWSTR pwszMachine,
  702. IN OUT LPWSTR *ppwcArguments,
  703. IN DWORD dwCurrentIndex,
  704. IN DWORD dwArgCount,
  705. IN DWORD dwFlags,
  706. IN LPCVOID pvData,
  707. OUT BOOL *pbDone
  708. )
  709. /*++
  710. Routine Description :
  711. Adds a partner ( either Push or Pull or Both ) to the WINS server
  712. Arguments :
  713. All aguments are passes as array of wide char strings in ppwcArguments.
  714. Compulsory, ServerIpAddress
  715. Optional, ServerNetBios name and PartnerType.
  716. Note : Server NetBios name is required when Ip address can not be resolved
  717. to a name.
  718. PartherType by default is both. Otherwise whatever specified.
  719. Return Value:
  720. Returns the status of the operation.
  721. --*/
  722. {
  723. DWORD Status = NO_ERROR;
  724. DWORD i, j, dwNumArgs, dwTagCount;
  725. TAG_TYPE pttTags[] = {
  726. {WINS_TOKEN_SERVER, TRUE, FALSE},
  727. {WINS_TOKEN_NETBIOS, FALSE, FALSE},
  728. {WINS_TOKEN_TYPE, FALSE, FALSE},
  729. };
  730. LPWSTR pwszServerName = NULL;
  731. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  732. PDWORD pdwTagType=NULL, pdwTagNum=NULL;
  733. BOOL fPush = TRUE,
  734. fPull = TRUE;
  735. HKEY hServer = NULL,
  736. hPartner = NULL,
  737. hDefault = NULL,
  738. hKey = NULL;
  739. LPWSTR pTemp = NULL;
  740. DWORD dwKeyLen = 0;
  741. DWORD dwData = 0,
  742. dwDataLen = 0,
  743. dwType = 0;
  744. BOOL fIsNetBios = TRUE;
  745. //Need at least the server Ip Address
  746. if( dwArgCount < dwCurrentIndex + 1 )
  747. {
  748. DisplayMessage(g_hModule, HLP_SRVR_ADD_PARTNER_EX);
  749. Status = ERROR_INVALID_PARAMETER;
  750. goto ErrorReturn;
  751. }
  752. //Start processing the arguments based on ppwcArguments and dwArgCount and dwCurrnetIndex
  753. dwNumArgs = dwArgCount - dwCurrentIndex;
  754. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  755. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  756. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  757. if( pdwTagType is NULL or
  758. pdwTagNum is NULL )
  759. {
  760. Status = ERROR_NOT_ENOUGH_MEMORY;
  761. goto ErrorReturn;
  762. }
  763. Status = PreProcessCommand(ppwcArguments,
  764. dwArgCount,
  765. dwCurrentIndex,
  766. pttTags,
  767. &dwTagCount,
  768. pdwTagType,
  769. pdwTagNum);
  770. if( Status isnot NO_ERROR )
  771. goto ErrorReturn;
  772. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  773. {
  774. if( pttTags[i].dwRequired is TRUE and
  775. pttTags[i].bPresent is FALSE
  776. )
  777. {
  778. Status = ERROR_INVALID_PARAMETER;
  779. goto ErrorReturn;
  780. }
  781. }
  782. for( j=0; j<dwTagCount; j++)
  783. {
  784. switch(pdwTagType[j])
  785. {
  786. //Server IP Address. Try to resolve the IP to a name
  787. case 0:
  788. {
  789. struct hostent * lpHostEnt = NULL;
  790. CHAR cAddr[16];
  791. BYTE pbAdd[4];
  792. char szAdd[4];
  793. int k = 0, l=0;
  794. DWORD dwLen,nLen = 0;
  795. CHAR *pTemp = NULL;
  796. CHAR *pNetBios = NULL;
  797. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) is FALSE )
  798. {
  799. Status = ERROR_INVALID_IPADDRESS;
  800. goto ErrorReturn;
  801. }
  802. //if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  803. else
  804. {
  805. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  806. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  807. if(lpHostEnt isnot NULL )//Valid IP Address
  808. {
  809. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  810. }
  811. else
  812. {
  813. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  814. fIsNetBios = FALSE;
  815. break;
  816. }
  817. }
  818. dwLen = strlen(lpHostEnt->h_name);
  819. pTemp = WinsAllocateMemory(dwLen+1);
  820. if( pTemp is NULL )
  821. {
  822. Status = ERROR_NOT_ENOUGH_MEMORY;
  823. goto ErrorReturn;
  824. }
  825. strcpy(pTemp, lpHostEnt->h_name);
  826. pNetBios = strchr(pTemp, '.');
  827. if( pNetBios isnot NULL )
  828. {
  829. dwLen = (DWORD)(pNetBios - pTemp);
  830. pTemp[dwLen] = '\0';
  831. }
  832. pwszServerName = WinsAllocateMemory((dwLen+1)*sizeof(WCHAR));
  833. if( pwszServerName is NULL )
  834. {
  835. Status = ERROR_NOT_ENOUGH_MEMORY;
  836. goto ErrorReturn;
  837. }
  838. wcscpy(pwszServerName, WinsAnsiToUnicode(pTemp, NULL));
  839. if( pTemp )
  840. {
  841. WinsFreeMemory(pTemp);
  842. pTemp = NULL;
  843. }
  844. break;
  845. }
  846. //Server NetBios Name. Required only when Ip can not be resolved to a name.
  847. //Otherwise ignored.
  848. case 1:
  849. {
  850. if( fIsNetBios is FALSE )
  851. {
  852. pwszServerName = WinsAllocateMemory((wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]])+1)*sizeof(WCHAR));
  853. if( pwszServerName is NULL )
  854. {
  855. Status = ERROR_NOT_ENOUGH_MEMORY;
  856. goto ErrorReturn;
  857. }
  858. wcscpy(pwszServerName, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  859. fIsNetBios = TRUE;
  860. }
  861. break;
  862. }
  863. //Partner Type. Default is BOTH
  864. case 2:
  865. {
  866. DWORD dwType = 0;
  867. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  868. {
  869. Status = ERROR_INVALID_PARAMETER;
  870. goto ErrorReturn;
  871. }
  872. dwType = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  873. switch(dwType)
  874. {
  875. case 0:
  876. {
  877. fPull = TRUE;
  878. fPush = FALSE;
  879. break;
  880. }
  881. case 1:
  882. {
  883. fPull = FALSE;
  884. fPush = TRUE;
  885. break;
  886. }
  887. case 2:
  888. default:
  889. {
  890. fPull = TRUE;
  891. fPush = TRUE;
  892. break;
  893. }
  894. }
  895. break;
  896. }
  897. default:
  898. {
  899. Status = ERROR_INVALID_PARAMETER;
  900. goto ErrorReturn;
  901. }
  902. }
  903. }
  904. if( fIsNetBios is FALSE )
  905. {
  906. Status = ERROR_INVALID_IPADDRESS;
  907. goto ErrorReturn;
  908. }
  909. //Add the partner information to the registry and set the appropriate parameter
  910. {
  911. if( wcslen(g_ServerNetBiosName) > 0 )
  912. {
  913. pTemp = g_ServerNetBiosName;
  914. }
  915. Status = RegConnectRegistry(pTemp,
  916. HKEY_LOCAL_MACHINE,
  917. &hServer);
  918. if( Status isnot ERROR_SUCCESS )
  919. goto ErrorReturn;
  920. //Add the pull partner information
  921. if( fPull )
  922. {
  923. DWORD dwDisposition = 0;
  924. Status = RegCreateKeyEx(hServer,
  925. PULLROOT,
  926. 0,
  927. NULL,
  928. REG_OPTION_NON_VOLATILE,
  929. KEY_ALL_ACCESS,
  930. NULL,
  931. &hPartner,
  932. &dwDisposition);
  933. if( Status isnot NO_ERROR )
  934. {
  935. if( fPush )
  936. goto PUSH;
  937. goto ErrorReturn;
  938. }
  939. Status = RegCreateKeyEx(hPartner,
  940. wcServerIpAdd,
  941. 0,
  942. NULL,
  943. REG_OPTION_NON_VOLATILE,
  944. KEY_ALL_ACCESS,
  945. NULL,
  946. &hKey,
  947. NULL);
  948. if( Status isnot NO_ERROR )
  949. {
  950. if( fPush )
  951. goto PUSH;
  952. goto ErrorReturn;
  953. }
  954. Status = RegSetValueEx(hKey,
  955. NETBIOSNAME,
  956. 0,
  957. REG_SZ,
  958. (LPBYTE)pwszServerName,
  959. (wcslen(pwszServerName)+1)*sizeof(WCHAR));
  960. if(Status isnot NO_ERROR )
  961. {
  962. if( fPush )
  963. goto PUSH;
  964. goto ErrorReturn;
  965. }
  966. dwType = REG_DWORD;
  967. dwData = 0;
  968. dwDataLen = sizeof(DWORD);
  969. Status = RegQueryValueEx(
  970. hPartner,
  971. PERSISTENCE,
  972. 0,
  973. &dwType,
  974. (LPBYTE)&dwData,
  975. &dwDataLen);
  976. if( Status isnot NO_ERROR )
  977. {
  978. dwData = 0;
  979. dwDataLen = sizeof(DWORD);
  980. }
  981. Status = RegSetValueEx(hKey,
  982. PERSISTENCE,
  983. 0,
  984. REG_DWORD,
  985. (LPBYTE)&dwData,
  986. dwDataLen);
  987. if( Status isnot NO_ERROR )
  988. {
  989. if( fPush )
  990. goto PUSH;
  991. goto ErrorReturn;
  992. }
  993. dwType = REG_DWORD;
  994. dwData = 0;
  995. dwDataLen = sizeof(DWORD);
  996. Status = RegQueryValueEx(hPartner,
  997. WINSCNF_SELF_FND_NM,
  998. 0,
  999. &dwType,
  1000. (LPBYTE)&dwData,
  1001. &dwDataLen);
  1002. if( Status isnot NO_ERROR )
  1003. {
  1004. dwData = 0;
  1005. dwDataLen = sizeof(DWORD);
  1006. }
  1007. Status = RegSetValueEx(hKey,
  1008. WINSCNF_SELF_FND_NM,
  1009. 0,
  1010. REG_DWORD,
  1011. (LPBYTE)&dwData,
  1012. dwDataLen);
  1013. if( Status isnot NO_ERROR )
  1014. {
  1015. if( fPush )
  1016. goto PUSH;
  1017. goto ErrorReturn;
  1018. }
  1019. Status = RegOpenKeyEx(hServer,
  1020. DEFAULTPULL,
  1021. 0,
  1022. KEY_ALL_ACCESS,
  1023. &hDefault);
  1024. if( Status is NO_ERROR )
  1025. {
  1026. dwType = REG_DWORD;
  1027. dwData = 0;
  1028. dwDataLen = sizeof(DWORD);
  1029. Status = RegQueryValueEx(hDefault,
  1030. WINSCNF_RPL_INTERVAL_NM,
  1031. 0,
  1032. &dwType,
  1033. (LPBYTE)&dwData,
  1034. &dwDataLen);
  1035. if(Status isnot NO_ERROR )
  1036. {
  1037. dwData = 1800;
  1038. dwDataLen = sizeof(DWORD);
  1039. }
  1040. }
  1041. else
  1042. {
  1043. dwData = 1800;
  1044. dwDataLen = sizeof(DWORD);
  1045. }
  1046. Status = RegSetValueEx(hKey,
  1047. WINSCNF_RPL_INTERVAL_NM,
  1048. 0,
  1049. REG_DWORD,
  1050. (LPBYTE)&dwData,
  1051. dwDataLen);
  1052. if( Status isnot NO_ERROR )
  1053. {
  1054. if( fPush )
  1055. goto PUSH;
  1056. goto ErrorReturn;
  1057. }
  1058. }
  1059. //Add the push partner information
  1060. PUSH: if( hKey )
  1061. {
  1062. RegCloseKey(hKey);
  1063. hKey = NULL;
  1064. }
  1065. if( hDefault )
  1066. {
  1067. RegCloseKey(hDefault);
  1068. hDefault = NULL;
  1069. }
  1070. if( hPartner )
  1071. {
  1072. RegCloseKey(hPartner);
  1073. hPartner = NULL;
  1074. }
  1075. if( fPush )
  1076. {
  1077. DWORD dwDisposition = 0;
  1078. Status = RegCreateKeyEx(hServer,
  1079. PUSHROOT,
  1080. 0,
  1081. NULL,
  1082. REG_OPTION_NON_VOLATILE,
  1083. KEY_ALL_ACCESS,
  1084. NULL,
  1085. &hPartner,
  1086. &dwDisposition);
  1087. if( Status isnot NO_ERROR )
  1088. {
  1089. goto ErrorReturn;
  1090. }
  1091. Status = RegCreateKeyEx(hPartner,
  1092. wcServerIpAdd,
  1093. 0,
  1094. NULL,
  1095. REG_OPTION_NON_VOLATILE,
  1096. KEY_ALL_ACCESS,
  1097. NULL,
  1098. &hKey,
  1099. NULL);
  1100. if( Status isnot NO_ERROR )
  1101. {
  1102. goto ErrorReturn;
  1103. }
  1104. Status = RegSetValueEx(hKey,
  1105. NETBIOSNAME,
  1106. 0,
  1107. REG_SZ,
  1108. (LPBYTE)pwszServerName,
  1109. (wcslen(pwszServerName)+1)*sizeof(WCHAR));
  1110. if(Status isnot NO_ERROR )
  1111. {
  1112. goto ErrorReturn;
  1113. }
  1114. dwType = REG_DWORD;
  1115. dwData = 0;
  1116. dwDataLen = sizeof(DWORD);
  1117. Status = RegQueryValueEx(
  1118. hPartner,
  1119. PERSISTENCE,
  1120. 0,
  1121. &dwType,
  1122. (LPBYTE)&dwData,
  1123. &dwDataLen);
  1124. if( Status isnot NO_ERROR )
  1125. {
  1126. dwData = 0;
  1127. dwDataLen = sizeof(DWORD);
  1128. }
  1129. Status = RegSetValueEx(hKey,
  1130. PERSISTENCE,
  1131. 0,
  1132. REG_DWORD,
  1133. (LPBYTE)&dwData,
  1134. dwDataLen);
  1135. if( Status isnot NO_ERROR )
  1136. {
  1137. goto ErrorReturn;
  1138. }
  1139. dwType = REG_DWORD;
  1140. dwData = 0;
  1141. dwDataLen = sizeof(DWORD);
  1142. Status = RegQueryValueEx(hPartner,
  1143. WINSCNF_SELF_FND_NM,
  1144. 0,
  1145. &dwType,
  1146. (LPBYTE)&dwData,
  1147. &dwDataLen);
  1148. if( Status isnot NO_ERROR )
  1149. {
  1150. dwData = 0;
  1151. dwDataLen = sizeof(DWORD);
  1152. }
  1153. Status = RegSetValueEx(hKey,
  1154. WINSCNF_SELF_FND_NM,
  1155. 0,
  1156. REG_DWORD,
  1157. (LPBYTE)&dwData,
  1158. dwDataLen);
  1159. if( Status isnot NO_ERROR )
  1160. goto ErrorReturn;
  1161. Status = RegOpenKeyEx(hServer,
  1162. DEFAULTPUSH,
  1163. 0,
  1164. KEY_ALL_ACCESS,
  1165. &hDefault);
  1166. if( Status is NO_ERROR )
  1167. {
  1168. dwType = REG_DWORD;
  1169. dwData = 0;
  1170. dwDataLen = sizeof(DWORD);
  1171. Status = RegQueryValueEx(hDefault,
  1172. WINSCNF_UPDATE_COUNT_NM,
  1173. 0,
  1174. &dwType,
  1175. (LPBYTE)&dwData,
  1176. &dwDataLen);
  1177. if(Status isnot NO_ERROR )
  1178. {
  1179. dwData = 0;
  1180. dwDataLen = sizeof(DWORD);
  1181. }
  1182. }
  1183. else
  1184. {
  1185. dwData = 0;
  1186. dwDataLen = sizeof(DWORD);
  1187. }
  1188. Status = RegSetValueEx(hKey,
  1189. WINSCNF_UPDATE_COUNT_NM,
  1190. 0,
  1191. REG_DWORD,
  1192. (LPBYTE)&dwData,
  1193. dwDataLen);
  1194. if( Status isnot NO_ERROR )
  1195. {
  1196. goto ErrorReturn;
  1197. }
  1198. if( hKey )
  1199. {
  1200. RegCloseKey(hKey);
  1201. hKey = NULL;
  1202. }
  1203. if( hDefault )
  1204. {
  1205. RegCloseKey(hDefault);
  1206. hDefault = NULL;
  1207. }
  1208. if( hPartner )
  1209. {
  1210. RegCloseKey(hPartner);
  1211. hPartner = NULL;
  1212. }
  1213. }
  1214. }
  1215. CommonReturn:
  1216. if( Status is NO_ERROR )
  1217. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  1218. if( pdwTagType )
  1219. {
  1220. WinsFreeMemory(pdwTagType);
  1221. pdwTagType = NULL;
  1222. }
  1223. if( pdwTagNum )
  1224. {
  1225. WinsFreeMemory(pdwTagNum);
  1226. pdwTagNum = NULL;
  1227. }
  1228. if( pwszServerName )
  1229. {
  1230. WinsFreeMemory(pwszServerName);
  1231. pwszServerName = NULL;
  1232. }
  1233. if( hServer )
  1234. {
  1235. RegCloseKey(hServer);
  1236. hServer = NULL;
  1237. }
  1238. if( hDefault )
  1239. {
  1240. RegCloseKey(hDefault);
  1241. hDefault = NULL;
  1242. }
  1243. return Status;
  1244. ErrorReturn:
  1245. DisplayErrorMessage(EMSG_SRVR_ADD_PARTNER, Status);
  1246. if( hKey )
  1247. {
  1248. RegCloseKey(hKey);
  1249. hKey = NULL;
  1250. }
  1251. if( hPartner )
  1252. {
  1253. RegDeleteKey(hPartner, g_ServerIpAddressUnicodeString);
  1254. RegCloseKey(hPartner);
  1255. hPartner = NULL;
  1256. }
  1257. goto CommonReturn;
  1258. }
  1259. BOOL CheckValidPgOp(HKEY hPartner, BOOL fGrata)
  1260. /*++
  1261. Routine Description :
  1262. Check whether Persona Mode allows operation for persona grata (fGrata) or non-grata (!fGrata)
  1263. Arguments :
  1264. hPartner = opened handle to the 'Partners' registry key
  1265. fGrata specifies whether the check is done for a persona Grata (TRUE) operation or of
  1266. a persona Non-Grata (FALSE) operation
  1267. Return Value:
  1268. Returns TRUE if the operation is allowed, FALSE otherwise.
  1269. --*/
  1270. {
  1271. DWORD dwPersMode = 0; // default (entry not existant) = Persona Non-Grata
  1272. DWORD dwType;
  1273. DWORD dwSize = sizeof(DWORD);
  1274. // don't chare about the return code. If something goes wrong (entry not existant)
  1275. // consider Persona Mode as being 'Persona Non-Grata'.
  1276. RegQueryValueExA(hPartner,
  1277. WINSCNF_PERSONA_MODE_NM,
  1278. NULL,
  1279. &dwType,
  1280. (LPVOID)&dwPersMode,
  1281. &dwSize);
  1282. return dwPersMode ? fGrata : !fGrata;
  1283. }
  1284. DWORD
  1285. HandleSrvrAddPersona(
  1286. IN LPCWSTR pwszMachine,
  1287. IN OUT LPWSTR *ppwcArguments,
  1288. IN DWORD dwCurrentIndex,
  1289. IN DWORD dwArgCount,
  1290. IN DWORD dwFlags,
  1291. IN LPCVOID pvData,
  1292. OUT BOOL *pbDone
  1293. )
  1294. /*++
  1295. Routine Description :
  1296. Add Persona Non Grata servers for the WINS Server
  1297. Arguments :
  1298. All aguments are passes as array of wide char strings in ppwcArguments.
  1299. Compulsory, List of Server Ip addresses seperated by commas and enclosed
  1300. by {} ( curly braces )
  1301. Return Value:
  1302. Returns the status of the operation.
  1303. --*/
  1304. {
  1305. DWORD Status = NO_ERROR;
  1306. DWORD i, j, dwNumArgs, dwTagCount;
  1307. TAG_TYPE pttTags[] = {
  1308. {WINS_TOKEN_SERVERS, TRUE, FALSE},
  1309. };
  1310. DWORD dwTagType = 0,
  1311. dwTagNum = 0;
  1312. DWORD dwSize = 0,
  1313. dwType = REG_MULTI_SZ,
  1314. dwPngIp = 0,
  1315. dwTotal = 0;
  1316. LPWSTR pwszPngIp = NULL;
  1317. LPWSTR pTemp = NULL;
  1318. LPWSTR pwszTempKey = NULL;
  1319. LPBYTE pbByte = NULL;
  1320. HKEY hServer = NULL,
  1321. hPartner = NULL;
  1322. LPDWORD pdwPngIp = NULL;
  1323. DWORD dwLenCount = 0,
  1324. dwTemp = 0;
  1325. BOOL fGrata;
  1326. fGrata = (wcsstr(CMD_SRVR_ADD_PNGSERVER, ppwcArguments[dwCurrentIndex-1]) == NULL);
  1327. //Needs a parameter always
  1328. if( dwArgCount < dwCurrentIndex + 1 )
  1329. {
  1330. DisplayMessage(g_hModule, fGrata ? HLP_SRVR_ADD_PGSERVER_EX : HLP_SRVR_ADD_PNGSERVER_EX);
  1331. Status = ERROR_INVALID_PARAMETER;
  1332. goto ErrorReturn;
  1333. }
  1334. dwNumArgs = dwArgCount - dwCurrentIndex;
  1335. if( wcslen(g_ServerNetBiosName) > 0 )
  1336. {
  1337. pTemp = g_ServerNetBiosName;
  1338. }
  1339. Status = RegConnectRegistry(pTemp,
  1340. HKEY_LOCAL_MACHINE,
  1341. &hServer);
  1342. if( Status isnot NO_ERROR )
  1343. goto ErrorReturn;
  1344. Status = RegOpenKeyEx(hServer,
  1345. PARTNERROOT,
  1346. 0,
  1347. KEY_ALL_ACCESS,
  1348. &hPartner);
  1349. if( Status isnot NO_ERROR )
  1350. goto ErrorReturn;
  1351. if (!CheckValidPgOp(hPartner, fGrata))
  1352. {
  1353. DisplayMessage(g_hModule, fGrata ? EMSG_SRVR_PG_INVALIDOP : EMSG_SRVR_PNG_INVALIDOP);
  1354. Status = ERROR_INVALID_PARAMETER;
  1355. goto CommonReturn;
  1356. }
  1357. if (fGrata)
  1358. pwszTempKey = WinsOemToUnicode(WINSCNF_PERSONA_GRATA_NM, NULL);
  1359. else
  1360. pwszTempKey = WinsOemToUnicode(WINSCNF_PERSONA_NON_GRATA_NM, NULL);
  1361. if( pwszTempKey is NULL )
  1362. {
  1363. Status = ERROR_NOT_ENOUGH_MEMORY;
  1364. goto ErrorReturn;
  1365. }
  1366. Status = RegQueryValueEx(hPartner,
  1367. pwszTempKey,
  1368. NULL,
  1369. &dwType,
  1370. pbByte,
  1371. &dwSize);
  1372. WinsFreeMemory(pwszTempKey);
  1373. pwszTempKey = NULL;
  1374. if( Status isnot NO_ERROR and
  1375. Status isnot 2 )
  1376. goto ErrorReturn;
  1377. if( dwSize > 7 )
  1378. {
  1379. LPWSTR pwszPng = NULL;
  1380. pbByte = WinsAllocateMemory(dwSize+2);
  1381. dwSize+=2;
  1382. if( pbByte is NULL )
  1383. {
  1384. Status = ERROR_NOT_ENOUGH_MEMORY;
  1385. goto ErrorReturn;
  1386. }
  1387. Status = RegQueryValueEx(hPartner,
  1388. fGrata ? PGSERVER : PNGSERVER,
  1389. NULL,
  1390. &dwType,
  1391. pbByte,
  1392. &dwSize);
  1393. if( Status isnot NO_ERROR )
  1394. goto ErrorReturn;
  1395. pwszPng = (LPWSTR)pbByte;
  1396. pwszPngIp = WinsAllocateMemory(dwSize);
  1397. if( pwszPngIp is NULL )
  1398. {
  1399. Status = ERROR_NOT_ENOUGH_MEMORY;
  1400. goto ErrorReturn;
  1401. }
  1402. memcpy(pwszPngIp, pbByte, dwSize);
  1403. for( i=0; i<(dwSize+2)/sizeof(WCHAR); i++ )
  1404. {
  1405. if( pwszPng[i] is L'\0' and
  1406. pwszPng[i+1] isnot L'\0')
  1407. {
  1408. pwszPng[i] = L',';
  1409. i++;
  1410. }
  1411. }
  1412. dwPngIp = 0;
  1413. pTemp = wcstok(pwszPng, L",");
  1414. while(pTemp isnot NULL )
  1415. {
  1416. LPDWORD pdwTemp = pdwPngIp;
  1417. dwPngIp++;
  1418. dwLenCount += wcslen(pTemp);
  1419. pdwPngIp = WinsAllocateMemory(dwPngIp*sizeof(DWORD));
  1420. if( pdwPngIp is NULL )
  1421. {
  1422. WinsFreeMemory(pdwTemp);
  1423. pdwTemp = NULL;
  1424. Status = ERROR_INVALID_PARAMETER;
  1425. goto ErrorReturn;
  1426. }
  1427. if( pdwTemp isnot NULL )
  1428. {
  1429. memcpy(pdwPngIp, pdwTemp, (dwPngIp-1)*sizeof(DWORD));
  1430. WinsFreeMemory(pdwTemp);
  1431. pdwTemp = NULL;
  1432. }
  1433. pdwPngIp[dwPngIp-1] = StringToIpAddress(pTemp);
  1434. pTemp = wcstok(NULL, L",");
  1435. dwLenCount++;
  1436. }
  1437. }
  1438. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  1439. Status = PreProcessCommand(ppwcArguments,
  1440. dwArgCount,
  1441. dwCurrentIndex,
  1442. pttTags,
  1443. &dwTagCount,
  1444. &dwTagType,
  1445. &dwTagNum);
  1446. if( Status isnot NO_ERROR )
  1447. goto ErrorReturn;
  1448. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  1449. {
  1450. if( pttTags[i].dwRequired is TRUE and
  1451. pttTags[i].bPresent is FALSE
  1452. )
  1453. {
  1454. Status = ERROR_INVALID_PARAMETER;
  1455. goto ErrorReturn;
  1456. }
  1457. }
  1458. for( j=0; j<dwTagCount; j++ )
  1459. {
  1460. switch(dwTagType)
  1461. {
  1462. //Server Ip Address List
  1463. case 0:
  1464. {
  1465. DWORD dwIpLen = 0;
  1466. LPWSTR pwszIps = NULL;
  1467. dwIpLen = wcslen(ppwcArguments[dwCurrentIndex+dwTagNum]);
  1468. if( ppwcArguments[dwCurrentIndex+dwTagNum][0] isnot L'{' or
  1469. ppwcArguments[dwCurrentIndex+dwTagNum][dwIpLen-1] isnot L'}')
  1470. {
  1471. Status = ERROR_INVALID_PARAMETER;
  1472. goto ErrorReturn;
  1473. }
  1474. ppwcArguments[dwCurrentIndex+dwTagNum][dwIpLen-1] =L'\0';
  1475. dwIpLen--;
  1476. pwszIps = WinsAllocateMemory((dwIpLen)*sizeof(WCHAR));
  1477. if( pwszIps is NULL )
  1478. {
  1479. Status = ERROR_NOT_ENOUGH_MEMORY;
  1480. goto ErrorReturn;
  1481. }
  1482. memcpy(pwszIps, ppwcArguments[dwCurrentIndex+dwTagNum]+1, (dwIpLen-1)*sizeof(WCHAR));
  1483. i=0;
  1484. pTemp = wcstok(pwszIps, L",");
  1485. while(pTemp isnot NULL)
  1486. {
  1487. BOOL fPresent = FALSE;
  1488. DWORD dw = 0;
  1489. if( IsIpAddress(pTemp) is FALSE )
  1490. {
  1491. DisplayMessage(g_hModule,
  1492. EMSG_SRVR_IP_DISCARD,
  1493. pTemp);
  1494. pTemp = wcstok(NULL, L",");
  1495. continue;
  1496. }
  1497. else
  1498. {
  1499. dw = StringToIpAddress(pTemp);
  1500. for( j=0; j<dwPngIp; j++ )
  1501. {
  1502. if( dw is INADDR_NONE )
  1503. {
  1504. continue;
  1505. }
  1506. if( pdwPngIp[j] is dw )
  1507. {
  1508. fPresent = TRUE;
  1509. break;
  1510. }
  1511. else
  1512. {
  1513. continue;
  1514. }
  1515. }
  1516. if( fPresent is FALSE )
  1517. {
  1518. LPDWORD pdwTemp = pdwPngIp;
  1519. pdwPngIp = WinsAllocateMemory((dwPngIp+1)*sizeof(DWORD));
  1520. if( pdwTemp )
  1521. {
  1522. memcpy(pdwPngIp, pdwTemp, dwPngIp*sizeof(DWORD));
  1523. WinsFreeMemory(pdwTemp);
  1524. pdwTemp = NULL;
  1525. }
  1526. pdwPngIp[dwPngIp] = dw;
  1527. dwPngIp++;
  1528. dwTotal++;
  1529. }
  1530. else
  1531. {
  1532. DisplayMessage(g_hModule,
  1533. EMSG_SRVR_DUPLICATE_DISCARD,
  1534. pTemp);
  1535. }
  1536. }
  1537. pTemp = wcstok(NULL, L",");
  1538. }
  1539. if( pwszIps )
  1540. {
  1541. WinsFreeMemory(pwszIps);
  1542. pwszIps = NULL;
  1543. }
  1544. break;
  1545. }
  1546. default:
  1547. {
  1548. Status = ERROR_INVALID_PARAMETER;
  1549. goto ErrorReturn;
  1550. }
  1551. }
  1552. }
  1553. if( pwszPngIp )
  1554. {
  1555. WinsFreeMemory(pwszPngIp);
  1556. pwszPngIp = NULL;
  1557. }
  1558. pwszPngIp = WinsAllocateMemory((dwPngIp*(MAX_IP_STRING_LEN+1)+2)*sizeof(WCHAR));
  1559. if( pwszPngIp is NULL )
  1560. {
  1561. Status = ERROR_NOT_ENOUGH_MEMORY;
  1562. goto ErrorReturn;
  1563. }
  1564. dwTemp = 0;
  1565. for( i=0; i<dwPngIp; i++ )
  1566. {
  1567. LPWSTR pwIp = IpAddressToString(pdwPngIp[i]);
  1568. if( pwIp is NULL )
  1569. {
  1570. Status = ERROR_NOT_ENOUGH_MEMORY;
  1571. goto ErrorReturn;
  1572. }
  1573. wcscpy(pwszPngIp+dwTemp, pwIp);
  1574. dwTemp+= wcslen(pwIp);
  1575. dwTemp++;
  1576. WinsFreeMemory(pwIp);
  1577. pwIp = NULL;
  1578. }
  1579. pwszPngIp[dwTemp] = L'\0';
  1580. pwszPngIp[dwTemp+1] = L'\0';
  1581. Status = RegSetValueEx(hPartner,
  1582. fGrata? PGSERVER : PNGSERVER,
  1583. 0,
  1584. REG_MULTI_SZ,
  1585. (LPBYTE)pwszPngIp,
  1586. (dwTemp+1)*sizeof(WCHAR));
  1587. if( Status isnot NO_ERROR )
  1588. goto ErrorReturn;
  1589. CommonReturn:
  1590. if( Status is NO_ERROR )
  1591. {
  1592. if( dwTotal is 0 )
  1593. {
  1594. DisplayMessage(g_hModule,
  1595. fGrata ? EMSG_SRVR_NO_IP_ADDED_PG : EMSG_SRVR_NO_IP_ADDED_PNG);
  1596. }
  1597. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  1598. }
  1599. if( hPartner )
  1600. {
  1601. RegCloseKey(hPartner);
  1602. hPartner = NULL;
  1603. }
  1604. if( hServer )
  1605. {
  1606. RegCloseKey(hServer);
  1607. hServer = NULL;
  1608. }
  1609. if( pwszPngIp )
  1610. {
  1611. WinsFreeMemory(pwszPngIp);
  1612. pwszPngIp = NULL;
  1613. }
  1614. if( pdwPngIp )
  1615. {
  1616. WinsFreeMemory(pdwPngIp);
  1617. pdwPngIp = NULL;
  1618. }
  1619. if( pbByte )
  1620. {
  1621. WinsFreeMemory(pbByte);
  1622. pbByte = NULL;
  1623. }
  1624. return Status;
  1625. ErrorReturn:
  1626. DisplayErrorMessage(fGrata ? EMSG_SRVR_ADD_PGSERVER : EMSG_SRVR_ADD_PNGSERVER, Status);
  1627. goto CommonReturn;
  1628. }
  1629. DWORD
  1630. HandleSrvrCheckDatabase(
  1631. IN LPCWSTR pwszMachine,
  1632. IN OUT LPWSTR *ppwcArguments,
  1633. IN DWORD dwCurrentIndex,
  1634. IN DWORD dwArgCount,
  1635. IN DWORD dwFlags,
  1636. IN LPCVOID pvData,
  1637. OUT BOOL *pbDone
  1638. )
  1639. /*++
  1640. Routine Description :
  1641. Checks the consistency of the database
  1642. Arguments :
  1643. No arguments
  1644. Return Value:
  1645. Returns the status of the operation.
  1646. --*/
  1647. {
  1648. DWORD Status = NO_ERROR;
  1649. DWORD i, j, dwNumArgs, dwTagCount;
  1650. TAG_TYPE pttTags[] = {
  1651. {WINS_TOKEN_ALL, FALSE, FALSE},
  1652. {WINS_TOKEN_FORCE, FALSE, FALSE},
  1653. };
  1654. BOOL fAll = FALSE, fForce = FALSE;
  1655. LPDWORD pdwTagType = NULL, pdwTagNum = NULL;
  1656. WINSINTF_SCV_REQ_T ScvReq;
  1657. if( dwArgCount > dwCurrentIndex )
  1658. {
  1659. //Start processing the arguments
  1660. dwNumArgs = dwArgCount - dwCurrentIndex;
  1661. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  1662. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  1663. if( pdwTagType is NULL or
  1664. pdwTagNum is NULL )
  1665. {
  1666. Status = ERROR_NOT_ENOUGH_MEMORY;
  1667. goto ErrorReturn;
  1668. }
  1669. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  1670. Status = PreProcessCommand(ppwcArguments,
  1671. dwArgCount,
  1672. dwCurrentIndex,
  1673. pttTags,
  1674. &dwTagCount,
  1675. pdwTagType,
  1676. pdwTagNum);
  1677. if( Status isnot NO_ERROR )
  1678. goto ErrorReturn;
  1679. for( j=0; j<dwTagCount; j++ )
  1680. {
  1681. switch(pdwTagType[j])
  1682. {
  1683. //Consistency check all or those older than verify interval
  1684. case 0:
  1685. {
  1686. DWORD dw = 0;
  1687. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  1688. {
  1689. Status = ERROR_INVALID_PARAMETER;
  1690. goto ErrorReturn;
  1691. }
  1692. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  1693. if( dw == 1 )
  1694. {
  1695. fAll = TRUE;
  1696. }
  1697. else if( dw == 0 )
  1698. {
  1699. fAll = FALSE;
  1700. }
  1701. else
  1702. {
  1703. Status = ERROR_INVALID_PARAMETER;
  1704. goto ErrorReturn;
  1705. }
  1706. break;
  1707. }
  1708. //Override wins checking in overloaded condition
  1709. case 1 :
  1710. {
  1711. DWORD dw = 0;
  1712. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  1713. {
  1714. Status = ERROR_INVALID_PARAMETER;
  1715. goto ErrorReturn;
  1716. }
  1717. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  1718. if( dw == 1 )
  1719. {
  1720. fForce = TRUE;
  1721. }
  1722. else if( dw == 0 )
  1723. {
  1724. fForce = FALSE;
  1725. }
  1726. else
  1727. {
  1728. Status = ERROR_INVALID_PARAMETER;
  1729. goto ErrorReturn;
  1730. }
  1731. break;
  1732. }
  1733. default:
  1734. {
  1735. Status = ERROR_INVALID_PARAMETER;
  1736. goto ErrorReturn;
  1737. }
  1738. }
  1739. }
  1740. }
  1741. if( fAll )
  1742. ScvReq.Age = 0; // check all the replicas
  1743. else
  1744. ScvReq.Age = 1;
  1745. if( fForce )
  1746. ScvReq.fForce = TRUE;
  1747. else
  1748. ScvReq.fForce = FALSE;
  1749. ScvReq.Opcode_e = WINSINTF_E_SCV_VERIFY;
  1750. Status = WinsDoScavengingNew(g_hBind, &ScvReq);
  1751. if( Status isnot NO_ERROR )
  1752. goto ErrorReturn;
  1753. DisplayMessage(g_hModule, MSG_WINS_COMMAND_QUEUED);
  1754. CommonReturn:
  1755. if( pdwTagType )
  1756. {
  1757. WinsFreeMemory(pdwTagType);
  1758. pdwTagType = NULL;
  1759. }
  1760. if( pdwTagNum )
  1761. {
  1762. WinsFreeMemory(pdwTagNum);
  1763. pdwTagNum = NULL;
  1764. }
  1765. return Status;
  1766. ErrorReturn:
  1767. DisplayErrorMessage(EMSG_SRVR_CHECK_DATABASE,
  1768. Status);
  1769. goto CommonReturn;
  1770. }
  1771. DWORD
  1772. HandleSrvrCheckName(
  1773. IN LPCWSTR pwszMachine,
  1774. IN OUT LPWSTR *ppwcArguments,
  1775. IN DWORD dwCurrentIndex,
  1776. IN DWORD dwArgCount,
  1777. IN DWORD dwFlags,
  1778. IN LPCVOID pvData,
  1779. OUT BOOL *pbDone
  1780. )
  1781. /*++
  1782. Routine Description :
  1783. Checks a list of names against a list of WINS servers
  1784. Arguments :
  1785. All aguments are passes as array of wide char strings in ppwcArguments.
  1786. Compulsory, either a list of names or a file which contains the list of names.
  1787. Names should be in the format (name)*(16th char) and either a list of server
  1788. IP addresses, separated by commas and enclosed by {} or a file that contains
  1789. the list of ip address in comma seperated format.
  1790. Optional, to include all partners in the server list.
  1791. Return Value:
  1792. Returns the status of the operation.
  1793. --*/
  1794. {
  1795. DWORD Status = NO_ERROR;
  1796. DWORD i, j, dwNumArgs, dwTagCount;
  1797. TAG_TYPE pttTags[] = {
  1798. {WINS_TOKEN_NAMELIST, FALSE, FALSE},
  1799. {WINS_TOKEN_NAMEFILE, FALSE, FALSE},
  1800. {WINS_TOKEN_SERVERLIST, FALSE, FALSE},
  1801. {WINS_TOKEN_SERVERFILE, FALSE, FALSE},
  1802. {WINS_TOKEN_INCLPARTNER, FALSE, FALSE},
  1803. };
  1804. BOOL fNameFile = FALSE,
  1805. fServerFile = FALSE;
  1806. LPWSTR pwszNameFile = NULL,
  1807. pwszServerFile = NULL;
  1808. PDWORD pdwTagType = NULL,
  1809. pdwTagNum = NULL;
  1810. PDWORD pdwIpAddress = NULL;
  1811. LPWSTR *ppNames = NULL;
  1812. BOOL fInclPartner = FALSE,
  1813. fIpEmpty = TRUE;
  1814. //Need at least a list of names either directly or thro' file and
  1815. //a list of server Ip either direcly or thro' file.
  1816. if( dwArgCount < dwCurrentIndex + 2 )
  1817. {
  1818. DisplayMessage(g_hModule, HLP_SRVR_CHECK_NAME_EX);
  1819. Status = ERROR_INVALID_PARAMETER;
  1820. goto ErrorReturn;
  1821. }
  1822. //Start processing the arguments
  1823. dwNumArgs = dwArgCount - dwCurrentIndex;
  1824. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  1825. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  1826. if( pdwTagType is NULL or
  1827. pdwTagNum is NULL )
  1828. {
  1829. Status = ERROR_NOT_ENOUGH_MEMORY;
  1830. goto ErrorReturn;
  1831. }
  1832. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  1833. Status = PreProcessCommand(ppwcArguments,
  1834. dwArgCount,
  1835. dwCurrentIndex,
  1836. pttTags,
  1837. &dwTagCount,
  1838. pdwTagType,
  1839. pdwTagNum);
  1840. if( Status isnot NO_ERROR )
  1841. goto ErrorReturn;
  1842. if( ( pttTags[0].bPresent is TRUE and
  1843. pttTags[1].bPresent is TRUE ) or
  1844. ( pttTags[2].bPresent is TRUE and
  1845. pttTags[3].bPresent is TRUE ) )
  1846. {
  1847. Status = ERROR_INVALID_PARAMETER_SPECIFICATION;
  1848. goto ErrorReturn;
  1849. }
  1850. WinServers = WinsAllocateMemory(MAX_SERVERS*sizeof(*WinServers));
  1851. if( WinServers is NULL )
  1852. {
  1853. Status = ERROR_NOT_ENOUGH_MEMORY;
  1854. goto ErrorReturn;
  1855. }
  1856. NBNames = (u_char ** )WinsAllocateMemory(MAX_NB_NAMES*sizeof(u_char*));
  1857. if( NBNames is NULL )
  1858. {
  1859. Status = ERROR_NOT_ENOUGH_MEMORY;
  1860. goto ErrorReturn;
  1861. }
  1862. for( j=0; j<dwTagCount; j++ )
  1863. {
  1864. switch(pdwTagType[j])
  1865. {
  1866. case 0://NameList
  1867. {
  1868. LPWSTR pwszToken = L",\r\n\t ";
  1869. LPWSTR pwszName = NULL;
  1870. LPWSTR pwszTemp = NULL;
  1871. int ilen = 0;
  1872. LPWSTR pTemp = NULL;
  1873. BOOL fPresent = FALSE;
  1874. DWORD dw = 0,
  1875. dwType = 0;
  1876. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  1877. if( dwLen < 2 )
  1878. {
  1879. NumNBNames = 0;
  1880. break;
  1881. }
  1882. if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] isnot L'{' or
  1883. ppwcArguments[dwCurrentIndex+pdwTagNum[j]][dwLen-1] isnot L'}' )
  1884. {
  1885. NumNBNames = 0;
  1886. break;
  1887. }
  1888. pwszTemp = WinsAllocateMemory((dwLen)*sizeof(WCHAR));
  1889. if(pwszTemp is NULL )
  1890. {
  1891. Status = ERROR_NOT_ENOUGH_MEMORY;
  1892. goto ErrorReturn;
  1893. }
  1894. for( ilen=0; ilen<NumNBNames; ilen++ )
  1895. {
  1896. if( NBNames[ilen] isnot NULL )
  1897. {
  1898. WinsFreeMemory(NBNames[ilen]);
  1899. NBNames[ilen] = NULL;
  1900. }
  1901. }
  1902. NumNBNames = 0;
  1903. wcscpy(pwszTemp, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+1);
  1904. pwszTemp[dwLen-2] = L'\0';
  1905. pwszName = wcstok(pwszTemp, pwszToken);
  1906. while(pwszName isnot NULL )
  1907. {
  1908. dw = wcslen(pwszName);
  1909. if( dw < 1 or
  1910. dw > 18 )
  1911. {
  1912. DisplayMessage(g_hModule, EMSG_WINS_INVALID_NAME, pwszName);
  1913. }
  1914. else
  1915. {
  1916. pTemp = wcsstr(pwszName, L"*");
  1917. if( pTemp is NULL )
  1918. {
  1919. DisplayMessage(g_hModule, EMSG_WINS_INVALID_NAME, pwszName);
  1920. }
  1921. else
  1922. {
  1923. CHAR chEnd = 0x00;
  1924. dw = (DWORD)(pTemp - pwszName + 1);
  1925. if( dw > 16 )
  1926. {
  1927. DisplayMessage(g_hModule,
  1928. EMSG_SRVR_INVALID_NETBIOS_NAME);
  1929. goto ErrorReturn;
  1930. }
  1931. pwszName[dw-1] = L'\0';
  1932. chEnd = StringToHexA(pTemp+1);
  1933. if( dwType > 255 )
  1934. {
  1935. DisplayMessage(g_hModule, EMSG_WINS_VALUE_OUTOFRANGE);
  1936. }
  1937. else
  1938. {
  1939. LPWSTR pwcTemp = WinsAllocateMemory((NBT_NONCODED_NMSZ+1)*sizeof(WCHAR));
  1940. LPWSTR pwTemp = NULL;
  1941. if( pwcTemp is NULL )
  1942. {
  1943. Status = ERROR_NOT_ENOUGH_MEMORY;
  1944. if( pwszTemp isnot NULL )
  1945. {
  1946. WinsFreeMemory(pwszTemp );
  1947. pwszTemp = NULL;
  1948. }
  1949. goto ErrorReturn;
  1950. }
  1951. wcscpy(pwcTemp, pwszName);
  1952. wcsncat(pwcTemp,
  1953. L" ",
  1954. (16 - wcslen(pwszName)));
  1955. pwcTemp[15] = chEnd;
  1956. for( ilen=0; ilen<NumNBNames; ilen++)
  1957. {
  1958. pwTemp = WinsOemToUnicode(NBNames[ilen], NULL);
  1959. if( pwTemp is NULL )
  1960. {
  1961. Status = ERROR_NOT_ENOUGH_MEMORY;
  1962. goto ErrorReturn;
  1963. }
  1964. if(_wcsicmp(pwTemp, pwcTemp) is 0 )
  1965. {
  1966. fPresent = TRUE;
  1967. break;
  1968. }
  1969. WinsFreeMemory(pwTemp);
  1970. pwTemp = NULL;
  1971. }
  1972. if( pwTemp )
  1973. {
  1974. WinsFreeMemory(pwTemp);
  1975. pwTemp = NULL;
  1976. }
  1977. if( fPresent is FALSE )
  1978. {
  1979. LPSTR pcTemp = NULL;
  1980. NBNames[NumNBNames] = WinsAllocateMemory(17);
  1981. if( NBNames[NumNBNames] is NULL )
  1982. {
  1983. if( pwszTemp isnot NULL )
  1984. {
  1985. WinsFreeMemory(pwszTemp );
  1986. pwszTemp = NULL;
  1987. }
  1988. Status = ERROR_NOT_ENOUGH_MEMORY;
  1989. goto ErrorReturn;
  1990. }
  1991. pcTemp = WinsUnicodeToOem(pwcTemp, NULL);
  1992. if( pcTemp is NULL )
  1993. {
  1994. Status = ERROR_NOT_ENOUGH_MEMORY;
  1995. goto ErrorReturn;
  1996. }
  1997. strncpy(NBNames[NumNBNames], pcTemp, 16);
  1998. NBNames[NumNBNames][15] = (CHAR)chEnd;
  1999. NBNames[NumNBNames][16] = '\0';
  2000. NumNBNames++;
  2001. WinsFreeMemory(pcTemp);
  2002. pcTemp = NULL;
  2003. }
  2004. if( pwcTemp )
  2005. {
  2006. WinsFreeMemory(pwcTemp);
  2007. pwcTemp = NULL;
  2008. }
  2009. }
  2010. }
  2011. }
  2012. pwszName = wcstok(NULL, pwszToken);
  2013. }
  2014. if( pwszTemp )
  2015. {
  2016. WinsFreeMemory(pwszTemp);
  2017. pwszTemp = NULL;
  2018. }
  2019. break;
  2020. }
  2021. case 1://NameFile
  2022. {
  2023. HANDLE hFile = NULL;
  2024. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]),
  2025. dwFileSize = 0,
  2026. dw = 0,
  2027. dwType = 0,
  2028. dwBytesRead = 0;
  2029. BOOL fPresent = FALSE;
  2030. int ilen = 0;
  2031. LPBYTE pbFileData = NULL;
  2032. LPSTR pszToken = " ,\r\n\t",
  2033. pszData = NULL,
  2034. pTemp = NULL,
  2035. pszName = NULL,
  2036. pszTemp = NULL;
  2037. LPWSTR pwszTempName = NULL;
  2038. if( dwLen < 1 )
  2039. {
  2040. DisplayMessage(g_hModule,
  2041. EMSG_WINS_INVALID_FILENAME,
  2042. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2043. goto CommonReturn;
  2044. }
  2045. hFile = CreateFile(ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  2046. GENERIC_READ | GENERIC_WRITE,
  2047. 0,
  2048. NULL,
  2049. OPEN_EXISTING,
  2050. FILE_ATTRIBUTE_NORMAL,
  2051. NULL);
  2052. if( hFile is INVALID_HANDLE_VALUE )
  2053. {
  2054. Status = GetLastError();
  2055. goto ErrorReturn;
  2056. }
  2057. dwFileSize = GetFileSize(hFile, NULL);
  2058. if( dwFileSize is 0 )
  2059. {
  2060. DisplayMessage(g_hModule,
  2061. EMSG_WINS_EMPTY_FILE,
  2062. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2063. CloseHandle(hFile);
  2064. hFile = NULL;
  2065. goto CommonReturn;
  2066. }
  2067. pbFileData = WinsAllocateMemory(dwFileSize+1);
  2068. if( pbFileData is NULL )
  2069. {
  2070. Status = ERROR_NOT_ENOUGH_MEMORY;
  2071. CloseHandle(hFile);
  2072. hFile = NULL;
  2073. goto ErrorReturn;
  2074. }
  2075. if( !ReadFile( hFile, pbFileData, dwFileSize, &dwBytesRead, NULL) )
  2076. {
  2077. DisplayMessage(g_hModule, EMSG_WINS_FILEREAD_FAILED);
  2078. CloseHandle(hFile);
  2079. hFile = NULL;
  2080. goto CommonReturn;
  2081. }
  2082. CloseHandle(hFile);
  2083. hFile = NULL;
  2084. for( ilen=0; ilen<NumNBNames; ilen++ )
  2085. {
  2086. if( NBNames[ilen] isnot NULL )
  2087. {
  2088. WinsFreeMemory(NBNames[ilen]);
  2089. NBNames[ilen] = NULL;
  2090. }
  2091. }
  2092. NumNBNames = 0;
  2093. pszData = (LPSTR)pbFileData;
  2094. pszName = strtok(pszData, pszToken);
  2095. while( pszName isnot NULL )
  2096. {
  2097. dw = strlen(pszName);
  2098. if( dw < 1 or
  2099. dw > 18 )
  2100. {
  2101. pwszTempName = WinsOemToUnicode(pszName, NULL);
  2102. if( pwszTempName is NULL )
  2103. {
  2104. Status = ERROR_NOT_ENOUGH_MEMORY;
  2105. goto ErrorReturn;
  2106. }
  2107. DisplayMessage(g_hModule, EMSG_WINS_INVALID_NAME, pwszTempName);
  2108. WinsFreeMemory(pwszTempName);
  2109. pwszTempName = NULL;
  2110. }
  2111. else
  2112. {
  2113. WCHAR wcEnd[2] = {L'\0'};
  2114. CHAR cEnd[2] = {L'\0'};
  2115. pTemp = strstr(pszName, "*");
  2116. if( pTemp is NULL )
  2117. {
  2118. pwszTempName = WinsOemToUnicode(pszName, NULL);
  2119. if( pwszTempName is NULL )
  2120. {
  2121. Status = ERROR_NOT_ENOUGH_MEMORY;
  2122. goto ErrorReturn;
  2123. }
  2124. DisplayMessage(g_hModule, EMSG_WINS_INVALID_NAME, pwszTempName);
  2125. WinsFreeMemory(pwszTempName);
  2126. pwszTempName = NULL;
  2127. }
  2128. else
  2129. {
  2130. CHAR chEndChar = 0x00;
  2131. LPWSTR pwszTempBuf = NULL;
  2132. dw = (DWORD)(pTemp - pszName + 1);
  2133. if( dw > 16 )
  2134. {
  2135. DisplayMessage(g_hModule,
  2136. EMSG_SRVR_INVALID_NETBIOS_NAME);
  2137. goto ErrorReturn;
  2138. }
  2139. pszName[dw-1] = L'\0';
  2140. pwszTempBuf = WinsOemToUnicode(pTemp+1, NULL);
  2141. if( pwszTempBuf is NULL )
  2142. {
  2143. Status = ERROR_NOT_ENOUGH_MEMORY;
  2144. goto ErrorReturn;
  2145. }
  2146. chEndChar = StringToHexA(pwszTempBuf);
  2147. WinsFreeMemory(pwszTempBuf);
  2148. pwszTempBuf = NULL;
  2149. if( dwType > 255 )
  2150. {
  2151. DisplayMessage(g_hModule, EMSG_WINS_VALUE_OUTOFRANGE);
  2152. }
  2153. else
  2154. {
  2155. LPSTR pcTemp = WinsAllocateMemory(NBT_NONCODED_NMSZ+1);
  2156. if( pcTemp is NULL )
  2157. {
  2158. Status = ERROR_NOT_ENOUGH_MEMORY;
  2159. if( pbFileData isnot NULL )
  2160. {
  2161. WinsFreeMemory(pbFileData );
  2162. pbFileData = NULL;
  2163. }
  2164. goto ErrorReturn;
  2165. }
  2166. strcpy(pcTemp, pszName);
  2167. strncat(pcTemp,
  2168. " ",
  2169. (16-strlen(pszName)));
  2170. pcTemp[15] = chEndChar;
  2171. for( ilen=0; ilen<NumNBNames; ilen++)
  2172. {
  2173. if(_stricmp(NBNames[ilen], pcTemp) is 0 )
  2174. {
  2175. fPresent = TRUE;
  2176. break;
  2177. }
  2178. }
  2179. if( fPresent is FALSE )
  2180. {
  2181. LPSTR pszOem = NULL;
  2182. NBNames[NumNBNames] = WinsAllocateMemory(17);
  2183. if( NBNames[NumNBNames] is NULL )
  2184. {
  2185. Status = ERROR_NOT_ENOUGH_MEMORY;
  2186. goto ErrorReturn;
  2187. }
  2188. pszOem = WinsAnsiToOem(pcTemp);
  2189. if( pszOem is NULL )
  2190. {
  2191. Status = ERROR_NOT_ENOUGH_MEMORY;
  2192. goto ErrorReturn;
  2193. }
  2194. strncpy(NBNames[NumNBNames], pszOem, 16);
  2195. WinsFreeMemory(pszOem);
  2196. pszOem = NULL;
  2197. NBNames[NumNBNames][15] = (CHAR)chEndChar;
  2198. NumNBNames++;
  2199. }
  2200. if( pcTemp )
  2201. {
  2202. WinsFreeMemory(pcTemp);
  2203. pcTemp = NULL;
  2204. }
  2205. }
  2206. }
  2207. }
  2208. pszName = strtok(NULL, pszToken);
  2209. }
  2210. if( pbFileData )
  2211. {
  2212. WinsFreeMemory(pbFileData);
  2213. pbFileData = NULL;
  2214. }
  2215. break;
  2216. }
  2217. case 2://ServerList
  2218. {
  2219. LPWSTR pwszToken = L",\r\n\t ",
  2220. pwszName = NULL,
  2221. pwszTemp = NULL;
  2222. int ilen = 0;
  2223. BOOL fPresent = FALSE;
  2224. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2225. if( dwLen < 2 )
  2226. {
  2227. NumWinServers = 0;
  2228. break;
  2229. }
  2230. if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] isnot L'{' or
  2231. ppwcArguments[dwCurrentIndex+pdwTagNum[j]][dwLen-1] isnot L'}' )
  2232. {
  2233. NumWinServers = 0;
  2234. break;
  2235. }
  2236. pwszTemp = WinsAllocateMemory((dwLen)*sizeof(WCHAR));
  2237. if(pwszTemp is NULL )
  2238. {
  2239. Status = ERROR_NOT_ENOUGH_MEMORY;
  2240. goto ErrorReturn;
  2241. }
  2242. if( fInclPartner is FALSE )
  2243. {
  2244. memset(WinServers, 0x00, MAX_SERVERS*sizeof(WINSERVERS));
  2245. NumWinServers = 0;
  2246. }
  2247. wcscpy(pwszTemp, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+1);
  2248. pwszTemp[dwLen-2] = L'\0';
  2249. pwszName = wcstok(pwszTemp, pwszToken);
  2250. while(pwszName isnot NULL )
  2251. {
  2252. fPresent = FALSE;
  2253. if( IsIpAddress(pwszName) is FALSE )
  2254. {
  2255. DisplayMessage(g_hModule, EMSG_WINS_INVALID_IPADDRESS, pwszName);
  2256. }
  2257. else
  2258. {
  2259. struct in_addr Temp;
  2260. LPSTR pszTempAddr = NULL;
  2261. pszTempAddr = WinsUnicodeToAnsi(pwszName, NULL);
  2262. if( pszTempAddr is NULL )
  2263. {
  2264. Status = ERROR_NOT_ENOUGH_MEMORY;
  2265. goto ErrorReturn;
  2266. }
  2267. Temp.s_addr = inet_addr(pszTempAddr);
  2268. WinsFreeMemory(pszTempAddr);
  2269. pszTempAddr = NULL;
  2270. if( Temp.s_addr isnot INADDR_NONE )
  2271. {
  2272. for( ilen=0; ilen<NumWinServers; ilen++)
  2273. {
  2274. if( WinServers[ilen].Server.s_addr is Temp.s_addr )
  2275. {
  2276. fPresent = TRUE;
  2277. break;
  2278. }
  2279. }
  2280. fIpEmpty = FALSE;
  2281. if( fPresent is FALSE )
  2282. {
  2283. WinServers[NumWinServers].Server.s_addr = Temp.s_addr;
  2284. NumWinServers++;
  2285. }
  2286. }
  2287. }
  2288. pwszName = wcstok(NULL, pwszToken);
  2289. }
  2290. break;
  2291. }
  2292. case 3://ServerFile
  2293. {
  2294. HANDLE hFile = NULL;
  2295. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]),
  2296. dwFileSize = 0,
  2297. dwBytesRead = 0;
  2298. BOOL fPresent = FALSE;
  2299. int ilen = 0;
  2300. LPBYTE pbFileData = NULL;
  2301. LPSTR pszToken = " ,\r\n\t",
  2302. pszData = NULL,
  2303. pszName = NULL;
  2304. LPWSTR pwszToken = L" ,\r\n\t",
  2305. pwszName = NULL,
  2306. pwszData = NULL;
  2307. if( dwLen < 1 )
  2308. {
  2309. DisplayMessage(g_hModule,
  2310. EMSG_WINS_INVALID_FILENAME,
  2311. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2312. goto CommonReturn;
  2313. }
  2314. hFile = CreateFile(ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  2315. GENERIC_READ | GENERIC_WRITE,
  2316. 0,
  2317. NULL,
  2318. OPEN_EXISTING,
  2319. FILE_ATTRIBUTE_NORMAL,
  2320. NULL);
  2321. if( hFile is INVALID_HANDLE_VALUE )
  2322. {
  2323. Status = GetLastError();
  2324. goto ErrorReturn;
  2325. }
  2326. dwFileSize = GetFileSize(hFile, NULL);
  2327. if( dwFileSize is 0 )
  2328. {
  2329. DisplayMessage(g_hModule,
  2330. EMSG_WINS_EMPTY_FILE,
  2331. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2332. CloseHandle(hFile);
  2333. hFile = NULL;
  2334. goto CommonReturn;
  2335. }
  2336. pbFileData = WinsAllocateMemory(dwFileSize+1);
  2337. if( pbFileData is NULL )
  2338. {
  2339. Status = ERROR_NOT_ENOUGH_MEMORY;
  2340. CloseHandle(hFile);
  2341. hFile = NULL;
  2342. goto ErrorReturn;
  2343. }
  2344. if( !ReadFile( hFile, pbFileData, dwFileSize, &dwBytesRead, NULL) )
  2345. {
  2346. CloseHandle(hFile);
  2347. hFile = NULL;
  2348. DisplayMessage(g_hModule, EMSG_WINS_FILEREAD_FAILED);
  2349. goto CommonReturn;
  2350. }
  2351. CloseHandle(hFile);
  2352. hFile = NULL;
  2353. if( fInclPartner is FALSE )
  2354. {
  2355. memset(WinServers, 0x00, MAX_SERVERS*sizeof(WINSERVERS));
  2356. NumWinServers = 0;
  2357. }
  2358. pszData = (LPSTR)pbFileData;
  2359. pwszData = WinsOemToUnicode(pszData, NULL);
  2360. if( pwszData is NULL )
  2361. {
  2362. Status = ERROR_NOT_ENOUGH_MEMORY;
  2363. goto ErrorReturn;
  2364. }
  2365. pwszName = wcstok(pwszData, pwszToken);
  2366. while( pwszName isnot NULL )
  2367. {
  2368. fPresent = FALSE;
  2369. pszName = WinsUnicodeToOem(pwszName, NULL);
  2370. if( pszName is NULL )
  2371. {
  2372. Status = ERROR_NOT_ENOUGH_MEMORY;
  2373. goto ErrorReturn;
  2374. }
  2375. if( IsIpAddress(pwszName) is FALSE )
  2376. {
  2377. DisplayMessage(g_hModule, EMSG_WINS_INVALID_IPADDRESS, pwszName);
  2378. }
  2379. else
  2380. {
  2381. struct in_addr Temp;
  2382. Temp.s_addr = inet_addr(pszName);
  2383. if( Temp.s_addr isnot INADDR_NONE )
  2384. {
  2385. for( ilen=0; ilen<NumWinServers; ilen++)
  2386. {
  2387. if( WinServers[ilen].Server.s_addr is Temp.s_addr )
  2388. {
  2389. fPresent = TRUE;
  2390. break;
  2391. }
  2392. }
  2393. fIpEmpty = FALSE;
  2394. if( fPresent is FALSE )
  2395. {
  2396. WinServers[NumWinServers].Server.s_addr = Temp.s_addr;
  2397. NumWinServers++;
  2398. }
  2399. }
  2400. }
  2401. pwszName = wcstok(NULL, pwszToken);
  2402. if( pszName )
  2403. {
  2404. WinsFreeMemory(pszName);
  2405. pszName = NULL;
  2406. }
  2407. }
  2408. if( pbFileData )
  2409. {
  2410. WinsFreeMemory(pbFileData);
  2411. pbFileData = NULL;
  2412. }
  2413. if( pwszData )
  2414. {
  2415. WinsFreeMemory(pwszData);
  2416. pwszData = NULL;
  2417. }
  2418. break;
  2419. }
  2420. case 4://IncludePartners
  2421. {
  2422. HKEY hServer = NULL,
  2423. hPull = NULL,
  2424. hPush = NULL;
  2425. LPWSTR pTemp = NULL;
  2426. WCHAR wcKey[MAX_IP_STRING_LEN+1] = {L'\0'};
  2427. DWORD dw = 0,
  2428. dwLen = MAX_IP_STRING_LEN+1,
  2429. dwKeys = 0;
  2430. if(wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  2431. {
  2432. Status = ERROR_INVALID_PARAMETER;
  2433. goto ErrorReturn;
  2434. }
  2435. if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] isnot L'Y' and
  2436. ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] isnot L'y' )
  2437. {
  2438. Status = ERROR_INVALID_PARAMETER;
  2439. goto ErrorReturn;
  2440. }
  2441. if( wcslen(g_ServerNetBiosName) < 2 )
  2442. {
  2443. pTemp = NULL;
  2444. }
  2445. Status = RegConnectRegistry(pTemp,
  2446. HKEY_LOCAL_MACHINE,
  2447. &hServer );
  2448. if( Status isnot NO_ERROR )
  2449. {
  2450. Status = NO_ERROR;
  2451. break;
  2452. }
  2453. while(TRUE)
  2454. {
  2455. Status = RegOpenKeyEx(hServer,
  2456. PULLROOT,
  2457. 0,
  2458. KEY_ALL_ACCESS,
  2459. &hPull);
  2460. if( Status isnot NO_ERROR )
  2461. {
  2462. Status = NO_ERROR;
  2463. break;
  2464. }
  2465. Status = RegQueryInfoKey(hPull,
  2466. NULL,
  2467. NULL,
  2468. NULL,
  2469. &dwKeys,
  2470. NULL,
  2471. NULL,
  2472. NULL,
  2473. NULL,
  2474. NULL,
  2475. NULL,
  2476. NULL);
  2477. if( Status isnot NO_ERROR )
  2478. {
  2479. Status = NO_ERROR;
  2480. break;
  2481. }
  2482. if( dwKeys < 1 )
  2483. break;
  2484. for( dw=0; dw<dwKeys; dw++ )
  2485. {
  2486. DWORD i = 0;
  2487. LPSTR pszTempAddr = NULL;
  2488. BOOL fPresent = FALSE;
  2489. struct in_addr Temp;
  2490. dwLen = MAX_IP_STRING_LEN+1;
  2491. memset(wcKey, 0x00, (MAX_IP_STRING_LEN+1)*sizeof(WCHAR));
  2492. Status = RegEnumKeyEx(hPull,
  2493. dw,
  2494. wcKey,
  2495. &dwLen,
  2496. NULL,
  2497. NULL,
  2498. NULL,
  2499. NULL);
  2500. if( Status isnot NO_ERROR )
  2501. continue;
  2502. pszTempAddr = WinsUnicodeToOem(wcKey, NULL);
  2503. if( pszTempAddr is NULL )
  2504. {
  2505. Status = ERROR_NOT_ENOUGH_MEMORY;
  2506. goto ErrorReturn;
  2507. }
  2508. Temp.s_addr = inet_addr(pszTempAddr);
  2509. WinsFreeMemory(pszTempAddr);
  2510. pszTempAddr = NULL;
  2511. if( Temp.s_addr isnot INADDR_NONE )
  2512. {
  2513. fPresent = FALSE;
  2514. if( MAX_SERVERS > NumWinServers )
  2515. {
  2516. for( i=0; i<(DWORD)NumWinServers; i++)
  2517. {
  2518. if( WinServers[i].Server.s_addr is Temp.s_addr )
  2519. {
  2520. fPresent = TRUE;
  2521. break;
  2522. }
  2523. }
  2524. if( fPresent is FALSE )
  2525. {
  2526. WinServers[NumWinServers].Server.s_addr = Temp.s_addr;
  2527. NumWinServers++;
  2528. }
  2529. }
  2530. else
  2531. break;
  2532. }
  2533. }
  2534. }
  2535. if( hPull )
  2536. {
  2537. RegCloseKey(hPull);
  2538. hPull = NULL;
  2539. }
  2540. dw = dwKeys = 0;
  2541. while(TRUE)
  2542. {
  2543. Status = RegOpenKeyEx(hServer,
  2544. PUSHROOT,
  2545. 0,
  2546. KEY_ALL_ACCESS,
  2547. &hPush);
  2548. if( Status isnot NO_ERROR )
  2549. {
  2550. Status = NO_ERROR;
  2551. break;
  2552. }
  2553. Status = RegQueryInfoKey(hPush,
  2554. NULL,
  2555. NULL,
  2556. NULL,
  2557. &dwKeys,
  2558. NULL,
  2559. NULL,
  2560. NULL,
  2561. NULL,
  2562. NULL,
  2563. NULL,
  2564. NULL);
  2565. if( Status isnot NO_ERROR )
  2566. {
  2567. Status = NO_ERROR;
  2568. break;
  2569. }
  2570. if( dwKeys < 1 )
  2571. break;
  2572. for( dw=0; dw<dwKeys; dw++ )
  2573. {
  2574. DWORD i = 0;
  2575. BOOL fPresent = FALSE;
  2576. LPSTR pszTempAddr = NULL;
  2577. struct in_addr Temp;
  2578. dwLen = MAX_IP_STRING_LEN+1;
  2579. memset(wcKey, 0x00, (MAX_IP_STRING_LEN+1)*sizeof(WCHAR));
  2580. Status = RegEnumKeyEx(hPush,
  2581. dw,
  2582. wcKey,
  2583. &dwLen,
  2584. NULL,
  2585. NULL,
  2586. NULL,
  2587. NULL);
  2588. if( Status isnot NO_ERROR )
  2589. continue;
  2590. pszTempAddr = WinsUnicodeToOem(wcKey, NULL);
  2591. if( pszTempAddr is NULL )
  2592. {
  2593. Status = ERROR_NOT_ENOUGH_MEMORY;
  2594. goto ErrorReturn;
  2595. }
  2596. Temp.s_addr = inet_addr(pszTempAddr);
  2597. WinsFreeMemory(pszTempAddr);
  2598. pszTempAddr = NULL;
  2599. if( Temp.s_addr isnot INADDR_NONE )
  2600. {
  2601. if( MAX_SERVERS > NumWinServers )
  2602. {
  2603. for( i=0; i<(DWORD)NumWinServers; i++)
  2604. {
  2605. if( WinServers[i].Server.s_addr is Temp.s_addr )
  2606. {
  2607. fPresent = TRUE;
  2608. break;
  2609. }
  2610. }
  2611. if( fPresent is FALSE )
  2612. {
  2613. WinServers[NumWinServers].Server.s_addr = Temp.s_addr;
  2614. NumWinServers++;
  2615. }
  2616. }
  2617. else
  2618. break;
  2619. }
  2620. }
  2621. }
  2622. if( hPush )
  2623. {
  2624. RegCloseKey(hPush);
  2625. hPush = NULL;
  2626. }
  2627. if( hServer )
  2628. {
  2629. RegCloseKey(hServer);
  2630. hServer = NULL;
  2631. }
  2632. break;
  2633. }
  2634. default:
  2635. {
  2636. Status = ERROR_INVALID_PARAMETER;
  2637. goto ErrorReturn;
  2638. }
  2639. }
  2640. }
  2641. if( NumNBNames is 0 )
  2642. {
  2643. DisplayMessage(g_hModule, EMSG_WINS_NO_NAMES);
  2644. Status = ERROR_INVALID_PARAMETER;
  2645. goto ErrorReturn;
  2646. }
  2647. if( NumWinServers is 0 )
  2648. {
  2649. DisplayMessage(g_hModule, EMSG_WINS_NO_SERVERS);
  2650. Status = ERROR_INVALID_PARAMETER;
  2651. goto ErrorReturn;
  2652. }
  2653. if( fIpEmpty is TRUE )
  2654. {
  2655. DisplayMessage(g_hModule,
  2656. EMSG_WINS_NO_SERVERS);
  2657. Status = ERROR_INVALID_PARAMETER;
  2658. goto ErrorReturn;
  2659. }
  2660. else
  2661. {
  2662. CheckNameConsistency();
  2663. }
  2664. if( Status is NO_ERROR )
  2665. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  2666. CommonReturn:
  2667. if( pdwTagType )
  2668. {
  2669. WinsFreeMemory(pdwTagType);
  2670. pdwTagType = NULL;
  2671. }
  2672. if( pdwTagNum )
  2673. {
  2674. WinsFreeMemory(pdwTagNum);
  2675. pdwTagNum = NULL;
  2676. }
  2677. if( pdwIpAddress )
  2678. {
  2679. WinsFreeMemory(pdwIpAddress);
  2680. pdwIpAddress = NULL;
  2681. }
  2682. if( ppNames )
  2683. {
  2684. WinsFreeMemory(ppNames);
  2685. ppNames = NULL;
  2686. }
  2687. if( WinServers )
  2688. {
  2689. WinsFreeMemory(WinServers);
  2690. WinServers = NULL;
  2691. }
  2692. if( NBNames )
  2693. {
  2694. WinsFreeMemory(NBNames);
  2695. NBNames = NULL;
  2696. }
  2697. return Status;
  2698. ErrorReturn:
  2699. DisplayErrorMessage(EMSG_SRVR_CHECK_NAME, Status);
  2700. goto CommonReturn;
  2701. }
  2702. DWORD
  2703. HandleSrvrCheckVersion(
  2704. IN LPCWSTR pwszMachine,
  2705. IN OUT LPWSTR *ppwcArguments,
  2706. IN DWORD dwCurrentIndex,
  2707. IN DWORD dwArgCount,
  2708. IN DWORD dwFlags,
  2709. IN LPCVOID pvData,
  2710. OUT BOOL *pbDone
  2711. )
  2712. /*++
  2713. Routine Description :
  2714. Checks the version number consistencies for the records
  2715. Arguments :
  2716. All aguments are passes as array of wide char strings in ppwcArguments.
  2717. Compulsory, IP address of the server to start with.
  2718. Optional, a File Name to store the output in proper format.
  2719. Return Value:
  2720. Returns the status of the operation.
  2721. --*/
  2722. {
  2723. DWORD Status = NO_ERROR;
  2724. DWORD i, j, dwNumArgs, dwTagCount = 0;
  2725. TAG_TYPE pttTags[] = {
  2726. {WINS_TOKEN_SERVER, TRUE, FALSE},
  2727. {WINS_TOKEN_FILE, FALSE, FALSE},
  2728. };
  2729. PDWORD pdwTagNum = NULL,
  2730. pdwTagType = NULL;
  2731. BOOL fFile = FALSE;
  2732. FILE *pFile = NULL;
  2733. LPSTR pStartIp = NULL;
  2734. //Must provide the IP address of the server to start with
  2735. if( dwArgCount < dwCurrentIndex + 1 )
  2736. {
  2737. DisplayMessage(g_hModule,
  2738. HLP_SRVR_CHECK_VERSION_EX);
  2739. Status = ERROR_INVALID_PARAMETER;
  2740. goto ErrorReturn;
  2741. }
  2742. //Start processing the arguements based on the
  2743. dwNumArgs = dwArgCount - dwCurrentIndex;
  2744. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  2745. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  2746. if( pdwTagType is NULL or
  2747. pdwTagNum is NULL )
  2748. {
  2749. Status = ERROR_NOT_ENOUGH_MEMORY;
  2750. goto ErrorReturn;
  2751. }
  2752. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  2753. Status = PreProcessCommand(ppwcArguments,
  2754. dwArgCount,
  2755. dwCurrentIndex,
  2756. pttTags,
  2757. &dwTagCount,
  2758. pdwTagType,
  2759. pdwTagNum);
  2760. if( Status isnot NO_ERROR )
  2761. {
  2762. goto ErrorReturn;
  2763. }
  2764. for( j=0; j<dwTagCount; j++ )
  2765. {
  2766. switch(pdwTagType[j])
  2767. {
  2768. //Ip Address of the server to start with
  2769. case 0:
  2770. {
  2771. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  2772. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) is FALSE )
  2773. {
  2774. Status = ERROR_INVALID_IPADDRESS;
  2775. goto ErrorReturn;
  2776. }
  2777. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2778. pStartIp = WinsUnicodeToOem(wcServerIpAdd, NULL);
  2779. if( pStartIp is NULL )
  2780. {
  2781. Status = ERROR_NOT_ENOUGH_MEMORY;
  2782. goto ErrorReturn;
  2783. }
  2784. break;
  2785. }
  2786. //File to store the output data
  2787. case 1:
  2788. {
  2789. WCHAR wcFile[MAX_PATH] = {L'\0'};
  2790. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 or
  2791. wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > MAX_PATH )
  2792. {
  2793. wcscpy(wcFile, L"wins.rec");
  2794. }
  2795. else
  2796. {
  2797. wcscpy(wcFile, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2798. }
  2799. pFile = _wfopen(wcFile, L"w+");
  2800. if( pFile is NULL )
  2801. {
  2802. pFile = _wfopen(L"wins.rec", L"w+");
  2803. fFile = TRUE;
  2804. }
  2805. else
  2806. {
  2807. fFile = TRUE;
  2808. }
  2809. break;
  2810. }
  2811. default:
  2812. {
  2813. Status = ERROR_INVALID_PARAMETER;
  2814. goto ErrorReturn;
  2815. }
  2816. }
  2817. }
  2818. CheckVersionNumbers( pStartIp,
  2819. fFile,
  2820. pFile);
  2821. CommonReturn:
  2822. if( pdwTagType )
  2823. {
  2824. WinsFreeMemory(pdwTagType);
  2825. pdwTagType = NULL;
  2826. }
  2827. if( pdwTagNum )
  2828. {
  2829. WinsFreeMemory(pdwTagNum);
  2830. pdwTagNum = NULL;
  2831. }
  2832. if( pFile )
  2833. {
  2834. fclose(pFile);
  2835. pFile = NULL;
  2836. }
  2837. if( pStartIp)
  2838. {
  2839. WinsFreeMemory(pStartIp);
  2840. pStartIp = NULL;
  2841. }
  2842. return Status;
  2843. ErrorReturn:
  2844. DisplayErrorMessage(EMSG_SRVR_CHECK_VERSION,
  2845. Status);
  2846. goto CommonReturn;
  2847. }
  2848. DWORD
  2849. HandleSrvrDeleteName(
  2850. IN LPCWSTR pwszMachine,
  2851. IN OUT LPWSTR *ppwcArguments,
  2852. IN DWORD dwCurrentIndex,
  2853. IN DWORD dwArgCount,
  2854. IN DWORD dwFlags,
  2855. IN LPCVOID pvData,
  2856. OUT BOOL *pbDone
  2857. )
  2858. /*++
  2859. Routine Description :
  2860. Deletes an record entry for the WINS server database
  2861. Arguments :
  2862. All aguments are passes as array of wide char strings in ppwcArguments.
  2863. Compulsory, Record Name, Endchar
  2864. Optional, Scope
  2865. Return Value:
  2866. Returns the status of the operation.
  2867. --*/
  2868. {
  2869. DWORD Status = NO_ERROR;
  2870. DWORD i, j, dwNumArgs, dwTagCount = 0;
  2871. TAG_TYPE pttTags[] = {
  2872. {WINS_TOKEN_NAME, TRUE, FALSE},
  2873. {WINS_TOKEN_ENDCHAR, TRUE, FALSE},
  2874. {WINS_TOKEN_SCOPE, FALSE, FALSE}
  2875. };
  2876. PDWORD pdwTagNum = NULL,
  2877. pdwTagType = NULL;
  2878. WCHAR wszName[MAX_STRING_LEN] = {L'\0'};
  2879. BOOL fEndChar = FALSE;
  2880. CHAR ch16thChar = 0x00;
  2881. BOOL fScope = FALSE;
  2882. WCHAR wszScope[MAX_STRING_LEN] = {L'\0'};
  2883. LPSTR pszTempName = NULL;
  2884. DWORD dwTempNameLen = 0;
  2885. DWORD dwStrLen = 0;
  2886. LPWSTR pwszTemp = NULL;
  2887. WINSINTF_RECORD_ACTION_T RecAction = {0};
  2888. PWINSINTF_RECORD_ACTION_T pRecAction = NULL;
  2889. memset(&RecAction, 0x00, sizeof(WINSINTF_RECORD_ACTION_T));
  2890. RecAction.fStatic = FALSE;
  2891. //Must provide at least the record name and endchar
  2892. if( dwArgCount < dwCurrentIndex + 2 )
  2893. {
  2894. DisplayMessage(g_hModule, HLP_SRVR_DELETE_NAME_EX);
  2895. Status = ERROR_INVALID_PARAMETER;
  2896. goto ErrorReturn;
  2897. }
  2898. //Start processing the arguments based on ppwcArguments, dwArgCount and dwCurrentIndex
  2899. dwNumArgs = dwArgCount - dwCurrentIndex;
  2900. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  2901. if( pdwTagNum is NULL )
  2902. {
  2903. Status = ERROR_NOT_ENOUGH_MEMORY;
  2904. goto ErrorReturn;
  2905. }
  2906. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  2907. if( pdwTagType is NULL )
  2908. {
  2909. Status = ERROR_NOT_ENOUGH_MEMORY;
  2910. goto ErrorReturn;
  2911. }
  2912. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  2913. Status = PreProcessCommand(ppwcArguments,
  2914. dwArgCount,
  2915. dwCurrentIndex,
  2916. pttTags,
  2917. &dwTagCount,
  2918. pdwTagType,
  2919. pdwTagNum);
  2920. if( Status isnot NO_ERROR )
  2921. goto ErrorReturn;
  2922. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  2923. {
  2924. if( pttTags[i].dwRequired is TRUE and
  2925. pttTags[i].bPresent is FALSE
  2926. )
  2927. {
  2928. Status = ERROR_INVALID_PARAMETER;
  2929. goto ErrorReturn;
  2930. }
  2931. }
  2932. i = dwTagCount;
  2933. for( j=0; j<i; j++ )
  2934. {
  2935. switch(pdwTagType[j])
  2936. {
  2937. //Record Name
  2938. case 0:
  2939. {
  2940. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2941. if( dwLen is 0 )
  2942. {
  2943. Status = ERROR_INVALID_PARAMETER;
  2944. goto ErrorReturn;
  2945. }
  2946. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  2947. memcpy(wszName,
  2948. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  2949. dwLen*sizeof(WCHAR));
  2950. wszName[dwLen] = L'\0';
  2951. break;
  2952. }
  2953. //Endchar
  2954. case 1:
  2955. {
  2956. DWORD dwLen = 0, k=0;
  2957. fEndChar = TRUE;
  2958. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2959. if( dwLen > 2 )
  2960. {
  2961. Status = ERROR_INVALID_PARAMETER;
  2962. goto ErrorReturn;
  2963. }
  2964. for( k=0; k<dwLen; k++ )
  2965. {
  2966. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  2967. if( towlower(wc) >= L'a' and
  2968. towlower(wc) <= L'z' )
  2969. {
  2970. if( towlower(wc) > L'f' )
  2971. {
  2972. Status = ERROR_INVALID_PARAMETER;
  2973. goto ErrorReturn;
  2974. }
  2975. }
  2976. }
  2977. ch16thChar = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2978. break;
  2979. }
  2980. //Scope
  2981. case 2:
  2982. {
  2983. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  2984. fScope = TRUE;
  2985. if( dwLen is 0 )
  2986. {
  2987. Status = ERROR_INVALID_PARAMETER;
  2988. goto ErrorReturn;
  2989. }
  2990. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  2991. memcpy(wszScope,
  2992. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  2993. dwLen*sizeof(WCHAR));
  2994. wszScope[dwLen] = L'\0';
  2995. break;
  2996. }
  2997. default:
  2998. {
  2999. Status = ERROR_INVALID_PARAMETER;
  3000. goto ErrorReturn;
  3001. }
  3002. }
  3003. }
  3004. _wcsupr(wszName);
  3005. _wcsupr(wszScope);
  3006. pszTempName = WinsUnicodeToOem(wszName, NULL);
  3007. if( pszTempName is NULL )
  3008. {
  3009. Status = ERROR_NOT_ENOUGH_MEMORY;
  3010. goto ErrorReturn;
  3011. }
  3012. dwStrLen = strlen(pszTempName);
  3013. if( dwStrLen >= 16 )
  3014. {
  3015. DisplayMessage(g_hModule,
  3016. EMSG_SRVR_INVALID_NETBIOS_NAME);
  3017. Status = ERROR_INVALID_PARAMETER;
  3018. WinsFreeMemory(pszTempName);
  3019. pszTempName = NULL;
  3020. goto ErrorReturn;
  3021. }
  3022. RecAction.pName = WinsAllocateMemory(273);
  3023. if( RecAction.pName is NULL )
  3024. {
  3025. Status = ERROR_NOT_ENOUGH_MEMORY;
  3026. goto ErrorReturn;
  3027. }
  3028. strncpy(RecAction.pName, pszTempName, dwStrLen);
  3029. WinsFreeMemory(pszTempName);
  3030. pszTempName = NULL;
  3031. for( i=dwStrLen; i < 16; i++ )
  3032. {
  3033. RecAction.pName[i] = ' ';
  3034. }
  3035. if( fEndChar )
  3036. {
  3037. if( ch16thChar is 0x00 )
  3038. {
  3039. RecAction.pName[15] = 0x00;
  3040. }
  3041. else
  3042. {
  3043. RecAction.pName[15] = ch16thChar;
  3044. }
  3045. }
  3046. RecAction.pName[16] = '\0';
  3047. dwStrLen = 16;
  3048. if( fScope )
  3049. {
  3050. DWORD dwLen = 0;
  3051. RecAction.pName[dwStrLen] = '.';
  3052. pszTempName = WinsUnicodeToOem(wszScope, NULL);
  3053. if( pszTempName is NULL )
  3054. {
  3055. Status = ERROR_NOT_ENOUGH_MEMORY;
  3056. goto ErrorReturn;
  3057. }
  3058. dwLen = strlen(pszTempName);
  3059. dwLen = ( 255 - dwStrLen < dwLen ) ? 255 - dwStrLen : dwLen;
  3060. strncpy(RecAction.pName + dwStrLen + 1, pszTempName, dwLen);
  3061. WinsFreeMemory(pszTempName);
  3062. pszTempName = NULL;
  3063. RecAction.pName[dwLen + dwStrLen + 1] = '\0';
  3064. if( fEndChar and
  3065. ch16thChar is 0x00 )
  3066. dwStrLen = 16+dwLen+1;
  3067. else
  3068. dwStrLen = strlen(RecAction.pName);
  3069. }
  3070. else
  3071. {
  3072. RecAction.pName[dwStrLen] = '\0';
  3073. }
  3074. RecAction.NameLen = dwStrLen;
  3075. RecAction.Cmd_e = WINSINTF_E_QUERY;
  3076. RecAction.OwnerId = StringToIpAddress(g_ServerIpAddressUnicodeString);
  3077. RecAction.NameLen = dwStrLen;
  3078. pRecAction = &RecAction;
  3079. Status = WinsRecordAction(g_hBind, &pRecAction);
  3080. if( Status isnot NO_ERROR )
  3081. goto ErrorReturn;
  3082. RecAction.Cmd_e = WINSINTF_E_DELETE;
  3083. RecAction.State_e = WINSINTF_E_DELETED;
  3084. pRecAction = &RecAction;
  3085. Status = WinsRecordAction(g_hBind, &pRecAction);
  3086. if( Status isnot NO_ERROR )
  3087. goto ErrorReturn;
  3088. CommonReturn:
  3089. if( Status is NO_ERROR )
  3090. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  3091. if( pszTempName )
  3092. {
  3093. WinsFreeMemory(pszTempName);
  3094. pszTempName = NULL;
  3095. }
  3096. if( pdwTagNum )
  3097. {
  3098. WinsFreeMemory(pdwTagNum);
  3099. pdwTagNum = NULL;
  3100. }
  3101. if( pdwTagType )
  3102. {
  3103. WinsFreeMemory(pdwTagType);
  3104. pdwTagType = NULL;
  3105. }
  3106. if( RecAction.pName )
  3107. {
  3108. WinsFreeMemory(RecAction.pName);
  3109. RecAction.pName = NULL;
  3110. }
  3111. return Status;
  3112. ErrorReturn:
  3113. DisplayErrorMessage(EMSG_SRVR_DELETE_NAME, Status);
  3114. goto CommonReturn;
  3115. return NO_ERROR;
  3116. }
  3117. DWORD
  3118. HandleSrvrDeletePartner(
  3119. IN LPCWSTR pwszMachine,
  3120. IN OUT LPWSTR *ppwcArguments,
  3121. IN DWORD dwCurrentIndex,
  3122. IN DWORD dwArgCount,
  3123. IN DWORD dwFlags,
  3124. IN LPCVOID pvData,
  3125. OUT BOOL *pbDone
  3126. )
  3127. /*++
  3128. Routine Description :
  3129. Delete a partner from the WINS server
  3130. Arguments :
  3131. All aguments are passes as array of wide char strings in ppwcArguments.
  3132. Compulsory : Confirmation
  3133. Optional : Server IP and Type.
  3134. Note : If no ip is provided, it deletes all partners in the list.
  3135. Return Value:
  3136. Returns the status of the operation.
  3137. --*/
  3138. {
  3139. DWORD Status = NO_ERROR;
  3140. DWORD i, j, dwNumArgs, dwTagCount;
  3141. PDWORD pdwTagType = NULL,
  3142. pdwTagNum = NULL;
  3143. TAG_TYPE pttTags[] = {
  3144. {WINS_TOKEN_SERVER, FALSE, FALSE},
  3145. {WINS_TOKEN_TYPE, FALSE, FALSE},
  3146. {WINS_TOKEN_CONFIRM, TRUE, FALSE},
  3147. };
  3148. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN + 1] = {L'\0'};
  3149. DWORD dwIpLen = (MAX_IP_STRING_LEN+1);
  3150. BOOL fPull = TRUE,
  3151. fPush = TRUE,
  3152. fConfirm = FALSE;
  3153. HKEY hServer = NULL,
  3154. hPartner = NULL;
  3155. LPWSTR pTemp = NULL;
  3156. //Must provide the confirmation in order for this to succeed.
  3157. if( dwArgCount < dwCurrentIndex + 1 )
  3158. {
  3159. DisplayMessage(g_hModule,
  3160. HLP_SRVR_DELETE_PARTNER_EX);
  3161. Status = ERROR_INVALID_PARAMETER;
  3162. goto ErrorReturn;
  3163. }
  3164. //Start processing the arguments based on ppwcArguments, dwCurrentIndex and dwArgCount
  3165. else
  3166. {
  3167. dwNumArgs = dwArgCount - dwCurrentIndex;
  3168. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3169. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3170. if( pdwTagType is NULL or
  3171. pdwTagNum is NULL )
  3172. {
  3173. Status = ERROR_NOT_ENOUGH_MEMORY;
  3174. goto ErrorReturn;
  3175. }
  3176. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  3177. Status = PreProcessCommand(ppwcArguments,
  3178. dwArgCount,
  3179. dwCurrentIndex,
  3180. pttTags,
  3181. &dwTagCount,
  3182. pdwTagType,
  3183. pdwTagNum);
  3184. if( Status isnot NO_ERROR )
  3185. goto ErrorReturn;
  3186. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  3187. {
  3188. if( pttTags[i].dwRequired is TRUE and
  3189. pttTags[i].bPresent is FALSE
  3190. )
  3191. {
  3192. Status = ERROR_INVALID_PARAMETER;
  3193. goto ErrorReturn;
  3194. }
  3195. }
  3196. for( j=0; j<dwTagCount; j++ )
  3197. {
  3198. switch(pdwTagType[j])
  3199. {
  3200. //Server Ip
  3201. case 0:
  3202. {
  3203. struct hostent * lpHostEnt = NULL;
  3204. CHAR cAddr[16];
  3205. BYTE pbAdd[4];
  3206. char szAdd[4];
  3207. int k = 0, l=0;
  3208. DWORD dwLen, nLen = 0;
  3209. CHAR *pTemp = NULL;
  3210. CHAR *pNetBios = NULL;
  3211. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) is FALSE )
  3212. {
  3213. Status = ERROR_INVALID_IPADDRESS;
  3214. goto ErrorReturn;
  3215. }
  3216. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  3217. break;
  3218. }
  3219. //Partner Type
  3220. case 1:
  3221. {
  3222. DWORD dw = 0;
  3223. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  3224. {
  3225. Status = ERROR_INVALID_PARAMETER;
  3226. goto ErrorReturn;
  3227. }
  3228. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  3229. switch(dw)
  3230. {
  3231. case 0:
  3232. {
  3233. fPull = TRUE;
  3234. fPush = FALSE;
  3235. break;
  3236. }
  3237. case 1:
  3238. {
  3239. fPull = FALSE;
  3240. fPush = TRUE;
  3241. break;
  3242. }
  3243. case 2:
  3244. {
  3245. fPull = TRUE;
  3246. fPush = TRUE;
  3247. break;
  3248. }
  3249. default:
  3250. {
  3251. Status = ERROR_INVALID_PARAMETER;
  3252. break;
  3253. }
  3254. }
  3255. break;
  3256. }
  3257. //Confirmation
  3258. case 2 :
  3259. {
  3260. if( 0 is _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"Y", 1) )
  3261. fConfirm = TRUE;
  3262. else if ( 0 is _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"N", 1) )
  3263. fConfirm = FALSE;
  3264. else
  3265. {
  3266. Status = ERROR_INVALID_PARAMETER;
  3267. goto ErrorReturn;
  3268. }
  3269. break;
  3270. }
  3271. default:
  3272. {
  3273. Status = ERROR_INVALID_PARAMETER;
  3274. goto ErrorReturn;
  3275. }
  3276. }
  3277. }
  3278. }
  3279. if( fConfirm is FALSE )
  3280. {
  3281. DisplayMessage(g_hModule,
  3282. MSG_WINS_CONFIRMATION_DENIED);
  3283. goto CommonReturn;
  3284. }
  3285. {
  3286. if( wcslen(g_ServerNetBiosName) > 0 )
  3287. {
  3288. pTemp = g_ServerNetBiosName;
  3289. }
  3290. Status = RegConnectRegistry(pTemp,
  3291. HKEY_LOCAL_MACHINE,
  3292. &hServer);
  3293. if( Status isnot ERROR_SUCCESS )
  3294. goto ErrorReturn;
  3295. //PullPartners
  3296. if( fPull )
  3297. {
  3298. Status = RegOpenKeyEx(hServer,
  3299. PULLROOT,
  3300. 0,
  3301. KEY_ALL_ACCESS,
  3302. &hPartner);
  3303. if( Status isnot NO_ERROR )
  3304. {
  3305. if (Status == ERROR_FILE_NOT_FOUND)
  3306. Status = NO_ERROR;
  3307. goto PUSH;
  3308. }
  3309. if( wcslen(wcServerIpAdd) < 3 )//not a valid Ip, delete all partners
  3310. {
  3311. while(TRUE)
  3312. {
  3313. Status = RegEnumKeyEx(hPartner, 0, wcServerIpAdd, &dwIpLen, NULL, NULL, NULL, NULL);
  3314. if (Status != ERROR_SUCCESS)
  3315. break;
  3316. RegDeleteKey(hPartner, wcServerIpAdd);
  3317. dwIpLen = (MAX_IP_STRING_LEN + 1)*sizeof(WCHAR);
  3318. memset(wcServerIpAdd, L'\0', MAX_IP_STRING_LEN+1);
  3319. }
  3320. }
  3321. else
  3322. {
  3323. RegDeleteKey(hPartner,
  3324. wcServerIpAdd);
  3325. }
  3326. if( hPartner )
  3327. {
  3328. RegCloseKey(hPartner);
  3329. hPartner = NULL;
  3330. }
  3331. if( Status is ERROR_NO_MORE_ITEMS )
  3332. {
  3333. Status = NO_ERROR;
  3334. goto PUSH;
  3335. }
  3336. if( Status is ERROR_FILE_NOT_FOUND )
  3337. {
  3338. DisplayMessage(g_hModule,
  3339. EMSG_INVALID_PARTNER_NAME);
  3340. if( fPush )
  3341. goto PUSH;
  3342. else
  3343. goto CommonReturn;
  3344. }
  3345. if( Status isnot NO_ERROR )
  3346. {
  3347. if( fPush )
  3348. goto PUSH;
  3349. else
  3350. goto CommonReturn;
  3351. }
  3352. }
  3353. //Push Partner
  3354. PUSH: if( fPush )
  3355. {
  3356. Status = RegOpenKeyEx(hServer,
  3357. PUSHROOT,
  3358. 0,
  3359. KEY_ALL_ACCESS,
  3360. &hPartner);
  3361. if (Status is ERROR_FILE_NOT_FOUND)
  3362. {
  3363. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  3364. goto CommonReturn;
  3365. }
  3366. if( Status isnot NO_ERROR )
  3367. goto ErrorReturn;
  3368. dwIpLen = (MAX_IP_STRING_LEN + 1);
  3369. if( wcslen(wcServerIpAdd) < 3 )//not a valid Ip, delete all partners
  3370. {
  3371. while( TRUE )
  3372. {
  3373. Status = RegEnumKeyEx(hPartner, 0, wcServerIpAdd, &dwIpLen, NULL, NULL, NULL, NULL);
  3374. if (Status != ERROR_SUCCESS)
  3375. break;
  3376. RegDeleteKey(hPartner, wcServerIpAdd);
  3377. dwIpLen = (MAX_IP_STRING_LEN + 1)*sizeof(WCHAR);
  3378. }
  3379. }
  3380. else
  3381. {
  3382. RegDeleteKey(hPartner,
  3383. wcServerIpAdd);
  3384. }
  3385. if( Status is ERROR_NO_MORE_ITEMS )
  3386. {
  3387. Status = NO_ERROR;
  3388. }
  3389. if( Status is ERROR_FILE_NOT_FOUND )
  3390. {
  3391. DisplayMessage(g_hModule,
  3392. EMSG_INVALID_PARTNER_NAME);
  3393. goto ErrorReturn;
  3394. }
  3395. if( Status isnot NO_ERROR )
  3396. goto ErrorReturn;
  3397. if( hPartner )
  3398. {
  3399. RegCloseKey(hPartner);
  3400. hPartner = NULL;
  3401. }
  3402. }
  3403. }
  3404. if( Status is NO_ERROR )
  3405. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  3406. else
  3407. goto ErrorReturn;
  3408. CommonReturn:
  3409. if( hPartner )
  3410. {
  3411. RegCloseKey(hPartner);
  3412. hPartner = NULL;
  3413. }
  3414. if( hServer )
  3415. {
  3416. RegCloseKey(hServer);
  3417. hServer = NULL;
  3418. }
  3419. if( pdwTagType )
  3420. {
  3421. WinsFreeMemory(pdwTagType);
  3422. pdwTagType = NULL;
  3423. }
  3424. if( pdwTagNum )
  3425. {
  3426. WinsFreeMemory(pdwTagNum);
  3427. pdwTagNum = NULL;
  3428. }
  3429. return Status;
  3430. ErrorReturn:
  3431. DisplayErrorMessage(EMSG_SRVR_DELETE_PARTNER, Status);
  3432. goto CommonReturn;
  3433. }
  3434. DWORD
  3435. HandleSrvrDeleteRecords(
  3436. IN LPCWSTR pwszMachine,
  3437. IN OUT LPWSTR *ppwcArguments,
  3438. IN DWORD dwCurrentIndex,
  3439. IN DWORD dwArgCount,
  3440. IN DWORD dwFlags,
  3441. IN LPCVOID pvData,
  3442. OUT BOOL *pbDone
  3443. )
  3444. /*++
  3445. Routine Description :
  3446. Delete or Tombstone records from a WINS server based on the version
  3447. Arguments :
  3448. All aguments are passes as array of wide char strings in ppwcArguments.
  3449. Compulsory : Minimum and Maximum version numbers( range of version ) to be
  3450. deleted/tombstoned
  3451. Optional : Operation - tombstone(default) or delete
  3452. Return Value:
  3453. Returns the status of the operation.
  3454. --*/
  3455. {
  3456. DWORD Status = NO_ERROR;
  3457. DWORD i, j, dwNumArgs, dwTagCount = 0;
  3458. PDWORD pdwTagType = NULL,
  3459. pdwTagNum = NULL;
  3460. TAG_TYPE pttTags[] = {
  3461. {WINS_TOKEN_MINVER, TRUE, FALSE},
  3462. {WINS_TOKEN_MAXVER, TRUE, FALSE},
  3463. {WINS_TOKEN_OP, FALSE, FALSE},
  3464. };
  3465. BOOL fDelete = TRUE;
  3466. WINSINTF_VERS_NO_T MinVer, MaxVer;
  3467. WINSINTF_ADD_T WinsAdd;
  3468. LPWSTR pwszTemp = NULL;
  3469. //Needs at least both Min Ver and Max ver
  3470. if( dwArgCount < dwCurrentIndex + 2 )
  3471. {
  3472. DisplayMessage(g_hModule, HLP_SRVR_DELETE_RECORDS_EX);
  3473. Status = ERROR_INVALID_PARAMETER;
  3474. goto ErrorReturn;
  3475. }
  3476. //Start processing the arguments based on ppwcArguments, dwCurrentIndex and dwArgCount
  3477. dwNumArgs = dwArgCount - dwCurrentIndex;
  3478. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3479. if( pdwTagType is NULL )
  3480. {
  3481. Status = ERROR_NOT_ENOUGH_MEMORY;
  3482. goto ErrorReturn;
  3483. }
  3484. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3485. if( pdwTagNum is NULL )
  3486. {
  3487. Status = ERROR_NOT_ENOUGH_MEMORY;
  3488. goto ErrorReturn;
  3489. }
  3490. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  3491. Status = PreProcessCommand(ppwcArguments,
  3492. dwArgCount,
  3493. dwCurrentIndex,
  3494. pttTags,
  3495. &dwTagCount,
  3496. pdwTagType,
  3497. pdwTagNum);
  3498. if( Status isnot NO_ERROR )
  3499. goto ErrorReturn;
  3500. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  3501. {
  3502. if( pttTags[i].dwRequired is TRUE and
  3503. pttTags[i].bPresent is FALSE
  3504. )
  3505. {
  3506. Status = ERROR_INVALID_PARAMETER;
  3507. goto ErrorReturn;
  3508. }
  3509. }
  3510. i = dwTagCount;
  3511. for( j=0; j<i; j++ )
  3512. {
  3513. switch(pdwTagType[j])
  3514. {
  3515. case 0://{high,low} format, Min version
  3516. {
  3517. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MinVer);
  3518. if( Status isnot NO_ERROR )
  3519. goto ErrorReturn;
  3520. break;
  3521. }
  3522. case 1://{high,low} format, Max version
  3523. {
  3524. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MaxVer);
  3525. if( Status isnot NO_ERROR )
  3526. goto ErrorReturn;
  3527. break;
  3528. }
  3529. case 2: //Operation 0 - delete 1 - Tombstone
  3530. {
  3531. DWORD dw = 0;
  3532. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  3533. {
  3534. Status = ERROR_INVALID_PARAMETER;
  3535. goto ErrorReturn;
  3536. }
  3537. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  3538. if( dw is 0 )
  3539. fDelete = TRUE;
  3540. else if( dw is 1 )
  3541. fDelete = FALSE;
  3542. else
  3543. {
  3544. Status = ERROR_INVALID_PARAMETER;
  3545. goto ErrorReturn;
  3546. }
  3547. break;
  3548. }
  3549. default:
  3550. {
  3551. Status = ERROR_INVALID_PARAMETER;
  3552. goto ErrorReturn;
  3553. }
  3554. }
  3555. }
  3556. WinsAdd.IPAdd = StringToIpAddress(g_ServerIpAddressUnicodeString);
  3557. WinsAdd.Len = 4;
  3558. WinsAdd.Type = 0;
  3559. if( fDelete )
  3560. {
  3561. Status = WinsDelDbRecs(g_hBind, &WinsAdd, MinVer, MaxVer);
  3562. }
  3563. else
  3564. {
  3565. Status = WinsTombstoneDbRecs(g_hBind, &WinsAdd, MinVer, MaxVer);
  3566. }
  3567. if( Status isnot NO_ERROR )
  3568. goto ErrorReturn;
  3569. CommonReturn:
  3570. if( Status is NO_ERROR )
  3571. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  3572. if( pdwTagType )
  3573. {
  3574. WinsFreeMemory(pdwTagType);
  3575. pdwTagType = NULL;
  3576. }
  3577. if( pdwTagNum )
  3578. {
  3579. WinsFreeMemory(pdwTagNum);
  3580. pdwTagNum = NULL;
  3581. }
  3582. return Status;
  3583. ErrorReturn:
  3584. DisplayErrorMessage(EMSG_SRVR_DELETE_RECORDS,
  3585. Status);
  3586. goto CommonReturn;
  3587. }
  3588. DWORD
  3589. HandleSrvrDeleteWins(
  3590. IN LPCWSTR pwszMachine,
  3591. IN OUT LPWSTR *ppwcArguments,
  3592. IN DWORD dwCurrentIndex,
  3593. IN DWORD dwArgCount,
  3594. IN DWORD dwFlags,
  3595. IN LPCVOID pvData,
  3596. OUT BOOL *pbDone
  3597. )
  3598. /*++
  3599. Routine Description :
  3600. Delete a partner from the WINS server
  3601. Arguments :
  3602. All aguments are passes as array of wide char strings in ppwcArguments.
  3603. Compulsory : Confirmation
  3604. Optional : Server IP and Type.
  3605. Note : If no ip is provided, it deletes all partners in the list.
  3606. Return Value:
  3607. Returns the status of the operation.
  3608. --*/
  3609. {
  3610. DWORD Status = NO_ERROR;
  3611. DWORD i, j, dwNumArgs, dwTagCount;
  3612. TAG_TYPE pttTags[] = {
  3613. {WINS_TOKEN_SERVERS, TRUE, FALSE},
  3614. {WINS_TOKEN_OP, FALSE, FALSE},
  3615. };
  3616. DWORD dwIpCount = 0;
  3617. LPDWORD pdwIp = NULL,
  3618. pdwTagType = NULL,
  3619. pdwTagNum = NULL;
  3620. BOOL fDelete = FALSE;
  3621. WINSINTF_ADD_T WinsAdd;
  3622. handle_t hBind;
  3623. WINSINTF_BIND_DATA_T BindData;
  3624. if( dwArgCount < dwCurrentIndex + 1 )
  3625. {
  3626. DisplayMessage(g_hModule,
  3627. HLP_SRVR_DELETE_WINS_EX);
  3628. Status = ERROR_INVALID_PARAMETER;
  3629. goto ErrorReturn;
  3630. }
  3631. dwNumArgs = dwArgCount - dwCurrentIndex;
  3632. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3633. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  3634. if( pdwTagType is NULL or
  3635. pdwTagNum is NULL )
  3636. {
  3637. Status = ERROR_NOT_ENOUGH_MEMORY;
  3638. goto ErrorReturn;
  3639. }
  3640. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  3641. Status = PreProcessCommand(ppwcArguments,
  3642. dwArgCount,
  3643. dwCurrentIndex,
  3644. pttTags,
  3645. &dwTagCount,
  3646. pdwTagType,
  3647. pdwTagNum);
  3648. if( Status isnot NO_ERROR )
  3649. goto ErrorReturn;
  3650. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  3651. {
  3652. if( pttTags[i].dwRequired is TRUE and
  3653. pttTags[i].bPresent is FALSE
  3654. )
  3655. {
  3656. Status = ERROR_INVALID_PARAMETER;
  3657. goto ErrorReturn;
  3658. }
  3659. }
  3660. for( j=0; j<dwTagCount; j++ )
  3661. {
  3662. switch(pdwTagType[j])
  3663. {
  3664. case 0:
  3665. {
  3666. LPWSTR pszIps = NULL;
  3667. DWORD dwIpLen = 0;
  3668. LPWSTR pTemp = NULL;
  3669. DWORD dwIp = 0;
  3670. dwIpCount = 0;
  3671. dwIpLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  3672. if( dwIpLen < 2 )
  3673. {
  3674. Status = ERROR_INVALID_PARAMETER;
  3675. goto ErrorReturn;
  3676. }
  3677. pszIps = WinsAllocateMemory((dwIpLen+1)*sizeof(WCHAR));
  3678. if( pszIps is NULL )
  3679. {
  3680. Status = ERROR_NOT_ENOUGH_MEMORY;
  3681. goto ErrorReturn;
  3682. }
  3683. wcscpy(pszIps, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  3684. if( pszIps[0] isnot L'{' or
  3685. pszIps[dwIpLen-1] isnot L'}')
  3686. {
  3687. Status = ERROR_INVALID_PARAMETER;
  3688. if( pszIps )
  3689. {
  3690. WinsFreeMemory(pszIps);
  3691. pszIps = NULL;
  3692. }
  3693. goto ErrorReturn;
  3694. }
  3695. pTemp = pszIps+1;
  3696. pszIps[dwIpLen-1] = L'\0';
  3697. pTemp = wcstok(pTemp, L",");
  3698. while(( pTemp isnot NULL ) && (dwIpCount < WINSINTF_MAX_MEM ) )
  3699. {
  3700. PDWORD pdwTemp = NULL;
  3701. dwIpCount++;
  3702. pdwTemp = WinsAllocateMemory(dwIpCount*sizeof(DWORD));
  3703. if( pdwTemp is NULL )
  3704. {
  3705. Status = ERROR_NOT_ENOUGH_MEMORY;
  3706. if( pszIps )
  3707. {
  3708. WinsFreeMemory(pszIps);
  3709. pszIps = NULL;
  3710. }
  3711. goto ErrorReturn;
  3712. }
  3713. if( pdwIp )
  3714. {
  3715. memcpy(pdwTemp, pdwIp, (dwIpCount-1)*sizeof(DWORD));
  3716. WinsFreeMemory(pdwIp);
  3717. pdwIp = NULL;
  3718. }
  3719. dwIp = StringToIpAddress(pTemp);
  3720. if( dwIp is INADDR_NONE )
  3721. {
  3722. Status = ERROR_INVALID_PARAMETER;
  3723. if( pszIps )
  3724. {
  3725. WinsFreeMemory(pszIps);
  3726. pszIps = NULL;
  3727. }
  3728. if( pdwTemp )
  3729. {
  3730. WinsFreeMemory(pdwTemp);
  3731. pdwTemp = NULL;
  3732. }
  3733. goto ErrorReturn;
  3734. }
  3735. pdwTemp[dwIpCount-1] = dwIp;
  3736. pdwIp = pdwTemp;
  3737. pTemp = wcstok(NULL, L",");
  3738. }
  3739. if( pszIps )
  3740. {
  3741. WinsFreeMemory(pszIps);
  3742. pszIps = NULL;
  3743. }
  3744. break;
  3745. }
  3746. case 1:
  3747. {
  3748. DWORD dw = 0;
  3749. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  3750. {
  3751. Status = ERROR_INVALID_PARAMETER;
  3752. goto ErrorReturn;
  3753. }
  3754. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  3755. if( dw is 0 )
  3756. {
  3757. fDelete = FALSE;
  3758. break;
  3759. }
  3760. else if( dw is 1 )
  3761. {
  3762. fDelete = TRUE;
  3763. break;
  3764. }
  3765. else
  3766. {
  3767. Status = ERROR_INVALID_PARAMETER;
  3768. goto ErrorReturn;
  3769. }
  3770. break;
  3771. }
  3772. default:
  3773. {
  3774. Status = ERROR_INVALID_PARAMETER;
  3775. goto ErrorReturn;
  3776. }
  3777. }
  3778. }
  3779. for( i=0; i<dwIpCount; i++ )
  3780. {
  3781. WinsAdd.Len = 4;
  3782. WinsAdd.Type = 0;
  3783. WinsAdd.IPAdd = pdwIp[i];
  3784. if( fDelete is TRUE )
  3785. {
  3786. DisplayMessage(g_hModule,
  3787. MSG_WINS_DELETING_RECORD,
  3788. IpAddressToString(pdwIp[i]));
  3789. Status = WinsDeleteWins(g_hBind,
  3790. &WinsAdd);
  3791. }
  3792. else
  3793. {
  3794. WINSINTF_RESULTS_T Results;
  3795. WINSINTF_VERS_NO_T MinVer;
  3796. WINSINTF_VERS_NO_T MaxVer;
  3797. MaxVer.HighPart = 0;
  3798. MaxVer.LowPart = 0;
  3799. MinVer.HighPart = 0;
  3800. MinVer.LowPart = 0;
  3801. DisplayMessage(g_hModule,
  3802. MSG_WINS_TOMBSTONE_RECORD,
  3803. IpAddressToString(pdwIp[i]));
  3804. Status = WinsTombstoneDbRecs(g_hBind,
  3805. &WinsAdd,
  3806. MinVer,
  3807. MaxVer);
  3808. }
  3809. if( Status isnot NO_ERROR )
  3810. {
  3811. DisplayMessage(g_hModule,
  3812. EMSG_WINS_OPERATION_FAILED,
  3813. IpAddressToString(pdwIp[i]));
  3814. DisplayErrorMessage(EMSG_SRVR_ERROR_MESSAGE,
  3815. Status);
  3816. continue;
  3817. }
  3818. }
  3819. if( Status is NO_ERROR )
  3820. {
  3821. DisplayMessage(g_hModule,
  3822. EMSG_WINS_ERROR_SUCCESS);
  3823. }
  3824. CommonReturn:
  3825. if( pdwTagType )
  3826. {
  3827. WinsFreeMemory(pdwTagType);
  3828. pdwTagType = NULL;
  3829. }
  3830. if( pdwTagNum )
  3831. {
  3832. WinsFreeMemory(pdwTagNum);
  3833. pdwTagNum = NULL;
  3834. }
  3835. if( pdwIp )
  3836. {
  3837. WinsFreeMemory(pdwIp);
  3838. pdwIp = NULL;
  3839. }
  3840. return Status;
  3841. ErrorReturn:
  3842. DisplayErrorMessage(EMSG_SRVR_DELETE_WINS,
  3843. Status);
  3844. goto CommonReturn;
  3845. }
  3846. DWORD
  3847. HandleSrvrDeletePersona(
  3848. IN LPCWSTR pwszMachine,
  3849. IN OUT LPWSTR *ppwcArguments,
  3850. IN DWORD dwCurrentIndex,
  3851. IN DWORD dwArgCount,
  3852. IN DWORD dwFlags,
  3853. IN LPCVOID pvData,
  3854. OUT BOOL *pbDone
  3855. )
  3856. /*++
  3857. Routine Description :
  3858. Delete one or all PNG servers from the list of PNG servers
  3859. Arguments :
  3860. All aguments are passes as array of wide char strings in ppwcArguments.
  3861. Compulsory : A list of server IP Address separated by commas and
  3862. enclosed by {}. If no server address is provided within {}
  3863. it will delete all PNG servers.
  3864. Return Value:
  3865. Returns the status of the operation.
  3866. --*/
  3867. {
  3868. DWORD Status = NO_ERROR;
  3869. DWORD i, j, dwTagCount, dwNumArgs;
  3870. HKEY hServer = NULL,
  3871. hPartner = NULL;
  3872. TAG_TYPE pttTags[] = {
  3873. {WINS_TOKEN_SERVERS,TRUE, FALSE},
  3874. };
  3875. LPBYTE pbData = NULL,
  3876. pbValue = NULL;
  3877. DWORD dwSize = 0,
  3878. dwType = 0,
  3879. dwCount = 0,
  3880. dwTemp = 0;
  3881. LPWSTR pTemp = NULL,
  3882. pwszPng = NULL;
  3883. DWORD dwTagType = 1,
  3884. dwTagNum = 1,
  3885. dwLenCount = 0,
  3886. dwPngIp = 0;
  3887. LPDWORD pdwPngIp = NULL;
  3888. BOOL fAtleastone = FALSE;
  3889. BOOL fGrata;
  3890. fGrata = (wcsstr(CMD_SRVR_DELETE_PNGSERVER, ppwcArguments[dwCurrentIndex-1]) == NULL);
  3891. if( dwArgCount < dwCurrentIndex + 1 )
  3892. {
  3893. DisplayMessage(g_hModule, fGrata ? HLP_SRVR_DELETE_PGSERVER_EX : HLP_SRVR_DELETE_PNGSERVER_EX);
  3894. Status = ERROR_INVALID_PARAMETER;
  3895. goto ErrorReturn;
  3896. }
  3897. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  3898. Status = PreProcessCommand(ppwcArguments,
  3899. dwArgCount,
  3900. dwCurrentIndex,
  3901. pttTags,
  3902. &dwTagCount,
  3903. &dwTagType,
  3904. &dwTagNum);
  3905. if( Status isnot NO_ERROR )
  3906. goto ErrorReturn;
  3907. if( pttTags[0].bPresent is FALSE )
  3908. {
  3909. Status = ERROR_INVALID_PARAMETER;
  3910. goto ErrorReturn;
  3911. }
  3912. if( wcslen(g_ServerNetBiosName) > 0 )
  3913. pTemp = g_ServerNetBiosName;
  3914. Status = RegConnectRegistry(pTemp,
  3915. HKEY_LOCAL_MACHINE,
  3916. &hServer);
  3917. if( Status isnot NO_ERROR )
  3918. {
  3919. goto ErrorReturn;
  3920. }
  3921. Status = RegOpenKeyEx(hServer,
  3922. PARTNERROOT,
  3923. 0,
  3924. KEY_ALL_ACCESS,
  3925. &hPartner);
  3926. if( Status isnot NO_ERROR )
  3927. {
  3928. goto ErrorReturn;
  3929. }
  3930. if (!CheckValidPgOp(hPartner, fGrata))
  3931. {
  3932. DisplayMessage(g_hModule, fGrata ? EMSG_SRVR_PG_INVALIDOP : EMSG_SRVR_PNG_INVALIDOP);
  3933. Status = ERROR_INVALID_PARAMETER;
  3934. goto CommonReturn;
  3935. }
  3936. Status = RegQueryValueEx(hPartner,
  3937. fGrata ? PGSERVER : PNGSERVER,
  3938. NULL,
  3939. &dwType,
  3940. NULL,
  3941. &dwSize);
  3942. if( Status isnot NO_ERROR && Status isnot ERROR_FILE_NOT_FOUND)
  3943. goto ErrorReturn;
  3944. if( dwSize < 7 )
  3945. {
  3946. DisplayMessage(g_hModule,
  3947. EMSG_WINS_ERROR_SUCCESS);
  3948. goto CommonReturn;
  3949. }
  3950. pbData = WinsAllocateMemory(dwSize);
  3951. if( pbData is NULL )
  3952. {
  3953. Status = ERROR_NOT_ENOUGH_MEMORY;
  3954. goto ErrorReturn;
  3955. }
  3956. Status = RegQueryValueEx(hPartner,
  3957. fGrata ? PGSERVER : PNGSERVER,
  3958. NULL,
  3959. &dwType,
  3960. pbData,
  3961. &dwSize);
  3962. if( Status isnot NO_ERROR )
  3963. goto ErrorReturn;
  3964. pwszPng = (LPWSTR)pbData;
  3965. for( i=0; i<(dwSize+2)/sizeof(WCHAR); i++ )
  3966. {
  3967. if( pwszPng[i] is L'\0' and
  3968. pwszPng[i+1] isnot L'\0')
  3969. {
  3970. pwszPng[i] = L',';
  3971. i++;
  3972. }
  3973. }
  3974. dwPngIp = 0;
  3975. dwCount = 0;
  3976. pTemp = wcstok(pwszPng, L",");
  3977. while((pTemp isnot NULL) && (dwLenCount+sizeof(WCHAR)*7<dwSize))
  3978. {
  3979. LPDWORD pdwTemp = pdwPngIp;
  3980. dwPngIp++;
  3981. dwLenCount += wcslen(pTemp)*sizeof(WCHAR);
  3982. pdwPngIp = WinsAllocateMemory(dwPngIp*sizeof(DWORD));
  3983. if( pdwPngIp is NULL )
  3984. {
  3985. WinsFreeMemory(pdwTemp);
  3986. pdwTemp = NULL;
  3987. Status = ERROR_INVALID_PARAMETER;
  3988. goto ErrorReturn;
  3989. }
  3990. if( pdwTemp isnot NULL )
  3991. {
  3992. memcpy(pdwPngIp, pdwTemp, (dwPngIp-1)*sizeof(DWORD));
  3993. WinsFreeMemory(pdwTemp);
  3994. pdwTemp = NULL;
  3995. }
  3996. pdwPngIp[dwPngIp-1] = StringToIpAddress(pTemp);
  3997. pTemp = wcstok(NULL, L",");
  3998. dwLenCount+=sizeof(WCHAR);
  3999. }
  4000. //Now parse the data
  4001. {
  4002. LPWSTR pwszTemp = NULL;
  4003. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex]);
  4004. if( ppwcArguments[dwCurrentIndex][0] isnot L'{' or
  4005. ppwcArguments[dwCurrentIndex][dwLen-1] isnot L'}' )
  4006. {
  4007. Status = ERROR_INVALID_PARAMETER;
  4008. goto ErrorReturn;
  4009. }
  4010. if( dwLen < 7 )
  4011. {
  4012. BYTE rgbByte[] = {0x00, 0x00, 0x00, 0x00};
  4013. Status = RegSetValueEx(hPartner,
  4014. fGrata ? PGSERVER : PNGSERVER,
  4015. 0,
  4016. REG_MULTI_SZ,
  4017. rgbByte,
  4018. sizeof(rgbByte));
  4019. if( Status isnot NO_ERROR )
  4020. goto ErrorReturn;
  4021. fAtleastone = TRUE;
  4022. DisplayMessage(g_hModule,
  4023. EMSG_WINS_ERROR_SUCCESS);
  4024. goto CommonReturn;
  4025. }
  4026. pwszTemp = WinsAllocateMemory((dwLen-1)*sizeof(WCHAR));
  4027. if( pwszTemp is NULL )
  4028. {
  4029. Status = ERROR_NOT_ENOUGH_MEMORY;
  4030. goto ErrorReturn;
  4031. }
  4032. wcsncpy(pwszTemp, ppwcArguments[dwCurrentIndex]+1, dwLen-1);
  4033. pwszTemp[dwLen-2] = L'\0';
  4034. pTemp = wcstok(pwszTemp, L",");
  4035. dwCount = 0;
  4036. while(pTemp isnot NULL )
  4037. {
  4038. DWORD dw = StringToIpAddress(pTemp);
  4039. BOOL fPresent = TRUE;
  4040. if( dw is INADDR_NONE )
  4041. {
  4042. DisplayMessage(g_hModule,
  4043. EMSG_WINS_INVALID_IPADDRESS,
  4044. pTemp);
  4045. }
  4046. else
  4047. {
  4048. for( i=0; i<dwPngIp; i++ )
  4049. {
  4050. if( dw is pdwPngIp[i] )
  4051. {
  4052. LPDWORD pdwTemp = pdwPngIp;
  4053. pdwPngIp = WinsAllocateMemory((dwPngIp-1)*sizeof(DWORD));
  4054. if( pdwPngIp is NULL )
  4055. {
  4056. WinsFreeMemory(pdwTemp);
  4057. pdwTemp = NULL;
  4058. WinsFreeMemory(pwszTemp);
  4059. pwszTemp = NULL;
  4060. Status = ERROR_NOT_ENOUGH_MEMORY;
  4061. goto ErrorReturn;
  4062. }
  4063. fAtleastone = TRUE;
  4064. memcpy(pdwPngIp, pdwTemp, i*sizeof(DWORD));
  4065. for( j=i+1; j<dwPngIp; j++ )
  4066. {
  4067. pdwPngIp[j-1] = pdwTemp[j];
  4068. }
  4069. dwPngIp--;
  4070. break;
  4071. }
  4072. else
  4073. continue;
  4074. }
  4075. }
  4076. pTemp = wcstok(NULL, L",");
  4077. }
  4078. dwTemp += 0;
  4079. pbValue = WinsAllocateMemory((dwPngIp*(MAX_IP_STRING_LEN+1)+1)*sizeof(WCHAR));
  4080. if( pbValue is NULL )
  4081. {
  4082. Status = ERROR_NOT_ENOUGH_MEMORY;
  4083. goto ErrorReturn;
  4084. }
  4085. pTemp = (LPWSTR)pbValue;
  4086. for( i=0; i<dwPngIp; i++ )
  4087. {
  4088. LPWSTR pwIp = NULL;
  4089. pwIp = IpAddressToString(pdwPngIp[i]);
  4090. if( pwIp is NULL )
  4091. {
  4092. Status = ERROR_NOT_ENOUGH_MEMORY;
  4093. goto ErrorReturn;
  4094. }
  4095. wcscpy(pTemp+dwTemp, pwIp);
  4096. dwTemp+=wcslen(pwIp);
  4097. dwTemp++;
  4098. WinsFreeMemory(pwIp);
  4099. pwIp = NULL;
  4100. }
  4101. pTemp[dwTemp++] = L'\0';
  4102. }
  4103. Status = RegSetValueEx(hPartner,
  4104. fGrata ? PGSERVER : PNGSERVER,
  4105. 0,
  4106. REG_MULTI_SZ,
  4107. pbValue,
  4108. dwTemp*sizeof(WCHAR));
  4109. if( Status isnot NO_ERROR )
  4110. goto ErrorReturn;
  4111. if( fAtleastone is FALSE )
  4112. {
  4113. DisplayMessage(g_hModule,
  4114. fGrata ? EMSG_SRVR_ATLEAST_ONE_PG : EMSG_SRVR_ATLEAST_ONE_PNG);
  4115. }
  4116. DisplayMessage(g_hModule,
  4117. EMSG_WINS_ERROR_SUCCESS);
  4118. CommonReturn:
  4119. if( pbData )
  4120. {
  4121. WinsFreeMemory(pbData);
  4122. pbData = NULL;
  4123. }
  4124. if( pbValue )
  4125. {
  4126. WinsFreeMemory(pbValue);
  4127. pbValue = NULL;
  4128. }
  4129. if( pdwPngIp )
  4130. {
  4131. WinsFreeMemory(pdwPngIp);
  4132. pdwPngIp = NULL;
  4133. }
  4134. if( hServer )
  4135. {
  4136. RegCloseKey(hServer);
  4137. hServer = NULL;
  4138. }
  4139. if( hPartner )
  4140. {
  4141. RegCloseKey(hPartner);
  4142. hPartner = NULL;
  4143. }
  4144. return Status;
  4145. ErrorReturn:
  4146. DisplayErrorMessage(fGrata ? EMSG_SRVR_DELETE_PGSERVER : EMSG_SRVR_DELETE_PNGSERVER,
  4147. Status);
  4148. goto CommonReturn;
  4149. }
  4150. DWORD
  4151. HandleSrvrInitBackup(
  4152. IN LPCWSTR pwszMachine,
  4153. IN OUT LPWSTR *ppwcArguments,
  4154. IN DWORD dwCurrentIndex,
  4155. IN DWORD dwArgCount,
  4156. IN DWORD dwFlags,
  4157. IN LPCVOID pvData,
  4158. OUT BOOL *pbDone
  4159. )
  4160. /*++
  4161. Routine Description :
  4162. Initiates a backup operation of WINS Server database.
  4163. Arguments :
  4164. All aguments are passes as array of wide char strings in ppwcArguments.
  4165. Optional : Backup directory. If none is specified, it will assume the
  4166. the default directory.
  4167. Return Value:
  4168. Returns the status of the operation.
  4169. --*/
  4170. {
  4171. DWORD Status = NO_ERROR;
  4172. DWORD i, j, dwNumArgs, dwTagCount;
  4173. PDWORD pdwNumTags = NULL, pdwTypeTags = NULL;
  4174. LPSTR pszBackupPath = NULL;
  4175. LPWSTR pwszTemp = NULL;
  4176. BOOL fIncremental = FALSE;
  4177. LPBYTE lpStr = NULL;
  4178. TAG_TYPE pttTags[] = { {WINS_TOKEN_DIR, FALSE, FALSE},
  4179. {WINS_TOKEN_TYPE, FALSE, FALSE},
  4180. };
  4181. if( dwArgCount > dwCurrentIndex )
  4182. {
  4183. dwNumArgs = dwArgCount - dwCurrentIndex;
  4184. pdwNumTags = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4185. if( pdwNumTags is NULL )
  4186. {
  4187. Status = ERROR_NOT_ENOUGH_MEMORY;
  4188. goto ErrorReturn;
  4189. }
  4190. pdwTypeTags = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4191. if( pdwTypeTags is NULL )
  4192. {
  4193. Status = ERROR_NOT_ENOUGH_MEMORY;
  4194. goto ErrorReturn;
  4195. }
  4196. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  4197. Status = PreProcessCommand(ppwcArguments,
  4198. dwArgCount,
  4199. dwCurrentIndex,
  4200. pttTags,
  4201. &dwTagCount,
  4202. pdwTypeTags,
  4203. pdwNumTags);
  4204. if( Status isnot NO_ERROR )
  4205. goto ErrorReturn;
  4206. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  4207. {
  4208. if( pttTags[i].dwRequired is TRUE and
  4209. pttTags[i].bPresent is FALSE
  4210. )
  4211. {
  4212. Status = ERROR_INVALID_PARAMETER;
  4213. goto ErrorReturn;
  4214. }
  4215. }
  4216. i = dwTagCount;
  4217. for( j = 0; j < i ; j++ )
  4218. {
  4219. switch(pdwTypeTags[j])
  4220. {
  4221. case 0:
  4222. {
  4223. pszBackupPath = WinsUnicodeToOem(ppwcArguments[dwCurrentIndex+pdwNumTags[j]], NULL);
  4224. if( pszBackupPath is NULL )
  4225. {
  4226. Status = ERROR_NOT_ENOUGH_MEMORY;
  4227. goto ErrorReturn;
  4228. }
  4229. break;
  4230. }
  4231. case 1:
  4232. {
  4233. DWORD dwType = 0;
  4234. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwNumTags[j]]) is FALSE )
  4235. {
  4236. Status = ERROR_INVALID_PARAMETER;
  4237. goto ErrorReturn;
  4238. }
  4239. dwType = STRTOUL(ppwcArguments[dwCurrentIndex+pdwNumTags[j]], NULL, 0);
  4240. if( dwType is 0 )
  4241. fIncremental = FALSE;
  4242. else if( dwType is 1 )
  4243. fIncremental = TRUE;
  4244. else
  4245. {
  4246. Status = ERROR_INVALID_PARAMETER;
  4247. goto ErrorReturn;
  4248. }
  4249. break;
  4250. }
  4251. default:
  4252. {
  4253. Status = ERROR_INVALID_PARAMETER;
  4254. goto ErrorReturn;
  4255. }
  4256. }
  4257. }
  4258. }
  4259. if( pszBackupPath is NULL ) //Look for the previously set backup path from Registry
  4260. {
  4261. HKEY hServer = NULL,
  4262. hParameter = NULL;
  4263. WCHAR wcTempSrc[1024] = {L'\0'},
  4264. wcTempDst[1024] = {L'\0'};
  4265. LPSTR pszTempPath = NULL;
  4266. DWORD dwType = REG_EXPAND_SZ,
  4267. dwTempLen = 1024*sizeof(WCHAR);
  4268. if( wcslen(g_ServerNetBiosName) > 0 )
  4269. pwszTemp = g_ServerNetBiosName;
  4270. Status = RegConnectRegistry(pwszTemp,
  4271. HKEY_LOCAL_MACHINE,
  4272. &hServer);
  4273. if( Status isnot NO_ERROR )
  4274. {
  4275. goto ErrorReturn;
  4276. }
  4277. Status = RegOpenKeyEx(hServer,
  4278. PARAMETER,
  4279. 0,
  4280. KEY_ALL_ACCESS,
  4281. &hParameter);
  4282. if( Status isnot NO_ERROR )
  4283. {
  4284. RegCloseKey(hServer);
  4285. hServer = NULL;
  4286. goto ErrorReturn;
  4287. }
  4288. Status = RegQueryValueEx(hParameter,
  4289. WINSCNF_BACKUP_DIR_PATH_NM,
  4290. 0,
  4291. &dwType,
  4292. (LPBYTE)wcTempSrc,
  4293. &dwTempLen);
  4294. RegCloseKey(hParameter);
  4295. hParameter = NULL;
  4296. RegCloseKey(hServer);
  4297. hServer = NULL;
  4298. if( Status is ERROR_FILE_NOT_FOUND or
  4299. wcslen(wcTempSrc) is 0 )
  4300. {
  4301. DisplayMessage(g_hModule,
  4302. EMSG_SRVR_NOBACKUP_PATH);
  4303. Status = ERROR_INVALID_PARAMETER;
  4304. goto CommonReturn;
  4305. }
  4306. if( Status isnot NO_ERROR )
  4307. {
  4308. goto ErrorReturn;
  4309. }
  4310. dwTempLen = ExpandEnvironmentStrings(wcTempSrc,
  4311. wcTempDst,
  4312. 1024);
  4313. if( dwTempLen is 0 )
  4314. {
  4315. goto ErrorReturn;
  4316. }
  4317. pszTempPath = WinsUnicodeToOem(wcTempDst, NULL);
  4318. if( pszTempPath is NULL )
  4319. {
  4320. Status = ERROR_NOT_ENOUGH_MEMORY;
  4321. goto ErrorReturn;
  4322. }
  4323. dwTempLen = MAX(dwTempLen, strlen(pszTempPath));
  4324. pszBackupPath = WinsAllocateMemory(dwTempLen+1);
  4325. if( pszBackupPath is NULL )
  4326. {
  4327. Status = ERROR_NOT_ENOUGH_MEMORY;
  4328. goto ErrorReturn;
  4329. }
  4330. strcpy(pszBackupPath, pszTempPath);
  4331. WinsFreeMemory(pszTempPath);
  4332. pszTempPath = NULL;
  4333. }
  4334. if( pszBackupPath[strlen(pszBackupPath) - 1] is '\\' )
  4335. {
  4336. pszBackupPath[strlen(pszBackupPath) - 1] = '\0';
  4337. }
  4338. Status = WinsBackup(g_hBind,
  4339. (LPBYTE)pszBackupPath,
  4340. (short)fIncremental);
  4341. if( Status isnot NO_ERROR )
  4342. goto ErrorReturn;
  4343. CommonReturn:
  4344. if( Status is NO_ERROR )
  4345. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  4346. if( pdwTypeTags )
  4347. {
  4348. WinsFreeMemory(pdwTypeTags);
  4349. pdwTypeTags = NULL;
  4350. }
  4351. if( pdwNumTags )
  4352. {
  4353. WinsFreeMemory(pdwNumTags);
  4354. pdwNumTags = NULL;
  4355. }
  4356. if( pszBackupPath )
  4357. {
  4358. WinsFreeMemory(pszBackupPath);
  4359. pszBackupPath = NULL;
  4360. }
  4361. return Status;
  4362. ErrorReturn:
  4363. DisplayErrorMessage(EMSG_SRVR_INIT_BACKUP,
  4364. Status);
  4365. goto CommonReturn;
  4366. }
  4367. DWORD
  4368. HandleSrvrInitImport(
  4369. IN LPCWSTR pwszMachine,
  4370. IN OUT LPWSTR *ppwcArguments,
  4371. IN DWORD dwCurrentIndex,
  4372. IN DWORD dwArgCount,
  4373. IN DWORD dwFlags,
  4374. IN LPCVOID pvData,
  4375. OUT BOOL *pbDone
  4376. )
  4377. /*++
  4378. Routine Description :
  4379. Initiates import of records from LMHOSTS file.
  4380. Arguments :
  4381. All aguments are passes as array of wide char strings in ppwcArguments.
  4382. Compulsory : Lmhosts file name.
  4383. Return Value:
  4384. Returns the status of the operation.
  4385. --*/
  4386. {
  4387. DWORD Status = NO_ERROR;
  4388. DWORD i, j, dwNumArgs, dwTagCount;
  4389. TAG_TYPE pttTags[] = {
  4390. {WINS_TOKEN_FILE, TRUE, FALSE},
  4391. };
  4392. PDWORD pdwTagType = NULL,
  4393. pdwTagNum = NULL;
  4394. LPWSTR pwszFileName = NULL;
  4395. WCHAR wcTemp[2042] = {L'\0'};
  4396. if( dwArgCount < dwCurrentIndex + 1 )
  4397. {
  4398. DisplayMessage(g_hModule, HLP_SRVR_INIT_IMPORT_EX);
  4399. Status = ERROR_INVALID_PARAMETER;
  4400. goto ErrorReturn;
  4401. }
  4402. dwNumArgs = dwArgCount - dwCurrentIndex;
  4403. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4404. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4405. if( pdwTagType is NULL or
  4406. pdwTagNum is NULL )
  4407. {
  4408. Status = ERROR_NOT_ENOUGH_MEMORY;
  4409. goto ErrorReturn;
  4410. }
  4411. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  4412. Status = PreProcessCommand(ppwcArguments,
  4413. dwArgCount,
  4414. dwCurrentIndex,
  4415. pttTags,
  4416. &dwTagCount,
  4417. pdwTagType,
  4418. pdwTagNum);
  4419. if( Status isnot NO_ERROR )
  4420. goto ErrorReturn;
  4421. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  4422. {
  4423. if( pttTags[i].dwRequired is TRUE and
  4424. pttTags[i].bPresent is FALSE
  4425. )
  4426. {
  4427. Status = ERROR_INVALID_PARAMETER;
  4428. goto ErrorReturn;
  4429. }
  4430. }
  4431. for( j=0; j<dwTagCount; j++ )
  4432. {
  4433. switch(pdwTagType[j])
  4434. {
  4435. case 0:
  4436. {
  4437. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4438. if( dwLen is 0 )
  4439. {
  4440. Status = ERROR_INVALID_PARAMETER;
  4441. goto ErrorReturn;
  4442. }
  4443. pwszFileName = WinsAllocateMemory((dwLen+1)*sizeof(WCHAR));
  4444. if( pwszFileName is NULL )
  4445. {
  4446. Status = ERROR_NOT_ENOUGH_MEMORY;
  4447. goto ErrorReturn;
  4448. }
  4449. wcscpy(pwszFileName, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4450. break;
  4451. }
  4452. default:
  4453. {
  4454. Status = ERROR_INVALID_PARAMETER;
  4455. goto ErrorReturn;
  4456. }
  4457. }
  4458. }
  4459. if( pwszFileName )
  4460. {
  4461. //
  4462. // If this is a local connection, we copy the file to
  4463. // temporary name (the source may be on a remote drive
  4464. // which is not accessible to the WINS service.
  4465. //
  4466. // If this is not a local connection, attempt to copy
  4467. // the file to a temp name on C$ of the WINS server
  4468. //
  4469. do
  4470. {
  4471. if (IsLocalServer())
  4472. {
  4473. wcscpy(wcTemp ,_wtempnam(NULL, L"WINS"));
  4474. //
  4475. // First copy file to a temporary name (since the file
  4476. // could be remote), and then import and delete this file
  4477. //
  4478. if (!CopyFile(pwszFileName, wcTemp, TRUE))
  4479. {
  4480. Status = GetLastError();
  4481. break;
  4482. }
  4483. //
  4484. // Now import the temporary file, and delete the file
  4485. // afterwards.
  4486. //
  4487. Status = ImportStaticMappingsFile(wcTemp, TRUE);
  4488. DeleteFile(wcTemp);
  4489. }
  4490. else
  4491. {
  4492. //
  4493. // Try copying to the remote machine C: drive
  4494. //
  4495. wcscat(wcTemp, L"\\\\");
  4496. wcscat(wcTemp, g_ServerNameUnicode);
  4497. wcscat(wcTemp, L"\\");
  4498. wcscat(wcTemp, L"C$");
  4499. wcscat(wcTemp, L"\\");
  4500. wcscat(wcTemp, L"WINS");
  4501. j = wcslen(wcTemp);
  4502. i=0;
  4503. while (TRUE)
  4504. {
  4505. WCHAR Buffer[10] = {L'\0'};
  4506. DWORD dwErr = 0;
  4507. _itow(i, Buffer, 10);
  4508. wcscat(wcTemp,Buffer);
  4509. if (GetFileAttributes(wcTemp) == -1)
  4510. {
  4511. dwErr = GetLastError();
  4512. if (dwErr is ERROR_FILE_NOT_FOUND)
  4513. {
  4514. break;
  4515. }
  4516. }
  4517. wcTemp[j] = L'\0';
  4518. i++;
  4519. }
  4520. //
  4521. // First copy file to a temporary name (since the file
  4522. // could be remote), and then import and delete this file
  4523. //
  4524. if (!CopyFile(pwszFileName, wcTemp, TRUE))
  4525. {
  4526. Status = GetLastError();
  4527. break;
  4528. }
  4529. //
  4530. // Now import the temporary file, and delete the file
  4531. // afterwards.
  4532. //
  4533. Status = ImportStaticMappingsFile(wcTemp, TRUE);
  4534. DeleteFile(wcTemp);
  4535. }
  4536. }while(FALSE);
  4537. if (Status isnot NO_ERROR )
  4538. {
  4539. goto ErrorReturn;
  4540. }
  4541. }
  4542. CommonReturn:
  4543. if( Status is NO_ERROR )
  4544. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  4545. if( pwszFileName )
  4546. {
  4547. WinsFreeMemory(pwszFileName);
  4548. pwszFileName = NULL;
  4549. }
  4550. if( pdwTagType )
  4551. {
  4552. WinsFreeMemory(pdwTagType);
  4553. pdwTagType = NULL;
  4554. }
  4555. if( pdwTagNum )
  4556. {
  4557. WinsFreeMemory(pdwTagNum);
  4558. pdwTagNum = NULL;
  4559. }
  4560. return Status;
  4561. ErrorReturn:
  4562. DisplayErrorMessage(EMSG_SRVR_INIT_IMPORT,
  4563. Status);
  4564. goto CommonReturn;
  4565. }
  4566. DWORD
  4567. HandleSrvrInitPull(
  4568. IN LPCWSTR pwszMachine,
  4569. IN OUT LPWSTR *ppwcArguments,
  4570. IN DWORD dwCurrentIndex,
  4571. IN DWORD dwArgCount,
  4572. IN DWORD dwFlags,
  4573. IN LPCVOID pvData,
  4574. OUT BOOL *pbDone
  4575. )
  4576. /*++
  4577. Routine Description :
  4578. Initiates and send pull trigger to the specified pull partner.
  4579. Arguments :
  4580. All aguments are passes as array of wide char strings in ppwcArguments.
  4581. Compulsory : Server Ip Address
  4582. Return Value:
  4583. Returns the status of the operation.
  4584. --*/
  4585. {
  4586. DWORD Status = NO_ERROR;
  4587. WINSINTF_ADD_T WinsAdd;
  4588. DWORD i, j, dwNumArgs, dwTagCount = 0;
  4589. PDWORD pdwTagType = NULL,
  4590. pdwTagNum = NULL;
  4591. TAG_TYPE pttTags[] = {
  4592. {WINS_TOKEN_SERVER, TRUE, FALSE},
  4593. };
  4594. LPWSTR pwszTemp = NULL;
  4595. if( dwArgCount < dwCurrentIndex+1 )
  4596. {
  4597. DisplayMessage(g_hModule, HLP_SRVR_INIT_PULL_EX);
  4598. Status = ERROR_INVALID_PARAMETER;
  4599. goto ErrorReturn;
  4600. }
  4601. dwNumArgs = dwArgCount - dwCurrentIndex;
  4602. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4603. if(pdwTagType is NULL )
  4604. {
  4605. Status = ERROR_NOT_ENOUGH_MEMORY;
  4606. goto ErrorReturn;
  4607. }
  4608. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4609. if(pdwTagType is NULL )
  4610. {
  4611. Status = ERROR_NOT_ENOUGH_MEMORY;
  4612. goto ErrorReturn;
  4613. }
  4614. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  4615. Status = PreProcessCommand(ppwcArguments,
  4616. dwArgCount,
  4617. dwCurrentIndex,
  4618. pttTags,
  4619. &dwTagCount,
  4620. pdwTagType,
  4621. pdwTagNum);
  4622. if( Status isnot NO_ERROR )
  4623. goto ErrorReturn;
  4624. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  4625. {
  4626. if( pttTags[i].dwRequired is TRUE and
  4627. pttTags[i].bPresent is FALSE
  4628. )
  4629. {
  4630. Status = ERROR_INVALID_PARAMETER;
  4631. goto ErrorReturn;
  4632. }
  4633. }
  4634. i = dwTagCount;
  4635. for( j=0; j<i; j++ )
  4636. {
  4637. switch(pdwTagType[j])
  4638. {
  4639. case 0:
  4640. {
  4641. WinsAdd.Len = 4;
  4642. WinsAdd.Type = 0;
  4643. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is 0 )
  4644. {
  4645. Status = ERROR_INVALID_PARAMETER;
  4646. goto ErrorReturn;
  4647. }
  4648. if( IsIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) )
  4649. {
  4650. WinsAdd.IPAdd = StringToIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4651. break;
  4652. }
  4653. else //Server UNC name
  4654. {
  4655. struct hostent * lpHostEnt = NULL;
  4656. CHAR cAddr[16];
  4657. BYTE pbAdd[4];
  4658. char szAdd[4];
  4659. int k = 0, l=0;
  4660. DWORD nLen = 0;
  4661. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  4662. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  4663. k = 2;
  4664. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  4665. if( lpHostEnt is NULL )
  4666. {
  4667. DisplayMessage(g_hModule,
  4668. EMSG_WINS_INVALID_COMPUTER_NAME,
  4669. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  4670. Status = ERROR_INVALID_PARAMETER;
  4671. goto ErrorReturn;
  4672. }
  4673. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  4674. for( l=0;l<4; l++)
  4675. {
  4676. _itoa((int)pbAdd[l], szAdd, 10);
  4677. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  4678. nLen += strlen(szAdd);
  4679. *(cAddr+nLen) = '.';
  4680. nLen++;
  4681. }
  4682. *(cAddr+nLen-1) = '\0';
  4683. WinsAdd.IPAdd = WinsDottedStringToIpAddress(cAddr);
  4684. }
  4685. break;
  4686. }
  4687. default:
  4688. {
  4689. Status = ERROR_INVALID_PARAMETER;
  4690. goto ErrorReturn;
  4691. }
  4692. }
  4693. }
  4694. for( j=0; j<sizeof(pttTags)/sizeof(TAG_TYPE); j++)
  4695. {
  4696. if( pttTags[j].dwRequired is TRUE &&
  4697. pttTags[j].bPresent is FALSE )
  4698. {
  4699. DisplayMessage(g_hModule,
  4700. EMSG_WINS_REQUIRED_PARAMETER,
  4701. j);
  4702. Status = ERROR_INVALID_PARAMETER;
  4703. goto ErrorReturn;
  4704. }
  4705. }
  4706. Status = WinsTrigger(g_hBind, &WinsAdd, WINSINTF_E_PULL);
  4707. if( Status isnot NO_ERROR )
  4708. goto ErrorReturn;
  4709. CommonReturn:
  4710. if( Status is NO_ERROR )
  4711. {
  4712. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  4713. }
  4714. if( pdwTagType )
  4715. {
  4716. WinsFreeMemory(pdwTagType);
  4717. pdwTagType = NULL;
  4718. }
  4719. if( pdwTagNum )
  4720. {
  4721. WinsFreeMemory(pdwTagNum);
  4722. pdwTagNum = NULL;
  4723. }
  4724. return Status;
  4725. ErrorReturn:
  4726. DisplayErrorMessage(EMSG_SRVR_INIT_PULL,
  4727. Status);
  4728. goto CommonReturn;
  4729. }
  4730. DWORD
  4731. HandleSrvrInitPullrange(
  4732. IN LPCWSTR pwszMachine,
  4733. IN OUT LPWSTR *ppwcArguments,
  4734. IN DWORD dwCurrentIndex,
  4735. IN DWORD dwArgCount,
  4736. IN DWORD dwFlags,
  4737. IN LPCVOID pvData,
  4738. OUT BOOL *pbDone
  4739. )
  4740. /*++
  4741. Routine Description :
  4742. Initiates and pulls a range of database from a particular server.
  4743. Arguments :
  4744. All aguments are passes as array of wide char strings in ppwcArguments.
  4745. Compulsory : Pulls a range of database from a particular server owned by
  4746. a particular server within the given version range.
  4747. Note : If no ip is provided, it deletes all partners in the list.
  4748. Return Value:
  4749. Returns the status of the operation.
  4750. --*/
  4751. {
  4752. DWORD Status = NO_ERROR;
  4753. DWORD i, j, dwTagCount, dwNumArgs;
  4754. TAG_TYPE pttTags[] = {
  4755. {WINS_TOKEN_OWNER, TRUE, FALSE},
  4756. {WINS_TOKEN_SERVER, TRUE, FALSE},
  4757. {WINS_TOKEN_MAXVER, TRUE, FALSE},
  4758. {WINS_TOKEN_MINVER, TRUE, FALSE},
  4759. };
  4760. LPDWORD pdwTagType = NULL,
  4761. pdwTagNum = NULL;
  4762. WINSINTF_VERS_NO_T MinVer, MaxVer;
  4763. WINSINTF_ADD_T PullAdd, OwnerAdd ;
  4764. if( dwArgCount < dwCurrentIndex + 4 )
  4765. {
  4766. DisplayMessage(g_hModule,
  4767. HLP_SRVR_INIT_PULLRANGE_EX);
  4768. Status = ERROR_INVALID_PARAMETER;
  4769. goto ErrorReturn;
  4770. }
  4771. dwNumArgs = dwArgCount - dwCurrentIndex;
  4772. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4773. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4774. if( pdwTagType is NULL or
  4775. pdwTagNum is NULL )
  4776. {
  4777. Status = ERROR_NOT_ENOUGH_MEMORY;
  4778. goto ErrorReturn;
  4779. }
  4780. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  4781. Status = PreProcessCommand(ppwcArguments,
  4782. dwArgCount,
  4783. dwCurrentIndex,
  4784. pttTags,
  4785. &dwTagCount,
  4786. pdwTagType,
  4787. pdwTagNum);
  4788. if( Status isnot NO_ERROR )
  4789. goto ErrorReturn;
  4790. for( j=0; j<sizeof(pttTags)/sizeof(TAG_TYPE); j++ )
  4791. {
  4792. if( pttTags[j].dwRequired is TRUE and
  4793. pttTags[j].bPresent is FALSE )
  4794. {
  4795. Status = ERROR_INVALID_PARAMETER;
  4796. goto ErrorReturn;
  4797. }
  4798. }
  4799. for( j=0; j<dwTagCount; j++ )
  4800. {
  4801. switch(pdwTagType[j])
  4802. {
  4803. case 0:
  4804. {
  4805. if( IsIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  4806. {
  4807. Status = ERROR_INVALID_PARAMETER;
  4808. goto ErrorReturn;
  4809. }
  4810. OwnerAdd.IPAdd = StringToIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4811. OwnerAdd.Type = 0;
  4812. OwnerAdd.Len = 4;
  4813. break;
  4814. }
  4815. case 1:
  4816. {
  4817. if( IsIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  4818. {
  4819. Status = ERROR_INVALID_PARAMETER;
  4820. goto ErrorReturn;
  4821. }
  4822. PullAdd.IPAdd = StringToIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4823. PullAdd.Type = 0;
  4824. PullAdd.Len = 4;
  4825. break;
  4826. }
  4827. case 2:
  4828. {
  4829. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MaxVer);
  4830. if( Status isnot NO_ERROR )
  4831. goto ErrorReturn;
  4832. break;
  4833. }
  4834. case 3:
  4835. {
  4836. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MinVer);
  4837. if( Status isnot NO_ERROR )
  4838. goto ErrorReturn;
  4839. break;
  4840. }
  4841. default:
  4842. {
  4843. Status = ERROR_INVALID_PARAMETER;
  4844. goto ErrorReturn;
  4845. }
  4846. }
  4847. }
  4848. Status = WinsPullRange(g_hBind, &PullAdd, &OwnerAdd, MinVer, MaxVer);
  4849. if( Status isnot NO_ERROR )
  4850. goto ErrorReturn;
  4851. DisplayMessage(g_hModule,
  4852. EMSG_WINS_ERROR_SUCCESS);
  4853. CommonReturn:
  4854. if( pdwTagType )
  4855. {
  4856. WinsFreeMemory(pdwTagType);
  4857. pdwTagType = NULL;
  4858. }
  4859. if( pdwTagNum )
  4860. {
  4861. WinsFreeMemory(pdwTagNum);
  4862. pdwTagNum = NULL;
  4863. }
  4864. return Status;
  4865. ErrorReturn:
  4866. DisplayErrorMessage(EMSG_SRVR_INIT_PULLRANGE,
  4867. Status);
  4868. goto CommonReturn;
  4869. }
  4870. DWORD
  4871. HandleSrvrInitPush(
  4872. IN LPCWSTR pwszMachine,
  4873. IN OUT LPWSTR *ppwcArguments,
  4874. IN DWORD dwCurrentIndex,
  4875. IN DWORD dwArgCount,
  4876. IN DWORD dwFlags,
  4877. IN LPCVOID pvData,
  4878. OUT BOOL *pbDone
  4879. )
  4880. /*++
  4881. Routine Description :
  4882. Initiate and sends push trigger to a particular Push partner.
  4883. Arguments :
  4884. All aguments are passes as array of wide char strings in ppwcArguments.
  4885. Compulsory : Push partner's IP Address
  4886. Optional : If user wants to propagate the push trigger
  4887. Return Value:
  4888. Returns the status of the operation.
  4889. --*/
  4890. {
  4891. DWORD Status = NO_ERROR;
  4892. WINSINTF_ADD_T WinsAdd;
  4893. DWORD i, j, dwNumArgs, dwTagCount=0;
  4894. PDWORD pdwTagType = NULL,
  4895. pdwTagNum = NULL;
  4896. TAG_TYPE pttTags[] = {
  4897. {WINS_TOKEN_SERVER, TRUE, FALSE},
  4898. {WINS_TOKEN_PROPAGATION, FALSE, FALSE},
  4899. };
  4900. LPWSTR pwszTemp = NULL;
  4901. DWORD dwChoice = WINSINTF_E_PUSH;
  4902. if( dwArgCount < dwCurrentIndex + 1 )
  4903. {
  4904. DisplayMessage(g_hModule, HLP_SRVR_INIT_PUSH_EX);
  4905. Status = ERROR_INVALID_PARAMETER;
  4906. goto ErrorReturn;
  4907. }
  4908. dwNumArgs = dwArgCount - dwCurrentIndex;
  4909. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4910. if(pdwTagType is NULL )
  4911. {
  4912. Status = ERROR_NOT_ENOUGH_MEMORY;
  4913. goto ErrorReturn;
  4914. }
  4915. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  4916. if(pdwTagType is NULL )
  4917. {
  4918. Status = ERROR_NOT_ENOUGH_MEMORY;
  4919. goto ErrorReturn;
  4920. }
  4921. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  4922. Status = PreProcessCommand(ppwcArguments,
  4923. dwArgCount,
  4924. dwCurrentIndex,
  4925. pttTags,
  4926. &dwTagCount,
  4927. pdwTagType,
  4928. pdwTagNum);
  4929. if( Status isnot NO_ERROR )
  4930. goto ErrorReturn;
  4931. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  4932. {
  4933. if( pttTags[i].dwRequired is TRUE and
  4934. pttTags[i].bPresent is FALSE
  4935. )
  4936. {
  4937. Status = ERROR_INVALID_PARAMETER;
  4938. goto ErrorReturn;
  4939. }
  4940. }
  4941. i = dwTagCount;
  4942. for( j=0; j<i; j++ )
  4943. {
  4944. switch(pdwTagType[j])
  4945. {
  4946. case 0:
  4947. {
  4948. WinsAdd.Len = 4;
  4949. WinsAdd.Type = 0;
  4950. if( IsIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) )
  4951. {
  4952. WinsAdd.IPAdd = StringToIpAddress(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  4953. }
  4954. else //Server UNC name
  4955. {
  4956. struct hostent * lpHostEnt = NULL;
  4957. CHAR cAddr[16];
  4958. BYTE pbAdd[4];
  4959. char szAdd[4];
  4960. int k = 0, l=0;
  4961. DWORD nLen = 0;
  4962. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  4963. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  4964. k = 2;
  4965. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  4966. if( lpHostEnt is NULL )
  4967. {
  4968. DisplayMessage(g_hModule,
  4969. EMSG_WINS_INVALID_COMPUTER_NAME,
  4970. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  4971. Status = ERROR_INVALID_PARAMETER;
  4972. goto ErrorReturn;
  4973. }
  4974. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  4975. for( l=0;l<4; l++)
  4976. {
  4977. _itoa((int)pbAdd[l], szAdd, 10);
  4978. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  4979. nLen += strlen(szAdd);
  4980. *(cAddr+nLen) = '.';
  4981. nLen++;
  4982. }
  4983. *(cAddr+nLen-1) = '\0';
  4984. WinsAdd.IPAdd = WinsDottedStringToIpAddress(cAddr);
  4985. }
  4986. break;
  4987. }
  4988. case 1:
  4989. {
  4990. DWORD dwVal = 0;
  4991. if( ( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE ) or
  4992. ( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 1 ) )
  4993. {
  4994. Status = ERROR_INVALID_PARAMETER;
  4995. goto ErrorReturn;
  4996. }
  4997. if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] is L'1' )
  4998. dwChoice = WINSINTF_E_PUSH_PROP;
  4999. else if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] is L'0' )
  5000. dwChoice = WINSINTF_E_PUSH;
  5001. else
  5002. {
  5003. Status = ERROR_INVALID_PARAMETER;
  5004. goto ErrorReturn;
  5005. }
  5006. break;
  5007. }
  5008. default:
  5009. {
  5010. Status = ERROR_INVALID_PARAMETER;
  5011. goto ErrorReturn;
  5012. }
  5013. }
  5014. }
  5015. for( j=0; j<sizeof(pttTags)/sizeof(TAG_TYPE); j++)
  5016. {
  5017. if( pttTags[j].dwRequired is TRUE &&
  5018. pttTags[j].bPresent is FALSE )
  5019. {
  5020. DisplayMessage(g_hModule,
  5021. EMSG_WINS_REQUIRED_PARAMETER,
  5022. j);
  5023. Status = ERROR_INVALID_PARAMETER;
  5024. goto ErrorReturn;
  5025. }
  5026. }
  5027. Status = WinsTrigger(g_hBind, &WinsAdd, dwChoice);
  5028. if( Status isnot NO_ERROR )
  5029. goto ErrorReturn;
  5030. CommonReturn:
  5031. if( Status is NO_ERROR )
  5032. {
  5033. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  5034. }
  5035. if( pdwTagType )
  5036. {
  5037. WinsFreeMemory(pdwTagType);
  5038. pdwTagType = NULL;
  5039. }
  5040. if( pdwTagNum )
  5041. {
  5042. WinsFreeMemory(pdwTagNum);
  5043. pdwTagNum = NULL;
  5044. }
  5045. return Status;
  5046. ErrorReturn:
  5047. DisplayErrorMessage(EMSG_SRVR_INIT_PUSH,
  5048. Status);
  5049. goto CommonReturn;
  5050. }
  5051. DWORD
  5052. HandleSrvrInitReplicate(
  5053. IN LPCWSTR pwszMachine,
  5054. IN OUT LPWSTR *ppwcArguments,
  5055. IN DWORD dwCurrentIndex,
  5056. IN DWORD dwArgCount,
  5057. IN DWORD dwFlags,
  5058. IN LPCVOID pvData,
  5059. OUT BOOL *pbDone
  5060. )
  5061. /*++
  5062. Routine Description :
  5063. Initiates a database replication with the partners
  5064. Arguments :
  5065. All aguments are passes as array of wide char strings in ppwcArguments.
  5066. NONE.
  5067. Return Value:
  5068. Returns the status of the operation.
  5069. --*/
  5070. {
  5071. DWORD Status = NO_ERROR;
  5072. HKEY hServer = NULL,
  5073. hPullRoot = NULL,
  5074. hPushRoot = NULL;
  5075. DWORD dw = 0,
  5076. dwKeyLen = MAX_IP_STRING_LEN+1,
  5077. dwPullKeys = 0,
  5078. dwPushKeys = 0;
  5079. WCHAR wcIpAddress[MAX_IP_STRING_LEN+1] = {L'\0'};
  5080. LPWSTR pTemp = NULL;
  5081. WINSINTF_ADD_T WinsAdd;
  5082. if( wcslen(g_ServerNetBiosName) > 0 )
  5083. {
  5084. pTemp = g_ServerNetBiosName;
  5085. }
  5086. Status = RegConnectRegistry(pTemp,
  5087. HKEY_LOCAL_MACHINE,
  5088. &hServer);
  5089. if( Status isnot NO_ERROR )
  5090. {
  5091. goto ErrorReturn;
  5092. }
  5093. Status = RegOpenKeyEx(hServer,
  5094. PULLROOT,
  5095. 0,
  5096. KEY_ALL_ACCESS,
  5097. &hPullRoot);
  5098. if( Status isnot NO_ERROR )
  5099. goto ErrorReturn;
  5100. Status = RegQueryInfoKey(hPullRoot,
  5101. NULL,
  5102. NULL,
  5103. NULL,
  5104. &dwPullKeys,
  5105. NULL,
  5106. NULL,
  5107. NULL,
  5108. NULL,
  5109. NULL,
  5110. NULL,
  5111. NULL);
  5112. if( Status isnot NO_ERROR )
  5113. goto ErrorReturn;
  5114. Status = RegOpenKeyEx(hServer,
  5115. PUSHROOT,
  5116. 0,
  5117. KEY_ALL_ACCESS,
  5118. &hPushRoot);
  5119. if( Status isnot NO_ERROR )
  5120. goto ErrorReturn;
  5121. Status = RegQueryInfoKey(hPushRoot,
  5122. NULL,
  5123. NULL,
  5124. NULL,
  5125. &dwPushKeys,
  5126. NULL,
  5127. NULL,
  5128. NULL,
  5129. NULL,
  5130. NULL,
  5131. NULL,
  5132. NULL);
  5133. if( Status isnot NO_ERROR )
  5134. goto ErrorReturn;
  5135. DisplayMessage(g_hModule, MSG_WINS_TIME_WARNING);
  5136. WinsAdd.Len = 4;
  5137. WinsAdd.Type = 0;
  5138. if( dwPullKeys is 0 )
  5139. {
  5140. DisplayMessage(g_hModule, EMSG_WINS_NO_PULLPARTNER);
  5141. }
  5142. if( dwPushKeys is 0 )
  5143. {
  5144. DisplayMessage(g_hModule, EMSG_WINS_NO_PUSHPARTNER);
  5145. }
  5146. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  5147. for( dw=0; dw<dwPullKeys; dw++ )
  5148. {
  5149. dwKeyLen = MAX_IP_STRING_LEN+1;
  5150. Status = RegEnumKeyEx(hPullRoot,
  5151. dw,
  5152. wcIpAddress,
  5153. &dwKeyLen,
  5154. NULL,
  5155. NULL,
  5156. NULL,
  5157. NULL);
  5158. if( Status isnot NO_ERROR )
  5159. continue;
  5160. WinsAdd.IPAdd = StringToIpAddress(wcIpAddress);
  5161. DisplayMessage(g_hModule, MSG_WINS_SEND_PULL, wcIpAddress);
  5162. Status = WinsTrigger(g_hBind, &WinsAdd, WINSINTF_E_PULL);
  5163. if( Status isnot NO_ERROR )
  5164. {
  5165. DisplayMessage(g_hModule, EMSG_WINS_PULL_FAILED);
  5166. }
  5167. else
  5168. {
  5169. DisplayMessage(g_hModule, MSG_WINS_TRIGGER_DONE);
  5170. }
  5171. }
  5172. WinsAdd.Len = 4;
  5173. WinsAdd.Type = 0;
  5174. for( dw=0; dw<dwPushKeys; dw++ )
  5175. {
  5176. dwKeyLen = MAX_IP_STRING_LEN+1;
  5177. Status = RegEnumKeyEx(hPushRoot,
  5178. dw,
  5179. wcIpAddress,
  5180. &dwKeyLen,
  5181. NULL,
  5182. NULL,
  5183. NULL,
  5184. NULL);
  5185. if( Status isnot NO_ERROR )
  5186. continue;
  5187. WinsAdd.IPAdd = StringToIpAddress(wcIpAddress);
  5188. DisplayMessage(g_hModule, MSG_WINS_SEND_PUSH, wcIpAddress);
  5189. Status = WinsTrigger(g_hBind, &WinsAdd, WINSINTF_E_PUSH_PROP);
  5190. if( Status isnot NO_ERROR )
  5191. {
  5192. DisplayMessage(g_hModule, EMSG_WINS_PUSH_FAILED);
  5193. }
  5194. else
  5195. {
  5196. DisplayMessage(g_hModule, MSG_WINS_TRIGGER_DONE);
  5197. }
  5198. }
  5199. if( Status isnot NO_ERROR )
  5200. goto CommonReturn;
  5201. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  5202. CommonReturn:
  5203. if( hServer )
  5204. {
  5205. RegCloseKey(hServer);
  5206. hServer = NULL;
  5207. }
  5208. if( hPullRoot )
  5209. {
  5210. RegCloseKey(hPullRoot);
  5211. hPullRoot = NULL;
  5212. }
  5213. if( hPushRoot )
  5214. {
  5215. RegCloseKey(hPushRoot);
  5216. hPushRoot = NULL;
  5217. }
  5218. return Status;
  5219. ErrorReturn:
  5220. if( Status is ERROR_FILE_NOT_FOUND )
  5221. {
  5222. DisplayMessage(g_hModule,
  5223. MSG_WINS_NO_PARTNER);
  5224. }
  5225. else
  5226. {
  5227. DisplayErrorMessage(EMSG_SRVR_INIT_REPLICATE,
  5228. Status);
  5229. }
  5230. goto CommonReturn;
  5231. }
  5232. DWORD
  5233. HandleSrvrInitRestore(
  5234. IN LPCWSTR pwszMachine,
  5235. IN OUT LPWSTR *ppwcArguments,
  5236. IN DWORD dwCurrentIndex,
  5237. IN DWORD dwArgCount,
  5238. IN DWORD dwFlags,
  5239. IN LPCVOID pvData,
  5240. OUT BOOL *pbDone
  5241. )
  5242. /*++
  5243. Routine Description :
  5244. Initiates and restore database
  5245. Arguments :
  5246. All aguments are passes as array of wide char strings in ppwcArguments.
  5247. Compulsory : Directory to do restore from
  5248. Return Value:
  5249. Returns the status of the operation.
  5250. --*/
  5251. {
  5252. DWORD Status = NO_ERROR,
  5253. Status1 = NO_ERROR,
  5254. i, j, dwNumArgs, dwTagCount=0;
  5255. PDWORD pdwNumTags = NULL, pdwTypeTags = NULL;
  5256. TAG_TYPE pttTags[] = { {WINS_TOKEN_DIR, TRUE, FALSE},
  5257. {WINS_TOKEN_VERSION, FALSE, FALSE},
  5258. };
  5259. CHAR szRestorePath[MAX_PATH+1] = {'\0'};
  5260. LPWSTR pwszTemp = NULL;
  5261. DWORD dwService = NO_ERROR;
  5262. DbVersion eVersion = 3;
  5263. BOOL fBackupOnTerm = FALSE;
  5264. handle_t wbdhBind = g_hBind;
  5265. WINSINTF_BIND_DATA_T wbdBindData = g_BindData;
  5266. DWORD dwError = NO_ERROR;
  5267. if( dwArgCount < dwCurrentIndex + 1 )
  5268. {
  5269. DisplayMessage(g_hModule, HLP_SRVR_INIT_RESTORE_EX);
  5270. Status = ERROR_INVALID_PARAMETER;
  5271. goto ErrorReturn;
  5272. }
  5273. if( IsLocalServer() is FALSE )
  5274. {
  5275. DisplayMessage(g_hModule,
  5276. EMSG_WINS_LOCAL_SERVER,
  5277. g_ServerIpAddressUnicodeString);
  5278. return ERROR_INVALID_PARAMETER;
  5279. }
  5280. dwNumArgs = dwArgCount - dwCurrentIndex;
  5281. pdwNumTags = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  5282. if( pdwNumTags is NULL )
  5283. {
  5284. Status = ERROR_NOT_ENOUGH_MEMORY;
  5285. goto ErrorReturn;
  5286. }
  5287. pdwTypeTags = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  5288. if( pdwTypeTags is NULL )
  5289. {
  5290. Status = ERROR_NOT_ENOUGH_MEMORY;
  5291. goto ErrorReturn;
  5292. }
  5293. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  5294. Status = PreProcessCommand(ppwcArguments,
  5295. dwArgCount,
  5296. dwCurrentIndex,
  5297. pttTags,
  5298. &dwTagCount,
  5299. pdwTypeTags,
  5300. pdwNumTags);
  5301. if( Status isnot NO_ERROR )
  5302. goto ErrorReturn;
  5303. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  5304. {
  5305. if( pttTags[i].dwRequired is TRUE and
  5306. pttTags[i].bPresent is FALSE
  5307. )
  5308. {
  5309. Status = ERROR_INVALID_PARAMETER;
  5310. goto ErrorReturn;
  5311. }
  5312. }
  5313. i = dwTagCount;
  5314. for( j = 0; j < i ; j++ )
  5315. {
  5316. switch(pdwTypeTags[j])
  5317. {
  5318. case 0:
  5319. {
  5320. DWORD dw = 0;
  5321. LPSTR pszTempPath = NULL;
  5322. pszTempPath = WinsUnicodeToOem(ppwcArguments[dwCurrentIndex+pdwNumTags[j]], NULL);
  5323. if( pszTempPath is NULL )
  5324. {
  5325. Status = ERROR_NOT_ENOUGH_MEMORY;
  5326. goto ErrorReturn;
  5327. }
  5328. dw = strlen(pszTempPath);
  5329. if( dw < 2 )
  5330. {
  5331. Status = ERROR_INVALID_PARAMETER;
  5332. WinsFreeMemory( pszTempPath );
  5333. pszTempPath = NULL;
  5334. goto ErrorReturn;
  5335. }
  5336. strncpy(szRestorePath,
  5337. pszTempPath,
  5338. ( dw > MAX_PATH - 1 ) ? MAX_PATH - 1 : dw );
  5339. WinsFreeMemory(pszTempPath);
  5340. pszTempPath = NULL;
  5341. break;
  5342. }
  5343. case 1:
  5344. {
  5345. DWORD eVer = 0;
  5346. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwNumTags[j]]) is FALSE )
  5347. {
  5348. Status = ERROR_INVALID_PARAMETER;
  5349. goto ErrorReturn;
  5350. }
  5351. eVer = STRTOUL(ppwcArguments[dwCurrentIndex+pdwNumTags[j]], NULL, 0);
  5352. if( eVer > DbVersionMin && eVer < DbVersionMax )
  5353. eVersion = eVer;
  5354. else
  5355. {
  5356. Status = ERROR_INVALID_DB_VERSION;
  5357. goto ErrorReturn;
  5358. }
  5359. break;
  5360. }
  5361. default:
  5362. {
  5363. Status = ERROR_INVALID_PARAMETER;
  5364. goto ErrorReturn;
  5365. }
  5366. }
  5367. }
  5368. //To restore the database, first stop WINS Service, Cleanup earlier dabase
  5369. //do DB restore and then restart WINS
  5370. {
  5371. //Unbind WINS
  5372. WinsUnbind(&g_BindData, g_hBind);
  5373. g_hBind = NULL;
  5374. //Reset Backup on Termination flag
  5375. {
  5376. HKEY hServer = NULL,
  5377. hParameter = NULL;
  5378. LPWSTR pTemp = NULL;
  5379. DWORD dwSize = sizeof(DWORD);
  5380. DWORD dwType = REG_DWORD;
  5381. DWORD dwData = 0;
  5382. if( wcslen(g_ServerNetBiosName) > 0 )
  5383. pTemp = g_ServerNetBiosName;
  5384. Status = RegConnectRegistry(pTemp,
  5385. HKEY_LOCAL_MACHINE,
  5386. &hServer);
  5387. if( Status isnot NO_ERROR )
  5388. goto EXIT;
  5389. Status = RegOpenKeyEx(hServer,
  5390. PARAMETER,
  5391. 0,
  5392. KEY_ALL_ACCESS,
  5393. &hParameter);
  5394. if( Status isnot NO_ERROR )
  5395. goto EXIT;
  5396. Status = RegQueryValueEx(hParameter,
  5397. WINSCNF_DO_BACKUP_ON_TERM_NM,
  5398. NULL,
  5399. &dwType,
  5400. (LPBYTE)&dwData,
  5401. &dwSize);
  5402. if( Status is NO_ERROR )
  5403. {
  5404. if( dwData is 1 )
  5405. {
  5406. DWORD dw = 0;
  5407. Status = RegSetValueEx(hParameter,
  5408. WINSCNF_DO_BACKUP_ON_TERM_NM,
  5409. 0,
  5410. REG_DWORD,
  5411. (LPBYTE)&dw,
  5412. sizeof(DWORD));
  5413. if( Status is NO_ERROR )
  5414. fBackupOnTerm = TRUE;
  5415. }
  5416. else
  5417. {
  5418. fBackupOnTerm = FALSE;
  5419. }
  5420. }
  5421. EXIT:
  5422. if( Status isnot NO_ERROR )
  5423. {
  5424. DisplayMessage(g_hModule,
  5425. EMSG_WINS_RESTORE_IMPROPER);
  5426. }
  5427. if( hServer )
  5428. {
  5429. RegCloseKey(hServer);
  5430. hServer = NULL;
  5431. }
  5432. if( hParameter )
  5433. {
  5434. RegCloseKey(hParameter);
  5435. hParameter = NULL;
  5436. }
  5437. Status = NO_ERROR;
  5438. }
  5439. //Stop WINS Service
  5440. Status = ControlWINSService(TRUE);
  5441. if( Status isnot NO_ERROR )
  5442. {
  5443. if( Status isnot ERROR_SERVICE_NOT_ACTIVE )
  5444. {
  5445. g_BindData = wbdBindData;
  5446. g_hBind = WinsBind(&g_BindData);
  5447. goto ErrorReturn;
  5448. }
  5449. else
  5450. {
  5451. dwService = ERROR_SERVICE_NOT_ACTIVE;
  5452. Status = NO_ERROR;
  5453. }
  5454. }
  5455. //Now try restoring the database
  5456. Status1 = WinsRestore((LPBYTE)szRestorePath);
  5457. if( Status1 isnot NO_ERROR )
  5458. {
  5459. DisplayErrorMessage(EMSG_SRVR_INIT_RESTORE,
  5460. Status1);
  5461. }
  5462. if( dwService isnot ERROR_SERVICE_NOT_ACTIVE )
  5463. Status = ControlWINSService(FALSE);
  5464. }
  5465. if( Status isnot NO_ERROR )
  5466. goto ErrorReturn;
  5467. if( Status1 isnot NO_ERROR )
  5468. {
  5469. Status = Status1;
  5470. goto ErrorReturn;
  5471. }
  5472. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  5473. CommonReturn:
  5474. g_BindData = wbdBindData;
  5475. g_hBind = WinsBind(&g_BindData);
  5476. //Reset the DoBackUpOnTerm value
  5477. if( fBackupOnTerm is TRUE )
  5478. {
  5479. HKEY hServer = NULL,
  5480. hParameter = NULL;
  5481. LPWSTR pTemp = NULL;
  5482. DWORD dwErr = NO_ERROR;
  5483. if( wcslen(g_ServerNetBiosName) > 0 )
  5484. {
  5485. pTemp = g_ServerNetBiosName;
  5486. }
  5487. dwErr = RegConnectRegistry(pTemp,
  5488. HKEY_LOCAL_MACHINE,
  5489. &hServer);
  5490. if( dwErr isnot NO_ERROR )
  5491. {
  5492. DisplayErrorMessage(EMSG_WINS_REGCONNECT_FAILED,
  5493. dwErr);
  5494. }
  5495. else
  5496. {
  5497. dwErr = RegOpenKeyEx(hServer,
  5498. PARAMETER,
  5499. 0,
  5500. KEY_ALL_ACCESS,
  5501. &hParameter);
  5502. if( dwErr isnot NO_ERROR )
  5503. {
  5504. RegCloseKey(hServer);
  5505. hServer = NULL;
  5506. DisplayErrorMessage(EMSG_WINS_REGOPEN_FAILED,
  5507. dwErr);
  5508. }
  5509. else
  5510. {
  5511. DWORD dw = 1;
  5512. dwErr = RegSetValueEx(hParameter,
  5513. WINSCNF_DO_BACKUP_ON_TERM_NM,
  5514. 0,
  5515. REG_DWORD,
  5516. (LPBYTE)&dw,
  5517. sizeof(DWORD));
  5518. if( dwErr isnot NO_ERROR )
  5519. {
  5520. DisplayErrorMessage(EMSG_WINS_REGSETVAL_FAILED,
  5521. dwErr);
  5522. }
  5523. RegCloseKey(hParameter);
  5524. hParameter = NULL;
  5525. RegCloseKey(hServer);
  5526. hServer = NULL;
  5527. }
  5528. }
  5529. }
  5530. if( pdwTypeTags )
  5531. {
  5532. WinsFreeMemory(pdwTypeTags);
  5533. pdwTypeTags = NULL;
  5534. }
  5535. if( pdwNumTags )
  5536. {
  5537. WinsFreeMemory(pdwNumTags);
  5538. pdwNumTags = NULL;
  5539. }
  5540. return Status;
  5541. ErrorReturn:
  5542. DisplayErrorMessage(EMSG_SRVR_INIT_RESTORE,
  5543. Status);
  5544. goto CommonReturn;
  5545. }
  5546. DWORD
  5547. HandleSrvrInitScavenge(
  5548. IN LPCWSTR pwszMachine,
  5549. IN OUT LPWSTR *ppwcArguments,
  5550. IN DWORD dwCurrentIndex,
  5551. IN DWORD dwArgCount,
  5552. IN DWORD dwFlags,
  5553. IN LPCVOID pvData,
  5554. OUT BOOL *pbDone
  5555. )
  5556. /*++
  5557. Routine Description :
  5558. Initiates scavenging of database for the server
  5559. Arguments :
  5560. All aguments are passes as array of wide char strings in ppwcArguments.
  5561. NONE.
  5562. Return Value:
  5563. Returns the status of the operation.
  5564. --*/
  5565. {
  5566. DWORD Status = NO_ERROR;
  5567. struct in_addr InAddr;
  5568. BOOL fIpAddress = TRUE;
  5569. DWORD j = 0;
  5570. WCHAR wcName[256] = {L'\0'};
  5571. DWORD dwLen = 0;
  5572. WINSINTF_ADD_T WinsAdd;
  5573. WINSINTF_RESULTS_T Results;
  5574. WINSINTF_VERS_NO_T MaxVer, MinVer;
  5575. WINSINTF_RECS_T Recs;
  5576. PWINSINTF_RECORD_ACTION_T pRow = NULL;
  5577. Status = WinsDoScavenging( g_hBind );
  5578. if( Status is NO_ERROR )
  5579. {
  5580. DisplayMessage(g_hModule,
  5581. EMSG_WINS_ERROR_SUCCESS);
  5582. }
  5583. else
  5584. {
  5585. DisplayErrorMessage(EMSG_SRVR_INIT_SCAVENGE,
  5586. Status);
  5587. }
  5588. return Status;
  5589. }
  5590. DWORD
  5591. HandleSrvrInitSearch(
  5592. IN LPCWSTR pwszMachine,
  5593. IN OUT LPWSTR *ppwcArguments,
  5594. IN DWORD dwCurrentIndex,
  5595. IN DWORD dwArgCount,
  5596. IN DWORD dwFlags,
  5597. IN LPCVOID pvData,
  5598. OUT BOOL *pbDone
  5599. )
  5600. /*++
  5601. Routine Description :
  5602. Search WINS database based on Name, 16th char, case and optionally stores the result to a file,
  5603. Arguments :
  5604. All aguments are passes as array of wide char strings in ppwcArguments.
  5605. Compulsory : Name to search for
  5606. Optional : 16th char, case sensitive or not and if the result to be stored in a file, then the file
  5607. Name.
  5608. Return Value:
  5609. Returns the status of the operation.
  5610. --*/
  5611. {
  5612. DWORD Status = NO_ERROR;
  5613. DWORD i, j, k, dwNumArgs, dwTagCount;
  5614. TAG_TYPE pttTags[]={
  5615. {WINS_TOKEN_NAME, TRUE, FALSE},
  5616. {WINS_TOKEN_ENDCHAR, FALSE, FALSE},
  5617. {WINS_TOKEN_CASE, FALSE, FALSE},
  5618. {WINS_TOKEN_FILE, FALSE, FALSE},
  5619. };
  5620. PDWORD pdwTagType = NULL,
  5621. pdwTagNum = NULL;
  5622. CHAR chEndChar = (CHAR)0x00;
  5623. BOOL fEndChar = FALSE;
  5624. WCHAR wcName[256+1] = {L'\0'};
  5625. WCHAR wcFile[MAX_PATH] = {L'\0'};
  5626. BOOL fFile = FALSE;
  5627. DWORD dwLen = 0;
  5628. BOOL fIpAddress = TRUE;
  5629. BOOL fMatch = FALSE;
  5630. BOOL fCase = FALSE;
  5631. BOOL fNew = TRUE;
  5632. struct in_addr InAddr;
  5633. LPSTR pszName = NULL;
  5634. WINSINTF_ADD_T WinsAdd;
  5635. WINSINTF_RESULTS_T Results = {0};
  5636. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  5637. WINSINTF_VERS_NO_T MaxVer, MinVer;
  5638. WINSINTF_RECS_T Recs;
  5639. PWINSINTF_RECORD_ACTION_T pRow = NULL;
  5640. i = j = k = dwNumArgs = dwTagCount = 0;
  5641. if( dwArgCount < dwCurrentIndex + 1 )
  5642. {
  5643. DisplayMessage(g_hModule, HLP_SRVR_INIT_SEARCH_EX);
  5644. Status = ERROR_INVALID_PARAMETER;
  5645. goto ErrorReturn;
  5646. }
  5647. dwNumArgs = dwArgCount - dwCurrentIndex;
  5648. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  5649. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  5650. if( pdwTagType is NULL or
  5651. pdwTagNum is NULL )
  5652. {
  5653. Status = ERROR_NOT_ENOUGH_MEMORY;
  5654. goto ErrorReturn;
  5655. }
  5656. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  5657. Status = PreProcessCommand(ppwcArguments,
  5658. dwArgCount,
  5659. dwCurrentIndex,
  5660. pttTags,
  5661. &dwTagCount,
  5662. pdwTagType,
  5663. pdwTagNum);
  5664. if( Status isnot NO_ERROR )
  5665. goto ErrorReturn;
  5666. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  5667. {
  5668. if( pttTags[i].dwRequired is TRUE and
  5669. pttTags[i].bPresent is FALSE
  5670. )
  5671. {
  5672. Status = ERROR_INVALID_PARAMETER;
  5673. goto ErrorReturn;
  5674. }
  5675. }
  5676. for( j=0; j<dwTagCount; j++)
  5677. {
  5678. switch(pdwTagType[j])
  5679. {
  5680. case 0:
  5681. {
  5682. DWORD dwLen = 0;
  5683. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  5684. if( dwLen is 0 )
  5685. {
  5686. Status = ERROR_INVALID_PARAMETER;
  5687. goto ErrorReturn;
  5688. }
  5689. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  5690. memcpy(wcName,
  5691. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  5692. dwLen*sizeof(WCHAR));
  5693. wcName[dwLen] = L'\0';
  5694. fIpAddress = FALSE;
  5695. break;
  5696. }
  5697. case 1:
  5698. {
  5699. DWORD dwLen = 0, k=0;
  5700. fEndChar = TRUE;
  5701. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  5702. if( dwLen > 2 )
  5703. {
  5704. Status = ERROR_INVALID_PARAMETER;
  5705. goto ErrorReturn;
  5706. }
  5707. for( k=0; k<dwLen; k++ )
  5708. {
  5709. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  5710. if( towlower(wc) >= L'a' and
  5711. towlower(wc) <= L'z' )
  5712. {
  5713. if( towlower(wc) > L'f' )
  5714. {
  5715. Status = ERROR_INVALID_PARAMETER;
  5716. goto ErrorReturn;
  5717. }
  5718. }
  5719. }
  5720. chEndChar = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  5721. break;
  5722. }
  5723. case 2:
  5724. {
  5725. DWORD dw = 0;
  5726. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  5727. {
  5728. Status = ERROR_INVALID_PARAMETER;
  5729. goto ErrorReturn;
  5730. }
  5731. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  5732. if( dw is 0 )
  5733. {
  5734. fCase = FALSE;
  5735. break;
  5736. }
  5737. if( dw is 1 )
  5738. {
  5739. fCase = TRUE;
  5740. break;
  5741. }
  5742. else
  5743. {
  5744. Status = ERROR_INVALID_PARAMETER;
  5745. goto ErrorReturn;
  5746. }
  5747. }
  5748. case 3:
  5749. {
  5750. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  5751. if( dwLen is 0 )
  5752. {
  5753. wcscpy(wcFile, L"wins.rec");
  5754. fFile = TRUE;
  5755. break;
  5756. }
  5757. wcscpy(wcFile, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  5758. fFile = TRUE;
  5759. break;
  5760. }
  5761. default:
  5762. {
  5763. Status = ERROR_INVALID_PARAMETER;
  5764. goto ErrorReturn;
  5765. }
  5766. }
  5767. }
  5768. pszName = WinsUnicodeToOem(wcName, NULL);
  5769. if( pszName is NULL )
  5770. {
  5771. Status = ERROR_NOT_ENOUGH_MEMORY;
  5772. goto ErrorReturn;
  5773. }
  5774. dwLen = strlen(pszName);
  5775. if( dwLen >= 16 )
  5776. {
  5777. DisplayMessage(g_hModule,
  5778. EMSG_SRVR_INVALID_NETBIOS_NAME);
  5779. Status = ERROR_INVALID_PARAMETER;
  5780. goto ErrorReturn;
  5781. }
  5782. if( fEndChar )
  5783. {
  5784. LPSTR pTemp = pszName;
  5785. pszName = WinsAllocateMemory(17);
  5786. if( pszName is NULL )
  5787. {
  5788. Status = ERROR_NOT_ENOUGH_MEMORY;
  5789. goto ErrorReturn;
  5790. }
  5791. memcpy(pszName, pTemp, 15);
  5792. for( i=strlen(pszName); i<16; i++ )
  5793. {
  5794. pszName[i] = ' ';
  5795. }
  5796. pszName[15] = chEndChar;
  5797. pszName[16] = '\0';
  5798. WinsFreeMemory(pTemp);
  5799. pTemp = NULL;
  5800. dwLen = 16;
  5801. }
  5802. ResultsN.WinsStat.NoOfPnrs = 0;
  5803. ResultsN.WinsStat.pRplPnrs = 0;
  5804. ResultsN.NoOfWorkerThds = 1;
  5805. ResultsN.pAddVersMaps = NULL;
  5806. Status = WinsStatusNew(g_hBind, WINSINTF_E_CONFIG_ALL_MAPS, &ResultsN);
  5807. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  5808. {
  5809. //Try old API
  5810. Results.WinsStat.NoOfPnrs = 0;
  5811. Results.WinsStat.pRplPnrs = 0;
  5812. Status = WinsStatus(g_hBind, WINSINTF_E_CONFIG_ALL_MAPS, &Results);
  5813. fNew = FALSE;
  5814. }
  5815. if( Status isnot NO_ERROR )
  5816. goto ErrorReturn;
  5817. g_dwSearchCount = 0;
  5818. g_fHeader = FALSE;
  5819. if( fNew is FALSE )
  5820. {
  5821. if( Results.NoOfOwners is 0 )
  5822. goto CommonReturn;
  5823. for( j=0; j<Results.NoOfOwners; j++)
  5824. {
  5825. WinsAdd.Len = 4;
  5826. WinsAdd.Type = 0;
  5827. WinsAdd.IPAdd = Results.AddVersMaps[j].Add.IPAdd;
  5828. if( WinsAdd.IPAdd is 0 )
  5829. continue;
  5830. DisplayMessage(g_hModule,
  5831. MSG_WINS_SEARCHING_STATUS,
  5832. IpAddressToString(Results.AddVersMaps[j].Add.IPAdd));
  5833. InAddr.s_addr = htonl(Results.AddVersMaps[j].Add.IPAdd);
  5834. MaxVer = Results.AddVersMaps[j].VersNo;
  5835. MinVer.HighPart = 0;
  5836. MinVer.LowPart = 0;
  5837. Status = GetDbRecs(MinVer,
  5838. MaxVer,
  5839. &WinsAdd,
  5840. inet_ntoa(InAddr),
  5841. fIpAddress ? FALSE : TRUE,
  5842. pszName,
  5843. dwLen,
  5844. FALSE,
  5845. 0,
  5846. FALSE,
  5847. fCase,
  5848. fFile,
  5849. fFile ? wcFile : NULL);
  5850. if(Status isnot NO_ERROR )
  5851. {
  5852. if( Results.WinsStat.pRplPnrs)
  5853. {
  5854. WinsFreeMem(Results.WinsStat.pRplPnrs);
  5855. Results.WinsStat.pRplPnrs = NULL;
  5856. }
  5857. goto ErrorReturn;
  5858. }
  5859. }
  5860. if( Results.WinsStat.pRplPnrs)
  5861. {
  5862. WinsFreeMem(Results.WinsStat.pRplPnrs);
  5863. Results.WinsStat.pRplPnrs = NULL;
  5864. }
  5865. if( Status isnot NO_ERROR )
  5866. goto ErrorReturn;
  5867. }
  5868. else
  5869. {
  5870. if( ResultsN.NoOfOwners is 0 )
  5871. goto CommonReturn;
  5872. for( j=0; j<ResultsN.NoOfOwners; j++)
  5873. {
  5874. WinsAdd.Len = 4;
  5875. WinsAdd.Type = 0;
  5876. WinsAdd.IPAdd = ResultsN.pAddVersMaps[j].Add.IPAdd;
  5877. if( WinsAdd.IPAdd is 0 )
  5878. continue;
  5879. DisplayMessage(g_hModule,
  5880. MSG_WINS_SEARCHING_STATUS,
  5881. IpAddressToString(ResultsN.pAddVersMaps[j].Add.IPAdd));
  5882. InAddr.s_addr = htonl(ResultsN.pAddVersMaps[j].Add.IPAdd);
  5883. MaxVer = ResultsN.pAddVersMaps[j].VersNo;
  5884. MinVer.HighPart = 0;
  5885. MinVer.LowPart = 0;
  5886. Status = GetDbRecs(MinVer,
  5887. MaxVer,
  5888. &WinsAdd,
  5889. inet_ntoa(InAddr),
  5890. fIpAddress ? FALSE : TRUE,
  5891. pszName,
  5892. dwLen,
  5893. FALSE,
  5894. 0,
  5895. FALSE,
  5896. fCase,
  5897. fFile,
  5898. fFile ? wcFile : NULL);
  5899. if(Status isnot NO_ERROR )
  5900. {
  5901. if( ResultsN.WinsStat.pRplPnrs)
  5902. {
  5903. WinsFreeMem(ResultsN.WinsStat.pRplPnrs);
  5904. ResultsN.WinsStat.pRplPnrs = NULL;
  5905. }
  5906. goto ErrorReturn;
  5907. }
  5908. }
  5909. if( ResultsN.WinsStat.pRplPnrs)
  5910. {
  5911. WinsFreeMem(ResultsN.WinsStat.pRplPnrs);
  5912. ResultsN.WinsStat.pRplPnrs = NULL;
  5913. }
  5914. if( Status isnot NO_ERROR )
  5915. goto ErrorReturn;
  5916. }
  5917. if( pszName )
  5918. {
  5919. WinsFreeMemory(pszName);
  5920. pszName = NULL;
  5921. }
  5922. DisplayMessage(g_hModule,
  5923. MSG_SRVR_SEARCH_COUNT,
  5924. g_dwSearchCount);
  5925. if( fFile )
  5926. {
  5927. FILE * pFile = _wfopen(wcFile, L"a+");
  5928. if( pFile isnot NULL )
  5929. {
  5930. DumpMessage(g_hModule,
  5931. pFile,
  5932. MSG_SRVR_SEARCH_COUNT,
  5933. g_dwSearchCount);
  5934. fclose(pFile);
  5935. pFile = NULL;
  5936. }
  5937. }
  5938. CommonReturn:
  5939. if( Status is NO_ERROR )
  5940. {
  5941. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  5942. }
  5943. if( pszName )
  5944. {
  5945. WinsFreeMemory(pszName);
  5946. pszName = NULL;
  5947. }
  5948. if( pdwTagType )
  5949. {
  5950. WinsFreeMemory(pdwTagType);
  5951. pdwTagType = NULL;
  5952. }
  5953. if( pdwTagNum )
  5954. {
  5955. WinsFreeMemory(pdwTagNum);
  5956. pdwTagNum = NULL;
  5957. }
  5958. g_dwSearchCount = 0;
  5959. g_fHeader = FALSE;
  5960. return Status;
  5961. ErrorReturn:
  5962. DisplayErrorMessage(EMSG_SRVR_INIT_SEARCH,
  5963. Status);
  5964. goto CommonReturn;
  5965. }
  5966. DWORD
  5967. HandleSrvrResetCounter(
  5968. IN LPCWSTR pwszMachine,
  5969. IN OUT LPWSTR *ppwcArguments,
  5970. IN DWORD dwCurrentIndex,
  5971. IN DWORD dwArgCount,
  5972. IN DWORD dwFlags,
  5973. IN LPCVOID pvData,
  5974. OUT BOOL *pbDone
  5975. )
  5976. /*++
  5977. Routine Description :
  5978. Resets the version counter
  5979. Arguments :
  5980. All aguments are passes as array of wide char strings in ppwcArguments.
  5981. NONE.
  5982. Return Value:
  5983. Returns the status of the operation.
  5984. --*/
  5985. {
  5986. DWORD Status = NO_ERROR;
  5987. Status = WinsResetCounters( g_hBind );
  5988. if( Status is NO_ERROR )
  5989. {
  5990. DisplayMessage(g_hModule,
  5991. EMSG_WINS_ERROR_SUCCESS);
  5992. }
  5993. else
  5994. {
  5995. DisplayErrorMessage(EMSG_SRVR_INIT_BACKUP,
  5996. Status);
  5997. }
  5998. return Status;
  5999. }
  6000. DWORD
  6001. HandleSrvrSetAutopartnerconfig(
  6002. IN LPCWSTR pwszMachine,
  6003. IN OUT LPWSTR *ppwcArguments,
  6004. IN DWORD dwCurrentIndex,
  6005. IN DWORD dwArgCount,
  6006. IN DWORD dwFlags,
  6007. IN LPCVOID pvData,
  6008. OUT BOOL *pbDone
  6009. )
  6010. /*++
  6011. Routine Description :
  6012. Sets automatic partner configuration parameters.
  6013. Arguments :
  6014. All aguments are passes as array of wide char strings in ppwcArguments.
  6015. Compulsory : State to set or disable
  6016. Optional : Time Interval or TTL value
  6017. Return Value:
  6018. Returns the status of the operation.
  6019. --*/
  6020. {
  6021. DWORD Status = NO_ERROR;
  6022. DWORD i, j, dwNumArgs, dwTagCount;
  6023. PDWORD pdwTagType = NULL,
  6024. pdwTagNum = NULL;
  6025. LPWSTR pTemp = NULL;
  6026. TAG_TYPE pttTags[] = {
  6027. {WINS_TOKEN_STATE, TRUE, FALSE},
  6028. {WINS_TOKEN_INTERVAL, FALSE, FALSE},
  6029. {WINS_TOKEN_TTL, FALSE, FALSE},
  6030. };
  6031. DWORD dwInterval = WINSCNF_DEF_MCAST_INTVL;
  6032. DWORD dwTTL = WINSCNF_DEF_MCAST_TTL;
  6033. BOOL fState = FALSE,
  6034. fTTL = FALSE,
  6035. fInterval = FALSE;
  6036. HKEY hServer = NULL,
  6037. hParameter = NULL;
  6038. if( dwArgCount < dwCurrentIndex + 1 )
  6039. {
  6040. DisplayMessage(g_hModule, HLP_SRVR_SET_AUTOPARTNERCONFIG_EX);
  6041. Status = ERROR_INVALID_PARAMETER;
  6042. goto ErrorReturn;
  6043. }
  6044. {
  6045. dwNumArgs = dwArgCount - dwCurrentIndex;
  6046. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6047. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6048. if( pdwTagType is NULL or
  6049. pdwTagNum is NULL )
  6050. {
  6051. Status = ERROR_NOT_ENOUGH_MEMORY;
  6052. goto ErrorReturn;
  6053. }
  6054. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  6055. Status = PreProcessCommand(ppwcArguments,
  6056. dwArgCount,
  6057. dwCurrentIndex,
  6058. pttTags,
  6059. &dwTagCount,
  6060. pdwTagType,
  6061. pdwTagNum);
  6062. if( Status isnot NO_ERROR )
  6063. goto ErrorReturn;
  6064. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  6065. {
  6066. if( pttTags[i].dwRequired is TRUE and
  6067. pttTags[i].bPresent is FALSE
  6068. )
  6069. {
  6070. Status = ERROR_INVALID_PARAMETER;
  6071. goto ErrorReturn;
  6072. }
  6073. }
  6074. for( j=0; j<dwTagCount; j++ )
  6075. {
  6076. switch(pdwTagType[j])
  6077. {
  6078. case 0:
  6079. {
  6080. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  6081. if( wc is L'1' )
  6082. {
  6083. fState = TRUE;
  6084. }
  6085. else if( wc is L'0' )
  6086. {
  6087. fState = FALSE;
  6088. }
  6089. else
  6090. {
  6091. Status = ERROR_INVALID_PARAMETER;
  6092. goto ErrorReturn;
  6093. }
  6094. break;
  6095. }
  6096. case 1:
  6097. {
  6098. DWORD dw = 0;
  6099. fInterval = TRUE;
  6100. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  6101. break;
  6102. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  6103. {
  6104. Status = ERROR_INVALID_PARAMETER;
  6105. goto ErrorReturn;
  6106. }
  6107. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  6108. if( dw >= ONEDAY )
  6109. {
  6110. Status = ERROR_INVALID_PARAMETER;
  6111. goto ErrorReturn;
  6112. }
  6113. dwInterval = dw;
  6114. break;
  6115. }
  6116. case 2:
  6117. {
  6118. DWORD dw = 0;
  6119. fTTL = TRUE;
  6120. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  6121. break;
  6122. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  6123. {
  6124. Status = ERROR_INVALID_PARAMETER;
  6125. goto ErrorReturn;
  6126. }
  6127. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  6128. if( dw > 32 )
  6129. {
  6130. Status = ERROR_INVALID_PARAMETER;
  6131. goto ErrorReturn;
  6132. }
  6133. if( dw <= 0 )
  6134. {
  6135. Status = ERROR_INVALID_PARAMETER;
  6136. goto ErrorReturn;
  6137. }
  6138. dwTTL = dw;
  6139. break;
  6140. }
  6141. default:
  6142. {
  6143. Status = ERROR_INVALID_PARAMETER;
  6144. goto ErrorReturn;
  6145. }
  6146. }
  6147. }
  6148. }
  6149. {
  6150. if( wcslen(g_ServerNetBiosName) > 0 )
  6151. {
  6152. pTemp = g_ServerNetBiosName;
  6153. }
  6154. Status = RegConnectRegistry(pTemp,
  6155. HKEY_LOCAL_MACHINE,
  6156. &hServer);
  6157. if( Status isnot NO_ERROR )
  6158. goto ErrorReturn;
  6159. Status = RegOpenKeyEx(hServer,
  6160. PARAMETER,
  6161. 0,
  6162. KEY_ALL_ACCESS,
  6163. &hParameter);
  6164. if( Status isnot NO_ERROR )
  6165. goto ErrorReturn;
  6166. Status = RegSetValueEx(hParameter,
  6167. WINSCNF_USE_SELF_FND_PNRS_NM,
  6168. 0,
  6169. REG_DWORD,
  6170. (LPBYTE)&fState,
  6171. sizeof(BOOL));
  6172. if( Status isnot NO_ERROR )
  6173. goto ErrorReturn;
  6174. if( fInterval )
  6175. {
  6176. Status = RegSetValueEx(hParameter,
  6177. WINSCNF_MCAST_INTVL_NM,
  6178. 0,
  6179. REG_DWORD,
  6180. (LPBYTE)&dwInterval,
  6181. sizeof(DWORD));
  6182. if( Status isnot NO_ERROR )
  6183. goto ErrorReturn;
  6184. }
  6185. if( fTTL )
  6186. {
  6187. Status = RegSetValueEx(hParameter,
  6188. WINSCNF_MCAST_TTL_NM,
  6189. 0,
  6190. REG_DWORD,
  6191. (LPBYTE)&dwTTL,
  6192. sizeof(DWORD));
  6193. if( Status isnot NO_ERROR )
  6194. goto ErrorReturn;
  6195. }
  6196. }
  6197. CommonReturn:
  6198. if( Status is NO_ERROR )
  6199. {
  6200. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  6201. }
  6202. if( hParameter )
  6203. {
  6204. RegCloseKey(hParameter);
  6205. hParameter = NULL;
  6206. }
  6207. if( hServer )
  6208. {
  6209. RegCloseKey(hServer);
  6210. hServer = NULL;
  6211. }
  6212. if( pdwTagType )
  6213. {
  6214. WinsFreeMemory(pdwTagType);
  6215. pdwTagType = NULL;
  6216. }
  6217. if( pdwTagNum )
  6218. {
  6219. WinsFreeMemory(pdwTagNum);
  6220. pdwTagNum = NULL;
  6221. }
  6222. return Status;
  6223. ErrorReturn:
  6224. DisplayErrorMessage(EMSG_SRVR_SET_AUTOPARTNERCONFIG,
  6225. Status);
  6226. goto CommonReturn;
  6227. }
  6228. DWORD
  6229. HandleSrvrSetBackuppath(
  6230. IN LPCWSTR pwszMachine,
  6231. IN OUT LPWSTR *ppwcArguments,
  6232. IN DWORD dwCurrentIndex,
  6233. IN DWORD dwArgCount,
  6234. IN DWORD dwFlags,
  6235. IN LPCVOID pvData,
  6236. OUT BOOL *pbDone
  6237. )
  6238. /*++
  6239. Routine Description :
  6240. Sets the backup path for the WINS database
  6241. Arguments :
  6242. All aguments are passes as array of wide char strings in ppwcArguments.
  6243. Compulsory : Backup dir
  6244. Optional : Enable backup at server shutdown.
  6245. Return Value:
  6246. Returns the status of the operation.
  6247. --*/
  6248. {
  6249. DWORD Status = NO_ERROR;
  6250. DWORD i, j, dwNumArgs, dwTagCount;
  6251. PDWORD pdwTagType = NULL,
  6252. pdwTagNum = NULL;
  6253. TAG_TYPE pttTags[] = {
  6254. {WINS_TOKEN_DIR, FALSE, FALSE},
  6255. {WINS_TOKEN_ATSHUTDOWN, FALSE, FALSE},
  6256. };
  6257. LPWSTR pwszDir = L"C:\\\\";
  6258. BOOL fDir = FALSE;
  6259. BOOL fAtShutDown = FALSE;
  6260. LPWSTR pTemp = NULL;
  6261. HKEY hServer = NULL,
  6262. hParameter = NULL;
  6263. if( dwArgCount < dwCurrentIndex + 1 )
  6264. {
  6265. DisplayMessage(g_hModule, HLP_SRVR_SET_BACKUPPATH_EX);
  6266. Status = ERROR_INVALID_PARAMETER;
  6267. goto ErrorReturn;
  6268. }
  6269. dwNumArgs = dwArgCount - dwCurrentIndex;
  6270. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6271. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6272. if( pdwTagType is NULL or
  6273. pdwTagNum is NULL )
  6274. {
  6275. Status = ERROR_NOT_ENOUGH_MEMORY;
  6276. goto ErrorReturn;
  6277. }
  6278. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  6279. Status = PreProcessCommand(ppwcArguments,
  6280. dwArgCount,
  6281. dwCurrentIndex,
  6282. pttTags,
  6283. &dwTagCount,
  6284. pdwTagType,
  6285. pdwTagNum);
  6286. if( Status isnot NO_ERROR )
  6287. goto ErrorReturn;
  6288. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  6289. {
  6290. if( pttTags[i].dwRequired is TRUE and
  6291. pttTags[i].bPresent is FALSE
  6292. )
  6293. {
  6294. Status = ERROR_INVALID_PARAMETER;
  6295. goto ErrorReturn;
  6296. }
  6297. }
  6298. for( j=0; j<dwTagCount; j++ )
  6299. {
  6300. switch(pdwTagType[j])
  6301. {
  6302. case 0:
  6303. {
  6304. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 0 )
  6305. {
  6306. pwszDir = ppwcArguments[dwCurrentIndex+pdwTagNum[j]];
  6307. }
  6308. else
  6309. {
  6310. pwszDir = L"";
  6311. }
  6312. fDir = TRUE;
  6313. break;
  6314. }
  6315. case 1:
  6316. {
  6317. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  6318. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  6319. {
  6320. Status = ERROR_INVALID_PARAMETER;
  6321. goto ErrorReturn;
  6322. }
  6323. if( wc is L'0' )
  6324. fAtShutDown = FALSE;
  6325. else if( wc is L'1' )
  6326. fAtShutDown = TRUE;
  6327. else
  6328. {
  6329. Status = ERROR_INVALID_PARAMETER;
  6330. goto ErrorReturn;
  6331. }
  6332. break;
  6333. }
  6334. default:
  6335. {
  6336. Status = ERROR_INVALID_PARAMETER;
  6337. goto ErrorReturn;
  6338. }
  6339. }
  6340. }
  6341. if( wcslen(g_ServerNetBiosName) > 0 )
  6342. {
  6343. pTemp = g_ServerNetBiosName;
  6344. }
  6345. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  6346. if( Status isnot NO_ERROR )
  6347. goto ErrorReturn;
  6348. Status = RegCreateKeyEx(hServer,
  6349. PARAMETER,
  6350. 0,
  6351. NULL,
  6352. REG_OPTION_NON_VOLATILE,
  6353. KEY_ALL_ACCESS,
  6354. NULL,
  6355. &hParameter,
  6356. NULL);
  6357. if( Status isnot NO_ERROR )
  6358. goto ErrorReturn;
  6359. if( fDir )
  6360. {
  6361. Status = RegSetValueEx(hParameter,
  6362. WINSCNF_BACKUP_DIR_PATH_NM,
  6363. 0,
  6364. REG_EXPAND_SZ,
  6365. (LPBYTE)pwszDir,
  6366. (wcslen(pwszDir)+1)*sizeof(WCHAR));
  6367. if( Status isnot NO_ERROR )
  6368. {
  6369. goto ErrorReturn;
  6370. }
  6371. }
  6372. Status = RegSetValueEx(hParameter,
  6373. WINSCNF_DO_BACKUP_ON_TERM_NM,
  6374. 0,
  6375. REG_DWORD,
  6376. (LPBYTE)&fAtShutDown,
  6377. sizeof(BOOL));
  6378. if( Status isnot NO_ERROR )
  6379. goto ErrorReturn;
  6380. CommonReturn:
  6381. if( Status is NO_ERROR )
  6382. {
  6383. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  6384. }
  6385. if( hParameter )
  6386. {
  6387. RegCloseKey(hParameter);
  6388. hParameter = NULL;
  6389. }
  6390. if( hServer )
  6391. {
  6392. RegCloseKey(hServer);
  6393. hServer = NULL;
  6394. }
  6395. if( pdwTagType )
  6396. {
  6397. WinsFreeMemory(pdwTagType);
  6398. pdwTagType = NULL;
  6399. }
  6400. if( pdwTagNum )
  6401. {
  6402. WinsFreeMemory(pdwTagNum);
  6403. pdwTagNum = NULL;
  6404. }
  6405. return Status;
  6406. ErrorReturn:
  6407. DisplayErrorMessage(EMSG_SRVR_SET_BACKUPPATH,
  6408. Status);
  6409. goto CommonReturn;
  6410. }
  6411. DWORD
  6412. HandleSrvrSetDefaultparam(
  6413. IN LPCWSTR pwszMachine,
  6414. IN OUT LPWSTR *ppwcArguments,
  6415. IN DWORD dwCurrentIndex,
  6416. IN DWORD dwArgCount,
  6417. IN DWORD dwFlags,
  6418. IN LPCVOID pvData,
  6419. OUT BOOL *pbDone
  6420. )
  6421. /*++
  6422. Routine Description :
  6423. Sets the default values for all the configuration parameter. This command
  6424. must be run at least once before running the dump command.
  6425. Arguments :
  6426. All aguments are passes as array of wide char strings in ppwcArguments.
  6427. NONE.
  6428. Return Value:
  6429. Returns the status of the operation.
  6430. --*/
  6431. {
  6432. DWORD Status = NO_ERROR;
  6433. HKEY hServer = NULL,
  6434. hWins = NULL,
  6435. hParameter = NULL,
  6436. hDefault = NULL,
  6437. hDefaultPull = NULL,
  6438. hDefaultPush = NULL,
  6439. hPartner = NULL,
  6440. hCheck = NULL,
  6441. hPullPart = NULL,
  6442. hPushPart = NULL;
  6443. DWORD dwSize = 0,
  6444. dwType = 0,
  6445. dwData = 0;
  6446. LPWSTR pTemp = NULL;
  6447. if( wcslen(g_ServerNetBiosName) > 2 )
  6448. pTemp = g_ServerNetBiosName;
  6449. Status = RegConnectRegistry(pTemp,
  6450. HKEY_LOCAL_MACHINE,
  6451. &hServer);
  6452. if( Status isnot NO_ERROR )
  6453. {
  6454. goto RETURN;
  6455. }
  6456. //Open all required Registry key handles
  6457. Status = RegCreateKeyEx(hServer,
  6458. PARAMETER,
  6459. 0,
  6460. NULL,
  6461. REG_OPTION_NON_VOLATILE,
  6462. KEY_ALL_ACCESS,
  6463. NULL,
  6464. &hParameter,
  6465. NULL);
  6466. if( Status isnot NO_ERROR )
  6467. goto RETURN;
  6468. Status = RegCreateKeyEx(hServer,
  6469. PARTNERROOT,
  6470. 0,
  6471. NULL,
  6472. REG_OPTION_NON_VOLATILE,
  6473. KEY_ALL_ACCESS,
  6474. NULL,
  6475. &hPartner,
  6476. NULL);
  6477. if( Status isnot NO_ERROR )
  6478. goto RETURN;
  6479. Status = RegCreateKeyEx(hServer,
  6480. PULLROOT,
  6481. 0,
  6482. NULL,
  6483. REG_OPTION_NON_VOLATILE,
  6484. KEY_ALL_ACCESS,
  6485. NULL,
  6486. &hPullPart,
  6487. NULL);
  6488. if( Status isnot NO_ERROR )
  6489. goto RETURN;
  6490. Status = RegCreateKeyEx(hServer,
  6491. PUSHROOT,
  6492. 0,
  6493. NULL,
  6494. REG_OPTION_NON_VOLATILE,
  6495. KEY_ALL_ACCESS,
  6496. NULL,
  6497. &hPushPart,
  6498. NULL);
  6499. if( Status isnot NO_ERROR )
  6500. goto RETURN;
  6501. Status = RegCreateKeyEx(hServer,
  6502. DEFAULTPULL,
  6503. 0,
  6504. NULL,
  6505. REG_OPTION_NON_VOLATILE,
  6506. KEY_ALL_ACCESS,
  6507. NULL,
  6508. &hDefaultPull,
  6509. NULL);
  6510. if( Status isnot NO_ERROR )
  6511. goto RETURN;
  6512. Status = RegCreateKeyEx(hServer,
  6513. DEFAULTPUSH,
  6514. 0,
  6515. NULL,
  6516. REG_OPTION_NON_VOLATILE,
  6517. KEY_ALL_ACCESS,
  6518. NULL,
  6519. &hDefaultPush,
  6520. NULL);
  6521. if( Status isnot NO_ERROR )
  6522. goto RETURN;
  6523. //Start setting the default values.
  6524. Status = RegSetValueEx(hParameter,
  6525. WINSCNF_BACKUP_DIR_PATH_NM,
  6526. 0,
  6527. REG_EXPAND_SZ,
  6528. (LPBYTE)L"",
  6529. (wcslen(L"")+1)*sizeof(WCHAR));
  6530. if( Status isnot NO_ERROR )
  6531. goto RETURN;
  6532. dwData = 0;
  6533. Status = RegSetValueEx(hParameter,
  6534. WINSCNF_DO_BACKUP_ON_TERM_NM,
  6535. 0,
  6536. REG_DWORD,
  6537. (LPBYTE)&dwData,
  6538. sizeof(DWORD));
  6539. if( Status isnot NO_ERROR )
  6540. goto RETURN;
  6541. dwData = 0x7e900;
  6542. Status = RegSetValueEx(hParameter,
  6543. WINSCNF_REFRESH_INTVL_NM,
  6544. 0,
  6545. REG_DWORD,
  6546. (LPBYTE)&dwData,
  6547. sizeof(DWORD));
  6548. if( Status isnot NO_ERROR )
  6549. goto RETURN;
  6550. dwData = 0x54600;
  6551. Status = RegSetValueEx(hParameter,
  6552. WINSCNF_TOMBSTONE_INTVL_NM,
  6553. 0,
  6554. REG_DWORD,
  6555. (LPBYTE)&dwData,
  6556. sizeof(DWORD));
  6557. if( Status isnot NO_ERROR )
  6558. goto RETURN;
  6559. dwData = 0x7e900;
  6560. Status = RegSetValueEx(hParameter,
  6561. WINSCNF_TOMBSTONE_TMOUT_NM,
  6562. 0,
  6563. REG_DWORD,
  6564. (LPBYTE)&dwData,
  6565. sizeof(DWORD));
  6566. if( Status isnot NO_ERROR )
  6567. goto RETURN;
  6568. dwData = 0x1fa400;
  6569. Status = RegSetValueEx(hParameter,
  6570. WINSCNF_VERIFY_INTVL_NM,
  6571. 0,
  6572. REG_DWORD,
  6573. (LPBYTE)&dwData,
  6574. sizeof(DWORD));
  6575. if( Status isnot NO_ERROR )
  6576. goto RETURN;
  6577. dwData = 1;
  6578. Status = RegSetValueEx(hParameter,
  6579. WINSCNF_BURST_HANDLING_NM,
  6580. 0,
  6581. REG_DWORD,
  6582. (LPBYTE)&dwData,
  6583. sizeof(DWORD));
  6584. if( Status isnot NO_ERROR )
  6585. goto RETURN;
  6586. dwData = 0x1f4;
  6587. Status = RegSetValueEx(hParameter,
  6588. WINSCNF_BURST_QUE_SIZE_NM,
  6589. 0,
  6590. REG_DWORD,
  6591. (LPBYTE)&dwData,
  6592. sizeof(DWORD));
  6593. if( Status isnot NO_ERROR )
  6594. goto RETURN;
  6595. dwData = 0;
  6596. Status = RegSetValueEx(hParameter,
  6597. WINSCNF_LOG_DETAILED_EVTS_NM,
  6598. 0,
  6599. REG_DWORD,
  6600. (LPBYTE)&dwData,
  6601. sizeof(DWORD));
  6602. if( Status isnot NO_ERROR )
  6603. goto RETURN;
  6604. dwData = 1;
  6605. Status = RegSetValueEx(hParameter,
  6606. WINSCNF_LOG_FLAG_NM,
  6607. 0,
  6608. REG_DWORD,
  6609. (LPBYTE)&dwData,
  6610. sizeof(DWORD));
  6611. if( Status isnot NO_ERROR )
  6612. goto RETURN;
  6613. Status = RegSetValueEx(hParameter,
  6614. WINSCNF_LOG_FILE_PATH_NM,
  6615. 0,
  6616. REG_EXPAND_SZ,
  6617. (LPBYTE)L"%windir%\\system32\\wins",
  6618. (wcslen(L"%windir%\\system32\\wins")+1)*sizeof(WCHAR));
  6619. if( Status isnot NO_ERROR )
  6620. goto RETURN;
  6621. dwData = 0;
  6622. Status = RegSetValueEx(hParameter,
  6623. WINSCNF_USE_SELF_FND_PNRS_NM,
  6624. 0,
  6625. REG_DWORD,
  6626. (LPBYTE)&dwData,
  6627. sizeof(DWORD));
  6628. if( Status isnot NO_ERROR )
  6629. goto RETURN;
  6630. dwData = 0;
  6631. Status = RegSetValueEx(hParameter,
  6632. WINSCNF_MIGRATION_ON_NM,
  6633. 0,
  6634. REG_DWORD,
  6635. (LPBYTE)&dwData,
  6636. sizeof(DWORD));
  6637. if( Status isnot NO_ERROR )
  6638. goto RETURN;
  6639. dwData = 0x1;
  6640. Status = RegSetValueEx(hParameter,
  6641. WINSCNF_RPL_ONLY_W_CNF_PNRS_NM,
  6642. 0,
  6643. REG_DWORD,
  6644. (LPBYTE)&dwData,
  6645. sizeof(DWORD));
  6646. if( Status isnot NO_ERROR )
  6647. goto RETURN;
  6648. Status = RegSetValueEx(hParameter,
  6649. WINSCNF_DB_FILE_NM,
  6650. 0,
  6651. REG_EXPAND_SZ,
  6652. (LPBYTE)L"%windir%\\system32\\wins\\wins.mdb",
  6653. (wcslen(L"%windir%\\system32\\wins\\wins.mdb")+1)*sizeof(WCHAR));
  6654. if( Status isnot NO_ERROR )
  6655. goto RETURN;
  6656. dwData = 2;
  6657. Status = RegSetValueEx(hParameter,
  6658. WINSCNF_MCAST_TTL_NM,
  6659. 0,
  6660. REG_DWORD,
  6661. (LPBYTE)&dwData,
  6662. sizeof(DWORD));
  6663. if( Status isnot NO_ERROR )
  6664. goto RETURN;
  6665. dwData = 0x960;
  6666. Status = RegSetValueEx(hParameter,
  6667. WINSCNF_MCAST_INTVL_NM,
  6668. 0,
  6669. REG_DWORD,
  6670. (LPBYTE)&dwData,
  6671. sizeof(DWORD));
  6672. if( Status isnot NO_ERROR )
  6673. goto RETURN;
  6674. dwData = 0;
  6675. Status = RegSetValueEx(hParameter,
  6676. WINSCNF_INIT_VERSNO_VAL_HW_NM,
  6677. 0,
  6678. REG_DWORD,
  6679. (LPBYTE)&dwData,
  6680. sizeof(DWORD));
  6681. if( Status isnot NO_ERROR )
  6682. goto RETURN;
  6683. dwData = 0;
  6684. Status = RegSetValueEx(hParameter,
  6685. WINSCNF_INIT_VERSNO_VAL_LW_NM,
  6686. 0,
  6687. REG_DWORD,
  6688. (LPBYTE)&dwData,
  6689. sizeof(DWORD));
  6690. if( Status isnot NO_ERROR )
  6691. goto RETURN;
  6692. dwData = 0x708;
  6693. Status = RegSetValueEx(hDefaultPull,
  6694. WINSCNF_RPL_INTERVAL_NM,
  6695. 0,
  6696. REG_DWORD,
  6697. (LPBYTE)&dwData,
  6698. sizeof(DWORD));
  6699. if( Status isnot NO_ERROR )
  6700. goto RETURN;
  6701. dwData = 0;
  6702. Status = RegSetValueEx(hDefaultPush,
  6703. WINSCNF_UPDATE_COUNT_NM,
  6704. 0,
  6705. REG_DWORD,
  6706. (LPBYTE)&dwData,
  6707. sizeof(DWORD));
  6708. if( Status isnot NO_ERROR )
  6709. goto RETURN;
  6710. dwData = 0x3;
  6711. Status = RegSetValueEx(hPullPart,
  6712. WINSCNF_RETRY_COUNT_NM,
  6713. 0,
  6714. REG_DWORD,
  6715. (LPBYTE)&dwData,
  6716. sizeof(DWORD));
  6717. if( Status isnot NO_ERROR )
  6718. goto RETURN;
  6719. dwData = 0x1;
  6720. Status = RegSetValueEx(hPullPart,
  6721. WINSCNF_INIT_TIME_RPL_NM,
  6722. 0,
  6723. REG_DWORD,
  6724. (LPBYTE)&dwData,
  6725. sizeof(DWORD));
  6726. if( Status isnot NO_ERROR )
  6727. goto RETURN;
  6728. dwData = 0x1;
  6729. Status = RegSetValueEx(hPullPart,
  6730. WINSCNF_PRS_CONN_NM,
  6731. 0,
  6732. REG_DWORD,
  6733. (LPBYTE)&dwData,
  6734. sizeof(DWORD));
  6735. if( Status isnot NO_ERROR )
  6736. goto RETURN;
  6737. dwData = 0x0;
  6738. Status = RegSetValueEx(hPushPart,
  6739. WINSCNF_INIT_TIME_RPL_NM,
  6740. 0,
  6741. REG_DWORD,
  6742. (LPBYTE)&dwData,
  6743. sizeof(DWORD));
  6744. if( Status isnot NO_ERROR )
  6745. goto RETURN;
  6746. dwData = 0x1;
  6747. Status = RegSetValueEx(hPushPart,
  6748. WINSCNF_PRS_CONN_NM,
  6749. 0,
  6750. REG_DWORD,
  6751. (LPBYTE)&dwData,
  6752. sizeof(DWORD));
  6753. if( Status isnot NO_ERROR )
  6754. goto RETURN;
  6755. dwData = 0x0;
  6756. Status = RegSetValueEx(hPushPart,
  6757. WINSCNF_ADDCHG_TRIGGER_NM,
  6758. 0,
  6759. REG_DWORD,
  6760. (LPBYTE)&dwData,
  6761. sizeof(DWORD));
  6762. if( Status isnot NO_ERROR )
  6763. goto RETURN;
  6764. DisplayMessage(g_hModule,
  6765. EMSG_WINS_ERROR_SUCCESS);
  6766. RETURN:
  6767. if( Status isnot NO_ERROR )
  6768. DisplayErrorMessage(EMSG_SRVR_SET_DEFAULTPARAM,
  6769. Status);
  6770. if( hPushPart )
  6771. {
  6772. RegCloseKey(hPushPart);
  6773. hPushPart = NULL;
  6774. }
  6775. if( hPullPart )
  6776. {
  6777. RegCloseKey(hPullPart);
  6778. hPullPart = NULL;
  6779. }
  6780. if( hPartner )
  6781. {
  6782. RegCloseKey(hPartner);
  6783. hPartner = NULL;
  6784. }
  6785. if( hCheck )
  6786. {
  6787. RegCloseKey(hCheck);
  6788. hCheck = NULL;
  6789. }
  6790. if( hDefaultPull )
  6791. {
  6792. RegCloseKey(hDefaultPull);
  6793. hDefaultPull = NULL;
  6794. }
  6795. if( hDefaultPush )
  6796. {
  6797. RegCloseKey(hDefaultPush);
  6798. hDefaultPush = NULL;
  6799. }
  6800. if( hDefault )
  6801. {
  6802. RegCloseKey(hDefault);
  6803. hDefault = NULL;
  6804. }
  6805. if( hParameter )
  6806. {
  6807. RegCloseKey(hParameter);
  6808. hParameter = NULL;
  6809. }
  6810. if( hWins )
  6811. {
  6812. RegCloseKey(hWins);
  6813. hWins = NULL;
  6814. }
  6815. if( hServer )
  6816. {
  6817. RegCloseKey(hServer);
  6818. hServer = NULL;
  6819. }
  6820. return Status;
  6821. }
  6822. DWORD
  6823. HandleSrvrSetMigrateflag(
  6824. IN LPCWSTR pwszMachine,
  6825. IN OUT LPWSTR *ppwcArguments,
  6826. IN DWORD dwCurrentIndex,
  6827. IN DWORD dwArgCount,
  6828. IN DWORD dwFlags,
  6829. IN LPCVOID pvData,
  6830. OUT BOOL *pbDone
  6831. )
  6832. /*++
  6833. Routine Description :
  6834. Set the migrate on/off flag
  6835. Arguments :
  6836. All aguments are passes as array of wide char strings in ppwcArguments.
  6837. Compulsory : Set or disable
  6838. Return Value:
  6839. Returns the status of the operation.
  6840. --*/
  6841. {
  6842. DWORD Status = NO_ERROR;
  6843. DWORD i, j, dwNumArgs, dwTagCount;
  6844. PDWORD pdwTagType = NULL,
  6845. pdwTagNum = NULL;
  6846. TAG_TYPE pttTags[] = {
  6847. {WINS_TOKEN_STATE, TRUE, FALSE},
  6848. };
  6849. BOOL fMigrate = FALSE;
  6850. LPWSTR pTemp = NULL;
  6851. HKEY hServer = NULL,
  6852. hParameter = NULL;
  6853. if( dwArgCount < dwCurrentIndex + 1 )
  6854. {
  6855. DisplayMessage(g_hModule, HLP_SRVR_SET_MIGRATEFLAG_EX);
  6856. Status = ERROR_INVALID_PARAMETER;
  6857. goto ErrorReturn;
  6858. }
  6859. dwNumArgs = dwArgCount - dwCurrentIndex;
  6860. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6861. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  6862. if( pdwTagType is NULL or
  6863. pdwTagNum is NULL )
  6864. {
  6865. Status = ERROR_NOT_ENOUGH_MEMORY;
  6866. goto ErrorReturn;
  6867. }
  6868. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  6869. Status = PreProcessCommand(ppwcArguments,
  6870. dwArgCount,
  6871. dwCurrentIndex,
  6872. pttTags,
  6873. &dwTagCount,
  6874. pdwTagType,
  6875. pdwTagNum);
  6876. if( Status isnot NO_ERROR )
  6877. goto ErrorReturn;
  6878. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  6879. {
  6880. if( pttTags[i].dwRequired is TRUE and
  6881. pttTags[i].bPresent is FALSE
  6882. )
  6883. {
  6884. Status = ERROR_INVALID_PARAMETER;
  6885. goto ErrorReturn;
  6886. }
  6887. }
  6888. for( j=0; j<dwTagCount; j++ )
  6889. {
  6890. switch(pdwTagType[j])
  6891. {
  6892. case 0:
  6893. {
  6894. DWORD dw = 0;
  6895. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE or
  6896. wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  6897. {
  6898. Status = ERROR_INVALID_PARAMETER;
  6899. goto ErrorReturn;
  6900. }
  6901. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  6902. if( dw is 1 )
  6903. fMigrate = TRUE;
  6904. else if( dw is 0 )
  6905. fMigrate = FALSE;
  6906. else
  6907. {
  6908. Status = ERROR_INVALID_PARAMETER;
  6909. goto ErrorReturn;
  6910. }
  6911. break;
  6912. }
  6913. default:
  6914. {
  6915. Status = ERROR_INVALID_PARAMETER;
  6916. goto ErrorReturn;
  6917. }
  6918. }
  6919. }
  6920. {
  6921. if( wcslen(g_ServerNetBiosName) > 0 )
  6922. pTemp = g_ServerNetBiosName;
  6923. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  6924. if( Status isnot NO_ERROR )
  6925. goto ErrorReturn;
  6926. Status = RegCreateKeyEx(hServer,
  6927. PARAMETER,
  6928. 0,
  6929. NULL,
  6930. REG_OPTION_NON_VOLATILE,
  6931. KEY_ALL_ACCESS,
  6932. NULL,
  6933. &hParameter,
  6934. NULL);
  6935. if( Status isnot NO_ERROR )
  6936. goto ErrorReturn;
  6937. Status = RegSetValueEx(hParameter,
  6938. WINSCNF_MIGRATION_ON_NM,
  6939. 0,
  6940. REG_DWORD,
  6941. (LPBYTE)&fMigrate,
  6942. sizeof(BOOL));
  6943. if( Status isnot NO_ERROR )
  6944. goto ErrorReturn;
  6945. }
  6946. CommonReturn:
  6947. if( Status is NO_ERROR )
  6948. {
  6949. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  6950. }
  6951. if( hParameter )
  6952. {
  6953. RegCloseKey(hParameter);
  6954. hParameter = NULL;
  6955. }
  6956. if( hServer )
  6957. {
  6958. RegCloseKey(hServer);
  6959. hServer = NULL;
  6960. }
  6961. if( pdwTagType )
  6962. {
  6963. WinsFreeMemory(pdwTagType);
  6964. pdwTagType = NULL;
  6965. }
  6966. if( pdwTagNum )
  6967. {
  6968. WinsFreeMemory(pdwTagNum);
  6969. pdwTagNum = NULL;
  6970. }
  6971. return Status;
  6972. ErrorReturn:
  6973. DisplayErrorMessage(EMSG_SRVR_SET_MIGRATEFLAG,
  6974. Status);
  6975. goto CommonReturn;
  6976. }
  6977. DWORD
  6978. HandleSrvrSetNamerecord(
  6979. IN LPCWSTR pwszMachine,
  6980. IN OUT LPWSTR *ppwcArguments,
  6981. IN DWORD dwCurrentIndex,
  6982. IN DWORD dwArgCount,
  6983. IN DWORD dwFlags,
  6984. IN LPCVOID pvData,
  6985. OUT BOOL *pbDone
  6986. )
  6987. /*++
  6988. Routine Description :
  6989. Set the name record parameters for the server.
  6990. Arguments :
  6991. All aguments are passes as array of wide char strings in ppwcArguments.
  6992. Optional : Renew, extinction interval, extinction timeout and verification values.
  6993. Note : All parameters are optional.
  6994. Return Value:
  6995. Returns the status of the operation.
  6996. --*/
  6997. {
  6998. DWORD Status = NO_ERROR;
  6999. DWORD i, j, dwNumArgs, dwTagCount;
  7000. PDWORD pdwTagType = NULL,
  7001. pdwTagNum = NULL;
  7002. TAG_TYPE pttTags[] = {
  7003. {WINS_TOKEN_RENEW, FALSE, FALSE},
  7004. {WINS_TOKEN_EXTINCTION, FALSE, FALSE},
  7005. {WINS_TOKEN_EXTIMEOUT, FALSE, FALSE},
  7006. {WINS_TOKEN_VERIFICATION, FALSE, FALSE},
  7007. };
  7008. DWORD dwRenew = SIX_DAYS,
  7009. dwExtinction = SIX_DAYS,
  7010. dwExTimeOut = SIX_DAYS,
  7011. dwVerify = WINSCNF_MIN_VERIFY_INTERVAL;
  7012. BOOL fRenew = FALSE,
  7013. fExtinction = FALSE,
  7014. fExTimeOut = FALSE,
  7015. fVerify = FALSE;
  7016. LPWSTR pTemp = NULL;
  7017. HKEY hServer = NULL,
  7018. hParameter = NULL;
  7019. if( dwArgCount < dwCurrentIndex + 1 )
  7020. {
  7021. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  7022. return NO_ERROR;
  7023. }
  7024. dwNumArgs = dwArgCount - dwCurrentIndex;
  7025. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7026. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7027. if( pdwTagType is NULL or
  7028. pdwTagNum is NULL )
  7029. {
  7030. Status = ERROR_NOT_ENOUGH_MEMORY;
  7031. goto ErrorReturn;
  7032. }
  7033. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  7034. Status = PreProcessCommand(ppwcArguments,
  7035. dwArgCount,
  7036. dwCurrentIndex,
  7037. pttTags,
  7038. &dwTagCount,
  7039. pdwTagType,
  7040. pdwTagNum);
  7041. if( Status isnot NO_ERROR )
  7042. goto ErrorReturn;
  7043. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  7044. {
  7045. if( pttTags[i].dwRequired is TRUE and
  7046. pttTags[i].bPresent is FALSE
  7047. )
  7048. {
  7049. Status = ERROR_INVALID_PARAMETER;
  7050. goto ErrorReturn;
  7051. }
  7052. }
  7053. for( j=0; j<dwTagCount; j++ )
  7054. {
  7055. switch(pdwTagType[j])
  7056. {
  7057. case 0:
  7058. {
  7059. DWORD dw = 0;
  7060. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7061. {
  7062. Status = ERROR_INVALID_PARAMETER;
  7063. goto ErrorReturn;
  7064. }
  7065. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  7066. {
  7067. dwRenew = SIX_DAYS;
  7068. }
  7069. else
  7070. {
  7071. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  7072. dwRenew = dw;
  7073. }
  7074. fRenew = TRUE;
  7075. break;
  7076. }
  7077. case 1:
  7078. {
  7079. DWORD dw = 0;
  7080. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7081. {
  7082. Status = ERROR_INVALID_PARAMETER;
  7083. goto ErrorReturn;
  7084. }
  7085. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  7086. {
  7087. dwExtinction = SIX_DAYS;
  7088. }
  7089. else
  7090. {
  7091. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7092. dwExtinction = dw;
  7093. }
  7094. fExtinction = TRUE;
  7095. break;
  7096. }
  7097. case 2:
  7098. {
  7099. DWORD dw = 0;
  7100. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7101. {
  7102. Status = ERROR_INVALID_PARAMETER;
  7103. goto ErrorReturn;
  7104. }
  7105. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  7106. {
  7107. dwExTimeOut = SIX_DAYS;
  7108. }
  7109. else
  7110. {
  7111. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7112. dwExTimeOut = dw;
  7113. }
  7114. fExTimeOut = TRUE;
  7115. break;
  7116. }
  7117. case 3:
  7118. {
  7119. DWORD dw = 0;
  7120. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7121. {
  7122. Status = ERROR_INVALID_PARAMETER;
  7123. goto ErrorReturn;
  7124. }
  7125. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  7126. {
  7127. dwVerify = WINSCNF_MIN_VERIFY_INTERVAL;
  7128. }
  7129. else
  7130. {
  7131. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7132. dwVerify = dw;
  7133. }
  7134. fVerify = TRUE;
  7135. break;
  7136. }
  7137. default:
  7138. {
  7139. Status = ERROR_INVALID_PARAMETER;
  7140. goto ErrorReturn;
  7141. }
  7142. }
  7143. }
  7144. {
  7145. DWORD dwValue = 0,
  7146. dwType = REG_DWORD,
  7147. dwSize = sizeof(DWORD);
  7148. if( wcslen(g_ServerNetBiosName) > 0 )
  7149. pTemp = g_ServerNetBiosName;
  7150. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  7151. if( Status isnot NO_ERROR )
  7152. goto ErrorReturn;
  7153. Status = RegCreateKeyEx(hServer,
  7154. PARAMETER,
  7155. 0,
  7156. NULL,
  7157. REG_OPTION_NON_VOLATILE,
  7158. KEY_ALL_ACCESS,
  7159. NULL,
  7160. &hParameter,
  7161. NULL);
  7162. if( Status isnot NO_ERROR )
  7163. goto ErrorReturn;
  7164. //First retrieve the older values for all the parameters
  7165. Status = RegQueryValueEx(hParameter,
  7166. WINSCNF_REFRESH_INTVL_NM,
  7167. NULL,
  7168. &dwType,
  7169. (LPBYTE)&dwValue,
  7170. &dwSize);
  7171. if( Status is NO_ERROR )
  7172. {
  7173. if( fRenew is FALSE )
  7174. {
  7175. dwRenew = dwValue;
  7176. }
  7177. }
  7178. dwSize = sizeof(DWORD);
  7179. Status = RegQueryValueEx(hParameter,
  7180. WINSCNF_TOMBSTONE_INTVL_NM,
  7181. NULL,
  7182. &dwType,
  7183. (LPBYTE)&dwValue,
  7184. &dwSize);
  7185. if( Status is NO_ERROR )
  7186. {
  7187. if( fExtinction is FALSE )
  7188. dwExtinction = dwValue;
  7189. }
  7190. dwSize = sizeof(DWORD);
  7191. Status = RegQueryValueEx(hParameter,
  7192. WINSCNF_TOMBSTONE_TMOUT_NM,
  7193. NULL,
  7194. &dwType,
  7195. (LPBYTE)&dwValue,
  7196. &dwSize);
  7197. if( Status is NO_ERROR )
  7198. {
  7199. if( fExTimeOut is FALSE )
  7200. dwExTimeOut = dwValue;
  7201. }
  7202. dwSize = sizeof(DWORD);
  7203. Status = RegQueryValueEx(hParameter,
  7204. WINSCNF_VERIFY_INTVL_NM,
  7205. NULL,
  7206. &dwType,
  7207. (LPBYTE)&dwValue,
  7208. &dwSize);
  7209. if( Status is NO_ERROR )
  7210. {
  7211. if( fVerify is FALSE )
  7212. dwVerify = dwValue;
  7213. }
  7214. //Check the validity and range of values
  7215. {
  7216. if( dwRenew < WINSCNF_MIN_REFRESH_INTERVAL )
  7217. {
  7218. DisplayMessage(g_hModule,
  7219. EMSG_SRVR_RENEW_INTERVAL);
  7220. Status = ERROR_INVALID_PARAMETER;
  7221. goto ErrorReturn;
  7222. }
  7223. if( dwRenew > ONE_YEAR )
  7224. {
  7225. dwRenew = ONE_YEAR;
  7226. }
  7227. if( dwExTimeOut < WINSCNF_MIN_TOMBSTONE_TIMEOUT )
  7228. {
  7229. DisplayMessage(g_hModule,
  7230. EMSG_SRVR_TOMBSTONE_TIMEOUT,
  7231. WINSCNF_MIN_TOMBSTONE_TIMEOUT);
  7232. Status = ERROR_INVALID_PARAMETER;
  7233. goto ErrorReturn;
  7234. }
  7235. if( dwExTimeOut > ONE_YEAR )
  7236. {
  7237. dwExTimeOut = ONE_YEAR;
  7238. }
  7239. if( dwExTimeOut < dwRenew )
  7240. {
  7241. DisplayMessage(g_hModule,
  7242. EMSG_SRVR_TOMBSTONE_TIMEOUT,
  7243. dwRenew);
  7244. Status = ERROR_INVALID_PARAMETER;
  7245. goto ErrorReturn;
  7246. }
  7247. if( dwExtinction < WINSCNF_MAKE_TOMB_INTVL_0_M(dwRenew) )
  7248. {
  7249. DisplayMessage(g_hModule,
  7250. EMSG_SRVR_TOMBSTONE_INTERVAL,
  7251. WINSCNF_MAKE_TOMB_INTVL_0_M(dwRenew) );
  7252. Status = ERROR_INVALID_PARAMETER;
  7253. goto ErrorReturn;
  7254. }
  7255. if( dwVerify < WINSCNF_MAKE_VERIFY_INTVL_M(dwExtinction) )
  7256. {
  7257. if( WINSCNF_MAKE_VERIFY_INTVL_M(dwExtinction) == TWENTY_FOUR_DAYS )
  7258. {
  7259. DisplayMessage(g_hModule,
  7260. EMSG_SRVR_VERIFY_INTERVAL,
  7261. TOMB_MULTIPLIER_FOR_VERIFY,
  7262. WINSCNF_MAKE_VERIFY_INTVL_M(dwExtinction));
  7263. Status = ERROR_INVALID_PARAMETER;
  7264. goto ErrorReturn;
  7265. }
  7266. }
  7267. }
  7268. Status = RegSetValueEx(hParameter,
  7269. WINSCNF_REFRESH_INTVL_NM,
  7270. 0,
  7271. REG_DWORD,
  7272. (LPBYTE)&dwRenew,
  7273. sizeof(DWORD));
  7274. if( Status isnot NO_ERROR )
  7275. goto ErrorReturn;
  7276. Status = RegSetValueEx(hParameter,
  7277. WINSCNF_TOMBSTONE_INTVL_NM,
  7278. 0,
  7279. REG_DWORD,
  7280. (LPBYTE)&dwExtinction,
  7281. sizeof(DWORD));
  7282. if( Status isnot NO_ERROR )
  7283. goto ErrorReturn;
  7284. Status = RegSetValueEx(hParameter,
  7285. WINSCNF_TOMBSTONE_TMOUT_NM,
  7286. 0,
  7287. REG_DWORD,
  7288. (LPBYTE)&dwExTimeOut,
  7289. sizeof(DWORD));
  7290. if( Status isnot NO_ERROR )
  7291. goto ErrorReturn;
  7292. Status = RegSetValueEx(hParameter,
  7293. WINSCNF_VERIFY_INTVL_NM,
  7294. 0,
  7295. REG_DWORD,
  7296. (LPBYTE)&dwVerify,
  7297. sizeof(DWORD));
  7298. if( Status isnot NO_ERROR )
  7299. goto ErrorReturn;
  7300. }
  7301. if( Status is NO_ERROR )
  7302. {
  7303. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  7304. }
  7305. CommonReturn:
  7306. if( hParameter )
  7307. {
  7308. RegCloseKey(hParameter);
  7309. hParameter = NULL;
  7310. }
  7311. if( hServer )
  7312. {
  7313. RegCloseKey(hServer);
  7314. hServer = NULL;
  7315. }
  7316. if( pdwTagType )
  7317. {
  7318. WinsFreeMemory(pdwTagType);
  7319. pdwTagType = NULL;
  7320. }
  7321. if( pdwTagNum )
  7322. {
  7323. WinsFreeMemory(pdwTagNum);
  7324. pdwTagNum = NULL;
  7325. }
  7326. return Status;
  7327. ErrorReturn:
  7328. DisplayErrorMessage(EMSG_SRVR_SET_NAMERECORD,
  7329. Status);
  7330. goto CommonReturn;
  7331. }
  7332. DWORD
  7333. HandleSrvrSetPeriodicdbchecking(
  7334. IN LPCWSTR pwszMachine,
  7335. IN OUT LPWSTR *ppwcArguments,
  7336. IN DWORD dwCurrentIndex,
  7337. IN DWORD dwArgCount,
  7338. IN DWORD dwFlags,
  7339. IN LPCVOID pvData,
  7340. OUT BOOL *pbDone
  7341. )
  7342. /*++
  7343. Routine Description :
  7344. Set the periodic database checking parameters for the server
  7345. Arguments :
  7346. All aguments are passes as array of wide char strings in ppwcArguments.
  7347. Compulsory : State
  7348. Optional : Maximum record count, and other parameters.
  7349. Return Value:
  7350. Returns the status of the operation.
  7351. --*/
  7352. {
  7353. DWORD Status = NO_ERROR;
  7354. DWORD i, j, dwNumArgs, dwTagCount;
  7355. PDWORD pdwTagType = NULL,
  7356. pdwTagNum = NULL;
  7357. TAG_TYPE pttTags[] = {
  7358. {WINS_TOKEN_STATE, TRUE, FALSE},
  7359. {WINS_TOKEN_MAXRECORDCOUNT, FALSE, FALSE},
  7360. {WINS_TOKEN_CHECKAGAINST, FALSE, FALSE},
  7361. {WINS_TOKEN_CHECKEVERY, FALSE, FALSE},
  7362. {WINS_TOKEN_START, FALSE, FALSE},
  7363. };
  7364. DWORD dwMaxRec = WINSCNF_CC_DEF_RECS_AAT,
  7365. dwEvery = WINSCNF_CC_DEF_INTERVAL,
  7366. dwStart = WINSCNF_DEF_CC_SP_HR*60*60;
  7367. BOOL fPartner = WINSCNF_CC_DEF_USE_RPL_PNRS,
  7368. fIsPartner = FALSE,
  7369. fMax = FALSE,
  7370. fEvery = FALSE,
  7371. fStart = FALSE,
  7372. fState = TRUE;
  7373. LPWSTR pTemp = NULL;
  7374. HKEY hServer = NULL,
  7375. hCCRoot = NULL;
  7376. if( dwArgCount < dwCurrentIndex + 1 )
  7377. {
  7378. DisplayMessage(g_hModule, HLP_SRVR_SET_PERIODICDBCHECKING_EX);
  7379. Status = ERROR_INVALID_PARAMETER;
  7380. goto ErrorReturn;
  7381. }
  7382. dwNumArgs = dwArgCount - dwCurrentIndex;
  7383. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7384. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7385. if( pdwTagType is NULL or
  7386. pdwTagNum is NULL )
  7387. {
  7388. Status = ERROR_NOT_ENOUGH_MEMORY;
  7389. goto ErrorReturn;
  7390. }
  7391. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  7392. Status = PreProcessCommand(ppwcArguments,
  7393. dwArgCount,
  7394. dwCurrentIndex,
  7395. pttTags,
  7396. &dwTagCount,
  7397. pdwTagType,
  7398. pdwTagNum);
  7399. if( Status isnot NO_ERROR )
  7400. goto ErrorReturn;
  7401. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  7402. {
  7403. if( pttTags[i].dwRequired is TRUE and
  7404. pttTags[i].bPresent is FALSE
  7405. )
  7406. {
  7407. Status = ERROR_INVALID_PARAMETER;
  7408. goto ErrorReturn;
  7409. }
  7410. }
  7411. for( j=0; j<dwTagCount; j++ )
  7412. {
  7413. switch(pdwTagType[j])
  7414. {
  7415. case 0:
  7416. {
  7417. DWORD dw = 0;
  7418. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7419. {
  7420. Status = ERROR_INVALID_PARAMETER;
  7421. goto ErrorReturn;
  7422. }
  7423. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7424. if( dw is 0 )
  7425. fState = FALSE;
  7426. else
  7427. fState = TRUE;
  7428. break;
  7429. }
  7430. case 1:
  7431. {
  7432. DWORD dw = 0;
  7433. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7434. {
  7435. Status = ERROR_INVALID_PARAMETER;
  7436. goto ErrorReturn;
  7437. }
  7438. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7439. dwMaxRec = dw;
  7440. fMax = TRUE;
  7441. break;
  7442. }
  7443. case 2:
  7444. {
  7445. DWORD dw = 0;
  7446. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7447. {
  7448. Status = ERROR_INVALID_PARAMETER;
  7449. goto ErrorReturn;
  7450. }
  7451. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7452. if( dw is 1 )
  7453. fPartner = TRUE;
  7454. else
  7455. fPartner = FALSE;
  7456. fIsPartner = TRUE;
  7457. break;
  7458. }
  7459. case 3:
  7460. {
  7461. DWORD dw = 0;
  7462. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7463. {
  7464. Status = ERROR_INVALID_PARAMETER;
  7465. goto ErrorReturn;
  7466. }
  7467. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7468. dwEvery = dw*60*60;
  7469. fEvery = TRUE;
  7470. break;
  7471. }
  7472. case 4:
  7473. {
  7474. DWORD dw = 0;
  7475. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7476. {
  7477. Status = ERROR_INVALID_PARAMETER;
  7478. goto ErrorReturn;
  7479. }
  7480. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7481. dwStart = dw;
  7482. fStart = TRUE;
  7483. break;
  7484. }
  7485. default:
  7486. {
  7487. Status = ERROR_INVALID_PARAMETER;
  7488. goto ErrorReturn;
  7489. }
  7490. }
  7491. }
  7492. if( fState is FALSE )
  7493. {
  7494. if( wcslen(g_ServerNetBiosName) > 0 )
  7495. pTemp = g_ServerNetBiosName;
  7496. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  7497. if( Status isnot NO_ERROR )
  7498. goto ErrorReturn;
  7499. RegDeleteKey(hServer, CCROOT);
  7500. }
  7501. else
  7502. {
  7503. if( fMax is TRUE or
  7504. fEvery is TRUE or
  7505. fIsPartner is TRUE or
  7506. fStart is TRUE )
  7507. {
  7508. if( wcslen(g_ServerNetBiosName) > 0 )
  7509. pTemp = g_ServerNetBiosName;
  7510. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  7511. if( Status isnot NO_ERROR )
  7512. goto ErrorReturn;
  7513. Status = RegCreateKeyEx(hServer,
  7514. CCROOT,
  7515. 0,
  7516. NULL,
  7517. REG_OPTION_NON_VOLATILE,
  7518. KEY_ALL_ACCESS,
  7519. NULL,
  7520. &hCCRoot,
  7521. NULL);
  7522. if( Status isnot NO_ERROR )
  7523. goto ErrorReturn;
  7524. if( fMax )
  7525. {
  7526. Status = RegSetValueEx(hCCRoot,
  7527. WINSCNF_CC_MAX_RECS_AAT_NM,
  7528. 0,
  7529. REG_DWORD,
  7530. (LPBYTE)&dwMaxRec,
  7531. sizeof(DWORD));
  7532. if( Status isnot NO_ERROR )
  7533. goto ErrorReturn;
  7534. }
  7535. if( fIsPartner )
  7536. {
  7537. Status = RegSetValueEx(hCCRoot,
  7538. WINSCNF_CC_USE_RPL_PNRS_NM,
  7539. 0,
  7540. REG_DWORD,
  7541. (LPBYTE)&fPartner,
  7542. sizeof(BOOL));
  7543. if( Status isnot NO_ERROR )
  7544. goto ErrorReturn;
  7545. }
  7546. if( fEvery )
  7547. {
  7548. Status = RegSetValueEx(hCCRoot,
  7549. WINSCNF_CC_INTVL_NM,
  7550. 0,
  7551. REG_DWORD,
  7552. (LPBYTE)&dwEvery,
  7553. sizeof(DWORD));
  7554. if( Status isnot NO_ERROR )
  7555. goto ErrorReturn;
  7556. }
  7557. if( fStart )
  7558. {
  7559. LPWSTR pwszTime = MakeTimeString(dwStart);
  7560. if( pwszTime is NULL )
  7561. {
  7562. Status = ERROR_NOT_ENOUGH_MEMORY;
  7563. goto ErrorReturn;
  7564. }
  7565. Status = RegSetValueEx(hCCRoot,
  7566. WINSCNF_SP_TIME_NM,
  7567. 0,
  7568. REG_SZ,
  7569. (LPBYTE)pwszTime,
  7570. (wcslen(pwszTime)+1)*sizeof(WCHAR));
  7571. WinsFreeMemory(pwszTime);
  7572. pwszTime = NULL;
  7573. if( Status isnot NO_ERROR )
  7574. goto ErrorReturn;
  7575. }
  7576. }
  7577. }
  7578. CommonReturn:
  7579. if( Status is NO_ERROR )
  7580. {
  7581. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  7582. }
  7583. if( hCCRoot )
  7584. {
  7585. RegCloseKey(hCCRoot);
  7586. hCCRoot = NULL;
  7587. }
  7588. if( hServer )
  7589. {
  7590. RegCloseKey(hServer);
  7591. hServer = NULL;
  7592. }
  7593. if( pdwTagType )
  7594. {
  7595. WinsFreeMemory(pdwTagType);
  7596. pdwTagType = NULL;
  7597. }
  7598. if( pdwTagNum )
  7599. {
  7600. WinsFreeMemory(pdwTagNum);
  7601. pdwTagNum = NULL;
  7602. }
  7603. return Status;
  7604. ErrorReturn:
  7605. DisplayErrorMessage(EMSG_SRVR_SET_PERIODICDBCHECKING,
  7606. Status);
  7607. if( hServer )
  7608. {
  7609. if( hCCRoot )
  7610. {
  7611. RegCloseKey(hCCRoot);
  7612. hCCRoot = NULL;
  7613. }
  7614. RegDeleteKey(hServer, CCROOT);
  7615. }
  7616. goto CommonReturn;
  7617. }
  7618. DWORD
  7619. HandleSrvrSetPullpersistentconnection(
  7620. IN LPCWSTR pwszMachine,
  7621. IN OUT LPWSTR *ppwcArguments,
  7622. IN DWORD dwCurrentIndex,
  7623. IN DWORD dwArgCount,
  7624. IN DWORD dwFlags,
  7625. IN LPCVOID pvData,
  7626. OUT BOOL *pbDone
  7627. )
  7628. /*++
  7629. Routine Description :
  7630. Set the pull partner configuration parameters
  7631. Arguments :
  7632. All aguments are passes as array of wide char strings in ppwcArguments.
  7633. Compulsory : Server IP and persistence state
  7634. Optional : Start value and Time interval
  7635. Note : All parameters are optional.
  7636. Return Value:
  7637. Returns the status of the operation.
  7638. --*/
  7639. {
  7640. DWORD Status = NO_ERROR;
  7641. DWORD i, j, dwNumArgs, dwTagCount;
  7642. PDWORD pdwTagType = NULL,
  7643. pdwTagNum = NULL;
  7644. TAG_TYPE pttTags[] = {
  7645. {WINS_TOKEN_STATE, TRUE, FALSE},
  7646. {WINS_TOKEN_SERVER, TRUE, FALSE},
  7647. {WINS_TOKEN_START, FALSE, FALSE},
  7648. {WINS_TOKEN_INTERVAL, FALSE, FALSE},
  7649. };
  7650. DWORD dwStart = 0,
  7651. dwInterval = 1800;
  7652. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN + 1] = {L'\0'};
  7653. BOOL fState = TRUE,
  7654. fStart = FALSE,
  7655. fInterval = FALSE;
  7656. LPWSTR pTemp = NULL;
  7657. HKEY hServer = NULL,
  7658. hPullRoot = NULL,
  7659. hPullServer = NULL;
  7660. if( dwArgCount < dwCurrentIndex + 2 )
  7661. {
  7662. DisplayMessage(g_hModule, HLP_SRVR_SET_PULLPERSISTENTCONNECTION_EX);
  7663. Status = ERROR_INVALID_PARAMETER;
  7664. goto ErrorReturn;
  7665. }
  7666. dwNumArgs = dwArgCount - dwCurrentIndex;
  7667. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7668. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7669. if( pdwTagType is NULL or
  7670. pdwTagNum is NULL )
  7671. {
  7672. Status = ERROR_NOT_ENOUGH_MEMORY;
  7673. goto ErrorReturn;
  7674. }
  7675. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  7676. Status = PreProcessCommand(ppwcArguments,
  7677. dwArgCount,
  7678. dwCurrentIndex,
  7679. pttTags,
  7680. &dwTagCount,
  7681. pdwTagType,
  7682. pdwTagNum);
  7683. if( Status isnot NO_ERROR )
  7684. goto ErrorReturn;
  7685. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  7686. {
  7687. if( pttTags[i].dwRequired is TRUE and
  7688. pttTags[i].bPresent is FALSE
  7689. )
  7690. {
  7691. Status = ERROR_INVALID_PARAMETER;
  7692. goto ErrorReturn;
  7693. }
  7694. }
  7695. for( j=0; j<dwTagCount; j++ )
  7696. {
  7697. switch(pdwTagType[j])
  7698. {
  7699. case 0:
  7700. {
  7701. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  7702. if( wc is L'0' )
  7703. fState = FALSE;
  7704. else if ( wc is L'1' )
  7705. fState = TRUE;
  7706. else
  7707. {
  7708. Status = ERROR_INVALID_PARAMETER;
  7709. goto ErrorReturn;
  7710. }
  7711. break;
  7712. }
  7713. case 1:
  7714. {
  7715. struct hostent * lpHostEnt = NULL;
  7716. CHAR cAddr[16];
  7717. BYTE pbAdd[4];
  7718. char szAdd[4];
  7719. int k = 0, l=0;
  7720. DWORD dwLen, nLen = 0;
  7721. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  7722. {
  7723. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  7724. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  7725. if(lpHostEnt isnot NULL )//Valid IP Address
  7726. {
  7727. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  7728. break;
  7729. }
  7730. else
  7731. {
  7732. Status = ERROR_INVALID_IPADDRESS;
  7733. goto ErrorReturn;
  7734. }
  7735. }
  7736. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  7737. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  7738. k = 2;
  7739. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  7740. if( lpHostEnt is NULL )
  7741. {
  7742. DisplayMessage(g_hModule,
  7743. EMSG_WINS_INVALID_COMPUTER_NAME,
  7744. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  7745. Status = ERROR_INVALID_PARAMETER;
  7746. goto ErrorReturn;
  7747. }
  7748. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  7749. for( l=0; l<4; l++)
  7750. {
  7751. _itoa((int)pbAdd[l], szAdd, 10);
  7752. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  7753. nLen += strlen(szAdd);
  7754. *(cAddr+nLen) = '.';
  7755. nLen++;
  7756. }
  7757. *(cAddr+nLen-1) = '\0';
  7758. WinsAnsiToUnicode(cAddr, wcServerIpAdd);
  7759. break; }
  7760. case 2:
  7761. {
  7762. DWORD dw = 0;
  7763. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7764. {
  7765. Status = ERROR_INVALID_PARAMETER;
  7766. goto ErrorReturn;
  7767. }
  7768. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7769. dwStart = dw;
  7770. fStart = TRUE;
  7771. break;
  7772. }
  7773. case 3:
  7774. {
  7775. DWORD dw = 0;
  7776. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  7777. {
  7778. Status = ERROR_INVALID_PARAMETER;
  7779. goto ErrorReturn;
  7780. }
  7781. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  7782. dwInterval = dw;
  7783. fInterval = TRUE;
  7784. break;
  7785. }
  7786. default:
  7787. {
  7788. Status = ERROR_INVALID_PARAMETER;
  7789. goto ErrorReturn;
  7790. }
  7791. }
  7792. }
  7793. {
  7794. DWORD dwDisposition = 0;
  7795. if( wcslen(g_ServerNetBiosName) > 0 )
  7796. pTemp = g_ServerNetBiosName;
  7797. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  7798. if( Status isnot NO_ERROR )
  7799. goto ErrorReturn;
  7800. Status = RegOpenKeyEx(hServer,
  7801. PULLROOT,
  7802. 0,
  7803. KEY_ALL_ACCESS,
  7804. &hPullRoot);
  7805. if( Status isnot NO_ERROR )
  7806. goto ErrorReturn;
  7807. Status = RegOpenKeyEx(hPullRoot,
  7808. wcServerIpAdd,
  7809. 0,
  7810. KEY_ALL_ACCESS,
  7811. &hPullServer);
  7812. if( Status is ERROR_FILE_NOT_FOUND )
  7813. {
  7814. DisplayMessage(g_hModule,
  7815. EMSG_SRVR_INVALID_PARTNER,
  7816. wcServerIpAdd);
  7817. goto CommonReturn;
  7818. }
  7819. if( Status isnot NO_ERROR )
  7820. goto ErrorReturn;
  7821. Status = RegSetValueEx(hPullServer,
  7822. PERSISTENCE,
  7823. 0,
  7824. REG_DWORD,
  7825. (LPBYTE)&fState,
  7826. sizeof(BOOL));
  7827. if( Status isnot NO_ERROR )
  7828. {
  7829. goto ErrorReturn;
  7830. }
  7831. if( fInterval )
  7832. {
  7833. Status = RegSetValueEx(hPullServer,
  7834. WINSCNF_RPL_INTERVAL_NM,
  7835. 0,
  7836. REG_DWORD,
  7837. (LPBYTE)&dwInterval,
  7838. sizeof(DWORD));
  7839. if( Status isnot NO_ERROR )
  7840. {
  7841. goto ErrorReturn;
  7842. }
  7843. }
  7844. if( fStart )
  7845. {
  7846. LPWSTR pwszTime = MakeTimeString(dwStart);
  7847. if( pwszTime is NULL )
  7848. {
  7849. Status = ERROR_NOT_ENOUGH_MEMORY;
  7850. goto ErrorReturn;
  7851. }
  7852. Status = RegSetValueEx(hPullServer,
  7853. WINSCNF_SP_TIME_NM,
  7854. 0,
  7855. REG_SZ,
  7856. (LPBYTE)pwszTime,
  7857. (wcslen(pwszTime)+1)*sizeof(WCHAR));
  7858. WinsFreeMemory(pwszTime);
  7859. pwszTime = NULL;
  7860. if( Status isnot NO_ERROR )
  7861. {
  7862. goto ErrorReturn;
  7863. }
  7864. }
  7865. }
  7866. CommonReturn:
  7867. if( Status is NO_ERROR )
  7868. {
  7869. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  7870. }
  7871. if( hPullServer )
  7872. {
  7873. RegCloseKey(hPullServer);
  7874. hPullServer = NULL;
  7875. }
  7876. if( hPullRoot )
  7877. {
  7878. RegCloseKey(hPullRoot);
  7879. hPullRoot = NULL;
  7880. }
  7881. if( hServer )
  7882. {
  7883. RegCloseKey(hServer);
  7884. hServer = NULL;
  7885. }
  7886. if( pdwTagType )
  7887. {
  7888. WinsFreeMemory(pdwTagType);
  7889. pdwTagType = NULL;
  7890. }
  7891. if( pdwTagNum )
  7892. {
  7893. WinsFreeMemory(pdwTagNum);
  7894. pdwTagNum = NULL;
  7895. }
  7896. return Status;
  7897. ErrorReturn:
  7898. DisplayErrorMessage(EMSG_SRVR_SET_PULLPERSISTENTCONNECTION,
  7899. Status);
  7900. goto CommonReturn;
  7901. }
  7902. DWORD
  7903. HandleSrvrSetPushpersistentconnection(
  7904. IN LPCWSTR pwszMachine,
  7905. IN OUT LPWSTR *ppwcArguments,
  7906. IN DWORD dwCurrentIndex,
  7907. IN DWORD dwArgCount,
  7908. IN DWORD dwFlags,
  7909. IN LPCVOID pvData,
  7910. OUT BOOL *pbDone
  7911. )
  7912. /*++
  7913. Routine Description :
  7914. Set the push partner configuration parameters
  7915. Arguments :
  7916. All aguments are passes as array of wide char strings in ppwcArguments.
  7917. Compulsory : Server IP and persistence state
  7918. Optional : Update count
  7919. Note : All parameters are optional.
  7920. Return Value:
  7921. Returns the status of the operation.
  7922. --*/
  7923. {
  7924. DWORD Status = NO_ERROR;
  7925. DWORD i, j, dwNumArgs, dwTagCount;
  7926. PDWORD pdwTagType = NULL,
  7927. pdwTagNum = NULL;
  7928. TAG_TYPE pttTags[] = {
  7929. {WINS_TOKEN_STATE, TRUE, FALSE},
  7930. {WINS_TOKEN_SERVER, TRUE, FALSE},
  7931. {WINS_TOKEN_UPDATE,FALSE, FALSE},
  7932. };
  7933. DWORD dwUpdate = 0;
  7934. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN + 1] = {L'\0'};
  7935. BOOL fState = TRUE,
  7936. fUpdate = FALSE;
  7937. LPWSTR pTemp = NULL;
  7938. HKEY hServer = NULL,
  7939. hPushRoot = NULL,
  7940. hPushServer = NULL;
  7941. if( dwArgCount < dwCurrentIndex + 2 )
  7942. {
  7943. DisplayMessage(g_hModule, HLP_SRVR_SET_PUSHPERSISTENTCONNECTION_EX);
  7944. Status = ERROR_INVALID_PARAMETER;
  7945. goto ErrorReturn;
  7946. }
  7947. dwNumArgs = dwArgCount - dwCurrentIndex;
  7948. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7949. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  7950. if( pdwTagType is NULL or
  7951. pdwTagNum is NULL )
  7952. {
  7953. Status = ERROR_NOT_ENOUGH_MEMORY;
  7954. goto ErrorReturn;
  7955. }
  7956. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  7957. Status = PreProcessCommand(ppwcArguments,
  7958. dwArgCount,
  7959. dwCurrentIndex,
  7960. pttTags,
  7961. &dwTagCount,
  7962. pdwTagType,
  7963. pdwTagNum);
  7964. if( Status isnot NO_ERROR )
  7965. goto ErrorReturn;
  7966. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  7967. {
  7968. if( pttTags[i].dwRequired is TRUE and
  7969. pttTags[i].bPresent is FALSE
  7970. )
  7971. {
  7972. Status = ERROR_INVALID_PARAMETER;
  7973. goto ErrorReturn;
  7974. }
  7975. }
  7976. for( j=0; j<dwTagCount; j++ )
  7977. {
  7978. switch(pdwTagType[j])
  7979. {
  7980. case 0:
  7981. {
  7982. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  7983. if( wc is L'0' )
  7984. fState = FALSE;
  7985. else if ( wc is L'1' )
  7986. fState = TRUE;
  7987. else
  7988. {
  7989. Status = ERROR_INVALID_PARAMETER;
  7990. goto ErrorReturn;
  7991. }
  7992. break;
  7993. }
  7994. case 1:
  7995. {
  7996. struct hostent * lpHostEnt = NULL;
  7997. CHAR cAddr[16];
  7998. BYTE pbAdd[4];
  7999. char szAdd[4];
  8000. int k = 0, l=0;
  8001. DWORD dwLen, nLen = 0;
  8002. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  8003. {
  8004. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  8005. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  8006. if(lpHostEnt isnot NULL )//Valid IP Address
  8007. {
  8008. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  8009. break;
  8010. }
  8011. else
  8012. {
  8013. Status = ERROR_INVALID_IPADDRESS;
  8014. goto ErrorReturn;
  8015. }
  8016. }
  8017. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  8018. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  8019. k = 2;
  8020. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  8021. if( lpHostEnt is NULL )
  8022. {
  8023. DisplayMessage(g_hModule,
  8024. EMSG_WINS_INVALID_COMPUTER_NAME,
  8025. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  8026. Status = ERROR_INVALID_PARAMETER;
  8027. goto ErrorReturn;
  8028. }
  8029. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  8030. for( l=0;l<4; l++)
  8031. {
  8032. _itoa((int)pbAdd[l], szAdd, 10);
  8033. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  8034. nLen += strlen(szAdd);
  8035. *(cAddr+nLen) = '.';
  8036. nLen++;
  8037. }
  8038. *(cAddr+nLen-1) = '\0';
  8039. WinsAnsiToUnicode(cAddr, wcServerIpAdd);
  8040. break;
  8041. }
  8042. case 2:
  8043. {
  8044. DWORD dw = 0;
  8045. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8046. {
  8047. Status = ERROR_INVALID_PARAMETER;
  8048. goto ErrorReturn;
  8049. }
  8050. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8051. dwUpdate = dw;
  8052. fUpdate = TRUE;
  8053. break;
  8054. }
  8055. default:
  8056. {
  8057. Status = ERROR_INVALID_PARAMETER;
  8058. goto ErrorReturn;
  8059. }
  8060. }
  8061. }
  8062. {
  8063. DWORD dwDisposition = 0;
  8064. if( wcslen(g_ServerNetBiosName) > 0 )
  8065. pTemp = g_ServerNetBiosName;
  8066. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  8067. if( Status isnot NO_ERROR )
  8068. goto ErrorReturn;
  8069. Status = RegOpenKeyEx(hServer,
  8070. PUSHROOT,
  8071. 0,
  8072. KEY_ALL_ACCESS,
  8073. &hPushRoot);
  8074. if( Status isnot NO_ERROR )
  8075. goto ErrorReturn;
  8076. Status = RegOpenKeyEx(hPushRoot,
  8077. wcServerIpAdd,
  8078. 0,
  8079. KEY_ALL_ACCESS,
  8080. &hPushServer);
  8081. if( Status is ERROR_FILE_NOT_FOUND )
  8082. {
  8083. DisplayMessage(g_hModule,
  8084. EMSG_SRVR_INVALID_PARTNER,
  8085. wcServerIpAdd);
  8086. goto CommonReturn;
  8087. }
  8088. if( Status isnot NO_ERROR )
  8089. goto ErrorReturn;
  8090. Status = RegSetValueEx(hPushServer,
  8091. PERSISTENCE,
  8092. 0,
  8093. REG_DWORD,
  8094. (LPBYTE)&fState,
  8095. sizeof(BOOL));
  8096. if( Status isnot NO_ERROR )
  8097. {
  8098. goto ErrorReturn;
  8099. }
  8100. if( fUpdate )
  8101. {
  8102. Status = RegSetValueEx(hPushServer,
  8103. WINSCNF_UPDATE_COUNT_NM,
  8104. 0,
  8105. REG_DWORD,
  8106. (LPBYTE)&dwUpdate,
  8107. sizeof(DWORD));
  8108. if( Status isnot NO_ERROR )
  8109. {
  8110. goto ErrorReturn;
  8111. }
  8112. }
  8113. }
  8114. CommonReturn:
  8115. if( Status is NO_ERROR )
  8116. {
  8117. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  8118. }
  8119. if( hPushServer )
  8120. {
  8121. RegCloseKey(hPushServer);
  8122. hPushServer = NULL;
  8123. }
  8124. if( hPushRoot )
  8125. {
  8126. RegCloseKey(hPushRoot);
  8127. hPushRoot = NULL;
  8128. }
  8129. if( hServer )
  8130. {
  8131. RegCloseKey(hServer);
  8132. hServer = NULL;
  8133. }
  8134. if( pdwTagType )
  8135. {
  8136. WinsFreeMemory(pdwTagType);
  8137. pdwTagType = NULL;
  8138. }
  8139. if( pdwTagNum )
  8140. {
  8141. WinsFreeMemory(pdwTagNum);
  8142. pdwTagNum = NULL;
  8143. }
  8144. return Status;
  8145. ErrorReturn:
  8146. DisplayErrorMessage(EMSG_SRVR_SET_PUSHPERSISTENTCONNECTION,
  8147. Status);
  8148. goto CommonReturn;
  8149. }
  8150. DWORD
  8151. HandleSrvrSetPullparam(
  8152. IN LPCWSTR pwszMachine,
  8153. IN OUT LPWSTR *ppwcArguments,
  8154. IN DWORD dwCurrentIndex,
  8155. IN DWORD dwArgCount,
  8156. IN DWORD dwFlags,
  8157. IN LPCVOID pvData,
  8158. OUT BOOL *pbDone
  8159. )
  8160. /*++
  8161. Routine Description :
  8162. Set the default pull parameters
  8163. Arguments :
  8164. All aguments are passes as array of wide char strings in ppwcArguments.
  8165. Compulsory : persistence state
  8166. Optional : Startup value, Start time and Time interval and retry count
  8167. Note : All parameters are optional.
  8168. Return Value:
  8169. Returns the status of the operation.
  8170. --*/
  8171. {
  8172. DWORD Status = NO_ERROR;
  8173. DWORD i, j, dwNumArgs, dwTagCount;
  8174. PDWORD pdwTagType = NULL,
  8175. pdwTagNum = NULL;
  8176. TAG_TYPE pttTags[] = {
  8177. {WINS_TOKEN_STATE, TRUE, FALSE},
  8178. {WINS_TOKEN_STARTUP, FALSE, FALSE},
  8179. {WINS_TOKEN_START, FALSE, FALSE},
  8180. {WINS_TOKEN_INTERVAL, FALSE, FALSE},
  8181. {WINS_TOKEN_RETRY, FALSE, FALSE},
  8182. };
  8183. DWORD dwStart = 0,
  8184. dwInterval = 1800,
  8185. dwRetry = 3;
  8186. BOOL fStart = FALSE,
  8187. fStartup = FALSE,
  8188. fInterval = FALSE,
  8189. fRetry = FALSE,
  8190. fState = TRUE;
  8191. LPWSTR pTemp = NULL;
  8192. HKEY hServer = NULL,
  8193. hDefault = NULL,
  8194. hPullRoot = NULL;
  8195. if( dwArgCount < dwCurrentIndex + 1 )
  8196. {
  8197. DisplayMessage(g_hModule, HLP_SRVR_SET_PULLPARAM_EX);
  8198. Status = ERROR_INVALID_PARAMETER;
  8199. goto ErrorReturn;
  8200. }
  8201. dwNumArgs = dwArgCount - dwCurrentIndex;
  8202. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8203. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8204. if( pdwTagType is NULL or
  8205. pdwTagNum is NULL )
  8206. {
  8207. Status = ERROR_NOT_ENOUGH_MEMORY;
  8208. goto ErrorReturn;
  8209. }
  8210. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  8211. Status = PreProcessCommand(ppwcArguments,
  8212. dwArgCount,
  8213. dwCurrentIndex,
  8214. pttTags,
  8215. &dwTagCount,
  8216. pdwTagType,
  8217. pdwTagNum);
  8218. if( Status isnot NO_ERROR )
  8219. goto ErrorReturn;
  8220. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  8221. {
  8222. if( pttTags[i].dwRequired is TRUE and
  8223. pttTags[i].bPresent is FALSE
  8224. )
  8225. {
  8226. Status = ERROR_INVALID_PARAMETER;
  8227. goto ErrorReturn;
  8228. }
  8229. }
  8230. for( j=0; j<dwTagCount; j++ )
  8231. {
  8232. switch(pdwTagType[j])
  8233. {
  8234. case 0:
  8235. {
  8236. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8237. if( wc is L'0' )
  8238. fState = FALSE;
  8239. else if ( wc is L'1' )
  8240. fState = TRUE;
  8241. else
  8242. {
  8243. Status = ERROR_INVALID_PARAMETER;
  8244. goto ErrorReturn;
  8245. }
  8246. break;
  8247. }
  8248. case 1:
  8249. {
  8250. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8251. if( wc is L'1' )
  8252. {
  8253. fStartup = TRUE;
  8254. }
  8255. else if ( wc is L'0' )
  8256. {
  8257. fStartup = FALSE;
  8258. }
  8259. else
  8260. {
  8261. Status = ERROR_INVALID_PARAMETER;
  8262. goto ErrorReturn;
  8263. }
  8264. break;
  8265. }
  8266. case 2:
  8267. {
  8268. DWORD dw = 0;
  8269. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8270. {
  8271. Status = ERROR_INVALID_PARAMETER;
  8272. goto ErrorReturn;
  8273. }
  8274. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8275. dwStart = dw;
  8276. fStart = TRUE;
  8277. break;
  8278. }
  8279. case 3:
  8280. {
  8281. DWORD dw = 0;
  8282. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8283. {
  8284. Status = ERROR_INVALID_PARAMETER;
  8285. goto ErrorReturn;
  8286. }
  8287. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8288. if( dw > 0 &&
  8289. dw < 60 ) // 1 minute
  8290. {
  8291. Status = ERROR_INVALID_PARAMETER;
  8292. goto ErrorReturn;
  8293. }
  8294. dwInterval = dw;
  8295. fInterval = TRUE;
  8296. break;
  8297. }
  8298. case 4:
  8299. {
  8300. DWORD dw = 0;
  8301. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8302. {
  8303. Status = ERROR_INVALID_PARAMETER;
  8304. goto ErrorReturn;
  8305. }
  8306. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8307. dwRetry = dw;
  8308. fRetry = TRUE;
  8309. break;
  8310. }
  8311. default:
  8312. {
  8313. Status = ERROR_INVALID_PARAMETER;
  8314. goto ErrorReturn;
  8315. }
  8316. }
  8317. }
  8318. {
  8319. if( wcslen(g_ServerNetBiosName) > 0 )
  8320. pTemp = g_ServerNetBiosName;
  8321. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  8322. if( Status isnot NO_ERROR )
  8323. goto ErrorReturn;
  8324. Status = RegCreateKeyEx(hServer,
  8325. PULLROOT,
  8326. 0,
  8327. NULL,
  8328. REG_OPTION_NON_VOLATILE,
  8329. KEY_ALL_ACCESS,
  8330. NULL,
  8331. &hPullRoot,
  8332. NULL);
  8333. if( Status isnot NO_ERROR )
  8334. goto ErrorReturn;
  8335. Status = RegSetValueEx(hPullRoot,
  8336. PERSISTENCE,
  8337. 0,
  8338. REG_DWORD,
  8339. (LPBYTE)&fState,
  8340. sizeof(BOOL));
  8341. if( Status isnot NO_ERROR )
  8342. goto ErrorReturn;
  8343. Status = RegSetValueEx(hPullRoot,
  8344. WINSCNF_INIT_TIME_RPL_NM,
  8345. 0,
  8346. REG_DWORD,
  8347. (LPBYTE)&fStartup,
  8348. sizeof(BOOL));
  8349. if( Status isnot NO_ERROR )
  8350. goto ErrorReturn;
  8351. if( fRetry )
  8352. {
  8353. Status = RegSetValueEx(hPullRoot,
  8354. WINSCNF_RETRY_COUNT_NM,
  8355. 0,
  8356. REG_DWORD,
  8357. (LPBYTE)&dwRetry,
  8358. sizeof(DWORD));
  8359. if( Status isnot NO_ERROR )
  8360. goto ErrorReturn;
  8361. }
  8362. if( fStart is TRUE or
  8363. fInterval is TRUE )
  8364. {
  8365. Status = RegCreateKeyEx(hServer,
  8366. DEFAULTPULL,
  8367. 0,
  8368. NULL,
  8369. REG_OPTION_NON_VOLATILE,
  8370. KEY_ALL_ACCESS,
  8371. NULL,
  8372. &hDefault,
  8373. NULL);
  8374. if( Status isnot NO_ERROR )
  8375. goto ErrorReturn;
  8376. if( fStart )
  8377. {
  8378. LPWSTR pwszTime = MakeTimeString(dwStart);
  8379. if( pwszTime is NULL )
  8380. {
  8381. Status = ERROR_NOT_ENOUGH_MEMORY;
  8382. goto ErrorReturn;
  8383. }
  8384. Status = RegSetValueEx(hDefault,
  8385. WINSCNF_SP_TIME_NM,
  8386. 0,
  8387. REG_SZ,
  8388. (LPBYTE)pwszTime,
  8389. (wcslen(pwszTime)+1)*sizeof(WCHAR));
  8390. WinsFreeMemory(pwszTime);
  8391. pwszTime = NULL;
  8392. if( Status isnot NO_ERROR )
  8393. goto ErrorReturn;
  8394. }
  8395. if( fInterval )
  8396. {
  8397. Status = RegSetValueEx(hDefault,
  8398. WINSCNF_RPL_INTERVAL_NM,
  8399. 0,
  8400. REG_DWORD,
  8401. (LPBYTE)&dwInterval,
  8402. sizeof(DWORD));
  8403. if( Status isnot NO_ERROR )
  8404. goto ErrorReturn;
  8405. }
  8406. }
  8407. }
  8408. CommonReturn:
  8409. if( Status is NO_ERROR )
  8410. {
  8411. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  8412. }
  8413. if( hPullRoot )
  8414. {
  8415. RegCloseKey(hPullRoot);
  8416. hPullRoot = NULL;
  8417. }
  8418. if( hDefault )
  8419. {
  8420. RegCloseKey(hDefault);
  8421. hDefault = NULL;
  8422. }
  8423. if( hServer )
  8424. {
  8425. RegCloseKey(hServer);
  8426. hServer = NULL;
  8427. }
  8428. if( pdwTagType )
  8429. {
  8430. WinsFreeMemory(pdwTagType);
  8431. pdwTagType = NULL;
  8432. }
  8433. if( pdwTagNum )
  8434. {
  8435. WinsFreeMemory(pdwTagNum);
  8436. pdwTagNum = NULL;
  8437. }
  8438. return Status;
  8439. ErrorReturn:
  8440. DisplayErrorMessage(EMSG_SRVR_SET_PULLPARAM,
  8441. Status);
  8442. goto CommonReturn;
  8443. }
  8444. DWORD
  8445. HandleSrvrSetPushparam(
  8446. IN LPCWSTR pwszMachine,
  8447. IN OUT LPWSTR *ppwcArguments,
  8448. IN DWORD dwCurrentIndex,
  8449. IN DWORD dwArgCount,
  8450. IN DWORD dwFlags,
  8451. IN LPCVOID pvData,
  8452. OUT BOOL *pbDone
  8453. )
  8454. /*++
  8455. Routine Description :
  8456. Set the default push parameters
  8457. Arguments :
  8458. All aguments are passes as array of wide char strings in ppwcArguments.
  8459. Compulsory : Server IP and persistence state
  8460. Optional : Start value and Time interval
  8461. Return Value:
  8462. Returns the status of the operation.
  8463. --*/
  8464. {
  8465. DWORD Status = NO_ERROR;
  8466. DWORD i, j, dwNumArgs, dwTagCount;
  8467. PDWORD pdwTagType = NULL,
  8468. pdwTagNum = NULL;
  8469. TAG_TYPE pttTags[] = {
  8470. {WINS_TOKEN_STATE, TRUE, FALSE},
  8471. {WINS_TOKEN_STARTUP, FALSE, FALSE},
  8472. {WINS_TOKEN_ADDRESSCHANGE, FALSE, FALSE},
  8473. {WINS_TOKEN_UPDATE, FALSE, FALSE},
  8474. };
  8475. DWORD dwUpdate = 3;
  8476. BOOL fStartup = FALSE,
  8477. IsStartup = FALSE,
  8478. fAddressChange = FALSE,
  8479. IsAddChange = FALSE,
  8480. fAdd = FALSE,
  8481. IsAdd = FALSE,
  8482. fUpdate = FALSE,
  8483. IsUpdate = FALSE,
  8484. fState = TRUE;
  8485. LPWSTR pTemp = NULL;
  8486. HKEY hServer = NULL,
  8487. hDefault = NULL,
  8488. hPushRoot = NULL;
  8489. if( dwArgCount < dwCurrentIndex + 1 )
  8490. {
  8491. DisplayMessage(g_hModule, HLP_SRVR_SET_PUSHPARAM_EX);
  8492. Status = ERROR_INVALID_PARAMETER;
  8493. goto ErrorReturn;
  8494. }
  8495. dwNumArgs = dwArgCount - dwCurrentIndex;
  8496. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8497. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8498. if( pdwTagType is NULL or
  8499. pdwTagNum is NULL )
  8500. {
  8501. Status = ERROR_NOT_ENOUGH_MEMORY;
  8502. goto ErrorReturn;
  8503. }
  8504. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  8505. Status = PreProcessCommand(ppwcArguments,
  8506. dwArgCount,
  8507. dwCurrentIndex,
  8508. pttTags,
  8509. &dwTagCount,
  8510. pdwTagType,
  8511. pdwTagNum);
  8512. if( Status isnot NO_ERROR )
  8513. goto ErrorReturn;
  8514. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  8515. {
  8516. if( pttTags[i].dwRequired is TRUE and
  8517. pttTags[i].bPresent is FALSE
  8518. )
  8519. {
  8520. Status = ERROR_INVALID_PARAMETER;
  8521. goto ErrorReturn;
  8522. }
  8523. }
  8524. for( j=0; j<dwTagCount; j++ )
  8525. {
  8526. switch(pdwTagType[j])
  8527. {
  8528. case 0:
  8529. {
  8530. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8531. if( wc is L'0' )
  8532. fState = FALSE;
  8533. else if ( wc is L'1' )
  8534. fState = TRUE;
  8535. else
  8536. {
  8537. Status = ERROR_INVALID_PARAMETER;
  8538. goto ErrorReturn;
  8539. }
  8540. break;
  8541. }
  8542. case 1:
  8543. {
  8544. WCHAR wc ;
  8545. IsStartup = TRUE;
  8546. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  8547. break;
  8548. wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8549. if( wc is L'1' )
  8550. {
  8551. fStartup = TRUE;
  8552. }
  8553. else if( wc is L'0' )
  8554. fStartup = 0;
  8555. else
  8556. {
  8557. Status = ERROR_INVALID_PARAMETER;
  8558. goto ErrorReturn;
  8559. }
  8560. break;
  8561. }
  8562. case 2:
  8563. {
  8564. WCHAR wc ;
  8565. IsAddChange = TRUE;
  8566. fAdd = TRUE;
  8567. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) < 1 )
  8568. break;
  8569. wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8570. if( wc is L'1' )
  8571. fAddressChange = TRUE;
  8572. else if( wc is L'0' )
  8573. fAddressChange = FALSE;
  8574. else
  8575. {
  8576. Status = ERROR_INVALID_PARAMETER;
  8577. goto ErrorReturn;
  8578. }
  8579. break;
  8580. }
  8581. case 3:
  8582. {
  8583. DWORD dw = 0;
  8584. IsUpdate = TRUE;
  8585. fUpdate = TRUE;
  8586. if( wcslen( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) < 1 )
  8587. break;
  8588. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8589. {
  8590. Status = ERROR_INVALID_PARAMETER;
  8591. goto ErrorReturn;
  8592. }
  8593. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8594. if( dw < 1000 )
  8595. dwUpdate = dw;
  8596. else
  8597. dwUpdate = 999;
  8598. break;
  8599. }
  8600. default:
  8601. {
  8602. Status = ERROR_INVALID_PARAMETER;
  8603. goto ErrorReturn;
  8604. }
  8605. }
  8606. }
  8607. {
  8608. if( wcslen(g_ServerNetBiosName) > 0 )
  8609. pTemp = g_ServerNetBiosName;
  8610. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  8611. if( Status isnot NO_ERROR )
  8612. goto ErrorReturn;
  8613. Status = RegCreateKeyEx(hServer,
  8614. PUSHROOT,
  8615. 0,
  8616. NULL,
  8617. REG_OPTION_NON_VOLATILE,
  8618. KEY_ALL_ACCESS,
  8619. NULL,
  8620. &hPushRoot,
  8621. NULL);
  8622. if( Status isnot NO_ERROR )
  8623. goto ErrorReturn;
  8624. Status = RegSetValueEx(hPushRoot,
  8625. PERSISTENCE,
  8626. 0,
  8627. REG_DWORD,
  8628. (LPBYTE)&fState,
  8629. sizeof(BOOL));
  8630. if( Status isnot NO_ERROR )
  8631. goto ErrorReturn;
  8632. if( IsStartup )
  8633. {
  8634. Status = RegSetValueEx(hPushRoot,
  8635. WINSCNF_INIT_TIME_RPL_NM,
  8636. 0,
  8637. REG_DWORD,
  8638. (LPBYTE)&fStartup,
  8639. sizeof(BOOL));
  8640. if( Status isnot NO_ERROR )
  8641. goto ErrorReturn;
  8642. }
  8643. if( fAdd )
  8644. {
  8645. Status = RegSetValueEx(hPushRoot,
  8646. WINSCNF_ADDCHG_TRIGGER_NM,
  8647. 0,
  8648. REG_DWORD,
  8649. (LPBYTE)&fAddressChange,
  8650. sizeof(DWORD));
  8651. if( Status isnot NO_ERROR )
  8652. goto ErrorReturn;
  8653. }
  8654. if( fUpdate is TRUE )
  8655. {
  8656. Status = RegCreateKeyEx(hServer,
  8657. DEFAULTPUSH,
  8658. 0,
  8659. NULL,
  8660. REG_OPTION_NON_VOLATILE,
  8661. KEY_ALL_ACCESS,
  8662. NULL,
  8663. &hDefault,
  8664. NULL);
  8665. if( Status isnot NO_ERROR )
  8666. goto ErrorReturn;
  8667. Status = RegSetValueEx(hDefault,
  8668. WINSCNF_UPDATE_COUNT_NM,
  8669. 0,
  8670. REG_DWORD,
  8671. (LPBYTE)&dwUpdate,
  8672. sizeof(DWORD));
  8673. if( Status isnot NO_ERROR )
  8674. goto ErrorReturn;
  8675. }
  8676. }
  8677. CommonReturn:
  8678. if( Status is NO_ERROR )
  8679. {
  8680. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  8681. }
  8682. if( hPushRoot )
  8683. {
  8684. RegCloseKey(hPushRoot);
  8685. hPushRoot = NULL;
  8686. }
  8687. if( hDefault )
  8688. {
  8689. RegCloseKey(hDefault);
  8690. hDefault = NULL;
  8691. }
  8692. if( hServer )
  8693. {
  8694. RegCloseKey(hServer);
  8695. hServer = NULL;
  8696. }
  8697. if( pdwTagType )
  8698. {
  8699. WinsFreeMemory(pdwTagType);
  8700. pdwTagType = NULL;
  8701. }
  8702. if( pdwTagNum )
  8703. {
  8704. WinsFreeMemory(pdwTagNum);
  8705. pdwTagNum = NULL;
  8706. }
  8707. return Status;
  8708. ErrorReturn:
  8709. DisplayErrorMessage(EMSG_SRVR_SET_PUSHPARAM,
  8710. Status);
  8711. goto CommonReturn;
  8712. }
  8713. DWORD
  8714. HandleSrvrSetReplicateflag(
  8715. IN LPCWSTR pwszMachine,
  8716. IN OUT LPWSTR *ppwcArguments,
  8717. IN DWORD dwCurrentIndex,
  8718. IN DWORD dwArgCount,
  8719. IN DWORD dwFlags,
  8720. IN LPCVOID pvData,
  8721. OUT BOOL *pbDone
  8722. )
  8723. /*++
  8724. Routine Description :
  8725. Set the replication flag
  8726. Arguments :
  8727. All aguments are passes as array of wide char strings in ppwcArguments.
  8728. Compulsory : Flag state
  8729. Return Value:
  8730. Returns the status of the operation.
  8731. --*/
  8732. {
  8733. DWORD Status = NO_ERROR;
  8734. DWORD i, j, dwNumArgs, dwTagCount;
  8735. PDWORD pdwTagType = NULL,
  8736. pdwTagNum = NULL;
  8737. TAG_TYPE pttTags[] = {
  8738. {WINS_TOKEN_STATE, TRUE, FALSE},
  8739. };
  8740. BOOL fReplicate = FALSE;
  8741. LPWSTR pTemp = NULL;
  8742. HKEY hServer = NULL,
  8743. hParameter = NULL;
  8744. if( dwArgCount < dwCurrentIndex + 1 )
  8745. {
  8746. DisplayMessage(g_hModule, HLP_SRVR_SET_REPLICATEFLAG_EX);
  8747. Status = ERROR_INVALID_PARAMETER;
  8748. goto ErrorReturn;
  8749. }
  8750. dwNumArgs = dwArgCount - dwCurrentIndex;
  8751. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8752. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8753. if( pdwTagType is NULL or
  8754. pdwTagNum is NULL )
  8755. {
  8756. Status = ERROR_NOT_ENOUGH_MEMORY;
  8757. goto ErrorReturn;
  8758. }
  8759. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  8760. Status = PreProcessCommand(ppwcArguments,
  8761. dwArgCount,
  8762. dwCurrentIndex,
  8763. pttTags,
  8764. &dwTagCount,
  8765. pdwTagType,
  8766. pdwTagNum);
  8767. if( Status isnot NO_ERROR )
  8768. goto ErrorReturn;
  8769. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  8770. {
  8771. if( pttTags[i].dwRequired is TRUE and
  8772. pttTags[i].bPresent is FALSE
  8773. )
  8774. {
  8775. Status = ERROR_INVALID_PARAMETER;
  8776. goto ErrorReturn;
  8777. }
  8778. }
  8779. for( j=0; j<dwTagCount; j++ )
  8780. {
  8781. switch(pdwTagType[j])
  8782. {
  8783. case 0:
  8784. {
  8785. DWORD dw = 0;
  8786. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  8787. {
  8788. Status = ERROR_INVALID_PARAMETER;
  8789. goto ErrorReturn;
  8790. }
  8791. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 0);
  8792. if( dw is 1 )
  8793. fReplicate = TRUE;
  8794. else if( dw is 0 )
  8795. fReplicate = FALSE;
  8796. else
  8797. {
  8798. Status = ERROR_INVALID_PARAMETER;
  8799. goto ErrorReturn;
  8800. }
  8801. break;
  8802. }
  8803. default:
  8804. {
  8805. Status = ERROR_INVALID_PARAMETER;
  8806. goto ErrorReturn;
  8807. }
  8808. }
  8809. }
  8810. {
  8811. if( wcslen(g_ServerNetBiosName) > 0 )
  8812. pTemp = g_ServerNetBiosName;
  8813. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  8814. if( Status isnot NO_ERROR )
  8815. goto ErrorReturn;
  8816. Status = RegCreateKeyEx(hServer,
  8817. PARAMETER,
  8818. 0,
  8819. NULL,
  8820. REG_OPTION_NON_VOLATILE,
  8821. KEY_ALL_ACCESS,
  8822. NULL,
  8823. &hParameter,
  8824. NULL);
  8825. if( Status isnot NO_ERROR )
  8826. goto ErrorReturn;
  8827. Status = RegSetValueEx(hParameter,
  8828. WINSCNF_RPL_ONLY_W_CNF_PNRS_NM,
  8829. 0,
  8830. REG_DWORD,
  8831. (LPBYTE)&fReplicate,
  8832. sizeof(BOOL));
  8833. if( Status isnot NO_ERROR )
  8834. goto ErrorReturn;
  8835. }
  8836. CommonReturn:
  8837. if( Status is NO_ERROR )
  8838. {
  8839. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  8840. }
  8841. if( hParameter )
  8842. {
  8843. RegCloseKey(hParameter);
  8844. hParameter = NULL;
  8845. }
  8846. if( hServer )
  8847. {
  8848. RegCloseKey(hServer);
  8849. hServer = NULL;
  8850. }
  8851. if( pdwTagType )
  8852. {
  8853. WinsFreeMemory(pdwTagType);
  8854. pdwTagType = NULL;
  8855. }
  8856. if( pdwTagNum )
  8857. {
  8858. WinsFreeMemory(pdwTagNum);
  8859. pdwTagNum = NULL;
  8860. }
  8861. return Status;
  8862. ErrorReturn:
  8863. DisplayErrorMessage(EMSG_SRVR_SET_REPLICATEFLAG,
  8864. Status);
  8865. goto CommonReturn;
  8866. }
  8867. DWORD
  8868. HandleSrvrSetLogparam(
  8869. IN LPCWSTR pwszMachine,
  8870. IN OUT LPWSTR *ppwcArguments,
  8871. IN DWORD dwCurrentIndex,
  8872. IN DWORD dwArgCount,
  8873. IN DWORD dwFlags,
  8874. IN LPCVOID pvData,
  8875. OUT BOOL *pbDone
  8876. )
  8877. /*++
  8878. Routine Description :
  8879. Set the logging parameters
  8880. Arguments :
  8881. All aguments are passes as array of wide char strings in ppwcArguments.
  8882. Optional : Log database change and detail event log options
  8883. Note : All parameters are optional.
  8884. Return Value:
  8885. Returns the status of the operation.
  8886. --*/
  8887. {
  8888. DWORD Status = NO_ERROR;
  8889. DWORD i, j, dwNumArgs, dwTagCount;
  8890. TAG_TYPE pttTags[] = {
  8891. {WINS_TOKEN_DBCHANGE, FALSE, FALSE},
  8892. {WINS_TOKEN_EVENT, FALSE, FALSE},
  8893. };
  8894. PDWORD pdwTagType = NULL,
  8895. pdwTagNum = NULL;
  8896. BOOL fDbChange = FALSE,
  8897. IsDbChange = FALSE,
  8898. fEvent = FALSE,
  8899. IsEvent = FALSE;
  8900. if( dwArgCount < dwCurrentIndex + 1 )
  8901. {
  8902. DisplayMessage(g_hModule,
  8903. EMSG_WINS_ERROR_SUCCESS);
  8904. goto CommonReturn;
  8905. }
  8906. dwNumArgs = dwArgCount - dwCurrentIndex;
  8907. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8908. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  8909. if( pdwTagType is NULL or
  8910. pdwTagNum is NULL )
  8911. {
  8912. Status = ERROR_NOT_ENOUGH_MEMORY;
  8913. goto ErrorReturn;
  8914. }
  8915. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  8916. Status = PreProcessCommand(ppwcArguments,
  8917. dwArgCount,
  8918. dwCurrentIndex,
  8919. pttTags,
  8920. &dwTagCount,
  8921. pdwTagType,
  8922. pdwTagNum);
  8923. if( Status isnot NO_ERROR )
  8924. goto ErrorReturn;
  8925. for( j=0; j<dwTagCount; j++ )
  8926. {
  8927. switch(pdwTagType[j])
  8928. {
  8929. case 0:
  8930. {
  8931. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8932. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is 0 )
  8933. {
  8934. fDbChange = FALSE;
  8935. IsDbChange = TRUE;
  8936. break;
  8937. }
  8938. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  8939. {
  8940. Status = ERROR_INVALID_PARAMETER;
  8941. goto ErrorReturn;
  8942. }
  8943. if( wc is L'0' )
  8944. {
  8945. fDbChange = FALSE;
  8946. }
  8947. else if( wc is L'1' )
  8948. {
  8949. fDbChange = TRUE;
  8950. }
  8951. else
  8952. {
  8953. Status = ERROR_INVALID_PARAMETER;
  8954. goto ErrorReturn;
  8955. }
  8956. IsDbChange = TRUE;
  8957. break;
  8958. }
  8959. case 1:
  8960. {
  8961. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  8962. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is 0 )
  8963. {
  8964. fEvent = FALSE;
  8965. IsEvent = TRUE;
  8966. break;
  8967. }
  8968. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  8969. {
  8970. Status = ERROR_INVALID_PARAMETER;
  8971. goto ErrorReturn;
  8972. }
  8973. if( wc is L'0' )
  8974. {
  8975. fEvent = FALSE;
  8976. }
  8977. else if( wc is L'1' )
  8978. {
  8979. fEvent = TRUE;
  8980. }
  8981. else
  8982. {
  8983. Status = ERROR_INVALID_PARAMETER;
  8984. goto ErrorReturn;
  8985. }
  8986. IsEvent = TRUE;
  8987. break;
  8988. }
  8989. default:
  8990. {
  8991. Status = ERROR_INVALID_PARAMETER;
  8992. goto ErrorReturn;
  8993. }
  8994. }
  8995. }
  8996. {
  8997. HKEY hServer = NULL,
  8998. hParameter = NULL;
  8999. LPWSTR pTemp = NULL;
  9000. DWORD dwType = REG_DWORD,
  9001. dwSize = sizeof(BOOL);
  9002. if( wcslen(g_ServerNetBiosName) > 0 )
  9003. pTemp = g_ServerNetBiosName;
  9004. Status = RegConnectRegistry(pTemp,
  9005. HKEY_LOCAL_MACHINE,
  9006. &hServer);
  9007. if( Status isnot NO_ERROR )
  9008. goto ErrorReturn;
  9009. Status = RegOpenKeyEx(hServer,
  9010. PARAMETER,
  9011. 0,
  9012. KEY_ALL_ACCESS,
  9013. &hParameter);
  9014. if( Status isnot NO_ERROR )
  9015. {
  9016. RegCloseKey(hServer);
  9017. hServer = NULL;
  9018. goto ErrorReturn;
  9019. }
  9020. if( IsDbChange )
  9021. {
  9022. Status = RegSetValueEx(hParameter,
  9023. WINSCNF_LOG_FLAG_NM,
  9024. 0,
  9025. dwType,
  9026. (LPBYTE)&fDbChange,
  9027. dwSize);
  9028. if( Status isnot NO_ERROR )
  9029. {
  9030. RegCloseKey(hServer);
  9031. hServer = NULL;
  9032. RegCloseKey(hParameter);
  9033. hParameter = NULL;
  9034. goto ErrorReturn;
  9035. }
  9036. }
  9037. if( IsEvent )
  9038. {
  9039. Status = RegSetValueEx(hParameter,
  9040. WINSCNF_LOG_DETAILED_EVTS_NM,
  9041. 0,
  9042. dwType,
  9043. (LPBYTE)&fEvent,
  9044. dwSize);
  9045. if( Status isnot NO_ERROR )
  9046. {
  9047. RegCloseKey(hServer);
  9048. hServer = NULL;
  9049. RegCloseKey(hParameter);
  9050. hParameter = NULL;
  9051. goto ErrorReturn;
  9052. }
  9053. }
  9054. if( hServer )
  9055. {
  9056. RegCloseKey(hServer);
  9057. hServer = NULL;
  9058. }
  9059. if( hParameter )
  9060. {
  9061. RegCloseKey(hParameter);
  9062. hParameter = NULL;
  9063. }
  9064. }
  9065. DisplayMessage(g_hModule,
  9066. EMSG_WINS_ERROR_SUCCESS);
  9067. CommonReturn:
  9068. if( pdwTagType )
  9069. {
  9070. WinsFreeMemory(pdwTagType);
  9071. pdwTagType = NULL;
  9072. }
  9073. if( pdwTagType )
  9074. {
  9075. WinsFreeMemory(pdwTagNum);
  9076. pdwTagNum = NULL;
  9077. }
  9078. return Status;
  9079. ErrorReturn:
  9080. DisplayErrorMessage(EMSG_SRVR_SET_LOGPARAM,
  9081. Status);
  9082. goto CommonReturn;
  9083. }
  9084. DWORD
  9085. HandleSrvrSetBurstparam(
  9086. IN LPCWSTR pwszMachine,
  9087. IN OUT LPWSTR *ppwcArguments,
  9088. IN DWORD dwCurrentIndex,
  9089. IN DWORD dwArgCount,
  9090. IN DWORD dwFlags,
  9091. IN LPCVOID pvData,
  9092. OUT BOOL *pbDone
  9093. )
  9094. /*++
  9095. Routine Description :
  9096. Set the burst handling parameters
  9097. Arguments :
  9098. All aguments are passes as array of wide char strings in ppwcArguments.
  9099. Compulsory : To enable or disable burst handling
  9100. Optional : Burst handling value.
  9101. Return Value:
  9102. Returns the status of the operation.
  9103. --*/
  9104. {
  9105. DWORD Status = NO_ERROR;
  9106. DWORD i, j, dwNumArgs, dwTagCount;
  9107. TAG_TYPE pttTags[] = {
  9108. {WINS_TOKEN_STATE, TRUE, FALSE},
  9109. {WINS_TOKEN_VALUE, FALSE, FALSE},
  9110. };
  9111. PDWORD pdwTagType = NULL,
  9112. pdwTagNum = NULL;
  9113. BOOL fState = FALSE,
  9114. fValue = FALSE;
  9115. DWORD dwValue = 0;
  9116. if( dwArgCount < dwCurrentIndex + 1 )
  9117. {
  9118. DisplayMessage(g_hModule,
  9119. HLP_SRVR_SET_BURSTPARAM_EX);
  9120. Status = ERROR_INVALID_PARAMETER;
  9121. goto ErrorReturn;
  9122. }
  9123. dwNumArgs = dwArgCount - dwCurrentIndex;
  9124. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9125. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9126. if( pdwTagType is NULL or
  9127. pdwTagNum is NULL )
  9128. {
  9129. Status = ERROR_NOT_ENOUGH_MEMORY;
  9130. goto ErrorReturn;
  9131. }
  9132. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  9133. Status = PreProcessCommand(ppwcArguments,
  9134. dwArgCount,
  9135. dwCurrentIndex,
  9136. pttTags,
  9137. &dwTagCount,
  9138. pdwTagType,
  9139. pdwTagNum);
  9140. if( Status isnot NO_ERROR )
  9141. goto ErrorReturn;
  9142. for( j=0; j<dwTagCount; j++ )
  9143. {
  9144. switch(pdwTagType[j])
  9145. {
  9146. case 0:
  9147. {
  9148. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  9149. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is 0 )
  9150. {
  9151. fState = FALSE;
  9152. break;
  9153. }
  9154. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  9155. {
  9156. Status = ERROR_INVALID_PARAMETER;
  9157. goto ErrorReturn;
  9158. }
  9159. if( wc is L'0' )
  9160. {
  9161. fState = FALSE;
  9162. }
  9163. else if( wc is L'1' )
  9164. {
  9165. fState = TRUE;
  9166. }
  9167. else
  9168. {
  9169. Status = ERROR_INVALID_PARAMETER;
  9170. goto ErrorReturn;
  9171. }
  9172. break;
  9173. }
  9174. case 1:
  9175. {
  9176. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  9177. {
  9178. Status = ERROR_INVALID_PARAMETER;
  9179. goto ErrorReturn;
  9180. }
  9181. dwValue = wcstoul(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  9182. if( dwValue < 50 or
  9183. dwValue > 5000 )
  9184. {
  9185. DisplayMessage(g_hModule,
  9186. EMSG_SRVR_BURST_PARAM_OUTOFRANGE);
  9187. Status = ERROR_INVALID_PARAMETER;
  9188. goto ErrorReturn;
  9189. }
  9190. fValue = TRUE;
  9191. break;
  9192. }
  9193. default:
  9194. {
  9195. Status = ERROR_INVALID_PARAMETER;
  9196. goto ErrorReturn;
  9197. }
  9198. }
  9199. }
  9200. {
  9201. HKEY hServer = NULL,
  9202. hParameter = NULL;
  9203. LPWSTR pTemp = NULL;
  9204. DWORD dwType = REG_DWORD,
  9205. dwSize = sizeof(BOOL);
  9206. if( wcslen(g_ServerNetBiosName) > 0 )
  9207. pTemp = g_ServerNetBiosName;
  9208. Status = RegConnectRegistry(pTemp,
  9209. HKEY_LOCAL_MACHINE,
  9210. &hServer);
  9211. if( Status isnot NO_ERROR )
  9212. goto ErrorReturn;
  9213. Status = RegOpenKeyEx(hServer,
  9214. PARAMETER,
  9215. 0,
  9216. KEY_ALL_ACCESS,
  9217. &hParameter);
  9218. if( Status isnot NO_ERROR )
  9219. {
  9220. RegCloseKey(hServer);
  9221. hServer = NULL;
  9222. goto ErrorReturn;
  9223. }
  9224. Status = RegSetValueEx(hParameter,
  9225. WINSCNF_BURST_HANDLING_NM,
  9226. 0,
  9227. dwType,
  9228. (LPBYTE)&fState,
  9229. dwSize);
  9230. if( Status isnot NO_ERROR )
  9231. {
  9232. RegCloseKey(hServer);
  9233. hServer = NULL;
  9234. RegCloseKey(hParameter);
  9235. hParameter = NULL;
  9236. goto ErrorReturn;
  9237. }
  9238. if( fValue )
  9239. {
  9240. dwSize = sizeof(DWORD);
  9241. Status = RegSetValueEx(hParameter,
  9242. WINSCNF_BURST_QUE_SIZE_NM,
  9243. 0,
  9244. dwType,
  9245. (LPBYTE)&dwValue,
  9246. dwSize);
  9247. if( Status isnot NO_ERROR )
  9248. {
  9249. RegCloseKey(hServer);
  9250. hServer = NULL;
  9251. RegCloseKey(hParameter);
  9252. hParameter = NULL;
  9253. goto ErrorReturn;
  9254. }
  9255. }
  9256. if( hServer )
  9257. {
  9258. RegCloseKey(hServer);
  9259. hServer = NULL;
  9260. }
  9261. if( hParameter )
  9262. {
  9263. RegCloseKey(hParameter);
  9264. hParameter = NULL;
  9265. }
  9266. }
  9267. DisplayMessage(g_hModule,
  9268. EMSG_WINS_ERROR_SUCCESS);
  9269. CommonReturn:
  9270. if( pdwTagType )
  9271. {
  9272. WinsFreeMemory(pdwTagType);
  9273. pdwTagType = NULL;
  9274. }
  9275. if( pdwTagType )
  9276. {
  9277. WinsFreeMemory(pdwTagNum);
  9278. pdwTagNum = NULL;
  9279. }
  9280. return Status;
  9281. ErrorReturn:
  9282. DisplayErrorMessage(EMSG_SRVR_SET_BURSTPARAM,
  9283. Status);
  9284. goto CommonReturn;
  9285. }
  9286. DWORD
  9287. HandleSrvrSetStartversion(
  9288. IN LPCWSTR pwszMachine,
  9289. IN OUT LPWSTR *ppwcArguments,
  9290. IN DWORD dwCurrentIndex,
  9291. IN DWORD dwArgCount,
  9292. IN DWORD dwFlags,
  9293. IN LPCVOID pvData,
  9294. OUT BOOL *pbDone
  9295. )
  9296. /*++
  9297. Routine Description :
  9298. Set start value of the version counter
  9299. Arguments :
  9300. All aguments are passes as array of wide char strings in ppwcArguments.
  9301. Compulsory : Version counter value in {high,low} format
  9302. Return Value:
  9303. Returns the status of the operation.
  9304. --*/
  9305. {
  9306. DWORD Status = 0;
  9307. DWORD i, j, dwTagCount, dwNumArgs;
  9308. TAG_TYPE pttTags[] = {
  9309. {WINS_TOKEN_VERSION, TRUE, FALSE},
  9310. };
  9311. WINSINTF_VERS_NO_T Version={0};
  9312. LPWSTR pServer = NULL;
  9313. PDWORD pdwTagNum = NULL,
  9314. pdwTagType = NULL;
  9315. HKEY hServer = NULL,
  9316. hParameter = NULL;
  9317. if( dwArgCount < dwCurrentIndex + 1 )
  9318. {
  9319. DisplayMessage(g_hModule,
  9320. HLP_SRVR_SET_STARTVERSION_EX);
  9321. Status = ERROR_INVALID_PARAMETER;
  9322. goto ErrorReturn;
  9323. }
  9324. dwNumArgs = dwArgCount - dwCurrentIndex;
  9325. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9326. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9327. if( pdwTagType is NULL or
  9328. pdwTagNum is NULL )
  9329. {
  9330. Status = ERROR_NOT_ENOUGH_MEMORY;
  9331. goto ErrorReturn;
  9332. }
  9333. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  9334. Status = PreProcessCommand(ppwcArguments,
  9335. dwArgCount,
  9336. dwCurrentIndex,
  9337. pttTags,
  9338. &dwTagCount,
  9339. pdwTagType,
  9340. pdwTagNum);
  9341. if( Status isnot NO_ERROR )
  9342. goto ErrorReturn;
  9343. for( j=0; j<dwTagCount; j++ )
  9344. {
  9345. switch(pdwTagType[0])
  9346. {
  9347. case 0:
  9348. {
  9349. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &Version);
  9350. if( Status isnot NO_ERROR )
  9351. goto ErrorReturn;
  9352. break;
  9353. }
  9354. default:
  9355. {
  9356. Status = ERROR_INVALID_PARAMETER;
  9357. goto ErrorReturn;
  9358. }
  9359. }
  9360. }
  9361. if( wcslen(g_ServerNetBiosName) > 0 )
  9362. pServer = g_ServerNetBiosName;
  9363. Status = RegConnectRegistry(pServer,
  9364. HKEY_LOCAL_MACHINE,
  9365. &hServer);
  9366. if( Status isnot NO_ERROR )
  9367. goto ErrorReturn;
  9368. Status = RegOpenKeyEx(hServer,
  9369. PARAMETER,
  9370. 0,
  9371. KEY_ALL_ACCESS,
  9372. &hParameter);
  9373. if( Status isnot NO_ERROR )
  9374. goto ErrorReturn;
  9375. Status = RegSetValueEx(hParameter,
  9376. WINSCNF_INIT_VERSNO_VAL_HW_NM,
  9377. 0,
  9378. REG_DWORD,
  9379. (LPBYTE)&Version.HighPart,
  9380. sizeof(DWORD));
  9381. if( Status isnot NO_ERROR )
  9382. goto ErrorReturn;
  9383. Status = RegSetValueEx(hParameter,
  9384. WINSCNF_INIT_VERSNO_VAL_LW_NM,
  9385. 0,
  9386. REG_DWORD,
  9387. (LPBYTE)&Version.LowPart,
  9388. sizeof(DWORD));
  9389. if( Status isnot NO_ERROR )
  9390. goto ErrorReturn;
  9391. DisplayMessage(g_hModule,
  9392. EMSG_WINS_ERROR_SUCCESS);
  9393. CommonReturn:
  9394. if( hServer )
  9395. {
  9396. RegCloseKey(hServer);
  9397. hServer = NULL;
  9398. }
  9399. if( hParameter )
  9400. {
  9401. RegCloseKey(hParameter);
  9402. hParameter = NULL;
  9403. }
  9404. if( pdwTagNum )
  9405. {
  9406. WinsFreeMemory(pdwTagNum);
  9407. pdwTagNum = NULL;
  9408. }
  9409. if( pdwTagType )
  9410. {
  9411. WinsFreeMemory(pdwTagType);
  9412. pdwTagType = NULL;
  9413. }
  9414. return Status;
  9415. ErrorReturn:
  9416. DisplayErrorMessage(EMSG_SRVR_SET_STARTVERSION,
  9417. Status);
  9418. goto CommonReturn;
  9419. }
  9420. DWORD
  9421. HandleSrvrSetPersMode(
  9422. IN LPCWSTR pwszMachine,
  9423. IN OUT LPWSTR *ppwcArguments,
  9424. IN DWORD dwCurrentIndex,
  9425. IN DWORD dwArgCount,
  9426. IN DWORD dwFlags,
  9427. IN LPCVOID pvData,
  9428. OUT BOOL *pbDone
  9429. )
  9430. /*++
  9431. Routine Description :
  9432. Set Persona Grata/Non-Grata mode
  9433. Arguments :
  9434. All aguments are passes as array of wide char strings in ppwcArguments.
  9435. Compulsory : Grat|Non-Grata
  9436. Return Value:
  9437. Returns the status of the operation.
  9438. --*/
  9439. {
  9440. DWORD Status = 0;
  9441. DWORD dwTagCount;
  9442. DWORD dwPersMode;
  9443. PDWORD pdwTagNum = NULL;
  9444. PDWORD pdwTagType = NULL;
  9445. TAG_TYPE pttTags[] = {{WINS_TOKEN_MODE, TRUE, FALSE},};
  9446. LPWSTR lpwszMode;
  9447. LPWSTR pTemp;
  9448. HKEY hServer, hPartner;
  9449. if( dwArgCount < dwCurrentIndex + 1 )
  9450. {
  9451. DisplayMessage(g_hModule, HLP_SRVR_SET_PGMODE_EX);
  9452. Status = ERROR_INVALID_PARAMETER;
  9453. goto ErrorReturn;
  9454. }
  9455. pdwTagType = WinsAllocateMemory((dwArgCount - dwCurrentIndex)*sizeof(DWORD));
  9456. pdwTagNum = WinsAllocateMemory((dwArgCount - dwCurrentIndex)*sizeof(DWORD));
  9457. if( pdwTagType is NULL || pdwTagNum is NULL )
  9458. {
  9459. Status = ERROR_NOT_ENOUGH_MEMORY;
  9460. goto ErrorReturn;
  9461. }
  9462. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  9463. Status = PreProcessCommand(ppwcArguments,
  9464. dwArgCount,
  9465. dwCurrentIndex,
  9466. pttTags,
  9467. &dwTagCount,
  9468. pdwTagType,
  9469. pdwTagNum);
  9470. if( Status isnot NO_ERROR )
  9471. goto ErrorReturn;
  9472. lpwszMode = ppwcArguments[dwCurrentIndex+pdwTagNum[0]];
  9473. if (wcslen(lpwszMode) == 1 &&
  9474. (lpwszMode[0] == L'0' || lpwszMode[0] == L'1'))
  9475. {
  9476. // set the value for 'persona grata mode'
  9477. dwPersMode = lpwszMode[0] == L'0' ? PERSMODE_NON_GRATA : PERSMODE_GRATA;
  9478. }
  9479. else
  9480. {
  9481. Status = ERROR_INVALID_PARAMETER;
  9482. goto ErrorReturn;
  9483. }
  9484. if( wcslen(g_ServerNetBiosName) > 0 )
  9485. {
  9486. pTemp = g_ServerNetBiosName;
  9487. }
  9488. Status = RegConnectRegistry(pTemp,
  9489. HKEY_LOCAL_MACHINE,
  9490. &hServer);
  9491. if( Status isnot NO_ERROR )
  9492. goto ErrorReturn;
  9493. Status = RegOpenKeyEx(hServer,
  9494. PARTNERROOT,
  9495. 0,
  9496. KEY_ALL_ACCESS,
  9497. &hPartner);
  9498. if (Status isnot NO_ERROR)
  9499. goto ErrorReturn;
  9500. Status = RegSetValueExA(
  9501. hPartner,
  9502. WINSCNF_PERSONA_MODE_NM,
  9503. 0,
  9504. REG_DWORD,
  9505. (LPVOID)&dwPersMode,
  9506. sizeof(DWORD));
  9507. DisplayMessage(g_hModule,
  9508. EMSG_WINS_ERROR_SUCCESS);
  9509. CommonReturn:
  9510. if( hServer )
  9511. {
  9512. RegCloseKey(hServer);
  9513. hServer = NULL;
  9514. }
  9515. if( hPartner )
  9516. {
  9517. RegCloseKey(hPartner);
  9518. hPartner = NULL;
  9519. }
  9520. if( pdwTagNum )
  9521. {
  9522. WinsFreeMemory(pdwTagNum);
  9523. pdwTagNum = NULL;
  9524. }
  9525. if( pdwTagType )
  9526. {
  9527. WinsFreeMemory(pdwTagType);
  9528. pdwTagType = NULL;
  9529. }
  9530. return Status;
  9531. ErrorReturn:
  9532. DisplayErrorMessage(EMSG_SRVR_SET_PGMODE, Status);
  9533. goto CommonReturn;
  9534. }
  9535. DWORD
  9536. HandleSrvrShowDatabase(
  9537. IN LPCWSTR pwszMachine,
  9538. IN OUT LPWSTR *ppwcArguments,
  9539. IN DWORD dwCurrentIndex,
  9540. IN DWORD dwArgCount,
  9541. IN DWORD dwFlags,
  9542. IN LPCVOID pvData,
  9543. OUT BOOL *pbDone
  9544. )
  9545. /*++
  9546. Routine Description :
  9547. Displays wins database based on (optionally)different filtering conditions
  9548. Arguments :
  9549. All aguments are passes as array of wide char strings in ppwcArguments.
  9550. Compulsory : Server ip whose database to be displayed
  9551. Optional : Different conditions
  9552. Return Value:
  9553. Returns the status of the operation.
  9554. --*/
  9555. {
  9556. DWORD Status = NO_ERROR;
  9557. WINSINTF_ADD_T WinsAdd = {0};
  9558. TAG_TYPE pttTags[] = { {WINS_TOKEN_SERVERS, TRUE, FALSE},
  9559. {WINS_TOKEN_RECORDTYPE, FALSE, FALSE},
  9560. {WINS_TOKEN_RECCOUNT, FALSE, FALSE},
  9561. {WINS_TOKEN_START, FALSE, FALSE},
  9562. {WINS_TOKEN_ENDCHAR, FALSE, FALSE},
  9563. {WINS_TOKEN_FILE, FALSE, FALSE},
  9564. };
  9565. PDWORD pdwTagType = NULL,
  9566. pdwTagNum = NULL,
  9567. pdwIp = NULL;
  9568. WCHAR wcFilter = L'\0';
  9569. CHAR chFilter = 0x00;
  9570. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1]={L'\0'};
  9571. WCHAR wcFile[MAX_PATH] = {L'\0'};
  9572. DWORD i, j, dwNumArgs, dwTagCount;
  9573. DWORD dwStart = WINSINTF_BEGINNING;
  9574. DWORD NoOfRecsDesired = (DWORD)~0;
  9575. DWORD TypeOfRec,
  9576. dwIpCount = 0,
  9577. dwRecCount = 0,
  9578. dwTotal = 0,
  9579. dw=0;
  9580. WINSINTF_RECS_T Recs = {0};
  9581. PWINSINTF_RECORD_ACTION_T pRow = NULL;
  9582. BOOL fFilter = FALSE,
  9583. fFile = FALSE;
  9584. BOOL fAll = FALSE,
  9585. fHeader = FALSE,
  9586. fError = FALSE,
  9587. fOnce = FALSE,
  9588. fNew = TRUE;
  9589. WINSINTF_RESULTS_T Results = {0};
  9590. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  9591. FILE *pFile = NULL;
  9592. BOOL fOpenFile = FALSE;
  9593. WCHAR wszFilter[3] = {L'\0'};
  9594. LPWSTR pwszTemp = NULL;
  9595. LPWSTR pwszTime = NULL;
  9596. NoOfRecsDesired = (DWORD)~0;
  9597. TypeOfRec = WINSINTF_BOTH;
  9598. if( dwArgCount < dwCurrentIndex + 1 )
  9599. {
  9600. DisplayMessage(g_hModule,
  9601. HLP_SRVR_SHOW_DATABASE_EX);
  9602. Status = ERROR_INVALID_PARAMETER;
  9603. goto ErrorReturn;
  9604. }
  9605. {
  9606. dwNumArgs = dwArgCount - dwCurrentIndex;
  9607. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9608. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  9609. if( pdwTagType is NULL or
  9610. pdwTagNum is NULL )
  9611. {
  9612. Status = ERROR_NOT_ENOUGH_MEMORY;
  9613. goto ErrorReturn;
  9614. }
  9615. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  9616. Status = PreProcessCommand(ppwcArguments,
  9617. dwArgCount,
  9618. dwCurrentIndex,
  9619. pttTags,
  9620. &dwTagCount,
  9621. pdwTagType,
  9622. pdwTagNum);
  9623. if( Status isnot NO_ERROR )
  9624. goto ErrorReturn;
  9625. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  9626. {
  9627. if( pttTags[i].dwRequired is TRUE and
  9628. pttTags[i].bPresent is FALSE
  9629. )
  9630. {
  9631. Status = ERROR_INVALID_PARAMETER;
  9632. goto ErrorReturn;
  9633. }
  9634. }
  9635. for( j=0; j<dwTagCount; j++ )
  9636. {
  9637. switch(pdwTagType[j])
  9638. {
  9639. case 0:
  9640. {
  9641. LPWSTR pwcTemp = NULL,
  9642. pwcTag = L",\r\n",
  9643. pwcToken = NULL,
  9644. pwszIps = NULL;
  9645. DWORD dwLen = 0;
  9646. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  9647. if( ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0] isnot L'{' or
  9648. ppwcArguments[dwCurrentIndex+pdwTagNum[j]][dwLen-1] isnot L'}')
  9649. {
  9650. Status = ERROR_INVALID_PARAMETER;
  9651. goto ErrorReturn;
  9652. }
  9653. pwcTemp = ppwcArguments[dwCurrentIndex+pdwTagNum[j]] + 1;
  9654. dwLen--;
  9655. ppwcArguments[dwCurrentIndex+pdwTagNum[j]][dwLen] = L'\0';
  9656. dwLen--;
  9657. if( dwLen <= 0 )
  9658. {
  9659. fAll = TRUE;
  9660. break;
  9661. }
  9662. if( dwLen < 7 )
  9663. {
  9664. Status = ERROR_INVALID_PARAMETER;
  9665. goto ErrorReturn;
  9666. }
  9667. pwszIps = WinsAllocateMemory(dwLen*sizeof(WCHAR));
  9668. if( pwszIps is NULL )
  9669. {
  9670. Status = ERROR_NOT_ENOUGH_MEMORY;
  9671. goto ErrorReturn;
  9672. }
  9673. wcscpy(pwszIps, pwcTemp);
  9674. pwcToken = wcstok(pwszIps, pwcTag);
  9675. dwIpCount = 0;
  9676. while( pwcToken isnot NULL )
  9677. {
  9678. PDWORD pdwTemp = NULL;
  9679. if( IsIpAddress( pwcToken ) is FALSE )
  9680. {
  9681. Status = ERROR_INVALID_PARAMETER;
  9682. WinsFreeMemory(pwszIps);
  9683. pwszIps = NULL;
  9684. goto ErrorReturn;
  9685. }
  9686. pdwTemp = pdwIp;
  9687. pdwIp = WinsAllocateMemory((dwIpCount+1)*sizeof(DWORD));
  9688. if( pdwIp is NULL )
  9689. {
  9690. Status = ERROR_NOT_ENOUGH_MEMORY;
  9691. WinsFreeMemory(pwszIps);
  9692. pwszIps = NULL;
  9693. if( pdwTemp )
  9694. {
  9695. WinsFreeMemory(pdwTemp);
  9696. pdwTemp = NULL;
  9697. }
  9698. goto ErrorReturn;
  9699. }
  9700. if( pdwTemp )
  9701. {
  9702. memcpy(pdwIp, pdwTemp, dwIpCount*sizeof(DWORD));
  9703. WinsFreeMemory(pdwTemp);
  9704. pdwTemp = NULL;
  9705. }
  9706. pdwIp[dwIpCount] = StringToIpAddress(pwcToken);
  9707. dwIpCount++;
  9708. pwcToken = wcstok(NULL, pwcTag);
  9709. }
  9710. if( pwszIps )
  9711. {
  9712. WinsFreeMemory(pwszIps);
  9713. pwszIps = NULL;
  9714. }
  9715. break;
  9716. }
  9717. case 1:
  9718. {
  9719. DWORD dw = 0;
  9720. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  9721. {
  9722. Status = ERROR_INVALID_PARAMETER;
  9723. goto ErrorReturn;
  9724. }
  9725. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  9726. if( dw is 1 )
  9727. TypeOfRec = WINSINTF_STATIC;
  9728. else if( dw is 2 )
  9729. TypeOfRec = WINSINTF_DYNAMIC;
  9730. else if( dw is 0 )
  9731. TypeOfRec = WINSINTF_BOTH;
  9732. else
  9733. {
  9734. Status = ERROR_INVALID_PARAMETER;
  9735. goto ErrorReturn;
  9736. }
  9737. break;
  9738. }
  9739. case 2:
  9740. {
  9741. DWORD dw = 0;
  9742. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  9743. {
  9744. Status = ERROR_INVALID_PARAMETER;
  9745. goto ErrorReturn;
  9746. }
  9747. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  9748. NoOfRecsDesired = dw;
  9749. break;
  9750. }
  9751. case 3:
  9752. {
  9753. DWORD dw = 0;
  9754. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE )
  9755. {
  9756. Status = ERROR_INVALID_PARAMETER;
  9757. goto ErrorReturn;
  9758. }
  9759. dw = STRTOUL(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL, 10);
  9760. if( dw is 0 )
  9761. {
  9762. dwStart = WINSINTF_BEGINNING;
  9763. }
  9764. else if ( dw is 1 )
  9765. {
  9766. dwStart = WINSINTF_END;
  9767. }
  9768. else
  9769. {
  9770. Status = ERROR_INVALID_PARAMETER;
  9771. goto ErrorReturn;
  9772. }
  9773. break;
  9774. }
  9775. case 4:
  9776. {
  9777. DWORD dwLen = 0, k=0;
  9778. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  9779. if( dwLen > 2 )
  9780. {
  9781. Status = ERROR_INVALID_PARAMETER;
  9782. goto ErrorReturn;
  9783. }
  9784. for( k=0; k<dwLen; k++ )
  9785. {
  9786. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  9787. if( isalpha(wc) is TRUE )
  9788. {
  9789. if( towlower(wc) < L'a' or
  9790. towlower(wc) > L'f' )
  9791. {
  9792. Status = ERROR_INVALID_PARAMETER;
  9793. goto ErrorReturn;
  9794. }
  9795. }
  9796. }
  9797. chFilter = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  9798. wcsncpy(wszFilter, ppwcArguments[dwCurrentIndex+pdwTagNum[j]], 2);
  9799. fFilter = TRUE;
  9800. break;
  9801. }
  9802. case 5:
  9803. {
  9804. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  9805. if( dwLen is 0 or
  9806. dwLen > MAX_PATH )
  9807. {
  9808. wcscpy(wcFile, L"wins.rec");
  9809. fFile = TRUE;
  9810. break;
  9811. }
  9812. wcscpy(wcFile, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  9813. fFile = TRUE;
  9814. break;
  9815. }
  9816. default:
  9817. {
  9818. Status = ERROR_INVALID_PARAMETER;
  9819. goto ErrorReturn;
  9820. }
  9821. }
  9822. }
  9823. }
  9824. if( fAll )
  9825. {
  9826. ResultsN.WinsStat.NoOfPnrs = 0;
  9827. ResultsN.WinsStat.pRplPnrs = 0;
  9828. ResultsN.NoOfWorkerThds = 1;
  9829. ResultsN.pAddVersMaps = NULL;
  9830. Status = WinsStatusNew(g_hBind, WINSINTF_E_CONFIG_ALL_MAPS, &ResultsN);
  9831. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  9832. {
  9833. //Try old API
  9834. Results.WinsStat.NoOfPnrs = 0;
  9835. Results.WinsStat.pRplPnrs = 0;
  9836. Status = WinsStatus(g_hBind, WINSINTF_E_CONFIG_ALL_MAPS, &Results);
  9837. fNew = FALSE;
  9838. }
  9839. if( Status isnot NO_ERROR )
  9840. goto ErrorReturn;
  9841. if( fNew )
  9842. {
  9843. dwIpCount = ResultsN.NoOfOwners;
  9844. }
  9845. else
  9846. {
  9847. dwIpCount = Results.NoOfOwners;
  9848. }
  9849. }
  9850. if( fFile is TRUE )
  9851. {
  9852. pFile = _wfopen(wcFile, L"a+");
  9853. if( pFile is NULL )
  9854. {
  9855. DisplayMessage(g_hModule,
  9856. EMSG_WINS_FILEOPEN_FAILED,
  9857. wcFile);
  9858. fOpenFile = FALSE;
  9859. }
  9860. else
  9861. {
  9862. fOpenFile = TRUE;
  9863. }
  9864. }
  9865. for( dw=0; dw<dwIpCount; dw++ )
  9866. {
  9867. LPSTR pszLastName = NULL;
  9868. DWORD dwLastNameLen = 0;
  9869. DWORD dwDesired = 0;
  9870. BOOL fDone = FALSE;
  9871. if( fHeader is FALSE )
  9872. {
  9873. DisplayMessage(g_hModule,
  9874. MSG_WINS_RECORD_DESC);
  9875. DisplayMessage(g_hModule,
  9876. MSG_WINS_RECORD_TABLE);
  9877. if( fOpenFile )
  9878. {
  9879. DumpMessage(g_hModule,
  9880. pFile,
  9881. FMSG_WINS_RECORDS_TABLE);
  9882. }
  9883. DisplayMessage(g_hModule,
  9884. WINS_FORMAT_LINE);
  9885. fHeader = TRUE;
  9886. }
  9887. WinsAdd.Len = 4;
  9888. WinsAdd.Type = 0;
  9889. if( fAll )
  9890. {
  9891. if( fNew )
  9892. {
  9893. WinsAdd.IPAdd = ResultsN.pAddVersMaps[dw].Add.IPAdd;
  9894. }
  9895. else
  9896. {
  9897. WinsAdd.IPAdd = Results.AddVersMaps[dw].Add.IPAdd;
  9898. }
  9899. }
  9900. else
  9901. {
  9902. WinsAdd.IPAdd = pdwIp[dw];
  9903. }
  9904. DisplayMessage(g_hModule,
  9905. MSG_SRVR_RETRIEVE_DATABASE,
  9906. IpAddressToString(WinsAdd.IPAdd));
  9907. fOnce = FALSE;
  9908. Status = NO_ERROR;
  9909. dwTotal = 0;
  9910. fDone = FALSE;
  9911. while( Status is NO_ERROR and
  9912. dwTotal < NoOfRecsDesired and
  9913. fDone is FALSE )
  9914. {
  9915. dwDesired = ( NoOfRecsDesired - dwTotal > 500 ) ? 500 : (NoOfRecsDesired - dwTotal);
  9916. if( Recs.pRow )
  9917. {
  9918. WinsFreeMem(Recs.pRow);
  9919. Recs.pRow = NULL;
  9920. }
  9921. memset( &Recs, 0x00, sizeof(WINSINTF_RECS_T));
  9922. Status = WinsGetDbRecsByName(g_hBind,
  9923. &WinsAdd,
  9924. dwStart,
  9925. fOnce ? pszLastName: NULL,
  9926. dwLastNameLen,
  9927. dwDesired,
  9928. TypeOfRec,
  9929. &Recs);
  9930. if( Status isnot NO_ERROR )
  9931. {
  9932. if( fOnce is FALSE )
  9933. {
  9934. DisplayMessage(g_hModule,
  9935. EMSG_SRVR_RETRIEVEDB_FAILED,
  9936. IpAddressToString(WinsAdd.IPAdd));
  9937. DisplayErrorMessage(EMSG_SRVR_ERROR_MESSAGE,
  9938. Status);
  9939. fError = TRUE;
  9940. }
  9941. else if ( Status isnot ERROR_REC_NON_EXISTENT )
  9942. {
  9943. DisplayMessage(g_hModule,
  9944. EMSG_SRVR_RETRIEVEDB_FAILED,
  9945. IpAddressToString(WinsAdd.IPAdd));
  9946. DisplayErrorMessage(EMSG_SRVR_ERROR_MESSAGE,
  9947. Status);
  9948. fError = TRUE;
  9949. }
  9950. Status = NO_ERROR;
  9951. break;
  9952. }
  9953. fOnce = TRUE;
  9954. dwTotal += Recs.NoOfRecs;
  9955. if( dwDesired > Recs.NoOfRecs )
  9956. {
  9957. fDone = TRUE;
  9958. }
  9959. pRow = Recs.pRow;
  9960. if( Recs.NoOfRecs is 0 )
  9961. {
  9962. DisplayMessage(g_hModule,
  9963. MSG_WINS_NO_RECORDS);
  9964. }
  9965. else
  9966. {
  9967. WCHAR Name[21] = {L'\0'};
  9968. WCHAR Type[2] = {L'\0'};
  9969. WCHAR State[2] = {L'\0'};
  9970. WCHAR Version[9] = {L'\0'};
  9971. WCHAR Group[2] = {L'\0'};
  9972. WCHAR IPAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  9973. WCHAR Buffer[16] = {L'\0'};
  9974. DWORD dwState = WINS_STATE_ACTIVE;
  9975. DWORD dwType = WINS_TYPE_STATIC;
  9976. DWORD dwGroup = WINS_GROUP_UNIQUE;
  9977. DWORD dwTempLen = 0;
  9978. struct tm* time = NULL;
  9979. int iType = 1;
  9980. for( j=0; j<Recs.NoOfRecs; j++ )
  9981. {
  9982. LPWSTR pwszGroup = NULL,
  9983. pwszStatic = NULL,
  9984. pwszType = NULL,
  9985. pwszState = NULL;
  9986. WCHAR wszGroup[100] = {L'\0'},
  9987. wszType[100] = {L'\0'},
  9988. wszState[100] = {L'\0'};
  9989. CHAR chEndChar = (CHAR)0x00;
  9990. DWORD dwGrouplen = 0,
  9991. dwTypelen = 0,
  9992. dwStatelen = 0;
  9993. memset( Name, 0x00, 21*sizeof(WCHAR));
  9994. if( j is Recs.NoOfRecs - 1 )
  9995. {
  9996. if( pszLastName )
  9997. {
  9998. WinsFreeMemory(pszLastName);
  9999. pszLastName = NULL;
  10000. }
  10001. pszLastName = WinsAllocateMemory(strlen(pRow->pName)+2);
  10002. if(pszLastName is NULL )
  10003. {
  10004. Status = ERROR_NOT_ENOUGH_MEMORY;
  10005. goto ErrorReturn;
  10006. }
  10007. memset(pszLastName, 0x00, strlen(pRow->pName)+2);
  10008. strcpy(pszLastName, pRow->pName);
  10009. //1B records detected at the boundary, swap 1st and
  10010. //16th char
  10011. if( pszLastName[15] == 0x1B )
  10012. {
  10013. CHAR ch = pszLastName[15];
  10014. pszLastName[15] = pszLastName[0];
  10015. pszLastName[0] = ch;
  10016. }
  10017. strcat(pszLastName, "\x01");
  10018. dwLastNameLen = pRow->NameLen+1;
  10019. }
  10020. if( pRow->NameLen > 16 )
  10021. i = 15;
  10022. else
  10023. i = pRow->NameLen;
  10024. chEndChar = pRow->pName[i];
  10025. pRow->pName[i] = (CHAR)0x20;
  10026. //pRow->pName[16] = '\0';
  10027. if( fFilter is TRUE )
  10028. {
  10029. if( chFilter isnot chEndChar )
  10030. {
  10031. pRow++;
  10032. continue;
  10033. }
  10034. }
  10035. pwszTemp = WinsOemToUnicode(pRow->pName, NULL);
  10036. if( pwszTemp is NULL )
  10037. {
  10038. Status = ERROR_NOT_ENOUGH_MEMORY;
  10039. goto ErrorReturn;
  10040. }
  10041. dwTempLen = wcslen(pwszTemp);
  10042. dwTempLen = (dwTempLen>16) ? 16 : dwTempLen;
  10043. wcsncpy(Name, pwszTemp, dwTempLen);
  10044. WinsFreeMemory(pwszTemp);
  10045. pwszTemp = NULL;
  10046. for( i=dwTempLen; i<16; i++ )
  10047. Name[i] = L' ';
  10048. Name[15] = L'[';
  10049. i=0;
  10050. WinsHexToString(Name+16, (LPBYTE)&chEndChar, 1);
  10051. Name[18] = L'h';
  10052. Name[19] = L']';
  10053. Name[20] = L'\0';
  10054. if( pRow->fStatic )
  10055. {
  10056. wcscpy(Type, L"S");
  10057. pwszType = L"STATIC ";
  10058. dwType = WINS_TYPE_STATIC;
  10059. }
  10060. else
  10061. {
  10062. wcscpy(Type, L"D");
  10063. pwszType = L"DYNAMIC";
  10064. dwType = WINS_TYPE_DYNAMIC;
  10065. }
  10066. if( pRow->State_e is WINSINTF_E_ACTIVE )
  10067. {
  10068. wcscpy(State, L"A");
  10069. pwszState = L"ACTIVE ";
  10070. dwState = WINS_STATE_ACTIVE;
  10071. }
  10072. else if( pRow->State_e is WINSINTF_E_RELEASED )
  10073. {
  10074. wcscpy(State, L"R");
  10075. pwszState = L"RELEASED ";
  10076. dwState = WINS_STATE_RELEASED;
  10077. }
  10078. else
  10079. {
  10080. wcscpy(State, L"T");
  10081. pwszState = L"TOMBSTONE";
  10082. dwState = WINS_STATE_TOMBSTONE;
  10083. }
  10084. if( pRow->TypOfRec_e is WINSINTF_E_UNIQUE )
  10085. {
  10086. wcscpy(Group,L"U");
  10087. pwszGroup = L"UNIQUE ";
  10088. dwGroup = WINS_GROUP_UNIQUE;
  10089. }
  10090. else if( pRow->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  10091. {
  10092. wcscpy(Group,L"N");
  10093. pwszGroup = L"GROUP ";
  10094. dwGroup = WINS_GROUP_GROUP;
  10095. }
  10096. else if( pRow->TypOfRec_e is WINSINTF_E_SPEC_GROUP )
  10097. {
  10098. if( pRow->pName[15] is 0x1C )
  10099. {
  10100. wcscpy(Group, L"D");
  10101. pwszGroup = L"DOMAIN NAME ";
  10102. dwGroup = WINS_GROUP_DOMAIN;
  10103. }
  10104. else
  10105. {
  10106. wcscpy(Group,L"I");
  10107. pwszGroup = L"INTERNET GROUP";
  10108. dwGroup = WINS_GROUP_INTERNET;
  10109. }
  10110. }
  10111. else
  10112. {
  10113. wcscpy(Group,L"M");
  10114. pwszGroup = L"MULTIHOMED ";
  10115. dwGroup = WINS_GROUP_MULTIHOMED;
  10116. }
  10117. dwStatelen = LoadStringW(g_hModule,
  10118. dwState,
  10119. wszState,
  10120. sizeof(wszState)/sizeof(WCHAR));
  10121. dwGrouplen = LoadStringW(g_hModule,
  10122. dwGroup,
  10123. wszGroup,
  10124. sizeof(wszGroup)/sizeof(WCHAR));
  10125. dwTypelen = LoadStringW(g_hModule,
  10126. dwType,
  10127. wszType,
  10128. sizeof(wszType)/sizeof(WCHAR));
  10129. memset(Version, L'\0', 9);
  10130. _itow((int)pRow->VersNo.LowPart, Buffer, 16);
  10131. wcsncpy(Version, Buffer, wcslen(Buffer)>8?8:wcslen(Buffer));
  10132. for( i=wcslen(Version); i<9; i++ )
  10133. Version[i] = L' ';
  10134. Version[8] = L'\0';
  10135. pwszTime = GetDateTimeString(pRow->TimeStamp,
  10136. TRUE,
  10137. &iType);
  10138. if ( pRow->TypOfRec_e is WINSINTF_E_UNIQUE or
  10139. pRow->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  10140. {
  10141. wcscpy(IPAdd, IpAddressToString(pRow->Add.IPAdd));
  10142. for( i=wcslen(IPAdd); i<MAX_IP_STRING_LEN; i++ )
  10143. IPAdd[i] = L' ';
  10144. IPAdd[MAX_IP_STRING_LEN] = L'\0';
  10145. DisplayMessage(g_hModule,
  10146. MSG_WINS_RECORD_ENTRY,
  10147. Name,
  10148. Type,
  10149. State,
  10150. Version,
  10151. Group,
  10152. IPAdd,
  10153. iType ? wszInfinite : pwszTime);
  10154. if( fOpenFile )
  10155. {
  10156. DumpMessage(g_hModule,
  10157. pFile,
  10158. FMSG_WINS_RECORD_ENTRY,
  10159. Name,
  10160. ( dwTypelen > 0 ) ? wszType : pwszType,
  10161. ( dwStatelen > 0 ) ? wszState : pwszState,
  10162. Version,
  10163. ( dwGrouplen > 0 ) ? wszGroup : pwszGroup,
  10164. iType ? wszInfinite : pwszTime,
  10165. IPAdd,
  10166. IpAddressToString(WinsAdd.IPAdd));
  10167. }
  10168. }
  10169. else //spec. grp or multihomed
  10170. {
  10171. DWORD ind;
  10172. BOOL fFirst = FALSE;
  10173. for ( ind=0; ind < pRow->NoOfAdds ; /*no third expr*/ )
  10174. {
  10175. struct in_addr InAddr1, InAddr2;
  10176. LPWSTR pwszTempAddr = NULL;
  10177. InAddr1.s_addr = htonl( (pRow->pAdd + ind++)->IPAdd);
  10178. InAddr2.s_addr = htonl( (pRow->pAdd + ind++)->IPAdd);
  10179. pwszTempAddr = WinsOemToUnicode(inet_ntoa(InAddr2), NULL);
  10180. if( pwszTempAddr is NULL )
  10181. {
  10182. Status = ERROR_NOT_ENOUGH_MEMORY;
  10183. goto ErrorReturn;
  10184. }
  10185. wcscpy(IPAdd, pwszTempAddr);
  10186. WinsFreeMemory(pwszTempAddr);
  10187. pwszTempAddr = NULL;
  10188. for( i=wcslen(IPAdd); i<MAX_IP_STRING_LEN; i++ )
  10189. IPAdd[i] = L' ';
  10190. if( fFirst is FALSE )
  10191. {
  10192. fFirst = TRUE;
  10193. DisplayMessage(g_hModule,
  10194. MSG_WINS_RECORD_ENTRY,
  10195. Name,
  10196. Type,
  10197. State,
  10198. Version,
  10199. Group,
  10200. IPAdd,
  10201. iType ? wszInfinite : pwszTime);
  10202. if( fOpenFile )
  10203. {
  10204. pwszTempAddr = WinsOemToUnicode(inet_ntoa(InAddr1), NULL);
  10205. if( pwszTempAddr is NULL )
  10206. {
  10207. Status = ERROR_NOT_ENOUGH_MEMORY;
  10208. goto ErrorReturn;
  10209. }
  10210. DumpMessage(g_hModule,
  10211. pFile,
  10212. FMSG_WINS_RECORD_ENTRY,
  10213. Name,
  10214. ( dwTypelen > 0 ) ? wszType : pwszType,
  10215. ( dwStatelen > 0 ) ? wszState : pwszState,
  10216. Version,
  10217. ( dwGrouplen > 0 ) ? wszGroup : pwszGroup,
  10218. iType ? wszInfinite : pwszTime,
  10219. IPAdd,
  10220. pwszTempAddr);
  10221. WinsFreeMemory(pwszTempAddr);
  10222. pwszTempAddr = NULL;
  10223. }
  10224. }
  10225. else
  10226. {
  10227. pwszTempAddr = WinsOemToUnicode(inet_ntoa(InAddr2), NULL);
  10228. if( pwszTempAddr is NULL )
  10229. {
  10230. Status = ERROR_NOT_ENOUGH_MEMORY;
  10231. goto ErrorReturn;
  10232. }
  10233. DisplayMessage(g_hModule,
  10234. MSG_WINS_RECORD_IPADDRESS,
  10235. pwszTempAddr);
  10236. WinsFreeMemory(pwszTempAddr);
  10237. pwszTempAddr = NULL;
  10238. if( fOpenFile )
  10239. {
  10240. pwszTempAddr = WinsOemToUnicode(inet_ntoa(InAddr1), NULL);
  10241. if( pwszTempAddr is NULL )
  10242. {
  10243. Status = ERROR_NOT_ENOUGH_MEMORY;
  10244. goto ErrorReturn;
  10245. }
  10246. DumpMessage(g_hModule,
  10247. pFile,
  10248. FMSG_WINS_RECORD_IPADDRESS,
  10249. IPAdd,
  10250. pwszTempAddr);
  10251. WinsFreeMemory(pwszTempAddr);
  10252. pwszTempAddr = NULL;
  10253. DumpMessage(g_hModule,
  10254. pFile,
  10255. WINS_FORMAT_LINE);
  10256. }
  10257. DisplayMessage(g_hModule,
  10258. WINS_FORMAT_LINE);
  10259. }
  10260. }
  10261. }
  10262. pRow++;
  10263. dwRecCount++;
  10264. if( pwszTime )
  10265. {
  10266. WinsFreeMemory(pwszTime);
  10267. pwszTime = NULL;
  10268. }
  10269. }
  10270. }
  10271. }
  10272. DisplayMessage(g_hModule,
  10273. MSG_WINS_RECORDS_RETRIEVED,
  10274. IpAddressToString(WinsAdd.IPAdd),
  10275. dwTotal);
  10276. }
  10277. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10278. if( fFilter )
  10279. {
  10280. DisplayMessage(g_hModule,
  10281. MSG_SRVR_FILTER_RECCOUNT,
  10282. wszFilter,
  10283. dwRecCount);
  10284. if( fOpenFile )
  10285. {
  10286. DumpMessage(g_hModule,
  10287. pFile,
  10288. MSG_SRVR_FILTER_RECCOUNT,
  10289. wszFilter,
  10290. dwRecCount);
  10291. }
  10292. }
  10293. else
  10294. {
  10295. DisplayMessage(g_hModule,
  10296. MSG_SRVR_TOTAL_RECCOUNT,
  10297. dwRecCount);
  10298. if( fOpenFile )
  10299. {
  10300. DumpMessage(g_hModule,
  10301. pFile,
  10302. MSG_SRVR_TOTAL_RECCOUNT,
  10303. dwRecCount);
  10304. }
  10305. }
  10306. CommonReturn:
  10307. if( Status is NO_ERROR and
  10308. fError is FALSE )
  10309. {
  10310. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  10311. }
  10312. else if( fError is TRUE )
  10313. {
  10314. DisplayMessage(g_hModule,
  10315. EMSG_WINS_RETRIEVEDB_PARTIAL);
  10316. }
  10317. if( fOpenFile )
  10318. {
  10319. fclose(pFile);
  10320. pFile = NULL;
  10321. }
  10322. if( Recs.pRow )
  10323. {
  10324. WinsFreeMem(Recs.pRow);
  10325. Recs.pRow = NULL;
  10326. }
  10327. if( pwszTime )
  10328. {
  10329. WinsFreeMemory(pwszTime);
  10330. pwszTime = NULL;
  10331. }
  10332. if( pdwTagType )
  10333. {
  10334. WinsFreeMemory(pdwTagType);
  10335. pdwTagType = NULL;
  10336. }
  10337. if( pdwTagNum )
  10338. {
  10339. WinsFreeMemory(pdwTagNum);
  10340. pdwTagNum = NULL;
  10341. }
  10342. return Status;
  10343. ErrorReturn:
  10344. DisplayErrorMessage(EMSG_SRVR_SHOW_DATABASE,
  10345. Status);
  10346. goto CommonReturn;
  10347. }
  10348. DWORD
  10349. HandleSrvrShowDomain(
  10350. IN LPCWSTR pwszMachine,
  10351. IN OUT LPWSTR *ppwcArguments,
  10352. IN DWORD dwCurrentIndex,
  10353. IN DWORD dwArgCount,
  10354. IN DWORD dwFlags,
  10355. IN LPCVOID pvData,
  10356. OUT BOOL *pbDone
  10357. )
  10358. /*++
  10359. Routine Description :
  10360. Displays the domain master browser records
  10361. Arguments :
  10362. All aguments are passes as array of wide char strings in ppwcArguments.
  10363. NONE.
  10364. Return Value:
  10365. Returns the status of the operation.
  10366. --*/
  10367. {
  10368. DWORD Status = NO_ERROR;
  10369. DWORD i = 0, j=0;
  10370. WINSINTF_BROWSER_NAMES_T Names;
  10371. PWINSINTF_BROWSER_INFO_T pInfo = NULL;
  10372. PWINSINTF_BROWSER_INFO_T pInfoSv = NULL;
  10373. WCHAR wcName[273] = {L'\0'},
  10374. wcCount[20] = {L'\0'};
  10375. for(i=0; i<273; i++ )
  10376. wcName[i] = L' ';
  10377. for(i=0; i<20; i++ )
  10378. wcCount[i] = L' ';
  10379. wcCount[19] = L'\0';
  10380. Names.EntriesRead = 0;
  10381. Names.pInfo = NULL;
  10382. Status = WinsGetBrowserNames(&g_BindData, &Names);
  10383. if (Status is NO_ERROR )
  10384. {
  10385. DisplayMessage(g_hModule,
  10386. MSG_WINS_DOMAIN_COUNT,
  10387. Names.EntriesRead);
  10388. DisplayMessage(g_hModule,
  10389. WINS_FORMAT_LINE);
  10390. DisplayMessage(g_hModule,
  10391. MSG_WINS_DOMAIN_TABLE);
  10392. pInfoSv = pInfo = Names.pInfo;
  10393. for(i=0; i < Names.EntriesRead; i++)
  10394. {
  10395. LPWSTR pwcTemp = NULL;
  10396. LPSTR pcTemp = NULL;
  10397. _itow((int)i, wcCount+3, 10);
  10398. for( j=wcslen(wcCount); j<19; j++ )
  10399. wcCount[j] = L' ';
  10400. wcCount[19] = L'\0';
  10401. pwcTemp = WinsOemToUnicode(pInfo->pName, NULL);
  10402. if( pwcTemp is NULL )
  10403. {
  10404. Status = ERROR_NOT_ENOUGH_MEMORY;
  10405. goto ErrorReturn;
  10406. }
  10407. wcsncpy(wcName+3, pwcTemp, (15>wcslen(pwcTemp))? wcslen(pwcTemp) : 15);
  10408. wcName[18] = L'[';
  10409. if( strlen(pInfo->pName ) > 15 )
  10410. pcTemp = pInfo->pName + 15;
  10411. else
  10412. pcTemp = pInfo->pName + strlen(pInfo->pName);
  10413. WinsHexToString(wcName+19,
  10414. (LPBYTE)pcTemp,
  10415. 1);
  10416. wcName[21] = L'h';
  10417. wcName[22] = L']';
  10418. if( strlen(pInfo->pName)>16)
  10419. {
  10420. wcName[23] = L'.';
  10421. wcscpy(wcName+24, pwcTemp+17);
  10422. wcName[wcslen(wcName)] = L'\0';
  10423. }
  10424. else
  10425. wcName[23] = L'\0';
  10426. DisplayMessage(g_hModule,
  10427. MSG_WINS_DOMAIN_ENTRY,
  10428. wcCount,
  10429. wcName);
  10430. if( pwcTemp )
  10431. {
  10432. WinsFreeMemory(pwcTemp);
  10433. pwcTemp = NULL;
  10434. }
  10435. pInfo++;
  10436. }
  10437. WinsFreeMem(pInfoSv);
  10438. pInfoSv = NULL;
  10439. if( Status is NO_ERROR )
  10440. DisplayMessage(g_hModule,
  10441. EMSG_WINS_ERROR_SUCCESS);
  10442. }
  10443. else
  10444. goto ErrorReturn;
  10445. CommonReturn:
  10446. if( pInfoSv )
  10447. {
  10448. WinsFreeMem(pInfoSv);
  10449. pInfoSv = NULL;
  10450. }
  10451. return Status;
  10452. ErrorReturn:
  10453. DisplayErrorMessage(EMSG_SRVR_SHOW_DOMAIN,
  10454. Status);
  10455. goto CommonReturn;
  10456. }
  10457. DWORD
  10458. HandleSrvrShowInfo(
  10459. IN LPCWSTR pwszMachine,
  10460. IN OUT LPWSTR *ppwcArguments,
  10461. IN DWORD dwCurrentIndex,
  10462. IN DWORD dwArgCount,
  10463. IN DWORD dwFlags,
  10464. IN LPCVOID pvData,
  10465. OUT BOOL *pbDone
  10466. )
  10467. /*++
  10468. Routine Description :
  10469. Displays server properties
  10470. Arguments :
  10471. All aguments are passes as array of wide char strings in ppwcArguments.
  10472. NONE.
  10473. Return Value:
  10474. Returns the status of the operation.
  10475. --*/
  10476. {
  10477. DWORD Status = NO_ERROR;
  10478. HKEY hServer = NULL,
  10479. hParameter = NULL,
  10480. hCCRoot = NULL;
  10481. LPWSTR pTemp = NULL;
  10482. WCHAR wcData[256] = {L'\0'};
  10483. DWORD dwType = REG_SZ,
  10484. dwLen = 256*sizeof(WCHAR),
  10485. dwData = 0,
  10486. dwLow = 0;
  10487. LPWSTR pwszDayString = NULL,
  10488. pwszTimeString = NULL;
  10489. if( wcslen(g_ServerNetBiosName) > 0 )
  10490. {
  10491. pTemp = g_ServerNetBiosName;
  10492. }
  10493. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  10494. if( Status isnot NO_ERROR )
  10495. goto ErrorReturn;
  10496. Status = RegOpenKeyEx(hServer,
  10497. PARAMETER,
  10498. 0,
  10499. KEY_READ,
  10500. &hParameter);
  10501. if( Status isnot NO_ERROR )
  10502. goto ErrorReturn;
  10503. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10504. DisplayMessage(g_hModule, MSG_WINS_DATABASE_BACKUPPARAM);
  10505. Status = RegQueryValueEx(hParameter,
  10506. WINSCNF_BACKUP_DIR_PATH_NM,
  10507. 0,
  10508. &dwType,
  10509. (LPBYTE)wcData,
  10510. &dwLen);
  10511. if( Status is NO_ERROR )
  10512. {
  10513. DisplayMessage(g_hModule,
  10514. MSG_WINS_DATABASE_BACKUPDIR,
  10515. wcData);
  10516. }
  10517. else
  10518. {
  10519. DisplayMessage(g_hModule,
  10520. MSG_WINS_DATABASE_BACKUPDIR,
  10521. wszUnknown);
  10522. }
  10523. dwLen = sizeof(DWORD);
  10524. dwType = REG_DWORD;
  10525. Status = RegQueryValueEx(hParameter,
  10526. WINSCNF_DO_BACKUP_ON_TERM_NM,
  10527. 0,
  10528. &dwType,
  10529. (LPBYTE)&dwData,
  10530. &dwLen);
  10531. if( Status is NO_ERROR )
  10532. {
  10533. DisplayMessage(g_hModule,
  10534. MSG_WINS_DATABASE_BACKUPONTERM,
  10535. dwData ? wszEnable : wszDisable);
  10536. }
  10537. else
  10538. {
  10539. DisplayMessage(g_hModule,
  10540. MSG_WINS_DATABASE_BACKUPONTERM,
  10541. wszUnknown);
  10542. }
  10543. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10544. DisplayMessage(g_hModule, MSG_WINS_NAMERECORD_SETTINGS);
  10545. {
  10546. WINSINTF_RESULTS_T Results = {0};
  10547. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  10548. BOOL fNew = TRUE;
  10549. ResultsN.WinsStat.NoOfPnrs = 0;
  10550. ResultsN.WinsStat.pRplPnrs = NULL;
  10551. ResultsN.NoOfWorkerThds = 1;
  10552. Status = WinsStatusNew(g_hBind,
  10553. WINSINTF_E_CONFIG,
  10554. &ResultsN);
  10555. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  10556. {
  10557. //Try old API
  10558. Results.WinsStat.NoOfPnrs = 0;
  10559. Results.WinsStat.pRplPnrs = 0;
  10560. Status = WinsStatus(g_hBind, WINSINTF_E_CONFIG, &Results);
  10561. fNew = FALSE;
  10562. }
  10563. if( Status is NO_ERROR )
  10564. {
  10565. if( fNew )
  10566. {
  10567. LPWSTR pwszDayString = NULL;
  10568. pwszDayString = MakeDayTimeString(ResultsN.RefreshInterval);
  10569. DisplayMessage(g_hModule,
  10570. MSG_WINS_NAMERECORD_REFRESHINTVL,
  10571. pwszDayString);
  10572. WinsFreeMemory(pwszDayString);
  10573. pwszDayString = NULL;
  10574. pwszDayString = MakeDayTimeString(ResultsN.TombstoneInterval);
  10575. DisplayMessage(g_hModule,
  10576. MSG_WINS_NAMERECORD_TOMBSTONEINTVL,
  10577. pwszDayString);
  10578. WinsFreeMemory(pwszDayString);
  10579. pwszDayString = NULL;
  10580. pwszDayString = MakeDayTimeString(ResultsN.TombstoneTimeout);
  10581. DisplayMessage(g_hModule,
  10582. MSG_WINS_NAMERECORD_TOMBSTONETMOUT,
  10583. pwszDayString);
  10584. WinsFreeMemory(pwszDayString);
  10585. pwszDayString = NULL;
  10586. pwszDayString = MakeDayTimeString(ResultsN.VerifyInterval);
  10587. DisplayMessage(g_hModule,
  10588. MSG_WINS_NAMERECORD_VERIFYINTVL,
  10589. pwszDayString);
  10590. WinsFreeMemory(pwszDayString);
  10591. pwszDayString = NULL;
  10592. if( ResultsN.WinsStat.pRplPnrs)
  10593. {
  10594. WinsFreeMem(ResultsN.WinsStat.pRplPnrs);
  10595. ResultsN.WinsStat.pRplPnrs = NULL;
  10596. }
  10597. }
  10598. else
  10599. {
  10600. LPWSTR pwszDayString = NULL;
  10601. pwszDayString = MakeDayTimeString(Results.RefreshInterval);
  10602. DisplayMessage(g_hModule,
  10603. MSG_WINS_NAMERECORD_REFRESHINTVL,
  10604. pwszDayString);
  10605. WinsFreeMemory(pwszDayString);
  10606. pwszDayString = NULL;
  10607. pwszDayString = MakeDayTimeString(Results.TombstoneInterval);
  10608. DisplayMessage(g_hModule,
  10609. MSG_WINS_NAMERECORD_TOMBSTONEINTVL,
  10610. pwszDayString);
  10611. WinsFreeMemory(pwszDayString);
  10612. pwszDayString = NULL;
  10613. pwszDayString = MakeDayTimeString(Results.TombstoneTimeout);
  10614. DisplayMessage(g_hModule,
  10615. MSG_WINS_NAMERECORD_TOMBSTONETMOUT,
  10616. pwszDayString);
  10617. WinsFreeMemory(pwszDayString);
  10618. pwszDayString = NULL;
  10619. pwszDayString = MakeDayTimeString(Results.VerifyInterval);
  10620. DisplayMessage(g_hModule,
  10621. MSG_WINS_NAMERECORD_VERIFYINTVL,
  10622. pwszDayString);
  10623. WinsFreeMemory(pwszDayString);
  10624. pwszDayString = NULL;
  10625. if( Results.WinsStat.pRplPnrs)
  10626. {
  10627. WinsFreeMem(Results.WinsStat.pRplPnrs);
  10628. Results.WinsStat.pRplPnrs = NULL;
  10629. }
  10630. }
  10631. }
  10632. else
  10633. {
  10634. DisplayMessage(g_hModule,
  10635. MSG_WINS_NAMERECORD_REFRESHINTVL,
  10636. wszUnknown);
  10637. DisplayMessage(g_hModule,
  10638. MSG_WINS_NAMERECORD_TOMBSTONEINTVL,
  10639. wszUnknown);
  10640. DisplayMessage(g_hModule,
  10641. MSG_WINS_NAMERECORD_TOMBSTONETMOUT,
  10642. wszUnknown);
  10643. DisplayMessage(g_hModule,
  10644. MSG_WINS_NAMERECORD_VERIFYINTVL,
  10645. wszUnknown);
  10646. }
  10647. }
  10648. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10649. DisplayMessage(g_hModule, MSG_WINS_DBCC_PARAM);
  10650. Status = RegOpenKeyEx(hParameter,
  10651. CC,
  10652. 0,
  10653. KEY_READ,
  10654. &hCCRoot);
  10655. if( Status isnot NO_ERROR )
  10656. {
  10657. DisplayMessage(g_hModule,
  10658. MSG_WINS_DBCC_STATE,
  10659. wszDisable);
  10660. }
  10661. else
  10662. {
  10663. DisplayMessage(g_hModule,
  10664. MSG_WINS_DBCC_STATE,
  10665. wszEnable);
  10666. dwType = REG_DWORD;
  10667. dwData = 0;
  10668. dwLen = sizeof(DWORD);
  10669. Status = RegQueryValueEx(hCCRoot,
  10670. WINSCNF_CC_MAX_RECS_AAT_NM,
  10671. 0,
  10672. &dwType,
  10673. (LPBYTE)&dwData,
  10674. &dwLen);
  10675. if( Status is NO_ERROR )
  10676. {
  10677. WCHAR Buffer[20] = {L'\0'};
  10678. _itow(dwData, Buffer, 10);
  10679. DisplayMessage(g_hModule,
  10680. MSG_WINS_DBCC_MAXCOUNT,
  10681. Buffer);
  10682. }
  10683. else
  10684. {
  10685. DisplayMessage(g_hModule,
  10686. MSG_WINS_DBCC_MAXCOUNT,
  10687. wszUnknown);
  10688. }
  10689. dwType = REG_DWORD;
  10690. dwData = 0;
  10691. dwLen = sizeof(DWORD);
  10692. Status = RegQueryValueEx(hCCRoot,
  10693. WINSCNF_CC_USE_RPL_PNRS_NM,
  10694. 0,
  10695. &dwType,
  10696. (LPBYTE)&dwData,
  10697. &dwLen);
  10698. if( Status is NO_ERROR )
  10699. {
  10700. DisplayMessage(g_hModule,
  10701. MSG_WINS_DBCC_CHECKAGAINST,
  10702. dwData ? wszRandom : wszOwner);
  10703. }
  10704. else
  10705. {
  10706. DisplayMessage(g_hModule,
  10707. MSG_WINS_DBCC_CHECKAGAINST,
  10708. wszUnknown);
  10709. }
  10710. dwType = REG_DWORD;
  10711. dwData = 0;
  10712. dwLen = sizeof(DWORD);
  10713. Status = RegQueryValueEx(hCCRoot,
  10714. WINSCNF_CC_INTVL_NM,
  10715. 0,
  10716. &dwType,
  10717. (LPBYTE)&dwData,
  10718. &dwLen);
  10719. if( Status is NO_ERROR )
  10720. {
  10721. WCHAR Buffer[5] = {L'\0'};
  10722. _itow(dwData/(60*60), Buffer, 10);
  10723. DisplayMessage(g_hModule,
  10724. MSG_WINS_DBCC_CHECKEVERY,
  10725. Buffer);
  10726. }
  10727. else
  10728. {
  10729. DisplayMessage(g_hModule,
  10730. MSG_WINS_DBCC_CHECKEVERY,
  10731. wszUnknown);
  10732. }
  10733. memset(wcData, 0x00, 256*sizeof(WCHAR));
  10734. dwType = REG_SZ;
  10735. dwLen = 256*sizeof(WCHAR);
  10736. Status = RegQueryValueEx(hCCRoot,
  10737. WINSCNF_SP_TIME_NM,
  10738. 0,
  10739. &dwType,
  10740. (LPBYTE)wcData,
  10741. &dwLen);
  10742. if( Status is NO_ERROR )
  10743. {
  10744. DisplayMessage(g_hModule,
  10745. MSG_WINS_DBCC_STARTAT,
  10746. wcData);
  10747. }
  10748. else
  10749. {
  10750. DisplayMessage(g_hModule,
  10751. MSG_WINS_DBCC_STARTAT,
  10752. wszUnknown);
  10753. }
  10754. }
  10755. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10756. DisplayMessage(g_hModule, MSG_WINS_LOGGING_PARAM);
  10757. dwType = REG_DWORD;
  10758. dwData = 0;
  10759. dwLen = sizeof(DWORD);
  10760. Status = RegQueryValueEx(hParameter,
  10761. WINSCNF_LOG_FLAG_NM,
  10762. 0,
  10763. &dwType,
  10764. (LPBYTE)&dwData,
  10765. &dwLen);
  10766. if( Status is NO_ERROR )
  10767. {
  10768. DisplayMessage(g_hModule,
  10769. MSG_WINS_LOGGING_FLAG,
  10770. dwData ? wszEnable : wszDisable);
  10771. }
  10772. else
  10773. {
  10774. DisplayMessage(g_hModule,
  10775. MSG_WINS_LOGGING_FLAG,
  10776. wszUnknown);
  10777. }
  10778. dwType = REG_DWORD;
  10779. dwData = 0;
  10780. dwLen = sizeof(DWORD);
  10781. Status = RegQueryValueEx(hParameter,
  10782. WINSCNF_LOG_DETAILED_EVTS_NM,
  10783. 0,
  10784. &dwType,
  10785. (LPBYTE)&dwData,
  10786. &dwLen);
  10787. if( Status is NO_ERROR )
  10788. {
  10789. DisplayMessage(g_hModule,
  10790. MSG_WINS_LOGGING_DETAILS,
  10791. dwData ? wszEnable : wszDisable);
  10792. }
  10793. else
  10794. {
  10795. DisplayMessage(g_hModule,
  10796. MSG_WINS_LOGGING_DETAILS,
  10797. wszUnknown);
  10798. }
  10799. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10800. DisplayMessage(g_hModule, MSG_WINS_BURSTHNDL_PARAM);
  10801. dwType = REG_DWORD;
  10802. dwData = 0;
  10803. dwLen = sizeof(DWORD);
  10804. Status = RegQueryValueEx(hParameter,
  10805. WINSCNF_BURST_HANDLING_NM,
  10806. 0,
  10807. &dwType,
  10808. (LPBYTE)&dwData,
  10809. &dwLen);
  10810. if( Status is NO_ERROR )
  10811. {
  10812. DisplayMessage(g_hModule,
  10813. MSG_WINS_BURSTHNDL_STATE,
  10814. dwData ? wszEnable : wszDisable);
  10815. if( dwData > 0 )
  10816. {
  10817. dwType = REG_DWORD;
  10818. dwData = 0;
  10819. dwLen = sizeof(DWORD);
  10820. Status = RegQueryValueEx(hParameter,
  10821. WINSCNF_BURST_QUE_SIZE_NM,
  10822. 0,
  10823. &dwType,
  10824. (LPBYTE)&dwData,
  10825. &dwLen);
  10826. if( Status is NO_ERROR )
  10827. {
  10828. WCHAR Buffer[10] = {L'\0'};
  10829. _itow(dwData, Buffer, 10);
  10830. DisplayMessage(g_hModule,
  10831. MSG_WINS_BURSTHNDL_SIZE,
  10832. Buffer);
  10833. }
  10834. else
  10835. {
  10836. DisplayMessage(g_hModule,
  10837. MSG_WINS_BURSTHNDL_SIZE,
  10838. wszUnknown);
  10839. }
  10840. }
  10841. }
  10842. else
  10843. {
  10844. DisplayMessage(g_hModule,
  10845. MSG_WINS_BURSTHNDL_STATE,
  10846. wszUnknown);
  10847. }
  10848. DisplayMessage(g_hModule,
  10849. WINS_FORMAT_LINE);
  10850. dwType = REG_DWORD;
  10851. dwData = 0;
  10852. dwLen = sizeof(DWORD);
  10853. Status = RegQueryValueEx(hParameter,
  10854. WINSCNF_INIT_VERSNO_VAL_HW_NM,
  10855. NULL,
  10856. &dwType,
  10857. (LPBYTE)&dwData,
  10858. &dwLen);
  10859. dwLow = 0;
  10860. Status = RegQueryValueEx(hParameter,
  10861. WINSCNF_INIT_VERSNO_VAL_LW_NM,
  10862. NULL,
  10863. &dwType,
  10864. (LPBYTE)&dwLow,
  10865. &dwLen);
  10866. if(Status is NO_ERROR )
  10867. {
  10868. wsprintf(wcData, L" %x , %x", dwData, dwLow);
  10869. DisplayMessage(g_hModule,
  10870. MSG_SRVR_START_VERSION,
  10871. wcData);
  10872. }
  10873. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  10874. CommonReturn:
  10875. if( Status is NO_ERROR )
  10876. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  10877. if( hCCRoot )
  10878. {
  10879. RegCloseKey(hCCRoot);
  10880. hCCRoot = NULL;
  10881. }
  10882. if( hParameter )
  10883. {
  10884. RegCloseKey(hParameter);
  10885. hParameter = NULL;
  10886. }
  10887. if( hServer )
  10888. {
  10889. RegCloseKey(hServer);
  10890. hServer = NULL;
  10891. }
  10892. return Status;
  10893. ErrorReturn:
  10894. DisplayErrorMessage(EMSG_SRVR_SHOW_INFO,
  10895. Status);
  10896. goto CommonReturn;
  10897. }
  10898. DWORD
  10899. HandleSrvrShowPartner(
  10900. IN LPCWSTR pwszMachine,
  10901. IN OUT LPWSTR *ppwcArguments,
  10902. IN DWORD dwCurrentIndex,
  10903. IN DWORD dwArgCount,
  10904. IN DWORD dwFlags,
  10905. IN LPCVOID pvData,
  10906. OUT BOOL *pbDone
  10907. )
  10908. /*++
  10909. Routine Description :
  10910. Displays the list of Partners optionally based on the partner type.
  10911. Arguments :
  10912. All aguments are passes as array of wide char strings in ppwcArguments.
  10913. Optional : Partner type - Pull or Push or Both(default)
  10914. Return Value:
  10915. Returns the status of the operation.
  10916. --*/
  10917. {
  10918. DWORD Status = NO_ERROR;
  10919. DWORD i, j, dwNumArgs, dwTagCount, dwCount;
  10920. TAG_TYPE pttTags[] = {
  10921. {WINS_TOKEN_TYPE, FALSE, FALSE}
  10922. };
  10923. PDWORD pdwTagType = NULL,
  10924. pdwTagNum = NULL;
  10925. DWORD p = 0;
  10926. typedef enum {all=0, pull, push, both}eType;
  10927. eType Type = all;
  10928. BOOL fPush = TRUE,
  10929. fPull = TRUE;
  10930. HKEY hServer = NULL,
  10931. hPullRoot = NULL,
  10932. hPushRoot = NULL;
  10933. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN] = {L'\0'};
  10934. WCHAR wcServer[256] = {L'\0'};
  10935. DWORD dwLen = 0;
  10936. typedef struct _Server_List {
  10937. WCHAR wcServerIpAddress[MAX_IP_STRING_LEN + 1];
  10938. WCHAR wcServerName[1024];
  10939. eType etype;
  10940. }Server_List, *PServer_List;
  10941. PServer_List pServerList = NULL;
  10942. LPWSTR pwszServerList = NULL;
  10943. LPWSTR pTemp = NULL;
  10944. dwCount = 0;
  10945. if( dwArgCount >= dwCurrentIndex + 1 )
  10946. {
  10947. dwNumArgs = dwArgCount - dwCurrentIndex;
  10948. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  10949. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  10950. if( pdwTagType is NULL or
  10951. pdwTagNum is NULL )
  10952. {
  10953. Status = ERROR_NOT_ENOUGH_MEMORY;
  10954. goto ErrorReturn;
  10955. }
  10956. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  10957. Status = PreProcessCommand(ppwcArguments,
  10958. dwArgCount,
  10959. dwCurrentIndex,
  10960. pttTags,
  10961. &dwTagCount,
  10962. pdwTagType,
  10963. pdwTagNum);
  10964. if( Status isnot NO_ERROR )
  10965. goto ErrorReturn;
  10966. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  10967. {
  10968. if( pttTags[i].dwRequired is TRUE and
  10969. pttTags[i].bPresent is FALSE
  10970. )
  10971. {
  10972. Status = ERROR_INVALID_PARAMETER;
  10973. goto ErrorReturn;
  10974. }
  10975. }
  10976. for( j=0; j<dwTagCount; j++ )
  10977. {
  10978. switch(pdwTagType[j])
  10979. {
  10980. case 0:
  10981. {
  10982. WCHAR wc = L'\0';
  10983. if( IsPureNumeric(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) is FALSE or
  10984. wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 1 )
  10985. {
  10986. Status = ERROR_INVALID_PARAMETER;
  10987. goto ErrorReturn;
  10988. }
  10989. wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  10990. if( wc is L'0' )
  10991. {
  10992. Type = all;
  10993. }
  10994. if( wc is L'1' )
  10995. {
  10996. Type = pull;
  10997. break;
  10998. }
  10999. else if( wc is L'2' )
  11000. {
  11001. Type = push;
  11002. break;
  11003. }
  11004. else if ( wc is L'3' )
  11005. {
  11006. Type = both;
  11007. break;
  11008. }
  11009. else
  11010. {
  11011. Status = ERROR_INVALID_PARAMETER;
  11012. break;
  11013. }
  11014. break;
  11015. }
  11016. default:
  11017. {
  11018. Status = ERROR_INVALID_PARAMETER;
  11019. goto ErrorReturn;
  11020. }
  11021. }
  11022. }
  11023. }
  11024. if( wcslen(g_ServerNetBiosName) > 0 )
  11025. {
  11026. pTemp = g_ServerNetBiosName;
  11027. }
  11028. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  11029. if( Status isnot NO_ERROR )
  11030. goto ErrorReturn;
  11031. Status = RegOpenKeyEx(hServer,
  11032. PULLROOT,
  11033. 0,
  11034. KEY_READ,
  11035. &hPullRoot);
  11036. if( Status isnot ERROR_FILE_NOT_FOUND and
  11037. Status isnot NO_ERROR )
  11038. goto ErrorReturn;
  11039. Status = RegOpenKeyEx(hServer,
  11040. PUSHROOT,
  11041. 0,
  11042. KEY_READ,
  11043. &hPushRoot);
  11044. if( Status isnot ERROR_FILE_NOT_FOUND and
  11045. Status isnot NO_ERROR )
  11046. goto ErrorReturn;
  11047. if( hPullRoot is NULL and
  11048. hPushRoot is NULL )
  11049. {
  11050. goto ErrorReturn;
  11051. }
  11052. Status = NO_ERROR;
  11053. {
  11054. DWORD dwSubkey = 0;
  11055. HKEY hKey = NULL;
  11056. if (hPullRoot != NULL)
  11057. {
  11058. Status = RegQueryInfoKey(hPullRoot,
  11059. NULL,
  11060. NULL,
  11061. NULL,
  11062. &dwSubkey,
  11063. NULL,
  11064. NULL,
  11065. NULL,
  11066. NULL,
  11067. NULL,
  11068. NULL,
  11069. NULL);
  11070. if (Status isnot NO_ERROR)
  11071. {
  11072. goto ErrorReturn;
  11073. }
  11074. }
  11075. if( dwSubkey > 0 )
  11076. {
  11077. pServerList = WinsAllocateMemory(dwSubkey*sizeof(Server_List));
  11078. if( pServerList is NULL )
  11079. {
  11080. Status = ERROR_NOT_ENOUGH_MEMORY;
  11081. goto ErrorReturn;
  11082. }
  11083. for( j=0; j<dwSubkey; j++ )
  11084. {
  11085. DWORD dwLen = (MAX_IP_STRING_LEN + 1)*sizeof(WCHAR);
  11086. DWORD dwType = REG_SZ;
  11087. Status = RegEnumKeyEx(hPullRoot,
  11088. j,
  11089. pServerList[j].wcServerIpAddress,
  11090. &dwLen,
  11091. NULL,
  11092. NULL,
  11093. NULL,
  11094. NULL);
  11095. if( Status isnot NO_ERROR )
  11096. {
  11097. if( Status is ERROR_FILE_NOT_FOUND )
  11098. {
  11099. continue;
  11100. }
  11101. else
  11102. {
  11103. goto ErrorReturn;
  11104. }
  11105. }
  11106. Status = RegOpenKeyEx(hPullRoot,
  11107. pServerList[j].wcServerIpAddress,
  11108. 0,
  11109. KEY_READ,
  11110. &hKey);
  11111. if( Status isnot NO_ERROR )
  11112. {
  11113. if( Status is ERROR_FILE_NOT_FOUND )
  11114. {
  11115. continue;
  11116. }
  11117. else
  11118. {
  11119. goto ErrorReturn;
  11120. }
  11121. }
  11122. dwLen = 1024*sizeof(WCHAR);
  11123. Status = RegQueryValueEx(hKey,
  11124. L"NetBIOSName",
  11125. 0,
  11126. &dwType,
  11127. (LPBYTE)pServerList[j].wcServerName,
  11128. &dwLen);
  11129. if( Status isnot NO_ERROR )
  11130. {
  11131. if( Status is ERROR_FILE_NOT_FOUND )
  11132. {
  11133. wcscpy(pServerList[j].wcServerName, wszUnknown);
  11134. }
  11135. else
  11136. {
  11137. goto ErrorReturn;
  11138. }
  11139. }
  11140. pServerList[j].etype = pull;
  11141. RegCloseKey(hKey);
  11142. hKey = NULL;
  11143. }
  11144. }
  11145. i = dwSubkey;
  11146. dwCount = i;
  11147. Status = NO_ERROR;
  11148. dwSubkey = 0;
  11149. if (hPushRoot != NULL)
  11150. {
  11151. Status = RegQueryInfoKey(hPushRoot,
  11152. NULL,
  11153. NULL,
  11154. NULL,
  11155. &dwSubkey,
  11156. NULL,
  11157. NULL,
  11158. NULL,
  11159. NULL,
  11160. NULL,
  11161. NULL,
  11162. NULL);
  11163. if (Status isnot NO_ERROR)
  11164. {
  11165. goto ErrorReturn;
  11166. }
  11167. }
  11168. if( dwSubkey > 0 )
  11169. {
  11170. PServer_List pTempList = NULL;
  11171. if( pServerList )
  11172. pTempList = pServerList;
  11173. pServerList= WinsAllocateMemory((dwSubkey+i)*sizeof(Server_List));
  11174. if( pServerList is NULL )
  11175. {
  11176. Status = ERROR_NOT_ENOUGH_MEMORY;
  11177. goto ErrorReturn;
  11178. }
  11179. memcpy(pServerList, pTempList, i*sizeof(Server_List));
  11180. if( pTempList )
  11181. {
  11182. WinsFreeMemory(pTempList);
  11183. pTempList = NULL;
  11184. }
  11185. p = 0;
  11186. for( j=0; j<dwSubkey; j++ )
  11187. {
  11188. DWORD dwLen = (MAX_IP_STRING_LEN + 1)*sizeof(WCHAR);
  11189. DWORD dwType = REG_SZ;
  11190. WCHAR wcIpTemp[MAX_IP_STRING_LEN+1] = {L'\0'};
  11191. DWORD k = 0;
  11192. BOOL fFind = FALSE;
  11193. Status = RegEnumKeyEx(hPushRoot,
  11194. j,
  11195. wcIpTemp,
  11196. &dwLen,
  11197. NULL,
  11198. NULL,
  11199. NULL,
  11200. NULL);
  11201. if( Status isnot NO_ERROR )
  11202. {
  11203. if( Status is ERROR_FILE_NOT_FOUND )
  11204. {
  11205. Status = NO_ERROR;
  11206. continue;
  11207. }
  11208. else
  11209. {
  11210. goto ErrorReturn;
  11211. }
  11212. }
  11213. for( k=0; k<i; k++ )
  11214. {
  11215. if( _wcsicmp(pServerList[k].wcServerIpAddress, wcIpTemp) is 0 )
  11216. {
  11217. pServerList[k].etype = all;
  11218. fFind = TRUE;
  11219. break;
  11220. }
  11221. }
  11222. if( fFind is FALSE )
  11223. {
  11224. wcscpy(pServerList[i+p].wcServerIpAddress, wcIpTemp);
  11225. Status = RegOpenKeyEx(hPushRoot,
  11226. pServerList[i+p].wcServerIpAddress,
  11227. 0,
  11228. KEY_READ,
  11229. &hKey);
  11230. if( Status isnot NO_ERROR )
  11231. {
  11232. if( Status is ERROR_FILE_NOT_FOUND )
  11233. {
  11234. Status = NO_ERROR;
  11235. continue;
  11236. }
  11237. else
  11238. {
  11239. goto ErrorReturn;
  11240. }
  11241. }
  11242. dwLen = 1024*sizeof(WCHAR);
  11243. Status = RegQueryValueEx(hKey,
  11244. L"NetBIOSName",
  11245. 0,
  11246. &dwType,
  11247. (LPBYTE)pServerList[i+p].wcServerName,
  11248. &dwLen);
  11249. if( Status isnot NO_ERROR )
  11250. {
  11251. if( Status is ERROR_FILE_NOT_FOUND )
  11252. {
  11253. wcscpy(pServerList[i+p].wcServerName, wszUnknown);
  11254. Status = NO_ERROR;
  11255. }
  11256. else
  11257. {
  11258. goto ErrorReturn;
  11259. }
  11260. }
  11261. pServerList[i+p].etype = push;
  11262. RegCloseKey(hKey);
  11263. hKey = NULL;
  11264. p++;
  11265. dwCount++;
  11266. }
  11267. else
  11268. continue;
  11269. }
  11270. }
  11271. }
  11272. if( dwCount <= 0 )
  11273. {
  11274. DisplayMessage(g_hModule, MSG_WINS_NO_PARTNER);
  11275. }
  11276. else
  11277. {
  11278. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  11279. DisplayMessage(g_hModule,
  11280. MSG_WINS_PARTNER_COUNT,
  11281. dwCount);
  11282. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  11283. DisplayMessage(g_hModule, MSG_WINS_PARTNERLIST_TABLE);
  11284. for( j=0; j<dwCount; j++)
  11285. {
  11286. WCHAR wcServer[32] = {L'\0'};
  11287. WCHAR wcIp[25] = {L'\0'};
  11288. DWORD dwServerLen = 0;
  11289. DWORD k = 0;
  11290. for( k=0; k<31; k++ )
  11291. wcServer[k] = L' ';
  11292. wcServer[31] = L'\0';
  11293. for( k=0; k<24; k++ )
  11294. wcIp[k] = L' ';
  11295. wcIp[24] = L'\0';
  11296. dwServerLen = MIN( 24, wcslen(pServerList[j].wcServerName) );
  11297. switch(Type)
  11298. {
  11299. case all:
  11300. default:
  11301. {
  11302. memcpy(wcServer+3, pServerList[j].wcServerName, dwServerLen*sizeof(WCHAR) );
  11303. memcpy(wcIp+3, pServerList[j].wcServerIpAddress, wcslen(pServerList[j].wcServerIpAddress)*sizeof(WCHAR));
  11304. DisplayMessage(g_hModule,
  11305. MSG_WINS_PARTNERLIST_ENTRY,
  11306. wcServer,
  11307. wcIp,
  11308. pServerList[j].etype is all ? wszPushpull:
  11309. (pServerList[j].etype is pull) ? wszPull : wszPush);
  11310. break;
  11311. }
  11312. case pull:
  11313. {
  11314. if( pServerList[j].etype is pull or
  11315. pServerList[j].etype is all )
  11316. {
  11317. memcpy(wcServer+3, pServerList[j].wcServerName, dwServerLen*sizeof(WCHAR));
  11318. memcpy(wcIp+3, pServerList[j].wcServerIpAddress, wcslen(pServerList[j].wcServerIpAddress)*sizeof(WCHAR));
  11319. DisplayMessage(g_hModule,
  11320. MSG_WINS_PARTNERLIST_ENTRY,
  11321. wcServer,
  11322. wcIp,
  11323. pServerList[j].etype is all ? wszPushpull : wszPull);
  11324. }
  11325. break;
  11326. }
  11327. case push:
  11328. {
  11329. if( pServerList[j].etype is push or
  11330. pServerList[j].etype is all )
  11331. {
  11332. memcpy(wcServer+3, pServerList[j].wcServerName, dwServerLen*sizeof(WCHAR));
  11333. memcpy(wcIp+3, pServerList[j].wcServerIpAddress, wcslen(pServerList[j].wcServerIpAddress)*sizeof(WCHAR));
  11334. DisplayMessage(g_hModule,
  11335. MSG_WINS_PARTNERLIST_ENTRY,
  11336. wcServer,
  11337. wcIp,
  11338. pServerList[j].etype is all ? wszPushpull : wszPush);
  11339. }
  11340. break;
  11341. }
  11342. case both:
  11343. {
  11344. if( pServerList[j].etype is all )
  11345. {
  11346. memcpy(wcServer+3, pServerList[j].wcServerName, dwServerLen*sizeof(WCHAR));
  11347. memcpy(wcIp+3, pServerList[j].wcServerIpAddress, wcslen(pServerList[j].wcServerIpAddress)*sizeof(WCHAR));
  11348. DisplayMessage(g_hModule,
  11349. MSG_WINS_PARTNERLIST_ENTRY,
  11350. wcServer,
  11351. wcIp,
  11352. wszPushpull);
  11353. }
  11354. }
  11355. }
  11356. }
  11357. }
  11358. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  11359. CommonReturn:
  11360. if( Status is NO_ERROR )
  11361. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  11362. if( hPullRoot )
  11363. {
  11364. RegCloseKey(hPullRoot);
  11365. hPullRoot = NULL;
  11366. }
  11367. if( hPushRoot )
  11368. {
  11369. RegCloseKey(hPushRoot);
  11370. hPushRoot = NULL;
  11371. }
  11372. if( hServer )
  11373. {
  11374. RegCloseKey(hServer);
  11375. hServer = NULL;
  11376. }
  11377. if( pdwTagType )
  11378. {
  11379. WinsFreeMemory(pdwTagType);
  11380. pdwTagType = NULL;
  11381. }
  11382. if( pdwTagNum )
  11383. {
  11384. WinsFreeMemory(pdwTagNum);
  11385. pdwTagNum = NULL;
  11386. }
  11387. return Status;
  11388. ErrorReturn:
  11389. if( Status is ERROR_FILE_NOT_FOUND )
  11390. {
  11391. DisplayMessage(g_hModule,
  11392. MSG_WINS_NO_PARTNER);
  11393. Status = NO_ERROR;
  11394. }
  11395. else
  11396. {
  11397. DisplayErrorMessage(EMSG_SRVR_SHOW_PARTNER,
  11398. Status);
  11399. }
  11400. goto CommonReturn;
  11401. }
  11402. DWORD
  11403. HandleSrvrShowReccount(
  11404. IN LPCWSTR pwszMachine,
  11405. IN OUT LPWSTR *ppwcArguments,
  11406. IN DWORD dwCurrentIndex,
  11407. IN DWORD dwArgCount,
  11408. IN DWORD dwFlags,
  11409. IN LPCVOID pvData,
  11410. OUT BOOL *pbDone
  11411. )
  11412. /*++
  11413. Routine Description :
  11414. Displays the record count based on the version(optionally)
  11415. Arguments :
  11416. All aguments are passes as array of wide char strings in ppwcArguments.
  11417. Compulsory : Address of the server whose records to be counted
  11418. Optional : Version range. Max and Min version both in the format {high,low}
  11419. Return Value:
  11420. Returns the status of the operation.
  11421. --*/
  11422. {
  11423. DWORD Status = NO_ERROR;
  11424. DWORD i, j, dwNumArgs, dwTagCount = 0;
  11425. TAG_TYPE pttTags[] = {
  11426. {WINS_TOKEN_SERVER, TRUE, FALSE},
  11427. {WINS_TOKEN_MAXVER, FALSE, FALSE},
  11428. {WINS_TOKEN_MINVER, FALSE, FALSE},
  11429. };
  11430. WINSINTF_VERS_NO_T MinVer={0}, MaxVer={0};
  11431. WINSINTF_ADD_T WinsAdd = {0};
  11432. WINSINTF_RECS_T Recs = {0};
  11433. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  11434. LPWSTR pwszTemp = NULL;
  11435. LPDWORD pdwTagType = NULL,
  11436. pdwTagNum = NULL;
  11437. if( dwArgCount < dwCurrentIndex + 1 )
  11438. {
  11439. DisplayMessage(g_hModule,
  11440. HLP_SRVR_SHOW_RECCOUNT_EX);
  11441. Status = ERROR_INVALID_PARAMETER;
  11442. goto ErrorReturn;
  11443. }
  11444. dwNumArgs = dwArgCount - dwCurrentIndex;
  11445. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11446. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11447. if( pdwTagType is NULL or
  11448. pdwTagNum is NULL )
  11449. {
  11450. Status = ERROR_NOT_ENOUGH_MEMORY;
  11451. goto ErrorReturn;
  11452. }
  11453. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  11454. Status = PreProcessCommand(ppwcArguments,
  11455. dwArgCount,
  11456. dwCurrentIndex,
  11457. pttTags,
  11458. &dwTagCount,
  11459. pdwTagType,
  11460. pdwTagNum);
  11461. if( Status isnot NO_ERROR )
  11462. goto ErrorReturn;
  11463. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  11464. {
  11465. if( pttTags[i].dwRequired is TRUE and
  11466. pttTags[i].bPresent is FALSE
  11467. )
  11468. {
  11469. Status = ERROR_INVALID_PARAMETER;
  11470. goto ErrorReturn;
  11471. }
  11472. }
  11473. for( j=0; j<dwTagCount; j++ )
  11474. {
  11475. switch( pdwTagType[j] )
  11476. {
  11477. case 0:
  11478. {
  11479. struct hostent * lpHostEnt = NULL;
  11480. CHAR cAddr[16];
  11481. BYTE pbAdd[4];
  11482. char szAdd[4];
  11483. int k = 0, l=0;
  11484. DWORD dwLen, nLen = 0;
  11485. CHAR *pTemp = NULL;
  11486. CHAR *pNetBios = NULL;
  11487. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  11488. {
  11489. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  11490. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  11491. if(lpHostEnt isnot NULL )//Valid IP Address
  11492. {
  11493. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11494. break;
  11495. }
  11496. else
  11497. {
  11498. Status = WSAGetLastError();
  11499. goto ErrorReturn;
  11500. }
  11501. }
  11502. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  11503. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  11504. k = 2;
  11505. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  11506. if( lpHostEnt is NULL )
  11507. {
  11508. DisplayMessage(g_hModule,
  11509. EMSG_WINS_INVALID_COMPUTER_NAME,
  11510. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  11511. Status = ERROR_INVALID_PARAMETER;
  11512. goto ErrorReturn;
  11513. }
  11514. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  11515. for( l=0;l<4; l++)
  11516. {
  11517. _itoa((int)pbAdd[l], szAdd, 10);
  11518. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  11519. nLen += strlen(szAdd);
  11520. *(cAddr+nLen) = '.';
  11521. nLen++;
  11522. }
  11523. *(cAddr+nLen-1) = '\0';
  11524. {
  11525. LPWSTR pstr = WinsAnsiToUnicode(cAddr, NULL);
  11526. if (pstr != NULL)
  11527. {
  11528. wcscpy(wcServerIpAdd, pstr);
  11529. WinsFreeMemory(pstr);
  11530. }
  11531. else
  11532. {
  11533. Status = ERROR_NOT_ENOUGH_MEMORY;
  11534. goto ErrorReturn;
  11535. }
  11536. }
  11537. break;
  11538. }
  11539. case 1:
  11540. {
  11541. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MaxVer);
  11542. if( Status isnot NO_ERROR )
  11543. goto ErrorReturn;
  11544. break;
  11545. }
  11546. case 2:
  11547. {
  11548. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MinVer);
  11549. if( Status isnot NO_ERROR )
  11550. goto ErrorReturn;
  11551. break;
  11552. }
  11553. default:
  11554. {
  11555. Status = ERROR_INVALID_PARAMETER;
  11556. goto ErrorReturn;
  11557. }
  11558. }
  11559. }
  11560. WinsAdd.IPAdd = StringToIpAddress(wcServerIpAdd);
  11561. WinsAdd.Len = 4;
  11562. WinsAdd.Type = 0;
  11563. Status = WinsGetDbRecs(g_hBind,
  11564. &WinsAdd,
  11565. MinVer,
  11566. MaxVer,
  11567. &Recs);
  11568. if( Status isnot NO_ERROR )
  11569. goto ErrorReturn;
  11570. DisplayMessage(g_hModule,
  11571. MSG_WINS_RECORDS_COUNT_OWNER,
  11572. wcServerIpAdd,
  11573. Recs.TotalNoOfRecs);
  11574. DisplayMessage(g_hModule,
  11575. EMSG_WINS_ERROR_SUCCESS);
  11576. CommonReturn:
  11577. if( pdwTagType )
  11578. {
  11579. WinsFreeMemory(pdwTagType);
  11580. pdwTagType = NULL;
  11581. }
  11582. if( pdwTagNum )
  11583. {
  11584. WinsFreeMemory(pdwTagNum);
  11585. pdwTagNum = NULL;
  11586. }
  11587. if( Recs.pRow )
  11588. {
  11589. WinsFreeMem(Recs.pRow);
  11590. Recs.pRow = NULL;
  11591. }
  11592. return Status;
  11593. ErrorReturn:
  11594. DisplayErrorMessage(EMSG_SRVR_SHOW_RECCOUNT,
  11595. Status);
  11596. goto CommonReturn;
  11597. }
  11598. DWORD
  11599. HandleSrvrShowRecbyversion(
  11600. IN LPCWSTR pwszMachine,
  11601. IN OUT LPWSTR *ppwcArguments,
  11602. IN DWORD dwCurrentIndex,
  11603. IN DWORD dwArgCount,
  11604. IN DWORD dwFlags,
  11605. IN LPCVOID pvData,
  11606. OUT BOOL *pbDone
  11607. )
  11608. /*++
  11609. Routine Description :
  11610. Displays records based on Version range, filtered by 16th char
  11611. Arguments :
  11612. All aguments are passes as array of wide char strings in ppwcArguments.
  11613. Compulsory : Address of the server whose records to be displayed
  11614. Optional : Version range. Max and Min version both in the format {high,low},
  11615. 16th character, Name etc
  11616. Return Value:
  11617. Returns the status of the operation.
  11618. --*/
  11619. {
  11620. DWORD Status = NO_ERROR;
  11621. DWORD i, j, dwTagCount, dwNumArgs;
  11622. TAG_TYPE pttTags[] = {
  11623. {WINS_TOKEN_SERVER, TRUE, FALSE},
  11624. {WINS_TOKEN_MAXVER, FALSE, FALSE},
  11625. {WINS_TOKEN_MINVER, FALSE, FALSE},
  11626. {WINS_TOKEN_NAME, FALSE, FALSE},
  11627. {WINS_TOKEN_ENDCHAR, FALSE, FALSE},
  11628. {WINS_TOKEN_CASE, FALSE, FALSE},
  11629. };
  11630. WCHAR wcName[17] = {L'\0'};
  11631. LPWSTR pwcScope = NULL;
  11632. CHAR ch16thChar = 0x00;
  11633. DWORD dwNameLen = 0;
  11634. WINSINTF_VERS_NO_T MinVer={0}, MaxVer={0};
  11635. WINSINTF_ADD_T WinsAdd = {0};
  11636. WINSINTF_RECS_T Recs = {0};
  11637. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  11638. WCHAR wcFile[MAX_PATH] = {L'\0'};
  11639. LPWSTR pwszTemp = NULL;
  11640. BOOL fEndChar = FALSE,
  11641. fCase = FALSE,
  11642. fFile = FALSE,
  11643. fName = FALSE;
  11644. LPDWORD pdwTagType = NULL,
  11645. pdwTagNum = NULL;
  11646. LPSTR pszTempAddr = NULL;
  11647. LPSTR lpName = NULL;
  11648. if( dwArgCount < dwCurrentIndex + 1 )
  11649. {
  11650. DisplayMessage(g_hModule,
  11651. HLP_SRVR_SHOW_RECBYVERSION_EX);
  11652. Status = ERROR_INVALID_PARAMETER;
  11653. goto ErrorReturn;
  11654. }
  11655. dwNumArgs = dwArgCount - dwCurrentIndex;
  11656. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11657. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11658. if( pdwTagType is NULL or
  11659. pdwTagNum is NULL )
  11660. {
  11661. Status = ERROR_NOT_ENOUGH_MEMORY;
  11662. goto ErrorReturn;
  11663. }
  11664. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  11665. Status = PreProcessCommand(ppwcArguments,
  11666. dwArgCount,
  11667. dwCurrentIndex,
  11668. pttTags,
  11669. &dwTagCount,
  11670. pdwTagType,
  11671. pdwTagNum);
  11672. if( Status isnot NO_ERROR )
  11673. goto ErrorReturn;
  11674. for( j=0; j<dwTagCount; j++ )
  11675. {
  11676. switch( pdwTagType[j] )
  11677. {
  11678. case 0:
  11679. {
  11680. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  11681. {
  11682. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11683. }
  11684. else
  11685. {
  11686. Status = ERROR_INVALID_PARAMETER;
  11687. goto ErrorReturn;
  11688. }
  11689. break;
  11690. }
  11691. case 1:
  11692. {
  11693. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MaxVer);
  11694. if( Status isnot NO_ERROR )
  11695. goto ErrorReturn;
  11696. break;
  11697. }
  11698. case 2:
  11699. {
  11700. Status = GetVersionData(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], &MinVer);
  11701. if( Status isnot NO_ERROR )
  11702. goto ErrorReturn;
  11703. break;
  11704. }
  11705. case 3:
  11706. {
  11707. wcsncpy(wcName, ppwcArguments[dwCurrentIndex+pdwTagNum[j]], 15);
  11708. fName = TRUE;
  11709. break;
  11710. }
  11711. case 4:
  11712. {
  11713. DWORD dwLen = 0, k=0;
  11714. fEndChar = TRUE;
  11715. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11716. if( dwLen > 2 )
  11717. {
  11718. Status = ERROR_INVALID_PARAMETER;
  11719. goto ErrorReturn;
  11720. }
  11721. for( k=0; k<dwLen; k++ )
  11722. {
  11723. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  11724. if( towlower(wc) >= L'a' and
  11725. towlower(wc) <= L'z' )
  11726. {
  11727. if( towlower(wc) > L'f' )
  11728. {
  11729. Status = ERROR_INVALID_PARAMETER;
  11730. goto ErrorReturn;
  11731. }
  11732. }
  11733. }
  11734. ch16thChar = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11735. break;
  11736. }
  11737. case 5:
  11738. {
  11739. WCHAR wc = L'\0';
  11740. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) isnot 1 )
  11741. {
  11742. Status = ERROR_INVALID_PARAMETER;
  11743. goto ErrorReturn;
  11744. }
  11745. wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][0];
  11746. if( wc is L'0' )
  11747. {
  11748. fCase = FALSE;
  11749. }
  11750. else if( wc is L'1' )
  11751. {
  11752. fCase = TRUE;
  11753. }
  11754. else
  11755. {
  11756. Status = ERROR_INVALID_PARAMETER;
  11757. goto ErrorReturn;
  11758. }
  11759. break;
  11760. }
  11761. default:
  11762. {
  11763. Status = ERROR_INVALID_PARAMETER;
  11764. goto ErrorReturn;
  11765. }
  11766. }
  11767. }
  11768. for( j=0; j<sizeof(pttTags)/sizeof(TAG_TYPE); j++ )
  11769. {
  11770. if( pttTags[j].dwRequired is TRUE and
  11771. pttTags[j].bPresent is FALSE )
  11772. {
  11773. Status = ERROR_INVALID_PARAMETER;
  11774. goto ErrorReturn;
  11775. }
  11776. }
  11777. if( fName )
  11778. {
  11779. //Process the name option if present
  11780. lpName = WinsUnicodeToOem(wcName, NULL);
  11781. if( lpName is NULL )
  11782. {
  11783. Status = ERROR_NOT_ENOUGH_MEMORY;
  11784. goto ErrorReturn;
  11785. }
  11786. dwNameLen = strlen(lpName);
  11787. if( dwNameLen >= 16 )
  11788. {
  11789. DisplayMessage(g_hModule,
  11790. EMSG_SRVR_INVALID_NETBIOS_NAME);
  11791. Status = ERROR_INVALID_PARAMETER;
  11792. goto ErrorReturn;
  11793. }
  11794. if( fEndChar)
  11795. {
  11796. LPSTR pTemp = lpName;
  11797. lpName = WinsAllocateMemory(17);
  11798. if( lpName is NULL )
  11799. {
  11800. Status = ERROR_NOT_ENOUGH_MEMORY;
  11801. goto ErrorReturn;
  11802. }
  11803. strcpy(lpName, pTemp);
  11804. for( i=strlen(pTemp); i<16; i++ )
  11805. {
  11806. lpName[i] = ' ';
  11807. }
  11808. lpName[15] = ch16thChar;
  11809. lpName[16] = '\0';
  11810. WinsFreeMemory(pTemp);
  11811. dwNameLen = 16;
  11812. }
  11813. }
  11814. WinsAdd.IPAdd = StringToIpAddress(wcServerIpAdd);
  11815. WinsAdd.Len = 4;
  11816. WinsAdd.Type = 0;
  11817. pszTempAddr = WinsUnicodeToOem(wcServerIpAdd, NULL);
  11818. if( pszTempAddr is NULL )
  11819. {
  11820. Status = ERROR_NOT_ENOUGH_MEMORY;
  11821. goto ErrorReturn;
  11822. }
  11823. Status = GetDbRecs(MinVer,
  11824. MaxVer,
  11825. &WinsAdd,
  11826. pszTempAddr,
  11827. fName,
  11828. lpName,
  11829. dwNameLen,
  11830. FALSE,
  11831. 0,
  11832. FALSE,
  11833. fCase,
  11834. fFile,
  11835. fFile ? wcFile : NULL);
  11836. WinsFreeMemory(pszTempAddr);
  11837. pszTempAddr = NULL;
  11838. if( lpName )
  11839. {
  11840. WinsFreeMemory(lpName);
  11841. lpName = NULL;
  11842. }
  11843. if( Status isnot NO_ERROR )
  11844. goto ErrorReturn;
  11845. DisplayMessage(g_hModule,
  11846. EMSG_WINS_ERROR_SUCCESS);
  11847. CommonReturn:
  11848. if( pdwTagType )
  11849. {
  11850. WinsFreeMemory(pdwTagType);
  11851. pdwTagType = NULL;
  11852. }
  11853. if( pdwTagNum )
  11854. {
  11855. WinsFreeMemory(pdwTagNum);
  11856. pdwTagNum = NULL;
  11857. }
  11858. return Status;
  11859. ErrorReturn:
  11860. DisplayErrorMessage(EMSG_SRVR_SHOW_RECBYVERSION,
  11861. Status);
  11862. goto CommonReturn;
  11863. }
  11864. DWORD
  11865. HandleSrvrShowName(
  11866. IN LPCWSTR pwszMachine,
  11867. IN OUT LPWSTR *ppwcArguments,
  11868. IN DWORD dwCurrentIndex,
  11869. IN DWORD dwArgCount,
  11870. IN DWORD dwFlags,
  11871. IN LPCVOID pvData,
  11872. OUT BOOL *pbDone
  11873. )
  11874. /*++
  11875. Routine Description :
  11876. Displays detail information for a particular name records
  11877. Arguments :
  11878. All aguments are passes as array of wide char strings in ppwcArguments.
  11879. Compulsory : Name of the records
  11880. Optional : 16th character and Scope
  11881. Return Value:
  11882. Returns the status of the operation.
  11883. --*/
  11884. {
  11885. DWORD Status = NO_ERROR;
  11886. DWORD i, j, dwNumArgs, dwTagCount = 0;
  11887. TAG_TYPE pttTags[] = {
  11888. {WINS_TOKEN_NAME, TRUE, FALSE},
  11889. {WINS_TOKEN_ENDCHAR, FALSE, FALSE},
  11890. {WINS_TOKEN_SCOPE, FALSE, FALSE}
  11891. };
  11892. PDWORD pdwTagNum = NULL,
  11893. pdwTagType = NULL;
  11894. WCHAR wszName[MAX_STRING_LEN+4] = {L'\0'};
  11895. BOOL fEndChar = FALSE;
  11896. CHAR ch16thChar = 0x00;
  11897. BOOL fScope = FALSE;
  11898. WCHAR wszScope[MAX_STRING_LEN] = {L'\0'};
  11899. DWORD dwStrLen = 0;
  11900. LPWSTR pwszTemp = NULL;
  11901. WINSINTF_RECORD_ACTION_T RecAction = {0};
  11902. PWINSINTF_RECORD_ACTION_T pRecAction = NULL;
  11903. LPWSTR pwszGroup = NULL,
  11904. pwszState = NULL,
  11905. pwszType = NULL;
  11906. CHAR chEndChar = (CHAR)0x00;
  11907. WCHAR wszGroup[50] = {L'\0'},
  11908. wszState[50] = {L'\0'},
  11909. wszType[50] = {L'\0'};
  11910. DWORD dwTempLen = 0;
  11911. struct tm* time = NULL;
  11912. DWORD dwGroup = WINS_GROUP_UNIQUE;
  11913. DWORD dwState = WINS_STATE_ACTIVE;
  11914. DWORD dwType = WINS_TYPE_STATIC;
  11915. DWORD dwGrouplen = 0,
  11916. dwStatelen = 0,
  11917. dwTypelen = 0;
  11918. LPSTR pszTemp = NULL;
  11919. LPWSTR pwszTime = NULL;
  11920. int iType = 1;
  11921. memset(&RecAction, 0x00, sizeof(WINSINTF_RECORD_ACTION_T));
  11922. RecAction.fStatic = TRUE;
  11923. if( dwArgCount < dwCurrentIndex + 1 )
  11924. {
  11925. DisplayMessage(g_hModule, HLP_SRVR_SHOW_NAME_EX);
  11926. Status = ERROR_INVALID_PARAMETER;
  11927. goto ErrorReturn;
  11928. }
  11929. dwNumArgs = dwArgCount - dwCurrentIndex;
  11930. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11931. if( pdwTagNum is NULL )
  11932. {
  11933. Status = ERROR_NOT_ENOUGH_MEMORY;
  11934. goto ErrorReturn;
  11935. }
  11936. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  11937. if( pdwTagType is NULL )
  11938. {
  11939. Status = ERROR_NOT_ENOUGH_MEMORY;
  11940. goto ErrorReturn;
  11941. }
  11942. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  11943. Status = PreProcessCommand(ppwcArguments,
  11944. dwArgCount,
  11945. dwCurrentIndex,
  11946. pttTags,
  11947. &dwTagCount,
  11948. pdwTagType,
  11949. pdwTagNum);
  11950. if( Status isnot NO_ERROR )
  11951. goto ErrorReturn;
  11952. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  11953. {
  11954. if( pttTags[i].dwRequired is TRUE and
  11955. pttTags[i].bPresent is FALSE
  11956. )
  11957. {
  11958. Status = ERROR_INVALID_PARAMETER;
  11959. goto ErrorReturn;
  11960. }
  11961. }
  11962. i = dwTagCount;
  11963. for( j=0; j<i; j++ )
  11964. {
  11965. switch(pdwTagType[j])
  11966. {
  11967. case 0:
  11968. {
  11969. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11970. if( dwLen is 0 )
  11971. {
  11972. Status = ERROR_INVALID_PARAMETER;
  11973. goto ErrorReturn;
  11974. }
  11975. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  11976. memcpy(wszName,
  11977. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  11978. dwLen*sizeof(WCHAR));
  11979. wszName[dwLen] = L'\0';
  11980. break;
  11981. }
  11982. case 1:
  11983. {
  11984. DWORD dwLen = 0, k=0;
  11985. fEndChar = TRUE;
  11986. dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  11987. if( dwLen > 2 )
  11988. {
  11989. Status = ERROR_INVALID_PARAMETER;
  11990. goto ErrorReturn;
  11991. }
  11992. for( k=0; k<dwLen; k++ )
  11993. {
  11994. WCHAR wc = ppwcArguments[dwCurrentIndex+pdwTagNum[j]][k];
  11995. if( towlower(wc) >= L'a' and
  11996. towlower(wc) <= L'z' )
  11997. {
  11998. if( towlower(wc) > L'f' )
  11999. {
  12000. Status = ERROR_INVALID_PARAMETER;
  12001. goto ErrorReturn;
  12002. }
  12003. }
  12004. }
  12005. ch16thChar = StringToHexA(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  12006. break;
  12007. }
  12008. case 2:
  12009. {
  12010. DWORD dwLen = wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  12011. fScope = TRUE;
  12012. if( dwLen is 0 )
  12013. {
  12014. Status = ERROR_INVALID_PARAMETER;
  12015. goto ErrorReturn;
  12016. }
  12017. dwLen = ( 255 < dwLen ) ? 255 : dwLen;
  12018. memcpy(wszScope,
  12019. ppwcArguments[dwCurrentIndex+pdwTagNum[j]],
  12020. dwLen*sizeof(WCHAR));
  12021. wszScope[dwLen] = L'\0';
  12022. break;
  12023. }
  12024. default:
  12025. {
  12026. Status = ERROR_INVALID_PARAMETER;
  12027. goto ErrorReturn;
  12028. }
  12029. }
  12030. }
  12031. _wcsupr(wszName);
  12032. _wcsupr(wszScope);
  12033. wszName[16] = L'\0';
  12034. pszTemp = WinsUnicodeToOem(wszName, NULL);
  12035. if( pszTemp is NULL )
  12036. {
  12037. Status = ERROR_NOT_ENOUGH_MEMORY;
  12038. goto ErrorReturn;
  12039. }
  12040. dwStrLen = strlen(pszTemp);
  12041. if( dwStrLen >= 16 )
  12042. {
  12043. DisplayMessage(g_hModule,
  12044. EMSG_SRVR_INVALID_NETBIOS_NAME);
  12045. Status = ERROR_INVALID_PARAMETER;
  12046. WinsFreeMemory(pszTemp);
  12047. pszTemp = NULL;
  12048. goto ErrorReturn;
  12049. }
  12050. RecAction.pName = WinsAllocateMemory(273);
  12051. if( RecAction.pName is NULL )
  12052. {
  12053. Status = ERROR_NOT_ENOUGH_MEMORY;
  12054. goto ErrorReturn;
  12055. }
  12056. strncpy(RecAction.pName, pszTemp, 16);
  12057. WinsFreeMemory(pszTemp);
  12058. pszTemp = NULL;
  12059. for( i = dwStrLen; i<16; i++ )
  12060. {
  12061. RecAction.pName[i] = ' ';
  12062. }
  12063. if( fEndChar )
  12064. {
  12065. RecAction.pName[15] = ch16thChar;
  12066. }
  12067. if( fEndChar and
  12068. ch16thChar is 0x00 )
  12069. RecAction.pName[15] = 0x00;
  12070. RecAction.pName[16] = '\0';
  12071. dwStrLen = 16;
  12072. if( fScope )
  12073. {
  12074. DWORD dwLen;
  12075. RecAction.pName[dwStrLen] = '.';
  12076. pszTemp = WinsUnicodeToOem(wszScope, NULL);
  12077. if( pszTemp is NULL )
  12078. {
  12079. Status = ERROR_NOT_ENOUGH_MEMORY;
  12080. goto ErrorReturn;
  12081. }
  12082. dwLen = strlen(pszTemp);
  12083. dwLen = ( 255 - dwStrLen < dwLen ) ? 255 - dwStrLen : dwLen;
  12084. strncpy(RecAction.pName + dwStrLen + 1, pszTemp, dwLen);
  12085. WinsFreeMemory(pszTemp);
  12086. pszTemp = NULL;
  12087. RecAction.pName[dwLen + dwStrLen + 1] = '\0';
  12088. if( fEndChar and
  12089. ch16thChar is 0x00 )
  12090. dwStrLen = 16+dwLen+1;
  12091. else
  12092. dwStrLen = strlen(RecAction.pName);
  12093. }
  12094. else
  12095. {
  12096. RecAction.pName[dwStrLen] = '\0';
  12097. }
  12098. RecAction.NameLen = dwStrLen;
  12099. RecAction.Cmd_e = WINSINTF_E_QUERY;
  12100. RecAction.OwnerId = StringToIpAddress(g_ServerIpAddressUnicodeString);
  12101. RecAction.NameLen = dwStrLen;
  12102. pRecAction = &RecAction;
  12103. Status = WinsRecordAction(g_hBind, &pRecAction);
  12104. if( Status isnot NO_ERROR )
  12105. goto ErrorReturn;
  12106. RecAction.pName[RecAction.NameLen] = L'\0';
  12107. memset(wszName, 0x00, MAX_STRING_LEN*sizeof(WCHAR));
  12108. if( pRecAction->NameLen >= 16 )
  12109. {
  12110. chEndChar = pRecAction->pName[15];
  12111. pRecAction->pName[15] = 0x00;
  12112. }
  12113. else
  12114. {
  12115. chEndChar = pRecAction->pName[pRecAction->NameLen];
  12116. pRecAction->pName[pRecAction->NameLen] = 0x00;
  12117. }
  12118. pwszTemp = WinsOemToUnicode(pRecAction->pName, NULL);
  12119. if( pwszTemp is NULL )
  12120. {
  12121. Status = ERROR_NOT_ENOUGH_MEMORY;
  12122. goto ErrorReturn;
  12123. }
  12124. wcscpy(wszName, pwszTemp);
  12125. WinsFreeMemory(pwszTemp);
  12126. pwszTemp = NULL;
  12127. for( i=wcslen(wszName); i<16; i++ )
  12128. {
  12129. wszName[i] = L' ';
  12130. }
  12131. wszName[15] = L'[';
  12132. WinsHexToString(wszName+16, (LPBYTE)&chEndChar, 1);
  12133. wszName[18] = L'h';
  12134. wszName[19] = L']';
  12135. if( pRecAction->NameLen > 16 )
  12136. {
  12137. pwszTemp = WinsOemToUnicode(pRecAction->pName+16, NULL);
  12138. if( pwszTemp is NULL )
  12139. {
  12140. Status = ERROR_NOT_ENOUGH_MEMORY;
  12141. goto ErrorReturn;
  12142. }
  12143. wcscpy(wszName + 20 , pwszTemp);
  12144. WinsFreeMemory(pwszTemp);
  12145. pwszTemp = NULL;
  12146. wszName[wcslen(wszName)] = L'\0';
  12147. }
  12148. else
  12149. {
  12150. wszName[20] = L'\0';
  12151. }
  12152. if( pRecAction->pName[15] is 0x1C )
  12153. {
  12154. pwszGroup = L"DOMAIN NAME";
  12155. dwGroup = WINS_GROUP_DOMAIN;
  12156. }
  12157. else if( pRecAction->TypOfRec_e is WINSINTF_E_UNIQUE )
  12158. {
  12159. pwszGroup = L"UNIQUE";
  12160. dwGroup = WINS_GROUP_UNIQUE;
  12161. }
  12162. else if( pRecAction->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  12163. {
  12164. pwszGroup = L"GROUP";
  12165. dwGroup = WINS_GROUP_GROUP;
  12166. }
  12167. else if( pRecAction->TypOfRec_e is WINSINTF_E_SPEC_GROUP )
  12168. {
  12169. pwszGroup = L"INTERNET GROUP";
  12170. dwGroup = WINS_GROUP_INTERNET;
  12171. }
  12172. else
  12173. {
  12174. pwszGroup = L"MULTIHOMED";
  12175. dwGroup = WINS_GROUP_MULTIHOMED;
  12176. }
  12177. //Load the group string
  12178. {
  12179. dwGrouplen = LoadStringW(g_hModule,
  12180. dwGroup,
  12181. wszGroup,
  12182. sizeof(wszGroup)/sizeof(WCHAR));
  12183. if( dwGrouplen is 0 )
  12184. wcscpy(wszGroup, pwszGroup);
  12185. }
  12186. pwszTime = GetDateTimeString(pRecAction->TimeStamp,
  12187. FALSE,
  12188. &iType);
  12189. if( pRecAction->State_e is WINSINTF_E_ACTIVE )
  12190. {
  12191. pwszState = L"ACTIVE";
  12192. dwState = WINS_STATE_ACTIVE;
  12193. }
  12194. else if( pRecAction->State_e is WINSINTF_E_RELEASED )
  12195. {
  12196. dwState = WINS_STATE_RELEASED;
  12197. pwszState = L"RELEASED";
  12198. }
  12199. else
  12200. {
  12201. dwState = WINS_STATE_TOMBSTONE;
  12202. pwszState = L"TOMBSTONE";
  12203. }
  12204. //Load the State string
  12205. {
  12206. dwStatelen = LoadStringW(g_hModule,
  12207. dwState,
  12208. wszState,
  12209. sizeof(wszState)/sizeof(WCHAR));
  12210. if( dwStatelen is 0 )
  12211. wcscpy(wszState, pwszState);
  12212. }
  12213. if( pRecAction->fStatic )
  12214. {
  12215. dwType = WINS_TYPE_STATIC;
  12216. pwszType = L"STATIC";
  12217. }
  12218. else
  12219. {
  12220. dwType = WINS_TYPE_DYNAMIC;
  12221. pwszType = L"DYNAMIC";
  12222. }
  12223. //Load the State string
  12224. {
  12225. dwTypelen = LoadStringW(g_hModule,
  12226. dwType,
  12227. wszType,
  12228. sizeof(wszType)/sizeof(WCHAR));
  12229. if( dwTypelen is 0 )
  12230. wcscpy(wszType, pwszType);
  12231. }
  12232. DisplayMessage( g_hModule,
  12233. MSG_WINS_DISPLAY_NAME,
  12234. wszName,
  12235. pRecAction->NodeTyp,
  12236. wszState,
  12237. iType ? wszInfinite : pwszTime,
  12238. wszGroup,
  12239. pRecAction->VersNo.HighPart,
  12240. pRecAction->VersNo.LowPart,
  12241. wszType);
  12242. if( pwszTime )
  12243. {
  12244. WinsFreeMemory(pwszTime);
  12245. pwszTime = NULL;
  12246. }
  12247. if ( ( pRecAction->pName[15] isnot 0x1C and
  12248. pRecAction->pName[15] isnot 0x1E ) and
  12249. ( pRecAction->TypOfRec_e is WINSINTF_E_UNIQUE or
  12250. pRecAction->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  12251. )
  12252. {
  12253. DisplayMessage(g_hModule,
  12254. MSG_WINS_IPADDRESS_STRING,
  12255. IpAddressToString(pRecAction->Add.IPAdd));
  12256. }
  12257. else
  12258. {
  12259. for (i=0; i<pRecAction->NoOfAdds; )
  12260. {
  12261. DisplayMessage(g_hModule,
  12262. MSG_WINS_OWNER_ADDRESS,
  12263. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12264. DisplayMessage(g_hModule,
  12265. MSG_WINS_MEMBER_ADDRESS,
  12266. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12267. }
  12268. }
  12269. //If UNIQUE, look for 0x00 and 0x03 records also
  12270. if( ( pRecAction->TypOfRec_e is WINSINTF_E_UNIQUE or
  12271. pRecAction->TypOfRec_e is WINSINTF_E_MULTIHOMED ) and
  12272. fEndChar is FALSE )
  12273. {
  12274. DWORD dwNameLen = RecAction.NameLen;
  12275. DisplayMessage(g_hModule,
  12276. WINS_FORMAT_LINE);
  12277. RecAction.pName[15] = 0x00;
  12278. RecAction.NameLen = 16;
  12279. pRecAction = &RecAction;
  12280. Status = WinsRecordAction(g_hBind, &pRecAction);
  12281. if( Status is NO_ERROR )
  12282. {
  12283. RecAction.pName[RecAction.NameLen] = L'\0';
  12284. memset(wszName, 0x00, MAX_STRING_LEN*sizeof(WCHAR));
  12285. pwszTemp = WinsOemToUnicode(pRecAction->pName, NULL);
  12286. if( pwszTemp is NULL )
  12287. {
  12288. Status = ERROR_NOT_ENOUGH_MEMORY;
  12289. goto ErrorReturn;
  12290. }
  12291. wcscpy(wszName, pwszTemp);
  12292. WinsFreeMemory(pwszTemp);
  12293. pwszTemp = NULL;
  12294. for( i=wcslen(wszName); i<16; i++ )
  12295. {
  12296. wszName[i] = L' ';
  12297. }
  12298. for( i=wcslen(wszName)+3; j>=15; j-- )
  12299. wszName[j-1] = wszName[j-4];
  12300. wszName[15] = L'[';
  12301. WinsHexToString(wszName+16, (LPBYTE)(pRecAction->pName+15), 1);
  12302. wszName[18] = L'h';
  12303. wszName[19] = L']';
  12304. if( pRecAction->NameLen > 16 )
  12305. {
  12306. pwszTemp = WinsOemToUnicode(pRecAction->pName+16, NULL);
  12307. if( pwszTemp is NULL )
  12308. {
  12309. Status = ERROR_NOT_ENOUGH_MEMORY;
  12310. goto ErrorReturn;
  12311. }
  12312. wcscpy(wszName + 20 , pwszTemp);
  12313. WinsFreeMemory(pwszTemp);
  12314. pwszTemp = NULL;
  12315. wszName[wcslen(wszName)] = L'\0';
  12316. }
  12317. else
  12318. {
  12319. wszName[20] = L'\0';
  12320. }
  12321. iType = 1;
  12322. pwszTime = GetDateTimeString(pRecAction->TimeStamp,
  12323. FALSE,
  12324. &iType);
  12325. DisplayMessage( g_hModule,
  12326. MSG_WINS_DISPLAY_NAME,
  12327. wszName,
  12328. pRecAction->NodeTyp,
  12329. wszState,
  12330. iType ? wszInfinite : pwszTime,
  12331. wszGroup,
  12332. pRecAction->VersNo.HighPart,
  12333. pRecAction->VersNo.LowPart,
  12334. wszType);
  12335. if( pwszTime )
  12336. {
  12337. WinsFreeMemory(pwszTime);
  12338. pwszTime = NULL;
  12339. }
  12340. if( pRecAction->TypOfRec_e is WINSINTF_E_UNIQUE )
  12341. {
  12342. DisplayMessage(g_hModule,
  12343. MSG_WINS_IPADDRESS_STRING,
  12344. IpAddressToString(pRecAction->Add.IPAdd));
  12345. }
  12346. else
  12347. {
  12348. for (i=0; i<pRecAction->NoOfAdds; )
  12349. {
  12350. DisplayMessage(g_hModule,
  12351. MSG_WINS_OWNER_ADDRESS,
  12352. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12353. DisplayMessage(g_hModule,
  12354. MSG_WINS_MEMBER_ADDRESS,
  12355. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12356. }
  12357. }
  12358. }
  12359. DisplayMessage(g_hModule,
  12360. WINS_FORMAT_LINE);
  12361. //Now Look for 0x03 record
  12362. if( fScope )
  12363. {
  12364. DWORD dwLen;
  12365. dwStrLen = 16;
  12366. RecAction.pName[dwStrLen] = '.';
  12367. pszTemp = WinsUnicodeToOem(wszScope, NULL);
  12368. if( pszTemp is NULL )
  12369. {
  12370. Status = ERROR_NOT_ENOUGH_MEMORY;
  12371. goto ErrorReturn;
  12372. }
  12373. dwLen = strlen(pszTemp);
  12374. dwLen = ( 255 - dwStrLen < dwLen ) ? 255 - dwStrLen : dwLen;
  12375. strncpy(RecAction.pName + dwStrLen + 1, pszTemp, dwLen);
  12376. WinsFreeMemory(pszTemp);
  12377. pszTemp = NULL;
  12378. RecAction.pName[dwLen + dwStrLen + 1] = '\0';
  12379. if( fEndChar and
  12380. ch16thChar is 0x00 )
  12381. dwStrLen = 16+dwLen+1;
  12382. else
  12383. dwStrLen = strlen(RecAction.pName);
  12384. }
  12385. else
  12386. {
  12387. RecAction.pName[dwStrLen] = '\0';
  12388. }
  12389. RecAction.pName[15] = 0x03;
  12390. RecAction.NameLen = dwNameLen;
  12391. pRecAction = &RecAction;
  12392. Status = WinsRecordAction(g_hBind, &pRecAction);
  12393. if( Status is NO_ERROR )
  12394. {
  12395. CHAR chEndChar = pRecAction->pName[15];
  12396. RecAction.pName[RecAction.NameLen] = L'\0';
  12397. memset(wszName, 0x00, MAX_STRING_LEN*sizeof(WCHAR));
  12398. if( pRecAction->NameLen >= 16 )
  12399. {
  12400. chEndChar = pRecAction->pName[15];
  12401. pRecAction->pName[15] = 0x00;
  12402. }
  12403. else
  12404. {
  12405. chEndChar = pRecAction->pName[pRecAction->NameLen];
  12406. pRecAction->pName[pRecAction->NameLen] = 0x00;
  12407. }
  12408. pwszTemp = WinsOemToUnicode(pRecAction->pName, NULL);
  12409. if( pwszTemp is NULL )
  12410. {
  12411. Status = ERROR_NOT_ENOUGH_MEMORY;
  12412. goto ErrorReturn;
  12413. }
  12414. wcscpy(wszName, pwszTemp);
  12415. WinsFreeMemory(pwszTemp);
  12416. pwszTemp = NULL;
  12417. for( i = wcslen(wszName); i < 16; i++ )
  12418. {
  12419. wszName[i] = L' ';
  12420. }
  12421. for( i=wcslen(wszName)+3; j>=15; j-- )
  12422. wszName[j-1] = wszName[j-4];
  12423. wszName[15] = L'[';
  12424. WinsHexToString(wszName+16, (LPBYTE)&chEndChar, 1);
  12425. wszName[18] = L'h';
  12426. wszName[19] = L']';
  12427. if( pRecAction->NameLen > 16 )
  12428. {
  12429. pwszTemp = WinsOemToUnicode(pRecAction->pName+16, NULL);
  12430. if( pwszTemp is NULL )
  12431. {
  12432. Status = ERROR_NOT_ENOUGH_MEMORY;
  12433. goto ErrorReturn;
  12434. }
  12435. wcscpy(wszName + 20 , pwszTemp);
  12436. WinsFreeMemory(pwszTemp);
  12437. pwszTemp = NULL;
  12438. wszName[wcslen(wszName)] = L'\0';
  12439. }
  12440. else
  12441. {
  12442. wszName[20] = L'\0';
  12443. }
  12444. iType = 1;
  12445. pwszTime = GetDateTimeString(pRecAction->TimeStamp,
  12446. FALSE,
  12447. &iType);
  12448. DisplayMessage(g_hModule,
  12449. MSG_WINS_DISPLAY_NAME,
  12450. wszName,
  12451. pRecAction->NodeTyp,
  12452. wszState,
  12453. iType ? wszInfinite : pwszTime,
  12454. wszGroup,
  12455. pRecAction->VersNo.HighPart,
  12456. pRecAction->VersNo.LowPart,
  12457. wszType);
  12458. if( pwszTime )
  12459. {
  12460. WinsFreeMemory(pwszTime);
  12461. pwszTime = NULL;
  12462. }
  12463. if( pRecAction->TypOfRec_e is WINSINTF_E_UNIQUE )
  12464. {
  12465. DisplayMessage(g_hModule,
  12466. MSG_WINS_IPADDRESS_STRING,
  12467. IpAddressToString(pRecAction->Add.IPAdd));
  12468. }
  12469. else
  12470. {
  12471. for (i=0; i<pRecAction->NoOfAdds; )
  12472. {
  12473. DisplayMessage(g_hModule,
  12474. MSG_WINS_OWNER_ADDRESS,
  12475. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12476. DisplayMessage(g_hModule,
  12477. MSG_WINS_MEMBER_ADDRESS,
  12478. IpAddressToString((pRecAction->pAdd + i++)->IPAdd));
  12479. }
  12480. }
  12481. }
  12482. }
  12483. CommonReturn:
  12484. if( Status is NO_ERROR )
  12485. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  12486. if( pdwTagNum )
  12487. {
  12488. WinsFreeMemory(pdwTagNum);
  12489. pdwTagNum = NULL;
  12490. }
  12491. if( pszTemp )
  12492. {
  12493. WinsFreeMemory(pszTemp);
  12494. pszTemp = NULL;
  12495. }
  12496. if( pdwTagType )
  12497. {
  12498. WinsFreeMemory(pdwTagType);
  12499. pdwTagType = NULL;
  12500. }
  12501. if( RecAction.pName )
  12502. {
  12503. WinsFreeMemory(RecAction.pName);
  12504. RecAction.pName = NULL;
  12505. }
  12506. return Status;
  12507. ErrorReturn:
  12508. DisplayErrorMessage(EMSG_SRVR_SHOW_NAME,
  12509. Status);
  12510. goto CommonReturn;
  12511. }
  12512. DWORD
  12513. HandleSrvrShowServer(
  12514. IN LPCWSTR pwszMachine,
  12515. IN OUT LPWSTR *ppwcArguments,
  12516. IN DWORD dwCurrentIndex,
  12517. IN DWORD dwArgCount,
  12518. IN DWORD dwFlags,
  12519. IN LPCVOID pvData,
  12520. OUT BOOL *pbDone
  12521. )
  12522. /*++
  12523. Routine Description :
  12524. Displays the current WINS server
  12525. Arguments :
  12526. All aguments are passes as array of wide char strings in ppwcArguments.
  12527. NONE.
  12528. Return Value:
  12529. Returns the status of the operation.
  12530. --*/
  12531. {
  12532. DisplayMessage(g_hModule,
  12533. MSG_WINS_SERVER_NAME,
  12534. g_ServerNameUnicode,
  12535. g_ServerIpAddressUnicodeString);
  12536. return NO_ERROR;
  12537. }
  12538. DWORD
  12539. HandleSrvrShowStatistics(
  12540. IN LPCWSTR pwszMachine,
  12541. IN OUT LPWSTR *ppwcArguments,
  12542. IN DWORD dwCurrentIndex,
  12543. IN DWORD dwArgCount,
  12544. IN DWORD dwFlags,
  12545. IN LPCVOID pvData,
  12546. OUT BOOL *pbDone
  12547. )
  12548. /*++
  12549. Routine Description :
  12550. Displays the Server statistics
  12551. Arguments :
  12552. All aguments are passes as array of wide char strings in ppwcArguments.
  12553. NONE.
  12554. Return Value:
  12555. Returns the status of the operation.
  12556. --*/
  12557. {
  12558. DWORD Status = NO_ERROR;
  12559. WINSINTF_RESULTS_T Results = {0};
  12560. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  12561. WCHAR IpAddress[33] = {L'\0'};
  12562. WCHAR RepCount[25] = {L'\0'};
  12563. WCHAR Buffer[8] = {L'\0'};
  12564. BOOL fNew = TRUE;
  12565. DWORD i = 0,
  12566. k = 0;
  12567. ResultsN.WinsStat.NoOfPnrs = 0;
  12568. ResultsN.WinsStat.pRplPnrs = NULL;
  12569. ResultsN.pAddVersMaps = NULL;
  12570. Status = WinsStatusNew(g_hBind, WINSINTF_E_STAT, &ResultsN);
  12571. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  12572. {
  12573. //Try old API
  12574. Results.WinsStat.NoOfPnrs = 0;
  12575. Results.WinsStat.pRplPnrs = 0;
  12576. Status = WinsStatus(g_hBind, WINSINTF_E_CONFIG_ALL_MAPS, &Results);
  12577. fNew = FALSE;
  12578. }
  12579. if( Status isnot NO_ERROR )
  12580. {
  12581. DisplayErrorMessage(EMSG_SRVR_SHOW_STATISTICS,
  12582. Status);
  12583. }
  12584. if( fNew )
  12585. {
  12586. DisplayMessage(g_hModule,
  12587. MSG_WINS_TIMESTAMP,
  12588. TMSTN.WinsStartTime.wMonth,
  12589. TMSTN.WinsStartTime.wDay,
  12590. TMSTN.WinsStartTime.wYear,
  12591. TMSTN.WinsStartTime.wHour,
  12592. TMSTN.WinsStartTime.wMinute,
  12593. TMSTN.WinsStartTime.wSecond
  12594. );
  12595. DisplayMessage(g_hModule,
  12596. MSG_WINS_LAST_INIT,
  12597. TIME_ARGSN(LastInitDbTime));
  12598. DisplayMessage(g_hModule,
  12599. MSG_WINS_PLANNED_SCV,
  12600. TIME_ARGSN(LastPScvTime));
  12601. DisplayMessage(g_hModule,
  12602. MSG_WINS_TRIGGERED_SCV,
  12603. TIME_ARGSN(LastATScvTime));
  12604. DisplayMessage(g_hModule,
  12605. MSG_WINS_TOMBSTONE_SCV,
  12606. TIME_ARGSN(LastTombScvTime));
  12607. DisplayMessage(g_hModule,
  12608. MSG_WINS_REPLICA_VERIFICATION,
  12609. TIME_ARGSN(LastVerifyScvTime));
  12610. DisplayMessage(g_hModule,
  12611. MSG_WINS_PLANNED_REPLICATION,
  12612. TMSTN.LastPRplTime.wMonth,
  12613. TMSTN.LastPRplTime.wDay,
  12614. TMSTN.LastPRplTime.wYear,
  12615. TMSTN.LastPRplTime.wHour,
  12616. TMSTN.LastPRplTime.wMinute,
  12617. TMSTN.LastPRplTime.wSecond
  12618. );
  12619. DisplayMessage(g_hModule,
  12620. MSG_WINS_TRIGGERED_REPLICATION,
  12621. TMSTN.LastATRplTime.wMonth,
  12622. TMSTN.LastATRplTime.wDay,
  12623. TMSTN.LastATRplTime.wYear,
  12624. TMSTN.LastATRplTime.wHour,
  12625. TMSTN.LastATRplTime.wMinute,
  12626. TMSTN.LastATRplTime.wSecond
  12627. );
  12628. DisplayMessage(g_hModule,
  12629. MSG_WINS_RESET_COUNTER,
  12630. TIME_ARGSN(CounterResetTime));
  12631. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  12632. DisplayMessage(g_hModule,
  12633. MSG_WINS_COUNTER_INFORMATION,
  12634. ResultsN.WinsStat.Counters.NoOfUniqueReg,
  12635. ResultsN.WinsStat.Counters.NoOfGroupReg,
  12636. ResultsN.WinsStat.Counters.NoOfSuccQueries,
  12637. ResultsN.WinsStat.Counters.NoOfFailQueries,
  12638. ResultsN.WinsStat.Counters.NoOfUniqueRef,
  12639. ResultsN.WinsStat.Counters.NoOfGroupRef,
  12640. ResultsN.WinsStat.Counters.NoOfSuccRel,
  12641. ResultsN.WinsStat.Counters.NoOfFailRel,
  12642. ResultsN.WinsStat.Counters.NoOfUniqueCnf,
  12643. ResultsN.WinsStat.Counters.NoOfGroupCnf
  12644. );
  12645. if (ResultsN.WinsStat.NoOfPnrs)
  12646. {
  12647. DisplayMessage(g_hModule,
  12648. MSG_WINS_PARTNER_TABLE);
  12649. for (i =0; i < ResultsN.WinsStat.NoOfPnrs; i++)
  12650. {
  12651. LPTSTR pstr;
  12652. for(k=0; k<32; k++)
  12653. {
  12654. IpAddress[k] = L' ';
  12655. }
  12656. IpAddress[32] = L'\0';
  12657. for(k=0; k<24; k++)
  12658. RepCount[k] = L' ';
  12659. RepCount[24] = L'\0';
  12660. pstr = IpAddressToString((ResultsN.WinsStat.pRplPnrs + i)->Add.IPAdd);
  12661. if (pstr == NULL)
  12662. {
  12663. Status = ERROR_NOT_ENOUGH_MEMORY;
  12664. break;
  12665. }
  12666. wcscpy(IpAddress+8, pstr);
  12667. IpAddress[wcslen(IpAddress)] = L' ';
  12668. _itow((ResultsN.WinsStat.pRplPnrs + i)->NoOfRpls, Buffer, 10);
  12669. wcscpy(RepCount+8, Buffer);
  12670. RepCount[wcslen(RepCount)] = L' ';
  12671. DisplayMessage(g_hModule,
  12672. MSG_WINS_PARTNER_INFO,
  12673. IpAddress,
  12674. RepCount,
  12675. (ResultsN.WinsStat.pRplPnrs + i)->NoOfCommFails
  12676. );
  12677. }
  12678. }
  12679. WinsFreeMem(ResultsN.pAddVersMaps);
  12680. ResultsN.pAddVersMaps = NULL;
  12681. WinsFreeMem(ResultsN.WinsStat.pRplPnrs);
  12682. ResultsN.WinsStat.pRplPnrs = NULL;
  12683. }
  12684. else
  12685. {
  12686. DisplayMessage(g_hModule,
  12687. MSG_WINS_TIMESTAMP,
  12688. TMST.WinsStartTime.wMonth,
  12689. TMST.WinsStartTime.wDay,
  12690. TMST.WinsStartTime.wYear,
  12691. TMST.WinsStartTime.wHour,
  12692. TMST.WinsStartTime.wMinute,
  12693. TMST.WinsStartTime.wSecond
  12694. );
  12695. DisplayMessage(g_hModule,
  12696. MSG_WINS_LAST_INIT,
  12697. TIME_ARGS(LastInitDbTime));
  12698. DisplayMessage(g_hModule,
  12699. MSG_WINS_PLANNED_SCV,
  12700. TIME_ARGS(LastPScvTime));
  12701. DisplayMessage(g_hModule,
  12702. MSG_WINS_TRIGGERED_SCV,
  12703. TIME_ARGS(LastATScvTime));
  12704. DisplayMessage(g_hModule,
  12705. MSG_WINS_TOMBSTONE_SCV,
  12706. TIME_ARGS(LastTombScvTime));
  12707. DisplayMessage(g_hModule,
  12708. MSG_WINS_REPLICA_VERIFICATION,
  12709. TIME_ARGS(LastVerifyScvTime));
  12710. DisplayMessage(g_hModule,
  12711. MSG_WINS_PLANNED_REPLICATION,
  12712. TMST.LastPRplTime.wMonth,
  12713. TMST.LastPRplTime.wDay,
  12714. TMST.LastPRplTime.wYear,
  12715. TMST.LastPRplTime.wHour,
  12716. TMST.LastPRplTime.wMinute,
  12717. TMST.LastPRplTime.wSecond
  12718. );
  12719. DisplayMessage(g_hModule,
  12720. MSG_WINS_TRIGGERED_REPLICATION,
  12721. TMST.LastATRplTime.wMonth,
  12722. TMST.LastATRplTime.wDay,
  12723. TMST.LastATRplTime.wYear,
  12724. TMST.LastATRplTime.wHour,
  12725. TMST.LastATRplTime.wMinute,
  12726. TMST.LastATRplTime.wSecond
  12727. );
  12728. DisplayMessage(g_hModule,
  12729. MSG_WINS_RESET_COUNTER,
  12730. TIME_ARGS(CounterResetTime));
  12731. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  12732. DisplayMessage(g_hModule,
  12733. MSG_WINS_COUNTER_INFORMATION,
  12734. Results.WinsStat.Counters.NoOfUniqueReg,
  12735. Results.WinsStat.Counters.NoOfGroupReg,
  12736. Results.WinsStat.Counters.NoOfSuccQueries,
  12737. Results.WinsStat.Counters.NoOfFailQueries,
  12738. Results.WinsStat.Counters.NoOfUniqueRef,
  12739. Results.WinsStat.Counters.NoOfGroupRef,
  12740. Results.WinsStat.Counters.NoOfSuccRel,
  12741. Results.WinsStat.Counters.NoOfFailRel,
  12742. Results.WinsStat.Counters.NoOfUniqueCnf,
  12743. Results.WinsStat.Counters.NoOfGroupCnf
  12744. );
  12745. if (Results.WinsStat.NoOfPnrs)
  12746. {
  12747. DisplayMessage(g_hModule,
  12748. MSG_WINS_PARTNER_TABLE);
  12749. for (i =0; i < Results.WinsStat.NoOfPnrs; i++)
  12750. {
  12751. for(k=0; k<32; k++)
  12752. {
  12753. IpAddress[k] = L' ';
  12754. }
  12755. IpAddress[32] = L'\0';
  12756. for(k=0; k<24; k++)
  12757. RepCount[k] = L' ';
  12758. RepCount[24] = L'\0';
  12759. wcscpy(IpAddress+8, IpAddressToString((Results.WinsStat.pRplPnrs + i)->Add.IPAdd));
  12760. IpAddress[wcslen(IpAddress)] = L' ';
  12761. _itow((Results.WinsStat.pRplPnrs + i)->NoOfRpls, Buffer, 10);
  12762. wcscpy(RepCount+8, Buffer);
  12763. RepCount[wcslen(RepCount)] = L' ';
  12764. DisplayMessage(g_hModule,
  12765. MSG_WINS_PARTNER_INFO,
  12766. IpAddress,
  12767. RepCount,
  12768. (Results.WinsStat.pRplPnrs + i)->NoOfCommFails
  12769. );
  12770. }
  12771. }
  12772. WinsFreeMem(Results.WinsStat.pRplPnrs);
  12773. Results.WinsStat.pRplPnrs = NULL;
  12774. }
  12775. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  12776. return Status;
  12777. }
  12778. DWORD
  12779. HandleSrvrShowVersion(
  12780. IN LPCWSTR pwszMachine,
  12781. IN OUT LPWSTR *ppwcArguments,
  12782. IN DWORD dwCurrentIndex,
  12783. IN DWORD dwArgCount,
  12784. IN DWORD dwFlags,
  12785. IN LPCVOID pvData,
  12786. OUT BOOL *pbDone
  12787. )
  12788. /*++
  12789. Routine Description :
  12790. Displas the current version counter value.
  12791. Arguments :
  12792. All aguments are passes as array of wide char strings in ppwcArguments.
  12793. NONE.
  12794. Return Value:
  12795. Returns the status of the operation.
  12796. --*/
  12797. {
  12798. DWORD Status = NO_ERROR;
  12799. WINSINTF_RESULTS_T Results;
  12800. Results.AddVersMaps[0].Add.Len = 4;
  12801. Results.AddVersMaps[0].Add.Type = 0;
  12802. Results.AddVersMaps[0].Add.IPAdd = StringToIpAddress(g_ServerIpAddressUnicodeString);
  12803. Results.WinsStat.NoOfPnrs = 0;
  12804. Results.WinsStat.pRplPnrs = NULL;
  12805. Status = WinsStatus(g_hBind, WINSINTF_E_ADDVERSMAP, &Results);
  12806. if( Status isnot NO_ERROR )
  12807. {
  12808. DisplayErrorMessage(EMSG_SRVR_SHOW_VERSION,
  12809. Status);
  12810. return Status;
  12811. }
  12812. DisplayMessage(g_hModule,
  12813. MSG_WINS_VERSION_INFO,
  12814. g_ServerIpAddressUnicodeString,
  12815. Results.AddVersMaps[0].VersNo.HighPart,
  12816. Results.AddVersMaps[0].VersNo.LowPart);
  12817. return Status;
  12818. }
  12819. DWORD
  12820. HandleSrvrShowVersionmap(
  12821. IN LPCWSTR pwszMachine,
  12822. IN OUT LPWSTR *ppwcArguments,
  12823. IN DWORD dwCurrentIndex,
  12824. IN DWORD dwArgCount,
  12825. IN DWORD dwFlags,
  12826. IN LPCVOID pvData,
  12827. OUT BOOL *pbDone
  12828. )
  12829. /*++
  12830. Routine Description :
  12831. Displays the version mapping
  12832. Arguments :
  12833. All aguments are passes as array of wide char strings in ppwcArguments.
  12834. NONE.
  12835. Return Value:
  12836. Returns the status of the operation.
  12837. --*/
  12838. {
  12839. DWORD Status = NO_ERROR;
  12840. WINSINTF_RESULTS_T Results = {0};
  12841. WINSINTF_RESULTS_NEW_T ResultsN = {0};
  12842. LPSTR pszIp = NULL;
  12843. ResultsN.WinsStat.NoOfPnrs = 0;
  12844. ResultsN.WinsStat.pRplPnrs = NULL;
  12845. pszIp = WinsUnicodeToOem(g_ServerIpAddressUnicodeString, NULL);
  12846. if( pszIp is NULL )
  12847. {
  12848. DisplayMessage(g_hModule,
  12849. EMSG_WINS_OUT_OF_MEMORY);
  12850. Status = ERROR_NOT_ENOUGH_MEMORY;
  12851. return Status;
  12852. }
  12853. Status = GetStatus(TRUE, (LPVOID)&ResultsN, TRUE, TRUE, pszIp);
  12854. if( Status is RPC_S_PROCNUM_OUT_OF_RANGE )
  12855. {
  12856. //Try old API
  12857. Results.WinsStat.NoOfPnrs = 0;
  12858. Results.WinsStat.pRplPnrs = 0;
  12859. Status = GetStatus(TRUE, (LPVOID)&Results, FALSE, TRUE, pszIp);
  12860. }
  12861. WinsFreeMemory(pszIp);
  12862. pszIp = NULL;
  12863. if( ResultsN.pAddVersMaps )
  12864. {
  12865. WinsFreeMem(ResultsN.pAddVersMaps);
  12866. ResultsN.pAddVersMaps = NULL;
  12867. }
  12868. if( Status isnot NO_ERROR )
  12869. {
  12870. DisplayErrorMessage(EMSG_SRVR_SHOW_VERSIONMAP,
  12871. Status);
  12872. return Status;
  12873. }
  12874. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  12875. return Status;
  12876. }
  12877. DWORD
  12878. HandleSrvrShowPartnerproperties(
  12879. IN LPCWSTR pwszMachine,
  12880. IN OUT LPWSTR *ppwcArguments,
  12881. IN DWORD dwCurrentIndex,
  12882. IN DWORD dwArgCount,
  12883. IN DWORD dwFlags,
  12884. IN LPCVOID pvData,
  12885. OUT BOOL *pbDone
  12886. )
  12887. /*++
  12888. Routine Description :
  12889. Displays the default partner properties
  12890. Arguments :
  12891. All aguments are passes as array of wide char strings in ppwcArguments.
  12892. NONE.
  12893. Return Value:
  12894. Returns the status of the operation.
  12895. --*/
  12896. {
  12897. DWORD Status = NO_ERROR;
  12898. HKEY hServer = NULL,
  12899. hDefaultPull = NULL,
  12900. hDefaultPush = NULL,
  12901. hPullRoot = NULL,
  12902. hPushRoot = NULL,
  12903. hPartner = NULL,
  12904. hParameter = NULL;
  12905. LPWSTR pTemp = NULL,
  12906. pServerList = NULL;
  12907. WCHAR wcBuffer[255] = {L'\0'};
  12908. DWORD dwRplWCnfPnrs = 0,
  12909. dwMigrate = 0,
  12910. dwData = 0,
  12911. i = 0,
  12912. dwPersonaMode = 0,
  12913. dwSelfFndPnrs = 0;
  12914. DWORD dwType = REG_DWORD;
  12915. DWORD dwSize = sizeof(DWORD);
  12916. LPBYTE pbData = NULL;
  12917. if( wcslen(g_ServerNetBiosName) > 0 )
  12918. {
  12919. pTemp = g_ServerNetBiosName;
  12920. }
  12921. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  12922. if( Status isnot NO_ERROR )
  12923. goto ErrorReturn;
  12924. Status = RegOpenKeyEx(hServer,
  12925. PARAMETER,
  12926. 0,
  12927. KEY_READ,
  12928. &hParameter);
  12929. if( Status isnot NO_ERROR )
  12930. {
  12931. goto ErrorReturn;
  12932. }
  12933. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  12934. Status = RegQueryValueEx(hParameter,
  12935. WINSCNF_RPL_ONLY_W_CNF_PNRS_NM,
  12936. 0,
  12937. &dwType,
  12938. (LPBYTE)&dwRplWCnfPnrs,
  12939. &dwSize);
  12940. if( Status is NO_ERROR )
  12941. {
  12942. DisplayMessage(g_hModule,
  12943. MSG_SRVR_REPLICATE_STATE,
  12944. dwRplWCnfPnrs ? wszEnable : wszDisable);
  12945. }
  12946. else
  12947. {
  12948. DisplayMessage(g_hModule,
  12949. MSG_SRVR_REPLICATE_STATE,
  12950. wszUnknown);
  12951. }
  12952. dwMigrate = 0;
  12953. dwSize = sizeof(DWORD);
  12954. Status = RegQueryValueEx(hParameter,
  12955. WINSCNF_MIGRATION_ON_NM,
  12956. 0,
  12957. &dwType,
  12958. (LPBYTE)&dwMigrate,
  12959. &dwSize);
  12960. if( Status is NO_ERROR )
  12961. {
  12962. DisplayMessage(g_hModule,
  12963. MSG_SRVR_MIGRATE_STATE,
  12964. dwMigrate ? wszEnable : wszDisable);
  12965. }
  12966. else
  12967. {
  12968. DisplayMessage(g_hModule,
  12969. MSG_SRVR_MIGRATE_STATE,
  12970. wszUnknown);
  12971. }
  12972. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  12973. DisplayMessage(g_hModule, MSG_SRVR_AUTOCONFIGURE);
  12974. Status = RegQueryValueEx(hParameter,
  12975. WINSCNF_USE_SELF_FND_PNRS_NM,
  12976. 0,
  12977. &dwType,
  12978. (LPBYTE)&dwSelfFndPnrs,
  12979. &dwSize);
  12980. if( Status isnot NO_ERROR )
  12981. {
  12982. DisplayMessage(g_hModule,
  12983. MSG_SRVR_SELFFINDPNRS_STATE,
  12984. wszUnknown);
  12985. }
  12986. else
  12987. {
  12988. DisplayMessage(g_hModule,
  12989. MSG_SRVR_SELFFINDPNRS_STATE,
  12990. dwSelfFndPnrs ? wszEnable : wszDisable);
  12991. if( dwSelfFndPnrs > 0 )
  12992. {
  12993. dwData = 0;
  12994. dwSize = sizeof(DWORD);
  12995. Status = RegQueryValueEx(hParameter,
  12996. WINSCNF_MCAST_INTVL_NM,
  12997. 0,
  12998. &dwType,
  12999. (LPBYTE)&dwData,
  13000. &dwSize);
  13001. if(Status is NO_ERROR )
  13002. {
  13003. LPWSTR pwszTime = MakeTimeString(dwData);
  13004. if( pwszTime is NULL )
  13005. {
  13006. Status = ERROR_NOT_ENOUGH_MEMORY;
  13007. goto ErrorReturn;
  13008. }
  13009. DisplayMessage(g_hModule,
  13010. MSG_SRVR_MCAST_INTERVAL,
  13011. pwszTime);
  13012. WinsFreeMemory(pwszTime);
  13013. pwszTime = NULL;
  13014. }
  13015. else
  13016. {
  13017. DisplayMessage(g_hModule,
  13018. MSG_SRVR_MCAST_INTERVAL,
  13019. wszUnknown);
  13020. }
  13021. dwData = 0;
  13022. dwSize = sizeof(DWORD);
  13023. Status = RegQueryValueEx(hParameter,
  13024. WINSCNF_MCAST_TTL_NM,
  13025. 0,
  13026. &dwType,
  13027. (LPBYTE)&dwData,
  13028. &dwSize);
  13029. if( Status is NO_ERROR )
  13030. {
  13031. WCHAR Buffer[10] = {L'\0'};
  13032. _itow(dwData, Buffer, 10);
  13033. DisplayMessage(g_hModule,
  13034. MSG_SRVR_MCAST_TTL,
  13035. Buffer);
  13036. }
  13037. else
  13038. {
  13039. DisplayMessage(g_hModule,
  13040. MSG_SRVR_MCAST_TTL,
  13041. wszUnknown);
  13042. }
  13043. }
  13044. }
  13045. //Display PNG Servers
  13046. DisplayMessage(g_hModule,
  13047. WINS_FORMAT_LINE);
  13048. Status = RegOpenKeyEx(hServer,
  13049. PARTNERROOT,
  13050. 0,
  13051. KEY_READ,
  13052. &hPartner);
  13053. if( Status isnot NO_ERROR )
  13054. goto ErrorReturn;
  13055. dwSize = sizeof(DWORD);
  13056. Status = RegQueryValueEx(hPartner,
  13057. TEXT(WINSCNF_PERSONA_MODE_NM),
  13058. 0,
  13059. &dwType,
  13060. (LPVOID)&dwPersonaMode,
  13061. &dwSize);
  13062. DisplayMessage(g_hModule,
  13063. dwPersonaMode == PERSMODE_NON_GRATA ?
  13064. MSG_WINS_PNGSERVER_TABLE : MSG_WINS_PGSERVER_TABLE);
  13065. dwSize = 0;
  13066. Status = RegQueryValueEx(hPartner,
  13067. dwPersonaMode == PERSMODE_NON_GRATA ? PNGSERVER : PGSERVER,
  13068. 0,
  13069. &dwType,
  13070. NULL,
  13071. &dwSize);
  13072. if( dwSize <= 2 )
  13073. {
  13074. DisplayMessage(g_hModule,
  13075. dwPersonaMode == PERSMODE_NON_GRATA ? MSG_WINS_NO_PNGSERVER : MSG_WINS_NO_PGSERVER);
  13076. }
  13077. else
  13078. {
  13079. pbData = WinsAllocateMemory(dwSize);
  13080. if( pbData is NULL )
  13081. {
  13082. Status = ERROR_NOT_ENOUGH_MEMORY;
  13083. goto ErrorReturn;
  13084. }
  13085. Status = RegQueryValueEx(hPartner,
  13086. dwPersonaMode == PERSMODE_NON_GRATA ? PNGSERVER : PGSERVER,
  13087. 0,
  13088. &dwType,
  13089. pbData,
  13090. &dwSize);
  13091. if( Status isnot NO_ERROR )
  13092. goto ErrorReturn;
  13093. pServerList = (LPWSTR)pbData;
  13094. i = 0;
  13095. while(TRUE)
  13096. {
  13097. if ( i+1 < dwSize/sizeof(WCHAR) )
  13098. {
  13099. if( pServerList[i] is L'\0' and
  13100. pServerList[i+1] isnot L'\0' )
  13101. {
  13102. pServerList[i] = L',';
  13103. }
  13104. i++;
  13105. }
  13106. else
  13107. break;
  13108. }
  13109. pTemp = wcstok(pServerList, L",");
  13110. while(pTemp isnot NULL )
  13111. {
  13112. DisplayMessage(g_hModule,
  13113. dwPersonaMode == PERSMODE_NON_GRATA ? MSG_WINS_PNGSERVER_ENTRY : MSG_WINS_PGSERVER_ENTRY,
  13114. pTemp);
  13115. pTemp = wcstok(NULL, L",");
  13116. }
  13117. }
  13118. Status = RegOpenKeyEx(hServer,
  13119. DEFAULTPULL,
  13120. 0,
  13121. KEY_READ,
  13122. &hDefaultPull);
  13123. if( Status is ERROR_FILE_NOT_FOUND )
  13124. {
  13125. DisplayMessage(g_hModule,
  13126. MSG_NO_DEFAULT_PULL);
  13127. }
  13128. else if( Status isnot NO_ERROR )
  13129. {
  13130. goto ErrorReturn;
  13131. }
  13132. Status = RegOpenKeyEx(hServer,
  13133. PULLROOT,
  13134. 0,
  13135. KEY_READ,
  13136. &hPullRoot);
  13137. if( Status is ERROR_FILE_NOT_FOUND )
  13138. {
  13139. DisplayMessage(g_hModule,
  13140. MSG_NO_DEFAULT_PULL);
  13141. }
  13142. else if( Status isnot NO_ERROR )
  13143. goto ErrorReturn;
  13144. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  13145. DisplayMessage(g_hModule, MSG_SRVR_PULL_INFO);
  13146. dwData = 0;
  13147. dwSize = sizeof(DWORD);
  13148. if( hPullRoot isnot NULL )
  13149. {
  13150. Status = RegQueryValueEx(hPullRoot,
  13151. PERSISTENCE,
  13152. 0,
  13153. &dwType,
  13154. (LPBYTE)&dwData,
  13155. &dwSize);
  13156. if( Status is NO_ERROR )
  13157. {
  13158. DisplayMessage(g_hModule,
  13159. MSG_SRVR_PULL_PERSISTENCE_STATE,
  13160. dwData ? wszEnable : wszDisable);
  13161. }
  13162. else
  13163. {
  13164. DisplayMessage(g_hModule,
  13165. MSG_SRVR_PULL_PERSISTENCE_STATE,
  13166. wszUnknown);
  13167. }
  13168. dwData = 0;
  13169. dwSize = sizeof(DWORD);
  13170. Status = RegQueryValueEx(hPullRoot,
  13171. WINSCNF_INIT_TIME_RPL_NM,
  13172. 0,
  13173. &dwType,
  13174. (LPBYTE)&dwData,
  13175. &dwSize);
  13176. if( Status is NO_ERROR )
  13177. {
  13178. DisplayMessage(g_hModule,
  13179. MSG_SRVR_PULL_INITTIMEREPL_STATE,
  13180. dwData ? wszEnable : wszDisable);
  13181. }
  13182. else
  13183. {
  13184. DisplayMessage(g_hModule,
  13185. MSG_SRVR_PULL_INITTIMEREPL_STATE,
  13186. wszUnknown);
  13187. }
  13188. }
  13189. dwData = 0;
  13190. dwSize = 255;
  13191. if( hDefaultPull isnot NULL )
  13192. {
  13193. Status = RegQueryValueEx(hDefaultPull,
  13194. WINSCNF_SP_TIME_NM,
  13195. 0,
  13196. &dwType,
  13197. (LPBYTE)wcBuffer,
  13198. &dwSize);
  13199. if( Status is NO_ERROR )
  13200. {
  13201. DisplayMessage(g_hModule,
  13202. MSG_SRVR_PULL_STARTTIME,
  13203. wcBuffer);
  13204. }
  13205. else
  13206. {
  13207. DisplayMessage(g_hModule,
  13208. MSG_SRVR_PULL_STARTTIME,
  13209. wszUnknown);
  13210. }
  13211. dwSize = sizeof(DWORD);
  13212. dwData = 0;
  13213. Status = RegQueryValueEx(hDefaultPull,
  13214. WINSCNF_RPL_INTERVAL_NM,
  13215. 0,
  13216. &dwType,
  13217. (LPBYTE)&dwData,
  13218. &dwSize);
  13219. if( Status is NO_ERROR )
  13220. {
  13221. LPWSTR pwszDayString = MakeDayTimeString(dwData);
  13222. DisplayMessage(g_hModule,
  13223. MSG_WINS_PULL_REPLINTERVAL,
  13224. MakeDayTimeString(dwData));
  13225. WinsFreeMemory(pwszDayString);
  13226. pwszDayString = NULL;
  13227. }
  13228. else
  13229. {
  13230. DisplayMessage(g_hModule,
  13231. MSG_WINS_PULL_REPLINTERVAL,
  13232. wszUnknown);
  13233. }
  13234. }
  13235. dwData = 0;
  13236. dwSize = sizeof(DWORD);
  13237. if( hPullRoot isnot NULL )
  13238. {
  13239. Status = RegQueryValueEx(hPullRoot,
  13240. WINSCNF_RETRY_COUNT_NM,
  13241. 0,
  13242. &dwType,
  13243. (LPBYTE)&dwData,
  13244. &dwSize);
  13245. if( Status is NO_ERROR )
  13246. {
  13247. WCHAR Buffer[20];
  13248. _itow(dwData, Buffer, 10);
  13249. DisplayMessage(g_hModule,
  13250. MSG_WINS_PULL_RETRYCOUNT,
  13251. Buffer);
  13252. }
  13253. else
  13254. {
  13255. DisplayMessage(g_hModule,
  13256. MSG_WINS_PULL_RETRYCOUNT,
  13257. wszUnknown);
  13258. }
  13259. }
  13260. Status = RegOpenKeyEx(hServer,
  13261. DEFAULTPUSH,
  13262. 0,
  13263. KEY_READ,
  13264. &hDefaultPush);
  13265. if( Status is ERROR_FILE_NOT_FOUND )
  13266. {
  13267. DisplayMessage(g_hModule,
  13268. MSG_NO_DEFAULT_PUSH);
  13269. }
  13270. else if( Status isnot NO_ERROR )
  13271. goto ErrorReturn;
  13272. Status = RegOpenKeyEx(hServer,
  13273. PUSHROOT,
  13274. 0,
  13275. KEY_READ,
  13276. &hPushRoot);
  13277. if( Status is ERROR_FILE_NOT_FOUND )
  13278. {
  13279. DisplayMessage(g_hModule,
  13280. MSG_NO_DEFAULT_PUSH);
  13281. }
  13282. else if( Status isnot NO_ERROR )
  13283. goto ErrorReturn;
  13284. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  13285. DisplayMessage(g_hModule, MSG_SRVR_PUSH_INFO);
  13286. dwData = 0;
  13287. dwSize = sizeof(DWORD);
  13288. if( hPushRoot isnot NULL )
  13289. {
  13290. Status = RegQueryValueEx(hPushRoot,
  13291. PERSISTENCE,
  13292. 0,
  13293. &dwType,
  13294. (LPBYTE)&dwData,
  13295. &dwSize);
  13296. if( Status is NO_ERROR )
  13297. {
  13298. DisplayMessage(g_hModule,
  13299. MSG_SRVR_PUSH_PERSISTENCE_STATE,
  13300. dwData ? wszEnable : wszDisable);
  13301. }
  13302. else
  13303. {
  13304. DisplayMessage(g_hModule,
  13305. MSG_SRVR_PUSH_PERSISTENCE_STATE,
  13306. wszUnknown);
  13307. }
  13308. dwData = 0;
  13309. dwSize = sizeof(DWORD);
  13310. Status = RegQueryValueEx(hPushRoot,
  13311. WINSCNF_INIT_TIME_RPL_NM,
  13312. 0,
  13313. &dwType,
  13314. (LPBYTE)&dwData,
  13315. &dwSize);
  13316. if( Status is NO_ERROR )
  13317. {
  13318. DisplayMessage(g_hModule,
  13319. MSG_SRVR_PUSH_INITTIMEREPL_STATE,
  13320. dwData ? wszEnable : wszDisable);
  13321. }
  13322. else
  13323. {
  13324. DisplayMessage(g_hModule,
  13325. MSG_SRVR_PUSH_INITTIMEREPL_STATE,
  13326. wszUnknown);
  13327. }
  13328. dwData = 0;
  13329. dwSize = sizeof(DWORD);
  13330. Status = RegQueryValueEx(hPushRoot,
  13331. WINSCNF_ADDCHG_TRIGGER_NM,
  13332. 0,
  13333. &dwType,
  13334. (LPBYTE)&dwData,
  13335. &dwSize);
  13336. if( Status is NO_ERROR )
  13337. {
  13338. DisplayMessage(g_hModule,
  13339. MSG_SRVR_PUSH_ONADDCHANGE,
  13340. dwData ? wszEnable : wszDisable);
  13341. }
  13342. else
  13343. {
  13344. DisplayMessage(g_hModule,
  13345. MSG_SRVR_PUSH_ONADDCHANGE,
  13346. wszUnknown);
  13347. }
  13348. }
  13349. dwData = 0;
  13350. dwSize = sizeof(DWORD);
  13351. Status = NO_ERROR;
  13352. if( hDefaultPush isnot NULL )
  13353. {
  13354. Status = RegQueryValueEx(hDefaultPush,
  13355. WINSCNF_UPDATE_COUNT_NM,
  13356. 0,
  13357. &dwType,
  13358. (LPBYTE)&dwData,
  13359. &dwSize);
  13360. if( Status is NO_ERROR )
  13361. {
  13362. WCHAR Buffer[10] = {L'\0'};
  13363. _itow(dwData, Buffer, 10);
  13364. DisplayMessage(g_hModule,
  13365. MSG_SRVR_PUSH_UPDATECOUNT,
  13366. Buffer);
  13367. }
  13368. else
  13369. {
  13370. DisplayMessage(g_hModule,
  13371. MSG_SRVR_PUSH_UPDATECOUNT,
  13372. wszUnknown);
  13373. }
  13374. }
  13375. CommonReturn:
  13376. if( Status is NO_ERROR )
  13377. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  13378. if( hPushRoot )
  13379. {
  13380. RegCloseKey(hPushRoot);
  13381. hPushRoot = NULL;
  13382. }
  13383. if( hPullRoot )
  13384. {
  13385. RegCloseKey(hPullRoot);
  13386. hPullRoot = NULL;
  13387. }
  13388. if( hDefaultPush )
  13389. {
  13390. RegCloseKey(hDefaultPush);
  13391. hDefaultPush = NULL;
  13392. }
  13393. if( hDefaultPull )
  13394. {
  13395. RegCloseKey(hDefaultPull);
  13396. hDefaultPull = NULL;
  13397. }
  13398. if( hParameter )
  13399. {
  13400. RegCloseKey(hParameter);
  13401. hParameter = NULL;
  13402. }
  13403. if( hPartner )
  13404. {
  13405. RegCloseKey(hPartner);
  13406. hPartner = NULL;
  13407. }
  13408. if( hServer )
  13409. {
  13410. RegCloseKey(hServer);
  13411. hServer = NULL;
  13412. }
  13413. if( pbData )
  13414. {
  13415. WinsFreeMemory(pbData);
  13416. pbData = NULL;
  13417. }
  13418. return Status;
  13419. ErrorReturn:
  13420. if( Status is ERROR_FILE_NOT_FOUND )
  13421. {
  13422. DisplayMessage(g_hModule,
  13423. MSG_WINS_NO_PARTNER);
  13424. }
  13425. else
  13426. {
  13427. DisplayErrorMessage(EMSG_SRVR_SHOW_PARTNERPROPERTIES,
  13428. Status);
  13429. }
  13430. goto CommonReturn;
  13431. }
  13432. DWORD
  13433. HandleSrvrShowPullpartnerproperties(
  13434. IN LPCWSTR pwszMachine,
  13435. IN OUT LPWSTR *ppwcArguments,
  13436. IN DWORD dwCurrentIndex,
  13437. IN DWORD dwArgCount,
  13438. IN DWORD dwFlags,
  13439. IN LPCVOID pvData,
  13440. OUT BOOL *pbDone
  13441. )
  13442. /*++
  13443. Routine Description :
  13444. Displays the properties for a particular Pull partner
  13445. Arguments :
  13446. All aguments are passes as array of wide char strings in ppwcArguments.
  13447. Compulsory : Pull partner address
  13448. Return Value:
  13449. Returns the status of the operation.
  13450. --*/
  13451. {
  13452. DWORD Status = NO_ERROR;
  13453. DWORD i, j, dwNumArgs, dwTagCount;
  13454. TAG_TYPE pttTags[] = {
  13455. {WINS_TOKEN_SERVER, TRUE, FALSE},
  13456. };
  13457. PDWORD pdwTagType = NULL,
  13458. pdwTagNum = NULL;
  13459. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  13460. HKEY hPullRoot = NULL,
  13461. hPullServer = NULL,
  13462. hServer = NULL;
  13463. BOOL fPush = FALSE;
  13464. LPWSTR pTemp = NULL;
  13465. if( dwArgCount < dwCurrentIndex + 1 )
  13466. {
  13467. DisplayMessage(g_hModule, HLP_SRVR_SHOW_PULLPARTNERPROPERTIES_EX);
  13468. Status = ERROR_INVALID_PARAMETER;
  13469. goto ErrorReturn;
  13470. }
  13471. dwNumArgs = dwArgCount - dwCurrentIndex;
  13472. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  13473. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  13474. if( pdwTagType is NULL or
  13475. pdwTagNum is NULL )
  13476. {
  13477. Status = ERROR_NOT_ENOUGH_MEMORY;
  13478. goto ErrorReturn;
  13479. }
  13480. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  13481. Status = PreProcessCommand(ppwcArguments,
  13482. dwArgCount,
  13483. dwCurrentIndex,
  13484. pttTags,
  13485. &dwTagCount,
  13486. pdwTagType,
  13487. pdwTagNum);
  13488. if( Status isnot NO_ERROR )
  13489. goto ErrorReturn;
  13490. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  13491. {
  13492. if( pttTags[i].dwRequired is TRUE and
  13493. pttTags[i].bPresent is FALSE
  13494. )
  13495. {
  13496. Status = ERROR_INVALID_PARAMETER;
  13497. goto ErrorReturn;
  13498. }
  13499. }
  13500. for( j=0; j<dwTagCount; j++ )
  13501. {
  13502. switch(pdwTagType[j])
  13503. {
  13504. case 0:
  13505. {
  13506. struct hostent * lpHostEnt = NULL;
  13507. CHAR cAddr[16];
  13508. BYTE pbAdd[4];
  13509. char szAdd[4];
  13510. int k = 0, l=0;
  13511. DWORD dwLen, nLen = 0;
  13512. CHAR *pTemp = NULL;
  13513. CHAR *pNetBios = NULL;
  13514. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  13515. {
  13516. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  13517. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  13518. if(lpHostEnt isnot NULL )//Valid IP Address
  13519. {
  13520. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  13521. break;
  13522. }
  13523. else
  13524. {
  13525. Status = ERROR_INVALID_IPADDRESS;
  13526. goto ErrorReturn;
  13527. }
  13528. }
  13529. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  13530. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  13531. k = 2;
  13532. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  13533. if( lpHostEnt is NULL )
  13534. {
  13535. DisplayMessage(g_hModule,
  13536. EMSG_WINS_INVALID_COMPUTER_NAME,
  13537. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  13538. Status = ERROR_INVALID_PARAMETER;
  13539. goto ErrorReturn;
  13540. }
  13541. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  13542. for( l=0;l<4; l++)
  13543. {
  13544. _itoa((int)pbAdd[l], szAdd, 10);
  13545. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  13546. nLen += strlen(szAdd);
  13547. *(cAddr+nLen) = '.';
  13548. nLen++;
  13549. }
  13550. *(cAddr+nLen-1) = '\0';
  13551. {
  13552. LPWSTR pstr = WinsAnsiToUnicode(cAddr, NULL);
  13553. if (pstr != NULL)
  13554. {
  13555. wcscpy(wcServerIpAdd, pstr);
  13556. WinsFreeMemory(pstr);
  13557. }
  13558. else
  13559. {
  13560. Status = ERROR_NOT_ENOUGH_MEMORY;
  13561. goto ErrorReturn;
  13562. }
  13563. }
  13564. break;
  13565. }
  13566. default:
  13567. {
  13568. Status = ERROR_INVALID_PARAMETER;
  13569. goto ErrorReturn;
  13570. }
  13571. }
  13572. }
  13573. if( wcslen(g_ServerNetBiosName) > 0 )
  13574. {
  13575. pTemp = g_ServerNetBiosName;
  13576. }
  13577. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  13578. if( Status isnot NO_ERROR )
  13579. goto ErrorReturn;
  13580. Status = RegOpenKeyEx(hServer,
  13581. PULLROOT,
  13582. 0,
  13583. KEY_READ,
  13584. &hPullRoot);
  13585. if( Status isnot NO_ERROR )
  13586. {
  13587. goto ErrorReturn;
  13588. }
  13589. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  13590. //Now check if the desired server is in the list of pull server.
  13591. Status = RegOpenKeyEx(hPullRoot,
  13592. wcServerIpAdd,
  13593. 0,
  13594. KEY_READ,
  13595. &hPullServer);
  13596. if( Status isnot NO_ERROR )
  13597. {
  13598. DisplayMessage(g_hModule,
  13599. EMSG_WINS_INVALID_PULLPARTNER,
  13600. wcServerIpAdd,
  13601. g_ServerIpAddressUnicodeString);
  13602. goto CommonReturn;
  13603. }
  13604. //Check if it is also a push partner or not.
  13605. {
  13606. DWORD dwKeyLen = 0;
  13607. HKEY hPushServer = NULL;
  13608. dwKeyLen = wcslen(PUSHROOT)+ wcslen(L"\\") + wcslen(wcServerIpAdd);
  13609. pTemp = WinsAllocateMemory((dwKeyLen+1)*sizeof(WCHAR));
  13610. if(pTemp is NULL )
  13611. {
  13612. Status = ERROR_NOT_ENOUGH_MEMORY;
  13613. goto ErrorReturn;
  13614. }
  13615. memset(pTemp, 0x00, (dwKeyLen+1)*sizeof(WCHAR));
  13616. wcscat(pTemp,PUSHROOT);
  13617. wcscat(pTemp, L"\\");
  13618. wcscat(pTemp, wcServerIpAdd);
  13619. Status = RegOpenKeyEx(hServer,
  13620. pTemp,
  13621. 0,
  13622. KEY_READ,
  13623. &hPushServer);
  13624. if( Status isnot NO_ERROR )
  13625. {
  13626. fPush = FALSE;
  13627. }
  13628. else
  13629. {
  13630. fPush = TRUE;
  13631. }
  13632. WinsFreeMemory(pTemp);
  13633. pTemp = NULL;
  13634. if( hPushServer )
  13635. {
  13636. RegCloseKey(hPushServer);
  13637. hPushServer = NULL;
  13638. }
  13639. }
  13640. //Now look for required parameters to display
  13641. {
  13642. WCHAR wcData[256] = {L'\0'};
  13643. DWORD dwData = 0;
  13644. DWORD dwDatalen = 256;
  13645. DWORD dwType = REG_SZ;
  13646. Status = RegQueryValueEx(hPullServer,
  13647. L"NetBIOSName",
  13648. 0,
  13649. &dwType,
  13650. (LPBYTE)wcData,
  13651. &dwDatalen);
  13652. if( Status isnot NO_ERROR )
  13653. {
  13654. DisplayMessage(g_hModule,
  13655. MSG_WINS_PULLPARTNER_INFO,
  13656. wcServerIpAdd,
  13657. wszUnknown,
  13658. (fPush is TRUE) ? wszPushpull : wszPull);
  13659. }
  13660. else
  13661. {
  13662. DisplayMessage(g_hModule,
  13663. MSG_WINS_PULLPARTNER_INFO,
  13664. wcServerIpAdd,
  13665. wcData,
  13666. (fPush is TRUE) ? wszPushpull : wszPull);
  13667. }
  13668. dwDatalen = sizeof(DWORD);
  13669. dwType = REG_DWORD;
  13670. Status = RegQueryValueEx(hPullServer,
  13671. PERSISTENCE,
  13672. 0,
  13673. &dwType,
  13674. (LPBYTE)&dwData,
  13675. &dwDatalen);
  13676. if( Status is NO_ERROR )
  13677. {
  13678. DisplayMessage(g_hModule,
  13679. MSG_SRVR_PULL_PERSISTENCE_STATE,
  13680. dwData ? wszEnable : wszDisable);
  13681. }
  13682. else
  13683. {
  13684. DisplayMessage(g_hModule,
  13685. MSG_SRVR_PULL_PERSISTENCE_STATE,
  13686. wszUnknown);
  13687. }
  13688. dwType = REG_SZ;
  13689. dwDatalen = 256;
  13690. Status = RegQueryValueEx(hPullServer,
  13691. WINSCNF_SP_TIME_NM,
  13692. 0,
  13693. &dwType,
  13694. (LPBYTE)wcData,
  13695. &dwDatalen);
  13696. if( Status is NO_ERROR )
  13697. {
  13698. DisplayMessage(g_hModule,
  13699. MSG_SRVR_PULL_STARTTIME,
  13700. wcData);
  13701. }
  13702. else
  13703. {
  13704. DisplayMessage(g_hModule,
  13705. MSG_SRVR_PULL_STARTTIME,
  13706. L"00:00:00");
  13707. }
  13708. dwDatalen = sizeof(DWORD);
  13709. dwType = REG_DWORD;
  13710. Status = RegQueryValueEx(hPullServer,
  13711. WINSCNF_RPL_INTERVAL_NM,
  13712. 0,
  13713. &dwType,
  13714. (LPBYTE)&dwData,
  13715. &dwDatalen);
  13716. if( Status is NO_ERROR )
  13717. {
  13718. LPWSTR pwszDayString = MakeDayTimeString(dwData);
  13719. DisplayMessage(g_hModule,
  13720. MSG_WINS_PULL_REPLINTERVAL,
  13721. pwszDayString);
  13722. WinsFreeMemory(pwszDayString);
  13723. pwszDayString = NULL;
  13724. }
  13725. else
  13726. {
  13727. DisplayMessage(g_hModule,
  13728. MSG_WINS_PULL_REPLINTERVAL,
  13729. L"00:00:00");
  13730. }
  13731. }
  13732. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  13733. CommonReturn:
  13734. if( Status is NO_ERROR )
  13735. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  13736. if( pdwTagNum )
  13737. {
  13738. WinsFreeMemory(pdwTagNum);
  13739. pdwTagNum = NULL;
  13740. }
  13741. if( pdwTagType )
  13742. {
  13743. WinsFreeMemory(pdwTagType);
  13744. pdwTagType = NULL;
  13745. }
  13746. if( hPullServer )
  13747. {
  13748. RegCloseKey(hPullServer);
  13749. hPullServer = NULL;
  13750. }
  13751. if( hPullRoot )
  13752. {
  13753. RegCloseKey(hPullRoot);
  13754. hPullRoot = NULL;
  13755. }
  13756. if( hServer )
  13757. {
  13758. RegCloseKey(hServer);
  13759. hServer = NULL;
  13760. }
  13761. return Status;
  13762. ErrorReturn:
  13763. DisplayErrorMessage(EMSG_SRVR_SHOW_PULLPARTNERPROPERTIES,
  13764. Status);
  13765. goto CommonReturn;
  13766. }
  13767. DWORD
  13768. HandleSrvrShowPushpartnerproperties(
  13769. IN LPCWSTR pwszMachine,
  13770. IN OUT LPWSTR *ppwcArguments,
  13771. IN DWORD dwCurrentIndex,
  13772. IN DWORD dwArgCount,
  13773. IN DWORD dwFlags,
  13774. IN LPCVOID pvData,
  13775. OUT BOOL *pbDone
  13776. )
  13777. /*++
  13778. Routine Description :
  13779. Displays the properties for a particular Push partner
  13780. Arguments :
  13781. All aguments are passes as array of wide char strings in ppwcArguments.
  13782. Compulsory : Push partner address
  13783. Return Value:
  13784. Returns the status of the operation.
  13785. --*/
  13786. {
  13787. DWORD Status = NO_ERROR;
  13788. DWORD i, j, dwNumArgs, dwTagCount;
  13789. TAG_TYPE pttTags[] = {
  13790. {WINS_TOKEN_SERVER, TRUE, FALSE},
  13791. };
  13792. PDWORD pdwTagType = NULL,
  13793. pdwTagNum = NULL;
  13794. WCHAR wcServerIpAdd[MAX_IP_STRING_LEN+1] = {L'\0'};
  13795. HKEY hPushRoot = NULL,
  13796. hPushServer = NULL,
  13797. hServer = NULL;
  13798. BOOL fPull = FALSE;
  13799. LPWSTR pTemp = NULL;
  13800. if( dwArgCount < dwCurrentIndex + 1 )
  13801. {
  13802. DisplayMessage(g_hModule, HLP_SRVR_SHOW_PUSHPARTNERPROPERTIES_EX);
  13803. Status = ERROR_INVALID_PARAMETER;
  13804. goto ErrorReturn;
  13805. }
  13806. dwNumArgs = dwArgCount - dwCurrentIndex;
  13807. pdwTagType = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  13808. pdwTagNum = WinsAllocateMemory(dwNumArgs*sizeof(DWORD));
  13809. if( pdwTagType is NULL or
  13810. pdwTagNum is NULL )
  13811. {
  13812. Status = ERROR_NOT_ENOUGH_MEMORY;
  13813. goto ErrorReturn;
  13814. }
  13815. dwTagCount = sizeof(pttTags)/sizeof(TAG_TYPE);
  13816. Status = PreProcessCommand(ppwcArguments,
  13817. dwArgCount,
  13818. dwCurrentIndex,
  13819. pttTags,
  13820. &dwTagCount,
  13821. pdwTagType,
  13822. pdwTagNum);
  13823. if( Status isnot NO_ERROR )
  13824. goto ErrorReturn;
  13825. for( i=0; i<sizeof(pttTags)/sizeof(TAG_TYPE); i++ )
  13826. {
  13827. if( pttTags[i].dwRequired is TRUE and
  13828. pttTags[i].bPresent is FALSE
  13829. )
  13830. {
  13831. Status = ERROR_INVALID_PARAMETER;
  13832. goto ErrorReturn;
  13833. }
  13834. }
  13835. for( j=0; j<dwTagCount; j++ )
  13836. {
  13837. switch(pdwTagType[j])
  13838. {
  13839. case 0:
  13840. {
  13841. struct hostent * lpHostEnt = NULL;
  13842. CHAR cAddr[16];
  13843. BYTE pbAdd[4];
  13844. char szAdd[4];
  13845. int k = 0, l=0;
  13846. DWORD dwLen, nLen = 0;
  13847. CHAR *pTemp = NULL;
  13848. CHAR *pNetBios = NULL;
  13849. if( IsIpAddress( ppwcArguments[dwCurrentIndex+pdwTagNum[j]] ) )
  13850. {
  13851. DWORD dwIp = inet_addr(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], NULL));
  13852. lpHostEnt = gethostbyaddr((char *)&dwIp, 4, AF_INET);
  13853. if(lpHostEnt isnot NULL )//Valid IP Address
  13854. {
  13855. wcscpy(wcServerIpAdd, ppwcArguments[dwCurrentIndex+pdwTagNum[j]]);
  13856. break;
  13857. }
  13858. else
  13859. {
  13860. Status = ERROR_INVALID_IPADDRESS;
  13861. goto ErrorReturn;
  13862. }
  13863. }
  13864. if( wcslen(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]) > 2 and
  13865. _wcsnicmp(ppwcArguments[dwCurrentIndex+pdwTagNum[j]], L"\\\\", 2) is 0 )
  13866. k = 2;
  13867. lpHostEnt = gethostbyname(WinsUnicodeToAnsi(ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k, NULL));
  13868. if( lpHostEnt is NULL )
  13869. {
  13870. DisplayMessage(g_hModule,
  13871. EMSG_WINS_INVALID_COMPUTER_NAME,
  13872. ppwcArguments[dwCurrentIndex+pdwTagNum[j]]+k);
  13873. Status = ERROR_INVALID_PARAMETER;
  13874. goto ErrorReturn;
  13875. }
  13876. memcpy(pbAdd, lpHostEnt->h_addr_list[0], 4);
  13877. for( l=0;l<4; l++)
  13878. {
  13879. _itoa((int)pbAdd[l], szAdd, 10);
  13880. memcpy(cAddr+nLen, szAdd, strlen(szAdd));
  13881. nLen += strlen(szAdd);
  13882. *(cAddr+nLen) = '.';
  13883. nLen++;
  13884. }
  13885. *(cAddr+nLen-1) = '\0';
  13886. {
  13887. LPWSTR pstr = WinsAnsiToUnicode(cAddr, NULL);
  13888. if (pstr != NULL)
  13889. {
  13890. wcscpy(wcServerIpAdd, pstr);
  13891. WinsFreeMemory(pstr);
  13892. }
  13893. else
  13894. {
  13895. Status = ERROR_NOT_ENOUGH_MEMORY;
  13896. goto ErrorReturn;
  13897. }
  13898. }
  13899. break;
  13900. }
  13901. default:
  13902. {
  13903. Status = ERROR_INVALID_PARAMETER;
  13904. goto ErrorReturn;
  13905. }
  13906. }
  13907. }
  13908. if( wcslen(g_ServerNetBiosName) > 0 )
  13909. {
  13910. pTemp = g_ServerNetBiosName;
  13911. }
  13912. Status = RegConnectRegistry(pTemp, HKEY_LOCAL_MACHINE, &hServer);
  13913. if( Status isnot NO_ERROR )
  13914. goto ErrorReturn;
  13915. Status = RegOpenKeyEx(hServer,
  13916. PUSHROOT,
  13917. 0,
  13918. KEY_READ,
  13919. &hPushRoot);
  13920. if( Status isnot NO_ERROR )
  13921. {
  13922. goto ErrorReturn;
  13923. }
  13924. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  13925. //Now check if the desired server is in the list of push server.
  13926. Status = RegOpenKeyEx(hPushRoot,
  13927. wcServerIpAdd,
  13928. 0,
  13929. KEY_READ,
  13930. &hPushServer);
  13931. if( Status isnot NO_ERROR )
  13932. {
  13933. DisplayMessage(g_hModule,
  13934. EMSG_WINS_INVALID_PUSHPARTNER,
  13935. wcServerIpAdd,
  13936. g_ServerIpAddressUnicodeString);
  13937. goto CommonReturn;
  13938. }
  13939. //Check if it is also a pull partner or not.
  13940. {
  13941. DWORD dwKeyLen = 0;
  13942. HKEY hPullServer = NULL;
  13943. dwKeyLen = wcslen(PULLROOT)+ wcslen(L"\\") + wcslen(wcServerIpAdd);
  13944. pTemp = WinsAllocateMemory((dwKeyLen+1)*sizeof(WCHAR));
  13945. if(pTemp is NULL )
  13946. {
  13947. Status = ERROR_NOT_ENOUGH_MEMORY;
  13948. goto ErrorReturn;
  13949. }
  13950. memset(pTemp, 0x00, (dwKeyLen+1)*sizeof(WCHAR));
  13951. wcscat(pTemp,PULLROOT);
  13952. wcscat(pTemp, L"\\");
  13953. wcscat(pTemp, wcServerIpAdd);
  13954. Status = RegOpenKeyEx(hServer,
  13955. pTemp,
  13956. 0,
  13957. KEY_READ,
  13958. &hPullServer);
  13959. if( Status isnot NO_ERROR )
  13960. {
  13961. fPull = FALSE;
  13962. }
  13963. else
  13964. {
  13965. fPull = TRUE;
  13966. }
  13967. WinsFreeMemory(pTemp);
  13968. pTemp = NULL;
  13969. if( hPullServer )
  13970. {
  13971. RegCloseKey(hPullServer);
  13972. hPullServer = NULL;
  13973. }
  13974. }
  13975. //Now look for required parameters to display
  13976. {
  13977. WCHAR wcData[256] = {L'\0'};
  13978. DWORD dwData = 0;
  13979. DWORD dwDatalen = 256;
  13980. DWORD dwType = REG_SZ;
  13981. Status = RegQueryValueEx(hPushServer,
  13982. L"NetBIOSName",
  13983. 0,
  13984. &dwType,
  13985. (LPBYTE)wcData,
  13986. &dwDatalen);
  13987. if( Status isnot NO_ERROR )
  13988. {
  13989. DisplayMessage(g_hModule,
  13990. MSG_WINS_PUSHPARTNER_INFO,
  13991. wcServerIpAdd,
  13992. wszUnknown,
  13993. (fPull is TRUE) ? wszPushpull : wszPush);
  13994. }
  13995. else
  13996. {
  13997. DisplayMessage(g_hModule,
  13998. MSG_WINS_PUSHPARTNER_INFO,
  13999. wcServerIpAdd,
  14000. wcData,
  14001. (fPull is TRUE) ? wszPushpull : wszPush);
  14002. }
  14003. dwDatalen = sizeof(DWORD);
  14004. dwType = REG_DWORD;
  14005. Status = RegQueryValueEx(hPushServer,
  14006. PERSISTENCE,
  14007. 0,
  14008. &dwType,
  14009. (LPBYTE)&dwData,
  14010. &dwDatalen);
  14011. if( Status is NO_ERROR )
  14012. {
  14013. DisplayMessage(g_hModule,
  14014. MSG_SRVR_PUSH_PERSISTENCE_STATE,
  14015. dwData ? wszEnable : wszDisable);
  14016. }
  14017. else
  14018. {
  14019. DisplayMessage(g_hModule,
  14020. MSG_SRVR_PUSH_PERSISTENCE_STATE,
  14021. wszUnknown);
  14022. }
  14023. dwDatalen = sizeof(DWORD);
  14024. dwType = REG_DWORD;
  14025. Status = RegQueryValueEx(hPushServer,
  14026. WINSCNF_UPDATE_COUNT_NM,
  14027. 0,
  14028. &dwType,
  14029. (LPBYTE)&dwData,
  14030. &dwDatalen);
  14031. if( Status is NO_ERROR )
  14032. {
  14033. WCHAR Buffer[10] = {L'\0'};
  14034. _itow(dwData, Buffer, 10);
  14035. DisplayMessage(g_hModule,
  14036. MSG_SRVR_PUSH_UPDATECOUNT,
  14037. Buffer);
  14038. }
  14039. else
  14040. {
  14041. DisplayMessage(g_hModule,
  14042. MSG_SRVR_PUSH_UPDATECOUNT,
  14043. wszUnknown);
  14044. }
  14045. }
  14046. DisplayMessage(g_hModule, WINS_FORMAT_LINE);
  14047. CommonReturn:
  14048. if( Status is NO_ERROR )
  14049. DisplayMessage(g_hModule, EMSG_WINS_ERROR_SUCCESS);
  14050. if( hPushServer )
  14051. {
  14052. RegCloseKey(hPushServer);
  14053. hPushServer = NULL;
  14054. }
  14055. if( hPushRoot )
  14056. {
  14057. RegCloseKey(hPushRoot);
  14058. hPushRoot = NULL;
  14059. }
  14060. if( hServer )
  14061. {
  14062. RegCloseKey(hServer);
  14063. hServer = NULL;
  14064. }
  14065. if( pdwTagType )
  14066. {
  14067. WinsFreeMemory(pdwTagType);
  14068. pdwTagType = NULL;
  14069. }
  14070. if( pdwTagNum )
  14071. {
  14072. WinsFreeMemory(pdwTagNum);
  14073. pdwTagNum = NULL;
  14074. }
  14075. return Status;
  14076. ErrorReturn:
  14077. DisplayErrorMessage(EMSG_SRVR_SHOW_PUSHPARTNERPROPERTIES,
  14078. Status);
  14079. goto CommonReturn;
  14080. }
  14081. DWORD
  14082. GetVersionData(
  14083. LPWSTR pwszVers,
  14084. WINSINTF_VERS_NO_T *Version
  14085. )
  14086. {
  14087. LPWSTR pTemp = NULL;
  14088. LPWSTR pwcBuffer = NULL;
  14089. DWORD dwLen = 0;
  14090. LPWSTR pwszToken=L",-.";
  14091. if( ( pwszVers is NULL ) or
  14092. ( IsBadStringPtr(pwszVers, MAX_STRING_LEN) is TRUE ) )
  14093. {
  14094. return ERROR_INVALID_PARAMETER;
  14095. }
  14096. dwLen = wcslen(pwszVers);
  14097. if( dwLen<2 )
  14098. {
  14099. return ERROR_INVALID_PARAMETER;
  14100. }
  14101. pwcBuffer = WinsAllocateMemory((dwLen+1)*sizeof(WCHAR));
  14102. if( pwcBuffer is NULL )
  14103. {
  14104. return ERROR_NOT_ENOUGH_MEMORY;
  14105. }
  14106. wcscpy(pwcBuffer, pwszVers);
  14107. if( pwcBuffer[0] isnot L'{' or
  14108. pwcBuffer[dwLen-1] isnot L'}' )
  14109. {
  14110. WinsFreeMemory(pwcBuffer);
  14111. pwcBuffer = NULL;
  14112. return ERROR_INVALID_PARAMETER;
  14113. }
  14114. pwcBuffer[dwLen-1] = L'\0';
  14115. pTemp = wcstok(pwcBuffer+1, pwszToken);
  14116. if( pTemp is NULL )
  14117. {
  14118. WinsFreeMemory(pwcBuffer);
  14119. pwcBuffer = NULL;
  14120. return ERROR_INVALID_PARAMETER;
  14121. }
  14122. Version->HighPart = wcstoul(pTemp, NULL, 16);
  14123. pTemp = wcstok(NULL, pwszToken);
  14124. if( pTemp is NULL )
  14125. {
  14126. WinsFreeMemory(pwcBuffer);
  14127. pwcBuffer = NULL;
  14128. return ERROR_INVALID_PARAMETER;
  14129. }
  14130. Version->LowPart = wcstoul(pTemp, NULL, 16);
  14131. WinsFreeMemory(pwcBuffer);
  14132. pwcBuffer = NULL;
  14133. return NO_ERROR;
  14134. }
  14135. DWORD
  14136. PreProcessCommand(
  14137. IN LPWSTR *ppwcArguments,
  14138. IN DWORD dwArgCount,
  14139. IN DWORD dwCurrentIndex,
  14140. IN OUT PTAG_TYPE pttTags,
  14141. IN OUT PDWORD pdwTagCount,
  14142. OUT PDWORD pdwTagType,
  14143. OUT PDWORD pdwTagNum
  14144. )
  14145. {
  14146. DWORD Status = NO_ERROR;
  14147. DWORD i, j, dwTag = 0;
  14148. LPWSTR pwszTemp = NULL;
  14149. if( pdwTagType is NULL or
  14150. pdwTagNum is NULL or
  14151. pttTags is NULL or
  14152. pdwTagCount is NULL )
  14153. {
  14154. return ERROR_INVALID_PARAMETER;
  14155. }
  14156. dwTag = *pdwTagCount;
  14157. i = 0;
  14158. if( wcsstr(ppwcArguments[dwCurrentIndex], NETSH_ARG_DELIMITER) isnot NULL )
  14159. {
  14160. LPWSTR pwszTag = NULL;
  14161. while( IsBadStringPtr(ppwcArguments[dwCurrentIndex+i], MAX_STRING_LEN) is FALSE )
  14162. {
  14163. pwszTag = NULL;
  14164. if( dwArgCount <= dwCurrentIndex + i )
  14165. break;
  14166. if( wcslen(ppwcArguments[dwCurrentIndex+i]) is 0 )
  14167. break;
  14168. pwszTemp = WinsAllocateMemory((wcslen(ppwcArguments[dwCurrentIndex+i])+1)*sizeof(WCHAR));
  14169. if( pwszTemp is NULL )
  14170. {
  14171. Status = ERROR_NOT_ENOUGH_MEMORY;
  14172. goto ErrorReturn;
  14173. }
  14174. wcscpy(pwszTemp, ppwcArguments[dwCurrentIndex+i]);
  14175. if( wcsstr(ppwcArguments[dwCurrentIndex+i], NETSH_ARG_DELIMITER ) is NULL )
  14176. {
  14177. DisplayMessage(g_hModule,
  14178. EMSG_SRVR_NOT_TAGGED,
  14179. i+1);
  14180. i++;
  14181. continue;
  14182. }
  14183. pwszTag = wcstok(pwszTemp, NETSH_ARG_DELIMITER);
  14184. for( j=0; j<dwTag; j++ )
  14185. {
  14186. if( FALSE is MatchToken(pwszTag,
  14187. pttTags[j].pwszTag) )
  14188. {
  14189. continue;
  14190. }
  14191. else
  14192. {
  14193. if( pttTags[j].bPresent is TRUE )
  14194. {
  14195. Status = ERROR_INVALID_PARAMETER;
  14196. WinsFreeMemory(pwszTemp);
  14197. pwszTemp = NULL;
  14198. goto ErrorReturn;
  14199. }
  14200. else
  14201. {
  14202. LPWSTR pwszVal = wcstok(NULL, NETSH_ARG_DELIMITER);
  14203. if( pwszVal is NULL )
  14204. {
  14205. wcscpy(ppwcArguments[dwCurrentIndex+i], L"");
  14206. }
  14207. else
  14208. {
  14209. wcscpy(ppwcArguments[dwCurrentIndex+i], pwszVal);
  14210. }
  14211. pttTags[j].bPresent = TRUE;
  14212. pdwTagType[i] = j;
  14213. pdwTagNum[i] = i;
  14214. break;
  14215. }
  14216. }
  14217. }
  14218. if( pwszTemp )
  14219. {
  14220. WinsFreeMemory(pwszTemp);
  14221. pwszTemp = NULL;
  14222. }
  14223. i++;
  14224. }
  14225. }
  14226. else
  14227. {
  14228. while( IsBadStringPtr(ppwcArguments[dwCurrentIndex+i], MAX_STRING_LEN) is FALSE )
  14229. {
  14230. if( wcsstr(ppwcArguments[dwCurrentIndex+i], NETSH_ARG_DELIMITER) isnot NULL )
  14231. {
  14232. DisplayMessage(g_hModule,
  14233. EMSG_SRVR_NOT_UNTAGGED,
  14234. i+1);
  14235. Status = ERROR_INVALID_PARAMETER;
  14236. goto ErrorReturn;
  14237. }
  14238. if( dwArgCount <= dwCurrentIndex + i )
  14239. break;
  14240. // if( wcslen(ppwcArguments[dwCurrentIndex+i]) is 0 )
  14241. // break;
  14242. if( dwTag <= i )
  14243. {
  14244. break;
  14245. }
  14246. pdwTagType[i] = i;
  14247. pdwTagNum[i] = i;
  14248. pttTags[i].bPresent = TRUE;
  14249. i++;
  14250. }
  14251. }
  14252. *pdwTagCount = i;
  14253. CommonReturn:
  14254. if( pwszTemp )
  14255. {
  14256. WinsFreeMemory(pwszTemp);
  14257. pwszTemp = NULL;
  14258. }
  14259. return Status;
  14260. ErrorReturn:
  14261. goto CommonReturn;
  14262. }
  14263. DWORD
  14264. GetStatus(
  14265. BOOL fPrint,
  14266. LPVOID pResultsA,
  14267. BOOL fNew,
  14268. BOOL fShort,
  14269. LPCSTR pStartIp
  14270. )
  14271. {
  14272. DWORD Status, i;
  14273. struct in_addr InAddr;
  14274. PWINSINTF_RESULTS_T pResults = pResultsA;
  14275. PWINSINTF_RESULTS_NEW_T pResultsN = pResultsA;
  14276. PWINSINTF_ADD_VERS_MAP_T pAddVersMaps;
  14277. DWORD NoOfOwners;
  14278. WCHAR IpAddress[21] = {L'\0'};
  14279. WCHAR OwnerId[15] = {L'\0'};
  14280. WCHAR Buffer[5] = {L'\0'};
  14281. LPWSTR pwszDay = NULL;
  14282. handle_t BindHdl;
  14283. WINSINTF_BIND_DATA_T BindData = {0};
  14284. BindData.fTcpIp = TRUE;
  14285. BindData.pServerAdd = (LPBYTE)WinsOemToUnicode(pStartIp, NULL);
  14286. if( BindData.pServerAdd is NULL )
  14287. {
  14288. return ERROR_NOT_ENOUGH_MEMORY;
  14289. }
  14290. DisplayMessage(g_hModule,
  14291. MSG_SRVR_MAPTABLE_HEADER,
  14292. BindData.pServerAdd);
  14293. BindHdl = WinsBind(&BindData);
  14294. if( BindHdl is NULL )
  14295. {
  14296. DisplayMessage(g_hModule,
  14297. EMSG_WINS_BIND_FAILED,
  14298. BindData.pServerAdd);
  14299. return NO_ERROR;
  14300. }
  14301. if (!fNew)
  14302. {
  14303. Status = WinsStatus(BindHdl, WINSINTF_E_CONFIG, pResultsA);
  14304. }
  14305. else
  14306. {
  14307. pResultsN->pAddVersMaps = NULL;
  14308. Status = WinsStatusNew(BindHdl, WINSINTF_E_CONFIG, pResultsN);
  14309. }
  14310. if( Status isnot NO_ERROR )
  14311. {
  14312. WinsUnbind(&BindData, BindHdl);
  14313. return Status;
  14314. }
  14315. if( fShort is TRUE )
  14316. {
  14317. DisplayMessage(g_hModule,
  14318. MSG_WINS_NAMERECORD_SETTINGS);
  14319. if( fNew )
  14320. {
  14321. pwszDay = MakeDayTimeString(pResultsN->RefreshInterval);
  14322. }
  14323. else
  14324. {
  14325. pwszDay = MakeDayTimeString(pResults->RefreshInterval);
  14326. }
  14327. DisplayMessage(g_hModule,
  14328. MSG_WINS_NAMERECORD_REFRESHINTVL,
  14329. pwszDay);
  14330. WinsFreeMemory(pwszDay);
  14331. pwszDay = NULL;
  14332. if( fNew )
  14333. {
  14334. pwszDay = MakeDayTimeString(pResultsN->TombstoneInterval);
  14335. }
  14336. else
  14337. {
  14338. pwszDay = MakeDayTimeString(pResults->TombstoneInterval);
  14339. }
  14340. DisplayMessage(g_hModule,
  14341. MSG_WINS_NAMERECORD_TOMBSTONEINTVL,
  14342. pwszDay);
  14343. WinsFreeMemory(pwszDay);
  14344. pwszDay = NULL;
  14345. if( fNew )
  14346. {
  14347. pwszDay = MakeDayTimeString(pResultsN->TombstoneTimeout);
  14348. }
  14349. else
  14350. {
  14351. pwszDay = MakeDayTimeString(pResults->TombstoneTimeout);
  14352. }
  14353. DisplayMessage(g_hModule,
  14354. MSG_WINS_NAMERECORD_TOMBSTONETMOUT,
  14355. pwszDay);
  14356. WinsFreeMemory(pwszDay);
  14357. pwszDay = NULL;
  14358. if( fNew )
  14359. {
  14360. pwszDay = MakeDayTimeString(pResultsN->VerifyInterval);
  14361. }
  14362. else
  14363. {
  14364. pwszDay = MakeDayTimeString(pResults->VerifyInterval);
  14365. }
  14366. DisplayMessage(g_hModule,
  14367. MSG_WINS_NAMERECORD_VERIFYINTVL,
  14368. pwszDay);
  14369. WinsFreeMemory(pwszDay);
  14370. pwszDay = NULL;
  14371. DisplayMessage(g_hModule,WINS_FORMAT_LINE);
  14372. if (!fNew)
  14373. {
  14374. DisplayMessage(g_hModule,
  14375. MSG_WINS_PRIORITY_CLASS,
  14376. pResults->WinsPriorityClass == NORMAL_PRIORITY_CLASS ? wszNormal : wszHigh);
  14377. DisplayMessage(g_hModule,
  14378. MSG_WINS_WORKER_THREAD,
  14379. pResults->NoOfWorkerThds);
  14380. pAddVersMaps = pResults->AddVersMaps;
  14381. NoOfOwners = pResults->NoOfOwners;
  14382. }
  14383. else
  14384. {
  14385. DisplayMessage(g_hModule,
  14386. MSG_WINS_PRIORITY_CLASS,
  14387. pResultsN->WinsPriorityClass == NORMAL_PRIORITY_CLASS ? wszNormal : wszHigh);
  14388. DisplayMessage(g_hModule,
  14389. MSG_WINS_WORKER_THREAD,
  14390. pResultsN->NoOfWorkerThds);
  14391. pAddVersMaps = pResultsN->pAddVersMaps;
  14392. NoOfOwners = pResultsN->NoOfOwners;
  14393. }
  14394. DisplayMessage(g_hModule,WINS_FORMAT_LINE);
  14395. if (NoOfOwners isnot 0)
  14396. {
  14397. DisplayMessage(g_hModule,
  14398. MSG_WINS_OWNER_TABLE);
  14399. for ( i= 0; i < NoOfOwners; i++, pAddVersMaps++)
  14400. {
  14401. DWORD j=0;
  14402. for(j=0; j<20; j++)
  14403. {
  14404. IpAddress[j] = L' ';
  14405. }
  14406. IpAddress[20] = L'\0';
  14407. for(j=0; j<14; j++)
  14408. {
  14409. OwnerId[j] = L' ';
  14410. }
  14411. OwnerId[14] = L'\0';
  14412. _itow(i, Buffer, 10);
  14413. wcscpy(OwnerId+4, Buffer);
  14414. for(j=wcslen(OwnerId); j<14; j++)
  14415. OwnerId[j] = L' ';
  14416. OwnerId[14] = L'\0';
  14417. wcscpy(IpAddress+2, IpAddressToString(pAddVersMaps->Add.IPAdd));
  14418. for(j=wcslen(IpAddress); j<20; j++)
  14419. IpAddress[j] = L' ';
  14420. IpAddress[20] = L'\0';
  14421. if (fNew)
  14422. {
  14423. if( pAddVersMaps->VersNo.HighPart is MAXLONG and
  14424. pAddVersMaps->VersNo.LowPart is MAXULONG )
  14425. {
  14426. DisplayMessage(g_hModule,
  14427. MSG_WINS_OWNER_INFO_MAX,
  14428. OwnerId,
  14429. IpAddress,
  14430. wszDeleted);
  14431. continue;
  14432. }
  14433. if (fShort && pAddVersMaps->VersNo.QuadPart == 0)
  14434. {
  14435. continue;
  14436. }
  14437. DisplayMessage(g_hModule,
  14438. MSG_WINS_OWNER_INFO,
  14439. OwnerId,
  14440. IpAddress,
  14441. pAddVersMaps->VersNo.HighPart,
  14442. pAddVersMaps->VersNo.LowPart);
  14443. }
  14444. }
  14445. }
  14446. else
  14447. {
  14448. DisplayMessage(g_hModule, MSG_WINS_NO_RECORDS);
  14449. }
  14450. }
  14451. WinsUnbind(&BindData, BindHdl);
  14452. if( BindData.pServerAdd )
  14453. {
  14454. WinsFreeMemory(BindData.pServerAdd);
  14455. BindData.pServerAdd = NULL;
  14456. }
  14457. return(Status);
  14458. }
  14459. VOID
  14460. ChkAdd(
  14461. PWINSINTF_RECORD_ACTION_T pRow,
  14462. DWORD Add,
  14463. BOOL fFile,
  14464. FILE *pFile,
  14465. DWORD OwnerIP,
  14466. LPBOOL pfMatch
  14467. )
  14468. {
  14469. struct in_addr InAddr1, InAddr2;
  14470. DWORD dwIpAddress = 0;
  14471. LPWSTR pwszAdd1 = NULL;
  14472. LPWSTR pwszAdd2 = NULL;
  14473. LPWSTR pwszOwner = NULL;
  14474. BOOL fFirst = FALSE;
  14475. if ( pRow->TypOfRec_e is WINSINTF_E_UNIQUE or
  14476. pRow->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  14477. {
  14478. pwszAdd2 = IpAddressToString(pRow->Add.IPAdd);
  14479. pwszOwner = IpAddressToString(OwnerIP);
  14480. if( pwszAdd2 is NULL or
  14481. pwszOwner is NULL )
  14482. {
  14483. DisplayMessage(g_hModule,
  14484. EMSG_WINS_OUT_OF_MEMORY);
  14485. if( pwszAdd2 )
  14486. {
  14487. WinsFreeMemory(pwszAdd2);
  14488. pwszAdd2 = NULL;
  14489. }
  14490. if( pwszOwner )
  14491. {
  14492. WinsFreeMemory(pwszOwner);
  14493. pwszOwner = NULL;
  14494. }
  14495. return;
  14496. }
  14497. if (*pfMatch)
  14498. {
  14499. if (Add isnot pRow->Add.IPAdd)
  14500. {
  14501. WinsFreeMemory(pwszAdd2);
  14502. pwszAdd2 = NULL;
  14503. WinsFreeMemory(pwszOwner );
  14504. pwszOwner = NULL;
  14505. *pfMatch = FALSE;
  14506. return;
  14507. }
  14508. }
  14509. DisplayMessage(g_hModule,
  14510. MSG_WINS_IPADDRESS_STRING,
  14511. pwszAdd2 );
  14512. if( fFile )
  14513. {
  14514. DumpMessage(g_hModule,
  14515. pFile,
  14516. FMSG_WINS_IPADDRESS_STRING,
  14517. pwszAdd2,
  14518. pwszOwner);
  14519. }
  14520. WinsFreeMemory(pwszAdd2);
  14521. pwszAdd2 = NULL;
  14522. WinsFreeMemory(pwszOwner );
  14523. pwszOwner = NULL;
  14524. return;
  14525. }
  14526. else //spec. grp or multihomed
  14527. {
  14528. DWORD ind;
  14529. if (!*pfMatch)
  14530. {
  14531. DisplayMessage(g_hModule,
  14532. MSG_WINS_MEMBER_COUNT,
  14533. pRow->NoOfAdds/2);
  14534. }
  14535. for ( ind=0; ind < pRow->NoOfAdds ; /*no third expr*/ )
  14536. {
  14537. LPSTR psz1 = NULL;
  14538. InAddr1.s_addr = htonl( (pRow->pAdd + ind++)->IPAdd);
  14539. psz1 = inet_ntoa(InAddr1);
  14540. if( psz1 is NULL )
  14541. {
  14542. continue;
  14543. }
  14544. pwszAdd1 = WinsOemToUnicode(psz1, NULL );
  14545. if( pwszAdd1 is NULL )
  14546. {
  14547. DisplayMessage(g_hModule,
  14548. EMSG_WINS_OUT_OF_MEMORY);
  14549. return;
  14550. }
  14551. if (!*pfMatch)
  14552. {
  14553. DisplayMessage(g_hModule,
  14554. MSG_WINS_OWNER_ADDRESS,
  14555. pwszAdd1);
  14556. }
  14557. InAddr2.s_addr = htonl((pRow->pAdd + ind++)->IPAdd);
  14558. psz1 = inet_ntoa(InAddr2);
  14559. if( psz1 is NULL )
  14560. {
  14561. if( pwszAdd1 )
  14562. {
  14563. WinsFreeMemory(pwszAdd1);
  14564. pwszAdd1 = NULL;
  14565. }
  14566. continue;
  14567. }
  14568. pwszAdd2 = WinsOemToUnicode(psz1, NULL);
  14569. if( pwszAdd2 is NULL )
  14570. {
  14571. DisplayMessage(g_hModule,
  14572. EMSG_WINS_OUT_OF_MEMORY);
  14573. if( pwszAdd1 )
  14574. {
  14575. WinsFreeMemory(pwszAdd1);
  14576. pwszAdd1 = NULL;
  14577. }
  14578. return;
  14579. }
  14580. if (!*pfMatch)
  14581. {
  14582. DisplayMessage(g_hModule,
  14583. MSG_WINS_IPADDRESS_STRING,
  14584. pwszAdd2 );
  14585. if( fFile )
  14586. {
  14587. if( fFirst is FALSE )
  14588. {
  14589. DumpMessage(g_hModule,
  14590. pFile,
  14591. FMSG_WINS_IPADDRESS_STRING,
  14592. pwszAdd2,
  14593. pwszAdd1);
  14594. fFirst = TRUE;
  14595. }
  14596. else
  14597. {
  14598. DumpMessage(g_hModule,
  14599. pFile,
  14600. FMSG_WINS_IPADDRESS_LIST,
  14601. pwszAdd2,
  14602. pwszAdd1);
  14603. }
  14604. }
  14605. }
  14606. if (*pfMatch)
  14607. {
  14608. if (Add isnot (pRow->pAdd + ind - 1)->IPAdd)
  14609. {
  14610. *pfMatch = FALSE;
  14611. if( pwszAdd1 )
  14612. {
  14613. WinsFreeMemory(pwszAdd1);
  14614. pwszAdd1 = NULL;
  14615. }
  14616. if( pwszAdd2 )
  14617. {
  14618. WinsFreeMemory(pwszAdd2);
  14619. pwszAdd2 = NULL;
  14620. }
  14621. return;
  14622. }
  14623. }
  14624. }
  14625. //
  14626. // If there were no members to compare with, then
  14627. // let us set *pfMatch to FALSE.
  14628. //
  14629. if (ind == 0)
  14630. {
  14631. if (*pfMatch)
  14632. {
  14633. *pfMatch = FALSE;
  14634. }
  14635. }
  14636. if( pwszAdd1 )
  14637. {
  14638. WinsFreeMemory(pwszAdd1);
  14639. pwszAdd1 = NULL;
  14640. }
  14641. if( pwszAdd2 )
  14642. {
  14643. WinsFreeMemory(pwszAdd2);
  14644. pwszAdd2 = NULL;
  14645. }
  14646. return;
  14647. }
  14648. }
  14649. DWORD
  14650. GetDbRecs(
  14651. WINSINTF_VERS_NO_T LowVersNo,
  14652. WINSINTF_VERS_NO_T HighVersNo,
  14653. PWINSINTF_ADD_T pWinsAdd,
  14654. LPBYTE pTgtAdd,
  14655. BOOL fSetFilter,
  14656. LPBYTE pFilterName,
  14657. DWORD Len,
  14658. BOOL fAddFilter,
  14659. DWORD AddFilter,
  14660. BOOL fCountRec,
  14661. BOOL fCase,
  14662. BOOL fFile,
  14663. LPWSTR pwszFile
  14664. )
  14665. {
  14666. WINSINTF_RECS_T Recs;
  14667. DWORD Choice;
  14668. DWORD Status = WINSINTF_SUCCESS;
  14669. DWORD TotalCnt = 0;
  14670. BOOL fMatch;
  14671. WINSINTF_VERS_NO_T sTmpVersNo;
  14672. WCHAR Name[20] = {L'\0'};
  14673. DWORD dwCount = 0;
  14674. struct tm* time = NULL;
  14675. LPWSTR pwszTime = NULL;
  14676. int iType = 1;
  14677. FILE *pFile = NULL;
  14678. BOOL fOpenFile = FALSE;
  14679. BOOL fHeader = FALSE;
  14680. LPWSTR pwszGroup = NULL,
  14681. pwszType = NULL,
  14682. pwszState = NULL;
  14683. WCHAR wszGroup[50] = {L'\0'},
  14684. wszState[50] = {L'\0'},
  14685. wszType[50] = {L'\0'};
  14686. DWORD dwGroup = WINS_GROUP_UNIQUE,
  14687. dwGrouplen = 0,
  14688. dwState = WINS_STATE_ACTIVE,
  14689. dwStatelen = 0,
  14690. dwType = WINS_TYPE_STATIC,
  14691. dwTypelen = 0;
  14692. sTmpVersNo.LowPart = 1;
  14693. sTmpVersNo.HighPart = 0;
  14694. if( fFile )
  14695. {
  14696. pFile = _wfopen(pwszFile,
  14697. L"a+");
  14698. if( pFile is NULL )
  14699. {
  14700. fOpenFile = FALSE;
  14701. DisplayMessage(g_hModule,
  14702. EMSG_WINS_FILEOPEN_FAILED,
  14703. pwszFile);
  14704. }
  14705. else
  14706. {
  14707. fOpenFile = TRUE;
  14708. }
  14709. }
  14710. while (TRUE)
  14711. {
  14712. LPWSTR pwszTempTgt = NULL;
  14713. Recs.pRow = NULL;
  14714. Status = WinsGetDbRecs(g_hBind, pWinsAdd, LowVersNo, HighVersNo, &Recs);
  14715. if (fCountRec)
  14716. {
  14717. DisplayMessage(g_hModule,
  14718. MSG_WINS_RECORDS_COUNT,
  14719. Recs.TotalNoOfRecs);
  14720. break;
  14721. }
  14722. if (Status is WINSINTF_SUCCESS)
  14723. {
  14724. if (Recs.NoOfRecs > 0)
  14725. {
  14726. DWORD i, k;
  14727. PWINSINTF_RECORD_ACTION_T pRow = Recs.pRow;
  14728. TotalCnt += Recs.NoOfRecs;
  14729. if (!fSetFilter)
  14730. {
  14731. DisplayMessage(g_hModule,
  14732. MSG_WINS_RECORDS_RETRIEVED,
  14733. IpAddressToString(pWinsAdd->IPAdd),
  14734. Recs.NoOfRecs);
  14735. }
  14736. for (i=0; i<Recs.NoOfRecs; i++)
  14737. {
  14738. if (fAddFilter)
  14739. {
  14740. //
  14741. // The address filter was specfied
  14742. // If the address matches, then
  14743. // fMatch will be TRUE after the
  14744. // function returns.
  14745. //
  14746. fMatch = TRUE;
  14747. ChkAdd(
  14748. pRow,
  14749. AddFilter,
  14750. fOpenFile,
  14751. pFile,
  14752. pWinsAdd->IPAdd,
  14753. &fMatch
  14754. );
  14755. }
  14756. else
  14757. {
  14758. fMatch = FALSE;
  14759. }
  14760. //
  14761. // If the address matched or if no filter
  14762. // was specified or if there was a name
  14763. // filter and the names matched, print
  14764. // out the details
  14765. //
  14766. if( fCase )
  14767. {
  14768. if( fMatch or
  14769. fSetFilter is FALSE or
  14770. ( fAddFilter is FALSE and
  14771. IsBadStringPtrA(pRow->pName, 256) is FALSE and
  14772. strncmp(pRow->pName, pFilterName, (pRow->NameLen>Len)?Len:pRow->NameLen) is 0 )
  14773. )
  14774. {
  14775. WCHAR Name[256] = {L'\0'};
  14776. CHAR chEndChar = 0x00;
  14777. LPWSTR pwszTemp = NULL;
  14778. DWORD dwTempLen = 0;
  14779. DisplayMessage(g_hModule,
  14780. MSG_WINS_RECORD_LINE);
  14781. if( fOpenFile and
  14782. g_fHeader is FALSE )
  14783. {
  14784. DumpMessage(g_hModule,
  14785. pFile,
  14786. FMSG_WINS_RECORD_TABLE);
  14787. g_fHeader = TRUE;
  14788. }
  14789. chEndChar = (CHAR)pRow->pName[15];
  14790. pRow->pName[15] = '\0';
  14791. pwszTemp = WinsOemToUnicode(pRow->pName, NULL);
  14792. if( pwszTemp is NULL )
  14793. {
  14794. DisplayMessage(g_hModule,
  14795. EMSG_WINS_OUT_OF_MEMORY);
  14796. Status = WINSINTF_FAILURE;
  14797. break;
  14798. }
  14799. dwTempLen = ( 16 > wcslen(pwszTemp) ) ? wcslen(pwszTemp) : 16;
  14800. wcsncpy(Name, pwszTemp, dwTempLen);
  14801. WinsFreeMemory(pwszTemp);
  14802. pwszTemp = NULL;
  14803. for( k=dwTempLen; k<15; k++ )
  14804. {
  14805. Name[k] = L' ';
  14806. }
  14807. Name[15] = L'[';
  14808. WinsHexToString(Name+16, (LPBYTE)&chEndChar, 1);
  14809. Name[18] = L'h';
  14810. Name[19] = L']';
  14811. Name[20] = L'\0';
  14812. if( IsBadStringPtrA(pRow->pName+16, 240) is FALSE )
  14813. {
  14814. pwszTemp = WinsOemToUnicode(pRow->pName+16, NULL);
  14815. if( pwszTemp is NULL )
  14816. {
  14817. DisplayMessage(g_hModule,
  14818. EMSG_WINS_OUT_OF_MEMORY);
  14819. Status = WINSINTF_FAILURE;
  14820. break;
  14821. }
  14822. dwTempLen = ( 240 > wcslen(pwszTemp) ) ? wcslen(pwszTemp) : 240;
  14823. wcsncpy(Name+20, pwszTemp, dwTempLen);
  14824. WinsFreeMemory(pwszTemp);
  14825. pwszTemp = NULL;
  14826. }
  14827. Name[wcslen(Name)] = L'\0';
  14828. if( chEndChar is 0x1C )
  14829. {
  14830. dwGroup = WINS_GROUP_DOMAIN;
  14831. pwszGroup = L"DOMAIN NAME ";
  14832. }
  14833. else if( pRow->TypOfRec_e is WINSINTF_E_UNIQUE )
  14834. {
  14835. pwszGroup = L"UNIQUE ";
  14836. dwGroup = WINS_GROUP_UNIQUE;
  14837. }
  14838. else if( pRow->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  14839. {
  14840. pwszGroup = L"GROUP ";
  14841. dwGroup = WINS_GROUP_GROUP;
  14842. }
  14843. else if( pRow->TypOfRec_e is WINSINTF_E_SPEC_GROUP )
  14844. {
  14845. pwszGroup = L"INTERNET GROUP";
  14846. dwGroup = WINS_GROUP_INTERNET;
  14847. }
  14848. else
  14849. {
  14850. pwszGroup = L"MULTIHOMED ";
  14851. dwGroup = WINS_GROUP_MULTIHOMED;
  14852. }
  14853. //Load the group string
  14854. {
  14855. dwGrouplen = LoadStringW(g_hModule,
  14856. dwGroup,
  14857. wszGroup,
  14858. sizeof(wszGroup)/sizeof(WCHAR));
  14859. if( dwGrouplen is 0 )
  14860. wcscpy(wszGroup, pwszGroup);
  14861. }
  14862. if( pRow->State_e is WINSINTF_E_ACTIVE )
  14863. {
  14864. pwszState = L"ACTIVE";
  14865. dwState = WINS_STATE_ACTIVE;
  14866. }
  14867. else if( pRow->State_e is WINSINTF_E_RELEASED )
  14868. {
  14869. dwState = WINS_STATE_RELEASED;
  14870. pwszState = L"RELEASED";
  14871. }
  14872. else
  14873. {
  14874. dwState = WINS_STATE_TOMBSTONE;
  14875. pwszState = L"TOMBSTONE";
  14876. }
  14877. //Load the State string
  14878. {
  14879. dwStatelen = LoadStringW(g_hModule,
  14880. dwState,
  14881. wszState,
  14882. sizeof(wszState)/sizeof(WCHAR));
  14883. if( dwStatelen is 0 )
  14884. wcscpy(wszState, pwszState);
  14885. }
  14886. if( pRow->fStatic )
  14887. {
  14888. dwType = WINS_TYPE_STATIC;
  14889. pwszType = L"STATIC";
  14890. }
  14891. else
  14892. {
  14893. dwType = WINS_TYPE_DYNAMIC;
  14894. pwszType = L"DYNAMIC";
  14895. }
  14896. //Load the State string
  14897. {
  14898. dwTypelen = LoadStringW(g_hModule,
  14899. dwType,
  14900. wszType,
  14901. sizeof(wszType)/sizeof(WCHAR));
  14902. if( dwTypelen is 0 )
  14903. wcscpy(wszType, pwszType);
  14904. }
  14905. iType = 1;
  14906. pwszTime = GetDateTimeString(pRow->TimeStamp,
  14907. FALSE,
  14908. &iType);
  14909. DisplayMessage(g_hModule,
  14910. MSG_WINS_RECORD_INFO,
  14911. Name,
  14912. wszType,
  14913. wszState,
  14914. pRow->VersNo.HighPart,
  14915. pRow->VersNo.LowPart,
  14916. pRow->NodeTyp,
  14917. wszGroup,
  14918. iType ? wszInfinite : pwszTime);
  14919. if( fOpenFile )
  14920. {
  14921. DumpMessage(g_hModule,
  14922. pFile,
  14923. FMSG_WINS_RECORDS_INFO,
  14924. Name,
  14925. wszType,
  14926. wszState,
  14927. pRow->VersNo.HighPart,
  14928. pRow->VersNo.LowPart,
  14929. pRow->NodeTyp,
  14930. wszGroup,
  14931. iType ? wszInfinite : pwszTime);
  14932. }
  14933. if( pwszTime )
  14934. {
  14935. WinsFreeMemory(pwszTime);
  14936. pwszTime = NULL;
  14937. }
  14938. fMatch = FALSE;
  14939. ChkAdd(
  14940. pRow,
  14941. AddFilter,
  14942. fOpenFile,
  14943. pFile,
  14944. pWinsAdd->IPAdd,
  14945. &fMatch
  14946. );
  14947. DisplayMessage(g_hModule,
  14948. MSG_WINS_RECORD_LINE);
  14949. dwCount++;
  14950. }
  14951. }
  14952. else
  14953. {
  14954. if( fMatch or
  14955. fSetFilter is FALSE or
  14956. ( fAddFilter is FALSE and
  14957. IsBadStringPtrA(pRow->pName, 256) is FALSE and
  14958. _strnicmp(pRow->pName, pFilterName, (pRow->NameLen>Len)?Len:pRow->NameLen) is 0 )
  14959. )
  14960. {
  14961. WCHAR Name[256] = {L'\0'};
  14962. CHAR chEndChar = 0x00;
  14963. LPWSTR pwszTemp = NULL;
  14964. DWORD dwTempLen = 0;
  14965. DisplayMessage(g_hModule,
  14966. MSG_WINS_RECORD_LINE);
  14967. if( fOpenFile and
  14968. g_fHeader is FALSE )
  14969. {
  14970. DumpMessage(g_hModule,
  14971. pFile,
  14972. FMSG_WINS_RECORD_TABLE);
  14973. g_fHeader = TRUE;
  14974. }
  14975. chEndChar = (CHAR)pRow->pName[15];
  14976. pRow->pName[15] = '\0';
  14977. pwszTemp = WinsOemToUnicode(pRow->pName, NULL);
  14978. if( pwszTemp is NULL )
  14979. {
  14980. DisplayMessage(g_hModule,
  14981. EMSG_WINS_OUT_OF_MEMORY);
  14982. Status = WINSINTF_FAILURE;
  14983. break;
  14984. }
  14985. dwTempLen = ( 16 > wcslen(pwszTemp) ) ? wcslen(pwszTemp) : 16;
  14986. wcsncpy(Name, pwszTemp, dwTempLen);
  14987. WinsFreeMemory(pwszTemp);
  14988. pwszTemp = NULL;
  14989. for( k=dwTempLen; k<15; k++ )
  14990. {
  14991. Name[k] = L' ';
  14992. }
  14993. Name[15] = L'[';
  14994. WinsHexToString(Name+16, (LPBYTE)&chEndChar, 1);
  14995. Name[18] = L'h';
  14996. Name[19] = L']';
  14997. Name[20] = L'\0';
  14998. if( IsBadStringPtrA(pRow->pName+16, 240) is FALSE )
  14999. {
  15000. pwszTemp = WinsOemToUnicode(pRow->pName+16, NULL);
  15001. if( pwszTemp is NULL )
  15002. {
  15003. DisplayMessage(g_hModule,
  15004. EMSG_WINS_OUT_OF_MEMORY);
  15005. Status = WINSINTF_FAILURE;
  15006. break;
  15007. }
  15008. dwTempLen = ( 240 > wcslen(pwszTemp) ) ? wcslen(pwszTemp) : 240;
  15009. wcsncpy(Name+20, pwszTemp, dwTempLen);
  15010. WinsFreeMemory(pwszTemp);
  15011. pwszTemp = NULL;
  15012. }
  15013. Name[wcslen(Name)] = L'\0';
  15014. if( chEndChar is 0x1C )
  15015. {
  15016. dwGroup = WINS_GROUP_DOMAIN;
  15017. pwszGroup = L"DOMAIN NAME ";
  15018. }
  15019. else if( pRow->TypOfRec_e is WINSINTF_E_UNIQUE )
  15020. {
  15021. pwszGroup = L"UNIQUE ";
  15022. dwGroup = WINS_GROUP_UNIQUE;
  15023. }
  15024. else if( pRow->TypOfRec_e is WINSINTF_E_NORM_GROUP )
  15025. {
  15026. pwszGroup = L"GROUP ";
  15027. dwGroup = WINS_GROUP_GROUP;
  15028. }
  15029. else if( pRow->TypOfRec_e is WINSINTF_E_SPEC_GROUP )
  15030. {
  15031. pwszGroup = L"INTERNET GROUP";
  15032. dwGroup = WINS_GROUP_INTERNET;
  15033. }
  15034. else
  15035. {
  15036. pwszGroup = L"MULTIHOMED ";
  15037. dwGroup = WINS_GROUP_MULTIHOMED;
  15038. }
  15039. //Load the group string
  15040. {
  15041. dwGrouplen = LoadStringW(g_hModule,
  15042. dwGroup,
  15043. wszGroup,
  15044. sizeof(wszGroup)/sizeof(WCHAR));
  15045. if( dwGrouplen is 0 )
  15046. wcscpy(wszGroup, pwszGroup);
  15047. }
  15048. if( pRow->State_e is WINSINTF_E_ACTIVE )
  15049. {
  15050. pwszState = L"ACTIVE";
  15051. dwState = WINS_STATE_ACTIVE;
  15052. }
  15053. else if( pRow->State_e is WINSINTF_E_RELEASED )
  15054. {
  15055. dwState = WINS_STATE_RELEASED;
  15056. pwszState = L"RELEASED";
  15057. }
  15058. else
  15059. {
  15060. dwState = WINS_STATE_TOMBSTONE;
  15061. pwszState = L"TOMBSTONE";
  15062. }
  15063. //Load the State string
  15064. {
  15065. dwStatelen = LoadStringW(g_hModule,
  15066. dwState,
  15067. wszState,
  15068. sizeof(wszState)/sizeof(WCHAR));
  15069. if( dwStatelen is 0 )
  15070. wcscpy(wszState, pwszState);
  15071. }
  15072. if( pRow->fStatic )
  15073. {
  15074. dwType = WINS_TYPE_STATIC;
  15075. pwszType = L"STATIC";
  15076. }
  15077. else
  15078. {
  15079. dwType = WINS_TYPE_DYNAMIC;
  15080. pwszType = L"DYNAMIC";
  15081. }
  15082. //Load the State string
  15083. {
  15084. dwTypelen = LoadStringW(g_hModule,
  15085. dwType,
  15086. wszType,
  15087. sizeof(wszType)/sizeof(WCHAR));
  15088. if( dwTypelen is 0 )
  15089. wcscpy(wszType, pwszType);
  15090. }
  15091. iType = 1;
  15092. pwszTime = GetDateTimeString(pRow->TimeStamp,
  15093. FALSE,
  15094. &iType);
  15095. DisplayMessage(g_hModule,
  15096. MSG_WINS_RECORD_INFO,
  15097. Name,
  15098. wszType,
  15099. wszState,
  15100. pRow->VersNo.HighPart,
  15101. pRow->VersNo.LowPart,
  15102. pRow->NodeTyp,
  15103. wszGroup,
  15104. iType ? wszInfinite : pwszTime);
  15105. if( fOpenFile )
  15106. {
  15107. DumpMessage(g_hModule,
  15108. pFile,
  15109. FMSG_WINS_RECORDS_INFO,
  15110. Name,
  15111. wszType,
  15112. wszState,
  15113. pRow->VersNo.HighPart,
  15114. pRow->VersNo.LowPart,
  15115. pRow->NodeTyp,
  15116. wszGroup,
  15117. iType ? wszInfinite : pwszTime);
  15118. }
  15119. if( pwszTime )
  15120. {
  15121. WinsFreeMemory(pwszTime);
  15122. pwszTime = NULL;
  15123. }
  15124. fMatch = FALSE;
  15125. ChkAdd(
  15126. pRow,
  15127. AddFilter,
  15128. fOpenFile,
  15129. pFile,
  15130. pWinsAdd->IPAdd,
  15131. &fMatch
  15132. );
  15133. DisplayMessage(g_hModule,
  15134. MSG_WINS_RECORD_LINE);
  15135. dwCount++;
  15136. }
  15137. }
  15138. pRow++;
  15139. }// end of for (all recs)
  15140. if (Status != WINSINTF_SUCCESS)
  15141. break;
  15142. //
  15143. // If a range was chosen and records
  15144. // retrieved are == the limit of 100
  15145. // and if the Max vers no retrieved
  15146. // is less than that specified, ask
  15147. // user if he wishes to continue
  15148. //
  15149. if (!fSetFilter)
  15150. {
  15151. DisplayMessage(g_hModule,
  15152. MSG_WINS_RECORDS_SEARCHED,
  15153. Recs.NoOfRecs);
  15154. }
  15155. if ( Recs.NoOfRecs < Recs.TotalNoOfRecs and
  15156. LiLtr((--pRow)->VersNo,HighVersNo) )
  15157. {
  15158. LowVersNo.QuadPart = LiAdd(pRow->VersNo, sTmpVersNo);
  15159. continue;
  15160. }
  15161. DisplayMessage(g_hModule,
  15162. MSG_WINS_SEARCHDB_COUNT,
  15163. TotalCnt);
  15164. break;
  15165. }
  15166. pwszTempTgt = WinsOemToUnicode(pTgtAdd, NULL);
  15167. if( pwszTempTgt is NULL )
  15168. {
  15169. DisplayMessage(g_hModule,
  15170. EMSG_WINS_OUT_OF_MEMORY);
  15171. Status = WINSINTF_FAILURE;
  15172. break;
  15173. }
  15174. DisplayMessage(g_hModule,
  15175. MSG_WINS_NO_RECORD,
  15176. pwszTempTgt);
  15177. WinsFreeMemory(pwszTempTgt);
  15178. pwszTempTgt = NULL;
  15179. }
  15180. else
  15181. {
  15182. pwszTempTgt = WinsOemToUnicode(pTgtAdd, NULL);
  15183. if( pwszTempTgt is NULL )
  15184. {
  15185. DisplayMessage(g_hModule,
  15186. EMSG_WINS_OUT_OF_MEMORY);
  15187. break;
  15188. }
  15189. DisplayMessage(g_hModule,
  15190. MSG_WINS_NO_RECORD,
  15191. pwszTempTgt);
  15192. WinsFreeMemory(pwszTempTgt);
  15193. pwszTempTgt = NULL;
  15194. }
  15195. break;
  15196. } // while (TRUE)
  15197. DisplayMessage(g_hModule,
  15198. MSG_SRVR_RECORD_MATCH,
  15199. dwCount);
  15200. if( fOpenFile is TRUE )
  15201. {
  15202. fclose(pFile);
  15203. pFile = NULL;
  15204. }
  15205. g_dwSearchCount += dwCount;
  15206. if (Recs.pRow != NULL)
  15207. {
  15208. WinsFreeMem(Recs.pRow);
  15209. }
  15210. return(Status);
  15211. } // GetDbRecs
  15212. LPWSTR
  15213. GetDateTimeString(DWORD_PTR TimeStamp,
  15214. BOOL fShort,
  15215. int *piType
  15216. )
  15217. {
  15218. DWORD Status = NO_ERROR,
  15219. dwTime = 0;
  15220. int iType = 1;
  15221. LPWSTR pwszTime = NULL;
  15222. if( TimeStamp is INFINITE_EXPIRATION )
  15223. {
  15224. iType = 1;
  15225. }
  15226. else
  15227. {
  15228. Status = FormatDateTimeString(TimeStamp,
  15229. fShort,
  15230. NULL,
  15231. &dwTime);
  15232. if( Status is NO_ERROR )
  15233. {
  15234. pwszTime = WinsAllocateMemory((dwTime+1)*sizeof(WCHAR));
  15235. if( pwszTime )
  15236. {
  15237. dwTime++;
  15238. Status = FormatDateTimeString(TimeStamp,
  15239. fShort,
  15240. pwszTime,
  15241. &dwTime);
  15242. }
  15243. if( Status is NO_ERROR )
  15244. {
  15245. iType = 0;
  15246. }
  15247. }
  15248. }
  15249. *piType = iType;
  15250. return pwszTime;
  15251. }