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

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