From 695ef3f0f34641191fae3c7ef8f4e01dd6d3210d Mon Sep 17 00:00:00 2001 From: PHO Date: Tue, 24 Mar 2009 14:15:07 +0900 Subject: [PATCH 1/1] Initial revision --- Makefile | 10 ++++++ ssh-agent-manager | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Makefile create mode 100755 ssh-agent-manager diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..154330d --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +prefix = /usr/local +bindir = $(prefix)/bin + +all: + +install: + install -d $(DESTDIR)$(bindir) + install ssh-agent-manager $(DESTDIR)$(bindir) + +.PHONY: all install diff --git a/ssh-agent-manager b/ssh-agent-manager new file mode 100755 index 0000000..8458522 --- /dev/null +++ b/ssh-agent-manager @@ -0,0 +1,85 @@ +#!/usr/bin/perl +# ----------------------------------------------------------------------------- +# Esta programa envuelve la ssh-agent. Devuelve los mismos pid y socket siemple +# durante la ssh-agent está viva. +# ----------------------------------------------------------------------------- +# No puede hacer `ssh-agent-manager '. +# ----------------------------------------------------------------------------- +use strict; +use warnings; +use IO::File; + +# Esta programa no dedice el tipo de shell usa usted. +# Lo fije siemple. +my $csh_mode; +my $bsh_mode; +foreach my $arg (@ARGV) { + if ($arg eq '-c') { + $csh_mode = 1; + } + elsif ($arg eq '-s') { + $bsh_mode = 1; + } +} +if ((!$csh_mode and !$bsh_mode) or + ($csh_mode and $bsh_mode)) { + print "Usage: ssh-agent-manager (-c | -s)\n"; + print "\n"; + print " -c csh mode\n"; + print " -s bsh mode\n"; + exit; +} + +# lee /tmp/ssh-agent-info si ése existe. +# $> es la uid efectiva. +my $infofile = IO::File->new("/tmp/ssh-agent-info.$>", 'r'); +if ($infofile) { + my @contents = <$infofile>; + my $info = &parse(join("\n", @contents)); + $infofile->close; + + my $pid = $info->{'SSH_AGENT_PID'}; + if ($pid and kill(0, $pid) == 1) { + # ssh-agent está aún viva. + &serialize($info); + exit; + } +} + +# comienza la ssh-agent... +my $info = &parse(scalar `ssh-agent -s`); + +$infofile = IO::File->new("/tmp/ssh-agent-info.$>", 'w'); +while (my ($key, $value) = each %$info) { + $infofile->print("$key=$value\n"); +} +$infofile->close; + +&serialize($info); +exit; + +sub parse { + my $lines = shift; + my %info; + foreach my $line (split /\n/, $lines) { + chomp $line; + # falte si el formato que la da `ssh-agent -s` cambie... + if ($line =~ m/^(.+?)=(.+?);/ or + $line =~ m/^(.+?)=(.+)$/) { + $info{$1} = $2; + } + } + \%info; +} + +sub serialize { + my $info = shift; + while (my ($key, $value) = each %$info) { + if ($bsh_mode) { + print qq{$key=$value; export $key;\n}; + } + elsif ($csh_mode) { + print qq{setenv $key $value;\n}; + } + } +} -- 2.40.0