Win32 API 日本語リファレンス
ホーム › Devices.BiometricFramework › PIBIO_ENGINE_CONTROL_UNIT_PRIVILEGED_FN

PIBIO_ENGINE_CONTROL_UNIT_PRIVILEGED_FN

コールバック

シグネチャ

HRESULT PIBIO_ENGINE_CONTROL_UNIT_PRIVILEGED_FN(
    WINBIO_PIPELINE* Pipeline,
    DWORD ControlCode,
    BYTE* SendBuffer,
    UINT_PTR SendBufferSize,
    BYTE* ReceiveBuffer,
    UINT_PTR ReceiveBufferSize,
    UINT_PTR* ReceiveDataSize,
    DWORD* OperationStatus
);

パラメーター

フィールド型説明
PipelineWINBIO_PIPELINE*操作を実行するバイオメトリックユニットに関連付けられた WINBIO_PIPELINE 構造体へのポインター。
ControlCodeDWORD実行するベンダー定義の操作を指定する ULONG 値。
SendBufferBYTE*エンジンアダプターに送信される制御情報を格納したバッファーへのポインター。バッファーの形式と内容はベンダー定義です。
SendBufferSizeUINT_PTRSendBuffer パラメーターで指定したバッファーのサイズ (バイト単位)。
ReceiveBufferBYTE*制御操作に応じてエンジンアダプターが返す情報を受け取るバッファーへのポインター。バッファーの形式はベンダー定義です。
ReceiveBufferSizeUINT_PTRReceiveBuffer パラメーターで指定したバッファーのサイズ (バイト単位)。
ReceiveDataSizeUINT_PTR*ReceiveBuffer パラメーターで指定したバッファーに書き込まれたデータのサイズ (バイト単位) を受け取る変数へのポインター。
OperationStatusDWORD*制御操作の結果を示すベンダー定義のステータスコードを受け取る変数へのポインター。

公式ドキュメント

Windows Biometric Framework から呼び出され、昇格した特権を必要とするベンダー定義の制御操作を実行します。昇格した特権を必要としないベンダー定義の制御操作を実行するには、EngineAdapterControlUnit 関数を呼び出します。

戻り値

関数が成功した場合は S_OK を返します。失敗した場合は、エラーを示すために次の HRESULT 値のいずれかを返す必要があります。

リターンコード 説明
E_POINTER
必須のポインター引数が NULL です。
E_INVALIDARG
SendBuffer パラメーターで指定したバッファーのサイズまたは形式が正しくないか、ControlCode パラメーターで指定した値がアダプターで認識されません。
E_NOT_SUFFICIENT_BUFFER
ReceiveBuffer パラメーターで指定したバッファーが小さすぎます。
WINBIO_E_CANCELED
操作はキャンセルされました。
WINBIO_E_DEVICE_FAILURE
ハードウェア障害が発生しました。
WINBIO_E_INVALID_CONTROL_CODE
ControlCode パラメーターで指定した値がアダプターで認識されません。
注 Windows 8 以降では、この状態を通知するには E_INVALIDARG のみを使用してください。

解説(Remarks)

この関数の実装は、ControlCode パラメーターで指定される操作の実行に昇格した特権が必要である点を除き、EngineAdapterControlUnit 関数の実装と同一にする必要があります。操作を定義し、どの操作に昇格した特権を必要とするかを決定するのは実装者の責任です。

この関数では、ReceiveBufferSize パラメーターの値を確認し、ReceiveBuffer パラメーターで指定されたバッファーが返されるデータを格納できる十分な大きさであることを確かめる必要があります。

例

次の擬似コードは、この関数の実装例の 1 つを示しています。この例はコンパイルできません。目的に合わせて調整してください。

