Debian Codegraph @

debian/patches/singpolyma-0101-Repair-broken-passphrase-retry.patch

raw
1 From 0411946bef40d584ae77ed5a84b8ef1dbb152cec Mon Sep 17 00:00:00 2001
2 From: Jan Losinski <[email protected]>
3 Date: Tue, 24 Feb 2015 22:19:53 +0100
4 Subject: [PATCH 01/10] Repair broken passphrase retry
5
6 The exit code handling of the gpg process to detect wrong passphrases
7 was a bit adventurous. It checked for the raw status value from waitpid
8 instead of the WEXITSTATUS() macro.
9 The code that handles the waitpid also does not check for any errors.
10 This is now fixed by evaluating the waitpid return value and the use of
11 the WEXITSTATUS() macro.
12
13 Signed-off-by: Jan Losinski <[email protected]>
14 ---
15 src/core/popenRWE.c | 4 +++-
16 src/core/tools.c | 21 +++++++++++++++++----
17 2 files changed, 20 insertions(+), 5 deletions(-)
18
19 --- a/src/core/popenRWE.c
20 +++ b/src/core/popenRWE.c
21 @@ -88,6 +88,8 @@
22 close(rwepipe[0]);
23 close(rwepipe[1]);
24 close(rwepipe[2]);
25 - rc = waitpid(pid, &status, 0);
26 + do {
27 + rc = waitpid(pid, &status, 0);
28 + } while (rc != 0 && ! WIFEXITED(status));
29 return status;
30 }
31 --- a/src/core/tools.c
32 +++ b/src/core/tools.c
33 @@ -21,6 +21,7 @@
34 #include <stdio.h>
35
36 #include <string.h>
37 +#include <sys/wait.h>
38
39 #include "module.h"
40 #include "recode.h"
41 @@ -34,8 +35,8 @@
42
43 static const char *utf8_charset = "UTF-8";
44
45 -char *call_gpg(char *switches, char *input, char *input2, \
46 - int get_stderr, int snip_data) {
47 +char *call_gpg_round(char *switches, char *input, char *input2, \
48 + int get_stderr, int snip_data, unsigned round) {
49 int pipefd[2], rwepipe[3], childpid, tmp2_fd = 0, in_data = !snip_data;
50 FILE* cstream;
51 char *cmd, *tmp2_path = NULL, *output = NULL;
52 @@ -124,10 +125,15 @@
53 strcat(output, buf2);
54 }
55
56 - if(pcloseRWE(childpid, rwepipe) == 512) { /* TODO: more check exit code */
57 + // http://www.gnu-darwin.org/www001/src/ports/security/libgpg-error/work/libgpg-error-1.5/src/err-codes.h.in
58 + // 11 GPG_ERR_BAD_PASSPHRASE Bad passphrase
59 + // 31 GPG_ERR_INV_PASSPHRASE Invalid passphrase
60 + int exit_status = WEXITSTATUS(pcloseRWE(childpid, rwepipe));
61 + if(round > 0 && (exit_status == 11 || exit_status == 31)) {
62 g_free(pgp_passwd);
63 pgp_passwd = NULL;
64 - output = call_gpg(switches, input, input2, get_stderr, snip_data);
65 + output = call_gpg_round(switches, input, input2, get_stderr,
66 + snip_data, round--);
67 }
68
69 if(tmp2_fd) close(tmp2_fd);
70 @@ -141,6 +147,13 @@
71 }
72
73
74 +char *call_gpg(char *switches, char *input, char *input2, \
75 + int get_stderr, int snip_data, unsigned round) {
76 + return call_gpg_round(switches, input, input2, get_stderr,
77 + snip_data, 3);
78 +}
79 +
80 +
81
82 static gboolean
83 xmpp_get_local_charset(const char **charset)