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.

1032 lines
21 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: cipsec.cxx
  7. //
  8. // Contents: IPSecurity object
  9. //
  10. // History: 21-4-97 SophiaC Created.
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "iis.hxx"
  14. #pragma hdrstop
  15. #define _RDNS_STANDALONE
  16. #define ILIST_DENY 0
  17. #define ILIST_GRANT 1
  18. #define ITYPE_DNS 0
  19. #define ITYPE_IP 1
  20. #define SENTINEL_ADDR "0.0.0.0, 255.255.255.255"
  21. #define DEFAULT_MASK "255.255.255.255"
  22. LPBYTE
  23. GetIp(
  24. LPSTR pArg
  25. );
  26. BOOL
  27. FreeIp(
  28. LPBYTE pIp
  29. );
  30. // Class CIPSecurity
  31. DEFINE_Simple_IDispatch_Implementation(CIPSecurity)
  32. CIPSecurity::CIPSecurity():
  33. _pDispMgr(NULL)
  34. {
  35. ENLIST_TRACKING(CIPSecurity);
  36. }
  37. HRESULT
  38. CIPSecurity::CreateIPSecurity(
  39. REFIID riid,
  40. void **ppvObj
  41. )
  42. {
  43. CIPSecurity FAR * pIPSecurity = NULL;
  44. HRESULT hr = S_OK;
  45. hr = AllocateIPSecurityObject(&pIPSecurity);
  46. BAIL_ON_FAILURE(hr);
  47. hr = pIPSecurity->QueryInterface(riid, ppvObj);
  48. BAIL_ON_FAILURE(hr);
  49. pIPSecurity->Release();
  50. RRETURN(hr);
  51. error:
  52. delete pIPSecurity;
  53. RRETURN(hr);
  54. }
  55. CIPSecurity::~CIPSecurity( )
  56. {
  57. delete _pDispMgr;
  58. _AddrChk.UnbindCheckList();
  59. }
  60. STDMETHODIMP
  61. CIPSecurity::QueryInterface(
  62. REFIID iid,
  63. LPVOID FAR* ppv
  64. )
  65. {
  66. if (IsEqualIID(iid, IID_IUnknown))
  67. {
  68. *ppv = (IISIPSecurity FAR *) this;
  69. }
  70. else if (IsEqualIID(iid, IID_IISIPSecurity))
  71. {
  72. *ppv = (IISIPSecurity FAR *) this;
  73. }
  74. else if (IsEqualIID(iid, IID_IDispatch))
  75. {
  76. *ppv = (IISIPSecurity FAR *) this;
  77. }
  78. else
  79. {
  80. *ppv = NULL;
  81. return E_NOINTERFACE;
  82. }
  83. AddRef();
  84. return NOERROR;
  85. }
  86. HRESULT
  87. CIPSecurity::InitFromBinaryBlob(
  88. LPBYTE pByte,
  89. DWORD dwLength
  90. )
  91. {
  92. DWORD dwDenyEntries, dwGrantEntries;
  93. LPBYTE pBuffer = NULL;
  94. if (pByte && dwLength) {
  95. pBuffer = (LPBYTE) AllocADsMem(dwLength);
  96. if (!pBuffer) {
  97. return(E_OUTOFMEMORY);
  98. }
  99. memcpy(pBuffer, pByte, dwLength);
  100. }
  101. //
  102. // Length of 0 is the default value for empty blob
  103. //
  104. if ((pByte == NULL) || (dwLength == 0)) {
  105. _AddrChk.BindCheckList(NULL, 0);
  106. } else {
  107. _AddrChk.BindCheckList(pBuffer, dwLength);
  108. }
  109. dwDenyEntries = _AddrChk.GetNbAddr(FALSE) +
  110. _AddrChk.GetNbName(FALSE);
  111. dwGrantEntries = _AddrChk.GetNbAddr(TRUE) +
  112. _AddrChk.GetNbName(TRUE);
  113. if (dwGrantEntries > dwDenyEntries) {
  114. _bGrantByDefault = FALSE;
  115. //
  116. // check if entry is a sentinel address
  117. //
  118. if (dwGrantEntries == 1 && _AddrChk.GetNbAddr(TRUE) == 1) {
  119. DWORD dwFlags;
  120. LPBYTE pM;
  121. LPBYTE pA;
  122. CHAR achE[80];
  123. if (_AddrChk.GetAddr(TRUE, 0, &dwFlags, &pM, &pA) == TRUE) {
  124. wsprintfA( (LPSTR)achE, "%d.%d.%d.%d, %d.%d.%d.%d",
  125. pA[3], pA[2], pA[1], pA[0],
  126. pM[3], pM[2], pM[1], pM[0] );
  127. }
  128. if (strcmp(achE, SENTINEL_ADDR) == 0) {
  129. _AddrChk.DeleteAllAddr(TRUE);
  130. }
  131. }
  132. }
  133. else {
  134. _bGrantByDefault = TRUE;
  135. }
  136. return S_OK;
  137. }
  138. HRESULT
  139. CIPSecurity::CopyIPSecurity(
  140. LPBYTE *ppByte,
  141. PDWORD pdwLength
  142. )
  143. {
  144. //
  145. // Remove the other list if default by grant
  146. //
  147. _AddrChk.DeleteAllAddr(_bGrantByDefault);
  148. _AddrChk.DeleteAllName(_bGrantByDefault);
  149. //
  150. // List is empty. If deny by default is on, create
  151. // a dummy sentinel entry to grant access to single
  152. // address 0.0.0.0, otherwise we're ok.
  153. //
  154. if (!_bGrantByDefault &&
  155. !_AddrChk.GetNbAddr(TRUE) &&
  156. !_AddrChk.GetNbName(TRUE)) {
  157. BYTE bMask[4] = { 0xff, 0xff, 0xff, 0xff };
  158. BYTE bIp[4] = { 0, 0, 0, 0 };
  159. _AddrChk.AddAddr(
  160. ILIST_GRANT,
  161. AF_INET,
  162. bMask,
  163. bIp
  164. );
  165. }
  166. *ppByte = _AddrChk.QueryCheckListPtr();
  167. *pdwLength = _AddrChk.QueryCheckListSize();
  168. return S_OK;
  169. }
  170. HRESULT
  171. CIPSecurity::AllocateIPSecurityObject(
  172. CIPSecurity ** ppIPSecurity
  173. )
  174. {
  175. CIPSecurity FAR * pIPSecurity = NULL;
  176. CAggregatorDispMgr FAR * pDispMgr = NULL;
  177. HRESULT hr = S_OK;
  178. pIPSecurity = new CIPSecurity();
  179. if (pIPSecurity == NULL) {
  180. hr = E_OUTOFMEMORY;
  181. }
  182. BAIL_ON_FAILURE(hr);
  183. pDispMgr = new CAggregatorDispMgr;
  184. if (pDispMgr == NULL) {
  185. hr = E_OUTOFMEMORY;
  186. }
  187. BAIL_ON_FAILURE(hr);
  188. hr = pDispMgr->LoadTypeInfoEntry(
  189. LIBID_IISOle,
  190. IID_IISIPSecurity,
  191. (IISIPSecurity *)pIPSecurity,
  192. DISPID_REGULAR
  193. );
  194. BAIL_ON_FAILURE(hr);
  195. pIPSecurity->_pDispMgr = pDispMgr;
  196. *ppIPSecurity = pIPSecurity;
  197. RRETURN(hr);
  198. error:
  199. delete pDispMgr;
  200. RRETURN(hr);
  201. }
  202. STDMETHODIMP
  203. CIPSecurity::get_IPDeny(THIS_ VARIANT FAR * retval)
  204. {
  205. long i = 0;
  206. HRESULT hr = S_OK;
  207. DWORD dwNumEntries = _AddrChk.GetNbAddr(FALSE);
  208. VariantInit(retval);
  209. SAFEARRAY *aList = NULL;
  210. SAFEARRAYBOUND aBound;
  211. aBound.lLbound = 0;
  212. aBound.cElements = dwNumEntries; // number of entries
  213. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  214. if ( aList == NULL )
  215. {
  216. hr = E_OUTOFMEMORY;
  217. BAIL_ON_FAILURE(hr);
  218. }
  219. for ( i = 0; i < (long) dwNumEntries; i++ )
  220. {
  221. VARIANT v;
  222. LPBYTE pByte = NULL;
  223. DWORD dwStatus;
  224. VariantInit(&v);
  225. v.vt = VT_BSTR;
  226. GetEntry(ITYPE_IP, ILIST_DENY, &pByte, i);
  227. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  228. if (pByte) {
  229. FreeADsMem(pByte);
  230. }
  231. BAIL_ON_FAILURE(hr);
  232. hr = SafeArrayPutElement( aList, &i, &v );
  233. VariantClear(&v);
  234. BAIL_ON_FAILURE(hr);
  235. }
  236. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  237. V_ARRAY(retval) = aList;
  238. RRETURN(S_OK);
  239. error:
  240. if ( aList )
  241. SafeArrayDestroy( aList );
  242. RRETURN(hr);
  243. }
  244. STDMETHODIMP
  245. CIPSecurity::put_IPDeny(THIS_ VARIANT pVarIPDeny)
  246. {
  247. VARIANT * pVarArray = NULL;
  248. VARIANT * pvProp = NULL;
  249. VARIANT vVar;
  250. DWORD dwNumValues;
  251. DWORD dwStatus;
  252. DWORD i;
  253. LPSTR pszAnsiName = NULL;
  254. HRESULT hr = S_OK;
  255. VariantInit(&vVar);
  256. VariantCopyInd(&vVar, &pVarIPDeny);
  257. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  258. hr = ConvertArrayToVariantArray(
  259. vVar,
  260. &pVarArray,
  261. &dwNumValues
  262. );
  263. BAIL_ON_FAILURE(hr);
  264. pvProp = pVarArray;
  265. }
  266. else {
  267. dwNumValues = 1;
  268. pvProp = &pVarIPDeny;
  269. }
  270. _AddrChk.DeleteAllAddr(FALSE);
  271. for (i = 0; i < dwNumValues; i++ ) {
  272. dwStatus = AllocAnsi(
  273. (LPWSTR)pvProp->bstrVal,
  274. &pszAnsiName
  275. );
  276. if (dwStatus) {
  277. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  278. }
  279. if (pszAnsiName) {
  280. if (!AddToList(ITYPE_IP, ILIST_DENY, pszAnsiName)) {
  281. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  282. }
  283. FreeAnsi(pszAnsiName);
  284. pszAnsiName = NULL;
  285. BAIL_ON_FAILURE(hr);
  286. }
  287. pvProp++;
  288. }
  289. error:
  290. if (pVarArray) {
  291. for (i = 0; i < dwNumValues; i++) {
  292. VariantClear(pVarArray + i);
  293. }
  294. FreeADsMem(pVarArray);
  295. }
  296. VariantClear(&vVar);
  297. RRETURN(hr);
  298. }
  299. STDMETHODIMP
  300. CIPSecurity::get_IPGrant(THIS_ VARIANT FAR * retval)
  301. {
  302. long i = 0;
  303. HRESULT hr = S_OK;
  304. DWORD dwNumEntries = _AddrChk.GetNbAddr(TRUE);
  305. VariantInit(retval);
  306. SAFEARRAY *aList = NULL;
  307. SAFEARRAYBOUND aBound;
  308. aBound.lLbound = 0;
  309. aBound.cElements = dwNumEntries; // number of entries
  310. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  311. if ( aList == NULL )
  312. {
  313. hr = E_OUTOFMEMORY;
  314. BAIL_ON_FAILURE(hr);
  315. }
  316. for ( i = 0; i < (long) dwNumEntries; i++ )
  317. {
  318. VARIANT v;
  319. LPBYTE pByte = NULL;
  320. DWORD dwStatus;
  321. LPWSTR pszUnicode;
  322. VariantInit(&v);
  323. v.vt = VT_BSTR;
  324. GetEntry(ITYPE_IP, ILIST_GRANT, &pByte, i);
  325. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  326. if (pByte) {
  327. FreeADsMem(pByte);
  328. }
  329. BAIL_ON_FAILURE(hr);
  330. hr = SafeArrayPutElement( aList, &i, &v );
  331. VariantClear(&v);
  332. BAIL_ON_FAILURE(hr);
  333. }
  334. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  335. V_ARRAY(retval) = aList;
  336. RRETURN(S_OK);
  337. error:
  338. if ( aList )
  339. SafeArrayDestroy( aList );
  340. RRETURN(hr);
  341. }
  342. STDMETHODIMP
  343. CIPSecurity::put_IPGrant(THIS_ VARIANT pVarIPGrant)
  344. {
  345. HRESULT hr = S_OK;
  346. VARIANT * pVarArray = NULL;
  347. VARIANT * pvProp = NULL;
  348. VARIANT vVar;
  349. DWORD dwNumValues;
  350. DWORD dwStatus;
  351. DWORD i;
  352. LPSTR pszAnsiName = NULL;
  353. VariantInit(&vVar);
  354. VariantCopyInd(&vVar, &pVarIPGrant);
  355. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  356. hr = ConvertArrayToVariantArray(
  357. vVar,
  358. &pVarArray,
  359. &dwNumValues
  360. );
  361. BAIL_ON_FAILURE(hr);
  362. pvProp = pVarArray;
  363. }
  364. else {
  365. dwNumValues = 1;
  366. pvProp = &pVarIPGrant;
  367. }
  368. _AddrChk.DeleteAllAddr(TRUE);
  369. for (i = 0; i < dwNumValues; i++ ) {
  370. dwStatus = AllocAnsi(
  371. (LPWSTR)pvProp->bstrVal,
  372. &pszAnsiName
  373. );
  374. if (dwStatus) {
  375. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  376. }
  377. if (pszAnsiName) {
  378. if (!AddToList(ITYPE_IP, ILIST_GRANT, pszAnsiName) ) {
  379. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  380. }
  381. FreeAnsi(pszAnsiName);
  382. pszAnsiName = NULL;
  383. BAIL_ON_FAILURE(hr);
  384. }
  385. pvProp++;
  386. }
  387. error:
  388. if (pVarArray) {
  389. for (i = 0; i < dwNumValues; i++) {
  390. VariantClear(pVarArray + i);
  391. }
  392. FreeADsMem(pVarArray);
  393. }
  394. VariantClear(&vVar);
  395. RRETURN(hr);
  396. }
  397. STDMETHODIMP
  398. CIPSecurity::get_DomainDeny(THIS_ VARIANT FAR * retval)
  399. {
  400. long i = 0;
  401. HRESULT hr = S_OK;
  402. DWORD dwNumEntries = _AddrChk.GetNbName(FALSE);
  403. VariantInit(retval);
  404. SAFEARRAY *aList = NULL;
  405. SAFEARRAYBOUND aBound;
  406. aBound.lLbound = 0;
  407. aBound.cElements = dwNumEntries; // number of entries
  408. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  409. if ( aList == NULL )
  410. {
  411. hr = E_OUTOFMEMORY;
  412. BAIL_ON_FAILURE(hr);
  413. }
  414. for ( i = 0; i < (long) dwNumEntries; i++ )
  415. {
  416. VARIANT v;
  417. LPBYTE pByte = NULL;
  418. DWORD dwStatus;
  419. VariantInit(&v);
  420. v.vt = VT_BSTR;
  421. GetEntry(ITYPE_DNS, ILIST_DENY, &pByte, i);
  422. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  423. if (pByte) {
  424. FreeADsMem(pByte);
  425. }
  426. BAIL_ON_FAILURE(hr);
  427. hr = SafeArrayPutElement( aList, &i, &v );
  428. VariantClear(&v);
  429. BAIL_ON_FAILURE(hr);
  430. }
  431. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  432. V_ARRAY(retval) = aList;
  433. RRETURN(S_OK);
  434. error:
  435. if ( aList )
  436. SafeArrayDestroy( aList );
  437. RRETURN(hr);
  438. }
  439. STDMETHODIMP
  440. CIPSecurity::put_DomainDeny(THIS_ VARIANT pVarDomainDeny)
  441. {
  442. HRESULT hr = S_OK;
  443. VARIANT * pVarArray = NULL;
  444. VARIANT * pvProp = NULL;
  445. VARIANT vVar;
  446. DWORD dwNumValues;
  447. DWORD dwStatus;
  448. DWORD i;
  449. LPSTR pszAnsiName = NULL;
  450. VariantInit(&vVar);
  451. VariantCopyInd(&vVar, &pVarDomainDeny);
  452. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  453. hr = ConvertArrayToVariantArray(
  454. vVar,
  455. &pVarArray,
  456. &dwNumValues
  457. );
  458. BAIL_ON_FAILURE(hr);
  459. pvProp = pVarArray;
  460. }
  461. else {
  462. dwNumValues = 1;
  463. pvProp = &pVarDomainDeny;
  464. }
  465. _AddrChk.DeleteAllName(FALSE);
  466. for (i = 0; i < dwNumValues; i++ ) {
  467. dwStatus = AllocAnsi(
  468. (LPWSTR)pvProp->bstrVal,
  469. &pszAnsiName
  470. );
  471. if (dwStatus) {
  472. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  473. }
  474. if (pszAnsiName) {
  475. if (!AddToList(ITYPE_DNS, ILIST_DENY, pszAnsiName)) {
  476. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  477. }
  478. FreeAnsi(pszAnsiName);
  479. pszAnsiName = NULL;
  480. BAIL_ON_FAILURE(hr);
  481. }
  482. pvProp++;
  483. }
  484. error:
  485. if (pVarArray) {
  486. for (i = 0; i < dwNumValues; i++) {
  487. VariantClear(pVarArray + i);
  488. }
  489. FreeADsMem(pVarArray);
  490. }
  491. VariantClear(&vVar);
  492. RRETURN(hr);
  493. }
  494. STDMETHODIMP
  495. CIPSecurity::get_DomainGrant(THIS_ VARIANT FAR * retval)
  496. {
  497. long i = 0;
  498. HRESULT hr = S_OK;
  499. DWORD dwNumEntries = _AddrChk.GetNbName(TRUE);
  500. VariantInit(retval);
  501. SAFEARRAY *aList = NULL;
  502. SAFEARRAYBOUND aBound;
  503. aBound.lLbound = 0;
  504. aBound.cElements = dwNumEntries; // number of entries
  505. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  506. if ( aList == NULL )
  507. {
  508. hr = E_OUTOFMEMORY;
  509. BAIL_ON_FAILURE(hr);
  510. }
  511. for ( i = 0; i < (long) dwNumEntries; i++ )
  512. {
  513. VARIANT v;
  514. LPBYTE pByte = NULL;
  515. DWORD dwStatus;
  516. VariantInit(&v);
  517. v.vt = VT_BSTR;
  518. GetEntry(ITYPE_DNS, ILIST_GRANT, &pByte, i);
  519. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  520. if (pByte) {
  521. FreeADsMem(pByte);
  522. }
  523. BAIL_ON_FAILURE(hr);
  524. hr = SafeArrayPutElement( aList, &i, &v );
  525. VariantClear(&v);
  526. BAIL_ON_FAILURE(hr);
  527. }
  528. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  529. V_ARRAY(retval) = aList;
  530. RRETURN(S_OK);
  531. error:
  532. if ( aList )
  533. SafeArrayDestroy( aList );
  534. RRETURN(hr);
  535. }
  536. STDMETHODIMP
  537. CIPSecurity::put_DomainGrant(THIS_ VARIANT pVarDomainGrant)
  538. {
  539. HRESULT hr = S_OK;
  540. VARIANT * pVarArray = NULL;
  541. VARIANT * pvProp = NULL;
  542. VARIANT vVar;
  543. DWORD dwNumValues;
  544. DWORD dwStatus;
  545. DWORD i;
  546. LPSTR pszAnsiName = NULL;
  547. VariantInit(&vVar);
  548. VariantCopyInd(&vVar, &pVarDomainGrant);
  549. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  550. hr = ConvertArrayToVariantArray(
  551. vVar,
  552. &pVarArray,
  553. &dwNumValues
  554. );
  555. BAIL_ON_FAILURE(hr);
  556. pvProp = pVarArray;
  557. }
  558. else {
  559. dwNumValues = 1;
  560. pvProp = &pVarDomainGrant;
  561. }
  562. _AddrChk.DeleteAllName(TRUE);
  563. for (i = 0; i < dwNumValues; i++ ) {
  564. dwStatus = AllocAnsi(
  565. (LPWSTR)pvProp->bstrVal,
  566. &pszAnsiName
  567. );
  568. if (dwStatus) {
  569. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  570. }
  571. if (pszAnsiName) {
  572. if (!AddToList(ITYPE_DNS, ILIST_GRANT, pszAnsiName)) {
  573. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  574. }
  575. FreeAnsi(pszAnsiName);
  576. pszAnsiName = NULL;
  577. BAIL_ON_FAILURE(hr);
  578. }
  579. pvProp++;
  580. }
  581. error:
  582. if (pVarArray) {
  583. for (i = 0; i < dwNumValues; i++) {
  584. VariantClear(pVarArray + i);
  585. }
  586. FreeADsMem(pVarArray);
  587. }
  588. VariantClear(&vVar);
  589. RRETURN(hr);
  590. }
  591. STDMETHODIMP
  592. CIPSecurity::get_GrantByDefault(THIS_ VARIANT_BOOL FAR * retval)
  593. {
  594. *retval = _bGrantByDefault ? VARIANT_TRUE : VARIANT_FALSE;
  595. RRETURN(S_OK);
  596. }
  597. STDMETHODIMP
  598. CIPSecurity::put_GrantByDefault(THIS_ VARIANT_BOOL bGrantByDefault)
  599. {
  600. _bGrantByDefault = bGrantByDefault ? TRUE : FALSE;
  601. RRETURN(S_OK);
  602. }
  603. /* INTRINSA suppress=null_pointers */
  604. BOOL
  605. CIPSecurity::AddToList(
  606. int iType,
  607. int iList,
  608. LPSTR pArg
  609. )
  610. {
  611. BOOL fSt;
  612. LPBYTE pMask = NULL;
  613. LPBYTE pAddr = NULL;
  614. DWORD dwFlags = 0;
  615. int * piArg;
  616. switch ( iType )
  617. {
  618. case ITYPE_IP:
  619. if (pAddr = GetIp( strtok(pArg,",") ))
  620. {
  621. pMask = GetIp( pArg+strlen(pArg)+1 );
  622. if (!pMask) {
  623. pMask = GetIp(DEFAULT_MASK);
  624. }
  625. fSt = _AddrChk.AddAddr( iList, AF_INET, pMask, pAddr );
  626. }
  627. else
  628. {
  629. fSt = FALSE;
  630. }
  631. FreeIp( pMask );
  632. FreeIp( pAddr );
  633. return fSt;
  634. case ITYPE_DNS:
  635. if ( !strncmp( pArg, "*.", 2 ) )
  636. {
  637. pArg += 2;
  638. }
  639. else
  640. {
  641. dwFlags |= DNSLIST_FLAG_NOSUBDOMAIN;
  642. }
  643. return _AddrChk.AddName( iList, pArg, dwFlags );
  644. break;
  645. }
  646. return FALSE;
  647. }
  648. BOOL
  649. CIPSecurity::GetEntry(
  650. int iType,
  651. int iList,
  652. LPBYTE * ppbyte,
  653. int dwEntry
  654. )
  655. {
  656. UINT i;
  657. UINT x;
  658. DWORD dwF;
  659. DWORD dwStatus;
  660. BOOL fSt = FALSE;
  661. LPWSTR pszStr = NULL;
  662. *ppbyte = NULL;
  663. switch ( iType )
  664. {
  665. case ITYPE_IP:
  666. LPBYTE pM;
  667. LPBYTE pA;
  668. CHAR achE[80];
  669. fSt = _AddrChk.GetAddr( iList, dwEntry, &dwF, &pM, &pA );
  670. if (fSt) {
  671. wsprintfA( (LPSTR)achE, "%d.%d.%d.%d, %d.%d.%d.%d",
  672. pA[0], pA[1], pA[2], pA[3],
  673. pM[0], pM[1], pM[2], pM[3] );
  674. dwStatus = AllocUnicode(
  675. (LPSTR)achE,
  676. &pszStr
  677. );
  678. if (dwStatus == ERROR_SUCCESS) {
  679. *ppbyte = (LPBYTE) pszStr;
  680. }
  681. else {
  682. fSt = FALSE;
  683. }
  684. }
  685. break;
  686. case ITYPE_DNS:
  687. LPSTR pN;
  688. DWORD dwLen;
  689. UINT err;
  690. // Use break to exit on error condition
  691. fSt = _AddrChk.GetName( iList, dwEntry, &pN, &dwF );
  692. if( !fSt )
  693. {
  694. break;
  695. }
  696. dwLen = strlen(pN) + 1;
  697. // pszStr is the working copy of our memory
  698. // *ppbyte is the data to be returned
  699. if ( dwF & DNSLIST_FLAG_NOSUBDOMAIN )
  700. {
  701. pszStr = (LPWSTR) AllocADsMem(dwLen*sizeof(WCHAR));
  702. if( !pszStr )
  703. {
  704. fSt = FALSE;
  705. break;
  706. }
  707. *ppbyte = (LPBYTE)pszStr;
  708. }
  709. else
  710. {
  711. // In this case we have a subdomain restriction, so
  712. // we want to pre-pend "*." to the string.
  713. pszStr = (LPWSTR) AllocADsMem((dwLen+2)*sizeof(WCHAR));
  714. if( !pszStr )
  715. {
  716. fSt = FALSE;
  717. break;
  718. }
  719. // Save the address to return
  720. *ppbyte = (LPBYTE)pszStr;
  721. wcscpy((LPWSTR)pszStr, L"*.");
  722. pszStr += wcslen(pszStr);
  723. }
  724. err = (UINT) !MultiByteToWideChar(CP_ACP,
  725. MB_PRECOMPOSED,
  726. pN,
  727. dwLen,
  728. pszStr,
  729. dwLen);
  730. if (err)
  731. {
  732. FreeADsMem( *ppbyte );
  733. *ppbyte = NULL;
  734. fSt = FALSE;
  735. break;
  736. }
  737. // Final break
  738. break;
  739. }
  740. return fSt;
  741. }
  742. LPBYTE
  743. GetIp(
  744. LPSTR pArg
  745. )
  746. {
  747. if (pArg)
  748. {
  749. LPBYTE p;
  750. if ( p = (LPBYTE)LocalAlloc( LMEM_FIXED, 4 ) )
  751. {
  752. int p0, p1, p2, p3;
  753. if ( sscanf( pArg, "%d.%d.%d.%d", &p0, &p1, &p2, &p3 ) == 4 )
  754. {
  755. //
  756. // network byte order
  757. //
  758. p[3] = (BYTE)(p3 & 0xFF);
  759. p[2] = (BYTE)(p2 & 0xFF);
  760. p[1] = (BYTE)(p1 & 0xFF);
  761. p[0] = (BYTE)(p0 & 0xFF);
  762. return p;
  763. }
  764. LocalFree( p );
  765. return NULL;
  766. }
  767. }
  768. return NULL;
  769. }
  770. BOOL
  771. FreeIp(
  772. LPBYTE pIp
  773. )
  774. {
  775. if ( pIp )
  776. {
  777. LocalFree( pIp );
  778. }
  779. return TRUE;
  780. }
  781. typedef
  782. VOID
  783. (* PFN_SCHED_CALLBACK)(
  784. VOID * pContext
  785. );
  786. dllexp
  787. DWORD
  788. ScheduleWorkItem(
  789. PFN_SCHED_CALLBACK pfnCallback,
  790. PVOID pContext,
  791. DWORD msecTimeInterval,
  792. BOOL fPeriodic = FALSE
  793. )
  794. {
  795. return 0;
  796. }
  797. dllexp
  798. BOOL
  799. RemoveWorkItem(
  800. DWORD pdwCookie
  801. )
  802. {
  803. return FALSE;
  804. }