Win32 API 日本語リファレンス
ホームSystem.Threading › AddIntegrityLabelToBoundaryDescriptor

AddIntegrityLabelToBoundaryDescriptor

関数
境界記述子に整合性ラベルのSIDを追加する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows 7 以降

シグネチャ

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

BOOL AddIntegrityLabelToBoundaryDescriptor(
    HANDLE* BoundaryDescriptor,
    PSID IntegrityLabel
);

パラメーター

名前方向説明
BoundaryDescriptorHANDLE*inout境界記述子へのハンドル。このハンドルは CreateBoundaryDescriptor 関数によって返されます。
IntegrityLabelPSIDin

名前空間の必須整合性レベルを表す SID 構造体へのポインター。SID を作成するには、次のいずれかの RID 値を使用します。

SECURITY_MANDATORY_UNTRUSTED_RID SECURITY_MANDATORY_LOW_RID SECURITY_MANDATORY_MEDIUM_RID SECURITY_MANDATORY_SYSTEM_RID SECURITY_MANDATORY_PROTECTED_PROCESS_RID 詳細については、Well-Known SIDs を参照してください。

戻り値の型: BOOL

公式ドキュメント

指定された境界記述子に、新しい必須のセキュリティ識別子 (SID) を追加します。

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

プロセスは、現在のプロセスの整合性レベル以下の整合性レベルでのみプライベート名前空間を作成できます。したがって、高整合性レベルのプロセスは、高、中、または低整合性レベルの名前空間を作成できます。中整合性レベルのプロセスは、中または低整合性レベルの名前空間のみを作成できます。

プロセスは通常、より低い整合性レベルのプロセスによるスクワッティング攻撃から保護するために、プロセスと同じ整合性レベルの名前空間を指定します。

名前空間を誰が開けるかは、作成者が名前空間に設定するセキュリティ記述子によって決まります。そのため、名前空間のセキュリティ記述子が許可していれば、低または中整合性レベルのプロセスに高整合性レベルの名前空間を開く権限を与えることもできます。

