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