Win32 API 日本語リファレンス
ホームSecurity.Authentication.Identity › SspiEncodeStringsAsAuthIdentity

SspiEncodeStringsAsAuthIdentity

関数
ユーザー名やドメイン名などの文字列から認証情報構造体を生成する。
DLLSECUR32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT SspiEncodeStringsAsAuthIdentity(
    LPCWSTR pszUserName,   // optional
    LPCWSTR pszDomainName,   // optional
    LPCWSTR pszPackedCredentialsString,   // optional
    void** ppAuthIdentity
);

パラメーター

名前方向説明
pszUserNameLPCWSTRinoptional認証IDに設定するユーザー名を示すワイド文字列。NULL可。
pszDomainNameLPCWSTRinoptional認証IDに設定するドメイン名を示すワイド文字列。NULL可。
pszPackedCredentialsStringLPCWSTRinoptional認証IDに設定するパスワード等のパック済み資格情報文字列。NULL可。
ppAuthIdentityvoid**out出力。生成された認証ID構造体を受け取るポインタ。SspiFreeAuthIdentityで解放する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT SspiEncodeStringsAsAuthIdentity(
    LPCWSTR pszUserName,   // optional
    LPCWSTR pszDomainName,   // optional
    LPCWSTR pszPackedCredentialsString,   // optional
    void** ppAuthIdentity
);
[DllImport("SECUR32.dll", ExactSpelling = true)]
static extern int SspiEncodeStringsAsAuthIdentity(
    [MarshalAs(UnmanagedType.LPWStr)] string pszUserName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszDomainName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszPackedCredentialsString,   // LPCWSTR optional
    IntPtr ppAuthIdentity   // void** out
);
<DllImport("SECUR32.dll", ExactSpelling:=True)>
Public Shared Function SspiEncodeStringsAsAuthIdentity(
    <MarshalAs(UnmanagedType.LPWStr)> pszUserName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszDomainName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> pszPackedCredentialsString As String,   ' LPCWSTR optional
    ppAuthIdentity As IntPtr   ' void** out
) As Integer
End Function
' pszUserName : LPCWSTR optional
' pszDomainName : LPCWSTR optional
' pszPackedCredentialsString : LPCWSTR optional
' ppAuthIdentity : void** out
Declare PtrSafe Function SspiEncodeStringsAsAuthIdentity Lib "secur32" ( _
    ByVal pszUserName As LongPtr, _
    ByVal pszDomainName As LongPtr, _
    ByVal pszPackedCredentialsString As LongPtr, _
    ByVal ppAuthIdentity As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SspiEncodeStringsAsAuthIdentity = ctypes.windll.secur32.SspiEncodeStringsAsAuthIdentity
SspiEncodeStringsAsAuthIdentity.restype = ctypes.c_int
SspiEncodeStringsAsAuthIdentity.argtypes = [
    wintypes.LPCWSTR,  # pszUserName : LPCWSTR optional
    wintypes.LPCWSTR,  # pszDomainName : LPCWSTR optional
    wintypes.LPCWSTR,  # pszPackedCredentialsString : LPCWSTR optional
    ctypes.c_void_p,  # ppAuthIdentity : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SECUR32.dll')
SspiEncodeStringsAsAuthIdentity = Fiddle::Function.new(
  lib['SspiEncodeStringsAsAuthIdentity'],
  [
    Fiddle::TYPE_VOIDP,  # pszUserName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszDomainName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # pszPackedCredentialsString : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # ppAuthIdentity : void** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "secur32")]
extern "system" {
    fn SspiEncodeStringsAsAuthIdentity(
        pszUserName: *const u16,  // LPCWSTR optional
        pszDomainName: *const u16,  // LPCWSTR optional
        pszPackedCredentialsString: *const u16,  // LPCWSTR optional
        ppAuthIdentity: *mut *mut ()  // void** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SECUR32.dll")]
public static extern int SspiEncodeStringsAsAuthIdentity([MarshalAs(UnmanagedType.LPWStr)] string pszUserName, [MarshalAs(UnmanagedType.LPWStr)] string pszDomainName, [MarshalAs(UnmanagedType.LPWStr)] string pszPackedCredentialsString, IntPtr ppAuthIdentity);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SECUR32_SspiEncodeStringsAsAuthIdentity' -Namespace Win32 -PassThru
# $api::SspiEncodeStringsAsAuthIdentity(pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity)
#uselib "SECUR32.dll"
#func global SspiEncodeStringsAsAuthIdentity "SspiEncodeStringsAsAuthIdentity" sptr, sptr, sptr, sptr
; SspiEncodeStringsAsAuthIdentity pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity   ; 戻り値は stat
; pszUserName : LPCWSTR optional -> "sptr"
; pszDomainName : LPCWSTR optional -> "sptr"
; pszPackedCredentialsString : LPCWSTR optional -> "sptr"
; ppAuthIdentity : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SECUR32.dll"
#cfunc global SspiEncodeStringsAsAuthIdentity "SspiEncodeStringsAsAuthIdentity" wstr, wstr, wstr, sptr
; res = SspiEncodeStringsAsAuthIdentity(pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity)
; pszUserName : LPCWSTR optional -> "wstr"
; pszDomainName : LPCWSTR optional -> "wstr"
; pszPackedCredentialsString : LPCWSTR optional -> "wstr"
; ppAuthIdentity : void** out -> "sptr"
; HRESULT SspiEncodeStringsAsAuthIdentity(LPCWSTR pszUserName, LPCWSTR pszDomainName, LPCWSTR pszPackedCredentialsString, void** ppAuthIdentity)
#uselib "SECUR32.dll"
#cfunc global SspiEncodeStringsAsAuthIdentity "SspiEncodeStringsAsAuthIdentity" wstr, wstr, wstr, intptr
; res = SspiEncodeStringsAsAuthIdentity(pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity)
; pszUserName : LPCWSTR optional -> "wstr"
; pszDomainName : LPCWSTR optional -> "wstr"
; pszPackedCredentialsString : LPCWSTR optional -> "wstr"
; ppAuthIdentity : void** out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	secur32 = windows.NewLazySystemDLL("SECUR32.dll")
	procSspiEncodeStringsAsAuthIdentity = secur32.NewProc("SspiEncodeStringsAsAuthIdentity")
)

// pszUserName (LPCWSTR optional), pszDomainName (LPCWSTR optional), pszPackedCredentialsString (LPCWSTR optional), ppAuthIdentity (void** out)
r1, _, err := procSspiEncodeStringsAsAuthIdentity.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszUserName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszDomainName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPackedCredentialsString))),
	uintptr(ppAuthIdentity),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function SspiEncodeStringsAsAuthIdentity(
  pszUserName: PWideChar;   // LPCWSTR optional
  pszDomainName: PWideChar;   // LPCWSTR optional
  pszPackedCredentialsString: PWideChar;   // LPCWSTR optional
  ppAuthIdentity: Pointer   // void** out
): Integer; stdcall;
  external 'SECUR32.dll' name 'SspiEncodeStringsAsAuthIdentity';
result := DllCall("SECUR32\SspiEncodeStringsAsAuthIdentity"
    , "WStr", pszUserName   ; LPCWSTR optional
    , "WStr", pszDomainName   ; LPCWSTR optional
    , "WStr", pszPackedCredentialsString   ; LPCWSTR optional
    , "Ptr", ppAuthIdentity   ; void** out
    , "Int")   ; return: HRESULT
●SspiEncodeStringsAsAuthIdentity(pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity) = DLL("SECUR32.dll", "int SspiEncodeStringsAsAuthIdentity(char*, char*, char*, void*)")
# 呼び出し: SspiEncodeStringsAsAuthIdentity(pszUserName, pszDomainName, pszPackedCredentialsString, ppAuthIdentity)
# pszUserName : LPCWSTR optional -> "char*"
# pszDomainName : LPCWSTR optional -> "char*"
# pszPackedCredentialsString : LPCWSTR optional -> "char*"
# ppAuthIdentity : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SspiEncodeStringsAsAuthIdentityNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>);
typedef SspiEncodeStringsAsAuthIdentityDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>);
final SspiEncodeStringsAsAuthIdentity = DynamicLibrary.open('SECUR32.dll')
    .lookupFunction<SspiEncodeStringsAsAuthIdentityNative, SspiEncodeStringsAsAuthIdentityDart>('SspiEncodeStringsAsAuthIdentity');
// pszUserName : LPCWSTR optional -> Pointer<Utf16>
// pszDomainName : LPCWSTR optional -> Pointer<Utf16>
// pszPackedCredentialsString : LPCWSTR optional -> Pointer<Utf16>
// ppAuthIdentity : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SspiEncodeStringsAsAuthIdentity(
  pszUserName: PWideChar;   // LPCWSTR optional
  pszDomainName: PWideChar;   // LPCWSTR optional
  pszPackedCredentialsString: PWideChar;   // LPCWSTR optional
  ppAuthIdentity: Pointer   // void** out
): Integer; stdcall;
  external 'SECUR32.dll' name 'SspiEncodeStringsAsAuthIdentity';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SspiEncodeStringsAsAuthIdentity"
  c_SspiEncodeStringsAsAuthIdentity :: CWString -> CWString -> CWString -> Ptr () -> IO Int32
