Win32 API 日本語リファレンス
ホームNetworking.Ldap › ldap_search_st

ldap_search_st

関数
時間制限付きで同期的にLDAP検索する。
DLLWLDAP32.dll文字セットANSI (-A)呼出規約cdecl対応OSWindows Vista 以降

シグネチャ

// WLDAP32.dll  (ANSI / -A)
#include <windows.h>

DWORD ldap_search_st(
    LDAP* ld,
    LPSTR base,   // optional
    DWORD scope,
    LPSTR filter,
    CHAR** attrs,
    DWORD attrsonly,
    LDAP_TIMEVAL* timeout,
    LDAPMessage** res
);

パラメーター

名前方向説明
ldLDAP*inout検索を実行する対象のLDAPセッションハンドル。
baseLPSTRinoptional検索の起点となるベースDN(ANSI)。この識別名を基準に探索する。
scopeDWORDin検索範囲を示すフラグ。LDAP_SCOPE_BASE/ONELEVEL/SUBTREEのいずれかを指定する。
filterLPSTRin検索フィルター文字列(ANSI)。RFC形式の検索条件を指定する。
attrsCHAR**in取得する属性名のNULL終端配列。NULLで全属性を返す。
attrsonlyDWORDin属性名のみ取得するかのフラグ。非0で値を除き属性名だけを返す。
timeoutLDAP_TIMEVAL*inout検索の制限時間を示すLDAP_TIMEVAL構造体へのポインタ。NULLで無制限。
resLDAPMessage**out検索結果メッセージを受け取るLDAPMessage*へのポインタ。使用後はldap_msgfreeで解放する。

戻り値の型: DWORD

各言語での呼び出し定義

// WLDAP32.dll  (ANSI / -A)
#include <windows.h>

