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

LSA_TOKEN_INFORMATION_V3

構造体
サイズx64: 88 バイト / x86: 48 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
ExpirationTimeLONGLONG8+0+0生成するトークンの有効期限を示すタイムスタンプ。
UserTOKEN_USER16/8+8+8トークンの所有ユーザーSIDを保持するTOKEN_USER。
GroupsTOKEN_GROUPS*8/4+24+16トークンに含めるグループSID群を保持するTOKEN_GROUPSへのポインタ。
PrimaryGroupTOKEN_PRIMARY_GROUP8/4+32+20トークンのプライマリグループSIDを保持するTOKEN_PRIMARY_GROUP。
PrivilegesTOKEN_PRIVILEGES*8/4+40+24トークンに付与する特権群を保持するTOKEN_PRIVILEGESへのポインタ。
OwnerTOKEN_OWNER8/4+48+28新規オブジェクトの既定所有者SIDを保持するTOKEN_OWNER。
DefaultDaclTOKEN_DEFAULT_DACL8/4+56+32新規オブジェクトの既定DACLを保持するTOKEN_DEFAULT_DACL。
UserClaimsTOKEN_USER_CLAIMS8/4+64+36ユーザーに関連付く属性クレームを保持するTOKEN_USER_CLAIMS。
DeviceClaimsTOKEN_DEVICE_CLAIMS8/4+72+40デバイスに関連付く属性クレームを保持するTOKEN_DEVICE_CLAIMS。
DeviceGroupsTOKEN_GROUPS*8/4+80+44デバイスのグループSID群を保持するTOKEN_GROUPSへのポインタ。

各言語での定義

#include <windows.h>

// SID_AND_ATTRIBUTES  (x64 16 / x86 8 バイト)
typedef struct SID_AND_ATTRIBUTES {
    PSID Sid;
    DWORD Attributes;
} SID_AND_ATTRIBUTES;

// TOKEN_USER  (x64 16 / x86 8 バイト)
typedef struct TOKEN_USER {
    SID_AND_ATTRIBUTES User;
} TOKEN_USER;

// TOKEN_PRIMARY_GROUP  (x64 8 / x86 4 バイト)
typedef struct TOKEN_PRIMARY_GROUP {
    PSID PrimaryGroup;
} TOKEN_PRIMARY_GROUP;

// TOKEN_OWNER  (x64 8 / x86 4 バイト)
typedef struct TOKEN_OWNER {
    PSID Owner;
} TOKEN_OWNER;

// TOKEN_DEFAULT_DACL  (x64 8 / x86 4 バイト)
typedef struct TOKEN_DEFAULT_DACL {
    ACL* DefaultDacl;
} TOKEN_DEFAULT_DACL;

// TOKEN_USER_CLAIMS  (x64 8 / x86 4 バイト)
typedef struct TOKEN_USER_CLAIMS {
    void* UserClaims;
} TOKEN_USER_CLAIMS;

// TOKEN_DEVICE_CLAIMS  (x64 8 / x86 4 バイト)
typedef struct TOKEN_DEVICE_CLAIMS {
    void* DeviceClaims;
} TOKEN_DEVICE_CLAIMS;

