Win32 API 日本語リファレンス
ホームStorage.DistributedFileSystem › NetDfsSetSecurity

NetDfsSetSecurity

関数
指定DFSエントリのセキュリティ記述子を設定する。
DLLNETAPI32.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD NetDfsSetSecurity(
    LPWSTR DfsEntryPath,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);

パラメーター

名前方向説明
DfsEntryPathLPWSTRinセキュリティ記述子を設定するDFSエントリのパスを示すワイド文字列。
SecurityInformationDWORDin設定するセキュリティ情報の種別を示すビットフラグ。
pSecurityDescriptorPSECURITY_DESCRIPTORin設定するセキュリティ記述子へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD NetDfsSetSecurity(
    LPWSTR DfsEntryPath,
    DWORD SecurityInformation,
    PSECURITY_DESCRIPTOR pSecurityDescriptor
);
[DllImport("NETAPI32.dll", ExactSpelling = true)]
static extern uint NetDfsSetSecurity(
    [MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath,   // LPWSTR
    uint SecurityInformation,   // DWORD
    IntPtr pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
<DllImport("NETAPI32.dll", ExactSpelling:=True)>
Public Shared Function NetDfsSetSecurity(
    <MarshalAs(UnmanagedType.LPWStr)> DfsEntryPath As String,   ' LPWSTR
    SecurityInformation As UInteger,   ' DWORD
    pSecurityDescriptor As IntPtr   ' PSECURITY_DESCRIPTOR
) As UInteger
End Function
' DfsEntryPath : LPWSTR
' SecurityInformation : DWORD
' pSecurityDescriptor : PSECURITY_DESCRIPTOR
Declare PtrSafe Function NetDfsSetSecurity Lib "netapi32" ( _
    ByVal DfsEntryPath As LongPtr, _
    ByVal SecurityInformation As Long, _
    ByVal pSecurityDescriptor As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NetDfsSetSecurity = ctypes.windll.netapi32.NetDfsSetSecurity
NetDfsSetSecurity.restype = wintypes.DWORD
NetDfsSetSecurity.argtypes = [
    wintypes.LPCWSTR,  # DfsEntryPath : LPWSTR
    wintypes.DWORD,  # SecurityInformation : DWORD
    wintypes.HANDLE,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('NETAPI32.dll')
NetDfsSetSecurity = Fiddle::Function.new(
  lib['NetDfsSetSecurity'],
  [
    Fiddle::TYPE_VOIDP,  # DfsEntryPath : LPWSTR
    -Fiddle::TYPE_INT,  # SecurityInformation : DWORD
    Fiddle::TYPE_VOIDP,  # pSecurityDescriptor : PSECURITY_DESCRIPTOR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "netapi32")]
extern "system" {
    fn NetDfsSetSecurity(
        DfsEntryPath: *mut u16,  // LPWSTR
        SecurityInformation: u32,  // DWORD
        pSecurityDescriptor: *mut core::ffi::c_void  // PSECURITY_DESCRIPTOR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("NETAPI32.dll")]
public static extern uint NetDfsSetSecurity([MarshalAs(UnmanagedType.LPWStr)] string DfsEntryPath, uint SecurityInformation, IntPtr pSecurityDescriptor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'NETAPI32_NetDfsSetSecurity' -Namespace Win32 -PassThru
# $api::NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
#uselib "NETAPI32.dll"
#func global NetDfsSetSecurity "NetDfsSetSecurity" sptr, sptr, sptr
; NetDfsSetSecurity DfsEntryPath, SecurityInformation, pSecurityDescriptor   ; 戻り値は stat
; DfsEntryPath : LPWSTR -> "sptr"
; SecurityInformation : DWORD -> "sptr"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "NETAPI32.dll"
#cfunc global NetDfsSetSecurity "NetDfsSetSecurity" wstr, int, sptr
; res = NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
; DfsEntryPath : LPWSTR -> "wstr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "sptr"
; DWORD NetDfsSetSecurity(LPWSTR DfsEntryPath, DWORD SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor)
#uselib "NETAPI32.dll"
#cfunc global NetDfsSetSecurity "NetDfsSetSecurity" wstr, int, intptr
; res = NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
; DfsEntryPath : LPWSTR -> "wstr"
; SecurityInformation : DWORD -> "int"
; pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	netapi32 = windows.NewLazySystemDLL("NETAPI32.dll")
	procNetDfsSetSecurity = netapi32.NewProc("NetDfsSetSecurity")
)

// DfsEntryPath (LPWSTR), SecurityInformation (DWORD), pSecurityDescriptor (PSECURITY_DESCRIPTOR)
r1, _, err := procNetDfsSetSecurity.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(DfsEntryPath))),
	uintptr(SecurityInformation),
	uintptr(pSecurityDescriptor),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function NetDfsSetSecurity(
  DfsEntryPath: PWideChar;   // LPWSTR
  SecurityInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsSetSecurity';
result := DllCall("NETAPI32\NetDfsSetSecurity"
    , "WStr", DfsEntryPath   ; LPWSTR
    , "UInt", SecurityInformation   ; DWORD
    , "Ptr", pSecurityDescriptor   ; PSECURITY_DESCRIPTOR
    , "UInt")   ; return: DWORD
●NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor) = DLL("NETAPI32.dll", "dword NetDfsSetSecurity(char*, dword, void*)")
# 呼び出し: NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
# DfsEntryPath : LPWSTR -> "char*"
# SecurityInformation : DWORD -> "dword"
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "netapi32" fn NetDfsSetSecurity(
    DfsEntryPath: [*c]const u16, // LPWSTR
    SecurityInformation: u32, // DWORD
    pSecurityDescriptor: ?*anyopaque // PSECURITY_DESCRIPTOR
) callconv(std.os.windows.WINAPI) u32;
proc NetDfsSetSecurity(
    DfsEntryPath: WideCString,  # LPWSTR
    SecurityInformation: uint32,  # DWORD
    pSecurityDescriptor: pointer  # PSECURITY_DESCRIPTOR
): uint32 {.importc: "NetDfsSetSecurity", stdcall, dynlib: "NETAPI32.dll".}
pragma(lib, "netapi32");
extern(Windows)
uint NetDfsSetSecurity(
    const(wchar)* DfsEntryPath,   // LPWSTR
    uint SecurityInformation,   // DWORD
    void* pSecurityDescriptor   // PSECURITY_DESCRIPTOR
);
ccall((:NetDfsSetSecurity, "NETAPI32.dll"), stdcall, UInt32,
      (Cwstring, UInt32, Ptr{Cvoid}),
      DfsEntryPath, SecurityInformation, pSecurityDescriptor)
# DfsEntryPath : LPWSTR -> Cwstring
# SecurityInformation : DWORD -> UInt32
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NetDfsSetSecurity(
    const uint16_t* DfsEntryPath,
    uint32_t SecurityInformation,
    void* pSecurityDescriptor);
]]
local netapi32 = ffi.load("netapi32")
-- netapi32.NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
-- DfsEntryPath : LPWSTR
-- SecurityInformation : DWORD
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('NETAPI32.dll');
const NetDfsSetSecurity = lib.func('__stdcall', 'NetDfsSetSecurity', 'uint32_t', ['str16', 'uint32_t', 'void *']);
// NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
// DfsEntryPath : LPWSTR -> 'str16'
// SecurityInformation : DWORD -> 'uint32_t'
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("NETAPI32.dll", {
  NetDfsSetSecurity: { parameters: ["buffer", "u32", "pointer"], result: "u32" },
});
// lib.symbols.NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor)
// DfsEntryPath : LPWSTR -> "buffer"
// SecurityInformation : DWORD -> "u32"
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NetDfsSetSecurity(
    const uint16_t* DfsEntryPath,
    uint32_t SecurityInformation,
    void* pSecurityDescriptor);
C, "NETAPI32.dll");
// $ffi->NetDfsSetSecurity(DfsEntryPath, SecurityInformation, pSecurityDescriptor);
// DfsEntryPath : LPWSTR
// SecurityInformation : DWORD
// 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 Netapi32 extends StdCallLibrary {
    Netapi32 INSTANCE = Native.load("netapi32", Netapi32.class);
    int NetDfsSetSecurity(
        WString DfsEntryPath,   // LPWSTR
        int SecurityInformation,   // DWORD
        Pointer pSecurityDescriptor   // PSECURITY_DESCRIPTOR
    );
}
@[Link("netapi32")]
lib LibNETAPI32
  fun NetDfsSetSecurity = NetDfsSetSecurity(
    DfsEntryPath : UInt16*,   # LPWSTR
    SecurityInformation : UInt32,   # DWORD
    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 NetDfsSetSecurityNative = Uint32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef NetDfsSetSecurityDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final NetDfsSetSecurity = DynamicLibrary.open('NETAPI32.dll')
    .lookupFunction<NetDfsSetSecurityNative, NetDfsSetSecurityDart>('NetDfsSetSecurity');
// DfsEntryPath : LPWSTR -> Pointer<Utf16>
// SecurityInformation : DWORD -> Uint32
// pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NetDfsSetSecurity(
  DfsEntryPath: PWideChar;   // LPWSTR
  SecurityInformation: DWORD;   // DWORD
  pSecurityDescriptor: THandle   // PSECURITY_DESCRIPTOR
): DWORD; stdcall;
  external 'NETAPI32.dll' name 'NetDfsSetSecurity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NetDfsSetSecurity"
  c_NetDfsSetSecurity :: CWString -> Word32 -> Ptr () -> IO Word32
-- DfsEntryPath : LPWSTR -> CWString
-- SecurityInformation : DWORD -> Word32
-- pSecurityDescriptor : PSECURITY_DESCRIPTOR -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let netdfssetsecurity =
  foreign "NetDfsSetSecurity"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* DfsEntryPath : LPWSTR -> (ptr uint16_t) *)
(* SecurityInformation : DWORD -> uint32_t *)
(* pSecurityDescriptor : PSECURITY_DESCRIPTOR -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library netapi32 (t "NETAPI32.dll"))
(cffi:use-foreign-library netapi32)

(cffi:defcfun ("NetDfsSetSecurity" net-dfs-set-security :convention :stdcall) :uint32
  (dfs-entry-path (:string :encoding :utf-16le))   ; LPWSTR
  (security-information :uint32)   ; DWORD
  (p-security-descriptor :pointer))   ; PSECURITY_DESCRIPTOR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NetDfsSetSecurity = Win32::API::More->new('NETAPI32',
    'DWORD NetDfsSetSecurity(LPCWSTR DfsEntryPath, DWORD SecurityInformation, HANDLE pSecurityDescriptor)');
# my $ret = $NetDfsSetSecurity->Call($DfsEntryPath, $SecurityInformation, $pSecurityDescriptor);
# DfsEntryPath : LPWSTR -> LPCWSTR
# SecurityInformation : DWORD -> DWORD
# pSecurityDescriptor : PSECURITY_DESCRIPTOR -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。