Win32 API 日本語リファレンス
ホームSystem.Com › CoQueryAuthenticationServices

CoQueryAuthenticationServices

関数
プロセスに登録済みの認証サービス一覧を取得する。
DLLOLE32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// OLE32.dll
#include <windows.h>

HRESULT CoQueryAuthenticationServices(
    DWORD* pcAuthSvc,
    SOLE_AUTHENTICATION_SERVICE** asAuthSvc
);

パラメーター

名前方向説明
pcAuthSvcDWORD*outasAuthSvc 配列で返されるエントリ数を受け取る変数へのポインター。
asAuthSvcSOLE_AUTHENTICATION_SERVICE**outSOLE_AUTHENTICATION_SERVICE 構造体の配列へのポインター。この一覧は CoTaskMemAlloc 関数の呼び出しによって割り当てられます。呼び出し側は、使用し終えたら CoTaskMemFree 関数を呼び出して一覧を解放する必要があります。

戻り値の型: HRESULT

公式ドキュメント

プロセスが CoInitializeSecurity を呼び出した際に登録された認証サービスの一覧を取得します。

戻り値

この関数は、標準の戻り値である E_INVALIDARGE_OUTOFMEMORY、および S_OK を返すことがあります。

解説(Remarks)

CoQueryAuthenticationServices は、現在登録されている認証サービスの一覧を取得します。プロセスが CoInitializeSecurity を呼び出している場合は、その呼び出しによって登録されたサービスが返されます。アプリケーションがこれを呼び出さない場合は、最初にインターフェイスがマーシャリングまたはアンマーシャリングされる際に COM によって CoInitializeSecurity が自動的に呼び出され、既定のセキュリティパッケージが登録されます。

この関数は、CoInitializeSecurity で登録された認証サービスのみを返します。コンピューターにインストールされているすべての認証サービスを返すわけではありませんが、EnumerateSecurityPackages はそれらすべてを返します。CoQueryAuthenticationServices は主に、カスタムマーシャラーがアプリケーションで使用できるプリンシパル名を判別するために役立ちます。

認証サービスごとにサポートするセキュリティのレベルは異なります。たとえば、NTLMSSP は委任や相互認証をサポートしませんが、Kerberos はサポートします。アプリケーションは、自身が必要とする機能を提供する認証サービスのみを登録する責任を負います。この関数は、CoInitializeSecurity でどのサービスが登録されたかを確認する手段を提供します。

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

各言語での呼び出し定義

// OLE32.dll
#include <windows.h>

