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

Feature request: PAUTHZ_CLIENT_CONTEXT_HANDLE in functions should be a pointer or &mut AUTHZ_CLIENT_CONTEXT_HANDLE #1004

Closed
Zerowalker opened this issue Jul 21, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@Zerowalker
Copy link

Motivation

Prevents having to cast to *const/mut isize and makes it consistent with the functions.

say: https://docs.microsoft.com/en-us/windows/win32/api/authz/nf-authz-authzinitializecontextfromsid
If i am not mistaken it will always give you a AUTHZ_CLIENT_CONTEXT_HANDLE at the out parameter phAuthzClientContext.
And if so it doesn't make much sense for it to be a neutral isize, actually find it weird it's that and not c_void though.
Looking at the metadata it looks like it's seens as a *AUTHZ_CLIENT_CONTEXT_HANDLE.

Drawbacks

If it's not actually not always a &mut/cont AUTHZ_CLIENT_CONTEXT_HANDLE and some other data can be written in the/some functions then the typing will break that.

Rationale and alternatives

The current design makes you able to pass any isize (in a nutshell any HANDLE.0) which makes it "confusing" for no reason.
If it's just a single type, then it's better to just utilize that to make rust do it's thing without extra steps.

Additional context

Current art is kinda like this:

    let mut client_context = AUTHZ_CLIENT_CONTEXT_HANDLE::default();
            unsafe {
                AuthzInitializeContextFromSid(
                    0,
                    ...,
                    ...,
                    null_mut(),
                    LUID::default(),
                    null_mut(),
                    &mut client_context.0,
                )
            }
            .ok().unwrap();
@Zerowalker Zerowalker added the enhancement New feature or request label Jul 21, 2022
@kennykerr
Copy link
Contributor

The metadata appears to lose the type of its final out parameter:

[DllImport("AUTHZ", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public unsafe static extern BOOL AuthzInitializeContextFromSid([In] uint Flags, [In] PSID UserSid, [In] AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager, [Optional][In] LARGE_INTEGER* pExpirationTime, [In] LUID Identifier, [Optional][In] void* DynamicGroupArgs, [Out] IntPtr* phAuthzClientContext);

If I'm not mistaken, the function should just use the handle type as its final out parameter as the original header does:

AUTHZAPI
BOOL
WINAPI
AuthzInitializeContextFromSid(
    _In_      DWORD                         Flags,
    _In_      PSID                          UserSid,
    _In_      AUTHZ_RESOURCE_MANAGER_HANDLE hAuthzResourceManager,
    _In_opt_  PLARGE_INTEGER                pExpirationTime,
    _In_      LUID                          Identifier,
    _In_opt_  PVOID                         DynamicGroupArgs,
    _Out_     PAUTHZ_CLIENT_CONTEXT_HANDLE  phAuthzClientContext
    );

Thanks for reporting! I'll transfer to the win32metadata repo for a fix.

@kennykerr kennykerr transferred this issue from microsoft/windows-rs Jul 21, 2022
@kennykerr kennykerr added bug Something isn't working and removed enhancement New feature or request labels Jul 21, 2022
@Zerowalker
Copy link
Author

Oh, was looking at the wrong place, probably cause i looked at the type itself (which doesn't exist in Rust),
and it came up in the meta.

Glad i could help.

@mikebattista mikebattista self-assigned this Aug 1, 2022
@mikebattista
Copy link
Contributor

Windows.Win32.Security.Authorization.Apis.AuthzInitializeContextFromToken : phAuthzClientContext...IntPtr* => AUTHZ_CLIENT_CONTEXT_HANDLE*
Windows.Win32.Security.Authorization.Apis.AuthzInitializeContextFromSid : phAuthzClientContext...IntPtr* => AUTHZ_CLIENT_CONTEXT_HANDLE*
Windows.Win32.Security.Authorization.Apis.AuthzInitializeContextFromAuthzContext : phNewAuthzClientContext...IntPtr* => AUTHZ_CLIENT_CONTEXT_HANDLE*
Windows.Win32.Security.Authorization.Apis.AuthzInitializeCompoundContext : phCompoundContext...IntPtr* => AUTHZ_CLIENT_CONTEXT_HANDLE*
Windows.Win32.Security.Authorization.Apis.AuthzAddSidsToContext : phNewAuthzClientContext...IntPtr* => AUTHZ_CLIENT_CONTEXT_HANDLE*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants