ldap_bind_sA
関数シグネチャ
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_bind_sA(
LDAP* ld,
LPSTR dn, // optional
LPSTR cred, // optional
DWORD method
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | セッション ハンドル。 |
| dn | LPSTR | inoptional | バインドに使用するエントリの識別名を格納した、null で終わる文字列へのポインター。ここには DN、UPN、WinNT 形式のユーザー名、またはディレクトリ サーバーが識別子として受け入れるその他の名前を指定できます。 |
| cred | LPSTR | inoptional | 認証に使用する資格情報を格納した、null で終わる文字列へのポインター。このパラメーターを使用して任意の資格情報を渡すことができます。資格情報の形式と内容は、method パラメーターの設定によって異なります。詳細については、「解説」を参照してください。 |
| method | DWORD | in | 使用する認証方法を示します。有効な非同期認証方法の詳細と一覧については、「解説」セクションを参照してください。有効な非同期認証方法の詳細と説明については、 ldap_bind を参照してください。 |
戻り値の型: DWORD
公式ドキュメント
クライアントを LDAP サーバーに対して同期的に認証します。(ldap_bind_sA)
戻り値
関数が成功した場合、戻り値は LDAP_SUCCESS です。
関数が失敗した場合は、エラー コードを返します。詳細については、 戻り値を参照してください。
解説(Remarks)
Windows Server 2008 および Windows Vista で User Account Control が導入されたことは、LDAP における変更や追加を行ううえで非常に重要な影響を及ぼします。制限された UAC の Administrator トークンで DC にログオンしているユーザーが NULL の資格情報を使用した場合、ディレクトリへの変更や追加、およびスキーマ変更操作はすべて失敗します。これには、DirSync 検索、SecurityDescriptorFlags を使用してオブジェクトの ntSecurityDescriptor 属性から SACL を取得する操作、その他多くの操作が含まれます。
これらはすべて、アクセス権が不足しているために失敗します。
User Account Control が有効な状態で管理者が DC にログオンすると、そのログオン セッションでは制限されたトークンが与えられます。この状態で NULL の資格情報を指定して ldap_bind_s を使用すると、変更や追加を行う操作は失敗します。
ldap_bind_s の実装は、次の表に示す認証方法をサポートします。LDAP_AUTH_SIMPLE オプションを指定して ldap_bind_s を呼び出すことは、ldap_simple_bind_s を呼び出すことと同等です。
| 方法 | 説明 | 資格情報 |
|---|---|---|
| LDAP_AUTH_SIMPLE | 平文パスワードによる認証。 | ユーザーのパスワードを格納した文字列。 |
| LDAP_AUTH_DIGEST | ダイジェスト認証パッケージ。 | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体へのポインターを設定します。 |
| LDAP_AUTH_DPA | 分散パスワード認証。Microsoft Membership System で使用されます。 | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体へのポインターを設定します。 |
| LDAP_AUTH_MSN | Microsoft Network 認証サービス。 | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体へのポインターを設定します。 |
| LDAP_AUTH_NEGOTIATE | 汎用セキュリティ サービス (GSS) (Snego)。認証自体は行わず、利用可能なサービスの一覧から最も適切な認証方法を選択し、すべての認証データをそのサービスに渡します。 | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体または SEC_WINNT_AUTH_IDENTITY_EX 構造体へのポインターを設定します。 |
| LDAP_AUTH_NTLM | NT LAN Manager | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体または SEC_WINNT_AUTH_IDENTITY_EX 構造体へのポインターを設定します。 |
| LDAP_AUTH_SICILY | MSN サーバーに対するパッケージ ネゴシエーションに対応します。 | 現在のユーザーとしてログインするには、dn パラメーターと cred パラメーターを NULL に設定します。別のユーザーとしてログインするには、dn パラメーターを NULL に設定し、cred パラメーターには適切なユーザー名、ドメイン名、パスワードを設定した SEC_WINNT_AUTH_IDENTITY 構造体へのポインターを設定します。 |
| LDAP_AUTH_SSPI | 旧式です。下位互換性のために含まれています。この定数を使用すると、GSS (Snego) ネゴシエーション サービスが選択されます。 | LDAP_AUTH_NEGOTIATE と同じです。 |
非同期のバインド認証を行うには、LDAP_AUTH_SIMPLE を ldap_bind と共に使用します。
バインド操作は、識別名とパスワードなどの何らかの認証資格情報を提供することで、クライアントをディレクトリ サーバーに対して識別します。実際に必要となる資格情報は、使用する認証方法によって異なります。ldap_bind_s() (単純バインド以外) で資格情報に NULL を渡した場合は、現在のユーザーまたはサービスの資格情報が使用されます。単純バインドの方法 ( ldap_simple_bind_s と同様) を指定した場合は、NULL の平文パスワードを指定したことと同等になります。詳細については、 ldap_bind を参照してください。
LDAP 2 サーバーでは、認証を必要とする他の操作を試みる前に、アプリケーションがバインドを行う必要があることに注意してください。
マルチスレッド: バインドの呼び出しは接続全体に適用されるため、安全ではありません。複数のスレッドが接続を共有し、バインド操作を他の操作と共にスレッド化しようとする場合は注意してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_bind_sA(
LDAP* ld,
LPSTR dn, // optional
LPSTR cred, // optional
DWORD method
);[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_bind_sA(
IntPtr ld, // LDAP* in/out
[MarshalAs(UnmanagedType.LPStr)] string dn, // LPSTR optional
[MarshalAs(UnmanagedType.LPStr)] string cred, // LPSTR optional
uint method // DWORD
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_bind_sA(
ld As IntPtr, ' LDAP* in/out
<MarshalAs(UnmanagedType.LPStr)> dn As String, ' LPSTR optional
<MarshalAs(UnmanagedType.LPStr)> cred As String, ' LPSTR optional
method As UInteger ' DWORD
) As UInteger
End Function' ld : LDAP* in/out
' dn : LPSTR optional
' cred : LPSTR optional
' method : DWORD
Declare PtrSafe Function ldap_bind_sA Lib "wldap32" ( _
ByVal ld As LongPtr, _
ByVal dn As String, _
ByVal cred As String, _
ByVal method As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ldap_bind_sA = ctypes.cdll.wldap32.ldap_bind_sA
ldap_bind_sA.restype = wintypes.DWORD
ldap_bind_sA.argtypes = [
ctypes.c_void_p, # ld : LDAP* in/out
wintypes.LPCSTR, # dn : LPSTR optional
wintypes.LPCSTR, # cred : LPSTR optional
wintypes.DWORD, # method : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_bind_sA = Fiddle::Function.new(
lib['ldap_bind_sA'],
[
Fiddle::TYPE_VOIDP, # ld : LDAP* in/out
Fiddle::TYPE_VOIDP, # dn : LPSTR optional
Fiddle::TYPE_VOIDP, # cred : LPSTR optional
-Fiddle::TYPE_INT, # method : DWORD
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "wldap32")]
extern "C" {
fn ldap_bind_sA(
ld: *mut LDAP, // LDAP* in/out
dn: *mut u8, // LPSTR optional
cred: *mut u8, // LPSTR optional
method: u32 // DWORD
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern uint ldap_bind_sA(IntPtr ld, [MarshalAs(UnmanagedType.LPStr)] string dn, [MarshalAs(UnmanagedType.LPStr)] string cred, uint method);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_bind_sA' -Namespace Win32 -PassThru
# $api::ldap_bind_sA(ld, dn, cred, method)#uselib "WLDAP32.dll"
#func global ldap_bind_sA "ldap_bind_sA" sptr, sptr, sptr, sptr
; ldap_bind_sA varptr(ld), dn, cred, method ; 戻り値は stat
; ld : LDAP* in/out -> "sptr"
; dn : LPSTR optional -> "sptr"
; cred : LPSTR optional -> "sptr"
; method : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WLDAP32.dll" #cfunc global ldap_bind_sA "ldap_bind_sA" var, str, str, int ; res = ldap_bind_sA(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPSTR optional -> "str" ; cred : LPSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_bind_sA "ldap_bind_sA" sptr, str, str, int ; res = ldap_bind_sA(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "sptr" ; dn : LPSTR optional -> "str" ; cred : LPSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD ldap_bind_sA(LDAP* ld, LPSTR dn, LPSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bind_sA "ldap_bind_sA" var, str, str, int ; res = ldap_bind_sA(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPSTR optional -> "str" ; cred : LPSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_bind_sA(LDAP* ld, LPSTR dn, LPSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bind_sA "ldap_bind_sA" intptr, str, str, int ; res = ldap_bind_sA(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "intptr" ; dn : LPSTR optional -> "str" ; cred : LPSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_bind_sA = wldap32.NewProc("ldap_bind_sA")
)
// ld (LDAP* in/out), dn (LPSTR optional), cred (LPSTR optional), method (DWORD)
r1, _, err := procldap_bind_sA.Call(
uintptr(ld),
uintptr(unsafe.Pointer(windows.BytePtrFromString(dn))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(cred))),
uintptr(method),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_bind_sA(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPSTR optional
cred: PAnsiChar; // LPSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bind_sA';result := DllCall("WLDAP32\ldap_bind_sA"
, "Ptr", ld ; LDAP* in/out
, "AStr", dn ; LPSTR optional
, "AStr", cred ; LPSTR optional
, "UInt", method ; DWORD
, "Cdecl UInt") ; return: DWORD●ldap_bind_sA(ld, dn, cred, method) = DLL("WLDAP32.dll", "dword ldap_bind_sA(void*, char*, char*, dword)")
# 呼び出し: ldap_bind_sA(ld, dn, cred, method)
# ld : LDAP* in/out -> "void*"
# dn : LPSTR optional -> "char*"
# cred : LPSTR optional -> "char*"
# method : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "wldap32" fn ldap_bind_sA(
ld: [*c]LDAP, // LDAP* in/out
dn: [*c]const u8, // LPSTR optional
cred: [*c]const u8, // LPSTR optional
method: u32 // DWORD
) callconv(.c) u32;proc ldap_bind_sA(
ld: ptr LDAP, # LDAP* in/out
dn: cstring, # LPSTR optional
cred: cstring, # LPSTR optional
`method`: uint32 # DWORD
): uint32 {.importc: "ldap_bind_sA", cdecl, dynlib: "WLDAP32.dll".}pragma(lib, "wldap32");
extern(C)
uint ldap_bind_sA(
LDAP* ld, // LDAP* in/out
const(char)* dn, // LPSTR optional
const(char)* cred, // LPSTR optional
uint method // DWORD
);ccall((:ldap_bind_sA, "WLDAP32.dll"), UInt32,
(Ptr{LDAP}, Cstring, Cstring, UInt32),
ld, dn, cred, method)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPSTR optional -> Cstring
# cred : LPSTR optional -> Cstring
# method : DWORD -> UInt32local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_bind_sA(
void* ld,
const char* dn,
const char* cred,
uint32_t method);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_bind_sA(ld, dn, cred, method)
-- ld : LDAP* in/out
-- dn : LPSTR optional
-- cred : LPSTR optional
-- method : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_bind_sA = lib.func('__cdecl', 'ldap_bind_sA', 'uint32_t', ['void *', 'str', 'str', 'uint32_t']);
// ldap_bind_sA(ld, dn, cred, method)
// ld : LDAP* in/out -> 'void *'
// dn : LPSTR optional -> 'str'
// cred : LPSTR optional -> 'str'
// method : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_bind_sA: { parameters: ["pointer", "buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.ldap_bind_sA(ld, dn, cred, method)
// ld : LDAP* in/out -> "pointer"
// dn : LPSTR optional -> "buffer"
// cred : LPSTR optional -> "buffer"
// method : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_bind_sA(
void* ld,
const char* dn,
const char* cred,
uint32_t method);
C, "WLDAP32.dll");
// $ffi->ldap_bind_sA(ld, dn, cred, method);
// ld : LDAP* in/out
// dn : LPSTR optional
// cred : LPSTR 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.ASCII_OPTIONS);
int ldap_bind_sA(
Pointer ld, // LDAP* in/out
String dn, // LPSTR optional
String cred, // LPSTR optional
int method // DWORD
);
}@[Link("wldap32")]
lib LibWLDAP32
fun ldap_bind_sA = ldap_bind_sA(
ld : LDAP*, # LDAP* in/out
dn : UInt8*, # LPSTR optional
cred : UInt8*, # LPSTR optional
method : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_bind_sANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Uint32);
typedef ldap_bind_sADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, int);
final ldap_bind_sA = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_bind_sANative, ldap_bind_sADart>('ldap_bind_sA');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPSTR optional -> Pointer<Utf8>
// cred : LPSTR optional -> Pointer<Utf8>
// method : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_bind_sA(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPSTR optional
cred: PAnsiChar; // LPSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bind_sA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_bind_sA"
c_ldap_bind_sA :: Ptr () -> CString -> CString -> Word32 -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPSTR optional -> CString
-- cred : LPSTR optional -> CString
-- method : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_bind_sa =
foreign "ldap_bind_sA"
((ptr void) @-> string @-> string @-> uint32_t @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPSTR optional -> string *)
(* cred : LPSTR optional -> string *)
(* 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_bind_sA" ldap-bind-s-a :convention :cdecl) :uint32
(ld :pointer) ; LDAP* in/out
(dn :string) ; LPSTR optional
(cred :string) ; LPSTR optional
(method :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_bind_sA = Win32::API::More->new('WLDAP32',
'DWORD ldap_bind_sA(LPVOID ld, LPCSTR dn, LPCSTR cred, DWORD method)');
# my $ret = $ldap_bind_sA->Call($ld, $dn, $cred, $method);
# ld : LDAP* in/out -> LPVOID
# dn : LPSTR optional -> LPCSTR
# cred : LPSTR optional -> LPCSTR
# method : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ldap_bind_sW (Unicode版) — 指定方式でLDAPサーバーに同期バインドする(Unicode版)。
- s SEC_WINNT_AUTH_IDENTITY_A
- f ldap_bindA — 指定方式でLDAPサーバーに非同期バインドする(ANSI版)。
- f ldap_simple_bind_sA — DNとパスワードで同期的に簡易バインドする(ANSI版)。
- f ldap_unbind — LDAPセッションを切断し資源を解放する。