Permalink
Browse files

Raise ban/exempt/ignore limit to 5 years. Closes #541

Found by: Robby
Patch by: michaelortmann
Fixes: #541 

TODO - Still need to address the year 2038 problem sometime in the next decade or so...
  • Loading branch information...
michaelortmann authored and vanosg committed Oct 27, 2018
1 parent 4c781e9 commit 5ad083240a2377b4fec1e27d639c4593f6341113
Showing with 80 additions and 53 deletions.
  1. +3 −2 help/cmds1.help
  2. +22 −14 src/cmds.c
  3. +49 −31 src/mod/channels.mod/cmdschan.c
  4. +6 −6 src/mod/channels.mod/help/channels.help
@@ -15,10 +15,11 @@ See also: -bot
See also: -host
%{help=+ignore}%{+m}
### %b+ignore%b <hostmask> [%%<XdXhXm>] [comment]
### %b+ignore%b <hostmask> [%%<XyXdXhXm>] [comment]
Adds an ignore to the list of ignores stored on the bot, with optional
comment and ignore time. This ignore is stored with your handle as the
creator. Ignore time has to be expressed in days, hours, and/or minutes.
creator. Ignore time has to be expressed in years, days, hours and/or
minutes.
See also: -ignore, ignores
%{help=+user}%{+m}
@@ -2586,48 +2586,56 @@ static void cmd_unloadmod(struct userrec *u, int idx, char *par)
static void cmd_pls_ignore(struct userrec *u, int idx, char *par)
{
char *who, s[UHOSTLEN];
unsigned long int expire_time = 0;
char *who, s[UHOSTLEN], *p, *p_expire;
long expire_foo;
unsigned long expire_time = 0;
if (!par[0]) {
dprintf(idx, "Usage: +ignore <hostmask> [%%<XdXhXm>] [comment]\n");
dprintf(idx, "Usage: +ignore <hostmask> [%%<XyXdXhXm>] [comment]\n");
return;
}
who = newsplit(&par);
if (par[0] == '%') {
char *p, *p_expire;
unsigned long int expire_foo;
p = newsplit(&par);
p_expire = p + 1;
while (*(++p) != 0) {
switch (tolower((unsigned) *p)) {
case 'y':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
expire_time += 60 * 60 * 24 * 365 * expire_foo;
p_expire = p + 1;
break;
case 'd':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 365)
expire_foo = 365;
expire_time += 86400 * expire_foo;
expire_time += 60 * 60 * 24 * expire_foo;
p_expire = p + 1;
break;
case 'h':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 8760)
expire_foo = 8760;
expire_time += 3600 * expire_foo;
expire_time += 60 * 60 * expire_foo;
p_expire = p + 1;
break;
case 'm':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 525600)
expire_foo = 525600;
expire_time += 60 * expire_foo;
p_expire = p + 1;
}
}
/* For whomever is stuck with maintaining this in 2033- this will
* break. Hopefully we've dealt with the max unixtime issue by now
* (Year 2038 problem), but if you're reading this, clearly we
* haven't because we are lazy. Sorry.
*/
if (expire_time > (60 * 60 * 24 * 365 * 5)) {
dprintf(idx, "expire time must be equal to or less than 5 years"
"(1825 days)\n");
return;
}
}
if (!par[0])
par = "requested";
@@ -30,20 +30,21 @@ static struct flag_record victim = { FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0 };
static void cmd_pls_ban(struct userrec *u, int idx, char *par)
{
char *chname, *who, s[UHOSTLEN], s1[UHOSTLEN], *p, *p_expire;
unsigned long int expire_time = 0, expire_foo;
long expire_foo;
unsigned long expire_time = 0;
int sticky = 0;
struct chanset_t *chan = NULL;
module_entry *me;
if (!par[0]) {
dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XyXdXhXm>] [reason]\n");
} else {
who = newsplit(&par);
/* Sanity check for <channel> <ban> vs. <ban> <channel> */
if (par[0] && strchr(CHANMETA, who[0])) {
chname = who;
who = newsplit(&par);
dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
dprintf(idx, "Usage: +ban <hostmask> [channel] [%%<XyXdXhXm>] [reason]\n");
dprintf(idx, "Did you mean: .+ban %s %s %s\n", who, chname, par);
return;
} else if (par[0] && strchr(CHANMETA, par[0]))
@@ -72,31 +73,36 @@ static void cmd_pls_ban(struct userrec *u, int idx, char *par)
p_expire = p + 1;
while (*(++p) != 0) {
switch (tolower((unsigned) *p)) {
case 'y':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
expire_time += 60 * 60 * 24 * 365 * expire_foo;
p_expire = p + 1;
break;
case 'd':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 365)
expire_foo = 365;
expire_time += 86400 * expire_foo;
expire_time += 60 * 60 * 24 * expire_foo;
p_expire = p + 1;
break;
case 'h':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 8760)
expire_foo = 8760;
expire_time += 3600 * expire_foo;
expire_time += 60 * 60 * expire_foo;
p_expire = p + 1;
break;
case 'm':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 525600)
expire_foo = 525600;
expire_time += 60 * expire_foo;
p_expire = p + 1;
}
}
if (expire_time > (60 * 60 * 24 * 365 * 5)) {
dprintf(idx, "Ban expiration time cannot exceed 5 years "
"(1825 days)\n");
return;
}
}
if (!par[0])
par = "requested";
@@ -171,15 +177,16 @@ static void cmd_pls_ban(struct userrec *u, int idx, char *par)
static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
{
char *chname, *who, s[UHOSTLEN], *p, *p_expire;
unsigned long int expire_time = 0, expire_foo;
long expire_foo;
unsigned long expire_time = 0;
struct chanset_t *chan = NULL;
if (!use_exempts) {
dprintf(idx, "This command can only be used with use-exempts enabled.\n");
return;
}
if (!par[0]) {
dprintf(idx, "Usage: +exempt <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
dprintf(idx, "Usage: +exempt <hostmask> [channel] [%%<XydXhXm>] [reason]\n");
} else {
who = newsplit(&par);
if (par[0] && strchr(CHANMETA, par[0]))
@@ -208,31 +215,36 @@ static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
p_expire = p + 1;
while (*(++p) != 0) {
switch (tolower((unsigned) *p)) {
case 'y':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
expire_time += 60 * 60 * 24 * 365 * expire_foo;
p_expire = p + 1;
break;
case 'd':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 365)
expire_foo = 365;
expire_time += 86400 * expire_foo;
expire_time += 60 * 60 * 24 * expire_foo;
p_expire = p + 1;
break;
case 'h':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 8760)
expire_foo = 8760;
expire_time += 3600 * expire_foo;
expire_time += 60 * 60 * expire_foo;
p_expire = p + 1;
break;
case 'm':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 525600)
expire_foo = 525600;
expire_time += 60 * expire_foo;
p_expire = p + 1;
}
}
if (expire_time > (60 * 60 * 24 * 365 * 5)) {
dprintf(idx, "Exempt expiration time cannot exceed 5 years "
"(1825 days)\n");
return;
}
}
if (!par[0])
par = "requested";
@@ -292,7 +304,8 @@ static void cmd_pls_exempt(struct userrec *u, int idx, char *par)
static void cmd_pls_invite(struct userrec *u, int idx, char *par)
{
char *chname, *who, s[UHOSTLEN], *p, *p_expire;
unsigned long int expire_time = 0, expire_foo;
long expire_foo;
unsigned long expire_time = 0;
struct chanset_t *chan = NULL;
if (!use_invites) {
@@ -301,7 +314,7 @@ static void cmd_pls_invite(struct userrec *u, int idx, char *par)
}
if (!par[0]) {
dprintf(idx, "Usage: +invite <hostmask> [channel] [%%<XdXhXm>] [reason]\n");
dprintf(idx, "Usage: +invite <hostmask> [channel] [%%<XyXdXhXm>] [reason]\n");
} else {
who = newsplit(&par);
if (par[0] && strchr(CHANMETA, par[0]))
@@ -330,31 +343,36 @@ static void cmd_pls_invite(struct userrec *u, int idx, char *par)
p_expire = p + 1;
while (*(++p) != 0) {
switch (tolower((unsigned) *p)) {
case 'y':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
expire_time += 60 * 60 * 24 * 365 * expire_foo;
p_expire = p + 1;
break;
case 'd':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 365)
expire_foo = 365;
expire_time += 86400 * expire_foo;
expire_time += 60 * 60 * 24 * expire_foo;
p_expire = p + 1;
break;
case 'h':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 8760)
expire_foo = 8760;
expire_time += 3600 * expire_foo;
expire_time += 60 * 60 * expire_foo;
p_expire = p + 1;
break;
case 'm':
*p = 0;
expire_foo = strtol(p_expire, NULL, 10);
if (expire_foo > 525600)
expire_foo = 525600;
expire_time += 60 * expire_foo;
p_expire = p + 1;
}
}
if (expire_time > (60 * 60 * 24 * 365 * 5)) {
dprintf(idx, "Invite expiration time cannot exceed 5 years "
"(1825 days)\n");
return;
}
}
if (!par[0])
par = "requested";
@@ -1,29 +1,29 @@
%{help=+ban}%{+lo|lo}
### %b+ban%b <hostmask> [channel] [%%<XdXhXm>] [comment]
### %b+ban%b <hostmask> [channel] [%%<XyXdXhXm>] [comment]
Adds a ban to the list of bans stored on the bot, with optional comment and
ban time. This ban is stored with your handle as the creator, and will be
in effect for every channel if no channel is specified. Prefixing a comment
with '@' will make it only visible within the bot, and not used as the ban
reason. Prefixing the comment with '*' will make the ban sticky. Ban time
has to be expressed in days, hours, and/or minutes.
has to be expressed in years, days, hours and/or minutes.
See also: bans, -ban, stick, unstick
%{help=+exempt}%{+lo|lo}
### %b+exempt%b <hostmask> [channel] [%%<XdXhXm>] [comment]
### %b+exempt%b <hostmask> [channel] [%%<XyXdXhXm>] [comment]
Adds an exempt to the list of exempts stored on the bot, with optional
comment and exempt time. This exempt is stored with your handle as the
creator, and will be in effect for every channel if no channel is specified.
Prefixing a comment with '*' will make the exempt sticky. Exempt time has
to be expressed in days, hours, and/or minutes.
to be expressed in years, days, hours and/or minutes.
See also: exempts, -exempt, stick, unstick
%{help=+invite}%{+lo|lo}
### %b+invite%b <hostmask> [channel] [%%<XdXhXm>] [comment]
### %b+invite%b <hostmask> [channel] [%%<XyXdXhXm>] [comment]
Adds an invite to the list of invites stored on the bot, with optional
comment and invite time. This invite is stored with your handle as the
creator, and will be in effect for every channel if no channel is specified.
Prefixing a comment with '*' will make the invite sticky. Invite time has
to be expressed in days, hours, and/or minutes.
to be expressed in years, days, hours and/or minutes.
See also: invites, -invite, stick, unstick
%{help=+chan}%{+n}

0 comments on commit 5ad0832

Please sign in to comment.