[Pkg-privacy-commits] [irssi-plugin-otr] 123/267: Add /otr distrust command
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:35 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.
commit 1bbd9ffd2aa2d0adeb788f3bce8917e945a60f7a
Author: David Goulet <dgoulet at ev0ke.net>
Date: Mon Nov 12 17:20:13 2012 -0500
Add /otr distrust command
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/cmd.c | 26 ++++++++++++++++++++++++
src/otr.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/otr.h | 2 ++
3 files changed, 98 insertions(+)
diff --git a/src/cmd.c b/src/cmd.c
index 4d0a31c..b603b51 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -263,6 +263,31 @@ error:
return;
}
+static void _cmd_distrust(struct otr_user_state *ustate, SERVER_REC *irssi,
+ int argc, char *argv[], char *argv_eol[], char *target,
+ const char *orig_args)
+{
+ char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *fp = NULL;
+
+ if (argc == 5) {
+ utils_hash_parts_to_readable_hash((const char **) argv, str_fp);
+ fp = str_fp;
+ } else if (!irssi || (irssi && argc != 0)) {
+ /* If no IRSSI or some arguments (not 5), bad command. */
+ IRSSI_NOTICE(irssi, target, "%9OTR%9: Usage %9/otr distrust [FP]%9 "
+ "where FP is the five part of the fingerprint listed by "
+ "%9/otr contexts%9 or do the command inside an OTR session "
+ "private message window");
+ goto error;
+ }
+
+ /* Trigger the forget action. */
+ otr_distrust(irssi, target, fp, ustate);
+
+error:
+ return;
+}
+
static struct irssi_commands cmds[] = {
{ "version", _cmd_version },
{ "debug", _cmd_debug },
@@ -270,6 +295,7 @@ static struct irssi_commands cmds[] = {
{ "init", _cmd_init },
{ "finish", _cmd_finish },
{ "trust", _cmd_trust },
+ { "distrust", _cmd_distrust },
{ "forget", _cmd_forget },
{ "authabort", _cmd_authabort },
{ "auth", _cmd_auth },
diff --git a/src/otr.c b/src/otr.c
index 3e7bbfb..de4b61a 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -879,3 +879,73 @@ error:
free(accname);
return;
}
+
+/*
+ * Distrust a fingerprint.
+ *
+ * If str_fp is not NULL, it must be on the OTR human format like this:
+ * "487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A". If str_fp is NULL, get the
+ * context of the target nickname, check for the OTR peer context active
+ * fingerprint and distrust it.
+ */
+void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp,
+ struct otr_user_state *ustate)
+{
+ int ret;
+ char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *accname = NULL;
+ Fingerprint *fp_distrust;
+ ConnContext *ctx;
+ struct otr_peer_context *opc;
+
+ if (!irssi && !str_fp) {
+ IRSSI_NOTICE(NULL, nick, "%9OTR%9: Need a fingerprint!");
+ goto error;
+ }
+
+ /* No human string fingerprint given. */
+ if (!str_fp) {
+ accname = create_account_name(irssi);
+ if (!accname) {
+ goto error;
+ }
+
+ ctx = otr_find_context(accname, nick, FALSE, irssi);
+ if (!ctx) {
+ goto error;
+ }
+
+ opc = ctx->app_data;
+ /* Always NEED a peer context or else code error. */
+ assert(opc);
+
+ fp_distrust = opc->active_fingerprint;
+ } else {
+ fp_distrust = otr_find_hash_fingerprint_from_human(str_fp, ustate);
+ }
+
+ IRSSI_DEBUG("%9OTR%9: Distrust fingerprint: %s",
+ (str_fp != NULL) ? str_fp : fp);
+
+ if (fp_distrust) {
+ ret = otrl_context_is_fingerprint_trusted(fp_distrust);
+ if (!ret) {
+ /* Fingerprint already not trusted. Do nothing. */
+ goto end;
+ }
+
+ otrl_privkey_hash_to_human(fp, fp_distrust->fingerprint);
+ otrl_context_set_trust(fp_distrust, "");
+ /* Update fingerprints file. */
+ key_write_fingerprints(ustate);
+ IRSSI_NOTICE(irssi, nick, "%9OTR%9: Fingerprint %y%s%n distrusted.",
+ fp);
+ } else {
+ IRSSI_NOTICE(irssi, nick, "%9OTR%9: Fingerprint %y%s%n NOT found",
+ (str_fp != NULL) ? str_fp : fp);
+ }
+
+end:
+error:
+ free(accname);
+ return;
+}
diff --git a/src/otr.h b/src/otr.h
index 3ecfe6a..c9e7e5b 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -198,6 +198,8 @@ struct ctxlist_ *otr_contexts(struct otr_user_state *ustate);
void otr_finishall(struct otr_user_state *ustate);
void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
struct otr_user_state *ustate);
+void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp,
+ struct otr_user_state *ustate);
int otr_getstatus_format(SERVER_REC *irssi, const char *nick);
struct otr_peer_context *otr_create_peer_context(void);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git
More information about the Pkg-privacy-commits
mailing list