Win32 API 日本語リファレンス
ホームSecurity › GetSecurityDescriptorOwner

GetSecurityDescriptorOwner

関数
セキュリティ記述子から所有者SIDを取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL GetSecurityDescriptorOwner(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID* pOwner,
    BOOL* lpbOwnerDefaulted
);

パラメーター

名前方向
pSecurityDescriptorPSECURITY_DESCRIPTORin
pOwnerPSID*out
lpbOwnerDefaultedBOOL*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetSecurityDescriptorOwner(
    PSECURITY_DESCRIPTOR pSecurityDescriptor,
    PSID* pOwner,
    BOOL* lpbOwnerDefaulted
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetSecurityDescriptorOwner(
    IntPtr pSecurityDescriptor,   // PSECURITY_DESCRIPTOR
    IntPtr pOwner,   // PSID* out
    out int lpbOwnerDefaulted   // BOOL* out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetSecurityDescriptorOwner(
    pSecurityDescriptor As IntPtr,   ' PSECURITY_DESCRIPTOR
    pOwner As IntPtr,   ' PSID* out
    <Out> ByRef lpbOwnerDefaulted As Integer   ' BOOL* out
) As Boolean
End Function
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
' pOwner : PSID* out
' lpbOwnerDefaulted : BOOL* out
Declare PtrSafe Function GetSecurityDescriptorOwner Lib "advapi32" ( _
    ByVal pSecurityDescriptor As LongPtr, _
    ByVal pOwner As LongPtr, _
    ByRef lpbOwnerDefaulted As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetSecurityDescriptorOwner = ctypes.windll.advapi32.GetSecurityDescriptorOwner
GetSecurityDescriptorOwner.restype = wintypes.BOOL
GetSecurityDescriptorOwner.argtypes = [
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    ctypes.c_void_p,  # pOwner : PSID* out
    ctypes.c_void_p,  # lpbOwnerDefaulted : BOOL* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
GetSecurityDescriptorOwner = Fiddle::Function.new(
  lib['GetSecurityDescriptorOwner'],
  [
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
    Fiddle::TYPE_VOIDP,  # pOwner : PSID* out
    Fiddle::TYPE_VOIDP,  # lpbOwnerDefaulted : BOOL* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn GetSecurityDescriptorOwner(
        pSecurityDescriptor: *mut core::ffi::c_void,  // PSECURITY_DESCRIPTOR
        pOwner: *mut *mut core::ffi::c_void,  // PSID* out
        lpbOwnerDefaulted: *mut i32  // BOOL* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool GetSecurityDescriptorOwner(IntPtr pSecurityDescriptor, IntPtr pOwner, out int lpbOwnerDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetSecurityDescriptorOwner' -Namespace Win32 -PassThru
# $api::GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
#uselib "ADVAPI32.dll"
#func global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" sptr, sptr, sptr
; GetSecurityDescriptorOwner pSecurityDescriptor, pOwner, lpbOwnerDefaulted   ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pOwner : PSID* out -> "sptr"
; lpbOwnerDefaulted : BOOL* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" sptr, sptr, int
; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; pOwner : PSID* out -> "sptr"
; lpbOwnerDefaulted : BOOL* out -> "int"
; BOOL GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pOwner, BOOL* lpbOwnerDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" intptr, intptr, int
; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
; pOwner : PSID* out -> "intptr"
; lpbOwnerDefaulted : BOOL* out -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetSecurityDescriptorOwner = advapi32.NewProc("GetSecurityDescriptorOwner")
)

// pSecurityDescriptor (PSECURITY_DESCRIPTOR), pOwner (PSID* out), lpbOwnerDefaulted (BOOL* out)
r1, _, err := procGetSecurityDescriptorOwner.Call(
	uintptr(pSecurityDescriptor),
	uintptr(pOwner),
	uintptr(lpbOwnerDefaulted),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetSecurityDescriptorOwner(
  pSecurityDescriptor: THandle;   // PSECURITY_DESCRIPTOR
  pOwner: Pointer;   // PSID* out
  lpbOwnerDefaulted: Pointer   // BOOL* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'GetSecurityDescriptorOwner';
result := DllCall("ADVAPI32\GetSecurityDescriptorOwner"
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "Ptr", pOwner   ; PSID* out
    , "Ptr", lpbOwnerDefaulted   ; BOOL* out
    , "Int")   ; return: BOOL
●GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted) = DLL("ADVAPI32.dll", "bool GetSecurityDescriptorOwner(void*, void*, void*)")
# 呼び出し: GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# pOwner : PSID* out -> "void*"
# lpbOwnerDefaulted : BOOL* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。