/** * ns_ratelimitreg.C: Rate limits account registrations. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Jilles Tjoelker * Rights to this code are as documented in doc/pod/license.pod. * * $Id: ns_ratelimitreg.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: ns_ratelimitreg.C,v 1.6 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("contrib/ns_ratelimitreg", false, "Jilles Tjoelker "); /* settings */ int ratelimitreg_max = 5; /* allow this many account registrations */ int ratelimitreg_period = 60; /* in this time */ int ratelimitreg_wallops_period = 3600; /* send wallops at most once an hour */ /* dynamic state */ int ratelimitreg_count = 0; time_t ratelimitreg_firsttime = 0; static bool check_registration (sourceinfo_t *si, char const * const account, char const * const email) { bool approved = true; static time_t lastwallops; if (ratelimitreg_firsttime + ratelimitreg_period > NOW) ratelimitreg_count = 0, ratelimitreg_firsttime = NOW; if (ratelimitreg_count > ratelimitreg_max && !has_priv (si, PRIV_FLOOD)) { command_fail (si, fault::toomany, "The system is currently too busy to process your registration, please try again later."); approved = false; snoop ("REGISTER:THROTTLED: %s by \2%s\2", account, si->su != NULL ? si->su->nick : get_source_name (si)); if (lastwallops + ratelimitreg_wallops_period < NOW) { wallops ("Registration of %s by %s was throttled.", account, get_oper_name (si)); lastwallops = NOW; } } return approved; } static void handle_register (myuser_t *mu) { if (ratelimitreg_firsttime + ratelimitreg_period > NOW) ratelimitreg_count = 0, ratelimitreg_firsttime = NOW; ratelimitreg_count++; } bool _modinit (module *m) { user_t::callback.can_register.attach (check_registration); myuser_t::callback.registered.attach (handle_register); return true; } void _moddeinit (void) { user_t::callback.can_register.detach (check_registration); myuser_t::callback.registered.detach (handle_register); }