diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.c | 91 | ||||
-rw-r--r-- | src/chanserv.c | 9 | ||||
-rw-r--r-- | src/nickserv.c | 6 | ||||
-rw-r--r-- | src/servers.c | 96 | ||||
-rw-r--r-- | src/sessions.c | 51 |
5 files changed, 174 insertions, 79 deletions
diff --git a/src/actions.c b/src/actions.c index c97eb9930..e7f8eac6a 100644 --- a/src/actions.c +++ b/src/actions.c @@ -16,46 +16,52 @@ /*************************************************************************/ -/* Note a bad password attempt for the given user. If they've used up - * their limit, toss them off. +/** + * Note a bad password attempt for the given user. If they've used up + * their limit, toss them off. + * @param u the User to check + * @return void */ - void bad_password(User * u) { time_t now = time(NULL); - if (!u) { + if (!u || !BadPassLimit) { return; } - if (!BadPassLimit) - return; - if (BadPassTimeout > 0 && u->invalid_pw_time > 0 && u->invalid_pw_time < now - BadPassTimeout) u->invalid_pw_count = 0; u->invalid_pw_count++; u->invalid_pw_time = now; - if (u->invalid_pw_count >= BadPassLimit) + if (u->invalid_pw_count >= BadPassLimit) { kill_user(NULL, u->nick, "Too many invalid passwords"); + } } /*************************************************************************/ -/* Remove a user from the IRC network. `source' is the nick which should - * generate the kill, or NULL for a server-generated kill. +/** + * Remove a user from the IRC network. + * @param source is the nick which should generate the kill, or NULL for a server-generated kill. + * @param user to remove + * @param reason for the kill + * @return void */ - void kill_user(char *source, char *user, char *reason) { char buf[BUFSIZE]; - if (!user || !*user) + if (!user || !*user) { return; - if (!source || !*source) + } + if (!source || !*source) { source = ServerName; - if (!reason) + } + if (!reason) { reason = ""; + } snprintf(buf, sizeof(buf), "%s (%s)", source, reason); @@ -68,31 +74,35 @@ void kill_user(char *source, char *user, char *reason) /*************************************************************************/ +/** + * Check and enforce SQlines + * @param mask of the sqline + * @param reason for the sqline + * @return void + */ void sqline(char *mask, char *reason) { + int i; + Channel *c, *next; + char *av[3]; + struct c_userlist *cu, *cunext; + if (ircd->chansqline) { if (*mask == '#') { - int i; - Channel *c, *next; - - char *av[3]; - struct c_userlist *cu, *cunext; - anope_cmd_sqline(mask, reason); for (i = 0; i < 1024; i++) { for (c = chanlist[i]; c; c = next) { next = c->next; - if (!match_wild_nocase(mask, c->name)) + if (!match_wild_nocase(mask, c->name)) { continue; - + } for (cu = c->users; cu; cu = cunext) { cunext = cu->next; - - if (is_oper(cu->user)) + if (is_oper(cu->user)) { continue; - + } av[0] = c->name; av[1] = cu->user->nick; av[2] = reason; @@ -112,6 +122,12 @@ void sqline(char *mask, char *reason) /*************************************************************************/ +/** + * Unban the nick from a channel + * @param ci channel info for the channel + * @param nick to remove the ban for + * @return void + */ void common_unban(ChannelInfo * ci, char *nick) { int count, i; @@ -119,11 +135,13 @@ void common_unban(ChannelInfo * ci, char *nick) User *u; char *host; - if (!ci || !ci->c || !nick) + if (!ci || !ci->c || !nick) { return; + } - if (!(u = finduser(nick))) + if (!(u = finduser(nick))) { return; + } host = host_resolve(u->host); @@ -157,6 +175,13 @@ void common_unban(ChannelInfo * ci, char *nick) /*************************************************************************/ +/** + * Prepare to set SVSMODE and update internal user modes + * @param u user to apply modes to + * @param modes the modes to set on the user + * @param arg the arguments for the user modes + * @return void + */ void common_svsmode(User * u, char *modes, char *arg) { int ac = 1; @@ -174,6 +199,12 @@ void common_svsmode(User * u, char *modes, char *arg) /*************************************************************************/ +/** + * Get the vhost for the user, if set else return the host, on ircds without + * vhost this returns the host + * @param u user to get the vhost for + * @return vhost + */ char *common_get_vhost(User * u) { if (!u) { @@ -192,6 +223,12 @@ char *common_get_vhost(User * u) /*************************************************************************/ +/** + * Get the vident for the user, if set else return the ident, on ircds without + * vident this returns the ident + * @param u user to get info the vident for + * @return vident + */ char *common_get_vident(User * u) { if (!u) { diff --git a/src/chanserv.c b/src/chanserv.c index e6b4522e2..feda36356 100644 --- a/src/chanserv.c +++ b/src/chanserv.c @@ -4725,10 +4725,13 @@ static int do_akick(User * u) if (ci->akick[b].flags & AK_ISNICK) { ci->akick[a].u.nc = ci->akick[b].u.nc; } else { - ci->akick[a].u.mask = ci->akick[b].u.mask; + ci->akick[a].u.mask = + sstrdup(ci->akick[b].u.mask); } - ci->akick[a].reason = ci->akick[b].reason; - ci->akick[a].creator = ci->akick[b].creator; + ci->akick[a].reason = + sstrdup(ci->akick[b].reason); + ci->akick[a].creator = + sstrdup(ci->akick[b].creator); ci->akick[a].addtime = ci->akick[b].addtime; akick_del(u, &ci->akick[b]); diff --git a/src/nickserv.c b/src/nickserv.c index d853464af..49cc697c5 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -4010,7 +4010,11 @@ static int do_ghost(User * u) char buf[NICKMAX + 32]; snprintf(buf, sizeof(buf), "GHOST command used by %s", u->nick); - del_session(u2->host); +#ifndef STREAMLINED + if (LimitSessions) { + del_session(u2->host); + } +#endif kill_user(s_NickServ, nick, buf); notice_lang(s_NickServ, u, NICK_GHOST_KILLED, nick); } else { diff --git a/src/servers.c b/src/servers.c index 303f25d87..4cd04e8eb 100644 --- a/src/servers.c +++ b/src/servers.c @@ -23,7 +23,11 @@ static Server *server_cur; /*************************************************************************/ -/* Walk through the servers list */ +/** + * Return the first server in the server struct + * @param flags Server Flags, see services.h + * @return Server Struct + */ Server *first_server(int flags) { server_cur = servlist; @@ -34,6 +38,13 @@ Server *first_server(int flags) return server_cur; } +/*************************************************************************/ + +/** + * Return the next server in the server struct + * @param flags Server Flags, see services.h + * @return Server Struct + */ Server *next_server(int flags) { if (!server_cur) @@ -60,12 +71,18 @@ Server *next_server(int flags) /*************************************************************************/ -/* This function makes a new Server structure and links it in the right +/** + * This function makes a new Server structure and links it in the right * places in the linked list if a Server struct to it's uplink if provided. * It can also be NULL to indicate it's the uplink and should be first in * the server list. + * @param uplink Server struct + * @param name Server Name + * @param desc Server Description + * @param flags Server Flags, see services.h + * @param suid Server Universal ID + * @return Server Struct */ - Server *new_server(Server * uplink, const char *name, const char *desc, uint16 flags, char *suid) { @@ -102,13 +119,16 @@ Server *new_server(Server * uplink, const char *name, const char *desc, /*************************************************************************/ -/* Remove and free a Server structure. This function is the most complete +/** + * Remove and free a Server structure. This function is the most complete * remove treatment a server can get, as it first quits all clients which * still pretend to be on this server, then it walks through all connected * servers and disconnects them too. If all mess is cleared, the server * itself will be too. + * @param Server struct + * @param reason the server quit + * @return void */ - static void delete_server(Server * serv, const char *quitreason) { Server *s, *snext; @@ -140,8 +160,9 @@ static void delete_server(Server * serv, const char *quitreason) (quitreason ? sstrdup(quitreason) : NULL); } #ifndef STREAMLINED - if (LimitSessions) + if (LimitSessions) { del_session(u->host); + } #endif delete_user(u); } @@ -177,8 +198,12 @@ static void delete_server(Server * serv, const char *quitreason) /*************************************************************************/ -/* Find a server by name, returns NULL if not found */ - +/** + * Find a server by name, returns NULL if not found + * @param s Server struct + * @param name Server Name + * @return Server struct + */ Server *findserver(Server * s, const char *name) { Server *sl; @@ -187,30 +212,35 @@ Server *findserver(Server * s, const char *name) return NULL; } - if (debug >= 3) + if (debug >= 3) { alog("debug: findserver(%p)", name); + } while (s && (stricmp(s->name, name) != 0)) { if (s->links) { sl = findserver(s->links, name); - if (sl) + if (sl) { s = sl; - else + } else { s = s->next; + } } else { s = s->next; } } - if (debug >= 3) + if (debug >= 3) { alog("debug: findserver(%s) -> %p", name, (void *) s); + } return s; } -/* - Not Synced = -1 - Error = 0 - Synced = 1 -*/ +/*************************************************************************/ +/** + * Find if the server is synced with the network + * @param s Server struct + * @param name Server Name + * @return Not Synced returns -1, Synced returns 1, Error returns 0 + */ int anope_check_sync(const char *name) { Server *s; @@ -227,7 +257,15 @@ int anope_check_sync(const char *name) } /*************************************************************************/ -/* :<introducing server> SERVER <servername> <hops> :<description> + +/** + * Handle adding the server to the Server struct + * @param source Name of the uplink if any + * @param servername Name of the server being linked + * @param hops Number of hops to reach this server + * @param descript Description of the server + * @param numeric Server Numberic/SUID + * @return void */ void do_server(const char *source, char *servername, char *hops, char *descript, char *numeric) @@ -252,7 +290,13 @@ void do_server(const char *source, char *servername, char *hops, } /*************************************************************************/ -/* SQUIT <server> :<comment> + +/** + * Handle removing the server from the Server struct + * @param source Name of the server leaving + * @param ac Number of arguments in av + * @param av Agruments as part of the SQUIT + * @return void */ void do_squit(const char *source, int ac, char **av) { @@ -271,8 +315,9 @@ void do_squit(const char *source, int ac, char **av) if (ircdcap->unconnect) { if ((s->uplink == me_server) && (uplink_capab & ircdcap->unconnect)) { - if (debug) + if (debug) { alog("debug: Sending UNCONNECT SQUIT for %s", s->name); + } /* need to fix */ anope_cmd_squit(s->name, buf); } @@ -281,6 +326,14 @@ void do_squit(const char *source, int ac, char **av) delete_server(s, buf); } +/*************************************************************************/ + +/** + * Handle parsing the CAPAB/PROTOCTL messages + * @param ac Number of arguments in av + * @param av Agruments + * @return void + */ void capab_parse(int ac, char **av) { int i; @@ -371,12 +424,9 @@ void capab_parse(int ac, char **av) if (!stricmp(s, "SSJ3")) { uplink_capab |= CAPAB_SSJ3; } - if (!stricmp(s, "SJB64")) { uplink_capab |= CAPAB_SJB64; - } - if (!stricmp(s, "CHANMODES")) { uplink_capab |= CAPAB_CHANMODE; if (tmp) { diff --git a/src/sessions.c b/src/sessions.c index 939c92afb..86a440b35 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -51,36 +51,19 @@ /*************************************************************************/ -typedef struct session_ Session; -struct session_ { - Session *prev, *next; - char *host; - int count; /* Number of clients with this host */ - int hits; /* Number of subsequent kills for a host */ -}; - /* I'm sure there is a better way to hash the list of hosts for which we are * storing session information. This should be sufficient for the mean time. * -TheShadow */ #define HASH(host) (((host)[0]&31)<<5 | ((host)[1]&31)) -static Session *sessionlist[1024]; -static int32 nsessions = 0; +Session *sessionlist[1024]; +int32 nsessions = 0; Exception *exceptions = NULL; int16 nexceptions = 0; /*************************************************************************/ - -static Session *findsession(const char *host); - -static Exception *find_host_exception(const char *host); -static int exception_add(User * u, const char *mask, const int limit, - const char *reason, const char *who, - const time_t expires); - -/*************************************************************************/ /****************************** Statistics *******************************/ /*************************************************************************/ @@ -195,13 +178,14 @@ int do_session(User * u) /********************* Internal Session Functions ************************/ /*************************************************************************/ -static Session *findsession(const char *host) +Session *findsession(const char *host) { Session *session; int i; - if (!host) + if (!host) { return NULL; + } for (i = 0; i < 1024; i++) { for (session = sessionlist[i]; session; session = session->next) { @@ -282,6 +266,20 @@ void del_session(const char *host) { Session *session; + if (!LimitSessions) { + if (debug) { + alog("debug: del_session called when LimitSessions is disabled"); + } + return; + } + + if (!host || !*host) { + if (debug) { + alog("debug: del_session called with NULL values"); + } + return; + } + if (debug >= 2) alog("debug: del_session() called"); @@ -291,7 +289,10 @@ void del_session(const char *host) anope_cmd_global(s_OperServ, "WARNING: Tried to delete non-existant session: \2%s", host); - alog("session: Tried to delete non-existant session: %s", host); + if (debug) { + alog("session: Tried to delete non-existant session: %s", + host); + } return; } @@ -479,9 +480,9 @@ void save_rdb_exceptions() /************************ Exception Manipulation *************************/ /*************************************************************************/ -static int exception_add(User * u, const char *mask, const int limit, - const char *reason, const char *who, - const time_t expires) +int exception_add(User * u, const char *mask, const int limit, + const char *reason, const char *who, + const time_t expires) { int i; |