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

LsaRegisterLogonProcess

関数
ログオンプロセスとしてLSAに登録し接続ハンドルを取得する。
DLLSECUR32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

// SECUR32.dll
#include <windows.h>

NTSTATUS LsaRegisterLogonProcess(
    LSA_STRING* LogonProcessName,
    HANDLE* LsaHandle,
    DWORD* SecurityMode
);

パラメーター

名前型方向説明
LogonProcessNameLSA_STRING*in

ログオンアプリケーションを識別する LSA_STRING 構造体へのポインター。これは、管理者に表示するのに適した印刷可能な名前である必要があります。たとえば、Windows のログオンアプリケーションでは "User32LogonProcess" という名前を使用することがあります。この名前は、監査の際に LSA によって使用されます。LsaRegisterLogonProcess は、その名前が既に使用されているかどうかをチェックしません。

この文字列は 127 バイトを超えてはなりません。

LsaHandleHANDLE*out以降の認証関数の呼び出しで使用されるハンドルを受け取るポインター。
SecurityModeDWORD*out返される値には意味がないため、無視してください。

戻り値の型: NTSTATUS

公式ドキュメント

LSA サーバーへの接続を確立し、呼び出し元がログオンアプリケーションであることを検証します。

戻り値

関数が成功した場合、戻り値は STATUS_SUCCESS です。

関数が失敗した場合、戻り値は NTSTATUS コードです。次のエラーコードが返される可能性があります。

戻り値 説明
STATUS_PORT_CONNECTION_REFUSED
呼び出し元が、この関数の呼び出しに必要な SeTcbPrivilege 特権を持っていません。

この特権は、 LsaAddAccountRights を呼び出すことで設定できます。

STATUS_NAME_TOO_LONG
指定されたログオンプロセス名が 127 バイトを超えています。

詳細については、 LSA ポリシー関数の戻り値を参照してください。

LsaNtStatusToWinError 関数は、NTSTATUS コードを Windows のエラーコードに変換します。

解説(Remarks)

ログオンプロセスが LSA の提供する他のログオン認証関数を使用するには、事前にこの関数を呼び出す必要があります。

LsaRegisterLogonProcess 関数は、関数を呼び出しているアプリケーションに SeTcbPrivilege 特権が設定されているかどうかを確認することで、そのアプリケーションがログオンプロセスであることを検証します。また、以降の LSA 認証呼び出しに備えて、そのアプリケーションのプロセスを PROCESS_DUP_HANDLE アクセスで開きます。詳細については、 DuplicateHandle を参照してください。

LSA サーバーへの接続の使用を終えたら、LsaDeregisterLogonProcess 関数を呼び出して、呼び出し元のログオンアプリケーションコンテキストを削除し、接続を閉じてください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// SECUR32.dll
#include <windows.h>