DWORD ldap_search_st(
    LDAP* ld,
    LPSTR base,   // optional
    DWORD scope,
    LPSTR filter,
    CHAR** attrs,
    DWORD attrsonly,
    LDAP_TIMEVAL* timeout,
    LDAPMessage** res
);
[DllImport("WLDAP32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern uint ldap_search_st(
    IntPtr ld,   // LDAP* in/out
    [MarshalAs(UnmanagedType.LPStr)] string base,   // LPSTR optional
    uint scope,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string filter,   // LPSTR
    IntPtr attrs,   // CHAR**
    uint attrsonly,   // DWORD
    IntPtr timeout,   // LDAP_TIMEVAL* in/out
    IntPtr res   // LDAPMessage** out
);
<DllImport("WLDAP32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ldap_search_st(
    ld As IntPtr,   ' LDAP* in/out
    <MarshalAs(UnmanagedType.LPStr)> base As String,   ' LPSTR optional
    scope As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> filter As String,   ' LPSTR
    attrs As IntPtr,   ' CHAR**
    attrsonly As UInteger,   ' DWORD
    timeout As IntPtr,   ' LDAP_TIMEVAL* in/out
    res As IntPtr   ' LDAPMessage** out
) As UInteger
End Function
' ld : LDAP* in/out
' base : LPSTR optional
' scope : DWORD
' filter : LPSTR
' attrs : CHAR**
' attrsonly : DWORD
' timeout : LDAP_TIMEVAL* in/out
' res : LDAPMessage** out
Declare PtrSafe Function ldap_search_st Lib "wldap32" ( _
    ByVal ld As LongPtr, _
    ByVal base As String, _
    ByVal scope As Long, _
    ByVal filter As String, _
    ByVal attrs As LongPtr, _
    ByVal attrsonly As Long, _
    ByVal timeout As LongPtr, _
    ByVal res As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ldap_search_st = ctypes.cdll.wldap32.ldap_search_st
ldap_search_st.restype = wintypes.DWORD
ldap_search_st.argtypes = [
    ctypes.c_void_p,  # ld : LDAP* in/out
    wintypes.LPCSTR,  # base : LPSTR optional
    wintypes.DWORD,  # scope : DWORD
    wintypes.LPCSTR,  # filter : LPSTR
    ctypes.c_void_p,  # attrs : CHAR**
    wintypes.DWORD,  # attrsonly : DWORD
    ctypes.c_void_p,  # timeout : LDAP_TIMEVAL* in/out
    ctypes.c_void_p,  # res : LDAPMessage** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WLDAP32.dll')
ldap_search_st = Fiddle::Function.new(
  lib['ldap_search_st'],
  [
    Fiddle::TYPE_VOIDP,  # ld : LDAP* in/out
    Fiddle::TYPE_VOIDP,  # base : LPSTR optional
    -Fiddle::TYPE_INT,  # scope : DWORD
    Fiddle::TYPE_VOIDP,  # filter : LPSTR
    Fiddle::TYPE_VOIDP,  # attrs : CHAR**
    -Fiddle::TYPE_INT,  # attrsonly : DWORD
    Fiddle::TYPE_VOIDP,  # timeout : LDAP_TIMEVAL* in/out
    Fiddle::TYPE_VOIDP,  # res : LDAPMessage** out
  ],
  -Fiddle::TYPE_INT, Fiddle::Function::CDECL)
#[link(name = "wldap32")]
extern "C" {
    fn ldap_search_st(
        ld: *mut LDAP,  // LDAP* in/out
        base: *mut u8,  // LPSTR optional
        scope: u32,  // DWORD
        filter: *mut u8,  // LPSTR
        attrs: *mut *mut i8,  // CHAR**
        attrsonly: u32,  // DWORD
        timeout: *mut LDAP_TIMEVAL,  // LDAP_TIMEVAL* in/out
        res: *mut *mut LDAPMessage  // LDAPMessage** out
    ) -> 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_search_st(IntPtr ld, [MarshalAs(UnmanagedType.LPStr)] string base, uint scope, [MarshalAs(UnmanagedType.LPStr)] string filter, IntPtr attrs, uint attrsonly, IntPtr timeout, IntPtr res);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WLDAP32_ldap_search_st' -Namespace Win32 -PassThru
# $api::ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
#uselib "WLDAP32.dll"
#func global ldap_search_st "ldap_search_st" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ldap_search_st varptr(ld), base, scope, filter, varptr(attrs), attrsonly, varptr(timeout), varptr(res)   ; 戻り値は stat
; ld : LDAP* in/out -> "sptr"
; base : LPSTR optional -> "sptr"
; scope : DWORD -> "sptr"
; filter : LPSTR -> "sptr"
; attrs : CHAR** -> "sptr"
; attrsonly : DWORD -> "sptr"
; timeout : LDAP_TIMEVAL* in/out -> "sptr"
; res : LDAPMessage** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WLDAP32.dll"
#cfunc global ldap_search_st "ldap_search_st" var, str, int, str, var, int, var, var
; res = ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
; ld : LDAP* in/out -> "var"
; base : LPSTR optional -> "str"
; scope : DWORD -> "int"
; filter : LPSTR -> "str"
; attrs : CHAR** -> "var"
; attrsonly : DWORD -> "int"
; timeout : LDAP_TIMEVAL* in/out -> "var"
; res : LDAPMessage** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD ldap_search_st(LDAP* ld, LPSTR base, DWORD scope, LPSTR filter, CHAR** attrs, DWORD attrsonly, LDAP_TIMEVAL* timeout, LDAPMessage** res)
#uselib "WLDAP32.dll"
#cfunc global ldap_search_st "ldap_search_st" var, str, int, str, var, int, var, var
; res = ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
; ld : LDAP* in/out -> "var"
; base : LPSTR optional -> "str"
; scope : DWORD -> "int"
; filter : LPSTR -> "str"
; attrs : CHAR** -> "var"
; attrsonly : DWORD -> "int"
; timeout : LDAP_TIMEVAL* in/out -> "var"
; res : LDAPMessage** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wldap32 = windows.NewLazySystemDLL("WLDAP32.dll")
	procldap_search_st = wldap32.NewProc("ldap_search_st")
)

// ld (LDAP* in/out), base (LPSTR optional), scope (DWORD), filter (LPSTR), attrs (CHAR**), attrsonly (DWORD), timeout (LDAP_TIMEVAL* in/out), res (LDAPMessage** out)
r1, _, err := procldap_search_st.Call(
	uintptr(ld),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(base))),
	uintptr(scope),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(filter))),
	uintptr(attrs),
	uintptr(attrsonly),
	uintptr(timeout),
	uintptr(res),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function ldap_search_st(
  ld: Pointer;   // LDAP* in/out
  base: PAnsiChar;   // LPSTR optional
  scope: DWORD;   // DWORD
  filter: PAnsiChar;   // LPSTR
  attrs: Pointer;   // CHAR**
  attrsonly: DWORD;   // DWORD
  timeout: Pointer;   // LDAP_TIMEVAL* in/out
  res: Pointer   // LDAPMessage** out
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_search_st';
result := DllCall("WLDAP32\ldap_search_st"
    , "Ptr", ld   ; LDAP* in/out
    , "AStr", base   ; LPSTR optional
    , "UInt", scope   ; DWORD
    , "AStr", filter   ; LPSTR
    , "Ptr", attrs   ; CHAR**
    , "UInt", attrsonly   ; DWORD
    , "Ptr", timeout   ; LDAP_TIMEVAL* in/out
    , "Ptr", res   ; LDAPMessage** out
    , "Cdecl UInt")   ; return: DWORD
●ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res) = DLL("WLDAP32.dll", "dword ldap_search_st(void*, char*, dword, char*, void*, dword, void*, void*)")
# 呼び出し: ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
# ld : LDAP* in/out -> "void*"
# base : LPSTR optional -> "char*"
# scope : DWORD -> "dword"
# filter : LPSTR -> "char*"
# attrs : CHAR** -> "void*"
# attrsonly : DWORD -> "dword"
# timeout : LDAP_TIMEVAL* in/out -> "void*"
# res : LDAPMessage** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
const std = @import("std");

