Charles Wilson wrote:
> Karl M wrote:
>> Just a comment...keychain is pretty heavy for what you get in Cygwin. I had 
>> problems a long time ago with a slow laptop running XP SP2 with Cygwin 
>> windows taking a long time to open if I kicked off several at once, 
>> particularly at boot time.
>>
>> My solution was to launch ssh-agent as a service (one for each user that 
>> wants it). That service spawns the agent and updates the user environment in 
>> the registry so that other processes can find the ssh-agent process/socket. 
>> The advantages are that it is fast and the agent survives a logout (only 
>> rekey for a reboot is desired).
>>
>> I had thought about offering it as a package, but there was insufficient 
>> interest. Your are welcome to it if you are interested. It has been rock 
>> solid for years.
>
> That sounds like a useful alternative.
>
It is three bash script files and one C program (just compile it with gcc). The 
shell scripts (1) install the service, (2) are the service under cygrunsrv and 
(3) is the commands to add to your bash_profile. If you use a different shell, 
they will need syntax tweaking. The C program provides access to sending a 
Windows API call to broadcast a message for WM_SETTINGCHANGE. This is needed 
because the user can log in before the service is started in XP. I think that 
this all worked on WIN2k when last I tried it, but it has been a long time 
since I touched a WIN2k box. I have no experience with Vista :.).

Overall, it is fast and simple.

Enjoy,

...Karl

_________________________________________________________________
Express yourself wherever you are. Mobilize!
http://www.gowindowslive.com/Mobile/Landing/Messenger/Default.aspx?Locale=en-US?ocid=TAG_APRIL
#!/bin/bash
# secret-agent-service-install service-name user-name

if [ "~$1" = "~" ]; then
  echo A service name is required.
  exit 1
fi

if [ "~$2" = "~" ]; then
  echo A user name is required.
  exit 1
fi

echo Uninstalling the secret-agent service, $1.
cygrunsrv --remove $1

echo Adding the \"Log on as a Service\" right for $2.
editrights -a SeServiceLogonRight -u "$2"

echo Installing the secret-agent service, $1.
cygrunsrv --install $1 \
  --args '/bin/secret-agent-service' \
  --disp "Secret Agent $2" \
  --desc "Creates an ssh-agent process for $2." \
  --path '/bin/bash' \
  --shutdown \
  --user "$2"

echo Starting the secret-agent service, $1.
cygrunsrv --start $1
#!/bin/bash
# Launch the ssh-agent from a service so it survives logoff.

# When the service stops, kill the ssh-agent.
trap "ssh-agent -k;
  exit 0" TERM

# Clean up old files that may be left behind after a crash.
#   The file permissions make this safe to do in a multi-user
#   environment, but "/tmp" must be local to this host.
rm -rf /tmp/ssh-*

# Launch the ssh-agent.
eval $(ssh-agent)

# Provide the ssh-agent socket ID via the registry and broadcast
#   the change in case the user is logged before we finish.
#   Do not provide the ssh-agent PID to minimize the risk of
#   accidentally killing the ssh-agent.
regtool -s set /HKEY_CURRENT_USER/Environment/SSH_AUTH_SOCK $SSH_AUTH_SOCK
regtool remove /HKEY_CURRENT_USER/Environment/SSH_AGENT_PID
sendchenv

# Wait quietly until the service is stopped.
while true; do
  sleep 24h &
  wait
done
ssh-add -l >/dev/null 2>&1
if [ $? -eq 1 ]; then
  ssh-add
fi
// Notify all windows that environment variables may have changed.

#include <windows.h>

int main()
{
  DWORD dwReturnValue;
  
  if (SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
      (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue))
    return 0;
  else
    return 1;
}
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to