From f219bcd6646844f147a949ec97fe040f610b3bdc Mon Sep 17 00:00:00 2001 From: Fish <> Date: Sat, 21 Feb 2004 05:09:54 +0000 Subject: [PATCH] core support for looking up a users ip address when they sign on. Now to modify StatServ --- Bahamut.h | 3 +++ Ircu.h | 2 ++ QuantumIRCd.h | 2 ++ Ultimate.h | 4 ++++ Unreal.h | 5 +++++ events.h | 12 ++++++++++++ hybrid7.h | 2 ++ liquidircd.h | 2 ++ main.c | 1 + mystic.h | 2 ++ neoircd.h | 2 ++ stats.h | 3 ++- users.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 13 files changed, 88 insertions(+), 3 deletions(-) diff --git a/Bahamut.h b/Bahamut.h index 2409b562..f76bc67f 100644 --- a/Bahamut.h +++ b/Bahamut.h @@ -64,6 +64,9 @@ #define GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we have nickip */ +#define GOTNICKIP + /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/Ircu.h b/Ircu.h index 4e04e404..4daa8197 100644 --- a/Ircu.h +++ b/Ircu.h @@ -66,6 +66,8 @@ #undef GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we have nickip support */ +#define GOTNICKIP /* Override NeoStats core splitbuf function */ /* #define IRCD_SPLITBUF */ diff --git a/QuantumIRCd.h b/QuantumIRCd.h index 5140d12d..7101fa5e 100644 --- a/QuantumIRCd.h +++ b/QuantumIRCd.h @@ -64,6 +64,8 @@ #define GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we have nickip support */ +#define GOTNICKIP /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/Ultimate.h b/Ultimate.h index 91fd9c93..62b771a0 100644 --- a/Ultimate.h +++ b/Ultimate.h @@ -60,6 +60,8 @@ #define GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we dont have a nickip field in the nick message */ +#undef GOTNICKIP #else /* !ULTIMATE3 */ @@ -91,6 +93,8 @@ #undef GOTUSERSMODES /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we dont have a nickip field in the nick message */ +#undef GOTNICKIP #endif /* ULTIMATE3 */ diff --git a/Unreal.h b/Unreal.h index 3e48be7f..16237834 100644 --- a/Unreal.h +++ b/Unreal.h @@ -63,6 +63,11 @@ #define GOTSVSKILL /* we have automatic host cloaking support via Umode */ #define GOTUMODECLOAKING +/* we dont have a nickip field in the nick message */ +#undef GOTNICKIP + + + /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/events.h b/events.h index e2f1d634..e061fd98 100644 --- a/events.h +++ b/events.h @@ -267,3 +267,15 @@ */ #define EVENT_DELBAN "DELBAN" +/* EVENT_GOTNICKIP + * fired when we get the IP address of a user + * only fired if me.want_nickip = 1 and: + * the ircd sends the nickip as part of the connect message + * or + * a dns lookup completes and is successfull + * + * Parameters: + * av[0] nick + */ + +#define EVENT_GOTNICKIP "NICKIP" diff --git a/hybrid7.h b/hybrid7.h index a3677256..db45e97b 100644 --- a/hybrid7.h +++ b/hybrid7.h @@ -64,6 +64,8 @@ #undef GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we dont' ahve nickip support */ +#undef GOTNICKIP /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/liquidircd.h b/liquidircd.h index f22747d0..9a0f172f 100644 --- a/liquidircd.h +++ b/liquidircd.h @@ -64,6 +64,8 @@ #define GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we have NICKIP suport */ +#define GOTNICKIP /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/main.c b/main.c index 930cacff..04abbe1d 100644 --- a/main.c +++ b/main.c @@ -121,6 +121,7 @@ main (int argc, char *argv[]) me.now = time(NULL); ircsnprintf (me.strnow, STR_TIME_T_SIZE, "%ld", (long)me.now); me.want_privmsg = 0; + me.want_nickip = 0; me.die = 0; me.local[0] = '\0'; me.debug_mode = 0; diff --git a/mystic.h b/mystic.h index b7c8350a..41954854 100644 --- a/mystic.h +++ b/mystic.h @@ -64,6 +64,8 @@ #define GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we dont have nickip */ +#undef GOTNICKIP /* buffer sizes */ #define MAXHOST (75 + 1) diff --git a/neoircd.h b/neoircd.h index 2e1a7e3b..c4079d31 100644 --- a/neoircd.h +++ b/neoircd.h @@ -64,6 +64,8 @@ #undef GOTSVSKILL /* we don't have automatic host cloaking support via Umode */ #undef GOTUMODECLOAKING +/* we dont have nickip support */ +#undef GOTNICKIP /* buffer sizes */ #define MAXHOST (128 + 1) diff --git a/stats.h b/stats.h index 21918790..cd1145b3 100644 --- a/stats.h +++ b/stats.h @@ -228,7 +228,7 @@ #define T_TABLE_SIZE 300 /* Number of Timers */ #define B_TABLE_SIZE 100 /* Number of Bots */ #define MAXMODES -1 -#define DNS_QUEUE_SIZE 100 /* number on concurrent DNS lookups */ +#define DNS_QUEUE_SIZE 300 /* number on concurrent DNS lookups */ #define MAX_TRANSFERS 10 /* number of curl transfers */ #define bzero(x, y) memset(x, '\0', y); @@ -375,6 +375,7 @@ struct me { unsigned int onlyopers:1; unsigned int die:1; unsigned int debug_mode:1; + unsigned int want_nickip:1; #if defined(ULTIMATE3) || defined(QUANTUM) unsigned int client:1; #endif diff --git a/users.c b/users.c index 4135b824..5f3d1656 100644 --- a/users.c +++ b/users.c @@ -36,6 +36,11 @@ #ifdef SQLSRV #include "sqlsrv/rta.h" #endif +#ifndef GOTNICKIP +#include +#include +#include +#endif hash_t *uh; @@ -68,6 +73,21 @@ new_user (const char *nick) return (u); } +static void +lookupnickip(char *data, adns_answer *a) { + User *u; + char **av; + int ac = 0; + + u = finduser((char *)data); + if (a && a->nrrs > 0 && u && a->status == adns_s_ok) { + u->ipaddr.s_addr = a->rrs.addr->addr.inet.sin_addr.s_addr; +printf("%s\n", inet_ntoa(u->ipaddr)); + AddStringToList (&av, u->nick, &ac); + ModuleEvent (EVENT_GOTNICKIP, av, ac); + } +} + void AddUser (const char *nick, const char *user, const char *host, const char *realname, const char *server, const char*ip, const char* TS, const char* numeric) { @@ -77,6 +97,10 @@ AddUser (const char *nick, const char *user, const char *host, const char *realn int ac = 0; User *u; int i; +#ifndef GOTNICKIP + struct in_addr *ipad; + int res; +#endif SET_SEGV_LOCATION(); u = finduser (nick); @@ -85,10 +109,29 @@ AddUser (const char *nick, const char *user, const char *host, const char *realn return; } - if(ip) { + if(0) { ipaddress = strtoul (ip, NULL, 10); } else { - ipaddress = 0; +#ifndef GOTNICKIP + if (me.want_nickip == 1) { + /* first, if the u->host is a ip address, just convert it */ + ipad = malloc(sizeof(struct in_addr)); + res = inet_aton(host, ipad); + if (res > 0) { + /* its valid */ + ipaddress = ipad->s_addr; + free(ipad); + } else { + /* kick of a dns reverse lookup for this host */ + dns_lookup((char *)host, adns_r_addr, lookupnickip, (void *)nick); + ipaddress = 0; + } + } else { + ipaddress = 0; + } +#else + ipaddress = 0; +#endif } if(TS) { time = strtoul (TS, NULL, 10); @@ -139,6 +182,10 @@ AddUser (const char *nick, const char *user, const char *host, const char *realn AddStringToList (&av, u->nick, &ac); ModuleEvent (EVENT_SIGNON, av, ac); + if (me.want_nickip == 1 && ipaddress != 0) { + /* only fire this event if we have the nickip and some module wants it */ + ModuleEvent (EVENT_GOTNICKIP, av, ac); + } free (av); }