📄 setsecurity.cpp
字号:
/**************************************************************************************************/
/* */
/* Copyright (C) 2003, James Antognini, antognini@mindspring.com. */
/* */
/**************************************************************************************************/
#define JARtnName "SetSecurity"
#define JARtnVer "1.01"
#include <comdef.h>
#include <assert.h>
#include "stdafx.h"
#include "wmirtns.h"
/**************************************************************************************************/
/* */
/* Set the interface security to allow the server to impersonate us. Omitting to do this will */
/* probably cause an "access denied" failure. */
/* */
/**************************************************************************************************/
HRESULT
SetSecurity(
IUnknown * pInterface, // Pointer to interface.
WCHAR * pUserid, // Pointer to userid or NULL.
WCHAR * pPassword // Pointer to password or NULL.
)
{
HRESULT hr;
do
{
COAUTHIDENTITY AuthIdentity;
DWORD AuthnSvc,
AuthzSvc,
AuthnLevel,
ImpLevel,
Capabilities;
WCHAR * pServerPrinName = NULL;
RPC_AUTH_IDENTITY_HANDLE pAuthHndl = NULL;
hr = CoQueryProxyBlanket( // Get current authentication information for interface.
pInterface,
&AuthnSvc,
&AuthzSvc,
&pServerPrinName,
&AuthnLevel,
&ImpLevel,
&pAuthHndl,
&Capabilities
);
if (FALSE==SUCCEEDED(hr)) // A problem?
{
ReportError(_T("SetSecurity(): CoQueryProxyBlanket"), hr);
break;
}
if (NULL==pUserid) // No userid?
{
AuthIdentity.User = NULL;
AuthIdentity.UserLength = 0;
AuthIdentity.Password = NULL;
AuthIdentity.PasswordLength = 0;
}
else
{
AuthIdentity.User = pUserid;
AuthIdentity.UserLength = wcslen(pUserid);
AuthIdentity.Password = pPassword;
AuthIdentity.PasswordLength = wcslen(pPassword);
}
AuthIdentity.Domain = NULL;
AuthIdentity.DomainLength = 0;
AuthIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
hr = CoSetProxyBlanket( // Change authentication information for interface, providing identity information and "echoing back" everything else.
pInterface, // Object to set.
AuthnSvc,
AuthzSvc,
pServerPrinName,
AuthnLevel,
ImpLevel,
&AuthIdentity,
Capabilities
);
if (FALSE==SUCCEEDED(hr)) // A problem?
{
ReportError(_T("SetSecurity(): CoSetProxyBlanket"), hr);
}
} while(0);
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -