If Myon's magic to find stuff to build a ~/.caffrc fails, still produce something...
authorweasel <weasel@b513b33f-fedd-0310-b452-c3deb5f4c849>
Fri, 26 Aug 2005 22:47:29 +0000 (22:47 +0000)
committerweasel <weasel@b513b33f-fedd-0310-b452-c3deb5f4c849>
Fri, 26 Aug 2005 22:47:29 +0000 (22:47 +0000)
git-svn-id: svn://svn.debian.org/pgp-tools/trunk@238 b513b33f-fedd-0310-b452-c3deb5f4c849

caff/caff
debian/changelog

index 352017509dfe6d9a01119b1cd8490f8392fb34a2..8c9b105980562a015d85e79f23d26e7081306485 100755 (executable)
--- a/caff/caff
+++ b/caff/caff
@@ -308,32 +308,44 @@ sub trace2($) {
 
 
 sub generate_config() {
-       die "Error: \$LOGNAME is not set.\n" unless $ENV{LOGNAME};
-       my $gecos = (getpwnam($ENV{LOGNAME}))[6];
-       $gecos =~ s/,.*//;
+       notice("Error: \$LOGNAME is not set.\n") unless defined $ENV{'LOGNAME'};
+       my $gecos = defined $ENV{'LOGNAME'} ? (getpwnam($ENV{LOGNAME}))[6] : undef;
+       my $email;
+       my @keys;
+       my $hostname = `hostname -f`;
+       chomp $hostname;
+       if (defined $gecos) {
+               $gecos =~ s/,.*//;
 
-       my $gpg = GnuPG::Interface->new();
-       $gpg->call( 'gpg' );
-       $gpg->options->hash_init(
-               'extra_args' => [ qw{ --no-auto-check-trustdb --trust-model=always --with-colons --fixed-list-mode } ] );
-       $gpg->options->meta_interactive( 0 );
-       my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
-       my $pid = $gpg->list_public_keys(handles => $handles, command_args => [ $gecos ]);
-       my ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
-       waitpid $pid, 0;
+               my $gpg = GnuPG::Interface->new();
+               $gpg->call( 'gpg' );
+               $gpg->options->hash_init(
+                       'extra_args' => [ qw{ --no-auto-check-trustdb --trust-model=always --with-colons --fixed-list-mode } ] );
+               $gpg->options->meta_interactive( 0 );
+               my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
+               my $pid = $gpg->list_public_keys(handles => $handles, command_args => [ $gecos ]);
+               my ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
+               waitpid $pid, 0;
 
-       if ($stdout eq '') {
-               warn ("No data from gpg for list-key\n"); # There should be at least 'tru:' everywhere.
-       };
+               if ($stdout eq '') {
+                       warn ("No data from gpg for list-key\n"); # There should be at least 'tru:' everywhere.
+               };
 
-       my @keys;
-       unless (@keys = ($stdout =~ /^pub:[^r:]*:(?:[^:]*:){2,2}([^:]+):/mg)) {
-               die "Error: No keys were found using \"gpg --list-public-keys '$gecos'\".\n";
-       }
-       unless ($stdout =~ /^uid:.*<(.+@.+)>.*:/m) {
-               die "Error: No email address was found using \"gpg --list-public-keys '$gecos'\".\n";
-       }
-       my $email = $1;
+               @keys = ($stdout =~ /^pub:[^r:]*:(?:[^:]*:){2,2}([^:]+):/mg);
+               unless (scalar @keys) {
+                       info("Error: No keys were found using \"gpg --list-public-keys '$gecos'\".");
+                       @keys = qw{0123456789abcdef 89abcdef76543210}
+               }
+               ($email) =  ($stdout =~ /^uid:.*<(.+?@.+?)>.*:/m);
+               unless (defined $email) {
+                       info("Error: No email address was found using \"gpg --list-public-keys '$gecos'\".");
+                       $email = $ENV{'LOGNAME'}.'@'.$hostname;
+               }
+       } else {
+               $gecos = 'Unknown Caff User';
+               $email = $ENV{'LOGNAME'}.'@'.$hostname;
+               @keys = qw{0123456789abcdef 89abcdef76543210}
+       };
 
        return <<EOT;
 # .caffrc -- vim:syntax=perl:
@@ -347,6 +359,11 @@ sub generate_config() {
 #
 # if you have a v4 key, it will simply be the last 16 digits of
 # your fingerprint.
+#
+# Example:
+#   \$CONFIG{'keyid'}       = [ qw{FEDCBA9876543210} ];
+#  or, if you have more than one key:
+#   \$CONFIG{'keyid'}       = [ qw{0123456789ABCDEF 89ABCDEF76543210} ];
 
 \$CONFIG{'keyid'}       = [ qw{@keys} ];
 EOT
index dafb2f0097f72dde6ee134a6a66dca4c55165d49..3ffad68d42c44ff109d844de7c0c08e0d601a74f 100644 (file)
@@ -1,8 +1,12 @@
 signing-party (0.4.3-2) UNRELEASED; urgency=low
 
-  * 
+  * caff:
+     + When building a ~/.caffrc when there is none we would fail if
+       we cannot find a key or an email address for the current user.
+       Change this to produce something sensible in that case as well
+       (closes: #325156).
 
- -- Peter Palfrader <weasel@debian.org>  Tue, 23 Aug 2005 01:55:09 +0200
+ -- Peter Palfrader <weasel@debian.org>  Sat, 27 Aug 2005 00:43:27 +0200
 
 signing-party (0.4.3-1) unstable; urgency=low