ホーム › Networking.ActiveDirectory › DsGetSpnA
DsGetSpnA
関数サービス情報からSPNの配列を生成する(ANSI版)。
シグネチャ
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsGetSpnA(
DS_SPN_NAME_TYPE ServiceType,
LPCSTR ServiceClass,
LPCSTR ServiceName, // optional
WORD InstancePort,
WORD cInstanceNames,
LPCSTR* pInstanceNames, // optional
const WORD* pInstancePorts, // optional
DWORD* pcSpn,
LPSTR** prpszSpn
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ServiceType | DS_SPN_NAME_TYPE | in | 生成するSPNの種類を示すDS_SPN_NAME_TYPE列挙値。 |
| ServiceClass | LPCSTR | in | サービスクラス名(ANSI)。 |
| ServiceName | LPCSTR | inoptional | サービス名。種類により省略可。NULL可。 |
| InstancePort | WORD | in | 既定のインスタンスポート番号。0で省略する。 |
| cInstanceNames | WORD | in | pInstanceNames配列の要素数。0で単一SPN生成。 |
| pInstanceNames | LPCSTR* | inoptional | インスタンス名の配列へのポインタ。NULL可。 |
| pInstancePorts | WORD* | inoptional | 各インスタンスのポート番号配列へのポインタ。NULL可。 |
| pcSpn | DWORD* | out | 生成されたSPNの個数を受け取るDWORDへのポインタ。 |
| prpszSpn | LPSTR** | out | 生成されたSPN文字列配列を受け取るポインタのアドレス。DsFreeSpnArrayAで解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsGetSpnA(
DS_SPN_NAME_TYPE ServiceType,
LPCSTR ServiceClass,
LPCSTR ServiceName, // optional
WORD InstancePort,
WORD cInstanceNames,
LPCSTR* pInstanceNames, // optional
const WORD* pInstancePorts, // optional
DWORD* pcSpn,
LPSTR** prpszSpn
);[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsGetSpnA(
int ServiceType, // DS_SPN_NAME_TYPE
[MarshalAs(UnmanagedType.LPStr)] string ServiceClass, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string ServiceName, // LPCSTR optional
ushort InstancePort, // WORD
ushort cInstanceNames, // WORD
IntPtr pInstanceNames, // LPCSTR* optional
IntPtr pInstancePorts, // WORD* optional
out uint pcSpn, // DWORD* out
IntPtr prpszSpn // LPSTR** out
);<DllImport("NTDSAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsGetSpnA(
ServiceType As Integer, ' DS_SPN_NAME_TYPE
<MarshalAs(UnmanagedType.LPStr)> ServiceClass As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> ServiceName As String, ' LPCSTR optional
InstancePort As UShort, ' WORD
cInstanceNames As UShort, ' WORD
pInstanceNames As IntPtr, ' LPCSTR* optional
pInstancePorts As IntPtr, ' WORD* optional
<Out> ByRef pcSpn As UInteger, ' DWORD* out
prpszSpn As IntPtr ' LPSTR** out
) As UInteger
End Function' ServiceType : DS_SPN_NAME_TYPE
' ServiceClass : LPCSTR
' ServiceName : LPCSTR optional
' InstancePort : WORD
' cInstanceNames : WORD
' pInstanceNames : LPCSTR* optional
' pInstancePorts : WORD* optional
' pcSpn : DWORD* out
' prpszSpn : LPSTR** out
Declare PtrSafe Function DsGetSpnA Lib "ntdsapi" ( _
ByVal ServiceType As Long, _
ByVal ServiceClass As String, _
ByVal ServiceName As String, _
ByVal InstancePort As Integer, _
ByVal cInstanceNames As Integer, _
ByVal pInstanceNames As LongPtr, _
ByVal pInstancePorts As LongPtr, _
ByRef pcSpn As Long, _
ByVal prpszSpn As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DsGetSpnA = ctypes.windll.ntdsapi.DsGetSpnA
DsGetSpnA.restype = wintypes.DWORD
DsGetSpnA.argtypes = [
ctypes.c_int, # ServiceType : DS_SPN_NAME_TYPE
wintypes.LPCSTR, # ServiceClass : LPCSTR
wintypes.LPCSTR, # ServiceName : LPCSTR optional
ctypes.c_ushort, # InstancePort : WORD
ctypes.c_ushort, # cInstanceNames : WORD
ctypes.c_void_p, # pInstanceNames : LPCSTR* optional
ctypes.POINTER(ctypes.c_ushort), # pInstancePorts : WORD* optional
ctypes.POINTER(wintypes.DWORD), # pcSpn : DWORD* out
ctypes.c_void_p, # prpszSpn : LPSTR** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsGetSpnA = Fiddle::Function.new(
lib['DsGetSpnA'],
[
Fiddle::TYPE_INT, # ServiceType : DS_SPN_NAME_TYPE
Fiddle::TYPE_VOIDP, # ServiceClass : LPCSTR
Fiddle::TYPE_VOIDP, # ServiceName : LPCSTR optional
-Fiddle::TYPE_SHORT, # InstancePort : WORD
-Fiddle::TYPE_SHORT, # cInstanceNames : WORD
Fiddle::TYPE_VOIDP, # pInstanceNames : LPCSTR* optional
Fiddle::TYPE_VOIDP, # pInstancePorts : WORD* optional
Fiddle::TYPE_VOIDP, # pcSpn : DWORD* out
Fiddle::TYPE_VOIDP, # prpszSpn : LPSTR** out
],
-Fiddle::TYPE_INT)#[link(name = "ntdsapi")]
extern "system" {
fn DsGetSpnA(
ServiceType: i32, // DS_SPN_NAME_TYPE
ServiceClass: *const u8, // LPCSTR
ServiceName: *const u8, // LPCSTR optional
InstancePort: u16, // WORD
cInstanceNames: u16, // WORD
pInstanceNames: *const *const u8, // LPCSTR* optional
pInstancePorts: *const u16, // WORD* optional
pcSpn: *mut u32, // DWORD* out
prpszSpn: *mut *mut *mut u8 // LPSTR** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint DsGetSpnA(int ServiceType, [MarshalAs(UnmanagedType.LPStr)] string ServiceClass, [MarshalAs(UnmanagedType.LPStr)] string ServiceName, ushort InstancePort, ushort cInstanceNames, IntPtr pInstanceNames, IntPtr pInstancePorts, out uint pcSpn, IntPtr prpszSpn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsGetSpnA' -Namespace Win32 -PassThru
# $api::DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)#uselib "NTDSAPI.dll"
#func global DsGetSpnA "DsGetSpnA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; DsGetSpnA ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn) ; 戻り値は stat
; ServiceType : DS_SPN_NAME_TYPE -> "sptr"
; ServiceClass : LPCSTR -> "sptr"
; ServiceName : LPCSTR optional -> "sptr"
; InstancePort : WORD -> "sptr"
; cInstanceNames : WORD -> "sptr"
; pInstanceNames : LPCSTR* optional -> "sptr"
; pInstancePorts : WORD* optional -> "sptr"
; pcSpn : DWORD* out -> "sptr"
; prpszSpn : LPSTR** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NTDSAPI.dll" #cfunc global DsGetSpnA "DsGetSpnA" int, str, str, int, int, var, var, var, var ; res = DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR optional -> "str" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCSTR* optional -> "var" ; pInstancePorts : WORD* optional -> "var" ; pcSpn : DWORD* out -> "var" ; prpszSpn : LPSTR** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NTDSAPI.dll" #cfunc global DsGetSpnA "DsGetSpnA" int, str, str, int, int, sptr, sptr, sptr, sptr ; res = DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn)) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR optional -> "str" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCSTR* optional -> "sptr" ; pInstancePorts : WORD* optional -> "sptr" ; pcSpn : DWORD* out -> "sptr" ; prpszSpn : LPSTR** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DsGetSpnA(DS_SPN_NAME_TYPE ServiceType, LPCSTR ServiceClass, LPCSTR ServiceName, WORD InstancePort, WORD cInstanceNames, LPCSTR* pInstanceNames, WORD* pInstancePorts, DWORD* pcSpn, LPSTR** prpszSpn) #uselib "NTDSAPI.dll" #cfunc global DsGetSpnA "DsGetSpnA" int, str, str, int, int, var, var, var, var ; res = DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR optional -> "str" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCSTR* optional -> "var" ; pInstancePorts : WORD* optional -> "var" ; pcSpn : DWORD* out -> "var" ; prpszSpn : LPSTR** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DsGetSpnA(DS_SPN_NAME_TYPE ServiceType, LPCSTR ServiceClass, LPCSTR ServiceName, WORD InstancePort, WORD cInstanceNames, LPCSTR* pInstanceNames, WORD* pInstancePorts, DWORD* pcSpn, LPSTR** prpszSpn) #uselib "NTDSAPI.dll" #cfunc global DsGetSpnA "DsGetSpnA" int, str, str, int, int, intptr, intptr, intptr, intptr ; res = DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, varptr(pInstanceNames), varptr(pInstancePorts), varptr(pcSpn), varptr(prpszSpn)) ; ServiceType : DS_SPN_NAME_TYPE -> "int" ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR optional -> "str" ; InstancePort : WORD -> "int" ; cInstanceNames : WORD -> "int" ; pInstanceNames : LPCSTR* optional -> "intptr" ; pInstancePorts : WORD* optional -> "intptr" ; pcSpn : DWORD* out -> "intptr" ; prpszSpn : LPSTR** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsGetSpnA = ntdsapi.NewProc("DsGetSpnA")
)
// ServiceType (DS_SPN_NAME_TYPE), ServiceClass (LPCSTR), ServiceName (LPCSTR optional), InstancePort (WORD), cInstanceNames (WORD), pInstanceNames (LPCSTR* optional), pInstancePorts (WORD* optional), pcSpn (DWORD* out), prpszSpn (LPSTR** out)
r1, _, err := procDsGetSpnA.Call(
uintptr(ServiceType),
uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceClass))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceName))),
uintptr(InstancePort),
uintptr(cInstanceNames),
uintptr(pInstanceNames),
uintptr(pInstancePorts),
uintptr(pcSpn),
uintptr(prpszSpn),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsGetSpnA(
ServiceType: Integer; // DS_SPN_NAME_TYPE
ServiceClass: PAnsiChar; // LPCSTR
ServiceName: PAnsiChar; // LPCSTR optional
InstancePort: Word; // WORD
cInstanceNames: Word; // WORD
pInstanceNames: PPAnsiChar; // LPCSTR* optional
pInstancePorts: Pointer; // WORD* optional
pcSpn: Pointer; // DWORD* out
prpszSpn: PPAnsiChar // LPSTR** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsGetSpnA';result := DllCall("NTDSAPI\DsGetSpnA"
, "Int", ServiceType ; DS_SPN_NAME_TYPE
, "AStr", ServiceClass ; LPCSTR
, "AStr", ServiceName ; LPCSTR optional
, "UShort", InstancePort ; WORD
, "UShort", cInstanceNames ; WORD
, "Ptr", pInstanceNames ; LPCSTR* optional
, "Ptr", pInstancePorts ; WORD* optional
, "Ptr", pcSpn ; DWORD* out
, "Ptr", prpszSpn ; LPSTR** out
, "UInt") ; return: DWORD●DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn) = DLL("NTDSAPI.dll", "dword DsGetSpnA(int, char*, char*, int, int, void*, void*, void*, void*)")
# 呼び出し: DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
# ServiceType : DS_SPN_NAME_TYPE -> "int"
# ServiceClass : LPCSTR -> "char*"
# ServiceName : LPCSTR optional -> "char*"
# InstancePort : WORD -> "int"
# cInstanceNames : WORD -> "int"
# pInstanceNames : LPCSTR* optional -> "void*"
# pInstancePorts : WORD* optional -> "void*"
# pcSpn : DWORD* out -> "void*"
# prpszSpn : LPSTR** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ntdsapi" fn DsGetSpnA(
ServiceType: i32, // DS_SPN_NAME_TYPE
ServiceClass: [*c]const u8, // LPCSTR
ServiceName: [*c]const u8, // LPCSTR optional
InstancePort: u16, // WORD
cInstanceNames: u16, // WORD
pInstanceNames: [*c][*c]u8, // LPCSTR* optional
pInstancePorts: [*c]u16, // WORD* optional
pcSpn: [*c]u32, // DWORD* out
prpszSpn: [*c][*c][*c]u8 // LPSTR** out
) callconv(std.os.windows.WINAPI) u32;proc DsGetSpnA(
ServiceType: int32, # DS_SPN_NAME_TYPE
ServiceClass: cstring, # LPCSTR
ServiceName: cstring, # LPCSTR optional
InstancePort: uint16, # WORD
cInstanceNames: uint16, # WORD
pInstanceNames: ptr cstring, # LPCSTR* optional
pInstancePorts: ptr uint16, # WORD* optional
pcSpn: ptr uint32, # DWORD* out
prpszSpn: ptr cstring # LPSTR** out
): uint32 {.importc: "DsGetSpnA", stdcall, dynlib: "NTDSAPI.dll".}pragma(lib, "ntdsapi");
extern(Windows)
uint DsGetSpnA(
int ServiceType, // DS_SPN_NAME_TYPE
const(char)* ServiceClass, // LPCSTR
const(char)* ServiceName, // LPCSTR optional
ushort InstancePort, // WORD
ushort cInstanceNames, // WORD
char** pInstanceNames, // LPCSTR* optional
ushort* pInstancePorts, // WORD* optional
uint* pcSpn, // DWORD* out
char*** prpszSpn // LPSTR** out
);ccall((:DsGetSpnA, "NTDSAPI.dll"), stdcall, UInt32,
(Int32, Cstring, Cstring, UInt16, UInt16, Ptr{Ptr{UInt8}}, Ptr{UInt16}, Ptr{UInt32}, Ptr{Ptr{UInt8}}),
ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
# ServiceType : DS_SPN_NAME_TYPE -> Int32
# ServiceClass : LPCSTR -> Cstring
# ServiceName : LPCSTR optional -> Cstring
# InstancePort : WORD -> UInt16
# cInstanceNames : WORD -> UInt16
# pInstanceNames : LPCSTR* optional -> Ptr{Ptr{UInt8}}
# pInstancePorts : WORD* optional -> Ptr{UInt16}
# pcSpn : DWORD* out -> Ptr{UInt32}
# prpszSpn : LPSTR** out -> Ptr{Ptr{UInt8}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DsGetSpnA(
int32_t ServiceType,
const char* ServiceClass,
const char* ServiceName,
uint16_t InstancePort,
uint16_t cInstanceNames,
char** pInstanceNames,
uint16_t* pInstancePorts,
uint32_t* pcSpn,
char*** prpszSpn);
]]
local ntdsapi = ffi.load("ntdsapi")
-- ntdsapi.DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
-- ServiceType : DS_SPN_NAME_TYPE
-- ServiceClass : LPCSTR
-- ServiceName : LPCSTR optional
-- InstancePort : WORD
-- cInstanceNames : WORD
-- pInstanceNames : LPCSTR* optional
-- pInstancePorts : WORD* optional
-- pcSpn : DWORD* out
-- prpszSpn : LPSTR** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NTDSAPI.dll');
const DsGetSpnA = lib.func('__stdcall', 'DsGetSpnA', 'uint32_t', ['int32_t', 'str', 'str', 'uint16_t', 'uint16_t', 'void *', 'uint16_t *', 'uint32_t *', 'void *']);
// DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
// ServiceType : DS_SPN_NAME_TYPE -> 'int32_t'
// ServiceClass : LPCSTR -> 'str'
// ServiceName : LPCSTR optional -> 'str'
// InstancePort : WORD -> 'uint16_t'
// cInstanceNames : WORD -> 'uint16_t'
// pInstanceNames : LPCSTR* optional -> 'void *'
// pInstancePorts : WORD* optional -> 'uint16_t *'
// pcSpn : DWORD* out -> 'uint32_t *'
// prpszSpn : LPSTR** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NTDSAPI.dll", {
DsGetSpnA: { parameters: ["i32", "buffer", "buffer", "u16", "u16", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn)
// ServiceType : DS_SPN_NAME_TYPE -> "i32"
// ServiceClass : LPCSTR -> "buffer"
// ServiceName : LPCSTR optional -> "buffer"
// InstancePort : WORD -> "u16"
// cInstanceNames : WORD -> "u16"
// pInstanceNames : LPCSTR* optional -> "pointer"
// pInstancePorts : WORD* optional -> "pointer"
// pcSpn : DWORD* out -> "pointer"
// prpszSpn : LPSTR** out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DsGetSpnA(
int32_t ServiceType,
const char* ServiceClass,
const char* ServiceName,
uint16_t InstancePort,
uint16_t cInstanceNames,
char** pInstanceNames,
uint16_t* pInstancePorts,
uint32_t* pcSpn,
char*** prpszSpn);
C, "NTDSAPI.dll");
// $ffi->DsGetSpnA(ServiceType, ServiceClass, ServiceName, InstancePort, cInstanceNames, pInstanceNames, pInstancePorts, pcSpn, prpszSpn);
// ServiceType : DS_SPN_NAME_TYPE
// ServiceClass : LPCSTR
// ServiceName : LPCSTR optional
// InstancePort : WORD
// cInstanceNames : WORD
// pInstanceNames : LPCSTR* optional
// pInstancePorts : WORD* optional
// pcSpn : DWORD* out
// prpszSpn : LPSTR** 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 Ntdsapi extends StdCallLibrary {
Ntdsapi INSTANCE = Native.load("ntdsapi", Ntdsapi.class, W32APIOptions.ASCII_OPTIONS);
int DsGetSpnA(
int ServiceType, // DS_SPN_NAME_TYPE
String ServiceClass, // LPCSTR
String ServiceName, // LPCSTR optional
short InstancePort, // WORD
short cInstanceNames, // WORD
PointerByReference pInstanceNames, // LPCSTR* optional
ShortByReference pInstancePorts, // WORD* optional
IntByReference pcSpn, // DWORD* out
PointerByReference prpszSpn // LPSTR** out
);
}@[Link("ntdsapi")]
lib LibNTDSAPI
fun DsGetSpnA = DsGetSpnA(
ServiceType : Int32, # DS_SPN_NAME_TYPE
ServiceClass : UInt8*, # LPCSTR
ServiceName : UInt8*, # LPCSTR optional
InstancePort : UInt16, # WORD
cInstanceNames : UInt16, # WORD
pInstanceNames : UInt8**, # LPCSTR* optional
pInstancePorts : UInt16*, # WORD* optional
pcSpn : UInt32*, # DWORD* out
prpszSpn : UInt8*** # LPSTR** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DsGetSpnANative = Uint32 Function(Int32, Pointer<Utf8>, Pointer<Utf8>, Uint16, Uint16, Pointer<Pointer<Utf8>>, Pointer<Uint16>, Pointer<Uint32>, Pointer<Pointer<Utf8>>);
typedef DsGetSpnADart = int Function(int, Pointer<Utf8>, Pointer<Utf8>, int, int, Pointer<Pointer<Utf8>>, Pointer<Uint16>, Pointer<Uint32>, Pointer<Pointer<Utf8>>);
final DsGetSpnA = DynamicLibrary.open('NTDSAPI.dll')
.lookupFunction<DsGetSpnANative, DsGetSpnADart>('DsGetSpnA');
// ServiceType : DS_SPN_NAME_TYPE -> Int32
// ServiceClass : LPCSTR -> Pointer<Utf8>
// ServiceName : LPCSTR optional -> Pointer<Utf8>
// InstancePort : WORD -> Uint16
// cInstanceNames : WORD -> Uint16
// pInstanceNames : LPCSTR* optional -> Pointer<Pointer<Utf8>>
// pInstancePorts : WORD* optional -> Pointer<Uint16>
// pcSpn : DWORD* out -> Pointer<Uint32>
// prpszSpn : LPSTR** out -> Pointer<Pointer<Utf8>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DsGetSpnA(
ServiceType: Integer; // DS_SPN_NAME_TYPE
ServiceClass: PAnsiChar; // LPCSTR
ServiceName: PAnsiChar; // LPCSTR optional
InstancePort: Word; // WORD
cInstanceNames: Word; // WORD
pInstanceNames: PPAnsiChar; // LPCSTR* optional
pInstancePorts: Pointer; // WORD* optional
pcSpn: Pointer; // DWORD* out
prpszSpn: PPAnsiChar // LPSTR** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsGetSpnA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DsGetSpnA"
c_DsGetSpnA :: Int32 -> CString -> CString -> Word16 -> Word16 -> Ptr CString -> Ptr Word16 -> Ptr Word32 -> Ptr CString -> IO Word32
-- ServiceType : DS_SPN_NAME_TYPE -> Int32
-- ServiceClass : LPCSTR -> CString
-- ServiceName : LPCSTR optional -> CString
-- InstancePort : WORD -> Word16
-- cInstanceNames : WORD -> Word16
-- pInstanceNames : LPCSTR* optional -> Ptr CString
-- pInstancePorts : WORD* optional -> Ptr Word16
-- pcSpn : DWORD* out -> Ptr Word32
-- prpszSpn : LPSTR** out -> Ptr CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dsgetspna =
foreign "DsGetSpnA"
(int32_t @-> string @-> string @-> uint16_t @-> uint16_t @-> (ptr string) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> (ptr string) @-> returning uint32_t)
(* ServiceType : DS_SPN_NAME_TYPE -> int32_t *)
(* ServiceClass : LPCSTR -> string *)
(* ServiceName : LPCSTR optional -> string *)
(* InstancePort : WORD -> uint16_t *)
(* cInstanceNames : WORD -> uint16_t *)
(* pInstanceNames : LPCSTR* optional -> (ptr string) *)
(* pInstancePorts : WORD* optional -> (ptr uint16_t) *)
(* pcSpn : DWORD* out -> (ptr uint32_t) *)
(* prpszSpn : LPSTR** out -> (ptr string) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ntdsapi (t "NTDSAPI.dll"))
(cffi:use-foreign-library ntdsapi)
(cffi:defcfun ("DsGetSpnA" ds-get-spn-a :convention :stdcall) :uint32
(service-type :int32) ; DS_SPN_NAME_TYPE
(service-class :string) ; LPCSTR
(service-name :string) ; LPCSTR optional
(instance-port :uint16) ; WORD
(c-instance-names :uint16) ; WORD
(p-instance-names :pointer) ; LPCSTR* optional
(p-instance-ports :pointer) ; WORD* optional
(pc-spn :pointer) ; DWORD* out
(prpsz-spn :pointer)) ; LPSTR** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DsGetSpnA = Win32::API::More->new('NTDSAPI',
'DWORD DsGetSpnA(int ServiceType, LPCSTR ServiceClass, LPCSTR ServiceName, WORD InstancePort, WORD cInstanceNames, LPVOID pInstanceNames, LPVOID pInstancePorts, LPVOID pcSpn, LPVOID prpszSpn)');
# my $ret = $DsGetSpnA->Call($ServiceType, $ServiceClass, $ServiceName, $InstancePort, $cInstanceNames, $pInstanceNames, $pInstancePorts, $pcSpn, $prpszSpn);
# ServiceType : DS_SPN_NAME_TYPE -> int
# ServiceClass : LPCSTR -> LPCSTR
# ServiceName : LPCSTR optional -> LPCSTR
# InstancePort : WORD -> WORD
# cInstanceNames : WORD -> WORD
# pInstanceNames : LPCSTR* optional -> LPVOID
# pInstancePorts : WORD* optional -> LPVOID
# pcSpn : DWORD* out -> LPVOID
# prpszSpn : LPSTR** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f DsGetSpnW (Unicode版) — サービス情報からSPNの配列を生成する(Unicode版)。
使用する型