Platform SDK: Access Control |
The CreateRestrictedToken function creates a new access token that is a restricted version of an existing access token. For more information, see Restricted Tokens.
BOOL CreateRestrictedToken( HANDLE ExistingTokenHandle, // handle to existing token DWORD Flags, // privilege options DWORD DisableSidCount, // number of deny-only SIDs PSID_AND_ATTRIBUTES SidsToDisable, // deny-only SIDs DWORD DeletePrivilegeCount, // number of privileges PLUID_AND_ATTRIBUTES PrivilegesToDelete, // privileges DWORD RestrictedSidCount, // number of restricting SIDs PSID_AND_ATTRIBUTES SidsToRestrict, // list of restricting SIDs PHANDLE NewTokenHandle // handle to new token );
Value | Meaning |
---|---|
DISABLE_MAX_PRIVILEGE | Disables all privileges in the new token.
If this value is specified, the DeletePrivilegeCount and PrivilegesToDelete 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/2000: Requires Windows 2000.
Header: Declared in Winbase.h; include Windows.h.
Library: Use Advapi32.lib.
Access Control Overview, Access Control Functions, CreateProcessAsUser, GetTokenInformation, ImpersonateLoggedOnUser, IsTokenRestricted, LUID_AND_ATTRIBUTES, SID_AND_ATTRIBUTES