extern "wldap32" fn ldap_search_st(
    ld: [*c]LDAP, // LDAP* in/out
    base: [*c]const u8, // LPSTR optional
    scope: u32, // DWORD
    filter: [*c]const u8, // LPSTR
    attrs: [*c][*c]i8, // CHAR**
    attrsonly: u32, // DWORD
    timeout: [*c]LDAP_TIMEVAL, // LDAP_TIMEVAL* in/out
    res: [*c][*c]LDAPMessage // LDAPMessage** out
) callconv(.c) u32;
proc ldap_search_st(
    ld: ptr LDAP,  # LDAP* in/out
    base: cstring,  # LPSTR optional
    scope: uint32,  # DWORD
    filter: cstring,  # LPSTR
    attrs: ptr int8,  # CHAR**
    attrsonly: uint32,  # DWORD
    timeout: ptr LDAP_TIMEVAL,  # LDAP_TIMEVAL* in/out
    res: ptr LDAPMessage  # LDAPMessage** out
): uint32 {.importc: "ldap_search_st", cdecl, dynlib: "WLDAP32.dll".}
pragma(lib, "wldap32");
extern(C)
uint ldap_search_st(
    LDAP* ld,   // LDAP* in/out
    const(char)* base,   // LPSTR optional
    uint scope,   // DWORD
    const(char)* filter,   // LPSTR
    byte** attrs,   // CHAR**
    uint attrsonly,   // DWORD
    LDAP_TIMEVAL* timeout,   // LDAP_TIMEVAL* in/out
    LDAPMessage** res   // LDAPMessage** out
);
ccall((:ldap_search_st, "WLDAP32.dll"), UInt32,
      (Ptr{LDAP}, Cstring, UInt32, Cstring, Ptr{Int8}, UInt32, Ptr{LDAP_TIMEVAL}, Ptr{LDAPMessage}),
      ld, base, scope, filter, attrs, attrsonly, timeout, res)
