/***************************************************************************\
*									    *
*   WINNT.H								    *
*									    *
*   Some headers are used from the cygnus project			    *
*   Modified by:							    *
*    kiefer@isys.de							    *
*    rainer@mathematik.uni-bielefeld.de 				    *
*									    *
\***************************************************************************/

#if !defined (_WINNT_H)
#define _WINNT_H

#ifdef __cplusplus
extern "C" {
#endif

#define SE_CREATE_TOKEN_NAME		  TEXT("SeCreateTokenPrivilege")
#define SE_ASSIGNPRIMARYTOKEN_NAME	  TEXT("SeAssignPrimaryTokenPrivilege")
#define SE_LOCK_MEMORY_NAME		  TEXT("SeLockMemoryPrivilege")
#define SE_INCREASE_QUOTA_NAME		  TEXT("SeIncreaseQuotaPrivilege")
#define SE_UNSOLICITED_INPUT_NAME	  TEXT("SeUnsolicitedInputPrivilege")
#define SE_MACHINE_ACCOUNT_NAME 	  TEXT("SeMachineAccountPrivilege")
#define SE_TCB_NAME			  TEXT("SeTcbPrivilege")
#define SE_SECURITY_NAME		  TEXT("SeSecurityPrivilege")
#define SE_TAKE_OWNERSHIP_NAME		  TEXT("SeTakeOwnershipPrivilege")
#define SE_LOAD_DRIVER_NAME		  TEXT("SeLoadDriverPrivilege")
#define SE_SYSTEM_PROFILE_NAME		  TEXT("SeSystemProfilePrivilege")
#define SE_SYSTEMTIME_NAME		  TEXT("SeSystemtimePrivilege")
#define SE_PROF_SINGLE_PROCESS_NAME	  TEXT("SeProfileSingleProcessPrivilege")
#define SE_INC_BASE_PRIORITY_NAME	  TEXT("SeIncreaseBasePriorityPrivilege")
#define SE_CREATE_PAGEFILE_NAME 	  TEXT("SeCreatePagefilePrivilege")
#define SE_CREATE_PERMANENT_NAME	  TEXT("SeCreatePermanentPrivilege")
#define SE_BACKUP_NAME			  TEXT("SeBackupPrivilege")
#define SE_RESTORE_NAME 		  TEXT("SeRestorePrivilege")
#define SE_SHUTDOWN_NAME		  TEXT("SeShutdownPrivilege")
#define SE_DEBUG_NAME			  TEXT("SeDebugPrivilege")
#define SE_AUDIT_NAME			  TEXT("SeAuditPrivilege")
#define SE_SYSTEM_ENVIRONMENT_NAME	  TEXT("SeSystemEnvironmentPrivilege")
#define SE_CHANGE_NOTIFY_NAME		  TEXT("SeChangeNotifyPrivilege")
#define SE_REMOTE_SHUTDOWN_NAME 	  TEXT("SeRemoteShutdownPrivilege")

#define SE_PRIVILEGE_ENABLED_BY_DEFAULT (0x00000001L)
#define SE_PRIVILEGE_ENABLED		(0x00000002L)
#define SE_PRIVILEGE_USED_FOR_ACCESS	(0x80000000L)

#define TOKEN_ASSIGN_PRIMARY	(0x0001)
#define TOKEN_DUPLICATE 	(0x0002)
#define TOKEN_IMPERSONATE	(0x0004)
#define TOKEN_QUERY		(0x0008)
#define TOKEN_QUERY_SOURCE	(0x0010)
#define TOKEN_ADJUST_PRIVILEGES (0x0020)
#define TOKEN_ADJUST_GROUPS	(0x0040)
#define TOKEN_ADJUST_DEFAULT	(0x0080)
#define TOKEN_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED |\
			  TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE |\
			  TOKEN_IMPERSONATE | TOKEN_QUERY |\
			  TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES	 |\
			  TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT)
#define TOKEN_READ (STANDARD_RIGHTS_READ | TOKEN_QUERY)
#define TOKEN_WRITE (STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES   |\
			  TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT)
#define TOKEN_EXECUTE	 (STANDARD_RIGHTS_EXECUTE)

typedef enum {
    TokenPrimary = 1,
    TokenImpersonation
    } TOKEN_TYPE, *PTOKEN_TYPE;

