Impersonation wont work to remote server

G

Guest

Hi
I am trying to develop an web application that should use netsh dhcp to show information about our dhcp scope. The problem is that our dhcp server is different from our IIS (iis6).
I am trying to do this command via impersonation but I can't get the permissons to be right. I constantly get permission denied.
Below are the code used to execute the command and impersonation, is there anyone who know how to solve thos problem?
Best Regards Henrik Alstersjö


<Code>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If LogonUser(Session("User"), "RD", Session("Passw"), 3, LOGON32_PROVIDER_DEFAULT, token) = True Then
Dim tomte As String
Dim oImpContext As System.Security.Principal.WindowsImpersonationContext
oImpContext = System.Security.Principal.WindowsIdentity.Impersonate(token)
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
Dim proc As New System.Diagnostics.Process()

proc.StartInfo.FileName = "netsh"
proc.StartInfo.Arguments = "dhcp server \\semldsw2dhc078 show scope"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
TextBox1.Text = proc.StandardOutput.ReadToEnd.ToString
proc.Close()
proc.Dispose()
oImpContext.Undo()
Else
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString)
TextBox1.Text = "Det gick fel"
End If

End Sub
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

Const LOGON32_LOGON_INTERACTIVE As Long = 2
Const LOGON32_LOGON_NETWORK As Long = 3
Const LOGON32_PROVIDER_DEFAULT As Long = 0
Const LOGON32_PROVIDER_WINNT50 As Long = 3
Const LOGON32_PROVIDER_WINNT40 As Long = 2
Const LOGON32_PROVIDER_WINNT35 As Long = 1

Dim token As IntPtr

</Code>
 
B

Benjamin Bittner

Hallo Alstersjo
Alstersjo said:
Hi
I am trying to develop an web application that should use netsh dhcp to
show information about our dhcp scope. The problem is that our dhcp server
is different from our IIS (iis6).
I am trying to do this command via impersonation but I can't get the
permissons to be right. I constantly get permission denied.
Below are the code used to execute the command and impersonation, is there
anyone who know how to solve thos problem?
Best Regards Henrik Alstersjö


<Code>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If LogonUser(Session("User"), "RD", Session("Passw"), 3,
LOGON32_PROVIDER_DEFAULT, token) = True Then
Dim tomte As String
Dim oImpContext As System.Security.Principal.WindowsImpersonationContext
oImpContext = System.Security.Principal.WindowsIdentity.Impersonate(token)
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.T
oString)
Dim proc As New System.Diagnostics.Process()

proc.StartInfo.FileName = "netsh"
proc.StartInfo.Arguments = "dhcp server \\semldsw2dhc078 show scope"
proc.StartInfo.UseShellExecute = False
proc.StartInfo.RedirectStandardOutput = True
proc.Start()
TextBox1.Text = proc.StandardOutput.ReadToEnd.ToString
proc.Close()
proc.Dispose()
oImpContext.Undo()
Else
Response.Write(System.Security.Principal.WindowsIdentity.GetCurrent().Name.T
oString)
TextBox1.Text = "Det gick fel"
End If

End Sub
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

Const LOGON32_LOGON_INTERACTIVE As Long = 2
Const LOGON32_LOGON_NETWORK As Long = 3
Const LOGON32_PROVIDER_DEFAULT As Long = 0
Const LOGON32_PROVIDER_WINNT50 As Long = 3
Const LOGON32_PROVIDER_WINNT40 As Long = 2
Const LOGON32_PROVIDER_WINNT35 As Long = 1

Dim token As IntPtr

</Code>

I think the problem could be that Diagnostics.Process.Start starts a process
in the security context of the parent process, which is "aspnet_wp.exe" i
think. there a several workarounds, im fighting with one right now (topic:
Calling CreateProcessWithLogonW).

regards benni
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top