in reply to suidperl/sudo function-alike on Win32

Here is the only way I know to do it. You write your program in two parts. One part runs as a service with access to the file. The other part is a client, which connects to the service via a named pipe. You can use SECURITY_SQOS_PRESENT flag so that the service can verify (or even impersonate) the identity of the user running the client. The client sends requests to the service which then executes them.

I wrote this in C once to try it out. I have the source code at work which I can send you if you're interested. I don't think all the functions I used have been implemented in the Win32 modules.

For some time I have wanted to write a module which would perform this kind of automatically-authenticated IPC connection, with variants for different OSes. On some *nix systems there is a SO_PEERCRED socket option to identify a local connection. You can also use a convoluted protocol where the client proves his identity by performing some actions in the file system. But, alas, I haven't gotten around to doing it.

This style of programming is somewhat more secure than setuid or sudo. E.g. it's less susceptible to manipulation of environment variables. Also, with setuid programs, if you want to use a cryptographic key you have to store it in the file system and hope that file system security and obfuscation protect it. With the authenticated-IPC style, the (trusted) person who starts the process can type in a password once and the key can be kept in memory.

  • Comment on Re: suidperl/sudo function-alike on Win32