Debian Codegraph @

debian/patches/singpolyma-0003-If-an-OpenPGP-KeyID-is-set-sign-presence.patch

raw
1 From 86e642797d08ccd0bcf3ca2bc9eda5c0ed407ed6 Mon Sep 17 00:00:00 2001
2 From: Stephen Paul Weber <[email protected]>
3 Date: Thu, 21 Apr 2011 00:11:19 -0500
4 Subject: [PATCH 03/18] If an OpenPGP KeyID is set, sign presence
5
6 ---
7 src/core/protocol.c | 98 +++++++++++++++++++++++++++++++++++++++++++++----
8 src/core/xmpp-servers.c | 1 +
9 src/core/xmpp.h | 2 +
10 3 files changed, 94 insertions(+), 7 deletions(-)
11
12 --- a/src/core/protocol.c
13 +++ b/src/core/protocol.c
14 @@ -15,19 +15,84 @@
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 +#define _POSIX_SOURCE 1
19 +#define _BSD_SOURCE 1
20 +#define _SVID_SOURCE 1
21 +#include <stdio.h>
22 +
23 #include "module.h"
24 #include "signals.h"
25 +#include "settings.h"
26
27 #include "xmpp-servers.h"
28 #include "rosters-tools.h"
29 #include "tools.h"
30
31 +char *pgp_passwd = NULL;
32 +
33 +char *call_gpg(char *keyid, char *switches, char *input) {
34 + int pipefd[2], tmp_fd, in_data = 0;
35 + FILE *cstream;
36 + char *cmd, *tmp_path, *output = NULL;
37 + size_t output_size = 0;
38 + char buf[100], buf2[100] = "";
39 +
40 + if(pipe(pipefd)) goto pgp_error;
41 + if(!pgp_passwd) pgp_passwd = get_password("OpenPGP Password:");
42 +
43 + if(write(pipefd[1], pgp_passwd, strlen(pgp_passwd)) < 1) goto pgp_error;
44 + if(close(pipefd[1])) goto pgp_error;
45 +
46 + if(!(tmp_path = tempnam(NULL, "irssi-xmpp-gpg"))) goto pgp_error;
47 + if((tmp_fd = open(tmp_path, O_WRONLY|O_CREAT|O_EXCL, \
48 + S_IRUSR|S_IWUSR)) < 0)
49 + goto pgp_error;
50 +
51 + if(write(tmp_fd, input, strlen(input)) < 0) goto pgp_error;
52 +
53 + cmd = malloc(sizeof("gpg -u '' -qo - --no-tty --passphrase-fd '' ''") \
54 + +strlen(switches)+6+strlen(tmp_path));
55 + sprintf(cmd, "gpg -u '%s' %s -qo - --no-tty --passphrase-fd '%d' '%s'", \
56 + keyid, switches, pipefd[0], tmp_path);
57 + fflush(NULL);
58 + cstream = popen(cmd, "r");
59 +
60 + while(fgets(buf, sizeof(buf)-1, cstream)) {
61 + if(strlen(buf2) > 0) {
62 + output = realloc(output, output_size+strlen(buf2)+1);
63 + if(!output) goto pgp_error;
64 + if(output_size < 1) output[0] = '\0';
65 + output_size += strlen(buf2);
66 + strcat(output, buf2);
67 + }
68 +
69 + if(!in_data && buf[0] == '\n') {
70 + in_data = 1;
71 + continue;
72 + } else if(in_data) {
73 + strcpy(buf2, buf);
74 + }
75 + }
76 +
77 + pclose(cstream); /* TODO: check exit code */
78 +
79 + close(tmp_fd);
80 + close(pipefd[0]);
81 + free(tmp_path);
82 + free(cmd);
83 +
84 + return output;
85 +pgp_error:
86 + return NULL;
87 +}
88 +
89 static void
90 sig_set_presence(XMPP_SERVER_REC *server, const int show, const char *status,
91 const int priority)
92 {
93 LmMessage *lmsg;
94 char *str;
95 + const char *pgp_keyid;
96
97 g_return_if_fail(IS_XMPP_SERVER(server));
98 if (!xmpp_presence_changed(show, server->show, status,
99 @@ -35,23 +100,42 @@
100 signal_stop();
101 return;
102 }
103 +
104 + lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE);
105 server->show = show;
106 - g_free(server->away_reason);
107 - server->away_reason = g_strdup(status);
108 +
109 if (!xmpp_priority_out_of_bound(priority))
110 server->priority = priority;
111 - lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE);
112 +
113 if (show != XMPP_PRESENCE_AVAILABLE)
114 lm_message_node_add_child(lmsg->node, "show",
115 xmpp_presence_show[server->show]);
116 - if (status != NULL) {
117 - str = xmpp_recode_out(server->away_reason);
118 - lm_message_node_add_child(lmsg->node, "status", str);
119 - g_free(str);
120 +
121 + if(server->away_reason) g_free(server->away_reason);
122 + server->away_reason = NULL;
123 +
124 + if(!status) status = "";
125 + server->away_reason = g_strdup(status);
126 + str = xmpp_recode_out(server->away_reason);
127 + lm_message_node_add_child(lmsg->node, "status", str);
128 + if(!str) str = g_strdup("");
129 +
130 + if((pgp_keyid = settings_get_str("xmpp_pgp"))) {
131 + LmMessageNode *x;
132 + char *signature = call_gpg(pgp_keyid, "-ab", str);
133 +
134 + x = lm_message_node_add_child(lmsg->node, "x", signature);
135 + lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed");
136 +
137 + free(signature);
138 }
139 +
140 + g_free(str);
141 +
142 str = g_strdup_printf("%d", server->priority);
143 lm_message_node_add_child(lmsg->node, "priority", str);
144 g_free(str);
145 +
146 signal_emit("xmpp send presence", 2, server, lmsg);
147 lm_message_unref(lmsg);
148 if (show != XMPP_PRESENCE_AVAILABLE) /* away */
149 --- a/src/core/xmpp-servers.c
150 +++ b/src/core/xmpp-servers.c
151 @@ -590,6 +590,7 @@
152
153 settings_add_int("xmpp", "xmpp_priority", 0);
154 settings_add_int("xmpp", "xmpp_priority_away", -1);
155 + settings_add_str("xmpp", "xmpp_pgp", NULL);
156 settings_add_bool("xmpp_lookandfeel", "xmpp_set_nick_as_username",
157 FALSE);
158 settings_add_bool("xmpp_proxy", "xmpp_use_proxy", FALSE);
159 --- a/src/core/xmpp.h
160 +++ b/src/core/xmpp.h
161 @@ -13,4 +13,6 @@
162 #define IRSSI_XMPP_PACKAGE "irssi-xmpp"
163 #define IRSSI_XMPP_VERSION "0.54"
164
165 +extern char *pgp_passwd;
166 +
167 #endif