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.

892 lines
23 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: generic testing engine
  5. //================================================================================
  6. //===============================
  7. // headers
  8. //===============================
  9. #include <hdrmacro.h>
  10. #include <store.h>
  11. #include <dhcpmsg.h>
  12. #include <wchar.h>
  13. #include <dhcpbas.h>
  14. #include <mm\opt.h>
  15. #include <mm\optl.h>
  16. #include <mm\optdefl.h>
  17. #include <mm\optclass.h>
  18. #include <mm\classdefl.h>
  19. #include <mm\bitmask.h>
  20. #include <mm\reserve.h>
  21. #include <mm\range.h>
  22. #include <mm\subnet.h>
  23. #include <mm\sscope.h>
  24. #include <mm\oclassdl.h>
  25. #include <mm\server.h>
  26. #include <mm\address.h>
  27. #include <mm\server2.h>
  28. #include <mm\memfree.h>
  29. #include <mmreg\regutil.h>
  30. #include <mmreg\regread.h>
  31. #include <mmreg\regsave.h>
  32. #include <dhcpread.h>
  33. #include <dhcpapi.h>
  34. #include <rpcapi1.h>
  35. #include <rpcapi2.h>
  36. //BeginExport(typedefs)
  37. // supported data types are listed. any new datatypes should be added here.
  38. typedef enum /* anonymous */ {
  39. Char,
  40. wChar,
  41. Word,
  42. DWord,
  43. String,
  44. wString,
  45. IpAddress,
  46. xBytes,
  47. Invalid
  48. } NJIN_TYPES, *LPNJIN_TYPES;
  49. typedef struct /* anonymous */ {
  50. union /* anonymous */ {
  51. CHAR *Char;
  52. WCHAR *wChar;
  53. WORD *Word;
  54. DWORD *DWord;
  55. LPSTR String;
  56. LPWSTR wString;
  57. DWORD *IpAddress;
  58. struct /* anonymous */ {
  59. DWORD *xBytesLen;
  60. LPBYTE xBytesBuf;
  61. };
  62. };
  63. } NJIN_DATA, *LPNJIN_DATA;
  64. typedef struct /* anonymous */ {
  65. LPWSTR VarName;
  66. NJIN_TYPES VarType;
  67. NJIN_DATA VarData;
  68. VOID (*VarFunc)(LPWSTR VarName);
  69. BOOL ReadOnly;
  70. } NJIN_VAR, *LPNJIN_VAR;
  71. typedef struct /* anonymous */ {
  72. WCHAR cComment;
  73. WCHAR cEquals;
  74. WCHAR cReturn;
  75. WCHAR cEndOfLine;
  76. WCHAR cCharFmtActual;
  77. WCHAR cCharFmtNum;
  78. BOOL fEcho;
  79. BOOL fVerbose;
  80. } NJIN_ENV, *LPNJIN_ENV;
  81. //EndExport(typedefs)
  82. #define verbose if( Env->fVerbose) printf
  83. #define echo if( Env->fEcho) printf
  84. DWORD
  85. ConvertToIntegral(
  86. IN LPWSTR Str
  87. )
  88. {
  89. return _wtol(Str);
  90. }
  91. DWORD
  92. ConvertToAddress(
  93. IN LPWSTR Str
  94. )
  95. {
  96. CHAR Buf[1000];
  97. LPSTR s;
  98. s = Buf;
  99. while(*s ++ = (CHAR) *Str++ )
  100. /* skip */;
  101. return inet_addr(Buf);
  102. }
  103. DWORD
  104. CloneWString(
  105. IN LPWSTR Buf,
  106. IN LPWSTR Dest
  107. )
  108. {
  109. wcscpy(Dest, Buf);
  110. return ERROR_SUCCESS;
  111. }
  112. DWORD
  113. CloneString(
  114. IN LPWSTR Str,
  115. IN LPSTR s
  116. )
  117. {
  118. while(*s ++ = (CHAR) *Str ++ )
  119. /* skip */;
  120. return ERROR_SUCCESS;
  121. }
  122. BYTE
  123. Hex(
  124. IN WCHAR C
  125. )
  126. {
  127. if( C >= L'0' && C <= L'9' ) return C - L'0';
  128. if( C >= L'A' && C <= L'F' ) return C - L'A' + 10;
  129. if( C >= L'a' && C <= L'f' ) return C - L'a' + 10;
  130. return 0x55;
  131. }
  132. DWORD
  133. ConvertToHexBytes(
  134. IN LPWSTR Str,
  135. IN OUT LPBYTE Buf,
  136. IN OUT LPDWORD BufLen
  137. )
  138. {
  139. BYTE ch, ch2;
  140. *BufLen = 0;
  141. while( (ch = Hex(*Str++)) <= 0xF) {
  142. ch2 = Hex(*Str++);
  143. if( ch2 > 0xF ) {
  144. printf("illegal character found, ignored\n");
  145. ch2 = 0;
  146. }
  147. Buf[(*BufLen)++] = (ch <<4) | ch2;
  148. }
  149. return ERROR_SUCCESS;
  150. }
  151. DWORD
  152. ConvertDataType(
  153. IN LPNJIN_ENV Env,
  154. IN LPWSTR Buf,
  155. IN DWORD VarType,
  156. IN NJIN_DATA *VarData
  157. )
  158. {
  159. switch(VarType) {
  160. case Char:
  161. if( Env->cCharFmtActual == Buf[0] ) {
  162. *VarData->Char = (CHAR) Buf[1];
  163. } else if( Env->cCharFmtNum == Buf[0] ) {
  164. *VarData->Char = (CHAR) ConvertToIntegral(&Buf[1]);
  165. } else return ERROR_INVALID_DATA;
  166. return ERROR_SUCCESS;
  167. case wChar:
  168. if( Env->cCharFmtActual == Buf[0] ) {
  169. *VarData->wChar = Buf[1];
  170. } else if( Env->cCharFmtNum == Buf[0] ) {
  171. *VarData->wChar = (WCHAR) ConvertToIntegral(&Buf[1]);
  172. } else return ERROR_INVALID_DATA;
  173. return ERROR_SUCCESS;
  174. case Word:
  175. *VarData->Word = (WORD) ConvertToIntegral(Buf);
  176. return ERROR_SUCCESS;
  177. case DWord:
  178. *VarData->DWord = ConvertToIntegral(Buf);
  179. return ERROR_SUCCESS;
  180. case wString:
  181. return CloneWString(Buf, VarData->wString);
  182. case String:
  183. return CloneString(Buf, VarData->String);
  184. case IpAddress:
  185. *VarData->IpAddress = ConvertToAddress(Buf);
  186. return ERROR_SUCCESS;
  187. case xBytes:
  188. return ConvertToHexBytes(Buf, VarData->xBytesBuf, VarData->xBytesLen);
  189. default:
  190. verbose("unknown variable type\n");
  191. return ERROR_INVALID_DATA;
  192. }
  193. }
  194. //BeginExport(function)
  195. DWORD
  196. NjinExecuteLineA(
  197. IN LPNJIN_ENV Env,
  198. IN OUT LPNJIN_VAR Vars,
  199. IN DWORD nVars,
  200. IN LPWSTR Cmd
  201. ) //EndExport(function)
  202. {
  203. CHAR Ch, LastCh;
  204. DWORD i, Result;
  205. LPWSTR Var;
  206. LPWSTR Value;
  207. Var = NULL; Value = NULL;
  208. for( i = 0; Cmd[i] != L'\0' ; i ++ ) {
  209. if( Env->cEquals == Cmd[i] ) break;
  210. }
  211. if( Cmd[i] ) {
  212. Cmd[i] = L'\0';
  213. Var = Cmd;
  214. Value = &Cmd[i+1];
  215. } else {
  216. verbose("No parameter passed\n");
  217. return ERROR_INVALID_DATA;
  218. }
  219. for( i = 0; i < nVars; i ++ ) {
  220. if( !Vars[i].ReadOnly && 0 == wcscmp(Vars[i].VarName, Var) )
  221. break;
  222. }
  223. if( i >= nVars ) {
  224. verbose("No such variable or operation\n");
  225. return ERROR_FILE_NOT_FOUND;
  226. }
  227. Result = ConvertDataType(Env, Value, Vars[i].VarType, &Vars[i].VarData);
  228. if( ERROR_SUCCESS != Result ) {
  229. verbose("ConvertDataType: 0x%lx (%ld)\n", Result, Result );
  230. return Result;
  231. }
  232. if( Vars[i].VarFunc ) Vars[i].VarFunc(Vars[i].VarName );
  233. return ERROR_SUCCESS;
  234. }
  235. //BeginExport(function)
  236. DWORD
  237. NjinExecute(
  238. IN LPNJIN_ENV Env,
  239. IN OUT LPNJIN_VAR Vars,
  240. IN DWORD nVars
  241. ) //EndExport(function)
  242. {
  243. char ch, lastch;
  244. WCHAR buffer[1000];
  245. unsigned int i;
  246. DWORD Result;
  247. verbose("NjinExecute called\n");
  248. i = 0; lastch = (CHAR)Env->cEndOfLine;
  249. while ((ch = getchar()) != EOF ) {
  250. if( Env->cReturn == ch ) ch = (CHAR)Env->cEndOfLine;
  251. if( Env->cEndOfLine == lastch && Env->cComment == ch ) {
  252. while((ch = getchar()) != EOF && Env->cEndOfLine != ch )
  253. ;
  254. lastch = ch;
  255. continue;
  256. }
  257. if( Env->cEndOfLine == ch ) {
  258. if( i ) {
  259. buffer[i] = L'\0';
  260. Result = NjinExecuteLineA(Env,Vars,nVars, buffer);
  261. if( ERROR_SUCCESS != Result ) {
  262. verbose("Error: %ld (0x%lx)\n", Result, Result);
  263. return Result;
  264. }
  265. }
  266. i = 0;
  267. } else {
  268. buffer[i++] = (WCHAR)ch;
  269. }
  270. lastch = ch;
  271. }
  272. return ERROR_SUCCESS;
  273. }
  274. //================================================================================
  275. // DHCP SNAPIN DS WORK -- helper routines
  276. //================================================================================
  277. STORE_HANDLE hStore1, hStore2, hStore3, hStore4;
  278. LPSTORE_HANDLE hRoot = NULL, hDhcpC = NULL, hObject = NULL, hDhcpRoot = NULL;
  279. WCHAR gDsServer[100], gObject[100], gName[100], gComment[100];
  280. WCHAR gClassName[100], gClassComment[100];
  281. WCHAR Dummy[100];
  282. WCHAR gOptName[100], gOptComment[100];
  283. WCHAR gServerName[256];
  284. DWORD gServerAddress, gServerState;
  285. DWORD gOptId, gOptType, gOptLen, gIsVendor;
  286. DWORD gDwordOptData;
  287. BYTE gOptVal[255], gClassData[255];
  288. DWORD gClassDataLen;
  289. VOID
  290. print_DHCP_OPTION_DATA(
  291. IN DWORD nTabs,
  292. IN LPDHCP_OPTION_DATA OptData
  293. )
  294. {
  295. DWORD i;
  296. i = nTabs;
  297. while(i--) putchar('\t');
  298. printf("NumElements=%ld, Type=%ld [0x%lx]\n",
  299. OptData->NumElements, OptData->Elements[0].OptionType, OptData->Elements[0].Element.DWordOption
  300. );
  301. }
  302. VOID
  303. print_DHCP_OPTION(
  304. IN DWORD nTabs,
  305. IN LPDHCP_OPTION Option
  306. )
  307. {
  308. DWORD i;
  309. i = nTabs;
  310. while(i--) putchar('\t');
  311. printf("Option [x%03x] %ws %ws Type= %ld\n",
  312. Option->OptionID, Option->OptionName, Option->OptionComment?Option->OptionComment:L"", Option->OptionType
  313. );
  314. print_DHCP_OPTION_DATA(nTabs+1, &Option->DefaultValue);
  315. }
  316. VOID
  317. print_DHCP_OPTION_ARRAY(
  318. IN DWORD nTabs,
  319. IN LPDHCP_OPTION_ARRAY OptArray
  320. )
  321. {
  322. DWORD i;
  323. i = nTabs;
  324. while(i--) putchar('\t');
  325. printf("NumElements= %ld\n", OptArray->NumElements);
  326. for( i = 0; i < OptArray->NumElements; i++ )
  327. print_DHCP_OPTION(nTabs+1, &OptArray->Options[i]);
  328. }
  329. VOID
  330. print_DHCP_OPTION_VALUE(
  331. IN DWORD nTabs,
  332. IN LPDHCP_OPTION_VALUE OptVal
  333. )
  334. {
  335. DWORD i;
  336. i = nTabs;
  337. while(i--) putchar('\t');
  338. printf("OptionId=%ld\n", OptVal->OptionID);
  339. print_DHCP_OPTION_DATA(nTabs+1, &OptVal->Value);
  340. }
  341. VOID
  342. print_DHCP_OPTION_VALUE_ARRAY(
  343. IN DWORD nTabs,
  344. IN LPDHCP_OPTION_VALUE_ARRAY OptValues
  345. )
  346. {
  347. DWORD i;
  348. i = nTabs;
  349. while(i--) putchar('\t');
  350. printf("NumElements=%ld\n", OptValues->NumElements);
  351. for( i = 0; i < OptValues->NumElements ; i ++ )
  352. print_DHCP_OPTION_VALUE(nTabs+1, &OptValues->Values[i]);
  353. }
  354. VOID
  355. print_DHCP_CLASS_INFO(
  356. IN DWORD nTabs,
  357. IN LPDHCP_CLASS_INFO ClassInfo
  358. )
  359. {
  360. DWORD i;
  361. i = nTabs;
  362. while(i--) putchar('\t');
  363. printf("ClassName= %ws ClassComment= %ws DataLength = %ld\n",
  364. ClassInfo->ClassName, ClassInfo->ClassComment, ClassInfo->ClassDataLength
  365. );
  366. }
  367. VOID
  368. print_DHCP_CLASS_INFO_ARRAY(
  369. IN DWORD nTabs,
  370. IN LPDHCP_CLASS_INFO_ARRAY ClassInfoArray
  371. )
  372. {
  373. DWORD i;
  374. i = nTabs;
  375. while(i--) putchar('\t');
  376. printf("NumElements=%ld\n", ClassInfoArray->NumElements);
  377. for( i = 0; i < ClassInfoArray->NumElements ; i ++ )
  378. print_DHCP_CLASS_INFO(nTabs+1, &ClassInfoArray->Classes[i]);
  379. }
  380. VOID
  381. print_DHCPDS_SERVER(
  382. IN DWORD nTabs,
  383. IN LPDHCPDS_SERVER Server
  384. )
  385. {
  386. DWORD i;
  387. i = nTabs;
  388. while(i--) putchar('\t');
  389. printf("Name=[%ws] State=%ld Address=%s Loc=[%ws] Type=%ld\n",
  390. Server->ServerName, Server->Flags, inet_ntoa(*(struct in_addr *)&Server->IpAddress),
  391. Server->DsLocation? Server->DsLocation: L"(NULL)",
  392. Server->DsLocType
  393. );
  394. }
  395. VOID
  396. print_DHCPDS_SERVERS(
  397. IN DWORD nTabs,
  398. IN LPDHCPDS_SERVERS Servers
  399. )
  400. {
  401. DWORD i;
  402. i = nTabs;
  403. while(i--) putchar('\t');
  404. printf("NumElements=%ld\n", Servers->NumElements);
  405. for( i = 0; i < Servers->NumElements ; i ++ )
  406. print_DHCPDS_SERVER(nTabs+1, &Servers->Servers[i]);
  407. }
  408. VOID
  409. SetDsServer(
  410. IN LPWSTR VarNameUnused
  411. )
  412. {
  413. DWORD Err;
  414. if( NULL != hRoot ) {
  415. StoreCleanupHandle(hRoot, 0, TRUE);
  416. }
  417. hRoot = &hStore1;
  418. Err = StoreInitHandle(
  419. hRoot,
  420. 0,
  421. wcslen(gDsServer)?gDsServer:NULL,
  422. NULL,
  423. NULL,
  424. NULL,
  425. 0
  426. );
  427. if( ERROR_SUCCESS != Err ) {
  428. printf("StoreInitHandle():%ld 0x%lx\n", Err, Err);
  429. hRoot = NULL;
  430. return ;
  431. }
  432. if( hDhcpC ) StoreCleanupHandle(hDhcpC, 0, TRUE);
  433. hDhcpC = &hStore2;
  434. Err = StoreGetHandle(
  435. hRoot,
  436. 0,
  437. StoreGetChildType,
  438. DHCP_ROOT_OBJECT_PARENT_LOC,
  439. hDhcpC
  440. );
  441. if( ERROR_SUCCESS != Err ) {
  442. printf("StoreInitHandle():%ld 0x%lx\n", Err, Err);
  443. hRoot = NULL;
  444. return ;
  445. }
  446. if( hDhcpRoot ) StoreCleanupHandle(hDhcpRoot, 0, TRUE);
  447. hDhcpRoot = &hStore4;
  448. Err = DhcpDsGetRoot(
  449. DDS_FLAGS_CREATE,
  450. hRoot,
  451. hDhcpRoot
  452. );
  453. if( ERROR_SUCCESS != Err) {
  454. printf("DhcpDsGetRoot(): %ld 0x%lx", Err, Err);
  455. hDhcpRoot = NULL;
  456. }
  457. }
  458. VOID
  459. SetObject(
  460. IN LPWSTR VarNameUnused
  461. )
  462. {
  463. }
  464. VOID
  465. CreateOptDef(
  466. IN LPWSTR VarNameUnused
  467. )
  468. {
  469. DWORD Result;
  470. Result = DhcpDsCreateOptionDef(
  471. hDhcpC,
  472. hObject,
  473. 0,
  474. gOptName,
  475. wcslen(gOptComment)?gOptComment:NULL,
  476. wcslen(gClassName)?gClassName: NULL,
  477. gOptId,
  478. gOptType,
  479. gOptVal,
  480. gOptLen
  481. );
  482. printf("DhcpDsCreateOptionDef: %ld (0x%lx)\n", Result, Result);
  483. }
  484. VOID
  485. ModifyOptDef(
  486. IN LPWSTR VarNameUnused
  487. )
  488. {
  489. DWORD Result;
  490. Result = DhcpDsModifyOptionDef(
  491. hDhcpC,
  492. hObject,
  493. 0,
  494. gOptName,
  495. wcslen(gOptComment)?gOptComment:NULL,
  496. wcslen(gClassName)?gClassName: NULL,
  497. gOptId,
  498. gOptType,
  499. gOptVal,
  500. gOptLen
  501. );
  502. printf("DhcpDsModifyOptionDef: %ld (0x%lx)\n", Result, Result);
  503. }
  504. VOID
  505. DeleteOptDef(
  506. IN LPWSTR VarNameUnused
  507. )
  508. {
  509. DWORD Result;
  510. Result = DhcpDsDeleteOptionDef(
  511. hDhcpC,
  512. hObject,
  513. 0,
  514. wcslen(gClassName)?gClassName: NULL,
  515. gOptId
  516. );
  517. printf("DhcpDsDeleteOptionDef: %ld (0x%lx)\n", Result, Result);
  518. }
  519. VOID
  520. EnumOptDefs(
  521. IN LPWSTR VarNameUnused
  522. )
  523. {
  524. DWORD Result;
  525. LPDHCP_OPTION_ARRAY OptArray = NULL;
  526. Result = DhcpDsEnumOptionDefs(
  527. hDhcpC,
  528. hObject,
  529. 0,
  530. wcslen(gClassName)?gClassName: NULL,
  531. gIsVendor,
  532. &OptArray
  533. );
  534. printf("DhcpDsEnumOptionDefs: %ld (0x%lx)\n", Result, Result);
  535. if( ERROR_SUCCESS == Result ) print_DHCP_OPTION_ARRAY(0, OptArray);
  536. if( NULL != OptArray ) LocalFree(OptArray);
  537. }
  538. VOID
  539. SetOptValue(
  540. IN LPWSTR VarNameUnused
  541. )
  542. {
  543. DWORD Result;
  544. DHCP_OPTION_DATA OptData;
  545. DHCP_OPTION_DATA_ELEMENT OptDataElement;
  546. OptData.NumElements = 1;
  547. OptData.Elements = &OptDataElement;
  548. OptDataElement.OptionType = DhcpDWordOption;
  549. OptDataElement.Element.DWordOption = gDwordOptData;
  550. Result = DhcpDsSetOptionValue(
  551. hDhcpC,
  552. hObject,
  553. 0,
  554. wcslen(gClassName)?gClassName: NULL,
  555. gOptId,
  556. &OptData
  557. );
  558. printf("DhcpDsSetOptionValue: %ld (0x%lx)\n", Result, Result);
  559. }
  560. VOID
  561. RemoveOptValue(
  562. IN LPWSTR VarNameUnused
  563. )
  564. {
  565. DWORD Result;
  566. Result = DhcpDsRemoveOptionValue(
  567. hDhcpC,
  568. hObject,
  569. 0,
  570. wcslen(gClassName)? gClassName : NULL,
  571. gOptId
  572. );
  573. printf("DhcpDsRemoveOptionValue: %ld (0x%lx)\n", Result, Result);
  574. }
  575. VOID
  576. GetOptValue(
  577. IN LPWSTR VarNameUnused
  578. )
  579. {
  580. DWORD Result;
  581. LPDHCP_OPTION_VALUE OptVal = NULL;
  582. Result = DhcpDsGetOptionValue(
  583. hDhcpC,
  584. hObject,
  585. 0,
  586. wcslen(gClassName)? gClassName : NULL,
  587. gOptId,
  588. &OptVal
  589. );
  590. printf("DhcpDsGetOptionValue: %ld (0x%lx)\n", Result, Result);
  591. if( ERROR_SUCCESS == Result ) print_DHCP_OPTION_VALUE(0, OptVal);
  592. if( OptVal ) LocalFree(OptVal);
  593. }
  594. VOID
  595. EnumOptValues(
  596. IN LPWSTR VarNameUnused
  597. )
  598. {
  599. DWORD Result;
  600. LPDHCP_OPTION_VALUE_ARRAY OptValues = NULL;
  601. Result = DhcpDsEnumOptionValues(
  602. hDhcpC,
  603. hObject,
  604. 0,
  605. wcslen(gClassName)? gClassName : NULL,
  606. gIsVendor,
  607. &OptValues
  608. );
  609. printf("DhcpDsEnumOptionValue: %ld (0x%lx)\n", Result, Result);
  610. if( ERROR_SUCCESS == Result ) print_DHCP_OPTION_VALUE_ARRAY(0, OptValues);
  611. if( OptValues ) LocalFree(OptValues);
  612. }
  613. VOID
  614. CreateClass(
  615. IN LPWSTR VarNameUnused
  616. )
  617. {
  618. DWORD Result;
  619. Result = DhcpDsCreateClass(
  620. hDhcpC,
  621. hObject,
  622. 0,
  623. wcslen(gClassName)? gClassName : NULL,
  624. wcslen(gClassComment)? gClassComment : NULL,
  625. gClassData,
  626. gClassDataLen
  627. );
  628. printf("DhcpDsCreateClass: %ld (0x%lx)\n", Result, Result);
  629. }
  630. VOID
  631. DeleteClass(
  632. IN LPWSTR VarNameUnused
  633. )
  634. {
  635. DWORD Result;
  636. Result = DhcpDsDeleteClass(
  637. hDhcpC,
  638. hObject,
  639. 0,
  640. gClassName
  641. );
  642. printf("DhcpDsDeleteClass: %ld (0x%lx)\n", Result, Result);
  643. }
  644. VOID
  645. EnumClasses(
  646. IN LPWSTR VarNameUnused
  647. )
  648. {
  649. DWORD Result;
  650. LPDHCP_CLASS_INFO_ARRAY Classes = NULL;
  651. Result = DhcpDsEnumClasses(
  652. hDhcpC,
  653. hObject,
  654. 0,
  655. &Classes
  656. );
  657. printf("DhcpDsEnumClasses: %ld (0x%lx)\n", Result, Result);
  658. if( ERROR_SUCCESS == Result ) print_DHCP_CLASS_INFO_ARRAY(0, Classes);
  659. if( Classes ) LocalFree(Classes);
  660. }
  661. VOID
  662. AddServer(
  663. IN LPWSTR VarNameUnused
  664. )
  665. {
  666. DWORD Result;
  667. Result = DhcpDsAddServer(
  668. hDhcpC,
  669. hDhcpRoot,
  670. 0,
  671. gServerName,
  672. NULL,
  673. gServerAddress,
  674. gServerState
  675. );
  676. printf("DhcpDsAddServer: %ld (0x%lx)\n", Result, Result);
  677. }
  678. VOID
  679. DelServer(
  680. IN LPWSTR VarNameUnused
  681. )
  682. {
  683. DWORD Result;
  684. Result = DhcpDsDelServer(
  685. hDhcpC,
  686. hDhcpRoot,
  687. 0,
  688. gServerName,
  689. NULL,
  690. gServerAddress
  691. );
  692. printf("DhcpDsDelServer: %ld (0x%lx)\n", Result, Result);
  693. }
  694. VOID
  695. EnumServers(
  696. IN LPWSTR VarNameUnused
  697. )
  698. {
  699. DWORD Result;
  700. LPDHCPDS_SERVERS Servers;
  701. Servers = NULL;
  702. Result = DhcpDsEnumServers(
  703. hDhcpC,
  704. hDhcpRoot,
  705. 0,
  706. &Servers
  707. );
  708. printf("DhcpDsEnumServer: %ld (0x%lx)\n", Result, Result);
  709. if( ERROR_SUCCESS == Result ) print_DHCPDS_SERVERS( 0, Servers);
  710. if( Servers ) MemFree(Servers);
  711. }
  712. NJIN_VAR VarTable[] = {
  713. L"DsServer", wString, { (LPVOID) &gDsServer }, SetDsServer, FALSE, //0
  714. L"Object", wString, { (LPVOID) &gObject }, SetObject, FALSE, //1
  715. L"OptName", wString, { (LPVOID) &gOptName }, NULL, FALSE, //2
  716. L"OptComment", wString, { (LPVOID) &gOptComment }, NULL, FALSE, //3
  717. L"ClassName", wString, { (LPVOID) &gClassName }, NULL, FALSE, //4
  718. L"ClassComment",wString,{ (LPVOID) &gClassComment }, NULL, FALSE, //5
  719. L"OptId", DWord, { (LPVOID) &gOptId }, NULL, FALSE, //6
  720. L"OptType", DWord, { (LPVOID) &gOptType }, NULL, FALSE, //7
  721. L"OptData", xBytes, { (LPVOID) NULL }, NULL, FALSE, //############ -> Need to fill pointer..
  722. L"IsVendor", DWord, { (LPVOID) &gIsVendor }, NULL, FALSE, //9
  723. L"DwordOptData", DWord, { (LPVOID) &gDwordOptData }, NULL, FALSE, //10
  724. L"ClassData", xBytes, { (LPVOID) NULL }, NULL, FALSE, //############ -> need to fill pointer
  725. L"ServerName", wString, { (LPVOID) &gServerName }, NULL, FALSE,
  726. L"ServerAddress", IpAddress, { (LPVOID) &gServerAddress }, NULL, FALSE,
  727. L"ServerState", DWord, { (LPVOID) &gServerState }, NULL, FALSE,
  728. L"CreateOptionDef", wString, { (LPVOID) &Dummy }, CreateOptDef, FALSE, //12
  729. L"ModifyOptionDef", wString, { (LPVOID) &Dummy }, ModifyOptDef, FALSE,
  730. L"EnumOptionDefs", wString, { (LPVOID) &Dummy }, EnumOptDefs, FALSE,
  731. L"SetOptionValue", wString, { (LPVOID) &Dummy }, SetOptValue, FALSE,
  732. L"RemoveOptionValue", wString, { (LPVOID) &Dummy }, RemoveOptValue, FALSE,
  733. L"GetOptionValue", wString, { (LPVOID) &Dummy }, GetOptValue, FALSE,
  734. L"EnumOptionValues", wString, { (LPVOID) &Dummy }, EnumOptValues, FALSE,
  735. L"CreateClass", wString, { (LPVOID) &Dummy }, CreateClass, FALSE,
  736. L"DeleteClass", wString, { (LPVOID) &Dummy }, DeleteClass, FALSE,
  737. L"EnumClasses", wString, { (LPVOID) &Dummy }, EnumClasses, FALSE,
  738. L"AddServer", wString, { (LPVOID) &Dummy }, AddServer, FALSE,
  739. L"DelServer", wString, { (LPVOID) &Dummy }, DelServer, FALSE,
  740. L"EnumServers", wString, { (LPVOID) &Dummy }, EnumServers, FALSE,
  741. };
  742. NJIN_ENV Env[] = {
  743. L'#',
  744. L'=',
  745. L'\r',
  746. L'\n',
  747. L' ',
  748. L'#',
  749. TRUE,
  750. TRUE
  751. };
  752. #define VarTableSz (sizeof(VarTable)/sizeof(VarTable[0]))
  753. void _cdecl main (void) {
  754. DWORD Result;
  755. DWORD i;
  756. VarTable[8].VarData.xBytesLen = &gOptLen;
  757. VarTable[8].VarData.xBytesBuf = gOptVal;
  758. VarTable[11].VarData.xBytesLen = &gClassDataLen;
  759. VarTable[11].VarData.xBytesBuf = gClassData;
  760. Result = NjinExecute(
  761. Env,
  762. VarTable,
  763. VarTableSz
  764. );
  765. if( ERROR_SUCCESS != Result ) {
  766. printf("\nResult = %ld\n", Result);
  767. }
  768. }
  769. //================================================================================
  770. // end of file
  771. //================================================================================