| 1 |
From 854e60b80cf0f2bbb86f063a593038c3f671bd80 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Stephen Paul Weber <[email protected]> |
| 3 |
Date: Sat, 23 Apr 2011 15:04:04 -0500 |
| 4 |
Subject: [PATCH 10/18] More robuse call_gpg invocation |
| 5 |
|
| 6 |
--- |
| 7 |
src/core/protocol.c | 2 +- |
| 8 |
src/core/rosters.c | 2 +- |
| 9 |
src/core/tools.c | 23 +++++++++++++++++++---- |
| 10 |
src/core/tools.h | 3 ++- |
| 11 |
src/core/xmpp-servers.c | 4 ++-- |
| 12 |
5 files changed, 25 insertions(+), 9 deletions(-) |
| 13 |
|
| 14 |
--- a/src/core/protocol.c |
| 15 |
+++ b/src/core/protocol.c |
| 16 |
@@ -61,7 +61,7 @@ |
| 17 |
|
| 18 |
if((pgp_keyid = settings_get_str("xmpp_pgp"))) { |
| 19 |
LmMessageNode *x; |
| 20 |
- char *signature = call_gpg("-ab", str, NULL, 0); |
| 21 |
+ char *signature = call_gpg("-ab", str, NULL, 0, 1); |
| 22 |
|
| 23 |
x = lm_message_node_add_child(lmsg->node, "x", signature); |
| 24 |
lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed"); |
| 25 |
--- a/src/core/rosters.c |
| 26 |
+++ b/src/core/rosters.c |
| 27 |
@@ -515,7 +515,7 @@ |
| 28 |
strcat(send_to_gpg, signature->value); |
| 29 |
strcat(send_to_gpg, "----- END PGP SIGNATURE-----\n"); |
| 30 |
|
| 31 |
- from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1); |
| 32 |
+ from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1, 0); |
| 33 |
free(send_to_gpg); |
| 34 |
|
| 35 |
/* If there is a good signature, grab the key ID */ |
| 36 |
--- a/src/core/tools.c |
| 37 |
+++ b/src/core/tools.c |
| 38 |
@@ -33,8 +33,9 @@ |
| 39 |
|
| 40 |
static const char *utf8_charset = "UTF-8"; |
| 41 |
|
| 42 |
-char *call_gpg(char *switches, char *input, char *input2, int in_data) { |
| 43 |
- int pipefd[2], tmp_fd, tmp2_fd = 0; |
| 44 |
+char *call_gpg(char *switches, char *input, char *input2, \ |
| 45 |
+ int get_stderr, int snip_data) { |
| 46 |
+ int pipefd[2], tmp_fd, tmp2_fd = 0, in_data = !snip_data; |
| 47 |
FILE *cstream; |
| 48 |
char *cmd, *tmp_path, *tmp2_path = NULL, *output = NULL; |
| 49 |
size_t output_size = 0; |
| 50 |
@@ -65,7 +66,8 @@ |
| 51 |
if(write(tmp2_fd, input2, strlen(input2)) < 0) goto pgp_error; |
| 52 |
} |
| 53 |
|
| 54 |
- cmd = malloc(sizeof("gpg -u '' --passphrase-fd '' -qo - --batch --no-tty '' '' 2>&1") \ |
| 55 |
+ cmd = malloc(sizeof("gpg -u '' --passphrase-fd '' -qo - --batch " \ |
| 56 |
+ "--no-tty '' '' 2>/dev/null") \ |
| 57 |
+strlen(switches)+8+strlen(tmp_path)+ \ |
| 58 |
(tmp2_path ? strlen(tmp2_path) : 0)); |
| 59 |
if(keyid) { |
| 60 |
@@ -84,7 +86,11 @@ |
| 61 |
strcat(cmd, "'"); |
| 62 |
} |
| 63 |
|
| 64 |
- strcat(cmd, " 2>&1"); |
| 65 |
+ if(get_stderr) { |
| 66 |
+ strcat(cmd, " 2>&1"); |
| 67 |
+ } else { |
| 68 |
+ strcat(cmd, " 2>/dev/null"); |
| 69 |
+ } |
| 70 |
|
| 71 |
fflush(NULL); |
| 72 |
cstream = popen(cmd, "r"); |
| 73 |
@@ -106,6 +112,15 @@ |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
+ /* Get last line if not snipping */ |
| 78 |
+ if(!snip_data && strlen(buf2) > 0) { |
| 79 |
+ output = realloc(output, output_size+strlen(buf2)+1); |
| 80 |
+ if(!output) goto pgp_error; |
| 81 |
+ if(output_size < 1) output[0] = '\0'; |
| 82 |
+ output_size += strlen(buf2); |
| 83 |
+ strcat(output, buf2); |
| 84 |
+ } |
| 85 |
+ |
| 86 |
pclose(cstream); /* TODO: check exit code */ |
| 87 |
|
| 88 |
close(tmp_fd); |
| 89 |
--- a/src/core/tools.h |
| 90 |
+++ b/src/core/tools.h |
| 91 |
@@ -2,7 +2,8 @@ |
| 92 |
#define __TOOLS_H |
| 93 |
|
| 94 |
__BEGIN_DECLS |
| 95 |
-char *call_gpg(char *switches, char *input, char *input2, int in_data); |
| 96 |
+char *call_gpg(char *switches, char *input, char *input2, \ |
| 97 |
+ int get_stderr, int snip_data); |
| 98 |
|
| 99 |
char *xmpp_recode_out(const char *); |
| 100 |
char *xmpp_recode_in(const char *); |
| 101 |
--- a/src/core/xmpp-servers.c |
| 102 |
+++ b/src/core/xmpp-servers.c |
| 103 |
@@ -119,7 +119,7 @@ |
| 104 |
if(settings_get_str("xmpp_pgp")) strcat(switches, "s"); |
| 105 |
strcat(switches, "R "); |
| 106 |
strcat(switches, encrypt_to); |
| 107 |
- encrypted = call_gpg(switches, recoded, NULL, 0); |
| 108 |
+ encrypted = call_gpg(switches, recoded, NULL, 0, 1); |
| 109 |
|
| 110 |
x = lm_message_node_add_child(lmsg->node, "x", encrypted); |
| 111 |
lm_message_node_set_attribute(x, "xmlns", "jabber:x:encrypted"); |
| 112 |
@@ -130,7 +130,7 @@ |
| 113 |
recoded = g_strdup("[This message is encrypted.]"); |
| 114 |
} else if(settings_get_str("xmpp_pgp")) { |
| 115 |
LmMessageNode *x; |
| 116 |
- char *msigned = call_gpg("-ab", recoded, NULL, 0); |
| 117 |
+ char *msigned = call_gpg("-ab", recoded, NULL, 0, 1); |
| 118 |
x = lm_message_node_add_child(lmsg->node, "x", msigned); |
| 119 |
lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed"); |
| 120 |
free(msigned); |