Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DuplicateTokenEx ImpersonationLevel argument mismatches #249

Open
forderud opened this issue Dec 30, 2023 · 0 comments
Open

DuplicateTokenEx ImpersonationLevel argument mismatches #249

forderud opened this issue Dec 30, 2023 · 0 comments

Comments

@forderud
Copy link

forderud commented Dec 30, 2023

There appear to be a mismatches in the DllImport signatures for DuplicateTokenEx in this project. The 4th ImpersonationLevel argument is supposed to be of type SECURITY_IMPERSONATION_LEVEL, but is mapped to the .Net TokenImpersonationLevel counterpart. This .Net enumeration does on the surface appear identical, but the underlying values are shifted by one.

Affected files:

Suggested fix

  • Change TokenImpersonationLevel ImpersonationLevel argument to uint ImpersonationLevel or define a matching .Net SECURITY_IMPERSONATION_LEVEL enumeration. Both strategies are already applied in the dotnet/runtime repo.

Background material

From winnt.h SECURITY_IMPERSONATION_LEVEL:

// Impersonation Level
//
// Impersonation level is represented by a pair of bits in Windows.
// If a new impersonation level is added or lowest value is changed from
// 0 to something else, fix the Windows CreateFile call.
//

typedef enum _SECURITY_IMPERSONATION_LEVEL {
    SecurityAnonymous,
    SecurityIdentification,
    SecurityImpersonation,
    SecurityDelegation
    } SECURITY_IMPERSONATION_LEVEL, * PSECURITY_IMPERSONATION_LEVEL;

From .NET TokenImpersonationLevel:

namespace System.Security.Principal
{
    //
    // Summary:
    //     Defines security impersonation levels. Security impersonation levels govern the
    //     degree to which a server process can act on behalf of a client process.
    public enum TokenImpersonationLevel
    {
        None = 0,
        Anonymous = 1,
        Identification = 2,
        Impersonation = 3,
        Delegation = 4
    }
}
@forderud forderud changed the title DuplicateTokenEx ImpersonationLevel type mismatches DuplicateTokenEx DllImport argument mismatches Dec 31, 2023
@forderud forderud changed the title DuplicateTokenEx DllImport argument mismatches DuplicateTokenEx ImpersonationLevel argument mismatches Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant