diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sessions.c | 34 | ||||
| -rw-r--r-- | src/users.c | 17 |
2 files changed, 29 insertions, 22 deletions
diff --git a/src/sessions.c b/src/sessions.c index 4b665e1bc..5a37e526b 100644 --- a/src/sessions.c +++ b/src/sessions.c @@ -203,7 +203,7 @@ Session *findsession(const char *host) * Returns 1 if the host was added or 0 if the user was killed. */ -int add_session(char *nick, char *host) +int add_session(char *nick, char *host, char *hostip) { Session *session, **list; Exception *exception; @@ -212,7 +212,8 @@ int add_session(char *nick, char *host) session = findsession(host); if (session) { - exception = find_host_exception(host); + exception = find_hostip_exception(host, hostip); + if (checkDefCon(DEFCON_REDUCE_SESSION)) { sessionlimit = exception ? exception->limit : DefConSessionLimit; @@ -348,30 +349,33 @@ void expire_exceptions(void) } /* Find the first exception this host matches and return it. */ - Exception *find_host_exception(const char *host) { - char *ipbuf = NULL; - char *myhost = NULL; int i; - /* we try to resolve the hostname to an IP in case - * the exception was added by IP instead of hostname - DrStein */ - if (host) - myhost = sstrdup(host); - ipbuf = host_resolve(myhost); + for (i = 0; i < nexceptions; i++) { + if ((match_wild_nocase(exceptions[i].mask, host))) { + return &exceptions[i]; + } + } + + return NULL; +} + +/* Same as find_host_exception() except + * this tries to find the exception by IP also. */ +Exception *find_hostip_exception(const char *host, const char *hostip) +{ + int i; for (i = 0; i < nexceptions; i++) { if ((match_wild_nocase(exceptions[i].mask, host)) - || ((ipbuf != NULL) - && match_wild_nocase(exceptions[i].mask, ipbuf))) { - Anope_Free(myhost); + || ((ircd->nickip && hostip) + && (match_wild_nocase(exceptions[i].mask, hostip)))) { return &exceptions[i]; } } - Anope_Free(myhost); - return NULL; } diff --git a/src/users.c b/src/users.c index e46c07d5a..fa747acd0 100644 --- a/src/users.c +++ b/src/users.c @@ -232,6 +232,7 @@ void delete_user(User * user) free(user->uid); } Anope_Free(user->realname); + Anope_Free(user->hostip); if (debug >= 2) { alog("debug: delete_user(): remove from channels"); } @@ -607,10 +608,9 @@ User *do_nick(const char *source, char *nick, char *username, char *host, return NULL; } /* Now check for session limits */ - if (LimitSessions && !add_session(nick, host)) + if (LimitSessions && !add_session(nick, host, ipbuf)) return NULL; - /* Allocate User structure and fill it in. */ user = new_user(nick); user->username = sstrdup(username); @@ -626,6 +626,13 @@ User *do_nick(const char *source, char *nick, char *username, char *host, user->uid = NULL; } user->vident = sstrdup(username); + /* We now store the user's ip in the user_ struct, + * because we will use it in serveral places -- DrStein */ + if (ircd->nickip) { + user->hostip = sstrdup(ipbuf); + } else { + user->hostip = NULL; + } if (svid == 0) { display_news(user, NEWS_LOGON); @@ -915,7 +922,6 @@ int is_excepted(ChannelInfo * ci, User * user) int count, i; int isexcepted = 0; char **excepts; - char *hostip = NULL; if (!ci->c) return 0; @@ -928,16 +934,13 @@ int is_excepted(ChannelInfo * ci, User * user) excepts = scalloc(sizeof(char *) * count, 1); memcpy(excepts, ci->c->excepts, sizeof(char *) * count); - hostip = host_resolve(user->host); - for (i = 0; i < count; i++) { if (match_usermask(excepts[i], user) - || (hostip && match_userip(excepts[i], user, hostip))) { + || match_userip(excepts[i], user, user->hostip)) { isexcepted = 1; break; } } - Anope_Free(hostip); free(excepts); return isexcepted; } |
