GetSecurityDescriptorLength
関数セキュリティ記述子のバイト長を取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
DWORD GetSecurityDescriptorLength(
PSECURITY_DESCRIPTOR pSecurityDescriptor
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pSecurityDescriptor | PSECURITY_DESCRIPTOR | in | 関数が長さを返す対象の SECURITY_DESCRIPTOR 構造体へのポインターです。このポインターは有効であることが前提とされます。 |
戻り値の型: DWORD
公式ドキュメント
構造的に有効なセキュリティ記述子の長さをバイト単位で返します。この長さには、関連するすべての構造体の長さが含まれます。
戻り値
関数が成功した場合、SECURITY_DESCRIPTOR 構造体の長さをバイト単位で返します。
SECURITY_DESCRIPTOR 構造体が有効でない場合、戻り値は未定義です。
解説(Remarks)
セキュリティ記述子の最小の長さは SECURITY_DESCRIPTOR_MIN_LENGTH です。この長さのセキュリティ記述子には、 セキュリティ識別子(SID)や アクセス制御リスト(ACL)は関連付けられていません。
出典・ライセンス: 上記「公式ドキュメント」の内容は 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>
DWORD GetSecurityDescriptorLength(
PSECURITY_DESCRIPTOR pSecurityDescriptor
);[DllImport("ADVAPI32.dll", ExactSpelling = true)]
static extern uint GetSecurityDescriptorLength(
IntPtr pSecurityDescriptor // PSECURITY_DESCRIPTOR
);<DllImport("ADVAPI32.dll", ExactSpelling:=True)>
Public Shared Function GetSecurityDescriptorLength(
pSecurityDescriptor As IntPtr ' PSECURITY_DESCRIPTOR
) As UInteger
End Function' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function GetSecurityDescriptorLength Lib "advapi32" ( _
ByVal pSecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetSecurityDescriptorLength = ctypes.windll.advapi32.GetSecurityDescriptorLength
GetSecurityDescriptorLength.restype = wintypes.DWORD
GetSecurityDescriptorLength.argtypes = [
wintypes.HANDLE, # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('ADVAPI32.dll')
GetSecurityDescriptorLength = Fiddle::Function.new(
lib['GetSecurityDescriptorLength'],
[
Fiddle::TYPE_VOIDP, # pSecurityDescriptor : PSECURITY_DESCRIPTOR
],
-Fiddle::TYPE_INT)#[link(name = "advapi32")]
extern "system" {
fn GetSecurityDescriptorLength(
pSecurityDescriptor: *mut core::ffi::c_void // PSECURITY_DESCRIPTOR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("ADVAPI32.dll")]
public static extern uint GetSecurityDescriptorLength(IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetSecurityDescriptorLength' -Namespace Win32 -PassThru
# $api::GetSecurityDescriptorLength(pSecurityDescriptor)#uselib "ADVAPI32.dll"
#func global GetSecurityDescriptorLength "GetSecurityDescriptorLength" sptr
; GetSecurityDescriptorLength pSecurityDescriptor ; 戻り値は stat
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorLength "GetSecurityDescriptorLength" sptr
; res = GetSecurityDescriptorLength(pSecurityDescriptor)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"; DWORD GetSecurityDescriptorLength(PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "ADVAPI32.dll"
#cfunc global GetSecurityDescriptorLength "GetSecurityDescriptorLength" intptr
; res = GetSecurityDescriptorLength(pSecurityDescriptor)
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
procGetSecurityDescriptorLength = advapi32.NewProc("GetSecurityDescriptorLength")
)
// pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procGetSecurityDescriptorLength.Call(
uintptr(pSecurityDescriptor),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetSecurityDescriptorLength(
pSecurityDescriptor: THandle // PSECURITY_DESCRIPTOR
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'GetSecurityDescriptorLength';result := DllCall("ADVAPI32\GetSecurityDescriptorLength"
, "Ptr", pSecurityDescriptor ; PSECURITY_DESCRIPTOR
, "UInt") ; return: DWORD●GetSecurityDescriptorLength(pSecurityDescriptor) = DLL("ADVAPI32.dll", "dword GetSecurityDescriptorLength(void*)")
# 呼び出し: GetSecurityDescriptorLength(pSecurityDescriptor)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "advapi32" fn GetSecurityDescriptorLength(
pSecurityDescriptor: ?*anyopaque // PSECURITY_DESCRIPTOR
) callconv(std.os.windows.WINAPI) u32;proc GetSecurityDescriptorLength(
pSecurityDescriptor: pointer # PSECURITY_DESCRIPTOR
): uint32 {.importc: "GetSecurityDescriptorLength", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
uint GetSecurityDescriptorLength(
void* pSecurityDescriptor // PSECURITY_DESCRIPTOR
);ccall((:GetSecurityDescriptorLength, "ADVAPI32.dll"), stdcall, UInt32,
(Ptr{Cvoid},),
pSecurityDescriptor)
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetSecurityDescriptorLength(
void* pSecurityDescriptor);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetSecurityDescriptorLength(pSecurityDescriptor)
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetSecurityDescriptorLength = lib.func('__stdcall', 'GetSecurityDescriptorLength', 'uint32_t', ['void *']);
// GetSecurityDescriptorLength(pSecurityDescriptor)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
GetSecurityDescriptorLength: { parameters: ["pointer"], result: "u32" },
});
// lib.symbols.GetSecurityDescriptorLength(pSecurityDescriptor)
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetSecurityDescriptorLength(
void* pSecurityDescriptor);
C, "ADVAPI32.dll");
// $ffi->GetSecurityDescriptorLength(pSecurityDescriptor);
// pSecurityDescriptor : PSECURITY_DESCRIPTOR
// 構造体/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);
int GetSecurityDescriptorLength(
Pointer pSecurityDescriptor // PSECURITY_DESCRIPTOR
);
}@[Link("advapi32")]
lib LibADVAPI32
fun GetSecurityDescriptorLength = GetSecurityDescriptorLength(
pSecurityDescriptor : Void* # PSECURITY_DESCRIPTOR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetSecurityDescriptorLengthNative = Uint32 Function(Pointer<Void>);
typedef GetSecurityDescriptorLengthDart = int Function(Pointer<Void>);
final GetSecurityDescriptorLength = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<GetSecurityDescriptorLengthNative, GetSecurityDescriptorLengthDart>('GetSecurityDescriptorLength');
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetSecurityDescriptorLength(
pSecurityDescriptor: THandle // PSECURITY_DESCRIPTOR
): DWORD; stdcall;
external 'ADVAPI32.dll' name 'GetSecurityDescriptorLength';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetSecurityDescriptorLength"
c_GetSecurityDescriptorLength :: Ptr () -> IO Word32
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getsecuritydescriptorlength =
foreign "GetSecurityDescriptorLength"
((ptr void) @-> returning uint32_t)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)
(cffi:defcfun ("GetSecurityDescriptorLength" get-security-descriptor-length :convention :stdcall) :uint32
(p-security-descriptor :pointer)) ; PSECURITY_DESCRIPTOR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetSecurityDescriptorLength = Win32::API::More->new('ADVAPI32',
'DWORD GetSecurityDescriptorLength(HANDLE pSecurityDescriptor)');
# my $ret = $GetSecurityDescriptorLength->Call($pSecurityDescriptor);
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetSecurityDescriptorControl — セキュリティ記述子の制御フラグと改訂を取得する。
- f GetSecurityDescriptorDacl — セキュリティ記述子からDACLを取得する。
- f GetSecurityDescriptorGroup — セキュリティ記述子からプライマリグループSIDを取得する。
- f GetSecurityDescriptorOwner — セキュリティ記述子から所有者SIDを取得する。
- f GetSecurityDescriptorSacl — セキュリティ記述子からSACLを取得する。
- f IsValidSecurityDescriptor — セキュリティ記述子が有効かどうかを検証する。
- s SECURITY_DESCRIPTOR