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