Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Impersonation - LogonUser() problem

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to Impersonate a user thru code written in VB in an ASP page, so that I can connect to a Samba server on a Linux system for storing files.
The function LogonUSer(Win32 API call) fails when this is done. But, when the same code is run in VB, it works.
Following are the things I have tried:

1) Removing the Anonymous Access from directory security tab of the Website in IIS. This works but we cannot afford it as
we will be using Microsoft Challenge/Response services.
2) Adding the DLL that has Impersonation function to COM+/MTS. It doesnot work.
3) Performing Step2 and adding the Administrator security context to the Package. It doesnot work.
4) We have tried the suggestions given in query Q248187, Q223334 in MSDN and microsoft support site. They don't seem to work either.

Could someone help!
The basic idea behind the whole exercise is to move away from the Microsoft platform to Linux.


Code we used:

ASP
~~~
<%
dim o, f
set o = Server.CreateObject(&quot;Crypto.clsCrypto&quot;)
set f = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

o.Impersonate &quot;fileuser&quot;,&quot;samba&quot;,&quot;system1234&quot;
f.CreateFolder &quot;\\samba\permfiles\12&quot;
f.CreateTextFile &quot;\\samba\permfiles\12\new.txt&quot;
o.EndImpersonate
%>


VB Component COde:
~~~~~~~~~~~~~~~~~~
Private Declare Function ImpersonateLoggedOnUser Lib &quot;advapi32.dll&quot; (ByVal hToken As Long) As Long
Private Declare Function LogonUser Lib &quot;advapi32.dll&quot; Alias &quot;LogonUserA&quot; (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As Long) As Long
Private Declare Function RevertToSelf Lib &quot;advapi32.dll&quot; () As Long

Public Function Impersonate(ByVal sUserName As String, ByVal sDomain As String, ByVal sPassword As String) As Boolean
Dim Result As Long
Dim hToken As Long
Dim lngLastErr As Long

Call RevertToSelf
Result = LogonUser(sUserName, sDomain, sPassword, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, hToken)
Result = ImpersonateLoggedOnUser(hToken)
End Function


Thanks,
Gautam
 
Why not map the NT UID's to unix UID's on the Samba server? Sorry, I'm not a codemonkey, but it's the first thing to come to mind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top