Package: irssi-plugin-xmpp / 0.53-1~bpo8+1

singpolyma-0010-More-robuse-call_gpg-invocation.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
From 854e60b80cf0f2bbb86f063a593038c3f671bd80 Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Sat, 23 Apr 2011 15:04:04 -0500
Subject: [PATCH 10/18] More robuse call_gpg invocation

---
 src/core/protocol.c     |  2 +-
 src/core/rosters.c      |  2 +-
 src/core/tools.c        | 23 +++++++++++++++++++----
 src/core/tools.h        |  3 ++-
 src/core/xmpp-servers.c |  4 ++--
 5 files changed, 25 insertions(+), 9 deletions(-)

--- a/src/core/protocol.c
+++ b/src/core/protocol.c
@@ -61,7 +61,7 @@
 
 	if((pgp_keyid = settings_get_str("xmpp_pgp"))) {
 		LmMessageNode *x;
-		char *signature = call_gpg("-ab", str, NULL, 0);
+		char *signature = call_gpg("-ab", str, NULL, 0, 1);
 
 		x = lm_message_node_add_child(lmsg->node, "x", signature);
 		lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
--- a/src/core/rosters.c
+++ b/src/core/rosters.c
@@ -515,7 +515,7 @@
 			strcat(send_to_gpg, signature->value);
 			strcat(send_to_gpg, "----- END PGP SIGNATURE-----\n");
 
-			from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1);
+			from_gpg = call_gpg("--verify", send_to_gpg, send_status, 1, 0);
 			free(send_to_gpg);
 
 			/* If there is a good signature, grab the key ID */
--- a/src/core/tools.c
+++ b/src/core/tools.c
@@ -33,8 +33,9 @@
 
 static const char *utf8_charset = "UTF-8";
 
-char *call_gpg(char *switches, char *input, char *input2, int in_data) {
-	int pipefd[2], tmp_fd, tmp2_fd = 0;
+char *call_gpg(char *switches, char *input, char *input2, \
+               int get_stderr, int snip_data) {
+	int pipefd[2], tmp_fd, tmp2_fd = 0, in_data = !snip_data;
 	FILE *cstream;
 	char *cmd, *tmp_path, *tmp2_path = NULL, *output = NULL;
 	size_t output_size = 0;
@@ -65,7 +66,8 @@
 		if(write(tmp2_fd, input2, strlen(input2)) < 0) goto pgp_error;
 	}
 
-	cmd = malloc(sizeof("gpg -u '' --passphrase-fd '' -qo - --batch --no-tty '' '' 2>&1") \
+	cmd = malloc(sizeof("gpg -u '' --passphrase-fd '' -qo - --batch " \
+	              "--no-tty '' '' 2>/dev/null") \
 	              +strlen(switches)+8+strlen(tmp_path)+ \
 	              (tmp2_path ? strlen(tmp2_path) : 0));
 	if(keyid) {
@@ -84,7 +86,11 @@
 		strcat(cmd, "'");
 	}
 
-	strcat(cmd, " 2>&1");
+	if(get_stderr) {
+		strcat(cmd, " 2>&1");
+	} else {
+		strcat(cmd, " 2>/dev/null");
+	}
 
 	fflush(NULL);
 	cstream = popen(cmd, "r");
@@ -106,6 +112,15 @@
 		}
 	}
 
+	/* Get last line if not snipping */
+	if(!snip_data && strlen(buf2) > 0) {
+		output = realloc(output, output_size+strlen(buf2)+1);
+		if(!output) goto pgp_error;
+		if(output_size < 1) output[0] = '\0';
+		output_size += strlen(buf2);
+		strcat(output, buf2);
+	}
+
 	pclose(cstream); /* TODO: check exit code */
 
 	close(tmp_fd);
--- a/src/core/tools.h
+++ b/src/core/tools.h
@@ -2,7 +2,8 @@
 #define __TOOLS_H
 
 __BEGIN_DECLS
-char *call_gpg(char *switches, char *input, char *input2, int in_data);
+char *call_gpg(char *switches, char *input, char *input2, \
+               int get_stderr, int snip_data);
 
 char	*xmpp_recode_out(const char *);
 char	*xmpp_recode_in(const char *);
--- a/src/core/xmpp-servers.c
+++ b/src/core/xmpp-servers.c
@@ -102,7 +102,7 @@
 		if(settings_get_str("xmpp_pgp")) strcat(switches, "s");
 		strcat(switches, "R ");
 		strcat(switches, encrypt_to);
-		encrypted = call_gpg(switches, recoded, NULL, 0);
+		encrypted = call_gpg(switches, recoded, NULL, 0, 1);
 
 		x = lm_message_node_add_child(lmsg->node, "x", encrypted);
 		lm_message_node_set_attribute(x, "xmlns", "jabber:x:encrypted");
@@ -113,7 +113,7 @@
 		recoded = g_strdup("[This message is encrypted.]");
 	} else if(settings_get_str("xmpp_pgp")) {
 		LmMessageNode *x;
-		char *msigned = call_gpg("-ab", recoded, NULL, 0);
+		char *msigned = call_gpg("-ab", recoded, NULL, 0, 1);
 		x = lm_message_node_add_child(lmsg->node, "x", msigned);
 		lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
 		free(msigned);