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.

1051 lines
22 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. if (pIPSecurity)
  186. {
  187. delete pIPSecurity;
  188. }
  189. hr = E_OUTOFMEMORY;
  190. }
  191. BAIL_ON_FAILURE(hr);
  192. hr = pDispMgr->LoadTypeInfoEntry(
  193. LIBID_IISOle,
  194. IID_IISIPSecurity,
  195. (IISIPSecurity *)pIPSecurity,
  196. DISPID_REGULAR
  197. );
  198. BAIL_ON_FAILURE(hr);
  199. pIPSecurity->_pDispMgr = pDispMgr;
  200. *ppIPSecurity = pIPSecurity;
  201. RRETURN(hr);
  202. error:
  203. if (pDispMgr)
  204. {
  205. delete pDispMgr;
  206. }
  207. RRETURN(hr);
  208. }
  209. STDMETHODIMP
  210. CIPSecurity::get_IPDeny(THIS_ VARIANT FAR * retval)
  211. {
  212. long i = 0;
  213. HRESULT hr = S_OK;
  214. DWORD dwNumEntries = _AddrChk.GetNbAddr(FALSE);
  215. VariantInit(retval);
  216. SAFEARRAY *aList = NULL;
  217. SAFEARRAYBOUND aBound;
  218. aBound.lLbound = 0;
  219. aBound.cElements = dwNumEntries; // number of entries
  220. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  221. if ( aList == NULL )
  222. {
  223. hr = E_OUTOFMEMORY;
  224. BAIL_ON_FAILURE(hr);
  225. }
  226. for ( i = 0; i < (long) dwNumEntries; i++ )
  227. {
  228. VARIANT v;
  229. LPBYTE pByte = NULL;
  230. VariantInit(&v);
  231. v.vt = VT_BSTR;
  232. GetEntry(ITYPE_IP, ILIST_DENY, &pByte, i);
  233. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  234. if (pByte) {
  235. FreeADsMem(pByte);
  236. }
  237. BAIL_ON_FAILURE(hr);
  238. hr = SafeArrayPutElement( aList, &i, &v );
  239. VariantClear(&v);
  240. BAIL_ON_FAILURE(hr);
  241. }
  242. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  243. V_ARRAY(retval) = aList;
  244. RRETURN(S_OK);
  245. error:
  246. if ( aList )
  247. SafeArrayDestroy( aList );
  248. RRETURN(hr);
  249. }
  250. STDMETHODIMP
  251. CIPSecurity::put_IPDeny(THIS_ VARIANT pVarIPDeny)
  252. {
  253. VARIANT * pVarArray = NULL;
  254. VARIANT * pvProp = NULL;
  255. VARIANT vVar;
  256. DWORD dwNumValues;
  257. DWORD dwStatus;
  258. DWORD i;
  259. LPSTR pszAnsiName = NULL;
  260. HRESULT hr = S_OK;
  261. VariantInit(&vVar);
  262. hr = VariantCopyInd(&vVar, &pVarIPDeny);
  263. BAIL_ON_FAILURE(hr);
  264. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  265. hr = ConvertArrayToVariantArray(
  266. vVar,
  267. &pVarArray,
  268. &dwNumValues
  269. );
  270. BAIL_ON_FAILURE(hr);
  271. pvProp = pVarArray;
  272. }
  273. else {
  274. dwNumValues = 1;
  275. pvProp = &pVarIPDeny;
  276. }
  277. _AddrChk.DeleteAllAddr(FALSE);
  278. for (i = 0; i < dwNumValues; i++ ) {
  279. dwStatus = AllocAnsi(
  280. (LPWSTR)pvProp->bstrVal,
  281. &pszAnsiName
  282. );
  283. if (dwStatus) {
  284. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  285. }
  286. if (pszAnsiName) {
  287. if (!AddToList(ITYPE_IP, ILIST_DENY, pszAnsiName)) {
  288. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  289. }
  290. FreeAnsi(pszAnsiName);
  291. pszAnsiName = NULL;
  292. BAIL_ON_FAILURE(hr);
  293. }
  294. pvProp++;
  295. }
  296. error:
  297. if (pVarArray) {
  298. for (i = 0; i < dwNumValues; i++) {
  299. VariantClear(pVarArray + i);
  300. }
  301. FreeADsMem(pVarArray);
  302. }
  303. VariantClear(&vVar);
  304. RRETURN(hr);
  305. }
  306. STDMETHODIMP
  307. CIPSecurity::get_IPGrant(THIS_ VARIANT FAR * retval)
  308. {
  309. long i = 0;
  310. HRESULT hr = S_OK;
  311. DWORD dwNumEntries = _AddrChk.GetNbAddr(TRUE);
  312. VariantInit(retval);
  313. SAFEARRAY *aList = NULL;
  314. SAFEARRAYBOUND aBound;
  315. aBound.lLbound = 0;
  316. aBound.cElements = dwNumEntries; // number of entries
  317. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  318. if ( aList == NULL )
  319. {
  320. hr = E_OUTOFMEMORY;
  321. BAIL_ON_FAILURE(hr);
  322. }
  323. for ( i = 0; i < (long) dwNumEntries; i++ )
  324. {
  325. VARIANT v;
  326. LPBYTE pByte = NULL;
  327. VariantInit(&v);
  328. v.vt = VT_BSTR;
  329. GetEntry(ITYPE_IP, ILIST_GRANT, &pByte, i);
  330. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  331. if (pByte) {
  332. FreeADsMem(pByte);
  333. }
  334. BAIL_ON_FAILURE(hr);
  335. hr = SafeArrayPutElement( aList, &i, &v );
  336. VariantClear(&v);
  337. BAIL_ON_FAILURE(hr);
  338. }
  339. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  340. V_ARRAY(retval) = aList;
  341. RRETURN(S_OK);
  342. error:
  343. if ( aList )
  344. SafeArrayDestroy( aList );
  345. RRETURN(hr);
  346. }
  347. STDMETHODIMP
  348. CIPSecurity::put_IPGrant(THIS_ VARIANT pVarIPGrant)
  349. {
  350. HRESULT hr = S_OK;
  351. VARIANT * pVarArray = NULL;
  352. VARIANT * pvProp = NULL;
  353. VARIANT vVar;
  354. DWORD dwNumValues;
  355. DWORD dwStatus;
  356. DWORD i;
  357. LPSTR pszAnsiName = NULL;
  358. VariantInit(&vVar);
  359. hr = VariantCopyInd(&vVar, &pVarIPGrant);
  360. BAIL_ON_FAILURE(hr);
  361. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  362. hr = ConvertArrayToVariantArray(
  363. vVar,
  364. &pVarArray,
  365. &dwNumValues
  366. );
  367. BAIL_ON_FAILURE(hr);
  368. pvProp = pVarArray;
  369. }
  370. else {
  371. dwNumValues = 1;
  372. pvProp = &pVarIPGrant;
  373. }
  374. _AddrChk.DeleteAllAddr(TRUE);
  375. for (i = 0; i < dwNumValues; i++ ) {
  376. dwStatus = AllocAnsi(
  377. (LPWSTR)pvProp->bstrVal,
  378. &pszAnsiName
  379. );
  380. if (dwStatus) {
  381. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  382. }
  383. if (pszAnsiName) {
  384. if (!AddToList(ITYPE_IP, ILIST_GRANT, pszAnsiName) ) {
  385. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  386. }
  387. FreeAnsi(pszAnsiName);
  388. pszAnsiName = NULL;
  389. BAIL_ON_FAILURE(hr);
  390. }
  391. pvProp++;
  392. }
  393. error:
  394. if (pVarArray) {
  395. for (i = 0; i < dwNumValues; i++) {
  396. VariantClear(pVarArray + i);
  397. }
  398. FreeADsMem(pVarArray);
  399. }
  400. VariantClear(&vVar);
  401. RRETURN(hr);
  402. }
  403. STDMETHODIMP
  404. CIPSecurity::get_DomainDeny(THIS_ VARIANT FAR * retval)
  405. {
  406. long i = 0;
  407. HRESULT hr = S_OK;
  408. DWORD dwNumEntries = _AddrChk.GetNbName(FALSE);
  409. VariantInit(retval);
  410. SAFEARRAY *aList = NULL;
  411. SAFEARRAYBOUND aBound;
  412. aBound.lLbound = 0;
  413. aBound.cElements = dwNumEntries; // number of entries
  414. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  415. if ( aList == NULL )
  416. {
  417. hr = E_OUTOFMEMORY;
  418. BAIL_ON_FAILURE(hr);
  419. }
  420. for ( i = 0; i < (long) dwNumEntries; i++ )
  421. {
  422. VARIANT v;
  423. LPBYTE pByte = NULL;
  424. VariantInit(&v);
  425. v.vt = VT_BSTR;
  426. GetEntry(ITYPE_DNS, ILIST_DENY, &pByte, i);
  427. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  428. if (pByte) {
  429. FreeADsMem(pByte);
  430. }
  431. BAIL_ON_FAILURE(hr);
  432. hr = SafeArrayPutElement( aList, &i, &v );
  433. VariantClear(&v);
  434. BAIL_ON_FAILURE(hr);
  435. }
  436. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  437. V_ARRAY(retval) = aList;
  438. RRETURN(S_OK);
  439. error:
  440. if ( aList )
  441. SafeArrayDestroy( aList );
  442. RRETURN(hr);
  443. }
  444. STDMETHODIMP
  445. CIPSecurity::put_DomainDeny(THIS_ VARIANT pVarDomainDeny)
  446. {
  447. HRESULT hr = S_OK;
  448. VARIANT * pVarArray = NULL;
  449. VARIANT * pvProp = NULL;
  450. VARIANT vVar;
  451. DWORD dwNumValues;
  452. DWORD dwStatus;
  453. DWORD i;
  454. LPSTR pszAnsiName = NULL;
  455. VariantInit(&vVar);
  456. hr = VariantCopyInd(&vVar, &pVarDomainDeny);
  457. BAIL_ON_FAILURE(hr);
  458. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  459. hr = ConvertArrayToVariantArray(
  460. vVar,
  461. &pVarArray,
  462. &dwNumValues
  463. );
  464. BAIL_ON_FAILURE(hr);
  465. pvProp = pVarArray;
  466. }
  467. else {
  468. dwNumValues = 1;
  469. pvProp = &pVarDomainDeny;
  470. }
  471. _AddrChk.DeleteAllName(FALSE);
  472. for (i = 0; i < dwNumValues; i++ ) {
  473. dwStatus = AllocAnsi(
  474. (LPWSTR)pvProp->bstrVal,
  475. &pszAnsiName
  476. );
  477. if (dwStatus) {
  478. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  479. }
  480. if (pszAnsiName) {
  481. if (!AddToList(ITYPE_DNS, ILIST_DENY, pszAnsiName)) {
  482. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  483. }
  484. FreeAnsi(pszAnsiName);
  485. pszAnsiName = NULL;
  486. BAIL_ON_FAILURE(hr);
  487. }
  488. pvProp++;
  489. }
  490. error:
  491. if (pVarArray) {
  492. for (i = 0; i < dwNumValues; i++) {
  493. VariantClear(pVarArray + i);
  494. }
  495. FreeADsMem(pVarArray);
  496. }
  497. VariantClear(&vVar);
  498. RRETURN(hr);
  499. }
  500. STDMETHODIMP
  501. CIPSecurity::get_DomainGrant(THIS_ VARIANT FAR * retval)
  502. {
  503. long i = 0;
  504. HRESULT hr = S_OK;
  505. DWORD dwNumEntries = _AddrChk.GetNbName(TRUE);
  506. VariantInit(retval);
  507. SAFEARRAY *aList = NULL;
  508. SAFEARRAYBOUND aBound;
  509. aBound.lLbound = 0;
  510. aBound.cElements = dwNumEntries; // number of entries
  511. aList = SafeArrayCreate( VT_VARIANT, 1, &aBound );
  512. if ( aList == NULL )
  513. {
  514. hr = E_OUTOFMEMORY;
  515. BAIL_ON_FAILURE(hr);
  516. }
  517. for ( i = 0; i < (long) dwNumEntries; i++ )
  518. {
  519. VARIANT v;
  520. LPBYTE pByte = NULL;
  521. VariantInit(&v);
  522. v.vt = VT_BSTR;
  523. GetEntry(ITYPE_DNS, ILIST_GRANT, &pByte, i);
  524. hr = ADsAllocString((LPWSTR)pByte, &(v.bstrVal));
  525. if (pByte) {
  526. FreeADsMem(pByte);
  527. }
  528. BAIL_ON_FAILURE(hr);
  529. hr = SafeArrayPutElement( aList, &i, &v );
  530. VariantClear(&v);
  531. BAIL_ON_FAILURE(hr);
  532. }
  533. V_VT(retval) = VT_ARRAY | VT_VARIANT;
  534. V_ARRAY(retval) = aList;
  535. RRETURN(S_OK);
  536. error:
  537. if ( aList )
  538. SafeArrayDestroy( aList );
  539. RRETURN(hr);
  540. }
  541. STDMETHODIMP
  542. CIPSecurity::put_DomainGrant(THIS_ VARIANT pVarDomainGrant)
  543. {
  544. HRESULT hr = S_OK;
  545. VARIANT * pVarArray = NULL;
  546. VARIANT * pvProp = NULL;
  547. VARIANT vVar;
  548. DWORD dwNumValues;
  549. DWORD dwStatus;
  550. DWORD i;
  551. LPSTR pszAnsiName = NULL;
  552. VariantInit(&vVar);
  553. hr = VariantCopyInd(&vVar, &pVarDomainGrant);
  554. BAIL_ON_FAILURE(hr);
  555. if ((V_VT(&vVar) & VT_VARIANT) && V_ISARRAY(&vVar)) {
  556. hr = ConvertArrayToVariantArray(
  557. vVar,
  558. &pVarArray,
  559. &dwNumValues
  560. );
  561. BAIL_ON_FAILURE(hr);
  562. pvProp = pVarArray;
  563. }
  564. else {
  565. dwNumValues = 1;
  566. pvProp = &pVarDomainGrant;
  567. }
  568. _AddrChk.DeleteAllName(TRUE);
  569. for (i = 0; i < dwNumValues; i++ ) {
  570. dwStatus = AllocAnsi(
  571. (LPWSTR)pvProp->bstrVal,
  572. &pszAnsiName
  573. );
  574. if (dwStatus) {
  575. BAIL_ON_FAILURE(hr = HRESULT_FROM_WIN32(dwStatus));
  576. }
  577. if (pszAnsiName) {
  578. if (!AddToList(ITYPE_DNS, ILIST_GRANT, pszAnsiName)) {
  579. hr = RETURNCODETOHRESULT(ERROR_INVALID_PARAMETER);
  580. }
  581. FreeAnsi(pszAnsiName);
  582. pszAnsiName = NULL;
  583. BAIL_ON_FAILURE(hr);
  584. }
  585. pvProp++;
  586. }
  587. error:
  588. if (pVarArray) {
  589. for (i = 0; i < dwNumValues; i++) {
  590. VariantClear(pVarArray + i);
  591. }
  592. FreeADsMem(pVarArray);
  593. }
  594. VariantClear(&vVar);
  595. RRETURN(hr);
  596. }
  597. STDMETHODIMP
  598. CIPSecurity::get_GrantByDefault(THIS_ VARIANT_BOOL FAR * retval)
  599. {
  600. *retval = _bGrantByDefault ? VARIANT_TRUE : VARIANT_FALSE;
  601. RRETURN(S_OK);
  602. }
  603. STDMETHODIMP
  604. CIPSecurity::put_GrantByDefault(THIS_ VARIANT_BOOL bGrantByDefault)
  605. {
  606. _bGrantByDefault = bGrantByDefault ? TRUE : FALSE;
  607. RRETURN(S_OK);
  608. }
  609. /* INTRINSA suppress=null_pointers */
  610. BOOL
  611. CIPSecurity::AddToList(
  612. int iType,
  613. int iList,
  614. LPSTR pArg
  615. )
  616. {
  617. BOOL fSt;
  618. LPBYTE pMask = NULL;
  619. LPBYTE pAddr = NULL;
  620. char* pComma= NULL;
  621. DWORD dwFlags = 0;
  622. switch ( iType )
  623. {
  624. case ITYPE_IP:
  625. pComma = strstr(pArg, ",");
  626. if (NULL == pComma) {
  627. pMask = GetIp(DEFAULT_MASK);
  628. }
  629. else {
  630. pMask = GetIp(pComma+1);
  631. }
  632. if (pComma) {
  633. *pComma = 0;
  634. }
  635. pAddr = GetIp(pArg);
  636. if (pMask && pAddr)
  637. {
  638. fSt = _AddrChk.AddAddr( iList, AF_INET, pMask, pAddr );
  639. }
  640. else
  641. {
  642. fSt = FALSE;
  643. }
  644. FreeIp( pMask );
  645. FreeIp( pAddr );
  646. return fSt;
  647. case ITYPE_DNS:
  648. if ( !strncmp( pArg, "*.", 2 ) )
  649. {
  650. pArg += 2;
  651. }
  652. else
  653. {
  654. dwFlags |= DNSLIST_FLAG_NOSUBDOMAIN;
  655. }
  656. return _AddrChk.AddName( iList, pArg, dwFlags );
  657. break;
  658. }
  659. return FALSE;
  660. }
  661. BOOL
  662. CIPSecurity::GetEntry(
  663. int iType,
  664. int iList,
  665. LPBYTE * ppbyte,
  666. int dwEntry
  667. )
  668. {
  669. DWORD dwF;
  670. DWORD dwStatus;
  671. BOOL fSt = FALSE;
  672. LPWSTR pszStr = NULL;
  673. *ppbyte = NULL;
  674. switch ( iType )
  675. {
  676. case ITYPE_IP:
  677. LPBYTE pM;
  678. LPBYTE pA;
  679. CHAR achE[80];
  680. fSt = _AddrChk.GetAddr( iList, dwEntry, &dwF, &pM, &pA );
  681. if (fSt) {
  682. wsprintfA( (LPSTR)achE, "%d.%d.%d.%d, %d.%d.%d.%d",
  683. pA[0], pA[1], pA[2], pA[3],
  684. pM[0], pM[1], pM[2], pM[3] );
  685. dwStatus = AllocUnicode(
  686. (LPSTR)achE,
  687. &pszStr
  688. );
  689. if (dwStatus == ERROR_SUCCESS) {
  690. *ppbyte = (LPBYTE) pszStr;
  691. }
  692. else {
  693. fSt = FALSE;
  694. }
  695. }
  696. break;
  697. case ITYPE_DNS:
  698. LPSTR pN;
  699. DWORD dwLen;
  700. UINT err;
  701. // Use break to exit on error condition
  702. fSt = _AddrChk.GetName( iList, dwEntry, &pN, &dwF );
  703. if( !fSt )
  704. {
  705. break;
  706. }
  707. dwLen = (DWORD)strlen(pN) + 1;
  708. // pszStr is the working copy of our memory
  709. // *ppbyte is the data to be returned
  710. if ( dwF & DNSLIST_FLAG_NOSUBDOMAIN )
  711. {
  712. pszStr = (LPWSTR) AllocADsMem(dwLen*sizeof(WCHAR));
  713. if( !pszStr )
  714. {
  715. fSt = FALSE;
  716. break;
  717. }
  718. *ppbyte = (LPBYTE)pszStr;
  719. }
  720. else
  721. {
  722. // In this case we have a subdomain restriction, so
  723. // we want to pre-pend "*." to the string.
  724. pszStr = (LPWSTR) AllocADsMem((dwLen+2)*sizeof(WCHAR));
  725. if( !pszStr )
  726. {
  727. fSt = FALSE;
  728. break;
  729. }
  730. // Save the address to return
  731. *ppbyte = (LPBYTE)pszStr;
  732. wcscpy((LPWSTR)pszStr, L"*.");
  733. pszStr += wcslen(pszStr);
  734. }
  735. err = (UINT) !MultiByteToWideChar(CP_ACP,
  736. MB_PRECOMPOSED,
  737. pN,
  738. dwLen,
  739. pszStr,
  740. dwLen);
  741. if (err)
  742. {
  743. FreeADsMem( *ppbyte );
  744. *ppbyte = NULL;
  745. fSt = FALSE;
  746. break;
  747. }
  748. // Final break
  749. break;
  750. }
  751. return fSt;
  752. }
  753. LPBYTE
  754. GetIp(
  755. LPSTR pArg
  756. )
  757. {
  758. if (pArg)
  759. {
  760. LPBYTE p;
  761. p = (LPBYTE)LocalAlloc( LMEM_FIXED, 4 );
  762. if ( p )
  763. {
  764. int p0, p1, p2, p3;
  765. if ( sscanf( pArg, "%d.%d.%d.%d", &p0, &p1, &p2, &p3 ) == 4 )
  766. {
  767. //
  768. // network byte order
  769. //
  770. p[3] = (BYTE)(p3 & 0xFF);
  771. p[2] = (BYTE)(p2 & 0xFF);
  772. p[1] = (BYTE)(p1 & 0xFF);
  773. p[0] = (BYTE)(p0 & 0xFF);
  774. return p;
  775. }
  776. LocalFree( p );
  777. return NULL;
  778. }
  779. }
  780. return NULL;
  781. }
  782. BOOL
  783. FreeIp(
  784. LPBYTE pIp
  785. )
  786. {
  787. if ( pIp )
  788. {
  789. LocalFree( pIp );
  790. }
  791. return TRUE;
  792. }
  793. typedef
  794. VOID
  795. (* PFN_SCHED_CALLBACK)(
  796. VOID * pContext
  797. );
  798. dllexp
  799. DWORD
  800. ScheduleWorkItem(
  801. PFN_SCHED_CALLBACK pfnCallback,
  802. PVOID pContext,
  803. DWORD msecTimeInterval,
  804. BOOL fPeriodic = FALSE
  805. )
  806. {
  807. return 0;
  808. }
  809. dllexp
  810. BOOL
  811. RemoveWorkItem(
  812. DWORD pdwCookie
  813. )
  814. {
  815. return FALSE;
  816. }