From: Valery Yatsko Date: Wed, 2 Apr 2008 15:37:50 +0000 (+0400) Subject: Reverting some changed related not to moving on libratbox3 but using ratbox3 source! X-Git-Url: https://jfr.im/git/solanum.git/commitdiff_plain/54ac8b60a166683d6ed6fd1a2dadd5191873047a?hp=adbbdec52f5d9dcd617d40725e5cceabf49b2a16 Reverting some changed related not to moving on libratbox3 but using ratbox3 source! --- diff --git a/Makefile.in b/Makefile.in index f86c522c..7714844d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -46,7 +46,7 @@ CFLAGS = @CFLAGS@ # the system one. #CFLAGS= -DNDEBUG -g -O2 -D"FD_SETSIZE=1024" SHELL=/bin/sh -SUBDIRS=libratbox modules extensions src tools ssld doc help +SUBDIRS=libratbox modules extensions src tools servlink doc help CLEANDIRS = ${SUBDIRS} RSA_FILES=rsa_respond/README rsa_respond/respond.c rsa_respond/Makefile diff --git a/configure.ac b/configure.ac index 4adfe73d..6d9b2ef5 100644 --- a/configure.ac +++ b/configure.ac @@ -1237,7 +1237,7 @@ fi AC_CONFIG_FILES( \ Makefile \ - ssld/Makefile \ + servlink/Makefile \ extensions/Makefile \ unsupported/Makefile \ src/Makefile \ diff --git a/dwr.patch b/dwr.patch deleted file mode 100644 index 81fda0fc..00000000 --- a/dwr.patch +++ /dev/null @@ -1,5823 +0,0 @@ -diff -r a44630997728 Makefile.in ---- a/Makefile.in Wed Apr 02 00:10:51 2008 +0200 -+++ b/Makefile.in Wed Apr 02 04:03:16 2008 +0400 -@@ -46,7 +46,7 @@ - # the system one. - #CFLAGS= -DNDEBUG -g -O2 -D"FD_SETSIZE=1024" - SHELL=/bin/sh --SUBDIRS=libratbox modules extensions libcharybdis src tools servlink doc help -+SUBDIRS=libratbox modules extensions src tools servlink doc help - CLEANDIRS = ${SUBDIRS} - RSA_FILES=rsa_respond/README rsa_respond/respond.c rsa_respond/Makefile - -diff -r a44630997728 configure.ac ---- a/configure.ac Wed Apr 02 00:10:51 2008 +0200 -+++ b/configure.ac Wed Apr 02 04:03:16 2008 +0400 -@@ -1233,7 +1233,6 @@ - - AC_CONFIG_FILES( \ - Makefile \ -- libcharybdis/Makefile \ - servlink/Makefile \ - extensions/Makefile \ - unsupported/Makefile \ -diff -r a44630997728 extensions/Makefile.in ---- a/extensions/Makefile.in Wed Apr 02 00:10:51 2008 +0200 -+++ b/extensions/Makefile.in Wed Apr 02 04:03:16 2008 +0400 -@@ -23,7 +23,7 @@ - - IRCDLIBS = @LIBS@ $(SSL_LIBS) - --INCLUDES = -I. -I../include -I../libcharybdis -I../libratbox/include $(SSL_INCLUDES) -+INCLUDES = -I. -I../include -I../libratbox/include $(SSL_INCLUDES) - CPPFLAGS = ${INCLUDES} @CPPFLAGS@ - - SRCS = \ -diff -r a44630997728 extensions/hurt.c ---- a/extensions/hurt.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/extensions/hurt.c Wed Apr 02 04:03:16 2008 +0400 -@@ -14,7 +14,6 @@ - #include "send.h" - #include "numeric.h" - #include "hostmask.h" --#include "event.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "hash.h" -@@ -32,7 +31,7 @@ - typedef struct _hurt_state { - time_t start_time; - uint32_t n_hurts; -- dlink_list hurt_clients; -+ rb_dlink_list hurt_clients; - uint16_t cutoff; - time_t default_expire; - const char *exit_reason; -@@ -78,7 +77,7 @@ - - /* {{{ State containers */ - --dlink_list hurt_confs = { NULL, NULL, 0 }; -+rb_dlink_list hurt_confs = { NULL, NULL, 0 }; - - /* }}} */ - -@@ -152,15 +151,15 @@ - static void - modfini(void) - { -- dlink_node *ptr, *next_ptr; -+ rb_dlink_node *ptr, *next_ptr; - - /* and delete our events. */ - rb_event_delete(hurt_expire_ev); - rb_event_delete(hurt_check_ev); - -- DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) -+ RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) - { -- dlinkDestroy(ptr, &hurt_state.hurt_clients); -+ rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); - } - } - /* }}} */ -@@ -392,14 +391,14 @@ - static void - hurt_check_event(void *arg) - { -- dlink_node *ptr, *next_ptr; -+ rb_dlink_node *ptr, *next_ptr; - struct Client *client_p; - -- DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { -+ RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_state.hurt_clients.head) { - client_p = ptr->data; - if (!EmptyString(client_p->user->suser)) - { -- dlinkDestroy(ptr, &hurt_state.hurt_clients); -+ rb_dlinkDestroy(ptr, &hurt_state.hurt_clients); - sendto_one_notice(client_p, ":HURT restriction removed for this session"); - USED_TARGETS(client_p) = 0; - client_p->localClient->target_last = CurrentTime; /* don't ask --nenolod */ -@@ -414,16 +413,16 @@ - static void - hurt_expire_event(void *unused) - { -- dlink_node *ptr, *next_ptr; -+ rb_dlink_node *ptr, *next_ptr; - hurt_t *hurt; - -- DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) -+ RB_DLINK_FOREACH_SAFE (ptr, next_ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; - - if (hurt->expire <= CurrentTime) - { -- dlinkFindDestroy(hurt, &hurt_confs); -+ rb_dlinkFindDestroy(hurt, &hurt_confs); - hurt_destroy(hurt); - } - } -@@ -441,7 +440,7 @@ - s_assert(data != NULL); - s_assert(data->target != NULL); - -- dlinkFindDestroy(data->target, &hurt_state.hurt_clients); -+ rb_dlinkFindDestroy(data->target, &hurt_state.hurt_clients); - } - /* }}} */ - -@@ -458,7 +457,7 @@ - USED_TARGETS(source_p) = 10; - source_p->localClient->target_last = CurrentTime + 600; /* don't ask --nenolod */ - SetTGChange(source_p); -- dlinkAddAlloc(source_p, &hurt_state.hurt_clients); -+ rb_dlinkAddAlloc(source_p, &hurt_state.hurt_clients); - sendto_one_notice(source_p, ":You are hurt. Please identify to services immediately, or use /stats p for assistance."); - } - } -@@ -468,7 +467,7 @@ - static void - doing_stats_hook(hook_data_int *hdata) - { -- dlink_node *ptr; -+ rb_dlink_node *ptr; - hurt_t *hurt; - struct Client *source_p; - -@@ -502,7 +501,7 @@ - return; - } - -- DLINK_FOREACH(ptr, hurt_confs.head) -+ RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; - sendto_one_numeric(source_p, RPL_STATSKLINE, -@@ -543,10 +542,10 @@ - { - hurt_t *hurt; - -- hurt = MyMalloc(sizeof(hurt_t)); -+ hurt = rb_malloc(sizeof(hurt_t)); - -- DupString(hurt->ip, ip); -- DupString(hurt->reason, reason); -+ hurt->ip = rb_strdup(ip); -+ hurt->reason = rb_strdup(reason); - hurt->expire = CurrentTime + expire; - - return hurt; -@@ -563,25 +562,25 @@ - return; - - h = (hurt_t *) hurt; -- MyFree(h->ip); -- MyFree(h->reason); -- MyFree(h); -+ rb_free(h->ip); -+ rb_free(h->reason); -+ rb_free(h); - } - /* }}} */ - - static void - hurt_add(hurt_t *hurt) - { -- dlinkAddAlloc(hurt, &hurt_confs); -+ rb_dlinkAddAlloc(hurt, &hurt_confs); - } - - static hurt_t * - hurt_find_exact(const char *ip) - { -- dlink_node *ptr; -+ rb_dlink_node *ptr; - hurt_t *hurt; - -- DLINK_FOREACH(ptr, hurt_confs.head) -+ RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; - -@@ -595,10 +594,10 @@ - static hurt_t * - hurt_find(const char *ip) - { -- dlink_node *ptr; -+ rb_dlink_node *ptr; - hurt_t *hurt; - -- DLINK_FOREACH(ptr, hurt_confs.head) -+ RB_DLINK_FOREACH(ptr, hurt_confs.head) - { - hurt = (hurt_t *) ptr->data; - -@@ -614,7 +613,7 @@ - { - hurt_t *hurt = hurt_find_exact(ip); - -- dlinkFindDestroy(hurt, &hurt_confs); -+ rb_dlinkFindDestroy(hurt, &hurt_confs); - hurt_destroy(hurt); - } - -@@ -622,7 +621,7 @@ - static int - heal_nick(struct Client *source_p, struct Client *target_p) - { -- if (dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) -+ if (rb_dlinkFindDestroy(target_p, &hurt_state.hurt_clients)) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s used HEAL on %s", - get_oper_name(source_p), get_client_name(target_p, HIDE_IP)); -diff -r a44630997728 include/cache.h ---- a/include/cache.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/cache.h Wed Apr 02 04:03:16 2008 +0400 -@@ -3,7 +3,6 @@ - #define INCLUDED_CACHE_H - - #include "client.h" --#include "tools.h" - - #define HELP_MAX 100 - -diff -r a44630997728 include/class.h ---- a/include/class.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/class.h Wed Apr 02 04:03:16 2008 +0400 -@@ -26,8 +26,6 @@ - - #ifndef INCLUDED_class_h - #define INCLUDED_class_h -- --#include "tools.h" - - struct ConfItem; - struct Client; -diff -r a44630997728 include/client.h ---- a/include/client.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/client.h Wed Apr 02 04:03:16 2008 +0400 -@@ -35,14 +35,12 @@ - #endif - - #include "ircd_defs.h" --#include "linebuf.h" - #include "channel.h" - #include "res.h" - #include "snomask.h" - #include "irc_string.h" - #include "sprintf_irc.h" - #include "ircd.h" --#include "commio.h" - - /* other structs */ - struct Blacklist; -@@ -611,4 +609,7 @@ - extern void init_uid(void); - extern char *generate_uid(void); - -+void allocate_away(struct Client *); -+void free_away(struct Client *); -+ - #endif /* INCLUDED_client_h */ -diff -r a44630997728 include/hash.h ---- a/include/hash.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/hash.h Wed Apr 02 04:03:16 2008 +0400 -@@ -26,8 +26,6 @@ - - #ifndef INCLUDED_hash_h - #define INCLUDED_hash_h -- --#include "tools.h" - - struct Dictionary; - -diff -r a44630997728 include/irc_string.h ---- a/include/irc_string.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/irc_string.h Wed Apr 02 04:03:16 2008 +0400 -@@ -99,12 +99,6 @@ - size_t strlcat(char *dst, const char *src, size_t siz); - #endif - --#ifdef HAVE_STRDUP --#define DupString(x,y) do { x = strdup(y); if(x == NULL) outofmemory(); } while(0) --#else --#define DupString(x,y) do { x = malloc(strlen(y) + 1); if(x == NULL) outofmemory(); strcpy(x, y); } while(0) --#endif -- - #ifdef HAVE_STRNDUP - #define DupNString(x, y, len) do { x = strndup(y, len); if(x == NULL) outofmemory(); } while (0) - #else -diff -r a44630997728 include/ircd.h ---- a/include/ircd.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/ircd.h Wed Apr 02 04:03:16 2008 +0400 -@@ -28,8 +28,6 @@ - #define INCLUDED_ircd_h - - #include "config.h" --#include "tools.h" --#include "memory.h" - - struct Client; - struct rb_dlink_list; -@@ -82,11 +80,7 @@ - extern rb_dlink_list global_client_list; - extern struct Client *local[]; - extern struct Counter Count; --#if 0 --extern time_t CurrentTime; --#endif - extern struct timeval SystemTime; --#define CurrentTime SystemTime.tv_sec - extern int default_server_capabs; - - extern time_t startup_time; -diff -r a44630997728 include/modules.h ---- a/include/modules.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/modules.h Wed Apr 02 04:03:16 2008 +0400 -@@ -40,7 +40,6 @@ - #endif - - #include "msg.h" --#include "memory.h" - #include "hook.h" - - struct module -diff -r a44630997728 include/monitor.h ---- a/include/monitor.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/monitor.h Wed Apr 02 04:03:16 2008 +0400 -@@ -10,6 +10,8 @@ - #ifndef INCLUDED_monitor_h - #define INCLUDED_monitor_h - -+struct BlockHeap; -+ - struct monitor - { - struct monitor *hnext; -@@ -17,10 +19,12 @@ - rb_dlink_list users; - }; - --extern BlockHeap *monitor_heap; -+extern struct monitor *monitorTable[]; -+ -+#define MONITOR_HASH_BITS 16 -+#define MONITOR_HASH_SIZE (1< - --#include "tools.h" - #include "client.h" - - struct ConfEntry -diff -r a44630997728 include/packet.h ---- a/include/packet.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/packet.h Wed Apr 02 04:03:16 2008 +0400 -@@ -27,8 +27,6 @@ - #ifndef INCLUDED_packet_h - #define INCLUDED_packet_h - --#include "commio.h" -- - /* - * this hides in here rather than a config.h because it really shouldn't - * be tweaked unless you *REALLY REALLY* know what you're doing! -diff -r a44630997728 include/parse.h ---- a/include/parse.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/parse.h Wed Apr 02 04:03:16 2008 +0400 -@@ -28,7 +28,6 @@ - #define INCLUDED_parse_h_h - - #include "irc_dictionary.h" --#include "tools.h" - - struct Message; - struct Client; -diff -r a44630997728 include/res.h ---- a/include/res.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/res.h Wed Apr 02 04:03:16 2008 +0400 -@@ -9,7 +9,6 @@ - - #include "ircd_defs.h" - #include "common.h" --#include "commio.h" - #include "reslib.h" - #include "irc_string.h" - #include "sprintf_irc.h" -diff -r a44630997728 include/s_newconf.h ---- a/include/s_newconf.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/s_newconf.h Wed Apr 02 04:03:16 2008 +0400 -@@ -36,7 +36,6 @@ - #define INCLUDED_s_newconf_h - - #include "setup.h" --#include "tools.h" - - #ifdef HAVE_LIBCRYPTO - #include -diff -r a44630997728 include/send.h ---- a/include/send.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/send.h Wed Apr 02 04:03:16 2008 +0400 -@@ -38,6 +38,8 @@ - /* The nasty global also used in s_serv.c for server bursts */ - extern unsigned long current_serial; - -+extern void send_pop_queue(struct Client *); -+ - extern void send_queued(struct Client *to); - - extern void send_queued_slink_write(int fd, void *data); -diff -r a44630997728 include/stdinc.h ---- a/include/stdinc.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/stdinc.h Wed Apr 02 04:03:16 2008 +0400 -@@ -25,6 +25,7 @@ - - #include "ratbox_lib.h" - #include "config.h" /* Gotta pull in the autoconf stuff */ -+#include "ircd_defs.h" /* Needed for some reasons here -- dwr */ - - /* AIX requires this to be the first thing in the file. */ - #ifdef __GNUC__ -diff -r a44630997728 include/substitution.h ---- a/include/substitution.h Wed Apr 02 00:10:51 2008 +0200 -+++ b/include/substitution.h Wed Apr 02 04:03:16 2008 +0400 -@@ -34,7 +34,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - - #ifndef SUBSTITUTION_H - #define SUBSTITUTION_H -diff -r a44630997728 modules/Makefile.in ---- a/modules/Makefile.in Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/Makefile.in Wed Apr 02 04:03:16 2008 +0400 -@@ -32,7 +32,7 @@ - # Change this later! -- adrian - automoduledir = @moduledir@/autoload - --INCLUDES = -I../include -I../libcharybdis -I../libratbox/include $(SSL_INCLUDES) -+INCLUDES = -I../include -I../libratbox/include $(SSL_INCLUDES) - CPPFLAGS = ${INCLUDES} @CPPFLAGS@ - - CORE_SRCS = \ -diff -r a44630997728 modules/core/m_die.c ---- a/modules/core/m_die.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_die.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,12 +25,10 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" - #include "ircd.h" - #include "irc_string.h" - #include "numeric.h" --#include "commio.h" - #include "s_log.h" - #include "s_conf.h" - #include "send.h" -diff -r a44630997728 modules/core/m_error.c ---- a/modules/core/m_error.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_error.c Wed Apr 02 04:03:16 2008 +0400 -@@ -31,7 +31,6 @@ - #include "numeric.h" - #include "send.h" - #include "msg.h" --#include "memory.h" - #include "modules.h" - #include "s_log.h" - #include "s_conf.h" -diff -r a44630997728 modules/core/m_join.c ---- a/modules/core/m_join.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_join.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -263,7 +262,7 @@ - sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), - me.name, source_p->name, name); - if(successful_join_count) -- source_p->localClient->last_join_time = CurrentTime; -+ source_p->localClient->last_join_time = rb_current_time(); - return 0; - } - -@@ -304,10 +303,10 @@ - /* add the user to the channel */ - add_user_to_channel(chptr, source_p, flags); - if (chptr->mode.join_num && -- CurrentTime - chptr->join_delta >= chptr->mode.join_time) -+ rb_current_time() - chptr->join_delta >= chptr->mode.join_time) - { - chptr->join_count = 0; -- chptr->join_delta = CurrentTime; -+ chptr->join_delta = rb_current_time(); - } - chptr->join_count++; - -@@ -321,7 +320,7 @@ - /* its a new channel, set +nt and burst. */ - if(flags & CHFL_CHANOP) - { -- chptr->channelts = CurrentTime; -+ chptr->channelts = rb_current_time(); - chptr->mode.mode |= MODE_TOPICLIMIT; - chptr->mode.mode |= MODE_NOPRIVMSGS; - -@@ -368,7 +367,7 @@ - channel_member_names(chptr, source_p, 1); - - if(successful_join_count) -- source_p->localClient->last_join_time = CurrentTime; -+ source_p->localClient->last_join_time = rb_current_time(); - - hook_info.client = source_p; - hook_info.chptr = chptr; -@@ -495,10 +494,10 @@ - { - add_user_to_channel(chptr, source_p, CHFL_PEON); - if (chptr->mode.join_num && -- CurrentTime - chptr->join_delta >= chptr->mode.join_time) -+ rb_current_time() - chptr->join_delta >= chptr->mode.join_time) - { - chptr->join_count = 0; -- chptr->join_delta = CurrentTime; -+ chptr->join_delta = rb_current_time(); - } - chptr->join_count++; - sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s", -diff -r a44630997728 modules/core/m_kick.c ---- a/modules/core/m_kick.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_kick.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "irc_string.h" -diff -r a44630997728 modules/core/m_message.c ---- a/modules/core/m_message.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_message.c Wed Apr 02 04:03:16 2008 +0400 -@@ -41,7 +41,6 @@ - #include "msg.h" - #include "packet.h" - #include "send.h" --#include "event.h" - #include "s_newconf.h" - #include "s_stats.h" - -@@ -447,7 +446,7 @@ - { - /* idle time shouldnt be reset by notices --fl */ - if(p_or_n != NOTICE) -- source_p->localClient->last = CurrentTime; -+ source_p->localClient->last = rb_current_time(); - } - - if(chptr->mode.mode & MODE_NOCOLOR) -@@ -531,7 +530,7 @@ - { - /* idletime shouldnt be reset by notice --fl */ - if(p_or_n != NOTICE) -- source_p->localClient->last = CurrentTime; -+ source_p->localClient->last = rb_current_time(); - } - - sendto_channel_flags(client_p, type, source_p, chptr, "%s %c%s :%s", -@@ -552,12 +551,12 @@ - { - target = ptr->data; - -- if(target->expiry < CurrentTime) -+ if(target->expiry < rb_current_time()) - { - rb_dlinkDelete(ptr, &tgchange_list); - rb_patricia_remove(tgchange_tree, target->pnode); -- MyFree(target->ip); -- MyFree(target); -+ rb_free(target->ip); -+ rb_free(target); - } - } - } -@@ -577,7 +576,7 @@ - * - * XXX: is this controversial? - */ -- if(source_p->localClient->target_last > CurrentTime && IsOper(target_p)) -+ if(source_p->localClient->target_last > rb_current_time() && IsOper(target_p)) - return 1; - - hashv = fnv_hash_upper((const unsigned char *)use_id(target_p), 32); -@@ -598,17 +597,17 @@ - if(!IsTGChange(source_p)) - { - SetTGChange(source_p); -- source_p->localClient->target_last = CurrentTime; -+ source_p->localClient->target_last = rb_current_time(); - } - /* clear as many targets as we can */ -- else if((i = (CurrentTime - source_p->localClient->target_last) / 60)) -+ else if((i = (rb_current_time() - source_p->localClient->target_last) / 60)) - { - if(i > USED_TARGETS(source_p)) - USED_TARGETS(source_p) = 0; - else - USED_TARGETS(source_p) -= i; - -- source_p->localClient->target_last = CurrentTime; -+ source_p->localClient->target_last = rb_current_time(); - } - /* cant clear any, full target list */ - else if(USED_TARGETS(source_p) == 10) -@@ -623,7 +622,7 @@ - */ - else - { -- source_p->localClient->target_last = CurrentTime; -+ source_p->localClient->target_last = rb_current_time(); - SetTGChange(source_p); - } - -@@ -654,7 +653,7 @@ - /* reset idle time for message only if its not to self - * and its not a notice */ - if(p_or_n != NOTICE) -- source_p->localClient->last = CurrentTime; -+ source_p->localClient->last = rb_current_time(); - - /* target change stuff, dont limit ctcp replies as that - * would allow people to start filling up random users -@@ -717,7 +716,7 @@ - } - - if((target_p->localClient->last_caller_id_time + -- ConfigFileEntry.caller_id_wait) < CurrentTime) -+ ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, RPL_TARGNOTIFY, -@@ -728,7 +727,7 @@ - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); - -- target_p->localClient->last_caller_id_time = CurrentTime; -+ target_p->localClient->last_caller_id_time = rb_current_time(); - } - /* Only so opers can watch for floods */ - (void) flood_attack_client(p_or_n, source_p, target_p); -@@ -769,11 +768,11 @@ - - if(GlobalSetOptions.floodcount && MyConnect(target_p) && IsClient(source_p)) - { -- if((target_p->localClient->first_received_message_time + 1) < CurrentTime) -+ if((target_p->localClient->first_received_message_time + 1) < rb_current_time()) - { -- delta = CurrentTime - target_p->localClient->first_received_message_time; -+ delta = rb_current_time() - target_p->localClient->first_received_message_time; - target_p->localClient->received_number_of_privmsgs -= delta; -- target_p->localClient->first_received_message_time = CurrentTime; -+ target_p->localClient->first_received_message_time = rb_current_time(); - if(target_p->localClient->received_number_of_privmsgs <= 0) - { - target_p->localClient->received_number_of_privmsgs = 0; -@@ -824,11 +823,11 @@ - - if(GlobalSetOptions.floodcount && MyClient(source_p)) - { -- if((chptr->first_received_message_time + 1) < CurrentTime) -+ if((chptr->first_received_message_time + 1) < rb_current_time()) - { -- delta = CurrentTime - chptr->first_received_message_time; -+ delta = rb_current_time() - chptr->first_received_message_time; - chptr->received_number_of_privmsgs -= delta; -- chptr->first_received_message_time = CurrentTime; -+ chptr->first_received_message_time = rb_current_time(); - if(chptr->received_number_of_privmsgs <= 0) - { - chptr->received_number_of_privmsgs = 0; -diff -r a44630997728 modules/core/m_mode.c ---- a/modules/core/m_mode.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_mode.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,8 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" --#include "balloc.h" - #include "channel.h" - #include "client.h" - #include "hash.h" -diff -r a44630997728 modules/core/m_nick.c ---- a/modules/core/m_nick.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_nick.c Wed Apr 02 04:03:16 2008 +0400 -@@ -734,7 +734,7 @@ - char note[NICKLEN + 10]; - - /* This had to be copied here to avoid problems.. */ -- source_p->tsinfo = CurrentTime; -+ source_p->tsinfo = rb_current_time(); - if(source_p->name[0]) - del_from_client_hash(source_p->name, source_p); - -@@ -774,10 +774,10 @@ - nick, chptr->chname); - return; - } -- if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < CurrentTime) -+ if((source_p->localClient->last_nick_change + ConfigFileEntry.max_nick_time) < rb_current_time()) - source_p->localClient->number_of_nick_changes = 0; - -- source_p->localClient->last_nick_change = CurrentTime; -+ source_p->localClient->last_nick_change = rb_current_time(); - source_p->localClient->number_of_nick_changes++; - - if(ConfigFileEntry.anti_nick_flood && !IsOper(source_p) && -@@ -796,10 +796,10 @@ - if(!samenick) - { - /* force the TS to increase -- jilles */ -- if (source_p->tsinfo >= CurrentTime) -+ if (source_p->tsinfo >= rb_current_time()) - source_p->tsinfo++; - else -- source_p->tsinfo = CurrentTime; -+ source_p->tsinfo = rb_current_time(); - monitor_signoff(source_p); - /* we only do bancache for local users -- jilles */ - if(source_p->user) -@@ -870,7 +870,7 @@ - /* client changing their nick - dont reset ts if its same */ - if(!samenick) - { -- source_p->tsinfo = newts ? newts : CurrentTime; -+ source_p->tsinfo = newts ? newts : rb_current_time(); - monitor_signoff(source_p); - } - -diff -r a44630997728 modules/core/m_part.c ---- a/modules/core/m_part.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_part.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -128,7 +127,7 @@ - if(reason[0] && (is_chanop(msptr) || !MyConnect(source_p) || - ((can_send(chptr, source_p, msptr) > 0 && - (source_p->localClient->firsttime + -- ConfigFileEntry.anti_spam_exit_message_time) < CurrentTime)))) -+ ConfigFileEntry.anti_spam_exit_message_time) < rb_current_time())))) - { - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s PART %s :%s", use_id(source_p), chptr->chname, reason); -diff -r a44630997728 modules/core/m_quit.c ---- a/modules/core/m_quit.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_quit.c Wed Apr 02 04:03:16 2008 +0400 -@@ -74,7 +74,7 @@ - - if(!IsOper(source_p) && - (source_p->localClient->firsttime + ConfigFileEntry.anti_spam_exit_message_time) > -- CurrentTime) -+ rb_current_time()) - { - exit_client(client_p, source_p, source_p, "Client Quit"); - return 0; -diff -r a44630997728 modules/core/m_server.c ---- a/modules/core/m_server.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_server.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,10 +25,8 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" /* client struct */ - #include "common.h" /* TRUE bleah */ --#include "event.h" - #include "hash.h" /* add_to_client_hash */ - #include "irc_string.h" - #include "ircd.h" /* me */ -diff -r a44630997728 modules/core/m_sjoin.c ---- a/modules/core/m_sjoin.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/core/m_sjoin.c Wed Apr 02 04:03:16 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "hash.h" -diff -r a44630997728 modules/m_admin.c ---- a/modules/m_admin.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_admin.c Wed Apr 02 04:03:16 2008 +0400 -@@ -68,7 +68,7 @@ - { - static time_t last_used = 0L; - -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, -@@ -77,7 +77,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - do_admin(source_p); - -@@ -96,14 +96,14 @@ - - if(parc > 1) - { -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "ADMIN"); - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s ADMIN :%s", 1, parc, parv) != HUNTED_ISME) - return 0; -diff -r a44630997728 modules/m_away.c ---- a/modules/m_away.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_away.c Wed Apr 02 04:03:17 2008 +0400 -@@ -70,71 +70,46 @@ - static int - m_away(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) - { -- char *away; -- char *awy2; -- -- if(MyClient(source_p) && !IsFloodDone(source_p)) -- flood_endgrace(source_p); -- -- if(!IsClient(source_p)) -- return 0; -- -- away = source_p->user->away; -- -- if(parc < 2 || EmptyString(parv[1])) -- { -- /* Marking as not away */ -- if(away) -- { -- /* we now send this only if they were away before --is */ -- sendto_server(client_p, NULL, CAP_TS6, NOCAPS, -- ":%s AWAY", use_id(source_p)); -- sendto_server(client_p, NULL, NOCAPS, CAP_TS6, -- ":%s AWAY", source_p->name); -- MyFree(away); -- source_p->user->away = NULL; -- } -- if(MyConnect(source_p)) -- sendto_one_numeric(source_p, RPL_UNAWAY, form_str(RPL_UNAWAY)); -- return 0; -- } -- -- /* Marking as away */ -- -- if(MyConnect(source_p)) -- { -- if(!IsOper(source_p) && -- (CurrentTime - source_p->localClient->last_away) < ConfigFileEntry.pace_wait) -- { -- sendto_one(source_p, form_str(RPL_LOAD2HI), -- me.name, source_p->name, "AWAY"); -- return 0; -- } -- -- source_p->localClient->last_away = CurrentTime; -- } -- -- awy2 = LOCAL_COPY(parv[1]); -- if(strlen(awy2) > AWAYLEN) -- awy2[AWAYLEN] = '\0'; -- -- /* we now send this only if they weren't away already --is */ -- if(!away) -- { -- sendto_server(client_p, NULL, CAP_TS6, NOCAPS, -- ":%s AWAY :%s", use_id(source_p), awy2); -- sendto_server(client_p, NULL, NOCAPS, CAP_TS6, -- ":%s AWAY :%s", source_p->name, awy2); -- } -- else -- MyFree(away); -- -- DupString(away, awy2); -- -- source_p->user->away = away; -- -- if(MyConnect(source_p)) -- sendto_one_numeric(source_p, RPL_NOWAWAY, form_str(RPL_NOWAWAY)); -- -+ if(MyClient(source_p) && !IsFloodDone(source_p)) -+ flood_endgrace(source_p); -+ -+ if(!IsClient(source_p)) -+ return 0; -+ -+ if(parc < 2 || EmptyString(parv[1])) -+ { -+ /* Marking as not away */ -+ if(source_p->user->away != NULL) -+ { -+ /* we now send this only if they were away before --is */ -+ sendto_server(client_p, NULL, CAP_TS6, NOCAPS, -+ ":%s AWAY", use_id(source_p)); -+ sendto_server(client_p, NULL, NOCAPS, CAP_TS6, -+ ":%s AWAY", source_p->name); -+ free_away(source_p); -+ } -+ if(MyConnect(source_p)) -+ sendto_one(source_p, form_str(RPL_UNAWAY), -+ me.name, source_p->name); -+ return 0; -+ } -+ -+ -+ if(source_p->user->away == NULL) -+ { -+ allocate_away(source_p); -+ rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); -+ sendto_server(client_p, NULL, CAP_TS6, NOCAPS, -+ ":%s AWAY :%s", use_id(source_p), source_p->user->away); -+ sendto_server(client_p, NULL, NOCAPS, CAP_TS6, -+ ":%s AWAY :%s", source_p->name, source_p->user->away); -+ -+ } else { -+ rb_strlcpy(source_p->user->away, parv[1], AWAYLEN); -+ } -+ -+ if(MyConnect(source_p)) -+ sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, source_p->name); -+ - return 0; - } -diff -r a44630997728 modules/m_cap.c ---- a/modules/m_cap.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_cap.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "class.h" - #include "client.h" - #include "irc_string.h" -diff -r a44630997728 modules/m_capab.c ---- a/modules/m_capab.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_capab.c Wed Apr 02 04:03:17 2008 +0400 -@@ -78,8 +78,8 @@ - else - client_p->localClient->caps |= CAP_CAP; - -- MyFree(client_p->localClient->fullcaps); -- DupString(client_p->localClient->fullcaps, parv[1]); -+ rb_free(client_p->localClient->fullcaps); -+ client_p->localClient->fullcaps = rb_strdup(parv[1]); - - for (i = 1; i < parc; i++) - { -@@ -116,10 +116,10 @@ - if(!EmptyString(source_p->serv->fullcaps)) - { - source_p->serv->caps = 0; -- MyFree(source_p->serv->fullcaps); -+ rb_free(source_p->serv->fullcaps); - } - -- DupString(source_p->serv->fullcaps, parv[1]); -+ source_p->serv->fullcaps = rb_strdup(parv[1]); - - for (s = strtoken(&p, t, " "); s; s = strtoken(&p, NULL, " ")) - { -diff -r a44630997728 modules/m_challenge.c ---- a/modules/m_challenge.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_challenge.c Wed Apr 02 04:03:17 2008 +0400 -@@ -36,7 +36,6 @@ - #include - #endif - --#include "memory.h" - #include "client.h" - #include "ircd.h" - #include "modules.h" -@@ -92,8 +91,8 @@ - if(target_p->localClient == NULL) - return; - -- MyFree(target_p->localClient->challenge); -- MyFree(target_p->localClient->opername); -+ rb_free(target_p->localClient->challenge); -+ rb_free(target_p->localClient->opername); - target_p->localClient->challenge = NULL; - target_p->localClient->opername = NULL; - target_p->localClient->chal_time = 0; -@@ -129,7 +128,7 @@ - if(!source_p->localClient->challenge) - return 0; - -- if((CurrentTime - source_p->localClient->chal_time) > CHALLENGE_EXPIRES) -+ if((rb_current_time() - source_p->localClient->chal_time) > CHALLENGE_EXPIRES) - { - sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); - ilog(L_FOPER, "EXPIRED CHALLENGE (%s) by (%s!%s@%s) (%s)", -@@ -161,12 +160,12 @@ - source_p->name, source_p->username, - source_p->host); - -- MyFree(b_response); -+ rb_free(b_response); - cleanup_challenge(source_p); - return 0; - } - -- MyFree(b_response); -+ rb_free(b_response); - - oper_p = find_oper_conf(source_p->username, source_p->orighost, - source_p->sockhost, -@@ -227,7 +226,7 @@ - if(!generate_challenge(&challenge, &(source_p->localClient->challenge), oper_p->rsa_pubkey)) - { - char *chal = challenge; -- source_p->localClient->chal_time = CurrentTime; -+ source_p->localClient->chal_time = rb_current_time(); - for(;;) - { - cnt = strlcpy(chal_line, chal, CHALLENGE_WIDTH); -@@ -240,8 +239,8 @@ - } - sendto_one(source_p, form_str(RPL_ENDOFRSACHALLENGE2), - me.name, source_p->name); -- MyFree(challenge); -- DupString(source_p->localClient->opername, oper_p->name); -+ rb_free(challenge); -+ source_p->localClient->opername = rb_strdup(oper_p->name); - } - else - sendto_one_notice(source_p, ":Failed to generate challenge."); -@@ -287,21 +286,21 @@ - { - SHA1_Init(&ctx); - SHA1_Update(&ctx, (u_int8_t *)secret, CHALLENGE_SECRET_LENGTH); -- *r_response = MyMalloc(SHA_DIGEST_LENGTH); -+ *r_response = rb_malloc(SHA_DIGEST_LENGTH); - SHA1_Final((u_int8_t *)*r_response, &ctx); - - length = RSA_size(rsa); -- tmp = MyMalloc(length); -+ tmp = rb_malloc(length); - ret = RSA_public_encrypt(CHALLENGE_SECRET_LENGTH, secret, tmp, rsa, RSA_PKCS1_OAEP_PADDING); - - if (ret >= 0) - { - *r_challenge = (char *)ircd_base64_encode(tmp, ret); -- MyFree(tmp); -+ rb_free(tmp); - return 0; - } -- MyFree(tmp); -- MyFree(*r_response); -+ rb_free(tmp); -+ rb_free(*r_response); - *r_response = NULL; - } - -diff -r a44630997728 modules/m_chghost.c ---- a/modules/m_chghost.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_chghost.c Wed Apr 02 04:03:17 2008 +0400 -@@ -10,7 +10,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -18,7 +17,6 @@ - #include "config.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_serv.h" -diff -r a44630997728 modules/m_close.c ---- a/modules/m_close.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_close.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,11 +25,9 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "send.h" - #include "msg.h" - #include "parse.h" -diff -r a44630997728 modules/m_cmessage.c ---- a/modules/m_cmessage.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_cmessage.c Wed Apr 02 04:03:17 2008 +0400 -@@ -143,7 +143,7 @@ - form_str(ERR_TARGUMODEG), target_p->name); - - if((target_p->localClient->last_caller_id_time + -- ConfigFileEntry.caller_id_wait) < CurrentTime) -+ ConfigFileEntry.caller_id_wait) < rb_current_time()) - { - if(p_or_n != NOTICE) - sendto_one_numeric(source_p, RPL_TARGNOTIFY, -@@ -154,14 +154,14 @@ - me.name, target_p->name, source_p->name, - source_p->username, source_p->host); - -- target_p->localClient->last_caller_id_time = CurrentTime; -+ target_p->localClient->last_caller_id_time = rb_current_time(); - } - - return 0; - } - - if(p_or_n != NOTICE) -- source_p->localClient->last = CurrentTime; -+ source_p->localClient->last = rb_current_time(); - - sendto_anywhere(target_p, source_p, command, ":%s", parv[3]); - return 0; -diff -r a44630997728 modules/m_connect.c ---- a/modules/m_connect.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_connect.c Wed Apr 02 04:03:17 2008 +0400 -@@ -29,7 +29,6 @@ - #include "ircd.h" - #include "irc_string.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -diff -r a44630997728 modules/m_dline.c ---- a/modules/m_dline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_dline.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "class.h" - #include "client.h" -@@ -35,7 +34,6 @@ - #include "ircd.h" - #include "hostmask.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -@@ -188,7 +186,7 @@ - - aconf = make_conf(); - aconf->status = CONF_DLINE; -- DupString(aconf->host, dlhost); -+ aconf->host = rb_strdup(dlhost); - - /* Look for an oper reason */ - if((oper_reason = strchr(reason, '|')) != NULL) -@@ -197,7 +195,7 @@ - oper_reason++; - - if(!EmptyString(oper_reason)) -- DupString(aconf->spasswd, oper_reason); -+ aconf->spasswd = rb_strdup(oper_reason); - } - - if(tdline_time > 0) -@@ -205,8 +203,8 @@ - rb_snprintf(dlbuffer, sizeof(dlbuffer), - "Temporary D-line %d min. - %s (%s)", - (int) (tdline_time / 60), reason, current_date); -- DupString(aconf->passwd, dlbuffer); -- aconf->hold = CurrentTime + tdline_time; -+ aconf->passwd = rb_strdup(dlbuffer); -+ aconf->hold = rb_current_time() + tdline_time; - add_temp_dline(aconf); - - if(EmptyString(oper_reason)) -@@ -236,7 +234,7 @@ - else - { - rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date); -- DupString(aconf->passwd, dlbuffer); -+ aconf->passwd = rb_strdup(dlbuffer); - add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf); - write_confitem(DLINE_TYPE, source_p, NULL, aconf->host, reason, - oper_reason, current_date, 0); -diff -r a44630997728 modules/m_encap.c ---- a/modules/m_encap.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_encap.c Wed Apr 02 04:03:17 2008 +0400 -@@ -30,7 +30,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -38,7 +37,6 @@ - #include "config.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_serv.h" - #include "hash.h" - #include "msg.h" -diff -r a44630997728 modules/m_etrace.c ---- a/modules/m_etrace.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_etrace.c Wed Apr 02 04:03:17 2008 +0400 -@@ -42,7 +42,6 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "s_conf.h" - #include "s_newconf.h" -diff -r a44630997728 modules/m_gline.c ---- a/modules/m_gline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_gline.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "s_gline.h" - #include "channel.h" - #include "client.h" -@@ -36,7 +35,6 @@ - #include "ircd.h" - #include "hostmask.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "scache.h" -@@ -556,15 +554,15 @@ - oper_reason++; - - if(!EmptyString(oper_reason)) -- DupString(aconf->spasswd, oper_reason); -+ aconf->spasswd = rb_strdup(oper_reason); - } - - rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); - -- DupString(aconf->passwd, buffer); -- DupString(aconf->user, user); -- DupString(aconf->host, host); -- aconf->hold = CurrentTime + ConfigFileEntry.gline_time; -+ aconf->passwd = rb_strdup(buffer); -+ aconf->user = rb_strdup(user); -+ aconf->host = rb_strdup(host); -+ aconf->hold = rb_current_time() + ConfigFileEntry.gline_time; - add_gline(aconf); - - sendto_realops_snomask(SNO_GENERAL, L_ALL, -@@ -651,10 +649,10 @@ - sizeof(pending->oper_user2)); - strlcpy(pending->oper_host2, source_p->host, - sizeof(pending->oper_host2)); -- DupString(pending->reason2, reason); -+ pending->reason2 = rb_strdup(reason); - pending->oper_server2 = scache_get_name(source_p->servptr->serv->nameinfo); -- pending->last_gline_time = CurrentTime; -- pending->time_request2 = CurrentTime; -+ pending->last_gline_time = rb_current_time(); -+ pending->time_request2 = rb_current_time(); - return NO; - } - } -@@ -662,7 +660,7 @@ - - /* no pending gline, create a new one */ - pending = (struct gline_pending *) -- MyMalloc(sizeof(struct gline_pending)); -+ rb_malloc(sizeof(struct gline_pending)); - - strlcpy(pending->oper_nick1, source_p->name, - sizeof(pending->oper_nick1)); -@@ -675,11 +673,11 @@ - - strlcpy(pending->user, user, sizeof(pending->user)); - strlcpy(pending->host, host, sizeof(pending->host)); -- DupString(pending->reason1, reason); -+ pending->reason1 = rb_strdup(reason); - pending->reason2 = NULL; - -- pending->last_gline_time = CurrentTime; -- pending->time_request1 = CurrentTime; -+ pending->last_gline_time = rb_current_time(); -+ pending->time_request1 = rb_current_time(); - - rb_dlinkAddAlloc(pending, &pending_glines); - -diff -r a44630997728 modules/m_info.c ---- a/modules/m_info.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_info.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "m_info.h" - #include "channel.h" - #include "client.h" -@@ -624,7 +623,7 @@ - { - static time_t last_used = 0L; - -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), -@@ -633,7 +632,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s INFO :%s", 1, parc, parv) != HUNTED_ISME) - return 0; -diff -r a44630997728 modules/m_invite.c ---- a/modules/m_invite.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_invite.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "common.h" - #include "channel.h" - #include "client.h" -diff -r a44630997728 modules/m_kline.c ---- a/modules/m_kline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_kline.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "class.h" - #include "client.h" -@@ -35,7 +34,6 @@ - #include "ircd.h" - #include "hostmask.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -@@ -45,7 +43,6 @@ - #include "msg.h" - #include "parse.h" - #include "modules.h" --#include "event.h" - #include "reject.h" - - static int mo_kline(struct Client *, struct Client *, int, const char **); -@@ -181,8 +178,8 @@ - current_date = smalldate(); - aconf = make_conf(); - aconf->status = CONF_KILL; -- DupString(aconf->host, host); -- DupString(aconf->user, user); -+ aconf->host = rb_strdup(host); -+ aconf->user = rb_strdup(user); - aconf->port = 0; - - /* Look for an oper reason */ -@@ -192,7 +189,7 @@ - oper_reason++; - - if(!EmptyString(oper_reason)) -- DupString(aconf->spasswd, oper_reason); -+ aconf->spasswd = rb_strdup(oper_reason); - } - - if(tkline_time > 0) -@@ -200,13 +197,13 @@ - rb_snprintf(buffer, sizeof(buffer), - "Temporary K-line %d min. - %s (%s)", - (int) (tkline_time / 60), reason, current_date); -- DupString(aconf->passwd, buffer); -+ aconf->passwd = rb_strdup(buffer); - apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time); - } - else - { - rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); -- DupString(aconf->passwd, buffer); -+ aconf->passwd = rb_strdup(buffer); - apply_kline(source_p, aconf, reason, oper_reason, current_date); - } - -@@ -296,8 +293,8 @@ - aconf = make_conf(); - - aconf->status = CONF_KILL; -- DupString(aconf->user, user); -- DupString(aconf->host, host); -+ aconf->user = rb_strdup(user); -+ aconf->host = rb_strdup(host); - - /* Look for an oper reason */ - if((oper_reason = strchr(reason, '|')) != NULL) -@@ -306,7 +303,7 @@ - oper_reason++; - - if(!EmptyString(oper_reason)) -- DupString(aconf->spasswd, oper_reason); -+ aconf->spasswd = rb_strdup(oper_reason); - } - - current_date = smalldate(); -@@ -316,13 +313,13 @@ - rb_snprintf(buffer, sizeof(buffer), - "Temporary K-line %d min. - %s (%s)", - (int) (tkline_time / 60), reason, current_date); -- DupString(aconf->passwd, buffer); -+ aconf->passwd = rb_strdup(buffer); - apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time); - } - else - { - rb_snprintf(buffer, sizeof(buffer), "%s (%s)", reason, current_date); -- DupString(aconf->passwd, buffer); -+ aconf->passwd = rb_strdup(buffer); - apply_kline(source_p, aconf, reason, oper_reason, current_date); - } - -@@ -511,7 +508,7 @@ - apply_tkline(struct Client *source_p, struct ConfItem *aconf, - const char *reason, const char *oper_reason, const char *current_date, int tkline_time) - { -- aconf->hold = CurrentTime + tkline_time; -+ aconf->hold = rb_current_time() + tkline_time; - add_temp_kline(aconf); - - /* no oper reason.. */ -diff -r a44630997728 modules/m_knock.c ---- a/modules/m_knock.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_knock.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - - #include "stdinc.h" - #include "sprintf_irc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "hash.h" -@@ -138,13 +137,13 @@ - * allow one knock per channel per knock_delay_channel - */ - if(!IsOper(source_p) && -- (source_p->localClient->last_knock + ConfigChannel.knock_delay) > CurrentTime) -+ (source_p->localClient->last_knock + ConfigChannel.knock_delay) > rb_current_time()) - { - sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), - me.name, source_p->name, name, "user"); - return 0; - } -- else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > CurrentTime) -+ else if((chptr->last_knock + ConfigChannel.knock_delay_channel) > rb_current_time()) - { - sendto_one(source_p, form_str(ERR_TOOMANYKNOCK), - me.name, source_p->name, name, "channel"); -@@ -152,13 +151,13 @@ - } - - /* ok, we actually can send the knock, tell client */ -- source_p->localClient->last_knock = CurrentTime; -+ source_p->localClient->last_knock = rb_current_time(); - - sendto_one(source_p, form_str(RPL_KNOCKDLVR), - me.name, source_p->name, name); - } - -- chptr->last_knock = CurrentTime; -+ chptr->last_knock = rb_current_time(); - - if(ConfigChannel.use_knock) - sendto_channel_local(chptr->mode.mode & MODE_FREEINVITE ? ALL_MEMBERS : ONLY_CHANOPS, -diff -r a44630997728 modules/m_list.c ---- a/modules/m_list.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_list.c Wed Apr 02 04:03:17 2008 +0400 -@@ -34,7 +34,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "hash.h" -@@ -47,7 +46,6 @@ - #include "msg.h" - #include "parse.h" - #include "modules.h" --#include "event.h" - - static rb_dlink_list safelisting_clients = { NULL, NULL, 0 }; - -@@ -126,14 +124,14 @@ - if (parc < 2 || !IsChannelName(parv[1])) - { - /* pace this due to the sheer traffic involved */ -- if (((last_used + ConfigFileEntry.pace_wait) > CurrentTime)) -+ if (((last_used + ConfigFileEntry.pace_wait) > rb_current_time())) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "LIST"); - sendto_one(source_p, form_str(RPL_LISTEND), me.name, source_p->name); - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - return mo_list(client_p, source_p, parc, parv); -@@ -251,7 +249,7 @@ - s_assert(MyClient(client_p)); - s_assert(params != NULL); - -- self = MyMalloc(sizeof(struct ListClient)); -+ self = rb_malloc(sizeof(struct ListClient)); - - self->hash_indice = 0; - self->users_min = params->users_min; -@@ -285,7 +283,7 @@ - - rb_dlinkFindDestroy(client_p, &safelisting_clients); - -- MyFree(client_p->localClient->safelist_data); -+ rb_free(client_p->localClient->safelist_data); - - client_p->localClient->safelist_data = NULL; - -diff -r a44630997728 modules/m_lusers.c ---- a/modules/m_lusers.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_lusers.c Wed Apr 02 04:03:17 2008 +0400 -@@ -63,7 +63,7 @@ - - if (parc > 2) - { -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), -@@ -71,7 +71,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s LUSERS %s :%s", 2, parc, parv) != - HUNTED_ISME) -diff -r a44630997728 modules/m_monitor.c ---- a/modules/m_monitor.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_monitor.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" - #include "msg.h" - #include "parse.h" -diff -r a44630997728 modules/m_motd.c ---- a/modules/m_motd.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_motd.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,7 +26,6 @@ - - #include "stdinc.h" - #include "client.h" --#include "tools.h" - #include "ircd.h" - #include "send.h" - #include "numeric.h" -@@ -68,7 +67,7 @@ - { - static time_t last_used = 0; - -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), -@@ -78,7 +77,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s MOTD :%s", 1, parc, parv) != HUNTED_ISME) - return 0; -diff -r a44630997728 modules/m_names.c ---- a/modules/m_names.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_names.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,7 +26,6 @@ - - #include "stdinc.h" - #include "sprintf_irc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -93,7 +92,7 @@ - { - if(!IsOper(source_p)) - { -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "NAMES"); -@@ -102,7 +101,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - names_global(source_p); -diff -r a44630997728 modules/m_oper.c ---- a/modules/m_oper.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_oper.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,13 +25,11 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" - #include "common.h" - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -diff -r a44630997728 modules/m_operspy.c ---- a/modules/m_operspy.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_operspy.c Wed Apr 02 04:03:17 2008 +0400 -@@ -30,7 +30,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -38,7 +37,6 @@ - #include "config.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_serv.h" - #include "hash.h" - #include "msg.h" -diff -r a44630997728 modules/m_pass.c ---- a/modules/m_pass.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_pass.c Wed Apr 02 04:03:17 2008 +0400 -@@ -64,7 +64,7 @@ - { - memset(client_p->localClient->passwd, 0, - strlen(client_p->localClient->passwd)); -- MyFree(client_p->localClient->passwd); -+ rb_free(client_p->localClient->passwd); - } - - DupNString(client_p->localClient->passwd, parv[1], PASSWDLEN); -diff -r a44630997728 modules/m_pong.c ---- a/modules/m_pong.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_pong.c Wed Apr 02 04:03:17 2008 +0400 -@@ -89,7 +89,7 @@ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "End of burst (emulated) from %s (%d seconds)", - source_p->name, -- (signed int) (CurrentTime - source_p->localClient->firsttime)); -+ (signed int) (rb_current_time() - source_p->localClient->firsttime)); - SetEob(source_p); - eob_count++; - call_hook(h_server_eob, source_p); -diff -r a44630997728 modules/m_rehash.c ---- a/modules/m_rehash.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_rehash.c Wed Apr 02 04:03:17 2008 +0400 -@@ -136,9 +136,9 @@ - { - glp_ptr = ptr->data; - -- MyFree(glp_ptr->reason1); -- MyFree(glp_ptr->reason2); -- MyFree(glp_ptr); -+ rb_free(glp_ptr->reason1); -+ rb_free(glp_ptr->reason2); -+ rb_free(glp_ptr); - rb_dlinkDestroy(ptr, &pending_glines); - } - } -diff -r a44630997728 modules/m_resv.c ---- a/modules/m_resv.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_resv.c Wed Apr 02 04:03:17 2008 +0400 -@@ -224,13 +224,13 @@ - aconf = make_conf(); - aconf->status = CONF_RESV_CHANNEL; - aconf->port = 0; -- DupString(aconf->name, name); -- DupString(aconf->passwd, reason); -+ aconf->name = rb_strdup(name); -+ aconf->passwd = rb_strdup(reason); - add_to_resv_hash(aconf->name, aconf); - - if(temp_time > 0) - { -- aconf->hold = CurrentTime + temp_time; -+ aconf->hold = rb_current_time() + temp_time; - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. RESV for [%s] [%s]", -@@ -282,13 +282,13 @@ - aconf = make_conf(); - aconf->status = CONF_RESV_NICK; - aconf->port = 0; -- DupString(aconf->name, name); -- DupString(aconf->passwd, reason); -+ aconf->name = rb_strdup(name); -+ aconf->passwd = rb_strdup(reason); - rb_dlinkAddAlloc(aconf, &resv_conf_list); - - if(temp_time > 0) - { -- aconf->hold = CurrentTime + temp_time; -+ aconf->hold = rb_current_time() + temp_time; - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. RESV for [%s] [%s]", -diff -r a44630997728 modules/m_scan.c ---- a/modules/m_scan.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_scan.c Wed Apr 02 04:03:17 2008 +0400 -@@ -41,7 +41,6 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "s_conf.h" - #include "s_newconf.h" -diff -r a44630997728 modules/m_services.c ---- a/modules/m_services.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_services.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - - #include "stdinc.h" - --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -39,7 +38,6 @@ - #include "config.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_serv.h" -@@ -206,8 +204,8 @@ - newts = atol(parv[3]); - - /* timestamp is older than 15mins, ignore it */ -- if(newts < (CurrentTime - 900)) -- newts = CurrentTime - 900; -+ if(newts < (rb_current_time() - 900)) -+ newts = rb_current_time() - 900; - - target_p->tsinfo = newts; - -@@ -272,7 +270,7 @@ - add_nd_entry(parv[2]); - nd = irc_dictionary_retrieve(nd_dict, parv[2]); - if (nd != NULL) -- nd->expire = CurrentTime + duration; -+ nd->expire = rb_current_time() + duration; - } - - return 0; -diff -r a44630997728 modules/m_set.c ---- a/modules/m_set.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_set.c Wed Apr 02 04:03:17 2008 +0400 -@@ -28,12 +28,10 @@ - - #include "stdinc.h" - #include "client.h" --#include "event.h" - #include "irc_string.h" - #include "sprintf_irc.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "send.h" - #include "common.h" -diff -r a44630997728 modules/m_signon.c ---- a/modules/m_signon.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_signon.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - - #include "stdinc.h" - --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -39,7 +38,6 @@ - #include "config.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_conf.h" - #include "s_serv.h" - #include "hash.h" -@@ -259,7 +257,7 @@ - { - char note[NICKLEN + 10]; - -- send_signon(NULL, target_p, nick, user, host, CurrentTime, login); -+ send_signon(NULL, target_p, nick, user, host, rb_current_time(), login); - - rb_snprintf(note, NICKLEN + 10, "Nick: %s", target_p->name); - rb_note(target_p->localClient->F, note); -diff -r a44630997728 modules/m_snote.c ---- a/modules/m_snote.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_snote.c Wed Apr 02 04:03:17 2008 +0400 -@@ -41,7 +41,6 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "s_conf.h" - #include "s_newconf.h" -diff -r a44630997728 modules/m_stats.c ---- a/modules/m_stats.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_stats.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" /* rb_dlink_node/rb_dlink_list */ - #include "class.h" /* report_classes */ - #include "client.h" /* Client */ - #include "common.h" /* TRUE/FALSE */ -@@ -38,14 +37,11 @@ - #include "numeric.h" /* ERR_xxx */ - #include "scache.h" /* list_scache */ - #include "send.h" /* sendto_one */ --#include "commio.h" /* highest_fd */ - #include "s_conf.h" /* ConfItem */ - #include "s_serv.h" /* hunt_server */ - #include "s_stats.h" /* tstats */ - #include "s_user.h" /* show_opers */ --#include "event.h" /* events */ - #include "blacklist.h" /* dnsbl stuff */ --#include "linebuf.h" - #include "parse.h" - #include "modules.h" - #include "hook.h" -@@ -122,7 +118,7 @@ - static void stats_servlinks(struct Client *); - static void stats_ltrace(struct Client *, int, const char **); - static void stats_ziplinks(struct Client *); -- -+static void stats_comm(struct Client *); - /* This table contains the possible stats items, in order: - * stats letter, function to call, operonly? adminonly? - * case only matters in the stats letter column.. -- fl_ -@@ -139,8 +135,8 @@ - {'D', stats_deny, 1, 0, }, - {'e', stats_exempt, 1, 0, }, - {'E', stats_events, 1, 1, }, -- {'f', rb_dump, 1, 1, }, -- {'F', rb_dump, 1, 1, }, -+ {'f', stats_comm, 1, 1, }, -+ {'F', stats_comm, 1, 1, }, - {'g', stats_pending_glines, 1, 0, }, - {'G', stats_glines, 1, 0, }, - {'h', stats_hubleaf, 0, 0, }, -@@ -199,7 +195,7 @@ - if(MyClient(source_p) && !IsOper(source_p)) - { - /* Check the user is actually allowed to do /stats, and isnt flooding */ -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), -@@ -209,7 +205,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - if(hunt_server (client_p, source_p, ":%s STATS %s :%s", 2, parc, parv) != HUNTED_ISME) -@@ -447,10 +443,17 @@ - }} - - --static void --stats_events (struct Client *source_p) --{ -- show_events (source_p); -+static void -+stats_events_cb(char *str, void *ptr) -+{ -+ sendto_one_numeric(ptr, RPL_STATSDEBUG, "E :%s", str); -+} -+ -+static void -+stats_events (struct Client *source_p) -+{ -+ rb_dump_events(stats_events_cb, source_p); -+ send_pop_queue(source_p); - } - - /* stats_pending_glines() -@@ -891,7 +894,7 @@ - if(0 == secs) - secs = 1; - -- rup = (CurrentTime - startup_time) * hzz; -+ rup = (rb_current_time() - startup_time) * hzz; - if(0 == rup) - rup = 1; - -@@ -932,7 +935,7 @@ - { - time_t now; - -- now = CurrentTime - startup_time; -+ now = rb_current_time() - startup_time; - sendto_one_numeric(source_p, RPL_STATSUPTIME, - form_str (RPL_STATSUPTIME), - now / 86400, (now / 3600) % 24, -@@ -1046,7 +1049,7 @@ - target_p = ptr->data; - - j++; -- seconds = CurrentTime - target_p->localClient->firsttime; -+ seconds = rb_current_time() - target_p->localClient->firsttime; - - days = (int) (seconds / 86400); - seconds %= 86400; -@@ -1060,8 +1063,8 @@ - "Connected: %d day%s, %d:%02d:%02d", - target_p->name, - (target_p->serv->by[0] ? target_p->serv->by : "Remote."), -- (int) (CurrentTime - target_p->localClient->lasttime), -- (int) linebuf_len (&target_p->localClient->buf_sendq), -+ (int) (rb_current_time() - target_p->localClient->lasttime), -+ (int) rb_linebuf_len (&target_p->localClient->buf_sendq), - days, (days == 1) ? "" : "s", hours, minutes, - (int) seconds); - } -@@ -1186,14 +1189,14 @@ - sendto_one(source_p, Sformat, - get_id(&me, source_p), RPL_STATSLINKINFO, get_id(source_p, source_p), - get_server_name(target_p, SHOW_IP), -- (int) linebuf_len (&target_p->localClient->buf_sendq), -+ (int) rb_linebuf_len (&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, -- CurrentTime - target_p->localClient->firsttime, -- (CurrentTime > target_p->localClient->lasttime) ? -- (CurrentTime - target_p->localClient->lasttime) : 0, -+ rb_current_time() - target_p->localClient->firsttime, -+ (rb_current_time() > target_p->localClient->lasttime) ? -+ (rb_current_time() - target_p->localClient->lasttime) : 0, - IsOper (source_p) ? show_capabilities (target_p) : "TS"); - } - -@@ -1207,7 +1210,7 @@ - "? :Recv total : %7.2f %s", - _GMKv (receiveK), _GMKs (receiveK)); - -- uptime = (CurrentTime - startup_time); -+ uptime = (rb_current_time() - startup_time); - - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "? :Server send: %7.2f %s (%4.1f K/s)", -@@ -1339,14 +1342,14 @@ - { - sendto_one_numeric(source_p, RPL_STATSLINKINFO, Lformat, - get_server_name(target_p, SHOW_IP), -- (int) linebuf_len(&target_p->localClient->buf_sendq), -+ (int) rb_linebuf_len(&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, -- CurrentTime - target_p->localClient->firsttime, -- (CurrentTime > target_p->localClient->lasttime) ? -- (CurrentTime - target_p->localClient->lasttime) : 0, -+ rb_current_time() - target_p->localClient->firsttime, -+ (rb_current_time() > target_p->localClient->lasttime) ? -+ (rb_current_time() - target_p->localClient->lasttime) : 0, - IsOper(source_p) ? show_capabilities(target_p) : "-"); - } - -@@ -1358,16 +1361,30 @@ - get_client_name(target_p, SHOW_IP) : - get_client_name(target_p, HIDE_IP)) : - get_client_name(target_p, MASK_IP), -- (int) linebuf_len(&target_p->localClient->buf_sendq), -+ (int) rb_linebuf_len(&target_p->localClient->buf_sendq), - (int) target_p->localClient->sendM, - (int) target_p->localClient->sendK, - (int) target_p->localClient->receiveM, - (int) target_p->localClient->receiveK, -- CurrentTime - target_p->localClient->firsttime, -- (CurrentTime > target_p->localClient->lasttime) ? -- (CurrentTime - target_p->localClient->lasttime) : 0, -+ rb_current_time() - target_p->localClient->firsttime, -+ (rb_current_time() > target_p->localClient->lasttime) ? -+ (rb_current_time() - target_p->localClient->lasttime) : 0, - "-"); - } -+} -+ -+static void -+rb_dump_fd_callback(int fd, const char *desc, void *data) -+{ -+ struct Client *source_p = data; -+ sendto_one_numeric(source_p, RPL_STATSDEBUG, "F :fd %-3d desc '%s'", fd, desc); -+} -+ -+static void -+stats_comm(struct Client *source_p) -+{ -+ rb_dump_fd(rb_dump_fd_callback, source_p); -+ send_pop_queue(source_p); - } - - /* -diff -r a44630997728 modules/m_svinfo.c ---- a/modules/m_svinfo.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_svinfo.c Wed Apr 02 04:03:17 2008 +0400 -@@ -78,11 +78,11 @@ - } - - /* -- * since we're here, might as well set CurrentTime while we're at it -+ * since we're here, might as well set rb_current_time() while we're at it - */ - set_time(); - theirtime = atol(parv[4]); -- deltat = abs(theirtime - CurrentTime); -+ deltat = abs(theirtime - rb_current_time()); - - if(deltat > ConfigFileEntry.ts_max_delta) - { -@@ -90,13 +90,13 @@ - "Link %s dropped, excessive TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", - get_server_name(source_p, SHOW_IP), -- (long) CurrentTime, (long) theirtime, deltat); -+ (long) rb_current_time(), (long) theirtime, deltat); - ilog(L_SERVER, - "Link %s dropped, excessive TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", -- log_client_name(source_p, SHOW_IP), (long) CurrentTime, (long) theirtime, deltat); -+ log_client_name(source_p, SHOW_IP), (long) rb_current_time(), (long) theirtime, deltat); - snprintf(squitreason, sizeof squitreason, "Excessive TS delta (my TS=%ld, their TS=%ld, delta=%d)", -- (long) CurrentTime, (long) theirtime, deltat); -+ (long) rb_current_time(), (long) theirtime, deltat); - exit_client(source_p, source_p, source_p, squitreason); - return 0; - } -@@ -106,7 +106,7 @@ - sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, - "Link %s notable TS delta" - " (my TS=%ld, their TS=%ld, delta=%d)", -- source_p->name, (long) CurrentTime, (long) theirtime, deltat); -+ source_p->name, (long) rb_current_time(), (long) theirtime, deltat); - } - - return 0; -diff -r a44630997728 modules/m_tb.c ---- a/modules/m_tb.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_tb.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -diff -r a44630997728 modules/m_testline.c ---- a/modules/m_testline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_testline.c Wed Apr 02 04:03:17 2008 +0400 -@@ -30,7 +30,6 @@ - * $Id: m_testline.c 3303 2007-03-28 15:22:49Z jilles $ - */ - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "client.h" - #include "modules.h" -@@ -82,7 +81,7 @@ - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - resv_p->hold ? 'q' : 'Q', -- resv_p->hold ? (long) ((resv_p->hold - CurrentTime) / 60) : 0L, -+ resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, - resv_p->name, resv_p->passwd); - /* this is a false positive, so make sure it isn't counted in stats q - * --nenolod -@@ -133,7 +132,7 @@ - me.name, source_p->name, - (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'd' : 'D', - (aconf->flags & CONF_FLAGS_TEMPORARY) ? -- (long) ((aconf->hold - CurrentTime) / 60) : 0L, -+ (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - aconf->host, aconf->passwd); - - return 0; -@@ -169,7 +168,7 @@ - me.name, source_p->name, - (aconf->flags & CONF_FLAGS_TEMPORARY) ? 'k' : 'K', - (aconf->flags & CONF_FLAGS_TEMPORARY) ? -- (long) ((aconf->hold - CurrentTime) / 60) : 0L, -+ (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - buf, aconf->passwd); - return 0; - } -@@ -179,7 +178,7 @@ - aconf->user, aconf->host); - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, -- 'G', (long) ((aconf->hold - CurrentTime) / 60), -+ 'G', (long) ((aconf->hold - rb_current_time()) / 60), - buf, aconf->passwd); - return 0; - } -@@ -191,7 +190,7 @@ - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - resv_p->hold ? 'q' : 'Q', -- resv_p->hold ? (long) ((resv_p->hold - CurrentTime) / 60) : 0L, -+ resv_p->hold ? (long) ((resv_p->hold - rb_current_time()) / 60) : 0L, - resv_p->name, resv_p->passwd); - - /* this is a false positive, so make sure it isn't counted in stats q -@@ -231,7 +230,7 @@ - sendto_one(source_p, form_str(RPL_TESTLINE), - me.name, source_p->name, - aconf->hold ? 'x' : 'X', -- aconf->hold ? (long) ((aconf->hold - CurrentTime) / 60) : 0L, -+ aconf->hold ? (long) ((aconf->hold - rb_current_time()) / 60) : 0L, - aconf->name, aconf->passwd); - return 0; - } -diff -r a44630997728 modules/m_time.c ---- a/modules/m_time.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_time.c Wed Apr 02 04:03:17 2008 +0400 -@@ -93,7 +93,7 @@ - time_t lclock; - int minswest; - -- lclock = CurrentTime; -+ lclock = rb_current_time(); - gm = gmtime(&lclock); - memcpy((void *) &gmbuf, (void *) gm, sizeof(gmbuf)); - gm = &gmbuf; -diff -r a44630997728 modules/m_topic.c ---- a/modules/m_topic.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_topic.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "hash.h" -@@ -104,7 +103,7 @@ - char topic_info[USERHOST_REPLYLEN]; - rb_sprintf(topic_info, "%s!%s@%s", - source_p->name, source_p->username, source_p->host); -- set_channel_topic(chptr, parv[2], topic_info, CurrentTime); -+ set_channel_topic(chptr, parv[2], topic_info, rb_current_time()); - - sendto_server(client_p, chptr, CAP_TS6, NOCAPS, - ":%s TOPIC %s :%s", -diff -r a44630997728 modules/m_trace.c ---- a/modules/m_trace.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_trace.c Wed Apr 02 04:03:17 2008 +0400 -@@ -34,7 +34,6 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "s_conf.h" - #include "s_newconf.h" -@@ -370,7 +369,7 @@ - sendto_one_numeric(source_p, RPL_TRACEUNKNOWN, - form_str(RPL_TRACEUNKNOWN), - class_name, name, ip, -- CurrentTime - target_p->localClient->firsttime); -+ rb_current_time() - target_p->localClient->firsttime); - cnt++; - break; - -@@ -387,16 +386,16 @@ - form_str(RPL_TRACEOPERATOR), - class_name, name, - show_ip(source_p, target_p) ? ip : "255.255.255.255", -- CurrentTime - target_p->localClient->lasttime, -- CurrentTime - target_p->localClient->last); -+ rb_current_time() - target_p->localClient->lasttime, -+ rb_current_time() - target_p->localClient->last); - - else - sendto_one_numeric(source_p, RPL_TRACEUSER, - form_str(RPL_TRACEUSER), - class_name, name, - show_ip(source_p, target_p) ? ip : "255.255.255.255", -- CurrentTime - target_p->localClient->lasttime, -- CurrentTime - target_p->localClient->last); -+ rb_current_time() - target_p->localClient->lasttime, -+ rb_current_time() - target_p->localClient->last); - cnt++; - } - break; -@@ -411,7 +410,7 @@ - sendto_one_numeric(source_p, RPL_TRACESERVER, form_str(RPL_TRACESERVER), - class_name, servcount, usercount, name, - *(target_p->serv->by) ? target_p->serv->by : "*", "*", -- me.name, CurrentTime - target_p->localClient->lasttime); -+ me.name, rb_current_time() - target_p->localClient->lasttime); - cnt++; - - } -diff -r a44630997728 modules/m_user.c ---- a/modules/m_user.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_user.c Wed Apr 02 04:03:17 2008 +0400 -@@ -73,8 +73,8 @@ - *p = '\0'; - - rb_snprintf(buf, sizeof(buf), "%s %s", parv[2], parv[3]); -- MyFree(source_p->localClient->fullcaps); -- DupString(source_p->localClient->fullcaps, buf); -+ rb_free(source_p->localClient->fullcaps); -+ source_p->localClient->fullcaps = rb_strdup(buf); - - do_local_user(client_p, source_p, parv[1], parv[4]); - return 0; -diff -r a44630997728 modules/m_version.c ---- a/modules/m_version.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_version.c Wed Apr 02 04:03:17 2008 +0400 -@@ -61,7 +61,7 @@ - - if(parc > 1) - { -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - /* safe enough to give this on a local connect only */ - sendto_one(source_p, form_str(RPL_LOAD2HI), -@@ -69,7 +69,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - - if(hunt_server(client_p, source_p, ":%s VERSION :%s", 1, parc, parv) != HUNTED_ISME) - return 0; -diff -r a44630997728 modules/m_who.c ---- a/modules/m_who.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_who.c Wed Apr 02 04:03:17 2008 +0400 -@@ -24,7 +24,6 @@ - * $Id: m_who.c 3350 2007-04-02 22:03:08Z jilles $ - */ - #include "stdinc.h" --#include "tools.h" - #include "common.h" - #include "client.h" - #include "channel.h" -@@ -177,7 +176,7 @@ - /* it has to be a global who at this point, limit it */ - if(!IsOper(source_p)) - { -- if((last_used + ConfigFileEntry.pace_wait) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHO"); -@@ -186,7 +185,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - /* Note: operspy_dont_care_user_info does not apply to -diff -r a44630997728 modules/m_whois.c ---- a/modules/m_whois.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_whois.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "common.h" - #include "client.h" - #include "hash.h" -@@ -91,7 +90,7 @@ - if(!IsOper(source_p)) - { - /* seeing as this is going across servers, we should limit it */ -- if((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHOIS"); -@@ -100,7 +99,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - if(hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1, parc, parv) != -@@ -346,7 +345,7 @@ - - sendto_one_numeric(source_p, RPL_WHOISIDLE, form_str(RPL_WHOISIDLE), - target_p->name, -- CurrentTime - target_p->localClient->last, -+ rb_current_time() - target_p->localClient->last, - target_p->localClient->firsttime); - } - else -diff -r a44630997728 modules/m_whowas.c ---- a/modules/m_whowas.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_whowas.c Wed Apr 02 04:03:17 2008 +0400 -@@ -69,7 +69,7 @@ - - if(!IsOper(source_p)) - { -- if((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime) -+ if((last_used + ConfigFileEntry.pace_wait_simple) > rb_current_time()) - { - sendto_one(source_p, form_str(RPL_LOAD2HI), - me.name, source_p->name, "WHOWAS"); -@@ -78,7 +78,7 @@ - return 0; - } - else -- last_used = CurrentTime; -+ last_used = rb_current_time(); - } - - -diff -r a44630997728 modules/m_xline.c ---- a/modules/m_xline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/modules/m_xline.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "client.h" -@@ -40,7 +39,6 @@ - #include "class.h" - #include "ircd.h" - #include "numeric.h" --#include "memory.h" - #include "s_log.h" - #include "s_serv.h" - #include "whowas.h" -@@ -313,17 +311,17 @@ - } - - *new = '\0'; -- DupString(aconf->name, tmp); -+ aconf->name = rb_strdup(tmp); - } - else -- DupString(aconf->name, name); -+ aconf->name = rb_strdup(name); - -- DupString(aconf->passwd, reason); -+ aconf->passwd = rb_strdup(reason); - collapse(aconf->name); - - if(temp_time > 0) - { -- aconf->hold = CurrentTime + temp_time; -+ aconf->hold = rb_current_time() + temp_time; - - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s added temporary %d min. X-Line for [%s] [%s]", -@@ -347,7 +345,7 @@ - get_oper_name(source_p), name, reason); - } - -- dlinkAddAlloc(aconf, &xline_conf_list); -+ rb_dlinkAddAlloc(aconf, &xline_conf_list); - check_xlines(); - } - -@@ -375,7 +373,7 @@ - - rb_sprintf(buffer, "\"%s\",\"0\",\"%s\",\"%s\",%ld\n", - aconf->name, aconf->passwd, -- get_oper_name(source_p), CurrentTime); -+ get_oper_name(source_p), rb_current_time()); - - if(fputs(buffer, out) == -1) - { -diff -r a44630997728 src/Makefile.in ---- a/src/Makefile.in Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/Makefile.in Wed Apr 02 04:03:17 2008 +0400 -@@ -33,9 +33,9 @@ - SSL_LIBS = @SSL_LIBS@ - SSL_INCLUDES = @SSL_INCLUDES@ - --IRCDLIBS = @MODULES_LIBS@ -L../libcharybdis -lcharybdis -L../libratbox/src/.libs -lratbox @LIBS@ $(SSL_LIBS) -+IRCDLIBS = @MODULES_LIBS@ -L../libratbox/src/.libs -lratbox @LIBS@ $(SSL_LIBS) - --INCLUDES = -I../include -I../libcharybdis -I../libratbox/include $(SSL_INCLUDES) -+INCLUDES = -I../include -I../libratbox/include $(SSL_INCLUDES) - CPPFLAGS = ${INCLUDES} @CPPFLAGS@ - - default: all -diff -r a44630997728 src/blacklist.c ---- a/src/blacklist.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/blacklist.c Wed Apr 02 04:03:17 2008 +0400 -@@ -36,8 +36,6 @@ - #include "stdinc.h" - #include "client.h" - #include "res.h" --#include "tools.h" --#include "memory.h" - #include "numeric.h" - #include "reject.h" - #include "s_conf.h" -@@ -74,7 +72,7 @@ - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "blacklist_dns_callback(): blcptr->client_p->preClient (%s) is NULL", get_client_name(blcptr->client_p, HIDE_IP)); -- MyFree(blcptr); -+ rb_free(blcptr); - return; - } - -@@ -84,12 +82,12 @@ - if (reply->addr.ss_family == AF_INET && - !memcmp(&((struct sockaddr_in *)&reply->addr)->sin_addr, "\177\0\0", 3)) - listed = TRUE; -- else if (blcptr->blacklist->lastwarning + 3600 < CurrentTime) -+ else if (blcptr->blacklist->lastwarning + 3600 < rb_current_time()) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Garbage reply from blacklist %s", - blcptr->blacklist->host); -- blcptr->blacklist->lastwarning = CurrentTime; -+ blcptr->blacklist->lastwarning = rb_current_time(); - } - } - -@@ -112,13 +110,13 @@ - register_local_user(blcptr->client_p, blcptr->client_p, buf); - } - -- MyFree(blcptr); -+ rb_free(blcptr); - } - - /* XXX: no IPv6 implementation, not to concerned right now though. */ - static void initiate_blacklist_dnsquery(struct Blacklist *blptr, struct Client *client_p) - { -- struct BlacklistClient *blcptr = MyMalloc(sizeof(struct BlacklistClient)); -+ struct BlacklistClient *blcptr = rb_malloc(sizeof(struct BlacklistClient)); - char buf[IRCD_BUFSIZE]; - int ip[4]; - -@@ -151,7 +149,7 @@ - blptr = find_blacklist(name); - if (blptr == NULL) - { -- blptr = MyMalloc(sizeof(struct Blacklist)); -+ blptr = rb_malloc(sizeof(struct Blacklist)); - rb_dlinkAddAlloc(blptr, &blacklist_list); - } - else -@@ -169,7 +167,7 @@ - if (blptr->status & CONF_ILLEGAL && blptr->refcount <= 0) - { - rb_dlinkFindDestroy(blptr, &blacklist_list); -- MyFree(blptr); -+ rb_free(blptr); - } - } - -@@ -203,7 +201,7 @@ - rb_dlinkDelete(&blcptr->node, &client_p->preClient->dnsbl_queries); - unref_blacklist(blcptr->blacklist); - delete_resolver_queries(&blcptr->dns_query); -- MyFree(blcptr); -+ rb_free(blcptr); - } - } - -@@ -220,7 +218,7 @@ - blptr->status |= CONF_ILLEGAL; - else - { -- MyFree(ptr->data); -+ rb_free(ptr->data); - rb_dlinkDestroy(ptr, &blacklist_list); - } - } -diff -r a44630997728 src/cache.c ---- a/src/cache.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/cache.c Wed Apr 02 04:03:17 2008 +0400 -@@ -36,11 +36,7 @@ - #include "ircd_defs.h" - #include "common.h" - #include "s_conf.h" --#include "tools.h" - #include "client.h" --#include "memory.h" --#include "balloc.h" --#include "event.h" - #include "hash.h" - #include "cache.h" - #include "sprintf_irc.h" -diff -r a44630997728 src/channel.c ---- a/src/channel.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/channel.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -41,9 +40,6 @@ - #include "whowas.h" - #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ - #include "s_newconf.h" --#include "event.h" --#include "memory.h" --#include "balloc.h" - #include "s_log.h" - - extern rb_dlink_list global_channel_list; -@@ -93,14 +89,14 @@ - { - struct Channel *chptr; - chptr = BlockHeapAlloc(channel_heap); -- DupString(chptr->chname, chname); -+ chptr->chname = rb_strdup(chname); - return (chptr); - } - - void - free_channel(struct Channel *chptr) - { -- MyFree(chptr->chname); -+ rb_free(chptr->chname); - BlockHeapFree(channel_heap, chptr); - } - -@@ -109,8 +105,8 @@ - { - struct Ban *bptr; - bptr = BlockHeapAlloc(ban_heap); -- DupString(bptr->banstr, banstr); -- DupString(bptr->who, who); -+ bptr->banstr = rb_strdup(banstr); -+ bptr->who = rb_strdup(who); - - return (bptr); - } -@@ -118,8 +114,8 @@ - void - free_ban(struct Ban *bptr) - { -- MyFree(bptr->banstr); -- MyFree(bptr->who); -+ rb_free(bptr->banstr); -+ rb_free(bptr->who); - BlockHeapFree(ban_heap, bptr); - } - -@@ -246,7 +242,7 @@ - if(client_p->servptr == &me) - rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); - -- chptr->users_last = CurrentTime; -+ chptr->users_last = rb_current_time(); - - if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) - destroy_channel(chptr); -@@ -283,7 +279,7 @@ - if(client_p->servptr == &me) - rb_dlinkDelete(&msptr->locchannode, &chptr->locmembers); - -- chptr->users_last = CurrentTime; -+ chptr->users_last = rb_current_time(); - - if(!(chptr->mode.mode & MODE_PERMANENT) && rb_dlink_list_length(&chptr->members) <= 0) - destroy_channel(chptr); -@@ -788,7 +784,7 @@ - /* join throttling stuff --nenolod */ - else if(chptr->mode.join_num > 0 && chptr->mode.join_time > 0) - { -- if ((CurrentTime - chptr->join_delta <= -+ if ((rb_current_time() - chptr->join_delta <= - chptr->mode.join_time) && (chptr->join_count >= - chptr->mode.join_num)) - i = ERR_THROTTLE; -@@ -946,7 +942,7 @@ - else - { - if((t_delta = -- (CurrentTime - source_p->localClient->last_leave_time)) > -+ (rb_current_time() - source_p->localClient->last_leave_time)) > - JOIN_LEAVE_COUNT_EXPIRE_TIME) - { - decrement_count = (t_delta / JOIN_LEAVE_COUNT_EXPIRE_TIME); -@@ -957,7 +953,7 @@ - } - else - { -- if((CurrentTime - -+ if((rb_current_time() - - (source_p->localClient->last_join_time)) < GlobalSetOptions.spam_time) - { - /* oh, its a possible spambot */ -@@ -965,9 +961,9 @@ - } - } - if(name != NULL) -- source_p->localClient->last_join_time = CurrentTime; -+ source_p->localClient->last_join_time = rb_current_time(); - else -- source_p->localClient->last_leave_time = CurrentTime; -+ source_p->localClient->last_leave_time = rb_current_time(); - } - } - -diff -r a44630997728 src/chmode.c ---- a/src/chmode.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/chmode.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,7 +26,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -42,9 +41,6 @@ - #include "whowas.h" - #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ - #include "s_newconf.h" --#include "event.h" --#include "memory.h" --#include "balloc.h" - #include "s_log.h" - - /* bitmasks for error returns, so we send once per call */ -@@ -133,7 +129,7 @@ - strlcpy(who, source_p->name, sizeof(who)); - - actualBan = allocate_ban(realban, who); -- actualBan->when = CurrentTime; -+ actualBan->when = rb_current_time(); - - rb_dlinkAdd(actualBan, &actualBan->node, list); - -diff -r a44630997728 src/class.c ---- a/src/class.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/class.c Wed Apr 02 04:03:17 2008 +0400 -@@ -27,7 +27,6 @@ - #include "stdinc.h" - #include "config.h" - --#include "tools.h" - #include "class.h" - #include "client.h" - #include "common.h" -@@ -37,7 +36,6 @@ - #include "s_newconf.h" - #include "send.h" - #include "irc_string.h" --#include "memory.h" - - #define BAD_CONF_CLASS -1 - #define BAD_PING -2 -@@ -51,7 +49,7 @@ - { - struct Class *tmp; - -- tmp = (struct Class *) MyMalloc(sizeof(struct Class)); -+ tmp = (struct Class *) rb_malloc(sizeof(struct Class)); - - ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; - PingFreq(tmp) = DEFAULT_PINGFREQUENCY; -@@ -68,8 +66,8 @@ - if(tmp->ip_limits) - rb_destroy_patricia(tmp->ip_limits, NULL); - -- MyFree(tmp->class_name); -- MyFree(tmp); -+ rb_free(tmp->class_name); -+ rb_free(tmp); - - } - -@@ -274,7 +272,7 @@ - initclass() - { - default_class = make_class(); -- DupString(ClassName(default_class), "default"); -+ ClassName(default_class) = rb_strdup("default"); - } - - /* -diff -r a44630997728 src/client.c ---- a/src/client.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/client.c Wed Apr 02 04:03:17 2008 +0400 -@@ -27,11 +27,9 @@ - #include "stdinc.h" - #include "config.h" - --#include "tools.h" - #include "client.h" - #include "class.h" - #include "common.h" --#include "event.h" - #include "hash.h" - #include "irc_string.h" - #include "sprintf_irc.h" -@@ -40,7 +38,6 @@ - #include "numeric.h" - #include "packet.h" - #include "s_auth.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -@@ -49,11 +46,8 @@ - #include "send.h" - #include "whowas.h" - #include "s_user.h" --#include "linebuf.h" - #include "hash.h" --#include "memory.h" - #include "hostmask.h" --#include "balloc.h" - #include "listener.h" - #include "hook.h" - #include "msg.h" -@@ -160,7 +154,7 @@ - SetMyConnect(client_p); - client_p->localClient = localClient; - -- client_p->localClient->lasttime = client_p->localClient->firsttime = CurrentTime; -+ client_p->localClient->lasttime = client_p->localClient->firsttime = rb_current_time(); - - client_p->localClient->F = NULL; - client_p->localClient->ctrlfd = -1; -@@ -229,13 +223,13 @@ - { - memset(client_p->localClient->passwd, 0, - strlen(client_p->localClient->passwd)); -- MyFree(client_p->localClient->passwd); -+ rb_free(client_p->localClient->passwd); - } - -- MyFree(client_p->localClient->challenge); -- MyFree(client_p->localClient->fullcaps); -- MyFree(client_p->localClient->opername); -- MyFree(client_p->localClient->mangledhost); -+ rb_free(client_p->localClient->challenge); -+ rb_free(client_p->localClient->fullcaps); -+ rb_free(client_p->localClient->opername); -+ rb_free(client_p->localClient->mangledhost); - - BlockHeapFree(lclient_heap, client_p->localClient); - client_p->localClient = NULL; -@@ -309,13 +303,13 @@ - - ping = get_client_ping(client_p); - -- if(ping < (CurrentTime - client_p->localClient->lasttime)) -+ if(ping < (rb_current_time() - client_p->localClient->lasttime)) - { - /* - * If the client/server hasnt talked to us in 2*ping seconds - * and it has a ping time, then close its connection. - */ -- if(((CurrentTime - client_p->localClient->lasttime) >= (2 * ping) -+ if(((rb_current_time() - client_p->localClient->lasttime) >= (2 * ping) - && (client_p->flags & FLAGS_PINGSENT))) - { - if(IsServer(client_p)) -@@ -329,7 +323,7 @@ - } - (void) rb_snprintf(scratch, sizeof(scratch), - "Ping timeout: %d seconds", -- (int) (CurrentTime - client_p->localClient->lasttime)); -+ (int) (rb_current_time() - client_p->localClient->lasttime)); - - exit_client(client_p, client_p, &me, scratch); - continue; -@@ -343,7 +337,7 @@ - */ - client_p->flags |= FLAGS_PINGSENT; - /* not nice but does the job */ -- client_p->localClient->lasttime = CurrentTime - ping; -+ client_p->localClient->lasttime = rb_current_time() - ping; - sendto_one(client_p, "PING :%s", me.name); - } - } -@@ -379,7 +373,7 @@ - */ - - timeout = IsAnyServer(client_p) ? ConfigFileEntry.connect_timeout : 30; -- if((CurrentTime - client_p->localClient->firsttime) > timeout) -+ if((rb_current_time() - client_p->localClient->firsttime) > timeout) - { - if(IsAnyServer(client_p)) - { -@@ -797,8 +791,8 @@ - if(client_p->serv->user != NULL) - free_user(client_p->serv->user, client_p); - if(client_p->serv->fullcaps) -- MyFree(client_p->serv->fullcaps); -- MyFree(client_p->serv); -+ rb_free(client_p->serv->fullcaps); -+ rb_free(client_p->serv); - } - } - -@@ -1289,7 +1283,7 @@ - */ - abt->client->flags &= ~FLAGS_CLOSING; - exit_client(abt->client, abt->client, &me, abt->notice); -- MyFree(abt); -+ rb_free(abt); - } - } - -@@ -1307,7 +1301,7 @@ - if(IsDead(client_p) || IsClosing(client_p) || IsMe(client_p)) - return; - -- abt = (struct abort_client *) MyMalloc(sizeof(struct abort_client)); -+ abt = (struct abort_client *) rb_malloc(sizeof(struct abort_client)); - - if(client_p->flags & FLAGS_SENDQEX) - strlcpy(abt->notice, "Max SendQ exceeded", sizeof(abt->notice)); -@@ -1559,10 +1553,10 @@ - - sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s was connected" - " for %ld seconds. %d/%d sendK/recvK.", -- source_p->name, CurrentTime - source_p->localClient->firsttime, sendk, recvk); -+ source_p->name, rb_current_time() - source_p->localClient->firsttime, sendk, recvk); - - ilog(L_SERVER, "%s was connected for %ld seconds. %d/%d sendK/recvK.", -- source_p->name, CurrentTime - source_p->localClient->firsttime, sendk, recvk); -+ source_p->name, rb_current_time() - source_p->localClient->firsttime, sendk, recvk); - - if(has_id(source_p)) - del_from_id_hash(source_p->id, source_p); -@@ -1609,10 +1603,10 @@ - show_ip(NULL, source_p) ? source_p->sockhost : "255.255.255.255", - comment); - -- on_for = CurrentTime - source_p->localClient->firsttime; -+ on_for = rb_current_time() - source_p->localClient->firsttime; - - ilog(L_USER, "%s (%3lu:%02lu:%02lu): %s!%s@%s %d/%d", -- myctime(CurrentTime), on_for / 3600, -+ myctime(rb_current_time()), on_for / 3600, - (on_for % 3600) / 60, on_for % 60, - source_p->name, source_p->username, source_p->host, - source_p->localClient->sendK, source_p->localClient->receiveK); -@@ -1894,7 +1888,7 @@ - - if(!serv) - { -- serv = (server_t *) MyMalloc(sizeof(server_t)); -+ serv = (server_t *) rb_malloc(sizeof(server_t)); - client_p->serv = serv; - } - return client_p->serv; -@@ -1915,7 +1909,7 @@ - if(--user->refcnt <= 0) - { - if(user->away) -- MyFree((char *) user->away); -+ rb_free((char *) user->away); - /* - * sanity check - */ -@@ -1940,6 +1934,23 @@ - - BlockHeapFree(user_heap, user); - } -+} -+ -+void -+allocate_away(struct Client *client_p) -+{ -+ if(client_p->user->away == NULL) -+ client_p->user->away = rb_bh_alloc(away_heap); -+} -+ -+ -+void -+free_away(struct Client *client_p) -+{ -+ if(client_p->user->away != NULL) { -+ rb_bh_free(away_heap, client_p->user->away); -+ client_p->user->away = NULL; -+ } - } - - void -@@ -2015,7 +2026,7 @@ - ServerStats->is_sbr += client_p->localClient->receiveB; - ServerStats->is_sks += client_p->localClient->sendK; - ServerStats->is_skr += client_p->localClient->receiveK; -- ServerStats->is_sti += CurrentTime - client_p->localClient->firsttime; -+ ServerStats->is_sti += rb_current_time() - client_p->localClient->firsttime; - if(ServerStats->is_sbs > 2047) - { - ServerStats->is_sks += (ServerStats->is_sbs >> 10); -@@ -2053,7 +2064,7 @@ - ServerStats->is_cbr += client_p->localClient->receiveB; - ServerStats->is_cks += client_p->localClient->sendK; - ServerStats->is_ckr += client_p->localClient->receiveK; -- ServerStats->is_cti += CurrentTime - client_p->localClient->firsttime; -+ ServerStats->is_cti += rb_current_time() - client_p->localClient->firsttime; - if(ServerStats->is_cbs > 2047) - { - ServerStats->is_cks += (ServerStats->is_cbs >> 10); -diff -r a44630997728 src/extban.c ---- a/src/extban.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/extban.c Wed Apr 02 04:03:17 2008 +0400 -@@ -23,7 +23,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -diff -r a44630997728 src/hash.c ---- a/src/hash.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/hash.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,7 +26,6 @@ - - #include "stdinc.h" - #include "ircd_defs.h" --#include "tools.h" - #include "s_conf.h" - #include "channel.h" - #include "client.h" -@@ -36,7 +35,6 @@ - #include "ircd.h" - #include "numeric.h" - #include "send.h" --#include "memory.h" - #include "msg.h" - #include "cache.h" - #include "s_newconf.h" -@@ -91,11 +89,11 @@ - void - init_hash(void) - { -- clientTable = MyMalloc(sizeof(rb_dlink_list) * U_MAX); -- idTable = MyMalloc(sizeof(rb_dlink_list) * U_MAX); -- channelTable = MyMalloc(sizeof(rb_dlink_list) * CH_MAX); -- hostTable = MyMalloc(sizeof(rb_dlink_list) * HOST_MAX); -- resvTable = MyMalloc(sizeof(rb_dlink_list) * R_MAX); -+ clientTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); -+ idTable = rb_malloc(sizeof(rb_dlink_list) * U_MAX); -+ channelTable = rb_malloc(sizeof(rb_dlink_list) * CH_MAX); -+ hostTable = rb_malloc(sizeof(rb_dlink_list) * HOST_MAX); -+ resvTable = rb_malloc(sizeof(rb_dlink_list) * R_MAX); - } - - #ifndef RICER_HASHING -@@ -602,7 +600,7 @@ - - rb_dlinkAdd(chptr, &chptr->node, &global_channel_list); - -- chptr->channelts = CurrentTime; /* doesn't hurt to set it here */ -+ chptr->channelts = rb_current_time(); /* doesn't hurt to set it here */ - - rb_dlinkAddAlloc(chptr, &channelTable[hashv]); - -diff -r a44630997728 src/hook.c ---- a/src/hook.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/hook.c Wed Apr 02 04:03:17 2008 +0400 -@@ -37,8 +37,6 @@ - * $Id: hook.c 712 2006-02-06 04:42:14Z gxti $ - */ - #include "stdinc.h" --#include "memory.h" --#include "tools.h" - #include "hook.h" - #include "irc_string.h" - -@@ -68,7 +66,7 @@ - void - init_hook(void) - { -- hooks = MyMalloc(sizeof(hook) * HOOK_INCREMENT); -+ hooks = rb_malloc(sizeof(hook) * HOOK_INCREMENT); - - #ifdef USE_IODEBUG_HOOKS - h_iosend_id = register_hook("iosend"); -@@ -96,10 +94,10 @@ - { - hook *newhooks; - -- newhooks = MyMalloc(sizeof(hook) * (max_hooks + HOOK_INCREMENT)); -+ newhooks = rb_malloc(sizeof(hook) * (max_hooks + HOOK_INCREMENT)); - memcpy(newhooks, hooks, sizeof(hook) * num_hooks); - -- MyFree(hooks); -+ rb_free(hooks); - hooks = newhooks; - max_hooks += HOOK_INCREMENT; - } -@@ -158,7 +156,7 @@ - if((i = find_hook(name)) < 0) - { - i = find_freehookslot(); -- DupString(hooks[i].name, name); -+ hooks[i].name = rb_strdup(name); - num_hooks++; - } - -diff -r a44630997728 src/hostmask.c ---- a/src/hostmask.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/hostmask.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,7 +26,6 @@ - */ - - #include "stdinc.h" --#include "memory.h" - #include "ircd_defs.h" - #include "s_conf.h" - #include "hostmask.h" -@@ -447,7 +446,7 @@ - - if(address == NULL) - address = "/NOMATCH!/"; -- arec = MyMalloc(sizeof(struct AddressRec)); -+ arec = rb_malloc(sizeof(struct AddressRec)); - masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); - #ifdef IPV6 - if(masktype == HM_IPV6) -@@ -504,7 +503,7 @@ - - if(address == NULL) - address = "/NOMATCH!/"; -- arec = MyMalloc(sizeof(struct AddressRec)); -+ arec = rb_malloc(sizeof(struct AddressRec)); - masktype = parse_netmask(address, (struct sockaddr *)&arec->Mask.ipa.addr, &bits); - arec->Mask.ipa.bits = bits; - arec->masktype = masktype; -@@ -579,7 +578,7 @@ - aconf->status |= CONF_ILLEGAL; - if(!aconf->clients) - free_conf(aconf); -- MyFree(arec); -+ rb_free(arec); - return; - } - arecl = arec; -@@ -619,7 +618,7 @@ - arec->aconf->status |= CONF_ILLEGAL; - if(!arec->aconf->clients) - free_conf(arec->aconf); -- MyFree(arec); -+ rb_free(arec); - } - } - *store_next = NULL; -@@ -652,7 +651,7 @@ - arec->aconf->status |= CONF_ILLEGAL; - if(!arec->aconf->clients) - free_conf(arec->aconf); -- MyFree(arec); -+ rb_free(arec); - } - } - *store_next = NULL; -diff -r a44630997728 src/irc_dictionary.c ---- a/src/irc_dictionary.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/irc_dictionary.c Wed Apr 02 04:03:17 2008 +0400 -@@ -24,12 +24,9 @@ - - #include "stdinc.h" - #include "sprintf_irc.h" --#include "tools.h" - #include "irc_string.h" - #include "client.h" --#include "memory.h" - #include "setup.h" --#include "balloc.h" - #include "irc_dictionary.h" - - static BlockHeap *elem_heap = NULL; -@@ -60,7 +57,7 @@ - */ - struct Dictionary *irc_dictionary_create(DCF compare_cb) - { -- struct Dictionary *dtree = (struct Dictionary *) MyMalloc(sizeof(struct Dictionary)); -+ struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); - - dtree->compare_cb = compare_cb; - -@@ -90,10 +87,10 @@ - struct Dictionary *irc_dictionary_create_named(const char *name, - DCF compare_cb) - { -- struct Dictionary *dtree = (struct Dictionary *) MyMalloc(sizeof(struct Dictionary)); -+ struct Dictionary *dtree = (struct Dictionary *) rb_malloc(sizeof(struct Dictionary)); - - dtree->compare_cb = compare_cb; -- DupString(dtree->id, name); -+ dtree->id = rb_strdup(name); - - if (!elem_heap) - elem_heap = BlockHeapCreate(sizeof(struct DictionaryElement), 1024); -@@ -479,7 +476,7 @@ - BlockHeapFree(elem_heap, n); - } - -- MyFree(dtree); -+ rb_free(dtree); - } - - /* -diff -r a44630997728 src/irc_string.c ---- a/src/irc_string.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/irc_string.c Wed Apr 02 04:03:17 2008 +0400 -@@ -26,10 +26,8 @@ - - #include "stdinc.h" - #include "sprintf_irc.h" --#include "tools.h" - #include "irc_string.h" - #include "client.h" --#include "memory.h" - #include "setup.h" - - #ifndef INADDRSZ -@@ -220,7 +218,7 @@ - return NULL; - } - -- result = MyMalloc(((length + 2) / 3) * 5); -+ result = rb_malloc(((length + 2) / 3) * 5); - p = result; - - while (length > 2) -@@ -257,7 +255,7 @@ - int ch, i = 0, j = 0, k; - unsigned char *result; - -- result = MyMalloc(length + 1); -+ result = rb_malloc(length + 1); - - while ((ch = *current++) != '\0' && length-- > 0) { - if (ch == base64_pad) break; -diff -r a44630997728 src/ircd.c ---- a/src/ircd.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/ircd.c Wed Apr 02 04:03:17 2008 +0400 -@@ -28,13 +28,11 @@ - #include "setup.h" - #include "config.h" - --#include "tools.h" - #include "ircd.h" - #include "channel.h" - #include "class.h" - #include "client.h" - #include "common.h" --#include "event.h" - #include "hash.h" - #include "irc_string.h" - #include "ircd_signal.h" -@@ -47,7 +45,6 @@ - #include "res.h" - #include "restart.h" - #include "s_auth.h" --#include "commio.h" - #include "s_conf.h" - #include "s_log.h" - #include "s_serv.h" /* try_connections */ -@@ -58,17 +55,14 @@ - #include "supported.h" - #include "whowas.h" - #include "modules.h" --#include "memory.h" - #include "hook.h" - #include "ircd_getopt.h" --#include "balloc.h" - #include "newconf.h" - #include "reject.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "cache.h" - #include "monitor.h" --#include "libcharybdis.h" - #include "patchlevel.h" - #include "serno.h" - -@@ -250,8 +244,8 @@ - newtime.tv_sec = time(NULL); - - #endif -- if(newtime.tv_sec < CurrentTime) -- rb_set_back_events(CurrentTime - newtime.tv_sec); -+ if(newtime.tv_sec < rb_current_time()) -+ rb_set_back_events(rb_current_time() - newtime.tv_sec); - - SystemTime.tv_sec = newtime.tv_sec; - SystemTime.tv_usec = newtime.tv_usec; -@@ -297,7 +291,7 @@ - */ - - delay = rb_event_next(); -- if(delay <= CurrentTime) -+ if(delay <= rb_current_time()) - rb_event_run(); - - -@@ -640,7 +634,7 @@ - me.servptr = &me; - SetMe(&me); - make_server(&me); -- startup_time = CurrentTime; -+ startup_time = rb_current_time(); - add_to_client_hash(me.name, &me); - add_to_id_hash(me.id, &me); - me.serv->nameinfo = scache_connect(me.name, me.info, 0); -diff -r a44630997728 src/ircd_parser.y ---- a/src/ircd_parser.y Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/ircd_parser.y Wed Apr 02 04:03:17 2008 +0400 -@@ -105,7 +105,7 @@ - { - case CF_STRING: - case CF_QSTRING: -- MyFree(list->v.string); -+ rb_free(list->v.string); - break; - case CF_LIST: - free_cur_list(list->v.list); -@@ -124,7 +124,7 @@ - { - if (cur_list == NULL) - { -- cur_list = MyMalloc(sizeof(conf_parm_t)); -+ cur_list = rb_malloc(sizeof(conf_parm_t)); - cur_list->type |= CF_FLIST; - cur_list->v.list = new; - } -@@ -139,7 +139,7 @@ - { - conf_parm_t *new; - -- new = MyMalloc(sizeof(conf_parm_t)); -+ new = rb_malloc(sizeof(conf_parm_t)); - new->next = NULL; - new->type = type; - -@@ -152,7 +152,7 @@ - break; - case CF_STRING: - case CF_QSTRING: -- DupString(new->v.string, str); -+ new->v.string = rb_strdup(str); - break; - } - -@@ -253,19 +253,19 @@ - - oneitem: qstring - { -- $$ = MyMalloc(sizeof(conf_parm_t)); -+ $$ = rb_malloc(sizeof(conf_parm_t)); - $$->type = CF_QSTRING; -- DupString($$->v.string, $1); -+ $$->v.string = rb_strdup($1); - } - | timespec - { -- $$ = MyMalloc(sizeof(conf_parm_t)); -+ $$ = rb_malloc(sizeof(conf_parm_t)); - $$->type = CF_TIME; - $$->v.number = $1; - } - | number - { -- $$ = MyMalloc(sizeof(conf_parm_t)); -+ $$ = rb_malloc(sizeof(conf_parm_t)); - $$->type = CF_INT; - $$->v.number = $1; - } -@@ -275,7 +275,7 @@ - so pass it as that, if so */ - int val = conf_get_yesno_value($1); - -- $$ = MyMalloc(sizeof(conf_parm_t)); -+ $$ = rb_malloc(sizeof(conf_parm_t)); - - if (val != -1) - { -@@ -285,7 +285,7 @@ - else - { - $$->type = CF_STRING; -- DupString($$->v.string, $1); -+ $$->v.string = rb_strdup($1); - } - } - ; -diff -r a44630997728 src/ircd_signal.c ---- a/src/ircd_signal.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/ircd_signal.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,8 +25,6 @@ - #include "ircd.h" /* dorehash */ - #include "restart.h" /* server_reboot */ - #include "s_log.h" --#include "memory.h" --#include "commio.h" - #include "s_conf.h" - #include "client.h" - #include "send.h" -diff -r a44630997728 src/ircd_state.c ---- a/src/ircd_state.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/ircd_state.c Wed Apr 02 04:03:17 2008 +0400 -@@ -38,14 +38,11 @@ - #include "config.h" - - #include "client.h" --#include "tools.h" --#include "tools.h" - #include "ircd.h" - #include "channel.h" - #include "class.h" - #include "client.h" - #include "common.h" --#include "event.h" - #include "hash.h" - #include "irc_string.h" - #include "ircd_signal.h" -@@ -58,7 +55,6 @@ - #include "res.h" - #include "restart.h" - #include "s_auth.h" --#include "commio.h" - #include "s_conf.h" - #include "s_log.h" - #include "s_serv.h" /* try_connections */ -@@ -68,10 +64,8 @@ - #include "send.h" - #include "whowas.h" - #include "modules.h" --#include "memory.h" - #include "hook.h" - #include "ircd_getopt.h" --#include "balloc.h" - #include "newconf.h" - #include "patricia.h" - #include "reject.h" -@@ -79,7 +73,6 @@ - #include "s_newconf.h" - #include "cache.h" - #include "monitor.h" --#include "libcharybdis.h" - #include "patchlevel.h" - #include "serno.h" - -diff -r a44630997728 src/kdparse.c ---- a/src/kdparse.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/kdparse.c Wed Apr 02 04:03:17 2008 +0400 -@@ -25,14 +25,12 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "s_log.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "hostmask.h" - #include "client.h" - #include "irc_string.h" --#include "memory.h" - #include "hash.h" - - /* conf_add_fields() -@@ -47,21 +45,21 @@ - const char *operreason_field, const char *date_field) - { - if(host_field != NULL) -- DupString(aconf->host, host_field); -+ aconf->host = rb_strdup(host_field); - if(pass_field != NULL) - { - if(!EmptyString(date_field)) - { -- aconf->passwd = MyMalloc(strlen(pass_field) + strlen(date_field) + 4); -+ aconf->passwd = rb_malloc(strlen(pass_field) + strlen(date_field) + 4); - rb_sprintf(aconf->passwd, "%s (%s)", pass_field, date_field); - } - else -- DupString(aconf->passwd, pass_field); -+ aconf->passwd = rb_strdup(pass_field); - } - if(user_field != NULL) -- DupString(aconf->user, user_field); -+ aconf->user = rb_strdup(user_field); - if(operreason_field != NULL) -- DupString(aconf->spasswd, operreason_field); -+ aconf->spasswd = rb_strdup(operreason_field); - } - - /* -@@ -196,8 +194,8 @@ - aconf = make_conf(); - aconf->status = CONF_XLINE; - -- DupString(aconf->name, gecos_field); -- DupString(aconf->passwd, reason_field); -+ aconf->name = rb_strdup(gecos_field); -+ aconf->passwd = rb_strdup(reason_field); - - rb_dlinkAddAlloc(aconf, &xline_conf_list); - } -@@ -237,8 +235,8 @@ - aconf->status = CONF_RESV_CHANNEL; - aconf->port = 0; - -- DupString(aconf->name, host_field); -- DupString(aconf->passwd, reason_field); -+ aconf->name = rb_strdup(host_field); -+ aconf->passwd = rb_strdup(reason_field); - add_to_resv_hash(aconf->name, aconf); - } - else if(clean_resv_nick(host_field)) -@@ -250,8 +248,8 @@ - aconf->status = CONF_RESV_NICK; - aconf->port = 0; - -- DupString(aconf->name, host_field); -- DupString(aconf->passwd, reason_field); -+ aconf->name = rb_strdup(host_field); -+ aconf->passwd = rb_strdup(reason_field); - rb_dlinkAddAlloc(aconf, &resv_conf_list); - } - } -diff -r a44630997728 src/listener.c ---- a/src/listener.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/listener.c Wed Apr 02 04:03:17 2008 +0400 -@@ -33,12 +33,10 @@ - #include "ircd.h" - #include "ircd_defs.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_stats.h" - #include "send.h" --#include "memory.h" - #include "s_auth.h" - #include "reject.h" - #include "s_conf.h" -@@ -60,7 +58,7 @@ - static listener_t * - make_listener(struct irc_sockaddr_storage *addr) - { -- listener_t *listener = (listener_t *) MyMalloc(sizeof(listener_t)); -+ listener_t *listener = (listener_t *) rb_malloc(sizeof(listener_t)); - s_assert(0 != listener); - - listener->name = me.name; -@@ -95,7 +93,7 @@ - } - - /* free */ -- MyFree(listener); -+ rb_free(listener); - } - - #define PORTNAMELEN 6 /* ":31337" */ -@@ -530,12 +528,12 @@ - /* - * slow down the whining to opers bit - */ -- if((last_oper_notice + 20) <= CurrentTime) -+ if((last_oper_notice + 20) <= rb_current_time()) - { - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "All connections in use. (%s)", - get_listener_name(listener)); -- last_oper_notice = CurrentTime; -+ last_oper_notice = rb_current_time(); - } - - write(fd, "ERROR :All connections in use\r\n", 32); -diff -r a44630997728 src/modules.c ---- a/src/modules.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/modules.c Wed Apr 02 04:03:17 2008 +0400 -@@ -38,8 +38,6 @@ - #include "parse.h" - #include "ircd_defs.h" - #include "irc_string.h" --#include "memory.h" --#include "tools.h" - #include "sprintf_irc.h" - - -@@ -166,7 +164,7 @@ - if(mod_find_path(path)) - return; - -- pathst = MyMalloc(sizeof(struct module_path)); -+ pathst = rb_malloc(sizeof(struct module_path)); - - strcpy(pathst->path, path); - rb_dlinkAddAlloc(pathst, &mod_paths); -@@ -185,7 +183,7 @@ - - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, mod_paths.head) - { -- MyFree(ptr->data); -+ rb_free(ptr->data); - free_rb_dlink_node(ptr); - } - -@@ -202,7 +200,7 @@ - char * - irc_basename(const char *path) - { -- char *mod_basename = MyMalloc(strlen(path) + 1); -+ char *mod_basename = rb_malloc(strlen(path) + 1); - const char *s; - - if(!(s = strrchr(path, '/'))) -@@ -250,7 +248,7 @@ - - modules_init(); - -- modlist = (struct module **) MyMalloc(sizeof(struct module) * (MODS_INCREMENT)); -+ modlist = (struct module **) rb_malloc(sizeof(struct module) * (MODS_INCREMENT)); - - max_mods = MODS_INCREMENT; - -@@ -366,13 +364,13 @@ - if(findmodule_byname(m_bn) != -1) - { - sendto_one_notice(source_p, ":Module %s is already loaded", m_bn); -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - - load_one_module(parv[1], 0); - -- MyFree(m_bn); -+ rb_free(m_bn); - - return 0; - } -@@ -397,14 +395,14 @@ - if((modindex = findmodule_byname(m_bn)) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - - if(modlist[modindex]->core == 1) - { - sendto_one_notice(source_p, ":Module %s is a core module and may not be unloaded", m_bn); -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - -@@ -413,7 +411,7 @@ - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); - } - -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - -@@ -437,7 +435,7 @@ - if((modindex = findmodule_byname(m_bn)) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - -@@ -446,7 +444,7 @@ - if(unload_one_module(m_bn, 1) == -1) - { - sendto_one_notice(source_p, ":Module %s is not loaded", m_bn); -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - -@@ -458,7 +456,7 @@ - exit(0); - } - -- MyFree(m_bn); -+ rb_free(m_bn); - return 0; - } - -@@ -759,7 +757,7 @@ - - dlclose(modlist[modindex]->address); - -- MyFree(modlist[modindex]->name); -+ rb_free(modlist[modindex]->name); - memcpy(&modlist[modindex], &modlist[modindex + 1], - sizeof(struct module) * ((num_mods - 1) - modindex)); - -@@ -808,7 +806,7 @@ - sendto_realops_snomask(SNO_GENERAL, L_ALL, - "Error loading module %s: %s", mod_basename, err); - ilog(L_MAIN, "Error loading module %s: %s", mod_basename, err); -- MyFree(mod_basename); -+ rb_free(mod_basename); - return -1; - } - -@@ -829,7 +827,7 @@ - mod_basename); - ilog(L_MAIN, "Data format error: module %s has no MAPI header.", mod_basename); - (void) dlclose(tmpptr); -- MyFree(mod_basename); -+ rb_free(mod_basename); - return -1; - } - -@@ -846,7 +844,7 @@ - "Module %s indicated failure during load.", - mod_basename); - dlclose(tmpptr); -- MyFree(mod_basename); -+ rb_free(mod_basename); - return -1; - } - if(mheader->mapi_command_list) -@@ -881,7 +879,7 @@ - "Module %s has unknown/unsupported MAPI version %d.", - mod_basename, *mapi_version); - dlclose(tmpptr); -- MyFree(mod_basename); -+ rb_free(mod_basename); - return -1; - } - -@@ -890,11 +888,11 @@ - - increase_modlist(); - -- modlist[num_mods] = MyMalloc(sizeof(struct module)); -+ modlist[num_mods] = rb_malloc(sizeof(struct module)); - modlist[num_mods]->address = tmpptr; - modlist[num_mods]->version = ver; - modlist[num_mods]->core = core; -- DupString(modlist[num_mods]->name, mod_basename); -+ modlist[num_mods]->name = rb_strdup(mod_basename); - modlist[num_mods]->mapi_header = mapi_version; - modlist[num_mods]->mapi_version = MAPI_VERSION(*mapi_version); - num_mods++; -@@ -908,7 +906,7 @@ - ilog(L_MAIN, "Module %s [version: %s; MAPI version: %d] loaded at 0x%lx", - mod_basename, ver, MAPI_VERSION(*mapi_version), (unsigned long) tmpptr); - } -- MyFree(mod_basename); -+ rb_free(mod_basename); - return 0; - } - -@@ -927,11 +925,11 @@ - if((num_mods + 1) < max_mods) - return; - -- new_modlist = (struct module **) MyMalloc(sizeof(struct module) * -+ new_modlist = (struct module **) rb_malloc(sizeof(struct module) * - (max_mods + MODS_INCREMENT)); - memcpy((void *) new_modlist, (void *) modlist, sizeof(struct module) * num_mods); - -- MyFree(modlist); -+ rb_free(modlist); - modlist = new_modlist; - max_mods += MODS_INCREMENT; - } -diff -r a44630997728 src/monitor.c ---- a/src/monitor.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/monitor.c Wed Apr 02 04:03:17 2008 +0400 -@@ -32,58 +32,57 @@ - * $Id: monitor.c 3520 2007-06-30 22:15:35Z jilles $ - */ - #include "stdinc.h" --#include "tools.h" - #include "client.h" --#include "memory.h" --#include "balloc.h" - #include "monitor.h" - #include "hash.h" --#include "event.h" - #include "numeric.h" - --static struct monitor *monitorTable[MONITOR_HASH_SIZE]; --BlockHeap *monitor_heap; -- --static void cleanup_monitor(void *unused); -+struct monitor *monitorTable[MONITOR_HASH_SIZE]; -+static rb_bh *monitor_heap; - - void - init_monitor(void) - { -- monitor_heap = BlockHeapCreate(sizeof(struct monitor), MONITOR_HEAP_SIZE); -- eventAddIsh("cleanup_monitor", cleanup_monitor, NULL, 3600); -+ monitor_heap = rb_bh_create(sizeof(struct monitor), MONITOR_HEAP_SIZE, "monitor_heap"); - } - - static inline unsigned int - hash_monitor_nick(const char *name) - { -- return fnv_hash_upper((const unsigned char *) name, MONITOR_HASH_BITS); -+ return fnv_hash_upper((const unsigned char *)name, MONITOR_HASH_BITS, 0); - } - - struct monitor * - find_monitor(const char *name, int add) - { -- struct monitor *monptr; -+ struct monitor *monptr; -+ -+ unsigned int hashv = hash_monitor_nick(name); -+ -+ for(monptr = monitorTable[hashv]; monptr; monptr = monptr->hnext) -+ { -+ if(!irccmp(monptr->name, name)) -+ return monptr; -+ } -+ -+ if(add) -+ { -+ monptr = rb_bh_alloc(monitor_heap); -+ rb_strlcpy(monptr->name, name, sizeof(monptr->name)); -+ -+ monptr->hnext = monitorTable[hashv]; -+ monitorTable[hashv] = monptr; -+ -+ return monptr; -+ } -+ -+ return NULL; -+} - -- unsigned int hashv = hash_monitor_nick(name); -- -- for(monptr = monitorTable[hashv]; monptr; monptr = monptr->hnext) -- { -- if(!irccmp(monptr->name, name)) -- return monptr; -- } -- -- if(add) -- { -- monptr = BlockHeapAlloc(monitor_heap); -- strlcpy(monptr->name, name, sizeof(monptr->name)); -- -- monptr->hnext = monitorTable[hashv]; -- monitorTable[hashv] = monptr; -- -- return monptr; -- } -- -- return NULL; -+void -+free_monitor(struct monitor *monptr) -+{ -+ rb_bh_free(monitor_heap, monptr); - } - - /* monitor_signon() -@@ -96,16 +95,15 @@ - void - monitor_signon(struct Client *client_p) - { -- char buf[USERHOST_REPLYLEN]; -- struct monitor *monptr = find_monitor(client_p->name, 0); -- -- /* noones watching this nick */ -- if(monptr == NULL) -- return; -- -- rb_snprintf(buf, sizeof(buf), "%s!%s@%s", -- client_p->name, client_p->username, client_p->host); -- -+ char buf[USERHOST_REPLYLEN]; -+ struct monitor *monptr = find_monitor(client_p->name, 0); -+ -+ /* noones watching this nick */ -+ if(monptr == NULL) -+ return; -+ -+ rb_snprintf(buf, sizeof(buf), "%s!%s@%s", client_p->name, client_p->username, client_p->host); -+ - sendto_monitor(monptr, form_str(RPL_MONONLINE), me.name, "*", buf); - } - -@@ -119,62 +117,30 @@ - void - monitor_signoff(struct Client *client_p) - { -- struct monitor *monptr = find_monitor(client_p->name, 0); -- -- /* noones watching this nick */ -- if(monptr == NULL) -- return; -- -- sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*", -+ struct monitor *monptr = find_monitor(client_p->name, 0); -+ -+ /* noones watching this nick */ -+ if(monptr == NULL) -+ return; -+ -+ sendto_monitor(monptr, form_str(RPL_MONOFFLINE), me.name, "*", - client_p->name); - } - - void - clear_monitor(struct Client *client_p) - { -- struct monitor *monptr; -- rb_dlink_node *ptr, *next_ptr; -- -- RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head) -- { -- monptr = ptr->data; -- -- /* we leave the actual entry around with no users, itll be -- * cleaned up periodically by cleanup_monitor() --anfl -- */ -- rb_dlinkFindDestroy(client_p, &monptr->users); -- free_rb_dlink_node(ptr); -- } -- -- client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL; -+ struct monitor *monptr; -+ rb_dlink_node *ptr, *next_ptr; -+ -+ RB_DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->monitor_list.head) -+ { -+ monptr = ptr->data; -+ -+ rb_dlinkFindDestroy(client_p, &monptr->users); -+ rb_free_rb_dlink_node(ptr); -+ } -+ -+ client_p->localClient->monitor_list.head = client_p->localClient->monitor_list.tail = NULL; - client_p->localClient->monitor_list.length = 0; - } -- --static void --cleanup_monitor(void *unused) --{ -- struct monitor *last_ptr = NULL; -- struct monitor *next_ptr, *ptr; -- int i; -- -- for(i = 0; i < MONITOR_HASH_SIZE; i++) -- { -- last_ptr = NULL; -- for(ptr = monitorTable[i]; ptr; ptr = next_ptr) -- { -- next_ptr = ptr->hnext; -- -- if(!rb_dlink_list_length(&ptr->users)) -- { -- if(last_ptr) -- last_ptr->hnext = next_ptr; -- else -- monitorTable[i] = next_ptr; -- -- BlockHeapFree(monitor_heap, ptr); -- } -- else -- last_ptr = ptr; -- } -- } --} -diff -r a44630997728 src/newconf.c ---- a/src/newconf.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/newconf.c Wed Apr 02 04:03:17 2008 +0400 -@@ -9,9 +9,7 @@ - #include - #endif - --#include "memory.h" - #include "newconf.h" --#include "tools.h" - #include "ircd_defs.h" - #include "sprintf_irc.h" - #include "common.h" -@@ -25,7 +23,6 @@ - #include "listener.h" - #include "hostmask.h" - #include "s_serv.h" --#include "event.h" - #include "hash.h" - #include "cache.h" - #include "ircd.h" -@@ -83,7 +80,7 @@ - { - struct TopConf *tc; - -- tc = MyMalloc(sizeof(struct TopConf)); -+ tc = rb_malloc(sizeof(struct TopConf)); - - tc->tc_name = name; - tc->tc_sfunc = sfunc; -@@ -153,7 +150,7 @@ - return -1; - - rb_dlinkDestroy(ptr, &conf_items); -- MyFree(tc); -+ rb_free(tc); - - return 0; - } -@@ -194,7 +191,7 @@ - - /* the ircd will exit() in main() if we dont set one */ - if(strlen(s) <= HOSTLEN) -- DupString(ServerInfo.name, (char *) data); -+ ServerInfo.name = rb_strdup((char *) data); - } - } - -@@ -225,8 +222,8 @@ - if((p = strchr((char *) data, ' '))) - *p = '\0'; - -- MyFree(ServerInfo.network_name); -- DupString(ServerInfo.network_name, (char *) data); -+ rb_free(ServerInfo.network_name); -+ ServerInfo.network_name = rb_strdup((char *) data); - } - - static void -@@ -271,7 +268,7 @@ - - load_one_module((char *) data, 0); - -- MyFree(m_bn); -+ rb_free(m_bn); - #else - conf_report_error("Ignoring modules::module -- loadable module support not present."); - #endif -@@ -484,7 +481,7 @@ - if(strlen(conf_cur_block_name) > OPERNICKLEN) - conf_cur_block_name[OPERNICKLEN] = '\0'; - -- DupString(yy_oper->name, conf_cur_block_name); -+ yy_oper->name = rb_strdup(conf_cur_block_name); - } - - if(EmptyString(yy_oper->name)) -@@ -512,11 +509,11 @@ - { - yy_tmpoper = ptr->data; - -- DupString(yy_tmpoper->name, yy_oper->name); -+ yy_tmpoper->name = rb_strdup(yy_oper->name); - - /* could be an rsa key instead.. */ - if(!EmptyString(yy_oper->passwd)) -- DupString(yy_tmpoper->passwd, yy_oper->passwd); -+ yy_tmpoper->passwd = rb_strdup(yy_oper->passwd); - - yy_tmpoper->flags = yy_oper->flags; - yy_tmpoper->umodes = yy_oper->umodes; -@@ -582,14 +579,14 @@ - { - *p++ = '\0'; - -- DupString(yy_tmpoper->username, host); -- DupString(yy_tmpoper->host, p); -+ yy_tmpoper->username = rb_strdup(host); -+ yy_tmpoper->host = rb_strdup(p); - } - else - { - -- DupString(yy_tmpoper->username, "*"); -- DupString(yy_tmpoper->host, host); -+ yy_tmpoper->username = rb_strdup("*"); -+ yy_tmpoper->host = rb_strdup(host); - } - - if(EmptyString(yy_tmpoper->username) || EmptyString(yy_tmpoper->host)) -@@ -608,18 +605,18 @@ - if(yy_oper->passwd) - { - memset(yy_oper->passwd, 0, strlen(yy_oper->passwd)); -- MyFree(yy_oper->passwd); -+ rb_free(yy_oper->passwd); - } - -- DupString(yy_oper->passwd, (char *) data); -+ yy_oper->passwd = rb_strdup((char *) data); - } - - static void - conf_set_oper_rsa_public_key_file(void *data) - { - #ifdef HAVE_LIBCRYPTO -- MyFree(yy_oper->rsa_pubkey_file); -- DupString(yy_oper->rsa_pubkey_file, (char *) data); -+ rb_free(yy_oper->rsa_pubkey_file); -+ yy_oper->rsa_pubkey_file = rb_strdup((char *) data); - #else - conf_report_error("Warning -- ignoring rsa_public_key_file (OpenSSL support not available"); - #endif -@@ -651,7 +648,7 @@ - conf_end_class(struct TopConf *tc) - { - if(conf_cur_block_name != NULL) -- DupString(yy_class->class_name, conf_cur_block_name); -+ yy_class->class_name = rb_strdup(conf_cur_block_name); - - if(EmptyString(yy_class->class_name)) - { -@@ -734,7 +731,7 @@ - static int - conf_begin_listen(struct TopConf *tc) - { -- MyFree(listener_address); -+ rb_free(listener_address); - listener_address = NULL; - return 0; - } -@@ -742,7 +739,7 @@ - static int - conf_end_listen(struct TopConf *tc) - { -- MyFree(listener_address); -+ rb_free(listener_address); - listener_address = NULL; - return 0; - } -@@ -786,8 +783,8 @@ - static void - conf_set_listen_address(void *data) - { -- MyFree(listener_address); -- DupString(listener_address, data); -+ rb_free(listener_address); -+ listener_address = rb_strdup(data); - } - - static int -@@ -819,7 +816,7 @@ - rb_dlink_node *next_ptr; - - if(EmptyString(yy_aconf->name)) -- DupString(yy_aconf->name, "NOMATCH"); -+ yy_aconf->name = rb_strdup("NOMATCH"); - - /* didnt even get one ->host? */ - if(EmptyString(yy_aconf->host)) -@@ -839,13 +836,13 @@ - yy_tmp = ptr->data; - - if(yy_aconf->passwd) -- DupString(yy_tmp->passwd, yy_aconf->passwd); -+ yy_tmp->passwd = rb_strdup(yy_aconf->passwd); - - /* this will always exist.. */ -- DupString(yy_tmp->name, yy_aconf->name); -+ yy_tmp->name = rb_strdup(yy_aconf->name); - - if(yy_aconf->className) -- DupString(yy_tmp->className, yy_aconf->className); -+ yy_tmp->className = rb_strdup(yy_aconf->className); - - yy_tmp->flags = yy_aconf->flags; - yy_tmp->port = yy_aconf->port; -@@ -882,13 +879,13 @@ - { - *p++ = '\0'; - -- DupString(yy_tmp->user, data); -- DupString(yy_tmp->host, p); -+ yy_tmp->user = rb_strdup(data); -+ yy_tmp->host = rb_strdup(p); - } - else - { -- DupString(yy_tmp->user, "*"); -- DupString(yy_tmp->host, data); -+ yy_tmp->user = rb_strdup("*"); -+ yy_tmp->host = rb_strdup(data); - } - - if(yy_aconf != yy_tmp) -@@ -900,8 +897,8 @@ - { - if(yy_aconf->passwd) - memset(yy_aconf->passwd, 0, strlen(yy_aconf->passwd)); -- MyFree(yy_aconf->passwd); -- DupString(yy_aconf->passwd, data); -+ rb_free(yy_aconf->passwd); -+ yy_aconf->passwd = rb_strdup(data); - } - - static void -@@ -960,8 +957,8 @@ - return; - } - -- MyFree(yy_aconf->name); -- DupString(yy_aconf->name, data); -+ rb_free(yy_aconf->name); -+ yy_aconf->name = rb_strdup(data); - yy_aconf->flags |= CONF_FLAGS_SPOOF_IP; - } - -@@ -977,8 +974,8 @@ - conf_set_auth_redir_serv(void *data) - { - yy_aconf->flags |= CONF_FLAGS_REDIR; -- MyFree(yy_aconf->name); -- DupString(yy_aconf->name, data); -+ rb_free(yy_aconf->name); -+ yy_aconf->name = rb_strdup(data); - } - - static void -@@ -993,8 +990,8 @@ - static void - conf_set_auth_class(void *data) - { -- MyFree(yy_aconf->className); -- DupString(yy_aconf->className, data); -+ rb_free(yy_aconf->className); -+ yy_aconf->className = rb_strdup(data); - } - - /* ok, shared_oper handles the stacking, shared_flags handles adding -@@ -1041,11 +1038,11 @@ - return; - } - -- DupString(yy_shared->server, args->v.string); -+ yy_shared->server = rb_strdup(args->v.string); - args = args->next; - } - else -- DupString(yy_shared->server, "*"); -+ yy_shared->server = rb_strdup("*"); - - if((args->type & CF_MTYPE) != CF_QSTRING) - { -@@ -1063,14 +1060,14 @@ - *p++ = '\0'; - - if(EmptyString(p)) -- DupString(yy_shared->host, "*"); -+ yy_shared->host = rb_strdup("*"); - else -- DupString(yy_shared->host, p); -+ yy_shared->host = rb_strdup(p); - - if(EmptyString(username)) -- DupString(yy_shared->username, "*"); -+ yy_shared->username = rb_strdup("*"); - else -- DupString(yy_shared->username, username); -+ yy_shared->username = rb_strdup(username); - - rb_dlinkAddAlloc(yy_shared, &yy_shared_list); - yy_shared = NULL; -@@ -1111,7 +1108,7 @@ - yy_server->flags |= SERVER_TB; - - if(conf_cur_block_name != NULL) -- DupString(yy_server->name, conf_cur_block_name); -+ yy_server->name = rb_strdup(conf_cur_block_name); - - return 0; - } -@@ -1164,8 +1161,8 @@ - static void - conf_set_connect_host(void *data) - { -- MyFree(yy_server->host); -- DupString(yy_server->host, data); -+ rb_free(yy_server->host); -+ yy_server->host = rb_strdup(data); - if (strchr(yy_server->host, ':')) - yy_server->aftype = AF_INET6; - } -@@ -1189,10 +1186,10 @@ - if(yy_server->spasswd) - { - memset(yy_server->spasswd, 0, strlen(yy_server->spasswd)); -- MyFree(yy_server->spasswd); -+ rb_free(yy_server->spasswd); - } - -- DupString(yy_server->spasswd, data); -+ yy_server->spasswd = rb_strdup(data); - } - - static void -@@ -1201,9 +1198,9 @@ - if(yy_server->passwd) - { - memset(yy_server->passwd, 0, strlen(yy_server->passwd)); -- MyFree(yy_server->passwd); -+ rb_free(yy_server->passwd); - } -- DupString(yy_server->passwd, data); -+ yy_server->passwd = rb_strdup(data); - } - - static void -@@ -1254,8 +1251,8 @@ - yy_hub = make_remote_conf(); - yy_hub->flags = CONF_HUB; - -- DupString(yy_hub->host, data); -- DupString(yy_hub->server, yy_server->name); -+ yy_hub->host = rb_strdup(data); -+ yy_hub->server = rb_strdup(yy_server->name); - rb_dlinkAdd(yy_hub, &yy_hub->node, &hubleaf_conf_list); - } - -@@ -1270,16 +1267,16 @@ - yy_leaf = make_remote_conf(); - yy_leaf->flags = CONF_LEAF; - -- DupString(yy_leaf->host, data); -- DupString(yy_leaf->server, yy_server->name); -+ yy_leaf->host = rb_strdup(data); -+ yy_leaf->server = rb_strdup(yy_server->name); - rb_dlinkAdd(yy_leaf, &yy_leaf->node, &hubleaf_conf_list); - } - - static void - conf_set_connect_class(void *data) - { -- MyFree(yy_server->class_name); -- DupString(yy_server->class_name, data); -+ rb_free(yy_server->class_name); -+ yy_server->class_name = rb_strdup(data); - } - - static void -@@ -1294,8 +1291,8 @@ - } - - yy_tmp = make_conf(); -- DupString(yy_tmp->passwd, "*"); -- DupString(yy_tmp->host, data); -+ yy_tmp->passwd = rb_strdup("*"); -+ yy_tmp->host = rb_strdup(data); - yy_tmp->status = CONF_EXEMPTDLINE; - add_conf_by_address(yy_tmp->host, CONF_EXEMPTDLINE, NULL, yy_tmp); - } -@@ -1327,7 +1324,7 @@ - free_remote_conf(yy_shared); - - yy_shared = make_remote_conf(); -- DupString(yy_shared->server, data); -+ yy_shared->server = rb_strdup(data); - rb_dlinkAddAlloc(yy_shared, &yy_cluster_list); - - yy_shared = NULL; -@@ -1575,7 +1572,7 @@ - return; - } - -- DupString(tmp, data); -+ tmp = rb_strdup(data); - rb_dlinkAddAlloc(tmp, &service_list); - - if((target_p = find_server(NULL, tmp))) -@@ -1585,10 +1582,10 @@ - static int - conf_begin_alias(struct TopConf *tc) - { -- yy_alias = MyMalloc(sizeof(struct alias_entry)); -+ yy_alias = rb_malloc(sizeof(struct alias_entry)); - - if (conf_cur_block_name != NULL) -- DupString(yy_alias->name, conf_cur_block_name); -+ yy_alias->name = rb_strdup(conf_cur_block_name); - - yy_alias->flags = 0; - yy_alias->hits = 0; -@@ -1606,7 +1603,7 @@ - { - conf_report_error("Ignoring alias -- must have a name."); - -- MyFree(yy_alias); -+ rb_free(yy_alias); - - return -1; - } -@@ -1615,7 +1612,7 @@ - { - conf_report_error("Ignoring alias -- must have a target."); - -- MyFree(yy_alias); -+ rb_free(yy_alias); - - return -1; - } -@@ -1634,7 +1631,7 @@ - if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ - return; - -- DupString(yy_alias->name, data); -+ yy_alias->name = rb_strdup(data); - } - - static void -@@ -1643,25 +1640,25 @@ - if (data == NULL || yy_alias == NULL) /* this shouldn't ever happen */ - return; - -- DupString(yy_alias->target, data); -+ yy_alias->target = rb_strdup(data); - } - - static void - conf_set_blacklist_host(void *data) - { -- DupString(yy_blacklist_host, data); -+ yy_blacklist_host = rb_strdup(data); - } - - static void - conf_set_blacklist_reason(void *data) - { -- DupString(yy_blacklist_reason, data); -+ yy_blacklist_reason = rb_strdup(data); - - if (yy_blacklist_host && yy_blacklist_reason) - { - new_blacklist(yy_blacklist_host, yy_blacklist_reason); -- MyFree(yy_blacklist_host); -- MyFree(yy_blacklist_reason); -+ rb_free(yy_blacklist_host); -+ rb_free(yy_blacklist_reason); - yy_blacklist_host = NULL; - yy_blacklist_reason = NULL; - } -@@ -1700,7 +1697,7 @@ - } - - if(name) -- DupString(conf_cur_block_name, name); -+ conf_cur_block_name = rb_strdup(name); - else - conf_cur_block_name = NULL; - -@@ -1717,7 +1714,7 @@ - if(tc->tc_efunc) - return tc->tc_efunc(tc); - -- MyFree(conf_cur_block_name); -+ rb_free(conf_cur_block_name); - return 0; - } - -@@ -1736,8 +1733,8 @@ - if(len && strlen(input) > len) - input[len] = '\0'; - -- MyFree(*loc); -- DupString(*loc, input); -+ rb_free(*loc); -+ *loc = rb_strdup(input); - } - - int -@@ -1779,9 +1776,9 @@ - value->v.list->type = CF_STRING; - - if(cp->v.number == 1) -- DupString(cp->v.string, "yes"); -+ cp->v.string = rb_strdup("yes"); - else -- DupString(cp->v.string, "no"); -+ cp->v.string = rb_strdup("no"); - } - - /* maybe it's a CF_TIME and they passed CF_INT -- -@@ -1849,7 +1846,7 @@ - if((cf = find_conf_item(tc, name)) != NULL) - return -1; - -- cf = MyMalloc(sizeof(struct ConfEntry)); -+ cf = rb_malloc(sizeof(struct ConfEntry)); - - cf->cf_name = name; - cf->cf_type = type; -@@ -1878,7 +1875,7 @@ - return -1; - - rb_dlinkDestroy(ptr, &tc->tc_items); -- MyFree(cf); -+ rb_free(cf); - - return 0; - } -diff -r a44630997728 src/numeric.c ---- a/src/numeric.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/numeric.c Wed Apr 02 04:03:17 2008 +0400 -@@ -31,7 +31,6 @@ - #include "numeric.h" - #include "irc_string.h" - #include "common.h" /* NULL cripes */ --#include "memory.h" - - #include "messages.tab" - -diff -r a44630997728 src/packet.c ---- a/src/packet.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/packet.c Wed Apr 02 04:03:17 2008 +0400 -@@ -24,8 +24,6 @@ - * $Id: packet.c 3446 2007-05-14 22:21:16Z jilles $ - */ - #include "stdinc.h" --#include "tools.h" --#include "commio.h" - #include "s_conf.h" - #include "s_serv.h" - #include "client.h" -@@ -34,7 +32,6 @@ - #include "parse.h" - #include "packet.h" - #include "irc_string.h" --#include "memory.h" - #include "hook.h" - #include "send.h" - -@@ -285,7 +282,7 @@ - reply->datalen |= *len; - reply->gotdatalen++; - if(reply->datalen > 0) -- reply->data = MyMalloc(reply->datalen); -+ reply->data = rb_malloc(reply->datalen); - } - - if(reply->gotdatalen < 2) -@@ -322,7 +319,7 @@ - - /* reset SlinkRpl */ - if(reply->datalen > 0) -- MyFree(reply->data); -+ rb_free(reply->data); - reply->command = 0; - - if(IsAnyDead(server)) -@@ -377,8 +374,8 @@ - call_hook(h_iorecv_id, &hdata); - #endif - -- if(client_p->localClient->lasttime < CurrentTime) -- client_p->localClient->lasttime = CurrentTime; -+ if(client_p->localClient->lasttime < rb_current_time()) -+ client_p->localClient->lasttime = rb_current_time(); - client_p->flags &= ~FLAGS_PINGSENT; - - /* -diff -r a44630997728 src/parse.c ---- a/src/parse.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/parse.c Wed Apr 02 04:03:17 2008 +0400 -@@ -40,7 +40,6 @@ - #include "send.h" - #include "msg.h" - #include "s_conf.h" --#include "memory.h" - #include "s_serv.h" - #include "packet.h" - -diff -r a44630997728 src/reject.c ---- a/src/reject.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/reject.c Wed Apr 02 04:03:17 2008 +0400 -@@ -28,8 +28,6 @@ - #include "patricia.h" - #include "client.h" - #include "s_conf.h" --#include "event.h" --#include "tools.h" - #include "reject.h" - #include "s_stats.h" - #include "msg.h" -@@ -100,11 +98,11 @@ - pnode = ptr->data; - rdata = pnode->data; - -- if(rdata->time + ConfigFileEntry.reject_duration > CurrentTime) -+ if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) - continue; - - rb_dlinkDelete(ptr, &reject_list); -- MyFree(rdata); -+ rb_free(rdata); - patricia_remove(reject_tree, pnode); - } - } -@@ -139,7 +137,7 @@ - if((pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) - { - rdata = pnode->data; -- rdata->time = CurrentTime; -+ rdata->time = rb_current_time(); - rdata->count++; - } - else -@@ -150,9 +148,9 @@ - bitlen = 128; - #endif - pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); -- pnode->data = rdata = MyMalloc(sizeof(struct reject_data)); -+ pnode->data = rdata = rb_malloc(sizeof(struct reject_data)); - rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); -- rdata->time = CurrentTime; -+ rdata->time = rb_current_time(); - rdata->count = 1; - } - rdata->mask_hashv = hashv; -@@ -174,7 +172,7 @@ - { - rdata = pnode->data; - -- rdata->time = CurrentTime; -+ rdata->time = rb_current_time(); - if(rdata->count > ConfigFileEntry.reject_after_count) - { - ServerStats->is_rej++; -@@ -201,7 +199,7 @@ - pnode = ptr->data; - rdata = pnode->data; - rb_dlinkDelete(ptr, &reject_list); -- MyFree(rdata); -+ rb_free(rdata); - patricia_remove(reject_tree, pnode); - } - } -@@ -220,7 +218,7 @@ - { - struct reject_data *rdata = pnode->data; - rb_dlinkDelete(&rdata->rnode, &reject_list); -- MyFree(rdata); -+ rb_free(rdata); - patricia_remove(reject_tree, pnode); - return 1; - } -@@ -248,7 +246,7 @@ - if (rdata->mask_hashv == hashv) - { - rb_dlinkDelete(ptr, &reject_list); -- MyFree(rdata); -+ rb_free(rdata); - patricia_remove(reject_tree, pnode); - n++; - } -diff -r a44630997728 src/res.c ---- a/src/res.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/res.c Wed Apr 02 04:03:18 2008 +0400 -@@ -29,11 +29,8 @@ - #include "ircd_defs.h" - #include "common.h" - #include "ircd.h" --#include "commio.h" - #include "res.h" - #include "reslib.h" --#include "tools.h" --#include "event.h" - #include "irc_string.h" - #include "sprintf_irc.h" - #include "numeric.h" -@@ -215,7 +212,7 @@ - */ - static void timeout_resolver(void *notused) - { -- timeout_query_list(CurrentTime); -+ timeout_query_list(rb_current_time()); - } - - /* -@@ -244,7 +241,7 @@ - void init_resolver(void) - { - #ifdef HAVE_SRAND48 -- srand48(CurrentTime); -+ srand48(rb_current_time()); - #endif - start_resolver(); - } -@@ -290,8 +287,8 @@ - static void rem_request(struct reslist *request) - { - rb_dlinkDelete(&request->node, &request_list); -- MyFree(request->name); -- MyFree(request); -+ rb_free(request->name); -+ rb_free(request); - } - - /* -@@ -299,9 +296,9 @@ - */ - static struct reslist *make_request(struct DNSQuery *query) - { -- struct reslist *request = MyMalloc(sizeof(struct reslist)); -+ struct reslist *request = rb_malloc(sizeof(struct reslist)); - -- request->sentat = CurrentTime; -+ request->sentat = rb_current_time(); - request->retries = 3; - request->resend = 1; - request->timeout = 4; /* start at 4 and exponential inc. */ -@@ -414,7 +411,7 @@ - if (request == NULL) - { - request = make_request(query); -- request->name = (char *)MyMalloc(strlen(host_name) + 1); -+ request->name = (char *)rb_malloc(strlen(host_name) + 1); - strcpy(request->name, host_name); - request->state = REQ_A; - } -@@ -436,7 +433,7 @@ - { - request = make_request(query); - memcpy(&request->addr, addr, sizeof(struct irc_sockaddr_storage)); -- request->name = (char *)MyMalloc(HOSTLEN + 1); -+ request->name = (char *)rb_malloc(HOSTLEN + 1); - } - - if (addr->ss_family == AF_INET) -@@ -834,7 +831,7 @@ - */ - reply = make_dnsreply(request); - (*request->query->callback) (request->query->ptr, reply); -- MyFree(reply); -+ rb_free(reply); - rem_request(request); - } - } -@@ -851,7 +848,7 @@ - struct DNSReply *cp; - s_assert(request != 0); - -- cp = (struct DNSReply *)MyMalloc(sizeof(struct DNSReply)); -+ cp = (struct DNSReply *)rb_malloc(sizeof(struct DNSReply)); - - cp->h_name = request->name; - memcpy(&cp->addr, &request->addr, sizeof(cp->addr)); -diff -r a44630997728 src/reslib.c ---- a/src/reslib.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/reslib.c Wed Apr 02 04:03:18 2008 +0400 -@@ -84,11 +84,8 @@ - #include "ircd_defs.h" - #include "common.h" - #include "ircd.h" --#include "commio.h" - #include "res.h" - #include "reslib.h" --#include "tools.h" --#include "event.h" - #include "irc_string.h" - #include "sprintf_irc.h" - -diff -r a44630997728 src/restart.c ---- a/src/restart.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/restart.c Wed Apr 02 04:03:18 2008 +0400 -@@ -25,14 +25,12 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "restart.h" - #include "common.h" - #include "ircd.h" - #include "send.h" - #include "s_log.h" - #include "client.h" /* for FLAGS_ALL */ --#include "memory.h" - - /* external var */ - extern char **myargv; -diff -r a44630997728 src/s_auth.c ---- a/src/s_auth.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_auth.c Wed Apr 02 04:03:18 2008 +0400 -@@ -35,23 +35,19 @@ - */ - #include "stdinc.h" - #include "config.h" --#include "tools.h" - #include "s_auth.h" - #include "s_conf.h" - #include "client.h" - #include "common.h" --#include "event.h" - #include "irc_string.h" - #include "sprintf_irc.h" - #include "ircd.h" - #include "numeric.h" - #include "packet.h" - #include "res.h" --#include "commio.h" - #include "s_log.h" - #include "s_stats.h" - #include "send.h" --#include "memory.h" - #include "hook.h" - #include "blacklist.h" - -@@ -120,7 +116,7 @@ - client->localClient->auth_request = request; - request->fd = -1; - request->client = client; -- request->timeout = CurrentTime + ConfigFileEntry.connect_timeout; -+ request->timeout = rb_current_time() + ConfigFileEntry.connect_timeout; - return request; - } - -@@ -437,7 +433,7 @@ - { - auth = ptr->data; - -- if(auth->timeout < CurrentTime) -+ if(auth->timeout < rb_current_time()) - { - if(auth->fd >= 0) - rb_close(auth->fd); -@@ -456,7 +452,7 @@ - sendheader(auth->client, REPORT_FAIL_DNS); - } - -- auth->client->localClient->lasttime = CurrentTime; -+ auth->client->localClient->lasttime = rb_current_time(); - release_auth_client(auth); - } - } -diff -r a44630997728 src/s_conf.c ---- a/src/s_conf.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_conf.c Wed Apr 02 04:03:18 2008 +0400 -@@ -26,7 +26,6 @@ - - #include "stdinc.h" - #include "ircd_defs.h" --#include "tools.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_serv.h" -@@ -35,7 +34,6 @@ - #include "class.h" - #include "client.h" - #include "common.h" --#include "event.h" - #include "hash.h" - #include "irc_string.h" - #include "sprintf_irc.h" -@@ -44,12 +42,9 @@ - #include "hostmask.h" - #include "modules.h" - #include "numeric.h" --#include "commio.h" - #include "s_log.h" - #include "send.h" - #include "s_gline.h" --#include "memory.h" --#include "balloc.h" - #include "patricia.h" - #include "reject.h" - #include "cache.h" -@@ -144,12 +139,12 @@ - if(aconf->spasswd) - memset(aconf->spasswd, 0, strlen(aconf->spasswd)); - -- MyFree(aconf->passwd); -- MyFree(aconf->spasswd); -- MyFree(aconf->name); -- MyFree(aconf->className); -- MyFree(aconf->user); -- MyFree(aconf->host); -+ rb_free(aconf->passwd); -+ rb_free(aconf->spasswd); -+ rb_free(aconf->name); -+ rb_free(aconf->className); -+ rb_free(aconf->user); -+ rb_free(aconf->host); - - BlockHeapFree(confitem_heap, aconf); - } -@@ -722,8 +717,8 @@ - /* ServerInfo.name is not rehashable */ - /* ServerInfo.name = ServerInfo.name; */ - ServerInfo.description = NULL; -- DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT); -- DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT); -+ ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); -+ ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); - - memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip)); - ServerInfo.specific_ipv4_vhost = 0; -@@ -738,9 +733,9 @@ - AdminInfo.email = NULL; - AdminInfo.description = NULL; - -- DupString(ConfigFileEntry.default_operstring, "is an IRC operator"); -- DupString(ConfigFileEntry.default_adminstring, "is a Server Administrator"); -- DupString(ConfigFileEntry.servicestring, "is a Network Service"); -+ ConfigFileEntry.default_operstring = rb_strdup("is an IRC operator"); -+ ConfigFileEntry.default_adminstring = rb_strdup("is a Server Administrator"); -+ ConfigFileEntry.servicestring = rb_strdup("is a Network Service"); - - ConfigFileEntry.default_umodes = UMODE_INVISIBLE; - ConfigFileEntry.failed_oper_notice = YES; -@@ -794,7 +789,7 @@ - ConfigFileEntry.hide_error_messages = 1; - ConfigFileEntry.dots_in_ident = 0; - ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT; -- DupString(ConfigFileEntry.servlink_path, SLPATH); -+ ConfigFileEntry.servlink_path = rb_strdup(SLPATH); - ConfigFileEntry.egdpool_path = NULL; - ConfigFileEntry.use_whois_actually = YES; - ConfigFileEntry.burst_away = NO; -@@ -880,13 +875,13 @@ - ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT; - - if(ConfigFileEntry.servlink_path == NULL) -- DupString(ConfigFileEntry.servlink_path, SLPATH); -+ ConfigFileEntry.servlink_path = rb_strdup(SLPATH); - - if(ServerInfo.network_name == NULL) -- DupString(ServerInfo.network_name, NETWORK_NAME_DEFAULT); -+ ServerInfo.network_name = rb_strdup(NETWORK_NAME_DEFAULT); - - if(ServerInfo.network_desc == NULL) -- DupString(ServerInfo.network_desc, NETWORK_DESC_DEFAULT); -+ ServerInfo.network_desc = rb_strdup(NETWORK_DESC_DEFAULT); - - if((ConfigFileEntry.client_flood < CLIENT_FLOOD_MIN) || - (ConfigFileEntry.client_flood > CLIENT_FLOOD_MAX)) -@@ -940,17 +935,17 @@ - void - add_temp_kline(struct ConfItem *aconf) - { -- if(aconf->hold >= CurrentTime + (10080 * 60)) -+ if(aconf->hold >= rb_current_time() + (10080 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_WEEK]); - aconf->port = TEMP_WEEK; - } -- else if(aconf->hold >= CurrentTime + (1440 * 60)) -+ else if(aconf->hold >= rb_current_time() + (1440 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_DAY]); - aconf->port = TEMP_DAY; - } -- else if(aconf->hold >= CurrentTime + (60 * 60)) -+ else if(aconf->hold >= rb_current_time() + (60 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_klines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; -@@ -974,17 +969,17 @@ - void - add_temp_dline(struct ConfItem *aconf) - { -- if(aconf->hold >= CurrentTime + (10080 * 60)) -+ if(aconf->hold >= rb_current_time() + (10080 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_WEEK]); - aconf->port = TEMP_WEEK; - } -- else if(aconf->hold >= CurrentTime + (1440 * 60)) -+ else if(aconf->hold >= rb_current_time() + (1440 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_DAY]); - aconf->port = TEMP_DAY; - } -- else if(aconf->hold >= CurrentTime + (60 * 60)) -+ else if(aconf->hold >= rb_current_time() + (60 * 60)) - { - rb_dlinkAddAlloc(aconf, &temp_dlines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; -@@ -1017,7 +1012,7 @@ - { - aconf = ptr->data; - -- if(aconf->hold <= CurrentTime) -+ if(aconf->hold <= rb_current_time()) - { - /* Alert opers that a TKline expired - Hwy */ - if(ConfigFileEntry.tkline_expire_notices) -@@ -1042,7 +1037,7 @@ - { - aconf = ptr->data; - -- if(aconf->hold < (CurrentTime + (60 * 60))) -+ if(aconf->hold < (rb_current_time() + (60 * 60))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_MIN] : &temp_dlines[TEMP_MIN]); -@@ -1050,14 +1045,14 @@ - } - else if(aconf->port > TEMP_HOUR) - { -- if(aconf->hold < (CurrentTime + (1440 * 60))) -+ if(aconf->hold < (rb_current_time() + (1440 * 60))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_HOUR] : &temp_dlines[TEMP_HOUR]); - aconf->port = TEMP_HOUR; - } - else if(aconf->port > TEMP_DAY && -- (aconf->hold < (CurrentTime + (10080 * 60)))) -+ (aconf->hold < (rb_current_time() + (10080 * 60)))) - { - rb_dlinkMoveNode(ptr, list, (aconf->status == CONF_KILL) ? - &temp_klines[TEMP_DAY] : &temp_dlines[TEMP_DAY]); -@@ -1198,9 +1193,9 @@ - { - struct alias_entry *aptr = ptr->data; - -- MyFree(aptr->name); -- MyFree(aptr->target); -- MyFree(aptr); -+ rb_free(aptr->name); -+ rb_free(aptr->target); -+ rb_free(aptr); - } - - /* -@@ -1238,19 +1233,19 @@ - #endif - - /* clean out ServerInfo */ -- MyFree(ServerInfo.description); -+ rb_free(ServerInfo.description); - ServerInfo.description = NULL; -- MyFree(ServerInfo.network_name); -+ rb_free(ServerInfo.network_name); - ServerInfo.network_name = NULL; -- MyFree(ServerInfo.network_desc); -+ rb_free(ServerInfo.network_desc); - ServerInfo.network_desc = NULL; - - /* clean out AdminInfo */ -- MyFree(AdminInfo.name); -+ rb_free(AdminInfo.name); - AdminInfo.name = NULL; -- MyFree(AdminInfo.email); -+ rb_free(AdminInfo.email); - AdminInfo.email = NULL; -- MyFree(AdminInfo.description); -+ rb_free(AdminInfo.description); - AdminInfo.description = NULL; - - /* operator{} and class{} blocks are freed above */ -@@ -1262,12 +1257,12 @@ - */ - - /* clean out general */ -- MyFree(ConfigFileEntry.servlink_path); -+ rb_free(ConfigFileEntry.servlink_path); - ConfigFileEntry.servlink_path = NULL; - - RB_DLINK_FOREACH_SAFE(ptr, next_ptr, service_list.head) - { -- MyFree(ptr->data); -+ rb_free(ptr->data); - rb_dlinkDestroy(ptr, &service_list); - } - -@@ -1382,18 +1377,18 @@ - rb_snprintf(buffer, sizeof(buffer), - "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", - user, host, reason, oper_reason, current_date, -- get_oper_name(source_p), CurrentTime); -+ get_oper_name(source_p), rb_current_time()); - } - else if(type == DLINE_TYPE) - { - rb_snprintf(buffer, sizeof(buffer), - "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",%ld\n", host, -- reason, oper_reason, current_date, get_oper_name(source_p), CurrentTime); -+ reason, oper_reason, current_date, get_oper_name(source_p), rb_current_time()); - } - else if(type == RESV_TYPE) - { - rb_snprintf(buffer, sizeof(buffer), "\"%s\",\"%s\",\"%s\",%ld\n", -- host, reason, get_oper_name(source_p), CurrentTime); -+ host, reason, get_oper_name(source_p), rb_current_time()); - } - - if(fputs(buffer, out) == -1) -@@ -1449,7 +1444,7 @@ - { - if(aconf->className == NULL) - { -- DupString(aconf->className, "default"); -+ aconf->className = rb_strdup("default"); - ClassPtr(aconf) = default_class; - return; - } -@@ -1465,16 +1460,16 @@ - aconf->className, aconf->user, aconf->host); - } - -- MyFree(aconf->className); -- DupString(aconf->className, "default"); -+ rb_free(aconf->className); -+ aconf->className = rb_strdup("default"); - return; - } - - if(ConfMaxUsers(aconf) < 0) - { - ClassPtr(aconf) = default_class; -- MyFree(aconf->className); -- DupString(aconf->className, "default"); -+ rb_free(aconf->className); -+ aconf->className = rb_strdup("default"); - return; - } - } -diff -r a44630997728 src/s_gline.c ---- a/src/s_gline.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_gline.c Wed Apr 02 04:03:18 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "channel.h" - #include "client.h" - #include "common.h" -@@ -34,7 +33,6 @@ - #include "ircd.h" - #include "hostmask.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "scache.h" - #include "send.h" -@@ -42,8 +40,6 @@ - #include "s_serv.h" - #include "s_gline.h" - #include "hash.h" --#include "event.h" --#include "memory.h" - - rb_dlink_list glines; - -@@ -125,7 +121,7 @@ - kill_ptr = gline_node->data; - - /* these are in chronological order */ -- if(kill_ptr->hold > CurrentTime) -+ if(kill_ptr->hold > rb_current_time()) - break; - - rb_dlinkDestroy(gline_node, &glines); -@@ -155,12 +151,12 @@ - glp_ptr = pending_node->data; - - if(((glp_ptr->last_gline_time + GLINE_PENDING_EXPIRE) <= -- CurrentTime) || find_is_glined(glp_ptr->host, glp_ptr->user)) -+ rb_current_time()) || find_is_glined(glp_ptr->host, glp_ptr->user)) - - { -- MyFree(glp_ptr->reason1); -- MyFree(glp_ptr->reason2); -- MyFree(glp_ptr); -+ rb_free(glp_ptr->reason1); -+ rb_free(glp_ptr->reason2); -+ rb_free(glp_ptr); - rb_dlinkDestroy(pending_node, &pending_glines); - } - } -diff -r a44630997728 src/s_log.c ---- a/src/s_log.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_log.c Wed Apr 02 04:03:18 2008 +0400 -@@ -210,7 +210,7 @@ - { - static char buf[MAX_DATE_STRING]; - struct tm *lt; -- time_t ltime = CurrentTime; -+ time_t ltime = rb_current_time(); - - lt = localtime(<ime); - -diff -r a44630997728 src/s_newconf.c ---- a/src/s_newconf.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_newconf.c Wed Apr 02 04:03:18 2008 +0400 -@@ -37,16 +37,12 @@ - #include "common.h" - #include "s_conf.h" - #include "s_newconf.h" --#include "tools.h" - #include "client.h" --#include "memory.h" - #include "s_serv.h" - #include "send.h" - #include "hostmask.h" - #include "newconf.h" - #include "hash.h" --#include "balloc.h" --#include "event.h" - #include "sprintf_irc.h" - #include "irc_dictionary.h" - -@@ -157,7 +153,7 @@ - struct remote_conf * - make_remote_conf(void) - { -- struct remote_conf *remote_p = MyMalloc(sizeof(struct remote_conf)); -+ struct remote_conf *remote_p = rb_malloc(sizeof(struct remote_conf)); - return remote_p; - } - -@@ -168,10 +164,10 @@ - if(remote_p == NULL) - return; - -- MyFree(remote_p->username); -- MyFree(remote_p->host); -- MyFree(remote_p->server); -- MyFree(remote_p); -+ rb_free(remote_p->username); -+ rb_free(remote_p->host); -+ rb_free(remote_p->server); -+ rb_free(remote_p); - } - - int -@@ -250,7 +246,7 @@ - struct oper_conf * - make_oper_conf(void) - { -- struct oper_conf *oper_p = MyMalloc(sizeof(struct oper_conf)); -+ struct oper_conf *oper_p = rb_malloc(sizeof(struct oper_conf)); - return oper_p; - } - -@@ -261,24 +257,24 @@ - if(oper_p == NULL) - return; - -- MyFree(oper_p->username); -- MyFree(oper_p->host); -- MyFree(oper_p->name); -+ rb_free(oper_p->username); -+ rb_free(oper_p->host); -+ rb_free(oper_p->name); - - if(oper_p->passwd) - { - memset(oper_p->passwd, 0, strlen(oper_p->passwd)); -- MyFree(oper_p->passwd); -+ rb_free(oper_p->passwd); - } - - #ifdef HAVE_LIBCRYPTO -- MyFree(oper_p->rsa_pubkey_file); -+ rb_free(oper_p->rsa_pubkey_file); - - if(oper_p->rsa_pubkey) - RSA_free(oper_p->rsa_pubkey); - #endif - -- MyFree(oper_p); -+ rb_free(oper_p); - } - - struct oper_conf * -@@ -373,7 +369,7 @@ - struct server_conf * - make_server_conf(void) - { -- struct server_conf *server_p = MyMalloc(sizeof(struct server_conf)); -+ struct server_conf *server_p = rb_malloc(sizeof(struct server_conf)); - server_p->aftype = AF_INET; - return server_p; - } -@@ -388,19 +384,19 @@ - if(!EmptyString(server_p->passwd)) - { - memset(server_p->passwd, 0, strlen(server_p->passwd)); -- MyFree(server_p->passwd); -+ rb_free(server_p->passwd); - } - - if(!EmptyString(server_p->spasswd)) - { - memset(server_p->spasswd, 0, strlen(server_p->spasswd)); -- MyFree(server_p->spasswd); -+ rb_free(server_p->spasswd); - } - -- MyFree(server_p->name); -- MyFree(server_p->host); -- MyFree(server_p->class_name); -- MyFree(server_p); -+ rb_free(server_p->name); -+ rb_free(server_p->host); -+ rb_free(server_p->class_name); -+ rb_free(server_p); - } - - void -@@ -408,7 +404,7 @@ - { - if(EmptyString(server_p->class_name)) - { -- DupString(server_p->class_name, "default"); -+ server_p->class_name = rb_strdup("default"); - server_p->class = default_class; - return; - } -@@ -420,8 +416,8 @@ - conf_report_error("Warning connect::class invalid for %s", - server_p->name); - -- MyFree(server_p->class_name); -- DupString(server_p->class_name, "default"); -+ rb_free(server_p->class_name); -+ server_p->class_name = rb_strdup("default"); - } - - if(strchr(server_p->host, '*') || strchr(server_p->host, '?')) -@@ -697,7 +693,7 @@ - { - aconf = ptr->data; - -- if(aconf->hold && aconf->hold <= CurrentTime) -+ if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, -@@ -714,7 +710,7 @@ - { - aconf = ptr->data; - -- if(aconf->hold && aconf->hold <= CurrentTime) -+ if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, -@@ -729,7 +725,7 @@ - { - aconf = ptr->data; - -- if(aconf->hold && aconf->hold <= CurrentTime) -+ if(aconf->hold && aconf->hold <= rb_current_time()) - { - if(ConfigFileEntry.tkline_expire_notices) - sendto_realops_snomask(SNO_GENERAL, L_ALL, -@@ -758,7 +754,7 @@ - nd = BlockHeapAlloc(nd_heap); - - strlcpy(nd->name, name, sizeof(nd->name)); -- nd->expire = CurrentTime + ConfigFileEntry.nick_delay; -+ nd->expire = rb_current_time() + ConfigFileEntry.nick_delay; - - /* this list is ordered */ - rb_dlinkAddTail(nd, &nd->lnode, &nd_list); -@@ -789,7 +785,7 @@ - /* this list is ordered - we can stop when we hit the first - * entry that doesnt expire.. - */ -- if(nd->expire > CurrentTime) -+ if(nd->expire > rb_current_time()) - return; - - free_nd_entry(nd); -@@ -805,14 +801,14 @@ - if(find_tgchange(host)) - return; - -- target = MyMalloc(sizeof(tgchange)); -+ target = rb_malloc(sizeof(tgchange)); - pnode = make_and_lookup(tgchange_tree, host); - - pnode->data = target; - target->pnode = pnode; - -- DupString(target->ip, host); -- target->expiry = CurrentTime + (60*60*12); -+ target->ip = rb_strdup(host); -+ target->expiry = rb_current_time() + (60*60*12); - - rb_dlinkAdd(target, &target->node, &tgchange_list); - } -diff -r a44630997728 src/s_serv.c ---- a/src/s_serv.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_serv.c Wed Apr 02 04:03:18 2008 +0400 -@@ -30,12 +30,10 @@ - #include - #endif - --#include "tools.h" - #include "s_serv.h" - #include "class.h" - #include "client.h" - #include "common.h" --#include "event.h" - #include "hash.h" - #include "irc_string.h" - #include "sprintf_irc.h" -@@ -44,7 +42,6 @@ - #include "numeric.h" - #include "packet.h" - #include "res.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -@@ -53,7 +50,6 @@ - #include "scache.h" - #include "send.h" - #include "client.h" --#include "memory.h" - #include "channel.h" /* chcap_usage_counts stuff... */ - #include "hook.h" - #include "msg.h" -@@ -218,7 +214,7 @@ - /* only bother if we haven't already got something queued... */ - if(!target_p->localClient->slinkq) - { -- target_p->localClient->slinkq = MyMalloc(1); /* sigh.. */ -+ target_p->localClient->slinkq = rb_malloc(1); /* sigh.. */ - target_p->localClient->slinkq[0] = SLINKCMD_ZIPSTATS; - target_p->localClient->slinkq_ofs = 0; - target_p->localClient->slinkq_len = 1; -@@ -374,7 +370,7 @@ - * made one successfull connection... [this algorithm is - * a bit fuzzy... -- msa >;) ] - */ -- if(tmp_p->hold > CurrentTime) -+ if(tmp_p->hold > rb_current_time()) - { - if(next > tmp_p->hold || next == 0) - next = tmp_p->hold; -@@ -382,7 +378,7 @@ - } - - confrq = get_con_freq(cltmp); -- tmp_p->hold = CurrentTime + confrq; -+ tmp_p->hold = rb_current_time() + confrq; - - /* - * Found a CONNECT config with port specified, scan clients -@@ -1020,7 +1016,7 @@ - if(client_p->localClient->passwd) - { - memset(client_p->localClient->passwd, 0, strlen(client_p->localClient->passwd)); -- MyFree(client_p->localClient->passwd); -+ rb_free(client_p->localClient->passwd); - client_p->localClient->passwd = NULL; - } - -@@ -1083,7 +1079,7 @@ - SetServlink(client_p); - } - -- sendto_one(client_p, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN, CurrentTime); -+ sendto_one(client_p, "SVINFO %d %d 0 :%ld", TS_CURRENT, TS_MIN, rb_current_time()); - - client_p->servptr = &me; - -@@ -1111,13 +1107,13 @@ - - if(client_p->localClient->fullcaps) - { -- DupString(client_p->serv->fullcaps, client_p->localClient->fullcaps); -- MyFree(client_p->localClient->fullcaps); -+ client_p->serv->fullcaps = rb_strdup(client_p->localClient->fullcaps); -+ rb_free(client_p->localClient->fullcaps); - client_p->localClient->fullcaps = NULL; - } - - client_p->serv->nameinfo = scache_connect(client_p->name, client_p->info, IsHidden(client_p)); -- client_p->localClient->firsttime = CurrentTime; -+ client_p->localClient->firsttime = rb_current_time(); - /* fixing eob timings.. -gnp */ - - if((rb_dlink_list_length(&lclient_list) + rb_dlink_list_length(&serv_list)) > -@@ -1251,7 +1247,7 @@ - int linecount = 0; - int linelen; - -- iobuf = MyMalloc(256); /* XXX: This seems arbitrary. Perhaps make it IRCD_BUFSIZE? --nenolod */ -+ iobuf = rb_malloc(256); /* XXX: This seems arbitrary. Perhaps make it IRCD_BUFSIZE? --nenolod */ - - if(IsCapable(server, CAP_ZIP)) - { -diff -r a44630997728 src/s_stats.c ---- a/src/s_stats.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_stats.c Wed Apr 02 04:03:18 2008 +0400 -@@ -30,9 +30,7 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "send.h" --#include "memory.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "whowas.h" -@@ -78,7 +76,7 @@ - sp->is_sbr += target_p->localClient->receiveB; - sp->is_sks += target_p->localClient->sendK; - sp->is_skr += target_p->localClient->receiveK; -- sp->is_sti += CurrentTime - target_p->localClient->firsttime; -+ sp->is_sti += rb_current_time() - target_p->localClient->firsttime; - sp->is_sv++; - if(sp->is_sbs > 1023) - { -@@ -100,7 +98,7 @@ - sp->is_cbr += target_p->localClient->receiveB; - sp->is_cks += target_p->localClient->sendK; - sp->is_ckr += target_p->localClient->receiveK; -- sp->is_cti += CurrentTime - target_p->localClient->firsttime; -+ sp->is_cti += rb_current_time() - target_p->localClient->firsttime; - sp->is_cl++; - if(sp->is_cbs > 1023) - { -diff -r a44630997728 src/s_user.c ---- a/src/s_user.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/s_user.c Wed Apr 02 04:03:18 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "s_user.h" - #include "channel.h" - #include "class.h" -@@ -38,7 +37,6 @@ - #include "listener.h" - #include "msg.h" - #include "numeric.h" --#include "commio.h" - #include "s_conf.h" - #include "s_newconf.h" - #include "s_log.h" -@@ -48,7 +46,6 @@ - #include "send.h" - #include "supported.h" - #include "whowas.h" --#include "memory.h" - #include "packet.h" - #include "reject.h" - #include "cache.h" -@@ -264,7 +261,7 @@ - if(rb_dlink_list_length(&source_p->preClient->dnsbl_queries) > 0) - return -1; - -- client_p->localClient->last = CurrentTime; -+ client_p->localClient->last = rb_current_time(); - /* Straight up the maximum rate of flooding... */ - source_p->localClient->allow_read = MAX_FLOOD_BURST; - -@@ -380,7 +377,7 @@ - if(source_p->localClient->passwd) - { - memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); -- MyFree(source_p->localClient->passwd); -+ rb_free(source_p->localClient->passwd); - source_p->localClient->passwd = NULL; - } - } -@@ -676,7 +673,7 @@ - source_p->localClient->passwd); - } - memset(source_p->localClient->passwd, 0, strlen(source_p->localClient->passwd)); -- MyFree(source_p->localClient->passwd); -+ rb_free(source_p->localClient->passwd); - source_p->localClient->passwd = NULL; - } - -@@ -990,7 +987,7 @@ - } - source_p->flags2 &= ~OPER_FLAGS; - -- MyFree(source_p->localClient->opername); -+ rb_free(source_p->localClient->opername); - source_p->localClient->opername = NULL; - - rb_dlinkFindDestroy(source_p, &local_oper_list); -@@ -1277,7 +1274,7 @@ - SetExemptKline(source_p); - - source_p->flags2 |= oper_p->flags; -- DupString(source_p->localClient->opername, oper_p->name); -+ source_p->localClient->opername = rb_strdup(oper_p->name); - - rb_dlinkAddAlloc(source_p, &local_oper_list); - rb_dlinkAddAlloc(source_p, &oper_list); -diff -r a44630997728 src/scache.c ---- a/src/scache.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/scache.c Wed Apr 02 04:03:18 2008 +0400 -@@ -32,7 +32,6 @@ - #include "numeric.h" - #include "send.h" - #include "scache.h" --#include "memory.h" - #include "s_conf.h" - - -@@ -100,13 +99,13 @@ - return ptr; - } - -- ptr = (struct scache_entry *) MyMalloc(sizeof(struct scache_entry)); -+ ptr = (struct scache_entry *) rb_malloc(sizeof(struct scache_entry)); - s_assert(0 != ptr); - - strlcpy(ptr->name, name, sizeof(ptr->name)); - ptr->info[0] = '\0'; - ptr->flags = 0; -- ptr->known_since = CurrentTime; -+ ptr->known_since = rb_current_time(); - ptr->last_connect = 0; - ptr->last_split = 0; - -@@ -127,7 +126,7 @@ - ptr->flags |= SC_HIDDEN; - else - ptr->flags &= ~SC_HIDDEN; -- ptr->last_connect = CurrentTime; -+ ptr->last_connect = rb_current_time(); - return ptr; - } - -@@ -137,7 +136,7 @@ - if (ptr == NULL) - return; - ptr->flags &= ~SC_ONLINE; -- ptr->last_split = CurrentTime; -+ ptr->last_split = rb_current_time(); - } - - const char *scache_get_name(struct scache_entry *ptr) -@@ -169,9 +168,9 @@ - !ConfigServerHide.disable_hidden) - show = FALSE; - else if (scache_ptr->flags & SC_ONLINE) -- show = scache_ptr->known_since < CurrentTime - ConfigServerHide.links_delay; -+ show = scache_ptr->known_since < rb_current_time() - ConfigServerHide.links_delay; - else -- show = scache_ptr->last_split > CurrentTime - ConfigServerHide.links_delay && scache_ptr->last_split - scache_ptr->known_since > ConfigServerHide.links_delay; -+ show = scache_ptr->last_split > rb_current_time() - ConfigServerHide.links_delay && scache_ptr->last_split - scache_ptr->known_since > ConfigServerHide.links_delay; - if (show) - sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS), - scache_ptr->name, me.name, 1, scache_ptr->info); -@@ -204,7 +203,7 @@ - scache_ptr = scache_hash[i]; - while (scache_ptr) - { -- if (!(scache_ptr->flags & SC_ONLINE) && scache_ptr->last_split > CurrentTime - MISSING_TIMEOUT) -+ if (!(scache_ptr->flags & SC_ONLINE) && scache_ptr->last_split > rb_current_time() - MISSING_TIMEOUT) - sendto_one_numeric(source_p, RPL_MAP, "** %s (recently split)", - scache_ptr->name); - -diff -r a44630997728 src/send.c ---- a/src/send.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/send.c Wed Apr 02 04:03:18 2008 +0400 -@@ -25,7 +25,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "send.h" - #include "channel.h" - #include "class.h" -@@ -34,14 +33,11 @@ - #include "irc_string.h" - #include "ircd.h" - #include "numeric.h" --#include "commio.h" - #include "s_serv.h" - #include "sprintf_irc.h" - #include "s_conf.h" - #include "s_newconf.h" --#include "linebuf.h" - #include "s_log.h" --#include "memory.h" - #include "hook.h" - #include "monitor.h" - -@@ -267,7 +263,7 @@ - else - { - to->localClient->slinkq_ofs = 0; -- MyFree(to->localClient->slinkq); -+ rb_free(to->localClient->slinkq); - to->localClient->slinkq = NULL; - } - } -diff -r a44630997728 src/substitution.c ---- a/src/substitution.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/substitution.c Wed Apr 02 04:03:18 2008 +0400 -@@ -34,8 +34,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" --#include "balloc.h" - #include "s_user.h" - #include "irc_string.h" - -@@ -59,10 +57,10 @@ - */ - void substitution_append_var(rb_dlink_list *varlist, const char *name, const char *value) - { -- struct substitution_variable *tmp = MyMalloc(sizeof(struct substitution_variable)); -+ struct substitution_variable *tmp = rb_malloc(sizeof(struct substitution_variable)); - -- DupString(tmp->name, name); -- DupString(tmp->value, value); -+ tmp->name = rb_strdup(name); -+ tmp->value = rb_strdup(value); - - rb_dlinkAddAlloc(tmp, varlist); - } -@@ -83,9 +81,9 @@ - struct substitution_variable *tmp = (struct substitution_variable *) nptr->data; - - rb_dlinkDelete(nptr, varlist); -- MyFree(tmp->name); -- MyFree(tmp->value); -- MyFree(tmp); -+ rb_free(tmp->name); -+ rb_free(tmp->value); -+ rb_free(tmp); - } - } - -diff -r a44630997728 src/supported.c ---- a/src/supported.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/supported.c Wed Apr 02 04:03:18 2008 +0400 -@@ -81,7 +81,6 @@ - */ - - #include "stdinc.h" --#include "tools.h" - #include "client.h" - #include "common.h" - #include "numeric.h" -@@ -104,7 +103,7 @@ - { - struct isupportitem *item; - -- item = MyMalloc(sizeof(struct isupportitem)); -+ item = rb_malloc(sizeof(struct isupportitem)); - item->name = name; - item->func = func; - item->param = param; -@@ -124,7 +123,7 @@ - if (!strcmp(item->name, name)) - { - rb_dlinkDelete(ptr, &isupportlist); -- MyFree(item); -+ rb_free(item); - } - } - } -diff -r a44630997728 src/whowas.c ---- a/src/whowas.c Wed Apr 02 00:10:51 2008 +0200 -+++ b/src/whowas.c Wed Apr 02 04:03:18 2008 +0400 -@@ -38,7 +38,6 @@ - #include "s_user.h" - #include "send.h" - #include "s_conf.h" --#include "memory.h" - #include "scache.h" - - /* internally defined function */ -@@ -73,7 +72,7 @@ - del_whowas_from_list(&WHOWASHASH[who->hashv], who); - } - who->hashv = hash_whowas_name(client_p->name); -- who->logoff = CurrentTime; -+ who->logoff = rb_current_time(); - /* - * NOTE: strcpy ok here, the sizes in the client struct MUST - * match the sizes in the whowas struct -@@ -119,7 +118,7 @@ - struct Whowas *temp; - int blah; - -- timelimit = CurrentTime - timelimit; -+ timelimit = rb_current_time() - timelimit; - blah = hash_whowas_name(nick); - temp = WHOWASHASH[blah]; - for (; temp; temp = temp->next) diff --git a/extensions/m_webirc.c b/extensions/m_webirc.c index 2f71fa12..36a83894 100644 --- a/extensions/m_webirc.c +++ b/extensions/m_webirc.c @@ -126,10 +126,12 @@ mr_webirc(struct Client *client_p, struct Client *source_p, int parc, const char else strlcpy(source_p->host, source_p->sockhost, sizeof(source_p->host)); - rb_inet_pton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); + del_unknown_ip(source_p); + inetpton_sock(parv[4], (struct sockaddr *)&source_p->localClient->ip); /* Check dlines now, k/glines will be checked on registration */ - if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip))) + if((aconf = find_dline((struct sockaddr *)&source_p->localClient->ip, + source_p->localClient->ip.ss_family))) { if(!(aconf->status & CONF_EXEMPTDLINE)) { diff --git a/include/class.h b/include/class.h index 058a0d69..af6fa84b 100644 --- a/include/class.h +++ b/include/class.h @@ -43,7 +43,7 @@ struct Class int con_freq; int ping_freq; int total; - rb_patricia_tree_t *ip_limits; + struct _patricia_tree_t *ip_limits; int cidr_bitlen; int cidr_amount; diff --git a/include/client.h b/include/client.h index 11b71f46..943098e6 100644 --- a/include/client.h +++ b/include/client.h @@ -233,7 +233,7 @@ struct LocalUser conf_item_t *att_conf; /* attached conf */ struct server_conf *att_sconf; - struct rb_sockaddr_storage ip; + struct irc_sockaddr_storage ip; time_t last_nick_change; int number_of_nick_changes; @@ -296,10 +296,6 @@ struct LocalUser char *mangledhost; /* non-NULL if host mangling module loaded and applicable to this client */ - - struct rb_sockaddr_storage *lip; /* alloc before auth/freed after auth */ - struct _ssl_ctl *ssl_ctl; /* which ssl daemon we're associate with */ - rb_uint32_t localflags; }; struct PreClient @@ -465,10 +461,6 @@ struct exit_client_hook #define FLAGS2_EXEMPTSHIDE 0x40000000 #define FLAGS2_EXEMPTJUPE 0x80000000 -/* flags for local clients, this needs stuff moved from above to here at some point */ -#define LFLAGS_SSL 0x00000001 -#define LFLAGS_FLUSH 0x00000002 - #define DEFAULT_OPER_UMODES (UMODE_SERVNOTICE | UMODE_OPERWALL | \ UMODE_WALLOP | UMODE_LOCOPS) #define DEFAULT_OPER_SNOMASK SNO_GENERAL @@ -511,16 +503,6 @@ struct exit_client_hook #define ClearDynSpoof(x) ((x)->flags &= ~FLAGS_DYNSPOOF) #define IsExUnknown(x) ((x)->flags & FLAGS_EXUNKNOWN) #define SetExUnknown(x) ((x)->flags |= FLAGS_EXUNKNOWN) - -/* local flags */ - -#define IsSSL(x) ((x)->localClient->localflags & LFLAGS_SSL) -#define SetSSL(x) ((x)->localClient->localflags |= LFLAGS_SSL) -#define ClearSSL(x) ((x)->localClient->localflags &= ~LFLAGS_SSL) - -#define IsFlush(x) ((x)->localClient->localflags & LFLAGS_FLUSH) -#define SetFlush(x) ((x)->localClient->localflags |= LFLAGS_FLUSH) -#define ClearFlush(x) ((x)->localClient->localflags &= ~LFLAGS_FLUSH) /* oper flags */ #define MyOper(x) (MyConnect(x) && IsOper(x)) @@ -627,7 +609,6 @@ extern void close_connection(struct Client *); extern void init_uid(void); extern char *generate_uid(void); -void flood_endgrace(struct Client *); void allocate_away(struct Client *); void free_away(struct Client *); diff --git a/include/common.h b/include/common.h index fe2afd89..b96cb0f8 100644 --- a/include/common.h +++ b/include/common.h @@ -65,7 +65,4 @@ /* Right out of the RFC */ #define IRCD_BUFSIZE 512 -/* readbuf size */ -#define READBUF_SIZE 16384 - #endif /* INCLUDED_common_h */ diff --git a/include/hash.h b/include/hash.h index a28a8d4c..97660221 100644 --- a/include/hash.h +++ b/include/hash.h @@ -45,9 +45,6 @@ extern struct Dictionary *nd_dict; #define U_MAX_BITS 17 #define U_MAX 131072 /* 2^17 */ -/* Client fd hash table size, used in hash.c */ -#define CLI_FD_MAX 4096 - /* Channel hash table size, hash.c/s_debug.c */ #define CH_MAX_BITS 16 #define CH_MAX 65536 /* 2^16 */ @@ -101,10 +98,6 @@ extern void del_from_resv_hash(const char *name, struct ConfItem *aconf); extern struct ConfItem *hash_find_resv(const char *name); extern void clear_resv_hash(void); -void add_to_cli_fd_hash(struct Client *client_p); -void del_from_cli_fd_hash(struct Client *client_p); -struct Client *find_cli_fd_hash(int fd); - extern void hash_stats(struct Client *); #endif /* INCLUDED_hash_h */ diff --git a/include/hostmask.h b/include/hostmask.h index f73c32ba..191cce53 100644 --- a/include/hostmask.h +++ b/include/hostmask.h @@ -51,6 +51,8 @@ struct ConfItem *find_address_conf(const char *host, const char *sockhost, const char *, const char *, struct sockaddr *, int); +struct ConfItem *find_dline(struct sockaddr *, int); + #define find_kline(x) (find_conf_by_address((x)->host, (x)->sockhost, \ (x)->orighost, \ (struct sockaddr *)&(x)->localClient->ip, CONF_KILL,\ @@ -83,7 +85,7 @@ struct AddressRec struct { /* Pointer into ConfItem... -A1kmm */ - struct rb_sockaddr_storage addr; + struct irc_sockaddr_storage addr; int bits; } ipa; diff --git a/include/irc_string.h b/include/irc_string.h index ba1d0a51..2aa7f41d 100644 --- a/include/irc_string.h +++ b/include/irc_string.h @@ -99,6 +99,12 @@ size_t strlcpy(char *dst, const char *src, size_t siz); size_t strlcat(char *dst, const char *src, size_t siz); #endif +#ifdef HAVE_STRNDUP +#define DupNString(x, y, len) do { x = strndup(y, len); if(x == NULL) outofmemory(); } while (0) +#else +#define DupNString(x, y, len) do { x = malloc(len+1); if(x == NULL) outofmemory(); strlcpy(x, y, len+1); } while(0) +#endif + /* * clean_string - cleanup control and high ascii characters * -Dianora diff --git a/include/ircd.h b/include/ircd.h index fd08c0a7..f026f3d0 100644 --- a/include/ircd.h +++ b/include/ircd.h @@ -109,7 +109,4 @@ extern int testing_conf; extern struct ev_entry *check_splitmode_ev; -extern int maxconnections; -extern int ssl_ok; - #endif diff --git a/include/ircd_defs.h b/include/ircd_defs.h index f5c359f6..7105a995 100644 --- a/include/ircd_defs.h +++ b/include/ircd_defs.h @@ -152,6 +152,17 @@ #endif #endif /* #ifdef IPV6 */ + +#ifdef IPV6 +#define irc_sockaddr_storage sockaddr_storage +#else +#define irc_sockaddr_storage sockaddr +#define ss_family sa_family +#ifdef SOCKADDR_IN_HAS_LEN +#define ss_len sa_len +#endif +#endif + #ifdef IPV6 #define PATRICIA_BITS 128 #else diff --git a/include/listener.h b/include/listener.h index bc03d080..9bab533b 100644 --- a/include/listener.h +++ b/include/listener.h @@ -27,25 +27,28 @@ #ifndef INCLUDED_listener_h #define INCLUDED_listener_h -struct Client; - -struct Listener -{ - rb_dlink_node node; - const char *name; /* listener name */ - rb_fde_t *F; /* file descriptor */ - int ref_count; /* number of connection references */ - int active; /* current state of listener */ - int ssl; /* ssl listener */ - struct rb_sockaddr_storage addr; - char vhost[HOSTLEN + 1]; /* virtual name of listener */ -}; - -void add_listener(int port, const char *vaddr_ip, int family, int ssl); -void close_listener(struct Listener *listener); -void close_listeners(void); -const char *get_listener_name(struct Listener *listener); -void show_ports(struct Client *client); -void free_listener(struct Listener *); +#include "ircd_defs.h" + +struct Client; + +struct Listener +{ + struct Listener *next; /* list node pointer */ + const char *name; /* listener name */ + int fd; /* file descriptor */ + int ref_count; /* number of connection references */ + int active; /* current state of listener */ + int index; /* index into poll array */ + struct irc_sockaddr_storage addr; + struct DNSQuery *dns_query; + char vhost[HOSTLEN + 1]; /* virtual name of listener */ +}; + +extern void add_listener(int port, const char *vaddr_ip, int family); +extern void close_listener(struct Listener *listener); +extern void close_listeners(void); +extern const char *get_listener_name(const struct Listener *listener); +extern void show_ports(struct Client *client); +extern void free_listener(struct Listener *); #endif /* INCLUDED_listener_h */ diff --git a/include/packet.h b/include/packet.h index 22830256..7962e6b3 100644 --- a/include/packet.h +++ b/include/packet.h @@ -46,8 +46,9 @@ #define MAX_FLOOD 5 #define MAX_FLOOD_BURST MAX_FLOOD * 8 -extern PF read_ctrl_packet; -extern PF read_packet; -extern EVH flood_recalc; +extern PF read_ctrl_packet; +extern PF read_packet; +extern PF flood_recalc; +extern void flood_endgrace(struct Client *); #endif /* INCLUDED_packet_h */ diff --git a/include/reject.h b/include/reject.h index e450891c..2a36f9a3 100644 --- a/include/reject.h +++ b/include/reject.h @@ -1,56 +1,45 @@ -/* - * ircd-ratbox: A slightly useful ircd - * reject.h: header to a file which rejects users with prejudice - * - * Copyright (C) 2003 Aaron Sethman - * Copyright (C) 2003-2005 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * - * $Id: reject.h 25056 2008-02-06 20:47:40Z androsyn $ - */ -#ifndef INCLUDED_reject_h -#define INCLUDED_reject_h - -/* amount of time to delay a rejected clients exit */ -#define DELAYED_EXIT_TIME 10 - -void init_reject(void); -int check_reject(rb_fde_t *F, struct sockaddr *addr); -void add_reject(struct Client *); -void flush_reject(void); -int remove_reject(const char *ip); -struct ConfItem *find_dline(struct sockaddr *addr); -struct ConfItem *find_dline_exact(struct sockaddr *addr, unsigned int bitlen); -void remove_dline(struct ConfItem *aconf); -int add_dline(struct ConfItem *aconf); -int add_eline(struct ConfItem *aconf); -void report_dlines(struct Client *); -void report_tdlines(struct Client *); -void report_elines(struct Client *); -unsigned long delay_exit_length(void); - -int throttle_add(struct sockaddr *addr); - -int inc_global_cidr_count(struct Client *client_p); -void dec_global_cidr_count(struct Client *client_p); -int check_global_cidr_count(struct Client *client_p); -void rehash_global_cidr_tree(void); - - -#endif - +/* + * ircd-ratbox: A slightly useful ircd + * reject.h: header to a file which rejects users with prejudice + * + * Copyright (C) 2003 Aaron Sethman + * Copyright (C) 2003-2004 ircd-ratbox development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * + * $Id: reject.h 3446 2007-05-14 22:21:16Z jilles $ + */ +#ifndef INCLUDED_reject_h +#define INCLUDED_reject_h + +/* amount of time to delay a rejected clients exit */ +#define DELAYED_EXIT_TIME 10 + +extern rb_dlink_list delay_exit; + +void init_reject(void); +int check_reject(struct Client *); +void add_reject(struct Client *, const char *mask1, const char *mask2); +void flush_reject(void); +int remove_reject_ip(const char *ip); +int remove_reject_mask(const char *mask1, const char *mask2); + +int add_unknown_ip(struct Client *client_p); +void del_unknown_ip(struct Client *client_p); + +#endif + diff --git a/include/res.h b/include/res.h index 2e7f6621..76338974 100644 --- a/include/res.h +++ b/include/res.h @@ -23,7 +23,7 @@ struct DNSReply { char *h_name; - struct rb_sockaddr_storage addr; + struct irc_sockaddr_storage addr; }; struct DNSQuery @@ -32,14 +32,14 @@ struct DNSQuery void (*callback)(void* vptr, struct DNSReply *reply); /* callback to call */ }; -extern struct rb_sockaddr_storage irc_nsaddr_list[]; +extern struct irc_sockaddr_storage irc_nsaddr_list[]; extern int irc_nscount; extern void init_resolver(void); extern void restart_resolver(void); extern void delete_resolver_queries(const struct DNSQuery *); extern void gethost_byname_type(const char *, struct DNSQuery *, int); -extern void gethost_byaddr(const struct rb_sockaddr_storage *, struct DNSQuery *); +extern void gethost_byaddr(const struct irc_sockaddr_storage *, struct DNSQuery *); extern void add_local_domain(char *, size_t); extern void report_dns_servers(struct Client *); diff --git a/include/s_conf.h b/include/s_conf.h index 5b917481..584fab5f 100644 --- a/include/s_conf.h +++ b/include/s_conf.h @@ -46,7 +46,7 @@ struct hostent; struct ip_value { - struct rb_sockaddr_storage ip; + struct irc_sockaddr_storage ip; int ip_mask; int type; }; @@ -54,26 +54,22 @@ struct ip_value extern FILE *conf_fbfile_in; extern char conf_line_in[256]; -struct ConfItem -{ - unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ - unsigned int flags; - int clients; /* Number of *LOCAL* clients using this */ - - union - { - char *name; /* IRC name, nick, server name, or original u@h */ - const char *oper; - } info; - - char *host; /* host part of user@host */ - char *passwd; /* doubles as kline reason *ugh* */ - char *spasswd; /* Password to send. */ - char *user; /* user part of user@host */ - int port; - time_t hold; /* Hold action until this time (calendar time) */ - struct Class *c_class; /* Class of connection */ - rb_patricia_node_t *pnode; +struct ConfItem +{ + struct ConfItem *next; /* list node pointer */ + unsigned int status; /* If CONF_ILLEGAL, delete when no clients */ + unsigned int flags; + int clients; /* Number of *LOCAL* clients using this */ + char *name; /* IRC name, nick, server name, or original u@h */ + char *host; /* host part of user@host */ + char *passwd; /* doubles as kline reason *ugh* */ + char *spasswd; /* Password to send. */ + char *user; /* user part of user@host */ + int port; + time_t hold; /* Hold action until this time (calendar time) */ + char *className; /* Name of class */ + struct Class *c_class; /* Class of connection */ + rb_patricia_node_t *pnode; /* Our patricia node */ }; #define CONF_ILLEGAL 0x80000000 @@ -341,8 +337,8 @@ extern struct ConfItem *find_tkline(const char *, const char *, struct sockaddr extern char *show_iline_prefix(struct Client *, struct ConfItem *, char *); extern void get_printable_conf(struct ConfItem *, char **, char **, char **, char **, int *, char **); -void get_printable_kline(struct Client *, struct ConfItem *, - const char **, const char **, const char **, const char **); +extern void get_printable_kline(struct Client *, struct ConfItem *, + char **, char **, char **, char **); extern void yyerror(const char *); extern int conf_yy_fatal_error(const char *); diff --git a/include/s_newconf.h b/include/s_newconf.h index 35670984..bd3282c6 100644 --- a/include/s_newconf.h +++ b/include/s_newconf.h @@ -203,7 +203,7 @@ struct server_conf time_t hold; int aftype; - struct rb_sockaddr_storage my_ipnum; + struct irc_sockaddr_storage my_ipnum; char *class_name; struct Class *class; diff --git a/include/s_stats.h b/include/s_stats.h index 0ed1634d..562e77c6 100644 --- a/include/s_stats.h +++ b/include/s_stats.h @@ -47,15 +47,15 @@ struct ServerStatistics unsigned int is_cl; /* number of client connections */ unsigned int is_sv; /* number of server connections */ unsigned int is_ni; /* connection but no idea who it was */ - unsigned long long int is_cbs; /* bytes sent to clients */ - unsigned long long int is_cbr; /* bytes received to clients */ - unsigned long long int is_sbs; /* bytes sent to servers */ - unsigned long long int is_sbr; /* bytes received to servers */ + unsigned short is_cbs; /* bytes sent to clients */ + unsigned short is_cbr; /* bytes received to clients */ + unsigned short is_sbs; /* bytes sent to servers */ + unsigned short is_sbr; /* bytes received to servers */ unsigned long is_cks; /* k-bytes sent to clients */ unsigned long is_ckr; /* k-bytes received to clients */ unsigned long is_sks; /* k-bytes sent to servers */ unsigned long is_skr; /* k-bytes received to servers */ - time_t is_cti; /* time spent connected by clients */ + time_t is_cti; /* time spent connected by clients */ time_t is_sti; /* time spent connected by servers */ unsigned int is_ac; /* connections accepted */ unsigned int is_ref; /* accepts refused */ @@ -74,7 +74,10 @@ struct ServerStatistics unsigned int is_tgch; /* messages blocked due to target change */ }; -extern struct ServerStatistics ServerStats; +extern struct ServerStatistics *ServerStats; + +extern void init_stats(void); +extern void tstats(struct Client *client); extern void count_memory(struct Client *); diff --git a/include/sslproc.h b/include/sslproc.h deleted file mode 100644 index b7b49b69..00000000 --- a/include/sslproc.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * sslproc.h: An interface to the ratbox ssld helper daemon - * Copyright (C) 2007 Aaron Sethman - * Copyright (C) 2007 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * $Id: sslproc.h 25179 2008-03-30 16:34:57Z androsyn $ - */ - -#ifndef INCLUDED_sslproc_h -#define INCLUDED_sslproc_h - -struct _ssl_ctl; -typedef struct _ssl_ctl ssl_ctl_t; - -void init_ssld(void); -int start_ssldaemon(int count, const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params); -ssl_ctl_t *start_ssld_accept(rb_fde_t *sslF, rb_fde_t *plainF, int id); -ssl_ctl_t *start_ssld_connect(rb_fde_t *sslF, rb_fde_t *plainF, int id); -void start_zlib_session(void *data); -void send_new_ssl_certs(const char *ssl_cert, const char *ssl_private_key, const char *ssl_dh_params); -void ssld_decrement_clicount(ssl_ctl_t *ctl); -int get_ssld_count(void); - -#endif - diff --git a/modules/core/m_message.c b/modules/core/m_message.c index 8f09c426..95a68fc7 100644 --- a/modules/core/m_message.c +++ b/modules/core/m_message.c @@ -612,6 +612,7 @@ add_target(struct Client *source_p, struct Client *target_p) /* cant clear any, full target list */ else if(USED_TARGETS(source_p) == 10) { + ServerStats->is_tgch++; add_tgchange(source_p->sockhost); return 0; } diff --git a/modules/core/m_nick.c b/modules/core/m_nick.c index d007ec46..02c27878 100644 --- a/modules/core/m_nick.c +++ b/modules/core/m_nick.c @@ -281,7 +281,7 @@ mc_nick(struct Client *client_p, struct Client *source_p, int parc, const char * /* if nicks erroneous, or too long, kill */ if(!clean_nick(parv[1], 0)) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick: %s From: %s(via %s)", parv[1], source_p->servptr->name, client_p->name); @@ -343,7 +343,7 @@ ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char * /* if nicks empty, erroneous, or too long, kill */ if(!clean_nick(parv[1], 0)) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick: %s From: %s(via %s)", parv[1], parv[7], client_p->name); @@ -354,7 +354,7 @@ ms_nick(struct Client *client_p, struct Client *source_p, int parc, const char * /* invalid username or host? */ if(!clean_username(parv[5]) || !clean_host(parv[6])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad user@host: %s@%s From: %s(via %s)", parv[5], parv[6], parv[7], client_p->name); @@ -435,7 +435,7 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p /* if nicks erroneous, or too long, kill */ if(!clean_nick(parv[1], 0)) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick: %s From: %s(via %s)", parv[1], source_p->name, client_p->name); @@ -445,7 +445,7 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p if(!clean_username(parv[5]) || !clean_host(parv[6])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad user@host: %s@%s From: %s(via %s)", parv[5], parv[6], source_p->name, client_p->name); @@ -455,7 +455,7 @@ ms_uid(struct Client *client_p, struct Client *source_p, int parc, const char *p if(!clean_uid(parv[8])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad UID: %s From: %s(via %s)", parv[8], source_p->name, client_p->name); @@ -527,7 +527,7 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char * /* if nicks erroneous, or too long, kill */ if(!clean_nick(parv[1], 0)) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick: %s From: %s(via %s)", parv[1], source_p->name, client_p->name); @@ -537,7 +537,7 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char * if(!clean_username(parv[5]) || !clean_host(parv[6])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad user@host: %s@%s From: %s(via %s)", parv[5], parv[6], source_p->name, client_p->name); @@ -547,7 +547,7 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char * if(!clean_uid(parv[8])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad UID: %s From: %s(via %s)", parv[8], source_p->name, client_p->name); @@ -557,7 +557,7 @@ ms_euid(struct Client *client_p, struct Client *source_p, int parc, const char * if(strcmp(parv[9], "*") && !clean_host(parv[9])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad realhost: %s From: %s(via %s)", parv[9], source_p->name, client_p->name); @@ -930,7 +930,7 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p, if (use_save) { save_user(&me, &me, target_p); - ServerStats.is_save++; + ServerStats->is_save++; sendto_one(client_p, ":%s SAVE %s %ld", me.id, uid, (long)newts); register_client(client_p, source_p, @@ -950,7 +950,7 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p, /* we then need to KILL the old client everywhere */ kill_client_serv_butone(NULL, target_p, "%s (Nick collision (new))", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; target_p->flags |= FLAGS_KILLED; exit_client(client_p, target_p, &me, "Nick collision (new)"); @@ -998,12 +998,12 @@ perform_nick_collides(struct Client *source_p, struct Client *client_p, if (use_save) { - ServerStats.is_save++; + ServerStats->is_save++; save_user(&me, &me, target_p); } else { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_one_numeric(target_p, ERR_NICKCOLLISION, form_str(ERR_NICKCOLLISION), target_p->name); @@ -1047,7 +1047,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, if (use_save) { - ServerStats.is_save += 2; + ServerStats->is_save += 2; save_user(&me, &me, target_p); sendto_one(client_p, ":%s SAVE %s %ld", me.id, source_p->id, (long)newts); @@ -1057,13 +1057,13 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, } else { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_one_numeric(target_p, ERR_NICKCOLLISION, form_str(ERR_NICKCOLLISION), target_p->name); kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); @@ -1095,7 +1095,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, if (use_save) { - ServerStats.is_save++; + ServerStats->is_save++; /* can't broadcast a SAVE because the * nickchange has happened at client_p * but not in other directions -- jilles */ @@ -1107,7 +1107,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, } else { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_one_numeric(target_p, ERR_NICKCOLLISION, form_str(ERR_NICKCOLLISION), target_p->name); @@ -1140,7 +1140,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, if (use_save) { - ServerStats.is_save++; + ServerStats->is_save++; save_user(&me, &me, target_p); } else @@ -1151,7 +1151,7 @@ perform_nickchange_collides(struct Client *source_p, struct Client *client_p, /* kill the client who existed before hand */ kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; target_p->flags |= FLAGS_KILLED; (void) exit_client(client_p, target_p, &me, "Nick collision"); @@ -1339,7 +1339,7 @@ save_user(struct Client *client_p, struct Client *source_p, "Killed %s!%s@%s for nick collision detected by %s (%s does not support SAVE)", target_p->name, target_p->username, target_p->host, source_p->name, target_p->from->name); kill_client_serv_butone(NULL, target_p, "%s (Nick collision (no SAVE support))", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; target_p->flags |= FLAGS_KILLED; (void) exit_client(NULL, target_p, &me, "Nick collision (no SAVE support)"); diff --git a/modules/m_dline.c b/modules/m_dline.c index 317bb244..1cf22a07 100644 --- a/modules/m_dline.c +++ b/modules/m_dline.c @@ -43,7 +43,6 @@ #include "msg.h" #include "parse.h" #include "modules.h" -#include "reject.h" static int mo_dline(struct Client *, struct Client *, int, const char **); static int mo_undline(struct Client *, struct Client *, int, const char **); @@ -77,6 +76,7 @@ mo_dline(struct Client *client_p, struct Client *source_p, const char *dlhost; char *oper_reason; char *reason = def; + struct irc_sockaddr_storage daddr; char cidr_form_host[HOSTLEN + 1]; struct ConfItem *aconf; int bits; @@ -149,37 +149,36 @@ mo_dline(struct Client *client_p, struct Client *source_p, } } - if(ConfigFileEntry.non_redundant_klines) - { - struct rb_sockaddr_storage daddr; - const char *creason; - int t = AF_INET, ty, b; - ty = parse_netmask(dlhost, (struct sockaddr *)&daddr, &b); -#ifdef IPV6 - if(ty == HM_IPV6) - t = AF_INET6; - else -#endif - t = AF_INET; - - if((aconf = find_dline((struct sockaddr *)&daddr)) != NULL) - { - int bx; - parse_netmask(aconf->host, NULL, &bx); - if(b >= bx) - { - creason = aconf->passwd ? aconf->passwd : ""; - if(IsConfExemptKline(aconf)) - sendto_one_notice(source_p, - ":[%s] is (E)d-lined by [%s] - %s", - dlhost, aconf->host, creason); - else - sendto_one_notice(source_p, - ":[%s] already D-lined by [%s] - %s", - dlhost, aconf->host, creason); - return 0; - } - } + if(ConfigFileEntry.non_redundant_klines) + { + const char *creason; + int t = AF_INET, ty, b; + ty = parse_netmask(dlhost, (struct sockaddr *)&daddr, &b); +#ifdef IPV6 + if(ty == HM_IPV6) + t = AF_INET6; + else +#endif + t = AF_INET; + + if((aconf = find_dline((struct sockaddr *)&daddr, t)) != NULL) + { + int bx; + parse_netmask(aconf->host, NULL, &bx); + if(b >= bx) + { + creason = aconf->passwd ? aconf->passwd : ""; + if(IsConfExemptKline(aconf)) + sendto_one(source_p, + ":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s", + me.name, parv[0], dlhost, aconf->host, creason); + else + sendto_one(source_p, + ":%s NOTICE %s :[%s] already D-lined by [%s] - %s", + me.name, parv[0], dlhost, aconf->host, creason); + return 0; + } + } } set_time(); diff --git a/modules/m_gline.c b/modules/m_gline.c index 9add8545..5e8db9d5 100644 --- a/modules/m_gline.c +++ b/modules/m_gline.c @@ -684,46 +684,47 @@ majority_gline(struct Client *source_p, const char *user, return NO; } -/* remove_temp_gline() - * - * inputs - username, hostname to ungline - * outputs - - * side effects - tries to ungline anything that matches - */ -static int -remove_temp_gline(const char *user, const char *host) -{ - struct ConfItem *aconf; - rb_dlink_node *ptr; - struct rb_sockaddr_storage addr, caddr; - int bits, cbits; - int mtype, gtype; - - mtype = parse_netmask(host, (struct sockaddr *)&addr, &bits); - - RB_DLINK_FOREACH(ptr, glines.head) - { - aconf = ptr->data; - - gtype = parse_netmask(aconf->host, (struct sockaddr *)&caddr, &cbits); - - if(gtype != mtype || (user && irccmp(user, aconf->user))) - continue; - - if(gtype == HM_HOST) - { - if(irccmp(aconf->host, host)) - continue; - } - else if(bits != cbits || - !comp_with_mask_sock((struct sockaddr *)&addr, - (struct sockaddr *)&caddr, bits)) - continue; - - rb_dlinkDestroy(ptr, &glines); - delete_one_address_conf(aconf->host, aconf); - return YES; - } - - return NO; +/* remove_temp_gline() + * + * inputs - username, hostname to ungline + * outputs - + * side effects - tries to ungline anything that matches + */ +static int +remove_temp_gline(const char *user, const char *host) +{ + struct ConfItem *aconf; + rb_dlink_node *ptr; + struct irc_sockaddr_storage addr, caddr; + int bits, cbits; + int mtype, gtype; + + mtype = parse_netmask(host, (struct sockaddr *)&addr, &bits); + + RB_DLINK_FOREACH(ptr, glines.head) + { + aconf = ptr->data; + + gtype = parse_netmask(aconf->host, (struct sockaddr *)&caddr, &cbits); + + if(gtype != mtype || (user && irccmp(user, aconf->user))) + continue; + + if(gtype == HM_HOST) + { + if(irccmp(aconf->host, host)) + continue; + } + else if(bits != cbits || + !comp_with_mask_sock((struct sockaddr *)&addr, + (struct sockaddr *)&caddr, bits)) + continue; + + rb_dlinkDestroy(ptr, &glines); + remove_reject_mask(aconf->user, aconf->host); + delete_one_address_conf(aconf->host, aconf); + return YES; + } + + return NO; } diff --git a/modules/m_kline.c b/modules/m_kline.c index 781538e2..faa6ad79 100644 --- a/modules/m_kline.c +++ b/modules/m_kline.c @@ -691,7 +691,7 @@ static int already_placed_kline(struct Client *source_p, const char *luser, const char *lhost, int tkline) { const char *reason, *p; - struct rb_sockaddr_storage iphost, *piphost; + struct irc_sockaddr_storage iphost, *piphost; struct ConfItem *aconf; int t, bits; @@ -859,7 +859,7 @@ remove_permkline_match(struct Client *source_p, struct ConfItem *aconf) ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), user, host); - /* remove_reject_mask(aconf->user, aconf->host); XXX <- gonna go on bandb */ + remove_reject_mask(aconf->user, aconf->host); delete_one_address_conf(aconf->host, aconf); return; @@ -929,7 +929,7 @@ remove_temp_kline(struct Client *source_p, struct ConfItem *aconf) get_oper_name(source_p), aconf->user, aconf->host); rb_dlinkDestroy(ptr, &temp_klines[i]); - /* remove_reject_mask(aconf->user, aconf->host); XXX */ + remove_reject_mask(aconf->user, aconf->host); delete_one_address_conf(aconf->host, aconf); return YES; } diff --git a/modules/m_pass.c b/modules/m_pass.c index 6ef11a8e..3f178e49 100644 --- a/modules/m_pass.c +++ b/modules/m_pass.c @@ -67,7 +67,7 @@ mr_pass(struct Client *client_p, struct Client *source_p, int parc, const char * rb_free(client_p->localClient->passwd); } - client_p->localClient->passwd = rb_strndup(parv[1], PASSWDLEN); + DupNString(client_p->localClient->passwd, parv[1], PASSWDLEN); /* These are for servers only */ if(parc > 2 && client_p->user == NULL) diff --git a/modules/m_sasl.c b/modules/m_sasl.c index d5f87140..451cb446 100644 --- a/modules/m_sasl.c +++ b/modules/m_sasl.c @@ -161,7 +161,7 @@ me_sasl(struct Client *client_p, struct Client *source_p, else if(*parv[4] == 'S') { sendto_one(target_p, form_str(RPL_SASLSUCCESS), me.name, EmptyString(target_p->name) ? "*" : target_p->name); target_p->preClient->sasl_complete = 1; - ServerStats.is_ssuc++; + ServerStats->is_ssuc++; } *target_p->preClient->sasl_agent = '\0'; /* Blank the stored agent so someone else can answer */ } @@ -179,7 +179,7 @@ abort_sasl(struct Client *data) return; data->preClient->sasl_out = data->preClient->sasl_complete = 0; - ServerStats.is_sbad++; + ServerStats->is_sbad++; if(!IsClosing(data)) sendto_one(data, form_str(ERR_SASLABORTED), me.name, EmptyString(data->name) ? "*" : data->name); diff --git a/modules/m_signon.c b/modules/m_signon.c index 4d242daf..5e56f240 100644 --- a/modules/m_signon.c +++ b/modules/m_signon.c @@ -276,7 +276,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, if(!clean_nick(parv[1])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad Nick from SIGNON: %s From: %s(via %s)", parv[1], source_p->servptr->name, client_p->name); @@ -294,7 +294,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, if(!clean_username(parv[2]) || !clean_host(parv[3])) { - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_realops_snomask(SNO_DEBUG, L_ALL, "Bad user@host from SIGNON: %s@%s From: %s(via %s)", parv[2], parv[3], source_p->servptr->name, client_p->name); @@ -338,13 +338,13 @@ ms_signon(struct Client *client_p, struct Client *source_p, source_p->name, target_p->name, target_p->from->name, client_p->name); - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_one_numeric(target_p, ERR_NICKCOLLISION, form_str(ERR_NICKCOLLISION), target_p->name); kill_client_serv_butone(NULL, source_p, "%s (Nick change collision)", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; kill_client_serv_butone(NULL, target_p, "%s (Nick change collision)", me.name); @@ -373,7 +373,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, source_p->name, target_p->name, target_p->from->name, client_p->name); - ServerStats.is_kill++; + ServerStats->is_kill++; sendto_one_numeric(target_p, ERR_NICKCOLLISION, form_str(ERR_NICKCOLLISION), target_p->name); @@ -410,7 +410,7 @@ ms_signon(struct Client *client_p, struct Client *source_p, kill_client_serv_butone(client_p, target_p, "%s (Nick collision)", me.name); - ServerStats.is_kill++; + ServerStats->is_kill++; target_p->flags |= FLAGS_KILLED; (void) exit_client(client_p, target_p, &me, "Nick collision"); diff --git a/modules/m_stats.c b/modules/m_stats.c index d3b8690f..f264e35f 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -47,7 +47,6 @@ #include "hook.h" #include "s_newconf.h" #include "hash.h" -#include "reject.h" static int m_stats (struct Client *, struct Client *, int, const char **); @@ -925,73 +924,10 @@ stats_usage (struct Client *source_p) (int) rus.ru_nivcsw); } -static void -stats_tstats(struct Client *source_p) -{ - struct Client *target_p; - struct ServerStatistics sp; - rb_dlink_node *ptr; - - memcpy(&sp, &ServerStats, sizeof(struct ServerStatistics)); - - RB_DLINK_FOREACH(ptr, serv_list.head) - { - target_p = ptr->data; - - sp.is_sbs += target_p->localClient->sendB; - sp.is_sbr += target_p->localClient->receiveB; - sp.is_sti += rb_current_time() - target_p->localClient->firsttime; - sp.is_sv++; - } - - RB_DLINK_FOREACH(ptr, lclient_list.head) - { - target_p = ptr->data; - - sp.is_cbs += target_p->localClient->sendB; - sp.is_cbr += target_p->localClient->receiveB; - sp.is_cti += rb_current_time() - target_p->localClient->firsttime; - sp.is_cl++; - } - - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :accepts %u refused %u", - sp.is_ac, sp.is_ref); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :rejected %u delaying %lu", - sp.is_rej, delay_exit_length()); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :nicks being delayed %lu", get_nd_count()); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :unknown commands %u prefixes %u", - sp.is_unco, sp.is_unpf); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :nick collisions %u saves %u unknown closes %u", - sp.is_kill, sp.is_save, sp.is_ni); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :wrong direction %u empty %u", - sp.is_wrdi, sp.is_empt); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :numerics seen %u", - sp.is_num); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :auth successes %u fails %u", - sp.is_asuc, sp.is_abad); - sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server"); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :connected %u %u", - sp.is_cl, sp.is_sv); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :bytes sent %lluK %lluK", - sp.is_cbs / 1024, - sp.is_sbs / 1024); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :bytes recv %lluK %lluK", - sp.is_cbr / 1024, - sp.is_sbr / 1024); - sendto_one_numeric(source_p, RPL_STATSDEBUG, - "T :time connected %lu %lu", - (long) sp.is_cti, (long) sp.is_sti); +static void +stats_tstats (struct Client *source_p) +{ + tstats (source_p); } static void diff --git a/modules/m_testline.c b/modules/m_testline.c index d6448aa4..53e698b3 100644 --- a/modules/m_testline.c +++ b/modules/m_testline.c @@ -40,7 +40,6 @@ #include "s_conf.h" #include "s_newconf.h" #include "sprintf_irc.h" -#include "reject.h" static int mo_testline(struct Client *, struct Client *, int, const char **); static int mo_testgecos(struct Client *, struct Client *, int, const char **); @@ -62,7 +61,7 @@ mo_testline(struct Client *client_p, struct Client *source_p, int parc, const ch { struct ConfItem *aconf; struct ConfItem *resv_p; - struct rb_sockaddr_storage ip; + struct irc_sockaddr_storage ip; char user_trunc[USERLEN + 1], notildeuser_trunc[USERLEN + 1]; const char *name = NULL; const char *username = NULL; @@ -120,12 +119,12 @@ mo_testline(struct Client *client_p, struct Client *source_p, int parc, const ch /* parses as an IP, check for a dline */ if((type = parse_netmask(host, (struct sockaddr *)&ip, &host_mask)) != HM_HOST) { -#ifdef IPV6 - if(type == HM_IPV6) - aconf = find_dline((struct sockaddr *)&ip); - else -#endif - aconf = find_dline((struct sockaddr *)&ip); +#ifdef IPV6 + if(type == HM_IPV6) + aconf = find_dline((struct sockaddr *)&ip, AF_INET6); + else +#endif + aconf = find_dline((struct sockaddr *)&ip, AF_INET); if(aconf && aconf->status & CONF_DLINE) { diff --git a/modules/m_unreject.c b/modules/m_unreject.c index 094e10d8..21e136a3 100644 --- a/modules/m_unreject.c +++ b/modules/m_unreject.c @@ -42,28 +42,30 @@ struct Message unreject_msgtab = { mapi_clist_av1 unreject_clist[] = { &unreject_msgtab, NULL }; DECLARE_MODULE_AV1(unreject, NULL, NULL, unreject_clist, NULL, NULL, "$Revision: 3161 $"); -/* - * mo_unreject - * - */ -static int -mo_unreject(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) -{ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - { - sendto_one_notice(source_p, ":Reject cache is disabled"); - return 0; - } - - if(!parse_netmask(parv[1], NULL, NULL)) - { - sendto_one_notice(source_p, ":Unable to parse netmask %s", parv[1]); - return 0; - } - - if(remove_reject(parv[1])) - sendto_one_notice(source_p, ":Removed reject for %s", parv[1]); - else - sendto_one_notice(source_p, ":Unable to remove reject for %s", parv[1]); - return 0; +/* + * mo_unreject + * + */ +static int +mo_unreject(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) +{ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0 || + ConfigFileEntry.reject_duration == 0) + { + sendto_one_notice(source_p, ":Reject cache is disabled"); + return 0; + } + + if(!parse_netmask(parv[1], NULL, NULL)) + { + sendto_one_notice(source_p, ":Unable to parse netmask %s", parv[1]); + return 0; + } + + if(remove_reject_ip(parv[1])) + sendto_one_notice(source_p, ":Removed reject for %s", parv[1]); + else + sendto_one_notice(source_p, ":Unable to remove reject for %s", parv[1]); + + return 0; } diff --git a/servlink/.cvsignore b/servlink/.cvsignore new file mode 100644 index 00000000..224f7c65 --- /dev/null +++ b/servlink/.cvsignore @@ -0,0 +1,3 @@ +Makefile +setup.h +servlink diff --git a/servlink/.indent.pro b/servlink/.indent.pro new file mode 100644 index 00000000..a4981660 --- /dev/null +++ b/servlink/.indent.pro @@ -0,0 +1 @@ +-i8 -bli0 -ut -nsai -l100 -npcs \ No newline at end of file diff --git a/servlink/Makefile.in b/servlink/Makefile.in new file mode 100644 index 00000000..a0470123 --- /dev/null +++ b/servlink/Makefile.in @@ -0,0 +1,82 @@ +# +# Makefile.in for servlink/src +# +# $Id: Makefile.in 1285 2006-05-05 15:03:53Z nenolod $ +# + +CC = @CC@ +INSTALL = @INSTALL@ +INSTALL_BIN = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SUID = @INSTALL_PROGRAM@ -o root -m 4755 +RM = @RM@ +LEX = @LEX@ +LEXLIB = @LEXLIB@ +CFLAGS = @IRC_CFLAGS@ -DIRCD_PREFIX=\"@prefix@\" +LDFLAGS = @LDFLAGS@ +MKDEP = @MKDEP@ -DIRCD_PREFIX=\"@prefix@\" +MV = @MV@ +RM = @RM@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +libexecdir = @libexecdir@ +confdir = @confdir@ +localstatedir = @localstatedir@ + +ZIP_LIB = @ZLIB_LD@ + +IRCDLIBS = @LIBS@ $(ZIP_LIB) + +INCLUDES = -I. -I../include $(SSL_INCLUDES) +CPPFLAGS = ${INCLUDES} @CPPFLAGS@ + +PROGS = servlink + +SOURCES = \ + servlink.c \ + io.c \ + control.c + + +OBJECTS = ${SOURCES:.c=.o} + +all: servlink + +build: all + +servlink: ${OBJECTS} + ${CC} ${CFLAGS} ${LDFLAGS} -o $@ ${OBJECTS} ${IRCDLIBS} + +install: build + @echo "ircd: installing servlink ($(PROGS))" + @for i in $(PROGS); do \ + if test -f $(DESTDIR)$(bindir)/$$i; then \ + $(MV) $(DESTDIR)$(bindir)/$$i $(DESTDIR)$(bindir)/$$i.old; \ + fi; \ + $(INSTALL_BIN) $$i $(DESTDIR)$(bindir); \ + done + +.c.o: + ${CC} ${CPPFLAGS} ${CFLAGS} -c $< + +.PHONY: depend clean distclean +depend: + @${MKDEP} ${CPPFLAGS} ${SOURCES} > .depend.tmp + @sed -e '/^# DO NOT DELETE THIS LINE/,$$d' Makefile.depend + @echo '# DO NOT DELETE THIS LINE!!!' >>Makefile.depend + @echo '# make depend needs it.' >>Makefile.depend + @cat .depend.tmp >>Makefile.depend + @mv Makefile.depend Makefile + @rm -f .depend.tmp + +clean: + ${RM} -f *.o *~ *.core core servlink + +lint: + lint -aacgprxhH $(CPPFLAGS) -DIRCD_PREFIX=\"@prefix@\" $(SOURCES) >>../lint.out + +distclean: clean + ${RM} -f Makefile + +# End of Makefile diff --git a/servlink/README b/servlink/README new file mode 100644 index 00000000..2ccfcd67 --- /dev/null +++ b/servlink/README @@ -0,0 +1,71 @@ +Servlink protocol documentation. +$Id: README 1285 2006-05-05 15:03:53Z nenolod $ +-------------- + +After negotiating an incoming/outgoing server connection, the ircd will +fork, then execve servlink, with fd 0 as one end of a control pipe and +fd 1 as one end of a data pipe. fd 2 will be the socket connected to +the remote server. + +The data pipe is used by the ircd to send/receive normal, decrypted, +uncompressed IRC commands to/from the remote server. The socket is used to +send the (processed) data to the remote server, and receive the data from +the remote server. + +The control pipe is used to activate encryption/compression and to set the +encryption key/algorithm to be used. + +Format of control messages: + + + +data format: + + +Commands: + +001 - SET_ZIP_OUT_LEVEL + data: yes + description: + set compression level (0 [use default, 6], or 1-9) + +002 - START_ZIP_OUT + data: no + description: + all data written to the data pipe will be compressed + prior to being sent to the remote server. + +003 - START_ZIP_IN + data: no + description: + all data not yet read from the slink program will be + decompressed before reading + +004 - INJECT_RECVQ + data: recvq + + Used before INIT to inject any data read from the server fd which + should be pre-processed by servlink before being sent back + to the LOCAL_FD through the data fd. + +005 - INJECT_SENDQ + data: sendq + + As above, but sent to remote server without processing. + +006 - INIT + +007 - ZIPSTATS + request to send ziplinks statistics reply. + +replies + +001 - ERROR + data: u32 len/char error[len] + + fatal error message. + +002 - ZIPSTATS + data: u32 in/u32 in_wire/u32 out/u32 out_wire + + ziplinks commpression statistics diff --git a/servlink/TODO b/servlink/TODO new file mode 100644 index 00000000..6fcefa16 --- /dev/null +++ b/servlink/TODO @@ -0,0 +1,7 @@ +Servlink todo list +$Id: TODO 6 2005-09-10 01:02:21Z nenolod $ +------------------ + +Fix any bugs that come up + +Think of improvements :) diff --git a/servlink/control.c b/servlink/control.c new file mode 100644 index 00000000..1f341a78 --- /dev/null +++ b/servlink/control.c @@ -0,0 +1,129 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/servlink.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: control.c 1285 2006-05-05 15:03:53Z nenolod $ + */ + +#include "setup.h" + +#include + +#include +#include +#include +#include +#ifdef HAVE_LIBZ +#include +#endif + +#include "servlink.h" +#include "io.h" +#include "control.h" + +static cmd_handler cmd_set_zip_out_level; +static cmd_handler cmd_start_zip_out; +static cmd_handler cmd_start_zip_in; +static cmd_handler cmd_init; + +struct command_def command_table[] = { + {CMD_SET_ZIP_OUT_LEVEL, cmd_set_zip_out_level, COMMAND_FLAG_DATA}, + {CMD_START_ZIP_OUT, cmd_start_zip_out, 0}, + {CMD_START_ZIP_IN, cmd_start_zip_in, 0}, + {CMD_INJECT_RECVQ, process_recvq, COMMAND_FLAG_DATA}, + {CMD_INJECT_SENDQ, process_sendq, COMMAND_FLAG_DATA}, + {CMD_INIT, cmd_init, 0}, + {CMD_ZIPSTATS, send_zipstats, 0}, + {0, 0, 0} +}; + +void +cmd_set_zip_out_level(struct ctrl_command *cmd) +{ +#ifdef HAVE_LIBZ + out_state.zip_state.level = *cmd->data; + if((out_state.zip_state.level < -1) || (out_state.zip_state.level > 9)) + send_error("invalid compression level %d", out_state.zip_state.level); +#else + send_error("can't set compression level - no libz support!"); +#endif +} + +void +cmd_start_zip_out(struct ctrl_command *cmd) +{ +#ifdef HAVE_LIBZ + int ret; + + if(out_state.zip) + send_error("can't start compression - already started!"); + + out_state.zip_state.z_stream.total_in = 0; + out_state.zip_state.z_stream.total_out = 0; + out_state.zip_state.z_stream.zalloc = (alloc_func) 0; + out_state.zip_state.z_stream.zfree = (free_func) 0; + out_state.zip_state.z_stream.data_type = Z_ASCII; + + if(out_state.zip_state.level <= 0) + out_state.zip_state.level = Z_DEFAULT_COMPRESSION; + + if((ret = deflateInit(&out_state.zip_state.z_stream, out_state.zip_state.level)) != Z_OK) + send_error("deflateInit failed: %s", zError(ret)); + + out_state.zip = 1; +#else + send_error("can't start compression - no libz support!"); +#endif +} + +void +cmd_start_zip_in(struct ctrl_command *cmd) +{ +#ifdef HAVE_LIBZ + int ret; + + if(in_state.zip) + send_error("can't start decompression - already started!"); + + in_state.zip_state.z_stream.total_in = 0; + in_state.zip_state.z_stream.total_out = 0; + in_state.zip_state.z_stream.zalloc = (alloc_func) 0; + in_state.zip_state.z_stream.zfree = (free_func) 0; + in_state.zip_state.z_stream.data_type = Z_ASCII; + if((ret = inflateInit(&in_state.zip_state.z_stream)) != Z_OK) + send_error("inflateInit failed: %s", zError(ret)); + in_state.zip = 1; +#else + send_error("can't start decompression - no libz support!"); +#endif +} + + +void +cmd_init(struct ctrl_command *cmd) +{ + if(in_state.active || out_state.active) + send_error("CMD_INIT sent twice!"); + + in_state.active = 1; + out_state.active = 1; + CONTROL.read_cb = read_ctrl; + CONTROL.write_cb = NULL; + LOCAL.read_cb = read_data; + LOCAL.write_cb = NULL; + REMOTE.read_cb = read_net; + REMOTE.write_cb = NULL; +} diff --git a/servlink/control.h b/servlink/control.h new file mode 100644 index 00000000..294eeb93 --- /dev/null +++ b/servlink/control.h @@ -0,0 +1,57 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/control.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: control.h 1285 2006-05-05 15:03:53Z nenolod $ + */ + +#ifndef INCLUDED_servlink_control_h +#define INCLUDED_servlink_control_h + +#define CMD_SET_ZIP_OUT_LEVEL 1 /* data */ +#define CMD_START_ZIP_OUT 2 +#define CMD_START_ZIP_IN 3 +#define CMD_INJECT_RECVQ 4 /* data */ +#define CMD_INJECT_SENDQ 5 /* data */ +#define CMD_INIT 6 +#define CMD_ZIPSTATS 7 + +#define RPL_ERROR 1 /* data */ +#define RPL_ZIPSTATS 2 /* data */ + +/* flags */ +#define COMMAND_FLAG_DATA 0x0001 /* command has data + following */ +struct ctrl_command +{ + int command; + int datalen; + int gotdatalen; + int readdata; + unsigned char *data; +}; + +typedef void cmd_handler(struct ctrl_command *); + +struct command_def +{ + unsigned int commandid; + cmd_handler *handler; + unsigned int flags; +}; + +extern struct command_def command_table[]; +#endif /* INCLUDED_servlink_control_h */ diff --git a/servlink/io.c b/servlink/io.c new file mode 100644 index 00000000..f4f91f2e --- /dev/null +++ b/servlink/io.c @@ -0,0 +1,657 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/io.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: io.c 3319 2007-03-29 20:03:06Z jilles $ + */ + +#include "setup.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBZ +#include +#endif + +#include "servlink.h" +#include "io.h" +#include "control.h" + +static int check_error(int, int, int); + +static const char * +fd_name(int fd) +{ + if(fd == CONTROL.fd) + return "control"; + if(fd == LOCAL.fd) + return "data"; + if(fd == REMOTE.fd) + return "network"; + + /* uh oh... */ + return "unknown"; +} + +#if defined( HAVE_LIBZ ) +static unsigned char tmp_buf[BUFLEN]; +static unsigned char tmp2_buf[BUFLEN]; +#endif + +static unsigned char ctrl_buf[256] = ""; +static unsigned int ctrl_len = 0; +static unsigned int ctrl_ofs = 0; + +void +io_loop(int nfds) +{ + fd_set rfds; + fd_set wfds; + int i, ret; + + /* loop forever */ + for (;;) + { + FD_ZERO(&rfds); + FD_ZERO(&wfds); + + for (i = 0; i < 3; i++) + { + if(fds[i].read_cb) + FD_SET(fds[i].fd, &rfds); + if(fds[i].write_cb) + FD_SET(fds[i].fd, &wfds); + } + + /* we have <3 fds ever, so I don't think select is too painful */ + ret = select(nfds, &rfds, &wfds, NULL, NULL); + + if(ret < 0) + { + check_error(ret, IO_SELECT, -1); /* exit on fatal errors */ + } + else if(ret > 0) + { + /* call any callbacks */ + for (i = 2; i >= 0; i--) + { + if(FD_ISSET(fds[i].fd, &rfds) && fds[i].read_cb) + (*fds[i].read_cb) (); + if(FD_ISSET(fds[i].fd, &wfds) && fds[i].write_cb) + (*fds[i].write_cb) (); + } + } + } +} + +void +send_data_blocking(int fd, unsigned char *data, int datalen) +{ + int ret; + fd_set wfds; + + while (1) + { + ret = write(fd, data, datalen); + + if(ret == datalen) + return; + else if(ret > 0) + { + data += ret; + datalen -= ret; + } + + ret = check_error(ret, IO_WRITE, fd); + + FD_ZERO(&wfds); + FD_SET(fd, &wfds); + + /* sleep until we can write to the fd */ + while (1) + { + ret = select(fd + 1, NULL, &wfds, NULL, NULL); + + if(ret > 0) /* break out so we can write */ + break; + + if(ret < 0) /* error ? */ + check_error(ret, IO_SELECT, fd); /* exit on fatal errors */ + + /* loop on non-fatal errors */ + } + } +} + +/* + * process_sendq: + * + * used before CMD_INIT to pass contents of SendQ from ircd + * to servlink. This data must _not_ be encrypted/compressed. + */ +void +process_sendq(struct ctrl_command *cmd) +{ + send_data_blocking(REMOTE.fd, cmd->data, cmd->datalen); +} + +/* + * process_recvq: + * + * used before CMD_INIT to pass contents of RecvQ from ircd + * to servlink. This data must be decrypted/decopmressed before + * sending back to the ircd. + */ +void +process_recvq(struct ctrl_command *cmd) +{ + int ret; + unsigned char *buf; + int blen; + unsigned char *data = cmd->data; + unsigned int datalen = cmd->datalen; + + buf = data; + blen = datalen; + ret = -1; + if(datalen > READLEN) + send_error("Error processing INJECT_RECVQ - buffer too long (%d > %d)", + datalen, READLEN); + +#ifdef HAVE_LIBZ + if(in_state.zip) + { + /* decompress data */ + in_state.zip_state.z_stream.next_in = buf; + in_state.zip_state.z_stream.avail_in = blen; + in_state.zip_state.z_stream.next_out = tmp2_buf; + in_state.zip_state.z_stream.avail_out = BUFLEN; + + buf = tmp2_buf; + while (in_state.zip_state.z_stream.avail_in) + { + if((ret = inflate(&in_state.zip_state.z_stream, Z_NO_FLUSH)) != Z_OK) + { + if(!strncmp("ERROR ", (char *)in_state.zip_state.z_stream.next_in, 6)) + send_error("Received uncompressed ERROR"); + else + send_error("Inflate failed: %s", zError(ret)); + } + blen = BUFLEN - in_state.zip_state.z_stream.avail_out; + + if(in_state.zip_state.z_stream.avail_in) + { + send_data_blocking(LOCAL.fd, buf, blen); + blen = 0; + in_state.zip_state.z_stream.next_out = buf; + in_state.zip_state.z_stream.avail_out = BUFLEN; + } + } + + if(!blen) + return; + } +#endif + + send_data_blocking(LOCAL.fd, buf, blen); +} + +void +send_zipstats(struct ctrl_command *unused) +{ +#ifdef HAVE_LIBZ + int i = 0; + int ret; + u_int32_t len; + if(!in_state.active || !out_state.active) + send_error("Error processing CMD_ZIPSTATS - link is not active!"); + if(!in_state.zip || !out_state.zip) + send_error("Error processing CMD_ZIPSTATS - link is not compressed!"); + + ctrl_buf[i++] = RPL_ZIPSTATS; + ctrl_buf[i++] = 0; + ctrl_buf[i++] = 16; + + len = (u_int32_t) in_state.zip_state.z_stream.total_out; + ctrl_buf[i++] = ((len >> 24) & 0xFF); + ctrl_buf[i++] = ((len >> 16) & 0xFF); + ctrl_buf[i++] = ((len >> 8) & 0xFF); + ctrl_buf[i++] = ((len) & 0xFF); + + len = (u_int32_t) in_state.zip_state.z_stream.total_in; + ctrl_buf[i++] = ((len >> 24) & 0xFF); + ctrl_buf[i++] = ((len >> 16) & 0xFF); + ctrl_buf[i++] = ((len >> 8) & 0xFF); + ctrl_buf[i++] = ((len) & 0xFF); + + len = (u_int32_t) out_state.zip_state.z_stream.total_in; + ctrl_buf[i++] = ((len >> 24) & 0xFF); + ctrl_buf[i++] = ((len >> 16) & 0xFF); + ctrl_buf[i++] = ((len >> 8) & 0xFF); + ctrl_buf[i++] = ((len) & 0xFF); + + len = (u_int32_t) out_state.zip_state.z_stream.total_out; + ctrl_buf[i++] = ((len >> 24) & 0xFF); + ctrl_buf[i++] = ((len >> 16) & 0xFF); + ctrl_buf[i++] = ((len >> 8) & 0xFF); + ctrl_buf[i++] = ((len) & 0xFF); + + in_state.zip_state.z_stream.total_in = 0; + in_state.zip_state.z_stream.total_out = 0; + out_state.zip_state.z_stream.total_in = 0; + out_state.zip_state.z_stream.total_out = 0; + + ret = check_error(write(CONTROL.fd, ctrl_buf, i), IO_WRITE, CONTROL.fd); + if(ret < i) + { + /* write incomplete, register write cb */ + CONTROL.write_cb = write_ctrl; + /* deregister read_cb */ + CONTROL.read_cb = NULL; + ctrl_ofs = ret; + ctrl_len = i - ret; + return; + } +#else + send_error("can't send_zipstats -- no zlib support!"); +#endif +} + +/* send_error + * - we ran into some problem, make a last ditch effort to + * flush the control fd sendq, then (blocking) send an + * error message over the control fd. + */ +void +send_error(const char *message, ...) +{ + va_list args; + static int sending_error = 0; + struct linger linger_opt = { 1, 30 }; /* wait 30 seconds */ + int len; + + if(sending_error) + exit(1); /* we did _try_ */ + + sending_error = 1; + + if(ctrl_len) /* attempt to flush any data we have... */ + { + send_data_blocking(CONTROL.fd, (ctrl_buf + ctrl_ofs), ctrl_len); + } + + /* prepare the message, in in_buf, since we won't be using it again.. */ + in_state.buf[0] = RPL_ERROR; + in_state.buf[1] = 0; + in_state.buf[2] = 0; + + va_start(args, message); + len = vsprintf((char *) in_state.buf + 3, message, args); + va_end(args); + + in_state.buf[3 + len++] = '\0'; + in_state.buf[1] = len >> 8; + in_state.buf[2] = len & 0xFF; + len += 3; + + send_data_blocking(CONTROL.fd, in_state.buf, len); + + /* XXX - is this portable? + * this obviously will fail on a non socket.. */ + setsockopt(CONTROL.fd, SOL_SOCKET, SO_LINGER, &linger_opt, sizeof(struct linger)); + + /* well, we've tried... */ + exit(1); /* now abort */ +} + +/* read_ctrl + * called when a command is waiting on the control pipe + */ +void +read_ctrl(void) +{ + int ret; + unsigned char tmp[2]; + unsigned char *len; + struct command_def *cdef; + static struct ctrl_command cmd = { 0, 0, 0, 0, NULL }; + + if(cmd.command == 0) /* we don't have a command yet */ + { + cmd.gotdatalen = 0; + cmd.datalen = 0; + cmd.readdata = 0; + cmd.data = NULL; + + /* read the command */ + if(!(ret = check_error(read(CONTROL.fd, tmp, 1), IO_READ, CONTROL.fd))) + return; + + cmd.command = tmp[0]; + } + + for (cdef = command_table; cdef->commandid; cdef++) + { + if((int)cdef->commandid == cmd.command) + break; + } + + if(!cdef->commandid) + { + send_error("Unsupported command (servlink/ircd out of sync?): %d", cmd.command); + /* NOTREACHED */ + } + + /* read datalen for commands including data */ + if(cdef->flags & COMMAND_FLAG_DATA) + { + if(cmd.gotdatalen < 2) + { + len = tmp; + if(!(ret = check_error(read(CONTROL.fd, len, + (2 - cmd.gotdatalen)), IO_READ, CONTROL.fd))) + return; + + if(cmd.gotdatalen == 0) + { + cmd.datalen = len[0] << 8; + cmd.gotdatalen++; + ret--; + len++; + } + if(ret && (cmd.gotdatalen == 1)) + { + cmd.datalen |= len[0]; + cmd.gotdatalen++; + if(cmd.datalen > 0) + cmd.data = calloc(cmd.datalen, 1); + } + } + } + + if(cmd.readdata < cmd.datalen) /* try to get any remaining data */ + { + if(!(ret = check_error(read(CONTROL.fd, + (cmd.data + cmd.readdata), + cmd.datalen - cmd.readdata), IO_READ, CONTROL.fd))) + return; + + cmd.readdata += ret; + if(cmd.readdata < cmd.datalen) + return; + } + + /* we now have the command and any data */ + (*cdef->handler) (&cmd); + + if(cmd.datalen > 0) + free(cmd.data); + cmd.command = 0; +} + +void +write_ctrl(void) +{ + int ret; + + assert(ctrl_len); + + if(!(ret = check_error(write(CONTROL.fd, (ctrl_buf + ctrl_ofs), + ctrl_len), IO_WRITE, CONTROL.fd))) + return; /* no data waiting */ + + ctrl_len -= ret; + + if(!ctrl_len) + { + /* write completed, de-register write cb */ + CONTROL.write_cb = NULL; + /* reregister read_cb */ + CONTROL.read_cb = read_ctrl; + ctrl_ofs = 0; + } + else + ctrl_ofs += ret; +} + +void +read_data(void) +{ + int ret, ret2; + unsigned char *buf = out_state.buf; + int blen; + ret2 = -1; + assert(!out_state.len); + +#if defined(HAVE_LIBZ) + if(out_state.zip || out_state.crypt) + buf = tmp_buf; +#endif + + while ((ret = check_error(read(LOCAL.fd, buf, READLEN), IO_READ, LOCAL.fd))) + { + blen = ret; +#ifdef HAVE_LIBZ + if(out_state.zip) + { + out_state.zip_state.z_stream.next_in = buf; + out_state.zip_state.z_stream.avail_in = ret; + + buf = out_state.buf; + out_state.zip_state.z_stream.next_out = buf; + out_state.zip_state.z_stream.avail_out = BUFLEN; + if(!(ret2 = deflate(&out_state.zip_state.z_stream, + Z_PARTIAL_FLUSH)) == Z_OK) + send_error("error compressing outgoing data - deflate returned: %s", + zError(ret2)); + + if(!out_state.zip_state.z_stream.avail_out) + send_error("error compressing outgoing data - avail_out == 0"); + if(out_state.zip_state.z_stream.avail_in) + send_error("error compressing outgoing data - avail_in != 0"); + + blen = BUFLEN - out_state.zip_state.z_stream.avail_out; + } +#endif + + + ret = check_error(write(REMOTE.fd, out_state.buf, blen), IO_WRITE, REMOTE.fd); + if(ret < blen) + { + /* write incomplete, register write cb */ + REMOTE.write_cb = write_net; + /* deregister read_cb */ + LOCAL.read_cb = NULL; + out_state.ofs = ret; + out_state.len = blen - ret; + return; + } +#if defined(HAVE_LIBZ) + if(out_state.zip) + buf = tmp_buf; +#endif + } + +} + +void +write_net(void) +{ + int ret; + + assert(out_state.len); + + if(!(ret = check_error(write(REMOTE.fd, + (out_state.buf + out_state.ofs), + out_state.len), IO_WRITE, REMOTE.fd))) + return; /* no data waiting */ + + out_state.len -= ret; + + if(!out_state.len) + { + /* write completed, de-register write cb */ + REMOTE.write_cb = NULL; + /* reregister read_cb */ + LOCAL.read_cb = read_data; + out_state.ofs = 0; + } + else + out_state.ofs += ret; +} + +void +read_net(void) +{ + int ret; + int ret2; + unsigned char *buf = in_state.buf; + int blen; + ret2 = -1; + assert(!in_state.len); + +#if defined(HAVE_LIBZ) + if(in_state.zip) + buf = tmp_buf; +#endif + + while ((ret = check_error(read(REMOTE.fd, buf, READLEN), IO_READ, REMOTE.fd))) + { + blen = ret; +#ifdef HAVE_LIBZ + if(in_state.zip) + { + /* decompress data */ + in_state.zip_state.z_stream.next_in = buf; + in_state.zip_state.z_stream.avail_in = ret; + in_state.zip_state.z_stream.next_out = in_state.buf; + in_state.zip_state.z_stream.avail_out = BUFLEN; + + while (in_state.zip_state.z_stream.avail_in) + { + if((ret2 = inflate(&in_state.zip_state.z_stream, + Z_NO_FLUSH)) != Z_OK) + { + if(!strncmp("ERROR ", (char *)buf, 6)) + send_error("Received uncompressed ERROR"); + send_error("Inflate failed: %s", zError(ret2)); + } + blen = BUFLEN - in_state.zip_state.z_stream.avail_out; + + if(in_state.zip_state.z_stream.avail_in) + { + if(blen) + { + send_data_blocking(LOCAL.fd, in_state.buf, blen); + blen = 0; + } + + in_state.zip_state.z_stream.next_out = in_state.buf; + in_state.zip_state.z_stream.avail_out = BUFLEN; + } + } + + if(!blen) + return; /* that didn't generate any decompressed input.. */ + } +#endif + + ret = check_error(write(LOCAL.fd, in_state.buf, blen), IO_WRITE, LOCAL.fd); + + if(ret < blen) + { + in_state.ofs = ret; + in_state.len = blen - ret; + /* write incomplete, register write cb */ + LOCAL.write_cb = write_data; + /* deregister read_cb */ + REMOTE.read_cb = NULL; + return; + } +#if defined(HAVE_LIBZ) + if(in_state.zip) + buf = tmp_buf; +#endif + } +} + +void +write_data(void) +{ + int ret; + + assert(in_state.len); + + if(!(ret = check_error(write(LOCAL.fd, + (in_state.buf + in_state.ofs), + in_state.len), IO_WRITE, LOCAL.fd))) + return; + + in_state.len -= ret; + + if(!in_state.len) + { + /* write completed, de-register write cb */ + LOCAL.write_cb = NULL; + /* reregister read_cb */ + REMOTE.read_cb = read_net; + in_state.ofs = 0; + } + else + in_state.ofs += ret; +} + +int +check_error(int ret, int io, int fd) +{ + if(ret > 0) /* no error */ + return ret; + if(ret == 0) /* EOF */ + { + send_error("%s failed on %s: EOF", IO_TYPE(io), FD_NAME(fd)); + exit(1); /* NOTREACHED */ + } + + /* ret == -1.. */ + switch (errno) + { + case EINPROGRESS: + case EWOULDBLOCK: +#if EAGAIN != EWOULDBLOCK + case EAGAIN: +#endif + case EALREADY: + case EINTR: +#ifdef ERESTART + case ERESTART: +#endif + /* non-fatal error, 0 bytes read */ + return 0; + } + + /* fatal error */ + send_error("%s failed on %s: %s", IO_TYPE(io), FD_NAME(fd), strerror(errno)); + exit(1); /* NOTREACHED */ +} diff --git a/servlink/io.h b/servlink/io.h new file mode 100644 index 00000000..da2126a3 --- /dev/null +++ b/servlink/io.h @@ -0,0 +1,48 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/io.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: io.h 6 2005-09-10 01:02:21Z nenolod $ + */ + +#ifndef INCLUDED_servlink_io_h +#define INCLUDED_servlink_io_h + +#include "control.h" + +#define IO_READ 0 +#define IO_WRITE 1 +#define IO_SELECT 2 + +#define IO_TYPE(io) ((io==IO_SELECT)?"select": \ + ((io==IO_WRITE)?"write":"read")) + +#define FD_NAME(fd) (fd_name(fd)) + +extern void io_loop(int nfds); +extern void write_data(void); +extern void read_data(void); +extern void write_ctrl(void); +extern void read_ctrl(void); +extern void write_net(void); +extern void read_net(void); +extern void send_error(const char *, ...); +extern void send_data_blocking(int fd, unsigned char *data, int datalen); +extern cmd_handler process_recvq; +extern cmd_handler process_sendq; +extern cmd_handler send_zipstats; + +#endif /* INCLUDED_servlink_io_h */ diff --git a/servlink/servlink.c b/servlink/servlink.c new file mode 100644 index 00000000..1276200c --- /dev/null +++ b/servlink/servlink.c @@ -0,0 +1,121 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/servlink.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: servlink.c 6 2005-09-10 01:02:21Z nenolod $ + */ + +#include "setup.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_LIBZ +#include +#endif + +#include "servlink.h" +#include "io.h" +#include "control.h" + +static void usage(void); + +struct slink_state in_state; +struct slink_state out_state; + +struct fd_table fds[3] = { + {0, read_ctrl, NULL}, /* ctrl */ + {0, NULL, NULL}, /* data */ + {0, NULL, NULL}, /* net */ +}; + +/* usage(); + * + * Display usage message + */ +static void +usage(void) +{ + fprintf(stderr, "ircd-ratbox server link v1.2\n"); + fprintf(stderr, "2004-03-02\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "This program is called by the ircd-ratbox ircd.\n"); + fprintf(stderr, "It cannot be used on its own.\n"); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + int max_fd = 0; + int i, x; +#ifdef SERVLINK_DEBUG + int GDBAttached = 0; + + while (!GDBAttached) + sleep(1); +#endif + + /* Make sure we are running under ircd.. */ + + if(argc != 4 || strcmp(argv[0], "-slink")) + usage(); /* exits */ + + + for (i = 0; i < 3; i++) + { + fds[i].fd = atoi(argv[i + 1]); + if(fds[i].fd < 0) + exit(1); + } + + for (i = 0; i < 3; i++) + { + /* XXX: Hack alert...we need to do dup2() here for some dumb + * platforms (Solaris) that don't like select using fds > 255 + */ + + if(fds[i].fd >= 255) + { + for(x = 0; x < 255; x++) + { + if(x != fds[0].fd && x != fds[1].fd && x != fds[2].fd) + { + if(dup2(fds[i].fd, x) < 0) + exit(1); + close(fds[i].fd); + fds[i].fd = x; + break; + } + } + } + fcntl(fds[i].fd, F_SETFL, O_NONBLOCK); + if(fds[i].fd > max_fd) + max_fd = fds[i].fd; + } + + /* enter io loop */ + io_loop(max_fd + 1); + + /* NOTREACHED */ + return (0); +} /* main() */ diff --git a/servlink/servlink.h b/servlink/servlink.h new file mode 100644 index 00000000..a0f37dea --- /dev/null +++ b/servlink/servlink.h @@ -0,0 +1,83 @@ +/************************************************************************ + * IRC - Internet Relay Chat, servlink/servlink.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id: servlink.h 1285 2006-05-05 15:03:53Z nenolod $ + */ + +#ifndef INCLUDED_servlink_servlink_h +#define INCLUDED_servlink_servlink_h + +#include "setup.h" + +#ifdef HAVE_LIBZ +#include +#endif + +/* do not use stdin/out/err, as it seems to break on solaris */ +#define CONTROL fds[0] +#define LOCAL fds[1] +#define REMOTE fds[2] + +#undef SERVLINK_DEBUG + +#define READLEN 16384 + +#ifdef HAVE_LIBZ +#define BUFLEN READLEN * 6 /* allow for decompression */ +#else +#define BUFLEN READLEN +#endif + + +#ifdef HAVE_LIBZ +struct zip_state +{ + z_stream z_stream; + int level; /* compression level */ +}; +#endif + +struct slink_state +{ + unsigned int crypt:1; + unsigned int zip:1; + unsigned int active:1; + + unsigned char buf[BUFLEN * 2]; + unsigned int ofs; + unsigned int len; + +#ifdef HAVE_LIBZ + struct zip_state zip_state; +#endif +}; + + +typedef void (io_callback) (void); + +struct fd_table +{ + int fd; + io_callback *read_cb; + io_callback *write_cb; +}; + +extern struct slink_state in_state; +extern struct slink_state out_state; +extern struct fd_table fds[3]; + +#endif /* INCLUDED_servlink_servlink_h */ diff --git a/src/class.c b/src/class.c index d630364d..3810d53c 100644 --- a/src/class.c +++ b/src/class.c @@ -44,31 +44,31 @@ rb_dlink_list class_list; struct Class *default_class; -struct Class * -make_class(void) -{ - struct Class *tmp; - - tmp = rb_malloc(sizeof(struct Class)); - - ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; - PingFreq(tmp) = DEFAULT_PINGFREQUENCY; - MaxUsers(tmp) = 1; - MaxSendq(tmp) = DEFAULT_SENDQ; - - tmp->ip_limits = rb_new_patricia(PATRICIA_BITS); - return tmp; +struct Class * +make_class(void) +{ + struct Class *tmp; + + tmp = (struct Class *) rb_malloc(sizeof(struct Class)); + + ConFreq(tmp) = DEFAULT_CONNECTFREQUENCY; + PingFreq(tmp) = DEFAULT_PINGFREQUENCY; + MaxUsers(tmp) = 1; + MaxSendq(tmp) = DEFAULT_SENDQ; + + tmp->ip_limits = rb_new_patricia(PATRICIA_BITS); + return tmp; } -void -free_class(struct Class *tmp) -{ - if(tmp->ip_limits) - rb_destroy_patricia(tmp->ip_limits, NULL); - - rb_free(tmp->class_name); - rb_free(tmp); - +void +free_class(struct Class *tmp) +{ + if(tmp->ip_limits) + rb_destroy_patricia(tmp->ip_limits, NULL); + + rb_free(tmp->class_name); + rb_free(tmp); + } /* diff --git a/src/client.c b/src/client.c index d84ca3ff..ecc87224 100644 --- a/src/client.c +++ b/src/client.c @@ -456,7 +456,7 @@ check_banned_lines(void) continue; /* if there is a returned struct ConfItem then kill it */ - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip))) + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip, client_p->localClient->ip.ss_family))) { if(aconf->status & CONF_EXEMPTDLINE) continue; @@ -540,7 +540,7 @@ check_banned_lines(void) { client_p = ptr->data; - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip))) + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family))) { if(aconf->status & CONF_EXEMPTDLINE) continue; @@ -675,7 +675,7 @@ check_dlines(void) if(IsMe(client_p)) continue; - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip)) != NULL) + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) { if(aconf->status & CONF_EXEMPTDLINE) continue; @@ -694,7 +694,7 @@ check_dlines(void) { client_p = ptr->data; - if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip)) != NULL) + if((aconf = find_dline((struct sockaddr *)&client_p->localClient->ip,client_p->localClient->ip.ss_family)) != NULL) { if(aconf->status & CONF_EXEMPTDLINE) continue; @@ -1401,6 +1401,7 @@ exit_unknown_client(struct Client *client_p, struct Client *source_p, struct Cli const char *comment) { delete_auth_queries(source_p); + del_unknown_ip(source_p); rb_dlinkDelete(&source_p->localClient->tnode, &unknown_list); if(!IsIOError(source_p)) @@ -2025,21 +2026,21 @@ close_connection(struct Client *client_p) { struct server_conf *server_p; - ServerStats.is_sv++; - ServerStats.is_sbs += client_p->localClient->sendB; - ServerStats.is_sbr += client_p->localClient->receiveB; - ServerStats.is_sks += client_p->localClient->sendK; - ServerStats.is_skr += client_p->localClient->receiveK; - ServerStats.is_sti += rb_current_time() - client_p->localClient->firsttime; - if(ServerStats.is_sbs > 2047) + ServerStats->is_sv++; + ServerStats->is_sbs += client_p->localClient->sendB; + ServerStats->is_sbr += client_p->localClient->receiveB; + ServerStats->is_sks += client_p->localClient->sendK; + ServerStats->is_skr += client_p->localClient->receiveK; + ServerStats->is_sti += rb_current_time() - client_p->localClient->firsttime; + if(ServerStats->is_sbs > 2047) { - ServerStats.is_sks += (ServerStats.is_sbs >> 10); - ServerStats.is_sbs &= 0x3ff; + ServerStats->is_sks += (ServerStats->is_sbs >> 10); + ServerStats->is_sbs &= 0x3ff; } - if(ServerStats.is_sbr > 2047) + if(ServerStats->is_sbr > 2047) { - ServerStats.is_skr += (ServerStats.is_sbr >> 10); - ServerStats.is_sbr &= 0x3ff; + ServerStats->is_skr += (ServerStats->is_sbr >> 10); + ServerStats->is_sbr &= 0x3ff; } /* @@ -2063,35 +2064,40 @@ close_connection(struct Client *client_p) } else if(IsClient(client_p)) { - ServerStats.is_cl++; - ServerStats.is_cbs += client_p->localClient->sendB; - ServerStats.is_cbr += client_p->localClient->receiveB; - ServerStats.is_cks += client_p->localClient->sendK; - ServerStats.is_ckr += client_p->localClient->receiveK; - ServerStats.is_cti += rb_current_time() - client_p->localClient->firsttime; - if(ServerStats.is_cbs > 2047) + ServerStats->is_cl++; + ServerStats->is_cbs += client_p->localClient->sendB; + ServerStats->is_cbr += client_p->localClient->receiveB; + ServerStats->is_cks += client_p->localClient->sendK; + ServerStats->is_ckr += client_p->localClient->receiveK; + ServerStats->is_cti += rb_current_time() - client_p->localClient->firsttime; + if(ServerStats->is_cbs > 2047) { - ServerStats.is_cks += (ServerStats.is_cbs >> 10); - ServerStats.is_cbs &= 0x3ff; + ServerStats->is_cks += (ServerStats->is_cbs >> 10); + ServerStats->is_cbs &= 0x3ff; } - if(ServerStats.is_cbr > 2047) + if(ServerStats->is_cbr > 2047) { - ServerStats.is_ckr += (ServerStats.is_cbr >> 10); - ServerStats.is_cbr &= 0x3ff; + ServerStats->is_ckr += (ServerStats->is_cbr >> 10); + ServerStats->is_cbr &= 0x3ff; } } else - ServerStats.is_ni++; - - /* XXX ctrlFd was here!!! */ - if(client_p->localClient->F != NULL) - { - /* attempt to flush any pending linebufs. Evil, but .. -- adrian */ - if(!IsIOError(client_p)) - send_pop_queue(client_p); - del_from_cli_fd_hash(client_p); - rb_close(client_p->localClient->F); - client_p->localClient->F = NULL; + ServerStats->is_ni++; + + if(client_p->localClient->F) + { + /* attempt to flush any pending dbufs. Evil, but .. -- adrian */ + if(!IsIOError(client_p)) + send_queued(client_p); + + rb_close(client_p->localClient->F); + client_p->localClient->F = NULL; + } + + if(-1 < client_p->localClient->ctrlfd) + { + rb_close(client_p->localClient->ctrlfd); + client_p->localClient->ctrlfd = -1; } rb_linebuf_donebuf(&client_p->localClient->buf_sendq); diff --git a/src/hash.c b/src/hash.c index 053f13c2..41829bbe 100644 --- a/src/hash.c +++ b/src/hash.c @@ -39,14 +39,11 @@ #include "cache.h" #include "s_newconf.h" -#define hash_cli_fd(x) (x % CLI_FD_MAX) - rb_dlink_list *clientTable; rb_dlink_list *channelTable; rb_dlink_list *idTable; rb_dlink_list *resvTable; rb_dlink_list *hostTable; -static rb_dlink_list clientbyfdTable[U_MAX]; /* * look in whowas.c for the missing ...[WW_MAX]; entry @@ -663,37 +660,6 @@ clear_resv_hash(void) HASH_WALK_END } -void -add_to_cli_fd_hash(struct Client *client_p) -{ - rb_dlinkAddAlloc(client_p, &clientbyfdTable[hash_cli_fd(rb_get_fd(client_p->localClient->F))]); -} - - -void -del_from_cli_fd_hash(struct Client *client_p) -{ - unsigned int hashv; - hashv = hash_cli_fd(rb_get_fd(client_p->localClient->F)); - rb_dlinkFindDestroy(client_p, &clientbyfdTable[hashv]); -} - -struct Client * -find_cli_fd_hash(int fd) -{ - struct Client *target_p; - rb_dlink_node *ptr; - unsigned int hashv; - hashv = hash_cli_fd(fd); - RB_DLINK_FOREACH(ptr, clientbyfdTable[hashv].head) - { - target_p = ptr->data; - if(rb_get_fd(target_p->localClient->F) == fd) - return target_p; - } - return NULL; -} - static void output_hash(struct Client *source_p, const char *name, int length, int *counts, int deepest) { diff --git a/src/hostmask.c b/src/hostmask.c index 772b020e..d00aeb7c 100644 --- a/src/hostmask.c +++ b/src/hostmask.c @@ -39,7 +39,7 @@ static unsigned long hash_ipv6(struct sockaddr *, int); static unsigned long hash_ipv4(struct sockaddr *, int); -/* int parse_netmask(const char *, struct rb_sockaddr_storage *, int *); +/* int parse_netmask(const char *, struct irc_sockaddr_storage *, int *); * Input: A hostmask, or an IPV4/6 address. * Output: An integer describing whether it is an IPV4, IPV6 address or a * hostmask, an address(if it is an IP mask), @@ -51,7 +51,7 @@ parse_netmask(const char *text, struct sockaddr *naddr, int *nb) { char *ip = LOCAL_COPY(text); char *ptr; - struct rb_sockaddr_storage *addr, xaddr; + struct irc_sockaddr_storage *addr, xaddr; int *b, xb; if(nb == NULL) b = &xb; @@ -59,9 +59,9 @@ parse_netmask(const char *text, struct sockaddr *naddr, int *nb) b = nb; if(naddr == NULL) - addr = (struct rb_sockaddr_storage *)&xaddr; + addr = (struct irc_sockaddr_storage *)&xaddr; else - addr = (struct rb_sockaddr_storage *)naddr; + addr = (struct irc_sockaddr_storage *)naddr; #ifdef IPV6 if(strchr(ip, ':')) @@ -109,7 +109,7 @@ init_host_hash(void) memset(&atable, 0, sizeof(atable)); } -/* unsigned long hash_ipv4(struct rb_sockaddr_storage*) +/* unsigned long hash_ipv4(struct irc_sockaddr_storage*) * Input: An IP address. * Output: A hash value of the IP address. * Side effects: None @@ -128,7 +128,7 @@ hash_ipv4(struct sockaddr *saddr, int bits) return 0; } -/* unsigned long hash_ipv6(struct rb_sockaddr_storage*) +/* unsigned long hash_ipv6(struct irc_sockaddr_storage*) * Input: An IP address. * Output: A hash value of the IP address. * Side effects: None @@ -196,7 +196,7 @@ get_mask_hash(const char *text) return hash_text(text); } -/* struct ConfItem* find_conf_by_address(const char*, struct rb_sockaddr_storage*, +/* struct ConfItem* find_conf_by_address(const char*, struct irc_sockaddr_storage*, * int type, int fam, const char *username) * Input: The hostname, the address, the type of mask to find, the address * family, the username. @@ -343,7 +343,7 @@ find_conf_by_address(const char *name, const char *sockhost, } /* struct ConfItem* find_address_conf(const char*, const char*, - * struct rb_sockaddr_storage*, int); + * struct irc_sockaddr_storage*, int); * Input: The hostname, username, address, address family. * Output: The applicable ConfItem. * Side-effects: None @@ -416,6 +416,21 @@ find_address_conf(const char *host, const char *sockhost, const char *user, return iconf; } +/* struct ConfItem* find_dline(struct irc_sockaddr_storage*, int) + * Input: An address, an address family. + * Output: The best matching D-line or exempt line. + * Side effects: None. + */ +struct ConfItem * +find_dline(struct sockaddr *addr, int aftype) +{ + struct ConfItem *eline; + eline = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL); + if(eline) + return eline; + return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL); +} + /* void find_exact_conf_by_address(const char*, int, const char *) * Input: * Output: ConfItem if found @@ -427,7 +442,7 @@ find_exact_conf_by_address(const char *address, int type, const char *username) int masktype, bits; unsigned long hv; struct AddressRec *arec; - struct rb_sockaddr_storage addr; + struct irc_sockaddr_storage addr; if(address == NULL) address = "/NOMATCH!/"; @@ -533,7 +548,7 @@ delete_one_address_conf(const char *address, struct ConfItem *aconf) int masktype, bits; unsigned long hv; struct AddressRec *arec, *arecl = NULL; - struct rb_sockaddr_storage addr; + struct irc_sockaddr_storage addr; masktype = parse_netmask(address, (struct sockaddr *)&addr, &bits); #ifdef IPV6 if(masktype == HM_IPV6) diff --git a/src/irc_string.c b/src/irc_string.c index f5f1187a..a32c1ccb 100644 --- a/src/irc_string.c +++ b/src/irc_string.c @@ -539,7 +539,7 @@ inetpton_sock(const char *src, struct sockaddr *dst) { ((struct sockaddr_in *) dst)->sin_port = 0; ((struct sockaddr_in *) dst)->sin_family = AF_INET; - SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in)); + SET_SS_LEN((struct irc_sockaddr_storage *) dst, sizeof(struct sockaddr_in)); return 1; } #ifdef IPV6 @@ -547,7 +547,7 @@ inetpton_sock(const char *src, struct sockaddr *dst) { ((struct sockaddr_in6 *) dst)->sin6_port = 0; ((struct sockaddr_in6 *) dst)->sin6_family = AF_INET6; - SET_SS_LEN((struct rb_sockaddr_storage *) dst, sizeof(struct sockaddr_in6)); + SET_SS_LEN((struct irc_sockaddr_storage *) dst, sizeof(struct sockaddr_in6)); return 1; } #endif diff --git a/src/ircd.c b/src/ircd.c index e3c2cb95..5d6e284b 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -78,10 +78,7 @@ extern int ServerRunning; extern struct LocalUser meLocalUser; extern char **myargv; -int maxconnections; /* XXX */ -int ssl_ok = 0; - -struct ServerStatistics ServerStats; +extern int maxconnections; /* XXX */ /* * print_startup - print startup information @@ -502,7 +499,6 @@ main(int argc, char *argv[]) memset((void *) &Count, 0, sizeof(Count)); memset((void *) &ServerInfo, 0, sizeof(ServerInfo)); memset((void *) &AdminInfo, 0, sizeof(AdminInfo)); - memset(&ServerStats, 0, sizeof(struct ServerStatistics)); /* Initialise the channel capability usage counts... */ init_chcap_usage_counts(); @@ -578,6 +574,7 @@ main(int argc, char *argv[]) init_channels(); initclass(); initwhowas(); + init_stats(); init_reject(); init_cache(); init_monitor(); diff --git a/src/listener.c b/src/listener.c index d86d6713..e8647cfd 100644 --- a/src/listener.c +++ b/src/listener.c @@ -1,556 +1,582 @@ -/* - * ircd-ratbox: A slightly useful ircd. - * listener.c: Listens on a port. - * - * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center - * Copyright (C) 1996-2002 Hybrid Development Team - * Copyright (C) 2002-2005 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * $Id: listener.c 25169 2008-03-29 21:41:31Z jilles $ - */ - -#include "stdinc.h" -#include "ratbox_lib.h" -#include "listener.h" -#include "client.h" -#include "ircd.h" -#include "numeric.h" -#include "s_conf.h" -#include "s_newconf.h" -#include "s_stats.h" -#include "send.h" -#include "s_auth.h" -#include "reject.h" -#include "s_log.h" -#include "hash.h" -#include "sslproc.h" -#include "hostmask.h" - -static rb_dlink_list listener_list; -static int accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data); -static void accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data); - - - -static struct Listener * -make_listener(struct rb_sockaddr_storage *addr) -{ - struct Listener *listener = rb_malloc(sizeof(struct Listener)); - s_assert(0 != listener); - listener->name = ServerInfo.name; /* me.name may not be valid yet -- jilles */ - listener->F = NULL; - memcpy(&listener->addr, addr, sizeof(struct rb_sockaddr_storage)); - return listener; -} - -void -free_listener(struct Listener *listener) -{ - s_assert(NULL != listener); - if(listener == NULL) - return; - - rb_dlinkDelete(&listener->node, &listener_list); - rb_free(listener); -} - -#define PORTNAMELEN 6 /* ":31337" */ - -/* - * get_listener_name - return displayable listener name and port - * returns "host.foo.org:6667" for a given listener - */ -const char * -get_listener_name(struct Listener *listener) -{ - static char buf[HOSTLEN + HOSTLEN + PORTNAMELEN + 4]; - int port = 0; - - s_assert(NULL != listener); - if(listener == NULL) - return NULL; - -#ifdef IPV6 - if(GET_SS_FAMILY(&listener->addr) == AF_INET6) - port = ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port); - else -#endif - port = ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port); - - rb_snprintf(buf, sizeof(buf), "%s[%s/%u]", me.name, listener->name, port); - return buf; -} - -/* - * show_ports - send port listing to a client - * inputs - pointer to client to show ports to - * output - none - * side effects - show ports - */ -void -show_ports(struct Client *source_p) -{ - struct Listener *listener; - rb_dlink_node *ptr; - - RB_DLINK_FOREACH(ptr, listener_list.head) - { - listener = ptr->data; - sendto_one_numeric(source_p, RPL_STATSPLINE, - form_str(RPL_STATSPLINE), 'P', -#ifdef IPV6 - ntohs(GET_SS_FAMILY(&listener->addr) == AF_INET ? ((struct sockaddr_in *)&listener->addr)->sin_port : - ((struct sockaddr_in6 *)&listener->addr)->sin6_port), -#else - ntohs(((struct sockaddr_in *)&listener->addr)->sin_port), -#endif - IsOperAdmin(source_p) ? listener->name : me.name, - listener->ref_count, (listener->active) ? "active" : "disabled", - listener->ssl ? " ssl" : ""); - } -} - -/* - * inetport - create a listener socket in the AF_INET or AF_INET6 domain, - * bind it to the port given in 'port' and listen to it - * returns true (1) if successful false (0) on error. - * - * If the operating system has a define for SOMAXCONN, use it, otherwise - * use RATBOX_SOMAXCONN - */ -#ifdef SOMAXCONN -#undef RATBOX_SOMAXCONN -#define RATBOX_SOMAXCONN SOMAXCONN -#endif - -static int -inetport(struct Listener *listener) -{ - rb_fde_t *F; - int ret; - int opt = 1; - - /* - * At first, open a new socket - */ - - F = rb_socket(GET_SS_FAMILY(&listener->addr), SOCK_STREAM, 0, "Listener socket"); - -#ifdef IPV6 - if(GET_SS_FAMILY(&listener->addr) == AF_INET6) - { - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&listener->addr; - if(!IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &in6addr_any)) - { - rb_inet_ntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost)); - listener->name = listener->vhost; - } - } else -#endif - { - struct sockaddr_in *in = (struct sockaddr_in *)&listener->addr; - if(in->sin_addr.s_addr != INADDR_ANY) - { - rb_inet_ntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost)); - listener->name = listener->vhost; - } - } - - - if(F == NULL) - { - report_error("opening listener socket %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - return 0; - } - else if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus*/ - { - report_error("no more connections left for listener %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - rb_close(F); - return 0; - } - /* - * XXX - we don't want to do all this crap for a listener - * set_sock_opts(listener); - */ - if(setsockopt(rb_get_fd(F), SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))) - { - report_error("setting SO_REUSEADDR for listener %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - rb_close(F); - return 0; - } - - /* - * Bind a port to listen for new connections if port is non-null, - * else assume it is already open and try get something from it. - */ - - if(bind(rb_get_fd(F), (struct sockaddr *) &listener->addr, GET_SS_LEN(&listener->addr))) - { - report_error("binding listener socket %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - rb_close(F); - return 0; - } - - if((ret = rb_listen(F, RATBOX_SOMAXCONN))) - { - report_error("listen failed for %s:%s", - get_listener_name(listener), - get_listener_name(listener), errno); - rb_close(F); - return 0; - } - - listener->F = F; - - rb_accept_tcp(listener->F, accept_precallback, accept_callback, listener); - return 1; -} - -static struct Listener * -find_listener(struct rb_sockaddr_storage *addr) -{ - struct Listener *listener = NULL; - struct Listener *last_closed = NULL; - rb_dlink_node *ptr; - - RB_DLINK_FOREACH(ptr, listener_list.head) - { - listener = ptr->data; - if(GET_SS_FAMILY(addr) != GET_SS_FAMILY(&listener->addr)) - continue; - - switch(GET_SS_FAMILY(addr)) - { - case AF_INET: - { - struct sockaddr_in *in4 = (struct sockaddr_in *)addr; - struct sockaddr_in *lin4 = (struct sockaddr_in *)&listener->addr; - if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr && - in4->sin_port == lin4->sin_port ) - { - if(listener->F == NULL) - last_closed = listener; - else - return(listener); - } - break; - } -#ifdef IPV6 - case AF_INET6: - { - struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; - struct sockaddr_in6 *lin6 =(struct sockaddr_in6 *)&listener->addr; - if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) && - in6->sin6_port == lin6->sin6_port) - { - if(listener->F == NULL) - last_closed = listener; - else - return(listener); - } - break; - - } -#endif - - default: - break; - } - } - return last_closed; -} - -/* - * add_listener- create a new listener - * port - the port number to listen on - * vhost_ip - if non-null must contain a valid IP address string in - * the format "255.255.255.255" - */ -void -add_listener(int port, const char *vhost_ip, int family, int ssl) -{ - struct Listener *listener; - struct rb_sockaddr_storage vaddr; - - /* - * if no port in conf line, don't bother - */ - if(port == 0) - return; - - memset(&vaddr, 0, sizeof(vaddr)); - GET_SS_FAMILY(&vaddr) = family; - - if(vhost_ip != NULL) - { - if(rb_inet_pton_sock(vhost_ip, (struct sockaddr *)&vaddr) <= 0) - return; - } else - { - switch(family) - { - case AF_INET: - ((struct sockaddr_in *)&vaddr)->sin_addr.s_addr = INADDR_ANY; - break; -#ifdef IPV6 - case AF_INET6: - memcpy(&((struct sockaddr_in6 *)&vaddr)->sin6_addr, &in6addr_any, sizeof(struct in6_addr)); - break; -#endif - default: - return; - } - } - switch(family) - { - case AF_INET: - SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in)); - ((struct sockaddr_in *)&vaddr)->sin_port = htons(port); - break; -#ifdef IPV6 - case AF_INET6: - SET_SS_LEN(&vaddr, sizeof(struct sockaddr_in6)); - ((struct sockaddr_in6 *)&vaddr)->sin6_port = htons(port); - break; -#endif - default: - break; - } - if((listener = find_listener(&vaddr))) - { - if(listener->F != NULL) - return; - } - else - { - listener = make_listener(&vaddr); - rb_dlinkAdd(listener, &listener->node, &listener_list); - } - - listener->F = NULL; - listener->ssl = ssl; - if(inetport(listener)) - listener->active = 1; - else - close_listener(listener); -} - -/* - * close_listener - close a single listener - */ -void -close_listener(struct Listener *listener) -{ - s_assert(listener != NULL); - if(listener == NULL) - return; - if(listener->F != NULL) - { - rb_close(listener->F); - listener->F = NULL; - } - - listener->active = 0; - - if(listener->ref_count) - return; - - free_listener(listener); -} - -/* - * close_listeners - close and free all listeners that are not being used - */ -void -close_listeners() -{ - struct Listener *listener; - rb_dlink_node *ptr, *next; - - RB_DLINK_FOREACH_SAFE(ptr, next, listener_list.head) - { - listener = ptr->data; - close_listener(listener); - } -} - -/* - * add_connection - creates a client which has just connected to us on - * the given fd. The sockhost field is initialized with the ip# of the host. - * The client is sent to the auth module for verification, and not put in - * any client list yet. - */ -static void -add_connection(struct Listener *listener, rb_fde_t *F, struct sockaddr *sai, struct sockaddr *lai, void *ssl_ctl) -{ - struct Client *new_client; - s_assert(NULL != listener); - /* - * get the client socket name from the socket - * the client has already been checked out in accept_connection - */ - new_client = make_client(NULL); - - memcpy(&new_client->localClient->ip, sai, sizeof(struct rb_sockaddr_storage)); - new_client->localClient->lip = rb_malloc(sizeof(struct rb_sockaddr_storage)); - memcpy(new_client->localClient->lip, lai, sizeof(struct rb_sockaddr_storage)); - - /* - * copy address to 'sockhost' as a string, copy it to host too - * so we have something valid to put into error messages... - */ - rb_inet_ntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost, - sizeof(new_client->sockhost)); - - - rb_strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); - -#ifdef IPV6 - if(GET_SS_FAMILY(&new_client->localClient->ip) == AF_INET6 && ConfigFileEntry.dot_in_ip6_addr == 1) - { - rb_strlcat(new_client->host, ".", sizeof(new_client->host)); - } -#endif - - new_client->localClient->F = F; - add_to_cli_fd_hash(new_client); - new_client->localClient->listener = listener; - new_client->localClient->ssl_ctl = ssl_ctl; - if(ssl_ctl != NULL || rb_fd_ssl(F)) - SetSSL(new_client); - - ++listener->ref_count; - - start_auth(new_client); -} - -static time_t last_oper_notice = 0; - -static const char *toofast = "ERROR :Reconnecting too fast, throttled.\r\n"; - -static int -accept_precallback(rb_fde_t *F, struct sockaddr *addr, rb_socklen_t addrlen, void *data) -{ - struct Listener *listener = (struct Listener *)data; - char buf[BUFSIZE]; - struct ConfItem *aconf; - - if(listener->ssl && (!ssl_ok || !get_ssld_count())) - { - fprintf(stderr, "closed socket\n"); - rb_close(F); - return 0; - } - - if((maxconnections - 10) < rb_get_fd(F)) /* XXX this is kinda bogus */ - { - ++ServerStats.is_ref; - /* - * slow down the whining to opers bit - */ - if((last_oper_notice + 20) <= rb_current_time()) - { - sendto_realops_flags(UMODE_ALL, L_ALL, - "All connections in use. (%s)", - get_listener_name(listener)); - last_oper_notice = rb_current_time(); - } - - rb_write(F, "ERROR :All connections in use\r\n", 32); - rb_close(F); - /* Re-register a new IO request for the next accept .. */ - return 0; - } - - aconf = find_dline(addr); - if(aconf != NULL && (aconf->status & CONF_EXEMPTDLINE)) - return 1; - - /* Do an initial check we aren't connecting too fast or with too many - * from this IP... */ - if(aconf != NULL) - { - ServerStats.is_ref++; - - if(ConfigFileEntry.dline_with_reason) - { - if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (int)(sizeof(buf)-1)) - { - buf[sizeof(buf) - 3] = '\r'; - buf[sizeof(buf) - 2] = '\n'; - buf[sizeof(buf) - 1] = '\0'; - } - } - else - strcpy(buf, "ERROR :You have been D-lined.\r\n"); - - rb_write(F, buf, strlen(buf)); - rb_close(F); - return 0; - } - - if(check_reject(F, addr)) - return 0; - - if(throttle_add(addr)) - { - rb_write(F, toofast, strlen(toofast)); - rb_close(F); - return 0; - } - - return 1; -} - -static void -accept_ssld(rb_fde_t *F, struct sockaddr *addr, struct sockaddr *laddr, struct Listener *listener) -{ - ssl_ctl_t *ctl; - rb_fde_t *xF[2]; - rb_socketpair(AF_UNIX, SOCK_STREAM, 0, &xF[0], &xF[1], "Incoming ssld Connection"); - ctl = start_ssld_accept(F, xF[1], rb_get_fd(xF[0])); /* this will close F for us */ - add_connection(listener, xF[0], addr, laddr, ctl); -} - -static void -accept_callback(rb_fde_t *F, int status, struct sockaddr *addr, rb_socklen_t addrlen, void *data) -{ - struct Listener *listener = data; - struct rb_sockaddr_storage lip; - unsigned int locallen = sizeof(struct rb_sockaddr_storage); - - ServerStats.is_ac++; - if(getsockname(rb_get_fd(F), (struct sockaddr *) &lip, &locallen) < 0) - { - /* this shouldn't fail so... */ - /* XXX add logging of this */ - rb_close(F); - } - if(listener->ssl) - accept_ssld(F, addr, (struct sockaddr *)&lip, listener); - else - add_connection(listener, F, addr, (struct sockaddr *)&lip, NULL); -} +/* + * ircd-ratbox: A slightly useful ircd. + * listener.c: Listens on a port. + * + * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center + * Copyright (C) 1996-2002 Hybrid Development Team + * Copyright (C) 2002-2005 ircd-ratbox development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id: listener.c 3460 2007-05-18 20:31:33Z jilles $ + */ + +#include "stdinc.h" +#include "setup.h" +#include "listener.h" +#include "client.h" +#include "irc_string.h" +#include "sprintf_irc.h" +#include "ircd.h" +#include "ircd_defs.h" +#include "numeric.h" +#include "s_conf.h" +#include "s_newconf.h" +#include "s_stats.h" +#include "send.h" +#include "s_auth.h" +#include "reject.h" +#include "s_conf.h" +#include "hostmask.h" + +#ifndef INADDR_NONE +#define INADDR_NONE ((unsigned int) 0xffffffff) +#endif + +#if defined(NO_IN6ADDR_ANY) && defined(IPV6) +static const struct in6_addr in6addr_any = +{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }; +#endif + +static PF accept_connection; + +static listener_t *ListenerPollList = NULL; + +static listener_t * +make_listener(struct irc_sockaddr_storage *addr) +{ + listener_t *listener = (listener_t *) rb_malloc(sizeof(listener_t)); + s_assert(0 != listener); + + listener->name = me.name; + listener->fd = -1; + memcpy(&listener->addr, addr, sizeof(struct irc_sockaddr_storage)); + listener->next = NULL; + return listener; +} + +void +free_listener(listener_t *listener) +{ + s_assert(NULL != listener); + if(listener == NULL) + return; + /* + * remove from listener list + */ + if(listener == ListenerPollList) + ListenerPollList = listener->next; + else + { + listener_t *prev = ListenerPollList; + for (; prev; prev = prev->next) + { + if(listener == prev->next) + { + prev->next = listener->next; + break; + } + } + } + + /* free */ + rb_free(listener); +} + +#define PORTNAMELEN 6 /* ":31337" */ + +/* + * get_listener_name - return displayable listener name and port + * returns "host.foo.org:6667" for a given listener + */ +const char * +get_listener_name(const listener_t *listener) +{ + static char buf[HOSTLEN + HOSTLEN + PORTNAMELEN + 4]; + int port = 0; + + s_assert(NULL != listener); + if(listener == NULL) + return NULL; + +#ifdef IPV6 + if(listener->addr.ss_family == AF_INET6) + port = ntohs(((const struct sockaddr_in6 *)&listener->addr)->sin6_port); + else +#endif + port = ntohs(((const struct sockaddr_in *)&listener->addr)->sin_port); + + rb_snprintf(buf, sizeof(buf), "%s[%s/%u]", me.name, listener->name, port); + return buf; +} + +/* + * show_ports - send port listing to a client + * inputs - pointer to client to show ports to + * output - none + * side effects - show ports + */ +void +show_ports(struct Client *source_p) +{ + listener_t *listener = 0; + + for (listener = ListenerPollList; listener; listener = listener->next) + { + sendto_one_numeric(source_p, RPL_STATSPLINE, + form_str(RPL_STATSPLINE), 'P', +#ifdef IPV6 + ntohs(listener->addr.ss_family == AF_INET ? ((struct sockaddr_in *)&listener->addr)->sin_port : + ((struct sockaddr_in6 *)&listener->addr)->sin6_port), +#else + ntohs(((struct sockaddr_in *)&listener->addr)->sin_port), +#endif + IsOperAdmin(source_p) ? listener->name : me.name, + listener->ref_count, (listener->active) ? "active" : "disabled"); + } +} + +/* + * inetport - create a listener socket in the AF_INET or AF_INET6 domain, + * bind it to the port given in 'port' and listen to it + * returns true (1) if successful false (0) on error. + * + * If the operating system has a define for SOMAXCONN, use it, otherwise + * use RATBOX_SOMAXCONN + */ +#ifdef SOMAXCONN +#undef RATBOX_SOMAXCONN +#define RATBOX_SOMAXCONN SOMAXCONN +#endif + +static int +inetport(listener_t *listener) +{ + int fd; + int opt = 1; + + /* + * At first, open a new socket + */ + + fd = rb_socket(listener->addr.ss_family, SOCK_STREAM, 0, "Listener socket"); + +#ifdef IPV6 + if(listener->addr.ss_family == AF_INET6) + { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&listener->addr; + if(!IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &in6addr_any)) + { + inetntop(AF_INET6, &in6->sin6_addr, listener->vhost, sizeof(listener->vhost)); + listener->name = listener->vhost; + } + } else +#endif + { + struct sockaddr_in *in = (struct sockaddr_in *)&listener->addr; + if(in->sin_addr.s_addr != INADDR_ANY) + { + inetntop(AF_INET, &in->sin_addr, listener->vhost, sizeof(listener->vhost)); + listener->name = listener->vhost; + } + } + + /* + * At one point, we enforced a strange arbitrary limit here. + * We no longer do this, and just check if the fd is valid or not. + * -nenolod + */ + if(fd == -1) + { + report_error("opening listener socket %s:%s", + get_listener_name(listener), + get_listener_name(listener), errno); + return 0; + } + + /* + * XXX - we don't want to do all this crap for a listener + * set_sock_opts(listener); + */ + if(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))) + { + report_error("setting SO_REUSEADDR for listener %s:%s", + get_listener_name(listener), + get_listener_name(listener), errno); + rb_close(fd); + return 0; + } + + /* + * Bind a port to listen for new connections if port is non-null, + * else assume it is already open and try get something from it. + */ + + if(bind(fd, (struct sockaddr *) &listener->addr, GET_SS_LEN(listener->addr))) + { + report_error("binding listener socket %s:%s", + get_listener_name(listener), + get_listener_name(listener), errno); + rb_close(fd); + return 0; + } + + if(listen(fd, RATBOX_SOMAXCONN)) + { + report_error("listen failed for %s:%s", + get_listener_name(listener), + get_listener_name(listener), errno); + rb_close(fd); + return 0; + } + + listener->fd = fd; + + /* Listen completion events are READ events .. */ + + accept_connection(fd, listener); + return 1; +} + +static listener_t * +find_listener(struct irc_sockaddr_storage *addr) +{ + listener_t *listener = NULL; + listener_t *last_closed = NULL; + + for (listener = ListenerPollList; listener; listener = listener->next) + { + if(addr->ss_family != listener->addr.ss_family) + continue; + + switch(addr->ss_family) + { + case AF_INET: + { + struct sockaddr_in *in4 = (struct sockaddr_in *)addr; + struct sockaddr_in *lin4 = (struct sockaddr_in *)&listener->addr; + if(in4->sin_addr.s_addr == lin4->sin_addr.s_addr && + in4->sin_port == lin4->sin_port ) + { + if(listener->fd == -1) + last_closed = listener; + else + return(listener); + } + break; + } +#ifdef IPV6 + case AF_INET6: + { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr; + struct sockaddr_in6 *lin6 =(struct sockaddr_in6 *)&listener->addr; + if(IN6_ARE_ADDR_EQUAL(&in6->sin6_addr, &lin6->sin6_addr) && + in6->sin6_port == lin6->sin6_port) + { + if(listener->fd == -1) + last_closed = listener; + else + return(listener); + } + break; + + } +#endif + + default: + break; + } + } + return last_closed; +} + + +/* + * add_listener- create a new listener + * port - the port number to listen on + * vhost_ip - if non-null must contain a valid IP address string in + * the format "255.255.255.255" + */ +void +add_listener(int port, const char *vhost_ip, int family) +{ + listener_t *listener; + struct irc_sockaddr_storage vaddr; + + /* + * if no port in conf line, don't bother + */ + if(port == 0) + return; + memset(&vaddr, 0, sizeof(vaddr)); + vaddr.ss_family = family; + + if(vhost_ip != NULL) + { + if(family == AF_INET) + { + if(inetpton(family, vhost_ip, &((struct sockaddr_in *)&vaddr)->sin_addr) <= 0) + return; + } +#ifdef IPV6 + else + { + if(inetpton(family, vhost_ip, &((struct sockaddr_in6 *)&vaddr)->sin6_addr) <= 0) + return; + + } +#endif + } else + { + switch(family) + { + case AF_INET: + ((struct sockaddr_in *)&vaddr)->sin_addr.s_addr = INADDR_ANY; + break; +#ifdef IPV6 + case AF_INET6: + memcpy(&((struct sockaddr_in6 *)&vaddr)->sin6_addr, &in6addr_any, sizeof(struct in6_addr)); + break; + default: + return; +#endif + } + } + switch(family) + { + case AF_INET: + SET_SS_LEN(vaddr, sizeof(struct sockaddr_in)); + ((struct sockaddr_in *)&vaddr)->sin_port = htons(port); + break; +#ifdef IPV6 + case AF_INET6: + SET_SS_LEN(vaddr, sizeof(struct sockaddr_in6)); + ((struct sockaddr_in6 *)&vaddr)->sin6_port = htons(port); + break; +#endif + default: + break; + } + if((listener = find_listener(&vaddr))) + { + if(listener->fd > -1) + return; + } + else + { + listener = make_listener(&vaddr); + listener->next = ListenerPollList; + ListenerPollList = listener; + } + + listener->fd = -1; + + if(inetport(listener)) + listener->active = 1; + else + close_listener(listener); +} + +/* + * close_listener - close a single listener + */ +void +close_listener(listener_t *listener) +{ + s_assert(listener != NULL); + if(listener == NULL) + return; + if(listener->fd >= 0) + { + rb_close(listener->fd); + listener->fd = -1; + } + + listener->active = 0; + + if(listener->ref_count) + return; + + free_listener(listener); +} + +/* + * close_listeners - close and free all listeners that are not being used + */ +void +close_listeners() +{ + listener_t *listener; + listener_t *listener_next = 0; + /* + * close all 'extra' listening ports we have + */ + for (listener = ListenerPollList; listener; listener = listener_next) + { + listener_next = listener->next; + close_listener(listener); + } +} + +#define DLINE_WARNING "ERROR :You have been D-lined.\r\n" + +/* + * add_connection - creates a client which has just connected to us on + * the given fd. The sockhost field is initialized with the ip# of the host. + * The client is sent to the auth module for verification, and not put in + * any client list yet. + */ +static void +add_connection(listener_t *listener, int fd, struct sockaddr *sai, int exempt) +{ + struct Client *new_client; + s_assert(NULL != listener); + + /* + * get the client socket name from the socket + * the client has already been checked out in accept_connection + */ + new_client = make_client(NULL); + + memcpy(&new_client->localClient->ip, sai, sizeof(struct irc_sockaddr_storage)); + + /* + * copy address to 'sockhost' as a string, copy it to host too + * so we have something valid to put into error messages... + */ + inetntop_sock((struct sockaddr *)&new_client->localClient->ip, new_client->sockhost, + sizeof(new_client->sockhost)); + + + strlcpy(new_client->host, new_client->sockhost, sizeof(new_client->host)); + + new_client->localClient->F = rb_add_fd(fd); + + new_client->localClient->listener = listener; + ++listener->ref_count; + + if(!exempt) + { + if(check_reject(new_client)) + return; + if(add_unknown_ip(new_client)) + return; + } + + start_auth(new_client); +} + + +static void +accept_connection(int pfd, void *data) +{ + static time_t last_oper_notice = 0; + struct irc_sockaddr_storage sai; + socklen_t addrlen = sizeof(sai); + int fd; + listener_t *listener = data; + struct ConfItem *aconf; + char buf[BUFSIZE]; + + s_assert(listener != NULL); + if(listener == NULL) + return; + /* + * There may be many reasons for error return, but + * in otherwise correctly working environment the + * probable cause is running out of file descriptors + * (EMFILE, ENFILE or others?). The man pages for + * accept don't seem to list these as possible, + * although it's obvious that it may happen here. + * Thus no specific errors are tested at this + * point, just assume that connections cannot + * be accepted until some old is closed first. + */ + + fd = rb_accept(listener->fd, (struct sockaddr *)&sai, &addrlen); + if(fd < 0) + { + /* Re-register a new IO request for the next accept .. */ + rb_setselect(listener->fd, FDLIST_SERVICE, + COMM_SELECT_READ, accept_connection, listener, 0); + return; + } + + /* This needs to be done here, otherwise we break dlines */ + mangle_mapped_sockaddr((struct sockaddr *)&sai); + + /* + * check for connection limit + * TBD: this is stupid... either we have a socket or we don't. -nenolod + */ + if((rb_get_maxconnections() - 10) < fd) + { + ++ServerStats->is_ref; + /* + * slow down the whining to opers bit + */ + if((last_oper_notice + 20) <= rb_current_time()) + { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "All connections in use. (%s)", + get_listener_name(listener)); + last_oper_notice = rb_current_time(); + } + + write(fd, "ERROR :All connections in use\r\n", 32); + rb_close(fd); + /* Re-register a new IO request for the next accept .. */ + rb_setselect(listener->fd, FDLIST_SERVICE, + COMM_SELECT_READ, accept_connection, listener, 0); + return; + } + + /* Do an initial check we aren't connecting too fast or with too many + * from this IP... */ + aconf = find_dline((struct sockaddr *) &sai, sai.ss_family); + /* check it wasn't an exempt */ + if (aconf != NULL && (aconf->status & CONF_EXEMPTDLINE) == 0) + { + ServerStats->is_ref++; + + if(ConfigFileEntry.dline_with_reason) + { + if (rb_snprintf(buf, sizeof(buf), "ERROR :*** Banned: %s\r\n", aconf->passwd) >= (sizeof(buf)-1)) + { + buf[sizeof(buf) - 3] = '\r'; + buf[sizeof(buf) - 2] = '\n'; + buf[sizeof(buf) - 1] = '\0'; + } + } + else + rb_sprintf(buf, "ERROR :You have been D-lined.\r\n"); + + write(fd, buf, strlen(buf)); + rb_close(fd); + + /* Re-register a new IO request for the next accept .. */ + rb_setselect(listener->fd, FDLIST_SERVICE, + COMM_SELECT_READ, accept_connection, listener, 0); + return; + } + + ServerStats->is_ac++; + add_connection(listener, fd, (struct sockaddr *)&sai, aconf ? 1 : 0); + + /* Re-register a new IO request for the next accept .. */ + rb_setselect(listener->fd, FDLIST_SERVICE, COMM_SELECT_READ, + accept_connection, listener, 0); +} diff --git a/src/match.c b/src/match.c index 12e4c01e..7a9ad94a 100644 --- a/src/match.c +++ b/src/match.c @@ -326,7 +326,7 @@ int comp_with_mask_sock(struct sockaddr *addr, struct sockaddr *dest, u_int mask */ int match_ips(const char *s1, const char *s2) { - struct rb_sockaddr_storage ipaddr, maskaddr; + struct irc_sockaddr_storage ipaddr, maskaddr; char mask[BUFSIZE]; char address[HOSTLEN + 1]; char *len; @@ -380,7 +380,7 @@ int match_ips(const char *s1, const char *s2) int match_cidr(const char *s1, const char *s2) { - struct rb_sockaddr_storage ipaddr, maskaddr; + struct irc_sockaddr_storage ipaddr, maskaddr; char mask[BUFSIZE]; char address[NICKLEN + USERLEN + HOSTLEN + 6]; char *ipmask; diff --git a/src/newconf.c b/src/newconf.c index c043b5a3..e36882f2 100644 --- a/src/newconf.c +++ b/src/newconf.c @@ -758,10 +758,9 @@ conf_set_listen_port(void *data) } if(listener_address == NULL) { - /* XXX put ssl here -- dwr */ - add_listener(args->v.number, listener_address, AF_INET, 0); + add_listener(args->v.number, listener_address, AF_INET); #ifdef IPV6 - add_listener(args->v.number, listener_address, AF_INET6, 0); + add_listener(args->v.number, listener_address, AF_INET6); #endif } else @@ -774,7 +773,7 @@ conf_set_listen_port(void *data) #endif family = AF_INET; - add_listener(args->v.number, listener_address, family, 0); + add_listener(args->v.number, listener_address, family); } diff --git a/src/packet.c b/src/packet.c index 6a650d21..d8afef07 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1,358 +1,474 @@ -/* - * ircd-ratbox: A slightly useful ircd. - * packet.c: Packet handlers. - * - * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center - * Copyright (C) 1996-2002 Hybrid Development Team - * Copyright (C) 2002-2005 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * $Id: packet.c 25179 2008-03-30 16:34:57Z androsyn $ - */ -#include "stdinc.h" -#include "s_conf.h" -#include "s_serv.h" -#include "client.h" -#include "ircd.h" -#include "parse.h" -#include "packet.h" -#include "hook.h" -#include "send.h" -#include "common.h" - -static char readBuf[READBUF_SIZE]; -static void client_dopacket(struct Client *client_p, char *buffer, size_t length); - - -/* - * parse_client_queued - parse client queued messages - */ -static void -parse_client_queued(struct Client *client_p) -{ - int dolen = 0; - int checkflood = 1; - - if(IsAnyDead(client_p)) - return; - - if(IsUnknown(client_p)) - { - for (;;) - { - if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) - break; - - dolen = rb_linebuf_get(&client_p->localClient-> - buf_recvq, readBuf, READBUF_SIZE, - LINEBUF_COMPLETE, LINEBUF_PARSED); - - if(dolen <= 0 || IsDead(client_p)) - break; - - client_dopacket(client_p, readBuf, dolen); - client_p->localClient->sent_parsed++; - - /* He's dead cap'n */ - if(IsAnyDead(client_p)) - return; - /* if theyve dropped out of the unknown state, break and move - * to the parsing for their appropriate status. --fl - */ - if(!IsUnknown(client_p)) - { - /* reset their flood limits, they're now - * graced to flood - */ - client_p->localClient->sent_parsed = 0; - break; - } - } - } - - if(IsAnyServer(client_p) || IsExemptFlood(client_p)) - { - while (!IsAnyDead(client_p) && (dolen = rb_linebuf_get(&client_p->localClient->buf_recvq, - readBuf, READBUF_SIZE, LINEBUF_COMPLETE, - LINEBUF_PARSED)) > 0) - { - client_dopacket(client_p, readBuf, dolen); - } - } - else if(IsClient(client_p)) - { - - if(IsOper(client_p) && ConfigFileEntry.no_oper_flood) - checkflood = 0; - /* - * Handle flood protection here - if we exceed our flood limit on - * messages in this loop, we simply drop out of the loop prematurely. - * -- adrian - */ - for (;;) - { - /* This flood protection works as follows: - * - * A client is given allow_read lines to send to the server. Every - * time a line is parsed, sent_parsed is increased. sent_parsed - * is decreased by 1 every time flood_recalc is called. - * - * Thus a client can 'burst' allow_read lines to the server, any - * excess lines will be parsed one per flood_recalc() call. - * - * Therefore a client will be penalised more if they keep flooding, - * as sent_parsed will always hover around the allow_read limit - * and no 'bursts' will be permitted. - */ - if(checkflood) - { - if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) - break; - } - - /* allow opers 4 times the amount of messages as users. why 4? - * why not. :) --fl_ - */ - else if(client_p->localClient->sent_parsed >= (4 * client_p->localClient->allow_read)) - break; - - dolen = rb_linebuf_get(&client_p->localClient-> - buf_recvq, readBuf, READBUF_SIZE, - LINEBUF_COMPLETE, LINEBUF_PARSED); - - if(!dolen) - break; - - client_dopacket(client_p, readBuf, dolen); - if(IsAnyDead(client_p)) - return; - client_p->localClient->sent_parsed++; - } - } -} - -/* - * flood_recalc - * - * recalculate the number of allowed flood lines. this should be called - * once a second on any given client. We then attempt to flush some data. - */ -void -flood_recalc(void *unused) -{ - rb_dlink_node *ptr, *next; - struct Client *client_p; - - RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head) - { - client_p = ptr->data; - - if(unlikely(IsMe(client_p))) - continue; - - if(unlikely(client_p->localClient == NULL)) - continue; - - if(IsFloodDone(client_p)) - client_p->localClient->sent_parsed -= 2; - else - client_p->localClient->sent_parsed = 0; - - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; - - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; - - parse_client_queued(client_p); - - if(unlikely(IsAnyDead(client_p))) - continue; - - } - - RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head) - { - client_p = ptr->data; - - if(client_p->localClient == NULL) - continue; - - client_p->localClient->sent_parsed--; - - if(client_p->localClient->sent_parsed < 0) - client_p->localClient->sent_parsed = 0; - - if(--client_p->localClient->actually_read < 0) - client_p->localClient->actually_read = 0; - - parse_client_queued(client_p); - } -} - - -/* - * read_packet - Read a 'packet' of data from a connection and process it. - */ -void -read_packet(rb_fde_t *F, void *data) -{ - struct Client *client_p = data; - struct LocalUser *lclient_p = client_p->localClient; - int length = 0; - int lbuf_len; - - int binary = 0; -#ifdef USE_IODEBUG_HOOKS - hook_data_int hdata; -#endif - - - while(1) /* note..for things like rt sigio to work you *must* loop on read until you get EAGAIN */ - { - if(IsAnyDead(client_p)) - return; - - /* - * Read some data. We *used to* do anti-flood protection here, but - * I personally think it makes the code too hairy to make sane. - * -- adrian - */ - length = rb_read(client_p->localClient->F, readBuf, READBUF_SIZE); - if(length < 0) - { - if(rb_ignore_errno(errno)) - { - rb_setselect(client_p->localClient->F, - RB_SELECT_READ, read_packet, client_p); - } else - error_exit_client(client_p, length); - return; - } else - if(length == 0) - { - error_exit_client(client_p, length); - return; - } - -#ifdef USE_IODEBUG_HOOKS - hdata.client = client_p; - hdata.arg1 = readBuf; - hdata.arg2 = length; - call_hook(h_iorecv_id, &hdata); -#endif - - if(client_p->localClient->lasttime < rb_current_time()) - client_p->localClient->lasttime = rb_current_time(); - client_p->flags &= ~FLAGS_PINGSENT; - - /* - * Before we even think of parsing what we just read, stick - * it on the end of the receive queue and do it when its - * turn comes around. - */ - if(IsHandshake(client_p) || IsUnknown(client_p)) - binary = 1; - - lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); - - lclient_p->actually_read += lbuf_len; - - if(IsAnyDead(client_p)) - return; - - /* Attempt to parse what we have */ - parse_client_queued(client_p); - - if(IsAnyDead(client_p)) - return; - - /* Check to make sure we're not flooding */ - if(!IsAnyServer(client_p) && - (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) - { - if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) - { - exit_client(client_p, client_p, client_p, "Excess Flood"); - return; - } - - } - - /* bail if short read */ - if(length < READBUF_SIZE) - { - rb_setselect(client_p->localClient->F, RB_SELECT_READ, read_packet, client_p); - return; - } - } -} - -/* - * client_dopacket - copy packet to client buf and parse it - * client_p - pointer to client structure for which the buffer data - * applies. - * buffer - pointr to the buffer containing the newly read data - * length - number of valid bytes of data in the buffer - * - * Note: - * It is implicitly assumed that dopacket is called only - * with client_p of "local" variation, which contains all the - * necessary fields (buffer etc..) - */ -void -client_dopacket(struct Client *client_p, char *buffer, size_t length) -{ - s_assert(client_p != NULL); - s_assert(buffer != NULL); - - if(client_p == NULL || buffer == NULL) - return; - if(IsAnyDead(client_p)) - return; - /* - * Update messages received - */ - ++me.localClient->receiveM; - ++client_p->localClient->receiveM; - - /* - * Update bytes received - */ - client_p->localClient->receiveB += length; - me.localClient->receiveB += length; - - parse(client_p, buffer, buffer + length); -} - -/* flood_endgrace() - * - * marks the end of the clients grace period - */ -void -flood_endgrace(struct Client *client_p) -{ - SetFloodDone(client_p); - - /* Drop their flood limit back down */ - client_p->localClient->allow_read = MAX_FLOOD; - - /* sent_parsed could be way over MAX_FLOOD but under MAX_FLOOD_BURST, - * so reset it. - */ - client_p->localClient->sent_parsed = 0; -} +/* + * ircd-ratbox: A slightly useful ircd. + * packet.c: Packet handlers. + * + * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center + * Copyright (C) 1996-2002 Hybrid Development Team + * Copyright (C) 2002-2005 ircd-ratbox development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id: packet.c 3446 2007-05-14 22:21:16Z jilles $ + */ +#include "stdinc.h" +#include "s_conf.h" +#include "s_serv.h" +#include "client.h" +#include "common.h" +#include "ircd.h" +#include "parse.h" +#include "packet.h" +#include "irc_string.h" +#include "hook.h" +#include "send.h" + +static char readBuf[READBUF_SIZE]; +static void client_dopacket(struct Client *client_p, char *buffer, size_t length); + + +/* + * parse_client_queued - parse client queued messages + */ +static void +parse_client_queued(struct Client *client_p) +{ + int dolen = 0; + int checkflood = 1; + + if(IsAnyDead(client_p)) + return; + + if(IsUnknown(client_p)) + { + for (;;) + { + if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) + break; + + dolen = linebuf_get(&client_p->localClient-> + buf_recvq, readBuf, READBUF_SIZE, + LINEBUF_COMPLETE, LINEBUF_PARSED); + + if(dolen <= 0 || IsDead(client_p)) + break; + + client_dopacket(client_p, readBuf, dolen); + client_p->localClient->sent_parsed++; + + /* He's dead cap'n */ + if(IsAnyDead(client_p)) + return; + /* if theyve dropped out of the unknown state, break and move + * to the parsing for their appropriate status. --fl + */ + if(!IsUnknown(client_p)) + { + /* reset their flood limits, they're now + * graced to flood + */ + client_p->localClient->sent_parsed = 0; + break; + } + + } + } + + if(IsAnyServer(client_p) || IsExemptFlood(client_p)) + { + while (!IsAnyDead(client_p) && (dolen = linebuf_get(&client_p->localClient->buf_recvq, + readBuf, READBUF_SIZE, LINEBUF_COMPLETE, + LINEBUF_PARSED)) > 0) + { + client_dopacket(client_p, readBuf, dolen); + } + } + else if(IsClient(client_p)) + { + + if(IsOper(client_p) && ConfigFileEntry.no_oper_flood) + checkflood = 0; + /* + * Handle flood protection here - if we exceed our flood limit on + * messages in this loop, we simply drop out of the loop prematurely. + * -- adrian + */ + for (;;) + { + /* This flood protection works as follows: + * + * A client is given allow_read lines to send to the server. Every + * time a line is parsed, sent_parsed is increased. sent_parsed + * is decreased by 1 every time flood_recalc is called. + * + * Thus a client can 'burst' allow_read lines to the server, any + * excess lines will be parsed one per flood_recalc() call. + * + * Therefore a client will be penalised more if they keep flooding, + * as sent_parsed will always hover around the allow_read limit + * and no 'bursts' will be permitted. + */ + if(checkflood) + { + if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read) + break; + } + + /* allow opers 4 times the amount of messages as users. why 4? + * why not. :) --fl_ + */ + else if(client_p->localClient->sent_parsed >= (4 * client_p->localClient->allow_read)) + break; + + dolen = linebuf_get(&client_p->localClient-> + buf_recvq, readBuf, READBUF_SIZE, + LINEBUF_COMPLETE, LINEBUF_PARSED); + + if(!dolen) + break; + + client_dopacket(client_p, readBuf, dolen); + if(IsAnyDead(client_p)) + return; + client_p->localClient->sent_parsed++; + } + } +} + +/* flood_endgrace() + * + * marks the end of the clients grace period + */ +void +flood_endgrace(struct Client *client_p) +{ + SetFloodDone(client_p); + + /* Drop their flood limit back down */ + client_p->localClient->allow_read = MAX_FLOOD; + + /* sent_parsed could be way over MAX_FLOOD but under MAX_FLOOD_BURST, + * so reset it. + */ + client_p->localClient->sent_parsed = 0; +} + +/* + * flood_recalc + * + * recalculate the number of allowed flood lines. this should be called + * once a second on any given client. We then attempt to flush some data. + */ +void +flood_recalc(int fd, void *data) +{ + struct Client *client_p = data; + struct LocalUser *lclient_p = client_p->localClient; + + /* This can happen in the event that the client detached. */ + if(!lclient_p) + return; + + /* allow a bursting client their allocation per second, allow + * a client whos flooding an extra 2 per second + */ + if(IsFloodDone(client_p)) + lclient_p->sent_parsed -= 2; + else + lclient_p->sent_parsed = 0; + + if(lclient_p->sent_parsed < 0) + lclient_p->sent_parsed = 0; + + if(--lclient_p->actually_read < 0) + lclient_p->actually_read = 0; + + parse_client_queued(client_p); + + if(IsAnyDead(client_p)) + return; + + /* and finally, reset the flood check */ + rb_setflush(fd, 1000, flood_recalc, client_p); +} + +/* + * read_ctrl_packet - Read a 'packet' of data from a servlink control + * link and process it. + */ +void +read_ctrl_packet(int fd, void *data) +{ + struct Client *server = data; + struct LocalUser *lserver = server->localClient; + struct SlinkRpl *reply; + int length = 0; + unsigned char tmp[2]; + unsigned char *len = tmp; + struct SlinkRplDef *replydef; +#ifdef USE_IODEBUG_HOOKS + hook_data_int hdata; +#endif + + s_assert(lserver != NULL); + if(IsAnyDead(server)) + return; + + reply = &lserver->slinkrpl; + + + if(!reply->command) + { + reply->gotdatalen = 0; + reply->readdata = 0; + reply->data = NULL; + + length = read(fd, tmp, 1); + + if(length <= 0) + { + if((length == -1) && ignoreErrno(errno)) + goto nodata; + error_exit_client(server, length); + return; + } + + reply->command = tmp[0]; + } + + for (replydef = slinkrpltab; replydef->handler; replydef++) + { + if((int)replydef->replyid == reply->command) + break; + } + + /* we should be able to trust a local slink process... + * and if it sends an invalid command, that's a bug.. */ + s_assert(replydef->handler); + + if((replydef->flags & SLINKRPL_FLAG_DATA) && (reply->gotdatalen < 2)) + { + /* we need a datalen u16 which we don't have yet... */ + length = read(fd, len, (2 - reply->gotdatalen)); + if(length <= 0) + { + if((length == -1) && ignoreErrno(errno)) + goto nodata; + error_exit_client(server, length); + return; + } + + if(reply->gotdatalen == 0) + { + reply->datalen = *len << 8; + reply->gotdatalen++; + length--; + len++; + } + if(length && (reply->gotdatalen == 1)) + { + reply->datalen |= *len; + reply->gotdatalen++; + if(reply->datalen > 0) + reply->data = rb_malloc(reply->datalen); + } + + if(reply->gotdatalen < 2) + return; /* wait for more data */ + } + + if(reply->readdata < reply->datalen) /* try to get any remaining data */ + { + length = read(fd, (reply->data + reply->readdata), + (reply->datalen - reply->readdata)); + if(length <= 0) + { + if((length == -1) && ignoreErrno(errno)) + goto nodata; + error_exit_client(server, length); + return; + } + + reply->readdata += length; + if(reply->readdata < reply->datalen) + return; /* wait for more data */ + } + +#ifdef USE_IODEBUG_HOOKS + hdata.client = server; + hdata.arg1 = NULL; + hdata.arg2 = reply->command; + hdata.data = NULL; + call_hook(h_iorecvctrl_id, &hdata); +#endif + + /* we now have the command and any data, pass it off to the handler */ + (*replydef->handler) (reply->command, reply->datalen, reply->data, server); + + /* reset SlinkRpl */ + if(reply->datalen > 0) + rb_free(reply->data); + reply->command = 0; + + if(IsAnyDead(server)) + return; + + nodata: + /* If we get here, we need to register for another COMM_SELECT_READ */ + rb_setselect(fd, FDLIST_SERVER, COMM_SELECT_READ, read_ctrl_packet, server, 0); +} + +/* + * read_packet - Read a 'packet' of data from a connection and process it. + */ +void +read_packet(int fd, void *data) +{ + struct Client *client_p = data; + struct LocalUser *lclient_p = client_p->localClient; + int length = 0; + int lbuf_len; + + int binary = 0; +#ifdef USE_IODEBUG_HOOKS + hook_data_int hdata; +#endif + if(IsAnyDead(client_p)) + return; + + /* + * Read some data. We *used to* do anti-flood protection here, but + * I personally think it makes the code too hairy to make sane. + * -- adrian + */ + length = client_p->localClient->F->read_impl(client_p->localClient->F, readBuf, READBUF_SIZE); + + if(length <= 0) + { + if((length == -1) && ignoreErrno(errno)) + { + rb_setselect(client_p->localClient->F->fd, FDLIST_IDLECLIENT, + COMM_SELECT_READ, read_packet, client_p, 0); + return; + } + error_exit_client(client_p, length); + return; + } + +#ifdef USE_IODEBUG_HOOKS + hdata.client = client_p; + hdata.arg1 = readBuf; + hdata.arg2 = length; + call_hook(h_iorecv_id, &hdata); +#endif + + if(client_p->localClient->lasttime < rb_current_time()) + client_p->localClient->lasttime = rb_current_time(); + client_p->flags &= ~FLAGS_PINGSENT; + + /* + * Before we even think of parsing what we just read, stick + * it on the end of the receive queue and do it when its + * turn comes around. + */ + if(IsHandshake(client_p) || IsUnknown(client_p)) + binary = 1; + + lbuf_len = linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary); + + lclient_p->actually_read += lbuf_len; + + if(IsAnyDead(client_p)) + return; + + /* Attempt to parse what we have */ + parse_client_queued(client_p); + + if(IsAnyDead(client_p)) + return; + + /* Check to make sure we're not flooding */ + if(!IsAnyServer(client_p) && + (linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood)) + { + if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p))) + { + exit_client(client_p, client_p, client_p, "Excess Flood"); + return; + } + } + + /* If we get here, we need to register for another COMM_SELECT_READ */ + if(PARSE_AS_SERVER(client_p)) + { + rb_setselect(client_p->localClient->F->fd, FDLIST_SERVER, COMM_SELECT_READ, + read_packet, client_p, 0); + } + else + { + rb_setselect(client_p->localClient->F->fd, FDLIST_IDLECLIENT, + COMM_SELECT_READ, read_packet, client_p, 0); + } +} + +/* + * client_dopacket - copy packet to client buf and parse it + * client_p - pointer to client structure for which the buffer data + * applies. + * buffer - pointr to the buffer containing the newly read data + * length - number of valid bytes of data in the buffer + * + * Note: + * It is implicitly assumed that dopacket is called only + * with client_p of "local" variation, which contains all the + * necessary fields (buffer etc..) + */ +void +client_dopacket(struct Client *client_p, char *buffer, size_t length) +{ + s_assert(client_p != NULL); + s_assert(buffer != NULL); + + if(client_p == NULL || buffer == NULL) + return; + if(IsAnyDead(client_p)) + return; + /* + * Update messages received + */ + ++me.localClient->receiveM; + ++client_p->localClient->receiveM; + + /* + * Update bytes received + */ + client_p->localClient->receiveB += length; + + if(client_p->localClient->receiveB > 1023) + { + client_p->localClient->receiveK += (client_p->localClient->receiveB >> 10); + client_p->localClient->receiveB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */ + } + + me.localClient->receiveB += length; + + if(me.localClient->receiveB > 1023) + { + me.localClient->receiveK += (me.localClient->receiveB >> 10); + me.localClient->receiveB &= 0x03ff; + } + + parse(client_p, buffer, buffer + length); +} diff --git a/src/parse.c b/src/parse.c index b26022dd..36976ce7 100644 --- a/src/parse.c +++ b/src/parse.c @@ -162,7 +162,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) /* didnt find any matching client, issue a kill */ if(from == NULL) { - ServerStats.is_unpf++; + ServerStats->is_unpf++; remove_unknown(client_p, sender, pbuffer); return; } @@ -172,7 +172,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) /* fake direction, hmm. */ if(from->from != client_p) { - ServerStats.is_wrdi++; + ServerStats->is_wrdi++; cancel_clients(client_p, from, pbuffer); return; } @@ -183,7 +183,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) if(*ch == '\0') { - ServerStats.is_empt++; + ServerStats->is_empt++; return; } @@ -204,7 +204,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) { mptr = NULL; numeric = ch; - ServerStats.is_num++; + ServerStats->is_num++; s = ch + 3; /* I know this is ' ' from above if */ *s++ = '\0'; /* blow away the ' ', and point s to next part */ } @@ -248,7 +248,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend) me.name, from->name, ch); } } - ServerStats.is_unco++; + ServerStats->is_unco++; return; } diff --git a/src/reject.c b/src/reject.c index a076fc9f..02ddfb84 100644 --- a/src/reject.c +++ b/src/reject.c @@ -1,589 +1,303 @@ -/* - * ircd-ratbox: A slightly useful ircd - * reject.c: reject users with prejudice - * - * Copyright (C) 2003 Aaron Sethman - * Copyright (C) 2003-2005 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * $Id: reject.c 25119 2008-03-13 16:57:05Z androsyn $ - */ - -#include "stdinc.h" -#include "client.h" -#include "s_conf.h" -#include "reject.h" -#include "s_stats.h" -#include "ircd.h" -#include "send.h" -#include "numeric.h" -#include "parse.h" -#include "hostmask.h" - -static rb_patricia_tree_t *global_tree; -static rb_patricia_tree_t *reject_tree; -static rb_patricia_tree_t *dline_tree; -static rb_patricia_tree_t *eline_tree; -static rb_dlink_list delay_exit; -static rb_dlink_list reject_list; -static rb_dlink_list throttle_list; -static rb_patricia_tree_t *throttle_tree; -static void throttle_expires(void *unused); - - -typedef struct _reject_data -{ - rb_dlink_node rnode; - time_t time; - unsigned int count; -} reject_t; - -typedef struct _delay_data -{ - rb_dlink_node node; - rb_fde_t *F; -} delay_t; - -typedef struct _throttle -{ - rb_dlink_node node; - time_t last; - int count; -} throttle_t; - -typedef struct _global_data -{ - int count; -} global_t; - - -static rb_patricia_node_t * -add_ipline(struct ConfItem *aconf, rb_patricia_tree_t *tree, struct sockaddr *addr, int cidr) -{ - rb_patricia_node_t *pnode; - pnode = make_and_lookup_ip(tree, addr, cidr); - if(pnode == NULL) - return NULL; - aconf->pnode = pnode; - pnode->data = aconf; - return (pnode); -} - -int -add_dline(struct ConfItem *aconf) -{ - struct rb_sockaddr_storage st; - int bitlen; - if(parse_netmask(aconf->host, (struct sockaddr *)&st, &bitlen) == HM_HOST) - return 0; - - if(add_ipline(aconf, dline_tree, (struct sockaddr *)&st, bitlen) != NULL) - return 1; - return 0; -} - -int -add_eline(struct ConfItem *aconf) -{ - struct rb_sockaddr_storage st; - int bitlen; - if(parse_netmask(aconf->host, (struct sockaddr *)&st, &bitlen) == HM_HOST) - return 0; - - if(add_ipline(aconf, eline_tree, (struct sockaddr *)&st, bitlen) != NULL) - return 1; - return 0; -} - -unsigned long -delay_exit_length(void) -{ - return rb_dlink_list_length(&delay_exit); -} - -static void -reject_exit(void *unused) -{ - rb_dlink_node *ptr, *ptr_next; - delay_t *ddata; - static const char *errbuf = "ERROR :Closing Link: (*** Banned (cache))\r\n"; - - RB_DLINK_FOREACH_SAFE(ptr, ptr_next, delay_exit.head) - { - ddata = ptr->data; - - rb_write(ddata->F, errbuf, strlen(errbuf)); - rb_close(ddata->F); - rb_free(ddata); - } - - delay_exit.head = delay_exit.tail = NULL; - delay_exit.length = 0; -} - -static void -reject_expires(void *unused) -{ - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - reject_t *rdata; - - RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) - { - pnode = ptr->data; - rdata = pnode->data; - - if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) - continue; - - rb_dlinkDelete(ptr, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - } -} - -void -init_reject(void) -{ - reject_tree = rb_new_patricia(PATRICIA_BITS); - dline_tree = rb_new_patricia(PATRICIA_BITS); - eline_tree = rb_new_patricia(PATRICIA_BITS); - throttle_tree = rb_new_patricia(PATRICIA_BITS); - global_tree = rb_new_patricia(PATRICIA_BITS); - rb_event_add("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME); - rb_event_add("reject_expires", reject_expires, NULL, 60); - rb_event_add("throttle_expires", throttle_expires, NULL, 10); -} - - -void -add_reject(struct Client *client_p) -{ - rb_patricia_node_t *pnode; - reject_t *rdata; - - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return; - - if((pnode = rb_match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) - { - rdata = pnode->data; - rdata->time = rb_current_time(); - rdata->count++; - } - else - { - int bitlen = 32; -#ifdef RB_IPV6 - if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6) - bitlen = 128; -#endif - pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); - pnode->data = rdata = rb_malloc(sizeof(reject_t)); - rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); - rdata->time = rb_current_time(); - rdata->count = 1; - } -} - -int -check_reject(rb_fde_t *F, struct sockaddr *addr) -{ - rb_patricia_node_t *pnode; - reject_t *rdata; - delay_t *ddata; - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return 0; - - pnode = rb_match_ip(reject_tree, addr); - if(pnode != NULL) - { - rdata = pnode->data; - - rdata->time = rb_current_time(); - if(rdata->count > (unsigned long)ConfigFileEntry.reject_after_count) - { - ddata = rb_malloc(sizeof(delay_t)); - ServerStats.is_rej++; - rb_setselect(F, RB_SELECT_WRITE | RB_SELECT_READ, NULL, NULL); - ddata->F = F; - rb_dlinkAdd(ddata, &ddata->node, &delay_exit); - return 1; - } - } - /* Caller does what it wants */ - return 0; -} - -void -flush_reject(void) -{ - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - reject_t *rdata; - - RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) - { - pnode = ptr->data; - rdata = pnode->data; - rb_dlinkDelete(ptr, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - } -} - -int -remove_reject(const char *ip) -{ - rb_patricia_node_t *pnode; - - /* Reject is disabled */ - if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_duration == 0) - return -1; - - if((pnode = rb_match_string(reject_tree, ip)) != NULL) - { - reject_t *rdata = pnode->data; - rb_dlinkDelete(&rdata->rnode, &reject_list); - rb_free(rdata); - rb_patricia_remove(reject_tree, pnode); - return 1; - } - return 0; -} - -static void -delete_ipline(struct ConfItem *aconf, rb_patricia_tree_t *t) -{ - rb_patricia_remove(t, aconf->pnode); - if(!aconf->clients) - { - free_conf(aconf); - } -} - -static struct ConfItem * -find_ipline(rb_patricia_tree_t *t, struct sockaddr *addr) -{ - rb_patricia_node_t *pnode; - pnode = rb_match_ip(t, addr); - if(pnode != NULL) - return (struct ConfItem *) pnode->data; - return NULL; -} - -static struct ConfItem * -find_ipline_exact(rb_patricia_tree_t *t, struct sockaddr *addr, unsigned int bitlen) -{ - rb_patricia_node_t *pnode; - pnode = rb_match_ip_exact(t, addr, bitlen); - if(pnode != NULL) - return (struct ConfItem *) pnode->data; - return NULL; -} - - -struct ConfItem * -find_dline(struct sockaddr *addr) -{ - struct ConfItem *aconf; - aconf = find_ipline(eline_tree, addr); - if(aconf != NULL) - { - return aconf; - } - return (find_ipline(dline_tree, addr)); -} - -struct ConfItem * -find_dline_exact(struct sockaddr *addr, unsigned int bitlen) -{ - return find_ipline_exact(dline_tree, addr, bitlen); -} - -void -remove_dline(struct ConfItem *aconf) -{ - delete_ipline(aconf, dline_tree); -} - -void -report_dlines(struct Client *source_p) -{ - rb_patricia_node_t *pnode; - struct ConfItem *aconf; - const char *host, *pass, *user, *oper_reason; - RB_PATRICIA_WALK(dline_tree->head, pnode) - { - aconf = pnode->data; - if(aconf->flags & CONF_FLAGS_TEMPORARY) - RB_PATRICIA_WALK_BREAK; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str (RPL_STATSDLINE), - 'D', host, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - RB_PATRICIA_WALK_END; -} - -void -report_tdlines(struct Client *source_p) -{ - rb_patricia_node_t *pnode; - struct ConfItem *aconf; - const char *host, *pass, *user, *oper_reason; - RB_PATRICIA_WALK(dline_tree->head, pnode) - { - aconf = pnode->data; - if(!(aconf->flags & CONF_FLAGS_TEMPORARY)) - RB_PATRICIA_WALK_BREAK; - get_printable_kline(source_p, aconf, &host, &pass, &user, &oper_reason); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str (RPL_STATSDLINE), - 'd', host, pass, - oper_reason ? "|" : "", - oper_reason ? oper_reason : ""); - } - RB_PATRICIA_WALK_END; -} - -void -report_elines(struct Client *source_p) -{ - rb_patricia_node_t *pnode; - struct ConfItem *aconf; - int port; - const char *name, *host, *pass, *user, *classname; - RB_PATRICIA_WALK(eline_tree->head, pnode) - { - aconf = pnode->data; - get_printable_conf(aconf, &name, &host, &pass, &user, &port, &classname); - sendto_one_numeric(source_p, RPL_STATSDLINE, - form_str (RPL_STATSDLINE), - 'e', host, pass, - "", ""); - } - RB_PATRICIA_WALK_END; -} - - - -int -throttle_add(struct sockaddr *addr) -{ - throttle_t *t; - rb_patricia_node_t *pnode; - - if((pnode = rb_match_ip(throttle_tree, addr)) != NULL) - { - t = pnode->data; - - if(t->count > ConfigFileEntry.throttle_count) - return 1; - - /* Stop penalizing them after they've been throttled */ - t->last = rb_current_time(); - t->count++; - - } else { - int bitlen = 32; -#ifdef RB_IPV6 - if(GET_SS_FAMILY(addr) == AF_INET6) - bitlen = 128; -#endif - t = rb_malloc(sizeof(throttle_t)); - t->last = rb_current_time(); - t->count = 1; - pnode = make_and_lookup_ip(throttle_tree, addr, bitlen); - pnode->data = t; - rb_dlinkAdd(pnode, &t->node, &throttle_list); - } - return 0; -} - -static void -throttle_expires(void *unused) -{ - rb_dlink_node *ptr, *next; - rb_patricia_node_t *pnode; - throttle_t *t; - - RB_DLINK_FOREACH_SAFE(ptr, next, throttle_list.head) - { - pnode = ptr->data; - t = pnode->data; - - if(t->last + ConfigFileEntry.throttle_duration > rb_current_time()) - continue; - - rb_dlinkDelete(ptr, &throttle_list); - rb_free(t); - rb_patricia_remove(throttle_tree, pnode); - } -} - -static int -get_global_count(struct sockaddr *addr) -{ - rb_patricia_node_t *pnode; - global_t *glb; - - if((pnode = rb_match_ip(global_tree, addr))) - { - glb = pnode->data; - return glb->count; - } - return 0; -} - -static int -inc_global_ip(struct sockaddr *addr, int bitlen) -{ - rb_patricia_node_t *pnode; - global_t *glb; - - - if((pnode = rb_match_ip(global_tree, addr))) - { - glb = pnode->data; - } - else - { - pnode = make_and_lookup_ip(global_tree, addr, bitlen); - glb = rb_malloc(sizeof(global_t)); - pnode->data = glb; - } - glb->count++; - return glb->count; -} - -static void -dec_global_ip(struct sockaddr *addr) -{ - rb_patricia_node_t *pnode; - global_t *glb; - - if((pnode = rb_match_ip(global_tree, addr))) - { - glb = pnode->data; - glb->count--; - if(glb->count == 0) - { - rb_free(glb); - rb_patricia_remove(global_tree, pnode); - return; - } - } -} - -int -inc_global_cidr_count(struct Client *client_p) -{ - struct rb_sockaddr_storage ip; - struct sockaddr *addr; - int bitlen; - - if(!MyClient(client_p)) - { - if(EmptyString(client_p->sockhost) || !strcmp(client_p->sockhost, "0")) - return -1; - if(!rb_inet_pton_sock(client_p->sockhost, (struct sockaddr *)&ip)) - return -1; - addr = (struct sockaddr *)&ip; - } else - addr = (struct sockaddr *)&client_p->localClient->ip; -#ifdef RB_IPV6 - if(GET_SS_FAMILY(addr) == AF_INET6) - { - bitlen = ConfigFileEntry.global_cidr_ipv6_bitlen; - } else -#endif - bitlen = ConfigFileEntry.global_cidr_ipv4_bitlen; - - return inc_global_ip(addr, bitlen); -} - -void -dec_global_cidr_count(struct Client *client_p) -{ - struct rb_sockaddr_storage ip; - struct sockaddr *addr; - if(!MyClient(client_p)) - { - if(EmptyString(client_p->sockhost) || !strcmp(client_p->sockhost, "0")) - return; - if(!rb_inet_pton_sock(client_p->sockhost, (struct sockaddr *)&ip)) - return; - addr = (struct sockaddr *)&ip; - } else - addr = (struct sockaddr *)&client_p->localClient->ip; - - dec_global_ip(addr); -} - -int -check_global_cidr_count(struct Client *client_p) -{ - struct rb_sockaddr_storage ip; - struct sockaddr *addr; - int count, max; - if(!MyClient(client_p)) - { - if(EmptyString(client_p->sockhost) || !strcmp(client_p->sockhost, "0")) - return -1; - if(!rb_inet_pton_sock(client_p->sockhost, (struct sockaddr *)&ip)) - return -1; - addr = (struct sockaddr *)&ip; - } else - addr = (struct sockaddr *)&client_p->localClient->ip; - count = get_global_count(addr); -#ifdef RB_IPV6 - if(GET_SS_FAMILY(addr) == AF_INET6) - max = ConfigFileEntry.global_cidr_ipv6_count; - else -#endif - max = ConfigFileEntry.global_cidr_ipv4_count; - if(count >= max) - return 1; - return 0; -} - -static void -clear_cidr_tree(void *data) -{ - rb_free(data); -} - -void -rehash_global_cidr_tree(void) -{ - struct Client *client_p; - rb_dlink_node *ptr; - rb_clear_patricia(global_tree, clear_cidr_tree); - RB_DLINK_FOREACH(ptr, global_client_list.head) - { - client_p = ptr->data; - if(IsMe(client_p) && IsServer(client_p)) - continue; - inc_global_cidr_count(client_p); - } - return; -} +/* + * ircd-ratbox: A slightly useful ircd + * reject.c: reject users with prejudice + * + * Copyright (C) 2003 Aaron Sethman + * Copyright (C) 2003-2005 ircd-ratbox development team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * $Id: reject.c 3456 2007-05-18 19:14:18Z jilles $ + */ + +#include "stdinc.h" +#include "config.h" +#include "patricia.h" +#include "client.h" +#include "s_conf.h" +#include "reject.h" +#include "s_stats.h" +#include "msg.h" +#include "hash.h" + +static patricia_tree_t *reject_tree; +rb_dlink_list delay_exit; +static rb_dlink_list reject_list; + +static patricia_tree_t *unknown_tree; + +struct reject_data +{ + rb_dlink_node rnode; + time_t time; + unsigned int count; + uint32_t mask_hashv; +}; + +static patricia_tree_t *unknown_tree; + +static void +reject_exit(void *unused) +{ + struct Client *client_p; + rb_dlink_node *ptr, *ptr_next; + + RB_DLINK_FOREACH_SAFE(ptr, ptr_next, delay_exit.head) + { + client_p = ptr->data; + if(IsDead(client_p)) + continue; + + /* this MUST be here, to prevent the possibility + * sendto_one() generates a write error, and then a client + * ends up on the dead_list and the abort_list --fl + * + * new disconnect notice stolen from ircu --nenolod + * no, this only happens when someone's IP has some + * ban on it and rejects them rather longer than the + * ircu message suggests --jilles + */ + if(!IsIOError(client_p)) + { + if(IsExUnknown(client_p)) + sendto_one(client_p, "ERROR :Closing Link: %s (*** Too many unknown connections)", client_p->host); + else + sendto_one(client_p, "ERROR :Closing Link: %s (*** Banned (cache))", client_p->host); + } + close_connection(client_p); + SetDead(client_p); + rb_dlinkAddAlloc(client_p, &dead_list); + } + + delay_exit.head = delay_exit.tail = NULL; + delay_exit.length = 0; +} + +static void +reject_expires(void *unused) +{ + rb_dlink_node *ptr, *next; + patricia_node_t *pnode; + struct reject_data *rdata; + + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) + { + pnode = ptr->data; + rdata = pnode->data; + + if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) + continue; + + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + patricia_remove(reject_tree, pnode); + } +} + +void +init_reject(void) +{ + reject_tree = New_Patricia(PATRICIA_BITS); + unknown_tree = New_Patricia(PATRICIA_BITS); + rb_event_add("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME); + rb_event_add("reject_expires", reject_expires, NULL, 60); +} + + +void +add_reject(struct Client *client_p, const char *mask1, const char *mask2) +{ + patricia_node_t *pnode; + struct reject_data *rdata; + uint32_t hashv; + + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0) + return; + + hashv = 0; + if (mask1 != NULL) + hashv ^= fnv_hash_upper(mask1, 32); + if (mask2 != NULL) + hashv ^= fnv_hash_upper(mask2, 32); + + if((pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) + { + rdata = pnode->data; + rdata->time = rb_current_time(); + rdata->count++; + } + else + { + int bitlen = 32; +#ifdef IPV6 + if(client_p->localClient->ip.ss_family == AF_INET6) + bitlen = 128; +#endif + pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); + pnode->data = rdata = rb_malloc(sizeof(struct reject_data)); + rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); + rdata->time = rb_current_time(); + rdata->count = 1; + } + rdata->mask_hashv = hashv; +} + +int +check_reject(struct Client *client_p) +{ + patricia_node_t *pnode; + struct reject_data *rdata; + + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0 || + ConfigFileEntry.reject_duration == 0) + return 0; + + pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip); + if(pnode != NULL) + { + rdata = pnode->data; + + rdata->time = rb_current_time(); + if(rdata->count > ConfigFileEntry.reject_after_count) + { + ServerStats->is_rej++; + SetReject(client_p); + rb_setselect(client_p->localClient->F->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0); + SetClosing(client_p); + rb_dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &delay_exit); + return 1; + } + } + /* Caller does what it wants */ + return 0; +} + +void +flush_reject(void) +{ + rb_dlink_node *ptr, *next; + patricia_node_t *pnode; + struct reject_data *rdata; + + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) + { + pnode = ptr->data; + rdata = pnode->data; + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + patricia_remove(reject_tree, pnode); + } +} + +int +remove_reject_ip(const char *ip) +{ + patricia_node_t *pnode; + + /* Reject is disabled */ + if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0 || + ConfigFileEntry.reject_duration == 0) + return -1; + + if((pnode = match_string(reject_tree, ip)) != NULL) + { + struct reject_data *rdata = pnode->data; + rb_dlinkDelete(&rdata->rnode, &reject_list); + rb_free(rdata); + patricia_remove(reject_tree, pnode); + return 1; + } + return 0; +} + +int +remove_reject_mask(const char *mask1, const char *mask2) +{ + rb_dlink_node *ptr, *next; + patricia_node_t *pnode; + struct reject_data *rdata; + uint32_t hashv; + int n = 0; + + hashv = 0; + if (mask1 != NULL) + hashv ^= fnv_hash_upper(mask1, 32); + if (mask2 != NULL) + hashv ^= fnv_hash_upper(mask2, 32); + RB_DLINK_FOREACH_SAFE(ptr, next, reject_list.head) + { + pnode = ptr->data; + rdata = pnode->data; + if (rdata->mask_hashv == hashv) + { + rb_dlinkDelete(ptr, &reject_list); + rb_free(rdata); + patricia_remove(reject_tree, pnode); + n++; + } + } + return n; +} + + +int +add_unknown_ip(struct Client *client_p) +{ + patricia_node_t *pnode; + + if((pnode = match_ip(unknown_tree, (struct sockaddr *)&client_p->localClient->ip)) == NULL) + { + int bitlen = 32; +#ifdef IPV6 + if(client_p->localClient->ip.ss_family == AF_INET6) + bitlen = 128; +#endif + pnode = make_and_lookup_ip(unknown_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); + pnode->data = (void *)0; + } + + if((unsigned long)pnode->data >= ConfigFileEntry.max_unknown_ip) + { + SetExUnknown(client_p); + SetReject(client_p); + rb_setselect(client_p->localClient->F->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0); + SetClosing(client_p); + rb_dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &delay_exit); + return 1; + } + + pnode->data = (void *)((unsigned long)pnode->data + 1); + + return 0; +} + +void +del_unknown_ip(struct Client *client_p) +{ + patricia_node_t *pnode; + + if((pnode = match_ip(unknown_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) + { + pnode->data = (void *)((unsigned long)pnode->data - 1); + if((unsigned long)pnode->data <= 0) + { + patricia_remove(unknown_tree, pnode); + } + } + /* this can happen due to m_webirc.c's manipulations, for example */ +} diff --git a/src/res.c b/src/res.c index e84e7a58..f61485e5 100644 --- a/src/res.c +++ b/src/res.c @@ -79,7 +79,7 @@ struct reslist char resend; /* send flag. 0 == dont resend */ time_t sentat; time_t timeout; - struct rb_sockaddr_storage addr; + struct irc_sockaddr_storage addr; char *name; struct DNSQuery *query; /* query callback for this request */ }; @@ -90,7 +90,7 @@ static rb_dlink_list request_list = { NULL, NULL, 0 }; static void rem_request(struct reslist *request); static struct reslist *make_request(struct DNSQuery *query); static void do_query_name(struct DNSQuery *query, const char *name, struct reslist *request, int); -static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *, +static void do_query_number(struct DNSQuery *query, const struct irc_sockaddr_storage *, struct reslist *request); static void query_name(struct reslist *request); static int send_res_msg(const char *buf, int len, int count); @@ -100,7 +100,7 @@ static int proc_answer(struct reslist *request, HEADER * header, char *, char *) static struct reslist *find_id(int id); static struct DNSReply *make_dnsreply(struct reslist *request); -extern struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS]; +extern struct irc_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS]; extern int irc_nscount; extern char irc_domain[HOSTLEN + 1]; @@ -116,7 +116,7 @@ extern char irc_domain[HOSTLEN + 1]; * paul vixie, 29may94 * revised for ircd, cryogen(stu) may03 */ -static int res_ourserver(const struct rb_sockaddr_storage *inp) +static int res_ourserver(const struct irc_sockaddr_storage *inp) { #ifdef IPV6 struct sockaddr_in6 *v6; @@ -128,7 +128,7 @@ static int res_ourserver(const struct rb_sockaddr_storage *inp) for (ns = 0; ns < irc_nscount; ns++) { - const struct rb_sockaddr_storage *srv = &irc_nsaddr_list[ns]; + const struct irc_sockaddr_storage *srv = &irc_nsaddr_list[ns]; #ifdef IPV6 v6 = (struct sockaddr_in6 *)srv; #endif @@ -392,7 +392,7 @@ void gethost_byname_type(const char *name, struct DNSQuery *query, int type) /* * gethost_byaddr - get host name from address */ -void gethost_byaddr(const struct rb_sockaddr_storage *addr, struct DNSQuery *query) +void gethost_byaddr(const struct irc_sockaddr_storage *addr, struct DNSQuery *query) { do_query_number(query, addr, NULL); } @@ -424,7 +424,7 @@ static void do_query_name(struct DNSQuery *query, const char *name, struct resli /* * do_query_number - Use this to do reverse IP# lookups. */ -static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_storage *addr, +static void do_query_number(struct DNSQuery *query, const struct irc_sockaddr_storage *addr, struct reslist *request) { const unsigned char *cp; @@ -432,7 +432,7 @@ static void do_query_number(struct DNSQuery *query, const struct rb_sockaddr_sto if (request == NULL) { request = make_request(query); - memcpy(&request->addr, addr, sizeof(struct rb_sockaddr_storage)); + memcpy(&request->addr, addr, sizeof(struct irc_sockaddr_storage)); request->name = (char *)rb_malloc(HOSTLEN + 1); } @@ -734,8 +734,8 @@ static void res_readreply(int fd, void *data) struct DNSReply *reply = NULL; int rc; int answer_count; - socklen_t len = sizeof(struct rb_sockaddr_storage); - struct rb_sockaddr_storage lsin; + socklen_t len = sizeof(struct irc_sockaddr_storage); + struct irc_sockaddr_storage lsin; rc = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&lsin, &len); diff --git a/src/reslib.c b/src/reslib.c index 4f2c5703..d2b029cf 100644 --- a/src/reslib.c +++ b/src/reslib.c @@ -96,7 +96,7 @@ /* $Id: reslib.c 1695 2006-06-27 15:11:23Z jilles $ */ /* from Hybrid Id: reslib.c 177 2005-10-22 09:05:05Z michael $ */ -struct rb_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS]; +struct irc_sockaddr_storage irc_nsaddr_list[IRCD_MAXNS]; int irc_nscount = 0; char irc_domain[HOSTLEN + 1]; diff --git a/src/s_auth.c b/src/s_auth.c index 1d8282ca..d2454704 100644 --- a/src/s_auth.c +++ b/src/s_auth.c @@ -243,7 +243,7 @@ auth_dns_callback(void *vptr, struct DNSReply *reply) static void auth_error(struct AuthRequest *auth) { - ++ServerStats.is_abad; + ++ServerStats->is_abad; rb_close(auth->fd); auth->fd = -1; @@ -265,8 +265,8 @@ auth_error(struct AuthRequest *auth) static int start_auth_query(struct AuthRequest *auth) { - struct rb_sockaddr_storage localaddr; - socklen_t locallen = sizeof(struct rb_sockaddr_storage); + struct irc_sockaddr_storage localaddr; + socklen_t locallen = sizeof(struct irc_sockaddr_storage); int fd; int family; @@ -279,7 +279,7 @@ start_auth_query(struct AuthRequest *auth) report_error("creating auth stream socket %s:%s", get_client_name(auth->client, SHOW_IP), log_client_name(auth->client, SHOW_IP), errno); - ++ServerStats.is_abad; + ++ServerStats->is_abad; return 0; } @@ -441,7 +441,7 @@ timeout_auth_queries_event(void *notused) if(IsDoingAuth(auth)) { ClearAuth(auth); - ++ServerStats.is_abad; + ++ServerStats->is_abad; sendheader(auth->client, REPORT_FAIL_ID); auth->client->localClient->auth_request = NULL; } @@ -571,14 +571,14 @@ read_auth_reply(int fd, void *data) if(s == NULL) { - ++ServerStats.is_abad; + ++ServerStats->is_abad; strcpy(auth->client->username, "unknown"); sendheader(auth->client, REPORT_FAIL_ID); } else { sendheader(auth->client, REPORT_FIN_ID); - ++ServerStats.is_asuc; + ++ServerStats->is_asuc; SetGotId(auth->client); } diff --git a/src/s_conf.c b/src/s_conf.c index 9ea157ad..f45601fc 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -195,7 +195,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern source_p->name, IsGotId(source_p) ? "" : "~", source_p->username, source_p->sockhost); - ServerStats.is_ref++; + ServerStats->is_ref++; exit_client(client_p, source_p, &me, "Too many host connections (local)"); break; @@ -209,7 +209,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern source_p->name, IsGotId(source_p) ? "" : "~", source_p->username, source_p->sockhost); - ServerStats.is_ref++; + ServerStats->is_ref++; exit_client(client_p, source_p, &me, "Too many host connections (global)"); break; @@ -223,7 +223,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern source_p->name, IsGotId(source_p) ? "" : "~", source_p->username, source_p->sockhost); - ServerStats.is_ref++; + ServerStats->is_ref++; exit_client(client_p, source_p, &me, "Too many user connections (global)"); break; @@ -238,7 +238,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern source_p->name, IsGotId(source_p) ? "" : "~", source_p->username, source_p->sockhost); - ServerStats.is_ref++; + ServerStats->is_ref++; exit_client(client_p, source_p, &me, "No more connections allowed in your connection class"); break; @@ -253,7 +253,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern #endif port = ntohs(((struct sockaddr_in *)&source_p->localClient->listener->addr)->sin_port); - ServerStats.is_ref++; + ServerStats->is_ref++; /* jdc - lists server name & port connections are on */ /* a purely cosmetical change */ /* why ipaddr, and not just source_p->sockhost? --fl */ @@ -281,7 +281,7 @@ check_client(struct Client *client_p, struct Client *source_p, const char *usern } case BANNED_CLIENT: exit_client(client_p, client_p, &me, "*** Banned "); - ServerStats.is_ref++; + ServerStats->is_ref++; break; case 0: @@ -1120,21 +1120,21 @@ get_printable_conf(struct ConfItem *aconf, char **name, char **host, *port = (int) aconf->port; } -void -get_printable_kline(struct Client *source_p, struct ConfItem *aconf, - const char **host, const char **reason, - const char **user, const char **oper_reason) -{ - static const char *null = ""; - - *host = EmptyString(aconf->host) ? null : aconf->host; - *reason = EmptyString(aconf->passwd) ? null : aconf->passwd; - *user = EmptyString(aconf->user) ? null : aconf->user; - - if(EmptyString(aconf->spasswd) || !IsOper(source_p)) - *oper_reason = NULL; - else - *oper_reason = aconf->spasswd; +void +get_printable_kline(struct Client *source_p, struct ConfItem *aconf, + char **host, char **reason, + char **user, char **oper_reason) +{ + static char null[] = ""; + + *host = EmptyString(aconf->host) ? null : aconf->host; + *reason = EmptyString(aconf->passwd) ? null : aconf->passwd; + *user = EmptyString(aconf->user) ? null : aconf->user; + + if(EmptyString(aconf->spasswd) || !IsOper(source_p)) + *oper_reason = NULL; + else + *oper_reason = aconf->spasswd; } /* diff --git a/src/s_log.c b/src/s_log.c index b48ee6fc..3cafbf0e 100644 --- a/src/s_log.c +++ b/src/s_log.c @@ -148,7 +148,7 @@ inotice(const char *format, ...) va_list args; va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); + ircvsnprintf(buf, sizeof(buf), format, args); va_end(args); _iprint("notice", buf); @@ -163,7 +163,7 @@ iwarn(const char *format, ...) va_list args; va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); + ircvsnprintf(buf, sizeof(buf), format, args); va_end(args); _iprint("warning", buf); @@ -178,7 +178,7 @@ ierror(const char *format, ...) va_list args; va_start(args, format); - rb_vsnprintf(buf, sizeof(buf), format, args); + ircvsnprintf(buf, sizeof(buf), format, args); va_end(args); _iprint("error", buf); diff --git a/src/s_newconf.c b/src/s_newconf.c index c73db3df..222a32e0 100644 --- a/src/s_newconf.c +++ b/src/s_newconf.c @@ -284,7 +284,7 @@ struct oper_conf * find_oper_conf(const char *username, const char *host, const char *locip, const char *name) { struct oper_conf *oper_p; - struct rb_sockaddr_storage ip, cip; + struct irc_sockaddr_storage ip, cip; char addr[HOSTLEN+1]; int bits, cbits; rb_dlink_node *ptr; diff --git a/src/s_serv.c b/src/s_serv.c index 73b9fec5..cd3a90f1 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -1030,7 +1030,7 @@ server_estab(struct Client *client_p) { if(client_p != serv_list.head->data || serv_list.head->next) { - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one(client_p, "ERROR :I'm a leaf not a hub"); return exit_client(client_p, client_p, client_p, "I'm a leaf"); } @@ -1469,7 +1469,7 @@ int serv_connect(struct server_conf *server_p, struct Client *by) { struct Client *client_p; - struct rb_sockaddr_storage myipnum; + struct irc_sockaddr_storage myipnum; int fd; char vhoststr[HOSTIPLEN]; diff --git a/src/s_stats.c b/src/s_stats.c index 86bf37f6..c972293a 100644 --- a/src/s_stats.c +++ b/src/s_stats.c @@ -41,7 +41,126 @@ /* * stats stuff */ -struct ServerStatistics ServerStats; +static struct ServerStatistics ircst; +struct ServerStatistics *ServerStats = &ircst; + +void +init_stats() +{ + memset(&ircst, 0, sizeof(ircst)); +} + +/* + * tstats + * + * inputs - client to report to + * output - NONE + * side effects - + */ +void +tstats(struct Client *source_p) +{ + struct Client *target_p; + struct ServerStatistics *sp; + struct ServerStatistics tmp; + rb_dlink_node *ptr; + + sp = &tmp; + memcpy(sp, ServerStats, sizeof(struct ServerStatistics)); + + RB_DLINK_FOREACH(ptr, serv_list.head) + { + target_p = ptr->data; + + sp->is_sbs += target_p->localClient->sendB; + sp->is_sbr += target_p->localClient->receiveB; + sp->is_sks += target_p->localClient->sendK; + sp->is_skr += target_p->localClient->receiveK; + sp->is_sti += rb_current_time() - target_p->localClient->firsttime; + sp->is_sv++; + if(sp->is_sbs > 1023) + { + sp->is_sks += (sp->is_sbs >> 10); + sp->is_sbs &= 0x3ff; + } + if(sp->is_sbr > 1023) + { + sp->is_skr += (sp->is_sbr >> 10); + sp->is_sbr &= 0x3ff; + } + } + + RB_DLINK_FOREACH(ptr, lclient_list.head) + { + target_p = ptr->data; + + sp->is_cbs += target_p->localClient->sendB; + sp->is_cbr += target_p->localClient->receiveB; + sp->is_cks += target_p->localClient->sendK; + sp->is_ckr += target_p->localClient->receiveK; + sp->is_cti += rb_current_time() - target_p->localClient->firsttime; + sp->is_cl++; + if(sp->is_cbs > 1023) + { + sp->is_cks += (sp->is_cbs >> 10); + sp->is_cbs &= 0x3ff; + } + if(sp->is_cbr > 1023) + { + sp->is_ckr += (sp->is_cbr >> 10); + sp->is_cbr &= 0x3ff; + } + + } + + RB_DLINK_FOREACH(ptr, unknown_list.head) + { + sp->is_ni++; + } + + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :accepts %u refused %u", sp->is_ac, sp->is_ref); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :rejected %u delaying %lu", + sp->is_rej, rb_dlink_list_length(&delay_exit)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :nicks being delayed %lu", + get_nd_count()); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :unknown commands %u prefixes %u", + sp->is_unco, sp->is_unpf); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :nick collisions %u saves %u unknown closes %u", + sp->is_kill, sp->is_save, sp->is_ni); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :wrong direction %u empty %u", + sp->is_wrdi, sp->is_empt); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :numerics seen %u", sp->is_num); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :tgchange blocked msgs %u restricted addrs %lu", + sp->is_tgch, rb_dlink_list_length(&tgchange_list)); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :auth successes %u fails %u", + sp->is_asuc, sp->is_abad); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :sasl successes %u fails %u", + sp->is_ssuc, sp->is_sbad); + sendto_one_numeric(source_p, RPL_STATSDEBUG, "T :Client Server"); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :connected %u %u", sp->is_cl, sp->is_sv); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :bytes sent %d.%uK %d.%uK", + (int) sp->is_cks, sp->is_cbs, + (int) sp->is_sks, sp->is_sbs); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :bytes recv %d.%uK %d.%uK", + (int) sp->is_ckr, sp->is_cbr, + (int) sp->is_skr, sp->is_sbr); + sendto_one_numeric(source_p, RPL_STATSDEBUG, + "T :time connected %d %d", + (int) sp->is_cti, (int) sp->is_sti); +} void count_memory(struct Client *source_p) diff --git a/src/s_user.c b/src/s_user.c index 1d385e17..2428c856 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -323,7 +323,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char if(IsNeedIdentd(aconf)) { - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one_notice(source_p, ":*** Notice -- You need to install identd to use this server"); exit_client(client_p, source_p, &me, "Install identd"); return (CLIENT_EXITED); @@ -350,7 +350,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char if(IsNeedSasl(aconf) && !*user->suser) { - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one_notice(source_p, ":*** Notice -- You need to identify via SASL to use this server"); exit_client(client_p, source_p, &me, "SASL access only"); return (CLIENT_EXITED); @@ -370,7 +370,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char if(strcmp(encr, aconf->passwd)) { - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); exit_client(client_p, source_p, &me, "Bad Password"); return (CLIENT_EXITED); @@ -404,7 +404,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char sendto_realops_snomask(SNO_FULL, L_ALL, "Too many clients, rejecting %s[%s].", source_p->name, source_p->host); - ServerStats.is_ref++; + ServerStats->is_ref++; exit_client(client_p, source_p, &me, "Sorry, server is full - try later"); return (CLIENT_EXITED); } @@ -413,8 +413,8 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char if(!IsExemptKline(source_p) && (xconf = find_xline(source_p->info, 1)) != NULL) { - ServerStats.is_ref++; - add_reject(source_p); + ServerStats->is_ref++; + add_reject(source_p, xconf->name, NULL); exit_client(client_p, source_p, &me, "Bad user info"); return CLIENT_EXITED; } @@ -435,7 +435,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char substitution_append_var(&varlist, "dnsbl-host", source_p->preClient->dnsbl_listed->host); substitution_append_var(&varlist, "network-name", ServerInfo.network_name); - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one(source_p, form_str(ERR_YOUREBANNEDCREEP), me.name, source_p->name, @@ -446,7 +446,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char sendto_one_notice(source_p, ":*** Your IP address %s is listed in %s", source_p->sockhost, source_p->preClient->dnsbl_listed->host); source_p->preClient->dnsbl_listed->hits++; - add_reject(source_p); + add_reject(source_p, NULL, NULL); exit_client(client_p, source_p, &me, "*** Banned (DNS blacklist)"); return CLIENT_EXITED; } @@ -459,7 +459,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char sendto_realops_snomask(SNO_REJ, L_ALL, "Invalid username: %s (%s@%s)", source_p->name, source_p->username, source_p->host); - ServerStats.is_ref++; + ServerStats->is_ref++; sendto_one_notice(source_p, ":*** Your username is invalid. Please make sure that your username contains " "only alphanumeric characters."); rb_sprintf(tmpstr2, "Invalid username [%s]", source_p->username); @@ -526,6 +526,7 @@ register_local_user(struct Client *client_p, struct Client *source_p, const char Count.invisi++; s_assert(!IsClient(source_p)); + del_unknown_ip(source_p); rb_dlinkMoveNode(&source_p->localClient->tnode, &unknown_list, &lclient_list); SetClient(source_p); diff --git a/ssld/Makefile.am b/ssld/Makefile.am deleted file mode 100644 index f6aeb4c7..00000000 --- a/ssld/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -# -# $Id: Makefile.am 24818 2008-01-02 18:38:26Z androsyn $ -# -bin_PROGRAMS = ssld -AM_CFLAGS=$(WARNFLAGS) - -INCLUDES = -I../include -I../libratbox/include - - -ssld_SOURCES = ssld.c - -ssld_LDADD = ../libratbox/src/libratbox.la @ZLIB_LD@ - - diff --git a/ssld/Makefile.in b/ssld/Makefile.in deleted file mode 100644 index 7504608c..00000000 --- a/ssld/Makefile.in +++ /dev/null @@ -1,499 +0,0 @@ -# Makefile.in generated by automake 1.10.1 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -bin_PROGRAMS = ssld$(EXEEXT) -subdir = ssld -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \ - $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs -CONFIG_HEADER = $(top_builddir)/include/setup.h -CONFIG_CLEAN_FILES = -am__installdirs = "$(DESTDIR)$(bindir)" -binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) -PROGRAMS = $(bin_PROGRAMS) -am_ssld_OBJECTS = ssld.$(OBJEXT) -ssld_OBJECTS = $(am_ssld_OBJECTS) -ssld_DEPENDENCIES = ../libratbox/src/libratbox.la -DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)/include -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -CCLD = $(CC) -LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \ - --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \ - $(LDFLAGS) -o $@ -SOURCES = $(ssld_SOURCES) -DIST_SOURCES = $(ssld_SOURCES) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -ALLOCA = @ALLOCA@ -AMTAR = @AMTAR@ -AR = @AR@ -AS = @AS@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CP = @CP@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DSYMUTIL = @DSYMUTIL@ -ECHO = @ECHO@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -ETC_DIR = @ETC_DIR@ -EXEEXT = @EXEEXT@ -F77 = @F77@ -FFLAGS = @FFLAGS@ -GREP = @GREP@ -HELP_DIR = @HELP_DIR@ -INCLTDL = @INCLTDL@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -IRCD_PREFIX = @IRCD_PREFIX@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LEX = @LEX@ -LEXLIB = @LEXLIB@ -LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@ -LIBLTDL = @LIBLTDL@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LN = @LN@ -LN_S = @LN_S@ -LOG_DIR = @LOG_DIR@ -LTLIBOBJS = @LTLIBOBJS@ -LT_OBJDIR = @LT_OBJDIR@ -MAINT = @MAINT@ -MAKEINFO = @MAKEINFO@ -MKDIR_P = @MKDIR_P@ -MODULE_DIR = @MODULE_DIR@ -MV = @MV@ -NMEDIT = @NMEDIT@ -OBJEXT = @OBJEXT@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -PICFLAGS = @PICFLAGS@ -RANLIB = @RANLIB@ -RM = @RM@ -SED = @SED@ -SEDOBJ = @SEDOBJ@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -SHLIBEXT = @SHLIBEXT@ -SQLITE_INCLUDES = @SQLITE_INCLUDES@ -SQLITE_LD = @SQLITE_LD@ -SQLITE_SUBDIR = @SQLITE_SUBDIR@ -SSL_INCLUDES = @SSL_INCLUDES@ -SSL_LIBS = @SSL_LIBS@ -SSL_SRCS_ENABLE = @SSL_SRCS_ENABLE@ -STRIP = @STRIP@ -TOUCH = @TOUCH@ -VERSION = @VERSION@ -WARNFLAGS = @WARNFLAGS@ -YACC = @YACC@ -YFLAGS = @YFLAGS@ -ZLIB_LD = @ZLIB_LD@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_F77 = @ac_ct_F77@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -confdir = @confdir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -helpdir = @helpdir@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -logdir = @logdir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -moduledir = @moduledir@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -subdirs = @subdirs@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -AM_CFLAGS = $(WARNFLAGS) -INCLUDES = -I../include -I../libratbox/include -ssld_SOURCES = ssld.c -ssld_LDADD = ../libratbox/src/libratbox.la @ZLIB_LD@ -all: all-am - -.SUFFIXES: -.SUFFIXES: .c .lo .o .obj -$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \ - && exit 0; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu ssld/Makefile'; \ - cd $(top_srcdir) && \ - $(AUTOMAKE) --gnu ssld/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -install-binPROGRAMS: $(bin_PROGRAMS) - @$(NORMAL_INSTALL) - test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)" - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - if test -f $$p \ - || test -f $$p1 \ - ; then \ - f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \ - $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \ - else :; fi; \ - done - -uninstall-binPROGRAMS: - @$(NORMAL_UNINSTALL) - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \ - echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \ - rm -f "$(DESTDIR)$(bindir)/$$f"; \ - done - -clean-binPROGRAMS: - @list='$(bin_PROGRAMS)'; for p in $$list; do \ - f=`echo $$p|sed 's/$(EXEEXT)$$//'`; \ - echo " rm -f $$p $$f"; \ - rm -f $$p $$f ; \ - done -ssld$(EXEEXT): $(ssld_OBJECTS) $(ssld_DEPENDENCIES) - @rm -f ssld$(EXEEXT) - $(LINK) $(ssld_OBJECTS) $(ssld_LDADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ssld.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c $< - -.c.obj: -@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$tags $$unique; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - tags=; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$tags$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$tags $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && cd $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) $$here - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ - fi; \ - cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ - else \ - test -f $(distdir)/$$file \ - || cp -p $$d/$$file $(distdir)/$$file \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: check-am -all-am: Makefile $(PROGRAMS) -installdirs: - for dir in "$(DESTDIR)$(bindir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." -clean: clean-am - -clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -info: info-am - -info-am: - -install-data-am: - -install-dvi: install-dvi-am - -install-exec-am: install-binPROGRAMS - -install-html: install-html-am - -install-info: install-info-am - -install-man: - -install-pdf: install-pdf-am - -install-ps: install-ps-am - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-binPROGRAMS - -.MAKE: install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \ - clean-generic clean-libtool ctags distclean distclean-compile \ - distclean-generic distclean-libtool distclean-tags distdir dvi \ - dvi-am html html-am info info-am install install-am \ - install-binPROGRAMS install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip installcheck installcheck-am installdirs \ - maintainer-clean maintainer-clean-generic mostlyclean \ - mostlyclean-compile mostlyclean-generic mostlyclean-libtool \ - pdf pdf-am ps ps-am tags uninstall uninstall-am \ - uninstall-binPROGRAMS - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/ssld/ssld.c b/ssld/ssld.c deleted file mode 100644 index 238201cb..00000000 --- a/ssld/ssld.c +++ /dev/null @@ -1,1096 +0,0 @@ -/* - * ssld.c: The ircd-ratbox ssl/zlib helper daemon thingy - * Copyright (C) 2007 Aaron Sethman - * Copyright (C) 2007 ircd-ratbox development team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 - * USA - * - * $Id: ssld.c 25179 2008-03-30 16:34:57Z androsyn $ - */ - - -#include "stdinc.h" - -#ifdef HAVE_ZLIB -#include -#endif - -#define MAXPASSFD 4 -#ifndef READBUF_SIZE -#define READBUF_SIZE 16384 -#endif - -static void setup_signals(void); - -static inline rb_int32_t buf_to_int32(char *buf) -{ - rb_int32_t x; - x = *buf << 24; - x |= *(++buf) << 16; - x |= *(++buf) << 8; - x |= *(++buf); - return x; -} - -static inline void int32_to_buf(char *buf, rb_int32_t x) -{ - *(buf) = x >> 24 & 0xFF; - *(++buf) = x >> 16 & 0xFF; - *(++buf) = x >> 8 & 0xFF; - *(++buf) = x & 0xFF; - return; -} - -static inline rb_uint16_t buf_to_uint16(char *buf) -{ - rb_uint16_t x; - x = *(buf) << 8; - x |= *(++buf); - return x; -} - -static inline void uint16_to_buf(char *buf, rb_uint16_t x) -{ - *(buf) = x >> 8 & 0xFF; - *(++buf) = x & 0xFF; - return; -} - - - -static char inbuf[READBUF_SIZE]; -static char outbuf[READBUF_SIZE]; - -typedef struct _mod_ctl_buf -{ - rb_dlink_node node; - char *buf; - size_t buflen; - rb_fde_t *F[MAXPASSFD]; - int nfds; -} mod_ctl_buf_t; - -typedef struct _mod_ctl -{ - rb_dlink_node node; - int cli_count; - rb_fde_t *F; - rb_fde_t *F_pipe; - rb_dlink_list readq; - rb_dlink_list writeq; -} mod_ctl_t; - -static mod_ctl_t *mod_ctl; - - -#ifdef HAVE_ZLIB -typedef struct _zlib_stream -{ - z_stream instream; - z_stream outstream; -} zlib_stream_t; -#endif - -typedef struct _conn -{ - rb_dlink_node node; - mod_ctl_t *ctl; - rawbuf_head_t *modbuf_out; - rawbuf_head_t *plainbuf_out; - - rb_int32_t id; - - rb_fde_t *mod_fd; - rb_fde_t *plain_fd; - unsigned long long mod_out; - unsigned long long mod_in; - unsigned long long plain_in; - unsigned long long plain_out; - rb_uint8_t flags; - void *stream; -} conn_t; - -#define FLAG_SSL 0x01 -#define FLAG_ZIP 0x02 -#define FLAG_CORK 0x04 -#define FLAG_DEAD 0x08 - - -#define IsSSL(x) ((x)->flags & FLAG_SSL) -#define IsZip(x) ((x)->flags & FLAG_ZIP) -#define IsCork(x) ((x)->flags & FLAG_CORK) -#define IsDead(x) ((x)->flags & FLAG_DEAD) - -#define SetSSL(x) ((x)->flags |= FLAG_SSL) -#define SetZip(x) ((x)->flags |= FLAG_ZIP) -#define SetCork(x) ((x)->flags |= FLAG_CORK) -#define SetDead(x) ((x)->flags |= FLAG_DEAD) - -#define ClearSSL(x) ((x)->flags &= ~FLAG_SSL) -#define ClearZip(x) ((x)->flags &= ~FLAG_ZIP) -#define ClearCork(x) ((x)->flags &= ~FLAG_CORK) -#define ClearDead(x) ((x)->flags &= ~FLAG_DEAD) - -#define NO_WAIT 0x0 -#define WAIT_PLAIN 0x1 - -#define CONN_HASH_SIZE 2000 -#define connid_hash(x) (&connid_hash_table[(x % CONN_HASH_SIZE)]) - -static rb_dlink_list connid_hash_table[CONN_HASH_SIZE]; -static rb_dlink_list dead_list; - -static void conn_mod_write_sendq(rb_fde_t *, void *data); -static void conn_plain_write_sendq(rb_fde_t *, void *data); -static void mod_write_ctl(rb_fde_t *, void *data); -static void conn_plain_read_cb(rb_fde_t * fd, void *data); -static void mod_cmd_write_queue(mod_ctl_t *ctl, const void *data, size_t len); -static const char *remote_closed = "Remote host closed the connection"; -static int ssl_ok; -#ifdef HAVE_ZLIB -static int zlib_ok = 1; -#else -static int zlib_ok = 0; -#endif -static void * -ssld_alloc(void *unused, size_t count, size_t size) -{ - return rb_malloc(count * size); -} - -static void -ssld_free(void *unused, void *ptr) -{ - rb_free(ptr); -} - -static conn_t * -conn_find_by_id(rb_int32_t id) -{ - rb_dlink_node *ptr; - conn_t *conn; - - RB_DLINK_FOREACH(ptr, (connid_hash(id))->head) - { - conn = ptr->data; - if(conn->id == id && !IsDead(conn)) - return conn; - } - return NULL; -} - -static void -conn_add_id_hash(conn_t * conn, rb_int32_t id) -{ - conn->id = id; - rb_dlinkAdd(conn, &conn->node, connid_hash(id)); -} - -static void -free_conn(conn_t * conn) -{ - rb_free_rawbuffer(conn->modbuf_out); - rb_free_rawbuffer(conn->plainbuf_out); - if(IsZip(conn)) - { - zlib_stream_t *stream = conn->stream; - inflateEnd(&stream->instream); - deflateEnd(&stream->outstream); - } - rb_free(conn); -} - -static void -clean_dead_conns(void *unused) -{ - conn_t *conn; - rb_dlink_node *ptr, *next; - RB_DLINK_FOREACH_SAFE(ptr, next, dead_list.head) - { - conn = ptr->data; - free_conn(conn); - } - dead_list.tail = dead_list.head = NULL; -} - - -static void -close_conn(conn_t * conn, int wait_plain, const char *fmt, ...) -{ - va_list ap; - char reason[128]; /* must always be under 250 bytes */ - char buf[256]; - int len; - if(IsDead(conn)) - return; - - rb_rawbuf_flush(conn->modbuf_out, conn->mod_fd); - rb_rawbuf_flush(conn->plainbuf_out, conn->plain_fd); - rb_close(conn->mod_fd); - SetDead(conn); - - if(!wait_plain || fmt == NULL) - { - rb_close(conn->plain_fd); - - if(conn->id >= 0) - rb_dlinkDelete(&conn->node, connid_hash(conn->id)); - rb_dlinkAdd(conn, &conn->node, &dead_list); - return; - } - rb_setselect(conn->plain_fd, RB_SELECT_WRITE|RB_SELECT_READ, NULL, NULL); - va_start(ap, fmt); - rb_vsnprintf(reason, sizeof(reason), fmt, ap); - va_end(ap); - - buf[0] = 'D'; - int32_to_buf(&buf[1], conn->id); - strcpy(&buf[5], reason); - len = (strlen(reason) + 1) + 5; - mod_cmd_write_queue(conn->ctl, buf, len); -} - -static conn_t * -make_conn(mod_ctl_t *ctl, rb_fde_t * mod_fd, rb_fde_t * plain_fd) -{ - conn_t *conn = rb_malloc(sizeof(conn_t)); - conn->ctl = ctl; - conn->modbuf_out = rb_new_rawbuffer(); - conn->plainbuf_out = rb_new_rawbuffer(); - conn->mod_fd = mod_fd; - conn->plain_fd = plain_fd; - conn->id = -1; - conn->stream = NULL; - rb_set_nb(mod_fd); - rb_set_nb(plain_fd); - return conn; -} - -static void -conn_mod_write_sendq(rb_fde_t * fd, void *data) -{ - conn_t *conn = data; - const char *err; - int retlen; - if(IsDead(conn)) - return; - - while ((retlen = rb_rawbuf_flush(conn->modbuf_out, fd)) > 0) - conn->mod_out += retlen; - - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - if(retlen == 0) - close_conn(conn, WAIT_PLAIN, "%s", remote_closed); - if(IsSSL(conn) && retlen == RB_RW_SSL_ERROR) - err = rb_get_ssl_strerror(conn->mod_fd); - else - err = strerror(errno); - close_conn(conn, WAIT_PLAIN, "Write error: %s", err); - return; - } - if(rb_rawbuf_length(conn->modbuf_out) > 0) - { - int flags = RB_SELECT_WRITE; - if(retlen == RB_RW_SSL_NEED_READ) - flags |= RB_SELECT_READ; - - rb_setselect(conn->mod_fd, flags, conn_mod_write_sendq, conn); - } - else - rb_setselect(conn->mod_fd, RB_SELECT_WRITE, NULL, NULL); - - if(IsCork(conn) && rb_rawbuf_length(conn->modbuf_out) == 0) - { - ClearCork(conn); - conn_plain_read_cb(conn->plain_fd, conn); - } - -} - -static void -conn_mod_write(conn_t * conn, void *data, size_t len) -{ - if(IsDead(conn)) /* no point in queueing to a dead man */ - return; - rb_rawbuf_append(conn->modbuf_out, data, len); -} - -static void -conn_plain_write(conn_t * conn, void *data, size_t len) -{ - if(IsDead(conn)) /* again no point in queueing to dead men */ - return; - rb_rawbuf_append(conn->plainbuf_out, data, len); -} - -static void -mod_cmd_write_queue(mod_ctl_t * ctl, const void *data, size_t len) -{ - mod_ctl_buf_t *ctl_buf; - ctl_buf = rb_malloc(sizeof(mod_ctl_buf_t)); - ctl_buf->buf = rb_malloc(len); - ctl_buf->buflen = len; - memcpy(ctl_buf->buf, data, len); - ctl_buf->nfds = 0; - rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->writeq); - mod_write_ctl(ctl->F, ctl); -} - -#ifdef HAVE_ZLIB -static void -common_zlib_deflate(conn_t * conn, void *buf, size_t len) -{ - int ret, have; - z_stream *outstream = &((zlib_stream_t *)conn->stream)->outstream; - outstream->next_in = buf; - outstream->avail_in = len; - outstream->next_out = (Bytef *) outbuf; - outstream->avail_out = sizeof(outbuf); - - ret = deflate(outstream, Z_SYNC_FLUSH); - if(ret != Z_OK) - { - /* deflate error */ - close_conn(conn, WAIT_PLAIN, "Deflate failed: %s", zError(ret)); - return; - } - if(outstream->avail_out == 0) - { - /* avail_out empty */ - close_conn(conn, WAIT_PLAIN, "error compressing data, avail_out == 0"); - return; - } - if(outstream->avail_in != 0) - { - /* avail_in isn't empty...*/ - close_conn(conn, WAIT_PLAIN, "error compressing data, avail_in != 0"); - return; - } - have = sizeof(outbuf) - outstream->avail_out; - conn_mod_write(conn, outbuf, have); -} - -static void -common_zlib_inflate(conn_t * conn, void *buf, size_t len) -{ - int ret, have; - ((zlib_stream_t *)conn->stream)->instream.next_in = buf; - ((zlib_stream_t *)conn->stream)->instream.avail_in = len; - ((zlib_stream_t *)conn->stream)->instream.next_out = (Bytef *) outbuf; - ((zlib_stream_t *)conn->stream)->instream.avail_out = sizeof(outbuf); - - while (((zlib_stream_t *)conn->stream)->instream.avail_in) - { - ret = inflate(&((zlib_stream_t *)conn->stream)->instream, Z_NO_FLUSH); - if(ret != Z_OK) - { - if(!strncmp("ERROR ", buf, 6)) - { - close_conn(conn, WAIT_PLAIN, "Received uncompressed ERROR"); - return; - } - close_conn(conn, WAIT_PLAIN, "Inflate failed: %s", zError(ret)); - return; - } - have = sizeof(outbuf) - ((zlib_stream_t *)conn->stream)->instream.avail_out; - - if(((zlib_stream_t *)conn->stream)->instream.avail_in) - { - conn_plain_write(conn, outbuf, have); - have = 0; - ((zlib_stream_t *)conn->stream)->instream.next_out = (Bytef *) outbuf; - ((zlib_stream_t *)conn->stream)->instream.avail_out = sizeof(outbuf); - } - } - if(have == 0) - return; - - conn_plain_write(conn, outbuf, have); -} -#endif - -static int -plain_check_cork(conn_t * conn) -{ - if(rb_rawbuf_length(conn->modbuf_out) >= 4096) - { - /* if we have over 4k pending outbound, don't read until - * we've cleared the queue */ - SetCork(conn); - rb_setselect(conn->plain_fd, RB_SELECT_READ, NULL, NULL); - /* try to write */ - conn_mod_write_sendq(conn->mod_fd, conn); - return 1; - } - return 0; -} - - -static void -conn_plain_read_cb(rb_fde_t * fd, void *data) -{ - conn_t *conn = data; - int length = 0; - if(conn == NULL) - return; - - if(IsDead(conn)) - return; - - if(plain_check_cork(conn)) - return; - - while (1) - { - if(IsDead(conn)) - return; - - length = rb_read(conn->plain_fd, inbuf, sizeof(inbuf)); - - if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) - { - close_conn(conn, NO_WAIT, NULL); - return; - } - - if(length < 0) - { - rb_setselect(conn->plain_fd, RB_SELECT_READ, conn_plain_read_cb, conn); - conn_mod_write_sendq(conn->mod_fd, conn); - return; - } - conn->plain_in += length; - -#ifdef HAVE_ZLIB - if(IsZip(conn)) - common_zlib_deflate(conn, inbuf, length); - else -#endif - conn_mod_write(conn, inbuf, length); - if(IsDead(conn)) - return; - if(plain_check_cork(conn)) - return; - } -} - -static void -conn_mod_read_cb(rb_fde_t * fd, void *data) -{ - conn_t *conn = data; - const char *err = remote_closed; - int length; - if(conn == NULL) - return; - if(IsDead(conn)) - return; - - while (1) - { - if(IsDead(conn)) - return; - - length = rb_read(conn->mod_fd, inbuf, sizeof(inbuf)); - - if(length == 0 || (length < 0 && !rb_ignore_errno(errno))) - { - if(length == 0) { - close_conn(conn, WAIT_PLAIN, "%s", remote_closed); - return; - } - - if(IsSSL(conn) && length == RB_RW_SSL_ERROR) - err = rb_get_ssl_strerror(conn->mod_fd); - else - err = strerror(errno); - close_conn(conn, WAIT_PLAIN, "Read error: %s", err); - return; - } - if(length < 0) - { - int flags = RB_SELECT_READ; - if(length == RB_RW_SSL_NEED_WRITE) - flags |= RB_SELECT_WRITE; - - rb_setselect(conn->mod_fd, flags, conn_mod_read_cb, conn); - conn_plain_write_sendq(conn->plain_fd, conn); - return; - } - conn->mod_in += length; -#ifdef HAVE_ZLIB - if(IsZip(conn)) - common_zlib_inflate(conn, inbuf, length); - else -#endif - conn_plain_write(conn, inbuf, length); - } -} - -static void -conn_plain_write_sendq(rb_fde_t * fd, void *data) -{ - conn_t *conn = data; - int retlen; - - if(IsDead(conn)) - return; - - while ((retlen = rb_rawbuf_flush(conn->plainbuf_out, fd)) > 0) - { - conn->plain_out += retlen; - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - { - close_conn(data, NO_WAIT, NULL); - return; - } - - - if(rb_rawbuf_length(conn->plainbuf_out) > 0) - rb_setselect(conn->plain_fd, RB_SELECT_WRITE, conn_plain_write_sendq, conn); - else - rb_setselect(conn->plain_fd, RB_SELECT_WRITE, NULL, NULL); -} - -static int -maxconn(void) -{ -#if defined(RLIMIT_NOFILE) && defined(HAVE_SYS_RESOURCE_H) - struct rlimit limit; - - if(!getrlimit(RLIMIT_NOFILE, &limit)) - { - return limit.rlim_cur; - } -#endif /* RLIMIT_FD_MAX */ - return MAXCONNECTIONS; -} - -static void -ssl_process_accept_cb(rb_fde_t * F, int status, struct sockaddr *addr, rb_socklen_t len, void *data) -{ - conn_t *conn = data; - if(status == RB_OK) - { - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - return; - } - close_conn(conn, NO_WAIT, 0); - return; -} - -static void -ssl_process_connect_cb(rb_fde_t * F, int status, void *data) -{ - conn_t *conn = data; - if(status == RB_OK) - { - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - return; - } - close_conn(conn, NO_WAIT, 0); - return; -} - - -static void -ssl_process_accept(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) -{ - conn_t *conn; - rb_int32_t id; - - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - - id = buf_to_int32(&ctlb->buf[1]); - - if(id >= 0) - conn_add_id_hash(conn, id); - SetSSL(conn); - - if(rb_get_type(conn->mod_fd) & RB_FD_UNKNOWN) - { - - rb_set_type(conn->mod_fd, RB_FD_SOCKET); - } - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); - - rb_ssl_start_accepted(ctlb->F[0], ssl_process_accept_cb, conn, 10); -} - -static void -ssl_process_connect(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) -{ - conn_t *conn; - rb_int32_t id; - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - - id = buf_to_int32(&ctlb->buf[1]); - - if(id >= 0) - conn_add_id_hash(conn, id); - SetSSL(conn); - - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->mod_fd, RB_FD_SOCKET); - - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); - - - rb_ssl_start_connected(ctlb->F[0], ssl_process_connect_cb, conn, 10); -} - -static void -process_stats(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) -{ - char outstat[512]; - conn_t *conn; - const char *odata; - rb_int32_t id; - - id = buf_to_int32(&ctlb->buf[1]); - - if(id < 0) - return; - - odata = &ctlb->buf[5]; - conn = conn_find_by_id(id); - - if(conn == NULL) - return; - - rb_snprintf(outstat, sizeof(outstat), "S %s %llu %llu %llu %llu", odata, - conn->plain_out, conn->mod_in, conn->plain_in, conn->mod_out); - conn->plain_out = 0; - conn->plain_in = 0; - conn->mod_in = 0; - conn->mod_out = 0; - mod_cmd_write_queue(ctl, outstat, strlen(outstat) + 1); /* +1 is so we send the \0 as well */ -} - -#ifdef HAVE_ZLIB -static void -zlib_send_zip_ready(mod_ctl_t *ctl, conn_t *conn) -{ - char buf[5]; - - buf[0] = 'R'; - int32_to_buf(&buf[1], conn->id); - mod_cmd_write_queue(conn->ctl, buf, sizeof(buf)); -} - -static void -zlib_process(mod_ctl_t * ctl, mod_ctl_buf_t * ctlb) -{ - rb_uint8_t level; - size_t recvqlen; - size_t hdr = (sizeof(rb_uint8_t) * 2) + sizeof(rb_int32_t); - void *recvq_start; - z_stream *instream, *outstream; - conn_t *conn; - rb_int32_t id; - - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - if(rb_get_type(conn->mod_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->mod_fd, RB_FD_SOCKET); - - if(rb_get_type(conn->plain_fd) == RB_FD_UNKNOWN) - rb_set_type(conn->plain_fd, RB_FD_SOCKET); - - id = buf_to_int32(&ctlb->buf[1]); - conn_add_id_hash(conn, id); - - level = (rb_uint8_t) ctlb->buf[5]; - - recvqlen = ctlb->buflen - hdr; - recvq_start = &ctlb->buf[6]; - - SetZip(conn); - conn->stream = rb_malloc(sizeof(zlib_stream_t)); - instream = &((zlib_stream_t *)conn->stream)->instream; - outstream = &((zlib_stream_t *)conn->stream)->outstream; - - instream->total_in = 0; - instream->total_out = 0; - instream->zalloc = (alloc_func) ssld_alloc; - instream->zfree = (free_func) ssld_free; - instream->data_type = Z_ASCII; - inflateInit(&((zlib_stream_t *)conn->stream)->instream); - - outstream->total_in = 0; - outstream->total_out = 0; - outstream->zalloc = (alloc_func) ssld_alloc; - outstream->zfree = (free_func) ssld_free; - outstream->data_type = Z_ASCII; - - if(level > 9) - level = Z_DEFAULT_COMPRESSION; - - deflateInit(&((zlib_stream_t *)conn->stream)->outstream, level); - if(recvqlen > 0) - common_zlib_inflate(conn, recvq_start, recvqlen); - zlib_send_zip_ready(ctl, conn); - conn_mod_read_cb(conn->mod_fd, conn); - conn_plain_read_cb(conn->plain_fd, conn); - return; - -} -#endif - -static void -init_prng(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf) -{ - char *path; - prng_seed_t seed_type; - - seed_type = (prng_seed_t)ctl_buf->buf[1]; - path = &ctl_buf->buf[2]; - rb_init_prng(path, seed_type); -} - - -static void -ssl_new_keys(mod_ctl_t * ctl, mod_ctl_buf_t * ctl_buf) -{ - char *buf; - char *cert, *key, *dhparam; - - buf = &ctl_buf->buf[2]; - cert = buf; - buf += strlen(cert) + 1; - key = buf; - buf += strlen(key) + 1; - dhparam = buf; - if(strlen(dhparam) == 0) - dhparam = NULL; - - if(!rb_setup_ssl_server(cert, key, dhparam)) - { - const char *invalid = "I"; - mod_cmd_write_queue(ctl, invalid, strlen(invalid)); - return; - } -} - -static void -send_nossl_support(mod_ctl_t *ctl, mod_ctl_buf_t *ctlb) -{ - static const char *nossl_cmd = "N"; - conn_t *conn; - rb_int32_t id; - - if(ctlb != NULL) - { - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); - - if(id >= 0) - conn_add_id_hash(conn, id); - close_conn(conn, WAIT_PLAIN, "libratbox reports no SSL/TLS support"); - } - mod_cmd_write_queue(ctl, nossl_cmd, strlen(nossl_cmd)); -} - -static void -send_i_am_useless(mod_ctl_t *ctl) -{ - static const char *useless = "U"; - mod_cmd_write_queue(ctl, useless, strlen(useless)); -} - -static void -send_nozlib_support(mod_ctl_t *ctl, mod_ctl_buf_t *ctlb) -{ - static const char *nozlib_cmd = "z"; - conn_t *conn; - rb_int32_t id; - if(ctlb != NULL) - { - conn = make_conn(ctl, ctlb->F[0], ctlb->F[1]); - id = buf_to_int32(&ctlb->buf[1]); - - if(id >= 0) - conn_add_id_hash(conn, id); - close_conn(conn, WAIT_PLAIN, "libratbox reports no zlib support"); - } - mod_cmd_write_queue(ctl, nozlib_cmd, strlen(nozlib_cmd)); -} - -static void -mod_process_cmd_recv(mod_ctl_t * ctl) -{ - rb_dlink_node *ptr, *next; - mod_ctl_buf_t *ctl_buf; - - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->readq.head) - { - ctl_buf = ptr->data; - - switch (*ctl_buf->buf) - { - case 'A': - { - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_process_accept(ctl, ctl_buf); - break; - } - case 'C': - { - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_process_connect(ctl, ctl_buf); - break; - } - - case 'K': - { - if(!ssl_ok) - { - send_nossl_support(ctl, ctl_buf); - break; - } - ssl_new_keys(ctl, ctl_buf); - break; - } - case 'I': - init_prng(ctl, ctl_buf); - break; - case 'S': - { - process_stats(ctl, ctl_buf); - break; - } -#ifdef HAVE_ZLIB - case 'Z': - { - /* just zlib only */ - zlib_process(ctl, ctl_buf); - break; - } -#else - case 'Y': - case 'Z': - send_nozlib_support(ctl); - break; - -#endif - default: - break; - /* Log unknown commands */ - } - rb_dlinkDelete(ptr, &ctl->readq); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } - -} - - - -static void -mod_read_ctl(rb_fde_t * F, void *data) -{ - mod_ctl_buf_t *ctl_buf; - mod_ctl_t *ctl = data; - int retlen; - - do - { - ctl_buf = rb_malloc(sizeof(mod_ctl_buf_t)); - ctl_buf->buf = rb_malloc(READBUF_SIZE); - ctl_buf->buflen = READBUF_SIZE; - retlen = rb_recv_fd_buf(ctl->F, ctl_buf->buf, ctl_buf->buflen, ctl_buf->F, - MAXPASSFD); - if(retlen <= 0) - { - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - } - else - { - ctl_buf->buflen = retlen; - rb_dlinkAddTail(ctl_buf, &ctl_buf->node, &ctl->readq); - } - } - while (retlen > 0); - - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); - - mod_process_cmd_recv(ctl); - rb_setselect(ctl->F, RB_SELECT_READ, mod_read_ctl, ctl); -} - -static void -mod_write_ctl(rb_fde_t * F, void *data) -{ - mod_ctl_t *ctl = data; - mod_ctl_buf_t *ctl_buf; - rb_dlink_node *ptr, *next; - int retlen, x; - - RB_DLINK_FOREACH_SAFE(ptr, next, ctl->writeq.head) - { - ctl_buf = ptr->data; - retlen = rb_send_fd_buf(ctl->F, ctl_buf->F, ctl_buf->nfds, ctl_buf->buf, - ctl_buf->buflen); - if(retlen > 0) - { - rb_dlinkDelete(ptr, &ctl->writeq); - for (x = 0; x < ctl_buf->nfds; x++) - rb_close(ctl_buf->F[x]); - rb_free(ctl_buf->buf); - rb_free(ctl_buf); - - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); - - rb_setselect(ctl->F, RB_SELECT_WRITE, mod_write_ctl, ctl); - } -} - - -static void -read_pipe_ctl(rb_fde_t * F, void *data) -{ - int retlen; - while ((retlen = rb_read(F, inbuf, sizeof(inbuf))) > 0) - { - ;; /* we don't do anything with the pipe really, just care if the other process dies.. */ - } - if(retlen == 0 || (retlen < 0 && !rb_ignore_errno(errno))) - exit(0); - rb_setselect(F, RB_SELECT_READ, read_pipe_ctl, NULL); - -} - -int -main(int argc, char **argv) -{ - const char *s_ctlfd, *s_pipe; - int ctlfd, pipefd, x, maxfd; - maxfd = maxconn(); - s_ctlfd = getenv("CTL_FD"); - s_pipe = getenv("CTL_PIPE"); - - if(s_ctlfd == NULL || s_pipe == NULL) - { - fprintf(stderr, "This is ircd-ratbox ssld. You know you aren't supposed to run me directly?\n"); - fprintf(stderr, "You get an Id tag for this: $Id: ssld.c 25179 2008-03-30 16:34:57Z androsyn $\n"); - fprintf(stderr, "Have a nice life\n"); - exit(1); - } - - ctlfd = atoi(s_ctlfd); - pipefd = atoi(s_pipe); - - for (x = 0; x < maxfd; x++) - { - if(x != ctlfd && x != pipefd && x > 2) - close(x); - } - -#if 0 - x = open("/dev/null", O_RDWR); - if(x >= 0) - { - if(ctlfd != 0 && pipefd != 0) - dup2(x, 0); - if(ctlfd != 1 && pipefd != 1) - dup2(x, 1); - if(ctlfd != 2 && pipefd != 2) - dup2(x, 2); - if(x > 2) - close(x); - } -#endif - setup_signals(); - rb_lib_init(NULL, NULL, NULL, 0, maxfd, 1024, 4096); - rb_init_rawbuffers(1024); - ssl_ok = rb_supports_ssl(); - - mod_ctl = rb_malloc(sizeof(mod_ctl_t)); - mod_ctl->F = rb_open(ctlfd, RB_FD_SOCKET, "ircd control socket"); - mod_ctl->F_pipe = rb_open(pipefd, RB_FD_PIPE, "ircd pipe"); - rb_set_nb(mod_ctl->F); - rb_set_nb(mod_ctl->F_pipe); - rb_event_addish("clean_dead_conns", clean_dead_conns, NULL, 10); - read_pipe_ctl(mod_ctl->F_pipe, NULL); - mod_read_ctl(mod_ctl->F, mod_ctl); - if(!zlib_ok && !ssl_ok) - { - /* this is really useless... */ - send_i_am_useless(mod_ctl); - /* sleep until the ircd kills us */ - rb_sleep(2<<30, 0); - exit(1); - } - - if(!zlib_ok) - send_nozlib_support(mod_ctl, NULL); - if(!ssl_ok) - send_nossl_support(mod_ctl, NULL); - rb_lib_loop(0); - return 0; -} - - - -static void -dummy_handler(int sig) -{ - return; -} - -static void -setup_signals() -{ - struct sigaction act; - - act.sa_flags = 0; - act.sa_handler = SIG_IGN; - sigemptyset(&act.sa_mask); - sigaddset(&act.sa_mask, SIGPIPE); - sigaddset(&act.sa_mask, SIGALRM); -#ifdef SIGTRAP - sigaddset(&act.sa_mask, SIGTRAP); -#endif - -#ifdef SIGWINCH - sigaddset(&act.sa_mask, SIGWINCH); - sigaction(SIGWINCH, &act, 0); -#endif - sigaction(SIGPIPE, &act, 0); -#ifdef SIGTRAP - sigaction(SIGTRAP, &act, 0); -#endif - - act.sa_handler = dummy_handler; - sigaction(SIGALRM, &act, 0); -} -