ホーム › Networking.ActiveDirectory › DsClientMakeSpnForTargetServerA
DsClientMakeSpnForTargetServerA
関数対象サーバー向けのクライアント用SPNを生成する(ANSI版)。
シグネチャ
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsClientMakeSpnForTargetServerA(
LPCSTR ServiceClass,
LPCSTR ServiceName,
DWORD* pcSpnLength,
LPSTR pszSpn
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| ServiceClass | LPCSTR | in |
| ServiceName | LPCSTR | in |
| pcSpnLength | DWORD* | inout |
| pszSpn | LPSTR | out |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsClientMakeSpnForTargetServerA(
LPCSTR ServiceClass,
LPCSTR ServiceName,
DWORD* pcSpnLength,
LPSTR pszSpn
);[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsClientMakeSpnForTargetServerA(
[MarshalAs(UnmanagedType.LPStr)] string ServiceClass, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string ServiceName, // LPCSTR
ref uint pcSpnLength, // DWORD* in/out
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszSpn // LPSTR out
);<DllImport("NTDSAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsClientMakeSpnForTargetServerA(
<MarshalAs(UnmanagedType.LPStr)> ServiceClass As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> ServiceName As String, ' LPCSTR
ByRef pcSpnLength As UInteger, ' DWORD* in/out
<MarshalAs(UnmanagedType.LPStr)> pszSpn As System.Text.StringBuilder ' LPSTR out
) As UInteger
End Function' ServiceClass : LPCSTR
' ServiceName : LPCSTR
' pcSpnLength : DWORD* in/out
' pszSpn : LPSTR out
Declare PtrSafe Function DsClientMakeSpnForTargetServerA Lib "ntdsapi" ( _
ByVal ServiceClass As String, _
ByVal ServiceName As String, _
ByRef pcSpnLength As Long, _
ByVal pszSpn As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DsClientMakeSpnForTargetServerA = ctypes.windll.ntdsapi.DsClientMakeSpnForTargetServerA
DsClientMakeSpnForTargetServerA.restype = wintypes.DWORD
DsClientMakeSpnForTargetServerA.argtypes = [
wintypes.LPCSTR, # ServiceClass : LPCSTR
wintypes.LPCSTR, # ServiceName : LPCSTR
ctypes.POINTER(wintypes.DWORD), # pcSpnLength : DWORD* in/out
wintypes.LPSTR, # pszSpn : LPSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsClientMakeSpnForTargetServerA = Fiddle::Function.new(
lib['DsClientMakeSpnForTargetServerA'],
[
Fiddle::TYPE_VOIDP, # ServiceClass : LPCSTR
Fiddle::TYPE_VOIDP, # ServiceName : LPCSTR
Fiddle::TYPE_VOIDP, # pcSpnLength : DWORD* in/out
Fiddle::TYPE_VOIDP, # pszSpn : LPSTR out
],
-Fiddle::TYPE_INT)#[link(name = "ntdsapi")]
extern "system" {
fn DsClientMakeSpnForTargetServerA(
ServiceClass: *const u8, // LPCSTR
ServiceName: *const u8, // LPCSTR
pcSpnLength: *mut u32, // DWORD* in/out
pszSpn: *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 DsClientMakeSpnForTargetServerA([MarshalAs(UnmanagedType.LPStr)] string ServiceClass, [MarshalAs(UnmanagedType.LPStr)] string ServiceName, ref uint pcSpnLength, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder pszSpn);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsClientMakeSpnForTargetServerA' -Namespace Win32 -PassThru
# $api::DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, pcSpnLength, pszSpn)#uselib "NTDSAPI.dll"
#func global DsClientMakeSpnForTargetServerA "DsClientMakeSpnForTargetServerA" sptr, sptr, sptr, sptr
; DsClientMakeSpnForTargetServerA ServiceClass, ServiceName, varptr(pcSpnLength), varptr(pszSpn) ; 戻り値は stat
; ServiceClass : LPCSTR -> "sptr"
; ServiceName : LPCSTR -> "sptr"
; pcSpnLength : DWORD* in/out -> "sptr"
; pszSpn : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "NTDSAPI.dll" #cfunc global DsClientMakeSpnForTargetServerA "DsClientMakeSpnForTargetServerA" str, str, var, var ; res = DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, pcSpnLength, pszSpn) ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR -> "str" ; pcSpnLength : DWORD* in/out -> "var" ; pszSpn : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "NTDSAPI.dll" #cfunc global DsClientMakeSpnForTargetServerA "DsClientMakeSpnForTargetServerA" str, str, sptr, sptr ; res = DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, varptr(pcSpnLength), varptr(pszSpn)) ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR -> "str" ; pcSpnLength : DWORD* in/out -> "sptr" ; pszSpn : LPSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD DsClientMakeSpnForTargetServerA(LPCSTR ServiceClass, LPCSTR ServiceName, DWORD* pcSpnLength, LPSTR pszSpn) #uselib "NTDSAPI.dll" #cfunc global DsClientMakeSpnForTargetServerA "DsClientMakeSpnForTargetServerA" str, str, var, var ; res = DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, pcSpnLength, pszSpn) ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR -> "str" ; pcSpnLength : DWORD* in/out -> "var" ; pszSpn : LPSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD DsClientMakeSpnForTargetServerA(LPCSTR ServiceClass, LPCSTR ServiceName, DWORD* pcSpnLength, LPSTR pszSpn) #uselib "NTDSAPI.dll" #cfunc global DsClientMakeSpnForTargetServerA "DsClientMakeSpnForTargetServerA" str, str, intptr, intptr ; res = DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, varptr(pcSpnLength), varptr(pszSpn)) ; ServiceClass : LPCSTR -> "str" ; ServiceName : LPCSTR -> "str" ; pcSpnLength : DWORD* in/out -> "intptr" ; pszSpn : LPSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsClientMakeSpnForTargetServerA = ntdsapi.NewProc("DsClientMakeSpnForTargetServerA")
)
// ServiceClass (LPCSTR), ServiceName (LPCSTR), pcSpnLength (DWORD* in/out), pszSpn (LPSTR out)
r1, _, err := procDsClientMakeSpnForTargetServerA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceClass))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(ServiceName))),
uintptr(pcSpnLength),
uintptr(pszSpn),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsClientMakeSpnForTargetServerA(
ServiceClass: PAnsiChar; // LPCSTR
ServiceName: PAnsiChar; // LPCSTR
pcSpnLength: Pointer; // DWORD* in/out
pszSpn: PAnsiChar // LPSTR out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsClientMakeSpnForTargetServerA';result := DllCall("NTDSAPI\DsClientMakeSpnForTargetServerA"
, "AStr", ServiceClass ; LPCSTR
, "AStr", ServiceName ; LPCSTR
, "Ptr", pcSpnLength ; DWORD* in/out
, "Ptr", pszSpn ; LPSTR out
, "UInt") ; return: DWORD●DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, pcSpnLength, pszSpn) = DLL("NTDSAPI.dll", "dword DsClientMakeSpnForTargetServerA(char*, char*, void*, char*)")
# 呼び出し: DsClientMakeSpnForTargetServerA(ServiceClass, ServiceName, pcSpnLength, pszSpn)
# ServiceClass : LPCSTR -> "char*"
# ServiceName : LPCSTR -> "char*"
# pcSpnLength : DWORD* in/out -> "void*"
# pszSpn : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。