Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Windows not allow WinSock to be started while impersonating another user

Using my own program or others I can't get winsock to run when calling if the process is created with CreateProcessWithLogonW or CreateProcessAsUserW. It returns this error when I create the socket:

WSAEPROVIDERFAILEDINIT 10106

Service provider failed to initialize.

The requested service provider could not be loaded or initialized.

This error is returned if either a service provider's DLL could not be loaded (LoadLibrary failed) or the provider's WSPStartup or NSPStartup function failed

.

However, WSAStartup seems to go w/o an error. Just creating the socket with WSASocket returns this.

UPDATE:

Errors:

LoadUserProfile: Error Code 2. Can't find file specified

AdjustTokenPrivs: Error Code 5. Access Denied

like image 579
Christopher Tarquini Avatar asked Oct 12 '09 14:10

Christopher Tarquini


2 Answers

I encountered exactly the same problem and it was due to the environment (!): Apparently WinSock expects a valid SystemRoot environment variable to be set. In my case I was calling CreateProcess() by specifying only one environment variable specific to my app (without inheriting the caller's environment), and it was failing.

Check that you created your process by either passing NULL to lpEnvironment to inherit the caller's environment, or specify a valid SystemRoot environment variable.

Completely undocumented AFAIK, but it worked for me.

like image 172
Nico Avatar answered Oct 06 '22 10:10

Nico


Perhaps the user you executed the process with isn't allowed to use the TCP/IP stack?

Try to start the application with an administrator user that is not your own account.

like image 20
Yannick Motton Avatar answered Oct 06 '22 10:10

Yannick Motton