ホーム › Networking.Ldap › ldap_simple_bind_sA
ldap_simple_bind_sA
関数DNとパスワードで同期的に簡易バインドする(ANSI版)。
シグネチャ
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_simple_bind_sA(
LDAP* ld,
LPSTR dn, // optional
LPSTR passwd // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| ld | LDAP* | inout | バインドを行う対象のLDAPセッションハンドル。 |
| dn | LPSTR | inoptional | 認証に使う識別名(DN、ANSI)。匿名バインドの場合はNULLを指定する。 |
| passwd | LPSTR | inoptional | 認証パスワード(ANSI)。同期的にバインドが完了するまで待機する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// WLDAP32.dll (ANSI / -A)
#include <windows.h>
DWORD ldap_simple_bind_sA(
LDAP* ld,
LPSTR dn, // optional
LPSTR passwd // optional
);[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_simple_bind_sA(
IntPtr ld, // LDAP* in/out
[MarshalAs(UnmanagedType.LPStr)] string dn, // LPSTR optional
[MarshalAs(UnmanagedType.LPStr)] string passwd // LPSTR optional
);<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_simple_bind_sA(
ld As IntPtr, ' LDAP* in/out
<MarshalAs(UnmanagedType.LPStr)> dn As String, ' LPSTR optional
<MarshalAs(UnmanagedType.LPStr)> passwd As String ' LPSTR optional
) As UInteger
End Function' ld : LDAP* in/out
' dn : LPSTR optional
' passwd : LPSTR optional
Declare PtrSafe Function ldap_simple_bind_sA Lib "wldap32" ( _
ByVal ld As LongPtr, _
ByVal dn As String, _
ByVal passwd As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ldap_simple_bind_sA = ctypes.cdll.wldap32.ldap_simple_bind_sA
ldap_simple_bind_sA.restype = wintypes.DWORD
ldap_simple_bind_sA.argtypes = [
ctypes.c_void_p, # ld : LDAP* in/out
wintypes.LPCSTR, # dn : LPSTR optional
wintypes.LPCSTR, # passwd : LPSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WLDAP32.dll')
ldap_simple_bind_sA = Fiddle::Function.new(
lib['ldap_simple_bind_sA'],
[
Fiddle::TYPE_VOIDP, # ld : LDAP* in/out
Fiddle::TYPE_VOIDP, # dn : LPSTR optional
Fiddle::TYPE_VOIDP, # passwd : LPSTR optional
],
-Fiddle::TYPE_INT, Fiddle::Function::CDECL)#[link(name = "wldap32")]
extern "C" {
fn ldap_simple_bind_sA(
ld: *mut LDAP, // LDAP* in/out
dn: *mut u8, // LPSTR optional
passwd: *mut u8 // LPSTR optional
) -> 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_simple_bind_sA(IntPtr ld, [MarshalAs(UnmanagedType.LPStr)] string dn, [MarshalAs(UnmanagedType.LPStr)] string passwd);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_simple_bind_sA' -Namespace Win32 -PassThru
# $api::ldap_simple_bind_sA(ld, dn, passwd)#uselib "WLDAP32.dll"
#func global ldap_simple_bind_sA "ldap_simple_bind_sA" sptr, sptr, sptr
; ldap_simple_bind_sA varptr(ld), dn, passwd ; 戻り値は stat
; ld : LDAP* in/out -> "sptr"
; dn : LPSTR optional -> "sptr"
; passwd : LPSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WLDAP32.dll" #cfunc global ldap_simple_bind_sA "ldap_simple_bind_sA" var, str, str ; res = ldap_simple_bind_sA(ld, dn, passwd) ; ld : LDAP* in/out -> "var" ; dn : LPSTR optional -> "str" ; passwd : LPSTR optional -> "str" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WLDAP32.dll" #cfunc global ldap_simple_bind_sA "ldap_simple_bind_sA" sptr, str, str ; res = ldap_simple_bind_sA(varptr(ld), dn, passwd) ; ld : LDAP* in/out -> "sptr" ; dn : LPSTR optional -> "str" ; passwd : LPSTR optional -> "str" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD ldap_simple_bind_sA(LDAP* ld, LPSTR dn, LPSTR passwd) #uselib "WLDAP32.dll" #cfunc global ldap_simple_bind_sA "ldap_simple_bind_sA" var, str, str ; res = ldap_simple_bind_sA(ld, dn, passwd) ; ld : LDAP* in/out -> "var" ; dn : LPSTR optional -> "str" ; passwd : LPSTR optional -> "str" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD ldap_simple_bind_sA(LDAP* ld, LPSTR dn, LPSTR passwd) #uselib "WLDAP32.dll" #cfunc global ldap_simple_bind_sA "ldap_simple_bind_sA" intptr, str, str ; res = ldap_simple_bind_sA(varptr(ld), dn, passwd) ; ld : LDAP* in/out -> "intptr" ; dn : LPSTR optional -> "str" ; passwd : LPSTR optional -> "str" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
procldap_simple_bind_sA = wldap32.NewProc("ldap_simple_bind_sA")
)
// ld (LDAP* in/out), dn (LPSTR optional), passwd (LPSTR optional)
r1, _, err := procldap_simple_bind_sA.Call(
uintptr(ld),
uintptr(unsafe.Pointer(windows.BytePtrFromString(dn))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(passwd))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction ldap_simple_bind_sA(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPSTR optional
passwd: PAnsiChar // LPSTR optional
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_simple_bind_sA';result := DllCall("WLDAP32\ldap_simple_bind_sA"
, "Ptr", ld ; LDAP* in/out
, "AStr", dn ; LPSTR optional
, "AStr", passwd ; LPSTR optional
, "Cdecl UInt") ; return: DWORD●ldap_simple_bind_sA(ld, dn, passwd) = DLL("WLDAP32.dll", "dword ldap_simple_bind_sA(void*, char*, char*)")
# 呼び出し: ldap_simple_bind_sA(ld, dn, passwd)
# ld : LDAP* in/out -> "void*"
# dn : LPSTR optional -> "char*"
# passwd : LPSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。const std = @import("std");
extern "wldap32" fn ldap_simple_bind_sA(
ld: [*c]LDAP, // LDAP* in/out
dn: [*c]const u8, // LPSTR optional
passwd: [*c]const u8 // LPSTR optional
) callconv(.c) u32;proc ldap_simple_bind_sA(
ld: ptr LDAP, # LDAP* in/out
dn: cstring, # LPSTR optional
passwd: cstring # LPSTR optional
): uint32 {.importc: "ldap_simple_bind_sA", cdecl, dynlib: "WLDAP32.dll".}pragma(lib, "wldap32");
extern(C)
uint ldap_simple_bind_sA(
LDAP* ld, // LDAP* in/out
const(char)* dn, // LPSTR optional
const(char)* passwd // LPSTR optional
);ccall((:ldap_simple_bind_sA, "WLDAP32.dll"), UInt32,
(Ptr{LDAP}, Cstring, Cstring),
ld, dn, passwd)
# ld : LDAP* in/out -> Ptr{LDAP}
# dn : LPSTR optional -> Cstring
# passwd : LPSTR optional -> Cstringlocal ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_simple_bind_sA(
void* ld,
const char* dn,
const char* passwd);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_simple_bind_sA(ld, dn, passwd)
-- ld : LDAP* in/out
-- dn : LPSTR optional
-- passwd : LPSTR optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_simple_bind_sA = lib.func('__cdecl', 'ldap_simple_bind_sA', 'uint32_t', ['void *', 'str', 'str']);
// ldap_simple_bind_sA(ld, dn, passwd)
// ld : LDAP* in/out -> 'void *'
// dn : LPSTR optional -> 'str'
// passwd : LPSTR optional -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WLDAP32.dll", {
ldap_simple_bind_sA: { parameters: ["pointer", "buffer", "buffer"], result: "u32" },
});
// lib.symbols.ldap_simple_bind_sA(ld, dn, passwd)
// ld : LDAP* in/out -> "pointer"
// dn : LPSTR optional -> "buffer"
// passwd : LPSTR optional -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_simple_bind_sA(
void* ld,
const char* dn,
const char* passwd);
C, "WLDAP32.dll");
// $ffi->ldap_simple_bind_sA(ld, dn, passwd);
// ld : LDAP* in/out
// dn : LPSTR optional
// passwd : LPSTR optional
// 構造体/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_simple_bind_sA(
Pointer ld, // LDAP* in/out
String dn, // LPSTR optional
String passwd // LPSTR optional
);
}@[Link("wldap32")]
lib LibWLDAP32
fun ldap_simple_bind_sA = ldap_simple_bind_sA(
ld : LDAP*, # LDAP* in/out
dn : UInt8*, # LPSTR optional
passwd : UInt8* # LPSTR optional
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ldap_simple_bind_sANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>);
typedef ldap_simple_bind_sADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>);
final ldap_simple_bind_sA = DynamicLibrary.open('WLDAP32.dll')
.lookupFunction<ldap_simple_bind_sANative, ldap_simple_bind_sADart>('ldap_simple_bind_sA');
// ld : LDAP* in/out -> Pointer<Void>
// dn : LPSTR optional -> Pointer<Utf8>
// passwd : LPSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ldap_simple_bind_sA(
ld: Pointer; // LDAP* in/out
dn: PAnsiChar; // LPSTR optional
passwd: PAnsiChar // LPSTR optional
): DWORD; cdecl;
external 'WLDAP32.dll' name 'ldap_simple_bind_sA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import ccall safe "ldap_simple_bind_sA"
c_ldap_simple_bind_sA :: Ptr () -> CString -> CString -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- dn : LPSTR optional -> CString
-- passwd : LPSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let ldap_simple_bind_sa =
foreign "ldap_simple_bind_sA"
((ptr void) @-> string @-> string @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* dn : LPSTR optional -> string *)
(* passwd : LPSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)
(cffi:defcfun ("ldap_simple_bind_sA" ldap-simple-bind-s-a :convention :cdecl) :uint32
(ld :pointer) ; LDAP* in/out
(dn :string) ; LPSTR optional
(passwd :string)) ; LPSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ldap_simple_bind_sA = Win32::API::More->new('WLDAP32',
'DWORD ldap_simple_bind_sA(LPVOID ld, LPCSTR dn, LPCSTR passwd)');
# my $ret = $ldap_simple_bind_sA->Call($ld, $dn, $passwd);
# ld : LDAP* in/out -> LPVOID
# dn : LPSTR optional -> LPCSTR
# passwd : LPSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f ldap_simple_bind_sW (Unicode版) — DNとパスワードで同期的に簡易バインドする(Unicode版)。
使用する型