ホーム › System.Rpc › RpcBindingSetAuthInfoW
RpcBindingSetAuthInfoW
関数RPCバインディングハンドルに認証レベルや認証サービスなどの認証情報を設定する(Unicode版)。
シグネチャ
// RPCRT4.dll (Unicode / -W)
#include <windows.h>
RPC_STATUS RpcBindingSetAuthInfoW(
void* Binding,
LPWSTR ServerPrincName, // optional
DWORD AuthnLevel,
DWORD AuthnSvc,
void* AuthIdentity, // optional
DWORD AuthzSvc
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Binding | void* | in | 認証情報を設定する対象のクライアントバインディングハンドル。 |
| ServerPrincName | LPWSTR | inoptional | 期待するサーバープリンシパル名(Unicode)。相互認証に使用。NULL可。 |
| AuthnLevel | DWORD | in | 適用する認証レベル(RPC_C_AUTHN_LEVEL_*)を指定する。 |
| AuthnSvc | DWORD | in | 使用する認証サービス(RPC_C_AUTHN_*)を指定する。 |
| AuthIdentity | void* | inoptional | 認証に用いる資格情報構造体へのポインタ。NULLで現在のログオンコンテキスト。 |
| AuthzSvc | DWORD | in | 使用する認可サービス(RPC_C_AUTHZ_*)を指定する。 |
戻り値の型: RPC_STATUS
各言語での呼び出し定義
// RPCRT4.dll (Unicode / -W)
#include <windows.h>
RPC_STATUS RpcBindingSetAuthInfoW(
void* Binding,
LPWSTR ServerPrincName, // optional
DWORD AuthnLevel,
DWORD AuthnSvc,
void* AuthIdentity, // optional
DWORD AuthzSvc
);[DllImport("RPCRT4.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int RpcBindingSetAuthInfoW(
IntPtr Binding, // void*
[MarshalAs(UnmanagedType.LPWStr)] string ServerPrincName, // LPWSTR optional
uint AuthnLevel, // DWORD
uint AuthnSvc, // DWORD
IntPtr AuthIdentity, // void* optional
uint AuthzSvc // DWORD
);<DllImport("RPCRT4.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function RpcBindingSetAuthInfoW(
Binding As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> ServerPrincName As String, ' LPWSTR optional
AuthnLevel As UInteger, ' DWORD
AuthnSvc As UInteger, ' DWORD
AuthIdentity As IntPtr, ' void* optional
AuthzSvc As UInteger ' DWORD
) As Integer
End Function' Binding : void*
' ServerPrincName : LPWSTR optional
' AuthnLevel : DWORD
' AuthnSvc : DWORD
' AuthIdentity : void* optional
' AuthzSvc : DWORD
Declare PtrSafe Function RpcBindingSetAuthInfoW Lib "rpcrt4" ( _
ByVal Binding As LongPtr, _
ByVal ServerPrincName As LongPtr, _
ByVal AuthnLevel As Long, _
ByVal AuthnSvc As Long, _
ByVal AuthIdentity As LongPtr, _
ByVal AuthzSvc As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RpcBindingSetAuthInfoW = ctypes.windll.rpcrt4.RpcBindingSetAuthInfoW
RpcBindingSetAuthInfoW.restype = ctypes.c_int
RpcBindingSetAuthInfoW.argtypes = [
ctypes.POINTER(None), # Binding : void*
wintypes.LPCWSTR, # ServerPrincName : LPWSTR optional
wintypes.DWORD, # AuthnLevel : DWORD
wintypes.DWORD, # AuthnSvc : DWORD
ctypes.POINTER(None), # AuthIdentity : void* optional
wintypes.DWORD, # AuthzSvc : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('RPCRT4.dll')
RpcBindingSetAuthInfoW = Fiddle::Function.new(
lib['RpcBindingSetAuthInfoW'],
[
Fiddle::TYPE_VOIDP, # Binding : void*
Fiddle::TYPE_VOIDP, # ServerPrincName : LPWSTR optional
-Fiddle::TYPE_INT, # AuthnLevel : DWORD
-Fiddle::TYPE_INT, # AuthnSvc : DWORD
Fiddle::TYPE_VOIDP, # AuthIdentity : void* optional
-Fiddle::TYPE_INT, # AuthzSvc : DWORD
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "rpcrt4")]
extern "system" {
fn RpcBindingSetAuthInfoW(
Binding: *mut (), // void*
ServerPrincName: *mut u16, // LPWSTR optional
AuthnLevel: u32, // DWORD
AuthnSvc: u32, // DWORD
AuthIdentity: *mut (), // void* optional
AuthzSvc: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("RPCRT4.dll", CharSet = CharSet.Unicode)]
public static extern int RpcBindingSetAuthInfoW(IntPtr Binding, [MarshalAs(UnmanagedType.LPWStr)] string ServerPrincName, uint AuthnLevel, uint AuthnSvc, IntPtr AuthIdentity, uint AuthzSvc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'RPCRT4_RpcBindingSetAuthInfoW' -Namespace Win32 -PassThru
# $api::RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)#uselib "RPCRT4.dll"
#func global RpcBindingSetAuthInfoW "RpcBindingSetAuthInfoW" wptr, wptr, wptr, wptr, wptr, wptr
; RpcBindingSetAuthInfoW Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc ; 戻り値は stat
; Binding : void* -> "wptr"
; ServerPrincName : LPWSTR optional -> "wptr"
; AuthnLevel : DWORD -> "wptr"
; AuthnSvc : DWORD -> "wptr"
; AuthIdentity : void* optional -> "wptr"
; AuthzSvc : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "RPCRT4.dll"
#cfunc global RpcBindingSetAuthInfoW "RpcBindingSetAuthInfoW" sptr, wstr, int, int, sptr, int
; res = RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
; Binding : void* -> "sptr"
; ServerPrincName : LPWSTR optional -> "wstr"
; AuthnLevel : DWORD -> "int"
; AuthnSvc : DWORD -> "int"
; AuthIdentity : void* optional -> "sptr"
; AuthzSvc : DWORD -> "int"; RPC_STATUS RpcBindingSetAuthInfoW(void* Binding, LPWSTR ServerPrincName, DWORD AuthnLevel, DWORD AuthnSvc, void* AuthIdentity, DWORD AuthzSvc)
#uselib "RPCRT4.dll"
#cfunc global RpcBindingSetAuthInfoW "RpcBindingSetAuthInfoW" intptr, wstr, int, int, intptr, int
; res = RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
; Binding : void* -> "intptr"
; ServerPrincName : LPWSTR optional -> "wstr"
; AuthnLevel : DWORD -> "int"
; AuthnSvc : DWORD -> "int"
; AuthIdentity : void* optional -> "intptr"
; AuthzSvc : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
rpcrt4 = windows.NewLazySystemDLL("RPCRT4.dll")
procRpcBindingSetAuthInfoW = rpcrt4.NewProc("RpcBindingSetAuthInfoW")
)
// Binding (void*), ServerPrincName (LPWSTR optional), AuthnLevel (DWORD), AuthnSvc (DWORD), AuthIdentity (void* optional), AuthzSvc (DWORD)
r1, _, err := procRpcBindingSetAuthInfoW.Call(
uintptr(Binding),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(ServerPrincName))),
uintptr(AuthnLevel),
uintptr(AuthnSvc),
uintptr(AuthIdentity),
uintptr(AuthzSvc),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // RPC_STATUSfunction RpcBindingSetAuthInfoW(
Binding: Pointer; // void*
ServerPrincName: PWideChar; // LPWSTR optional
AuthnLevel: DWORD; // DWORD
AuthnSvc: DWORD; // DWORD
AuthIdentity: Pointer; // void* optional
AuthzSvc: DWORD // DWORD
): Integer; stdcall;
external 'RPCRT4.dll' name 'RpcBindingSetAuthInfoW';result := DllCall("RPCRT4\RpcBindingSetAuthInfoW"
, "Ptr", Binding ; void*
, "WStr", ServerPrincName ; LPWSTR optional
, "UInt", AuthnLevel ; DWORD
, "UInt", AuthnSvc ; DWORD
, "Ptr", AuthIdentity ; void* optional
, "UInt", AuthzSvc ; DWORD
, "Int") ; return: RPC_STATUS●RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc) = DLL("RPCRT4.dll", "int RpcBindingSetAuthInfoW(void*, char*, dword, dword, void*, dword)")
# 呼び出し: RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
# Binding : void* -> "void*"
# ServerPrincName : LPWSTR optional -> "char*"
# AuthnLevel : DWORD -> "dword"
# AuthnSvc : DWORD -> "dword"
# AuthIdentity : void* optional -> "void*"
# AuthzSvc : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "rpcrt4" fn RpcBindingSetAuthInfoW(
Binding: ?*anyopaque, // void*
ServerPrincName: [*c]const u16, // LPWSTR optional
AuthnLevel: u32, // DWORD
AuthnSvc: u32, // DWORD
AuthIdentity: ?*anyopaque, // void* optional
AuthzSvc: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc RpcBindingSetAuthInfoW(
Binding: pointer, # void*
ServerPrincName: WideCString, # LPWSTR optional
AuthnLevel: uint32, # DWORD
AuthnSvc: uint32, # DWORD
AuthIdentity: pointer, # void* optional
AuthzSvc: uint32 # DWORD
): int32 {.importc: "RpcBindingSetAuthInfoW", stdcall, dynlib: "RPCRT4.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "rpcrt4");
extern(Windows)
int RpcBindingSetAuthInfoW(
void* Binding, // void*
const(wchar)* ServerPrincName, // LPWSTR optional
uint AuthnLevel, // DWORD
uint AuthnSvc, // DWORD
void* AuthIdentity, // void* optional
uint AuthzSvc // DWORD
);ccall((:RpcBindingSetAuthInfoW, "RPCRT4.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, UInt32, UInt32, Ptr{Cvoid}, UInt32),
Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
# Binding : void* -> Ptr{Cvoid}
# ServerPrincName : LPWSTR optional -> Cwstring
# AuthnLevel : DWORD -> UInt32
# AuthnSvc : DWORD -> UInt32
# AuthIdentity : void* optional -> Ptr{Cvoid}
# AuthzSvc : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t RpcBindingSetAuthInfoW(
void* Binding,
const uint16_t* ServerPrincName,
uint32_t AuthnLevel,
uint32_t AuthnSvc,
void* AuthIdentity,
uint32_t AuthzSvc);
]]
local rpcrt4 = ffi.load("rpcrt4")
-- rpcrt4.RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
-- Binding : void*
-- ServerPrincName : LPWSTR optional
-- AuthnLevel : DWORD
-- AuthnSvc : DWORD
-- AuthIdentity : void* optional
-- AuthzSvc : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('RPCRT4.dll');
const RpcBindingSetAuthInfoW = lib.func('__stdcall', 'RpcBindingSetAuthInfoW', 'int32_t', ['void *', 'str16', 'uint32_t', 'uint32_t', 'void *', 'uint32_t']);
// RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
// Binding : void* -> 'void *'
// ServerPrincName : LPWSTR optional -> 'str16'
// AuthnLevel : DWORD -> 'uint32_t'
// AuthnSvc : DWORD -> 'uint32_t'
// AuthIdentity : void* optional -> 'void *'
// AuthzSvc : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("RPCRT4.dll", {
RpcBindingSetAuthInfoW: { parameters: ["pointer", "buffer", "u32", "u32", "pointer", "u32"], result: "i32" },
});
// lib.symbols.RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc)
// Binding : void* -> "pointer"
// ServerPrincName : LPWSTR optional -> "buffer"
// AuthnLevel : DWORD -> "u32"
// AuthnSvc : DWORD -> "u32"
// AuthIdentity : void* optional -> "pointer"
// AuthzSvc : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t RpcBindingSetAuthInfoW(
void* Binding,
const uint16_t* ServerPrincName,
uint32_t AuthnLevel,
uint32_t AuthnSvc,
void* AuthIdentity,
uint32_t AuthzSvc);
C, "RPCRT4.dll");
// $ffi->RpcBindingSetAuthInfoW(Binding, ServerPrincName, AuthnLevel, AuthnSvc, AuthIdentity, AuthzSvc);
// Binding : void*
// ServerPrincName : LPWSTR optional
// AuthnLevel : DWORD
// AuthnSvc : DWORD
// AuthIdentity : void* optional
// AuthzSvc : DWORD
// 構造体/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 Rpcrt4 extends StdCallLibrary {
Rpcrt4 INSTANCE = Native.load("rpcrt4", Rpcrt4.class, W32APIOptions.UNICODE_OPTIONS);
int RpcBindingSetAuthInfoW(
Pointer Binding, // void*
WString ServerPrincName, // LPWSTR optional
int AuthnLevel, // DWORD
int AuthnSvc, // DWORD
Pointer AuthIdentity, // void* optional
int AuthzSvc // DWORD
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("rpcrt4")]
lib LibRPCRT4
fun RpcBindingSetAuthInfoW = RpcBindingSetAuthInfoW(
Binding : Void*, # void*
ServerPrincName : UInt16*, # LPWSTR optional
AuthnLevel : UInt32, # DWORD
AuthnSvc : UInt32, # DWORD
AuthIdentity : Void*, # void* optional
AuthzSvc : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef RpcBindingSetAuthInfoWNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Uint32, Pointer<Void>, Uint32);
typedef RpcBindingSetAuthInfoWDart = int Function(Pointer<Void>, Pointer<Utf16>, int, int, Pointer<Void>, int);
final RpcBindingSetAuthInfoW = DynamicLibrary.open('RPCRT4.dll')
.lookupFunction<RpcBindingSetAuthInfoWNative, RpcBindingSetAuthInfoWDart>('RpcBindingSetAuthInfoW');
// Binding : void* -> Pointer<Void>
// ServerPrincName : LPWSTR optional -> Pointer<Utf16>
// AuthnLevel : DWORD -> Uint32
// AuthnSvc : DWORD -> Uint32
// AuthIdentity : void* optional -> Pointer<Void>
// AuthzSvc : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function RpcBindingSetAuthInfoW(
Binding: Pointer; // void*
ServerPrincName: PWideChar; // LPWSTR optional
AuthnLevel: DWORD; // DWORD
AuthnSvc: DWORD; // DWORD
AuthIdentity: Pointer; // void* optional
AuthzSvc: DWORD // DWORD
): Integer; stdcall;
external 'RPCRT4.dll' name 'RpcBindingSetAuthInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "RpcBindingSetAuthInfoW"
c_RpcBindingSetAuthInfoW :: Ptr () -> CWString -> Word32 -> Word32 -> Ptr () -> Word32 -> IO Int32
-- Binding : void* -> Ptr ()
-- ServerPrincName : LPWSTR optional -> CWString
-- AuthnLevel : DWORD -> Word32
-- AuthnSvc : DWORD -> Word32
-- AuthIdentity : void* optional -> Ptr ()
-- AuthzSvc : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let rpcbindingsetauthinfow =
foreign "RpcBindingSetAuthInfoW"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* Binding : void* -> (ptr void) *)
(* ServerPrincName : LPWSTR optional -> (ptr uint16_t) *)
(* AuthnLevel : DWORD -> uint32_t *)
(* AuthnSvc : DWORD -> uint32_t *)
(* AuthIdentity : void* optional -> (ptr void) *)
(* AuthzSvc : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library rpcrt4 (t "RPCRT4.dll"))
(cffi:use-foreign-library rpcrt4)
(cffi:defcfun ("RpcBindingSetAuthInfoW" rpc-binding-set-auth-info-w :convention :stdcall) :int32
(binding :pointer) ; void*
(server-princ-name (:string :encoding :utf-16le)) ; LPWSTR optional
(authn-level :uint32) ; DWORD
(authn-svc :uint32) ; DWORD
(auth-identity :pointer) ; void* optional
(authz-svc :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $RpcBindingSetAuthInfoW = Win32::API::More->new('RPCRT4',
'int RpcBindingSetAuthInfoW(LPVOID Binding, LPCWSTR ServerPrincName, DWORD AuthnLevel, DWORD AuthnSvc, LPVOID AuthIdentity, DWORD AuthzSvc)');
# my $ret = $RpcBindingSetAuthInfoW->Call($Binding, $ServerPrincName, $AuthnLevel, $AuthnSvc, $AuthIdentity, $AuthzSvc);
# Binding : void* -> LPVOID
# ServerPrincName : LPWSTR optional -> LPCWSTR
# AuthnLevel : DWORD -> DWORD
# AuthnSvc : DWORD -> DWORD
# AuthIdentity : void* optional -> LPVOID
# AuthzSvc : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f RpcBindingSetAuthInfoA (ANSI版) — バインディングに認証情報を設定する(ANSI版)。
類似 API
- f RpcBindingSetAuthInfoExW — RPCバインディングハンドルに認証・認可情報とセキュリティQOSを設定する(Unicode版)。
使用する型