#include "match.h"
#include "numeric.h"
#include "s_bsd.h"
+#include "s_debug.h"
#include "s_misc.h"
#include "send.h"
#include "struct.h"
#include <assert.h>
#include <string.h>
+#include <stdio.h>
+#include <arpa/inet.h> /* for inet_ntoa */
struct Gline* GlobalGlineList = 0;
struct Gline* BadChanGlineList = 0;
DupString(gline->gl_user, user); /* remember them... */
DupString(gline->gl_host, host);
- if (check_if_ipmask(host)) /* mark if it's an IP mask */
+ if (check_if_ipmask(host)) { /* mark if it's an IP mask */
+ int class;
+ char ipname[16];
+ int ad[4] = { 0 };
+ int bits2 = 0;
+
+ class = sscanf(host,"%d.%d.%d.%d/%d",
+ &ad[0],&ad[1],&ad[2],&ad[3], &bits2);
+ if (class!=5) {
+ gline->bits=class*8;
+ }
+ else {
+ gline->bits=bits2;
+ }
+ sprintf_irc(ipname,"%d.%d.%d.%d",ad[0],ad[1],ad[2],ad[3]);
+ gline->ipnum.s_addr = inet_addr(ipname);
+ Debug((DEBUG_DEBUG,"IP gline: %08x/%i",gline->ipnum.s_addr,gline->bits));
gline->gl_flags |= GLINE_IPMASK;
+ }
if (after) {
gline->gl_next = after->gl_next;
if ((acptr = LocalClientArray[fd])) {
if (!acptr->user)
continue;
-
- if ((GlineIsIpMask(gline) ? match(gline->gl_host, acptr->sock_ip) :
- match(gline->gl_host, acptr->sockhost)) == 0 &&
- (!acptr->user->username ||
- match(gline->gl_user, acptr->user->username) == 0)) {
- /* ok, here's one that got G-lined */
- send_reply(acptr, RPL_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s",
- gline->gl_reason);
-
- /* let the ops know about it */
- sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s",
- get_client_name(acptr, FALSE));
-
- /* and get rid of him */
- if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
- gline->gl_reason)))
- retval = tval; /* retain killed status */
+
+ if (acptr->user->username &&
+ match(gline->gl_user, acptr->user->username) == 0)
+ continue;
+
+ if (GlineIsIpMask(gline)) {
+ Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",cptr->ip.s_addr,gline->ipnum.s_addr,gline->bits));
+ if ((cptr->ip.s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+ continue;
}
+ else {
+ if (match(gline->gl_host, acptr->sock_ip) != 0)
+ continue;
+ }
+
+ /* ok, here's one that got G-lined */
+ send_reply(acptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s",
+ gline->gl_reason);
+
+ /* let the ops know about it */
+ sendto_opmask_butone(0, SNO_GLINE, "G-line active for %s",
+ get_client_name(acptr, FALSE));
+
+ /* and get rid of him */
+ if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)",
+ gline->gl_reason)))
+ retval = tval; /* retain killed status */
}
}
-
return retval;
}
unsigned int saveflags = 0;
assert(0 != gline);
- assert(!GlineIsLocal(gline));
saveflags = gline->gl_flags;
gline->gl_expire + TSoffset, gline->gl_reason);
#endif /* GPATH */
- propagate_gline(cptr, sptr, gline);
+ if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
+ propagate_gline(cptr, sptr, gline);
return GlineIsBadChan(gline) ? 0 : do_gline(cptr, sptr, gline);
}
time_t lastmod, unsigned int flags)
{
unsigned int saveflags = 0;
+ char *msg;
assert(0 != gline);
saveflags = gline->gl_flags;
- if (!GlineIsLocal(gline)) {
+ if (GlineIsLocal(gline))
+ msg = "removing local";
+ else if (!gline->gl_lastmod && !(flags & GLINE_LOCAL))
+ msg = "removing global";
+ else {
+ msg = "deactivating global";
+
if (flags & GLINE_LOCAL)
gline->gl_flags |= GLINE_LDEACT;
else {
sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s, expiring at %Tu: "
"%s",
IsServer(sptr) ? sptr->name : sptr->user->server->name,
- GlineIsLocal(gline) ? "removing local" :
- "deactivating global",
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+ msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
gline->gl_expire + TSoffset, gline->gl_reason);
#ifdef GPATH
write_log(GPATH, "# %Tu %C %s %s for %s%s%s, expiring at %Tu: %s\n",
- TStime(), sptr,
- GlineIsLocal(gline) ? "removing local" : "deactivating global",
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+ TStime(), sptr, msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
gline->gl_expire + TSoffset, gline->gl_reason);
#endif /* GPATH */
- if (GlineIsLocal(gline))
+ if (GlineIsLocal(gline) || (!gline->gl_lastmod && !(flags & GLINE_LOCAL)))
gline_free(gline);
- else
+ else if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
propagate_gline(cptr, sptr, gline);
return 0;
if (gline->gl_expire <= CurrentTime)
gline_free(gline);
+ else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+ (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+ continue;
else if ((flags & GLINE_EXACT ? ircd_strcmp(gline->gl_user, userhost) :
match(gline->gl_user, userhost)) == 0)
return gline;
if (gline->gl_expire <= CurrentTime)
gline_free(gline);
+ else if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+ (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+ continue;
else if (flags & GLINE_EXACT) {
if (ircd_strcmp(gline->gl_host, host) == 0 &&
((!user && ircd_strcmp(gline->gl_user, "*") == 0) ||
}
struct Gline *
-gline_lookup(struct Client *cptr)
+gline_lookup(struct Client *cptr, unsigned int flags)
{
struct Gline *gline;
struct Gline *sgline;
for (gline = GlobalGlineList; gline; gline = sgline) {
sgline = gline->gl_next;
- if (gline->gl_expire <= CurrentTime)
+ if (gline->gl_expire <= CurrentTime) {
gline_free(gline);
- else if ((GlineIsIpMask(gline) ?
- match(gline->gl_host, ircd_ntoa((const char *)&cptr->ip)) :
- match(gline->gl_host, cptr->user->host)) == 0 &&
- match(gline->gl_user, cptr->user->username) == 0)
- return gline;
+ continue;
+ }
+
+ if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
+ (flags & GLINE_LASTMOD && !gline->gl_lastmod))
+ continue;
+
+ if (match(gline->gl_user, cptr->user->username) != 0)
+ continue;
+
+ if (GlineIsIpMask(gline)) {
+ Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",cptr->ip.s_addr,gline->ipnum.s_addr,gline->bits));
+ if ((cptr->ip.s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+ continue;
+ }
+ else {
+ if (match(gline->gl_host, cptr->user->host) != 0)
+ continue;
+ }
+ return gline;
}
-
+ /*
+ * No Glines matched
+ */
return 0;
}