この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を 0x0601 以降として定義します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL AddIntegrityLabelToBoundaryDescriptor(
    HANDLE* BoundaryDescriptor,
    PSID IntegrityLabel
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AddIntegrityLabelToBoundaryDescriptor(
    IntPtr BoundaryDescriptor,   // HANDLE* in/out
    IntPtr IntegrityLabel   // PSID
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AddIntegrityLabelToBoundaryDescriptor(
    BoundaryDescriptor As IntPtr,   ' HANDLE* in/out
    IntegrityLabel As IntPtr   ' PSID
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' BoundaryDescriptor : HANDLE* in/out
' IntegrityLabel : PSID
Declare PtrSafe Function AddIntegrityLabelToBoundaryDescriptor Lib "kernel32" ( _
    ByVal BoundaryDescriptor As LongPtr, _
    ByVal IntegrityLabel As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AddIntegrityLabelToBoundaryDescriptor = ctypes.windll.kernel32.AddIntegrityLabelToBoundaryDescriptor
AddIntegrityLabelToBoundaryDescriptor.restype = wintypes.BOOL
AddIntegrityLabelToBoundaryDescriptor.argtypes = [
    ctypes.c_void_p,  # BoundaryDescriptor : HANDLE* in/out
    wintypes.HANDLE,  # IntegrityLabel : PSID
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procAddIntegrityLabelToBoundaryDescriptor = kernel32.NewProc("AddIntegrityLabelToBoundaryDescriptor")
)

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

extern "kernel32" fn AddIntegrityLabelToBoundaryDescriptor(
    BoundaryDescriptor: ?*anyopaque, // HANDLE* in/out
    IntegrityLabel: ?*anyopaque // PSID
) callconv(std.os.windows.WINAPI) i32;
proc AddIntegrityLabelToBoundaryDescriptor(
    BoundaryDescriptor: pointer,  # HANDLE* in/out
    IntegrityLabel: pointer  # PSID
): int32 {.importc: "AddIntegrityLabelToBoundaryDescriptor", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int AddIntegrityLabelToBoundaryDescriptor(
    void* BoundaryDescriptor,   // HANDLE* in/out
    void* IntegrityLabel   // PSID
);
ccall((:AddIntegrityLabelToBoundaryDescriptor, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}),
      BoundaryDescriptor, IntegrityLabel)
# BoundaryDescriptor : HANDLE* in/out -> Ptr{Cvoid}
# IntegrityLabel : PSID -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t AddIntegrityLabelToBoundaryDescriptor(
    void* BoundaryDescriptor,
    void* IntegrityLabel);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.AddIntegrityLabelToBoundaryDescriptor(BoundaryDescriptor, IntegrityLabel)
-- BoundaryDescriptor : HANDLE* in/out
-- IntegrityLabel : PSID
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const AddIntegrityLabelToBoundaryDescriptor = lib.func('__stdcall', 'AddIntegrityLabelToBoundaryDescriptor', 'int32_t', ['void *', 'void *']);
// AddIntegrityLabelToBoundaryDescriptor(BoundaryDescriptor, IntegrityLabel)
// BoundaryDescriptor : HANDLE* in/out -> 'void *'
// IntegrityLabel : PSID -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  AddIntegrityLabelToBoundaryDescriptor: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.AddIntegrityLabelToBoundaryDescriptor(BoundaryDescriptor, IntegrityLabel)
// BoundaryDescriptor : HANDLE* in/out -> "pointer"
// IntegrityLabel : PSID -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t AddIntegrityLabelToBoundaryDescriptor(
    void* BoundaryDescriptor,
    void* IntegrityLabel);
C, "KERNEL32.dll");
// $ffi->AddIntegrityLabelToBoundaryDescriptor(BoundaryDescriptor, IntegrityLabel);
// BoundaryDescriptor : HANDLE* in/out
// IntegrityLabel : PSID
// 構造体/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 Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean AddIntegrityLabelToBoundaryDescriptor(
        Pointer BoundaryDescriptor,   // HANDLE* in/out
        Pointer IntegrityLabel   // PSID
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun AddIntegrityLabelToBoundaryDescriptor = AddIntegrityLabelToBoundaryDescriptor(
    BoundaryDescriptor : Void*,   # HANDLE* in/out
    IntegrityLabel : Void*   # PSID
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef AddIntegrityLabelToBoundaryDescriptorNative = Int32 Function(Pointer<Void>, Pointer<Void>);
typedef AddIntegrityLabelToBoundaryDescriptorDart = int Function(Pointer<Void>, Pointer<Void>);
final AddIntegrityLabelToBoundaryDescriptor = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<AddIntegrityLabelToBoundaryDescriptorNative, AddIntegrityLabelToBoundaryDescriptorDart>('AddIntegrityLabelToBoundaryDescriptor');
// BoundaryDescriptor : HANDLE* in/out -> Pointer<Void>
// IntegrityLabel : PSID -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function AddIntegrityLabelToBoundaryDescriptor(
  BoundaryDescriptor: Pointer;   // HANDLE* in/out
  IntegrityLabel: THandle   // PSID
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'AddIntegrityLabelToBoundaryDescriptor';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "AddIntegrityLabelToBoundaryDescriptor"
  c_AddIntegrityLabelToBoundaryDescriptor :: Ptr () -> Ptr () -> IO CInt
-- BoundaryDescriptor : HANDLE* in/out -> Ptr ()
-- IntegrityLabel : PSID -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let addintegritylabeltoboundarydescriptor =
  foreign "AddIntegrityLabelToBoundaryDescriptor"
    ((ptr void) @-> (ptr void) @-> returning int32_t)
(* BoundaryDescriptor : HANDLE* in/out -> (ptr void) *)
(* IntegrityLabel : PSID -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("AddIntegrityLabelToBoundaryDescriptor" add-integrity-label-to-boundary-descriptor :convention :stdcall) :int32
  (boundary-descriptor :pointer)   ; HANDLE* in/out
  (integrity-label :pointer))   ; PSID
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $AddIntegrityLabelToBoundaryDescriptor = Win32::API::More->new('KERNEL32',
    'BOOL AddIntegrityLabelToBoundaryDescriptor(HANDLE BoundaryDescriptor, HANDLE IntegrityLabel)');
# my $ret = $AddIntegrityLabelToBoundaryDescriptor->Call($BoundaryDescriptor, $IntegrityLabel);
# BoundaryDescriptor : HANDLE* in/out -> HANDLE
# IntegrityLabel : PSID -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目