I am trying to invoke an interface with a different username / password, like this:
wchar_t* bwusername = L"username";
wchar_t* bwpassword = L"password";
wchar_t* bwdomain = L"domain.local";
authidentity = malloc(sizeof(COAUTHIDENTITY));
authidentity->User = bwusername;
authidentity->Password = bwpassword;
authidentity->Domain = bwdomain;
authidentity->UserLength = wcslen(authidentity->User);
authidentity->PasswordLength = wcslen(authidentity->Password);
authidentity->DomainLength = wcslen(authidentity->Domain);
authidentity->Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
COAUTHINFO* authInfo = malloc(sizeof(COAUTHINFO));
authInfo->dwAuthnSvc = RPC_C_AUTHN_WINNT;
authInfo->dwAuthzSvc = RPC_C_AUTHZ_NONE;
authInfo->pwszServerPrincName = NULL;
authInfo->dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
authInfo->dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
authInfo->pAuthIdentityData = authidentity;
authInfo->dwCapabilities = EOAC_NONE;
COSERVERINFO* srvinfo = malloc(sizeof(COSERVERINFO));;
srvinfo->dwReserved1 = 0;
srvinfo->dwReserved2 = 0;
srvinfo->pwszName = bwtarget;
srvinfo->pAuthInfo = authInfo;
CoInitialize(NULL);
CLSID clsid;
CLSIDFromString(L"SomeCLSID", &clsid);
IID ApplicationIID;
IIDFromString(L"SomeApplicationIID", &ApplicationIID);
MULTI_QI mqi[1] = { &ApplicationIID, NULL, 0 };
CoCreateInstanceEx(&clsid, NULL, CLSCTX_REMOTE_SERVER, srvinfo, 1, mqi);
//This call fails
((IDispatchVtbl*)(mqi->pItf->lpVtbl))->Invoke(mqi->pItf, (LONG)4, &IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYGET, &dp, vDocIfc, NULL, 0);
The last call fails with error code 0x80070005. However running the same code under the usercontext I am filling the authidentity with succeeds.
What am I missing here? It seems like the code ignores the authidentity.
Also note that I skipped the error handling, so that the code stays clean.