Re: Impersonation and accessing Windows file share



That worked!!!!!!!!!!!! I changed the Const LOGON32_LOGON_NETWORK = 3 to
LOGON32_LOGON_NETWORK_CLEARTEXT = 8.
Thank you thank you thank you! :-)

"Joe Kaplan (MVP - ADSI)" wrote:

I think I see your problem. You are using LOGON32_LOGON_NETWORK, but if you
read the docs for LogonUser in MSDN carefully, you'll see that this type of
logon doesn't have network credentials. You probably should switch to
LOGON32_LOGON_NETWORK_CLEARTEXT.

Joe K.

"Julie" <hermie@xxxxxxxxxxxxx> wrote in message
news:CA883E64-1822-48B7-9B7D-3D6859FEC262@xxxxxxxxxxxxxxxx
I can see on the Event log on my web server that the service account is
logging in successfully.
However, on the file server, the event log shows that the user is
connecting
to the file server as NT AUTHORITY\ANONYMOUS LOGON. Interesting.

My Logon code looks like this:
Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal
lpszUsername As [String], _
ByVal lpszDomain As [String], ByVal lpszPassword As [String], _
ByVal dwLogonType As Integer, ByVal dwLogonProvider As Integer,
_
ByRef phToken As IntPtr) As Boolean


Private Function Logon() As WindowsIdentity
Dim handle As IntPtr = New IntPtr(0)
handle = IntPtr.Zero

Const LOGON32_LOGON_NETWORK As Integer = 3
Const LOGON32_PROVIDER_DEFAULT As Integer = 0

Dim logonSucceeded As Boolean = LogonUser(Me.sUsername, Me.sDomain,
Me.sPassword, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, handle)

If Not logonSucceeded Then
Dim errorCode As Integer = Marshal.GetLastWin32Error
Throw New Exception("User logon failed. Error number: " &
errorCode)
Exit Function
End If

Dim winIdentity As WindowsIdentity = New WindowsIdentity(handle)
CloseHandle(handle)
Return winIdentity
End Function




"Joe Kaplan (MVP - ADSI)" wrote:

If you enable logon event auditing on the file server, what does the
logon
failure say on that end? That may give you some clues.

Also, when you called LogonUser, what type of logon did you do? You need
to
make sure you use one that gives you network credentials.

Joe K.

"Julie" <hermie@xxxxxxxxxxxxx> wrote in message
news:674C986D-5107-420D-A65C-3FC8B440766B@xxxxxxxxxxxxxxxx
I use that code and I can confirm that impersonation is impersonating
the
correct user. And yes, I can access the file share as the system
account -
thanks for checking. :-)


"Luke Zhang [MSFT]" wrote:

Hello,

First, you can use the following code to determine what user the
thread
is
executing as:

System.Security.Principal.WindowsIdentity.GetCurrent().Name

Also, you if logon as the System account on the server, can you access
the
Windows file share like "\\Myserver\Myshare"?

Regards,

Luke Zhang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader
so
that others may learn and benefit from your issue.
==================================================

(This posting is provided "AS IS", with no warranties, and confers no
rights.)








.



Relevant Pages

  • Re: Impersonation and accessing Windows file share
    ... I can see on the Event log on my web server that the service account is ... However, on the file server, the event log shows that the user is connecting ... My Logon code looks like this: ... Dim handle As IntPtr = New IntPtr ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: LogOnUser with Smart Card Credentials
    ... from the Windows logon dialog and serves our application only). ... call LogonUser with the credentials provided in the dialog. ... The card needs to be present to verify the PIN and also to obtain a token. ...
    (microsoft.public.platformsdk.security)
  • Re: LogOnUser with Smart Card Credentials
    ... from the Windows logon dialog and serves our application only). ... call LogonUser with the credentials provided in the dialog. ... The card needs to be present to verify the PIN and also to obtain a token. ...
    (microsoft.public.platformsdk.security)
  • Re: Remote system access
    ... >> That Service at some point does a LogonUser and ImpersonateLoggedOnUser ... >> to log on as a service, if the SERVICE logon type is selected. ... It is some box in the network, ... >> permissions or rights for the DsGetDcName to successfully be executed by ...
    (microsoft.public.win32.programmer.networks)
  • Re: Impersonation and accessing Windows file share
    ... logon doesn't have network credentials. ... However, on the file server, the event log shows that the user is ... Private Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal ... Dim handle As IntPtr = New IntPtr ...
    (microsoft.public.dotnet.framework.aspnet.security)