From: Kevin L. Mitchell Date: Tue, 2 Jan 2001 21:47:31 +0000 (+0000) Subject: Author: Kev X-Git-Url: http://git.pk910.de/?a=commitdiff_plain;h=3b3486935371949a57e2541b73ba4ce97032c7f4;p=ircu2.10.12-pk.git Author: Kev Log message: Some efficiency enhancements in m_motd.c; a new way to set the PRNG's seed and some randomness enhancements (feedback); featurization of many compile- time options; a new feature flag to inhibit all display of something, like, say, the random seed. Testing: Compiles, no warnings; runs without apparent problems. Please brute-force it to see if any of the features can be broken. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@353 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ChangeLog b/ChangeLog index e9007aa..2429d94 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,68 @@ +2001-01-02 Kevin L. Mitchell + + * ircd/s_user.c: retrieve MAXSILES and MAXSILELENGTH (now + AVBANLEN*MAXSILES) from features subsystem + + * ircd/s_debug.c (debug_serveropts): CMDLINE_CONFIG doesn't go to + anything anymore + + * ircd/s_bsd.c: retrieve HANGONGOODLINK and HANGONRETRYDELAY from + the features subsystem + + * ircd/s_auth.c (start_auth): NODNS migrated to the features + subsystem + + * ircd/random.c: created random_seed_set() function to set seed + value, along with some stuff to make ircrandom() a little more + random--state preserving, xor of time instead of direct usage, + etc.; it's still a pseudo-random number generator, though, and + hopefully I haven't broken the randomness + + * ircd/m_version.c: FEATUREVALUES makes use of feature_int() calls + + * ircd/m_join.c: use features interface to retrieve + MAXCHANNELSPERUSER + + * ircd/ircd_features.c: add NODISP flag for super-secret features; + add a whole bunch of new features migrated over from make config + + * ircd/ircd.c: use features interface to retrieve PINGFREQUENCY, + CONNECTTIMEOUT, and TIMESEC + + * ircd/client.c (client_get_ping): use features interface to + retrieve PINGFREQUENCY + + * ircd/class.c: use features interface to retrieve PINGFREQUENCY, + CONNECTFREQUENCY, MAXIMUM_LINKS, and DEFAULTMAXSENDQLENGTH + + * ircd/chkconf.c (DEFAULTMAXSENDQLENGTH): since it's now in the + features subsystem, we have to add something explicit + + * ircd/channel.c: use features interface to retrieve + KILLCHASETIMELIMIT, MAXBANLENGTH, MAXBANS, and MAXCHANNELSPERUSER; + note that MAXBANLENGTH is now calculated dynamically from MAXBANS + and AVBANLEN + + * ircd/Makefile.in: run make depend + + * include/supported.h (FEATURESVALUES): update to reference + feature settings + + * include/random.h: add prototype for random_seed_set + + * include/ircd_features.h: add several more features + + * include/channel.h: move MAXBANS and MAXBANLENGTH into feature + subsystem + + * config/config-sh.in: feature-ized some more stuff + + * include/motd.h: some new elements in motd.h for motd.c changes + + * ircd/motd.c: motd_cache() now searches a list of already cached + MOTD files; saves us from having duplicate caches in memory if + there are two identical T-lines for two different sites... + 2001-01-02 Perry Lorier * ircd/motd.c: don't core if the motd isn't found. Bug found by Amarande. diff --git a/config/config-sh.in b/config/config-sh.in index f5661c2..405741a 100644 --- a/config/config-sh.in +++ b/config/config-sh.in @@ -69,7 +69,6 @@ comment 'Debugging (do not define this on production servers)' EXTRA_CPPFLAGS="-DNDEBUG $EXTRA_CPPFLAGS" fi fi - bool 'Are you testing on a host without DNS' NODNS endmenu mainmenu_option next_comment @@ -178,8 +177,6 @@ comment 'Host specific defines' DOMAINNAME_DEFAULT=none fi define_string DOMAINNAME $DOMAINNAME_DEFAULT - - string 'Please give a random seed of eight characters' RANDOM_SEED 12345678 endmenu mainmenu_option next_comment @@ -193,7 +190,6 @@ comment 'General defines' define_bool CHROOTDIR n define_int IRC_UID $IRC_UID define_int IRC_GID $IRC_GID - bool 'Allow to specify configuration file on command line' CMDLINE_CONFIG if [ "$CMDLINE_CONFIG" = "y" ]; then echo " SECURITY: Then don't install the daemon SUID or SGID !" fi @@ -236,21 +232,3 @@ comment 'Server characteristics' define_bool DEFAULT_LIST_PARAM n fi endmenu - -mainmenu_option next_comment -comment 'Mandatory defines (you should leave these untouched)' - int 'Max auto connects per class (1!)' MAXIMUM_LINKS 1 - int 'KILL nick chase time limit (30)' KILLCHASETIMELIMIT 30 - int 'Max number of channels per user' MAXCHANNELSPERUSER 10 - int 'Max number of silence masks (15!)' MAXSILES 15 - int 'Expected average banmask length (40!)' AVBANLEN 40 - eval define_macro MAXSILELENGTH \'\($AVBANLEN * MAXSILES\)\' - echo '* These are default values, used for class 0:' - int 'Max server idle time (60)' TIMESEC 60 - int 'Class 0 ping frequency (120)' PINGFREQUENCY 120 - int 'Class 0 connect frequency (600)' CONNECTFREQUENCY 600 - int 'Min time before a link is good (300)' HANGONGOODLINK 300 - int 'Wait before reconnecting to good link (10!)' HANGONRETRYDELAY 10 - int 'connect(2) timeout (90!)' CONNECTTIMEOUT 90 - int 'Max send queue (40000)' DEFAULTMAXSENDQLENGTH 40000 -endmenu diff --git a/include/channel.h b/include/channel.h index 5655487..87c51e9 100644 --- a/include/channel.h +++ b/include/channel.h @@ -44,8 +44,6 @@ struct Client; #define KEYLEN 23 #define CHANNELLEN 200 -#define MAXBANS 30 -#define MAXBANLENGTH 1024 #define MAXJOINARGS 15 /* number of slots for join buffer */ #define STARTJOINLEN 10 /* fuzzy numbers */ diff --git a/include/ircd_features.h b/include/ircd_features.h index fe194f4..04f03af 100644 --- a/include/ircd_features.h +++ b/include/ircd_features.h @@ -37,6 +37,23 @@ enum Feature { FEAT_IDLE_FROM_MSG, FEAT_HUB, FEAT_WALLOPS_OPER_ONLY, + FEAT_NODNS, + FEAT_RANDOM_SEED, + + /* features that probably should not be touched */ + FEAT_KILLCHASETIMELIMIT, + FEAT_MAXCHANNELSPERUSER, + FEAT_AVBANLEN, + FEAT_MAXBANS, + FEAT_MAXSILES, + FEAT_HANGONGOODLINK, + FEAT_HANGONRETRYDELAY, + FEAT_CONNECTTIMEOUT, + FEAT_TIMESEC, + FEAT_MAXIMUM_LINKS, + FEAT_PINGFREQUENCY, + FEAT_CONNECTFREQUENCY, + FEAT_DEFAULTMAXSENDQLENGTH, /* Some misc. default paths */ FEAT_MPATH, diff --git a/include/motd.h b/include/motd.h index 8bf6638..ba2204a 100644 --- a/include/motd.h +++ b/include/motd.h @@ -56,6 +56,11 @@ struct Motd { #define MOTD_MAXREMOTE 3 struct MotdCache { + struct MotdCache* next; /* these fields let us read MOTDs only once */ + struct MotdCache** prev_p; + int ref; + char* path; + int maxcount; struct tm modtime; int count; char motd[1][MOTD_LINESIZE]; diff --git a/include/random.h b/include/random.h index 9981062..b6d3057 100644 --- a/include/random.h +++ b/include/random.h @@ -6,10 +6,15 @@ #ifndef INCLUDED_random_h #define INCLUDED_random_h +struct Client; + /* * Proto types */ +extern int random_seed_set(struct Client* from, const char* const* fields, + int count); + extern unsigned int ircrandom(void); #endif /* INCLUDED_random_h */ diff --git a/include/supported.h b/include/supported.h index 520f4da..4f73a04 100644 --- a/include/supported.h +++ b/include/supported.h @@ -49,8 +49,10 @@ " CHANTYPES=%s" \ " PREFIX=%s" -#define FEATURESVALUES MAXSILES,MAXMODEPARAMS,MAXCHANNELSPERUSER,MAXBANS, \ - NICKLEN,TOPICLEN,TOPICLEN,"+#&","@+" +#define FEATURESVALUES feature_int(FEAT_MAXSILES), MAXMODEPARAMS, \ + feature_int(FEAT_MAXCHANNELSPERUSER), \ + feature_int(FEAT_MAXBANS), NICKLEN, TOPICLEN, \ + TOPICLEN, "+#&", "@+" #endif /* INCLUDED_supported_h */ diff --git a/ircd/Makefile.in b/ircd/Makefile.in index 0aa7445..da39d2e 100644 --- a/ircd/Makefile.in +++ b/ircd/Makefile.in @@ -303,11 +303,11 @@ channel.o: channel.c ../include/channel.h ../config/config.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ ../include/hash.h ../include/ircd.h ../include/struct.h \ ../include/ircd_alloc.h ../include/fda.h ../include/ircd_chattr.h \ - ../include/ircd_log.h ../include/ircd_reply.h \ - ../include/ircd_snprintf.h ../include/ircd_string.h ../include/list.h \ - ../include/match.h ../include/msg.h ../include/numeric.h \ - ../include/numnicks.h ../include/querycmds.h \ - ../include/ircd_features.h ../include/s_bsd.h ../include/s_conf.h \ + ../include/ircd_features.h ../include/ircd_log.h \ + ../include/ircd_reply.h ../include/ircd_snprintf.h \ + ../include/ircd_string.h ../include/list.h ../include/match.h \ + ../include/msg.h ../include/numeric.h ../include/numnicks.h \ + ../include/querycmds.h ../include/s_bsd.h ../include/s_conf.h \ ../include/s_debug.h ../include/s_misc.h ../include/s_user.h \ ../include/send.h ../include/sprintf_irc.h ../include/support.h \ ../include/sys.h ../include/whowas.h @@ -315,9 +315,9 @@ class.o: class.c ../include/class.h ../include/client.h \ ../include/ircd_defs.h ../config/config.h ../config/setup.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ ../include/ircd.h ../include/struct.h ../include/ircd_alloc.h \ - ../include/fda.h ../include/ircd_reply.h ../include/list.h \ - ../include/numeric.h ../include/s_conf.h ../include/s_debug.h \ - ../include/send.h + ../include/fda.h ../include/ircd_features.h ../include/ircd_reply.h \ + ../include/list.h ../include/numeric.h ../include/s_conf.h \ + ../include/s_debug.h ../include/send.h client.o: client.c ../include/client.h ../include/ircd_defs.h \ ../config/config.h ../config/setup.h ../include/dbuf.h \ ../include/msgq.h ../include/ircd_handler.h ../include/class.h \ @@ -378,9 +378,9 @@ ircd_features.o: ircd_features.c ../config/config.h ../config/setup.h \ ../include/ircd_alloc.h ../include/fda.h ../include/ircd_log.h \ ../include/ircd_reply.h ../include/ircd_string.h \ ../include/ircd_chattr.h ../include/match.h ../include/msg.h \ - ../include/numeric.h ../include/numnicks.h ../include/s_bsd.h \ - ../include/s_debug.h ../include/s_misc.h ../include/send.h \ - ../include/support.h ../include/sys.h + ../include/numeric.h ../include/numnicks.h ../include/random.h \ + ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \ + ../include/send.h ../include/support.h ../include/sys.h ircd_log.o: ircd_log.c ../include/ircd_log.h ../include/client.h \ ../include/ircd_defs.h ../config/config.h ../config/setup.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ @@ -587,7 +587,8 @@ m_join.o: m_join.c ../include/channel.h ../config/config.h \ ../config/setup.h ../include/ircd_defs.h ../include/client.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ ../include/gline.h ../include/hash.h ../include/ircd.h \ - ../include/struct.h ../include/ircd_chattr.h ../include/ircd_reply.h \ + ../include/struct.h ../include/ircd_chattr.h \ + ../include/ircd_features.h ../include/ircd_reply.h \ ../include/ircd_string.h ../include/msg.h ../include/numeric.h \ ../include/numnicks.h ../include/s_debug.h ../include/s_user.h \ ../include/send.h @@ -742,9 +743,10 @@ m_proto.o: m_proto.c ../include/client.h ../include/ircd_defs.h \ ../include/msgq.h ../include/ircd_handler.h ../include/ircd.h \ ../include/struct.h ../include/ircd_alloc.h ../include/fda.h \ ../include/ircd_chattr.h ../include/ircd_reply.h \ - ../include/ircd_string.h ../include/numeric.h ../include/numnicks.h \ - ../include/s_debug.h ../include/s_misc.h ../include/send.h \ - ../include/supported.h ../include/channel.h ../include/version.h + ../include/ircd_string.h ../include/msg.h ../include/numeric.h \ + ../include/numnicks.h ../include/s_debug.h ../include/s_misc.h \ + ../include/send.h ../include/supported.h ../include/channel.h \ + ../include/version.h m_quit.o: m_quit.c ../include/channel.h ../config/config.h \ ../config/setup.h ../include/ircd_defs.h ../include/client.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ @@ -888,11 +890,12 @@ m_userip.o: m_userip.c ../include/client.h ../include/ircd_defs.h \ m_version.o: m_version.c ../include/client.h ../include/ircd_defs.h \ ../config/config.h ../config/setup.h ../include/dbuf.h \ ../include/msgq.h ../include/ircd_handler.h ../include/hash.h \ - ../include/ircd.h ../include/struct.h ../include/ircd_reply.h \ - ../include/ircd_string.h ../include/ircd_chattr.h ../include/msg.h \ - ../include/numeric.h ../include/numnicks.h ../include/s_debug.h \ - ../include/s_user.h ../include/send.h ../include/supported.h \ - ../include/channel.h ../include/version.h + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \ + ../include/ircd_reply.h ../include/ircd_string.h \ + ../include/ircd_chattr.h ../include/msg.h ../include/numeric.h \ + ../include/numnicks.h ../include/s_debug.h ../include/s_user.h \ + ../include/send.h ../include/supported.h ../include/channel.h \ + ../include/version.h m_wallchops.o: m_wallchops.c ../include/channel.h ../config/config.h \ ../config/setup.h ../include/ircd_defs.h ../include/client.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ @@ -977,8 +980,10 @@ parse.o: parse.c ../include/parse.h ../include/client.h \ ../include/sys.h ../include/whocmds.h ../include/whowas.h querycmds.o: querycmds.c ../include/querycmds.h \ ../include/ircd_features.h -random.o: random.c ../include/random.h ../config/config.h \ - ../config/setup.h +random.o: random.c ../include/random.h ../include/client.h \ + ../include/ircd_defs.h ../config/config.h ../config/setup.h \ + ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ + ../include/ircd_log.h ../include/ircd_reply.h ../include/send.h res.o: res.c ../include/res.h ../include/client.h \ ../include/ircd_defs.h ../config/config.h ../config/setup.h \ ../include/dbuf.h ../include/msgq.h ../include/ircd_handler.h \ diff --git a/ircd/channel.c b/ircd/channel.c index 3208d71..edb4229 100644 --- a/ircd/channel.c +++ b/ircd/channel.c @@ -26,6 +26,7 @@ #include "ircd_alloc.h" #include "ircd_chattr.h" #include "ircd_defs.h" +#include "ircd_features.h" #include "ircd_log.h" #include "ircd_reply.h" #include "ircd_snprintf.h" @@ -148,7 +149,7 @@ struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing) if (who) return who; - if (!(who = get_history(user, KILLCHASETIMELIMIT))) { + if (!(who = get_history(user, feature_int(FEAT_KILLCHASETIMELIMIT)))) { send_reply(sptr, ERR_NOSUCHNICK, user); return 0; } @@ -339,7 +340,9 @@ int add_banid(struct Client *cptr, struct Channel *chptr, char *banid, banp = &(*banp)->next; } } - if (MyUser(cptr) && !removed_bans && (len > MAXBANLENGTH || (cnt >= MAXBANS))) + if (MyUser(cptr) && !removed_bans && + (len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXBANS)) || + (cnt >= feature_int(FEAT_MAXBANS)))) { send_reply(cptr, ERR_BANLISTFULL, chptr->chname, banid); return -1; @@ -1155,7 +1158,7 @@ void add_invite(struct Client *cptr, struct Channel *chptr) * Delete last link in chain if the list is max length */ assert(list_length((cli_user(cptr))->invited) == (cli_user(cptr))->invites); - if ((cli_user(cptr))->invites>=MAXCHANNELSPERUSER) + if ((cli_user(cptr))->invites >= feature_int(FEAT_MAXCHANNELSPERUSER)) del_invite(cptr, (cli_user(cptr))->invited->value.chptr); /* * Add client to channel invite list @@ -2256,7 +2259,8 @@ mode_process_bans(struct ParseState *state) MyFree(ban->value.ban.banstr); } else { if (state->flags & MODE_PARSE_SET && MyUser(state->sptr) && - (len > MAXBANLENGTH || count >= MAXBANS)) { + (len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXBANS)) || + count >= feature_int(FEAT_MAXBANS))) { send_reply(state->sptr, ERR_BANLISTFULL, state->chptr->chname, ban->value.ban.banstr); count--; diff --git a/ircd/chkconf.c b/ircd/chkconf.c index 15e8ff4..1df6214 100644 --- a/ircd/chkconf.c +++ b/ircd/chkconf.c @@ -55,6 +55,8 @@ #define CONF_KLINE (CONF_KILL | CONF_IPKILL) #define CONF_CRULE (CONF_CRULEALL | CONF_CRULEAUTO) +/* DEFAULTMAXSENDQLENGTH went into the features subsystem... */ +#define DEFAULTMAXSENDQLENGTH 40000 /* * For the connect rule patch.. these really should be in a header, diff --git a/ircd/class.c b/ircd/class.c index a3f855f..feb5dd8 100644 --- a/ircd/class.c +++ b/ircd/class.c @@ -22,6 +22,7 @@ #include "client.h" #include "ircd.h" #include "ircd_alloc.h" +#include "ircd_features.h" #include "ircd_reply.h" #include "list.h" #include "numeric.h" @@ -70,10 +71,10 @@ void init_class(void) connClassList = (struct ConnectionClass*) make_class(); ConClass(connClassList) = 0; - PingFreq(connClassList) = PINGFREQUENCY; - ConFreq(connClassList) = CONNECTFREQUENCY; - MaxLinks(connClassList) = MAXIMUM_LINKS; - MaxSendq(connClassList) = DEFAULTMAXSENDQLENGTH; + PingFreq(connClassList) = feature_int(FEAT_PINGFREQUENCY); + ConFreq(connClassList) = feature_int(FEAT_CONNECTFREQUENCY); + MaxLinks(connClassList) = feature_int(FEAT_MAXIMUM_LINKS); + MaxSendq(connClassList) = feature_int(FEAT_DEFAULTMAXSENDQLENGTH); connClassList->valid = 1; Links(connClassList) = 0; connClassList->next = 0; @@ -185,11 +186,11 @@ unsigned int get_client_ping(struct Client *acptr) } } else { - ping = PINGFREQUENCY; + ping = feature_int(FEAT_PINGFREQUENCY); Debug((DEBUG_DEBUG, "No Attached Confs for: %s", cli_name(acptr))); } if (ping <= 0) - ping = PINGFREQUENCY; + ping = feature_int(FEAT_PINGFREQUENCY); Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping)); return (ping); } @@ -199,7 +200,7 @@ unsigned int get_con_freq(struct ConnectionClass * clptr) if (clptr) return (ConFreq(clptr)); else - return (CONNECTFREQUENCY); + return feature_int(FEAT_CONNECTFREQUENCY); } /* @@ -230,7 +231,7 @@ void add_class(unsigned int conClass, unsigned int ping, unsigned int confreq, ConFreq(p) = confreq; PingFreq(p) = ping; MaxLinks(p) = maxli; - MaxSendq(p) = (sendq > 0) ? sendq : DEFAULTMAXSENDQLENGTH; + MaxSendq(p) = (sendq > 0) ? sendq : feature_int(FEAT_DEFAULTMAXSENDQLENGTH); p->valid = 1; if (p != t) Links(p) = 0; @@ -278,7 +279,7 @@ unsigned int get_sendq(struct Client *cptr) } } } - return DEFAULTMAXSENDQLENGTH; + return feature_int(FEAT_DEFAULTMAXSENDQLENGTH); } void class_send_meminfo(struct Client* cptr) diff --git a/ircd/client.c b/ircd/client.c index b1ed01f..0c74465 100644 --- a/ircd/client.c +++ b/ircd/client.c @@ -55,7 +55,7 @@ int client_get_ping(const struct Client* acptr) } } if (0 == ping) - ping = PINGFREQUENCY; + ping = feature_int(FEAT_PINGFREQUENCY); Debug((DEBUG_DEBUG, "Client %s Ping %d", cli_name(acptr), ping)); return ping; diff --git a/ircd/ircd.c b/ircd/ircd.c index 24d966d..d60cc0c 100644 --- a/ircd/ircd.c +++ b/ircd/ircd.c @@ -273,9 +273,11 @@ static time_t try_connections(void) { *--------------------------------------------------------------------------*/ static time_t check_pings(void) { int expire = 0; - int next_check = CurrentTime + PINGFREQUENCY; + int next_check = CurrentTime; int max_ping = 0; int i; + + next_check += feature_int(FEAT_PINGFREQUENCY); /* Scan through the client table */ for (i=0; i <= HighestFd; i++) { @@ -293,7 +295,8 @@ static time_t check_pings(void) { continue; } - max_ping = IsRegistered(cptr) ? client_get_ping(cptr) : CONNECTTIMEOUT; + max_ping = IsRegistered(cptr) ? client_get_ping(cptr) : + feature_int(FEAT_CONNECTTIMEOUT); Debug((DEBUG_DEBUG, "check_pings(%s)=status:%s limit: %d current: %d", cli_name(cptr), (cli_flags(cptr) & FLAGS_PINGSENT) ? "[Ping Sent]" : "[]", @@ -478,7 +481,7 @@ static void event_loop(void) { if (delay < 1) read_message(1); else - read_message(IRCD_MIN(delay, TIMESEC)); + read_message(IRCD_MIN(delay, feature_int(FEAT_TIMESEC))); /* ...perhaps should not do these loops every time, but only if there is * some chance of something happening (but, note that conf->hold times may diff --git a/ircd/ircd_features.c b/ircd/ircd_features.c index 7c8e9fb..9e6983b 100644 --- a/ircd/ircd_features.c +++ b/ircd/ircd_features.c @@ -31,6 +31,7 @@ #include "msg.h" #include "numeric.h" #include "numnicks.h" +#include "random.h" /* random_seed_set */ #include "s_bsd.h" #include "s_debug.h" #include "s_misc.h" @@ -189,6 +190,7 @@ typedef void (*feat_report_call)(struct Client*, int); #define FEAT_OPER 0x0100 /* set to display only to opers */ #define FEAT_MYOPER 0x0200 /* set to display only to local opers */ +#define FEAT_NODISP 0x0400 /* feature must never be displayed */ #define FEAT_READ 0x1000 /* feature is read-only (for now, perhaps?) */ @@ -234,6 +236,23 @@ static struct FeatureDesc { F_B(IDLE_FROM_MSG, 0, 1), F_B(HUB, 0, 0), F_B(WALLOPS_OPER_ONLY, 0, 0), + F_B(NODNS, 0, 0), + F_N(RANDOM_SEED, FEAT_NODISP, random_seed_set, 0, 0, 0, 0, 0), + + /* features that probably should not be touched */ + F_I(KILLCHASETIMELIMIT, 0, 30), + F_I(MAXCHANNELSPERUSER, 0, 10), + F_I(AVBANLEN, 0, 40), + F_I(MAXBANS, 0, 30), + F_I(MAXSILES, 0, 15), + F_I(HANGONGOODLINK, 0, 300), + F_I(HANGONRETRYDELAY, 0, 10), + F_I(CONNECTTIMEOUT, 0, 90), + F_I(TIMESEC, 0, 60), + F_I(MAXIMUM_LINKS, 0, 1), + F_I(PINGFREQUENCY, 0, 120), + F_I(CONNECTFREQUENCY, 0, 600), + F_I(DEFAULTMAXSENDQLENGTH, 0, 40000), /* Some misc. default paths */ F_S(MPATH, FEAT_CASE | FEAT_MYOPER, "ircd.motd"), @@ -481,7 +500,8 @@ feature_get(struct Client* from, const char* const* fields, int count) if (count < 1) /* check parameters */ need_more_params(from, "GET"); else if ((feat = feature_desc(from, fields[0]))) { - if ((feat->flags & FEAT_MYOPER && !MyOper(from)) || + if ((feat->flags & FEAT_NODISP) || + (feat->flags & FEAT_MYOPER && !MyOper(from)) || (feat->flags & FEAT_OPER && !IsAnOper(from))) /* check privs */ return send_reply(from, ERR_NOPRIVILEGES); @@ -565,7 +585,8 @@ feature_report(struct Client* to) int i; for (i = 0; features[i].type; i++) { - if ((features[i].flags & FEAT_MYOPER && !MyOper(to)) || + if ((features[i].flags & FEAT_NODISP) || + (features[i].flags & FEAT_MYOPER && !MyOper(to)) || (features[i].flags & FEAT_OPER && !IsAnOper(to))) continue; /* skip this one */ diff --git a/ircd/m_join.c b/ircd/m_join.c index 437a52f..f07d1f1 100644 --- a/ircd/m_join.c +++ b/ircd/m_join.c @@ -93,6 +93,7 @@ #include "hash.h" #include "ircd.h" #include "ircd_chattr.h" +#include "ircd_features.h" #include "ircd_reply.h" #include "ircd_string.h" #include "msg.h" @@ -217,7 +218,7 @@ int m_join(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) } else flags = IsModelessChannel(name) ? CHFL_DEOPPED : CHFL_CHANOP; - if (cli_user(sptr)->joined >= MAXCHANNELSPERUSER && + if (cli_user(sptr)->joined >= feature_int(FEAT_MAXCHANNELSPERUSER) && !HasPriv(sptr, PRIV_CHAN_LIMIT)) { send_reply(sptr, ERR_TOOMANYCHANNELS, chptr ? chptr->chname : name); break; /* no point processing the other channels */ diff --git a/ircd/m_version.c b/ircd/m_version.c index 1366879..4893f01 100644 --- a/ircd/m_version.c +++ b/ircd/m_version.c @@ -90,6 +90,7 @@ #include "client.h" #include "hash.h" #include "ircd.h" +#include "ircd_features.h" #include "ircd_reply.h" #include "ircd_string.h" #include "msg.h" diff --git a/ircd/motd.c b/ircd/motd.c index 4fe4a56..f32bfb4 100644 --- a/ircd/motd.c +++ b/ircd/motd.c @@ -48,10 +48,11 @@ #include static struct { - struct Motd* local; - struct Motd* remote; - struct Motd* other; - struct Motd* freelist; + struct Motd* local; + struct Motd* remote; + struct Motd* other; + struct Motd* freelist; + struct MotdCache* cachelist; } MotdList; /* Create a struct Motd and initialize it */ @@ -118,6 +119,16 @@ motd_cache(struct Motd *motd) if (motd->cache) return motd->cache; + /* try to find it in the list of cached files... */ + for (cache = MotdList.cachelist; cache; cache = cache->next) { + if (!strcmp(cache->path, motd->path) && + cache->maxcount == motd->maxcount) { /* found one... */ + cache->ref++; /* increase reference count... */ + motd->cache = cache; /* remember cache... */ + return motd->cache; /* return it */ + } + } + /* gotta read in the file, now */ if (!(file = fbopen(motd->path, "r"))) { Debug((DEBUG_ERROR, "Couldn't open \"%s\": %s", motd->path, @@ -135,10 +146,14 @@ motd_cache(struct Motd *motd) cache = (struct MotdCache *)MyMalloc(sizeof(struct MotdCache) + (MOTD_LINESIZE * (MOTD_MAXLINES - 1))); + cache->ref = 1; + DupString(cache->path, motd->path); + cache->maxcount = motd->maxcount; + cache->modtime = *localtime((time_t *) &sb.st_mtime); /* store modtime */ cache->count = 0; - while (cache->count < motd->maxcount && fbgets(line, sizeof(line), file)) { + while (cache->count < cache->maxcount && fbgets(line, sizeof(line), file)) { /* copy over line, stopping when we overflow or hit line end */ for (tmp = line, i = 0; i < (MOTD_LINESIZE - 1) && *tmp && *tmp != '\r' && *tmp != '\n'; @@ -156,6 +171,13 @@ motd_cache(struct Motd *motd) (MOTD_LINESIZE * (cache->count - 1))); + /* now link it in... */ + motd->cache->next = MotdList.cachelist; + motd->cache->prev_p = &MotdList.cachelist; + if (MotdList.cachelist) + MotdList.cachelist->prev_p = &motd->cache->next; + MotdList.cachelist = motd->cache; + return motd->cache; } @@ -171,7 +193,15 @@ motd_decache(struct Motd *motd) motd->cache = 0; /* zero the cache */ - MyFree(cache); /* very simple for a reason... */ + if (!--cache->ref) { /* reduce reference count... */ + if (cache->next) /* ref is 0, delink from list and free */ + cache->next->prev_p = cache->prev_p; + *cache->prev_p = cache->next; + + MyFree(cache->path); /* free path info... */ + + MyFree(cache); /* very simple for a reason... */ + } } /* This function destroys a struct Motd, destroying the cache if needed */ @@ -303,6 +333,9 @@ motd_init(void) motd_cache(MotdList.remote); /* init remote and cache it */ MotdList.other = 0; /* no T-lines processed yet */ + + MotdList.freelist = 0; + MotdList.cachelist = 0; } /* This routine adds a MOTD */ diff --git a/ircd/random.c b/ircd/random.c index 0fab4de..528b8d4 100644 --- a/ircd/random.c +++ b/ircd/random.c @@ -18,14 +18,71 @@ * $Id$ */ #include "random.h" -#include "config.h" -#include -#include -#include +#include "client.h" +#include "ircd_log.h" +#include "ircd_reply.h" +#include "send.h" #include +#include + + +char localkey[9] = "12345678"; + +/* This devious-looking construct rolls a character to the left by r bits */ +#define char_roll(c, r) (((c) << (r)) | ((c) >> (8 - (r)))) + +/* this routine is intended to be called by the feature subsystem; it takes + * a key as found in the .conf and mashes it up for the seed for the random + * number generator. + */ +int +random_seed_set(struct Client* from, const char* const* fields, int count) +{ + const char *p = 0; + int len, i, roll = 0; + + if (count < 1) { + if (from) /* send an error */ + return need_more_params(from, "SET"); + else { + log_write(LS_CONFIG, L_ERROR, 0, "Not enough fields in F line"); + return 0; + } + } + + len = strlen(fields[0]); -char localkey[9] = RANDOM_SEED; + /* logic is: go through loop at least 8 times, but use all bits of seed */ + for (i = 0; i < (len < 8 ? 8 : len); i++, p++) { + if (!(i % len)) { /* if we've exceeded the string length, reset */ + p = fields[0]; + roll++; /* so latter part of string looks different from former */ + } + + /* set the appropriate location of localkey according to the following + * rules: first, roll current value by an amount depending on how many + * times we've touched this character. Then take seed value and roll + * it by an amount depending upon how many times we've touched that + * character. Finally, xor the values together. + */ + localkey[i % 8] = char_roll(localkey[i % 8], (i / 8) % 8) ^ + char_roll(*p, roll % 8); + } + + return 1; +} + +/* this is like memcpy except it xors the areas in memory. */ +static void +memxor(void *dest, void *src, int n) +{ + unsigned char *d = (unsigned char *)dest; + unsigned char *s = (unsigned char *)src; + + while (--n) + d[n] ^= s[n]; +} /* * MD5 transform algorithm, taken from code written by Colin Plumb, @@ -39,6 +96,12 @@ char localkey[9] = RANDOM_SEED; * record: Cleaned up to work with ircd. RANDOM_TOKEN is defined in * setup.h by the make script; if people start to "guess" your cookies, * consider recompiling your server with a different random token. + * + * Kev: Now the seed comes from the feature subsystem and is fed into a + * mash routine (random_set_seed) that depends on previous values of the + * localkey array; also, part of the output of the RNG is fed back into + * the localkey array. Finally, the time values are xor'd with the local + * key to enhance non-determinability of the data fed into the MD5 core. */ /* The four core functions - F1 is optimized somewhat */ @@ -73,11 +136,12 @@ unsigned int ircrandom(void) unsigned char in[16]; struct timeval tv; - gettimeofday(&tv, NULL); + gettimeofday(&tv, 0); memcpy((void *)in, (void *)localkey, 8); - memcpy((void *)(in + 8), (void *)&tv.tv_sec, 4); - memcpy((void *)(in + 12), (void *)&tv.tv_usec, 4); + memcpy((void *)(in + 8), (void *)localkey, 8); + memxor((void *)(in + 8), (void *)&tv.tv_sec, 4); + memxor((void *)(in + 12), (void *)&tv.tv_usec, 4); a = 0x67452301; b = 0xefcdab89; @@ -152,9 +216,18 @@ unsigned int ircrandom(void) MD5STEP(F4, c, d, a, b, (int)in[2] + 0x2ad7d2bb, 15); MD5STEP(F4, b, c, d, a, (int)in[9] + 0xeb86d391, 21); + /* This feeds part of the output of the random number generator into the + * seed to further obscure any patterns + */ + memxor((void *)localkey, (void *)&a, 4); + memxor((void *)(localkey + 4), (void *)&b, 4); + /* * We have 4 unsigned longs generated by the above sequence; this scrambles * them together so that if there is any pattern, it will be obscured. + * + * a and b are now part of the state of the random number generator; + * returning them is a security hazard. */ - return (a ^ b ^ c ^ d); + return (c ^ d); } diff --git a/ircd/s_auth.c b/ircd/s_auth.c index 00ecdab..28158f7 100644 --- a/ircd/s_auth.c +++ b/ircd/s_auth.c @@ -522,31 +522,31 @@ void start_auth(struct Client* client) auth = make_auth_request(client); assert(0 != auth); -#if !defined(NODNS) - if (LOOPBACK == inet_netof(cli_ip(client))) { - strcpy(cli_sockhost(client), cli_name(&me)); - } - else { - struct DNSQuery query; - - query.vptr = auth; - query.callback = auth_dns_callback; - - if (IsUserPort(auth->client)) - sendheader(client, REPORT_DO_DNS); + if (!feature_bool(FEAT_NODNS)) { + if (LOOPBACK == inet_netof(cli_ip(client))) + strcpy(cli_sockhost(client), cli_name(&me)); + else { + struct DNSQuery query; - cli_dns_reply(client) = gethost_byaddr((const char*) &(cli_ip(client)), &query); + query.vptr = auth; + query.callback = auth_dns_callback; - if (cli_dns_reply(client)) { - ++(cli_dns_reply(client))->ref_count; - ircd_strncpy(cli_sockhost(client), cli_dns_reply(client)->hp->h_name, HOSTLEN); if (IsUserPort(auth->client)) - sendheader(client, REPORT_FIN_DNSC); + sendheader(client, REPORT_DO_DNS); + + cli_dns_reply(client) = gethost_byaddr((const char*) &(cli_ip(client)), + &query); + + if (cli_dns_reply(client)) { + ++(cli_dns_reply(client))->ref_count; + ircd_strncpy(cli_sockhost(client), cli_dns_reply(client)->hp->h_name, + HOSTLEN); + if (IsUserPort(auth->client)) + sendheader(client, REPORT_FIN_DNSC); + } else + SetDNSPending(auth); } - else - SetDNSPending(auth); } -#endif if (start_auth_query(auth)) link_auth_request(auth, &AuthPollList); diff --git a/ircd/s_bsd.c b/ircd/s_bsd.c index 6a5904f..e53658e 100644 --- a/ircd/s_bsd.c +++ b/ircd/s_bsd.c @@ -476,8 +476,9 @@ void close_connection(struct Client *cptr) * CONF_ILLEGAL). But only do this if it was a "good" link. */ aconf->hold = CurrentTime; - aconf->hold += (aconf->hold - cli_since(cptr) > HANGONGOODLINK) ? - HANGONRETRYDELAY : ConfConFreq(aconf); + aconf->hold += ((aconf->hold - cli_since(cptr) > + feature_int(FEAT_HANGONGOODLINK)) ? + feature_int(FEAT_HANGONRETRYDELAY) : ConfConFreq(aconf)); if (nextconnect > aconf->hold) nextconnect = aconf->hold; } diff --git a/ircd/s_debug.c b/ircd/s_debug.c index c28038a..96d986e 100644 --- a/ircd/s_debug.c +++ b/ircd/s_debug.c @@ -83,9 +83,6 @@ const char* debug_serveropts(void) #ifdef CHROOTDIR AddC('c'); #endif -#ifdef CMDLINE_CONFIG - AddC('C'); -#endif #ifdef DEBUGMODE AddC('D'); #endif diff --git a/ircd/s_user.c b/ircd/s_user.c index f483a0e..e8d00b7 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -1528,7 +1528,8 @@ int add_silence(struct Client* sptr, const char* mask) if (MyUser(sptr)) { len += strlen(lp->value.cp); - if ((len > MAXSILELENGTH) || (++cnt >= MAXSILES)) + if ((len > (feature_int(FEAT_AVBANLEN) * feature_int(FEAT_MAXSILES))) || + (++cnt >= feature_int(FEAT_MAXSILES))) { send_reply(sptr, ERR_SILELISTFULL, mask); return -1;