Bryan Drewery 21 лет назад
Родитель
Сommit
f970a6c622

+ 17 - 6
src/mod/irc.mod/chan.c

@@ -598,7 +598,7 @@ static void refresh_ban_kick(struct chanset_t *chan, char *user, char *nick)
      in second cycle. */
   for (int cycle = 0; cycle < 2; cycle++) {
     for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
-      if (wild_match(b->mask, user) || match_dir(b->mask, user)) {
+      if (wild_match(b->mask, user) || match_cidr(b->mask, user)) {
 	struct flag_record	fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 	char c[512] = "";		/* The ban comment.	*/
 	char s[UHOSTLEN] = "";
@@ -676,12 +676,14 @@ static void enforce_bans(struct chanset_t *chan)
   if (!me_op(chan))
     return;			/* Can't do it :( */
 
-  char me[UHOSTLEN] = "";
+  char me[UHOSTLEN] = "", meip[UHOSTLEN] = "";
 
   simple_sprintf(me, "%s!%s", botname, botuserhost);
+  simple_sprintf(meip, "%s!%s", botname, botuserip);
+
   /* Go through all bans, kicking the users. */
   for (masklist *b = chan->channel.ban; b && b->mask[0]; b = b->next) {
-    if (!wild_match(b->mask, me))
+    if (!(wild_match(b->mask, me) || match_cidr(b->mask, meip)))
       if (!isexempted(chan, b->mask) && !(chan->ircnet_status & CHAN_ASKED_EXEMPTS))
 	kick_all(chan, b->mask, IRC_YOUREBANNED, 1);
   }
@@ -1267,15 +1269,16 @@ void recheck_channel(struct chanset_t *chan, int dobans)
   stacking--;
 }
 
-#ifdef CACHE
 /* got 302: userhost
  * <server> 302 <to> :<nick??user@host>
  */
 static int got302(char *from, char *msg)
 {
   char *p = NULL, *nick = NULL, *uhost = NULL;
+#ifdef CACHE
   cache_t *cache = NULL;
   cache_chan_t *cchan = NULL;
+#endif
 
   newsplit(&msg);
   fixcolon(msg);
@@ -1293,6 +1296,13 @@ static int got302(char *from, char *msg)
   if ((p = strchr(uhost, ' ')))
     *p = 0;
 
+  if (match_my_nick(nick)) {
+    strlcpy(botuserip, uhost, UHOSTLEN);
+    sdprintf("botuserip: %s", botuserip);
+    return 0;
+  }
+
+#ifdef CACHE
   if ((cache = cache_find(nick))) {
     if (!cache->uhost[0])
     strcpy(cache->uhost, uhost);
@@ -1320,10 +1330,11 @@ static int got302(char *from, char *msg)
       }
     }
   }
-
+#endif
   return 0;
 }
 
+#ifdef CACHE
 /* got341 invited
  * <server> 341 <to> <nick> <channel>
  */
