ICertPolicy::VerifyRequest 方法 (certpol.h)

VerifyRequest 方法會通知原則模組新要求已進入系統。 接著,原則模組可以在擷取或設定要求或相關聯憑證的屬性時,傳遞 Context 做為參數來與該要求互動。

傳回的處置值會指出要求是否已接受、拒絕或已傳送至系統管理佇列,以供稍後評估。

語法

HRESULT VerifyRequest(
  [in]          const BSTR strConfig,
  [in]          LONG       Context,
  [in]          LONG       bNewRequest,
  [in]          LONG       Flags,
  [out, retval] LONG       *pDisposition
);

參數

[in] strConfig

表示 證書頒發機構單位的名稱,如憑證服務設定期間所輸入。 如需組態字串名稱的相關信息,請參閱 ICertConfig

[in] Context

識別建構中的要求和相關聯的憑證。 證書伺服器會將內容傳遞至這個方法。

[in] bNewRequest

如果設定為 TRUE,則指定要求是新的。 如果設定為 FALSE,要求會因為 ICertAdmin::ResubmitRequest 呼叫而重新提交至原則模組。 FALSE 值可用來指出系統管理員想要發出要求,或應該檢查系統管理員所設定的要求屬性。

請注意, TRUE 定義 (Microsoft 頭檔) C/C++ 程式設計人員,而 Visual Basic 會將 True 關鍵詞定義為負數。 因此,Visual Basic 開發人員必須使用一個 (,而不是 True) ,將此參數設定為 TRUE。 不過,若要將此參數設定為 FALSE,Visual Basic 開發人員可以使用零或 False

[in] Flags

此參數是保留的,而且必須設定為零。

[out, retval] pDisposition

處置值的指標。 方法會設定下列其中一個處置。

意義
VR_INSTANT_BAD
拒絕要求。
VR_INSTANT_OK
接受要求。
VR_PENDING
將要求新增至佇列,以在稍後接受或拒絕要求。

傳回值

C++

如果方法成功,方法會傳回S_OK。

如果方法失敗,它會傳回 HRESULT 值,指出錯誤。 如需常見錯誤碼的清單,請參閱 一般 HRESULT 值

VB

傳回值會指定處置,這必須是下列其中一個值。
傳回碼 Description
VR_INSTANT_BAD
拒絕要求。
VR_INSTANT_OK
接受要求。
VR_PENDING
將要求新增至佇列,以在稍後接受或拒絕要求。

備註

VerifyRequest 是免費的,可以繁衍其他進程,或存取外部資料庫來執行要求驗證。 如果驗證需要頻外處理或人為介入, VerifyRequest 可以通知另一個進程,或留下任何傳入要求所需的通知。 完成頻外處理之後,可以呼叫 ResubmitRequest ,或者提供的管理工具可用來將要求重新提交至原則模組。 原則模組可以再次檢查要求、存取任何必要的外部數據,並傳回值以指出應該發出或拒絕憑證。

當您撰寫自定義原則模組時,必須在模組中實作 VerifyRequest 功能。

範例

下列範例示範 VerifyRequest 方法的可能實作。

#include <windows.h>
#include <stdio.h>
#include <Certpol.h>

STDMETHODIMP CCertPolicy::VerifyRequest(
             BSTR const strConfig,
             LONG Context,
             LONG bNewRequest,
             LONG Flags,
             LONG __RPC_FAR *pDisposition)
{
    HRESULT            hr;
    long               nDisp = VR_INSTANT_BAD;
    ICertServerPolicy *pServer = NULL;
    BSTR               bstrPropName = NULL;
    VARIANT            varProp;

    // Verify that pointer is not NULL.
    if ( NULL == pDisposition )
    {
        hr = E_POINTER;  // E_POINTER is #defined in Winerror.h
        goto error;
    }
    
    // Set disposition to pending.
    *pDisposition = VR_PENDING; 

    // Obtain a pointer to the CertServerPolicy interface.
    hr = CoCreateInstance( CLSID_CCertServerPolicy,
                           NULL,
                           CLSCTX_INPROC_SERVER,
                           IID_ICertServerPolicy,
                           (void **) &pServer);
    if (FAILED( hr ))
    {
        printf("Failed CoCreateInstance for pServer - %x\n", hr );
        goto error;
    }

    // Set the context to refer to this request.
    hr = pServer->SetContext(Context);
    if (FAILED( hr ))
    {
        printf("Failed SetContext(%u) - %x\n", Context, hr );
        goto error;
    }

    // This policy will perform a database check on the CN.
    // Set the property name to Subject.Commonname.
    bstrPropName = SysAllocString(L"Subject.Commonname");
    if ( NULL == bstrPropName )
    {
        hr = E_OUTOFMEMORY;  // #defined in Winerror.h
        printf("Failed SysAllocString (no memory)\n" );
        goto error;
    }

    // Retrieve the certificate property for the CN.
    // Actual implementations may want to examine other properties.
    VariantInit( &varProp );
    hr = pServer->GetCertificateProperty( bstrPropName,
                                          PROPTYPE_STRING,
                                          &varProp );
    if (FAILED(hr))
    {
        printf("Failed GetCertificateProperty - %x\n", hr);
        goto error;
    }

    // For this simple sample, merely check CN in a database.
    // (Implementation not shown, as it is application-specific).
    hr = MyDatabaseCheck( varProp.bstrVal );
    if ( S_OK == hr )
        *pDisposition = VR_INSTANT_OK;   // Accepted.
    else 
        *pDisposition = VR_INSTANT_BAD;  // Denied.

error:

    // Free resources.
    if (NULL != pServer)
        pServer->Release();

    VariantClear( &varProp );

    if ( NULL != bstrPropName )
        SysFreeString( bstrPropName );

    return(hr);
}

規格需求

需求
最低支援的用戶端 都不支援
最低支援的伺服器 Windows Server 2003 [僅限傳統型應用程式]
目標平台 Windows
標頭 certpol.h (包括 Certsrv.h)
程式庫 Certidl.lib

另請參閱

ICertConfig

ICertPolicy

ICertPolicy2