diff --git a/include/ctcp.h b/include/ctcp.h index 9a1f9d0..466f652 100644 --- a/include/ctcp.h +++ b/include/ctcp.h @@ -71,6 +71,8 @@ extern char * do_notice_ctcp (char *, char *, char *); extern int in_ctcp (void); extern void send_ctcp (int, char *, int, char *, ...); extern int get_ctcp_val (char *); +extern char *sed_encrypt_msg(char *, const char *); +extern char *sed_decrypt_msg(const char *, const char *); void BX_split_CTCP (char *, char *, char *); diff --git a/include/encrypt.h b/include/encrypt.h index 81b536c..8082526 100644 --- a/include/encrypt.h +++ b/include/encrypt.h @@ -12,8 +12,6 @@ #ifndef ENCRYPT_H_ #define ENCRYPT_H_ -char *crypt_msg(char *, const char *); -char *decrypt_msg(const char *, const char *); void encrypt_cmd(char *, char *, char *, char *); const char *is_crypted(char *); void BX_my_decrypt(char *, int, const char *); diff --git a/source/Makefile.in b/source/Makefile.in index 8b9cd5e..ada0b23 100644 --- a/source/Makefile.in +++ b/source/Makefile.in @@ -336,7 +336,7 @@ cdcc.o: cdcc.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/debug.h ../include/newio.h ../include/ssl.h \ ../include/ircaux.h ../include/irc.h ../include/struct.h \ ../include/hash.h ../include/commands.h ../include/ignore.h \ - ../include/ctcp.h ../include/hook.h ../include/dcc.h ../include/struct.h \ + ../include/hook.h ../include/dcc.h ../include/struct.h \ ../include/flood.h ../include/screen.h ../include/window.h \ ../include/lastlog.h ../include/parse.h ../include/output.h \ ../include/input.h ../include/server.h ../include/who.h \ @@ -374,16 +374,16 @@ commands2.o: commands2.c ../include/irc.h ../include/defs.h \ ../include/names.h ../include/window.h ../include/lastlog.h \ ../include/irc.h ../include/struct.h ../include/notify.h \ ../include/alist.h ../include/ircaux.h ../include/chelp.h \ - ../include/commands.h ../include/encrypt.h ../include/vars.h \ - ../include/cset.h ../include/ircaux.h ../include/lastlog.h \ - ../include/log.h ../include/window.h ../include/screen.h \ - ../include/ircterm.h ../include/screen.h ../include/translat.h \ - ../include/who.h ../include/hook.h ../include/input.h \ - ../include/ignore.h ../include/keys.h ../include/names.h \ - ../include/alias.h ../include/array.h ../include/history.h \ - ../include/funny.h ../include/ctcp.h ../include/output.h \ - ../include/exec.h ../include/notify.h ../include/status.h \ - ../include/if.h ../include/help.h ../include/stack.h ../include/hook.h \ + ../include/commands.h ../include/vars.h ../include/cset.h \ + ../include/ircaux.h ../include/lastlog.h ../include/log.h \ + ../include/window.h ../include/screen.h ../include/ircterm.h \ + ../include/screen.h ../include/translat.h ../include/who.h \ + ../include/hook.h ../include/input.h ../include/ignore.h \ + ../include/keys.h ../include/names.h ../include/alias.h \ + ../include/array.h ../include/history.h ../include/funny.h \ + ../include/ctcp.h ../include/output.h ../include/exec.h \ + ../include/notify.h ../include/status.h ../include/if.h \ + ../include/help.h ../include/stack.h ../include/hook.h \ ../include/alias.h ../include/queue.h ../include/timer.h \ ../include/list.h ../include/misc.h ../include/userlist.h \ ../include/whowas.h ../include/flood.h ../include/hash2.h \ @@ -473,8 +473,8 @@ encrypt.o: encrypt.c ../include/irc.h ../include/defs.h \ ../include/ssl.h ../include/struct.h ../include/hash.h \ ../include/encrypt.h ../include/vars.h ../include/cset.h \ ../include/struct.h ../include/ircaux.h ../include/irc.h \ - ../include/list.h ../include/ctcp.h ../include/output.h \ - ../include/newio.h ../include/modval.h ../include/module.h + ../include/list.h ../include/output.h ../include/newio.h \ + ../include/modval.h ../include/module.h exec.o: exec.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/../.config.h ../include/bsdglob.h ../include/irc_std.h \ ../include/debug.h ../include/newio.h ../include/ssl.h \ @@ -733,16 +733,16 @@ misc.o: misc.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/who.h ../include/names.h ../include/window.h \ ../include/lastlog.h ../include/irc.h ../include/struct.h \ ../include/notify.h ../include/alist.h ../include/ircaux.h \ - ../include/dcc.h ../include/commands.h ../include/encrypt.h \ - ../include/vars.h ../include/cset.h ../include/ircaux.h \ - ../include/lastlog.h ../include/window.h ../include/screen.h \ - ../include/who.h ../include/hook.h ../include/input.h \ - ../include/ignore.h ../include/keys.h ../include/names.h \ - ../include/alias.h ../include/history.h ../include/funny.h \ - ../include/ctcp.h ../include/output.h ../include/exec.h \ - ../include/notify.h ../include/status.h ../include/list.h \ - ../include/timer.h ../include/userlist.h ../include/misc.h \ - ../include/gui.h ../include/cdns.h ../include/flood.h ../include/parse.h \ + ../include/dcc.h ../include/commands.h ../include/vars.h \ + ../include/cset.h ../include/ircaux.h ../include/lastlog.h \ + ../include/window.h ../include/screen.h ../include/who.h \ + ../include/hook.h ../include/input.h ../include/ignore.h \ + ../include/keys.h ../include/names.h ../include/alias.h \ + ../include/history.h ../include/funny.h ../include/ctcp.h \ + ../include/output.h ../include/exec.h ../include/notify.h \ + ../include/status.h ../include/list.h ../include/timer.h \ + ../include/userlist.h ../include/misc.h ../include/gui.h \ + ../include/cdns.h ../include/flood.h ../include/parse.h \ ../include/whowas.h ../include/hash2.h ../include/whowas.h \ ../include/cset.h ../include/if.h ../include/modval.h \ ../include/module.h @@ -850,7 +850,7 @@ output.o: output.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/window.h ../include/screen.h ../include/server.h \ ../include/who.h ../include/names.h ../include/notify.h \ ../include/alist.h ../include/ircaux.h ../include/hook.h \ - ../include/ctcp.h ../include/log.h ../include/misc.h ../include/modval.h \ + ../include/log.h ../include/misc.h ../include/modval.h \ ../include/module.h parse.o: parse.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/../.config.h ../include/bsdglob.h ../include/irc_std.h \ @@ -863,16 +863,15 @@ parse.o: parse.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/cset.h ../include/cdcc.h ../include/ctcp.h ../include/hook.h \ ../include/log.h ../include/commands.h ../include/ignore.h \ ../include/who.h ../include/lastlog.h ../include/input.h \ - ../include/ircaux.h ../include/funny.h ../include/encrypt.h \ - ../include/ircterm.h ../include/screen.h ../include/translat.h \ - ../include/flood.h ../include/window.h ../include/screen.h \ - ../include/output.h ../include/numbers.h ../include/parse.h \ - ../include/notify.h ../include/status.h ../include/list.h \ - ../include/userlist.h ../include/misc.h ../include/whowas.h \ - ../include/timer.h ../include/keys.h ../include/hash2.h \ - ../include/whowas.h ../include/cset.h ../include/module.h \ - ../include/gui.h ../include/tcl_bx.h ../include/modval.h \ - ../include/module.h + ../include/ircaux.h ../include/funny.h ../include/ircterm.h \ + ../include/screen.h ../include/translat.h ../include/flood.h \ + ../include/window.h ../include/screen.h ../include/output.h \ + ../include/numbers.h ../include/parse.h ../include/notify.h \ + ../include/status.h ../include/list.h ../include/userlist.h \ + ../include/misc.h ../include/whowas.h ../include/timer.h \ + ../include/keys.h ../include/hash2.h ../include/whowas.h \ + ../include/cset.h ../include/module.h ../include/gui.h \ + ../include/tcl_bx.h ../include/modval.h ../include/module.h pmbitchx.o: pmbitchx.c ../include/window.h ../include/irc_std.h \ ../include/defs.h ../include/lastlog.h ../include/gui.h \ ../include/server.h ../include/who.h ../include/names.h \ @@ -986,13 +985,13 @@ tcl.o: tcl.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/lastlog.h ../include/translat.h ../include/server.h \ ../include/who.h ../include/names.h ../include/irc.h ../include/struct.h \ ../include/notify.h ../include/alist.h ../include/ircaux.h \ - ../include/chelp.h ../include/commands.h ../include/encrypt.h \ - ../include/vars.h ../include/cset.h ../include/ircaux.h \ - ../include/lastlog.h ../include/window.h ../include/screen.h \ - ../include/who.h ../include/hook.h ../include/input.h \ - ../include/ignore.h ../include/keys.h ../include/names.h \ - ../include/alias.h ../include/history.h ../include/funny.h \ - ../include/ctcp.h ../include/dcc.h ../include/output.h ../include/exec.h \ + ../include/chelp.h ../include/commands.h ../include/vars.h \ + ../include/cset.h ../include/ircaux.h ../include/lastlog.h \ + ../include/window.h ../include/screen.h ../include/who.h \ + ../include/hook.h ../include/input.h ../include/ignore.h \ + ../include/keys.h ../include/names.h ../include/alias.h \ + ../include/history.h ../include/funny.h ../include/ctcp.h \ + ../include/dcc.h ../include/output.h ../include/exec.h \ ../include/notify.h ../include/status.h ../include/if.h \ ../include/help.h ../include/stack.h ../include/hook.h \ ../include/alias.h ../include/queue.h ../include/timer.h \ @@ -1055,26 +1054,25 @@ userlist.o: userlist.c ../include/irc.h ../include/defs.h \ ../include/server.h ../include/who.h ../include/names.h \ ../include/window.h ../include/lastlog.h ../include/irc.h \ ../include/struct.h ../include/notify.h ../include/alist.h \ - ../include/ircaux.h ../include/commands.h ../include/encrypt.h \ - ../include/vars.h ../include/cset.h ../include/ircaux.h \ - ../include/lastlog.h ../include/window.h ../include/screen.h \ - ../include/who.h ../include/hook.h ../include/input.h \ - ../include/ignore.h ../include/keys.h ../include/names.h \ - ../include/alias.h ../include/history.h ../include/funny.h \ - ../include/ctcp.h ../include/dcc.h ../include/output.h ../include/exec.h \ - ../include/notify.h ../include/status.h ../include/list.h \ - ../include/timer.h ../include/whowas.h ../include/misc.h \ - ../include/userlist.h ../include/parse.h ../include/hash2.h \ - ../include/whowas.h ../include/cset.h ../include/modval.h \ - ../include/module.h + ../include/ircaux.h ../include/commands.h ../include/vars.h \ + ../include/cset.h ../include/ircaux.h ../include/lastlog.h \ + ../include/window.h ../include/screen.h ../include/who.h \ + ../include/hook.h ../include/input.h ../include/ignore.h \ + ../include/keys.h ../include/names.h ../include/alias.h \ + ../include/history.h ../include/funny.h ../include/dcc.h \ + ../include/output.h ../include/exec.h ../include/notify.h \ + ../include/status.h ../include/list.h ../include/timer.h \ + ../include/whowas.h ../include/misc.h ../include/userlist.h \ + ../include/parse.h ../include/hash2.h ../include/whowas.h \ + ../include/cset.h ../include/modval.h ../include/module.h vars.o: vars.c ../include/irc.h ../include/defs.h ../include/config.h \ ../include/../.config.h ../include/bsdglob.h ../include/irc_std.h \ ../include/debug.h ../include/newio.h ../include/ssl.h \ ../include/struct.h ../include/hash.h ../include/status.h \ ../include/window.h ../include/lastlog.h ../include/lastlog.h \ - ../include/log.h ../include/encrypt.h ../include/history.h \ - ../include/notify.h ../include/alist.h ../include/ircaux.h \ - ../include/irc.h ../include/vars.h ../include/cset.h ../include/struct.h \ + ../include/log.h ../include/history.h ../include/notify.h \ + ../include/alist.h ../include/ircaux.h ../include/irc.h \ + ../include/vars.h ../include/cset.h ../include/struct.h \ ../include/input.h ../include/ircaux.h ../include/who.h \ ../include/ircterm.h ../include/screen.h ../include/window.h \ ../include/translat.h ../include/output.h ../include/screen.h \ diff --git a/source/cdcc.c b/source/cdcc.c index d3ede1c..9261e4d 100644 --- a/source/cdcc.c +++ b/source/cdcc.c @@ -22,7 +22,6 @@ CVS_REVISION(cdcc_c) #include "struct.h" #include "commands.h" #include "ignore.h" -#include "ctcp.h" #include "hook.h" #include "dcc.h" #include "flood.h" diff --git a/source/commands.c b/source/commands.c index 056ae7a..fc2b328 100644 --- a/source/commands.c +++ b/source/commands.c @@ -3877,7 +3877,7 @@ struct target_type target[4] = { char *breakage; breakage = LOCAL_COPY(text); - line = crypt_msg(breakage, key); + line = sed_encrypt_msg(breakage, key); } else line = m_strdup(text); @@ -3920,7 +3920,7 @@ struct target_type target[4] = { set_display_target(current_nick, target[i].level); - line = crypt_msg(copy, key); + line = sed_encrypt_msg(copy, key); if (hook && do_hook(target[i].hook_type, "%s %s", current_nick, copy)) put_it("%s", convert_output_format(target[i].format_encrypted, "%s %s %s %s", update_clock(GET_TIME), current_nick, get_server_nickname(from_server), text)); diff --git a/source/commands2.c b/source/commands2.c index 4835c7b..580373b 100644 --- a/source/commands2.c +++ b/source/commands2.c @@ -30,7 +30,6 @@ CVS_REVISION(commands2_c) #include "server.h" #include "chelp.h" #include "commands.h" -#include "encrypt.h" #include "vars.h" #include "ircaux.h" #include "lastlog.h" diff --git a/source/ctcp.c b/source/ctcp.c index d6ca007..f9783ee 100644 --- a/source/ctcp.c +++ b/source/ctcp.c @@ -603,6 +603,72 @@ int server; return NULL; } +/* Make this less than the trasmittable buffer */ +#define CRYPT_BUFFER_SIZE (IRCD_BUFFER_SIZE - 50) + +/* + * sed_encrypt_msg() + * + * Encrypts a message with my_encrypt() under the given key, and encapsulates it + * as a CTCP SED message ready to transmit. + */ +char *sed_encrypt_msg(char *str, const char *key) +{ + static const char sed_prefix[] = { CTCP_DELIM_CHAR, 'S', 'E', 'D', ' ', 0 }; + const size_t len = strlen(str); + char buffer[CRYPT_BUFFER_SIZE]; + char *ptr; + + my_encrypt(str, len, key); + ptr = ctcp_quote_it(str, len); + + if (ptr) + { + /* The - 1 terms here are to ensure that the trailing CTCP_DELIM_CHAR + * always gets added. */ + strlcpy(buffer, sed_prefix, sizeof buffer - 1); + strlcat(buffer, ptr, sizeof buffer - 1); + strlcat(buffer, CTCP_DELIM_STR, sizeof buffer); + new_free(&ptr); + } + else + strlcpy(buffer, str, sizeof buffer); + + return (m_strdup(buffer)); +} + +/* + * sed_decrypt_msg() + * + * Given a CTCP SED argument 'str', it attempts to unscramble the text + * into something more sane. If the 'key' is not the one used to scramble + * the text, the results are unpredictable. This is probably the point. + * + * Note that the retval MUST be at least 'BIG_BUFFER_SIZE + 1'. This is + * not an oversight -- the retval is passed is to do_ctcp() which requires + * a big buffer to scratch around (The decrypted text could be a CTCP UTC + * which could expand to a larger string of text.) + */ +char *sed_decrypt_msg(const char *str, const char *key) +{ + char *buffer = new_malloc(BIG_BUFFER_SIZE + 1); + char *ptr; + size_t len; + + ptr = ctcp_unquote_it(str, &len); + my_decrypt(ptr, len, key); + + if (ptr) + { + strlcpy(buffer, ptr, CRYPT_BUFFER_SIZE); + new_free(&ptr); + } + else + strlcat(buffer, str, CRYPT_BUFFER_SIZE); + + return buffer; +} + static char *try_decrypt(char *from, char *to, const char *msg) { const char *key; @@ -618,7 +684,7 @@ static char *try_decrypt(char *from, char *to, const char *msg) if (!key) return NULL; - return decrypt_msg(msg, key); + return sed_decrypt_msg(msg, key); } /* diff --git a/source/encrypt.c b/source/encrypt.c index 2cf6dbf..bae9093 100644 --- a/source/encrypt.c +++ b/source/encrypt.c @@ -18,7 +18,6 @@ CVS_REVISION(encrypt_c) #include "vars.h" #include "ircaux.h" #include "list.h" -#include "ctcp.h" #include "output.h" #include "newio.h" #define MAIN_SOURCE @@ -27,9 +26,6 @@ CVS_REVISION(encrypt_c) static void add_to_crypt (char *, char *); static int remove_crypt (char *); -#define CRYPT_BUFFER_SIZE (IRCD_BUFFER_SIZE - 50) /* Make this less than - * the trasmittable - * buffer */ /* * Crypt: the crypt list structure, consists of the nickname, and the * encryption key @@ -186,63 +182,3 @@ extern void BX_my_decrypt(char *str, int len, const char *key) str[i] = (char) 0; } -/* - * crypt_msg: Executes the encryption program on the given string with the - * given key. If flag is true, the string is encrypted and the returned - * string is ready to be sent over irc. If flag is false, the string is - * decrypted and the returned string should be readable - */ -char *crypt_msg(char *str, const char *key) -{ - static const char sed_prefix[] = { CTCP_DELIM_CHAR, 'S', 'E', 'D', ' ', 0 }; - const size_t len = strlen(str); - char buffer[CRYPT_BUFFER_SIZE]; - char *ptr; - - my_encrypt(str, len, key); - ptr = ctcp_quote_it(str, len); - - if (ptr) - { - /* The - 1 terms here are to ensure that the trailing CTCP_DELIM_CHAR - * always gets added. */ - strlcpy(buffer, sed_prefix, sizeof buffer - 1); - strlcat(buffer, ptr, sizeof buffer - 1); - strlcat(buffer, CTCP_DELIM_STR, sizeof buffer); - new_free(&ptr); - } - else - strlcpy(buffer, str, sizeof buffer); - - return (m_strdup(buffer)); -} - -/* - * Given a CTCP SED argument 'str', it attempts to unscramble the text - * into something more sane. If the 'key' is not the one used to scramble - * the text, the results are unpredictable. This is probably the point. - * - * Note that the retval MUST be at least 'BIG_BUFFER_SIZE + 1'. This is - * not an oversight -- the retval is passed is to do_ctcp() which requires - * a big buffer to scratch around (The decrypted text could be a CTCP UTC - * which could expand to a larger string of text.) - */ -char *decrypt_msg(const char *str, const char *key) -{ - char *buffer = new_malloc(BIG_BUFFER_SIZE + 1); - char *ptr; - size_t len; - - ptr = ctcp_unquote_it(str, &len); - my_decrypt(ptr, len, key); - - if (ptr) - { - strlcpy(buffer, ptr, CRYPT_BUFFER_SIZE); - new_free(&ptr); - } - else - strlcat(buffer, str, CRYPT_BUFFER_SIZE); - - return buffer; -} diff --git a/source/misc.c b/source/misc.c index 92e746b..842362e 100644 --- a/source/misc.c +++ b/source/misc.c @@ -34,7 +34,6 @@ CVS_REVISION(misc_c) #include "server.h" #include "dcc.h" #include "commands.h" -#include "encrypt.h" #include "vars.h" #include "ircaux.h" #include "lastlog.h" diff --git a/source/output.c b/source/output.c index b8d3108..c117188 100644 --- a/source/output.c +++ b/source/output.c @@ -27,7 +27,6 @@ CVS_REVISION(output_c) #include "screen.h" #include "server.h" #include "hook.h" -#include "ctcp.h" #include "log.h" #include "misc.h" #define MAIN_SOURCE diff --git a/source/parse.c b/source/parse.c index 82bb7f1..b228461 100644 --- a/source/parse.c +++ b/source/parse.c @@ -28,7 +28,6 @@ CVS_REVISION(parse_c) #include "input.h" #include "ircaux.h" #include "funny.h" -#include "encrypt.h" #include "input.h" #include "ircterm.h" #include "flood.h" diff --git a/source/tcl.c b/source/tcl.c index d48fcf2..fd58924 100644 --- a/source/tcl.c +++ b/source/tcl.c @@ -12,7 +12,6 @@ #include "server.h" #include "chelp.h" #include "commands.h" -#include "encrypt.h" #include "vars.h" #include "ircaux.h" #include "lastlog.h" diff --git a/source/userlist.c b/source/userlist.c index 32c6f6d..a194229 100644 --- a/source/userlist.c +++ b/source/userlist.c @@ -11,7 +11,6 @@ CVS_REVISION(userlist_c) #include "server.h" #include "commands.h" -#include "encrypt.h" #include "vars.h" #include "ircaux.h" #include "lastlog.h" @@ -26,7 +25,6 @@ CVS_REVISION(userlist_c) #include "alias.h" #include "history.h" #include "funny.h" -#include "ctcp.h" #include "dcc.h" #include "output.h" #include "exec.h" diff --git a/source/vars.c b/source/vars.c index f0aaa5a..d89a269 100644 --- a/source/vars.c +++ b/source/vars.c @@ -19,7 +19,6 @@ CVS_REVISION(vars_c) #include "window.h" #include "lastlog.h" #include "log.h" -#include "encrypt.h" #include "history.h" #include "notify.h" #include "vars.h"