大网数据广告活动
网络与域名解析

Writing an Authenticated SSPI Server

· 52CE 我爱测

Before authenticated communication can take place between the client and server programs, the server must register its authentication information.

Before authenticated communication can take place between the client and server programs, the server must register its authentication information. In particular, the server must register its principal name and specify the authentication service it uses. For more information on principal names, see Principal Names. For details about authentication services, see Authentication Services.

To register its authentication information, servers call the RpcServerRegisterAuthInfo function. Pass a pointer to the principal name as the value of the first parameter. Set the second parameter to a constant indicating the authentication service that the application will use. For a description of authentication services, see Authentication-Service Constants.

The server may also pass the address of a key acquisition function as the value of the third parameter. See Key Acquisition Functions. To use the default key acquisition function for the selected authentication service, set the third parameter to NULL. The last parameter to the RpcServerRegisterAuthInfo function is a pointer data to pass to the key acquisition function, if you provide a key acquisition function. A call to RpcServerRegisterAuthInfo is shown in the following code fragment.

dwStatus = DsMakeSpn(
    "ldap",
    "ServerName.domain.com",
    NULL,
    0,
    NULL,
    &pcSpnLength,
    pszSpn);

rpcStatus = RpcServerRegisterAuthInfo (
    psz,                                   // Server principal name
    RPC_C_AUTHN_GSS_NEGOTIATE,             // Authentication service
    NULL,                                  // Use default key function
    NULL);                                 // No arg for key function

In addition, the server may provide the RPC run-time library with an authorization function. To set an authorization function, call the RpcMgmtSetAuthorizationFn function.

The server portion of a distributed application can call the function RpcBindingInqAuthClient or RpcBindingInqAuthClientEx to query a binding handle for authentication information.

If your server registers with a security support provider, client calls with invalid credentials will not be dispatched. However, calls with no credentials will be dispatched. There are three ways to prevent this from happening:

  • Register the interface using RpcServerRegisterIfEx, with a security callback function; this will cause the RPC run-time library to automatically reject unauthenticated calls to that interface. Registering a callback function is compatible with other methods of checking access credentials; the callback function can itself call the RpcImpersonateClient, RpcGetAuthorizationContextForClient, or RpcBindingInqAuthClientEx functions, or others. However, these functions cannot use the arguments passed to the function, as they are not unmarshalled at that point.

Important: Registering the interface using RpcServerRegisterIfEx with a security callback function is the most heavily recommended method of checking client credentials.

  • Call RpcBindingInqAuthClient to determine the security level that the client is using. Your stub can then return an error if the client is unauthenticated.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。