From a0c6fc585aecedd236a79e3dc89e2ed67d881ad5 Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Sun, 26 Jun 2011 00:28:26 +0200 Subject: fix possible segfault(s) when changing otr status --- Makefile | 1 + otr.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index cb682287..052a4ad9 100644 --- a/Makefile +++ b/Makefile @@ -163,3 +163,4 @@ helloworld: @echo Hello World -include .depend/*.d +# DO NOT DELETE diff --git a/otr.c b/otr.c index 1bea9c44..326f8227 100644 --- a/otr.c +++ b/otr.c @@ -162,6 +162,9 @@ void otr_handle_smp(struct im_connection *ic, const char *handle, OtrlTLV *tlvs) void otr_smp_or_smpq(irc_t *irc, const char *nick, const char *question, const char *secret); +/* update flags within the irc_user structure to reflect OTR status of context */ +void otr_update_uflags(ConnContext *context, irc_user_t *u); + /* update op/voice flag of given user according to encryption state and settings returns 0 if neither op_buddies nor voice_buddies is set to "encrypted", i.e. msgstate should be announced seperately */ @@ -607,7 +610,6 @@ void op_gone_secure(void *opdata, ConnContext *context) check_imc(opdata, context->accountname, context->protocol); irc_user_t *u; irc_t *irc = ic->bee->ui_data; - const char *trust; u = peeruser(irc, context->username, context->protocol); if(!u) { @@ -617,11 +619,7 @@ void op_gone_secure(void *opdata, ConnContext *context) return; } - trust = context->active_fingerprint->trust; - if(trust && trust[0]) - u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED; - else - u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED; + otr_update_uflags(context, u); if(!otr_update_modeflags(irc, u)) irc_usermsg(irc, "conversation with %s is now off the record", u->nick); } @@ -640,7 +638,7 @@ void op_gone_insecure(void *opdata, ConnContext *context) context->username, context->protocol, context->accountname); return; } - u->flags &= ~( IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED ); + otr_update_uflags(context, u); if(!otr_update_modeflags(irc, u)) irc_usermsg(irc, "conversation with %s is now in the clear", u->nick); } @@ -659,10 +657,8 @@ void op_still_secure(void *opdata, ConnContext *context, int is_reply) context->username, context->protocol, context->accountname); return; } - if(context->active_fingerprint->trust[0]) - u->flags |= IRC_USER_OTR_ENCRYPTED | IRC_USER_OTR_TRUSTED; - else - u->flags = ( u->flags & ~IRC_USER_OTR_TRUSTED ) | IRC_USER_OTR_ENCRYPTED; + + otr_update_uflags(context, u); if(!otr_update_modeflags(irc, u)) irc_usermsg(irc, "otr connection with %s has been refreshed", u->nick); } @@ -1311,6 +1307,23 @@ const char *peernick(irc_t *irc, const char *handle, const char *protocol) } } +void otr_update_uflags(ConnContext *context, irc_user_t *u) +{ + const char *trust; + + if(context->active_fingerprint) { + u->flags |= IRC_USER_OTR_ENCRYPTED; + + trust = context->active_fingerprint->trust; + if(trust && trust[0]) + u->flags |= IRC_USER_OTR_TRUSTED; + else + u->flags &= ~IRC_USER_OTR_TRUSTED; + } else { + u->flags &= ~IRC_USER_OTR_ENCRYPTED; + } +} + int otr_update_modeflags(irc_t *irc, irc_user_t *u) { return 1; -- cgit v1.2.3 From 1dc00fe6d7f79f43660c5196a0132b0c788858f5 Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Sun, 26 Jun 2011 00:31:01 +0200 Subject: make otr status changes visible again --- otr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otr.c b/otr.c index 326f8227..753b85d0 100644 --- a/otr.c +++ b/otr.c @@ -1326,7 +1326,7 @@ void otr_update_uflags(ConnContext *context, irc_user_t *u) int otr_update_modeflags(irc_t *irc, irc_user_t *u) { - return 1; + return 0; } void show_fingerprints(irc_t *irc, ConnContext *ctx) -- cgit v1.2.3 From 9a57b1f353e733bbb5d3c8dd91e551dd307458dd Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Wed, 29 Jun 2011 02:40:31 +0200 Subject: bump copyright year --- otr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otr.c b/otr.c index 753b85d0..e16fbf2a 100644 --- a/otr.c +++ b/otr.c @@ -7,7 +7,7 @@ /* OTR support (cf. http://www.cypherpunks.ca/otr/) - (c) 2008-2010 Sven Moritz Hallberg + (c) 2008-2011 Sven Moritz Hallberg (c) 2008 funded by stonedcoder.org files used to store OTR data: -- cgit v1.2.3 From 1082395cb29e7d0bde7ee55fe1e5d73b41e0e984 Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Wed, 29 Jun 2011 03:35:18 +0200 Subject: treat OTR plaintext as HTML (setting otr_does_html) --- otr.c | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/otr.c b/otr.c index e16fbf2a..843aa3fa 100644 --- a/otr.c +++ b/otr.c @@ -239,6 +239,8 @@ gboolean otr_irc_new(irc_t *irc) l = g_slist_prepend( l, "manual" ); l = g_slist_prepend( l, "always" ); s->eval_data = l; + + s = set_add( &irc->b->set, "otr_does_html", "true", set_eval_bool, irc ); return TRUE; } @@ -387,26 +389,38 @@ char *otr_filter_msg_in(irc_user_t *iu, char *msg, int flags) /* OTR has processed this message */ ConnContext *context = otrl_context_find(irc->otr->us, iu->bu->handle, ic->acc->user, ic->acc->prpl->name, 0, NULL, NULL, NULL); - if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED && - set_getbool(&ic->bee->set, "otr_color_encrypted")) { - /* color according to f'print trust */ - int color; - const char *trust = context->active_fingerprint->trust; - if(trust && trust[0] != '\0') - color=3; /* green */ - else - color=5; /* red */ - - if(newmsg[0] == ',') { - /* could be a problem with the color code */ - /* insert a space between color spec and message */ - colormsg = g_strdup_printf("\x03%.2d %s\x0F", color, newmsg); - } else { - colormsg = g_strdup_printf("\x03%.2d%s\x0F", color, newmsg); + + if(context && context->msgstate == OTRL_MSGSTATE_ENCRYPTED) { + /* HTML decoding */ + /* perform any necessary stripping that the top level would miss */ + if(set_getbool(&ic->bee->set, "otr_does_html") && + !(ic->flags & OPT_DOES_HTML) && + set_getbool(&ic->bee->set, "strip_html")) { + strip_html(newmsg); + } + + /* coloring */ + if(set_getbool(&ic->bee->set, "otr_color_encrypted")) { + /* color according to f'print trust */ + int color; + const char *trust = context->active_fingerprint->trust; + if(trust && trust[0] != '\0') + color=3; /* green */ + else + color=5; /* red */ + + if(newmsg[0] == ',') { + /* could be a problem with the color code */ + /* insert a space between color spec and message */ + colormsg = g_strdup_printf("\x03%.2d %s\x0F", color, newmsg); + } else { + colormsg = g_strdup_printf("\x03%.2d%s\x0F", color, newmsg); + } } } else { colormsg = g_strdup(newmsg); } + otrl_message_free(newmsg); return colormsg; } @@ -424,6 +438,13 @@ char *otr_filter_msg_out(irc_user_t *iu, char *msg, int flags) if(ic->acc->prpl->options & OPT_NOOTR) { return msg; } + + /* HTML encoding */ + /* consider OTR plaintext to be HTML if otr_does_html is set */ + if(set_getbool(&ic->bee->set, "otr_does_html") && + (g_strncasecmp(msg, "", 6) != 0)) { + msg = escape_html(msg); + } st = otrl_message_sending(irc->otr->us, &otr_ops, ic, ic->acc->user, ic->acc->prpl->name, iu->bu->handle, -- cgit v1.2.3 From f1cf01c5eb91fdd3effe04a27cdc5a268ff5ee66 Mon Sep 17 00:00:00 2001 From: Sven Moritz Hallberg Date: Wed, 29 Jun 2011 03:59:46 +0200 Subject: report trust state in gone_secure/still_secure messages --- otr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/otr.c b/otr.c index 843aa3fa..3968da96 100644 --- a/otr.c +++ b/otr.c @@ -641,8 +641,10 @@ void op_gone_secure(void *opdata, ConnContext *context) } otr_update_uflags(context, u); - if(!otr_update_modeflags(irc, u)) - irc_usermsg(irc, "conversation with %s is now off the record", u->nick); + if(!otr_update_modeflags(irc, u)) { + char *trust = u->flags & IRC_USER_OTR_TRUSTED ? "trusted" : "untrusted!"; + irc_usermsg(irc, "conversation with %s is now off the record (%s)", u->nick, trust); + } } void op_gone_insecure(void *opdata, ConnContext *context) @@ -680,8 +682,10 @@ void op_still_secure(void *opdata, ConnContext *context, int is_reply) } otr_update_uflags(context, u); - if(!otr_update_modeflags(irc, u)) - irc_usermsg(irc, "otr connection with %s has been refreshed", u->nick); + if(!otr_update_modeflags(irc, u)) { + char *trust = u->flags & IRC_USER_OTR_TRUSTED ? "trusted" : "untrusted!"; + irc_usermsg(irc, "otr connection with %s has been refreshed (%s)", u->nick, trust); + } } void op_log_message(void *opdata, const char *message) -- cgit v1.2.3