# ld : LDAP* in/out -> Ptr{LDAP}
# base : LPSTR optional -> Cstring
# scope : DWORD -> UInt32
# filter : LPSTR -> Cstring
# attrs : CHAR** -> Ptr{Int8}
# attrsonly : DWORD -> UInt32
# timeout : LDAP_TIMEVAL* in/out -> Ptr{LDAP_TIMEVAL}
# res : LDAPMessage** out -> Ptr{LDAPMessage}
local ffi = require("ffi")
ffi.cdef[[
uint32_t ldap_search_st(
    void* ld,
    const char* base,
    uint32_t scope,
    const char* filter,
    int8_t** attrs,
    uint32_t attrsonly,
    void* timeout,
    void* res);
]]
local wldap32 = ffi.load("wldap32")
-- wldap32.ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
-- ld : LDAP* in/out
-- base : LPSTR optional
-- scope : DWORD
-- filter : LPSTR
-- attrs : CHAR**
-- attrsonly : DWORD
-- timeout : LDAP_TIMEVAL* in/out
-- res : LDAPMessage** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WLDAP32.dll');
const ldap_search_st = lib.func('__cdecl', 'ldap_search_st', 'uint32_t', ['void *', 'str', 'uint32_t', 'str', 'int8_t *', 'uint32_t', 'void *', 'void *']);
// ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
// ld : LDAP* in/out -> 'void *'
// base : LPSTR optional -> 'str'
// scope : DWORD -> 'uint32_t'
// filter : LPSTR -> 'str'
// attrs : CHAR** -> 'int8_t *'
// attrsonly : DWORD -> 'uint32_t'
// timeout : LDAP_TIMEVAL* in/out -> 'void *'
// res : LDAPMessage** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WLDAP32.dll", {
  ldap_search_st: { parameters: ["pointer", "buffer", "u32", "buffer", "pointer", "u32", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res)
// ld : LDAP* in/out -> "pointer"
// base : LPSTR optional -> "buffer"
// scope : DWORD -> "u32"
// filter : LPSTR -> "buffer"
// attrs : CHAR** -> "pointer"
// attrsonly : DWORD -> "u32"
// timeout : LDAP_TIMEVAL* in/out -> "pointer"
// res : LDAPMessage** out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ldap_search_st(
    void* ld,
    const char* base,
    uint32_t scope,
    const char* filter,
    int8_t** attrs,
    uint32_t attrsonly,
    void* timeout,
    void* res);
C, "WLDAP32.dll");
// $ffi->ldap_search_st(ld, base, scope, filter, attrs, attrsonly, timeout, res);
// ld : LDAP* in/out
// base : LPSTR optional
// scope : DWORD
// filter : LPSTR
// attrs : CHAR**
// attrsonly : DWORD
// timeout : LDAP_TIMEVAL* in/out
// res : LDAPMessage** out
// 構造体/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_search_st(
        Pointer ld,   // LDAP* in/out
        String base,   // LPSTR optional
        int scope,   // DWORD
        String filter,   // LPSTR
        Pointer attrs,   // CHAR**
        int attrsonly,   // DWORD
        Pointer timeout,   // LDAP_TIMEVAL* in/out
        Pointer res   // LDAPMessage** out
    );
}
@[Link("wldap32")]
lib LibWLDAP32
  fun ldap_search_st = ldap_search_st(
    ld : LDAP*,   # LDAP* in/out
    base : UInt8*,   # LPSTR optional
    scope : UInt32,   # DWORD
    filter : UInt8*,   # LPSTR
    attrs : Int8**,   # CHAR**
    attrsonly : UInt32,   # DWORD
    timeout : LDAP_TIMEVAL*,   # LDAP_TIMEVAL* in/out
    res : LDAPMessage**   # LDAPMessage** out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ldap_search_stNative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Utf8>, Pointer<Int8>, Uint32, Pointer<Void>, Pointer<Void>);
typedef ldap_search_stDart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Utf8>, Pointer<Int8>, int, Pointer<Void>, Pointer<Void>);
final ldap_search_st = DynamicLibrary.open('WLDAP32.dll')
    .lookupFunction<ldap_search_stNative, ldap_search_stDart>('ldap_search_st');
