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

PIBIO_STORAGE_CONTROL_UNIT_PRIVILEGED_FN

コールバック

シグネチャ

HRESULT PIBIO_STORAGE_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 から呼び出されます。昇格した特権を必要としないベンダー定義の制御操作を実行するには、StorageAdapterControlUnit 関数を呼び出します。

戻り値

関数が成功した場合は 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)

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

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

例

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

/////////////////////////////////////////////////////////////////////////////////////////
//
// StorageAdapterControlUnitPrivileged
//
// 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 
//                            storage adapter
//      SendBufferSize      - Size, in bytes, of the buffer specified by the 
//                            SendBuffer parameter
//      ReceiveBuffer       - Receives information returned by the storage 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
StorageAdapterControlUnitPrivileged(
    __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_STORAGE_CONTEXT storageContext = 
           (PWINBIO_STORAGE_CONTEXT)Pipeline->StorageContext;

    // Verify the state of the pipeline.
    if (storageContext == NULL ||
        Pipeline->StorageHandle == 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 non-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 (FAILED(hr))
    {
        goto cleanup;
    }

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

        result = GetOverlappedResult(
                    Pipeline->StorageHandle,
                    &storageContext->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)