///////////////////////////////////////////////////////////////////////////////
//
// EngineAdapterControlUnitPrivileged
//
// Purpose:
//      Performs a vendor-defined control operation that requires elevated 
//      privilege.
//
// Parameters:
//      Pipeline            - Pointer to a WINBIO_PIPELINE structure associated 
//                            with the biometric unit performing the operation
//      ControlCode         - Specifies the vendor-defined operation to perform
//      SendBuffer          - Contains the control information sent to the 
//                            engine adapter
//      SendBufferSize      - Size, in bytes, of the buffer specified by the 
//                            SendBuffer parameter
//      ReceiveBuffer       - Receives information returned by the engine adapter
//                            in response to the control operation
//      ReceiveBufferSize   - Size, in bytes, of the buffer specified by the 
//                            ReceiveBuffer parameter.
//      ReceiveDataSize     - Receives the size, in bytes, of the data written to 
//                            the buffer specified by the ReceiveBuffer parameter
//      OperationStatus     - Receives a vendor-defined status code that specifies 
//                            the outcome of the control operation.
//
static HRESULT
WINAPI
EngineAdapterControlUnitPrivileged(
    __inout PWINBIO_PIPELINE Pipeline,
    __in ULONG ControlCode,
    __in PUCHAR SendBuffer,
    __in SIZE_T SendBufferSize,
    __in PUCHAR ReceiveBuffer,
    __in SIZE_T ReceiveBufferSize,
    __out PSIZE_T ReceiveDataSize,
    __out PULONG OperationStatus
    )
{
    HRESULT hr = S_OK;
    BOOL result = TRUE;

    // Verify that pointer arguments are not NULL.
    if (!ARGUMENT_PRESENT(Pipeline) ||
        !ARGUMENT_PRESENT(SendBuffer) ||
        !ARGUMENT_PRESENT(ReceiveBuffer) ||
        !ARGUMENT_PRESENT(ReceiveDataSize) ||
        !ARGUMENT_PRESENT(OperationStatus))
    {
        hr = E_POINTER;
        goto cleanup;
    }

    // Retrieve the context from the pipeline.
    PWINBIO_ENGINE_CONTEXT engineContext = 
           (PWINBIO_ENGINE_CONTEXT)Pipeline->EngineContext;

    // Verify the state of the pipeline.
    if (engineContext == NULL ||
        engineContext->FileHandle == INVALID_HANDLE_VALUE)
    {
        hr = WINBIO_E_INVALID_DEVICE_STATE;
        goto cleanup;
    }

    switch (ControlCode)
    {
    case MY_PRIVILEGED_CTRL_CODE_P1:
        {
            CTRL_CODE_P1_SEND_BUFFER *sendBuffer = (CTRL_CODE_P1_SEND_BUFFER*)SendBuffer;

            // Verify the size of the send buffer.
            if (SendBufferSize < sizeof(CTRL_CODE_P1_SEND_BUFFER))
            {
                hr = E_INVALIDARG;
                break;
            }

            // Perform any other checks that may be required on the buffer 
            // contents. Return E_INVALIDARG if any of the checks fail.
            if (sendBuffer->SomeField != SomeSpecialValue ||
                sendBuffer->SomeOtherField != SomeOtherSpecialValue)
            {
                hr = E_INVALIDARG;
                break;
            }

            if (ReceiveBufferSize < sizeof(CTRL_CODE_P1_RECEIVE_BUFFER))
            {
                hr = E_NOT_SUFFICIENT_BUFFER;
                break;
            }
        }

        // Fall through and perform the control operation after the switch
        // statement. Alternatively, depending on your requirements, you can 
        // perform the control operation here.
        break;

    case MY_PRIVILEGED_CTRL_CODE_P2:
        // Continue testing for other privileged control codes that your
        // adapter supports.
        {
            CTRL_CODE_P2_SEND_BUFFER *sendBuffer = (CTRL_CODE_P2_SEND_BUFFER*)SendBuffer;

            // Verify the size of the send buffer.
            if (SendBufferSize < sizeof(CTRL_CODE_P2_SEND_BUFFER))
            {
                hr = E_INVALIDARG;
                break;
            }

            // Perform any other checks that may be required on the buffer 
            // contents. Return E_INVALIDARG if any of the checks fail.
            if (sendBuffer->SomeField != SomeSpecialValue ||
                sendBuffer->SomeOtherField != SomeOtherSpecialValue)
            {
                hr = E_INVALIDARG;
                break;
            }

            if (ReceiveBufferSize < sizeof(CTRL_CODE_P2_RECEIVE_BUFFER))
            {
                hr = E_NOT_SUFFICIENT_BUFFER;
                break;
            }
        }
        break;

    default:
        // All unrecognized control code values should return an error.
        hr = WINBIO_E_INVALID_CONTROL_CODE;
        break;
    }

    // If control code validation succeeds, perform the control operation. This
    // example assumes that your adapter context structure contains an open
    // handle to a hardware driver. It also assumes that the driver performs
    // overlapped I/O and that a properly initialized OVERLAPPED structure is
    // contained in the engine context.
    if (FAILED(hr))
    {
        goto cleanup;
    }
    result = DeviceIoControl(
                Pipeline->EngineHandle,
                ControlCode,
                SendBuffer,
                (DWORD)SendBufferSize,
                ReceiveBuffer,
                (DWORD)ReceiveBufferSize,
                (LPDWORD)ReceiveDataSize,
                &Pipeline->EngineContext->Overlapped
                );
    if (result == FALSE && GetLastError() == ERROR_IO_PENDING)
    {
        SetLastError(ERROR_SUCCESS);

        result = GetOverlappedResult(
                    Pipeline->EngineHandle,
                    &Pipeline->EngineContext->Overlapped,
                    (LPDWORD)ReceiveDataSize,
                    TRUE
                    );
    }
    *OperationStatus = GetLastError();

    if (!result)
    {
        hr = _AdapterGetHresultFromWin32(*OperationStatus);
    }

cleanup:

    return hr;
}
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)