ホーム › Security.Authentication.Identity › LsaLogonUser
LsaLogonUser
関数指定した認証情報でユーザーをログオンさせアクセストークンを取得する。
シグネチャ
// SECUR32.dll
#include <windows.h>
NTSTATUS LsaLogonUser(
HANDLE LsaHandle,
LSA_STRING* OriginName,
SECURITY_LOGON_TYPE LogonType,
DWORD AuthenticationPackage,
void* AuthenticationInformation,
DWORD AuthenticationInformationLength,
TOKEN_GROUPS* LocalGroups, // optional
TOKEN_SOURCE* SourceContext,
void** ProfileBuffer,
DWORD* ProfileBufferLength,
LUID* LogonId,
HANDLE* Token,
QUOTA_LIMITS* Quotas,
INT* SubStatus
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| LsaHandle | HANDLE | in | LsaRegisterLogonProcess等で取得したLSA接続ハンドル。 |
| OriginName | LSA_STRING* | in | ログオン元を示す名前を保持するLSA_STRINGへのポインタ。 |
| LogonType | SECURITY_LOGON_TYPE | in | ログオンの種類(対話/ネットワーク/サービス等)を示す列挙値。 |
| AuthenticationPackage | DWORD | in | 使用する認証パッケージの識別子。 |
| AuthenticationInformation | void* | in | 認証パッケージ固有の資格情報を格納したバッファへのポインタ。 |
| AuthenticationInformationLength | DWORD | in | AuthenticationInformationのバイト数。 |
| LocalGroups | TOKEN_GROUPS* | inoptional | トークンに追加するローカルグループのTOKEN_GROUPS。不要ならNULL可。 |
| SourceContext | TOKEN_SOURCE* | in | トークンのソース情報を示すTOKEN_SOURCEへのポインタ。 |
| ProfileBuffer | void** | out | 認証パッケージが返すプロファイル情報を受け取る出力ポインタ。 |
| ProfileBufferLength | DWORD* | out | ProfileBufferのバイト数を受け取る出力先。 |
| LogonId | LUID* | inout | 新規ログオンセッションのLUIDを受け取る出力先。 |
| Token | HANDLE* | out | 生成されたアクセストークンハンドルを受け取る出力先。 |
| Quotas | QUOTA_LIMITS* | out | 新規トークンに割り当てられたクォータ制限を受け取る出力先。 |
| SubStatus | INT* | out | ログオン失敗時の詳細サブステータスを受け取る出力先。 |
戻り値の型: NTSTATUS
各言語での呼び出し定義
// SECUR32.dll
#include <windows.h>
NTSTATUS LsaLogonUser(
HANDLE LsaHandle,
LSA_STRING* OriginName,
SECURITY_LOGON_TYPE LogonType,
DWORD AuthenticationPackage,
void* AuthenticationInformation,
DWORD AuthenticationInformationLength,
TOKEN_GROUPS* LocalGroups, // optional
TOKEN_SOURCE* SourceContext,
void** ProfileBuffer,
DWORD* ProfileBufferLength,
LUID* LogonId,
HANDLE* Token,
QUOTA_LIMITS* Quotas,
INT* SubStatus
);[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int LsaLogonUser(
IntPtr LsaHandle, // HANDLE
IntPtr OriginName, // LSA_STRING*
int LogonType, // SECURITY_LOGON_TYPE
uint AuthenticationPackage, // DWORD
IntPtr AuthenticationInformation, // void*
uint AuthenticationInformationLength, // DWORD
IntPtr LocalGroups, // TOKEN_GROUPS* optional
IntPtr SourceContext, // TOKEN_SOURCE*
IntPtr ProfileBuffer, // void** out
out uint ProfileBufferLength, // DWORD* out
IntPtr LogonId, // LUID* in/out
IntPtr Token, // HANDLE* out
IntPtr Quotas, // QUOTA_LIMITS* out
out int SubStatus // INT* out
);<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function LsaLogonUser(
LsaHandle As IntPtr, ' HANDLE
OriginName As IntPtr, ' LSA_STRING*
LogonType As Integer, ' SECURITY_LOGON_TYPE
AuthenticationPackage As UInteger, ' DWORD
AuthenticationInformation As IntPtr, ' void*
AuthenticationInformationLength As UInteger, ' DWORD
LocalGroups As IntPtr, ' TOKEN_GROUPS* optional
SourceContext As IntPtr, ' TOKEN_SOURCE*
ProfileBuffer As IntPtr, ' void** out
<Out> ByRef ProfileBufferLength As UInteger, ' DWORD* out
LogonId As IntPtr, ' LUID* in/out
Token As IntPtr, ' HANDLE* out
Quotas As IntPtr, ' QUOTA_LIMITS* out
<Out> ByRef SubStatus As Integer ' INT* out
) As Integer
End Function' LsaHandle : HANDLE
' OriginName : LSA_STRING*
' LogonType : SECURITY_LOGON_TYPE
' AuthenticationPackage : DWORD
' AuthenticationInformation : void*
' AuthenticationInformationLength : DWORD
' LocalGroups : TOKEN_GROUPS* optional
' SourceContext : TOKEN_SOURCE*
' ProfileBuffer : void** out
' ProfileBufferLength : DWORD* out
' LogonId : LUID* in/out
' Token : HANDLE* out
' Quotas : QUOTA_LIMITS* out
' SubStatus : INT* out
Declare PtrSafe Function LsaLogonUser Lib "secur32" ( _
ByVal LsaHandle As LongPtr, _
ByVal OriginName As LongPtr, _
ByVal LogonType As Long, _
ByVal AuthenticationPackage As Long, _
ByVal AuthenticationInformation As LongPtr, _
ByVal AuthenticationInformationLength As Long, _
ByVal LocalGroups As LongPtr, _
ByVal SourceContext As LongPtr, _
ByVal ProfileBuffer As LongPtr, _
ByRef ProfileBufferLength As Long, _
ByVal LogonId As LongPtr, _
ByVal Token As LongPtr, _
ByVal Quotas As LongPtr, _
ByRef SubStatus As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
LsaLogonUser = ctypes.windll.secur32.LsaLogonUser
LsaLogonUser.restype = ctypes.c_int
LsaLogonUser.argtypes = [
wintypes.HANDLE, # LsaHandle : HANDLE
ctypes.c_void_p, # OriginName : LSA_STRING*
ctypes.c_int, # LogonType : SECURITY_LOGON_TYPE
wintypes.DWORD, # AuthenticationPackage : DWORD
ctypes.POINTER(None), # AuthenticationInformation : void*
wintypes.DWORD, # AuthenticationInformationLength : DWORD
ctypes.c_void_p, # LocalGroups : TOKEN_GROUPS* optional
ctypes.c_void_p, # SourceContext : TOKEN_SOURCE*
ctypes.c_void_p, # ProfileBuffer : void** out
ctypes.POINTER(wintypes.DWORD), # ProfileBufferLength : DWORD* out
ctypes.c_void_p, # LogonId : LUID* in/out
ctypes.c_void_p, # Token : HANDLE* out
ctypes.c_void_p, # Quotas : QUOTA_LIMITS* out
ctypes.POINTER(ctypes.c_int), # SubStatus : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SECUR32.dll')
LsaLogonUser = Fiddle::Function.new(
lib['LsaLogonUser'],
[
Fiddle::TYPE_VOIDP, # LsaHandle : HANDLE
Fiddle::TYPE_VOIDP, # OriginName : LSA_STRING*
Fiddle::TYPE_INT, # LogonType : SECURITY_LOGON_TYPE
-Fiddle::TYPE_INT, # AuthenticationPackage : DWORD
Fiddle::TYPE_VOIDP, # AuthenticationInformation : void*
-Fiddle::TYPE_INT, # AuthenticationInformationLength : DWORD
Fiddle::TYPE_VOIDP, # LocalGroups : TOKEN_GROUPS* optional
Fiddle::TYPE_VOIDP, # SourceContext : TOKEN_SOURCE*
Fiddle::TYPE_VOIDP, # ProfileBuffer : void** out
Fiddle::TYPE_VOIDP, # ProfileBufferLength : DWORD* out
Fiddle::TYPE_VOIDP, # LogonId : LUID* in/out
Fiddle::TYPE_VOIDP, # Token : HANDLE* out
Fiddle::TYPE_VOIDP, # Quotas : QUOTA_LIMITS* out
Fiddle::TYPE_VOIDP, # SubStatus : INT* out
],
Fiddle::TYPE_INT)#[link(name = "secur32")]
extern "system" {
fn LsaLogonUser(
LsaHandle: *mut core::ffi::c_void, // HANDLE
OriginName: *mut LSA_STRING, // LSA_STRING*
LogonType: i32, // SECURITY_LOGON_TYPE
AuthenticationPackage: u32, // DWORD
AuthenticationInformation: *mut (), // void*
AuthenticationInformationLength: u32, // DWORD
LocalGroups: *mut TOKEN_GROUPS, // TOKEN_GROUPS* optional
SourceContext: *mut TOKEN_SOURCE, // TOKEN_SOURCE*
ProfileBuffer: *mut *mut (), // void** out
ProfileBufferLength: *mut u32, // DWORD* out
LogonId: *mut LUID, // LUID* in/out
Token: *mut *mut core::ffi::c_void, // HANDLE* out
Quotas: *mut QUOTA_LIMITS, // QUOTA_LIMITS* out
SubStatus: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SECUR32.dll")]
public static extern int LsaLogonUser(IntPtr LsaHandle, IntPtr OriginName, int LogonType, uint AuthenticationPackage, IntPtr AuthenticationInformation, uint AuthenticationInformationLength, IntPtr LocalGroups, IntPtr SourceContext, IntPtr ProfileBuffer, out uint ProfileBufferLength, IntPtr LogonId, IntPtr Token, IntPtr Quotas, out int SubStatus);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_LsaLogonUser' -Namespace Win32 -PassThru
# $api::LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)#uselib "SECUR32.dll"
#func global LsaLogonUser "LsaLogonUser" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; LsaLogonUser LsaHandle, varptr(OriginName), LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, varptr(LocalGroups), varptr(SourceContext), ProfileBuffer, varptr(ProfileBufferLength), varptr(LogonId), Token, varptr(Quotas), varptr(SubStatus) ; 戻り値は stat
; LsaHandle : HANDLE -> "sptr"
; OriginName : LSA_STRING* -> "sptr"
; LogonType : SECURITY_LOGON_TYPE -> "sptr"
; AuthenticationPackage : DWORD -> "sptr"
; AuthenticationInformation : void* -> "sptr"
; AuthenticationInformationLength : DWORD -> "sptr"
; LocalGroups : TOKEN_GROUPS* optional -> "sptr"
; SourceContext : TOKEN_SOURCE* -> "sptr"
; ProfileBuffer : void** out -> "sptr"
; ProfileBufferLength : DWORD* out -> "sptr"
; LogonId : LUID* in/out -> "sptr"
; Token : HANDLE* out -> "sptr"
; Quotas : QUOTA_LIMITS* out -> "sptr"
; SubStatus : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SECUR32.dll" #cfunc global LsaLogonUser "LsaLogonUser" sptr, var, int, int, sptr, int, var, var, sptr, var, var, sptr, var, var ; res = LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus) ; LsaHandle : HANDLE -> "sptr" ; OriginName : LSA_STRING* -> "var" ; LogonType : SECURITY_LOGON_TYPE -> "int" ; AuthenticationPackage : DWORD -> "int" ; AuthenticationInformation : void* -> "sptr" ; AuthenticationInformationLength : DWORD -> "int" ; LocalGroups : TOKEN_GROUPS* optional -> "var" ; SourceContext : TOKEN_SOURCE* -> "var" ; ProfileBuffer : void** out -> "sptr" ; ProfileBufferLength : DWORD* out -> "var" ; LogonId : LUID* in/out -> "var" ; Token : HANDLE* out -> "sptr" ; Quotas : QUOTA_LIMITS* out -> "var" ; SubStatus : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SECUR32.dll" #cfunc global LsaLogonUser "LsaLogonUser" sptr, sptr, int, int, sptr, int, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr ; res = LsaLogonUser(LsaHandle, varptr(OriginName), LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, varptr(LocalGroups), varptr(SourceContext), ProfileBuffer, varptr(ProfileBufferLength), varptr(LogonId), Token, varptr(Quotas), varptr(SubStatus)) ; LsaHandle : HANDLE -> "sptr" ; OriginName : LSA_STRING* -> "sptr" ; LogonType : SECURITY_LOGON_TYPE -> "int" ; AuthenticationPackage : DWORD -> "int" ; AuthenticationInformation : void* -> "sptr" ; AuthenticationInformationLength : DWORD -> "int" ; LocalGroups : TOKEN_GROUPS* optional -> "sptr" ; SourceContext : TOKEN_SOURCE* -> "sptr" ; ProfileBuffer : void** out -> "sptr" ; ProfileBufferLength : DWORD* out -> "sptr" ; LogonId : LUID* in/out -> "sptr" ; Token : HANDLE* out -> "sptr" ; Quotas : QUOTA_LIMITS* out -> "sptr" ; SubStatus : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; NTSTATUS LsaLogonUser(HANDLE LsaHandle, LSA_STRING* OriginName, SECURITY_LOGON_TYPE LogonType, DWORD AuthenticationPackage, void* AuthenticationInformation, DWORD AuthenticationInformationLength, TOKEN_GROUPS* LocalGroups, TOKEN_SOURCE* SourceContext, void** ProfileBuffer, DWORD* ProfileBufferLength, LUID* LogonId, HANDLE* Token, QUOTA_LIMITS* Quotas, INT* SubStatus) #uselib "SECUR32.dll" #cfunc global LsaLogonUser "LsaLogonUser" intptr, var, int, int, intptr, int, var, var, intptr, var, var, intptr, var, var ; res = LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus) ; LsaHandle : HANDLE -> "intptr" ; OriginName : LSA_STRING* -> "var" ; LogonType : SECURITY_LOGON_TYPE -> "int" ; AuthenticationPackage : DWORD -> "int" ; AuthenticationInformation : void* -> "intptr" ; AuthenticationInformationLength : DWORD -> "int" ; LocalGroups : TOKEN_GROUPS* optional -> "var" ; SourceContext : TOKEN_SOURCE* -> "var" ; ProfileBuffer : void** out -> "intptr" ; ProfileBufferLength : DWORD* out -> "var" ; LogonId : LUID* in/out -> "var" ; Token : HANDLE* out -> "intptr" ; Quotas : QUOTA_LIMITS* out -> "var" ; SubStatus : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; NTSTATUS LsaLogonUser(HANDLE LsaHandle, LSA_STRING* OriginName, SECURITY_LOGON_TYPE LogonType, DWORD AuthenticationPackage, void* AuthenticationInformation, DWORD AuthenticationInformationLength, TOKEN_GROUPS* LocalGroups, TOKEN_SOURCE* SourceContext, void** ProfileBuffer, DWORD* ProfileBufferLength, LUID* LogonId, HANDLE* Token, QUOTA_LIMITS* Quotas, INT* SubStatus) #uselib "SECUR32.dll" #cfunc global LsaLogonUser "LsaLogonUser" intptr, intptr, int, int, intptr, int, intptr, intptr, intptr, intptr, intptr, intptr, intptr, intptr ; res = LsaLogonUser(LsaHandle, varptr(OriginName), LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, varptr(LocalGroups), varptr(SourceContext), ProfileBuffer, varptr(ProfileBufferLength), varptr(LogonId), Token, varptr(Quotas), varptr(SubStatus)) ; LsaHandle : HANDLE -> "intptr" ; OriginName : LSA_STRING* -> "intptr" ; LogonType : SECURITY_LOGON_TYPE -> "int" ; AuthenticationPackage : DWORD -> "int" ; AuthenticationInformation : void* -> "intptr" ; AuthenticationInformationLength : DWORD -> "int" ; LocalGroups : TOKEN_GROUPS* optional -> "intptr" ; SourceContext : TOKEN_SOURCE* -> "intptr" ; ProfileBuffer : void** out -> "intptr" ; ProfileBufferLength : DWORD* out -> "intptr" ; LogonId : LUID* in/out -> "intptr" ; Token : HANDLE* out -> "intptr" ; Quotas : QUOTA_LIMITS* out -> "intptr" ; SubStatus : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
secur32 = windows.NewLazySystemDLL("SECUR32.dll")
procLsaLogonUser = secur32.NewProc("LsaLogonUser")
)
// LsaHandle (HANDLE), OriginName (LSA_STRING*), LogonType (SECURITY_LOGON_TYPE), AuthenticationPackage (DWORD), AuthenticationInformation (void*), AuthenticationInformationLength (DWORD), LocalGroups (TOKEN_GROUPS* optional), SourceContext (TOKEN_SOURCE*), ProfileBuffer (void** out), ProfileBufferLength (DWORD* out), LogonId (LUID* in/out), Token (HANDLE* out), Quotas (QUOTA_LIMITS* out), SubStatus (INT* out)
r1, _, err := procLsaLogonUser.Call(
uintptr(LsaHandle),
uintptr(OriginName),
uintptr(LogonType),
uintptr(AuthenticationPackage),
uintptr(AuthenticationInformation),
uintptr(AuthenticationInformationLength),
uintptr(LocalGroups),
uintptr(SourceContext),
uintptr(ProfileBuffer),
uintptr(ProfileBufferLength),
uintptr(LogonId),
uintptr(Token),
uintptr(Quotas),
uintptr(SubStatus),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // NTSTATUSfunction LsaLogonUser(
LsaHandle: THandle; // HANDLE
OriginName: Pointer; // LSA_STRING*
LogonType: Integer; // SECURITY_LOGON_TYPE
AuthenticationPackage: DWORD; // DWORD
AuthenticationInformation: Pointer; // void*
AuthenticationInformationLength: DWORD; // DWORD
LocalGroups: Pointer; // TOKEN_GROUPS* optional
SourceContext: Pointer; // TOKEN_SOURCE*
ProfileBuffer: Pointer; // void** out
ProfileBufferLength: Pointer; // DWORD* out
LogonId: Pointer; // LUID* in/out
Token: Pointer; // HANDLE* out
Quotas: Pointer; // QUOTA_LIMITS* out
SubStatus: Pointer // INT* out
): Integer; stdcall;
external 'SECUR32.dll' name 'LsaLogonUser';result := DllCall("SECUR32\LsaLogonUser"
, "Ptr", LsaHandle ; HANDLE
, "Ptr", OriginName ; LSA_STRING*
, "Int", LogonType ; SECURITY_LOGON_TYPE
, "UInt", AuthenticationPackage ; DWORD
, "Ptr", AuthenticationInformation ; void*
, "UInt", AuthenticationInformationLength ; DWORD
, "Ptr", LocalGroups ; TOKEN_GROUPS* optional
, "Ptr", SourceContext ; TOKEN_SOURCE*
, "Ptr", ProfileBuffer ; void** out
, "Ptr", ProfileBufferLength ; DWORD* out
, "Ptr", LogonId ; LUID* in/out
, "Ptr", Token ; HANDLE* out
, "Ptr", Quotas ; QUOTA_LIMITS* out
, "Ptr", SubStatus ; INT* out
, "Int") ; return: NTSTATUS●LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus) = DLL("SECUR32.dll", "int LsaLogonUser(void*, void*, int, dword, void*, dword, void*, void*, void*, void*, void*, void*, void*, void*)")
# 呼び出し: LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)
# LsaHandle : HANDLE -> "void*"
# OriginName : LSA_STRING* -> "void*"
# LogonType : SECURITY_LOGON_TYPE -> "int"
# AuthenticationPackage : DWORD -> "dword"
# AuthenticationInformation : void* -> "void*"
# AuthenticationInformationLength : DWORD -> "dword"
# LocalGroups : TOKEN_GROUPS* optional -> "void*"
# SourceContext : TOKEN_SOURCE* -> "void*"
# ProfileBuffer : void** out -> "void*"
# ProfileBufferLength : DWORD* out -> "void*"
# LogonId : LUID* in/out -> "void*"
# Token : HANDLE* out -> "void*"
# Quotas : QUOTA_LIMITS* out -> "void*"
# SubStatus : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "secur32" fn LsaLogonUser(
LsaHandle: ?*anyopaque, // HANDLE
OriginName: [*c]LSA_STRING, // LSA_STRING*
LogonType: i32, // SECURITY_LOGON_TYPE
AuthenticationPackage: u32, // DWORD
AuthenticationInformation: ?*anyopaque, // void*
AuthenticationInformationLength: u32, // DWORD
LocalGroups: [*c]TOKEN_GROUPS, // TOKEN_GROUPS* optional
SourceContext: [*c]TOKEN_SOURCE, // TOKEN_SOURCE*
ProfileBuffer: ?*anyopaque, // void** out
ProfileBufferLength: [*c]u32, // DWORD* out
LogonId: [*c]LUID, // LUID* in/out
Token: ?*anyopaque, // HANDLE* out
Quotas: [*c]QUOTA_LIMITS, // QUOTA_LIMITS* out
SubStatus: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;proc LsaLogonUser(
LsaHandle: pointer, # HANDLE
OriginName: ptr LSA_STRING, # LSA_STRING*
LogonType: int32, # SECURITY_LOGON_TYPE
AuthenticationPackage: uint32, # DWORD
AuthenticationInformation: pointer, # void*
AuthenticationInformationLength: uint32, # DWORD
LocalGroups: ptr TOKEN_GROUPS, # TOKEN_GROUPS* optional
SourceContext: ptr TOKEN_SOURCE, # TOKEN_SOURCE*
ProfileBuffer: pointer, # void** out
ProfileBufferLength: ptr uint32, # DWORD* out
LogonId: ptr LUID, # LUID* in/out
Token: pointer, # HANDLE* out
Quotas: ptr QUOTA_LIMITS, # QUOTA_LIMITS* out
SubStatus: ptr int32 # INT* out
): int32 {.importc: "LsaLogonUser", stdcall, dynlib: "SECUR32.dll".}pragma(lib, "secur32");
extern(Windows)
int LsaLogonUser(
void* LsaHandle, // HANDLE
LSA_STRING* OriginName, // LSA_STRING*
int LogonType, // SECURITY_LOGON_TYPE
uint AuthenticationPackage, // DWORD
void* AuthenticationInformation, // void*
uint AuthenticationInformationLength, // DWORD
TOKEN_GROUPS* LocalGroups, // TOKEN_GROUPS* optional
TOKEN_SOURCE* SourceContext, // TOKEN_SOURCE*
void** ProfileBuffer, // void** out
uint* ProfileBufferLength, // DWORD* out
LUID* LogonId, // LUID* in/out
void* Token, // HANDLE* out
QUOTA_LIMITS* Quotas, // QUOTA_LIMITS* out
int* SubStatus // INT* out
);ccall((:LsaLogonUser, "SECUR32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{LSA_STRING}, Int32, UInt32, Ptr{Cvoid}, UInt32, Ptr{TOKEN_GROUPS}, Ptr{TOKEN_SOURCE}, Ptr{Cvoid}, Ptr{UInt32}, Ptr{LUID}, Ptr{Cvoid}, Ptr{QUOTA_LIMITS}, Ptr{Int32}),
LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)
# LsaHandle : HANDLE -> Ptr{Cvoid}
# OriginName : LSA_STRING* -> Ptr{LSA_STRING}
# LogonType : SECURITY_LOGON_TYPE -> Int32
# AuthenticationPackage : DWORD -> UInt32
# AuthenticationInformation : void* -> Ptr{Cvoid}
# AuthenticationInformationLength : DWORD -> UInt32
# LocalGroups : TOKEN_GROUPS* optional -> Ptr{TOKEN_GROUPS}
# SourceContext : TOKEN_SOURCE* -> Ptr{TOKEN_SOURCE}
# ProfileBuffer : void** out -> Ptr{Cvoid}
# ProfileBufferLength : DWORD* out -> Ptr{UInt32}
# LogonId : LUID* in/out -> Ptr{LUID}
# Token : HANDLE* out -> Ptr{Cvoid}
# Quotas : QUOTA_LIMITS* out -> Ptr{QUOTA_LIMITS}
# SubStatus : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t LsaLogonUser(
void* LsaHandle,
void* OriginName,
int32_t LogonType,
uint32_t AuthenticationPackage,
void* AuthenticationInformation,
uint32_t AuthenticationInformationLength,
void* LocalGroups,
void* SourceContext,
void** ProfileBuffer,
uint32_t* ProfileBufferLength,
void* LogonId,
void* Token,
void* Quotas,
int32_t* SubStatus);
]]
local secur32 = ffi.load("secur32")
-- secur32.LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)
-- LsaHandle : HANDLE
-- OriginName : LSA_STRING*
-- LogonType : SECURITY_LOGON_TYPE
-- AuthenticationPackage : DWORD
-- AuthenticationInformation : void*
-- AuthenticationInformationLength : DWORD
-- LocalGroups : TOKEN_GROUPS* optional
-- SourceContext : TOKEN_SOURCE*
-- ProfileBuffer : void** out
-- ProfileBufferLength : DWORD* out
-- LogonId : LUID* in/out
-- Token : HANDLE* out
-- Quotas : QUOTA_LIMITS* out
-- SubStatus : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const LsaLogonUser = lib.func('__stdcall', 'LsaLogonUser', 'int32_t', ['void *', 'void *', 'int32_t', 'uint32_t', 'void *', 'uint32_t', 'void *', 'void *', 'void *', 'uint32_t *', 'void *', 'void *', 'void *', 'int32_t *']);
// LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)
// LsaHandle : HANDLE -> 'void *'
// OriginName : LSA_STRING* -> 'void *'
// LogonType : SECURITY_LOGON_TYPE -> 'int32_t'
// AuthenticationPackage : DWORD -> 'uint32_t'
// AuthenticationInformation : void* -> 'void *'
// AuthenticationInformationLength : DWORD -> 'uint32_t'
// LocalGroups : TOKEN_GROUPS* optional -> 'void *'
// SourceContext : TOKEN_SOURCE* -> 'void *'
// ProfileBuffer : void** out -> 'void *'
// ProfileBufferLength : DWORD* out -> 'uint32_t *'
// LogonId : LUID* in/out -> 'void *'
// Token : HANDLE* out -> 'void *'
// Quotas : QUOTA_LIMITS* out -> 'void *'
// SubStatus : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SECUR32.dll", {
LsaLogonUser: { parameters: ["pointer", "pointer", "i32", "u32", "pointer", "u32", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus)
// LsaHandle : HANDLE -> "pointer"
// OriginName : LSA_STRING* -> "pointer"
// LogonType : SECURITY_LOGON_TYPE -> "i32"
// AuthenticationPackage : DWORD -> "u32"
// AuthenticationInformation : void* -> "pointer"
// AuthenticationInformationLength : DWORD -> "u32"
// LocalGroups : TOKEN_GROUPS* optional -> "pointer"
// SourceContext : TOKEN_SOURCE* -> "pointer"
// ProfileBuffer : void** out -> "pointer"
// ProfileBufferLength : DWORD* out -> "pointer"
// LogonId : LUID* in/out -> "pointer"
// Token : HANDLE* out -> "pointer"
// Quotas : QUOTA_LIMITS* out -> "pointer"
// SubStatus : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t LsaLogonUser(
void* LsaHandle,
void* OriginName,
int32_t LogonType,
uint32_t AuthenticationPackage,
void* AuthenticationInformation,
uint32_t AuthenticationInformationLength,
void* LocalGroups,
void* SourceContext,
void** ProfileBuffer,
uint32_t* ProfileBufferLength,
void* LogonId,
void* Token,
void* Quotas,
int32_t* SubStatus);
C, "SECUR32.dll");
// $ffi->LsaLogonUser(LsaHandle, OriginName, LogonType, AuthenticationPackage, AuthenticationInformation, AuthenticationInformationLength, LocalGroups, SourceContext, ProfileBuffer, ProfileBufferLength, LogonId, Token, Quotas, SubStatus);
// LsaHandle : HANDLE
// OriginName : LSA_STRING*
// LogonType : SECURITY_LOGON_TYPE
// AuthenticationPackage : DWORD
// AuthenticationInformation : void*
// AuthenticationInformationLength : DWORD
// LocalGroups : TOKEN_GROUPS* optional
// SourceContext : TOKEN_SOURCE*
// ProfileBuffer : void** out
// ProfileBufferLength : DWORD* out
// LogonId : LUID* in/out
// Token : HANDLE* out
// Quotas : QUOTA_LIMITS* out
// SubStatus : INT* 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 Secur32 extends StdCallLibrary {
Secur32 INSTANCE = Native.load("secur32", Secur32.class);
int LsaLogonUser(
Pointer LsaHandle, // HANDLE
Pointer OriginName, // LSA_STRING*
int LogonType, // SECURITY_LOGON_TYPE
int AuthenticationPackage, // DWORD
Pointer AuthenticationInformation, // void*
int AuthenticationInformationLength, // DWORD
Pointer LocalGroups, // TOKEN_GROUPS* optional
Pointer SourceContext, // TOKEN_SOURCE*
Pointer ProfileBuffer, // void** out
IntByReference ProfileBufferLength, // DWORD* out
Pointer LogonId, // LUID* in/out
Pointer Token, // HANDLE* out
Pointer Quotas, // QUOTA_LIMITS* out
IntByReference SubStatus // INT* out
);
}@[Link("secur32")]
lib LibSECUR32
fun LsaLogonUser = LsaLogonUser(
LsaHandle : Void*, # HANDLE
OriginName : LSA_STRING*, # LSA_STRING*
LogonType : Int32, # SECURITY_LOGON_TYPE
AuthenticationPackage : UInt32, # DWORD
AuthenticationInformation : Void*, # void*
AuthenticationInformationLength : UInt32, # DWORD
LocalGroups : TOKEN_GROUPS*, # TOKEN_GROUPS* optional
SourceContext : TOKEN_SOURCE*, # TOKEN_SOURCE*
ProfileBuffer : Void**, # void** out
ProfileBufferLength : UInt32*, # DWORD* out
LogonId : LUID*, # LUID* in/out
Token : Void*, # HANDLE* out
Quotas : QUOTA_LIMITS*, # QUOTA_LIMITS* out
SubStatus : Int32* # INT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef LsaLogonUserNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
typedef LsaLogonUserDart = int Function(Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>, int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Int32>);
final LsaLogonUser = DynamicLibrary.open('SECUR32.dll')
.lookupFunction<LsaLogonUserNative, LsaLogonUserDart>('LsaLogonUser');
// LsaHandle : HANDLE -> Pointer<Void>
// OriginName : LSA_STRING* -> Pointer<Void>
// LogonType : SECURITY_LOGON_TYPE -> Int32
// AuthenticationPackage : DWORD -> Uint32
// AuthenticationInformation : void* -> Pointer<Void>
// AuthenticationInformationLength : DWORD -> Uint32
// LocalGroups : TOKEN_GROUPS* optional -> Pointer<Void>
// SourceContext : TOKEN_SOURCE* -> Pointer<Void>
// ProfileBuffer : void** out -> Pointer<Void>
// ProfileBufferLength : DWORD* out -> Pointer<Uint32>
// LogonId : LUID* in/out -> Pointer<Void>
// Token : HANDLE* out -> Pointer<Void>
// Quotas : QUOTA_LIMITS* out -> Pointer<Void>
// SubStatus : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function LsaLogonUser(
LsaHandle: THandle; // HANDLE
OriginName: Pointer; // LSA_STRING*
LogonType: Integer; // SECURITY_LOGON_TYPE
AuthenticationPackage: DWORD; // DWORD
AuthenticationInformation: Pointer; // void*
AuthenticationInformationLength: DWORD; // DWORD
LocalGroups: Pointer; // TOKEN_GROUPS* optional
SourceContext: Pointer; // TOKEN_SOURCE*
ProfileBuffer: Pointer; // void** out
ProfileBufferLength: Pointer; // DWORD* out
LogonId: Pointer; // LUID* in/out
Token: Pointer; // HANDLE* out
Quotas: Pointer; // QUOTA_LIMITS* out
SubStatus: Pointer // INT* out
): Integer; stdcall;
external 'SECUR32.dll' name 'LsaLogonUser';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "LsaLogonUser"
c_LsaLogonUser :: Ptr () -> Ptr () -> Int32 -> Word32 -> Ptr () -> Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr Word32 -> Ptr () -> Ptr () -> Ptr () -> Ptr Int32 -> IO Int32
-- LsaHandle : HANDLE -> Ptr ()
-- OriginName : LSA_STRING* -> Ptr ()
-- LogonType : SECURITY_LOGON_TYPE -> Int32
-- AuthenticationPackage : DWORD -> Word32
-- AuthenticationInformation : void* -> Ptr ()
-- AuthenticationInformationLength : DWORD -> Word32
-- LocalGroups : TOKEN_GROUPS* optional -> Ptr ()
-- SourceContext : TOKEN_SOURCE* -> Ptr ()
-- ProfileBuffer : void** out -> Ptr ()
-- ProfileBufferLength : DWORD* out -> Ptr Word32
-- LogonId : LUID* in/out -> Ptr ()
-- Token : HANDLE* out -> Ptr ()
-- Quotas : QUOTA_LIMITS* out -> Ptr ()
-- SubStatus : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let lsalogonuser =
foreign "LsaLogonUser"
((ptr void) @-> (ptr void) @-> int32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* LsaHandle : HANDLE -> (ptr void) *)
(* OriginName : LSA_STRING* -> (ptr void) *)
(* LogonType : SECURITY_LOGON_TYPE -> int32_t *)
(* AuthenticationPackage : DWORD -> uint32_t *)
(* AuthenticationInformation : void* -> (ptr void) *)
(* AuthenticationInformationLength : DWORD -> uint32_t *)
(* LocalGroups : TOKEN_GROUPS* optional -> (ptr void) *)
(* SourceContext : TOKEN_SOURCE* -> (ptr void) *)
(* ProfileBuffer : void** out -> (ptr void) *)
(* ProfileBufferLength : DWORD* out -> (ptr uint32_t) *)
(* LogonId : LUID* in/out -> (ptr void) *)
(* Token : HANDLE* out -> (ptr void) *)
(* Quotas : QUOTA_LIMITS* out -> (ptr void) *)
(* SubStatus : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)
(cffi:defcfun ("LsaLogonUser" lsa-logon-user :convention :stdcall) :int32
(lsa-handle :pointer) ; HANDLE
(origin-name :pointer) ; LSA_STRING*
(logon-type :int32) ; SECURITY_LOGON_TYPE
(authentication-package :uint32) ; DWORD
(authentication-information :pointer) ; void*
(authentication-information-length :uint32) ; DWORD
(local-groups :pointer) ; TOKEN_GROUPS* optional
(source-context :pointer) ; TOKEN_SOURCE*
(profile-buffer :pointer) ; void** out
(profile-buffer-length :pointer) ; DWORD* out
(logon-id :pointer) ; LUID* in/out
(token :pointer) ; HANDLE* out
(quotas :pointer) ; QUOTA_LIMITS* out
(sub-status :pointer)) ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $LsaLogonUser = Win32::API::More->new('SECUR32',
'int LsaLogonUser(HANDLE LsaHandle, LPVOID OriginName, int LogonType, DWORD AuthenticationPackage, LPVOID AuthenticationInformation, DWORD AuthenticationInformationLength, LPVOID LocalGroups, LPVOID SourceContext, LPVOID ProfileBuffer, LPVOID ProfileBufferLength, LPVOID LogonId, HANDLE Token, LPVOID Quotas, LPVOID SubStatus)');
# my $ret = $LsaLogonUser->Call($LsaHandle, $OriginName, $LogonType, $AuthenticationPackage, $AuthenticationInformation, $AuthenticationInformationLength, $LocalGroups, $SourceContext, $ProfileBuffer, $ProfileBufferLength, $LogonId, $Token, $Quotas, $SubStatus);
# LsaHandle : HANDLE -> HANDLE
# OriginName : LSA_STRING* -> LPVOID
# LogonType : SECURITY_LOGON_TYPE -> int
# AuthenticationPackage : DWORD -> DWORD
# AuthenticationInformation : void* -> LPVOID
# AuthenticationInformationLength : DWORD -> DWORD
# LocalGroups : TOKEN_GROUPS* optional -> LPVOID
# SourceContext : TOKEN_SOURCE* -> LPVOID
# ProfileBuffer : void** out -> LPVOID
# ProfileBufferLength : DWORD* out -> LPVOID
# LogonId : LUID* in/out -> LPVOID
# Token : HANDLE* out -> HANDLE
# Quotas : QUOTA_LIMITS* out -> LPVOID
# SubStatus : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。