ホーム › Security.Cryptography.Certificates › PstGetUserNameForCertificate
PstGetUserNameForCertificate
関数指定した証明書に対応するユーザー名を取得する。
シグネチャ
// certpoleng.dll
#include <windows.h>
NTSTATUS PstGetUserNameForCertificate(
const CERT_CONTEXT* pCertContext,
UNICODE_STRING* UserName
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pCertContext | CERT_CONTEXT* | in | ユーザー名を取得する対象の証明書を指すCERT_CONTEXT構造体へのポインタ。証明書のデコード済みコンテキストを渡す。 |
| UserName | UNICODE_STRING* | out | 証明書から導出されたユーザー名を受け取るUNICODE_STRING構造体へのポインタ。呼び出し側がバッファを管理する。 |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// certpoleng.dll
#include <windows.h>
NTSTATUS PstGetUserNameForCertificate(
const CERT_CONTEXT* pCertContext,
UNICODE_STRING* UserName
);[DllImport("certpoleng.dll", ExactSpelling = true)]
static extern int PstGetUserNameForCertificate(
IntPtr pCertContext, // CERT_CONTEXT*
IntPtr UserName // UNICODE_STRING* out
);<DllImport("certpoleng.dll", ExactSpelling:=True)>
Public Shared Function PstGetUserNameForCertificate(
pCertContext As IntPtr, ' CERT_CONTEXT*
UserName As IntPtr ' UNICODE_STRING* out
) As Integer
End Function' pCertContext : CERT_CONTEXT*
' UserName : UNICODE_STRING* out
Declare PtrSafe Function PstGetUserNameForCertificate Lib "certpoleng" ( _
ByVal pCertContext As LongPtr, _
ByVal UserName As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PstGetUserNameForCertificate = ctypes.windll.certpoleng.PstGetUserNameForCertificate
PstGetUserNameForCertificate.restype = ctypes.c_int
PstGetUserNameForCertificate.argtypes = [
ctypes.c_void_p, # pCertContext : CERT_CONTEXT*
ctypes.c_void_p, # UserName : UNICODE_STRING* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('certpoleng.dll')
PstGetUserNameForCertificate = Fiddle::Function.new(
lib['PstGetUserNameForCertificate'],
[
Fiddle::TYPE_VOIDP, # pCertContext : CERT_CONTEXT*
Fiddle::TYPE_VOIDP, # UserName : UNICODE_STRING* out
],
Fiddle::TYPE_INT)#[link(name = "certpoleng")]
extern "system" {
fn PstGetUserNameForCertificate(
pCertContext: *const CERT_CONTEXT, // CERT_CONTEXT*
UserName: *mut UNICODE_STRING // UNICODE_STRING* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("certpoleng.dll")]
public static extern int PstGetUserNameForCertificate(IntPtr pCertContext, IntPtr UserName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'certpoleng_PstGetUserNameForCertificate' -Namespace Win32 -PassThru
# $api::PstGetUserNameForCertificate(pCertContext, UserName)#uselib "certpoleng.dll"
#func global PstGetUserNameForCertificate "PstGetUserNameForCertificate" sptr, sptr
; PstGetUserNameForCertificate varptr(pCertContext), varptr(UserName) ; 戻り値は stat
; pCertContext : CERT_CONTEXT* -> "sptr"
; UserName : UNICODE_STRING* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "certpoleng.dll" #cfunc global PstGetUserNameForCertificate "PstGetUserNameForCertificate" var, var ; res = PstGetUserNameForCertificate(pCertContext, UserName) ; pCertContext : CERT_CONTEXT* -> "var" ; UserName : UNICODE_STRING* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "certpoleng.dll" #cfunc global PstGetUserNameForCertificate "PstGetUserNameForCertificate" sptr, sptr ; res = PstGetUserNameForCertificate(varptr(pCertContext), varptr(UserName)) ; pCertContext : CERT_CONTEXT* -> "sptr" ; UserName : UNICODE_STRING* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS PstGetUserNameForCertificate(CERT_CONTEXT* pCertContext, UNICODE_STRING* UserName) #uselib "certpoleng.dll" #cfunc global PstGetUserNameForCertificate "PstGetUserNameForCertificate" var, var ; res = PstGetUserNameForCertificate(pCertContext, UserName) ; pCertContext : CERT_CONTEXT* -> "var" ; UserName : UNICODE_STRING* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS PstGetUserNameForCertificate(CERT_CONTEXT* pCertContext, UNICODE_STRING* UserName) #uselib "certpoleng.dll" #cfunc global PstGetUserNameForCertificate "PstGetUserNameForCertificate" intptr, intptr ; res = PstGetUserNameForCertificate(varptr(pCertContext), varptr(UserName)) ; pCertContext : CERT_CONTEXT* -> "intptr" ; UserName : UNICODE_STRING* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
certpoleng = windows.NewLazySystemDLL("certpoleng.dll")
procPstGetUserNameForCertificate = certpoleng.NewProc("PstGetUserNameForCertificate")
)
// pCertContext (CERT_CONTEXT*), UserName (UNICODE_STRING* out)
r1, _, err := procPstGetUserNameForCertificate.Call(
uintptr(pCertContext),
uintptr(UserName),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction PstGetUserNameForCertificate(
pCertContext: Pointer; // CERT_CONTEXT*
UserName: Pointer // UNICODE_STRING* out
): Integer; stdcall;
external 'certpoleng.dll' name 'PstGetUserNameForCertificate';result := DllCall("certpoleng\PstGetUserNameForCertificate"
, "Ptr", pCertContext ; CERT_CONTEXT*
, "Ptr", UserName ; UNICODE_STRING* out
, "Int") ; return: NTSTATUS●PstGetUserNameForCertificate(pCertContext, UserName) = DLL("certpoleng.dll", "int PstGetUserNameForCertificate(void*, void*)")
# 呼び出し: PstGetUserNameForCertificate(pCertContext, UserName)
# pCertContext : CERT_CONTEXT* -> "void*"
# UserName : UNICODE_STRING* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "certpoleng" fn PstGetUserNameForCertificate(
pCertContext: [*c]CERT_CONTEXT, // CERT_CONTEXT*
UserName: [*c]UNICODE_STRING // UNICODE_STRING* out
) callconv(std.os.windows.WINAPI) i32;proc PstGetUserNameForCertificate(
pCertContext: ptr CERT_CONTEXT, # CERT_CONTEXT*
UserName: ptr UNICODE_STRING # UNICODE_STRING* out
): int32 {.importc: "PstGetUserNameForCertificate", stdcall, dynlib: "certpoleng.dll".}pragma(lib, "certpoleng");
extern(Windows)
int PstGetUserNameForCertificate(
CERT_CONTEXT* pCertContext, // CERT_CONTEXT*
UNICODE_STRING* UserName // UNICODE_STRING* out
);ccall((:PstGetUserNameForCertificate, "certpoleng.dll"), stdcall, Int32,
(Ptr{CERT_CONTEXT}, Ptr{UNICODE_STRING}),
pCertContext, UserName)
# pCertContext : CERT_CONTEXT* -> Ptr{CERT_CONTEXT}
# UserName : UNICODE_STRING* out -> Ptr{UNICODE_STRING}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t PstGetUserNameForCertificate(
void* pCertContext,
void* UserName);
]]
local certpoleng = ffi.load("certpoleng")
-- certpoleng.PstGetUserNameForCertificate(pCertContext, UserName)
-- pCertContext : CERT_CONTEXT*
-- UserName : UNICODE_STRING* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('certpoleng.dll');
const PstGetUserNameForCertificate = lib.func('__stdcall', 'PstGetUserNameForCertificate', 'int32_t', ['void *', 'void *']);
// PstGetUserNameForCertificate(pCertContext, UserName)
// pCertContext : CERT_CONTEXT* -> 'void *'
// UserName : UNICODE_STRING* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("certpoleng.dll", {
PstGetUserNameForCertificate: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.PstGetUserNameForCertificate(pCertContext, UserName)
// pCertContext : CERT_CONTEXT* -> "pointer"
// UserName : UNICODE_STRING* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t PstGetUserNameForCertificate(
void* pCertContext,
void* UserName);
C, "certpoleng.dll");
// $ffi->PstGetUserNameForCertificate(pCertContext, UserName);
// pCertContext : CERT_CONTEXT*
// UserName : UNICODE_STRING* 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 Certpoleng extends StdCallLibrary {
Certpoleng INSTANCE = Native.load("certpoleng", Certpoleng.class);
int PstGetUserNameForCertificate(
Pointer pCertContext, // CERT_CONTEXT*
Pointer UserName // UNICODE_STRING* out
);
}@[Link("certpoleng")]
lib Libcertpoleng
fun PstGetUserNameForCertificate = PstGetUserNameForCertificate(
pCertContext : CERT_CONTEXT*, # CERT_CONTEXT*
UserName : UNICODE_STRING* # UNICODE_STRING* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef PstGetUserNameForCertificateNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef PstGetUserNameForCertificateDart = int Function(Pointer<Void>, Pointer<Void>);
final PstGetUserNameForCertificate = DynamicLibrary.open('certpoleng.dll')
.lookupFunction<PstGetUserNameForCertificateNative, PstGetUserNameForCertificateDart>('PstGetUserNameForCertificate');
// pCertContext : CERT_CONTEXT* -> Pointer<Void>
// UserName : UNICODE_STRING* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PstGetUserNameForCertificate(
pCertContext: Pointer; // CERT_CONTEXT*
UserName: Pointer // UNICODE_STRING* out
): Integer; stdcall;
external 'certpoleng.dll' name 'PstGetUserNameForCertificate';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PstGetUserNameForCertificate"
c_PstGetUserNameForCertificate :: Ptr () -> Ptr () -> IO Int32
-- pCertContext : CERT_CONTEXT* -> Ptr ()
-- UserName : UNICODE_STRING* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let pstgetusernameforcertificate =
foreign "PstGetUserNameForCertificate"
((ptr void) @-> (ptr void) @-> returning int32_t)
(* pCertContext : CERT_CONTEXT* -> (ptr void) *)
(* UserName : UNICODE_STRING* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library certpoleng (t "certpoleng.dll"))
(cffi:use-foreign-library certpoleng)
(cffi:defcfun ("PstGetUserNameForCertificate" pst-get-user-name-for-certificate :convention :stdcall) :int32
(p-cert-context :pointer) ; CERT_CONTEXT*
(user-name :pointer)) ; UNICODE_STRING* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PstGetUserNameForCertificate = Win32::API::More->new('certpoleng',
'int PstGetUserNameForCertificate(LPVOID pCertContext, LPVOID UserName)');
# my $ret = $PstGetUserNameForCertificate->Call($pCertContext, $UserName);
# pCertContext : CERT_CONTEXT* -> LPVOID
# UserName : UNICODE_STRING* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。