[This is preliminary documentation and subject to change.]
The CreateRestrictedToken function creates a new access token that is a restricted version of an existing access token.
BOOL CreateRestrictedToken(
HANDLE ExistingTokenHandle, // handle to existing token
DWORD Flags, // flags to delete all privileges
// or apply the deny-only attribute to all SIDs
DWORD DisableSidCount, // number of deny-only SIDs
PSID_AND_ATTRIBUTES SidsToDisable, // array of deny-only SIDs
DWORD DeletePrivilegeCount, // number of privileges to delete
PLUID_AND_ATTRIBUTES PrivilegesToDelete, // privileges to delete
DWORD RestrictedSidCount, // number of restricting SIDs
PSID_AND_ATTRIBUTES SidsToRestrict, // array of restricting SIDs
PHANDLE NewTokenHandle // receives handle to new token
);
Flag | Meaning |
---|---|
DELETE_MAX_PRIVILEGES | Deletes all privileges in the new token. If this flag is specified, the DeletePrivilegeCount and PrivilegesToDelete parameters are ignored. |
DISABLE_MAX_SIDS | Applies the deny-only attribute to the user SID and all group SIDs in the new token. The system uses a deny-only SID to deny access to a securable object, but not to allow access. If this flag is specified, the DisableSidCount and SidsToDisable parameters are ignored. |
You can apply the deny-only attribute to any combination of the existing token's SIDs, including the user SID and group SIDs that have the SE_GROUP_MANDATORY attribute. To get the SIDs associated with the existing token, use the GetTokenInformation function with the TokenUser and TokenGroups flags. The function ignores any SIDs in the array that are not also found in the existing token.
The function ignores the Attributes members of the SID_AND_ATTRIBUTES structures.
This parameter can be NULL if you don't want to disable any SIDs.
You can use the GetTokenInformation function with the TokenPrivileges flag to get the privileges held by the existing token. The function ignores any privileges in the array that are not held by the existing token.
The function ignores the Attributes members of the LUID_AND_ATTRIBUTES structures.
This parameter can be NULL if you don't want to delete any privileges.
The Attributes members of the SID_AND_ATTRIBUTES structures must be zero. Restricting SIDs are always enabled for access checks.
This parameter can be NULL if you don't want to specify any restricting SIDs.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The CreateRestrictedToken function can restrict the token in the following ways:
You can use the restricted token in the CreateProcessAsUser function to create a process that has restricted access rights and privileges. If a process calls CreateProcessAsUser using a restricted version of its own token, the calling process does not need to have the SE_ASSIGNPRIMARYTOKEN_NAME privilege.
You can use the restricted token in the ImpersonateLoggedOnUser function.
Windows NT: Requires version 5.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use advapi32.lib.
Access Control Overview, Access Control Functions, CreateProcessAsUser, GetTokenInformation, ImpersonateLoggedOnUser, IsTokenRestricted, LUID_AND_ATTRIBUTES, SID_AND_ATTRIBUTES