ldap_bindW
関数シグネチャ
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_bindW(
LDAP* ld,
LPWSTR dn, // optional
LPWSTR cred, // optional
DWORD method
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | セッションハンドル。 |
| dn | LPWSTR | inoptional | バインドに使用するエントリの識別名を含む、null 終端文字列へのポインター。 |
| cred | LPWSTR | inoptional | 認証に使用する資格情報を含む、null 終端文字列へのポインター。このパラメーターを使用して、任意の資格情報を渡すことができます。資格情報の形式と内容は、method パラメーターの設定によって異なります。詳細については、「解説」セクションを参照してください。 |
| method | DWORD | in | 使用する認証方法。 |
戻り値の型: DWORD
公式ドキュメント
ldap_bindW (Unicode) 関数 (winldap.h) は、LDAP サーバーに対してクライアントを非同期に認証します。
戻り値
関数が成功した場合、戻り値は開始された操作のメッセージ ID です。
関数が失敗した場合は –1 を返し、LDAP 構造体にセッションのエラーパラメーターを設定します。
解説(Remarks)
この ldap_bind の実装は、次の認証方法をサポートします。
| 認証方法 | 説明 | 資格情報 |
|---|---|---|
| LDAP_AUTH_SIMPLE | 平文パスワードによる認証。 | ユーザーのパスワードを含む文字列。 |
LDAP_AUTH_SIMPLE は、非同期版のバインドである ldap_bind と互換性のある唯一の認証方法です。ldap_bind でこれ以外の認証方法を使用すると失敗し、LDAP_PARAM_ERROR が返されます。LDAP_AUTH_SIMPLE 方法で ldap_bind を呼び出すことは、ldap_simple_bind を呼び出すことと同等です。その他のすべての認証方法では、ldap_bind_s が提供する同期バインドが必要です。
LDAP 2 サーバーでは、認証を必要とする他の操作を試みる前に、アプリケーションがバインドを行う必要があることに注意してください。
マルチスレッド: バインド呼び出しは接続全体に適用されるため、安全ではありません。スレッド間で接続を共有する場合は注意し、可能であればバインド操作を他の操作とスレッド化してください。
winldap.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして ldap_bind を定義します。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じ、コンパイルエラーや実行時エラーの原因となることがあります。詳細については、「Conventions for Function Prototypes」を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WLDAP32.dll (Unicode / -W)
#include <windows.h>
DWORD ldap_bindW(
LDAP* ld,
LPWSTR dn, // optional
LPWSTR cred, // optional
DWORD method
);[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_bindW(
IntPtr ld, // LDAP* in/out
[MarshalAs(UnmanagedType.LPWStr)] string dn, // LPWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string cred, // LPWSTR optional
uint method // DWORD
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_bindW(
ld As IntPtr, ' LDAP* in/out
<MarshalAs(UnmanagedType.LPWStr)> dn As String, ' LPWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> cred As String, ' LPWSTR optional
method As UInteger ' DWORD
) As UInteger
End Function' ld : LDAP* in/out
' dn : LPWSTR optional
' cred : LPWSTR optional
' method : DWORD
Declare PtrSafe Function ldap_bindW Lib "wldap32" ( _
ByVal ld As LongPtr, _
ByVal dn As LongPtr, _
ByVal cred As LongPtr, _
ByVal method As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ldap_bindW = ctypes.cdll.wldap32.ldap_bindW
ldap_bindW.restype = wintypes.DWORD
ldap_bindW.argtypes = [
ctypes.c_void_p, # ld : LDAP* in/out
wintypes.LPCWSTR, # dn : LPWSTR optional
wintypes.LPCWSTR, # cred : LPWSTR optional
wintypes.DWORD, # method : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_bindW = Fiddle::Function.new(
lib['ldap_bindW'],
[
Fiddle::TYPE_VOIDP, # ld : LDAP* in/out
Fiddle::TYPE_VOIDP, # dn : LPWSTR optional
Fiddle::TYPE_VOIDP, # cred : LPWSTR optional
-Fiddle::TYPE_INT, # method : DWORD
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wldap32")]
extern "C" {
fn ldap_bindW(
ld: *mut LDAP, // LDAP* in/out
dn: *mut u16, // LPWSTR optional
cred: *mut u16, // LPWSTR optional
method: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WLDAP32.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern uint ldap_bindW(IntPtr ld, [MarshalAs(UnmanagedType.LPWStr)] string dn, [MarshalAs(UnmanagedType.LPWStr)] string cred, uint method);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_bindW' -Namespace Win32 -PassThru
# $api::ldap_bindW(ld, dn, cred, method)#uselib "WLDAP32.dll"
#func global ldap_bindW "ldap_bindW" wptr, wptr, wptr, wptr
; ldap_bindW varptr(ld), dn, cred, method ; 戻り値は stat
; ld : LDAP* in/out -> "wptr"
; dn : LPWSTR optional -> "wptr"
; cred : LPWSTR optional -> "wptr"
; method : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WLDAP32.dll" #cfunc global ldap_bindW "ldap_bindW" var, wstr, wstr, int ; res = ldap_bindW(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPWSTR optional -> "wstr" ; cred : LPWSTR optional -> "wstr" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_bindW "ldap_bindW" sptr, wstr, wstr, int ; res = ldap_bindW(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "sptr" ; dn : LPWSTR optional -> "wstr" ; cred : LPWSTR optional -> "wstr" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD ldap_bindW(LDAP* ld, LPWSTR dn, LPWSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bindW "ldap_bindW" var, wstr, wstr, int ; res = ldap_bindW(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPWSTR optional -> "wstr" ; cred : LPWSTR optional -> "wstr" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_bindW(LDAP* ld, LPWSTR dn, LPWSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bindW "ldap_bindW" intptr, wstr, wstr, int ; res = ldap_bindW(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "intptr" ; dn : LPWSTR optional -> "wstr" ; cred : LPWSTR optional -> "wstr" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_bindW = wldap32.NewProc("ldap_bindW")
)
// ld (LDAP* in/out), dn (LPWSTR optional), cred (LPWSTR optional), method (DWORD)
r1, _, err := procldap_bindW.Call(
uintptr(ld),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(dn))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(cred))),
uintptr(method),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_bindW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPWSTR optional
cred: PWideChar; // LPWSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bindW';result := DllCall("WLDAP32\ldap_bindW"
, "Ptr", ld ; LDAP* in/out
, "WStr", dn ; LPWSTR optional
, "WStr", cred ; LPWSTR optional
, "UInt", method ; DWORD
, "Cdecl UInt") ; return: DWORD●ldap_bindW(ld, dn, cred, method) = DLL("WLDAP32.dll", "dword ldap_bindW(void*, char*, char*, dword)")
# 呼び出し: ldap_bindW(ld, dn, cred, method)
# ld : LDAP* in/out -> "void*"
# dn : LPWSTR optional -> "char*"
# cred : LPWSTR optional -> "char*"
# method : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "wldap32" fn ldap_bindW(
ld: [*c]LDAP, // LDAP* in/out
dn: [*c]const u16, // LPWSTR optional
cred: [*c]const u16, // LPWSTR optional
method: u32 // DWORD
) callconv(.c) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ldap_bindW(
ld: ptr LDAP, # LDAP* in/out
dn: WideCString, # LPWSTR optional
cred: WideCString, # LPWSTR optional
`method`: uint32 # DWORD
): uint32 {.importc: "ldap_bindW", cdecl, dynlib: "WLDAP32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "wldap32");
extern(C)
uint ldap_bindW(
LDAP* ld, // LDAP* in/out
const(wchar)* dn, // LPWSTR optional
const(wchar)* cred, // LPWSTR optional
uint method // DWORD
);ccall((:ldap_bindW, "WLDAP32.dll"), UInt32,
(Ptr{LDAP}, Cwstring, Cwstring, UInt32),
ld, dn, cred, method)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPWSTR optional -> Cwstring
# cred : LPWSTR optional -> Cwstring
# method : DWORD -> UInt32
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_bindW(
void* ld,
const uint16_t* dn,
const uint16_t* cred,
uint32_t method);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_bindW(ld, dn, cred, method)
-- ld : LDAP* in/out
-- dn : LPWSTR optional
-- cred : LPWSTR optional
-- method : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_bindW = lib.func('__cdecl', 'ldap_bindW', 'uint32_t', ['void *', 'str16', 'str16', 'uint32_t']);
// ldap_bindW(ld, dn, cred, method)
// ld : LDAP* in/out -> 'void *'
// dn : LPWSTR optional -> 'str16'
// cred : LPWSTR optional -> 'str16'
// method : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_bindW: { parameters: ["pointer", "buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.ldap_bindW(ld, dn, cred, method)
// ld : LDAP* in/out -> "pointer"
// dn : LPWSTR optional -> "buffer"
// cred : LPWSTR optional -> "buffer"
// method : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_bindW(
void* ld,
const uint16_t* dn,
const uint16_t* cred,
uint32_t method);
C, "WLDAP32.dll");
// $ffi->ldap_bindW(ld, dn, cred, method);
// ld : LDAP* in/out
// dn : LPWSTR optional
// cred : LPWSTR optional
// method : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wldap32 extends Library {
Wldap32 INSTANCE = Native.load("wldap32", Wldap32.class, W32APIOptions.UNICODE_OPTIONS);
int ldap_bindW(
Pointer ld, // LDAP* in/out
WString dn, // LPWSTR optional
WString cred, // LPWSTR optional
int method // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("wldap32")]
lib LibWLDAP32
fun ldap_bindW = ldap_bindW(
ld : LDAP*, # LDAP* in/out
dn : UInt16*, # LPWSTR optional
cred : UInt16*, # LPWSTR optional
method : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_bindWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef ldap_bindWDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final ldap_bindW = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_bindWNative, ldap_bindWDart>('ldap_bindW');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPWSTR optional -> Pointer<Utf16>
// cred : LPWSTR optional -> Pointer<Utf16>
// method : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_bindW(
ld: Pointer; // LDAP* in/out
dn: PWideChar; // LPWSTR optional
cred: PWideChar; // LPWSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bindW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_bindW"
c_ldap_bindW :: Ptr () -> CWString -> CWString -> Word32 -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPWSTR optional -> CWString
-- cred : LPWSTR optional -> CWString
-- method : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_bindw =
foreign "ldap_bindW"
((ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPWSTR optional -> (ptr uint16_t) *)
(* cred : LPWSTR optional -> (ptr uint16_t) *)
(* method : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)
(cffi:defcfun ("ldap_bindW" ldap-bind-w :convention :cdecl) :uint32
(ld :pointer) ; LDAP* in/out
(dn (:string :encoding :utf-16le)) ; LPWSTR optional
(cred (:string :encoding :utf-16le)) ; LPWSTR optional
(method :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_bindW = Win32::API::More->new('WLDAP32',
'DWORD ldap_bindW(LPVOID ld, LPCWSTR dn, LPCWSTR cred, DWORD method)');
# my $ret = $ldap_bindW->Call($ld, $dn, $cred, $method);
# ld : LDAP* in/out -> LPVOID
# dn : LPWSTR optional -> LPCWSTR
# cred : LPWSTR optional -> LPCWSTR
# method : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f ldap_bindA (ANSI版) — 指定方式でLDAPサーバーに非同期バインドする(ANSI版)。
- s SEC_WINNT_AUTH_IDENTITY_W
- f ldap_bind_sW — 指定方式でLDAPサーバーに同期バインドする(Unicode版)。
- f ldap_simple_bindW — DNとパスワードで非同期に簡易バインドする(Unicode版)。
- f ldap_simple_bind_sW — DNとパスワードで同期的に簡易バインドする(Unicode版)。
- f ldap_unbind — LDAPセッションを切断し資源を解放する。