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.

888 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: policy.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // policy.h: Declaration of CCertPolicyEnterprise
  11. #include "resource.h"
  12. #include <certca.h>
  13. #include <userenv.h>
  14. #include <dsgetdc.h>
  15. #include <winldap.h>
  16. /////////////////////////////////////////////////////////////////////////////
  17. // certpol
  18. extern HANDLE g_hEventLog;
  19. extern HINSTANCE g_hInstance;
  20. #define MAX_INSERTION_ARRAY_SIZE 100
  21. #define B3_VERSION_NUMBER 2031
  22. #define CONFIGURE_EVENT_FORMAT TEXT("CA Configuration %ls")
  23. #define DS_ATTR_COMMON_NAME L"cn"
  24. //#define DS_ATTR_DISTINGUISHED_NAME L"distinguishedName"
  25. #define DS_ATTR_DNS_NAME L"dNSHostName"
  26. #define DS_ATTR_EMAIL_ADDR L"mail"
  27. #define DS_ATTR_OBJECT_GUID L"objectGUID"
  28. #define DS_ATTR_UPN L"userPrincipalName"
  29. class CTemplatePolicy;
  30. HRESULT
  31. polGetProperty(
  32. IN ICertServerPolicy *pServer,
  33. IN BOOL fRequest,
  34. IN WCHAR const *pwszPropertyName,
  35. IN DWORD PropType,
  36. OUT VARIANT *pvarOut);
  37. HRESULT
  38. polBuildErrorInfo(
  39. IN HRESULT hrLog,
  40. IN DWORD dwLogId,
  41. IN WCHAR const *pwszDescription,
  42. IN WCHAR const * const *ppwszInsert, // array of insert strings
  43. OPTIONAL IN OUT ICreateErrorInfo **ppCreateErrorInfo);
  44. HRESULT
  45. TPInitialize(
  46. IN ICertServerPolicy *pServer);
  47. VOID
  48. TPCleanup();
  49. // begin_sdksample
  50. HRESULT
  51. ReqInitialize(
  52. IN ICertServerPolicy *pServer);
  53. VOID
  54. ReqCleanup(VOID);
  55. class CRequestInstance;
  56. #ifndef __BSTRC__DEFINED__
  57. #define __BSTRC__DEFINED__
  58. typedef OLECHAR const *BSTRC;
  59. #endif
  60. HRESULT
  61. polGetServerCallbackInterface(
  62. OUT ICertServerPolicy **ppServer,
  63. IN LONG Context);
  64. HRESULT
  65. polGetRequestStringProperty(
  66. IN ICertServerPolicy *pServer,
  67. IN WCHAR const *pwszPropertyName,
  68. OUT BSTR *pstrOut);
  69. HRESULT
  70. polGetCertificateStringProperty(
  71. IN ICertServerPolicy *pServer,
  72. IN WCHAR const *pwszPropertyName,
  73. OUT BSTR *pstrOut);
  74. HRESULT
  75. polGetRequestLongProperty(
  76. IN ICertServerPolicy *pServer,
  77. IN WCHAR const *pwszPropertyName,
  78. OUT LONG *plOut);
  79. HRESULT
  80. polGetCertificateLongProperty(
  81. IN ICertServerPolicy *pServer,
  82. IN WCHAR const *pwszPropertyName,
  83. OUT LONG *plOut);
  84. HRESULT
  85. polGetRequestAttribute(
  86. IN ICertServerPolicy *pServer,
  87. IN WCHAR const *pwszAttributeName,
  88. OUT BSTR *pstrOut);
  89. HRESULT
  90. polGetCertificateExtension(
  91. IN ICertServerPolicy *pServer,
  92. IN WCHAR const *pwszExtensionName,
  93. IN DWORD dwPropType,
  94. IN OUT VARIANT *pvarOut);
  95. HRESULT
  96. polSetCertificateExtension(
  97. IN ICertServerPolicy *pServer,
  98. IN WCHAR const *pwszExtensionName,
  99. IN DWORD dwPropType,
  100. IN DWORD dwExtFlags,
  101. IN VARIANT const *pvarIn);
  102. DWORD
  103. polFindObjIdInList(
  104. IN WCHAR const *pwsz,
  105. IN DWORD count,
  106. IN WCHAR const * const *ppwsz);
  107. //
  108. // Class CCertPolicyEnterprise
  109. //
  110. // Actual policy module for a CA Policy
  111. //
  112. //
  113. class CCertPolicyEnterprise:
  114. public CComDualImpl<ICertPolicy2, &IID_ICertPolicy2, &LIBID_CERTPOLICYLib>,
  115. public ISupportErrorInfo,
  116. public CComObjectRoot,
  117. public CComCoClass<CCertPolicyEnterprise, &CLSID_CCertPolicy>
  118. {
  119. public:
  120. CCertPolicyEnterprise()
  121. {
  122. m_strDescription = NULL;
  123. // RevocationExtension variables:
  124. m_dwRevocationFlags = 0;
  125. m_wszASPRevocationURL = NULL;
  126. m_dwDispositionFlags = 0;
  127. m_dwEditFlags = 0;
  128. m_cEnableRequestExtensions = 0;
  129. m_apwszEnableRequestExtensions = NULL;
  130. m_cEnableEnrolleeRequestExtensions = 0;
  131. m_apwszEnableEnrolleeRequestExtensions = NULL;
  132. m_cDisableExtensions = 0;
  133. m_apwszDisableExtensions = NULL;
  134. // CA Name
  135. m_strRegStorageLoc = NULL;
  136. m_strCAName = NULL;
  137. m_strCASanitizedName = NULL;
  138. m_strCASanitizedDSName = NULL;
  139. m_strMachineDNSName = NULL;
  140. // CA and cert type info
  141. m_CAType = ENUM_UNKNOWN_CA;
  142. m_pCert = NULL;
  143. m_iCRL = 0;
  144. // end_sdksample
  145. //+--------------------------------------
  146. // CertTypeExtension variables:
  147. m_astrSubjectAltNameProp[0] = NULL;
  148. m_astrSubjectAltNameProp[1] = NULL;
  149. m_astrSubjectAltNameObjectId[0] = NULL;
  150. m_astrSubjectAltNameObjectId[1] = NULL;
  151. m_fTemplateCriticalSection = FALSE;
  152. m_pCreateErrorInfo = NULL;
  153. m_pbSMIME = NULL;
  154. m_fUseDS = FALSE;
  155. m_dwLogLevel = CERTLOG_WARNING;
  156. m_pld = NULL;
  157. m_pwszHostName = NULL;
  158. m_hCertTypeQuery = NULL;
  159. m_strDomainDN = NULL;
  160. m_strConfigDN = NULL;
  161. m_cTemplatePolicies = 0;
  162. m_apTemplatePolicies = NULL;
  163. m_fConfigLoaded = FALSE;
  164. m_dwCATemplListSequenceNum = 0;
  165. m_TemplateSequence = 0;
  166. //+--------------------------------------
  167. // begin_sdksample
  168. }
  169. ~CCertPolicyEnterprise();
  170. BEGIN_COM_MAP(CCertPolicyEnterprise)
  171. COM_INTERFACE_ENTRY(IDispatch)
  172. COM_INTERFACE_ENTRY(ICertPolicy)
  173. COM_INTERFACE_ENTRY(ICertPolicy2)
  174. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  175. END_COM_MAP()
  176. DECLARE_NOT_AGGREGATABLE(CCertPolicyEnterprise)
  177. // Remove the comment from the line above if you don't want your object to
  178. // support aggregation. The default is to support it
  179. DECLARE_REGISTRY(
  180. CCertPolicyEnterprise,
  181. wszCLASS_CERTPOLICY TEXT(".1"),
  182. wszCLASS_CERTPOLICY,
  183. IDS_CERTPOLICY_DESC,
  184. THREADFLAGS_BOTH)
  185. // ISupportsErrorInfo
  186. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  187. // ICertPolicy
  188. public:
  189. STDMETHOD(Initialize)(
  190. /* [in] */ BSTR const strConfig);
  191. STDMETHOD(VerifyRequest)(
  192. /* [in] */ BSTR const strConfig,
  193. /* [in] */ LONG Context,
  194. /* [in] */ LONG bNewRequest,
  195. /* [in] */ LONG Flags,
  196. /* [out, retval] */ LONG __RPC_FAR *pDisposition);
  197. STDMETHOD(GetDescription)(
  198. /* [out, retval] */ BSTR __RPC_FAR *pstrDescription);
  199. STDMETHOD(ShutDown)();
  200. // ICertPolicy2
  201. public:
  202. STDMETHOD(GetManageModule)(
  203. /* [out, retval] */ ICertManageModule **ppManageModule);
  204. public:
  205. HRESULT AddBasicConstraintsCommon(
  206. IN ICertServerPolicy *pServer,
  207. IN CERT_EXTENSION const *pExtension,
  208. IN BOOL fCA,
  209. IN BOOL fEnableExtension);
  210. BSTRC GetPolicyDescription() { return(m_strDescription); }
  211. // end_sdksample
  212. HRESULT FindTemplate(
  213. OPTIONAL IN WCHAR const *pwszTemplateName,
  214. OPTIONAL IN WCHAR const *pwszTemplateObjId,
  215. OUT CTemplatePolicy **ppTemplate);
  216. DWORD GetLogLevel() { return(m_dwLogLevel); }
  217. DWORD GetEditFlags() { return(m_dwEditFlags); }
  218. BYTE const *GetSMIME(OUT DWORD *pcbSMIME)
  219. {
  220. *pcbSMIME = m_cbSMIME;
  221. return(m_pbSMIME);
  222. }
  223. // begin_sdksample
  224. HRESULT AddV1TemplateNameExtension(
  225. IN ICertServerPolicy *pServer,
  226. OPTIONAL IN WCHAR const *pwszTemplateName);
  227. private:
  228. CERT_CONTEXT const *_GetIssuer(
  229. IN ICertServerPolicy *pServer);
  230. HRESULT _EnumerateExtensions(
  231. IN ICertServerPolicy *pServer,
  232. IN LONG bNewRequest,
  233. IN BOOL fFirstPass,
  234. IN BOOL fEnableEnrolleeExtensions,
  235. IN DWORD cCriticalExtensions,
  236. IN WCHAR const * const *apwszCriticalExtensions);
  237. #if DBG_CERTSRV
  238. VOID _DumpStringArray(
  239. IN char const *pszType,
  240. IN DWORD count,
  241. IN LPWSTR const *apwsz);
  242. #else
  243. #define _DumpStringArray(pszType, count, apwsz)
  244. #endif
  245. VOID _FreeStringArray(
  246. IN OUT DWORD *pcString,
  247. IN OUT LPWSTR **papwsz);
  248. VOID _Cleanup();
  249. HRESULT _SetSystemStringProp(
  250. IN ICertServerPolicy *pServer,
  251. IN WCHAR const *pwszName,
  252. OPTIONAL IN WCHAR const *pwszValue);
  253. HRESULT _AddStringArray(
  254. IN WCHAR const *pwszzValue,
  255. IN BOOL fURL,
  256. IN OUT DWORD *pcStrings,
  257. IN OUT LPWSTR **papwszRegValues);
  258. HRESULT _ReadRegistryString(
  259. IN HKEY hkey,
  260. IN BOOL fURL,
  261. IN WCHAR const *pwszRegName,
  262. IN WCHAR const *pwszSuffix,
  263. OUT LPWSTR *pwszRegValue);
  264. HRESULT _ReadRegistryStringArray(
  265. IN HKEY hkey,
  266. IN BOOL fURL,
  267. IN DWORD dwFlags,
  268. IN DWORD cRegNames,
  269. IN DWORD *aFlags,
  270. IN WCHAR const * const *apwszRegNames,
  271. IN OUT DWORD *pcStrings,
  272. IN OUT LPWSTR **papwszRegValues);
  273. VOID _InitRevocationExtension(
  274. IN HKEY hkey);
  275. VOID _InitRequestExtensionList(
  276. IN HKEY hkey);
  277. VOID _InitDisableExtensionList(
  278. IN HKEY hkey);
  279. HRESULT _AddRevocationExtension(
  280. IN ICertServerPolicy *pServer);
  281. HRESULT _AddOldCertTypeExtension(
  282. IN ICertServerPolicy *pServer,
  283. IN BOOL fCA);
  284. HRESULT _AddAuthorityKeyId(
  285. IN ICertServerPolicy *pServer);
  286. HRESULT _AddDefaultKeyUsageExtension(
  287. IN ICertServerPolicy *pServer,
  288. IN BOOL fCA);
  289. HRESULT _AddEnhancedKeyUsageExtension(
  290. IN ICertServerPolicy *pServer);
  291. HRESULT _AddDefaultBasicConstraintsExtension(
  292. IN ICertServerPolicy *pServer,
  293. IN BOOL fCA);
  294. HRESULT _SetValidityPeriod(
  295. IN ICertServerPolicy *pServer);
  296. // end_sdksample
  297. VOID _InitSubjectAltNameExtension(
  298. IN HKEY hkey,
  299. IN WCHAR const *pwszRegName,
  300. IN WCHAR const *pwszObjectId,
  301. IN DWORD iAltName);
  302. VOID _InitDefaultSMIMEExtension(
  303. IN HKEY hkey);
  304. HRESULT _AddSubjectAltNameExtension(
  305. IN ICertServerPolicy *pServer,
  306. IN DWORD iAltName);
  307. HRESULT _PatchExchangeSubjectAltName(
  308. IN ICertServerPolicy *pServer,
  309. OPTIONAL IN BSTRC strTemplateName);
  310. HRESULT _LoadDSConfig(
  311. IN ICertServerPolicy *pServer,
  312. IN BOOL fRediscover);
  313. VOID _UnloadDSConfig();
  314. HRESULT _UpdateTemplates(
  315. IN ICertServerPolicy *pServer,
  316. IN BOOL fForceLoad);
  317. HRESULT _UpgradeTemplatesInDS(
  318. IN const HCAINFO hCAInfo,
  319. IN BOOL fForceLoad,
  320. OUT BOOL *pfTemplateAdded);
  321. HRESULT _LogLoadTemplateError(
  322. IN ICertServerPolicy *pServer,
  323. HRESULT hr,
  324. LPCWSTR pcwszTemplate);
  325. HRESULT _LoadTemplates(
  326. IN ICertServerPolicy *pServer,
  327. OPTIONAL OUT HCAINFO *phCAInfo);
  328. VOID _ReleaseTemplates();
  329. HRESULT _AddTemplateToCA(
  330. IN HCAINFO hCAInfo,
  331. IN WCHAR const *pwszTemplateName,
  332. OUT BOOL *pfAdded);
  333. HRESULT _BuildErrorInfo(
  334. IN HRESULT hrLog,
  335. IN DWORD dwLogId);
  336. HRESULT _DuplicateAppPoliciesToEKU(
  337. IN ICertServerPolicy *pServer);
  338. // begin_sdksample
  339. private:
  340. // RevocationExtension variables:
  341. CERT_CONTEXT const *m_pCert;
  342. BSTR m_strDescription;
  343. DWORD m_dwRevocationFlags;
  344. LPWSTR m_wszASPRevocationURL;
  345. DWORD m_dwDispositionFlags;
  346. DWORD m_dwEditFlags;
  347. DWORD m_CAPathLength;
  348. DWORD m_cEnableRequestExtensions;
  349. LPWSTR *m_apwszEnableRequestExtensions;
  350. DWORD m_cEnableEnrolleeRequestExtensions;
  351. LPWSTR *m_apwszEnableEnrolleeRequestExtensions;
  352. DWORD m_cDisableExtensions;
  353. LPWSTR *m_apwszDisableExtensions;
  354. // CertTypeExtension variables:
  355. BSTR m_strRegStorageLoc;
  356. BSTR m_strCAName;
  357. BSTR m_strCASanitizedName;
  358. BSTR m_strCASanitizedDSName;
  359. BSTR m_strMachineDNSName;
  360. // CA and cert type info
  361. ENUM_CATYPES m_CAType;
  362. DWORD m_iCert;
  363. DWORD m_iCRL;
  364. // end_sdksample
  365. //+--------------------------------------
  366. // SubjectAltNameExtension variables:
  367. BSTR m_astrSubjectAltNameProp[2];
  368. BSTR m_astrSubjectAltNameObjectId[2];
  369. CRITICAL_SECTION m_TemplateCriticalSection;
  370. BOOL m_fTemplateCriticalSection;
  371. ICreateErrorInfo *m_pCreateErrorInfo;
  372. BOOL m_fUseDS;
  373. DWORD m_dwLogLevel;
  374. LDAP *m_pld;
  375. WCHAR *m_pwszHostName;
  376. HCERTTYPEQUERY m_hCertTypeQuery;
  377. DWORD m_TemplateSequence;
  378. BSTR m_strDomainDN;
  379. BSTR m_strConfigDN;
  380. DWORD m_cTemplatePolicies;
  381. CTemplatePolicy **m_apTemplatePolicies;
  382. BOOL m_fConfigLoaded;
  383. DWORD m_dwCATemplListSequenceNum;
  384. BYTE *m_pbSMIME;
  385. DWORD m_cbSMIME;
  386. //+--------------------------------------
  387. // begin_sdksample
  388. };
  389. // end_sdksample
  390. // Class CTemplatePolicy
  391. // Sub Policy information for a CA policy
  392. typedef struct _OBJECTIDLIST {
  393. DWORD cObjId;
  394. WCHAR **rgpwszObjId;
  395. } OBJECTIDLIST;
  396. // Template properties that can be cloned via CopyMemory:
  397. typedef struct _TEMPLATEPROPERTIES {
  398. DWORD dwTemplateMajorVersion;
  399. DWORD dwTemplateMinorVersion;
  400. DWORD dwSchemaVersion;
  401. DWORD dwEnrollmentFlags;
  402. DWORD dwSubjectNameFlags;
  403. DWORD dwPrivateKeyFlags;
  404. DWORD dwGeneralFlags;
  405. DWORD dwMinKeyLength;
  406. DWORD dwcSignatureRequired;
  407. LLFILETIME llftExpirationPeriod;
  408. LLFILETIME llftOverlapPeriod;
  409. } TEMPLATEPROPERTIES;
  410. class CTemplatePolicy
  411. {
  412. public:
  413. CTemplatePolicy();
  414. ~CTemplatePolicy();
  415. HRESULT Initialize(
  416. IN HCERTTYPE hCertType,
  417. IN ICertServerPolicy *pServer,
  418. IN CCertPolicyEnterprise *pPolicy);
  419. HRESULT AccessCheck(
  420. IN HANDLE hToken);
  421. HRESULT Clone(
  422. OUT CTemplatePolicy **ppTemplate);
  423. HRESULT Apply(
  424. IN ICertServerPolicy *pServer,
  425. IN CRequestInstance *pRequest,
  426. OUT BOOL *pfReenroll);
  427. HRESULT GetFlags(
  428. IN DWORD dwOption,
  429. OUT DWORD *pdwFlags);
  430. HRESULT GetCriticalExtensions(
  431. OUT DWORD *pcCriticalExtensions,
  432. OUT WCHAR const * const **papwszCriticalExtensions);
  433. BOOL IsRequestedTemplate(
  434. OPTIONAL IN WCHAR const *pwszTemplateName,
  435. OPTIONAL IN WCHAR const *pwszTemplateObjId);
  436. HRESULT GetV1TemplateClass(
  437. OUT WCHAR const **ppwszV1TemplateClass);
  438. WCHAR const *GetTemplateName() { return(m_pwszTemplateName); }
  439. WCHAR const *GetTemplateObjId() { return(m_pwszTemplateObjId); }
  440. private:
  441. VOID _Cleanup();
  442. HRESULT _CloneExtensions(
  443. IN CERT_EXTENSIONS const *pExtensionsIn,
  444. OUT CERT_EXTENSIONS **ppExtensionsOut);
  445. HRESULT _CloneObjectIdList(
  446. IN OBJECTIDLIST const *pObjectIdListIn,
  447. OUT OBJECTIDLIST *pObjectIdListOut);
  448. HRESULT _LogLoadResult(
  449. IN CCertPolicyEnterprise *pPolicy,
  450. IN ICertServerPolicy *pServer,
  451. IN HRESULT hrLoad);
  452. HRESULT _InitBasicConstraintsExtension(
  453. IN HKEY hkey);
  454. HRESULT _AddBasicConstraintsExtension(
  455. IN CRequestInstance *pRequest,
  456. IN ICertServerPolicy *pServer);
  457. HRESULT _InitKeyUsageExtension(
  458. IN HKEY hkey);
  459. HRESULT _AddKeyUsageExtension(
  460. IN ICertServerPolicy *pServer,
  461. IN CRequestInstance *pRequest);
  462. HRESULT _AddTemplateExtensionArray(
  463. IN ICertServerPolicy *pServer);
  464. HRESULT _AddTemplateExtension(
  465. IN ICertServerPolicy *pServer,
  466. IN CERT_EXTENSION const *pExt);
  467. HRESULT _AddSubjectName(
  468. IN ICertServerPolicy *pServer,
  469. IN CRequestInstance *pRequest);
  470. HRESULT _AddDSDistinguishedName(
  471. IN ICertServerPolicy *pServer,
  472. IN CRequestInstance *pRequest);
  473. HRESULT _AddAltSubjectName(
  474. IN ICertServerPolicy *pServer,
  475. IN CRequestInstance *pRequest);
  476. HRESULT _ApplyExpirationTime(
  477. IN ICertServerPolicy *pServer,
  478. IN CRequestInstance *pRequest);
  479. HRESULT _EnforceKeySizePolicy(
  480. IN ICertServerPolicy *pServer);
  481. HRESULT _EnforceKeyArchivalPolicy(
  482. IN ICertServerPolicy *pServer);
  483. HRESULT _EnforceSymmetricAlgorithms(
  484. IN ICertServerPolicy *pServer);
  485. HRESULT _EnforceMinimumTemplateVersion(
  486. IN CRequestInstance *pRequest);
  487. HRESULT _EnforceEnrollOnBehalfOfAllowed(
  488. IN ICertServerPolicy *pServer,
  489. OUT BOOL *pfEnrollOnBehalfOf);
  490. HRESULT _EnforceReenrollment(
  491. IN ICertServerPolicy *pServer,
  492. IN CRequestInstance *pRequest);
  493. HRESULT _EnforceSignaturePolicy(
  494. IN ICertServerPolicy *pServer,
  495. IN CRequestInstance *pRequest,
  496. IN BOOL fEnrollOnBehalfOf);
  497. HRESULT _LoadSignaturePolicies(
  498. IN ICertServerPolicy *pServer,
  499. IN WCHAR const *pwszPropNameRequest,
  500. OUT DWORD *pcPolicies,
  501. OUT OBJECTIDLIST **pprgPolicies);
  502. private:
  503. HCERTTYPE m_hCertType;
  504. TEMPLATEPROPERTIES m_tp;
  505. WCHAR *m_pwszTemplateName;
  506. WCHAR *m_pwszTemplateObjId;
  507. CERT_EXTENSIONS *m_pExtensions;
  508. OBJECTIDLIST m_CriticalExtensions;
  509. OBJECTIDLIST m_PoliciesApplication;
  510. OBJECTIDLIST m_PoliciesIssuance;
  511. CCertPolicyEnterprise *m_pPolicy;
  512. };
  513. // begin_sdksample
  514. //
  515. // Class CRequestInstance
  516. //
  517. // Instance data for a certificate that is being created.
  518. //
  519. class CRequestInstance
  520. {
  521. friend class CTemplatePolicy; // no_sdksample
  522. public:
  523. CRequestInstance()
  524. {
  525. m_strTemplateName = NULL;
  526. m_strTemplateObjId = NULL;
  527. m_pPolicy = NULL;
  528. // end_sdksample
  529. //+--------------------------------------
  530. m_pTemplate = NULL;
  531. m_hToken = NULL;
  532. m_pldGC = NULL;
  533. m_pldClientDC = NULL;
  534. m_pldT = NULL;
  535. m_SearchResult = NULL;
  536. m_PrincipalAttributes = NULL;
  537. m_strUserDN = NULL;
  538. m_pwszUPN = NULL;
  539. // The default version for clients is W2K beta3 (2031)
  540. m_RequestOsVersion.dwOSVersionInfoSize = sizeof(m_RequestOsVersion);
  541. m_RequestOsVersion.dwMajorVersion = 5;
  542. m_RequestOsVersion.dwMinorVersion = 0;
  543. m_RequestOsVersion.dwBuildNumber = B3_VERSION_NUMBER;
  544. m_RequestOsVersion.dwPlatformId = VER_PLATFORM_WIN32_NT;
  545. m_RequestOsVersion.szCSDVersion[0] = L'\0';
  546. m_RequestOsVersion.wServicePackMajor = 0;
  547. m_RequestOsVersion.wServicePackMinor = 0;
  548. m_RequestOsVersion.wSuiteMask = 0;
  549. m_RequestOsVersion.wProductType = 0;
  550. m_RequestOsVersion.wReserved = 0;
  551. m_fClientVersionSpecified = FALSE;
  552. m_fIsXenrollRequest = FALSE;
  553. m_fNewRequest = TRUE;
  554. m_pCreateErrorInfo = NULL;
  555. //+--------------------------------------
  556. // begin_sdksample
  557. }
  558. ~CRequestInstance();
  559. HRESULT Initialize(
  560. IN CCertPolicyEnterprise *pPolicy,
  561. IN BOOL fEnterpriseCA, // no_sdksample
  562. IN BOOL bNewRequest, // no_sdksample
  563. IN ICertServerPolicy *pServer,
  564. OUT BOOL *pfEnableEnrolleeExtensions);
  565. HRESULT SetTemplateName(
  566. IN ICertServerPolicy *pServer,
  567. IN OPTIONAL WCHAR const *pwszTemplateName,
  568. IN OPTIONAL WCHAR const *pwszTemplateObjId);
  569. BSTRC GetTemplateName() { return(m_strTemplateName); }
  570. BSTRC GetTemplateObjId() { return(m_strTemplateObjId); }
  571. // end_sdksample
  572. VOID SaveErrorInfo(
  573. OPTIONAL IN ICreateErrorInfo *pCreateErrorInfo);
  574. HRESULT SetErrorInfo();
  575. HRESULT BuildErrorInfo(
  576. IN HRESULT hrLog,
  577. IN DWORD dwLogId,
  578. OPTIONAL IN WCHAR const * const *ppwszInsert);
  579. HRESULT ApplyTemplate(
  580. IN ICertServerPolicy *pServer,
  581. OUT BOOL *pfReenroll,
  582. OUT DWORD *pdwEnrollmentFlags,
  583. OUT DWORD *pcCriticalExtensions,
  584. OUT WCHAR const * const **papwszCriticalExtensions);
  585. VOID GetTemplateVersion(
  586. OUT DWORD *pdwTemplateMajorVersion,
  587. OUT DWORD *pdwTemplateMinorVersion);
  588. BOOL IsNewRequest() { return m_fNewRequest; }
  589. // begin_sdksample
  590. BOOL IsCARequest() { return(m_fCA); }
  591. CCertPolicyEnterprise *GetPolicy() { return(m_pPolicy); }
  592. private:
  593. HRESULT _SetFlagsProperty(
  594. IN ICertServerPolicy *pServer,
  595. IN WCHAR const *pwszPropName,
  596. IN DWORD dwFlags);
  597. BOOL _TemplateNamesMatch(
  598. IN WCHAR const *pwszTemplateName1,
  599. IN WCHAR const *pwszTemplateName2,
  600. OUT BOOL *pfTemplateMissing);
  601. // end_sdksample
  602. //+--------------------------------------
  603. HRESULT _InitToken(
  604. IN ICertServerPolicy *pServer);
  605. HRESULT _InitClientOSVersionInfo(
  606. IN ICertServerPolicy *pServer);
  607. HANDLE _GetToken() { return(m_hToken); }
  608. BOOL _IsUser() { return(m_fUser); }
  609. BOOL _IsXenrollRequest() { return(m_fIsXenrollRequest); }
  610. BOOL _ClientVersionSpecified() { return(m_fClientVersionSpecified); }
  611. // Return TRUE if the requesting client is running NT and the OS version is
  612. // older than the passed version.
  613. BOOL _IsNTClientOlder(
  614. IN DWORD dwMajor,
  615. IN DWORD dwMinor,
  616. IN DWORD dwBuild,
  617. IN DWORD dwPlatform)
  618. {
  619. return(
  620. dwPlatform == m_RequestOsVersion.dwPlatformId &&
  621. (dwMajor > m_RequestOsVersion.dwMajorVersion ||
  622. (dwMajor == m_RequestOsVersion.dwMajorVersion &&
  623. (dwMinor > m_RequestOsVersion.dwMinorVersion ||
  624. (dwMinor == m_RequestOsVersion.dwMinorVersion &&
  625. dwBuild > m_RequestOsVersion.dwBuildNumber)))));
  626. }
  627. HRESULT _GetValueString(
  628. IN WCHAR const *pwszName,
  629. OUT BSTRC *pstrValue);
  630. HRESULT _GetValues(
  631. IN WCHAR const *pwszName,
  632. OUT WCHAR ***pppwszValues);
  633. HRESULT _FreeValues(
  634. IN WCHAR **ppwszValues);
  635. HRESULT _GetObjectGUID(
  636. OUT BSTR *pstrGuid);
  637. HRESULT _LoadPrincipalObject(
  638. IN ICertServerPolicy *pServer,
  639. IN CTemplatePolicy *pTemplate,
  640. IN BOOL fDNSNameRequired);
  641. VOID _ReleasePrincipalObject();
  642. VOID _Cleanup(); // add_sdksample
  643. HRESULT _GetDSObject(
  644. IN ICertServerPolicy *pServer,
  645. IN BOOL fDNSNameRequired,
  646. OPTIONAL IN WCHAR const *pwszClientDC);
  647. private: // add_sdksample
  648. HANDLE m_hToken;
  649. LDAP *m_pldGC;
  650. LDAP *m_pldClientDC;
  651. LDAP *m_pldT;
  652. BOOL m_fUser; // This is a user
  653. BOOL m_fEnterpriseCA;
  654. LDAPMessage *m_SearchResult;
  655. LDAPMessage *m_PrincipalAttributes; // Collected attrs for cert
  656. BSTR m_strUserDN; // Path to principal object
  657. WCHAR *m_pwszUPN; // Principal Name
  658. OSVERSIONINFOEX m_RequestOsVersion; // request version info
  659. BOOL m_fIsXenrollRequest; // not Netscape keygen
  660. BOOL m_fClientVersionSpecified;
  661. CTemplatePolicy *m_pTemplate;
  662. ICreateErrorInfo *m_pCreateErrorInfo;
  663. //+--------------------------------------
  664. // begin_sdksample
  665. CCertPolicyEnterprise *m_pPolicy;
  666. BSTR m_strTemplateName; // certificate type requested
  667. BSTR m_strTemplateObjId; // certificate type requested
  668. DWORD m_dwTemplateMajorVersion;
  669. DWORD m_dwTemplateMinorVersion;
  670. BOOL m_fCA;
  671. BOOL m_fNewRequest; // set if new request, no_sdksample
  672. };
  673. // end_sdksample