HRESULT CoQueryAuthenticationServices(
    DWORD* pcAuthSvc,
    SOLE_AUTHENTICATION_SERVICE** asAuthSvc
);
[DllImport("OLE32.dll", ExactSpelling = true)]
static extern int CoQueryAuthenticationServices(
    out uint pcAuthSvc,   // DWORD* out
    IntPtr asAuthSvc   // SOLE_AUTHENTICATION_SERVICE** out
);
<DllImport("OLE32.dll", ExactSpelling:=True)>
Public Shared Function CoQueryAuthenticationServices(
    <Out> ByRef pcAuthSvc As UInteger,   ' DWORD* out
    asAuthSvc As IntPtr   ' SOLE_AUTHENTICATION_SERVICE** out
) As Integer
End Function
' pcAuthSvc : DWORD* out
' asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out
Declare PtrSafe Function CoQueryAuthenticationServices Lib "ole32" ( _
    ByRef pcAuthSvc As Long, _
    ByVal asAuthSvc As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CoQueryAuthenticationServices = ctypes.windll.ole32.CoQueryAuthenticationServices
CoQueryAuthenticationServices.restype = ctypes.c_int
CoQueryAuthenticationServices.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # pcAuthSvc : DWORD* out
    ctypes.c_void_p,  # asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('OLE32.dll')
CoQueryAuthenticationServices = Fiddle::Function.new(
  lib['CoQueryAuthenticationServices'],
  [
    Fiddle::TYPE_VOIDP,  # pcAuthSvc : DWORD* out
    Fiddle::TYPE_VOIDP,  # asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ole32")]
extern "system" {
    fn CoQueryAuthenticationServices(
        pcAuthSvc: *mut u32,  // DWORD* out
        asAuthSvc: *mut *mut SOLE_AUTHENTICATION_SERVICE  // SOLE_AUTHENTICATION_SERVICE** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("OLE32.dll")]
public static extern int CoQueryAuthenticationServices(out uint pcAuthSvc, IntPtr asAuthSvc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLE32_CoQueryAuthenticationServices' -Namespace Win32 -PassThru
# $api::CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
#uselib "OLE32.dll"
#func global CoQueryAuthenticationServices "CoQueryAuthenticationServices" sptr, sptr
; CoQueryAuthenticationServices varptr(pcAuthSvc), varptr(asAuthSvc)   ; 戻り値は stat
; pcAuthSvc : DWORD* out -> "sptr"
; asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "OLE32.dll"
#cfunc global CoQueryAuthenticationServices "CoQueryAuthenticationServices" var, var
; res = CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
; pcAuthSvc : DWORD* out -> "var"
; asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT CoQueryAuthenticationServices(DWORD* pcAuthSvc, SOLE_AUTHENTICATION_SERVICE** asAuthSvc)
#uselib "OLE32.dll"
#cfunc global CoQueryAuthenticationServices "CoQueryAuthenticationServices" var, var
; res = CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
; pcAuthSvc : DWORD* out -> "var"
; asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ole32 = windows.NewLazySystemDLL("OLE32.dll")
	procCoQueryAuthenticationServices = ole32.NewProc("CoQueryAuthenticationServices")
)

// pcAuthSvc (DWORD* out), asAuthSvc (SOLE_AUTHENTICATION_SERVICE** out)
r1, _, err := procCoQueryAuthenticationServices.Call(
	uintptr(pcAuthSvc),
	uintptr(asAuthSvc),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function CoQueryAuthenticationServices(
  pcAuthSvc: Pointer;   // DWORD* out
  asAuthSvc: Pointer   // SOLE_AUTHENTICATION_SERVICE** out
): Integer; stdcall;
  external 'OLE32.dll' name 'CoQueryAuthenticationServices';
result := DllCall("OLE32\CoQueryAuthenticationServices"
    , "Ptr", pcAuthSvc   ; DWORD* out
    , "Ptr", asAuthSvc   ; SOLE_AUTHENTICATION_SERVICE** out
    , "Int")   ; return: HRESULT
●CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc) = DLL("OLE32.dll", "int CoQueryAuthenticationServices(void*, void*)")
# 呼び出し: CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
# pcAuthSvc : DWORD* out -> "void*"
# asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "ole32" fn CoQueryAuthenticationServices(
    pcAuthSvc: [*c]u32, // DWORD* out
    asAuthSvc: [*c][*c]SOLE_AUTHENTICATION_SERVICE // SOLE_AUTHENTICATION_SERVICE** out
) callconv(std.os.windows.WINAPI) i32;
proc CoQueryAuthenticationServices(
    pcAuthSvc: ptr uint32,  # DWORD* out
    asAuthSvc: ptr SOLE_AUTHENTICATION_SERVICE  # SOLE_AUTHENTICATION_SERVICE** out
): int32 {.importc: "CoQueryAuthenticationServices", stdcall, dynlib: "OLE32.dll".}
pragma(lib, "ole32");
extern(Windows)
int CoQueryAuthenticationServices(
    uint* pcAuthSvc,   // DWORD* out
    SOLE_AUTHENTICATION_SERVICE** asAuthSvc   // SOLE_AUTHENTICATION_SERVICE** out
);
ccall((:CoQueryAuthenticationServices, "OLE32.dll"), stdcall, Int32,
      (Ptr{UInt32}, Ptr{SOLE_AUTHENTICATION_SERVICE}),
      pcAuthSvc, asAuthSvc)
# pcAuthSvc : DWORD* out -> Ptr{UInt32}
# asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> Ptr{SOLE_AUTHENTICATION_SERVICE}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CoQueryAuthenticationServices(
    uint32_t* pcAuthSvc,
    void* asAuthSvc);
]]
local ole32 = ffi.load("ole32")
-- ole32.CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
-- pcAuthSvc : DWORD* out
-- asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('OLE32.dll');
const CoQueryAuthenticationServices = lib.func('__stdcall', 'CoQueryAuthenticationServices', 'int32_t', ['uint32_t *', 'void *']);
// CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
// pcAuthSvc : DWORD* out -> 'uint32_t *'
// asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("OLE32.dll", {
  CoQueryAuthenticationServices: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc)
