SetSecurityDescriptorOwner
関数セキュリティ記述子の所有者SIDを設定する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL SetSecurityDescriptorOwner(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
PSID pOwner, // optional
BOOL bOwnerDefaulted
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | inout | この関数によって所有者が設定される SECURITY_DESCRIPTOR 構造体へのポインターです。この関数は既存の所有者を新しい所有者で置き換えます。 |
| pOwner | PSID | inoptional | セキュリティ記述子の新しいプライマリ所有者を表す SID 構造体へのポインターです。SID 構造体はセキュリティ記述子にコピーされるのではなく、参照されます。このパラメーターが NULL の場合、関数はセキュリティ記述子の所有者情報をクリアします。これにより、セキュリティ記述子は所有者を持たないものとしてマークされます。 |
| bOwnerDefaulted | BOOL | in | 所有者情報が既定のメカニズムによって導出されたものかどうかを示します。この値が TRUE の場合、それは既定の情報です。関数はこの値を SECURITY_DESCRIPTOR_CONTROL 構造体内の SE_OWNER_DEFAULTED フラグとして格納します。このパラメーターがゼロの場合、SE_OWNER_DEFAULTED フラグはクリアされます。 |
戻り値の型: 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 SetSecurityDescriptorOwner(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
PSID pOwner, // optional
BOOL bOwnerDefaulted
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetSecurityDescriptorOwner(
IntPtr pSecurityDescriptor, // PSECURITY_DESCRIPTOR in/out
IntPtr pOwner, // PSID optional
bool bOwnerDefaulted // BOOL
);<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetSecurityDescriptorOwner(
pSecurityDescriptor As IntPtr, ' PSECURITY_DESCRIPTOR in/out
pOwner As IntPtr, ' PSID optional
bOwnerDefaulted As Boolean ' BOOL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
' pOwner : PSID optional
' bOwnerDefaulted : BOOL
Declare PtrSafe Function SetSecurityDescriptorOwner Lib "advapi32" ( _
ByVal pSecurityDescriptor As LongPtr, _
ByVal pOwner As LongPtr, _
ByVal bOwnerDefaulted As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetSecurityDescriptorOwner = ctypes.windll.advapi32.SetSecurityDescriptorOwner
SetSecurityDescriptorOwner.restype = wintypes.BOOL
SetSecurityDescriptorOwner.argtypes = [
wintypes.HANDLE, # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
wintypes.HANDLE, # pOwner : PSID optional
wintypes.BOOL, # bOwnerDefaulted : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
SetSecurityDescriptorOwner = Fiddle::Function.new(
lib['SetSecurityDescriptorOwner'],
[
Fiddle::TYPE_VOIDP, # pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
Fiddle::TYPE_VOIDP, # pOwner : PSID optional
Fiddle::TYPE_INT, # bOwnerDefaulted : BOOL
],
Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn SetSecurityDescriptorOwner(
pSecurityDescriptor: *mut core::ffi::c_void, // PSECURITY_DESCRIPTOR in/out
pOwner: *mut core::ffi::c_void, // PSID optional
bOwnerDefaulted: i32 // BOOL
) -> 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 SetSecurityDescriptorOwner(IntPtr pSecurityDescriptor, IntPtr pOwner, bool bOwnerDefaulted);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_SetSecurityDescriptorOwner' -Namespace Win32 -PassThru
# $api::SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)#uselib "ADVAPI32.dll"
#func global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" sptr, sptr, sptr
; SetSecurityDescriptorOwner pSecurityDescriptor, pOwner, bOwnerDefaulted ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pOwner : PSID optional -> "sptr"
; bOwnerDefaulted : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" sptr, sptr, int
; res = SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "sptr"
; pOwner : PSID optional -> "sptr"
; bOwnerDefaulted : BOOL -> "int"; BOOL SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
#uselib "ADVAPI32.dll"
#cfunc global SetSecurityDescriptorOwner "SetSecurityDescriptorOwner" intptr, intptr, int
; res = SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "intptr"
; pOwner : PSID optional -> "intptr"
; bOwnerDefaulted : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procSetSecurityDescriptorOwner = advapi32.NewProc("SetSecurityDescriptorOwner")
)
// pSecurityDescriptor (PSECURITY_DESCRIPTOR in/out), pOwner (PSID optional), bOwnerDefaulted (BOOL)
r1, _, err := procSetSecurityDescriptorOwner.Call(
uintptr(pSecurityDescriptor),
uintptr(pOwner),
uintptr(bOwnerDefaulted),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetSecurityDescriptorOwner(
pSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR in/out
pOwner: THandle; // PSID optional
bOwnerDefaulted: BOOL // BOOL
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SetSecurityDescriptorOwner';result := DllCall("ADVAPI32\SetSecurityDescriptorOwner"
, "Ptr", pSecurityDescriptor ; PSECURITY_DESCRIPTOR in/out
, "Ptr", pOwner ; PSID optional
, "Int", bOwnerDefaulted ; BOOL
, "Int") ; return: BOOL●SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted) = DLL("ADVAPI32.dll", "bool SetSecurityDescriptorOwner(void*, void*, bool)")
# 呼び出し: SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "void*"
# pOwner : PSID optional -> "void*"
# bOwnerDefaulted : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn SetSecurityDescriptorOwner(
pSecurityDescriptor: ?*anyopaque, // PSECURITY_DESCRIPTOR in/out
pOwner: ?*anyopaque, // PSID optional
bOwnerDefaulted: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc SetSecurityDescriptorOwner(
pSecurityDescriptor: pointer, # PSECURITY_DESCRIPTOR in/out
pOwner: pointer, # PSID optional
bOwnerDefaulted: int32 # BOOL
): int32 {.importc: "SetSecurityDescriptorOwner", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int SetSecurityDescriptorOwner(
void* pSecurityDescriptor, // PSECURITY_DESCRIPTOR in/out
void* pOwner, // PSID optional
int bOwnerDefaulted // BOOL
);ccall((:SetSecurityDescriptorOwner, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Int32),
pSecurityDescriptor, pOwner, bOwnerDefaulted)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr{Cvoid}
# pOwner : PSID optional -> Ptr{Cvoid}
# bOwnerDefaulted : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetSecurityDescriptorOwner(
void* pSecurityDescriptor,
void* pOwner,
int32_t bOwnerDefaulted);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
-- pOwner : PSID optional
-- bOwnerDefaulted : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const SetSecurityDescriptorOwner = lib.func('__stdcall', 'SetSecurityDescriptorOwner', 'int32_t', ['void *', 'void *', 'int32_t']);
// SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> 'void *'
// pOwner : PSID optional -> 'void *'
// bOwnerDefaulted : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
SetSecurityDescriptorOwner: { parameters: ["pointer", "pointer", "i32"], result: "i32" },
});
// lib.symbols.SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> "pointer"
// pOwner : PSID optional -> "pointer"
// bOwnerDefaulted : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetSecurityDescriptorOwner(
void* pSecurityDescriptor,
void* pOwner,
int32_t bOwnerDefaulted);
C, "ADVAPI32.dll");
// $ffi->SetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, bOwnerDefaulted);
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out
// pOwner : PSID optional
// bOwnerDefaulted : BOOL
// 構造体/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 SetSecurityDescriptorOwner(
Pointer pSecurityDescriptor, // PSECURITY_DESCRIPTOR in/out
Pointer pOwner, // PSID optional
boolean bOwnerDefaulted // BOOL
);
}@[Link("advapi32")]
lib LibADVAPI32
fun SetSecurityDescriptorOwner = SetSecurityDescriptorOwner(
pSecurityDescriptor : Void*, # PSECURITY_DESCRIPTOR in/out
pOwner : Void*, # PSID optional
bOwnerDefaulted : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetSecurityDescriptorOwnerNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32);
typedef SetSecurityDescriptorOwnerDart = int Function(Pointer<Void>, Pointer<Void>, int);
final SetSecurityDescriptorOwner = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<SetSecurityDescriptorOwnerNative, SetSecurityDescriptorOwnerDart>('SetSecurityDescriptorOwner');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Pointer<Void>
// pOwner : PSID optional -> Pointer<Void>
// bOwnerDefaulted : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetSecurityDescriptorOwner(
pSecurityDescriptor: THandle; // PSECURITY_DESCRIPTOR in/out
pOwner: THandle; // PSID optional
bOwnerDefaulted: BOOL // BOOL
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'SetSecurityDescriptorOwner';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetSecurityDescriptorOwner"
c_SetSecurityDescriptorOwner :: Ptr () -> Ptr () -> CInt -> IO CInt
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> Ptr ()
-- pOwner : PSID optional -> Ptr ()
-- bOwnerDefaulted : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setsecuritydescriptorowner =
foreign "SetSecurityDescriptorOwner"
((ptr void) @-> (ptr void) @-> int32_t @-> returning int32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> (ptr void) *)
(* pOwner : PSID optional -> (ptr void) *)
(* bOwnerDefaulted : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("SetSecurityDescriptorOwner" set-security-descriptor-owner :convention :stdcall) :int32
(p-security-descriptor :pointer) ; PSECURITY_DESCRIPTOR in/out
(p-owner :pointer) ; PSID optional
(b-owner-defaulted :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetSecurityDescriptorOwner = Win32::API::More->new('ADVAPI32',
'BOOL SetSecurityDescriptorOwner(HANDLE pSecurityDescriptor, HANDLE pOwner, BOOL bOwnerDefaulted)');
# my $ret = $SetSecurityDescriptorOwner->Call($pSecurityDescriptor, $pOwner, $bOwnerDefaulted);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR in/out -> HANDLE
# pOwner : PSID optional -> HANDLE
# bOwnerDefaulted : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSecurityDescriptorOwner — セキュリティ記述子から所有者SIDを取得する。
- f InitializeSecurityDescriptor — 新しいセキュリティ記述子を初期化する。
- f IsValidSecurityDescriptor — セキュリティ記述子が有効かどうかを検証する。
- s SECURITY_DESCRIPTOR
- s SID
- f SetSecurityDescriptorDacl — セキュリティ記述子にDACL(任意アクセス制御リスト)を設定する。
- f SetSecurityDescriptorGroup — セキュリティ記述子のプライマリグループSIDを設定する。
- f SetSecurityDescriptorSacl — セキュリティ記述子にSACL(システムアクセス制御リスト)を設定する。