Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Software > Activex Programming Control Webwiz > Need help on Ac...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 78 of 174
Post > Topic >>

Need help on ActiveX control permissions

by joao.maia@[EMAIL PROTECTED] (Joao Maia) Nov 12, 2004 at 07:48 AM

Hi there,

I have an ActiveX control running on a web page that needs to access a
shared folder with a given set of user credentials which is different
than the ones of the user that is running the control. That is:

User A is running the page on his IE browser, so the ActiveX control
on the page is running with User A credentials. However the control
needs to access a file on a folder, but only User B has permissions to
access that folder, so the ActiveX control needs to impersonate User B
and access the file while impersonating User B.

Does anyone know of a way to do this ? I tried using the advapi32.dll
API calls to LogonUser and ImpersonateLoggedOnUser on the ActiveX
control and I do manage to impersonate User B but when I try to access
the file it's as if the control is running with User A and no
impersonation took place (even though a call to GetUserName of the
same advapi32.dll while impersonating returns User B).

Here's some of the code of the ActiveX control... Maybe you guys can
help me figure out if something's wrong with it or if it just can't be
done...

Cheers,

Joao Maia

-------------------------------------------------------------------------

Private Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function LogonUser Lib "advapi32.dll" Alias
"LogonUserA" (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 ImpersonateLoggedOnUser Lib "advapi32.dll"
(ByVal hToken As Long) As Long

Private Declare Function RevertToSelf Lib "advapi32.dll" () As Long

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As
Long) As Long

Private Const LOGON32_LOGON_INTERACTIVE = 2
Private Const LOGON32_PROVIDER_DEFAULT = 0

Public Sub Logon(ByVal strAdminUser As String, ByVal strAdminPassword
As String, ByVal strAdminDomain As String)
    Dim lngTokenHandle, lngLogonType, lngLogonProvider As Long
    Dim blnResult As Boolean
    
    lngLogonType = LOGON32_LOGON_INTERACTIVE
    lngLogonProvider = LOGON32_PROVIDER_DEFAULT
    
    blnResult = RevertToSelf()
    
    blnResult = LogonUser(strAdminUser, strAdminDomain,
strAdminPassword, _
                                         lngLogonType,
lngLogonProvider, _
                                         lngTokenHandle)
    
    blnResult = ImpersonateLoggedOnUser(lngTokenHandle)
    CloseHandle (lngTokenHandle)
    
    LoadUserName
End Sub

Public Sub Logoff()
    Dim blnResult As Boolean
    blnResult = RevertToSelf()
    
    LoadUserName
End Sub

Public Function GetUser() As String
    GetUser = sUser
End Function

Private Sub LoadUserName()
    sUser = String(100, Chr$(0))
    GetUserName sUser, 100
    sUser = Left$(sUser, InStr(sUser, Chr$(0)) - 1)
End Sub

Private Sub Class_Initialize()
    LoadUserName
End Sub
 




 1 Posts in Topic:
Need help on ActiveX control permissions
joao.maia@[EMAIL PROTECTE  2004-11-12 07:48:51 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 19:14:53 CST 2008.