@@ -3024,8 +3035,8 @@ static int gotnotice(char *from, char *msg)
 
 static cmd_t irc_raw[] =
 {
-#ifdef CACHE
   {"302",       "",     (Function) got302,      "irc:302", LEAF},
+#ifdef CACHE
   {"341",       "",     (Function) got341,      "irc:341", LEAF},
 #endif /* CACHE */
   {"324",	"",	(Function) got324,	"irc:324", LEAF},

+ 19 - 28
src/mod/irc.mod/irc.c

@@ -336,8 +336,8 @@ getin_request(char *botnick, char *code, char *par)
 
   struct userrec *u = NULL;
   memberlist *mem = NULL;
-  char *hst = newsplit(&par), *ip4 = NULL, *ip6 = NULL, *tmp = NULL;
-  char nick[NICKLEN] = "", host[UHOSTLEN] = "", ip4host[UHOSTLEN] = "", ip6host[UHOSTLEN] = "";
+  char *hst = newsplit(&par), *ip = NULL, *tmp = NULL;
+  char nick[NICKLEN] = "", uhost[UHOSTLEN] = "", uip[UHOSTLEN];
   struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
 
   if (nck[0]) {
@@ -346,31 +346,20 @@ getin_request(char *botnick, char *code, char *par)
     nick[0] = 0;
 
   if (hst[0]) {
-    strlcpy(host, hst, sizeof(host));
-    ip4 = newsplit(&par);
-    if (ip4[0]) {
+    strlcpy(uhost, hst, sizeof(uhost));
+    ip = newsplit(&par);
+    if (ip[0]) {
       char *tmp2 = NULL;
 
-      tmp = strdup(host);
+      tmp = strdup(uhost);
       tmp2 = strtok(tmp, "@");
-      egg_snprintf(ip4host, sizeof ip4host, "%s@%s", strtok(tmp2, "@"), ip4);
+      egg_snprintf(uip, sizeof uip, "%s@%s", strtok(tmp2, "@"), ip);
       free(tmp);
     } else {
-      ip4host[0] = 0;
-    }
-    ip6 = newsplit(&par);
-    if (ip6[0]) {
-      char *tmp2 = NULL;
-
-      tmp = strdup(host);
-      tmp2 = strtok(tmp, "@");
-      egg_snprintf(ip6host, sizeof ip6host, "%s@%s", strtok(tmp2, "@"), ip6);
-      free(tmp);
-    } else {
-      ip6host[0] = 0;
+      uip[0] = 0;
     }
   } else
-    host[0] = 0;
+    uhost[0] = 0;
   /*
    * if (!ismember(chan, botname)) {
    * putlog(LOG_GETIN, "*", "getin req from %s for %s - I'm not on %s!", botnick, chname, chname);
@@ -516,8 +505,9 @@ getin_request(char *botnick, char *code, char *par)
 
     mr = &global_bans;
     while (*mr) {
-      if (wild_match((*mr)->mask, host) || wild_match((*mr)->mask, ip4host) || wild_match((*mr)->mask, ip6host) || 
-          match_cidr((*mr)->mask, ip4host) || match_cidr((*mr)->mask, ip6host)) {
+      if (wild_match((*mr)->mask, uhost) || 
+          wild_match((*mr)->mask, uip) || 
+          match_cidr((*mr)->mask, uip)) {
         if (!noshare) {
           shareout("-m b %s\n", (*mr)->mask);
         }
@@ -538,8 +528,9 @@ getin_request(char *botnick, char *code, char *par)
     }
     mr = &chan->bans;
     while (*mr) {
-      if (wild_match((*mr)->mask, host) || wild_match((*mr)->mask, ip4host) || wild_match((*mr)->mask, ip6host) ||
-          match_cidr((*mr)->mask, ip4host) || match_cidr((*mr)->mask, ip6host)) {
+      if (wild_match((*mr)->mask, uhost) || 
+          wild_match((*mr)->mask, uip) || 
+          match_cidr((*mr)->mask, uip)) {
         if (!noshare) {
           shareout("-mc b %s %s\n", chan->dname, (*mr)->mask);
         }
@@ -558,8 +549,9 @@ getin_request(char *botnick, char *code, char *par)
       }
     }
     for (struct maskstruct *b = chan->channel.ban; b->mask[0]; b = b->next) {
-      if (wild_match(b->mask, host) || wild_match(b->mask, ip4host) || wild_match(b->mask, ip6host) ||
-          match_cidr(b->mask, ip4host) || match_cidr(b->mask, ip6host)) {
+      if (wild_match(b->mask, uhost) || 
+          wild_match(b->mask, uip) || 
+          match_cidr(b->mask, uip)) {
         add_mode(chan, '-', 'b', b->mask);
         putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Removed active ban %s", botnick, nick, chan->dname,
                b->mask);
@@ -773,8 +765,7 @@ request_in(struct chanset_t *chan)
 
   if (!checked_hostmask)
     check_hostmask();           /* check, and update hostmask */
-  sprintf(s, "gi i %s %s %s!%s %s %s", chan->dname, botname, botname, botuserhost,
-          myipstr(4) ? myipstr(4) : ".", myipstr(6) ? myipstr(6) : ".");
+  sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
   while (cnt) {
     n = randint(i);
     if (botops[n]) {

+ 5 - 4
src/mod/irc.mod/mode.c

@@ -690,16 +690,17 @@ got_deop(struct chanset_t *chan, memberlist *m, memberlist *mv, char *isserver)
 static void
 got_ban(struct chanset_t *chan, memberlist *m, char *mask, char *isserver)
 {
-  char me[UHOSTLEN] = "", s[UHOSTLEN] = "";
+  char me[UHOSTLEN] = "", meip[UHOSTLEN] = "", s[UHOSTLEN] = "";
 
-  egg_snprintf(me, sizeof me, "%s!%s", botname, botuserhost);
+  simple_sprintf(me, "%s!%s", botname, botuserhost);
+  simple_sprintf(meip, "%s!%s", botname, botuserip);
   egg_snprintf(s, sizeof s, "%s!%s", m ? m->nick : "", m ? m->userhost : isserver);
   newban(chan, mask, s);
 
   if (channel_pending(chan) || !me_op(chan))
     return;
 
-  if ((wild_match(mask, me) || match_cidr(mask, me)) && !isexempted(chan, me)) {
+  if ((wild_match(mask, me) || match_cidr(mask, meip)) && !isexempted(chan, me)) {
     add_mode(chan, '-', 'b', mask);
     reversing = 1;
     return;
@@ -738,7 +739,7 @@ got_ban(struct chanset_t *chan, memberlist *m, char *mask, char *isserver)
     /* The point of this cycle crap is to first check chan->bans then global_bans for a reason */
     for (int cycle = 0; cycle < 2; cycle++) {
       for (b = cycle ? chan->bans : global_bans; b; b = b->next) {
-        if (wild_match(b->mask, mask)) {
+        if (wild_match(b->mask, mask) || match_cidr(b->mask, mask)) {
           if (b->desc && b->desc[0] != '@')
             egg_snprintf(resn, sizeof resn, "banned: %s", b->desc);
           else

+ 3 - 0
src/mod/server.mod/server.c

@@ -44,6 +44,8 @@ int flud_ctcp_thr = 3;	/* ctcp flood threshold */
 time_t flud_ctcp_time = 60;	/* ctcp flood time */
 char botuserhost[UHOSTLEN] = "";	/* bot's user@host (refreshed whenever the bot joins a channel) */
 					/* may not be correct user@host BUT it's how the server sees it */
+char botuserip[UHOSTLEN] = "";		/* bot's user@host with the ip. */
+
 static bool keepnick = 1;		/* keep trying to regain my intended
 				   nickname? */
 static bool nick_juped = 0;	/* True if origbotname is juped(RPL437) (dw) */
@@ -991,6 +993,7 @@ void server_report(int idx, int details)
     dprintf(idx, "    Online as: %s%s%s (%s)\n", botname,
 	    botuserhost[0] ? "!" : "", botuserhost[0] ? botuserhost : "",
 	    botrealname);
+    dprintf(idx, "    My userip: %s!%s\n", botname, botuserip);
     if (nick_juped)
       dprintf(idx, "    NICK IS JUPED: %s %s\n", origbotname,
 	      keepnick ? "(trying)" : "");

+ 1 - 1
src/mod/server.mod/server.h

@@ -50,7 +50,7 @@ extern int 		servidx, ctcp_mode, flud_thr, flud_ctcp_thr, answer_ctcp, serv;
 extern port_t		default_port, newserverport;
 extern time_t		server_online, cycle_time, flud_time, flud_ctcp_time;
 extern char		cursrvname[], botrealname[], botuserhost[], ctcp_reply[],
-			newserver[], newserverpass[], curnetwork[];
+			newserver[], newserverpass[], curnetwork[], botuserip[];
 extern struct server_list *serverlist;
 
 int check_bind_ctcpr(char *, char *, struct userrec *, char *, char *, char *, bind_table_t *);

+ 2 - 0
src/mod/server.mod/servmsg.c

@@ -158,6 +158,7 @@ static int got001(char *from, char *msg)
   strlcpy(cursrvname, from, sizeof(cursrvname));
 
   dprintf(DP_SERVER, "WHOIS %s\n", botname); /* get user@host */
+  dprintf(DP_SERVER, "USERHOST %s\n", botname); /* get user@ip */
   dprintf(DP_SERVER, "MODE %s +iws\n", botname);
   x = serverlist;
   if (x == NULL)
@@ -923,6 +924,7 @@ static void disconnect_server(int idx, int dolost)
   checked_hostmask = 0;
   floodless = 0;
   botuserhost[0] = 0;
+  botuserip[0] = 0;
   if (dolost) {
     Auth::DeleteAll();
     trying_server = 0;