#include "client.h"
#include "ircd.h"
#include "ircd_alloc.h"
+#include "ircd_log.h"
#include "ircd_reply.h"
#include "ircd_string.h"
#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;
* get the users!
*/
if ((acptr = LocalClientArray[fd])) {
- if (!acptr->user)
+ if (!cli_user(acptr))
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 */
- sendto_one(acptr, ":%s %d %s :*** %s.", me.name, ERR_YOUREBANNEDCREEP,
- acptr->name, gline->gl_reason);
-
- /* let the ops know about it */
- sendto_op_mask(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, (cli_user(acptr))->username) != 0)
+ continue;
+
+ if (GlineIsIpMask(gline)) {
+ Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",(cli_ip(cptr)).s_addr,gline->ipnum.s_addr,gline->bits));
+ if (((cli_ip(acptr)).s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+ continue;
+ }
+ else {
+ if (match(gline->gl_host, acptr->sockhost) != 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;
}
return;
if (gline->gl_lastmod)
- sendcmdto_serv_butone(cptr, CMD_GLINE, sptr, "* %c%s%s%s %Tu %Tu :%s",
+ sendcmdto_serv_butone(sptr, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
gline->gl_expire - CurrentTime, gline->gl_lastmod,
gline->gl_reason);
else
- sendcmdto_serv_butone(cptr, CMD_GLINE, sptr, "* %c%s%s%s %Tu :%s",
- GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
- GlineIsBadChan(gline) ? "" : "@",
+ sendcmdto_serv_butone(sptr, CMD_GLINE, cptr,
+ (GlineIsRemActive(gline) ?
+ "* +%s%s%s %Tu :%s" : "* -%s%s%s"),
+ gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
gline->gl_expire - CurrentTime, gline->gl_reason);
}
*/
if (!(flags & GLINE_FORCE) && (expire <= 0 || expire > GLINE_MAX_EXPIRE)) {
if (!IsServer(sptr) && MyConnect(sptr))
- send_error_to_client(sptr, ERR_BADEXPIRE, expire);
+ send_reply(sptr, ERR_BADEXPIRE, expire);
return 0;
}
expire += CurrentTime; /* convert from lifetime to timestamp */
/* NO_OLD_GLINE allows *@#channel to work correctly */
-#ifdef BADCHAN
if (*userhost == '#' || *userhost == '&' || *userhost == '+'
# ifndef NO_OLD_GLINE
|| userhost[2] == '#' || userhost[2] == '&' || userhost[2] == '+'
# endif
flags |= GLINE_BADCHAN;
}
-#endif /* BADCHAN */
/* Inform ops... */
- sendto_op_mask(SNO_GLINE, "%s adding %s %s for %s, expiring at "
- TIME_T_FMT ": %s",
- IsServer(sptr) ? sptr->name : sptr->user->server->name,
- flags & GLINE_LOCAL ? "local" : "global",
- flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
- expire + TSoffset, reason);
-
-#ifdef GPATH
+ sendto_opmask_butone(0, SNO_GLINE, "%s adding %s %s for %s, expiring at "
+ "%Tu: %s", IsServer(sptr) ? cli_name(sptr) :
+ cli_name((cli_user(sptr))->server),
+ flags & GLINE_LOCAL ? "local" : "global",
+ flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+ expire + TSoffset, reason);
+
/* and log it */
- if (IsServer(sptr))
- write_log(GPATH, "# " TIME_T_FMT " %s adding %s %s for %s, expiring at "
- TIME_T_FMT ": %s\n", TStime(), sptr->name,
- flags & GLINE_LOCAL ? "local" : "global",
- flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
- expire + TSoffset, reason);
- else
- write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s adding %s %s for %s, "
- "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
- sptr->user->username, sptr->user->host,
- flags & GLINE_LOCAL ? "local" : "global",
- flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
- expire + TSoffset, reason);
-#endif /* GPATH */
+ log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+ "%#C adding %s %s for %s, expiring at %Tu: %s", sptr,
+ flags & GLINE_LOCAL ? "local" : "global",
+ flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", userhost,
+ expire + TSoffset, reason);
/* make the gline */
agline = make_gline(userhost, reason, expire, lastmod, flags);
if (GlineIsBadChan(agline))
return 0;
-#ifdef GPATH
- /* this can be inserted into the conf */
- write_log(GPATH, "%c:%s:%s:%s\n", GlineIsIpMask(agline) ? 'k' : 'K',
- GlineHost(agline), GlineReason(agline), GlineUser(agline));
-#endif /* GPATH */
-
return do_gline(cptr, sptr, agline); /* knock off users if necessary */
}
unsigned int saveflags = 0;
assert(0 != gline);
- assert(!GlineIsLocal(gline));
saveflags = gline->gl_flags;
return 0; /* was active to begin with */
/* Inform ops and log it */
- sendto_op_mask(SNO_GLINE, "%s activating global %s for %s%s%s, expiring at "
- TIME_T_FMT ": %s",
- IsServer(sptr) ? sptr->name : sptr->user->server->name,
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
- gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
- GlineIsBadChan(gline) ? "" : gline->gl_host,
- gline->gl_expire + TSoffset, gline->gl_reason);
-
-#ifdef GPATH
- if (IsServer(sptr))
- write_log(GPATH, "# " TIME_T_FMT " %s activating global %s for %s%s%s, "
- "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
- gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
- GlineIsBadChan(gline) ? "" : gline->gl_host,
- gline->gl_expire + TSoffset, gline->gl_reason);
- else
- write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s activating %s for "
- "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
- sptr->user->username, sptr->user->host,
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
- gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
- GlineIsBadChan(gline) ? "" : gline->gl_host,
- gline->gl_expire + TSoffset, gline->gl_reason);
-#endif /* GPATH */
-
- propagate_gline(cptr, sptr, gline);
+ sendto_opmask_butone(0, SNO_GLINE, "%s activating global %s for %s%s%s, "
+ "expiring at %Tu: %s", IsServer(sptr) ? cli_name(sptr) :
+ cli_name((cli_user(sptr))->server),
+ GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+ gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+ GlineIsBadChan(gline) ? "" : gline->gl_host,
+ gline->gl_expire + TSoffset, gline->gl_reason);
+
+ log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+ "%#C activating global %s for %s%s%s, expiring at %Tu: %s", sptr,
+ GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
+ GlineIsBadChan(gline) ? "" : "@",
+ GlineIsBadChan(gline) ? "" : gline->gl_host,
+ gline->gl_expire + TSoffset, gline->gl_reason);
+
+ 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";
+ gline->gl_flags &= ~GLINE_ACTIVE; /* propagate a -<mask> */
+ } else {
+ msg = "deactivating global";
+
if (flags & GLINE_LOCAL)
gline->gl_flags |= GLINE_LDEACT;
else {
}
/* Inform ops and log it */
- sendto_op_mask(SNO_GLINE, "%s %s %s for %s%s%s, expiring at "
- TIME_T_FMT ": %s",
- IsServer(sptr) ? sptr->name : sptr->user->server->name,
- GlineIsLocal(gline) ? "removing local" :
- "deactivating global",
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
- gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
- GlineIsBadChan(gline) ? "" : gline->gl_host,
- gline->gl_expire + TSoffset, gline->gl_reason);
-
-#ifdef GPATH
- if (IsServer(sptr))
- write_log(GPATH, "# " TIME_T_FMT " %s %s %s for %s%s%s, "
- "expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
- GlineIsLocal(gline) ? "removing local" : "deactivating global",
- GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
- gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
- GlineIsBadChan(gline) ? "" : gline->gl_host,
- gline->gl_expire + TSoffset, gline->gl_reason);
- else
- write_log(GPATH, "# " TIME_T_FMT " %s!%s@%s %s %s for "
- "%s%s%s, expiring at " TIME_T_FMT ": %s\n", TStime(), sptr->name,
- sptr->user->username, sptr->user->host,
- GlineIsLocal(gline) ? "removing local" : "deactivating global",
- 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))
- gline_free(gline);
- else
+ sendto_opmask_butone(0, SNO_GLINE, "%s %s %s for %s%s%s, expiring at %Tu: "
+ "%s", IsServer(sptr) ? cli_name(sptr) :
+ cli_name((cli_user(sptr))->server),
+ msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
+ gline->gl_user, GlineIsBadChan(gline) ? "" : "@",
+ GlineIsBadChan(gline) ? "" : gline->gl_host,
+ gline->gl_expire + TSoffset, gline->gl_reason);
+
+ log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
+ "%#C %s %s for %s%s%s, expiring at %Tu: %s", sptr, msg,
+ GlineIsBadChan(gline) ? "BADCHAN" : "GLINE", gline->gl_user,
+ GlineIsBadChan(gline) ? "" : "@",
+ GlineIsBadChan(gline) ? "" : gline->gl_host,
+ gline->gl_expire + TSoffset, gline->gl_reason);
+
+ if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
propagate_gline(cptr, sptr, gline);
+ /* if it's a local gline or a Uworld gline (and not locally deactivated).. */
+ if (GlineIsLocal(gline) || (!gline->gl_lastmod && !(flags & GLINE_LOCAL)))
+ gline_free(gline); /* get rid of it */
+
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, (cli_user(cptr))->username) != 0)
+ continue;
+
+ if (GlineIsIpMask(gline)) {
+ Debug((DEBUG_DEBUG,"IP gline: %08x %08x/%i",(cli_ip(cptr)).s_addr,gline->ipnum.s_addr,gline->bits));
+ if (((cli_ip(cptr)).s_addr & NETMASK(gline->bits)) != gline->ipnum.s_addr)
+ continue;
+ }
+ else {
+ if (match(gline->gl_host, (cli_user(cptr))->host) != 0)
+ continue;
+ }
+ return gline;
}
-
+ /*
+ * No Glines matched
+ */
return 0;
}
if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
gline_free(gline);
else if (!GlineIsLocal(gline) && gline->gl_lastmod)
- sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s@%s %Tu %Tu :%s",
+ sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s@%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_host, gline->gl_expire - CurrentTime,
gline->gl_lastmod, gline->gl_reason);
if (gline->gl_expire <= CurrentTime) /* expire any that need expiring */
gline_free(gline);
else if (!GlineIsLocal(gline) && gline->gl_lastmod)
- sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s %Tu %Tu :%s",
+ sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_expire - CurrentTime, gline->gl_lastmod,
gline->gl_reason);
if (GlineIsLocal(gline) || !gline->gl_lastmod)
return 0;
- sendcmdto_one(cptr, CMD_GLINE, &me, "* %c%s%s%s %Tu %Tu :%s",
+ sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s%s%s %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
if (userhost) {
if (!(gline = gline_find(userhost, GLINE_ANY))) /* no such gline */
- return send_error_to_client(sptr, ERR_NOSUCHGLINE, userhost);
+ return send_reply(sptr, ERR_NOSUCHGLINE, userhost);
/* send gline information along */
- sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name, gline->gl_user,
+ send_reply(sptr, RPL_GLIST, gline->gl_user,
GlineIsBadChan(gline) ? "" : "@",
GlineIsBadChan(gline) ? "" : gline->gl_host,
gline->gl_expire + TSoffset,
if (gline->gl_expire <= CurrentTime)
gline_free(gline);
else
- sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name,
- gline->gl_user, "@", gline->gl_host,
+ send_reply(sptr, RPL_GLIST, gline->gl_user, "@", gline->gl_host,
gline->gl_expire + TSoffset,
GlineIsLocal(gline) ? me.name : "*",
GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
if (gline->gl_expire <= CurrentTime)
gline_free(gline);
else
- sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name,
- gline->gl_user, "", "", gline->gl_expire + TSoffset,
+ send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
+ gline->gl_expire + TSoffset,
GlineIsLocal(gline) ? me.name : "*",
GlineIsActive(gline) ? '+' : '-', gline->gl_reason);
}
}
/* end of gline information */
- sendto_one(sptr, rpl_str(RPL_ENDOFGLIST), me.name, sptr->name);
- return 0;
+ return send_reply(sptr, RPL_ENDOFGLIST);
}
void
if (gline->gl_expire <= CurrentTime)
gline_free(gline);
else
- sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, sptr->name, 'G',
- gline->gl_user, gline->gl_host, gline->gl_expire + TSoffset,
- gline->gl_reason);
+ send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user, gline->gl_host,
+ gline->gl_expire + TSoffset, gline->gl_reason);
}
}