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.

276 lines
11 KiB

  1. //================================================================================
  2. // Copyright (C) 1997 Microsoft Corporation
  3. // Author: RameshV
  4. // Description: This module has helper routines to delete the objects recursively.
  5. //
  6. //================================================================================
  7. #include <hdrmacro.h>
  8. #include <store.h>
  9. #include <dhcpmsg.h>
  10. #include <wchar.h>
  11. #include <dhcpbas.h>
  12. #include <mm\opt.h>
  13. #include <mm\optl.h>
  14. #include <mm\optdefl.h>
  15. #include <mm\optclass.h>
  16. #include <mm\classdefl.h>
  17. #include <mm\bitmask.h>
  18. #include <mm\reserve.h>
  19. #include <mm\range.h>
  20. #include <mm\subnet.h>
  21. #include <mm\sscope.h>
  22. #include <mm\oclassdl.h>
  23. #include <mm\server.h>
  24. #include <mm\address.h>
  25. #include <mm\server2.h>
  26. #include <mm\memfree.h>
  27. #include <mmreg\regutil.h>
  28. #include <mmreg\regread.h>
  29. #include <mmreg\regsave.h>
  30. #include <dhcpapi.h>
  31. //================================================================================
  32. // helper functions
  33. //================================================================================
  34. VOID static
  35. MemFreeFunc(
  36. IN OUT LPVOID Memory
  37. )
  38. {
  39. MemFree(Memory);
  40. }
  41. //================================================================================
  42. // exposed functions
  43. //================================================================================
  44. //BeginExport(function)
  45. //DOC SubnetDeleteReservation deletes the reservation object from off the DS.
  46. SubnetDeleteReservation( // delete reservation from DS
  47. IN OUT LPSTORE_HANDLE hDhcpC, // container for resrevation objs
  48. IN LPWSTR ServerName, // name of dhcp server
  49. IN OUT LPSTORE_HANDLE hServer, // server object in DS
  50. IN OUT LPSTORE_HANDLE hSubnet, // subnet object in DS
  51. IN LPWSTR ADsPath, // path of reservation object
  52. IN DWORD StoreGetType // path is relative, abs, or dif server?
  53. ) //EndExport(function)
  54. {
  55. return StoreDeleteThisObject // just delete the reservation object
  56. (
  57. /* hStore */ hDhcpC,
  58. /* Reserved */ DDS_RESERVED_DWORD,
  59. /* StoreGetType */ StoreGetType,
  60. /* Path */ ADsPath
  61. );
  62. }
  63. //BeginExport(function)
  64. //DOC ServerDeleteSubnet deletes the subnet specified from the DS by removing
  65. //DOC the subnet object.
  66. ServerDeleteSubnet( // remove subnet object from DS
  67. IN OUT LPSTORE_HANDLE hDhcpC, // container for subnet objs in Ds
  68. IN LPWSTR ServerName, // name of server this deletion is for
  69. IN OUT LPSTORE_HANDLE hServer, // server object in DS
  70. IN LPWSTR ADsPath, // Location of the subnet in DS
  71. IN DWORD StoreGetType // path is relative,abs or diff srvr?
  72. ) //EndExport(function)
  73. {
  74. DWORD Err, LastErr, LocType;
  75. STORE_HANDLE hSubnet;
  76. ARRAY Reservations;
  77. ARRAY_LOCATION Loc;
  78. PEATTRIB ThisAttrib;
  79. LPWSTR Location;
  80. LPVOID Ptr;
  81. Err = StoreGetHandle // get the server object from the DS
  82. (
  83. /* hStore */ hDhcpC,
  84. /* Reserved */ DDS_RESERVED_DWORD,
  85. /* StoreGetType */ StoreGetType,
  86. /* Path */ ADsPath,
  87. /* hStoreOut */ &hSubnet
  88. );
  89. if( ERROR_SUCCESS != Err ) return Err;
  90. Err = MemArrayInit(&Reservations); //= require ERROR_SUCCESS == Err
  91. Err = DhcpDsGetLists // get list or reservations
  92. (
  93. /* Reserved */ DDS_RESERVED_DWORD,
  94. /* hStore */ &hSubnet,
  95. /* RecursionDepth */ 0xFFFFFFFF,
  96. /* Servers */ NULL,
  97. /* Subnets */ NULL,
  98. /* IpAddress */ NULL,
  99. /* Mask */ NULL,
  100. /* Ranges */ NULL,
  101. /* Sites */ NULL,
  102. /* Reservations */ &Reservations,
  103. /* SuperScopes */ NULL,
  104. /* OptionDescription */ NULL,
  105. /* OptionsLocation */ NULL,
  106. /* Options */ NULL,
  107. /* Classes */ NULL
  108. );
  109. if( ERROR_SUCCESS != Err ) return Err;
  110. LastErr = ERROR_SUCCESS;
  111. for( // delete each subnet
  112. Err = MemArrayInitLoc(&Reservations, &Loc)
  113. ; ERROR_FILE_NOT_FOUND != Err;
  114. Err = MemArrayNextLoc(&Reservations, &Loc)
  115. ) {
  116. Err = MemArrayGetElement(&Reservations, &Loc, &ThisAttrib);
  117. //= require ERROR_SUCCESS == Err && NULL != ThisAttrib
  118. if( !IS_ADDRESS1_PRESENT(ThisAttrib) || // reserved address
  119. !IS_BINARY1_PRESENT(ThisAttrib) ) { // HW address info
  120. continue; // invalid subnet
  121. }
  122. if( !IS_ADSPATH_PRESENT(ThisAttrib) ) { // no location specified
  123. Location = MakeReservationLocation(ServerName, ThisAttrib->Address1);
  124. LocType = StoreGetChildType;
  125. Ptr = Location;
  126. } else {
  127. Location = ThisAttrib->ADsPath;
  128. LocType = ThisAttrib->StoreGetType;
  129. Ptr = NULL;
  130. }
  131. Err = SubnetDeleteReservation // now delete the reservation
  132. (
  133. /* hDhcpC */ hDhcpC,
  134. /* ServerName */ ServerName,
  135. /* hServer */ hServer,
  136. /* hSubnet */ &hSubnet,
  137. /* ADsPath */ Location,
  138. /* StoreGetType */ LocType
  139. );
  140. if( ERROR_SUCCESS != Err ) LastErr = Err;
  141. if( Ptr ) MemFree(Ptr);
  142. }
  143. MemArrayFree(&Reservations, MemFreeFunc);
  144. Err = StoreCleanupHandle(&hSubnet, 0); //= require ERROR_SUCCESS == Err
  145. Err = StoreDeleteThisObject // now really delete the subnet object
  146. (
  147. /* hStore */ hDhcpC,
  148. /* Reserved */ DDS_RESERVED_DWORD,
  149. /* StoreGetType */ StoreGetType,
  150. /* Path */ ADsPath
  151. );
  152. if( ERROR_SUCCESS != Err ) LastErr = Err; // try to delete the store object itself
  153. return LastErr;
  154. }
  155. //BeginExport(function)
  156. //DOC DeleteServer deletes the server object from the DS and deletes any SUBNET and
  157. //DOC reservation objects that it may point to.
  158. //DOC The hDhcpC parameter is the handle of the container where the server object
  159. //DOC may be located. This used in conjunction with the ADsPath and StoreGetType
  160. //DOC defines the location of the ServerObject.
  161. DWORD
  162. DeleteServer( // recurse delete server from DS
  163. IN OUT LPSTORE_HANDLE hDhcpC, // container where server obj may be
  164. IN LPWSTR ServerName, // name of server..
  165. IN LPWSTR ADsPath, // path of the server object
  166. IN DWORD StoreGetType // is path relative, absolute or dif srvr?
  167. ) //EndExport(function)
  168. {
  169. DWORD Err, LastErr, LocType;
  170. STORE_HANDLE hServer;
  171. ARRAY Subnets;
  172. ARRAY_LOCATION Loc;
  173. PEATTRIB ThisAttrib;
  174. LPWSTR Location;
  175. LPVOID Ptr;
  176. Err = StoreGetHandle // get the server object from the DS
  177. (
  178. /* hStore */ hDhcpC,
  179. /* Reserved */ DDS_RESERVED_DWORD,
  180. /* StoreGetType */ StoreGetType,
  181. /* Path */ ADsPath,
  182. /* hStoreOut */ &hServer
  183. );
  184. if( ERROR_SUCCESS != Err ) return Err;
  185. Err = MemArrayInit(&Subnets); //= require ERROR_SUCCESS == Err
  186. Err = DhcpDsGetLists // get subnets and other stuff
  187. (
  188. /* Reserved */ DDS_RESERVED_DWORD,
  189. /* hStore */ &hServer,
  190. /* RecursionDepth */ 0xFFFFFFFF,
  191. /* Servers */ NULL,
  192. /* Subnets */ &Subnets,
  193. /* IpAddress */ NULL,
  194. /* Mask */ NULL,
  195. /* Ranges */ NULL,
  196. /* Sites */ NULL,
  197. /* Reservations */ NULL,
  198. /* SuperScopes */ NULL,
  199. /* OptionDescription */ NULL,
  200. /* OptionsLocation */ NULL,
  201. /* Options */ NULL,
  202. /* Classes */ NULL
  203. );
  204. if( ERROR_SUCCESS != Err ) return Err;
  205. LastErr = ERROR_SUCCESS;
  206. for( // delete each subnet
  207. Err = MemArrayInitLoc(&Subnets, &Loc)
  208. ; ERROR_FILE_NOT_FOUND != Err;
  209. Err = MemArrayNextLoc(&Subnets, &Loc)
  210. ) {
  211. Err = MemArrayGetElement(&Subnets, &Loc, &ThisAttrib);
  212. //= require ERROR_SUCCESS == Err && NULL != ThisAttrib
  213. if( !IS_ADDRESS1_PRESENT(ThisAttrib) || // subnet address
  214. !IS_ADDRESS2_PRESENT(ThisAttrib) ) { // subnet mask
  215. continue; // invalid subnet
  216. }
  217. if( !IS_ADSPATH_PRESENT(ThisAttrib) ) { // no location specified
  218. Location = MakeSubnetLocation(ServerName, ThisAttrib->Address1);
  219. LocType = StoreGetChildType;
  220. Ptr = Location;
  221. } else {
  222. Location = ThisAttrib->ADsPath;
  223. LocType = ThisAttrib->StoreGetType;
  224. Ptr = NULL;
  225. }
  226. Err = ServerDeleteSubnet // now delete the subnet
  227. (
  228. /* hDhcpC */ hDhcpC,
  229. /* ServerName */ ServerName,
  230. /* hServer */ &hServer,
  231. /* ADsPath */ Location,
  232. /* StoreGetType */ LocType
  233. );
  234. if( ERROR_SUCCESS != Err ) LastErr = Err;
  235. if( Ptr ) MemFree(Ptr);
  236. }
  237. MemArrayFree(&Subnets, MemFreeFunc);
  238. Err = StoreCleanupHandle( &hServer, DDS_RESERVED_DWORD );
  239. Err = StoreDeleteThisObject // now really delete the server object
  240. (
  241. /* hStore */ hDhcpC,
  242. /* Reserved */ DDS_RESERVED_DWORD,
  243. /* StoreGetType */ StoreGetType,
  244. /* Path */ ADsPath
  245. );
  246. if( ERROR_SUCCESS != Err ) LastErr = Err; // try to delete the store object itself
  247. return LastErr;
  248. }
  249. //================================================================================
  250. // end of file
  251. //================================================================================