typedef enum {
    TokenUser = 1,
    TokenGroups,
    TokenPrivileges,
    TokenOwner,
    TokenPrimaryGroup,
    TokenDefaultDacl,
    TokenSource,
    TokenType,
    TokenImpersonationLevel,
    TokenStatistics
} TOKEN_INFORMATION_CLASS, *PTOKEN_INFORMATION_CLASS;

typedef long long LONGLONG;
typedef unsigned long long DWORDLONG;

typedef LONGLONG *PLONGLONG;
typedef DWORDLONG *PDWORDLONG;
typedef LONGLONG USN;

typedef union {
    struct {
	DWORD LowPart;
	LONG HighPart;
    } u;
    LONGLONG QuadPart;
} LARGE_INTEGER, *PLARGE_INTEGER;

typedef union {
    struct {
	DWORD LowPart;
	DWORD HighPart;
    } u;
    DWORDLONG QuadPart;
} ULARGE_INTEGER, *PULARGE_INTEGER;


#define ANYSIZE_ARRAY 1
typedef LARGE_INTEGER LUID, *PLUID;
typedef PVOID PACCESS_TOKEN;
typedef PVOID PSECURITY_DESCRIPTOR;
typedef PVOID PSID;

#pragma pack(4)
typedef struct {
    LUID Luid;
    DWORD Attributes;
    } LUID_AND_ATTRIBUTES, * PLUID_AND_ATTRIBUTES;
typedef LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
typedef LUID_AND_ATTRIBUTES_ARRAY *PLUID_AND_ATTRIBUTES_ARRAY;
#pragma pack()

typedef struct {
    BYTE  Value[6];
} SID_IDENTIFIER_AUTHORITY, *PSID_IDENTIFIER_AUTHORITY;

typedef struct {
   BYTE  Revision;
   BYTE  SubAuthorityCount;
   SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
   DWORD SubAuthority[ANYSIZE_ARRAY];
} SID, *PISID;

#define SID_REVISION					(1)
#define SID_MAX_SUB_AUTHORITIES 		(15)
#define SID_RECOMMENDED_SUB_AUTHORITIES (1)

typedef enum {
    SidTypeUser = 1,
    SidTypeGroup,
    SidTypeDomain,
    SidTypeAlias,
    SidTypeWellKnownGroup,
    SidTypeDeletedAccount,
    SidTypeInvalid,
    SidTypeUnknown
} SID_NAME_USE, *PSID_NAME_USE;

typedef struct {
    PSID Sid;
    DWORD Attributes;
} SID_AND_ATTRIBUTES, * PSID_AND_ATTRIBUTES;
typedef SID_AND_ATTRIBUTES SID_AND_ATTRIBUTES_ARRAY[ANYSIZE_ARRAY];
typedef SID_AND_ATTRIBUTES_ARRAY *PSID_AND_ATTRIBUTES_ARRAY;

typedef struct {
    SID_AND_ATTRIBUTES User;
} TOKEN_USER, *PTOKEN_USER;

typedef struct {
    DWORD GroupCount;
    SID_AND_ATTRIBUTES Groups[ANYSIZE_ARRAY];
} TOKEN_GROUPS, *PTOKEN_GROUPS;

typedef struct {
    DWORD PrivilegeCount;
    LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY];
} TOKEN_PRIVILEGES, *PTOKEN_PRIVILEGES;

typedef struct _GUID {
    DWORD Data1;
    WORD  Data2;
    WORD  Data3;
    BYTE  Data4[8];
} GUID;

BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess,
	PHANDLE TokenHandle);
BOOL WINAPI OpenThreadToken(HANDLE ThreadHandle, DWORD DesiredAccess,
	BOOL OpenAsSelf, PHANDLE TokenHandle);
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass,
	LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength);
BOOL WINAPI SetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass,
	LPVOID TokenInformation, DWORD TokenInformationLength);
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges,
	PTOKEN_PRIVILEGES NewState, DWORD BufferLength,
	PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength);
#define LookupPrivilegeValue TFUNCT(LookupPrivilegeValue)
BOOL WINAPI LookupPrivilegeValue(LPCTSTR lpSystemName,
	LPCTSTR lpName, PLUID lpLuid);

#ifdef __cplusplus
}
#endif

#endif /* !defined (_WINNT_H) */
