diff options
| author | drstein drstein@31f1291d-b8d6-0310-a050-a5561fc1590b <drstein drstein@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2007-08-31 20:40:36 +0000 |
|---|---|---|
| committer | drstein drstein@31f1291d-b8d6-0310-a050-a5561fc1590b <drstein drstein@31f1291d-b8d6-0310-a050-a5561fc1590b@5417fbe8-f217-4b02-8779-1006273d7864> | 2007-08-31 20:40:36 +0000 |
| commit | 317b3e0c4efa277c29e77f8acd3e8b4b000bdc36 (patch) | |
| tree | 8fb8df7ed5b7f5912ee2fbfc0e4956c5ed152a88 | |
| parent | d5a2079085b739a0eb31d1074822a2ecedc0e4fa (diff) | |
BUILD : 1.7.19 (1295) BUGS : N/A NOTES : We now have hostip in user_ struct so we can use it where needed. We wont do host_resolve() unless it is extremely necessary, coz we dont want to flood the nameserver.
git-svn-id: svn://svn.anope.org/anope/trunk@1295 31f1291d-b8d6-0310-a050-a5561fc1590b
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1013 5417fbe8-f217-4b02-8779-1006273d7864
| -rw-r--r-- | Changes | 1 | ||||
| -rw-r--r-- | include/extern.h | 3 | ||||
| -rw-r--r-- | include/services.h | 1 | ||||
| -rw-r--r-- | src/sessions.c | 34 | ||||
| -rw-r--r-- | src/users.c | 17 | ||||
| -rw-r--r-- | version.log | 7 |
6 files changed, 39 insertions, 24 deletions
@@ -1,5 +1,6 @@ Anope Version S V N -------------------- +08/31 A Added hostip member to user_ struct so we can now use users's IPs [ #00] 08/30 A Added support for channel keys to UnrealIRCd 3.2 SVSJOIN command [#774] 08/29 A Session limit exceptions now support IP numbers as hostmask [#723] 08/29 A Added InspIRCd11 vIdent support. [#684] diff --git a/include/extern.h b/include/extern.h index df8b7f74a..eefe55d23 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1053,7 +1053,7 @@ E void get_session_stats(long *nrec, long *memuse); E void get_exception_stats(long *nrec, long *memuse); E int do_session(User *u); -E int add_session(char *nick, char *host); +E int add_session(char *nick, char *host, char *hostip); E void del_session(const char *host); E void load_exceptions(void); @@ -1065,6 +1065,7 @@ E void expire_exceptions(void); E Session *findsession(const char *host); E Exception *find_host_exception(const char *host); +E Exception *find_hostip_exception(const char *host, const char *hostip); E int exception_add(User * u, const char *mask, const int limit, const char *reason, const char *who, const time_t expires); diff --git a/include/services.h b/include/services.h index 17e2c26a7..a98e3c121 100644 --- a/include/services.h +++ b/include/services.h @@ -849,6 +849,7 @@ struct user_ { char *username; /* ident */ char *host; /* User's real hostname */ + char *hostip; /* User's IP number */ char *vhost; /* User's virtual hostname */ char *vident; /* User's virtual ident */ char *realname; /* Realname */ 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; } diff --git a/version.log b/version.log index ef8858963..7c3cc2b86 100644 --- a/version.log +++ b/version.log @@ -9,10 +9,15 @@ VERSION_MAJOR="1" VERSION_MINOR="7" VERSION_PATCH="19" VERSION_EXTRA="-svn" -VERSION_BUILD="1294" +VERSION_BUILD="1295" # $Log$ # +# BUILD : 1.7.19 (1295) +# BUGS : N/A +# NOTES : We now have hostip in user_ struct so we can use it where needed. We wont do host_resolve() unless +# it is extremely necessary, coz we dont want to flood the nameserver. +# # BUILD : 1.7.19 (1294) # BUGS : N/A # NOTES : in is_excepted() if we found the exception, break(). There is no point on continue exploring the |