// pcAuthSvc : DWORD* out -> "pointer"
// asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CoQueryAuthenticationServices(
    uint32_t* pcAuthSvc,
    void* asAuthSvc);
C, "OLE32.dll");
// $ffi->CoQueryAuthenticationServices(pcAuthSvc, asAuthSvc);
// pcAuthSvc : DWORD* out
// asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Ole32 extends StdCallLibrary {
    Ole32 INSTANCE = Native.load("ole32", Ole32.class);
    int CoQueryAuthenticationServices(
        IntByReference pcAuthSvc,   // DWORD* out
        Pointer asAuthSvc   // SOLE_AUTHENTICATION_SERVICE** out
    );
}
@[Link("ole32")]
lib LibOLE32
  fun CoQueryAuthenticationServices = CoQueryAuthenticationServices(
    pcAuthSvc : UInt32*,   # DWORD* out
    asAuthSvc : SOLE_AUTHENTICATION_SERVICE**   # SOLE_AUTHENTICATION_SERVICE** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CoQueryAuthenticationServicesNative = Int32 Function(Pointer<Uint32>, Pointer<Void>);
typedef CoQueryAuthenticationServicesDart = int Function(Pointer<Uint32>, Pointer<Void>);
final CoQueryAuthenticationServices = DynamicLibrary.open('OLE32.dll')
    .lookupFunction<CoQueryAuthenticationServicesNative, CoQueryAuthenticationServicesDart>('CoQueryAuthenticationServices');
// pcAuthSvc : DWORD* out -> Pointer<Uint32>
// asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CoQueryAuthenticationServices(
  pcAuthSvc: Pointer;   // DWORD* out
  asAuthSvc: Pointer   // SOLE_AUTHENTICATION_SERVICE** out
): Integer; stdcall;
  external 'OLE32.dll' name 'CoQueryAuthenticationServices';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CoQueryAuthenticationServices"
  c_CoQueryAuthenticationServices :: Ptr Word32 -> Ptr () -> IO Int32
-- pcAuthSvc : DWORD* out -> Ptr Word32
-- asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let coqueryauthenticationservices =
  foreign "CoQueryAuthenticationServices"
    ((ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* pcAuthSvc : DWORD* out -> (ptr uint32_t) *)
(* asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library ole32 (t "OLE32.dll"))
(cffi:use-foreign-library ole32)

(cffi:defcfun ("CoQueryAuthenticationServices" co-query-authentication-services :convention :stdcall) :int32
  (pc-auth-svc :pointer)   ; DWORD* out
  (as-auth-svc :pointer))   ; SOLE_AUTHENTICATION_SERVICE** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CoQueryAuthenticationServices = Win32::API::More->new('OLE32',
    'int CoQueryAuthenticationServices(LPVOID pcAuthSvc, LPVOID asAuthSvc)');
# my $ret = $CoQueryAuthenticationServices->Call($pcAuthSvc, $asAuthSvc);
# pcAuthSvc : DWORD* out -> LPVOID
# asAuthSvc : SOLE_AUTHENTICATION_SERVICE** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型