blob: c68681c1ed52f365e5e2a1bb3156c756a735edc1 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001From bb48dbc88a58bc05a43d71a3375fb05358119ec5 Mon Sep 17 00:00:00 2001
2From: Robert Yang <liezhi.yang@windriver.com>
3Date: Sun, 20 Mar 2016 20:20:16 -0700
4Subject: [PATCH] rpmqv.c: check _gpg_passphrase before ask for input
5
6rpm always asked for pass phrasae when add signature, which made it
7can't work non-interactively, this patch fix the problem. It will work
8non-interactively if _gpg_passphrase is defined, and work as before if
9not.
10
11Upstream-Status: Pending
12
13Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
14---
15 macros/macros.in | 7 +++++--
16 rpmqv.c | 17 ++++++++++-------
17 2 files changed, 15 insertions(+), 9 deletions(-)
18
19diff --git a/macros/macros.in b/macros/macros.in
20index 2e5b07d..01b3aad 100644
21--- a/macros/macros.in
22+++ b/macros/macros.in
23@@ -520,15 +520,18 @@ $_arbitrary_tags_tests Foo:Bar
24 # Macro(s) to hold the arguments passed to GPG/PGP for package
25 # signing and verification.
26 #
27+
28+%_gpg_passphrase_way %{?_gpg_passphrase:--passphrase "%{_gpg_passphrase}"}%{!?_gpg_passphrase:--passphrase-fd 3}
29+
30 %__gpg_check_password_cmd %{__gpg} \
31- gpg --batch --no-verbose --passphrase-fd 3 -u "%{_gpg_name}" -so -
32+ gpg --batch --no-verbose %{_gpg_passphrase_way} -u "%{_gpg_name}" -so -
33 #%__pgp_check_password_cmd %{__pgp} \
34 # pgp +batchmode=on +verbose=0 "%{_pgp_name}" -sf
35 #%__pgp5_check_password_cmd %{__pgp} \
36 # pgps +batchmode=on +verbose=0 +armor=off "%{_pgp_name}" -f
37
38 %__gpg_sign_cmd %{__gpg} \
39- gpg --batch --no-verbose --no-armor --passphrase-fd 3 --no-secmem-warning \
40+ gpg --batch --no-verbose --no-armor %{_gpg_passphrase_way} --no-secmem-warning \
41 -u "%{_gpg_name}" -sbo %{__signature_filename} %{__plaintext_filename}
42 #%__pgp_sign_cmd %{__pgp} \
43 # pgp +batchmode=on +verbose=0 +armor=off \
44diff --git a/rpmqv.c b/rpmqv.c
45index b306486..7604396 100644
46--- a/rpmqv.c
47+++ b/rpmqv.c
48@@ -831,13 +831,16 @@ int main(int argc, const char ** argv)
49 #endif
50 )
51 {
52- passPhrase = Getpass(_("Enter pass phrase: "));
53- if (rpmCheckPassPhrase(passPhrase)) {
54- fprintf(stderr, _("Pass phrase check failed\n"));
55- ec = EXIT_FAILURE;
56- goto exit;
57+ passPhrase = rpmExpand("%{?_gpg_passphrase}", NULL);
58+ if (passPhrase == NULL || passPhrase[0] == '\0') {
59+ passPhrase = Getpass(_("Enter pass phrase: "));
60+ if (rpmCheckPassPhrase(passPhrase)) {
61+ fprintf(stderr, _("Pass phrase check failed\n"));
62+ ec = EXIT_FAILURE;
63+ goto exit;
64+ }
65+ fprintf(stderr, _("Pass phrase is good.\n"));
66 }
67- fprintf(stderr, _("Pass phrase is good.\n"));
68 /* XXX Getpass() should realloc instead. */
69 passPhrase = xstrdup(passPhrase);
70 }