[Rt-commit] r17857 - in rt/3.999/trunk: .
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Jan 21 07:49:05 EST 2009
Author: sunnavy
Date: Wed Jan 21 07:49:04 2009
New Revision: 17857
Modified:
rt/3.999/trunk/ (props changed)
rt/3.999/trunk/lib/RT/Crypt/GnuPG.pm
Log:
r18960 at sunnavys-mb: sunnavy | 2009-01-21 20:48:18 +0800
merged lib/RT/Crypt/GnuPG.pm
Modified: rt/3.999/trunk/lib/RT/Crypt/GnuPG.pm
==============================================================================
--- rt/3.999/trunk/lib/RT/Crypt/GnuPG.pm (original)
+++ rt/3.999/trunk/lib/RT/Crypt/GnuPG.pm Wed Jan 21 07:49:04 2009
@@ -436,6 +436,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnuPGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined $args{'passphrase'};
+
$opt{'digest-algo'} ||= 'SHA1';
$opt{'default_key'} = $args{'signer'}
if $args{'sign'} && $args{'signer'};
@@ -447,10 +452,6 @@
my $entity = $args{'entity'};
- # handling passphrase in GnuPGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined $args{'passphrase'};
-
if ( $args{'sign'} && !defined $args{'passphrase'} ) {
$args{'passphrase'} = get_passphrase( address => $args{'signer'} );
}
@@ -479,8 +480,11 @@
my $pid =
safe_run_child { $gnupg->detach_sign( handles => $handles ) };
$entity->make_multipart( 'mixed', Force => 1 );
- $entity->parts(0)->print( $handle{'stdin'} );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $entity->parts(0)->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
my $err = $@;
@@ -522,7 +526,7 @@
use_key_for_encryption($_) || $_, grep !$seen{$_}++, map
$_->address, map Email::Address->parse( $entity->head->get($_) ), qw(To Cc Bcc);
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles( stdout => $tmp_fh );
@@ -538,8 +542,11 @@
: $gnupg->encrypt( handles => $handles );
};
$entity->make_multipart( 'mixed', Force => 1 );
- $entity->parts(0)->print( $handle{'stdin'} );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $entity->parts(0)->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
@@ -618,6 +625,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnupGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined( $args{'passphrase'} );
+
$opt{'digest-algo'} ||= 'SHA1';
$opt{'default_key'} = $args{'signer'}
if $args{'sign'} && $args{'signer'};
@@ -627,10 +639,6 @@
meta_interactive => 0,
);
- # handling passphrase in GnupGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined( $args{'passphrase'} );
-
if ( $args{'sign'} && !defined $args{'passphrase'} ) {
$args{'passphrase'} = get_passphrase( address => $args{'signer'} );
}
@@ -643,7 +651,7 @@
my %res;
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles( stdout => $tmp_fh );
@@ -660,8 +668,11 @@
? 'sign_and_encrypt'
: ( $args{'sign'} ? 'clearsign' : 'encrypt' );
my $pid = safe_run_child { $gnupg->$method( handles => $handles ) };
- $entity->bodyhandle->print( $handle{'stdin'} );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $entity->bodyhandle->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
$res{'exit_code'} = $?;
@@ -706,6 +717,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnupGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined( $args{'passphrase'} );
+
$opt{'digest-algo'} ||= 'SHA1';
$opt{'default_key'} = $args{'signer'}
if $args{'sign'} && $args{'signer'};
@@ -715,10 +731,6 @@
meta_interactive => 0,
);
- # handling passphrase in GnupGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined( $args{'passphrase'} );
-
if ( $args{'sign'} && !defined $args{'passphrase'} ) {
$args{'passphrase'} = get_passphrase( address => $args{'signer'} );
}
@@ -732,7 +744,7 @@
my %res;
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles( stdout => $tmp_fh );
@@ -747,8 +759,11 @@
? 'sign_and_encrypt'
: ( $args{'sign'} ? 'detach_sign' : 'encrypt' );
my $pid = safe_run_child { $gnupg->$method( handles => $handles ) };
- $entity->bodyhandle->print( $handle{'stdin'} );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $entity->bodyhandle->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
$res{'exit_code'} = $?;
@@ -782,7 +797,7 @@
} else {
$entity->bodyhandle( new MIME::Body::File $tmp_fn );
$entity->effective_type('application/octet-stream');
- $args{'data'}->head->mime_attr( $_ => "$filename.pgp" ) foreach (qw(Content-Type.name Content-Disposition.filename));
+ $entity->head->mime_attr( $_ => "$filename.pgp" ) foreach (qw(Content-Type.name Content-Disposition.filename));
}
$entity->{'__store_tmp_handle_to_avoid_early_cleanup'} = $tmp_fh;
@@ -807,6 +822,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnupGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined( $args{'passphrase'} );
+
$opt{'digest-algo'} ||= 'SHA1';
$opt{'default_key'} = $args{'signer'}
if $args{'sign'} && $args{'signer'};
@@ -816,10 +836,6 @@
meta_interactive => 0,
);
- # handling passphrase in GnupGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined( $args{'passphrase'} );
-
if ( $args{'sign'} && !defined $args{'passphrase'} ) {
$args{'passphrase'} = get_passphrase( address => $args{'signer'} );
}
@@ -832,7 +848,7 @@
my %res;
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles( stdout => $tmp_fh );
@@ -847,8 +863,11 @@
? 'sign_and_encrypt'
: ( $args{'sign'} ? 'clearsign' : 'encrypt' );
my $pid = safe_run_child { $gnupg->$method( handles => $handles ) };
- $handle{'stdin'}->print( ${ $args{'content'} } );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $handle{'stdin'}->print( ${ $args{'content'} } );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
$res{'exit_code'} = $?;
@@ -1057,7 +1076,7 @@
$opt{'digest-algo'} ||= 'SHA1';
$gnupg->options->hash_init( _prepare_gnupg_options(%opt), meta_interactive => 0, );
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
$args{'data'}->bodyhandle->print($tmp_fh);
$tmp_fh->flush;
@@ -1074,9 +1093,11 @@
command_args => [ '-', $tmp_fn ]
);
};
- $args{'signature'}->bodyhandle->print( $handle{'stdin'} );
- close $handle{'stdin'};
-
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $args{'signature'}->bodyhandle->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
$res{'exit_code'} = $?;
@@ -1102,7 +1123,7 @@
$opt{'digest-algo'} ||= 'SHA1';
$gnupg->options->hash_init( _prepare_gnupg_options(%opt), meta_interactive => 0, );
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw:eol(CRLF?)';
$args{'data'}->print($tmp_fh);
$tmp_fh->flush;
@@ -1119,9 +1140,11 @@
command_args => [ '-', $tmp_fn ]
);
};
- $args{'signature'}->bodyhandle->print( $handle{'stdin'} );
- close $handle{'stdin'};
-
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $args{'signature'}->bodyhandle->print( $handle{'stdin'} );
+ close $handle{'stdin'};
+ }
waitpid $pid, 0;
};
$res{'exit_code'} = $?;
@@ -1150,6 +1173,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnupGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined( $args{'passphrase'} );
+
$opt{'digest-algo'} ||= 'SHA1';
$gnupg->options->hash_init( _prepare_gnupg_options(%opt), meta_interactive => 0, );
@@ -1158,14 +1186,10 @@
RT::EmailParser->_decode_body( $args{'data'} );
}
- # handling passphrase in GnupGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined( $args{'passphrase'} );
-
$args{'passphrase'} = get_passphrase()
unless defined $args{'passphrase'};
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles(
@@ -1179,8 +1203,11 @@
local $SIG{'CHLD'} = 'DEFAULT';
$gnupg->passphrase( $args{'passphrase'} );
my $pid = safe_run_child { $gnupg->decrypt( handles => $handles ) };
- $args{'data'}->bodyhandle->print( $handle{'stdin'} );
- close $handle{'stdin'};
+ {
+ local $SIG{'PIPE'} = 'IGNORE';
+ $args{'data'}->bodyhandle->print( $handle{'stdin'} );
+ close $handle{'stdin'}
+ }
waitpid $pid, 0;
};
@@ -1223,6 +1250,11 @@
);
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnuPGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined($args{'passphrase'});
+
$opt{'digest-algo'} ||= 'SHA1';
$gnupg->options->hash_init(
_prepare_gnupg_options( %opt ),
@@ -1234,14 +1266,10 @@
RT::EmailParser->_decode_body($args{'data'});
}
- # handling passphrase in GnuPGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined($args{'passphrase'});
-
$args{'passphrase'} = get_passphrase()
unless defined $args{'passphrase'};
- my ($tmp_fh, $tmp_fn) = File::Temp::tempfile();
+ my ($tmp_fh, $tmp_fn) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my $io = $args{'data'}->open('r');
@@ -1250,7 +1278,7 @@
}
my ($had_literal, $in_block) = ('', 0);
- my ($block_fh, $block_fn) = File::Temp::tempfile();
+ my ($block_fh, $block_fn) = File::Temp::tempfile( UNLINK => 1 );
binmode $block_fh, ':raw';
my %res;
@@ -1273,7 +1301,7 @@
}
print $tmp_fh "-----END OF PART-----\n" if $had_literal;
- ($block_fh, $block_fn) = File::Temp::tempfile();
+ ($block_fh, $block_fn) = File::Temp::tempfile( UNLINK => 1 );
binmode $block_fh, ':raw';
$in_block = 0;
}
@@ -1354,6 +1382,11 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
+ # handling passphrase in GnuPGOptions
+ $args{'passphrase'} = delete $opt{'passphrase'}
+ if !defined( $args{'passphrase'} );
+
$opt{'digest-algo'} ||= 'SHA1';
$gnupg->options->hash_init( _prepare_gnupg_options(%opt),
meta_interactive => 0, );
@@ -1363,14 +1396,10 @@
RT::EmailParser->_decode_body( $args{'data'} );
}
- # handling passphrase in GnuPGOptions
- $args{'passphrase'} = delete $opt{'passphrase'}
- if !defined( $args{'passphrase'} );
-
$args{'passphrase'} = get_passphrase()
unless defined $args{'passphrase'};
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
$args{'data'}->bodyhandle->print($tmp_fh);
seek $tmp_fh, 0, 0;
@@ -1401,17 +1430,18 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
- $opt{'digest-algo'} ||= 'SHA1';
- $gnupg->options->hash_init( _prepare_gnupg_options(%opt), meta_interactive => 0, );
# handling passphrase in GnuPGOptions
$args{'passphrase'} = delete $opt{'passphrase'}
if !defined( $args{'passphrase'} );
+ $opt{'digest-algo'} ||= 'SHA1';
+ $gnupg->options->hash_init( _prepare_gnupg_options(%opt), meta_interactive => 0, );
+
$args{'passphrase'} = get_passphrase()
unless defined $args{'passphrase'};
- my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile();
+ my ( $tmp_fh, $tmp_fn ) = File::Temp::tempfile( UNLINK => 1 );
binmode $tmp_fh, ':raw';
my ( $handles, $handle_list ) = _make_gpg_handles( stdout => $tmp_fh );
@@ -2004,6 +2034,7 @@
my $gnupg = new GnuPG::Interface;
my %opt = RT->config->get('GnuPGOptions');
+
$opt{'digest-algo'} ||= 'SHA1';
$opt{'with-colons'} = undef; # parseable format
$opt{'fingerprint'} = undef; # show fingerprint
@@ -2355,12 +2386,24 @@
eval {
local $SIG{'CHLD'} = 'DEFAULT';
- my $pid = safe_run_child { $gnupg->version( handles => $handles ) };
+ my $pid = safe_run_child {
+ $gnupg->wrap_call( commands => ['--version'], handles => $handles );
+ };
close $handle{'stdin'};
waitpid $pid, 0;
};
- return 0 if $@;
- return 0 if $?;
+ if ($@) {
+ Jifty->log->debug(
+ "Probe for GPG failed." . " Couldn't run `gpg --version`: " . $@ );
+ return 0;
+ }
+ if ($?) {
+ Jifty->log->debug( "Probe for GPG failed."
+ . " Process exitted with code "
+ . ( $? >> 8 )
+ . ( $? & 127 ? ( " as recieved signal " . ( $? & 127 ) ) : '' ) );
+ return 0;
+ }
return 1;
}
More information about the Rt-commit
mailing list