Index: /trunk/docs/Changelog
===================================================================
--- /trunk/docs/Changelog	(revision 52)
+++ /trunk/docs/Changelog	(revision 53)
@@ -1,3 +1,5 @@
 2.2.3:
+	* fix samhainadmin.pl: check for gpg-agent running if use-agent is set
+	  (ticket #28 by anonymous)
 	* fix stealth mode (regression in parser), problem reported by 
 	  Joschi Kuphal
Index: /trunk/scripts/samhainadmin.pl.in
===================================================================
--- /trunk/scripts/samhainadmin.pl.in	(revision 52)
+++ /trunk/scripts/samhainadmin.pl.in	(revision 53)
@@ -28,4 +28,5 @@
 use IO::Handle;
 use Fcntl qw(:DEFAULT :flock);
+use Tie::File;
 
 # Do I/O to the data file in binary mode (so it 
@@ -55,4 +56,59 @@
 $gpg = "gpg" if ($gpg eq "");
 
+sub check_gpg_agent() {
+    my  $gpgconf = "$ENV{'HOME'}/.gnupg/gpg.conf";
+
+    if (!-f "$gpgconf") {
+	$gpgconf = "$ENV{'HOME'}/.gnupg/options";
+    }
+
+    if (-f $gpgconf) {
+
+	my @array = ();
+	tie @array, 'Tie::File', $gpgconf or die "Cannot tie ${gpgconf}: $!";
+	my @grep = grep(/^\s*use-agent/, @array);
+	
+	# print "matches = $#grep\n";
+	
+	if ($#grep >= 0)
+	{
+	    if (exists $ENV{'GPG_AGENT_INFO'})
+	    {
+		my $socke = $ENV{'GPG_AGENT_INFO'};
+		$socke =~ s/:.*//;
+		
+		# print "socke = $socke\n";
+		
+		if (! -S $socke)
+		{
+		    print "--------------------------------------------------\n";
+		    print "\n";
+		    print " GPG is set to use gpg-agent, but GPG agent is";
+		    print " not running, though GPG_AGENT_INFO is defined.\n\n";
+		    print " Please restart gpg-agent, or remove the use-agent\n";
+		    print " option from ${gpgconf} and unset GPG_AGENT_INFO\n\n";
+		    print "--------------------------------------------------\n";
+		    print "\n";
+		    exit 1;
+		}
+	    }
+	    else
+	    {
+		print "--------------------------------------------------\n";
+		print "\n";
+		print " GPG is set to use gpg-agent, but ";
+		print " GPG_AGENT_INFO is not defined.\n\n";
+		print " Please start gpg-agent, or remove the use-agent\n";
+		print " option from ${gpgconf}\n\n";
+		print "--------------------------------------------------\n";
+		print "\n";
+		exit 1;
+	    }
+	}
+	untie @array;
+    }
+}
+
+
 sub usage() {
     print "Usage:\n";
@@ -391,4 +447,5 @@
 
     check_gpg_uid();
+    check_gpg_agent();
 
     if (!defined($file2)) {
