[Pkg-privacy-commits] [irssi-plugin-otr] 104/267: Make the authq command work with a question
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:22 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 2fa1a69b079e3fb91b123fb407cfb892ada66936
Author: David Goulet <dgoulet at ev0ke.net>
Date: Sat Nov 3 23:29:37 2012 -0400
Make the authq command work with a question
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/cmd.c | 53 ++++++++++++++++++++++++++----------------
src/cmd.h | 4 ++--
src/module.c | 5 ++--
src/utils.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/utils.h | 1 +
5 files changed, 114 insertions(+), 24 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index 648182e..3e4989b 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -25,7 +25,7 @@
* /otr debug
*/
static void _cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
debug = !debug;
otr_noticest(debug ? TXT_CMD_DEBUG_ON : TXT_CMD_DEBUG_OFF);
@@ -35,7 +35,7 @@ static void _cmd_debug(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv
* /otr version
*/
static void _cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
otr_noticest(TXT_CMD_VERSION, IRCOTR_VERSION);
}
@@ -44,7 +44,7 @@ static void _cmd_version(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *ar
* /otr help
*/
static void _cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
otr_log(ircctx, target, MSGLEVEL_CRAP, otr_help);
}
@@ -53,7 +53,7 @@ static void _cmd_help(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[
* /otr finish
*/
static void _cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
if (argc) {
otr_finish(NULL, NULL, argv[0], TRUE);
@@ -68,7 +68,7 @@ static void _cmd_finish(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *arg
* /otr trust
*/
static void _cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
if (argc) {
otr_trust(NULL, NULL, argv[0]);
@@ -83,7 +83,7 @@ static void _cmd_trust(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv
* /otr authabort
*/
static void _cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
- char *argv[], char *argv_eol[], char *target)
+ char *argv[], char *argv_eol[], char *target, const char *orig_args)
{
if (argc) {
otr_authabort(NULL, NULL, argv[0]);
@@ -98,7 +98,7 @@ static void _cmd_authabort(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
* /otr genkey
*/
static void _cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
if (argc) {
if (strncmp(argv[0], "abort", strlen("abort")) == 0) {
@@ -117,9 +117,11 @@ static void _cmd_genkey(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *arg
* Generic internal function for /otr auth command.
*/
static void _auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
- char *argv[], char *argv_eol[], char *target, int qanda)
+ char *argv[], char *argv_eol[], char *target, int qanda,
+ const char *orig_args)
{
- char *accountname = NULL, *question = NULL, *secret;
+ int ret;
+ char *accountname = NULL, *question = NULL, *secret = NULL;
/* have args? */
if (argc < (qanda ? 2 : 1)) {
@@ -141,14 +143,24 @@ static void _auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
/* have question? */
if (qanda) {
- question = argv[0];
- argv++; argv_eol++; argc--;
+ ret = utils_io_extract_smp(orig_args, &question, &secret);
+ if (ret < 0) {
+ otr_notice(ircctx, target, TXT_CMD_AUTH);
+ goto end;
+ }
+ } else {
+ secret = argv_eol[0];
}
- secret = argv_eol[0];
+ otr_logst(MSGLEVEL_CRAP, "q: '%s', s: '%s'\n", question, secret);
otr_auth(ircctx, target, accountname, question, secret);
+ free(question);
+ if (qanda) {
+ free(secret);
+ }
+
end:
return;
}
@@ -157,25 +169,25 @@ end:
* /otr authq (Authentication with a question)
*/
static void _cmd_authq(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
- char *argv[], char *argv_eol[], char *target)
+ char *argv[], char *argv_eol[], char *target, const char *orig_args)
{
- _auth(ioustate, ircctx, argc, argv, argv_eol, target, TRUE);
+ _auth(ioustate, ircctx, argc, argv, argv_eol, target, TRUE, orig_args);
}
/*
* /otr auth
*/
static void _cmd_auth(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
- _auth(ioustate, ircctx, argc, argv, argv_eol, target, FALSE);
+ _auth(ioustate, ircctx, argc, argv, argv_eol, target, FALSE, orig_args);
}
/*
* /otr contexts
*/
static void _cmd_contexts(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc,
- char *argv[], char *argv_eol[], char *target)
+ char *argv[], char *argv_eol[], char *target, const char *orig_args)
{
struct ctxlist_ *ctxlist = otr_contexts(ioustate), *ctxnext = ctxlist;
struct fplist_ *fplist, *fpnext;
@@ -228,7 +240,7 @@ static struct irssi_commands cmds[] = {
* Return TRUE if command exist and is executed else FALSE.
*/
int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target)
+ char *argv_eol[], char *target, const char *orig_args)
{
char *cmd;
struct irssi_commands *commands = cmds;
@@ -245,8 +257,9 @@ int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
argc--;
do {
- if (strncmp(commands->name, cmd, strlen(commands->name)) == 0) {
- commands->func(ioustate, ircctx, argc, argv, argv_eol, target);
+ if (strcmp(commands->name, cmd) == 0) {
+ commands->func(ioustate, ircctx, argc, argv, argv_eol, target,
+ orig_args);
goto done;
}
} while ((++commands)->name);
diff --git a/src/cmd.h b/src/cmd.h
index 5ff9c69..e9e411e 100644
--- a/src/cmd.h
+++ b/src/cmd.h
@@ -26,10 +26,10 @@
struct irssi_commands {
const char *name;
void (*func)(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target);
+ char *argv_eol[], char *target, const char *orig_args);
};
int cmd_generic(IOUSTATE *ioustate, IRC_CTX *ircctx, int argc, char *argv[],
- char *argv_eol[], char *target);
+ char *argv_eol[], char *target, const char *orig_args);
#endif /* IRSSI_OTR_CMD_H */
diff --git a/src/module.c b/src/module.c
index 45e7827..57077b6 100644
--- a/src/module.c
+++ b/src/module.c
@@ -142,9 +142,10 @@ static void cmd_otr(const char *data, void *server, WI_ITEM_REC *item)
utils_io_explode_args(data, &argv, &argv_eol, &argc);
if (query && query->server && query->server->connrec) {
- cmd_generic(ioustate, query->server, argc, argv, argv_eol, query->name);
+ cmd_generic(ioustate, query->server, argc, argv, argv_eol, query->name,
+ data);
} else {
- cmd_generic(ioustate, NULL, argc, argv, argv_eol, NULL);
+ cmd_generic(ioustate, NULL, argc, argv, argv_eol, NULL, data);
}
statusbar_items_redraw("otr");
diff --git a/src/utils.c b/src/utils.c
index c397975..0ea3cc8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -28,6 +28,81 @@ static const char *lvlstring[] = {
"DEBUG"
};
+int utils_io_extract_smp(const char *data, char **question, char **secret)
+{
+ unsigned int q_len, s_len;
+ const char *tmp, *q_end, *q_beg, *args = data;
+ char *q, *s;
+
+ *question = *secret = NULL;
+
+ /* Check for '[' as first char */
+ q_beg = strchr(args, '[');
+ if (!q_beg) {
+ goto error;
+ }
+
+ /*
+ * Move to "[my questions] secret"
+ * ^
+ */
+ args = q_beg + 1;
+
+ /* Search closing bracket for the end of the question. */
+ q_end = strchr(args, ']');
+ if (!q_end) {
+ /* Malformed authq command */
+ goto error;
+ }
+
+ /* Get the question length */
+ q_len = (unsigned int) (q_end - args);
+
+ /* Add 1 char for the \0 */
+ q = malloc((q_len + 1) * sizeof(char));
+ if (q == NULL) {
+ goto error;
+ }
+
+ /* Copy question */
+ strncpy(q, args, q_len);
+ q[q_len] = '\0';
+
+ /* Move to the closing bracket */
+ args = q_end;
+
+ tmp = strchr(args, ' ');
+ if (tmp == NULL) {
+ goto error;
+ }
+
+ /* Ignore the next white space */
+ args = tmp + 1;
+
+ /*
+ * "[my questions] secret"
+ * ^
+ */
+ s_len = (unsigned int) (args - data);
+
+ s = malloc((s_len + 1) * sizeof(char));
+ if (s == NULL) {
+ free(q);
+ goto error;
+ }
+
+ strncpy(s, args, s_len);
+ s[s_len] = '\0';
+
+ *question = q;
+ *secret = s;
+
+ return 0;
+
+error:
+ return -1;
+}
+
void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
int *argcp)
{
diff --git a/src/utils.h b/src/utils.h
index 978e340..1deaf40 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -36,5 +36,6 @@ void otr_log(IRC_CTX *server, const char *to, int lvl, const char *fmt, ...);
void utils_io_explode_args(const char *args, char ***argvp, char ***argv_eolp,
int *argcp);
+int utils_io_extract_smp(const char *data, char **question, char **secret);
#endif /* IRSSI_OTR_UTILS_H */
--
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