ホーム › Networking.Ldap › ldap_bind
ldap_bind
関数指定方式でLDAPサーバーに非同期バインドする。
シグネチャ
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_bind(
LDAP* ld,
LPCSTR dn, // optional
LPCSTR cred, // optional
DWORD method
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | バインドを行う対象のLDAPセッションハンドル。 |
| dn | LPCSTR | inoptional | 認証に使う識別名(DN、ANSI)。匿名の場合はNULLを指定する。 |
| cred | LPCSTR | inoptional | 認証資格情報(ANSI)。methodに応じパスワード等を指定する。 |
| method | DWORD | in | 認証方式を示すフラグ。LDAP_AUTH_SIMPLE等を指定する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_bind(
LDAP* ld,
LPCSTR dn, // optional
LPCSTR cred, // optional
DWORD method
);[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_bind(
IntPtr ld, // LDAP* in/out
[MarshalAs(UnmanagedType.LPStr)] string dn, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string cred, // LPCSTR optional
uint method // DWORD
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_bind(
ld As IntPtr, ' LDAP* in/out
<MarshalAs(UnmanagedType.LPStr)> dn As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> cred As String, ' LPCSTR optional
method As UInteger ' DWORD
) As UInteger
End Function' ld : LDAP* in/out
' dn : LPCSTR optional
' cred : LPCSTR optional
' method : DWORD
Declare PtrSafe Function ldap_bind 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 = ctypes.cdll.wldap32.ldap_bind
ldap_bind.restype = wintypes.DWORD
ldap_bind.argtypes = [
ctypes.c_void_p, # ld : LDAP* in/out
wintypes.LPCSTR, # dn : LPCSTR optional
wintypes.LPCSTR, # cred : LPCSTR optional
wintypes.DWORD, # method : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_bind = Fiddle::Function.new(
lib['ldap_bind'],
[
Fiddle::TYPE_VOIDP, # ld : LDAP* in/out
Fiddle::TYPE_VOIDP, # dn : LPCSTR optional
Fiddle::TYPE_VOIDP, # cred : LPCSTR optional
-Fiddle::TYPE_INT, # method : DWORD
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "wldap32")]
extern "C" {
fn ldap_bind(
ld: *mut LDAP, // LDAP* in/out
dn: *const u8, // LPCSTR optional
cred: *const u8, // LPCSTR 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(IntPtr ld, [MarshalAs(UnmanagedType.LPStr)] string dn, [MarshalAs(UnmanagedType.LPStr)] string cred, uint method);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_bind' -Namespace Win32 -PassThru
# $api::ldap_bind(ld, dn, cred, method)#uselib "WLDAP32.dll"
#func global ldap_bind "ldap_bind" sptr, sptr, sptr, sptr
; ldap_bind varptr(ld), dn, cred, method ; 戻り値は stat
; ld : LDAP* in/out -> "sptr"
; dn : LPCSTR optional -> "sptr"
; cred : LPCSTR optional -> "sptr"
; method : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WLDAP32.dll" #cfunc global ldap_bind "ldap_bind" var, str, str, int ; res = ldap_bind(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPCSTR optional -> "str" ; cred : LPCSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_bind "ldap_bind" sptr, str, str, int ; res = ldap_bind(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "sptr" ; dn : LPCSTR optional -> "str" ; cred : LPCSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ldap_bind(LDAP* ld, LPCSTR dn, LPCSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bind "ldap_bind" var, str, str, int ; res = ldap_bind(ld, dn, cred, method) ; ld : LDAP* in/out -> "var" ; dn : LPCSTR optional -> "str" ; cred : LPCSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_bind(LDAP* ld, LPCSTR dn, LPCSTR cred, DWORD method) #uselib "WLDAP32.dll" #cfunc global ldap_bind "ldap_bind" intptr, str, str, int ; res = ldap_bind(varptr(ld), dn, cred, method) ; ld : LDAP* in/out -> "intptr" ; dn : LPCSTR optional -> "str" ; cred : LPCSTR optional -> "str" ; method : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_bind = wldap32.NewProc("ldap_bind")
)
// ld (LDAP* in/out), dn (LPCSTR optional), cred (LPCSTR optional), method (DWORD)
r1, _, err := procldap_bind.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(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPCSTR optional
cred: PAnsiChar; // LPCSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bind';result := DllCall("WLDAP32\ldap_bind"
, "Ptr", ld ; LDAP* in/out
, "AStr", dn ; LPCSTR optional
, "AStr", cred ; LPCSTR optional
, "UInt", method ; DWORD
, "Cdecl UInt") ; return: DWORD●ldap_bind(ld, dn, cred, method) = DLL("WLDAP32.dll", "dword ldap_bind(void*, char*, char*, dword)")
# 呼び出し: ldap_bind(ld, dn, cred, method)
# ld : LDAP* in/out -> "void*"
# dn : LPCSTR optional -> "char*"
# cred : LPCSTR 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(
ld: [*c]LDAP, // LDAP* in/out
dn: [*c]const u8, // LPCSTR optional
cred: [*c]const u8, // LPCSTR optional
method: u32 // DWORD
) callconv(.c) u32;proc ldap_bind(
ld: ptr LDAP, # LDAP* in/out
dn: cstring, # LPCSTR optional
cred: cstring, # LPCSTR optional
`method`: uint32 # DWORD
): uint32 {.importc: "ldap_bind", cdecl, dynlib: "WLDAP32.dll".}pragma(lib, "wldap32");
extern(C)
uint ldap_bind(
LDAP* ld, // LDAP* in/out
const(char)* dn, // LPCSTR optional
const(char)* cred, // LPCSTR optional
uint method // DWORD
);ccall((:ldap_bind, "WLDAP32.dll"), UInt32,
(Ptr{LDAP}, Cstring, Cstring, UInt32),
ld, dn, cred, method)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPCSTR optional -> Cstring
# cred : LPCSTR optional -> Cstring
# method : DWORD -> UInt32local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_bind(
void* ld,
const char* dn,
const char* cred,
uint32_t method);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_bind(ld, dn, cred, method)
-- ld : LDAP* in/out
-- dn : LPCSTR optional
-- cred : LPCSTR optional
-- method : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_bind = lib.func('__cdecl', 'ldap_bind', 'uint32_t', ['void *', 'str', 'str', 'uint32_t']);
// ldap_bind(ld, dn, cred, method)
// ld : LDAP* in/out -> 'void *'
// dn : LPCSTR optional -> 'str'
// cred : LPCSTR optional -> 'str'
// method : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_bind: { parameters: ["pointer", "buffer", "buffer", "u32"], result: "u32" },
});
// lib.symbols.ldap_bind(ld, dn, cred, method)
// ld : LDAP* in/out -> "pointer"
// dn : LPCSTR optional -> "buffer"
// cred : LPCSTR 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(
void* ld,
const char* dn,
const char* cred,
uint32_t method);
C, "WLDAP32.dll");
// $ffi->ldap_bind(ld, dn, cred, method);
// ld : LDAP* in/out
// dn : LPCSTR optional
// cred : LPCSTR 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(
Pointer ld, // LDAP* in/out
String dn, // LPCSTR optional
String cred, // LPCSTR optional
int method // DWORD
);
}@[Link("wldap32")]
lib LibWLDAP32
fun ldap_bind = ldap_bind(
ld : LDAP*, # LDAP* in/out
dn : UInt8*, # LPCSTR optional
cred : UInt8*, # LPCSTR optional
method : UInt32 # DWORD
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_bindNative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Uint32);
typedef ldap_bindDart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, int);
final ldap_bind = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_bindNative, ldap_bindDart>('ldap_bind');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPCSTR optional -> Pointer<Utf8>
// cred : LPCSTR optional -> Pointer<Utf8>
// method : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_bind(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPCSTR optional
cred: PAnsiChar; // LPCSTR optional
method: DWORD // DWORD
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_bind';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_bind"
c_ldap_bind :: Ptr () -> CString -> CString -> Word32 -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPCSTR optional -> CString
-- cred : LPCSTR optional -> CString
-- method : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_bind =
foreign "ldap_bind"
((ptr void) @-> string @-> string @-> uint32_t @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPCSTR optional -> string *)
(* cred : LPCSTR 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" ldap-bind :convention :cdecl) :uint32
(ld :pointer) ; LDAP* in/out
(dn :string) ; LPCSTR optional
(cred :string) ; LPCSTR optional
(method :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_bind = Win32::API::More->new('WLDAP32',
'DWORD ldap_bind(LPVOID ld, LPCSTR dn, LPCSTR cred, DWORD method)');
# my $ret = $ldap_bind->Call($ld, $dn, $cred, $method);
# ld : LDAP* in/out -> LPVOID
# dn : LPCSTR optional -> LPCSTR
# cred : LPCSTR optional -> LPCSTR
# method : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f ldap_bindA (ANSI版) — 指定方式でLDAPサーバーに非同期バインドする(ANSI版)。
- f ldap_bindW (Unicode版) — 指定方式でLDAPサーバーに非同期バインドする(Unicode版)。
使用する型