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.

3137 lines
120 KiB

  1. //============================================================================
  2. // Copyright(c) 1998, Microsoft Corporation
  3. //
  4. // File: winscl.c
  5. //
  6. // Modification History:
  7. //
  8. // 1/14/1998 Ram Cherala (ramc)
  9. // Added this header and made the following changes to make winscl a more
  10. // intuitive and easy tool to use.
  11. // Expanded abbreviations like vers. to the full form words.
  12. // Made all string comparisions case insensitive.
  13. // Made the input choices more obvious - very specifically state what the
  14. // user should be entering as input to commands.
  15. // Printed version IDs in hexadecimal like the WINS snap-in does.
  16. //
  17. // Implementation of winscl command line utility
  18. //============================================================================
  19. #include <stdio.h>
  20. #include <time.h>
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. //#include <windef.h>
  25. #include <winsock.h>
  26. #include "windows.h"
  27. //#include "jet.h"
  28. //#include "winsif.h"
  29. #include "winsintf.h"
  30. //
  31. // This includes wins.h which includes windbg.h
  32. //
  33. // winsdbg.h defines STATIC to nothing now
  34. //
  35. #include "winsthd.h"
  36. #define FILEU "winsu"
  37. #define FILEO "winso"
  38. STATIC
  39. VOID
  40. GetNameInfo(
  41. PWINSINTF_RECORD_ACTION_T pRecAction,
  42. WINSINTF_ACT_E Cmd_e
  43. );
  44. STATIC
  45. VOID
  46. GetFilterName(
  47. LPBYTE pStr,
  48. LPDWORD pLen
  49. );
  50. STATIC
  51. DWORD
  52. GetStatus(
  53. BOOL fPrint,
  54. LPVOID pResults,
  55. BOOL fNew,
  56. BOOL fShort
  57. );
  58. VOID
  59. ChkAdd(
  60. PWINSINTF_RECORD_ACTION_T pRow,
  61. FILE *pFile,
  62. DWORD Add,
  63. LPBOOL pfMatch
  64. );
  65. STATIC
  66. VOID
  67. WantFile(
  68. FILE **ppFile
  69. );
  70. STATIC
  71. DWORD
  72. GetDbRecs(
  73. WINSINTF_VERS_NO_T LowVersNo,
  74. WINSINTF_VERS_NO_T HighVersNo,
  75. PWINSINTF_ADD_T pWinsAdd,
  76. LPBYTE pTgtAdd,
  77. BOOL fSetFilter,
  78. LPBYTE pFilterName,
  79. DWORD Len,
  80. BOOL fAddFilter,
  81. DWORD AddFilter,
  82. FILE *pFile,
  83. BOOL fCountRec
  84. );
  85. STATIC
  86. DWORD
  87. GetDbRecsByName(
  88. PWINSINTF_ADD_T pWinsAdd,
  89. DWORD Location,
  90. LPBYTE pName,
  91. DWORD NameLen,
  92. DWORD NoOfRecsDesired,
  93. DWORD TypeOfRecs,
  94. BOOL fFilter,
  95. DWORD AddFilter
  96. ) ;
  97. WINSINTF_VERS_NO_T sTmpVersNo;
  98. STATIC
  99. DWORD
  100. CreateFiles(
  101. PWINSINTF_RECS_T pRecs,
  102. PWINSINTF_ADD_T pWinsAdd,
  103. FILE *pFileU,
  104. FILE *pFileO
  105. );
  106. STATIC
  107. DWORD
  108. InitFromFile(
  109. VOID
  110. );
  111. VOID
  112. Usage(
  113. VOID
  114. );
  115. typedef enum _CMD_E *PCMD_E;
  116. VOID
  117. GetCmdCode(
  118. LPBYTE pCmd,
  119. PCMD_E pCmd_e
  120. );
  121. typedef enum _CMD_E {
  122. REG_NAME = 0,
  123. QUERY_NAME,
  124. DEL_NAME,
  125. GET_VERS_CTR_VAL,
  126. GET_MAPS,
  127. GET_MAPS_OLD,
  128. GET_STATS,
  129. GET_STATS_OLD,
  130. PUSH_TRIGGER,
  131. PULL_TRIGGER,
  132. STATIC_INIT,
  133. DO_CC,
  134. DO_SCV,
  135. DEL_RANGE_RECS,
  136. TOMBSTONE_RANGE_RECS,
  137. PULL_RANGE_RECS,
  138. GET_RECS_BY_NAME,
  139. GET_RECS_BY_VERS,
  140. BACKUP_DB,
  141. RESTORE_DB,
  142. // RESTORE_DB_OLD,
  143. RESET_COUNTERS,
  144. COUNT_DB_RECS,
  145. GET_WINS_INFO,
  146. SEARCH_DB,
  147. GET_DOMAIN_NAMES,
  148. DEL_WINS,
  149. CONNECT_WINS,
  150. WINS_ADD,
  151. MENU,
  152. NOMENU,
  153. EXIT,
  154. LAST_PSS_ENTRY,
  155. GET_MAPS_VERBOSE,
  156. REL_NAME,
  157. MOD_NAME,
  158. SYNC_DB,
  159. CHANGE_THDS,
  160. SET_PRIORITY_CLASS,
  161. MEM_DUMP,
  162. BS,
  163. SS,
  164. TERM_WINS,
  165. LAST_ENTRY,
  166. INVALID_VALUE,
  167. CREATE_LMHOSTS,
  168. INIT_FROM_FILE
  169. } CMD_E, *PCMD_E;
  170. static char ProgramName[MAX_PATH+1] ;
  171. struct {
  172. LPSTR SwitchName;
  173. LPSTR ShortName;
  174. ULONG SwitchValue;
  175. LPSTR SwitchInformation;
  176. } CommandSwitchList[] = {
  177. { "REGNAME", "RN", REG_NAME,
  178. "Register a name" },
  179. { "QUERYNAME", "QN", QUERY_NAME,
  180. "Query a name" },
  181. { "DELNAME", "DN", DEL_NAME,
  182. "Delete a name" },
  183. { "GETVERSCTRVAL", "GV", GET_VERS_CTR_VAL,
  184. "Get the current version counter value" },
  185. { "GETMAPS", "GM", GET_MAPS,
  186. "Get the Owner Id to Maximum Version Number mappings" },
  187. { "GETMAPSWINS3.5", "GMO", GET_MAPS_OLD,
  188. "Get the Owner Id to Maximum Version Number mappings (for 3.5 WINS server)" },
  189. { "GETSTATS", "GST", GET_STATS,
  190. "Get WINS statistics" },
  191. { "GETSTATSWINS3.5", "GSTO", GET_STATS_OLD,
  192. "Get WINS statistics (for 3.5 WINS server)" },
  193. { "PUSHTRIGGER", "PUSHT", PUSH_TRIGGER,
  194. "Send a push trigger to another WINS" },
  195. { "PULLTRIGGER", "PULLT", PULL_TRIGGER,
  196. "Send a pull trigger to another WINS" },
  197. { "STATICINIT", "SI", STATIC_INIT,
  198. "Statically initialize the WINS" },
  199. { "CONSISTENCY_CHECK", "CC", DO_CC,
  200. "Initiate consistency check on the WINS - HIGH OVERHEAD OPERATION" },
  201. { "SCAVENGING", "SC", DO_SCV,
  202. "Initiate scavenging on the WINS" },
  203. { "DELRANGEOFRECS", "DRR", DEL_RANGE_RECS,
  204. "Delete all or a range of records" },
  205. { "TOMBSTONERANGEOFRECS", "TRR", TOMBSTONE_RANGE_RECS,
  206. "Tombstone all or a range of records(max 50 at a time)" },
  207. { "PULLRANGERECS", "PRR", PULL_RANGE_RECS,
  208. "Pull all or a range of records from another WINS" },
  209. { "GETRECSBYNAME", "GRBN", GET_RECS_BY_NAME,
  210. "Get records by name" },
  211. { "GETRECSBYVERS", "GRBV", GET_RECS_BY_VERS,
  212. "Get Records by version numbers" },
  213. { "BACKUP", "BK", BACKUP_DB,
  214. "Backup the database" },
  215. { "RESTORE", "RS", RESTORE_DB,
  216. "Restore the database" },
  217. // { "RESTORE_OLD", "RSO", RESTORE_DB_OLD,
  218. // "Restore the db (created by a pre-SUR WINS" },
  219. { "RESETCOUNTERS", "RC", RESET_COUNTERS,
  220. "Reset WINS counters" },
  221. { "COUNTRECS", "CR", COUNT_DB_RECS,
  222. "Count the number of records in the database" },
  223. { "GETWINSINFO", "GI", GET_WINS_INFO,
  224. "Get Inforomation about WINS" },
  225. { "SEARCHDB", "SDB", SEARCH_DB,
  226. "Search the database" },
  227. { "GETDOMAINNAMES", "GD", GET_DOMAIN_NAMES,
  228. "Get domain names" },
  229. { "DELWINS", "DW", DEL_WINS,
  230. "Delete WINS records and info." },
  231. { "CONWINS", "CW", CONNECT_WINS,
  232. "Connect Wins" },
  233. { "WINSADD", "WA", WINS_ADD,
  234. "Get Address of current Wins" },
  235. { "MENU", "ME", MENU,
  236. "SHOW MENU" },
  237. { "NOMENU", "NOME", NOMENU,
  238. "DO NOT SHOW MENU" },
  239. //
  240. // NOTE: Any Option below and including "BREAK" will not be displayed
  241. // with _PSS_RELEASE Defined
  242. //
  243. { "EXIT", "EX", EXIT,
  244. "Terminate winscl" },
  245. { NULL, NULL, LAST_PSS_ENTRY,
  246. "PSS End Marker" },
  247. { "GETMAPS_VERB", "GM_V", GET_MAPS_VERBOSE,
  248. "Get the Owner Id to Max. Vers. No. mappings" },
  249. { "RELEASENAME", "RLN", REL_NAME,
  250. "Release a name" },
  251. { "MODIFYNAME", "MN", MOD_NAME,
  252. "Modify Name" },
  253. { "SYNCDB", "SDB", SYNC_DB,
  254. "Sync. up the db of WINS" },
  255. { "CHANGETHDS", "CT", CHANGE_THDS,
  256. "Change the no. of worker threads (query threads)" },
  257. { "SETPRIORITYCLASS", "SPC", SET_PRIORITY_CLASS,
  258. "Set the priority class of WINS" },
  259. { "MEMDUMP", "MD", MEM_DUMP,
  260. "DUMP MEMORY TO FILE ON WINS MACHINE" },
  261. { "BS", "BS", BS,
  262. "MAY DISRUPT OPERATION OF WINS" },
  263. { "SS", "SS", SS,
  264. "NOOP" },
  265. { "TERMWINS", "TW", TERM_WINS,
  266. "TERMINATE WINS" },
  267. { NULL, NULL, LAST_ENTRY,
  268. "End Marker" }
  269. };
  270. #define WINSCLENH TEXT("winsclenh")
  271. BOOL fEnhMode = FALSE;
  272. handle_t BindHdl;
  273. /////////////
  274. #include <sys\types.h>
  275. #include <sys\stat.h>
  276. FILE *spDbgFile;
  277. FILE *spDbgFile2;
  278. FILE *spServers;
  279. typedef struct {
  280. DWORD NoOfOwners;
  281. struct {
  282. DWORD OwnId;
  283. DWORD IpAdd;
  284. CHAR asIpAdd[20];
  285. WINSINTF_VERS_NO_T VersNo;
  286. BOOL fNameNotFound;
  287. BOOL fCommFail;
  288. } Maps[30];
  289. } WINS_INFO, *PWINS_INFO;
  290. typedef struct {
  291. char Name[18];
  292. BOOL fProb;
  293. } NAME_INFO, *PNAME_INFO;
  294. STATUS
  295. GetWinsInfo(
  296. PWINS_INFO pWinsInfo
  297. );
  298. VOID
  299. sync(
  300. VOID
  301. );
  302. VOID
  303. GetFullName(
  304. LPBYTE pName,
  305. DWORD SChar,
  306. PWINSINTF_RECORD_ACTION_T pRecAction
  307. );
  308. BOOL
  309. ReadNameFile(
  310. PNAME_INFO *ppFileInfo,
  311. LPDWORD pNoOfNames,
  312. LPBYTE pNameOfFile
  313. );
  314. BOOL
  315. BindToWins(
  316. LPBYTE asIpAdd,
  317. PWINSINTF_BIND_DATA_T pBindData,
  318. handle_t *pBindHdl
  319. );
  320. #define SUCCESS 0
  321. #define NAME_NOT_FOUND 1
  322. #define FAILURE 2
  323. DWORD
  324. QueryWins (
  325. LPBYTE pName,
  326. PWINSINTF_RECORD_ACTION_T pRecAction,
  327. PWINSINTF_RECORD_ACTION_T *ppRecAction
  328. );
  329. VOID
  330. StoreName(
  331. PWINSINTF_RECORD_ACTION_T pRecAction,
  332. LPBYTE pName
  333. );
  334. /////////////////
  335. _cdecl
  336. main(int argc, char **argv)
  337. {
  338. DWORD Status;
  339. WINSINTF_RECORD_ACTION_T RecAction;
  340. DWORD Choice;
  341. BYTE String[80];
  342. SYSTEMTIME SystemTime;
  343. BYTE tgtadd[50];
  344. TCHAR NmsAdd[50];
  345. WINSINTF_ADD_T WinsAdd;
  346. WINSINTF_ADD_T OwnAdd; //address of WINS owning records in the db
  347. WINSINTF_RESULTS_T Results;
  348. WINSINTF_RESULTS_NEW_T ResultsN;
  349. BOOL fExit = FALSE;
  350. DWORD i;
  351. WINSINTF_RECTYPE_E TypOfRec_e;
  352. WINSINTF_STATE_E State_e;
  353. DWORD Dynamic;
  354. struct in_addr InAddr;
  355. WINSINTF_VERS_NO_T MinVersNo, MaxVersNo;
  356. DWORD TotalCnt = 0;
  357. BOOL fCountRec = FALSE;
  358. WINSINTF_BIND_DATA_T BindData;
  359. BOOL fIncremental;
  360. PWINSINTF_RECORD_ACTION_T pRecAction;
  361. FILE *pFileU = NULL;
  362. FILE *pFileO = NULL;
  363. WINSINTF_RECS_T Recs;
  364. BOOL fFileInited = FALSE;
  365. LPBYTE *ppStr = argv;
  366. DWORD NoOfChars;
  367. CMD_E Cmd_e = GET_MAPS;
  368. BOOL fInteractive = TRUE;
  369. DWORD Access;
  370. try
  371. {
  372. NoOfChars = GetEnvironmentVariable(WINSCLENH, (LPTSTR)String, sizeof(String)/sizeof(TCHAR));
  373. //wprintf(L"Environmental string is %s\n", String);
  374. if ((NoOfChars == 1) && !lstrcmpi((LPTSTR)String, TEXT("1")))
  375. {
  376. fEnhMode = TRUE;
  377. }
  378. sTmpVersNo.LowPart = 1;
  379. sTmpVersNo.HighPart = 0;
  380. LABEL:
  381. if ((argc >= 2) && (!_strcmpi(*(ppStr + 1), "-?")))
  382. {
  383. Usage();
  384. return(1);
  385. }
  386. if (argc == 1)
  387. {
  388. printf("TCP/IP or named pipe. Enter 1 for TCP/IP or 0 for named pipe -- ");
  389. scanf("%d", &Choice);
  390. }
  391. else
  392. {
  393. if (!_strcmpi (*(ppStr + 1), "T"))
  394. {
  395. Choice = 1;
  396. }
  397. else
  398. {
  399. if (!_strcmpi (*(ppStr + 1), "N"))
  400. {
  401. Choice = 2;
  402. }
  403. else
  404. {
  405. BOOL fUsage = FALSE;
  406. TCHAR UserName[100];
  407. DWORD UserNameSize = sizeof(UserName)/sizeof(TCHAR);
  408. if (!GetUserName(UserName, &UserNameSize))
  409. {
  410. fUsage = TRUE;
  411. }
  412. else
  413. {
  414. if (!lstrcmpi(UserName, TEXT("pradeepb")))
  415. {
  416. if (!_strcmpi (*(ppStr + 1), "SYNC") || !_strcmpi(*(ppStr + 1), "SYNCB"))
  417. {
  418. if (!_strcmpi(*(ppStr + 1), "SYNCB"))
  419. {
  420. if ((spDbgFile = fopen("nmfl.dbg", "w")) == NULL)
  421. {
  422. return 1;
  423. }
  424. if ((spDbgFile2 = fopen("nmfls.dbg", "w")) == NULL)
  425. {
  426. return 1;
  427. }
  428. }
  429. else
  430. {
  431. spDbgFile = stdout;
  432. spDbgFile2 = stdout;
  433. }
  434. sync();
  435. return 1;
  436. }
  437. else
  438. {
  439. fUsage = TRUE;
  440. }
  441. }
  442. else
  443. {
  444. fUsage = TRUE;
  445. }
  446. }
  447. if (fUsage)
  448. {
  449. Usage();
  450. return(1);
  451. }
  452. }
  453. }
  454. }
  455. if (Choice == 1)
  456. {
  457. printf("Address of Nameserver to contact-- ");
  458. //scanf("%s", NmsAdd);
  459. wscanf(L"%s", NmsAdd);
  460. BindData.fTcpIp = TRUE;
  461. }
  462. else
  463. {
  464. printf("UNC name of machine-- ");
  465. wscanf(L"%s", NmsAdd);
  466. BindData.fTcpIp = FALSE;
  467. BindData.pPipeName = (LPBYTE)TEXT("\\pipe\\WinsPipe");
  468. }
  469. BindData.pServerAdd = (LPBYTE)NmsAdd;
  470. BindHdl = WinsBind(&BindData);
  471. if (BindHdl == NULL)
  472. {
  473. printf("Unable to bind to %s\n", NmsAdd);
  474. //wprintf(L"Unable to bind to %s\n", NmsAdd);
  475. goto LABEL;
  476. }
  477. //find out what type of access do we have
  478. Access = WINS_NO_ACCESS;
  479. Status = WinsCheckAccess(BindHdl, &Access);
  480. if (WINSINTF_SUCCESS == Status) {
  481. printf("*** You have %s access to this server ***\n",
  482. (Access ? (Access == WINS_CONTROL_ACCESS ? "Read and Write":"Read Only")
  483. : "No"));
  484. }
  485. while(!fExit)
  486. {
  487. BYTE Cmd[40];
  488. if ((argc == 3) && (Cmd_e != INVALID_VALUE))
  489. {
  490. GetCmdCode(*(ppStr + 2), &Cmd_e);
  491. argc = 0;
  492. fInteractive = FALSE;
  493. }
  494. else
  495. {
  496. DWORD LastEntry;
  497. if (fInteractive)
  498. {
  499. LastEntry = (fEnhMode ? LAST_ENTRY : LAST_PSS_ENTRY);
  500. for (Cmd_e = 0; Cmd_e < (CMD_E)LastEntry; Cmd_e++)
  501. {
  502. if (CommandSwitchList[Cmd_e].ShortName != NULL)
  503. {
  504. printf("%s-%s\n", CommandSwitchList[Cmd_e].ShortName,
  505. CommandSwitchList[Cmd_e].SwitchInformation);
  506. }
  507. }
  508. }
  509. printf("Command -- ");
  510. scanf("%s", Cmd);
  511. GetCmdCode(Cmd, &Cmd_e);
  512. }
  513. if (Cmd_e == COUNT_DB_RECS)
  514. {
  515. Cmd_e = GET_RECS_BY_VERS;
  516. fCountRec = TRUE;
  517. }
  518. switch(Cmd_e)
  519. {
  520. case(REG_NAME):
  521. GetNameInfo(&RecAction, WINSINTF_E_INSERT);
  522. RecAction.Cmd_e = WINSINTF_E_INSERT;
  523. pRecAction = &RecAction;
  524. Status = WinsRecordAction(BindHdl,&pRecAction);
  525. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  526. if (RecAction.pName != NULL)
  527. {
  528. WinsFreeMem(RecAction.pName);
  529. }
  530. if (RecAction.pAdd != NULL)
  531. {
  532. WinsFreeMem(RecAction.pAdd);
  533. }
  534. WinsFreeMem(pRecAction);
  535. break;
  536. case(QUERY_NAME):
  537. GetNameInfo(&RecAction, WINSINTF_E_QUERY);
  538. RecAction.Cmd_e = WINSINTF_E_QUERY;
  539. pRecAction = &RecAction;
  540. Status = WinsRecordAction(BindHdl, &pRecAction);
  541. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  542. if (Status == WINSINTF_SUCCESS)
  543. {
  544. printf("Name=(%s)\nNodeType=(%d)\nState=(%s)\nTimeStamp=(%.19s)\nOwnerId=(%d)\nType Of Rec=(%s)\nVersion No (%x %x)\nRecord is (%s)\n",
  545. pRecAction->pName,
  546. pRecAction->NodeTyp,
  547. pRecAction->State_e == WINSINTF_E_ACTIVE ? "ACTIVE" : (pRecAction->State_e == WINSINTF_E_RELEASED) ? "RELEASED" : "TOMBSTONE",
  548. asctime(localtime(&(pRecAction->TimeStamp))),
  549. pRecAction->OwnerId,
  550. (pRecAction->TypOfRec_e == WINSINTF_E_UNIQUE) ? "UNIQUE" : (pRecAction->TypOfRec_e == WINSINTF_E_NORM_GROUP) ? "NORMAL GROUP" :
  551. (pRecAction->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED",
  552. pRecAction->VersNo.HighPart,
  553. pRecAction->VersNo.LowPart,
  554. pRecAction->fStatic ? "STATIC" : "DYNAMIC"
  555. );
  556. if (
  557. (pRecAction->TypOfRec_e == WINSINTF_E_UNIQUE)
  558. ||
  559. (pRecAction->TypOfRec_e == WINSINTF_E_NORM_GROUP)
  560. )
  561. {
  562. InAddr.s_addr = htonl(pRecAction->Add.IPAdd);
  563. printf("Address is (%s)\n", inet_ntoa(InAddr));
  564. }
  565. else
  566. {
  567. for (i=0; i<pRecAction->NoOfAdds; )
  568. {
  569. InAddr.s_addr = htonl((pRecAction->pAdd +i++)->IPAdd);
  570. printf("Owner is (%s); ", inet_ntoa(InAddr));
  571. InAddr.s_addr = htonl((pRecAction->pAdd + i++)->IPAdd);
  572. printf("Member is (%s)\n", inet_ntoa(InAddr));
  573. }
  574. }
  575. }
  576. else
  577. {
  578. if (Status == WINSINTF_FAILURE)
  579. {
  580. printf("No such name in the database\n");
  581. }
  582. }
  583. if (RecAction.pName != NULL)
  584. {
  585. LocalFree(RecAction.pName);
  586. }
  587. if (RecAction.pAdd != NULL)
  588. {
  589. LocalFree(RecAction.pAdd);
  590. }
  591. WinsFreeMem(pRecAction);
  592. break;
  593. case(REL_NAME):
  594. GetNameInfo(&RecAction, WINSINTF_E_RELEASE);
  595. RecAction.Cmd_e = WINSINTF_E_RELEASE;
  596. pRecAction = &RecAction;
  597. Status = WinsRecordAction(BindHdl, &pRecAction);
  598. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  599. if (RecAction.pName != NULL)
  600. {
  601. LocalFree(RecAction.pName);
  602. }
  603. if (RecAction.pAdd != NULL)
  604. {
  605. LocalFree(RecAction.pAdd);
  606. }
  607. WinsFreeMem(pRecAction);
  608. break;
  609. //
  610. // Modify a record (timestamp, flag byte)
  611. //
  612. case(MOD_NAME):
  613. GetNameInfo(&RecAction, WINSINTF_E_MODIFY);
  614. RecAction.Cmd_e = WINSINTF_E_MODIFY;
  615. #if 0
  616. //
  617. // Get the input values
  618. //
  619. time((time_t *)&RecAction.TimeStamp);
  620. #endif
  621. printf("Unique/Normal Group record to a Special/Multihomed record or vice-versa DISALLOWED\n");
  622. printf("Type(1-Norm. Grp;2-Spec. Grp.;3-Multihomed; Any other-Unique -> ");
  623. scanf("%d", &TypOfRec_e);
  624. if (TypOfRec_e > 3 || TypOfRec_e < 1)
  625. {
  626. TypOfRec_e = 0;
  627. }
  628. RecAction.TypOfRec_e = TypOfRec_e;
  629. if ((TypOfRec_e != 1) && (TypOfRec_e != 2))
  630. {
  631. printf("Node Type -- P-node (0), H-node (1), B-node (2),default - P node -- ");
  632. scanf("%d", &Choice);
  633. switch(Choice)
  634. {
  635. default:
  636. case(0):
  637. RecAction.NodeTyp = WINSINTF_E_PNODE;
  638. break;
  639. case(1):
  640. RecAction.NodeTyp = WINSINTF_E_HNODE;
  641. break;
  642. case(2):
  643. RecAction.NodeTyp = WINSINTF_E_BNODE;
  644. break;
  645. }
  646. }
  647. else
  648. {
  649. RecAction.NodeTyp = 0;
  650. }
  651. printf("State-(1-RELEASED;2-TOMBSTONE;3-DELETE;Any other-ACTIVE -> ");
  652. scanf("%d", &State_e);
  653. if (State_e != 1 && State_e != 2 && State_e != 3)
  654. {
  655. State_e = 0;
  656. }
  657. RecAction.State_e = State_e;
  658. printf("Do you want it to be dynamic? 1 - yes. ");
  659. scanf("%d", &Dynamic);
  660. if (Dynamic == 1)
  661. {
  662. RecAction.fStatic = 0;
  663. }
  664. else
  665. {
  666. RecAction.fStatic = 1;
  667. }
  668. pRecAction = &RecAction;
  669. Status = WinsRecordAction(BindHdl, &pRecAction);
  670. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  671. if (RecAction.pName != NULL)
  672. {
  673. LocalFree(RecAction.pName);
  674. }
  675. if (RecAction.pAdd != NULL)
  676. {
  677. LocalFree(RecAction.pAdd);
  678. }
  679. WinsFreeMem(pRecAction);
  680. break;
  681. //
  682. // Delete a record
  683. //
  684. case(DEL_NAME):
  685. GetNameInfo(&RecAction, WINSINTF_E_DELETE);
  686. RecAction.Cmd_e = WINSINTF_E_DELETE;
  687. RecAction.State_e = WINSINTF_E_DELETED;
  688. pRecAction = &RecAction;
  689. Status = WinsRecordAction(BindHdl, &pRecAction);
  690. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  691. if (RecAction.pName != NULL)
  692. {
  693. LocalFree(RecAction.pName);
  694. }
  695. if (RecAction.pAdd != NULL)
  696. {
  697. LocalFree(RecAction.pAdd);
  698. }
  699. WinsFreeMem(pRecAction);
  700. break;
  701. //
  702. // Get Status
  703. //
  704. case(GET_VERS_CTR_VAL):
  705. {
  706. BYTE NmAdd[30];
  707. Results.AddVersMaps[0].Add.Len = 4;
  708. Results.AddVersMaps[0].Add.Type = 0;
  709. printf("Address of Nameserver (for max. version no)--");
  710. scanf("%s", NmAdd);
  711. Results.AddVersMaps[0].Add.IPAdd =
  712. ntohl(inet_addr(NmAdd));
  713. Results.WinsStat.NoOfPnrs = 0;
  714. Results.WinsStat.pRplPnrs = NULL;
  715. Status = WinsStatus(BindHdl, WINSINTF_E_ADDVERSMAP,
  716. &Results);
  717. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  718. if (Status == WINSINTF_SUCCESS)
  719. {
  720. printf("IP Address - (%s) - Max. Vers. No - (%x %x)\n",
  721. NmAdd,
  722. Results.AddVersMaps[0].VersNo.HighPart,
  723. Results.AddVersMaps[0].VersNo.LowPart
  724. );
  725. }
  726. }
  727. break;
  728. case(GET_MAPS_OLD):
  729. Results.WinsStat.NoOfPnrs = 0;
  730. Results.WinsStat.pRplPnrs = 0;
  731. (VOID)GetStatus(TRUE, &Results, FALSE, FALSE);
  732. break;
  733. //
  734. // Get Statistics
  735. //
  736. case(GET_STATS_OLD):
  737. #define TMST Results.WinsStat.TimeStamps
  738. #define TIME_ARGS(x) \
  739. TMST.x.wMonth, TMST.x.wDay, TMST.x.wYear, TMST.x.wHour, TMST.x.wMinute, TMST.x.wSecond
  740. Results.WinsStat.NoOfPnrs = 0;
  741. Results.WinsStat.pRplPnrs = 0;
  742. Status = WinsStatus(BindHdl, WINSINTF_E_STAT, &Results);
  743. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  744. if (Status == WINSINTF_SUCCESS)
  745. {
  746. printf("TIMESTAMPS\n");
  747. printf("WINS STARTED ON %d/%d/%d at %d hrs %d mts %d secs\n",
  748. TMST.WinsStartTime.wMonth,
  749. TMST.WinsStartTime.wDay,
  750. TMST.WinsStartTime.wYear,
  751. TMST.WinsStartTime.wHour,
  752. TMST.WinsStartTime.wMinute,
  753. TMST.WinsStartTime.wSecond
  754. );
  755. printf("LAST INIT OF DB on %d/%d/%d at %d hrs %d mts %d secs\n",
  756. TIME_ARGS(LastInitDbTime)
  757. );
  758. printf("LAST PLANNED SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  759. TIME_ARGS(LastPScvTime)
  760. );
  761. printf("LAST ADMIN TRIGGERED SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  762. TIME_ARGS(LastATScvTime)
  763. );
  764. printf("LAST REPLICAS TOMBSTONES SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  765. TIME_ARGS(LastTombScvTime)
  766. );
  767. printf("LAST OLD REPLICAS VERIFICATION (SCV) on %d/%d/%d at %d hrs %d mts %d secs\n",
  768. TIME_ARGS(LastVerifyScvTime)
  769. );
  770. printf("LAST PLANNED REPLICATION on %d/%d/%d at %d hrs %d mts %d secs\n",
  771. TMST.LastPRplTime.wMonth,
  772. TMST.LastPRplTime.wDay,
  773. TMST.LastPRplTime.wYear,
  774. TMST.LastPRplTime.wHour,
  775. TMST.LastPRplTime.wMinute,
  776. TMST.LastPRplTime.wSecond
  777. );
  778. printf("LAST ADMIN TRIGGERED REPLICATION on %d/%d/%d at %d hrs %d mts %d secs\n",
  779. TMST.LastATRplTime.wMonth,
  780. TMST.LastATRplTime.wDay,
  781. TMST.LastATRplTime.wYear,
  782. TMST.LastATRplTime.wHour,
  783. TMST.LastATRplTime.wMinute,
  784. TMST.LastATRplTime.wSecond
  785. );
  786. printf("LAST RESET OF COUNTERS on %d/%d/%d at %d hrs %d mts %d secs\n",
  787. TIME_ARGS(CounterResetTime)
  788. );
  789. printf("COUNTERS\n");
  790. printf("\n# of U and G Registration requests = (%d %d)\n# Of Successful/Failed Queries = (%d/%d)\n# Of U and G Refreshes = (%d %d)\n# Of Successful/Failed Releases = (%d/%d)\n# Of U. and G. Conflicts = (%d %d)\n",
  791. Results.WinsStat.Counters.NoOfUniqueReg,
  792. Results.WinsStat.Counters.NoOfGroupReg,
  793. Results.WinsStat.Counters.NoOfSuccQueries,
  794. Results.WinsStat.Counters.NoOfFailQueries,
  795. Results.WinsStat.Counters.NoOfUniqueRef,
  796. Results.WinsStat.Counters.NoOfGroupRef,
  797. Results.WinsStat.Counters.NoOfSuccRel,
  798. Results.WinsStat.Counters.NoOfFailRel,
  799. Results.WinsStat.Counters.NoOfUniqueCnf,
  800. Results.WinsStat.Counters.NoOfGroupCnf
  801. );
  802. }
  803. if (Results.WinsStat.NoOfPnrs)
  804. {
  805. printf("WINS partner --\t# of Succ. Repl--\t # of Comm Fails\n");
  806. for (i =0; i < Results.WinsStat.NoOfPnrs; i++)
  807. {
  808. InAddr.s_addr = htonl(
  809. (Results.WinsStat.pRplPnrs + i)->Add.IPAdd);
  810. printf("%s\t\t%d\t\t%d\n",
  811. inet_ntoa(InAddr),
  812. (Results.WinsStat.pRplPnrs + i)->NoOfRpls,
  813. (Results.WinsStat.pRplPnrs + i)->NoOfCommFails
  814. );
  815. }
  816. WinsFreeMem(Results.WinsStat.pRplPnrs);
  817. }
  818. break;
  819. case(GET_STATS):
  820. #define TMSTN ResultsN.WinsStat.TimeStamps
  821. #define TIME_ARGSN(x) \
  822. TMSTN.x.wMonth, TMSTN.x.wDay, TMSTN.x.wYear, TMSTN.x.wHour, TMSTN.x.wMinute, TMSTN.x.wSecond
  823. ResultsN.WinsStat.NoOfPnrs = 0;
  824. ResultsN.WinsStat.pRplPnrs = NULL;
  825. ResultsN.pAddVersMaps = NULL;
  826. Status = WinsStatusNew(BindHdl, WINSINTF_E_STAT, &ResultsN);
  827. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  828. if (Status == WINSINTF_SUCCESS)
  829. {
  830. printf("TIMESTAMPS\n");
  831. printf("WINS STARTED ON %d/%d/%d at %d hrs %d mts %d secs\n",
  832. TMSTN.WinsStartTime.wMonth,
  833. TMSTN.WinsStartTime.wDay,
  834. TMSTN.WinsStartTime.wYear,
  835. TMSTN.WinsStartTime.wHour,
  836. TMSTN.WinsStartTime.wMinute,
  837. TMSTN.WinsStartTime.wSecond
  838. );
  839. printf("LAST INIT OF DB on %d/%d/%d at %d hrs %d mts %d secs\n",
  840. TIME_ARGSN(LastInitDbTime)
  841. );
  842. printf("LAST PLANNED SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  843. TIME_ARGSN(LastPScvTime)
  844. );
  845. printf("LAST ADMIN TRIGGERED SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  846. TIME_ARGSN(LastATScvTime)
  847. );
  848. printf("LAST REPLICAS TOMBSTONES SCV on %d/%d/%d at %d hrs %d mts %d secs\n",
  849. TIME_ARGSN(LastTombScvTime)
  850. );
  851. printf("LAST OLD REPLICAS VERIFICATION (SCV) on %d/%d/%d at %d hrs %d mts %d secs\n",
  852. TIME_ARGSN(LastVerifyScvTime)
  853. );
  854. printf("LAST PLANNED REPLICATION on %d/%d/%d at %d hrs %d mts %d secs\n",
  855. TMSTN.LastPRplTime.wMonth,
  856. TMSTN.LastPRplTime.wDay,
  857. TMSTN.LastPRplTime.wYear,
  858. TMSTN.LastPRplTime.wHour,
  859. TMSTN.LastPRplTime.wMinute,
  860. TMSTN.LastPRplTime.wSecond
  861. );
  862. printf("LAST ADMIN TRIGGERED REPLICATION on %d/%d/%d at %d hrs %d mts %d secs\n",
  863. TMSTN.LastATRplTime.wMonth,
  864. TMSTN.LastATRplTime.wDay,
  865. TMSTN.LastATRplTime.wYear,
  866. TMSTN.LastATRplTime.wHour,
  867. TMSTN.LastATRplTime.wMinute,
  868. TMSTN.LastATRplTime.wSecond
  869. );
  870. printf("LAST RESET OF COUNTERS on %d/%d/%d at %d hrs %d mts %d secs\n",
  871. TIME_ARGSN(CounterResetTime)
  872. );
  873. printf("COUNTERS\n");
  874. printf("\n# of U and G Registration requests = (%d %d)\n# Of Successful/Failed Queries = (%d/%d)\n# Of U and G Refreshes = (%d %d)\n# Of Successful/Failed Releases = (%d/%d)\n# Of U. and G. Conflicts = (%d %d)\n",
  875. ResultsN.WinsStat.Counters.NoOfUniqueReg,
  876. ResultsN.WinsStat.Counters.NoOfGroupReg,
  877. ResultsN.WinsStat.Counters.NoOfSuccQueries,
  878. ResultsN.WinsStat.Counters.NoOfFailQueries,
  879. ResultsN.WinsStat.Counters.NoOfUniqueRef,
  880. ResultsN.WinsStat.Counters.NoOfGroupRef,
  881. ResultsN.WinsStat.Counters.NoOfSuccRel,
  882. ResultsN.WinsStat.Counters.NoOfFailRel,
  883. ResultsN.WinsStat.Counters.NoOfUniqueCnf,
  884. ResultsN.WinsStat.Counters.NoOfGroupCnf
  885. );
  886. }
  887. if (ResultsN.WinsStat.NoOfPnrs)
  888. {
  889. printf("WINS partner --\t# of Repl --\t # of Comm Fails\n");
  890. for (i =0; i < ResultsN.WinsStat.NoOfPnrs; i++)
  891. {
  892. InAddr.s_addr = htonl(
  893. (ResultsN.WinsStat.pRplPnrs + i)->Add.IPAdd);
  894. printf("%s\t\t%d\t\t%d\n",
  895. inet_ntoa(InAddr),
  896. (ResultsN.WinsStat.pRplPnrs + i)->NoOfRpls,
  897. (ResultsN.WinsStat.pRplPnrs + i)->NoOfCommFails
  898. );
  899. }
  900. WinsFreeMem(ResultsN.pAddVersMaps);
  901. WinsFreeMem(ResultsN.WinsStat.pRplPnrs);
  902. }
  903. break;
  904. case(PUSH_TRIGGER):
  905. WinsAdd.Len = 4;
  906. WinsAdd.Type = 0;
  907. printf("Address ? ");
  908. scanf("%s", tgtadd);
  909. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  910. printf("Want propagation (default - none) Input 1 for yes? ");
  911. scanf("%d", &Choice);
  912. Status = WinsTrigger(BindHdl, &WinsAdd, Choice == 1 ?
  913. WINSINTF_E_PUSH_PROP : WINSINTF_E_PUSH);
  914. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  915. break;
  916. case(PULL_TRIGGER):
  917. WinsAdd.Len = 4;
  918. WinsAdd.Type = 0;
  919. printf("Address ? ");
  920. scanf("%s", tgtadd);
  921. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  922. Status = WinsTrigger(BindHdl, &WinsAdd, WINSINTF_E_PULL);
  923. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  924. break;
  925. case(STATIC_INIT):
  926. printf("Do you wish to specify a data file (1 - yes) -- ");
  927. scanf("%d", &Choice);
  928. if (Choice == 1)
  929. {
  930. WCHAR String[80];
  931. BOOL fDel;
  932. printf("Enter full file path -- ");
  933. wscanf(L"%s", String);
  934. printf("Delete file after use. Input 1 for yes 0 for no -- ");
  935. scanf("%d", &Choice);
  936. fDel = Choice == 1 ? TRUE : FALSE;
  937. Status = WinsDoStaticInit(BindHdl, String, fDel);
  938. }
  939. else
  940. {
  941. Status = WinsDoStaticInit(BindHdl, (WCHAR *)NULL, FALSE);
  942. }
  943. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  944. break;
  945. case(DO_CC):
  946. {
  947. WINSINTF_SCV_REQ_T ScvReq;
  948. #if 0
  949. printf("Scavenging/consistency check\nInput 0 for General; 1 for Consistency Chk -- ");
  950. scanf("%d", &Choice);
  951. ScvReq.Opcode_e = (Choice == 0) ? WINSINTF_E_SCV_GENERAL : WINSINTF_E_SCV_VERIFY;
  952. #endif
  953. ScvReq.Opcode_e = WINSINTF_E_SCV_VERIFY;
  954. #if 0
  955. if (Choice != 0)
  956. #endif
  957. {
  958. printf("Consistency Check all or those older than verify interval\nCAUTION: CONSISTENCY CHECKING ALL REPLICAS IS A NETWORK AND RESOURCE INTENSIVE OPERATION\nInput 1 for consistency checking all.\nAny other for those older than verify interval -- ");
  959. scanf("%d", &Choice);
  960. ScvReq.Age = (Choice == 1) ? 0 : Choice;
  961. }
  962. #if 0
  963. if (ScvReq.Opcode_e != WINSINTF_E_SCV_GENERAL)
  964. #endif
  965. {
  966. printf("Do you want to override WINS checking for overload condition ?\nOverload condition is Consistency Check command being repeated within a duration of 1 hour.\nInput 1 for yes. Any other no. will not affect WINS checking -- ");
  967. scanf("%d", &Choice);
  968. }
  969. #if 0
  970. else
  971. {
  972. Choice = 0;
  973. printf("Do you want to override WINS safety checks as regards tombstone deletion.\nWINS normally does not delete tombstones until it has been up and running\nfor a certain duration of time\nInput 1 for overriding the safety checks. Otherwise, input any other no. -- ");
  974. }
  975. ScvReq.fForce = (Choice == 1) ? TRUE : FALSE;
  976. #endif
  977. ScvReq.fForce = (Choice == 1) ? TRUE : FALSE;
  978. Status = WinsDoScavengingNew(BindHdl, &ScvReq);
  979. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  980. }
  981. break;
  982. case(DO_SCV):
  983. Status = WinsDoScavenging(BindHdl );
  984. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  985. break;
  986. case(DEL_RANGE_RECS):
  987. printf("Address of Owner Wins -- ");
  988. scanf("%s", tgtadd);
  989. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  990. WinsAdd.Len = 4;
  991. WinsAdd.Type = 0;
  992. printf("Min. Vers. No (<high part> <low part> -- ");
  993. scanf("%d %d", &MinVersNo.HighPart, &MinVersNo.LowPart);
  994. printf("Max. Vers. No (<high part> <low part> -- ");
  995. scanf("%d %d", &MaxVersNo.HighPart, &MaxVersNo.LowPart);
  996. Status = WinsDelDbRecs(BindHdl, &WinsAdd, MinVersNo, MaxVersNo);
  997. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  998. break;
  999. case(TOMBSTONE_RANGE_RECS):
  1000. printf("Address of Owner Wins -- ");
  1001. scanf("%s", tgtadd);
  1002. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1003. WinsAdd.Len = 4;
  1004. WinsAdd.Type = 0;
  1005. printf("Min. Vers. No (<high part> <low part> or <0 0> for all -- ");
  1006. scanf("%lx %lx", &MinVersNo.HighPart, &MinVersNo.LowPart);
  1007. printf("Max. Vers. No (<high part> <low part> or <0 0> for all -- ");
  1008. scanf("%lx %lx", &MaxVersNo.HighPart, &MaxVersNo.LowPart);
  1009. Status = WinsTombstoneDbRecs(BindHdl,&WinsAdd, MinVersNo, MaxVersNo);
  1010. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1011. break;
  1012. case(PULL_RANGE_RECS):
  1013. printf("Address of Wins to pull from -- ");
  1014. scanf("%s", tgtadd);
  1015. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1016. WinsAdd.Len = 4;
  1017. printf("Address of Wins whose recs are to be pulled -- ");
  1018. scanf("%s", tgtadd);
  1019. OwnAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1020. OwnAdd.Len = 4;
  1021. OwnAdd.Type = 0;
  1022. printf("Min. Vers. No (<high part> <low part> -- ");
  1023. scanf("%d %d", &MinVersNo.HighPart, &MinVersNo.LowPart);
  1024. printf("Max. Vers. No (<high part> <low part> -- ");
  1025. scanf("%d %d", &MaxVersNo.HighPart, &MaxVersNo.LowPart);
  1026. printf("NOTE: If the local WINS contains any record with a VERS. No. > Min. Vers. and < Max. Vers. No, it will be deleted prior to pulling \n");
  1027. printf("it will be deleted prior to pulling the range\n");
  1028. printf("Process 1 for yes, any other to quit -- ");
  1029. scanf("%d", &Choice);
  1030. if (Choice == 1)
  1031. {
  1032. Status = WinsPullRange(BindHdl, &WinsAdd, &OwnAdd, MinVersNo,
  1033. MaxVersNo);
  1034. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1035. }
  1036. break;
  1037. case(GET_RECS_BY_VERS):
  1038. {
  1039. FILE *pFile;
  1040. DWORD Len;
  1041. BOOL fSetFilter;
  1042. pFile = NULL;
  1043. WinsAdd.Len = 4;
  1044. WinsAdd.Type = 0;
  1045. printf("Address of owner WINS? ");
  1046. scanf("%s", tgtadd);
  1047. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1048. if (!fCountRec)
  1049. {
  1050. printf("Want to specify range -- (input 1) or all (default) -- ");
  1051. }
  1052. else
  1053. {
  1054. printf("Want to specify range -- (input 1) or count all (default) -- ");
  1055. }
  1056. scanf("%d", &Choice);
  1057. if (Choice != 1)
  1058. {
  1059. MinVersNo.LowPart = MinVersNo.HighPart = 0;
  1060. MaxVersNo.LowPart = MaxVersNo.HighPart = 0;
  1061. }
  1062. else
  1063. {
  1064. printf("Min. Vers. No (<high part> <low part> -- ");
  1065. scanf("%d %d", &MinVersNo.HighPart, &MinVersNo.LowPart);
  1066. printf("Max. Vers. No (<high part> <low part> -- ");
  1067. scanf("%d %d", &MaxVersNo.HighPart, &MaxVersNo.LowPart);
  1068. }
  1069. if (!fCountRec)
  1070. {
  1071. printf("Use filter (1 for yes, 0 for no) -- ");
  1072. scanf("%d", &Choice);
  1073. if (Choice == 1)
  1074. {
  1075. GetFilterName(String, &Len);
  1076. fSetFilter = TRUE;
  1077. }
  1078. else
  1079. {
  1080. fSetFilter = FALSE;
  1081. }
  1082. WantFile(&pFile);
  1083. if (pFile != NULL)
  1084. {
  1085. GetSystemTime(&SystemTime);
  1086. fprintf(pFile, "\n*******************************\n\n");
  1087. fprintf(pFile, "OWNER WINS = (%s); LOCAL DB OF WINS = (%s)\n", tgtadd, NmsAdd);
  1088. fprintf(pFile, "Time is %d:%d:%d on %d/%d/%d\n",
  1089. SystemTime.wHour, SystemTime.wMinute,
  1090. SystemTime.wSecond, SystemTime.wMonth,
  1091. SystemTime.wDay, SystemTime.wYear);
  1092. fprintf(pFile, "*******************************\n\n");
  1093. }
  1094. }
  1095. Status = GetDbRecs(
  1096. MinVersNo,
  1097. MaxVersNo,
  1098. &WinsAdd,
  1099. tgtadd,
  1100. fSetFilter,
  1101. String,
  1102. Len,
  1103. FALSE, //fAddFilter
  1104. 0, //Address
  1105. pFile,
  1106. fCountRec
  1107. );
  1108. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1109. if (pFile != NULL)
  1110. {
  1111. fclose(pFile);
  1112. }
  1113. break;
  1114. }
  1115. case(BACKUP_DB):
  1116. printf(" Full (1) or Incremental (any other) -- ");
  1117. scanf("%d", &Choice);
  1118. if (Choice == 1)
  1119. {
  1120. fIncremental = FALSE;
  1121. }
  1122. else
  1123. {
  1124. fIncremental = TRUE;
  1125. }
  1126. printf("Backup file path -- ");
  1127. scanf("%s", String);
  1128. Status = WinsBackup(BindHdl, String, (short)fIncremental );
  1129. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1130. if (Status != WINSINTF_SUCCESS)
  1131. {
  1132. printf("Check if the backup directory is empty. If not, cleanup and retry\n");
  1133. }
  1134. break;
  1135. case(RESTORE_DB): {
  1136. DbVersion Version;
  1137. printf("Which version of Databse do you want to restore?\n");
  1138. printf("Type 1 for NT3.51, 2 for NT4.0 and 3 for NT5.0 : ");
  1139. scanf("%d", &Version);
  1140. if ( Version <= DbVersionMin || Version >= DbVersionMax ) {
  1141. printf("Invalid choice..\n");
  1142. break;
  1143. }
  1144. printf("Backup file path -- ");
  1145. scanf("%s", String);
  1146. Status = WinsRestoreEx(String, Version);
  1147. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1148. break;
  1149. }
  1150. case(CONNECT_WINS):
  1151. WinsUnbind(&BindData, BindHdl);
  1152. goto LABEL;
  1153. break;
  1154. case(TERM_WINS):
  1155. printf("You sure ??? (yes - 1) ");
  1156. scanf("%d", &Choice);
  1157. if (Choice == 1)
  1158. {
  1159. printf("Abrupt Termination ? (yes - 1) ");
  1160. scanf("%d", &Choice);
  1161. if (Choice == 1)
  1162. {
  1163. Status = WinsTerm(BindHdl, TRUE);
  1164. }
  1165. else
  1166. {
  1167. Status = WinsTerm(BindHdl, FALSE);
  1168. }
  1169. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1170. }
  1171. break;
  1172. case(SET_PRIORITY_CLASS):
  1173. printf("Input Priority Class (1-High, any other-Normal) -- ");
  1174. scanf("%d", &Choice);
  1175. if (Choice == 1)
  1176. {
  1177. Choice = WINSINTF_E_HIGH;
  1178. }
  1179. else
  1180. {
  1181. Choice = WINSINTF_E_NORMAL;
  1182. }
  1183. Status = WinsSetPriorityClass(BindHdl, Choice);
  1184. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1185. break;
  1186. case(RESET_COUNTERS):
  1187. Status = WinsResetCounters(BindHdl);
  1188. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1189. break;
  1190. case(CHANGE_THDS):
  1191. printf("Print the new count of Nbt Threads (1 to %d) -- ", WINSTHD_MAX_NO_NBT_THDS);
  1192. scanf("%d", &Choice);
  1193. if ((Choice < 1) || (Choice > WINSTHD_MAX_NO_NBT_THDS))
  1194. {
  1195. printf("Wrong number \n");
  1196. break;
  1197. }
  1198. Status = WinsWorkerThdUpd(BindHdl, Choice);
  1199. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1200. break;
  1201. case(WINS_ADD):
  1202. wprintf(L"%s\n", NmsAdd);
  1203. break;
  1204. case(MENU):
  1205. fInteractive = TRUE;
  1206. break;
  1207. case(NOMENU):
  1208. fInteractive = FALSE;
  1209. break;
  1210. case(SYNC_DB):
  1211. WinsAdd.Len = 4;
  1212. WinsAdd.Type = 0;
  1213. printf("Address of WINS to sync up with? ");
  1214. scanf("%s", tgtadd);
  1215. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1216. printf("Address of WINS whose records are to be retrieved ? ");
  1217. scanf("%s", tgtadd);
  1218. OwnAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1219. WinsSyncUp(BindHdl, &WinsAdd, &OwnAdd);
  1220. break;
  1221. case(GET_WINS_INFO):
  1222. Status = WinsGetNameAndAdd(BindHdl, &WinsAdd, String);
  1223. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1224. if (Status == WINSINTF_SUCCESS)
  1225. {
  1226. InAddr.s_addr = htonl(WinsAdd.IPAdd);
  1227. printf("Address is (%s)\nName is (%s)\n",
  1228. inet_ntoa(InAddr), String);
  1229. }
  1230. break;
  1231. case(SEARCH_DB):
  1232. {
  1233. DWORD Len;
  1234. BYTE Add[30];
  1235. BOOL fAddFilter;
  1236. DWORD AddFilter;
  1237. FILE *pFile;
  1238. printf("Search by Address or Name (1 for Address, 0 for Name) --" );
  1239. scanf("%d", &Choice);
  1240. if (Choice == 1)
  1241. {
  1242. printf("Address (dotted decimal) -- ");
  1243. scanf("%s", Add);
  1244. AddFilter = ntohl(inet_addr(Add));
  1245. fAddFilter = TRUE;
  1246. }
  1247. else
  1248. {
  1249. GetFilterName(String, &Len);
  1250. fAddFilter = FALSE;
  1251. }
  1252. WantFile(&pFile);
  1253. if (pFile != NULL)
  1254. {
  1255. GetSystemTime(&SystemTime);
  1256. fprintf(pFile, "\n*******************************\n\n");
  1257. fprintf(pFile, "Searching Database of WINS with address = (%s)\n", NmsAdd);
  1258. fprintf(pFile, "Time is %d:%d:%d on %d/%d/%d\n",
  1259. SystemTime.wHour, SystemTime.wMinute,
  1260. SystemTime.wSecond, SystemTime.wMonth,
  1261. SystemTime.wDay, SystemTime.wYear);
  1262. fprintf(pFile, "*******************************\n\n");
  1263. }
  1264. Results.WinsStat.NoOfPnrs = 0;
  1265. Results.WinsStat.pRplPnrs = 0;
  1266. if (GetStatus(FALSE, &Results, FALSE, TRUE) == WINSINTF_SUCCESS)
  1267. {
  1268. if (Results.NoOfOwners != 0)
  1269. {
  1270. for ( i= 0; i < Results.NoOfOwners; i++)
  1271. {
  1272. InAddr.s_addr = htonl(
  1273. Results.AddVersMaps[i].Add.IPAdd);
  1274. printf("Searching records owned by %s\n",
  1275. inet_ntoa(InAddr) );
  1276. WinsAdd.Len = 4;
  1277. WinsAdd.Type = 0;
  1278. WinsAdd.IPAdd =
  1279. Results.AddVersMaps[i].Add.IPAdd;
  1280. MaxVersNo =
  1281. Results.AddVersMaps[i].VersNo;
  1282. MinVersNo.LowPart = 0;
  1283. MinVersNo.HighPart = 0;
  1284. Status = GetDbRecs(
  1285. MinVersNo,
  1286. MaxVersNo,
  1287. &WinsAdd,
  1288. inet_ntoa(InAddr),
  1289. TRUE, //fSetFilter
  1290. String,
  1291. Len,
  1292. fAddFilter,
  1293. AddFilter,
  1294. pFile, //pFile
  1295. FALSE //fCountRec
  1296. );
  1297. if (Status != WINSINTF_SUCCESS)
  1298. {
  1299. break;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. break;
  1306. case(GET_DOMAIN_NAMES):
  1307. {
  1308. WINSINTF_BROWSER_NAMES_T Names;
  1309. PWINSINTF_BROWSER_INFO_T pInfo;
  1310. PWINSINTF_BROWSER_INFO_T pInfoSv;
  1311. DWORD i;
  1312. Names.pInfo = NULL;
  1313. Status = WinsGetBrowserNames(&BindData, &Names);
  1314. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1315. if (Status == WINSINTF_SUCCESS)
  1316. {
  1317. printf("No Of records returned are %d\n",
  1318. Names.EntriesRead);
  1319. pInfoSv = pInfo = Names.pInfo;
  1320. for(i=0; i < Names.EntriesRead; i++)
  1321. {
  1322. printf("Name[%d] = %s\n",
  1323. i,
  1324. pInfo->pName
  1325. );
  1326. pInfo++;
  1327. }
  1328. WinsFreeMem(pInfoSv);
  1329. }
  1330. }
  1331. break;
  1332. case(DEL_WINS):
  1333. WinsAdd.Len = 4;
  1334. WinsAdd.Type = 0;
  1335. printf("Address of Wins to delete? ");
  1336. scanf("%s", tgtadd);
  1337. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1338. Status = WinsDeleteWins(BindHdl, &WinsAdd);
  1339. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1340. break;
  1341. case(CREATE_LMHOSTS):
  1342. if (GetStatus(FALSE, &Results, FALSE, TRUE) == WINSINTF_SUCCESS)
  1343. {
  1344. if (Results.NoOfOwners != 0)
  1345. {
  1346. for ( i= 0; i < Results.NoOfOwners; i++)
  1347. {
  1348. Recs.pRow = NULL;
  1349. InAddr.s_addr = htonl(
  1350. Results.AddVersMaps[i].Add.IPAdd);
  1351. printf(" Will get records owned by %s\n",
  1352. inet_ntoa(InAddr) );
  1353. WinsAdd.Len = 4;
  1354. WinsAdd.Type = 0;
  1355. WinsAdd.IPAdd =
  1356. Results.AddVersMaps[i].Add.IPAdd;
  1357. MaxVersNo =
  1358. Results.AddVersMaps[i].VersNo;
  1359. MinVersNo.LowPart = 0;
  1360. MinVersNo.HighPart = 0;
  1361. Status = WinsGetDbRecs(BindHdl, &WinsAdd,
  1362. MinVersNo, MaxVersNo, &Recs);
  1363. if (Status != WINSINTF_SUCCESS)
  1364. {
  1365. break;
  1366. }
  1367. else
  1368. {
  1369. if ((pFileU == NULL) || (pFileO == NULL))
  1370. {
  1371. pFileU = fopen(FILEU, "a");
  1372. if (pFileU == NULL)
  1373. {
  1374. printf("Could not open file %s for appending\n", FILEU);
  1375. break;
  1376. }
  1377. pFileO = fopen(FILEO, "a");
  1378. if (pFileO == NULL)
  1379. {
  1380. printf("Could not open file %s for appending\n", FILEO);
  1381. break;
  1382. }
  1383. }
  1384. else
  1385. {
  1386. break;
  1387. }
  1388. }
  1389. if(CreateFiles(&Recs, &WinsAdd, pFileU, pFileO) == WINSINTF_SUCCESS)
  1390. {
  1391. fclose(pFileU);
  1392. fclose(pFileO);
  1393. pFileU = NULL;
  1394. pFileO = NULL;
  1395. fFileInited = TRUE;
  1396. }
  1397. }
  1398. }
  1399. }
  1400. else
  1401. {
  1402. printf("GetStatus failed\n");
  1403. }
  1404. break;
  1405. case(INIT_FROM_FILE):
  1406. if (fFileInited)
  1407. {
  1408. if (InitFromFile() != WINSINTF_SUCCESS)
  1409. {
  1410. printf("Init failed\n");
  1411. }
  1412. }
  1413. else
  1414. {
  1415. printf("Use old files (0 for yes) -- ");
  1416. scanf("%d", &Choice);
  1417. if (Choice == 0)
  1418. {
  1419. if (InitFromFile() != WINSINTF_SUCCESS)
  1420. {
  1421. printf("Init failed\n");
  1422. }
  1423. }
  1424. else
  1425. {
  1426. printf("First create file\n");
  1427. }
  1428. }
  1429. break;
  1430. case(GET_RECS_BY_NAME):
  1431. {
  1432. PWINSINTF_ADD_T pWinsAdd = NULL;
  1433. BOOL fAlloc = TRUE;
  1434. BYTE Name[5];
  1435. BYTE strAdd[20];
  1436. DWORD NoOfRecsDesired;
  1437. DWORD TypeOfRec;
  1438. DWORD Location = WINSINTF_BEGINNING;
  1439. printf ("Want to input Name (0 for yes, 1 for no) -- ");
  1440. scanf("%d", &Choice);
  1441. if (Choice == 0)
  1442. {
  1443. printf("First char non-printable 0 for no, 1 for yes -- ");
  1444. scanf("%d", &Choice);
  1445. if (Choice != 0)
  1446. {
  1447. printf("Input 1st char in hex -- ");
  1448. scanf("%x", &Name[0]);
  1449. Name[1] = (BYTE)NULL;
  1450. printf("Name is %s\n", Name);
  1451. RecAction.pName = Name;
  1452. RecAction.NameLen = 1;
  1453. fAlloc = FALSE;
  1454. }
  1455. else
  1456. {
  1457. GetNameInfo(&RecAction, WINSINTF_E_QUERY);
  1458. }
  1459. }
  1460. else
  1461. {
  1462. RecAction.pName = NULL;
  1463. RecAction.NameLen = 0;
  1464. }
  1465. printf("Start from beginning or end of db -- 0 for beginning, 1 for end -");
  1466. scanf("%d", &Choice);
  1467. if (Choice != 0)
  1468. {
  1469. Location = WINSINTF_END;
  1470. }
  1471. printf("Recs of all or of a particular owner (0 for all, or 1 for particular owner) -- ");
  1472. scanf("%d", &Choice);
  1473. if (Choice != 0)
  1474. {
  1475. WinsAdd.Len = 4;
  1476. WinsAdd.Type = 0;
  1477. printf("Address of Wins whose records are to be retrieved? ");
  1478. scanf("%s", tgtadd);
  1479. WinsAdd.IPAdd = ntohl(inet_addr(tgtadd));
  1480. pWinsAdd = &WinsAdd;
  1481. }
  1482. printf("Input - No Of Recs desired (Max is 5000 - for max input 0) -- ");
  1483. scanf("%d", &NoOfRecsDesired);
  1484. printf("Only static (1), only dynamic (2) or both (4) -- ");
  1485. scanf("%d", &TypeOfRec);
  1486. if((TypeOfRec == 1) || (TypeOfRec == 2) || (TypeOfRec == 4))
  1487. {
  1488. BOOL fFilter = FALSE;
  1489. DWORD AddFilter;
  1490. printf("Search for records based on IP Address (0 for no, 1 for yes) -- ");
  1491. scanf("%d", &Choice);
  1492. if ( Choice != 0)
  1493. {
  1494. fFilter = TRUE;
  1495. printf("Input IP address in dotted notation -- ");
  1496. printf("Address (dotted decimal) -- ");
  1497. scanf("%s", strAdd);
  1498. AddFilter = ntohl(inet_addr(strAdd));
  1499. }
  1500. Status = GetDbRecsByName(pWinsAdd, Location, RecAction.pName, RecAction.NameLen, NoOfRecsDesired, TypeOfRec, fFilter, AddFilter);
  1501. if (fAlloc && (RecAction.pName != NULL))
  1502. {
  1503. WinsFreeMem(RecAction.pName);
  1504. }
  1505. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1506. }
  1507. else
  1508. {
  1509. printf("Wrong choice\n");
  1510. }
  1511. }
  1512. break;
  1513. case(GET_MAPS):
  1514. case(GET_MAPS_VERBOSE):
  1515. {
  1516. WINSINTF_RESULTS_NEW_T ResultsN;
  1517. Results.WinsStat.NoOfPnrs = 0;
  1518. Results.WinsStat.pRplPnrs = NULL;
  1519. (VOID)GetStatus(TRUE, (LPVOID)&ResultsN, TRUE,
  1520. Cmd_e == GET_MAPS ? TRUE : FALSE );
  1521. }
  1522. break;
  1523. case(EXIT):
  1524. fExit = TRUE;
  1525. break;
  1526. case(MEM_DUMP):
  1527. printf("Mem. Dump - 2; Heap Dump -4; Que Items dump - 8; or combo -- ");
  1528. scanf("%d", &Choice);
  1529. Status = WinsSetFlags(BindHdl, Choice);
  1530. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1531. break;
  1532. case(BS):
  1533. Status = WinsSetFlags(BindHdl, 1);
  1534. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1535. printf("Status returned is (%d)\n", Status);
  1536. break;
  1537. case(SS):
  1538. Status = WinsSetFlags(BindHdl, 0);
  1539. printf("Status returned (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1540. printf("Status returned is (%d)\n", Status);
  1541. break;
  1542. case(INVALID_VALUE):
  1543. printf("Wrong cmd\n");
  1544. break;
  1545. }
  1546. }
  1547. WinsUnbind(&BindData, BindHdl);
  1548. }
  1549. except(EXCEPTION_EXECUTE_HANDLER)
  1550. {
  1551. printf("Execution exception encountered..\n");
  1552. }
  1553. return(0);
  1554. }
  1555. VOID
  1556. GetNameInfo(
  1557. PWINSINTF_RECORD_ACTION_T pRecAction,
  1558. WINSINTF_ACT_E Cmd_e
  1559. )
  1560. {
  1561. BYTE tgtadd[30];
  1562. BYTE Name[255];
  1563. int Choice;
  1564. int Choice2;
  1565. DWORD LastChar;
  1566. size_t Len;
  1567. pRecAction->pAdd = NULL;
  1568. pRecAction->NoOfAdds = 0;
  1569. pRecAction->fStatic = TRUE;
  1570. printf("Name ? ");
  1571. scanf("%s", Name);
  1572. _strupr(Name);
  1573. if ((Len = strlen(Name)) < 16)
  1574. {
  1575. printf("Do you want to input a 16th char (1 for yes, 0 for no) -- ");
  1576. scanf("%d", &Choice);
  1577. if (Choice)
  1578. {
  1579. printf("16th char in hex -- ");
  1580. scanf("%x", &LastChar);
  1581. memset(&Name[Len], (int)' ',16-Len);
  1582. Name[15] = (BYTE)(LastChar & 0xff);
  1583. Name[16] = (CHAR)NULL;
  1584. Len = 16;
  1585. }
  1586. else {
  1587. memset(&Name[Len], (int)' ',16-Len);
  1588. Name[16] = (CHAR)NULL;
  1589. Len = 16;
  1590. }
  1591. }
  1592. else
  1593. {
  1594. Name[16] = (CHAR)NULL;
  1595. Len = 16;
  1596. }
  1597. printf("Scope - 1 for yes, 0 for no --");
  1598. scanf("%d", &Choice);
  1599. if (Choice == 1)
  1600. {
  1601. Name[Len] = '.';
  1602. printf("Enter scope -- ");
  1603. scanf("%s", &Name[Len + 1]);
  1604. Len = strlen(Name);
  1605. }
  1606. if (Cmd_e == WINSINTF_E_INSERT)
  1607. {
  1608. Choice = 0;
  1609. printf("TypeOfRec - Static(0), Dynamic(1) - Default Static -- ");
  1610. scanf("%d", &Choice);
  1611. if (1 == Choice) {
  1612. pRecAction->fStatic = FALSE;
  1613. }
  1614. Choice = 0;
  1615. printf("TypeOfNode - U(0), Norm Grp (1), Spec Grp (2), Multihomed (3) default Unique -- ");
  1616. scanf("%d", &Choice);
  1617. switch (Choice)
  1618. {
  1619. case(0):
  1620. default:
  1621. pRecAction->TypOfRec_e = WINSINTF_E_UNIQUE;
  1622. break;
  1623. case(1):
  1624. pRecAction->TypOfRec_e = WINSINTF_E_NORM_GROUP;
  1625. break;
  1626. case(2):
  1627. pRecAction->TypOfRec_e = WINSINTF_E_SPEC_GROUP;
  1628. break;
  1629. case(3):
  1630. pRecAction->TypOfRec_e = WINSINTF_E_MULTIHOMED;
  1631. break;
  1632. }
  1633. if ((Choice == 2) || (Choice == 3))
  1634. {
  1635. int i;
  1636. printf("How many addresses do you wish to input (Max %d) -- ",
  1637. WINSINTF_MAX_MEM);
  1638. scanf("%d", &Choice2);
  1639. pRecAction->pAdd = WinsAllocMem(
  1640. sizeof(WINSINTF_ADD_T) * Choice2);
  1641. for(i = 0; i < Choice2 && i < WINSINTF_MAX_MEM; i++)
  1642. {
  1643. printf("IP Address no (%d) ? ", i);
  1644. scanf("%s", tgtadd);
  1645. (pRecAction->pAdd + i)->IPAdd =
  1646. ntohl(inet_addr(tgtadd));
  1647. (pRecAction->pAdd + i)->Type = 0;
  1648. (pRecAction->pAdd + i)->Len = 4;
  1649. }
  1650. pRecAction->NoOfAdds = i;
  1651. }
  1652. else
  1653. {
  1654. printf("IP Address ? ");
  1655. scanf("%s", tgtadd);
  1656. pRecAction->Add.IPAdd = ntohl(inet_addr(tgtadd));
  1657. pRecAction->Add.Type = 0;
  1658. pRecAction->Add.Len = 4;
  1659. // pRecAction->NoOfAdds = 1;
  1660. }
  1661. if ((Choice != 1) && (Choice != 2))
  1662. {
  1663. Choice = 0;
  1664. printf("Node Type -- P-node (0), H-node (1), B-node (2),default - P node -- ");
  1665. scanf("%d", &Choice);
  1666. switch(Choice)
  1667. {
  1668. default:
  1669. case(0):
  1670. pRecAction->NodeTyp = WINSINTF_E_PNODE;
  1671. break;
  1672. case(1):
  1673. pRecAction->NodeTyp = WINSINTF_E_HNODE;
  1674. break;
  1675. case(2):
  1676. pRecAction->NodeTyp = WINSINTF_E_BNODE;
  1677. break;
  1678. }
  1679. }
  1680. }
  1681. #if 0
  1682. if (Cmd_e == WINSINTF_E_RELEASE)
  1683. {
  1684. printf("Want to specify address (pkt add) 1 for yes, 0 for no -- ");
  1685. scanf("%d", &Choice);
  1686. if (Choice == 1)
  1687. {
  1688. if(
  1689. ( pRecAction->TypOfRec_e == WINSINTF_E_SPEC_GROUP)
  1690. ||
  1691. ( pRecAction->TypOfRec_e == WINSINTF_E_MULTIHOMED)
  1692. )
  1693. {
  1694. pRecAction->pAdd = WinsAllocMem(sizeof(WINSINTF_ADD_T));
  1695. printf("IP Address ? -- ");
  1696. scanf("%s", tgtadd);
  1697. pRecAction->pAdd->IPAdd = ntohl(inet_addr(tgtadd));
  1698. pRecAction->pAdd->Type = 0;
  1699. pRecAction->pAdd->Len = 4;
  1700. }
  1701. printf("IP Address ? -- ");
  1702. scanf("%s", tgtadd);
  1703. pRecAction->Add.IPAdd = ntohl(inet_addr(tgtadd));
  1704. pRecAction->Add.Type = 0;
  1705. pRecAction->Add.Len = 4;
  1706. }
  1707. }
  1708. #endif
  1709. pRecAction->pName = WinsAllocMem(Len);
  1710. (void)memcpy(pRecAction->pName, Name, Len);
  1711. pRecAction->NameLen = Len;
  1712. return;
  1713. }
  1714. VOID
  1715. GetFilterName(
  1716. LPBYTE pStr,
  1717. LPDWORD pLen
  1718. )
  1719. {
  1720. DWORD LastChar;
  1721. DWORD Choice;
  1722. printf("Name ? ");
  1723. scanf("%s", pStr);
  1724. if ((*pLen = strlen(pStr)) < 16)
  1725. {
  1726. printf("Do you want to input a 16th char (1 for yes, 0 for no) -- ");
  1727. scanf("%d", &Choice);
  1728. if (Choice)
  1729. {
  1730. printf("16th char in hex -- ");
  1731. scanf("%x", &LastChar);
  1732. memset(&pStr[*pLen], (int)' ',16-*pLen);
  1733. pStr[15] = (BYTE)LastChar && 0xff;
  1734. pStr[16] = (TCHAR)NULL;
  1735. *pLen = 16;
  1736. }
  1737. }
  1738. return;
  1739. }
  1740. DWORD
  1741. GetStatus(
  1742. BOOL fPrint,
  1743. LPVOID pResultsA,
  1744. BOOL fNew,
  1745. BOOL fShort
  1746. )
  1747. {
  1748. DWORD Status, i;
  1749. struct in_addr InAddr;
  1750. PWINSINTF_RESULTS_T pResults = pResultsA;
  1751. PWINSINTF_RESULTS_NEW_T pResultsN = pResultsA;
  1752. PWINSINTF_ADD_VERS_MAP_T pAddVersMaps;
  1753. DWORD NoOfOwners;
  1754. if (!fNew)
  1755. {
  1756. Status = WinsStatus(BindHdl, WINSINTF_E_CONFIG, pResultsA);
  1757. }
  1758. else
  1759. {
  1760. pResultsN->pAddVersMaps = NULL;
  1761. Status = WinsStatusNew(BindHdl, WINSINTF_E_CONFIG_ALL_MAPS, pResultsN);
  1762. }
  1763. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1764. if (Status == WINSINTF_SUCCESS)
  1765. {
  1766. if (fPrint)
  1767. {
  1768. printf("Refresh Interval = (%d)\n",
  1769. fNew ? pResultsN->RefreshInterval :
  1770. pResults->RefreshInterval
  1771. );
  1772. printf("Tombstone Interval = (%d)\n",
  1773. fNew ? pResultsN->TombstoneInterval :
  1774. pResults->TombstoneInterval);
  1775. printf("Tombstone Timeout = (%d)\n",
  1776. fNew ? pResultsN->TombstoneTimeout :
  1777. pResults->TombstoneTimeout);
  1778. printf("Verify Interval = (%d)\n",
  1779. fNew ? pResultsN->VerifyInterval :
  1780. pResults->VerifyInterval);
  1781. if (!fNew)
  1782. {
  1783. printf("WINS Priority Class = (%s)\n",
  1784. pResults->WinsPriorityClass == NORMAL_PRIORITY_CLASS ? "NORMAL" : "HIGH");
  1785. printf("No of Worker Thds in WINS = (%d)\n",
  1786. pResults->NoOfWorkerThds);
  1787. pAddVersMaps = pResults->AddVersMaps;
  1788. NoOfOwners = pResults->NoOfOwners;
  1789. }
  1790. else
  1791. {
  1792. printf("WINS Priority Class = (%s)\n",
  1793. pResultsN->WinsPriorityClass == NORMAL_PRIORITY_CLASS ? "NORMAL" : "HIGH");
  1794. printf("No of Worker Thds in WINS = (%d)\n",
  1795. pResultsN->NoOfWorkerThds);
  1796. pAddVersMaps = pResultsN->pAddVersMaps;
  1797. NoOfOwners = pResultsN->NoOfOwners;
  1798. }
  1799. if (NoOfOwners != 0)
  1800. {
  1801. printf("OWNER ID\t\tADDRESS\t\tVERS.NO\n");
  1802. printf("--------\t\t-------\t\t-------\n");
  1803. for ( i= 0; i < NoOfOwners; i++, pAddVersMaps++)
  1804. {
  1805. InAddr.s_addr = htonl(
  1806. pAddVersMaps->Add.IPAdd);
  1807. if (fNew)
  1808. {
  1809. if (
  1810. (pAddVersMaps->VersNo.HighPart
  1811. == MAXLONG)
  1812. &&
  1813. (pAddVersMaps->VersNo.LowPart ==
  1814. MAXULONG)
  1815. )
  1816. {
  1817. if (!fShort)
  1818. {
  1819. printf("%d\t\t%s\t\t", i, inet_ntoa(InAddr));
  1820. printf("DELETED. SLOT WILL BE REUSED LATER\n");
  1821. }
  1822. continue;
  1823. }
  1824. }
  1825. if (fShort &&
  1826. pAddVersMaps->VersNo.QuadPart == 0)
  1827. {
  1828. continue;
  1829. }
  1830. printf("%d\t\t%s\t\t", i, inet_ntoa(InAddr));
  1831. printf("%lx %lx\n",
  1832. pAddVersMaps->VersNo.HighPart,
  1833. pAddVersMaps->VersNo.LowPart
  1834. );
  1835. }
  1836. if (fNew)
  1837. {
  1838. WinsFreeMem(pResultsN->pAddVersMaps);
  1839. }
  1840. }
  1841. else
  1842. {
  1843. printf("The Db is empty\n");
  1844. Status = WINSINTF_FAILURE;
  1845. }
  1846. }
  1847. }
  1848. return(Status);
  1849. }
  1850. DWORD
  1851. GetDbRecs(
  1852. WINSINTF_VERS_NO_T LowVersNo,
  1853. WINSINTF_VERS_NO_T HighVersNo,
  1854. PWINSINTF_ADD_T pWinsAdd,
  1855. LPBYTE pTgtAdd,
  1856. BOOL fSetFilter,
  1857. LPBYTE pFilterName,
  1858. DWORD Len,
  1859. BOOL fAddFilter,
  1860. DWORD AddFilter,
  1861. FILE *pFile,
  1862. BOOL fCountRec
  1863. )
  1864. {
  1865. WINSINTF_RECS_T Recs;
  1866. DWORD Choice;
  1867. DWORD Status = WINSINTF_SUCCESS;
  1868. DWORD TotalCnt = 0;
  1869. BOOL fMatch;
  1870. while (TRUE)
  1871. {
  1872. Recs.pRow = NULL;
  1873. Status = WinsGetDbRecs(BindHdl, pWinsAdd, LowVersNo, HighVersNo, &Recs);
  1874. if (!fSetFilter)
  1875. {
  1876. printf("Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  1877. }
  1878. if (fCountRec)
  1879. {
  1880. printf("Total number of records are (%d)\n", Recs.TotalNoOfRecs);
  1881. break;
  1882. }
  1883. if (Status == WINSINTF_SUCCESS)
  1884. {
  1885. if (Recs.NoOfRecs > 0)
  1886. {
  1887. DWORD i;
  1888. PWINSINTF_RECORD_ACTION_T pRow = Recs.pRow;
  1889. TotalCnt += Recs.NoOfRecs;
  1890. if (!fSetFilter)
  1891. {
  1892. if (pFile == NULL)
  1893. {
  1894. printf("Retrieved %d records of WINS\n", Recs.NoOfRecs);
  1895. }
  1896. else
  1897. {
  1898. fprintf(pFile, "RETRIEVED %d RECORDS OF WINS = (%s) \n", Recs.NoOfRecs, pTgtAdd);
  1899. }
  1900. }
  1901. for (i=0; i<Recs.NoOfRecs; i++)
  1902. {
  1903. if (fAddFilter)
  1904. {
  1905. //
  1906. // The address filter was specfied
  1907. // If the address matches, then
  1908. // fMatch will be TRUE after the
  1909. // function returns.
  1910. //
  1911. fMatch = TRUE;
  1912. ChkAdd(
  1913. pRow,
  1914. pFile,
  1915. AddFilter,
  1916. &fMatch
  1917. );
  1918. }
  1919. else
  1920. {
  1921. fMatch = FALSE;
  1922. }
  1923. //
  1924. // If the address matched or if no filter
  1925. // was specified or if there was a name
  1926. // filter and the names matched, print
  1927. // out the details
  1928. //
  1929. if (fMatch || !fSetFilter ||
  1930. (
  1931. !fAddFilter &&
  1932. !memcmp(pRow->pName, pFilterName, Len)
  1933. )
  1934. )
  1935. {
  1936. if (pFile == NULL)
  1937. {
  1938. printf("-----------------------\n");
  1939. printf("Name is (%s). 16th char is (%x)\nNameLen is (%d)\nType is (%s)\nState is (%s)\nVersion No is (%x %x)\nStatic flag is (%d)\nTimestamp is (%.19s)\n", pRow->pName, *(pRow->pName+15),
  1940. pRow->NameLen, pRow->TypOfRec_e == WINSINTF_E_UNIQUE ? "UNIQUE" : (pRow->TypOfRec_e == WINSINTF_E_NORM_GROUP) ? "NORMAL GROUP" : (pRow->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED",
  1941. pRow->State_e == WINSINTF_E_ACTIVE ? "ACTIVE" : (pRow->State_e == WINSINTF_E_RELEASED) ? "RELEASED" : "TOMBSTONE", pRow->VersNo.HighPart, pRow->VersNo.LowPart, pRow->fStatic, asctime(localtime(&(pRow->TimeStamp))));
  1942. }
  1943. else
  1944. {
  1945. fprintf(pFile, "-----------------------\n");
  1946. fprintf(pFile, "Name is (%s). 16th char is (%x)\nNameLen is (%d)\nType is (%s)\nState is (%s)\nVersion No is (%x %x)\nStatic flag is (%d)\nTimestamp is (%.19s)\n", pRow->pName, *(pRow->pName+15),
  1947. pRow->NameLen, pRow->TypOfRec_e == WINSINTF_E_UNIQUE ? "UNIQUE" : (pRow->TypOfRec_e == WINSINTF_E_NORM_GROUP) ? "NORMAL GROUP" : (pRow->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED",
  1948. pRow->State_e == WINSINTF_E_ACTIVE ? "ACTIVE" : (pRow->State_e == WINSINTF_E_RELEASED) ? "RELEASED" : "TOMBSTONE", pRow->VersNo.HighPart, pRow->VersNo.LowPart, pRow->fStatic, asctime(localtime(&(pRow->TimeStamp))));
  1949. }
  1950. fMatch = FALSE;
  1951. ChkAdd(
  1952. pRow,
  1953. pFile,
  1954. AddFilter,
  1955. &fMatch
  1956. );
  1957. if (pFile == NULL)
  1958. {
  1959. printf("-----------------------\n");
  1960. }
  1961. else
  1962. {
  1963. fprintf(pFile, "-----------------------\n");
  1964. }
  1965. }
  1966. pRow++;
  1967. } // end of for (all recs)
  1968. //
  1969. // If a range was chosen and records
  1970. // retrieved are == the limit of 100
  1971. // and if the Max vers no retrieved
  1972. // is less than that specified, ask
  1973. // user if he wishes to continue
  1974. //
  1975. if (!fSetFilter)
  1976. {
  1977. printf("Got %d records in this round\n",
  1978. Recs.NoOfRecs);
  1979. }
  1980. if (
  1981. (Recs.NoOfRecs < Recs.TotalNoOfRecs)
  1982. &&
  1983. LiLtr((--pRow)->VersNo,
  1984. HighVersNo )
  1985. )
  1986. {
  1987. if ((pFile == NULL) && (!fSetFilter))
  1988. {
  1989. printf("There may be more. Get them ?? Input 1 for yes, 0 for no -- ");
  1990. scanf("%d", &Choice);
  1991. }
  1992. else
  1993. {
  1994. Choice = 1;
  1995. }
  1996. if (Choice == 1)
  1997. {
  1998. LowVersNo.QuadPart = LiAdd(pRow->VersNo,sTmpVersNo);
  1999. //Recs.NoOfRecs = 0;
  2000. continue;
  2001. }
  2002. }
  2003. printf("Total No Of records %s = (%d)\n",
  2004. fSetFilter ? "searched" : "retrieved", TotalCnt);
  2005. if (pFile != NULL)
  2006. {
  2007. fprintf(pFile, "TOTAL NO OF RECORDS %s = (%d) for WINS (%s)\n",
  2008. fSetFilter ? "searched" : "retrieved", TotalCnt, pTgtAdd);
  2009. fprintf(pFile, "++++++++++++++++++++++++++++++\n");
  2010. }
  2011. }
  2012. else
  2013. {
  2014. printf("No records of WINS (%s) in the range requested are there in the local db\n", pTgtAdd);
  2015. }
  2016. }
  2017. break;
  2018. } // while (TRUE)
  2019. if (Recs.pRow != NULL)
  2020. {
  2021. WinsFreeMem(Recs.pRow);
  2022. }
  2023. return(Status);
  2024. } // GetDbRecs
  2025. VOID
  2026. ChkAdd(
  2027. PWINSINTF_RECORD_ACTION_T pRow,
  2028. FILE *pFile,
  2029. DWORD Add,
  2030. LPBOOL pfMatch
  2031. )
  2032. {
  2033. struct in_addr InAddr;
  2034. if (
  2035. (pRow->TypOfRec_e == WINSINTF_E_UNIQUE)
  2036. ||
  2037. (pRow->TypOfRec_e == WINSINTF_E_NORM_GROUP)
  2038. )
  2039. {
  2040. InAddr.s_addr = htonl( pRow->Add.IPAdd);
  2041. if (*pfMatch)
  2042. {
  2043. if (Add == pRow->Add.IPAdd)
  2044. {
  2045. return;
  2046. }
  2047. else
  2048. {
  2049. *pfMatch = FALSE;
  2050. return;
  2051. }
  2052. }
  2053. if (pFile == NULL)
  2054. {
  2055. printf("IP Address is (%s)\n", inet_ntoa(InAddr) );
  2056. }
  2057. else
  2058. {
  2059. fprintf(pFile, "IP Address is (%s)\n",
  2060. inet_ntoa(InAddr)
  2061. );
  2062. }
  2063. }
  2064. else //spec. grp or multihomed
  2065. {
  2066. DWORD ind;
  2067. if (!*pfMatch)
  2068. {
  2069. if (pFile == NULL)
  2070. {
  2071. printf("No. Of Members (%d)\n\n", pRow->NoOfAdds/2);
  2072. }
  2073. else
  2074. {
  2075. fprintf(pFile, "No. Of Members (%d)\n\n", pRow->NoOfAdds/2);
  2076. }
  2077. }
  2078. for ( ind=0; ind < pRow->NoOfAdds ; /*no third expr*/ )
  2079. {
  2080. InAddr.s_addr = htonl( (pRow->pAdd + ind++)->IPAdd);
  2081. if (!*pfMatch)
  2082. {
  2083. if (pFile == NULL)
  2084. {
  2085. printf("Owner is (%s); ", inet_ntoa(InAddr) );
  2086. }
  2087. else
  2088. {
  2089. fprintf(pFile, "Owner is (%s); ",
  2090. inet_ntoa(InAddr) );
  2091. }
  2092. }
  2093. InAddr.s_addr = htonl(
  2094. (pRow->pAdd + ind++)->IPAdd);
  2095. if (!*pfMatch)
  2096. {
  2097. if (pFile == NULL)
  2098. {
  2099. printf("Node is (%s)\n", inet_ntoa(InAddr) );
  2100. }
  2101. else
  2102. {
  2103. fprintf(pFile, "Node is (%s)\n",
  2104. inet_ntoa(InAddr)
  2105. );
  2106. }
  2107. }
  2108. if (*pfMatch)
  2109. {
  2110. if (Add == (pRow->pAdd + ind - 1)->IPAdd)
  2111. {
  2112. return;
  2113. }
  2114. else
  2115. {
  2116. *pfMatch = FALSE;
  2117. return;
  2118. }
  2119. }
  2120. }
  2121. //
  2122. // If there were no members to compare with, then
  2123. // let us set *pfMatch to FALSE.
  2124. //
  2125. if (ind == 0)
  2126. {
  2127. if (*pfMatch)
  2128. {
  2129. *pfMatch = FALSE;
  2130. }
  2131. }
  2132. }
  2133. }
  2134. VOID
  2135. WantFile(
  2136. FILE **ppFile
  2137. )
  2138. {
  2139. DWORD Choice;
  2140. printf("Put records in wins.rec file (1 for yes, 0 for no) -- ");
  2141. scanf("%d", &Choice);
  2142. if (Choice != 1)
  2143. {
  2144. *ppFile = NULL;
  2145. }
  2146. else
  2147. {
  2148. *ppFile = fopen("wins.rec", "a");
  2149. if (*ppFile == NULL)
  2150. {
  2151. printf("Could not open file wins.rec for appending\n");
  2152. }
  2153. }
  2154. return;
  2155. }
  2156. DWORD
  2157. CreateFiles(
  2158. PWINSINTF_RECS_T pRecs,
  2159. PWINSINTF_ADD_T pWinsAdd,
  2160. FILE *pFileU,
  2161. FILE *pFileO
  2162. )
  2163. {
  2164. DWORD no;
  2165. PWINSINTF_RECORD_ACTION_T pRow;
  2166. DWORD i;
  2167. struct in_addr InAddr;
  2168. pRow = pRecs->pRow;
  2169. InAddr.s_addr = htonl(pWinsAdd->IPAdd);
  2170. fprintf(pFileU, "##UNIQUE records of WINS with address %s\n\n", inet_ntoa(InAddr));
  2171. fprintf(pFileO, "##NON-UNIQUE records of WINS with address %s\n", inet_ntoa(InAddr));
  2172. for(no = 0; no < pRecs->NoOfRecs; no++)
  2173. {
  2174. if (pRow->TypOfRec_e == WINSINTF_E_UNIQUE)
  2175. {
  2176. InAddr.s_addr = htonl(pRow->Add.IPAdd);
  2177. fprintf(pFileU, "%s\t", inet_ntoa(InAddr));
  2178. for (i=0; i<pRow->NameLen; i++)
  2179. {
  2180. fprintf(pFileU, "%c", *(pRow->pName + i));
  2181. }
  2182. fprintf(pFileU, "\n");
  2183. }
  2184. else
  2185. {
  2186. fprintf(pFileO, "%d\t", pRow->NameLen);
  2187. for (i=0; i<pRow->NameLen; i++)
  2188. {
  2189. fprintf(pFileO, "%c", (BYTE)(*(pRow->pName + i)));
  2190. }
  2191. fprintf(pFileO, "\t%d", pRow->TypOfRec_e);
  2192. if (pRow->TypOfRec_e == WINSINTF_E_NORM_GROUP)
  2193. {
  2194. InAddr.s_addr = htonl(pRow->Add.IPAdd);
  2195. fprintf(pFileO, "\t%s", inet_ntoa(InAddr));
  2196. }
  2197. else
  2198. {
  2199. fprintf(pFileO, "\t%d\t", pRow->NoOfAdds);
  2200. for (i=0; i<pRow->NoOfAdds; i)
  2201. {
  2202. InAddr.s_addr = htonl((pRow->pAdd +i++)->IPAdd);
  2203. fprintf(pFileO, "%s\t", inet_ntoa(InAddr));
  2204. InAddr.s_addr = htonl((pRow->pAdd + i++)->IPAdd);
  2205. fprintf(pFileO, "%s\t", inet_ntoa(InAddr));
  2206. }
  2207. }
  2208. fprintf(pFileO, "\n");
  2209. }
  2210. pRow++;
  2211. }
  2212. fprintf(pFileO, "\n\n\n");
  2213. return(WINSINTF_SUCCESS);
  2214. }
  2215. DWORD
  2216. InitFromFile(
  2217. VOID
  2218. )
  2219. {
  2220. FILE *pFileO;
  2221. WINSINTF_RECORD_ACTION_T RecAction;
  2222. DWORD NoOfRecs = 0;
  2223. DWORD i;
  2224. DWORD RetStat = WINSINTF_SUCCESS;
  2225. BYTE Add[20];
  2226. pFileO = fopen(FILEO, "r");
  2227. if (pFileO == NULL)
  2228. {
  2229. printf("Could not open file %s\n", FILEO);
  2230. return(WINSINTF_FAILURE);
  2231. }
  2232. while(TRUE)
  2233. {
  2234. printf("Record no %d\n", ++NoOfRecs);
  2235. if (fscanf(pFileO, "%d\t", &RecAction.NameLen) == EOF)
  2236. {
  2237. printf("ERROR reading NameLen\n");
  2238. break;
  2239. }
  2240. RecAction.pName = WinsAllocMem(RecAction.NameLen);
  2241. for(i=0;i<RecAction.NameLen;i++)
  2242. {
  2243. if (fscanf(pFileO, "%c", (RecAction.pName + i)) == EOF)
  2244. {
  2245. printf("ERROR reading Name. i is %d", i);
  2246. break;
  2247. }
  2248. }
  2249. if (fscanf(pFileO, "\t%d", &RecAction.TypOfRec_e) == EOF)
  2250. {
  2251. printf("ERROR reading TypeOfRec\n");
  2252. break;
  2253. }
  2254. if (RecAction.TypOfRec_e == WINSINTF_E_NORM_GROUP)
  2255. {
  2256. fscanf(pFileO, "%s", Add);
  2257. RecAction.Add.IPAdd = 0xFFFFFFFF;
  2258. RecAction.Add.Type = 0;
  2259. RecAction.Add.Len = 4;
  2260. RecAction.NoOfAdds = 0;
  2261. }
  2262. else
  2263. {
  2264. if (fscanf(pFileO, "\t%d\t", &RecAction.NoOfAdds) == EOF)
  2265. {
  2266. printf("ERROR reading NoOfAdds");
  2267. break;
  2268. }
  2269. for (i=0; i<RecAction.NoOfAdds;i++)
  2270. {
  2271. BYTE Add[20];
  2272. RecAction.pAdd = WinsAllocMem(
  2273. sizeof(WINSINTF_ADD_T) * RecAction.NoOfAdds);
  2274. for(i = 0; i < RecAction.NoOfAdds; i++)
  2275. {
  2276. if (fscanf(pFileO, "%s\t", Add) == EOF)
  2277. {
  2278. printf("ERROR reading Address");
  2279. break;
  2280. }
  2281. (RecAction.pAdd + i)->IPAdd = ntohl(inet_addr(Add));
  2282. (RecAction.pAdd + i)->Type = 0;
  2283. (RecAction.pAdd + i)->Len = 4;
  2284. }
  2285. }
  2286. }
  2287. fscanf(pFileO, "\n");
  2288. } // end of while
  2289. printf("Name = (%s), TypeOfRec (%s)\n", RecAction.pName, RecAction.TypOfRec_e == WINSINTF_E_NORM_GROUP ? "NORMAL GROUP" : (RecAction.TypOfRec_e ==
  2290. WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED");
  2291. if (RecAction.TypOfRec_e == WINSINTF_E_NORM_GROUP)
  2292. {
  2293. printf("NORM GRP: Address is %x\n", RecAction.Add.IPAdd);
  2294. }
  2295. else
  2296. {
  2297. for (i=0; i < RecAction.NoOfAdds; i++)
  2298. {
  2299. printf("%d -- Owner (%d) is (%p)\t", i,
  2300. (RecAction.pAdd + i)->IPAdd);
  2301. printf("%d -- Address (%d) is (%p)\n", ++i,
  2302. (RecAction.pAdd + i)->IPAdd);
  2303. }
  2304. }
  2305. return(RetStat);
  2306. }
  2307. DWORD
  2308. GetDbRecsByName(
  2309. PWINSINTF_ADD_T pWinsAdd,
  2310. DWORD Location,
  2311. LPBYTE pName,
  2312. DWORD NameLen,
  2313. DWORD NoOfRecsDesired,
  2314. DWORD TypeOfRecs,
  2315. BOOL fFilter,
  2316. DWORD AddFilter
  2317. )
  2318. {
  2319. DWORD Status;
  2320. WINSINTF_RECS_T Recs;
  2321. DWORD TotalCnt = 0;
  2322. Recs.pRow = NULL;
  2323. Status = WinsGetDbRecsByName(BindHdl, pWinsAdd, Location, pName, NameLen,
  2324. NoOfRecsDesired, TypeOfRecs, &Recs);
  2325. printf("Total number of records are (%d)\n", Recs.TotalNoOfRecs);
  2326. if (Status == WINSINTF_SUCCESS)
  2327. {
  2328. if (Recs.NoOfRecs > 0)
  2329. {
  2330. DWORD i;
  2331. PWINSINTF_RECORD_ACTION_T pRow = Recs.pRow;
  2332. TotalCnt += Recs.NoOfRecs;
  2333. printf("Retrieved %d records\n", Recs.NoOfRecs);
  2334. for (i=0; i<Recs.NoOfRecs; i++)
  2335. {
  2336. printf("-----------------------\n");
  2337. printf("Name is (%s). 16th char is (%x)\nNameLen is (%d)\nType is (%s)\nState is (%s)\nVersion No is (%x %x)\nStatic flag is (%d)\nTimestamp is (%.19s)\n", pRow->pName, *(pRow->pName+15),
  2338. pRow->NameLen, pRow->TypOfRec_e == WINSINTF_E_UNIQUE ? "UNIQUE" : (pRow->TypOfRec_e == WINSINTF_E_NORM_GROUP) ? "NORMAL GROUP" : (pRow->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED",
  2339. pRow->State_e == WINSINTF_E_ACTIVE ? "ACTIVE" : (pRow->State_e == WINSINTF_E_RELEASED) ? "RELEASED" : "TOMBSTONE", pRow->VersNo.HighPart, pRow->VersNo.LowPart, pRow->fStatic, asctime(localtime(&(pRow->TimeStamp))));
  2340. ChkAdd(
  2341. pRow,
  2342. NULL,
  2343. AddFilter,
  2344. &fFilter
  2345. );
  2346. printf("-----------------------\n");
  2347. pRow++;
  2348. } // end of for (all recs)
  2349. }
  2350. else
  2351. {
  2352. printf("No records were retrieved\n");
  2353. }
  2354. }
  2355. if (Recs.pRow != NULL)
  2356. {
  2357. WinsFreeMem(Recs.pRow);
  2358. }
  2359. return(Status);
  2360. }
  2361. VOID
  2362. Usage(
  2363. VOID
  2364. )
  2365. {
  2366. CMD_E i;
  2367. DWORD LastEntry = (fEnhMode ? LAST_ENTRY : LAST_PSS_ENTRY);
  2368. printf("winscl {T or N} {CMD}\n");
  2369. printf("where\nT -- TCP/IP\nN -- Named Pipe\n");
  2370. printf("\n\nCMD is one of the following\n");
  2371. for (i = 0; i < (CMD_E)LastEntry; i++)
  2372. {
  2373. if (CommandSwitchList[i].SwitchName != NULL)
  2374. {
  2375. printf("%s or %s\n", CommandSwitchList[i].SwitchName,
  2376. CommandSwitchList[i].ShortName);
  2377. }
  2378. }
  2379. return;
  2380. }
  2381. VOID
  2382. GetCmdCode(
  2383. LPBYTE pCmd,
  2384. PCMD_E pCmd_e
  2385. )
  2386. {
  2387. CMD_E Cmd_e;
  2388. *pCmd_e = INVALID_VALUE;
  2389. for (Cmd_e = 0; Cmd_e < (fEnhMode ? LAST_ENTRY : LAST_PSS_ENTRY); Cmd_e++)
  2390. {
  2391. if (CommandSwitchList[Cmd_e].ShortName != NULL)
  2392. {
  2393. if (!_strcmpi(CommandSwitchList[Cmd_e].ShortName, pCmd)
  2394. ||
  2395. !_strcmpi(CommandSwitchList[Cmd_e].SwitchName, pCmd)
  2396. )
  2397. {
  2398. *pCmd_e = CommandSwitchList[Cmd_e].SwitchValue;
  2399. return;
  2400. }
  2401. }
  2402. }
  2403. return;
  2404. }
  2405. #define PRADEEPB_PTM "157.55.80.183"
  2406. #define PRADEEPB_486 "157.55.80.182"
  2407. //#define RHINO1 PRADEEPB_PTM
  2408. //#define RHINO2 PRADEEPB_486
  2409. #define RHINO1 "157.55.80.151"
  2410. #define RHINO2 "157.55.80.152"
  2411. #define RED03NS "157.54.16.159"
  2412. VOID
  2413. sync(VOID)
  2414. {
  2415. handle_t BindHdl;
  2416. WINSINTF_BIND_DATA_T BindData;
  2417. PNAME_INFO pNameInfo, pSrvInfo;
  2418. WINS_INFO WinsInfo;
  2419. DWORD i, n, t, s;
  2420. LPBYTE pWinsAdd = RHINO1;
  2421. DWORD Status;
  2422. PWINSINTF_RECORD_ACTION_T pSvRecAction = NULL;
  2423. WINSINTF_RECORD_ACTION_T RecAction;
  2424. PWINSINTF_RECORD_ACTION_T pRecAction;
  2425. PWINSINTF_RECORD_ACTION_T pOutRecAction;
  2426. BOOL fAtLeastOneFound;
  2427. DWORD NoOfNames, NoOfSrvNames;
  2428. if(!ReadNameFile( &pNameInfo, &NoOfNames, "nmfl.txt"))
  2429. {
  2430. return;
  2431. }
  2432. if(!ReadNameFile( &pSrvInfo, &NoOfSrvNames, "winss.txt"))
  2433. {
  2434. return;
  2435. }
  2436. WinsInfo.NoOfOwners = NoOfSrvNames;
  2437. for (i = 0; i < NoOfSrvNames; i++)
  2438. {
  2439. strcpy(WinsInfo.Maps[i].asIpAdd, pSrvInfo->Name);
  2440. WinsInfo.Maps[i].fCommFail = FALSE;
  2441. WinsInfo.Maps[i].fNameNotFound = FALSE;
  2442. fprintf(spDbgFile, "WINS server (%d) is (%s)\n", i, WinsInfo.Maps[i].asIpAdd);
  2443. pSrvInfo++;
  2444. }
  2445. i = 0;
  2446. #if 0
  2447. do
  2448. {
  2449. if (!BindToWins(pWinsAdd, &BindData, &BindHdl))
  2450. {
  2451. fprintf(spDbgFile, "Unable to bind to %s\n", pWinsAdd);
  2452. return;
  2453. }
  2454. fprintf(spDbgFile, "Connected to WINS = (%s)\n", pWinsAdd);
  2455. //
  2456. // Get WINS server info
  2457. //
  2458. WinsInfo.NoOfOwners = 0;
  2459. i++;
  2460. if (GetWinsInfo(&WinsInfo) != WINSINTF_SUCCESS)
  2461. {
  2462. fprintf(spDbgFile, "Comm. Failure with %s\n", pWinsAdd);
  2463. if (i < 2)
  2464. {
  2465. pWinsAdd = RHINO2;
  2466. }
  2467. }
  2468. else
  2469. {
  2470. i = 2;
  2471. }
  2472. WinsUnbind(&BindData, BindHdl);
  2473. } while (i < 2);
  2474. #endif
  2475. //
  2476. // Loop over all names read in. Query the name from all WINSs that
  2477. // we have in our list of WINS owners that we got from RHINO1
  2478. //
  2479. for (i = 0; (pNameInfo->Name[0] != 0) && (i < NoOfNames); i++, pNameInfo++)
  2480. {
  2481. DWORD LChar;
  2482. CHAR Name[50];
  2483. BOOL fStored;
  2484. for (s=0; s<2;s++)
  2485. {
  2486. LChar = (s==0) ? 0x20 : 0x0;
  2487. RecAction.Cmd_e = WINSINTF_E_QUERY;
  2488. strcpy(Name, pNameInfo->Name);
  2489. GetFullName(Name, LChar, &RecAction);
  2490. pRecAction = &RecAction;
  2491. //
  2492. // For a name, loop over all WINS owners
  2493. //
  2494. fStored = FALSE;
  2495. fAtLeastOneFound = FALSE;
  2496. for (n = 0; n < NoOfSrvNames; n++)
  2497. {
  2498. DWORD OwnIdOfName;
  2499. #if 0
  2500. if (
  2501. !_strcmpi(WinsInfo.Maps[n].asIpAdd, RHINO1) ||
  2502. !_strcmpi(WinsInfo.Maps[n].asIpAdd, RHINO2) ||
  2503. !_strcmpi(WinsInfo.Maps[n].asIpAdd, RED03NS)
  2504. )
  2505. #endif
  2506. fprintf(spDbgFile, "BINDING TO WINS = (%s)\n", WinsInfo.Maps[n].asIpAdd);
  2507. {
  2508. //
  2509. // Bind to the WINS
  2510. //
  2511. if (!BindToWins(WinsInfo.Maps[n].asIpAdd, &BindData, &BindHdl))
  2512. {
  2513. fprintf(spDbgFile, "FAILED BINDING\n");
  2514. continue; // go on to the next one
  2515. }
  2516. //
  2517. // Query Wins for the name
  2518. //
  2519. pRecAction = &RecAction;
  2520. if ((Status = QueryWins(Name, pRecAction, &pOutRecAction)) == NAME_NOT_FOUND)
  2521. {
  2522. fprintf(spDbgFile2, "DID NOT FIND NAME = (%s[%x]) in Wins = (%s) db\n",
  2523. Name, Name[15], WinsInfo.Maps[n].asIpAdd);
  2524. WinsInfo.Maps[n].fNameNotFound = TRUE;
  2525. WinsInfo.Maps[n].fCommFail = FALSE;
  2526. }
  2527. else
  2528. {
  2529. if ( Status == SUCCESS)
  2530. {
  2531. fprintf(spDbgFile, "FOUND name = (%s[%x]) in Wins = (%s) db\n",
  2532. Name, Name[15], WinsInfo.Maps[n].asIpAdd);
  2533. fAtLeastOneFound = TRUE;
  2534. if (!fStored)
  2535. {
  2536. fStored = TRUE;
  2537. pSvRecAction = pOutRecAction;
  2538. }
  2539. else
  2540. {
  2541. WinsFreeMem(pOutRecAction);
  2542. }
  2543. WinsInfo.Maps[n].fCommFail = FALSE;
  2544. WinsInfo.Maps[n].fNameNotFound = FALSE;
  2545. }
  2546. else
  2547. {
  2548. WinsInfo.Maps[n].fCommFail = TRUE;
  2549. }
  2550. }
  2551. WinsUnbind(&BindData, BindHdl);
  2552. }
  2553. #if 0
  2554. else
  2555. {
  2556. WinsInfo.Maps[n].fCommFail = TRUE;
  2557. }
  2558. #endif
  2559. }
  2560. //#if 0
  2561. for (t = 0; t < WinsInfo.NoOfOwners && fAtLeastOneFound; t++)
  2562. {
  2563. if (!WinsInfo.Maps[t].fCommFail && WinsInfo.Maps[t].fNameNotFound)
  2564. {
  2565. if(BindToWins(WinsInfo.Maps[t].asIpAdd, &BindData, &BindHdl))
  2566. {
  2567. StoreName(pSvRecAction, RecAction.pName);
  2568. WinsUnbind(&BindData, BindHdl);
  2569. }
  2570. }
  2571. else
  2572. {
  2573. continue;
  2574. }
  2575. }
  2576. //#endif
  2577. if (RecAction.pName != NULL)
  2578. {
  2579. WinsFreeMem(RecAction.pName);
  2580. RecAction.pName = NULL;
  2581. }
  2582. if (pSvRecAction)
  2583. {
  2584. WinsFreeMem(pSvRecAction);
  2585. pSvRecAction = NULL;
  2586. }
  2587. }
  2588. }
  2589. fclose(spDbgFile);
  2590. fclose(spDbgFile2);
  2591. return;
  2592. }
  2593. VOID
  2594. StoreName(
  2595. PWINSINTF_RECORD_ACTION_T pRecAction,
  2596. LPBYTE pName
  2597. )
  2598. {
  2599. DWORD Status;
  2600. DWORD i;
  2601. (void)strncpy(pRecAction->pName, pName, 16);
  2602. pRecAction->NameLen = 16;
  2603. pRecAction->Cmd_e = WINSINTF_E_INSERT;
  2604. if ((pRecAction->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ||
  2605. (pRecAction->TypOfRec_e == WINSINTF_E_MULTIHOMED))
  2606. {
  2607. for (i = 0; i < pRecAction->NoOfAdds; i++)
  2608. {
  2609. *(pRecAction->pAdd + i) = *(pRecAction->pAdd + i + 1);
  2610. i++;
  2611. }
  2612. pRecAction->NoOfAdds = pRecAction->NoOfAdds/2;
  2613. }
  2614. fprintf(spDbgFile2, "StoreName:STORING name %s[%x]\n", pRecAction->pName, pRecAction->pName[15]);
  2615. Status = WinsRecordAction(BindHdl, &pRecAction);
  2616. fprintf(spDbgFile2, "StoreName:Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  2617. WinsFreeMem(pRecAction);
  2618. return;
  2619. }
  2620. DWORD
  2621. QueryWins (
  2622. LPBYTE pName,
  2623. PWINSINTF_RECORD_ACTION_T pRecAction,
  2624. PWINSINTF_RECORD_ACTION_T *ppRecAct
  2625. )
  2626. {
  2627. DWORD RetStat;
  2628. struct in_addr InAddr;
  2629. DWORD i;
  2630. DWORD Status;
  2631. Status = WinsRecordAction(BindHdl, &pRecAction);
  2632. fprintf(spDbgFile, "Status returned is (%s - %d)\n", Status == 0 ? "SUCCESS" : "FAILURE", Status);
  2633. if (Status == WINSINTF_SUCCESS)
  2634. {
  2635. *ppRecAct = pRecAction;
  2636. fprintf(spDbgFile, "Name=(%s)\nNodeType=(%d)\nState=(%s)\nTimeStamp=(%.19s)\nOwnerId=(%d)\nType Of Rec=(%s)\nVersion No (%x %x)\nRecord is (%s)\n",
  2637. pRecAction->pName,
  2638. pRecAction->NodeTyp,
  2639. pRecAction->State_e == WINSINTF_E_ACTIVE ? "ACTIVE" : (pRecAction->State_e == WINSINTF_E_RELEASED) ? "RELEASED" : "TOMBSTONE",
  2640. asctime(localtime(&(pRecAction->TimeStamp))),
  2641. pRecAction->OwnerId,
  2642. (pRecAction->TypOfRec_e == WINSINTF_E_UNIQUE) ? "UNIQUE" : (pRecAction->TypOfRec_e == WINSINTF_E_NORM_GROUP) ? "NORMAL GROUP" :
  2643. (pRecAction->TypOfRec_e == WINSINTF_E_SPEC_GROUP) ? "SPECIAL GROUP" : "MULTIHOMED",
  2644. pRecAction->VersNo.HighPart,
  2645. pRecAction->VersNo.LowPart,
  2646. pRecAction->fStatic ? "STATIC" : "DYNAMIC"
  2647. );
  2648. if (
  2649. (pRecAction->TypOfRec_e == WINSINTF_E_UNIQUE)
  2650. ||
  2651. (pRecAction->TypOfRec_e == WINSINTF_E_NORM_GROUP)
  2652. )
  2653. {
  2654. InAddr.s_addr = htonl(pRecAction->Add.IPAdd);
  2655. fprintf(spDbgFile, "Address is (%s)\n", inet_ntoa(InAddr));
  2656. }
  2657. else
  2658. {
  2659. for (i=0; i<pRecAction->NoOfAdds; )
  2660. {
  2661. InAddr.s_addr = htonl((pRecAction->pAdd +i++)->IPAdd);
  2662. fprintf(spDbgFile, "Owner is (%s); ", inet_ntoa(InAddr));
  2663. InAddr.s_addr = htonl((pRecAction->pAdd + i++)->IPAdd);
  2664. fprintf(spDbgFile, "Member is (%s)\n", inet_ntoa(InAddr));
  2665. }
  2666. }
  2667. RetStat = SUCCESS;
  2668. }
  2669. else
  2670. {
  2671. if (Status == ERROR_REC_NON_EXISTENT)
  2672. {
  2673. fprintf(spDbgFile, "No such name in the db\n");
  2674. RetStat = NAME_NOT_FOUND;
  2675. }
  2676. else
  2677. {
  2678. fprintf(spDbgFile, "Status is (%x)\n", Status);
  2679. RetStat = FAILURE;
  2680. }
  2681. }
  2682. return RetStat;
  2683. }
  2684. handle_t
  2685. WinsABind(
  2686. PWINSINTF_BIND_DATA_T pBindData
  2687. );
  2688. BOOL
  2689. BindToWins(
  2690. LPBYTE asIpAdd,
  2691. PWINSINTF_BIND_DATA_T pBindData,
  2692. handle_t *pBindHdl
  2693. )
  2694. {
  2695. pBindData->pServerAdd = asIpAdd;
  2696. pBindData->fTcpIp = TRUE;
  2697. *pBindHdl = WinsABind(pBindData);
  2698. if (pBindHdl == NULL)
  2699. {
  2700. fprintf(spDbgFile, "Unable to bind to %s \n", asIpAdd);
  2701. return (FALSE);
  2702. }
  2703. return(TRUE);
  2704. }
  2705. BOOL
  2706. ReadNameFile(
  2707. PNAME_INFO *ppFileInfo,
  2708. LPDWORD pNoOfNames,
  2709. LPBYTE pNameOfFile
  2710. )
  2711. {
  2712. FILE *pFile;
  2713. struct _stat Stat;
  2714. PNAME_INFO pFileInfo;
  2715. DWORD SizeAlloc;
  2716. *pNoOfNames = 0;
  2717. if((pFile = fopen(pNameOfFile, "r")) == NULL)
  2718. {
  2719. return FALSE;
  2720. }
  2721. if (_stat(pNameOfFile, &Stat) == -1)
  2722. {
  2723. return FALSE;
  2724. }
  2725. SizeAlloc = Stat.st_size + Stat.st_size/15 * sizeof(NAME_INFO);
  2726. if (!(pFileInfo = malloc(SizeAlloc)))
  2727. {
  2728. return FALSE;
  2729. }
  2730. else
  2731. {
  2732. fprintf(spDbgFile, "Allocated %d bytes\n", SizeAlloc);
  2733. }
  2734. *ppFileInfo = pFileInfo;
  2735. memset(pFileInfo, 0, SizeAlloc);
  2736. //
  2737. // Read in names
  2738. //
  2739. while(fscanf(pFile, "%s\n", pFileInfo->Name) != EOF)
  2740. {
  2741. fprintf(spDbgFile, "Name is %s\n", pFileInfo->Name);
  2742. (*pNoOfNames)++;
  2743. pFileInfo++;
  2744. }
  2745. return(TRUE);
  2746. }
  2747. STATUS
  2748. GetWinsInfo(
  2749. PWINS_INFO pWinsInfo
  2750. )
  2751. {
  2752. DWORD Status;
  2753. WINSINTF_RESULTS_NEW_T Results;
  2754. PWINSINTF_RESULTS_NEW_T pResultsN = &Results;
  2755. DWORD NoOfOwners;
  2756. struct in_addr InAddr;
  2757. DWORD i, n;
  2758. PWINSINTF_ADD_VERS_MAP_T pAddVersMaps;
  2759. Results.WinsStat.NoOfPnrs = 0;
  2760. Results.WinsStat.pRplPnrs = NULL;
  2761. Results.pAddVersMaps = NULL;
  2762. Status = WinsStatusNew(BindHdl, WINSINTF_E_CONFIG_ALL_MAPS, pResultsN);
  2763. if (Status == WINSINTF_SUCCESS)
  2764. {
  2765. pAddVersMaps = pResultsN->pAddVersMaps;
  2766. if (pResultsN->NoOfOwners != 0)
  2767. {
  2768. for (n=0, i= 0; i < pResultsN->NoOfOwners; i++, pAddVersMaps++)
  2769. {
  2770. InAddr.s_addr = htonl(
  2771. pAddVersMaps->Add.IPAdd);
  2772. if (
  2773. (pAddVersMaps->VersNo.HighPart
  2774. == MAXLONG)
  2775. &&
  2776. (pAddVersMaps->VersNo.LowPart ==
  2777. MAXULONG)
  2778. )
  2779. {
  2780. continue;
  2781. }
  2782. if (pAddVersMaps->VersNo.QuadPart == 0)
  2783. {
  2784. continue;
  2785. }
  2786. fprintf(spDbgFile,"%d\t\t%s\t\t", i, inet_ntoa(InAddr));
  2787. fprintf(spDbgFile, "%lu %lu\n",
  2788. pAddVersMaps->VersNo.HighPart,
  2789. pAddVersMaps->VersNo.LowPart
  2790. );
  2791. pWinsInfo->Maps[n].OwnId = i;
  2792. strcpy(pWinsInfo->Maps[n].asIpAdd,inet_ntoa(InAddr));
  2793. pWinsInfo->Maps[n].VersNo = pAddVersMaps->VersNo;
  2794. n++;
  2795. }
  2796. pWinsInfo->NoOfOwners = n; //pResultsN->NoOfOwners;
  2797. WinsFreeMem(pResultsN->pAddVersMaps);
  2798. }
  2799. else
  2800. {
  2801. fprintf(spDbgFile, "The Db is empty\n");
  2802. }
  2803. }
  2804. else
  2805. {
  2806. pWinsInfo->NoOfOwners = 0;
  2807. }
  2808. return Status;
  2809. }
  2810. VOID
  2811. GetFullName(
  2812. LPBYTE pName,
  2813. DWORD SChar,
  2814. PWINSINTF_RECORD_ACTION_T pRecAction
  2815. )
  2816. {
  2817. size_t Len;
  2818. pRecAction->pAdd = NULL;
  2819. pRecAction->NoOfAdds = 0;
  2820. if ((Len = strlen(pName)) < 16)
  2821. {
  2822. memset(pName + Len, (int)' ',16-Len);
  2823. *(pName + 15) = (BYTE)(SChar & 0xff);
  2824. *(pName + 16) = (CHAR)NULL;
  2825. Len = 16;
  2826. }
  2827. else
  2828. {
  2829. *(pName + Len) = (CHAR)NULL;
  2830. }
  2831. pRecAction->pName = WinsAllocMem(Len);
  2832. (void)memcpy(pRecAction->pName, pName, Len);
  2833. pRecAction->NameLen = Len;
  2834. return;
  2835. }