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.

680 lines
21 KiB

  1. /******************************************************************
  2. LsFn.cpp -- Properties action functions (GET)
  3. MODULE:
  4. DhcpProv.dll
  5. DESCRIPTION:
  6. Contains the definition for the action functions associated to
  7. each manageable property from the class CDHCP_Lease
  8. REVISION:
  9. 08/14/98 - created
  10. ******************************************************************/
  11. #include <stdafx.h>
  12. #include "LsScal.h" // needed for DHCP_Lease_Property[] (for retrieving the property's name)
  13. #include "LsFn.h" // own header
  14. /*****************************************************************
  15. * The definition of the class CDHCP_Lease_Parameters
  16. *****************************************************************/
  17. // by default, all the data structures are NULL (and dw variables are 0'ed)
  18. // those values indicates that no data is cached from the server.
  19. void CDHCP_Lease_Parameters::DeleteClientInfo(LPCLIENT_INFO& pClientInfo)
  20. {
  21. if (pClientInfo != NULL)
  22. {
  23. if (pClientInfo->ClientName)
  24. DhcpRpcFreeMemory(pClientInfo->ClientName);
  25. if (pClientInfo->ClientComment != NULL)
  26. DhcpRpcFreeMemory(pClientInfo->ClientComment);
  27. if (pClientInfo->ClientHardwareAddress.Data != NULL)
  28. DhcpRpcFreeMemory(pClientInfo->ClientHardwareAddress.Data);
  29. if (pClientInfo->OwnerHost.NetBiosName != NULL)
  30. DhcpRpcFreeMemory(pClientInfo->OwnerHost.NetBiosName);
  31. if (pClientInfo->OwnerHost.HostName != NULL)
  32. DhcpRpcFreeMemory(pClientInfo->OwnerHost.HostName);
  33. DhcpRpcFreeMemory(pClientInfo);
  34. }
  35. }
  36. void CDHCP_Lease_Parameters::DeleteClientInfoArray(LPCLIENT_INFO_ARRAY& pClientInfoArray)
  37. {
  38. if (pClientInfoArray)
  39. {
  40. if (pClientInfoArray->Clients)
  41. {
  42. while(pClientInfoArray->NumElements)
  43. {
  44. DeleteClientInfo(pClientInfoArray->Clients[--(pClientInfoArray->NumElements)]);
  45. }
  46. DhcpRpcFreeMemory(pClientInfoArray->Clients);
  47. }
  48. DhcpRpcFreeMemory(pClientInfoArray);
  49. pClientInfoArray = NULL;
  50. }
  51. }
  52. CDHCP_Lease_Parameters::CDHCP_Lease_Parameters(DHCP_IP_ADDRESS dwSubnetAddress, DHCP_IP_ADDRESS dwClientAddress)
  53. {
  54. m_dwSubnetAddress = dwSubnetAddress;
  55. m_dwClientAddress = dwClientAddress;
  56. m_pClientInfoArray = NULL;
  57. m_pClientInfo = NULL;
  58. m_pClientSetInfo = NULL;
  59. }
  60. // the DHCP API calls are allocating memory for which the caller is responsible
  61. // to release. We are releasing this memory upon the destruction of this object's instance.
  62. CDHCP_Lease_Parameters::~CDHCP_Lease_Parameters()
  63. {
  64. DeleteClientInfoArray(m_pClientInfoArray);
  65. DeleteClientInfo(m_pClientSetInfo);
  66. m_pClientInfo = NULL;
  67. }
  68. // DESCRIPTION:
  69. // Fills the internal cache with the information from the database, starting
  70. // from the given handle. If the end of the database is reached, the handle is
  71. // reset to 0. Returns TRUE on success (regardless there is more data to be read or not).
  72. BOOL CDHCP_Lease_Parameters::NextSubnetClients(DHCP_RESUME_HANDLE ResumeHandle)
  73. {
  74. DWORD Error;
  75. DWORD ClientsRead = 0;
  76. DWORD ClientsTotal = 0;
  77. // each time the API gets called, the previous
  78. // m_pClientInfoArray is useless and should be freed
  79. DeleteClientInfoArray(m_pClientInfoArray);
  80. m_pClientInfo = NULL;
  81. // calls the API.
  82. #ifdef NT5
  83. Error = DhcpEnumSubnetClientsV5 (
  84. #else if NT4
  85. Error = DhcpEnumSubnetClientsV4 (
  86. #endif
  87. SERVER_IP_ADDRESS,
  88. m_dwSubnetAddress,
  89. &ResumeHandle,
  90. (DWORD)(-1),
  91. &m_pClientInfoArray,
  92. &ClientsRead,
  93. &ClientsTotal);
  94. if (Error == ERROR_SUCCESS)
  95. ResumeHandle = 0;
  96. return (Error == ERROR_SUCCESS || Error == ERROR_MORE_DATA);
  97. }
  98. BOOL CDHCP_Lease_Parameters::GetClientInfoFromCache(LPCLIENT_INFO& pClientInfo)
  99. {
  100. if (m_pClientInfo != NULL &&
  101. m_pClientInfo->ClientIpAddress == m_dwClientAddress)
  102. {
  103. pClientInfo = m_pClientInfo;
  104. return TRUE;
  105. }
  106. if (m_pClientInfoArray != NULL)
  107. {
  108. for (int i=0; i<m_pClientInfoArray->NumElements; i++)
  109. {
  110. // match the internal client id with the info from cache
  111. if (m_pClientInfoArray->Clients[i]->ClientIpAddress == m_dwClientAddress)
  112. {
  113. // client found, return info on client, and TRUE.
  114. pClientInfo = m_pClientInfoArray->Clients[i];
  115. m_pClientInfo = pClientInfo;
  116. return TRUE;
  117. }
  118. }
  119. }
  120. return FALSE;
  121. }
  122. // DESCRIPTION:
  123. // Provides the data structure filled in through the DhcpGetClientInfo API
  124. // If this data is cached and the caller is not forcing the refresh,
  125. // return the internal cache. Otherwise, the internal cache is refreshed as well.
  126. BOOL CDHCP_Lease_Parameters::GetClientInfo(LPCLIENT_INFO& pClientInfo, BOOL fRefresh)
  127. {
  128. if (m_pClientInfoArray == NULL)
  129. fRefresh = TRUE;
  130. if (!fRefresh &&
  131. GetClientInfoFromCache(pClientInfo))
  132. return TRUE;
  133. DHCP_RESUME_HANDLE ResumeHandle = 0;
  134. DWORD i;
  135. // either the caller wants full refresh, or the client was not found into the cache
  136. // do full refresh.
  137. do
  138. {
  139. if (NextSubnetClients(ResumeHandle) &&
  140. GetClientInfoFromCache(pClientInfo) )
  141. return TRUE;
  142. } while (ResumeHandle != 0);
  143. return FALSE;
  144. }
  145. BOOL CDHCP_Lease_Parameters::CheckExistsSetInfoPtr()
  146. {
  147. if (m_pClientSetInfo != NULL)
  148. return TRUE;
  149. m_pClientSetInfo = (LPCLIENT_INFO)MIDL_user_allocate(sizeof(CLIENT_INFO));
  150. if (m_pClientSetInfo == NULL)
  151. return FALSE;
  152. memset(m_pClientSetInfo, 0, sizeof(CLIENT_INFO));
  153. return TRUE;
  154. }
  155. // DESCRIPTION:
  156. // Sets to the server the information available for the client.
  157. // It assumes the info is already filled in. It only calls DhcpSetClientInfoV4()
  158. // and return TRUE on success and FALSE on failure
  159. BOOL CDHCP_Lease_Parameters::CommitSet(DWORD & errCode)
  160. {
  161. LPCLIENT_INFO pClientInfo;
  162. if (m_pClientSetInfo == NULL ||
  163. !GetClientInfo(pClientInfo, FALSE))
  164. {
  165. errCode = ERROR_FILE_NOT_FOUND;
  166. return FALSE;
  167. }
  168. // copies all the info we have to set onto the cache location for the client
  169. // duplicate the hardware address
  170. dupDhcpBinaryData(m_pClientSetInfo->ClientHardwareAddress, pClientInfo->ClientHardwareAddress);
  171. // copy the name
  172. if (pClientInfo->ClientName)
  173. DhcpRpcFreeMemory(pClientInfo->ClientName);
  174. pClientInfo->ClientName = _wcsdup(m_pClientSetInfo->ClientName);
  175. // copy the comment
  176. if (pClientInfo->ClientComment)
  177. DhcpRpcFreeMemory(pClientInfo->ClientComment);
  178. pClientInfo->ClientComment = _wcsdup(m_pClientSetInfo->ClientComment);
  179. // copy the client type
  180. pClientInfo->bClientType = m_pClientSetInfo->bClientType;
  181. // DHCP_CLIENT_INFO_V5 is only a one field extension of DHCP_CLIENT_INFO_V4
  182. errCode = DhcpSetClientInfoV4(
  183. SERVER_IP_ADDRESS,
  184. (LPDHCP_CLIENT_INFO_V4)pClientInfo);
  185. return errCode == ERROR_SUCCESS;
  186. }
  187. // GET function for the (RO)"Subnet" property
  188. MFN_PROPERTY_ACTION_DEFN(fnLsGetSubnet, pParams, pIn, pOut)
  189. {
  190. CDHCP_Lease_Parameters *pLeaseParams;
  191. LPCLIENT_INFO pClientInfo;
  192. if (pParams == NULL || pOut == NULL)
  193. return FALSE;
  194. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  195. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  196. pClientInfo != NULL)
  197. {
  198. WCHAR wsSubnet[16]; // should be enough to hold an IP Addr (xxx.xxx.xxx.xxx\0 = 16)
  199. DWORD dwSubnet;
  200. dwSubnet = pClientInfo->ClientIpAddress & pClientInfo->SubnetMask;
  201. swprintf(wsSubnet, L"%u.%u.%u.%u",(dwSubnet & 0xff000000) >> 24,
  202. (dwSubnet & 0x00ff0000) >> 16,
  203. (dwSubnet & 0x0000ff00) >> 8,
  204. (dwSubnet & 0x000000ff));
  205. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_Subnet].m_wsPropName, wsSubnet);
  206. return TRUE;
  207. }
  208. // the API call failed
  209. return FALSE;
  210. }
  211. // GET function for the (RO)"Address" property
  212. MFN_PROPERTY_ACTION_DEFN(fnLsGetAddress, pParams, pIn, pOut)
  213. {
  214. CDHCP_Lease_Parameters *pLeaseParams;
  215. LPCLIENT_INFO pClientInfo;
  216. if (pParams == NULL || pOut == NULL)
  217. return FALSE;
  218. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  219. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  220. pClientInfo != NULL)
  221. {
  222. WCHAR wsAddress[16]; // should be enough to hold an IP Addr (xxx.xxx.xxx.xxx\0 = 16)
  223. swprintf(wsAddress, L"%u.%u.%u.%u",(pClientInfo->ClientIpAddress & 0xff000000) >> 24,
  224. (pClientInfo->ClientIpAddress & 0x00ff0000) >> 16,
  225. (pClientInfo->ClientIpAddress & 0x0000ff00) >> 8,
  226. (pClientInfo->ClientIpAddress & 0x000000ff));
  227. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_Address].m_wsPropName, wsAddress);
  228. return TRUE;
  229. }
  230. // the API call failed
  231. return FALSE;
  232. }
  233. // GET function for the (RO) "Mask" property
  234. MFN_PROPERTY_ACTION_DEFN(fnLsGetMask, pParams, pIn, pOut)
  235. {
  236. CDHCP_Lease_Parameters *pLeaseParams;
  237. LPCLIENT_INFO pClientInfo;
  238. if (pParams == NULL || pOut == NULL)
  239. return FALSE;
  240. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  241. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  242. pClientInfo != NULL)
  243. {
  244. WCHAR wsMask[16]; // should be enough to hold an IP Addr (xxx.xxx.xxx.xxx\0 = 16)
  245. swprintf(wsMask, L"%u.%u.%u.%u",(pClientInfo->SubnetMask & 0xff000000) >> 24,
  246. (pClientInfo->SubnetMask & 0x00ff0000) >> 16,
  247. (pClientInfo->SubnetMask & 0x0000ff00) >> 8,
  248. (pClientInfo->SubnetMask & 0x000000ff));
  249. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_SubnetMask].m_wsPropName, wsMask);
  250. return TRUE;
  251. }
  252. // the API call failed
  253. return FALSE;
  254. }
  255. // GET function for the (RW)"UniqueClientIdentifier" property
  256. MFN_PROPERTY_ACTION_DEFN(fnLsGetHdwAddress, pParams, pIn, pOut)
  257. {
  258. CDHCP_Lease_Parameters *pLeaseParams;
  259. LPCLIENT_INFO pClientInfo;
  260. if (pParams == NULL || pOut == NULL)
  261. return FALSE;
  262. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  263. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  264. pClientInfo != NULL)
  265. {
  266. /*
  267. // -- uncomment the code below if want to change the format of the hdw address (from array of 6 bytes to string)
  268. // -- in this case, remove the 'return' lines below, and change the definition of the variable
  269. // -- DHCP_Lease::UniqueClientIdentifier to string.
  270. WCHAR wsHdwAddress[32]; // should be enough to hold the hardware address (xxyyzzuuvvww)
  271. for (int i = 0; i < pClientInfo->ClientHardwareAddress.DataLength && i < 16; i++)
  272. {
  273. swprintf(wsHdwAddress + 2*i, L"%02x", pClientInfo->ClientHardwareAddress.Data[i]);
  274. }
  275. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_UniqueClientIdentifier].m_wsPropName, wsHdwAddress);
  276. return TRUE;
  277. */
  278. return InstanceSetByteArray(
  279. pOut,
  280. DHCP_Lease_Property[IDX_Ls_UniqueClientIdentifier].m_wsPropName,
  281. pClientInfo->ClientHardwareAddress.Data,
  282. pClientInfo->ClientHardwareAddress.DataLength );
  283. }
  284. // the API call failed
  285. return FALSE;
  286. }
  287. // SET function for the (RW)"UniqueClientIdentifier" property
  288. MFN_PROPERTY_ACTION_DEFN(fnLsSetHdwAddress, pParams, pIn, pOut)
  289. {
  290. CDHCP_Lease_Parameters *pLeaseParams;
  291. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  292. // only some of the client info can be set (Name, Comment, HdwAddress, Type
  293. // therefore, the client has to be present into the cache. We will alter only (one of) the
  294. // parameters above.
  295. if (pLeaseParams == NULL ||
  296. !pLeaseParams->CheckExistsSetInfoPtr() ||
  297. pIn == NULL ||
  298. !InstanceGetByteArray(
  299. pIn,
  300. DHCP_Lease_Property[IDX_Ls_UniqueClientIdentifier].m_wsPropName,
  301. pLeaseParams->m_pClientSetInfo->ClientHardwareAddress.Data,
  302. pLeaseParams->m_pClientSetInfo->ClientHardwareAddress.DataLength)
  303. )
  304. return FALSE;
  305. // if this is a request for 'instant apply', do it now
  306. if (pOut != NULL)
  307. {
  308. DWORD errCode;
  309. pLeaseParams->CommitSet(errCode);
  310. // fill back the code returned by the underlying level
  311. if (pOut != NULL)
  312. pOut->SetDWORD(RETURN_CODE_PROPERTY_NAME, errCode);
  313. }
  314. // the API call succeded
  315. return TRUE;
  316. }
  317. // GET function for the (RW)"Name" property
  318. MFN_PROPERTY_ACTION_DEFN(fnLsGetName, pParams, pIn, pOut)
  319. {
  320. CDHCP_Lease_Parameters *pLeaseParams;
  321. LPCLIENT_INFO pClientInfo;
  322. if (pParams == NULL || pOut == NULL)
  323. return FALSE;
  324. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  325. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  326. pClientInfo != NULL)
  327. {
  328. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_Name].m_wsPropName,
  329. pClientInfo->ClientName);
  330. return TRUE;
  331. }
  332. // the API call failed
  333. return FALSE;
  334. }
  335. // SET function for the (RW)"Name" property
  336. MFN_PROPERTY_ACTION_DEFN(fnLsSetName, pParams, pIn, pOut)
  337. {
  338. CDHCP_Lease_Parameters *pLeaseParams;
  339. CHString wsName;
  340. LPCLIENT_INFO pClientInfo;
  341. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  342. // only some of the client info can be set (Name, Comment, HdwAddress, Type
  343. // therefore, the client has to be present into the cache. We will alter only (one of) the
  344. // parameters above.
  345. if (pLeaseParams == NULL ||
  346. !pLeaseParams->CheckExistsSetInfoPtr() ||
  347. pIn == NULL ||
  348. !pIn->GetCHString(DHCP_Lease_Property[IDX_Ls_Name].m_wsPropName, wsName))
  349. return FALSE;
  350. pClientInfo = pLeaseParams->m_pClientSetInfo;
  351. if (pClientInfo->ClientName != NULL)
  352. DhcpRpcFreeMemory(pClientInfo->ClientName);
  353. // allocate a new buffer able to hold this new name
  354. pClientInfo->ClientName = (WCHAR*)MIDL_user_allocate(sizeof(WCHAR)*wsName.GetLength()+sizeof(WCHAR));
  355. // make sure the allocation succeeded
  356. if (pClientInfo->ClientName == NULL)
  357. return FALSE;
  358. // copy the name to the new buffer
  359. #ifdef _UNICODE
  360. wcscpy(pClientInfo->ClientName, wsName);
  361. #else
  362. swprintf(pClientInfo->ClientName, L"%S", wsName);
  363. #endif
  364. // if this is a request for 'instant apply', do it now
  365. if (pOut != NULL)
  366. {
  367. DWORD errCode;
  368. pLeaseParams->CommitSet(errCode);
  369. // fill back the code returned by the underlying level
  370. if (pOut != NULL)
  371. pOut->SetDWORD(RETURN_CODE_PROPERTY_NAME, errCode);
  372. }
  373. // the API call succeded
  374. return TRUE;
  375. }
  376. // GET function for the (RW)"Comment" property
  377. MFN_PROPERTY_ACTION_DEFN(fnLsGetComment, pParams, pIn, pOut)
  378. {
  379. CDHCP_Lease_Parameters *pLeaseParams;
  380. LPCLIENT_INFO pClientInfo;
  381. if (pParams == NULL || pOut == NULL)
  382. return FALSE;
  383. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  384. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  385. pClientInfo != NULL)
  386. {
  387. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_Comment].m_wsPropName,
  388. pClientInfo->ClientComment);
  389. return TRUE;
  390. }
  391. // the API call failed
  392. return FALSE;
  393. }
  394. // SET function for the (RW)"Comment" property
  395. MFN_PROPERTY_ACTION_DEFN(fnLsSetComment, pParams, pIn, pOut)
  396. {
  397. CDHCP_Lease_Parameters *pLeaseParams;
  398. CHString wsComment;
  399. LPCLIENT_INFO pClientInfo;
  400. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  401. // only some of the client info can be set (Name, Comment, HdwAddress, Type
  402. // therefore, the client has to be present into the cache. We will alter only (one of) the
  403. // parameters above.
  404. if (pLeaseParams == NULL ||
  405. !pLeaseParams->CheckExistsSetInfoPtr() ||
  406. pIn == NULL ||
  407. !pIn->GetCHString(DHCP_Lease_Property[IDX_Ls_Comment].m_wsPropName, wsComment))
  408. return FALSE;
  409. pClientInfo = pLeaseParams->m_pClientSetInfo;
  410. if (pClientInfo->ClientComment != NULL)
  411. DhcpRpcFreeMemory(pClientInfo->ClientComment);
  412. // allocate a new buffer able to hold this new name
  413. pClientInfo->ClientComment = (WCHAR*)MIDL_user_allocate(sizeof(WCHAR)*wsComment.GetLength()+sizeof(WCHAR));
  414. // make sure the allocation succeeded
  415. if (pClientInfo->ClientComment == NULL)
  416. return FALSE;
  417. // copy the name to the new buffer
  418. #ifdef _UNICODE
  419. wcscpy(pClientInfo->ClientComment, wsComment);
  420. #else
  421. swprintf(pClientInfo->ClientComment, L"%S", wsComment);
  422. #endif
  423. // if this is a request for 'instant apply', do it now
  424. if (pOut != NULL)
  425. {
  426. DWORD errCode;
  427. pLeaseParams->CommitSet(errCode);
  428. // fill back the code returned by the underlying level
  429. if (pOut != NULL)
  430. pOut->SetDWORD(RETURN_CODE_PROPERTY_NAME, errCode);
  431. }
  432. // the API call succeded
  433. return TRUE;
  434. }
  435. // GET function for the (RO)"LeaseExpiryDate" property
  436. MFN_PROPERTY_ACTION_DEFN(fnLsGetExpiry, pParams, pIn, pOut)
  437. {
  438. CDHCP_Lease_Parameters *pLeaseParams;
  439. LPCLIENT_INFO pClientInfo;
  440. if (pParams == NULL || pOut == NULL)
  441. return FALSE;
  442. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  443. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  444. pClientInfo != NULL)
  445. {
  446. SYSTEMTIME sysTime;
  447. wchar_t wchBuffer [32];
  448. // convert the server startup time to a string (UTC) representation.
  449. _tzset () ;
  450. // timezone is offset from UTC in seconds, _daylight is 1 or 0 regarding the DST period
  451. LONG t_Offset = _timezone / 60 - _daylight * 60;
  452. char chOffset = t_Offset < 0 ? '+' : '-';
  453. // take the absolute value from t_Offset
  454. LONG t_absOffset = (1 - ((t_Offset < 0)<<1)) * t_Offset;
  455. FileTimeToSystemTime((FILETIME *)&(pClientInfo->ClientLeaseExpires), &sysTime);
  456. // should ensure we have a valid date format (even if inf.)
  457. if (sysTime.wYear > 9999)
  458. {
  459. sysTime.wYear = 9999;
  460. sysTime.wMonth = 12;
  461. sysTime.wDay = 31;
  462. sysTime.wHour = 23;
  463. sysTime.wMinute = 59;
  464. sysTime.wSecond = 59;
  465. sysTime.wMilliseconds = 0;
  466. }
  467. swprintf (
  468. wchBuffer ,
  469. L"%04ld%02ld%02ld%02ld%02ld%02ld.%06ld%c%03ld" ,
  470. sysTime.wYear,
  471. sysTime.wMonth,
  472. sysTime.wDay,
  473. sysTime.wHour,
  474. sysTime.wMinute,
  475. sysTime.wSecond,
  476. sysTime.wMilliseconds,
  477. chOffset,
  478. t_absOffset
  479. );
  480. // set the value of the property into the (CInstance*)pOut
  481. pOut->SetCHString(DHCP_Lease_Property[IDX_Ls_LeaseExpiryDate].m_wsPropName, wchBuffer);
  482. return TRUE;
  483. }
  484. // the API call failed
  485. return FALSE;
  486. }
  487. // GET function for the (RW)"Type" property
  488. MFN_PROPERTY_ACTION_DEFN(fnLsGetType, pParams, pIn, pOut)
  489. {
  490. CDHCP_Lease_Parameters *pLeaseParams;
  491. LPCLIENT_INFO pClientInfo;
  492. if (pParams == NULL || pOut == NULL)
  493. return FALSE;
  494. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  495. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  496. pClientInfo != NULL)
  497. {
  498. pOut->SetByte(DHCP_Lease_Property[IDX_Ls_Type].m_wsPropName,
  499. pClientInfo->bClientType);
  500. return TRUE;
  501. }
  502. // the API call failed
  503. return FALSE;
  504. }
  505. // SET function for the (RW)"Type" property
  506. MFN_PROPERTY_ACTION_DEFN(fnLsSetType, pParams, pIn, pOut)
  507. {
  508. CDHCP_Lease_Parameters *pLeaseParams;
  509. BYTE bClientType;
  510. LPCLIENT_INFO pClientInfo;
  511. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  512. // only some of the client info can be set (Name, Comment, HdwAddress, Type
  513. // therefore, the client has to be present into the cache. We will alter only (one of) the
  514. // parameters above.
  515. if (pLeaseParams == NULL ||
  516. !pLeaseParams->CheckExistsSetInfoPtr() ||
  517. pIn == NULL ||
  518. !pIn->GetByte(DHCP_Lease_Property[IDX_Ls_Type].m_wsPropName, bClientType))
  519. return FALSE;
  520. pClientInfo = pLeaseParams->m_pClientSetInfo;
  521. pClientInfo->bClientType = bClientType;
  522. // if this is a request for 'instant apply', do it now
  523. if (pOut != NULL)
  524. {
  525. DWORD errCode;
  526. pLeaseParams->CommitSet(errCode);
  527. // fill back the code returned by the underlying level
  528. if (pOut != NULL)
  529. pOut->SetDWORD(RETURN_CODE_PROPERTY_NAME, errCode);
  530. }
  531. // the API call succeded
  532. return TRUE;
  533. }
  534. #ifdef NT5
  535. // GET function for the (RO)"State" property
  536. MFN_PROPERTY_ACTION_DEFN(fnLsGetState, pParams, pIn, pOut)
  537. {
  538. CDHCP_Lease_Parameters *pLeaseParams;
  539. LPCLIENT_INFO pClientInfo;
  540. if (pParams == NULL || pOut == NULL)
  541. return FALSE;
  542. pLeaseParams = (CDHCP_Lease_Parameters *)pParams;
  543. if (pLeaseParams->GetClientInfo(pClientInfo, FALSE) &&
  544. pClientInfo != NULL)
  545. {
  546. pOut->SetByte(DHCP_Lease_Property[IDX_Ls_State].m_wsPropName,
  547. pClientInfo->AddressState);
  548. return TRUE;
  549. }
  550. // the API call failed
  551. return FALSE;
  552. }
  553. #endif