// LSA_TOKEN_INFORMATION_V3  (x64 88 / x86 48 バイト)
typedef struct LSA_TOKEN_INFORMATION_V3 {
    LONGLONG ExpirationTime;
    TOKEN_USER User;
    TOKEN_GROUPS* Groups;
    TOKEN_PRIMARY_GROUP PrimaryGroup;
    TOKEN_PRIVILEGES* Privileges;
    TOKEN_OWNER Owner;
    TOKEN_DEFAULT_DACL DefaultDacl;
    TOKEN_USER_CLAIMS UserClaims;
    TOKEN_DEVICE_CLAIMS DeviceClaims;
    TOKEN_GROUPS* DeviceGroups;
} LSA_TOKEN_INFORMATION_V3;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SID_AND_ATTRIBUTES
{
    public IntPtr Sid;
    public uint Attributes;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_USER
{
    public SID_AND_ATTRIBUTES User;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_PRIMARY_GROUP
{
    public IntPtr PrimaryGroup;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_OWNER
{
    public IntPtr Owner;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_DEFAULT_DACL
{
    public IntPtr DefaultDacl;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_USER_CLAIMS
{
    public IntPtr UserClaims;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct TOKEN_DEVICE_CLAIMS
{
    public IntPtr DeviceClaims;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct LSA_TOKEN_INFORMATION_V3
{
    public long ExpirationTime;
    public TOKEN_USER User;
    public IntPtr Groups;
    public TOKEN_PRIMARY_GROUP PrimaryGroup;
    public IntPtr Privileges;
    public TOKEN_OWNER Owner;
    public TOKEN_DEFAULT_DACL DefaultDacl;
    public TOKEN_USER_CLAIMS UserClaims;
    public TOKEN_DEVICE_CLAIMS DeviceClaims;
    public IntPtr DeviceGroups;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SID_AND_ATTRIBUTES
    Public Sid As IntPtr
    Public Attributes As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_USER
    Public User As SID_AND_ATTRIBUTES
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_PRIMARY_GROUP
    Public PrimaryGroup As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_OWNER
    Public Owner As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_DEFAULT_DACL
    Public DefaultDacl As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_USER_CLAIMS
    Public UserClaims As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure TOKEN_DEVICE_CLAIMS
    Public DeviceClaims As IntPtr
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure LSA_TOKEN_INFORMATION_V3
    Public ExpirationTime As Long
    Public User As TOKEN_USER
    Public Groups As IntPtr
    Public PrimaryGroup As TOKEN_PRIMARY_GROUP
    Public Privileges As IntPtr
    Public Owner As TOKEN_OWNER
    Public DefaultDacl As TOKEN_DEFAULT_DACL
    Public UserClaims As TOKEN_USER_CLAIMS
    Public DeviceClaims As TOKEN_DEVICE_CLAIMS
    Public DeviceGroups As IntPtr
End Structure
import ctypes
from ctypes import wintypes

class SID_AND_ATTRIBUTES(ctypes.Structure):
    _fields_ = [
        ("Sid", ctypes.c_void_p),
        ("Attributes", wintypes.DWORD),
    ]

class TOKEN_USER(ctypes.Structure):
    _fields_ = [
        ("User", SID_AND_ATTRIBUTES),
    ]

class TOKEN_PRIMARY_GROUP(ctypes.Structure):
    _fields_ = [
        ("PrimaryGroup", ctypes.c_void_p),
    ]

class TOKEN_OWNER(ctypes.Structure):
    _fields_ = [
        ("Owner", ctypes.c_void_p),
    ]

class TOKEN_DEFAULT_DACL(ctypes.Structure):
    _fields_ = [
        ("DefaultDacl", ctypes.c_void_p),
    ]

class TOKEN_USER_CLAIMS(ctypes.Structure):
    _fields_ = [
        ("UserClaims", ctypes.c_void_p),
    ]

class TOKEN_DEVICE_CLAIMS(ctypes.Structure):
    _fields_ = [
        ("DeviceClaims", ctypes.c_void_p),
    ]

class LSA_TOKEN_INFORMATION_V3(ctypes.Structure):
    _fields_ = [
        ("ExpirationTime", ctypes.c_longlong),
        ("User", TOKEN_USER),
        ("Groups", ctypes.c_void_p),
        ("PrimaryGroup", TOKEN_PRIMARY_GROUP),
        ("Privileges", ctypes.c_void_p),
        ("Owner", TOKEN_OWNER),
        ("DefaultDacl", TOKEN_DEFAULT_DACL),
        ("UserClaims", TOKEN_USER_CLAIMS),
        ("DeviceClaims", TOKEN_DEVICE_CLAIMS),
        ("DeviceGroups", ctypes.c_void_p),
    ]
#[repr(C)]
pub struct SID_AND_ATTRIBUTES {
    pub Sid: *mut core::ffi::c_void,
    pub Attributes: u32,
}

#[repr(C)]
pub struct TOKEN_USER {
    pub User: SID_AND_ATTRIBUTES,
}

#[repr(C)]
pub struct TOKEN_PRIMARY_GROUP {
    pub PrimaryGroup: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct TOKEN_OWNER {
    pub Owner: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct TOKEN_DEFAULT_DACL {
    pub DefaultDacl: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct TOKEN_USER_CLAIMS {
    pub UserClaims: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct TOKEN_DEVICE_CLAIMS {
    pub DeviceClaims: *mut core::ffi::c_void,
}

#[repr(C)]
pub struct LSA_TOKEN_INFORMATION_V3 {
    pub ExpirationTime: i64,
    pub User: TOKEN_USER,
    pub Groups: *mut core::ffi::c_void,
    pub PrimaryGroup: TOKEN_PRIMARY_GROUP,
    pub Privileges: *mut core::ffi::c_void,
    pub Owner: TOKEN_OWNER,
    pub DefaultDacl: TOKEN_DEFAULT_DACL,
    pub UserClaims: TOKEN_USER_CLAIMS,
    pub DeviceClaims: TOKEN_DEVICE_CLAIMS,
    pub DeviceGroups: *mut core::ffi::c_void,
}
import "golang.org/x/sys/windows"

type SID_AND_ATTRIBUTES struct {
	Sid uintptr
	Attributes uint32
}

type TOKEN_USER struct {
	User SID_AND_ATTRIBUTES
}

type TOKEN_PRIMARY_GROUP struct {
	PrimaryGroup uintptr
}

type TOKEN_OWNER struct {
	Owner uintptr
}

type TOKEN_DEFAULT_DACL struct {
	DefaultDacl uintptr
}

type TOKEN_USER_CLAIMS struct {
	UserClaims uintptr
}

type TOKEN_DEVICE_CLAIMS struct {
	DeviceClaims uintptr
}

type LSA_TOKEN_INFORMATION_V3 struct {
	ExpirationTime int64
	User TOKEN_USER
	Groups uintptr
	PrimaryGroup TOKEN_PRIMARY_GROUP
	Privileges uintptr
	Owner TOKEN_OWNER
	DefaultDacl TOKEN_DEFAULT_DACL
	UserClaims TOKEN_USER_CLAIMS
	DeviceClaims TOKEN_DEVICE_CLAIMS
	DeviceGroups uintptr
}
type
  SID_AND_ATTRIBUTES = record
    Sid: Pointer;
    Attributes: DWORD;
  end;

  TOKEN_USER = record
    User: SID_AND_ATTRIBUTES;
  end;

  TOKEN_PRIMARY_GROUP = record
    PrimaryGroup: Pointer;
  end;

  TOKEN_OWNER = record
    Owner: Pointer;
  end;

  TOKEN_DEFAULT_DACL = record
    DefaultDacl: Pointer;
  end;

  TOKEN_USER_CLAIMS = record
    UserClaims: Pointer;
  end;

  TOKEN_DEVICE_CLAIMS = record
    DeviceClaims: Pointer;
  end;

  LSA_TOKEN_INFORMATION_V3 = record
    ExpirationTime: Int64;
    User: TOKEN_USER;
    Groups: Pointer;
    PrimaryGroup: TOKEN_PRIMARY_GROUP;
    Privileges: Pointer;
    Owner: TOKEN_OWNER;
    DefaultDacl: TOKEN_DEFAULT_DACL;
    UserClaims: TOKEN_USER_CLAIMS;
    DeviceClaims: TOKEN_DEVICE_CLAIMS;
    DeviceGroups: Pointer;
  end;
const SID_AND_ATTRIBUTES = extern struct {
    Sid: ?*anyopaque,
    Attributes: u32,
};

const TOKEN_USER = extern struct {
    User: SID_AND_ATTRIBUTES,
};

const TOKEN_PRIMARY_GROUP = extern struct {
    PrimaryGroup: ?*anyopaque,
};

const TOKEN_OWNER = extern struct {
    Owner: ?*anyopaque,
};

const TOKEN_DEFAULT_DACL = extern struct {
    DefaultDacl: ?*anyopaque,
};

const TOKEN_USER_CLAIMS = extern struct {
    UserClaims: ?*anyopaque,
};

const TOKEN_DEVICE_CLAIMS = extern struct {
    DeviceClaims: ?*anyopaque,
};

const LSA_TOKEN_INFORMATION_V3 = extern struct {
    ExpirationTime: i64,
    User: TOKEN_USER,
    Groups: ?*anyopaque,
    PrimaryGroup: TOKEN_PRIMARY_GROUP,
    Privileges: ?*anyopaque,
    Owner: TOKEN_OWNER,
    DefaultDacl: TOKEN_DEFAULT_DACL,
    UserClaims: TOKEN_USER_CLAIMS,
    DeviceClaims: TOKEN_DEVICE_CLAIMS,
    DeviceGroups: ?*anyopaque,
};
type
  SID_AND_ATTRIBUTES {.bycopy.} = object
    Sid: pointer
    Attributes: uint32

  TOKEN_USER {.bycopy.} = object
    User: SID_AND_ATTRIBUTES

  TOKEN_PRIMARY_GROUP {.bycopy.} = object
    PrimaryGroup: pointer

  TOKEN_OWNER {.bycopy.} = object
    Owner: pointer

  TOKEN_DEFAULT_DACL {.bycopy.} = object
    DefaultDacl: pointer

  TOKEN_USER_CLAIMS {.bycopy.} = object
    UserClaims: pointer

  TOKEN_DEVICE_CLAIMS {.bycopy.} = object
    DeviceClaims: pointer

  LSA_TOKEN_INFORMATION_V3 {.bycopy.} = object
    ExpirationTime: int64
    User: TOKEN_USER
    Groups: pointer
    PrimaryGroup: TOKEN_PRIMARY_GROUP
    Privileges: pointer
    Owner: TOKEN_OWNER
    DefaultDacl: TOKEN_DEFAULT_DACL
    UserClaims: TOKEN_USER_CLAIMS
    DeviceClaims: TOKEN_DEVICE_CLAIMS
    DeviceGroups: pointer
struct SID_AND_ATTRIBUTES
{
    void* Sid;
    uint Attributes;
}

struct TOKEN_USER
{
    SID_AND_ATTRIBUTES User;
}

struct TOKEN_PRIMARY_GROUP
{
    void* PrimaryGroup;
}

struct TOKEN_OWNER
{
    void* Owner;
}

struct TOKEN_DEFAULT_DACL
{
    void* DefaultDacl;
}

struct TOKEN_USER_CLAIMS
{
    void* UserClaims;
}

struct TOKEN_DEVICE_CLAIMS
{
    void* DeviceClaims;
}

struct LSA_TOKEN_INFORMATION_V3
{
    long ExpirationTime;
    TOKEN_USER User;
    void* Groups;
    TOKEN_PRIMARY_GROUP PrimaryGroup;
    void* Privileges;
    TOKEN_OWNER Owner;
    TOKEN_DEFAULT_DACL DefaultDacl;
    TOKEN_USER_CLAIMS UserClaims;
    TOKEN_DEVICE_CLAIMS DeviceClaims;
    void* DeviceGroups;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; LSA_TOKEN_INFORMATION_V3 サイズ: 48 バイト(x86)
dim st, 12    ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; ExpirationTime : LONGLONG (+0, 8byte)  qpoke st,0,値 / qpeek(st,0)  ※IronHSPのみ。3.7/3.8は lpoke st,0,下位 : lpoke st,4,上位
; User : TOKEN_USER (+8, 8byte)  varptr(st)+8 を基点に操作(8byte:入れ子/配列)
; Groups : TOKEN_GROUPS* (+16, 4byte)  varptr(st)+16 を基点に操作(4byte:入れ子/配列)
; PrimaryGroup : TOKEN_PRIMARY_GROUP (+20, 4byte)  varptr(st)+20 を基点に操作(4byte:入れ子/配列)
; Privileges : TOKEN_PRIVILEGES* (+24, 4byte)  varptr(st)+24 を基点に操作(4byte:入れ子/配列)
; Owner : TOKEN_OWNER (+28, 4byte)  varptr(st)+28 を基点に操作(4byte:入れ子/配列)
; DefaultDacl : TOKEN_DEFAULT_DACL (+32, 4byte)  varptr(st)+32 を基点に操作(4byte:入れ子/配列)
; UserClaims : TOKEN_USER_CLAIMS (+36, 4byte)  varptr(st)+36 を基点に操作(4byte:入れ子/配列)
; DeviceClaims : TOKEN_DEVICE_CLAIMS (+40, 4byte)  varptr(st)+40 を基点に操作(4byte:入れ子/配列)
; DeviceGroups : TOKEN_GROUPS* (+44, 4byte)  varptr(st)+44 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; LSA_TOKEN_INFORMATION_V3 サイズ: 88 バイト(x64)
dim st, 22    ; 4byte整数×22(構造体サイズ 88 / 4 切り上げ)
; ExpirationTime : LONGLONG (+0, 8byte)  qpoke st,0,値 / qpeek(st,0)  ※IronHSPのみ。3.7/3.8は lpoke st,0,下位 : lpoke st,4,上位
; User : TOKEN_USER (+8, 16byte)  varptr(st)+8 を基点に操作(16byte:入れ子/配列)
; Groups : TOKEN_GROUPS* (+24, 8byte)  varptr(st)+24 を基点に操作(8byte:入れ子/配列)
; PrimaryGroup : TOKEN_PRIMARY_GROUP (+32, 8byte)  varptr(st)+32 を基点に操作(8byte:入れ子/配列)
; Privileges : TOKEN_PRIVILEGES* (+40, 8byte)  varptr(st)+40 を基点に操作(8byte:入れ子/配列)
; Owner : TOKEN_OWNER (+48, 8byte)  varptr(st)+48 を基点に操作(8byte:入れ子/配列)
; DefaultDacl : TOKEN_DEFAULT_DACL (+56, 8byte)  varptr(st)+56 を基点に操作(8byte:入れ子/配列)
; UserClaims : TOKEN_USER_CLAIMS (+64, 8byte)  varptr(st)+64 を基点に操作(8byte:入れ子/配列)
; DeviceClaims : TOKEN_DEVICE_CLAIMS (+72, 8byte)  varptr(st)+72 を基点に操作(8byte:入れ子/配列)
; DeviceGroups : TOKEN_GROUPS* (+80, 8byte)  varptr(st)+80 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SID_AND_ATTRIBUTES
    #field intptr Sid
    #field int Attributes
#endstruct

#defstruct global TOKEN_USER
    #field SID_AND_ATTRIBUTES User
#endstruct

#defstruct global TOKEN_PRIMARY_GROUP
    #field intptr PrimaryGroup
#endstruct

#defstruct global TOKEN_OWNER
    #field intptr Owner
#endstruct

#defstruct global TOKEN_DEFAULT_DACL
    #field intptr DefaultDacl
#endstruct

#defstruct global TOKEN_USER_CLAIMS
    #field intptr UserClaims
#endstruct

#defstruct global TOKEN_DEVICE_CLAIMS
    #field intptr DeviceClaims
#endstruct

#defstruct global LSA_TOKEN_INFORMATION_V3
    #field int64 ExpirationTime
    #field TOKEN_USER User
    #field intptr Groups
    #field TOKEN_PRIMARY_GROUP PrimaryGroup
    #field intptr Privileges
    #field TOKEN_OWNER Owner
    #field TOKEN_DEFAULT_DACL DefaultDacl
    #field TOKEN_USER_CLAIMS UserClaims
    #field TOKEN_DEVICE_CLAIMS DeviceClaims
    #field intptr DeviceGroups
#endstruct

stdim st, LSA_TOKEN_INFORMATION_V3        ; NSTRUCT 変数を確保
st->ExpirationTime = 100
mes "ExpirationTime=" + st->ExpirationTime