ホーム › Networking.ActiveDirectory › DsMakePasswordCredentialsA
DsMakePasswordCredentialsA
関数ユーザー名とパスワードから認証資格情報を作成する(ANSI版)。
シグネチャ
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsMakePasswordCredentialsA(
LPCSTR User, // optional
LPCSTR Domain, // optional
LPCSTR Password, // optional
void** pAuthIdentity
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| User | LPCSTR | inoptional | 資格情報のユーザー名(ANSI)。NULLで現在のログオンユーザーを使う。 |
| Domain | LPCSTR | inoptional | ユーザーが属するドメイン名(ANSI)。NULL可。 |
| Password | LPCSTR | inoptional | ユーザーのパスワード(ANSI)。NULL可。 |
| pAuthIdentity | void** | out | 生成された資格情報ハンドルを受け取るポインタ。DsFreePasswordCredentialsで解放する。 |
戻り値の型: DWORD
各言語での呼び出し定義
// NTDSAPI.dll (ANSI / -A)
#include <windows.h>
DWORD DsMakePasswordCredentialsA(
LPCSTR User, // optional
LPCSTR Domain, // optional
LPCSTR Password, // optional
void** pAuthIdentity
);[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint DsMakePasswordCredentialsA(
[MarshalAs(UnmanagedType.LPStr)] string User, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string Domain, // LPCSTR optional
[MarshalAs(UnmanagedType.LPStr)] string Password, // LPCSTR optional
IntPtr pAuthIdentity // void** out
);<DllImport("NTDSAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function DsMakePasswordCredentialsA(
<MarshalAs(UnmanagedType.LPStr)> User As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> Domain As String, ' LPCSTR optional
<MarshalAs(UnmanagedType.LPStr)> Password As String, ' LPCSTR optional
pAuthIdentity As IntPtr ' void** out
) As UInteger
End Function' User : LPCSTR optional
' Domain : LPCSTR optional
' Password : LPCSTR optional
' pAuthIdentity : void** out
Declare PtrSafe Function DsMakePasswordCredentialsA Lib "ntdsapi" ( _
ByVal User As String, _
ByVal Domain As String, _
ByVal Password As String, _
ByVal pAuthIdentity As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DsMakePasswordCredentialsA = ctypes.windll.ntdsapi.DsMakePasswordCredentialsA
DsMakePasswordCredentialsA.restype = wintypes.DWORD
DsMakePasswordCredentialsA.argtypes = [
wintypes.LPCSTR, # User : LPCSTR optional
wintypes.LPCSTR, # Domain : LPCSTR optional
wintypes.LPCSTR, # Password : LPCSTR optional
ctypes.c_void_p, # pAuthIdentity : void** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('NTDSAPI.dll')
DsMakePasswordCredentialsA = Fiddle::Function.new(
lib['DsMakePasswordCredentialsA'],
[
Fiddle::TYPE_VOIDP, # User : LPCSTR optional
Fiddle::TYPE_VOIDP, # Domain : LPCSTR optional
Fiddle::TYPE_VOIDP, # Password : LPCSTR optional
Fiddle::TYPE_VOIDP, # pAuthIdentity : void** out
],
-Fiddle::TYPE_INT)#[link(name = "ntdsapi")]
extern "system" {
fn DsMakePasswordCredentialsA(
User: *const u8, // LPCSTR optional
Domain: *const u8, // LPCSTR optional
Password: *const u8, // LPCSTR optional
pAuthIdentity: *mut *mut () // void** out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("NTDSAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint DsMakePasswordCredentialsA([MarshalAs(UnmanagedType.LPStr)] string User, [MarshalAs(UnmanagedType.LPStr)] string Domain, [MarshalAs(UnmanagedType.LPStr)] string Password, IntPtr pAuthIdentity);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NTDSAPI_DsMakePasswordCredentialsA' -Namespace Win32 -PassThru
# $api::DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)#uselib "NTDSAPI.dll"
#func global DsMakePasswordCredentialsA "DsMakePasswordCredentialsA" sptr, sptr, sptr, sptr
; DsMakePasswordCredentialsA User, Domain, Password, pAuthIdentity ; 戻り値は stat
; User : LPCSTR optional -> "sptr"
; Domain : LPCSTR optional -> "sptr"
; Password : LPCSTR optional -> "sptr"
; pAuthIdentity : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "NTDSAPI.dll"
#cfunc global DsMakePasswordCredentialsA "DsMakePasswordCredentialsA" str, str, str, sptr
; res = DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
; User : LPCSTR optional -> "str"
; Domain : LPCSTR optional -> "str"
; Password : LPCSTR optional -> "str"
; pAuthIdentity : void** out -> "sptr"; DWORD DsMakePasswordCredentialsA(LPCSTR User, LPCSTR Domain, LPCSTR Password, void** pAuthIdentity)
#uselib "NTDSAPI.dll"
#cfunc global DsMakePasswordCredentialsA "DsMakePasswordCredentialsA" str, str, str, intptr
; res = DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
; User : LPCSTR optional -> "str"
; Domain : LPCSTR optional -> "str"
; Password : LPCSTR optional -> "str"
; pAuthIdentity : void** out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ntdsapi = windows.NewLazySystemDLL("NTDSAPI.dll")
procDsMakePasswordCredentialsA = ntdsapi.NewProc("DsMakePasswordCredentialsA")
)
// User (LPCSTR optional), Domain (LPCSTR optional), Password (LPCSTR optional), pAuthIdentity (void** out)
r1, _, err := procDsMakePasswordCredentialsA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(User))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(Domain))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(Password))),
uintptr(pAuthIdentity),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction DsMakePasswordCredentialsA(
User: PAnsiChar; // LPCSTR optional
Domain: PAnsiChar; // LPCSTR optional
Password: PAnsiChar; // LPCSTR optional
pAuthIdentity: Pointer // void** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsMakePasswordCredentialsA';result := DllCall("NTDSAPI\DsMakePasswordCredentialsA"
, "AStr", User ; LPCSTR optional
, "AStr", Domain ; LPCSTR optional
, "AStr", Password ; LPCSTR optional
, "Ptr", pAuthIdentity ; void** out
, "UInt") ; return: DWORD●DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity) = DLL("NTDSAPI.dll", "dword DsMakePasswordCredentialsA(char*, char*, char*, void*)")
# 呼び出し: DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
# User : LPCSTR optional -> "char*"
# Domain : LPCSTR optional -> "char*"
# Password : LPCSTR optional -> "char*"
# pAuthIdentity : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ntdsapi" fn DsMakePasswordCredentialsA(
User: [*c]const u8, // LPCSTR optional
Domain: [*c]const u8, // LPCSTR optional
Password: [*c]const u8, // LPCSTR optional
pAuthIdentity: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) u32;proc DsMakePasswordCredentialsA(
User: cstring, # LPCSTR optional
Domain: cstring, # LPCSTR optional
Password: cstring, # LPCSTR optional
pAuthIdentity: pointer # void** out
): uint32 {.importc: "DsMakePasswordCredentialsA", stdcall, dynlib: "NTDSAPI.dll".}pragma(lib, "ntdsapi");
extern(Windows)
uint DsMakePasswordCredentialsA(
const(char)* User, // LPCSTR optional
const(char)* Domain, // LPCSTR optional
const(char)* Password, // LPCSTR optional
void** pAuthIdentity // void** out
);ccall((:DsMakePasswordCredentialsA, "NTDSAPI.dll"), stdcall, UInt32,
(Cstring, Cstring, Cstring, Ptr{Cvoid}),
User, Domain, Password, pAuthIdentity)
# User : LPCSTR optional -> Cstring
# Domain : LPCSTR optional -> Cstring
# Password : LPCSTR optional -> Cstring
# pAuthIdentity : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t DsMakePasswordCredentialsA(
const char* User,
const char* Domain,
const char* Password,
void** pAuthIdentity);
]]
local ntdsapi = ffi.load("ntdsapi")
-- ntdsapi.DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
-- User : LPCSTR optional
-- Domain : LPCSTR optional
-- Password : LPCSTR optional
-- pAuthIdentity : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('NTDSAPI.dll');
const DsMakePasswordCredentialsA = lib.func('__stdcall', 'DsMakePasswordCredentialsA', 'uint32_t', ['str', 'str', 'str', 'void *']);
// DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
// User : LPCSTR optional -> 'str'
// Domain : LPCSTR optional -> 'str'
// Password : LPCSTR optional -> 'str'
// pAuthIdentity : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("NTDSAPI.dll", {
DsMakePasswordCredentialsA: { parameters: ["buffer", "buffer", "buffer", "pointer"], result: "u32" },
});
// lib.symbols.DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity)
// User : LPCSTR optional -> "buffer"
// Domain : LPCSTR optional -> "buffer"
// Password : LPCSTR optional -> "buffer"
// pAuthIdentity : void** out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t DsMakePasswordCredentialsA(
const char* User,
const char* Domain,
const char* Password,
void** pAuthIdentity);
C, "NTDSAPI.dll");
// $ffi->DsMakePasswordCredentialsA(User, Domain, Password, pAuthIdentity);
// User : LPCSTR optional
// Domain : LPCSTR optional
// Password : LPCSTR optional
// pAuthIdentity : void** out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ntdsapi extends StdCallLibrary {
Ntdsapi INSTANCE = Native.load("ntdsapi", Ntdsapi.class, W32APIOptions.ASCII_OPTIONS);
int DsMakePasswordCredentialsA(
String User, // LPCSTR optional
String Domain, // LPCSTR optional
String Password, // LPCSTR optional
Pointer pAuthIdentity // void** out
);
}@[Link("ntdsapi")]
lib LibNTDSAPI
fun DsMakePasswordCredentialsA = DsMakePasswordCredentialsA(
User : UInt8*, # LPCSTR optional
Domain : UInt8*, # LPCSTR optional
Password : UInt8*, # LPCSTR optional
pAuthIdentity : Void** # void** out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef DsMakePasswordCredentialsANative = Uint32 Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>);
typedef DsMakePasswordCredentialsADart = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>);
final DsMakePasswordCredentialsA = DynamicLibrary.open('NTDSAPI.dll')
.lookupFunction<DsMakePasswordCredentialsANative, DsMakePasswordCredentialsADart>('DsMakePasswordCredentialsA');
// User : LPCSTR optional -> Pointer<Utf8>
// Domain : LPCSTR optional -> Pointer<Utf8>
// Password : LPCSTR optional -> Pointer<Utf8>
// pAuthIdentity : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function DsMakePasswordCredentialsA(
User: PAnsiChar; // LPCSTR optional
Domain: PAnsiChar; // LPCSTR optional
Password: PAnsiChar; // LPCSTR optional
pAuthIdentity: Pointer // void** out
): DWORD; stdcall;
external 'NTDSAPI.dll' name 'DsMakePasswordCredentialsA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "DsMakePasswordCredentialsA"
c_DsMakePasswordCredentialsA :: CString -> CString -> CString -> Ptr () -> IO Word32
-- User : LPCSTR optional -> CString
-- Domain : LPCSTR optional -> CString
-- Password : LPCSTR optional -> CString
-- pAuthIdentity : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let dsmakepasswordcredentialsa =
foreign "DsMakePasswordCredentialsA"
(string @-> string @-> string @-> (ptr void) @-> returning uint32_t)
(* User : LPCSTR optional -> string *)
(* Domain : LPCSTR optional -> string *)
(* Password : LPCSTR optional -> string *)
(* pAuthIdentity : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ntdsapi (t "NTDSAPI.dll"))
(cffi:use-foreign-library ntdsapi)
(cffi:defcfun ("DsMakePasswordCredentialsA" ds-make-password-credentials-a :convention :stdcall) :uint32
(user :string) ; LPCSTR optional
(domain :string) ; LPCSTR optional
(password :string) ; LPCSTR optional
(p-auth-identity :pointer)) ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $DsMakePasswordCredentialsA = Win32::API::More->new('NTDSAPI',
'DWORD DsMakePasswordCredentialsA(LPCSTR User, LPCSTR Domain, LPCSTR Password, LPVOID pAuthIdentity)');
# my $ret = $DsMakePasswordCredentialsA->Call($User, $Domain, $Password, $pAuthIdentity);
# User : LPCSTR optional -> LPCSTR
# Domain : LPCSTR optional -> LPCSTR
# Password : LPCSTR optional -> LPCSTR
# pAuthIdentity : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f DsMakePasswordCredentialsW (Unicode版) — ユーザー名とパスワードから認証資格情報を作成する(Unicode版)。