Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › LsaLogonUser

LsaLogonUser

関数
指定した認証情報でユーザーをログオンさせアクセストークンを取得する。
DLLSECUR32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// 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
);

パラメーター

名前方向
LsaHandleHANDLEin
OriginNameLSA_STRING*in
LogonTypeSECURITY_LOGON_TYPEin
AuthenticationPackageDWORDin
AuthenticationInformationvoid*in
AuthenticationInformationLengthDWORDin
LocalGroupsTOKEN_GROUPS*inoptional
SourceContextTOKEN_SOURCE*in
ProfileBuffervoid**out
ProfileBufferLengthDWORD*out
LogonIdLUID*inout
TokenHANDLE*out
QuotasQUOTA_LIMITS*out
SubStatusINT*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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // NTSTATUS
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';
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)。