Emulates Unix sudo in cygwin.
You can use this like::
$ sudo vim /etc/hosts
$ sudo cp foo.txt /cygdrive/c/Program Files/
$ suco cygstart cmd # open elevated standard command prompt
$ sudo cygstart regedit
$ sudo # just invoke elevated shell
This might be handy if you are running cygwin on Vista or Windows 7 with UAC. By this program, you can run processes as an administator, from normal, non-elevated cygwin shell.
UAC Elevation is usually done through UI prompt for good reasons. By this program, you can run elevated process without UI prompt that does not go along well with Cygwin shell environment. However, it also means that you are weakening the system in terms of security.
This is in fact a client/server application.
It looks as if the child process is running in the current terminal. However, in fact, it's invoked by the server, and running remotely (though "remote" is in the same PC).
You must launch a python script named sudoserver.py beforehand, in desired privileges. If you want function like "Run as administrator", just run sudoserver as administrator. For this purpose, Windows built-in Task Scheduler is handy.
sudoserver.py opens a listening port 127.0.0.1:7070 (by defaults), then sits and wait for connections from sudo.
sudo, when invoked, connects to the sudoserver. Then it sends it's command line arguments, environment variables, current working directory, and terminal window size, to the sudoserver.
When sudoserver accepts connection from sudo, sudoserver forks a child process with pty, set up environments, current working directory or something, then execute the process.
The child process is spawned by the sudoserver, therefore it runs in the privileges same as the server.
And, as the child process runs in a pty, it acts as if running in ordinary terminals. Therefore you can run cygwin's interactive console-based program like vim or less.
After execution, sudo and sudoserver bridges user's tty and the process I/O.
Both sudo and sudoserver.py is written in python, therefore you need to install Python.
Also, you need Python module named greenlet, and eventlet. These are not packaged in cygwin, therefore you must manually install them.
$ python setup.py install
PORT = 7070
$ /path/to/sudoserver.py
$ sudo ls -l
With argument "-nw" is specified, sudoserver hides it's console window.
sudoserver sets an aditional environment variable "ELEVATED_SHELL" when spawing child processes. You can use this variable for changing your elevated shell prompt (PS1), to see which environment you are in. For example, you can put the following in your .bashrc::
case $ELEVATED_SHELL in
1) PS1='\[\033[31m\][\u@\h]#\[\033[0m\] ';; # elevated
*) PS1='\[\033[32m\][\u@\h]$\[\033[0m\] ';;
esac