// ld : LDAP* in/out -> Pointer<Void>
// base : LPSTR optional -> Pointer<Utf8>
// scope : DWORD -> Uint32
// filter : LPSTR -> Pointer<Utf8>
// attrs : CHAR** -> Pointer<Int8>
// attrsonly : DWORD -> Uint32
// timeout : LDAP_TIMEVAL* in/out -> Pointer<Void>
// res : LDAPMessage** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ldap_search_st(
  ld: Pointer;   // LDAP* in/out
  base: PAnsiChar;   // LPSTR optional
  scope: DWORD;   // DWORD
  filter: PAnsiChar;   // LPSTR
  attrs: Pointer;   // CHAR**
  attrsonly: DWORD;   // DWORD
  timeout: Pointer;   // LDAP_TIMEVAL* in/out
  res: Pointer   // LDAPMessage** out
): DWORD; cdecl;
  external 'WLDAP32.dll' name 'ldap_search_st';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ldap_search_st"
  c_ldap_search_st :: Ptr () -> CString -> Word32 -> CString -> Ptr Int8 -> Word32 -> Ptr () -> Ptr () -> IO Word32
-- ld : LDAP* in/out -> Ptr ()
-- base : LPSTR optional -> CString
-- scope : DWORD -> Word32
-- filter : LPSTR -> CString
-- attrs : CHAR** -> Ptr Int8
-- attrsonly : DWORD -> Word32
-- timeout : LDAP_TIMEVAL* in/out -> Ptr ()
-- res : LDAPMessage** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let ldap_search_st =
  foreign "ldap_search_st"
    ((ptr void) @-> string @-> uint32_t @-> string @-> (ptr int8_t) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* ld : LDAP* in/out -> (ptr void) *)
(* base : LPSTR optional -> string *)
(* scope : DWORD -> uint32_t *)
(* filter : LPSTR -> string *)
(* attrs : CHAR** -> (ptr int8_t) *)
(* attrsonly : DWORD -> uint32_t *)
(* timeout : LDAP_TIMEVAL* in/out -> (ptr void) *)
(* res : LDAPMessage** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wldap32 (t "WLDAP32.dll"))
(cffi:use-foreign-library wldap32)

(cffi:defcfun ("ldap_search_st" ldap-search-st :convention :cdecl) :uint32
  (ld :pointer)   ; LDAP* in/out
  (base :string)   ; LPSTR optional
  (scope :uint32)   ; DWORD
  (filter :string)   ; LPSTR
  (attrs :pointer)   ; CHAR**
  (attrsonly :uint32)   ; DWORD
  (timeout :pointer)   ; LDAP_TIMEVAL* in/out
  (res :pointer))   ; LDAPMessage** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ldap_search_st = Win32::API::More->new('WLDAP32',
    'DWORD ldap_search_st(LPVOID ld, LPCSTR base, DWORD scope, LPCSTR filter, LPVOID attrs, DWORD attrsonly, LPVOID timeout, LPVOID res)');
# my $ret = $ldap_search_st->Call($ld, $base, $scope, $filter, $attrs, $attrsonly, $timeout, $res);
# ld : LDAP* in/out -> LPVOID
# base : LPSTR optional -> LPCSTR
# scope : DWORD -> DWORD
# filter : LPSTR -> LPCSTR
# attrs : CHAR** -> LPVOID
# attrsonly : DWORD -> DWORD
# timeout : LDAP_TIMEVAL* in/out -> LPVOID
# res : LDAPMessage** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
使用する型