X-Git-Url: http://git.sthu.org/?a=blobdiff_plain;f=caff%2Fcaff;h=a0a0ed64c270b2268b1430b044b39cab8e3c2a31;hb=a9630bdc99fdda11f2d20409730e777b300fabe9;hp=352017509dfe6d9a01119b1cd8490f8392fb34a2;hpb=29103470e4470c002d5e523c29c1407efd033801;p=pgp-tools.git diff --git a/caff/caff b/caff/caff index 3520175..a0a0ed6 100755 --- a/caff/caff +++ b/caff/caff @@ -308,47 +308,68 @@ 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; + my ($Cgecos,$Cemail,$Ckeys) = ('','',''); + 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}; + $Ckeys = '#'; + } + ($email) = ($stdout =~ /^uid:.*<(.+?@.+?)>.*:/m); + unless (defined $email) { + info("Error: No email address was found using \"gpg --list-public-keys '$gecos'\"."); + $email = $ENV{'LOGNAME'}.'@'.$hostname; + $Cemail = '#'; + } + } else { + $gecos = 'Unknown Caff User'; + $email = $ENV{'LOGNAME'}.'@'.$hostname; + @keys = qw{0123456789abcdef 89abcdef76543210}; + ($Cgecos,$Cemail,$Ckeys) = ('#','#','#'); + }; return < # # 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} ]; +$Ckeys\$CONFIG{'keyid'} = [ qw{@keys} ]; EOT }; @@ -368,12 +389,12 @@ sub load_config() { }; $CONFIG{'caffhome'}=$ENV{'HOME'}.'/.caff' unless defined $CONFIG{'caffhome'}; - die ("owner is not defined.\n") unless defined $CONFIG{'owner'}; - die ("email is not defined.\n") unless defined $CONFIG{'email'}; - die ("keyid is not defined.\n") unless defined $CONFIG{'keyid'}; - die ("keyid is not an array ref\n") unless (ref $CONFIG{'keyid'} eq 'ARRAY'); + die ("$PROGRAM_NAME: owner is not defined in $config.\n") unless defined $CONFIG{'owner'}; + die ("$PROGRAM_NAME: email is not defined in $config.\n") unless defined $CONFIG{'email'}; + die ("$PROGRAM_NAME: keyid is not defined in $config.\n") unless defined $CONFIG{'keyid'}; + die ("$PROGRAM_NAME: keyid is not an array ref in $config.\n") unless (ref $CONFIG{'keyid'} eq 'ARRAY'); for my $keyid (@{$CONFIG{'keyid'}}) { - $keyid =~ /^[A-F0-9]{16}$/i or die ("key $keyid is not a long (16 digit) keyid.\n"); + $keyid =~ /^[A-F0-9]{16}$/i or die ("$PROGRAM_NAME: key $keyid is not a long (16 digit) keyid in $config.\n"); }; @{$CONFIG{'keyid'}} = map { uc } @{$CONFIG{'keyid'}}; $CONFIG{'export-sig-age'}= 24*60*60 unless defined $CONFIG{'export-sig-age'};