Handle SED-encrypted CTCP replies properly

When a SED-encrypted NOTICE is scanned for CTCPs within the decrypted portion, they should be
handled with do_notice_ctcp() so they are treated as CTCP replies.
This commit is contained in:
Kevin Easton
2017-06-22 00:03:53 +10:00
parent 64d524804c
commit fb8dfc3946
2 changed files with 78 additions and 40 deletions

View File

@@ -1,5 +1,7 @@
[Changes 1.2.2] [Changes 1.2.2]
* Handle SED-encrypted CTCP replies properly. (caf)
* Add sent_nick flag to NickList struct, bump MODULE_VERSION. (caf) * Add sent_nick flag to NickList struct, bump MODULE_VERSION. (caf)
* Write correct length to terminal for unflash sequences. (caf) * Write correct length to terminal for unflash sequences. (caf)

View File

@@ -61,35 +61,38 @@ CVS_REVISION(ctcp_c)
* that will be inserted into the oringal message at the point of the ctcp. * that will be inserted into the oringal message at the point of the ctcp.
* if null is returned, nothing is added to the original message * if null is returned, nothing is added to the original message
*/ */
#define CTCP_HANDLER(x) \
static char * x (CtcpEntry *ctcp, char *from, char *to, char *cmd)
/* forward declarations for the built in CTCP functions */ /* forward declarations for the built in CTCP functions */
static char *do_sed (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_sed);
static char *do_version (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_sed_reply);
static char *do_clientinfo (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_version);
static char *do_ping (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_clientinfo);
static char *do_echo (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_ping);
static char *do_userinfo (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_echo);
static char *do_finger (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_userinfo);
static char *do_time (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_finger);
static char *do_atmosphere (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_time);
static char *do_dcc (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_atmosphere);
static char *do_utc (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_dcc);
static char *do_dcc_reply (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_utc);
static char *do_ping_reply (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_dcc_reply);
static char *do_bdcc (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_ping_reply);
static char *do_cinvite (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_bdcc);
static char *do_whoami (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_cinvite);
static char *do_ctcpops (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_whoami);
static char *do_ctcpunban (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_ctcpops);
static char *do_botlink (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_ctcpunban);
static char *do_ctcp_uptime (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_botlink);
static char *do_ctcpident (CtcpEntry *, char *, char *, char *); CTCP_HANDLER(do_ctcp_uptime);
CTCP_HANDLER(do_ctcpident);
static CtcpEntry ctcp_cmd[] = static CtcpEntry ctcp_cmd[] =
{ {
{ "SED", CTCP_SED, CTCP_INLINE | CTCP_NOLIMIT, { "SED", CTCP_SED, CTCP_INLINE | CTCP_NOLIMIT,
"contains simple_encrypted_data", "contains simple_encrypted_data",
do_sed, do_sed }, do_sed, do_sed_reply },
{ "UTC", CTCP_UTC, CTCP_INLINE | CTCP_NOLIMIT, { "UTC", CTCP_UTC, CTCP_INLINE | CTCP_NOLIMIT,
"substitutes the local timezone", "substitutes the local timezone",
do_utc, do_utc }, do_utc, do_utc },
@@ -191,9 +194,6 @@ int sed = 0;
*/ */
int in_ctcp_flag = 0; int in_ctcp_flag = 0;
#define CTCP_HANDLER(x) \
static char * x (CtcpEntry *ctcp, char *from, char *to, char *cmd)
/**************************** CTCP PARSERS ****************************/ /**************************** CTCP PARSERS ****************************/
/********** INLINE EXPANSION CTCPS ***************/ /********** INLINE EXPANSION CTCPS ***************/
@@ -606,7 +606,23 @@ int server;
return NULL; return NULL;
} }
static char *try_decrypt(char *from, char *to, char *msg)
{
char *key;
char *crypt_who;
if (*from == '=' || !my_stricmp(to, get_server_nickname(from_server)))
crypt_who = from;
else
crypt_who = to;
key = is_crypted(crypt_who);
if (!key)
return NULL;
return decrypt_msg(msg, key);
}
/* /*
* do_sed: Performs the Simple Encrypted Data trasfer for ctcp. Returns in a * do_sed: Performs the Simple Encrypted Data trasfer for ctcp. Returns in a
@@ -615,23 +631,12 @@ int server;
*/ */
CTCP_HANDLER(do_sed) CTCP_HANDLER(do_sed)
{ {
char *key = NULL, char *ret;
*crypt_who; char *ret2;
char *ret = NULL, *ret2 = NULL;
if (*from == '=') ret = try_decrypt(from, to, cmd);
crypt_who = from;
if (my_stricmp(to, get_server_nickname(from_server)))
crypt_who = to;
else
crypt_who = from;
if ((key = is_crypted(crypt_who))) if (ret)
ret = decrypt_msg(cmd, key);
if (!key || !ret)
malloc_strcpy(&ret2, "[ENCRYPTED MESSAGE]");
else
{ {
/* /*
* There might be a CTCP message in there, * There might be a CTCP message in there,
@@ -640,6 +645,37 @@ CTCP_HANDLER(do_sed)
ret2 = m_strdup(do_ctcp(from, to, ret)); ret2 = m_strdup(do_ctcp(from, to, ret));
sed = 1; sed = 1;
} }
else
{
ret2 = m_strdup("[ENCRYPTED MESSAGE]");
}
new_free(&ret);
return ret2;
}
/* do_sed_reply: Same as do_sed, but CTCPs within the SED are handled as
* CTCP replies. */
CTCP_HANDLER(do_sed_reply)
{
char *ret;
char *ret2;
ret = try_decrypt(from, to, cmd);
if (ret)
{
/*
* There might be a CTCP reply in there,
* so we see if we can find it.
*/
ret2 = m_strdup(do_notice_ctcp(from, to, ret));
sed = 1;
}
else
{
ret2 = m_strdup("[ENCRYPTED MESSAGE]");
}
new_free(&ret); new_free(&ret);
return ret2; return ret2;