GetSecurityDescriptorOwner
関数セキュリティ記述子から所有者SIDを取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL GetSecurityDescriptorOwner(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
PSID* pOwner,
BOOL* lpbOwnerDefaulted
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | in | 関数が所有者情報を取得する対象の SECURITY_DESCRIPTOR 構造体へのポインターです。 |
| pOwner | PSID* | out | 関数が戻るときに所有者を識別する セキュリティ識別子 (SID) へのポインターへのポインターです。セキュリティ記述子に所有者が含まれていない場合、関数は pOwner が指すポインターを NULL に設定し、残りの出力パラメーター lpbOwnerDefaulted を無視します。セキュリティ記述子に所有者が含まれている場合、関数は pOwner が指すポインターをセキュリティ記述子の所有者 SID のアドレスに設定し、lpbOwnerDefaulted が指す変数に有効な値を設定します。 |
| lpbOwnerDefaulted | BOOL* | out | 関数が戻るときに、 SECURITY_DESCRIPTOR_CONTROL 構造体の SE_OWNER_DEFAULTED フラグの値に設定されるフラグへのポインターです。pOwner パラメーターが指す変数に格納された値が NULL の場合、値は設定されません。 |
戻り値の型: BOOL
公式ドキュメント
セキュリティ記述子から所有者情報を取得します。
戻り値
関数が成功すると、0 以外の値を返します。
関数が失敗すると、0 を返します。拡張エラー情報を取得するには、 GetLastError を呼び出します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 bool 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 Boolean ' BOOL* out
) As <MarshalAs(UnmanagedType.Bool)> 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 bool 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, varptr(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, var ; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr" ; pOwner : PSID* out -> "sptr" ; lpbOwnerDefaulted : BOOL* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" sptr, sptr, sptr ; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, varptr(lpbOwnerDefaulted)) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr" ; pOwner : PSID* out -> "sptr" ; lpbOwnerDefaulted : BOOL* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pOwner, BOOL* lpbOwnerDefaulted) #uselib "ADVAPI32.dll" #cfunc global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" intptr, intptr, var ; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr" ; pOwner : PSID* out -> "intptr" ; lpbOwnerDefaulted : BOOL* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID* pOwner, BOOL* lpbOwnerDefaulted) #uselib "ADVAPI32.dll" #cfunc global GetSecurityDescriptorOwner "GetSecurityDescriptorOwner" intptr, intptr, intptr ; res = GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, varptr(lpbOwnerDefaulted)) ; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr" ; pOwner : PSID* out -> "intptr" ; lpbOwnerDefaulted : BOOL* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
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 // BOOLfunction 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)。const std = @import("std");
extern "advapi32" fn GetSecurityDescriptorOwner(
pSecurityDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR
pOwner: ?*anyopaque, // PSID* out
lpbOwnerDefaulted: [*c]i32 // BOOL* out
) callconv(std.os.windows.WINAPI) i32;proc GetSecurityDescriptorOwner(
pSecurityDescriptor: pointer, # PSECURITY_DESCRIPTOR
pOwner: pointer, # PSID* out
lpbOwnerDefaulted: ptr int32 # BOOL* out
): int32 {.importc: "GetSecurityDescriptorOwner", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int GetSecurityDescriptorOwner(
void* pSecurityDescriptor, // PSECURITY_DESCRIPTOR
void* pOwner, // PSID* out
int* lpbOwnerDefaulted // BOOL* out
);ccall((:GetSecurityDescriptorOwner, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Int32}),
pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr{Cvoid}
# pOwner : PSID* out -> Ptr{Cvoid}
# lpbOwnerDefaulted : BOOL* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetSecurityDescriptorOwner(
void* pSecurityDescriptor,
void* pOwner,
int32_t* lpbOwnerDefaulted);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR
-- pOwner : PSID* out
-- lpbOwnerDefaulted : BOOL* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetSecurityDescriptorOwner = lib.func('__stdcall', 'GetSecurityDescriptorOwner', 'int32_t', ['void *', 'void *', 'int32_t *']);
// GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> 'void *'
// pOwner : PSID* out -> 'void *'
// lpbOwnerDefaulted : BOOL* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
GetSecurityDescriptorOwner: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "pointer"
// pOwner : PSID* out -> "pointer"
// lpbOwnerDefaulted : BOOL* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetSecurityDescriptorOwner(
void* pSecurityDescriptor,
void* pOwner,
int32_t* lpbOwnerDefaulted);
C, "ADVAPI32.dll");
// $ffi->GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted);
// pSecurityDescriptor : PSECURITY_DESCRIPTOR
// pOwner : PSID* out
// lpbOwnerDefaulted : BOOL* 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 Advapi32 extends StdCallLibrary {
Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
boolean GetSecurityDescriptorOwner(
Pointer pSecurityDescriptor, // PSECURITY_DESCRIPTOR
Pointer pOwner, // PSID* out
IntByReference lpbOwnerDefaulted // BOOL* out
);
}@[Link("advapi32")]
lib LibADVAPI32
fun GetSecurityDescriptorOwner = GetSecurityDescriptorOwner(
pSecurityDescriptor : Void*, # PSECURITY_DESCRIPTOR
pOwner : Void*, # PSID* out
lpbOwnerDefaulted : Int32* # BOOL* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetSecurityDescriptorOwnerNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Int32>);
typedef GetSecurityDescriptorOwnerDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Int32>);
final GetSecurityDescriptorOwner = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<GetSecurityDescriptorOwnerNative, GetSecurityDescriptorOwnerDart>('GetSecurityDescriptorOwner');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// pOwner : PSID* out -> Pointer<Void>
// lpbOwnerDefaulted : BOOL* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetSecurityDescriptorOwner(
pSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR
pOwner: Pointer; // PSID* out
lpbOwnerDefaulted: Pointer // BOOL* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'GetSecurityDescriptorOwner';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetSecurityDescriptorOwner"
c_GetSecurityDescriptorOwner :: Ptr () -> Ptr () -> Ptr CInt -> IO CInt
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- pOwner : PSID* out -> Ptr ()
-- lpbOwnerDefaulted : BOOL* out -> Ptr CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getsecuritydescriptorowner =
foreign "GetSecurityDescriptorOwner"
((ptr void) @-> (ptr void) @-> (ptr int32_t) @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* pOwner : PSID* out -> (ptr void) *)
(* lpbOwnerDefaulted : BOOL* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("GetSecurityDescriptorOwner" get-security-descriptor-owner :convention :stdcall) :int32
(p-security-descriptor :pointer) ; PSECURITY_DESCRIPTOR
(p-owner :pointer) ; PSID* out
(lpb-owner-defaulted :pointer)) ; BOOL* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetSecurityDescriptorOwner = Win32::API::More->new('ADVAPI32',
'BOOL GetSecurityDescriptorOwner(HANDLE pSecurityDescriptor, HANDLE pOwner, LPVOID lpbOwnerDefaulted)');
# my $ret = $GetSecurityDescriptorOwner->Call($pSecurityDescriptor, $pOwner, $lpbOwnerDefaulted);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# pOwner : PSID* out -> HANDLE
# lpbOwnerDefaulted : BOOL* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSecurityDescriptorControl — セキュリティ記述子の制御フラグと改訂を取得する。
- f GetSecurityDescriptorDacl — セキュリティ記述子からDACLを取得する。
- f GetSecurityDescriptorGroup — セキュリティ記述子からプライマリグループSIDを取得する。
- f GetSecurityDescriptorLength — セキュリティ記述子のバイト長を取得する。
- f GetSecurityDescriptorSacl — セキュリティ記述子からSACLを取得する。
- f IsValidSecurityDescriptor — セキュリティ記述子が有効かどうかを検証する。
- s SECURITY_DESCRIPTOR
- f SetSecurityDescriptorOwner — セキュリティ記述子の所有者SIDを設定する。