I am trying to use RpcImpersonateClient, within a servie, to determine if
the caller has the permissions neccessary to utilize a RPC function call (by
looking up his SID/Username and checking membership in specific groups).
Below is a peice of code that I tried. The API all succeeds, but I get the
following information from the next function calls.
This is while the service is running and the SYSTEM account and interacts
with the desktop.
I am (SYSTEM) NT AUTHORITY\SYSTEM [S-1-5-18]
then ...
Now, I am (SYSTEM) \ []
Who am I at this point and how (or can I) check the calling user's
permissions/group membership?
Thanks,
Mark
//---------------------------------------------------------
GetUserName( szBuffer, &nSize );
GetProcessOwner(getpid(),
szUserName,
szDomainName,
szUserSID);
wsprintf(szTemp, "I am (%s) %s\\%s [%s]", szBuffer, szDomainName,
szUserName, szUserSID);
#if _DEBUG
printf("%s\n", szTemp);
MessageBox(0, szTemp, "SMT Service", 0);
#else
WriteLog(szTemp, 0);
#endif
status = RpcImpersonateClient(Binding);
if (status != RPC_S_OK)
{
return(RPC_S_ACCESS_DENIED);
}
GetUserName( szBuffer, &nSize );
GetProcessOwner(getpid(),
szUserName,
szDomainName,
szUserSID);
wsprintf(szTemp, "Now, I am (%s) %s\\%s [%s]", szBuffer, szDomainName,
szUserName, szUserSID);
#if _DEBUG
printf("%s\n", szTemp);
MessageBox(0, szTemp, "SMT Service", 0);
#else
WriteLog(szTemp, 0);
#endif
//---------------------------------------------------------
> GetUserName( szBuffer, &nSize );
I'll bet that your second call to GUN() returns an error because you
didn't re-initialize nSize to the buffer size.
Your second GetProcessOwner() call likely fails because the impersonated
user doesn't have permission to open your process (this is an educated
guess, but from your getpid() call I am sure you open the process
instead of using a pre-opened handle).
--
Cheers,
Felix.
If you post a reply, kindly refrain from emailing it, too.
Note to spammers: fel...@mvps.org is my real email address.
No anti-spam address here. Just one comment: IN YOUR FACE!