NTSTATUS LsaRegisterLogonProcess(
    LSA_STRING* LogonProcessName,
    HANDLE* LsaHandle,
    DWORD* SecurityMode
);
[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int LsaRegisterLogonProcess(
    IntPtr LogonProcessName,   // LSA_STRING*
    IntPtr LsaHandle,   // HANDLE* out
    out uint SecurityMode   // DWORD* out
);
<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function LsaRegisterLogonProcess(
    LogonProcessName As IntPtr,   ' LSA_STRING*
    LsaHandle As IntPtr,   ' HANDLE* out
    <Out> ByRef SecurityMode As UInteger   ' DWORD* out
) As Integer
End Function
' LogonProcessName : LSA_STRING*
' LsaHandle : HANDLE* out
' SecurityMode : DWORD* out
Declare PtrSafe Function LsaRegisterLogonProcess Lib "secur32" ( _
    ByVal LogonProcessName As LongPtr, _
    ByVal LsaHandle As LongPtr, _
    ByRef SecurityMode As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

LsaRegisterLogonProcess = ctypes.windll.secur32.LsaRegisterLogonProcess
LsaRegisterLogonProcess.restype = ctypes.c_int
LsaRegisterLogonProcess.argtypes = [
    ctypes.c_void_p,  # LogonProcessName : LSA_STRING*
    ctypes.c_void_p,  # LsaHandle : HANDLE* out
    ctypes.POINTER(wintypes.DWORD),  # SecurityMode : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SECUR32.dll')
LsaRegisterLogonProcess = Fiddle::Function.new(
  lib['LsaRegisterLogonProcess'],
  [
    Fiddle::TYPE_VOIDP,  # LogonProcessName : LSA_STRING*
    Fiddle::TYPE_VOIDP,  # LsaHandle : HANDLE* out
    Fiddle::TYPE_VOIDP,  # SecurityMode : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "secur32")]
extern "system" {
    fn LsaRegisterLogonProcess(
        LogonProcessName: *mut LSA_STRING,  // LSA_STRING*
        LsaHandle: *mut *mut core::ffi::c_void,  // HANDLE* out
        SecurityMode: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SECUR32.dll")]
public static extern int LsaRegisterLogonProcess(IntPtr LogonProcessName, IntPtr LsaHandle, out uint SecurityMode);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_LsaRegisterLogonProcess' -Namespace Win32 -PassThru
# $api::LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
#uselib "SECUR32.dll"
#func global LsaRegisterLogonProcess "LsaRegisterLogonProcess" sptr, sptr, sptr
; LsaRegisterLogonProcess varptr(LogonProcessName), LsaHandle, varptr(SecurityMode)   ; 戻り値は stat
; LogonProcessName : LSA_STRING* -> "sptr"
; LsaHandle : HANDLE* out -> "sptr"
; SecurityMode : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SECUR32.dll"
#cfunc global LsaRegisterLogonProcess "LsaRegisterLogonProcess" var, sptr, var
; res = LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
; LogonProcessName : LSA_STRING* -> "var"
; LsaHandle : HANDLE* out -> "sptr"
; SecurityMode : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; NTSTATUS LsaRegisterLogonProcess(LSA_STRING* LogonProcessName, HANDLE* LsaHandle, DWORD* SecurityMode)
#uselib "SECUR32.dll"
#cfunc global LsaRegisterLogonProcess "LsaRegisterLogonProcess" var, intptr, var
; res = LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
; LogonProcessName : LSA_STRING* -> "var"
; LsaHandle : HANDLE* out -> "intptr"
; SecurityMode : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procLsaRegisterLogonProcess = secur32.NewProc("LsaRegisterLogonProcess")
)

// LogonProcessName (LSA_STRING*), LsaHandle (HANDLE* out), SecurityMode (DWORD* out)
r1, _, err := procLsaRegisterLogonProcess.Call(
	uintptr(LogonProcessName),
	uintptr(LsaHandle),
	uintptr(SecurityMode),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // NTSTATUS
function LsaRegisterLogonProcess(
  LogonProcessName: Pointer;   // LSA_STRING*
  LsaHandle: Pointer;   // HANDLE* out
  SecurityMode: Pointer   // DWORD* out
): Integer; stdcall;
  external 'SECUR32.dll' name 'LsaRegisterLogonProcess';
result := DllCall("SECUR32\LsaRegisterLogonProcess"
    , "Ptr", LogonProcessName   ; LSA_STRING*
    , "Ptr", LsaHandle   ; HANDLE* out
    , "Ptr", SecurityMode   ; DWORD* out
    , "Int")   ; return: NTSTATUS
●LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode) = DLL("SECUR32.dll", "int LsaRegisterLogonProcess(void*, void*, void*)")
# 呼び出し: LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
# LogonProcessName : LSA_STRING* -> "void*"
# LsaHandle : HANDLE* out -> "void*"
# SecurityMode : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "secur32" fn LsaRegisterLogonProcess(
    LogonProcessName: [*c]LSA_STRING, // LSA_STRING*
    LsaHandle: ?*anyopaque, // HANDLE* out
    SecurityMode: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;
proc LsaRegisterLogonProcess(
    LogonProcessName: ptr LSA_STRING,  # LSA_STRING*
    LsaHandle: pointer,  # HANDLE* out
    SecurityMode: ptr uint32  # DWORD* out
): int32 {.importc: "LsaRegisterLogonProcess", stdcall, dynlib: "SECUR32.dll".}
pragma(lib, "secur32");
extern(Windows)
int LsaRegisterLogonProcess(
    LSA_STRING* LogonProcessName,   // LSA_STRING*
    void* LsaHandle,   // HANDLE* out
    uint* SecurityMode   // DWORD* out
);
ccall((:LsaRegisterLogonProcess, "SECUR32.dll"), stdcall, Int32,
      (Ptr{LSA_STRING}, Ptr{Cvoid}, Ptr{UInt32}),
      LogonProcessName, LsaHandle, SecurityMode)
# LogonProcessName : LSA_STRING* -> Ptr{LSA_STRING}
# LsaHandle : HANDLE* out -> Ptr{Cvoid}
# SecurityMode : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t LsaRegisterLogonProcess(
    void* LogonProcessName,
    void* LsaHandle,
    uint32_t* SecurityMode);
]]
local secur32 = ffi.load("secur32")
-- secur32.LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
-- LogonProcessName : LSA_STRING*
-- LsaHandle : HANDLE* out
-- SecurityMode : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SECUR32.dll');
const LsaRegisterLogonProcess = lib.func('__stdcall', 'LsaRegisterLogonProcess', 'int32_t', ['void *', 'void *', 'uint32_t *']);
// LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
// LogonProcessName : LSA_STRING* -> 'void *'
// LsaHandle : HANDLE* out -> 'void *'
// SecurityMode : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SECUR32.dll", {
  LsaRegisterLogonProcess: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode)
// LogonProcessName : LSA_STRING* -> "pointer"
// LsaHandle : HANDLE* out -> "pointer"
// SecurityMode : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t LsaRegisterLogonProcess(
    void* LogonProcessName,
    void* LsaHandle,
    uint32_t* SecurityMode);
C, "SECUR32.dll");
// $ffi->LsaRegisterLogonProcess(LogonProcessName, LsaHandle, SecurityMode);
// LogonProcessName : LSA_STRING*
// LsaHandle : HANDLE* out
// SecurityMode : DWORD* 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 LsaRegisterLogonProcess(
        Pointer LogonProcessName,   // LSA_STRING*
        Pointer LsaHandle,   // HANDLE* out
        IntByReference SecurityMode   // DWORD* out
    );
}
@[Link("secur32")]
lib LibSECUR32
  fun LsaRegisterLogonProcess = LsaRegisterLogonProcess(
    LogonProcessName : LSA_STRING*,   # LSA_STRING*
    LsaHandle : Void*,   # HANDLE* out
    SecurityMode : UInt32*   # DWORD* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef LsaRegisterLogonProcessNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef LsaRegisterLogonProcessDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final LsaRegisterLogonProcess = DynamicLibrary.open('SECUR32.dll')
    .lookupFunction<LsaRegisterLogonProcessNative, LsaRegisterLogonProcessDart>('LsaRegisterLogonProcess');
// LogonProcessName : LSA_STRING* -> Pointer<Void>
// LsaHandle : HANDLE* out -> Pointer<Void>
// SecurityMode : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function LsaRegisterLogonProcess(
  LogonProcessName: Pointer;   // LSA_STRING*
  LsaHandle: Pointer;   // HANDLE* out
  SecurityMode: Pointer   // DWORD* out
): Integer; stdcall;
  external 'SECUR32.dll' name 'LsaRegisterLogonProcess';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "LsaRegisterLogonProcess"
  c_LsaRegisterLogonProcess :: Ptr () -> Ptr () -> Ptr Word32 -> IO Int32
-- LogonProcessName : LSA_STRING* -> Ptr ()
-- LsaHandle : HANDLE* out -> Ptr ()
-- SecurityMode : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let lsaregisterlogonprocess =
  foreign "LsaRegisterLogonProcess"
    ((ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* LogonProcessName : LSA_STRING* -> (ptr void) *)
(* LsaHandle : HANDLE* out -> (ptr void) *)
(* SecurityMode : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)

(cffi:defcfun ("LsaRegisterLogonProcess" lsa-register-logon-process :convention :stdcall) :int32
  (logon-process-name :pointer)   ; LSA_STRING*
  (lsa-handle :pointer)   ; HANDLE* out
  (security-mode :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $LsaRegisterLogonProcess = Win32::API::More->new('SECUR32',
    'int LsaRegisterLogonProcess(LPVOID LogonProcessName, HANDLE LsaHandle, LPVOID SecurityMode)');
# my $ret = $LsaRegisterLogonProcess->Call($LogonProcessName, $LsaHandle, $SecurityMode);
# LogonProcessName : LSA_STRING* -> LPVOID
# LsaHandle : HANDLE* out -> HANDLE
# SecurityMode : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型