Export (0) Print
Expand All

AcquireCredentialsHandle (Negotiate) function

The AcquireCredentialsHandle (Negotiate) function acquires a handle to preexisting credentials of a security principal. This handle is required by the InitializeSecurityContext (Negotiate) and AcceptSecurityContext (Negotiate) functions. These can be either preexisting credentials, which are established through a system logon that is not described here, or the caller can provide alternative credentials.

Note  This is not a "log on to the network" and does not imply gathering of credentials.

Syntax


SECURITY_STATUS SEC_Entry AcquireCredentialsHandle(
  _In_   SEC_CHAR *pszPrincipal,
  _In_   SEC_CHAR *pszPackage,
  _In_   ULONG fCredentialUse,
  _In_   PLUID pvLogonID,
  _In_   PVOID pAuthData,
  _In_   SEC_GET_KEY_FN pGetKeyFn,
  _In_   PVOID pvGetKeyArgument,
  _Out_  PCredHandle phCredential,
  _Out_  PTimeStamp ptsExpiry
);

Parameters

pszPrincipal [in]

A pointer to a null-terminated string that specifies the name of the principal whose credentials the handle will reference.

Note  If the process that requests the handle does not have access to the credentials, the function returns an error. A null string indicates that the process requires a handle to the credentials of the user under whose security context it is executing.

pszPackage [in]

A pointer to a null-terminated string that specifies the name of the security package with which these credentials will be used. This is a security package name returned in the Name member of a SecPkgInfo structure returned by the EnumerateSecurityPackages function. After a context is established, QueryContextAttributes (Negotiate) can be called with ulAttribute set to SECPKG_ATTR_PACKAGE_INFO to return information on the security package in use.

To successfully call this function using the Schannel SSP, set this parameter to "Negotiate".

fCredentialUse [in]

A flag that indicates how these credentials will be used. This parameter can be one of the following values.

ValueMeaning
SECPKG_CRED_AUTOLOGON_RESTRICTED
0x00000010

The security does not use default logon credentials or credentials from Credential Manager.

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  This value is not supported.

SECPKG_CRED_BOTH

Validate an incoming credential or use a local credential to prepare an outgoing token. This flag enables both other flags.

SECPKG_CRED_INBOUND

Validate an incoming server credential. Inbound credentials might be validated by using an authenticating authority when InitializeSecurityContext (Negotiate) or AcceptSecurityContext (Negotiate) is called. If such an authority is not available, the function will fail and return SEC_E_NO_AUTHENTICATING_AUTHORITY. Validation is package specific.

SECPKG_CRED_OUTBOUND

Allow a local client credential to prepare an outgoing token.

SECPKG_CRED_PROCESS_POLICY_ONLY
0x00000020

The function processes server policy and returns SEC_E_NO_CREDENTIALS, indicating that the application should prompt for credentials.

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  This value is not supported.

 

pvLogonID [in]

A pointer to a locally unique identifier (LUID) that identifies the user. This parameter is provided for file-system processes such as network redirectors. This parameter can be NULL.

pAuthData [in]

A pointer to package-specific data. This parameter can be NULL, which indicates that the default credentials for that package must be used. To use supplied credentials, pass a PSEC_WINNT_AUTH_IDENTITY_OPAQUE structure returned from a previous call to the SspiPromptForCredentials function.

Windows Server 2008, Windows Vista, Windows Server 2003, and Windows XP:  The PSEC_WINNT_AUTH_IDENTITY_OPAQUE type and the SspiPromptForCredentials function are not supported. To use supplied credentials, pass a pointer to either a SEC_WINNT_AUTH_IDENTITY or SEC_WINNT_AUTH_IDENTITY_EX structure that includes those credentials.

The RPC run time passes whatever was provided in RpcBindingSetAuthInfo.

When using the Negotiate package, the maximum character lengths for user name, password, and domain are 256, 256, and 15, respectively.

pGetKeyFn [in]

This parameter is not used and should be set to NULL.

pvGetKeyArgument [in]

This parameter is not used and should be set to NULL.

phCredential [out]

A pointer to a CredHandle structure to receive the credential handle.

ptsExpiry [out]

A pointer to a TimeStamp structure that receives the time at which the returned credentials expire. The value returned in this TimeStamp structure depends on the security package. The security package must return this value in local time.

Return value

If the function succeeds, the function returns SEC_E_OK.

If the function fails, it returns one of the following error codes.

Return codeDescription
SEC_E_INSUFFICIENT_MEMORY

There is not enough memory available to complete the requested action.

SEC_E_INTERNAL_ERROR

An error occurred that did not map to an SSPI error code.

SEC_E_NO_CREDENTIALS

No credentials are available in the security package.

SEC_E_NOT_OWNER

The caller of the function does not have the necessary credentials.

SEC_E_SECPKG_NOT_FOUND

The requested security package does not exist.

SEC_E_UNKNOWN_CREDENTIALS

The credentials supplied to the package were not recognized.

 

Remarks

The AcquireCredentialsHandle (Negotiate) function returns a handle to the credentials of a principal, such as a user or client, as used by a specific security package. This can be the handle to preexisting credentials, or the function can create a new set of credentials and return it. This handle can be used in subsequent calls to the AcceptSecurityContext (Negotiate) and InitializeSecurityContext (Negotiate) functions.

In general, AcquireCredentialsHandle (Negotiate) does not allow a process to obtain a handle to the credentials of other users logged on to the same computer. However, a caller with SE_TCB_NAME privilege has the option of specifying the logon identifier (LUID) of any existing logon session token to get a handle to that session's credentials. Typically, this is used by kernel-mode modules that must act on behalf of a logged-on user.

A package might call the function in pGetKeyFn provided by the RPC run-time transport. If the transport does not support the notion of callback to retrieve credentials, this parameter must be NULL.

For kernel mode callers, the following differences must be noted:

  • The two string parameters must be Unicode strings.
  • The buffer values must be allocated in process virtual memory, not from the pool.

When you have finished using the returned credentials, free the memory used by the credentials by calling the FreeCredentialsHandle function.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Sspi.h (include Security.h)

Library

Secur32.lib

DLL

Secur32.dll

Unicode and ANSI names

AcquireCredentialsHandleW (Unicode) and AcquireCredentialsHandleA (ANSI)

See also

SSPI Functions
AcceptSecurityContext (Negotiate)
InitializeSecurityContext (Negotiate)
FreeCredentialsHandle

 

 

Community Additions

ADD
Show:
© 2014 Microsoft