Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1065 lines
31 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: This implements the save functionality.. whenever something needs
  5. // to be saved onto the registry, this is the place...
  6. // it is expected that this would be used only during API re-configuration or
  7. // during routine "address-allocation" where the bitmask needs to be flushed to disk
  8. //================================================================================
  9. #include <mmregpch.h>
  10. #include <regutil.h>
  11. #define InitArray(X) do{DWORD Error = MemArrayInit((X)); Require(ERROR_SUCCESS == Error); }while(0)
  12. #define ERRCHK do{if( ERROR_SUCCESS != Error ) goto Cleanup; }while(0)
  13. #define FreeArray1(X) Error = LoopThruArray((X), DestroyString, NULL, NULL);Require(ERROR_SUCCESS == Error);
  14. #define FreeArray2(X) Error = MemArrayCleanup((X)); Require(ERROR_SUCCESS == Error);
  15. #define FreeArray(X) do{ DWORD Error; FreeArray1(X); FreeArray2(X); }while(0)
  16. #define Report(Who) if(Error) DbgPrint("[DHCPServer] %s: %ld [0x%lx]\n", Who, Error, Error)
  17. typedef DWORD (*ARRAY_FN)(PREG_HANDLE, LPWSTR ArrayString, LPVOID MemObject);
  18. DWORD
  19. LoopThruArray(
  20. IN PARRAY Array,
  21. IN ARRAY_FN ArrayFn,
  22. IN PREG_HANDLE Hdl,
  23. IN LPVOID MemObject
  24. );
  25. DWORD
  26. DestroyString(
  27. IN PREG_HANDLE RegHdl,
  28. IN LPWSTR Str,
  29. IN LPVOID Something
  30. );
  31. //BeginExport(function)
  32. DWORD
  33. DhcpRegSaveOptDef(
  34. IN DWORD OptId,
  35. IN LPWSTR ClassName,
  36. IN LPWSTR VendorName,
  37. IN LPWSTR Name,
  38. IN LPWSTR Comment,
  39. IN DWORD OptType,
  40. IN LPBYTE OptVal,
  41. IN DWORD OptLen
  42. ) //EndExport(function)
  43. {
  44. DWORD Error, Error2;
  45. REG_HANDLE Hdl, Hdl2;
  46. LPWSTR OptDefStr;
  47. Error = DhcpRegGetThisServer(&Hdl);
  48. if( NO_ERROR != Error ) return Error;
  49. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  50. if( NULL == OptDefStr ) {
  51. Error = ERROR_NOT_ENOUGH_MEMORY;
  52. } else {
  53. Error = DhcpRegServerGetOptDefHdl(&Hdl, OptDefStr, &Hdl2);
  54. MemFree(OptDefStr);
  55. }
  56. Error2 = DhcpRegCloseHdl(&Hdl);
  57. Require(ERROR_SUCCESS == Error2);
  58. if( ERROR_SUCCESS != Error ) return Error;
  59. Error = DhcpRegOptDefSetAttributes(
  60. &Hdl2,
  61. &Name,
  62. &Comment,
  63. &OptType,
  64. &OptId,
  65. &ClassName,
  66. &VendorName,
  67. &OptVal,
  68. OptLen
  69. );
  70. Error2 = DhcpRegCloseHdl(&Hdl2);
  71. Require(ERROR_SUCCESS == Error2);
  72. return Error;
  73. }
  74. //BeginExport(function)
  75. DWORD
  76. DhcpRegDeleteOptDef(
  77. IN DWORD OptId,
  78. IN LPWSTR ClassName,
  79. IN LPWSTR VendorName
  80. ) //EndExport(function)
  81. {
  82. DWORD Error, Error2;
  83. REG_HANDLE Hdl, Hdl2;
  84. LPWSTR OptDefStr;
  85. Error = DhcpRegGetThisServer(&Hdl);
  86. if( NO_ERROR != Error ) return Error;
  87. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  88. if( NULL == OptDefStr ) {
  89. Error = ERROR_NOT_ENOUGH_MEMORY;
  90. } else {
  91. Error = DhcpRegServerGetOptDefHdl(&Hdl, L"", &Hdl2);
  92. if( ERROR_SUCCESS == Error ) {
  93. Error = DhcpRegRecurseDelete(&Hdl2, OptDefStr);
  94. Error2 = DhcpRegCloseHdl(&Hdl2);
  95. Require(ERROR_SUCCESS == Error2);
  96. }
  97. MemFree(OptDefStr);
  98. }
  99. Error2 = DhcpRegCloseHdl(&Hdl);
  100. Require(ERROR_SUCCESS == Error2);
  101. return Error;
  102. }
  103. //BeginExport(function)
  104. DWORD
  105. DhcpRegSaveGlobalOption(
  106. IN DWORD OptId,
  107. IN LPWSTR ClassName,
  108. IN LPWSTR VendorName,
  109. IN LPBYTE Value,
  110. IN DWORD ValueSize
  111. ) //EndExport(function)
  112. {
  113. DWORD Error, Error2;
  114. REG_HANDLE Hdl, Hdl2;
  115. LPWSTR OptDefStr;
  116. Error = DhcpRegGetThisServer(&Hdl);
  117. if( NO_ERROR != Error ) return Error;
  118. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  119. if( NULL == OptDefStr ) {
  120. DhcpRegCloseHdl(&Hdl);
  121. return ERROR_NOT_ENOUGH_MEMORY;
  122. }
  123. Error = DhcpRegServerGetOptHdl(&Hdl, OptDefStr, &Hdl2);
  124. MemFree(OptDefStr);
  125. Error2 = DhcpRegCloseHdl(&Hdl);
  126. Require(ERROR_SUCCESS == Error2);
  127. if( ERROR_SUCCESS == Error ) {
  128. Error = DhcpRegOptSetAttributes(
  129. &Hdl2,
  130. &OptId,
  131. &ClassName,
  132. &VendorName,
  133. NULL,
  134. &Value,
  135. ValueSize
  136. );
  137. Error2 = DhcpRegCloseHdl(&Hdl2);
  138. Require(ERROR_SUCCESS == Error2);
  139. }
  140. return Error;
  141. }
  142. //BeginExport(function)
  143. DWORD
  144. DhcpRegDeleteGlobalOption(
  145. IN DWORD OptId,
  146. IN LPWSTR ClassName,
  147. IN LPWSTR VendorName
  148. ) //EndExport(function)
  149. {
  150. DWORD Error, Error2;
  151. REG_HANDLE Hdl, Hdl2;
  152. LPWSTR OptDefStr;
  153. Error = DhcpRegGetThisServer(&Hdl);
  154. if( NO_ERROR != Error ) return Error;
  155. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  156. if( NULL == OptDefStr ) {
  157. Error = ERROR_NOT_ENOUGH_MEMORY;
  158. } else {
  159. Error = DhcpRegServerGetOptHdl(&Hdl, L"", &Hdl2);
  160. if( ERROR_SUCCESS == Error ) {
  161. Error = DhcpRegRecurseDelete(&Hdl2, OptDefStr);
  162. Error2 = DhcpRegCloseHdl(&Hdl2);
  163. Require(ERROR_SUCCESS == Error2);
  164. }
  165. MemFree(OptDefStr);
  166. }
  167. Error2 = DhcpRegCloseHdl(&Hdl);
  168. Require(ERROR_SUCCESS == Error2);
  169. return Error;
  170. }
  171. //BeginExport(function)
  172. DWORD
  173. DhcpRegSaveSubnetOption(
  174. IN PM_SUBNET Subnet,
  175. IN DWORD OptId,
  176. IN LPWSTR ClassName,
  177. IN LPWSTR VendorName,
  178. IN LPBYTE Value,
  179. IN DWORD ValueSize
  180. ) //EndExport(function)
  181. {
  182. DWORD Error, Error2;
  183. REG_HANDLE Hdl, Hdl2, Hdl3;
  184. LPWSTR OptDefStr;
  185. WCHAR SubnetStr[sizeof("000.000.000.000")];
  186. Error = DhcpRegGetThisServer(&Hdl);
  187. if( NO_ERROR != Error ) return Error;
  188. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  189. if( NULL == OptDefStr ) {
  190. DhcpRegCloseHdl(&Hdl);
  191. return ERROR_NOT_ENOUGH_MEMORY;
  192. }
  193. Error = Subnet->fSubnet
  194. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, SubnetStr), &Hdl2)
  195. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  196. Error2 = DhcpRegCloseHdl(&Hdl);
  197. Require(ERROR_SUCCESS == Error2);
  198. if( ERROR_SUCCESS == Error ) {
  199. Error = DhcpRegSubnetGetOptHdl(&Hdl2, OptDefStr, &Hdl3);
  200. Error2 = DhcpRegCloseHdl(&Hdl2);
  201. Require(ERROR_SUCCESS == Error2);
  202. }
  203. MemFree(OptDefStr);
  204. if( ERROR_SUCCESS == Error ) {
  205. Error = DhcpRegOptSetAttributes(
  206. &Hdl3,
  207. &OptId,
  208. &ClassName,
  209. &VendorName,
  210. NULL,
  211. &Value,
  212. ValueSize
  213. );
  214. Error2 = DhcpRegCloseHdl(&Hdl3);
  215. Require(ERROR_SUCCESS == Error2);
  216. }
  217. return Error;
  218. }
  219. //BeginExport(function)
  220. DWORD
  221. DhcpRegDeleteSubnetOption(
  222. IN PM_SUBNET Subnet,
  223. IN DWORD OptId,
  224. IN LPWSTR ClassName,
  225. IN LPWSTR VendorName
  226. ) //EndExport(function)
  227. {
  228. DWORD Error, Error2;
  229. REG_HANDLE Hdl, Hdl2, Hdl3;
  230. LPWSTR OptDefStr;
  231. WCHAR SubnetStr[sizeof("000.000.000.000")];
  232. Error = DhcpRegGetThisServer(&Hdl);
  233. if( NO_ERROR != Error ) return Error;
  234. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  235. if( NULL == OptDefStr ) {
  236. DhcpRegCloseHdl(&Hdl);
  237. return ERROR_NOT_ENOUGH_MEMORY;
  238. }
  239. Error = Subnet->fSubnet
  240. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, SubnetStr), &Hdl2)
  241. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  242. Error2 = DhcpRegCloseHdl(&Hdl);
  243. Require(ERROR_SUCCESS == Error2);
  244. if( ERROR_SUCCESS == Error ) {
  245. Error = DhcpRegSubnetGetOptHdl(&Hdl2, L"", &Hdl3);
  246. Error2 = DhcpRegCloseHdl(&Hdl2);
  247. Require(ERROR_SUCCESS == Error2);
  248. }
  249. if( ERROR_SUCCESS == Error ) {
  250. Error = DhcpRegRecurseDelete(&Hdl3, OptDefStr);
  251. Error2 = DhcpRegCloseHdl(&Hdl3);
  252. Require(ERROR_SUCCESS == Error2);
  253. }
  254. MemFree(OptDefStr);
  255. return Error;
  256. }
  257. //BeginExport(function)
  258. DWORD
  259. DhcpRegSaveReservedOption(
  260. IN DWORD Address,
  261. IN DWORD ReservedAddress,
  262. IN DWORD OptId,
  263. IN LPWSTR ClassName,
  264. IN LPWSTR VendorName,
  265. IN LPBYTE Value,
  266. IN DWORD ValueSize
  267. ) //EndExport(function)
  268. {
  269. DWORD Error, Error2;
  270. REG_HANDLE Hdl, Hdl2, Hdl3;
  271. LPWSTR OptDefStr;
  272. WCHAR SubnetStr[sizeof("000.000.000.000")];
  273. WCHAR ReservedStr[sizeof("000.000.000.000")];
  274. Error = DhcpRegGetThisServer(&Hdl);
  275. if( NO_ERROR != Error ) return Error;
  276. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  277. if( NULL == OptDefStr ) {
  278. DhcpRegCloseHdl(&Hdl);
  279. return ERROR_NOT_ENOUGH_MEMORY;
  280. }
  281. Error = DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Address, SubnetStr), &Hdl2);
  282. Error2 = DhcpRegCloseHdl(&Hdl);
  283. Require(ERROR_SUCCESS == Error2);
  284. if( ERROR_SUCCESS == Error ) {
  285. Error = DhcpRegSubnetGetReservationHdl(&Hdl2, ConvertAddressToLPWSTR(ReservedAddress, ReservedStr), &Hdl3);
  286. Error2 = DhcpRegCloseHdl(&Hdl2);
  287. Require(ERROR_SUCCESS == Error2);
  288. }
  289. if( ERROR_SUCCESS == Error ) {
  290. Error = DhcpRegReservationGetOptHdl(&Hdl3, OptDefStr, &Hdl2);
  291. Error2 = DhcpRegCloseHdl(&Hdl3);
  292. Require(ERROR_SUCCESS == Error2);
  293. }
  294. MemFree(OptDefStr);
  295. if( ERROR_SUCCESS == Error ) {
  296. Error = DhcpRegOptSetAttributes(
  297. &Hdl2,
  298. &OptId,
  299. &ClassName,
  300. &VendorName,
  301. NULL,
  302. &Value,
  303. ValueSize
  304. );
  305. Error2 = DhcpRegCloseHdl(&Hdl2);
  306. Require(ERROR_SUCCESS == Error2);
  307. }
  308. return Error;
  309. }
  310. //BeginExport(function)
  311. DWORD
  312. DhcpRegDeleteReservedOption(
  313. IN DWORD Address,
  314. IN DWORD ReservedAddress,
  315. IN DWORD OptId,
  316. IN LPWSTR ClassName,
  317. IN LPWSTR VendorName
  318. ) //EndExport(function)
  319. {
  320. DWORD Error, Error2;
  321. REG_HANDLE Hdl, Hdl2, Hdl3;
  322. LPWSTR OptDefStr;
  323. WCHAR SubnetStr[sizeof("000.000.000.000")];
  324. WCHAR ReservedStr[sizeof("000.000.000.000")];
  325. Error = DhcpRegGetThisServer(&Hdl);
  326. if( NO_ERROR != Error ) return Error;
  327. OptDefStr = DhcpRegCombineClassAndOption(ClassName, VendorName, OptId);
  328. if( NULL == OptDefStr ) {
  329. DhcpRegCloseHdl(&Hdl);
  330. return ERROR_NOT_ENOUGH_MEMORY;
  331. }
  332. Error = DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Address, SubnetStr), &Hdl2);
  333. Error2 = DhcpRegCloseHdl(&Hdl);
  334. Require(ERROR_SUCCESS == Error2);
  335. if( ERROR_SUCCESS == Error ) {
  336. Error = DhcpRegSubnetGetReservationHdl(&Hdl2, ConvertAddressToLPWSTR(ReservedAddress, ReservedStr), &Hdl3);
  337. Error2 = DhcpRegCloseHdl(&Hdl2);
  338. Require(ERROR_SUCCESS == Error2);
  339. }
  340. if( ERROR_SUCCESS == Error ) {
  341. Error = DhcpRegReservationGetOptHdl(&Hdl3, L"", &Hdl2);
  342. Error2 = DhcpRegCloseHdl(&Hdl3);
  343. Require(ERROR_SUCCESS == Error2);
  344. }
  345. if( ERROR_SUCCESS == Error ) {
  346. Error = DhcpRegRecurseDelete(&Hdl2, OptDefStr);
  347. Error2 = DhcpRegCloseHdl(&Hdl2);
  348. Require(ERROR_SUCCESS == Error2);
  349. }
  350. MemFree(OptDefStr);
  351. return Error;
  352. }
  353. //BeginExport(function)
  354. DWORD
  355. DhcpRegSaveClassDef(
  356. IN LPWSTR Name,
  357. IN LPWSTR Comment,
  358. IN DWORD Flags,
  359. IN LPBYTE Data,
  360. IN DWORD DataLength
  361. ) //EndExport(function)
  362. {
  363. DWORD Error, Error2;
  364. REG_HANDLE Hdl, Hdl2;
  365. if( NULL == Name ) return ERROR_INVALID_PARAMETER;
  366. Error = DhcpRegGetThisServer(&Hdl);
  367. if( NO_ERROR != Error ) return Error;
  368. Error = DhcpRegServerGetClassDefHdl(&Hdl, Name, &Hdl2);
  369. Error2 = DhcpRegCloseHdl(&Hdl);
  370. Require(ERROR_SUCCESS == Error2);
  371. Error = DhcpRegClassDefSetAttributes(
  372. &Hdl2,
  373. &Name,
  374. &Comment,
  375. &Flags,
  376. &Data,
  377. DataLength
  378. );
  379. Error2 = DhcpRegCloseHdl(&Hdl2);
  380. Require(ERROR_SUCCESS == Error2);
  381. return Error;
  382. }
  383. //BeginExport(function)
  384. DWORD
  385. DhcpRegDeleteClassDef(
  386. IN LPWSTR Name
  387. ) //EndExport(function)
  388. {
  389. DWORD Error, Error2;
  390. REG_HANDLE Hdl, Hdl2;
  391. if( NULL == Name ) return ERROR_INVALID_PARAMETER;
  392. Error = DhcpRegGetThisServer(&Hdl);
  393. if( NO_ERROR != Error ) return Error;
  394. Error = DhcpRegServerGetClassDefHdl(&Hdl, L"", &Hdl2);
  395. Error2 = DhcpRegCloseHdl(&Hdl);
  396. Require(ERROR_SUCCESS == Error2);
  397. Error = DhcpRegRecurseDelete(&Hdl2, Name);
  398. Error2 = DhcpRegCloseHdl(&Hdl2);
  399. Require(ERROR_SUCCESS == Error2);
  400. return Error;
  401. }
  402. //BeginExport(function)
  403. DWORD
  404. DhcpRegSaveReservation(
  405. IN DWORD Subnet,
  406. IN DWORD Address,
  407. IN DWORD Flags,
  408. IN LPBYTE ClientUID,
  409. IN DWORD ClientUIDLength
  410. ) //EndExport(function)
  411. {
  412. DWORD Error, Error2;
  413. REG_HANDLE Hdl, Hdl2, Hdl3;
  414. WCHAR AddressStr[sizeof("000.000.000.000")];
  415. Error = DhcpRegGetThisServer(&Hdl);
  416. if( NO_ERROR != Error ) return Error;
  417. Error = DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet, AddressStr), &Hdl2);
  418. Error2 = DhcpRegCloseHdl(&Hdl);
  419. Require(ERROR_SUCCESS == Error2);
  420. if( ERROR_SUCCESS != Error) return Error;
  421. Error = DhcpRegSubnetGetReservationHdl(&Hdl2, ConvertAddressToLPWSTR(Address, AddressStr), &Hdl3);
  422. Error2 = DhcpRegCloseHdl(&Hdl2);
  423. Require(ERROR_SUCCESS == Error2);
  424. if( ERROR_SUCCESS != Error ) return Error;
  425. Error = DhcpRegReservationSetAttributes(
  426. &Hdl3,
  427. NULL,
  428. NULL,
  429. &Flags,
  430. &Address,
  431. &ClientUID,
  432. ClientUIDLength
  433. );
  434. Error2 = DhcpRegCloseHdl(&Hdl3);
  435. Require(ERROR_SUCCESS == Error2);
  436. return Error;
  437. }
  438. //BeginExport(function)
  439. DWORD
  440. DhcpRegDeleteReservation(
  441. IN DWORD Subnet,
  442. IN DWORD Address
  443. ) //EndExport(function)
  444. {
  445. DWORD Error, Error2;
  446. REG_HANDLE Hdl, Hdl2, Hdl3;
  447. WCHAR AddressStr[sizeof("000.000.000.000")];
  448. Error = DhcpRegGetThisServer(&Hdl);
  449. if( NO_ERROR != Error ) return Error;
  450. Error = DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet, AddressStr), &Hdl2);
  451. Error2 = DhcpRegCloseHdl(&Hdl);
  452. Require(ERROR_SUCCESS == Error2);
  453. if( ERROR_SUCCESS != Error) return Error;
  454. Error = DhcpRegSubnetGetReservationHdl(&Hdl2, L"", &Hdl3);
  455. Error2 = DhcpRegCloseHdl(&Hdl2);
  456. Require(ERROR_SUCCESS == Error2);
  457. if( ERROR_SUCCESS != Error ) return Error;
  458. Error = DhcpRegRecurseDelete(&Hdl3, ConvertAddressToLPWSTR(Address, AddressStr));
  459. Error2 = DhcpRegCloseHdl(&Hdl3);
  460. Require(ERROR_SUCCESS == Error2);
  461. return Error;
  462. }
  463. //BeginExport(function)
  464. DWORD
  465. DhcpRegSScopeDeleteSubnet(
  466. IN LPWSTR SScopeName,
  467. IN DWORD SubnetAddress
  468. ) //EndExport(function)
  469. {
  470. DWORD Error, Error2;
  471. REG_HANDLE Hdl, Hdl2;
  472. WCHAR AddressStr[sizeof("000.000.000.000")];
  473. Error = DhcpRegGetThisServer(&Hdl);
  474. if( NO_ERROR != Error ) return Error;
  475. Error = DhcpRegServerGetSScopeHdl(&Hdl, SScopeName, &Hdl2);
  476. Error2 = DhcpRegCloseHdl(&Hdl);
  477. Require(ERROR_SUCCESS == Error2);
  478. if( ERROR_SUCCESS != Error ) return Error;
  479. Error = DhcpRegRecurseDelete(&Hdl2, ConvertAddressToLPWSTR(SubnetAddress, AddressStr));
  480. Error2 = DhcpRegCloseHdl(&Hdl2);
  481. Require(ERROR_SUCCESS == Error2);
  482. return Error;
  483. }
  484. DWORD
  485. DhcpRegpDelSubnetFromSScope(
  486. IN PREG_HANDLE Unused,
  487. IN LPWSTR SScopeName,
  488. IN LPVOID Address
  489. )
  490. {
  491. DWORD Error;
  492. Error = DhcpRegSScopeDeleteSubnet(SScopeName, PtrToUlong(Address));
  493. return ERROR_SUCCESS; // ignore if this subnet is not found in this sscope
  494. }
  495. //BeginExport(function)
  496. DWORD
  497. DhcpRegDelSubnetFromAllSScopes(
  498. IN DWORD Address
  499. ) //EndExport(function)
  500. {
  501. DWORD Error, Error2;
  502. ARRAY Array;
  503. REG_HANDLE Hdl, Hdl2;
  504. Error = MemArrayInit(&Array);
  505. Require(ERROR_SUCCESS == Error);
  506. Error = DhcpRegGetThisServer(&Hdl);
  507. if( NO_ERROR != Error ) return Error;
  508. Error = DhcpRegServerGetList(&Hdl, NULL, NULL, NULL, &Array, NULL, NULL);
  509. if( ERROR_SUCCESS == Error ) {
  510. Error = LoopThruArray(
  511. &Array, DhcpRegpDelSubnetFromSScope, &Hdl,
  512. ULongToPtr(Address));
  513. }
  514. Error2 = DhcpRegCloseHdl(&Hdl);
  515. Require(ERROR_SUCCESS == Error2);
  516. FreeArray(&Array);
  517. return Error;
  518. }
  519. //BeginExport(function)
  520. DWORD
  521. DhcpRegSScopeSaveSubnet(
  522. IN LPWSTR SScopeName,
  523. IN DWORD Address
  524. ) //EndExport(function)
  525. {
  526. DWORD Error, Error2;
  527. REG_HANDLE Hdl, Hdl2;
  528. WCHAR AddressStr[sizeof("000.000.000.000")];
  529. Error = DhcpRegGetThisServer(&Hdl);
  530. if( NO_ERROR != Error ) return Error;
  531. Error = DhcpRegServerGetSScopeHdl(&Hdl, SScopeName, &Hdl2);
  532. Error2 = DhcpRegCloseHdl(&Hdl);
  533. Require(ERROR_SUCCESS == Error2);
  534. if( ERROR_SUCCESS != Error ) return Error;
  535. Error = DhcpRegGetNextHdl(&Hdl2, ConvertAddressToLPWSTR(Address, AddressStr), &Hdl);
  536. Error2 = DhcpRegCloseHdl(&Hdl2);
  537. Require(ERROR_SUCCESS == Error2);
  538. Error2 = DhcpRegCloseHdl(&Hdl);
  539. Require(ERROR_SUCCESS == Error2);
  540. return Error;
  541. }
  542. //BeginExport(function)
  543. DWORD
  544. DhcpRegDeleteSScope(
  545. IN LPWSTR SScopeName
  546. ) //EndExport(function)
  547. {
  548. DWORD Error, Error2;
  549. REG_HANDLE Hdl, Hdl2;
  550. Error = DhcpRegGetThisServer(&Hdl);
  551. if( NO_ERROR != Error ) return Error;
  552. Error = DhcpRegServerGetSScopeHdl(&Hdl, L"", &Hdl2);
  553. Error2 = DhcpRegCloseHdl(&Hdl);
  554. Require(ERROR_SUCCESS == Error2);
  555. if( ERROR_SUCCESS != Error ) return Error;
  556. Error = DhcpRegRecurseDelete(&Hdl2, SScopeName );
  557. Error2 = DhcpRegCloseHdl(&Hdl2);
  558. Require(ERROR_SUCCESS == Error2);
  559. return Error;
  560. }
  561. //BeginExport(function)
  562. DWORD
  563. DhcpRegSaveSubnet(
  564. IN DWORD SubnetAddress,
  565. IN DWORD SubnetMask,
  566. IN DWORD SubnetState,
  567. IN LPWSTR SubnetName,
  568. IN LPWSTR SubnetComment
  569. ) //EndExport(function)
  570. {
  571. DWORD Error, Error2;
  572. REG_HANDLE Hdl, Hdl2;
  573. WCHAR AddressStr[sizeof("000.000.000.000")];
  574. Error = DhcpRegGetThisServer(&Hdl);
  575. if( NO_ERROR != Error ) return Error;
  576. Error = DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(SubnetAddress, AddressStr), &Hdl2);
  577. Error2 = DhcpRegCloseHdl(&Hdl);
  578. Require(ERROR_SUCCESS == Error2);
  579. if( ERROR_SUCCESS != Error ) return Error;
  580. Error = DhcpRegSubnetSetAttributes(
  581. &Hdl2,
  582. &SubnetName,
  583. &SubnetComment,
  584. &SubnetState,
  585. &SubnetAddress,
  586. &SubnetMask
  587. );
  588. Error2 = DhcpRegCloseHdl(&Hdl2);
  589. Require(ERROR_SUCCESS == Error2);
  590. return Error;
  591. }
  592. //BeginExport(function)
  593. DWORD
  594. DhcpRegDeleteSubnet(
  595. IN PM_SUBNET Subnet
  596. ) //EndExport(function)
  597. {
  598. DWORD Error, Error2;
  599. REG_HANDLE Hdl, Hdl2;
  600. WCHAR AddressStr[sizeof("000.000.000.000")];
  601. LPWSTR KeyName;
  602. Error = DhcpRegGetThisServer(&Hdl);
  603. if( NO_ERROR != Error ) return Error;
  604. Error = Subnet->fSubnet ? DhcpRegServerGetSubnetHdl(&Hdl, L"" , &Hdl2)
  605. : DhcpRegServerGetMScopeHdl(&Hdl, L"" , &Hdl2);
  606. Error2 = DhcpRegCloseHdl(&Hdl);
  607. Require(ERROR_SUCCESS == Error2);
  608. if( ERROR_SUCCESS != Error ) return Error;
  609. KeyName = Subnet->fSubnet ? ConvertAddressToLPWSTR(Subnet->Address, AddressStr) : Subnet->Name;
  610. Error = DhcpRegRecurseDelete(&Hdl2, KeyName);
  611. Error2 = DhcpRegCloseHdl(&Hdl2);
  612. Require(ERROR_SUCCESS == Error2);
  613. return Error;
  614. }
  615. //BeginExport(function)
  616. DWORD
  617. DhcpRegAddRange(
  618. IN PM_SUBNET Subnet,
  619. IN DWORD RangeStartAddress,
  620. IN DWORD RangeEndAddress,
  621. IN ULONG BootpAllocated,
  622. IN ULONG MaxBootpAllowed,
  623. IN DWORD Type
  624. ) //EndExport(function)
  625. {
  626. DWORD Error, Error2;
  627. REG_HANDLE Hdl, Hdl2;
  628. WCHAR AddressStr[sizeof("000.000.000.000")];
  629. LPWSTR KeyName;
  630. Error = DhcpRegGetThisServer(&Hdl);
  631. if( NO_ERROR != Error ) return Error;
  632. Error = DhcpRegRangeSetAttributes(
  633. &Hdl,
  634. NULL,
  635. NULL,
  636. &Type,
  637. &BootpAllocated,
  638. &MaxBootpAllowed,
  639. &RangeStartAddress,
  640. &RangeEndAddress,
  641. NULL,
  642. 0,
  643. NULL,
  644. 0
  645. );
  646. Error2 = DhcpRegCloseHdl(&Hdl);
  647. Require( ERROR_SUCCESS == Error2 );
  648. return Error;
  649. }
  650. //BeginExport(function)
  651. DWORD
  652. DhcpRegAddRangeEx(
  653. IN PM_SUBNET Subnet,
  654. IN DWORD RangeStartAddress,
  655. IN DWORD RangeEndAddress,
  656. IN DWORD Type,
  657. IN ULONG BootpAllocated,
  658. IN ULONG MaxBootpAllowed,
  659. IN LPBYTE InUseClusters,
  660. IN DWORD InUseClustersSize,
  661. IN LPBYTE UsedClusters,
  662. IN DWORD UsedClustersSize
  663. ) //EndExport(function)
  664. {
  665. DWORD Error, Error2;
  666. REG_HANDLE Hdl, Hdl2;
  667. WCHAR AddressStr[sizeof("000.000.000.000")];
  668. Error = DhcpRegGetThisServer(&Hdl);
  669. if( NO_ERROR != Error ) return Error;
  670. Error = Subnet->fSubnet
  671. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, AddressStr), &Hdl2)
  672. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  673. Error2 = DhcpRegCloseHdl(&Hdl);
  674. Require(ERROR_SUCCESS == Error2);
  675. if( ERROR_SUCCESS != Error ) return Error;
  676. Error = DhcpRegSubnetGetRangeHdl(&Hdl2, ConvertAddressToLPWSTR(RangeStartAddress, AddressStr), &Hdl);
  677. Error2 = DhcpRegCloseHdl(&Hdl2);
  678. Require(ERROR_SUCCESS == Error2);
  679. if( ERROR_SUCCESS != Error ) return Error;
  680. Error = DhcpRegRangeSetAttributes(
  681. &Hdl,
  682. NULL,
  683. NULL,
  684. &Type,
  685. &BootpAllocated,
  686. &MaxBootpAllowed,
  687. &RangeStartAddress,
  688. &RangeEndAddress,
  689. &InUseClusters,
  690. InUseClustersSize,
  691. &UsedClusters,
  692. UsedClustersSize
  693. );
  694. Error2 = DhcpRegCloseHdl(&Hdl);
  695. Require(ERROR_SUCCESS == Error2);
  696. return Error;
  697. }
  698. //BeginExport(function)
  699. DWORD
  700. DhcpRegDeleteRange(
  701. IN PM_SUBNET Subnet,
  702. IN DWORD RangeStartAddress
  703. ) //EndExport(function)
  704. {
  705. DWORD Error, Error2;
  706. REG_HANDLE Hdl, Hdl2;
  707. WCHAR AddressStr[sizeof("000.000.000.000")];
  708. Error = DhcpRegGetThisServer(&Hdl);
  709. if( NO_ERROR != Error ) return Error;
  710. Error = Subnet->fSubnet
  711. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, AddressStr), &Hdl2)
  712. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  713. Error2 = DhcpRegCloseHdl(&Hdl);
  714. Require(ERROR_SUCCESS == Error2);
  715. if( ERROR_SUCCESS != Error ) return Error;
  716. Error = DhcpRegSubnetGetRangeHdl(&Hdl2, L"", &Hdl);
  717. Error2 = DhcpRegCloseHdl(&Hdl2);
  718. Require(ERROR_SUCCESS == Error2);
  719. if( ERROR_SUCCESS != Error ) return Error;
  720. Error = DhcpRegRecurseDelete(&Hdl, ConvertAddressToLPWSTR(RangeStartAddress, AddressStr));
  721. Error2 = DhcpRegCloseHdl(&Hdl);
  722. Require(ERROR_SUCCESS == Error2);
  723. return Error;
  724. }
  725. //BeginExport(function)
  726. DWORD
  727. DhcpRegDeleteRangeEx(
  728. IN PM_SUBNET Subnet,
  729. IN DWORD RangeStartAddress,
  730. OUT LPBYTE *InUseClusters,
  731. OUT DWORD *InUseClustersSize,
  732. OUT LPBYTE *UsedClusters,
  733. OUT DWORD *UsedClustersSize
  734. ) //EndExport(function)
  735. {
  736. DWORD Error, Error2;
  737. REG_HANDLE Hdl, Hdl2;
  738. WCHAR AddressStr[sizeof("000.000.000.000")];
  739. Error = DhcpRegGetThisServer(&Hdl);
  740. if( NO_ERROR != Error ) return Error;
  741. Error = Subnet->fSubnet
  742. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, AddressStr), &Hdl2)
  743. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  744. Error2 = DhcpRegCloseHdl(&Hdl);
  745. Require(ERROR_SUCCESS == Error2);
  746. if( ERROR_SUCCESS != Error ) return Error;
  747. Error = DhcpRegSubnetGetRangeHdl(&Hdl2, ConvertAddressToLPWSTR(RangeStartAddress, AddressStr), &Hdl);
  748. Error2 = DhcpRegCloseHdl(&Hdl2);
  749. Require(ERROR_SUCCESS == Error2);
  750. if( ERROR_SUCCESS != Error ) return Error;
  751. Error = DhcpRegRangeGetAttributes(
  752. &Hdl,
  753. NULL,
  754. NULL,
  755. NULL,
  756. NULL,
  757. NULL,
  758. NULL,
  759. NULL,
  760. InUseClusters,
  761. InUseClustersSize,
  762. UsedClusters,
  763. UsedClustersSize
  764. );
  765. Error2 = DhcpRegCloseHdl(&Hdl);
  766. Require(ERROR_SUCCESS == Error2);
  767. if( ERROR_SUCCESS != Error ) return Error;
  768. return DhcpRegDeleteRange(Subnet, RangeStartAddress);
  769. }
  770. //BeginExport(function)
  771. DWORD
  772. DhcpRegSaveExcl(
  773. IN PM_SUBNET Subnet,
  774. IN LPBYTE ExclBytes,
  775. IN DWORD nBytes
  776. ) //EndExport(function)
  777. {
  778. DWORD Error, Error2;
  779. REG_HANDLE Hdl, Hdl2;
  780. WCHAR AddressStr[sizeof("000.000.000.000")];
  781. Error = DhcpRegGetThisServer(&Hdl);
  782. if( NO_ERROR != Error ) return Error;
  783. Error = Subnet->fSubnet
  784. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, AddressStr), &Hdl2)
  785. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  786. Error2 = DhcpRegCloseHdl(&Hdl);
  787. Require(ERROR_SUCCESS == Error2);
  788. if( ERROR_SUCCESS != Error ) return Error;
  789. Error = DhcpRegSubnetSetExclusions(
  790. &Hdl2,
  791. &ExclBytes,
  792. nBytes
  793. );
  794. Error2 = DhcpRegCloseHdl(&Hdl2);
  795. Require(ERROR_SUCCESS == Error2);
  796. return Error;
  797. }
  798. //BeginExport(function)
  799. DWORD
  800. DhcpRegSaveBitMask(
  801. IN PM_SUBNET Subnet,
  802. IN DWORD RangeStartAddress,
  803. IN LPBYTE InUse,
  804. IN DWORD InUseSize,
  805. IN LPBYTE Used,
  806. IN DWORD UsedSize
  807. ) //EndExport(function)
  808. {
  809. DWORD Error, Error2;
  810. REG_HANDLE Hdl, Hdl2;
  811. WCHAR AddressStr[sizeof("000.000.000.000")];
  812. Error = DhcpRegGetThisServer(&Hdl);
  813. if( NO_ERROR != Error ) return Error;
  814. Error = Subnet->fSubnet
  815. ? DhcpRegServerGetSubnetHdl(&Hdl, ConvertAddressToLPWSTR(Subnet->Address, AddressStr), &Hdl2)
  816. : DhcpRegServerGetMScopeHdl(&Hdl, Subnet->Name, &Hdl2);
  817. Error2 = DhcpRegCloseHdl(&Hdl);
  818. Require(ERROR_SUCCESS == Error2);
  819. if( ERROR_SUCCESS != Error ) return Error;
  820. Error = DhcpRegSubnetGetRangeHdl(&Hdl2, ConvertAddressToLPWSTR(RangeStartAddress, AddressStr), &Hdl);
  821. Error2 = DhcpRegCloseHdl(&Hdl2);
  822. Require(ERROR_SUCCESS == Error2);
  823. if( ERROR_SUCCESS != Error ) return Error;
  824. Error = DhcpRegRangeSetAttributes(
  825. &Hdl,
  826. NULL,
  827. NULL,
  828. NULL,
  829. NULL,
  830. NULL,
  831. NULL,
  832. NULL,
  833. &InUse,
  834. InUseSize,
  835. &Used,
  836. UsedSize
  837. );
  838. Error2 = DhcpRegCloseHdl(&Hdl);
  839. Require(ERROR_SUCCESS == Error2);
  840. return Error;
  841. }
  842. //BeginExport(function)
  843. DWORD
  844. DhcpRegSaveMScope(
  845. IN DWORD MScopeId,
  846. IN DWORD SubnetState,
  847. IN DWORD AddressPolicy,
  848. IN DWORD TTL,
  849. IN LPWSTR pMScopeName,
  850. IN LPWSTR pMScopeComment,
  851. IN LPWSTR LangTag,
  852. IN PDATE_TIME ExpiryTime
  853. ) //EndExport(function)
  854. {
  855. DWORD Error, Error2;
  856. REG_HANDLE Hdl, Hdl2;
  857. WCHAR AddressStr[sizeof("000.000.000.000")];
  858. Require( pMScopeName );
  859. Error = DhcpRegGetThisServer(&Hdl);
  860. if( NO_ERROR != Error ) return Error;
  861. Error = DhcpRegServerGetMScopeHdl(&Hdl, pMScopeName, &Hdl2);
  862. Error2 = DhcpRegCloseHdl(&Hdl);
  863. Require(ERROR_SUCCESS == Error2);
  864. if( ERROR_SUCCESS != Error ) return Error;
  865. Error = DhcpRegMScopeSetAttributes(
  866. &Hdl2,
  867. &pMScopeComment,
  868. &SubnetState,
  869. &MScopeId,
  870. &AddressPolicy,
  871. &TTL,
  872. &LangTag,
  873. &ExpiryTime
  874. );
  875. Error2 = DhcpRegCloseHdl(&Hdl2);
  876. Require(ERROR_SUCCESS == Error2);
  877. return Error;
  878. }
  879. //================================================================================
  880. // end of file
  881. //================================================================================