src/gline.c (KEY_LASTMOD): New key string.
(gline_add): Use new parameter to set lastmod.
(gline_add_record): Look for KEY_LASTMOD values.
(gline_write_entry): Set KEY_LASTMOD if lastmod is set.
(gline_discrim_create): Allow specification of lastmod criteria.
(gline_discrim_match): Check lastmod if appropriate.
src/gline.h (struct gline): Add lastmod field.
(struct gline_discrim): Add lastmod fields.
(gline_add): New parameter.
src/mod-sockcheck.c (sockcheck_issue_gline): Set lastmod.
src/opserv.c (OSMSG_NO_GLINE): New format string.
(opserv_block): Set lastmod.
(cmd_gline): Set lastmod.
(cmd_stats_glines): Allow searching for a particular G-line (just like
gtrace).
(opserv_new_user_check): Set lastmod.
(gtrace_print_func): Use intervals rather than fixed dates and show
lastmod.
src/opserv.help (GTRACE CRITERIA): Mention lastmod criteria.
src/proto-p10.c (irc_gline): Send lastmod if it is set.
(cmd_num_gline): Parse out lastmod if it is set.
(cmd_gline): Parse out lastmod if it is set.
git-archimport-id: srvx@srvx.net--2006/srvx--devo--1.3--patch-32
# arch-tag: automatic-ChangeLog--srvx@srvx.net--2006/srvx--devo--1.3
#
+2006-09-11 01:03:14 GMT Michael Poole <mdpoole@troilus.org> patch-32
+
+ Summary:
+ Support and use G-line lastmod timestamp.
+ Revision:
+ srvx--devo--1.3--patch-32
+
+ src/gline.c (KEY_LASTMOD): New key string.
+ (gline_add): Use new parameter to set lastmod.
+ (gline_add_record): Look for KEY_LASTMOD values.
+ (gline_write_entry): Set KEY_LASTMOD if lastmod is set.
+ (gline_discrim_create): Allow specification of lastmod criteria.
+ (gline_discrim_match): Check lastmod if appropriate.
+
+ src/gline.h (struct gline): Add lastmod field.
+ (struct gline_discrim): Add lastmod fields.
+ (gline_add): New parameter.
+
+ src/mod-sockcheck.c (sockcheck_issue_gline): Set lastmod.
+
+ src/opserv.c (OSMSG_NO_GLINE): New format string.
+ (opserv_block): Set lastmod.
+ (cmd_gline): Set lastmod.
+ (cmd_stats_glines): Allow searching for a particular G-line (just like
+ gtrace).
+ (opserv_new_user_check): Set lastmod.
+ (gtrace_print_func): Use intervals rather than fixed dates and show
+ lastmod.
+
+ src/opserv.help (GTRACE CRITERIA): Mention lastmod criteria.
+
+ src/proto-p10.c (irc_gline): Send lastmod if it is set.
+ (cmd_num_gline): Parse out lastmod if it is set.
+ (cmd_gline): Parse out lastmod if it is set.
+
+ modified files:
+ ChangeLog src/gline.c src/gline.h src/mod-sockcheck.c
+ src/opserv.c src/opserv.help src/proto-p10.c
+
+
2006-09-09 21:37:28 GMT Michael Poole <mdpoole@troilus.org> patch-31
Summary:
#define KEY_REASON "reason"
#define KEY_EXPIRES "expires"
+#define KEY_LASTMOD "lastmod"
#define KEY_ISSUER "issuer"
#define KEY_ISSUED "issued"
}
struct gline *
-gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, time_t issued, int announce)
+gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, time_t issued, time_t lastmod, int announce)
{
struct gline *ent;
struct gline *prev_first;
heap_remove_pred(gline_heap, gline_for_p, (char*)target);
if (ent->expires < (time_t)(now + duration))
ent->expires = now + duration;
+ if (ent->lastmod < lastmod)
+ ent->lastmod = lastmod;
} else {
ent = malloc(sizeof(*ent));
ent->issued = issued;
+ ent->lastmod = lastmod;
ent->issuer = strdup(issuer);
ent->target = strdup(target);
ent->expires = now + duration;
{
struct record_data *rd = data;
const char *issuer, *reason, *dstr;
- time_t issued, expiration;
+ time_t issued, expiration, lastmod;
if (!(reason = database_get_data(rd->d.object, KEY_REASON, RECDB_QSTRING))) {
log_module(MAIN_LOG, LOG_ERROR, "Missing reason for gline %s", key);
return 0;
}
expiration = strtoul(dstr, NULL, 0);
+ dstr = database_get_data(rd->d.object, KEY_LASTMOD, RECDB_QSTRING);
+ lastmod = dstr ? strtoul(dstr, NULL, 0) : 0;
if ((dstr = database_get_data(rd->d.object, KEY_ISSUED, RECDB_QSTRING))) {
issued = strtoul(dstr, NULL, 0);
} else {
issuer = "<unknown>";
}
if (expiration > now)
- gline_add(issuer, key, expiration - now, reason, issued, 0);
+ gline_add(issuer, key, expiration - now, reason, issued, lastmod, 0);
return 0;
}
saxdb_start_record(ctx, ent->target, 0);
saxdb_write_int(ctx, KEY_EXPIRES, ent->expires);
saxdb_write_int(ctx, KEY_ISSUED, ent->issued);
+ if (ent->lastmod)
+ saxdb_write_int(ctx, KEY_LASTMOD, ent->lastmod);
saxdb_write_string(ctx, KEY_REASON, ent->reason);
saxdb_write_string(ctx, KEY_ISSUER, ent->issuer);
saxdb_end_record(ctx);
struct gline_discrim *discrim;
discrim = calloc(1, sizeof(*discrim));
- discrim->max_issued = now;
discrim->limit = 50;
+ discrim->max_issued = INT_MAX;
+ discrim->max_lastmod = INT_MAX;
for (i=0; i<argc; i++) {
if (i + 2 > argc) {
discrim->min_expire = now + ParseInterval(argv[++i]);
else if (!irccasecmp(argv[i], "before"))
discrim->max_issued = now - ParseInterval(argv[++i]);
- else {
+ else if (!irccasecmp(argv[i], "lastmod")) {
+ const char *cmp = argv[++i];
+ if (cmp[0] == '<') {
+ if (cmp[1] == '=') {
+ discrim->min_lastmod = now - ParseInterval(cmp + 2);
+ } else {
+ discrim->min_lastmod = now - (ParseInterval(cmp + 1) - 1);
+ }
+ } else if (cmp[0] == '>') {
+ if (cmp[1] == '=') {
+ discrim->max_lastmod = now - ParseInterval(cmp + 2);
+ } else {
+ discrim->max_lastmod = now - (ParseInterval(cmp + 1) - 1);
+ }
+ } else {
+ discrim->min_lastmod = now - ParseInterval(cmp + 2);
+ }
+ } else {
send_message(user, src, "MSG_INVALID_CRITERIA", argv[i]);
goto fail;
}
&& (!discrim->alt_target_mask
|| !match_ircglobs(discrim->alt_target_mask, gline->target)))))
|| (discrim->max_issued < gline->issued)
- || (discrim->min_expire > gline->expires)) {
+ || (discrim->min_expire > gline->expires)
+ || (discrim->min_lastmod > gline->lastmod)
+ || (discrim->max_lastmod < gline->lastmod)) {
return 0;
}
return 1;
struct gline {
time_t issued;
+ time_t lastmod;
time_t expires;
char *issuer;
char *target;
char *reason_mask;
time_t max_issued;
time_t min_expire;
+ time_t min_lastmod;
+ time_t max_lastmod;
};
void gline_init(void);
-struct gline *gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, time_t issued, int announce);
+struct gline *gline_add(const char *issuer, const char *target, unsigned long duration, const char *reason, time_t issued, time_t lastmod, int announce);
struct gline *gline_find(const char *target);
int gline_remove(const char *target, int announce);
void gline_refresh_server(struct server *srv);
char addr[IRC_NTOP_MAX_SIZE + 2] = {'*', '@', '\0'};
irc_ntop(addr + 2, sizeof(addr) - 2, &sci->addr);
log_module(PC_LOG, LOG_INFO, "Issuing gline for client at %s: %s", addr + 2, sci->reason);
- gline_add("ProxyCheck", addr, sockcheck_conf.gline_duration, sci->reason, now, 1);
+ gline_add("ProxyCheck", addr, sockcheck_conf.gline_duration, sci->reason, now, now, 1);
}
static struct sockcheck_client *
{ "OSMSG_BADWORD_LIST", "Bad words: %s" },
{ "OSMSG_EXEMPTED_LIST", "Exempted channels: %s" },
{ "OSMSG_GLINE_COUNT", "There are %d glines active on the network." },
+ { "OSMSG_NO_GLINE", "$b%s$b is not a known G-line." },
{ "OSMSG_LINKS_SERVER", "%s%s (%u clients; %s)" },
{ "OSMSG_MAX_CLIENTS", "Max clients: %d at %s" },
{ "OSMSG_NETWORK_INFO", "Total users: %d (%d invisible, %d opers)" },
{ "OSMSG_GLINE_SEARCH_RESULTS", "The following glines were found:" },
{ "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
{ "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
- { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, expires %s): %s" },
+ { "OSMSG_GTRACE_FORMAT", "%s (issued %s by %s, lastmod %s, expires %s): %s" },
{ "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
{ "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
{ "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
"G-line requested by %s.", src_handle);
if (!duration)
duration = opserv_conf.block_gline_duration;
- return gline_add(src_handle, mask, duration, reason, now, 1);
+ return gline_add(src_handle, mask, duration, reason, now, now, 1);
}
static MODCMD_FUNC(cmd_block)
reply("MSG_INVALID_DURATION", argv[2]);
return 0;
}
- gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, 1);
+ gline = gline_add(user->handle_info->handle, argv[1], duration, reason, now, now, 1);
reply("OSMSG_GLINE_ISSUED", gline->target);
return 1;
}
return 1;
}
-static MODCMD_FUNC(cmd_stats_glines) {
- reply("OSMSG_GLINE_COUNT", gline_count());
- return 1;
-}
-
static void
trace_links(struct userNode *bot, struct userNode *user, struct server *server, unsigned int depth) {
unsigned int nn, pos;
} else if (ohi->clients.used > limit) {
char target[IRC_NTOP_MAX_SIZE + 3] = { '*', '@', '\0' };
strcpy(target + 2, addr);
- gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "AUTO Excessive connections from a single host.", now, 1);
+ gline_add(opserv->nick, target, opserv_conf.clone_gline_duration, "AUTO Excessive connections from a single host.", now, now, 1);
}
}
gtrace_print_func(struct gline *gline, void *extra)
{
struct gline_extra *xtra = extra;
- char *when_text, set_text[20];
- strftime(set_text, sizeof(set_text), "%Y-%m-%d", localtime(&gline->issued));
- when_text = asctime(localtime(&gline->expires));
- when_text[strlen(when_text)-1] = 0; /* strip lame \n */
- send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, set_text, gline->issuer, when_text, gline->reason);
+ char issued[INTERVALLEN];
+ char lastmod[INTERVALLEN];
+ char expires[INTERVALLEN];
+
+ intervalString(issued, now - gline->issued, xtra->user->handle_info);
+ if (gline->lastmod)
+ intervalString(lastmod, now - gline->lastmod, xtra->user->handle_info);
+ else
+ strcpy(lastmod, "<unknown>");
+ if (gline->expires)
+ intervalString(expires, gline->expires - now, xtra->user->handle_info);
+ else
+ strcpy(expires, "never");
+ send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason);
+}
+
+static MODCMD_FUNC(cmd_stats_glines) {
+ if (argc < 2) {
+ reply("OSMSG_GLINE_COUNT", gline_count());
+ return 1;
+ } else if (argc < 3) {
+ struct gline_extra extra;
+ struct gline *gl;
+
+ extra.user = user;
+ gl = gline_find(argv[1]);
+ if (!gl)
+ reply("OSMSG_NO_GLINE", argv[1]);
+ else
+ gtrace_print_func(gl, &extra);
+ return 1;
+ } else return 0;
}
static void
"$bLIMIT$b count Limits the number of matching glines.",
"$bREASON$b reason Looks for glines with the given reason.",
"$bISSUER$b account Looks for glines issued by the given account.",
+ "$BLASTMOD$b interval Looks for glines last modified in the specified time.",
"$bAFTER$b interval Looks for glines that expire more than $binterval$b in the future.");
"GSYNC" ("/msg $O GSYNC [server]",
"Requests a list of GLINES from its uplink or the specified server. This can be used in the event srvx is down for period and becomes desynced.",
void
irc_gline(struct server *srv, struct gline *gline)
{
- putsock("%s " P10_GLINE " %s +%s %ld :%s",
- self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, gline->reason);
+ if (gline->lastmod)
+ putsock("%s " P10_GLINE " %s +%s %ld %ld :%s",
+ self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, gline->lastmod, gline->reason);
+ else
+ putsock("%s " P10_GLINE " %s +%s %ld :%s",
+ self->numeric, (srv ? srv->numeric : "*"), gline->target, gline->expires-now, gline->reason);
}
void
static CMD_FUNC(cmd_num_gline)
{
+ time_t lastmod;
if (argc < 6)
return 0;
- gline_add(origin, argv[3], atoi(argv[4])-now, argv[5], now, 0);
+ lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
+ gline_add(origin, argv[3], atoi(argv[4])-now, argv[argc - 1], now, lastmod, 0);
return 1;
}
static CMD_FUNC(cmd_gline)
{
+ time_t lastmod;
+
if (argc < 3)
return 0;
if (argv[2][0] == '+') {
if (argc < 5)
return 0;
- gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, 0);
+ lastmod = (argc > 5) ? strtoul(argv[5], NULL, 0) : 0;
+ gline_add(origin, argv[2]+1, strtoul(argv[3], NULL, 0), argv[argc-1], now, lastmod, 0);
return 1;
} else if (argv[2][0] == '-') {
gline_remove(argv[2]+1, 0);