Impersonate user (seteuid/setegid for Windows)  
Author Message
tanis15063





PostPosted: Visual C++ Language, Impersonate user (seteuid/setegid for Windows) Top

Basically, I'm new to these forums, so I apologize if I am posting this to the wrong place.

I am currently porting over code that was written for Linux that utilized the seteuid and setegid functions.  These functions allow a high privileged user (root) to impersonate a user/group when trying to run certain system-level functions.

Basically is there something like these functions that exist in Visual C++    I'd like to be able to call functions, like requesting to delete a file, while impersonating a user.  I'd like to do this without having to run the process as that user.  This way, I could perform the same function over and over using different user profiles, if needed.

Please let me know if this makes sense and if there is a way to go about doing this. 

Thanks!


Visual C++6  
 
 
Kenny Kerr





PostPosted: Visual C++ Language, Impersonate user (seteuid/setegid for Windows) Top

Hi there,

Impersonation on Windows is achieved using the ImpersonateLoggedOnUser function. This function accepts a token representing the logon session of the user to impersonate on the current thread. You can create a logon session using the LogonUser function or retrieve it from the network layer in a server application. Be sure to call the RevertToSelf function after calling ImpersonateLoggedOnUser to terminate the impersonation.

Cheers,

Kenny Kerr
Microsoft MVP

http://weblogs.asp.net/kennykerr/


 
 
sushmsn





PostPosted: Visual C++ Language, Impersonate user (seteuid/setegid for Windows) Top

Hi
I have the following problem.
I have a process running in Local System user and in that process i want to log in as a user say "user1" and then run a function to delete the cookies for that particular user. I tired the way you suggested above.
For example i did the following
  • LogOnUser( as user1)
  • impersonate user
  • call delete cookies function.
I expected the code to delete the cookies of the user user1. But it didnt. It was not able to find the cookies. But when i do the following.
  • LogOnUser( as user1)
  • impersonate user
  • spwan a process that deletes the cookies.
This was i was able to implement it. I dont know what is the difference but the first method doesnt work. I dont want to spawwn a process. I just want to execute a delete cookies function. Is it possible

Thanks,
Sushmsn



 
 
sushmsn





PostPosted: Visual C++ Language, Impersonate user (seteuid/setegid for Windows) Top

Hi
I am looking for solution for similar problem. Please let me know in case you have solved the issue

Thanks