P
plmanikandan
Hi,
I need to check the SE_TCB_NAME previlige for the current user using
GetTokenInformation api call.i used the api call and get the
privilege,but i am unable to go thru each previlege to check whether
SE_TCB_NAME is enabled or not.my code is below[C#}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
namespace gettoken
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
enum TOKEN_INFORMATION_CLASS
{
TokenUser = 1,
TokenGroups,
TokenPrivileges,
TokenOwner,
TokenPrimaryGroup,
TokenDefaultDacl,
TokenSource,
TokenType,
TokenImpersonationLevel,
TokenStatistics,
TokenRestrictedSids,
TokenSessionId,
TokenGroupsAndPrivileges,
TokenSessionReference,
TokenSandBoxInert,
TokenAuditPolicy,
TokenOrigin
}
[StructLayout(LayoutKind.Sequential)]
public struct LUID
{
public int LowPart;
public int HighPart;
}
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_PRIVILEGES
{
public LUID Luid;
public int Attributes;
public int PrivilegeCount;
}
struct LUID_AND_ATTRIBUTES
{
public LUID Luid;
public int Attributes;
}
[DllImport("kernel32.dll")]
static extern IntPtr LocalFree(IntPtr hMem);
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool GetTokenInformation(
IntPtr TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
IntPtr TokenInformation,
int TokenInformationLength,
out int ReturnLength);
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(200, 48);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
int TokenInfLength = 0 ;
bool Result ;
// first call gets lenght of TokenInformation
Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token ,
TOKEN_INFORMATION_CLASS.TokenPrivileges , IntPtr.Zero , TokenInfLength
, out TokenInfLength );
IntPtr TokenInformation = Marshal.AllocHGlobal( TokenInfLength ) ;
Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token ,
TOKEN_INFORMATION_CLASS.TokenPrivileges , TokenInformation ,
TokenInfLength , out TokenInfLength ) ;
if( Result )
{
TOKEN_PRIVILEGES
TokenPrivilege=(TOKEN_PRIVILEGES)Marshal.PtrToStructure(
TokenInformation , typeof( TOKEN_PRIVILEGES ));
LUID_AND_ATTRIBUTES
luid=(LUID_AND_ATTRIBUTES)Marshal.PtrToStructure(TokenInformation ,
typeof( LUID_AND_ATTRIBUTES ));
IntPtr pstr = IntPtr.Zero;
MessageBox.Show(TokenPrivilege.PrivilegeCount.ToString());
LocalFree(pstr);
}
}
}
}
Please help me to solve the problem of checking SE_TCB_NAME Privilege
Regards,
Mani
I need to check the SE_TCB_NAME previlige for the current user using
GetTokenInformation api call.i used the api call and get the
privilege,but i am unable to go thru each previlege to check whether
SE_TCB_NAME is enabled or not.my code is below[C#}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
namespace gettoken
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
enum TOKEN_INFORMATION_CLASS
{
TokenUser = 1,
TokenGroups,
TokenPrivileges,
TokenOwner,
TokenPrimaryGroup,
TokenDefaultDacl,
TokenSource,
TokenType,
TokenImpersonationLevel,
TokenStatistics,
TokenRestrictedSids,
TokenSessionId,
TokenGroupsAndPrivileges,
TokenSessionReference,
TokenSandBoxInert,
TokenAuditPolicy,
TokenOrigin
}
[StructLayout(LayoutKind.Sequential)]
public struct LUID
{
public int LowPart;
public int HighPart;
}
[StructLayout(LayoutKind.Sequential)]
public struct TOKEN_PRIVILEGES
{
public LUID Luid;
public int Attributes;
public int PrivilegeCount;
}
struct LUID_AND_ATTRIBUTES
{
public LUID Luid;
public int Attributes;
}
[DllImport("kernel32.dll")]
static extern IntPtr LocalFree(IntPtr hMem);
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool GetTokenInformation(
IntPtr TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
IntPtr TokenInformation,
int TokenInformationLength,
out int ReturnLength);
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 136);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(200, 48);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
int TokenInfLength = 0 ;
bool Result ;
// first call gets lenght of TokenInformation
Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token ,
TOKEN_INFORMATION_CLASS.TokenPrivileges , IntPtr.Zero , TokenInfLength
, out TokenInfLength );
IntPtr TokenInformation = Marshal.AllocHGlobal( TokenInfLength ) ;
Result = GetTokenInformation( WindowsIdentity.GetCurrent().Token ,
TOKEN_INFORMATION_CLASS.TokenPrivileges , TokenInformation ,
TokenInfLength , out TokenInfLength ) ;
if( Result )
{
TOKEN_PRIVILEGES
TokenPrivilege=(TOKEN_PRIVILEGES)Marshal.PtrToStructure(
TokenInformation , typeof( TOKEN_PRIVILEGES ));
LUID_AND_ATTRIBUTES
luid=(LUID_AND_ATTRIBUTES)Marshal.PtrToStructure(TokenInformation ,
typeof( LUID_AND_ATTRIBUTES ));
IntPtr pstr = IntPtr.Zero;
MessageBox.Show(TokenPrivilege.PrivilegeCount.ToString());
LocalFree(pstr);
}
}
}
}
Please help me to solve the problem of checking SE_TCB_NAME Privilege
Regards,
Mani