-- pszUserName : LPCWSTR optional -> CWString
-- pszDomainName : LPCWSTR optional -> CWString
-- pszPackedCredentialsString : LPCWSTR optional -> CWString
-- ppAuthIdentity : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let sspiencodestringsasauthidentity =
  foreign "SspiEncodeStringsAsAuthIdentity"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> returning int32_t)
(* pszUserName : LPCWSTR optional -> (ptr uint16_t) *)
(* pszDomainName : LPCWSTR optional -> (ptr uint16_t) *)
(* pszPackedCredentialsString : LPCWSTR optional -> (ptr uint16_t) *)
(* ppAuthIdentity : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library secur32 (t "SECUR32.dll"))
(cffi:use-foreign-library secur32)

(cffi:defcfun ("SspiEncodeStringsAsAuthIdentity" sspi-encode-strings-as-auth-identity :convention :stdcall) :int32
  (psz-user-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (psz-domain-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (psz-packed-credentials-string (:string :encoding :utf-16le))   ; LPCWSTR optional
  (pp-auth-identity :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SspiEncodeStringsAsAuthIdentity = Win32::API::More->new('SECUR32',
    'int SspiEncodeStringsAsAuthIdentity(LPCWSTR pszUserName, LPCWSTR pszDomainName, LPCWSTR pszPackedCredentialsString, LPVOID ppAuthIdentity)');
# my $ret = $SspiEncodeStringsAsAuthIdentity->Call($pszUserName, $pszDomainName, $pszPackedCredentialsString, $ppAuthIdentity);
# pszUserName : LPCWSTR optional -> LPCWSTR
# pszDomainName : LPCWSTR optional -> LPCWSTR
# pszPackedCredentialsString : LPCWSTR optional -> LPCWSTR
# ppAuthIdentity : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。