/* Figure out the next pointer in list... */ \
if ((((next) = (gl)->gl_next) || 1) && \
/* Then see if it's expired */ \
- (gl)->gl_lifetime <= CurrentTime) \
+ (gl)->gl_lifetime <= TStime()) \
/* Record has expired, so free the G-line */ \
gline_free((gl)); \
/* See if we need to expire the G-line */ \
- else if ((((gl)->gl_expire > CurrentTime) || \
+ else if ((((gl)->gl_expire > TStime()) || \
(((gl)->gl_flags &= ~GLINE_ACTIVE) && 0) || \
((gl)->gl_state = GLOCAL_GLOBAL)) && 0) \
; /* empty statement */ \
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire - CurrentTime, gline->gl_lastmod,
+ gline->gl_expire - TStime(), gline->gl_lastmod,
gline->gl_lifetime, gline->gl_reason);
return 0;
/** Count number of users who match \a mask.
* @param[in] mask user\@host or user\@ip mask to check.
+ * @param[in] flags Bitmask possibly containing the value GLINE_LOCAL, to limit searches to this server.
* @return Count of matching users.
*/
static int
-count_users(char *mask)
+count_users(char *mask, int flags)
{
+ struct irc_in_addr ipmask;
struct Client *acptr;
int count = 0;
+ int ipmask_valid;
char namebuf[USERLEN + HOSTLEN + 2];
char ipbuf[USERLEN + SOCKIPLEN + 2];
+ unsigned char ipmask_len;
+ ipmask_valid = ipmask_parse(mask, &ipmask, &ipmask_len);
for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
if (!IsUser(acptr))
continue;
+ if ((flags & GLINE_LOCAL) && !MyConnect(acptr))
+ continue;
ircd_snprintf(0, namebuf, sizeof(namebuf), "%s@%s",
cli_user(acptr)->username, cli_user(acptr)->host);
ircd_snprintf(0, ipbuf, sizeof(ipbuf), "%s@%s", cli_user(acptr)->username,
ircd_ntoa(&cli_ip(acptr)));
- if (!match(mask, namebuf) || !match(mask, ipbuf))
+ if (!match(mask, namebuf)
+ || !match(mask, ipbuf)
+ || (ipmask_valid && ipmask_check(&cli_ip(acptr), &ipmask, ipmask_len)))
count++;
}
assert(0 != userhost);
assert(0 != reason);
+ assert(((flags & (GLINE_GLOBAL | GLINE_LOCAL)) == GLINE_GLOBAL) ||
+ ((flags & (GLINE_GLOBAL | GLINE_LOCAL)) == GLINE_LOCAL));
Debug((DEBUG_DEBUG, "gline_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu "
"%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), userhost, reason,
break;
}
- if ((tmp = count_users(uhmask)) >=
+ if ((tmp = count_users(uhmask, flags)) >=
feature_int(FEAT_GLINEMAXUSERCOUNT) && !(flags & GLINE_OPERFORCE))
return send_reply(sptr, ERR_TOOMANYUSERS, tmp);
}
* expiration time for greater than GLINE_MAX_EXPIRE.
*/
if (!(flags & GLINE_FORCE) &&
- (expire <= CurrentTime || expire > CurrentTime + GLINE_MAX_EXPIRE)) {
+ (expire <= TStime() || expire > TStime() + GLINE_MAX_EXPIRE)) {
if (!IsServer(sptr) && MyConnect(sptr))
send_reply(sptr, ERR_BADEXPIRE, expire);
return 0;
+ } else if (expire <= TStime()) {
+ /* This expired G-line was forced to be added, so mark it inactive. */
+ flags &= ~GLINE_ACTIVE;
}
if (!lifetime) /* no lifetime set, use expiration time */
/* Inform ops... */
sendto_opmask_butone(0, ircd_strncmp(reason, "AUTO", 4) ? SNO_GLINE :
- SNO_AUTO, "%s adding %s %s for %s%s%s, expiring at "
+ SNO_AUTO, "%s adding %s%s %s for %s%s%s, expiring at "
"%Tu: %s",
(feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
cli_name(sptr) :
cli_name((cli_user(sptr))->server),
+ (flags & GLINE_ACTIVE) ? "" : "deactivated ",
(flags & GLINE_LOCAL) ? "local" : "global",
(flags & GLINE_BADCHAN) ? "BADCHAN" : "GLINE", user,
(flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : "@",
(flags & (GLINE_BADCHAN|GLINE_REALNAME)) ? "" : host,
- expire + TSoffset, reason);
+ expire, reason);
/* and log it */
log_write(LS_GLINE, L_INFO, LOG_NOSNOTICE,
flags & GLINE_BADCHAN ? "BADCHAN" : "GLINE", user,
flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : "@",
flags & (GLINE_BADCHAN|GLINE_REALNAME) ? "" : host,
- expire + TSoffset, reason);
+ expire, reason);
/* make the gline */
agline = make_gline(user, host, reason, expire, lastmod, lifetime, flags);
GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
gline->gl_user, gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_reason);
-
+ gline->gl_expire, 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,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_reason);
+ gline->gl_expire, gline->gl_reason);
if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
gline_propagate(cptr, sptr, gline);
msg, GlineIsBadChan(gline) ? "BADCHAN" : "GLINE",
gline->gl_user, gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_reason);
+ gline->gl_expire, 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,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_reason);
+ gline->gl_expire, gline->gl_reason);
if (!(flags & GLINE_LOCAL)) /* don't propagate local changes */
gline_propagate(cptr, sptr, gline);
/* first, check out the expiration time... */
if ((flags & GLINE_EXPIRE) && expire) {
if (!(flags & GLINE_FORCE) &&
- (expire <= CurrentTime || expire > CurrentTime + GLINE_MAX_EXPIRE)) {
+ (expire <= TStime() || expire > TStime() + GLINE_MAX_EXPIRE)) {
if (!IsServer(sptr) && MyConnect(sptr)) /* bad expiration time */
send_reply(sptr, ERR_BADEXPIRE, expire);
return 0;
(action == GLINE_LOCAL_DEACTIVATE &&
(gline->gl_state == GLOCAL_DEACTIVATED)) ||
/* can't activate an expired G-line */
- IRCD_MAX(gline->gl_expire, expire) <= CurrentTime)
+ IRCD_MAX(gline->gl_expire, expire) <= TStime())
action = GLINE_MODIFY; /* no activity state modifications */
Debug((DEBUG_DEBUG, "About to perform changes; flags 0x%04x, action %s",
flags & GLINE_OPERFORCE ? "!" : "", op,
gline->gl_user, gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire - CurrentTime, gline->gl_lastmod,
+ gline->gl_expire - TStime(), gline->gl_lastmod,
gline->gl_lifetime, gline->gl_reason);
/* OK, let's do the G-line... */
if (flags & (GLINE_BADCHAN | GLINE_ANY)) {
gliter(BadChanGlineList, gline, sgline) {
- if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
- (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+ if ((flags & (GlineIsLocal(gline) ? GLINE_GLOBAL : GLINE_LOCAL)) ||
(flags & GLINE_LASTMOD && !gline->gl_lastmod))
continue;
else if ((flags & GLINE_EXACT ? ircd_strcmp(gline->gl_user, userhost) :
canon_userhost(t_uh, &user, &host, "*");
gliter(GlobalGlineList, gline, sgline) {
- if ((flags & GLINE_GLOBAL && gline->gl_flags & GLINE_LOCAL) ||
- (flags & GLINE_LOCAL && gline->gl_flags & GLINE_GLOBAL) ||
+ if ((flags & (GlineIsLocal(gline) ? GLINE_GLOBAL : GLINE_LOCAL)) ||
(flags & GLINE_LASTMOD && !gline->gl_lastmod))
continue;
else if (flags & GLINE_EXACT) {
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire - CurrentTime, gline->gl_lastmod,
+ gline->gl_expire - TStime(), gline->gl_lastmod,
gline->gl_lifetime, gline->gl_reason);
}
if (!GlineIsLocal(gline) && gline->gl_lastmod)
sendcmdto_one(&me, CMD_GLINE, cptr, "* %c%s %Tu %Tu %Tu :%s",
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
- gline->gl_expire - CurrentTime, gline->gl_lastmod,
+ gline->gl_expire - TStime(), gline->gl_lastmod,
gline->gl_lifetime, gline->gl_reason);
}
}
GlineIsRemActive(gline) ? '+' : '-', gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire - CurrentTime, gline->gl_lastmod,
+ gline->gl_expire - TStime(), gline->gl_lastmod,
gline->gl_lifetime, gline->gl_reason);
return 0;
send_reply(sptr, RPL_GLIST, gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_lastmod,
- gline->gl_lifetime + TSoffset,
+ gline->gl_expire, gline->gl_lastmod,
+ gline->gl_lifetime,
GlineIsLocal(gline) ? cli_name(&me) : "*",
gline->gl_state == GLOCAL_ACTIVATED ? ">" :
(gline->gl_state == GLOCAL_DEACTIVATED ? "<" : ""),
send_reply(sptr, RPL_GLIST, gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_lastmod,
- gline->gl_lifetime + TSoffset,
+ gline->gl_expire, gline->gl_lastmod,
+ gline->gl_lifetime,
GlineIsLocal(gline) ? cli_name(&me) : "*",
gline->gl_state == GLOCAL_ACTIVATED ? ">" :
(gline->gl_state == GLOCAL_DEACTIVATED ? "<" : ""),
gliter(BadChanGlineList, gline, sgline) {
send_reply(sptr, RPL_GLIST, gline->gl_user, "", "",
- gline->gl_expire + TSoffset, gline->gl_lastmod,
- gline->gl_lifetime + TSoffset,
+ gline->gl_expire, gline->gl_lastmod,
+ gline->gl_lifetime,
GlineIsLocal(gline) ? cli_name(&me) : "*",
gline->gl_state == GLOCAL_ACTIVATED ? ">" :
(gline->gl_state == GLOCAL_DEACTIVATED ? "<" : ""),
send_reply(sptr, RPL_STATSGLINE, 'G', gline->gl_user,
gline->gl_host ? "@" : "",
gline->gl_host ? gline->gl_host : "",
- gline->gl_expire + TSoffset, gline->gl_lastmod,
- gline->gl_lifetime + TSoffset,
+ gline->gl_expire, gline->gl_lastmod,
+ gline->gl_lifetime,
gline->gl_state == GLOCAL_ACTIVATED ? ">" :
(gline->gl_state == GLOCAL_DEACTIVATED ? "<" : ""),
GlineIsRemActive(gline) ? '+' : '-',