GetUserName() in extension dll
Hi Kevin,
GetUserName returns the name associated with the thread that calls the
function. If there is an impersonation token on the thread, then you'll get
the name of the impersonated user. If there is no impersonation happening,
then you'll get the name associated with what the process is running.
IIS will impersonate the authenticated user just before calling into
HttpExtensionProc or a completion that you specified with
HSE_REQ_IO_COMPLETION. So, in this case, you'll get the authenticated user.
If the your ISAPI has done something to get rid of the token, say called
RevertToSelf, then you'll get the name associated with whatever process is
hosting your ISAPI.
Also, if you create any new threads from your ISAPI - even while
impersonating the authenticated user - those threads will not automatically
impersonate. So, if you call GetUserName from one of those threads, you'll
get the hosting process again.
Finally, if you are calling GetUserName from inside a COM component hosted
by your ISAPI, there are many possible results, based on the threading model
of the component and how you CoInitialized. It is deterministic, but if you
are interested in following up on it, it's a very COM-centric topic.
Basically in any case where COM is do***ented to use a proxy interface, the
component will run as the process user. In any case where COM uses a direct
interface, the impersonation token from the calling thread will continue to
apply.
My advice is to play with it. Calling GetUserName from different points in
an ISAPI extension and logging the result or dumping it to debug output, is
an excellent introductory lesson into how authentication works in an ISAPI.
I hope that this helps,
-Wade A. Hilmo,
-Microsoft
|