Update modules to use bandb_add()/bandb_del().
This commit is contained in:
parent
2c9a27c46a
commit
d8a4c5f618
|
@ -21,7 +21,7 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* $Id: m_dline.c 3225 2007-03-04 23:42:55Z jilles $
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "stdinc.h"
|
||||
|
@ -42,6 +42,7 @@
|
|||
#include "msg.h"
|
||||
#include "parse.h"
|
||||
#include "modules.h"
|
||||
#include "bandbi.h"
|
||||
|
||||
static int mo_dline(struct Client *, struct Client *, int, const char **);
|
||||
static int me_dline(struct Client *, struct Client *, int, const char **);
|
||||
|
@ -52,16 +53,17 @@ struct Message dline_msgtab = {
|
|||
"DLINE", 0, 0, 0, MFLG_SLOW,
|
||||
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_dline, 3}, {mo_dline, 2}}
|
||||
};
|
||||
|
||||
struct Message undline_msgtab = {
|
||||
"UNDLINE", 0, 0, 0, MFLG_SLOW,
|
||||
{mg_unreg, mg_not_oper, mg_ignore, mg_ignore, {me_undline, 1}, {mo_undline, 2}}
|
||||
};
|
||||
|
||||
mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL };
|
||||
DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision: 3225 $");
|
||||
|
||||
DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision$");
|
||||
|
||||
static int valid_comment(char *comment);
|
||||
static int flush_write(struct Client *, FILE *, char *, char *);
|
||||
static int remove_temp_dline(struct ConfItem *);
|
||||
static int apply_dline(struct Client *, const char *, int, char *);
|
||||
static int apply_undline(struct Client *, const char *);
|
||||
|
@ -72,8 +74,7 @@ static int apply_undline(struct Client *, const char *);
|
|||
* parv[2] - reason
|
||||
*/
|
||||
static int
|
||||
mo_dline(struct Client *client_p, struct Client *source_p,
|
||||
int parc, const char *parv[])
|
||||
mo_dline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
char def[] = "No Reason";
|
||||
const char *dlhost;
|
||||
|
@ -85,8 +86,7 @@ mo_dline(struct Client *client_p, struct Client *source_p,
|
|||
|
||||
if(!IsOperK(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "kline");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,16 +98,16 @@ mo_dline(struct Client *client_p, struct Client *source_p,
|
|||
|
||||
loc++;
|
||||
|
||||
if(parc >= loc+2 && !irccmp(parv[loc], "ON"))
|
||||
{
|
||||
if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
|
||||
{
|
||||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_server = parv[loc+1];
|
||||
target_server = parv[loc + 1];
|
||||
loc += 2;
|
||||
}
|
||||
|
||||
|
@ -117,9 +117,9 @@ mo_dline(struct Client *client_p, struct Client *source_p,
|
|||
if(target_server != NULL)
|
||||
{
|
||||
sendto_match_servs(source_p, target_server,
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s DLINE %d %s :%s",
|
||||
target_server, tdline_time, dlhost, reason);
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s DLINE %d %s :%s",
|
||||
target_server, tdline_time, dlhost, reason);
|
||||
|
||||
if(!match(target_server, me.name))
|
||||
return 0;
|
||||
|
@ -143,11 +143,10 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
|
||||
if(!IsOperK(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "unkline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
cidr = parv[1];
|
||||
|
||||
if(parc >= 4 && !irccmp(parv[2], "ON"))
|
||||
|
@ -155,15 +154,13 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_server = parv[3];
|
||||
sendto_match_servs(source_p, target_server,
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s UNDLINE %s",
|
||||
target_server, cidr);
|
||||
CAP_ENCAP, NOCAPS, "ENCAP %s UNDLINE %s", target_server, cidr);
|
||||
|
||||
if(!match(target_server, me.name))
|
||||
return 0;
|
||||
|
@ -186,7 +183,8 @@ me_dline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
return 0;
|
||||
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name, tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE))
|
||||
source_p->servptr->name,
|
||||
tdline_time > 0 ? SHARED_TDLINE : SHARED_PDLINE))
|
||||
return 0;
|
||||
|
||||
apply_dline(source_p, parv[2], tdline_time, LOCAL_COPY(parv[3]));
|
||||
|
@ -202,7 +200,7 @@ me_undline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
return 0;
|
||||
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name, SHARED_UNDLINE))
|
||||
source_p->servptr->name, SHARED_UNDLINE))
|
||||
return 0;
|
||||
|
||||
apply_undline(source_p, parv[1]);
|
||||
|
@ -221,11 +219,10 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
int t = AF_INET, ty, b;
|
||||
const char *creason;
|
||||
|
||||
ty = parse_netmask(dlhost, (struct sockaddr *)&daddr, &b);
|
||||
ty = parse_netmask(dlhost, (struct sockaddr *) &daddr, &b);
|
||||
if(ty == HM_HOST)
|
||||
{
|
||||
sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line",
|
||||
me.name, source_p->name);
|
||||
sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", me.name, source_p->name);
|
||||
return 0;
|
||||
}
|
||||
#ifdef RB_IPV6
|
||||
|
@ -241,7 +238,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
if(b < 8)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":For safety, bitmasks less than 8 require conf access.");
|
||||
":For safety, bitmasks less than 8 require conf access.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +247,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
if(b < 16)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Dline bitmasks less than 16 are for admins only.");
|
||||
":Dline bitmasks less than 16 are for admins only.");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +262,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
|
||||
if(ConfigFileEntry.non_redundant_klines)
|
||||
{
|
||||
if((aconf = find_dline((struct sockaddr *)&daddr, t)) != NULL)
|
||||
if((aconf = find_dline((struct sockaddr *) &daddr, t)) != NULL)
|
||||
{
|
||||
int bx;
|
||||
parse_netmask(aconf->host, NULL, &bx);
|
||||
|
@ -275,11 +272,13 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
if(IsConfExemptKline(aconf))
|
||||
sendto_one(source_p,
|
||||
":%s NOTICE %s :[%s] is (E)d-lined by [%s] - %s",
|
||||
me.name, source_p->name, dlhost, aconf->host, creason);
|
||||
me.name, source_p->name, dlhost, aconf->host,
|
||||
creason);
|
||||
else
|
||||
sendto_one(source_p,
|
||||
":%s NOTICE %s :[%s] already D-lined by [%s] - %s",
|
||||
me.name, source_p->name, dlhost, aconf->host, creason);
|
||||
me.name, source_p->name, dlhost, aconf->host,
|
||||
creason);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -304,9 +303,9 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
|
||||
if(tdline_time > 0)
|
||||
{
|
||||
rb_snprintf(dlbuffer, sizeof(dlbuffer),
|
||||
"Temporary D-line %d min. - %s (%s)",
|
||||
(int) (tdline_time / 60), reason, current_date);
|
||||
rb_snprintf(dlbuffer, sizeof(dlbuffer),
|
||||
"Temporary D-line %d min. - %s (%s)",
|
||||
(int) (tdline_time / 60), reason, current_date);
|
||||
aconf->passwd = rb_strdup(dlbuffer);
|
||||
aconf->hold = rb_current_time() + tdline_time;
|
||||
add_temp_dline(aconf);
|
||||
|
@ -314,22 +313,21 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
if(EmptyString(oper_reason))
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. D-Line for [%s] [%s]",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason);
|
||||
"%s added temporary %d min. D-Line for [%s] [%s]",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason);
|
||||
ilog(L_KLINE, "D %s %d %s %s",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason);
|
||||
get_oper_name(source_p), tdline_time / 60, aconf->host, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. D-Line for [%s] [%s|%s]",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason, oper_reason);
|
||||
"%s added temporary %d min. D-Line for [%s] [%s|%s]",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason, oper_reason);
|
||||
ilog(L_KLINE, "D %s %d %s %s|%s",
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason, oper_reason);
|
||||
get_oper_name(source_p), tdline_time / 60,
|
||||
aconf->host, reason, oper_reason);
|
||||
}
|
||||
|
||||
sendto_one(source_p, ":%s NOTICE %s :Added temporary %d min. D-Line for [%s]",
|
||||
|
@ -340,8 +338,9 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date);
|
||||
aconf->passwd = rb_strdup(dlbuffer);
|
||||
add_conf_by_address(aconf->host, CONF_DLINE, NULL, NULL, aconf);
|
||||
write_confitem(DLINE_TYPE, source_p, NULL, aconf->host, reason,
|
||||
oper_reason, current_date, 0);
|
||||
|
||||
bandb_add(BANDB_DLINE, source_p, aconf->host, NULL,
|
||||
reason, EmptyString(aconf->spasswd) ? NULL : aconf->spasswd, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -350,12 +349,7 @@ apply_dline(struct Client *source_p, const char *dlhost, int tdline_time, char *
|
|||
static int
|
||||
apply_undline(struct Client *source_p, const char *cidr)
|
||||
{
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
char buf[BUFSIZE], buff[BUFSIZE], temppath[BUFSIZE], *p;
|
||||
const char *filename, *found_cidr;
|
||||
int pairme = NO, error_on_write = NO;
|
||||
mode_t oldumask;
|
||||
char buf[BUFSIZE];
|
||||
struct ConfItem *aconf;
|
||||
|
||||
if(parse_netmask(cidr, NULL, NULL) == HM_HOST)
|
||||
|
@ -364,8 +358,6 @@ apply_undline(struct Client *source_p, const char *cidr)
|
|||
return 0;
|
||||
}
|
||||
|
||||
rb_snprintf(temppath, sizeof(temppath), "%s.tmp", ConfigFileEntry.dlinefile);
|
||||
|
||||
aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL);
|
||||
if(aconf == NULL)
|
||||
{
|
||||
|
@ -380,95 +372,18 @@ apply_undline(struct Client *source_p, const char *cidr)
|
|||
":%s NOTICE %s :Un-dlined [%s] from temporary D-lines",
|
||||
me.name, source_p->name, buf);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the temporary D-Line for: [%s]",
|
||||
get_oper_name(source_p), buf);
|
||||
"%s has removed the temporary D-Line for: [%s]",
|
||||
get_oper_name(source_p), buf);
|
||||
ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
filename = get_conf_name(DLINE_TYPE);
|
||||
bandb_del(BANDB_DLINE, aconf->host, NULL);
|
||||
|
||||
if((in = fopen(filename, "r")) == 0)
|
||||
{
|
||||
sendto_one(source_p, ":%s NOTICE %s :Cannot open %s", me.name, source_p->name, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
oldumask = umask(0);
|
||||
if((out = fopen(temppath, "w")) == 0)
|
||||
{
|
||||
sendto_one(source_p, ":%s NOTICE %s :Cannot open %s", me.name, source_p->name, temppath);
|
||||
fclose(in);
|
||||
umask(oldumask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
umask(oldumask);
|
||||
|
||||
while (fgets(buf, sizeof(buf), in))
|
||||
{
|
||||
rb_strlcpy(buff, buf, sizeof(buff));
|
||||
|
||||
if((p = strchr(buff, '\n')) != NULL)
|
||||
*p = '\0';
|
||||
|
||||
if((*buff == '\0') || (*buff == '#'))
|
||||
{
|
||||
if(!error_on_write)
|
||||
flush_write(source_p, out, buf, temppath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if((found_cidr = getfield(buff)) == NULL)
|
||||
{
|
||||
if(!error_on_write)
|
||||
flush_write(source_p, out, buf, temppath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(irccmp(found_cidr, aconf->host) == 0)
|
||||
{
|
||||
pairme++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!error_on_write)
|
||||
flush_write(source_p, out, buf, temppath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
if (fclose(out))
|
||||
error_on_write = YES;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one(source_p,
|
||||
":%s NOTICE %s :Couldn't write D-line file, aborted",
|
||||
me.name, source_p->name);
|
||||
return 0;
|
||||
}
|
||||
else if(!pairme)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot find D-Line for %s in file",
|
||||
aconf->host);
|
||||
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rename(temppath, filename))
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name, aconf->host);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the D-Line for: [%s]", get_oper_name(source_p), aconf->host);
|
||||
sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, source_p->name,
|
||||
aconf->host);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the D-Line for: [%s]",
|
||||
get_oper_name(source_p), aconf->host);
|
||||
ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), aconf->host);
|
||||
delete_one_address_conf(aconf->host, aconf);
|
||||
|
||||
|
@ -494,40 +409,6 @@ valid_comment(char *comment)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* flush_write()
|
||||
*
|
||||
* inputs - pointer to client structure of oper requesting unkline
|
||||
* - out is the file descriptor
|
||||
* - buf is the buffer to write
|
||||
* - ntowrite is the expected number of character to be written
|
||||
* - temppath is the temporary file name to be written
|
||||
* output - YES for error on write
|
||||
* - NO for success
|
||||
* side effects - if successful, the buf is written to output file
|
||||
* if a write failure happesn, and the file pointed to
|
||||
* by temppath, if its non NULL, is removed.
|
||||
*
|
||||
* The idea here is, to be as robust as possible when writing to the
|
||||
* kline file.
|
||||
*
|
||||
* -Dianora
|
||||
*/
|
||||
static int
|
||||
flush_write(struct Client *source_p, FILE * out, char *buf, char *temppath)
|
||||
{
|
||||
int error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Unable to write to %s", temppath);
|
||||
fclose(out);
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
}
|
||||
return (error_on_write);
|
||||
}
|
||||
|
||||
/* remove_temp_dline()
|
||||
*
|
||||
* inputs - confitem to undline
|
||||
|
@ -540,11 +421,11 @@ remove_temp_dline(struct ConfItem *aconf)
|
|||
rb_dlink_node *ptr;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LAST_TEMP_TYPE; i++)
|
||||
for(i = 0; i < LAST_TEMP_TYPE; i++)
|
||||
{
|
||||
RB_DLINK_FOREACH(ptr, temp_dlines[i].head)
|
||||
{
|
||||
if (aconf == ptr->data)
|
||||
if(aconf == ptr->data)
|
||||
{
|
||||
rb_dlinkDestroy(ptr, &temp_dlines[i]);
|
||||
delete_one_address_conf(aconf->host, aconf);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* $Id: m_kline.c 3466 2007-05-19 23:36:51Z jilles $
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "stdinc.h"
|
||||
|
@ -43,6 +43,7 @@
|
|||
#include "parse.h"
|
||||
#include "modules.h"
|
||||
#include "reject.h"
|
||||
#include "bandbi.h"
|
||||
|
||||
static int mo_kline(struct Client *, struct Client *, int, const char **);
|
||||
static int ms_kline(struct Client *, struct Client *, int, const char **);
|
||||
|
@ -62,7 +63,8 @@ struct Message unkline_msgtab = {
|
|||
};
|
||||
|
||||
mapi_clist_av1 kline_clist[] = { &kline_msgtab, &unkline_msgtab, NULL };
|
||||
DECLARE_MODULE_AV1(kline, NULL, NULL, kline_clist, NULL, NULL, "$Revision: 3466 $");
|
||||
|
||||
DECLARE_MODULE_AV1(kline, NULL, NULL, kline_clist, NULL, NULL, "$Revision$");
|
||||
|
||||
/* Local function prototypes */
|
||||
static int find_user_host(struct Client *source_p, const char *userhost, char *user, char *host);
|
||||
|
@ -71,17 +73,15 @@ static int valid_user_host(struct Client *source_p, const char *user, const char
|
|||
static int valid_wild_card(struct Client *source_p, const char *user, const char *host);
|
||||
|
||||
static void handle_remote_kline(struct Client *source_p, int tkline_time,
|
||||
const char *user, const char *host, const char *reason);
|
||||
const char *user, const char *host, const char *reason);
|
||||
static void apply_kline(struct Client *source_p, struct ConfItem *aconf,
|
||||
const char *reason, const char *oper_reason, const char *current_date);
|
||||
static void apply_tkline(struct Client *source_p, struct ConfItem *aconf,
|
||||
const char *, const char *, const char *, int);
|
||||
static int already_placed_kline(struct Client *, const char *, const char *, int);
|
||||
|
||||
static void handle_remote_unkline(struct Client *source_p,
|
||||
const char *user, const char *host);
|
||||
static void handle_remote_unkline(struct Client *source_p, const char *user, const char *host);
|
||||
static void remove_permkline_match(struct Client *, struct ConfItem *);
|
||||
static int flush_write(struct Client *, FILE *, const char *, const char *);
|
||||
static int remove_temp_kline(struct Client *, struct ConfItem *);
|
||||
|
||||
/* mo_kline()
|
||||
|
@ -93,13 +93,13 @@ static int remove_temp_kline(struct Client *, struct ConfItem *);
|
|||
* parv[5] - reason
|
||||
*/
|
||||
static int
|
||||
mo_kline(struct Client *client_p, struct Client *source_p,
|
||||
int parc, const char **parv)
|
||||
mo_kline(struct Client *client_p, struct Client *source_p, int parc, const char **parv)
|
||||
{
|
||||
char def[] = "No Reason";
|
||||
char user[USERLEN + 2];
|
||||
char host[HOSTLEN + 2];
|
||||
char buffer[IRCD_BUFSIZE];
|
||||
char *reason;
|
||||
char *reason = def;
|
||||
char *oper_reason;
|
||||
const char *current_date;
|
||||
const char *target_server = NULL;
|
||||
|
@ -109,8 +109,7 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
|
||||
if(!IsOperK(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "kline");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "kline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -125,16 +124,16 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
|
||||
loc++;
|
||||
|
||||
if(parc >= loc+2 && !irccmp(parv[loc], "ON"))
|
||||
if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
|
||||
{
|
||||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_server = parv[loc+1];
|
||||
target_server = parv[loc + 1];
|
||||
loc += 2;
|
||||
}
|
||||
|
||||
|
@ -150,8 +149,7 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
if(target_server != NULL)
|
||||
{
|
||||
propagate_generic(source_p, "KLINE", target_server, CAP_KLN,
|
||||
"%d %s %s :%s",
|
||||
tkline_time, user, host, reason);
|
||||
"%d %s %s :%s", tkline_time, user, host, reason);
|
||||
|
||||
/* If we are sending it somewhere that doesnt include us, stop */
|
||||
if(!match(target_server, me.name))
|
||||
|
@ -159,14 +157,12 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
}
|
||||
/* if we have cluster servers, send it to them.. */
|
||||
else if(rb_dlink_list_length(&cluster_conf_list) > 0)
|
||||
cluster_generic(source_p, "KLINE",
|
||||
cluster_generic(source_p, "KLINE",
|
||||
(tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE, CAP_KLN,
|
||||
"%lu %s %s :%s",
|
||||
tkline_time, user, host, reason);
|
||||
"%lu %s %s :%s", tkline_time, user, host, reason);
|
||||
|
||||
if(!valid_user_host(source_p, user, host) ||
|
||||
!valid_wild_card(source_p, user, host) ||
|
||||
!valid_comment(source_p, reason))
|
||||
if(!valid_user_host(source_p, user, host) ||
|
||||
!valid_wild_card(source_p, user, host) || !valid_comment(source_p, reason))
|
||||
return 0;
|
||||
|
||||
if(already_placed_kline(source_p, user, host, tkline_time))
|
||||
|
@ -193,8 +189,8 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
if(tkline_time > 0)
|
||||
{
|
||||
rb_snprintf(buffer, sizeof(buffer),
|
||||
"Temporary K-line %d min. - %s (%s)",
|
||||
(int) (tkline_time / 60), reason, current_date);
|
||||
"Temporary K-line %d min. - %s (%s)",
|
||||
(int) (tkline_time / 60), reason, current_date);
|
||||
aconf->passwd = rb_strdup(buffer);
|
||||
apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time);
|
||||
}
|
||||
|
@ -210,7 +206,7 @@ mo_kline(struct Client *client_p, struct Client *source_p,
|
|||
if(kline_queued == 0)
|
||||
{
|
||||
rb_event_addonce("check_klines", check_klines_event, NULL,
|
||||
ConfigFileEntry.kline_delay);
|
||||
ConfigFileEntry.kline_delay);
|
||||
kline_queued = 1;
|
||||
}
|
||||
}
|
||||
|
@ -241,8 +237,7 @@ ms_kline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
return 0;
|
||||
|
||||
propagate_generic(source_p, "KLINE", parv[1], CAP_KLN,
|
||||
"%d %s %s :%s",
|
||||
tkline_time, parv[3], parv[4], parv[5]);
|
||||
"%d %s %s :%s", tkline_time, parv[3], parv[4], parv[5]);
|
||||
|
||||
if(!match(parv[1], me.name))
|
||||
return 0;
|
||||
|
@ -267,7 +262,7 @@ me_kline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
|
||||
static void
|
||||
handle_remote_kline(struct Client *source_p, int tkline_time,
|
||||
const char *user, const char *host, const char *kreason)
|
||||
const char *user, const char *host, const char *kreason)
|
||||
{
|
||||
char buffer[BUFSIZE];
|
||||
const char *current_date;
|
||||
|
@ -276,13 +271,12 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
|
|||
char *oper_reason;
|
||||
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name,
|
||||
(tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE))
|
||||
source_p->servptr->name,
|
||||
(tkline_time > 0) ? SHARED_TKLINE : SHARED_PKLINE))
|
||||
return;
|
||||
|
||||
if(!valid_user_host(source_p, user, host) ||
|
||||
!valid_wild_card(source_p, user, host) ||
|
||||
!valid_comment(source_p, reason))
|
||||
!valid_wild_card(source_p, user, host) || !valid_comment(source_p, reason))
|
||||
return;
|
||||
|
||||
if(already_placed_kline(source_p, user, host, tkline_time))
|
||||
|
@ -309,8 +303,8 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
|
|||
if(tkline_time > 0)
|
||||
{
|
||||
rb_snprintf(buffer, sizeof(buffer),
|
||||
"Temporary K-line %d min. - %s (%s)",
|
||||
(int) (tkline_time / 60), reason, current_date);
|
||||
"Temporary K-line %d min. - %s (%s)",
|
||||
(int) (tkline_time / 60), reason, current_date);
|
||||
aconf->passwd = rb_strdup(buffer);
|
||||
apply_tkline(source_p, aconf, reason, oper_reason, current_date, tkline_time);
|
||||
}
|
||||
|
@ -326,7 +320,7 @@ handle_remote_kline(struct Client *source_p, int tkline_time,
|
|||
if(kline_queued == 0)
|
||||
{
|
||||
rb_event_addonce("check_klines", check_klines_event, NULL,
|
||||
ConfigFileEntry.kline_delay);
|
||||
ConfigFileEntry.kline_delay);
|
||||
kline_queued = 1;
|
||||
}
|
||||
}
|
||||
|
@ -353,8 +347,7 @@ mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
|
||||
if(!IsOperUnkline(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "unkline");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "unkline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -394,12 +387,11 @@ mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN,
|
||||
"%s %s", user, host);
|
||||
propagate_generic(source_p, "UNKLINE", parv[3], CAP_UNKLN, "%s %s", user, host);
|
||||
|
||||
if(match(parv[3], me.name) == 0)
|
||||
return 0;
|
||||
|
@ -432,10 +424,9 @@ mo_unkline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
static int
|
||||
ms_unkline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* source_p parv[1] parv[2] parv[3]
|
||||
* oper target server user host */
|
||||
propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN,
|
||||
"%s %s", parv[2], parv[3]);
|
||||
/* parv[0] parv[1] parv[2] parv[3]
|
||||
* oper target server user host */
|
||||
propagate_generic(source_p, "UNKLINE", parv[1], CAP_UNKLN, "%s %s", parv[2], parv[3]);
|
||||
|
||||
if(!match(parv[1], me.name))
|
||||
return 0;
|
||||
|
@ -464,7 +455,7 @@ handle_remote_unkline(struct Client *source_p, const char *user, const char *hos
|
|||
struct ConfItem *aconf;
|
||||
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name, SHARED_UNKLINE))
|
||||
source_p->servptr->name, SHARED_UNKLINE))
|
||||
return;
|
||||
|
||||
aconf = find_exact_conf_by_address(host, CONF_KILL, user);
|
||||
|
@ -492,8 +483,8 @@ apply_kline(struct Client *source_p, struct ConfItem *aconf,
|
|||
const char *reason, const char *oper_reason, const char *current_date)
|
||||
{
|
||||
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
|
||||
write_confitem(KLINE_TYPE, source_p, aconf->user, aconf->host,
|
||||
reason, oper_reason, current_date, 0);
|
||||
bandb_add(BANDB_KLINE, source_p, aconf->user, aconf->host,
|
||||
reason, EmptyString(oper_reason) ? NULL : oper_reason, 0);
|
||||
}
|
||||
|
||||
/* apply_tkline()
|
||||
|
@ -513,22 +504,21 @@ apply_tkline(struct Client *source_p, struct ConfItem *aconf,
|
|||
if(EmptyString(oper_reason))
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. K-Line for [%s@%s] [%s]",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason);
|
||||
"%s added temporary %d min. K-Line for [%s@%s] [%s]",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason);
|
||||
ilog(L_KLINE, "K %s %d %s %s %s",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason);
|
||||
get_oper_name(source_p), tkline_time / 60, aconf->user, aconf->host, reason);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. K-Line for [%s@%s] [%s|%s]",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason, oper_reason);
|
||||
"%s added temporary %d min. K-Line for [%s@%s] [%s|%s]",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason, oper_reason);
|
||||
ilog(L_KLINE, "K %s %d %s %s %s|%s",
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason, oper_reason);
|
||||
get_oper_name(source_p), tkline_time / 60,
|
||||
aconf->user, aconf->host, reason, oper_reason);
|
||||
}
|
||||
|
||||
sendto_one_notice(source_p, ":Added temporary %d min. K-Line [%s@%s]",
|
||||
|
@ -547,7 +537,7 @@ find_user_host(struct Client *source_p, const char *userhost, char *luser, char
|
|||
char *hostp;
|
||||
|
||||
hostp = strchr(userhost, '@');
|
||||
|
||||
|
||||
if(hostp != NULL) /* I'm a little user@host */
|
||||
{
|
||||
*(hostp++) = '\0'; /* short and squat */
|
||||
|
@ -559,7 +549,7 @@ find_user_host(struct Client *source_p, const char *userhost, char *luser, char
|
|||
rb_strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
|
||||
else
|
||||
strcpy(lhost, "*");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no '@', no '.', so its not a user@host or host, therefore
|
||||
|
@ -588,10 +578,8 @@ find_user_host(struct Client *source_p, const char *userhost, char *luser, char
|
|||
static int
|
||||
valid_user_host(struct Client *source_p, const char *luser, const char *lhost)
|
||||
{
|
||||
/* # and " are invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */
|
||||
if(strchr(lhost, '#') || strchr(luser, '#') || strchr(lhost, '"') ||
|
||||
strchr(luser, '"') || strchr(luser, '!') ||
|
||||
strchr(lhost, '@'))
|
||||
/* # is invalid, as are '!' (n!u@h kline) and '@' (u@@h kline) */
|
||||
if(strchr(lhost, '#') || strchr(luser, '#') || strchr(luser, '!') || strchr(lhost, '@'))
|
||||
{
|
||||
sendto_one_notice(source_p, ":Invalid K-Line");
|
||||
return 0;
|
||||
|
@ -615,12 +603,12 @@ valid_wild_card(struct Client *source_p, const char *luser, const char *lhost)
|
|||
int bitlen;
|
||||
|
||||
/* user has no wildcards, always accept -- jilles */
|
||||
if (!strchr(luser, '?') && !strchr(luser, '*'))
|
||||
if(!strchr(luser, '?') && !strchr(luser, '*'))
|
||||
return 1;
|
||||
|
||||
/* check there are enough non wildcard chars */
|
||||
p = luser;
|
||||
while ((tmpch = *p++))
|
||||
while((tmpch = *p++))
|
||||
{
|
||||
if(!IsKWildChar(tmpch))
|
||||
{
|
||||
|
@ -632,17 +620,20 @@ valid_wild_card(struct Client *source_p, const char *luser, const char *lhost)
|
|||
|
||||
/* try host, as user didnt contain enough */
|
||||
/* special case for cidr masks -- jilles */
|
||||
if ((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1]))
|
||||
if((p = strrchr(lhost, '/')) != NULL && IsDigit(p[1]))
|
||||
{
|
||||
bitlen = atoi(p + 1);
|
||||
/* much like non-cidr for ipv6, rather arbitrary for ipv4 */
|
||||
if (bitlen > 0 && bitlen >= (strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 - 2 * nonwild))
|
||||
if(bitlen > 0
|
||||
&& bitlen >=
|
||||
(strchr(lhost, ':') ? 4 * (ConfigFileEntry.min_nonwildcard - nonwild) : 6 -
|
||||
2 * nonwild))
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
p = lhost;
|
||||
while ((tmpch = *p++))
|
||||
while((tmpch = *p++))
|
||||
{
|
||||
if(!IsKWildChar(tmpch))
|
||||
if(++nonwild >= ConfigFileEntry.min_nonwildcard)
|
||||
|
@ -651,9 +642,8 @@ valid_wild_card(struct Client *source_p, const char *luser, const char *lhost)
|
|||
}
|
||||
|
||||
sendto_one_notice(source_p,
|
||||
":Please include at least %d non-wildcard "
|
||||
"characters with the user@host",
|
||||
ConfigFileEntry.min_nonwildcard);
|
||||
":Please include at least %d non-wildcard "
|
||||
"characters with the user@host", ConfigFileEntry.min_nonwildcard);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -696,13 +686,13 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho
|
|||
const char *reason, *p;
|
||||
struct rb_sockaddr_storage iphost, *piphost;
|
||||
struct ConfItem *aconf;
|
||||
int t, bits;
|
||||
int t, bits;
|
||||
|
||||
aconf = find_exact_conf_by_address(lhost, CONF_KILL, luser);
|
||||
if (aconf == NULL && ConfigFileEntry.non_redundant_klines)
|
||||
if(aconf == NULL && ConfigFileEntry.non_redundant_klines)
|
||||
{
|
||||
bits = 0;
|
||||
if((t = parse_netmask(lhost, (struct sockaddr *)&iphost, &bits)) != HM_HOST)
|
||||
if((t = parse_netmask(lhost, (struct sockaddr *) &iphost, &bits)) != HM_HOST)
|
||||
{
|
||||
#ifdef RB_IPV6
|
||||
if(t == HM_IPV6)
|
||||
|
@ -710,14 +700,15 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho
|
|||
else
|
||||
#endif
|
||||
t = AF_INET;
|
||||
|
||||
|
||||
piphost = &iphost;
|
||||
}
|
||||
else
|
||||
piphost = NULL;
|
||||
|
||||
aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *)piphost, CONF_KILL, t, luser, NULL);
|
||||
if (aconf != NULL)
|
||||
aconf = find_conf_by_address(lhost, NULL, NULL, (struct sockaddr *) piphost,
|
||||
CONF_KILL, t, luser, NULL);
|
||||
if(aconf != NULL)
|
||||
{
|
||||
/* The above was really a lookup of a single IP,
|
||||
* so check if the new kline is wider than the
|
||||
|
@ -725,11 +716,11 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho
|
|||
* -- jilles
|
||||
*/
|
||||
p = strchr(aconf->host, '/');
|
||||
if (bits > 0 && (p == NULL || bits < atoi(p + 1)))
|
||||
if(bits > 0 && (p == NULL || bits < atoi(p + 1)))
|
||||
aconf = NULL;
|
||||
}
|
||||
}
|
||||
if (aconf != NULL)
|
||||
if(aconf != NULL)
|
||||
{
|
||||
/* setting a tkline, or existing one is perm */
|
||||
if(tkline || ((aconf->flags & CONF_FLAGS_TEMPORARY) == 0))
|
||||
|
@ -738,8 +729,7 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho
|
|||
|
||||
sendto_one_notice(source_p,
|
||||
":[%s@%s] already K-Lined by [%s@%s] - %s",
|
||||
luser, lhost, aconf->user,
|
||||
aconf->host, reason);
|
||||
luser, lhost, aconf->user, aconf->host, reason);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -754,155 +744,21 @@ already_placed_kline(struct Client *source_p, const char *luser, const char *lho
|
|||
static void
|
||||
remove_permkline_match(struct Client *source_p, struct ConfItem *aconf)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int pairme = 0;
|
||||
int error_on_write = NO;
|
||||
char buf[BUFSIZE];
|
||||
char matchbuf[BUFSIZE];
|
||||
char temppath[BUFSIZE];
|
||||
const char *filename;
|
||||
const char *host, *user;
|
||||
mode_t oldumask;
|
||||
int matchlen;
|
||||
|
||||
host = aconf->host;
|
||||
user = aconf->user;
|
||||
|
||||
rb_snprintf(temppath, sizeof(temppath),
|
||||
"%s.tmp", ConfigFileEntry.klinefile);
|
||||
|
||||
filename = get_conf_name(KLINE_TYPE);
|
||||
|
||||
if((in = fopen(filename, "r")) == 0)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
oldumask = umask(0);
|
||||
if((out = fopen(temppath, "w")) == 0)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", temppath);
|
||||
fclose(in);
|
||||
umask(oldumask);
|
||||
return;
|
||||
}
|
||||
|
||||
umask(oldumask);
|
||||
|
||||
snprintf(matchbuf, sizeof(matchbuf), "\"%s\",\"%s\"", user, host);
|
||||
matchlen = strlen(matchbuf);
|
||||
|
||||
while (fgets(buf, sizeof(buf), in))
|
||||
{
|
||||
if(error_on_write)
|
||||
break;
|
||||
|
||||
if(!strncasecmp(buf, matchbuf, matchlen))
|
||||
{
|
||||
pairme++;
|
||||
break;
|
||||
}
|
||||
else
|
||||
error_on_write = flush_write(source_p, out, buf, temppath);
|
||||
}
|
||||
|
||||
/* we dropped out of the loop early because we found a match,
|
||||
* to drop into this somewhat faster loop as we presume we'll never
|
||||
* have two matching klines --anfl
|
||||
*/
|
||||
if(pairme && !error_on_write)
|
||||
{
|
||||
while(fgets(buf, sizeof(buf), in))
|
||||
{
|
||||
if(error_on_write)
|
||||
break;
|
||||
|
||||
error_on_write = flush_write(source_p, out, buf, temppath);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
if (fclose(out))
|
||||
error_on_write = YES;
|
||||
|
||||
/* The result of the rename should be checked too... oh well */
|
||||
/* If there was an error on a write above, then its been reported
|
||||
* and I am not going to trash the original kline /conf file
|
||||
*/
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't write temp kline file, aborted");
|
||||
return;
|
||||
}
|
||||
else if(!pairme)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot find K-Line for %s@%s in file",
|
||||
user, host);
|
||||
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (rename(temppath, filename))
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
|
||||
return;
|
||||
}
|
||||
|
||||
sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed",
|
||||
user, host);
|
||||
sendto_one_notice(source_p, ":K-Line for [%s@%s] is removed", aconf->user, aconf->host);
|
||||
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the K-Line for: [%s@%s]",
|
||||
get_oper_name(source_p), user, host);
|
||||
"%s has removed the K-Line for: [%s@%s]",
|
||||
get_oper_name(source_p), aconf->user, aconf->host);
|
||||
|
||||
ilog(L_KLINE, "UK %s %s %s",
|
||||
get_oper_name(source_p), user, host);
|
||||
ilog(L_KLINE, "UK %s %s %s", get_oper_name(source_p), aconf->user, aconf->host);
|
||||
|
||||
remove_reject_mask(aconf->user, aconf->host);
|
||||
bandb_del(BANDB_KLINE, aconf->user, aconf->host);
|
||||
delete_one_address_conf(aconf->host, aconf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* flush_write()
|
||||
*
|
||||
* inputs - pointer to client structure of oper requesting unkline
|
||||
* - out is the file descriptor
|
||||
* - buf is the buffer to write
|
||||
* - ntowrite is the expected number of character to be written
|
||||
* - temppath is the temporary file name to be written
|
||||
* output - YES for error on write
|
||||
* - NO for success
|
||||
* side effects - if successful, the buf is written to output file
|
||||
* if a write failure happesn, and the file pointed to
|
||||
* by temppath, if its non NULL, is removed.
|
||||
*
|
||||
* The idea here is, to be as robust as possible when writing to the
|
||||
* kline file.
|
||||
*
|
||||
* -Dianora
|
||||
*/
|
||||
|
||||
static int
|
||||
flush_write(struct Client *source_p, FILE * out, const char *buf, const char *temppath)
|
||||
{
|
||||
int error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Unable to write to %s",
|
||||
temppath);
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
}
|
||||
return (error_on_write);
|
||||
}
|
||||
|
||||
/* remove_temp_kline()
|
||||
*
|
||||
* inputs - username, hostname to unkline
|
||||
|
@ -915,22 +771,22 @@ remove_temp_kline(struct Client *source_p, struct ConfItem *aconf)
|
|||
rb_dlink_node *ptr;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < LAST_TEMP_TYPE; i++)
|
||||
for(i = 0; i < LAST_TEMP_TYPE; i++)
|
||||
{
|
||||
RB_DLINK_FOREACH(ptr, temp_klines[i].head)
|
||||
{
|
||||
if (aconf == ptr->data)
|
||||
if(aconf == ptr->data)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Un-klined [%s@%s] from temporary k-lines",
|
||||
aconf->user, aconf->host);
|
||||
":Un-klined [%s@%s] from temporary k-lines",
|
||||
aconf->user, aconf->host);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the temporary K-Line for: [%s@%s]",
|
||||
get_oper_name(source_p), aconf->user, aconf->host);
|
||||
"%s has removed the temporary K-Line for: [%s@%s]",
|
||||
get_oper_name(source_p), aconf->user,
|
||||
aconf->host);
|
||||
|
||||
ilog(L_KLINE, "UK %s %s %s",
|
||||
get_oper_name(source_p),
|
||||
aconf->user, aconf->host);
|
||||
get_oper_name(source_p), aconf->user, aconf->host);
|
||||
rb_dlinkDestroy(ptr, &temp_klines[i]);
|
||||
remove_reject_mask(aconf->user, aconf->host);
|
||||
delete_one_address_conf(aconf->host, aconf);
|
||||
|
|
361
modules/m_resv.c
361
modules/m_resv.c
|
@ -20,7 +20,7 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA
|
||||
*
|
||||
* $Id: m_resv.c 3045 2006-12-26 23:16:57Z jilles $
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "stdinc.h"
|
||||
|
@ -37,6 +37,7 @@
|
|||
#include "s_newconf.h"
|
||||
#include "hash.h"
|
||||
#include "logger.h"
|
||||
#include "bandbi.h"
|
||||
|
||||
static int mo_resv(struct Client *, struct Client *, int, const char **);
|
||||
static int ms_resv(struct Client *, struct Client *, int, const char **);
|
||||
|
@ -49,28 +50,29 @@ struct Message resv_msgtab = {
|
|||
"RESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
|
||||
{mg_ignore, mg_not_oper, {ms_resv, 4}, {ms_resv, 4}, {me_resv, 5}, {mo_resv, 3}}
|
||||
};
|
||||
|
||||
struct Message unresv_msgtab = {
|
||||
"UNRESV", 0, 0, 0, MFLG_SLOW | MFLG_UNREG,
|
||||
{mg_ignore, mg_not_oper, {ms_unresv, 3}, {ms_unresv, 3}, {me_unresv, 2}, {mo_unresv, 2}}
|
||||
};
|
||||
|
||||
mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL };
|
||||
DECLARE_MODULE_AV1(resv, NULL, NULL, resv_clist, NULL, NULL, "$Revision: 3045 $");
|
||||
mapi_clist_av1 resv_clist[] = { &resv_msgtab, &unresv_msgtab, NULL };
|
||||
|
||||
DECLARE_MODULE_AV1(resv, NULL, NULL, resv_clist, NULL, NULL, "$Revision$");
|
||||
|
||||
static void parse_resv(struct Client *source_p, const char *name,
|
||||
const char *reason, int temp_time);
|
||||
const char *reason, int temp_time);
|
||||
static void propagate_resv(struct Client *source_p, const char *target,
|
||||
int temp_time, const char *name, const char *reason);
|
||||
static void cluster_resv(struct Client *source_p, int temp_time,
|
||||
const char *name, const char *reason);
|
||||
int temp_time, const char *name, const char *reason);
|
||||
static void cluster_resv(struct Client *source_p, int temp_time,
|
||||
const char *name, const char *reason);
|
||||
|
||||
static void handle_remote_unresv(struct Client *source_p, const char *name);
|
||||
static void remove_resv(struct Client *source_p, const char *name);
|
||||
static int remove_resv_from_file(struct Client *source_p, const char *name);
|
||||
static void resv_chan_forcepart(const char *name, const char *reason, int temp_time);
|
||||
|
||||
/*
|
||||
* mo_resv()
|
||||
* parv[0] = sender prefix
|
||||
* parv[1] = channel/nick to forbid
|
||||
* parv[2] = reason
|
||||
*/
|
||||
|
@ -85,8 +87,7 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
|
|||
|
||||
if(!IsOperResv(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "resv");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -101,23 +102,22 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
|
|||
name = parv[loc];
|
||||
loc++;
|
||||
|
||||
if((parc >= loc+2) && (irccmp(parv[loc], "ON") == 0))
|
||||
if((parc >= loc + 2) && (irccmp(parv[loc], "ON") == 0))
|
||||
{
|
||||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_server = parv[loc+1];
|
||||
target_server = parv[loc + 1];
|
||||
loc += 2;
|
||||
}
|
||||
|
||||
if(parc <= loc || EmptyString(parv[loc]))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
|
||||
me.name, source_p->name, "RESV");
|
||||
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "RESV");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -140,16 +140,16 @@ mo_resv(struct Client *client_p, struct Client *source_p, int parc, const char *
|
|||
}
|
||||
|
||||
/* ms_resv()
|
||||
* parv[0] = sender prefix
|
||||
* parv[1] = target server
|
||||
* parv[2] = channel/nick to forbid
|
||||
* parv[3] = reason
|
||||
*/
|
||||
static int
|
||||
ms_resv(struct Client *client_p, struct Client *source_p,
|
||||
int parc, const char *parv[])
|
||||
ms_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* source_p parv[1] parv[2] parv[3]
|
||||
* oper target server resv reason
|
||||
/* parv[0] parv[1] parv[2] parv[3]
|
||||
* oper target server resv reason
|
||||
*/
|
||||
propagate_resv(source_p, parv[1], 0, parv[2], parv[3]);
|
||||
|
||||
|
@ -164,8 +164,7 @@ ms_resv(struct Client *client_p, struct Client *source_p,
|
|||
}
|
||||
|
||||
static int
|
||||
me_resv(struct Client *client_p, struct Client *source_p,
|
||||
int parc, const char *parv[])
|
||||
me_resv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* time name 0 :reason */
|
||||
if(!IsPerson(source_p))
|
||||
|
@ -184,15 +183,14 @@ me_resv(struct Client *client_p, struct Client *source_p,
|
|||
* side effects - will parse the resv and create it if valid
|
||||
*/
|
||||
static void
|
||||
parse_resv(struct Client *source_p, const char *name,
|
||||
const char *reason, int temp_time)
|
||||
parse_resv(struct Client *source_p, const char *name, const char *reason, int temp_time)
|
||||
{
|
||||
struct ConfItem *aconf;
|
||||
|
||||
if(!MyClient(source_p) &&
|
||||
if(!MyClient(source_p) &&
|
||||
!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name,
|
||||
(temp_time > 0) ? SHARED_TRESV : SHARED_PRESV))
|
||||
source_p->servptr->name,
|
||||
(temp_time > 0) ? SHARED_TRESV : SHARED_PRESV))
|
||||
return;
|
||||
|
||||
if(IsChannelName(name))
|
||||
|
@ -200,29 +198,19 @@ parse_resv(struct Client *source_p, const char *name,
|
|||
if(hash_find_resv(name))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":A RESV has already been placed on channel: %s",
|
||||
name);
|
||||
":A RESV has already been placed on channel: %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(strlen(name) > CHANNELLEN)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Invalid RESV length: %s",
|
||||
name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(strchr(name, ','))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character ',' in channel RESV");
|
||||
sendto_one_notice(source_p, ":Invalid RESV length: %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(strchr(reason, '"'))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character '\"' in comment");
|
||||
sendto_one_notice(source_p, ":Invalid character '\"' in comment");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -232,56 +220,50 @@ parse_resv(struct Client *source_p, const char *name,
|
|||
aconf->name = rb_strdup(name);
|
||||
aconf->passwd = rb_strdup(reason);
|
||||
add_to_resv_hash(aconf->name, aconf);
|
||||
resv_chan_forcepart(aconf->name, aconf->passwd, temp_time);
|
||||
|
||||
if(temp_time > 0)
|
||||
{
|
||||
aconf->hold = rb_current_time() + temp_time;
|
||||
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. RESV for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
"%s added temporary %d min. RESV for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
ilog(L_KLINE, "R %s %d %s %s",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
get_oper_name(source_p), temp_time / 60, name, reason);
|
||||
sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]",
|
||||
temp_time / 60, name);
|
||||
temp_time / 60, name);
|
||||
}
|
||||
else
|
||||
write_confitem(RESV_TYPE, source_p, NULL, aconf->name,
|
||||
aconf->passwd, NULL, NULL, 0);
|
||||
bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0);
|
||||
}
|
||||
else if(clean_resv_nick(name))
|
||||
{
|
||||
if(strlen(name) > NICKLEN*2)
|
||||
if(strlen(name) > NICKLEN * 2)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Invalid RESV length: %s",
|
||||
name);
|
||||
sendto_one_notice(source_p, ":Invalid RESV length: %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
if(strchr(reason, '"'))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character '\"' in comment");
|
||||
sendto_one_notice(source_p, ":Invalid character '\"' in comment");
|
||||
return;
|
||||
}
|
||||
|
||||
if(!valid_wild_card_simple(name))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Please include at least %d non-wildcard "
|
||||
"characters with the resv",
|
||||
ConfigFileEntry.min_nonwildcard_simple);
|
||||
":Please include at least %d non-wildcard "
|
||||
"characters with the resv",
|
||||
ConfigFileEntry.min_nonwildcard_simple);
|
||||
return;
|
||||
}
|
||||
|
||||
if(find_nick_resv_mask(name))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":A RESV has already been placed on nick: %s",
|
||||
name);
|
||||
":A RESV has already been placed on nick: %s", name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -297,50 +279,41 @@ parse_resv(struct Client *source_p, const char *name,
|
|||
aconf->hold = rb_current_time() + temp_time;
|
||||
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. RESV for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
"%s added temporary %d min. RESV for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
ilog(L_KLINE, "R %s %d %s %s",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
get_oper_name(source_p), temp_time / 60, name, reason);
|
||||
sendto_one_notice(source_p, ":Added temporary %d min. RESV [%s]",
|
||||
temp_time / 60, name);
|
||||
temp_time / 60, name);
|
||||
}
|
||||
else
|
||||
write_confitem(RESV_TYPE, source_p, NULL, aconf->name,
|
||||
aconf->passwd, NULL, NULL, 0);
|
||||
bandb_add(BANDB_RESV, source_p, aconf->host, NULL, aconf->passwd, NULL, 0);
|
||||
}
|
||||
else
|
||||
sendto_one_notice(source_p,
|
||||
":You have specified an invalid resv: [%s]",
|
||||
name);
|
||||
sendto_one_notice(source_p, ":You have specified an invalid resv: [%s]", name);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
propagate_resv(struct Client *source_p, const char *target,
|
||||
int temp_time, const char *name, const char *reason)
|
||||
int temp_time, const char *name, const char *reason)
|
||||
{
|
||||
if(!temp_time)
|
||||
{
|
||||
sendto_match_servs(source_p, target,
|
||||
CAP_CLUSTER, NOCAPS,
|
||||
"RESV %s %s :%s",
|
||||
target, name, reason);
|
||||
CAP_CLUSTER, NOCAPS, "RESV %s %s :%s", target, name, reason);
|
||||
sendto_match_servs(source_p, target,
|
||||
CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s RESV %d %s 0 :%s",
|
||||
target, temp_time, name, reason);
|
||||
CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason);
|
||||
}
|
||||
else
|
||||
sendto_match_servs(source_p, target,
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s RESV %d %s 0 :%s",
|
||||
target, temp_time, name, reason);
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s RESV %d %s 0 :%s", target, temp_time, name, reason);
|
||||
}
|
||||
|
||||
static void
|
||||
cluster_resv(struct Client *source_p, int temp_time, const char *name,
|
||||
const char *reason)
|
||||
cluster_resv(struct Client *source_p, int temp_time, const char *name, const char *reason)
|
||||
{
|
||||
struct remote_conf *shared_p;
|
||||
rb_dlink_node *ptr;
|
||||
|
@ -358,25 +331,25 @@ cluster_resv(struct Client *source_p, int temp_time, const char *name,
|
|||
continue;
|
||||
|
||||
sendto_match_servs(source_p, shared_p->server,
|
||||
CAP_CLUSTER, NOCAPS,
|
||||
"RESV %s %s :%s",
|
||||
shared_p->server, name, reason);
|
||||
CAP_CLUSTER, NOCAPS,
|
||||
"RESV %s %s :%s", shared_p->server, name, reason);
|
||||
sendto_match_servs(source_p, shared_p->server,
|
||||
CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s RESV 0 %s 0 :%s",
|
||||
shared_p->server, name, reason);
|
||||
CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s RESV 0 %s 0 :%s",
|
||||
shared_p->server, name, reason);
|
||||
}
|
||||
else if(shared_p->flags & SHARED_TRESV)
|
||||
sendto_match_servs(source_p, shared_p->server,
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s RESV %d %s 0 :%s",
|
||||
shared_p->server, temp_time, name, reason);
|
||||
CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s RESV %d %s 0 :%s",
|
||||
shared_p->server, temp_time, name, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mo_unresv()
|
||||
* parv[0] = sender prefix
|
||||
* parv[1] = channel/nick to unforbid
|
||||
*/
|
||||
static int
|
||||
|
@ -384,8 +357,7 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
{
|
||||
if(!IsOperResv(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "resv");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "resv");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -394,36 +366,34 @@ mo_unresv(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER,
|
||||
"%s", parv[1]);
|
||||
propagate_generic(source_p, "UNRESV", parv[3], CAP_CLUSTER, "%s", parv[1]);
|
||||
|
||||
if(match(parv[3], me.name) == 0)
|
||||
return 0;
|
||||
}
|
||||
else if(rb_dlink_list_length(&cluster_conf_list) > 0)
|
||||
cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER,
|
||||
"%s", parv[1]);
|
||||
cluster_generic(source_p, "UNRESV", SHARED_UNRESV, CAP_CLUSTER, "%s", parv[1]);
|
||||
|
||||
remove_resv(source_p, parv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ms_unresv()
|
||||
* parv[0] = sender prefix
|
||||
* parv[1] = target server
|
||||
* parv[2] = resv to remove
|
||||
*/
|
||||
static int
|
||||
ms_unresv(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* source_p parv[1] parv[2]
|
||||
* oper target server resv to remove
|
||||
/* parv[0] parv[1] parv[2]
|
||||
* oper target server resv to remove
|
||||
*/
|
||||
propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER,
|
||||
"%s", parv[2]);
|
||||
propagate_generic(source_p, "UNRESV", parv[1], CAP_CLUSTER, "%s", parv[2]);
|
||||
|
||||
if(!match(parv[1], me.name))
|
||||
return 0;
|
||||
|
@ -450,7 +420,7 @@ static void
|
|||
handle_remote_unresv(struct Client *source_p, const char *name)
|
||||
{
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name, SHARED_UNRESV))
|
||||
source_p->servptr->name, SHARED_UNRESV))
|
||||
return;
|
||||
|
||||
remove_resv(source_p, name);
|
||||
|
@ -472,16 +442,13 @@ remove_resv(struct Client *source_p, const char *name)
|
|||
}
|
||||
|
||||
if(!aconf->hold)
|
||||
{
|
||||
if (!remove_resv_from_file(source_p, name))
|
||||
return;
|
||||
}
|
||||
bandb_del(BANDB_RESV, aconf->host, NULL);
|
||||
else
|
||||
{
|
||||
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the RESV for: [%s]",
|
||||
get_oper_name(source_p), name);
|
||||
"%s has removed the RESV for: [%s]",
|
||||
get_oper_name(source_p), name);
|
||||
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
|
||||
}
|
||||
del_from_resv_hash(name, aconf);
|
||||
|
@ -507,16 +474,13 @@ remove_resv(struct Client *source_p, const char *name)
|
|||
}
|
||||
|
||||
if(!aconf->hold)
|
||||
{
|
||||
if (!remove_resv_from_file(source_p, name))
|
||||
return;
|
||||
}
|
||||
bandb_del(BANDB_RESV, aconf->host, NULL);
|
||||
else
|
||||
{
|
||||
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the RESV for: [%s]",
|
||||
get_oper_name(source_p), name);
|
||||
"%s has removed the RESV for: [%s]",
|
||||
get_oper_name(source_p), name);
|
||||
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
|
||||
}
|
||||
/* already have ptr from the loop above.. */
|
||||
|
@ -526,168 +490,3 @@ remove_resv(struct Client *source_p, const char *name)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
/* remove_resv_from_file()
|
||||
*
|
||||
* inputs - client removing the resv
|
||||
* - resv to remove
|
||||
* outputs -
|
||||
* side effects - resv if found, is removed from conf
|
||||
* - does not touch resv hash or resv_conf_list
|
||||
*/
|
||||
static int
|
||||
remove_resv_from_file(struct Client *source_p, const char *name)
|
||||
{
|
||||
FILE *in, *out;
|
||||
char buf[BUFSIZE];
|
||||
char buff[BUFSIZE];
|
||||
char temppath[BUFSIZE];
|
||||
const char *filename;
|
||||
mode_t oldumask;
|
||||
char *p;
|
||||
int error_on_write = 0;
|
||||
int found_resv = 0;
|
||||
|
||||
rb_sprintf(temppath, "%s.tmp", ConfigFileEntry.resvfile);
|
||||
filename = get_conf_name(RESV_TYPE);
|
||||
|
||||
if((in = fopen(filename, "r")) == NULL)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
oldumask = umask(0);
|
||||
|
||||
if((out = fopen(temppath, "w")) == NULL)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", temppath);
|
||||
fclose(in);
|
||||
umask(oldumask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
umask(oldumask);
|
||||
|
||||
while (fgets(buf, sizeof(buf), in))
|
||||
{
|
||||
const char *resv_name;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
rb_strlcpy(buff, buf, sizeof(buff));
|
||||
|
||||
if((p = strchr(buff, '\n')) != NULL)
|
||||
*p = '\0';
|
||||
|
||||
if((*buff == '\0') || (*buff == '#'))
|
||||
{
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
continue;
|
||||
}
|
||||
|
||||
if((resv_name = getfield(buff)) == NULL)
|
||||
{
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(irccmp(resv_name, name) == 0)
|
||||
{
|
||||
found_resv++;
|
||||
}
|
||||
else
|
||||
{
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
if (fclose(out))
|
||||
error_on_write = YES;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't write temp resv file, aborted");
|
||||
return 0;
|
||||
}
|
||||
else if(!found_resv)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot find RESV for %s in file", name);
|
||||
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rename(temppath, filename))
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sendto_one_notice(source_p, ":RESV for [%s] is removed", name);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the RESV for: [%s]", get_oper_name(source_p), name);
|
||||
ilog(L_KLINE, "UR %s %s", get_oper_name(source_p), name);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
resv_chan_forcepart(const char *name, const char *reason, int temp_time)
|
||||
{
|
||||
rb_dlink_node *ptr;
|
||||
rb_dlink_node *next_ptr;
|
||||
struct Channel *chptr;
|
||||
struct membership *msptr;
|
||||
struct Client *target_p;
|
||||
|
||||
if(!ConfigChannel.resv_forcepart)
|
||||
return;
|
||||
|
||||
/* for each user on our server in the channel list
|
||||
* send them a PART, and notify opers.
|
||||
*/
|
||||
chptr = find_channel(name);
|
||||
if(chptr != NULL)
|
||||
{
|
||||
RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
|
||||
{
|
||||
msptr = ptr->data;
|
||||
target_p = msptr->client_p;
|
||||
|
||||
if(IsExemptResv(target_p))
|
||||
continue;
|
||||
|
||||
sendto_server(target_p, chptr, CAP_TS6, NOCAPS,
|
||||
":%s PART %s", target_p->id, chptr->chname);
|
||||
|
||||
sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s :%s",
|
||||
target_p->name, target_p->username,
|
||||
target_p->host, chptr->chname, target_p->name);
|
||||
|
||||
remove_user_from_channel(msptr);
|
||||
|
||||
/* notify opers & user they were removed from the channel */
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"Forced PART for %s!%s@%s from %s (%s)",
|
||||
target_p->name, target_p->username,
|
||||
target_p->host, name, reason);
|
||||
|
||||
if(temp_time > 0)
|
||||
sendto_one_notice(target_p, ":*** Channel %s is temporarily unavailable on this server.",
|
||||
name);
|
||||
else
|
||||
sendto_one_notice(target_p, ":*** Channel %s is no longer available on this server.",
|
||||
name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: m_xline.c 3161 2007-01-25 07:23:01Z nenolod $
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "stdinc.h"
|
||||
|
@ -50,43 +50,45 @@
|
|||
#include "s_conf.h"
|
||||
#include "s_newconf.h"
|
||||
#include "reject.h"
|
||||
#include "bandbi.h"
|
||||
|
||||
static int mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int me_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int me_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]);
|
||||
static int mo_unxline(struct Client *client_p, struct Client *source_p, int parc,
|
||||
const char *parv[]);
|
||||
static int ms_unxline(struct Client *client_p, struct Client *source_p, int parc,
|
||||
const char *parv[]);
|
||||
static int me_unxline(struct Client *client_p, struct Client *source_p, int parc,
|
||||
const char *parv[]);
|
||||
|
||||
struct Message xline_msgtab = {
|
||||
"XLINE", 0, 0, 0, MFLG_SLOW,
|
||||
{mg_unreg, mg_not_oper, {ms_xline, 5}, {ms_xline, 5}, {me_xline, 5}, {mo_xline, 3}}
|
||||
};
|
||||
|
||||
struct Message unxline_msgtab = {
|
||||
"UNXLINE", 0, 0, 0, MFLG_SLOW,
|
||||
{mg_unreg, mg_not_oper, {ms_unxline, 3}, {ms_unxline, 3}, {me_unxline, 2}, {mo_unxline, 2}}
|
||||
};
|
||||
|
||||
mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL };
|
||||
DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision: 3161 $");
|
||||
mapi_clist_av1 xline_clist[] = { &xline_msgtab, &unxline_msgtab, NULL };
|
||||
|
||||
static char *escape_perm_xline(const char *);
|
||||
static int valid_xline(struct Client *, const char *, const char *, int);
|
||||
static void apply_xline(struct Client *client_p, const char *name,
|
||||
DECLARE_MODULE_AV1(xline, NULL, NULL, xline_clist, NULL, NULL, "$Revision$");
|
||||
|
||||
static int valid_xline(struct Client *, const char *, const char *);
|
||||
static void apply_xline(struct Client *client_p, const char *name,
|
||||
const char *reason, int temp_time);
|
||||
static void write_xline(struct Client *source_p, struct ConfItem *aconf);
|
||||
static void propagate_xline(struct Client *source_p, const char *target,
|
||||
int temp_time, const char *name,
|
||||
const char *type, const char *reason);
|
||||
int temp_time, const char *name, const char *type, const char *reason);
|
||||
static void cluster_xline(struct Client *source_p, int temp_time,
|
||||
const char *name, const char *reason);
|
||||
const char *name, const char *reason);
|
||||
|
||||
static void handle_remote_xline(struct Client *source_p, int temp_time,
|
||||
const char *name, const char *reason);
|
||||
static void handle_remote_unxline(struct Client *source_p, const char *name);
|
||||
|
||||
static void remove_xline(struct Client *source_p, const char *name);
|
||||
static int remove_xline_from_file(struct Client *source_p, const char *gecos);
|
||||
|
||||
|
||||
/* m_xline()
|
||||
|
@ -100,7 +102,6 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
{
|
||||
struct ConfItem *aconf;
|
||||
const char *name;
|
||||
char *escapedname;
|
||||
const char *reason;
|
||||
const char *target_server = NULL;
|
||||
int temp_time;
|
||||
|
@ -108,8 +109,7 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
|
||||
if(!IsOperXline(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "xline");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -123,68 +123,49 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
loc++;
|
||||
|
||||
/* XLINE <gecos> ON <server> :<reason> */
|
||||
if(parc >= loc+2 && !irccmp(parv[loc], "ON"))
|
||||
if(parc >= loc + 2 && !irccmp(parv[loc], "ON"))
|
||||
{
|
||||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
target_server = parv[loc+1];
|
||||
target_server = parv[loc + 1];
|
||||
loc += 2;
|
||||
}
|
||||
|
||||
if(parc <= loc || EmptyString(parv[loc]))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
|
||||
me.name, source_p->name, "XLINE");
|
||||
me.name, source_p->name, "XLINE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
reason = parv[loc];
|
||||
|
||||
if (temp_time == 0)
|
||||
{
|
||||
escapedname = escape_perm_xline(name);
|
||||
if (strcmp(escapedname, name))
|
||||
sendto_one_notice(source_p, ":Changed xline from [%s] to [%s]",
|
||||
name, escapedname);
|
||||
}
|
||||
else
|
||||
escapedname = rb_strdup(name);
|
||||
|
||||
if(target_server != NULL)
|
||||
{
|
||||
propagate_xline(source_p, target_server, temp_time,
|
||||
escapedname, "2", reason);
|
||||
propagate_xline(source_p, target_server, temp_time, name, "2", reason);
|
||||
|
||||
if(!match(target_server, me.name))
|
||||
{
|
||||
rb_free(escapedname);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else if(rb_dlink_list_length(&cluster_conf_list) > 0)
|
||||
cluster_xline(source_p, temp_time, escapedname, reason);
|
||||
cluster_xline(source_p, temp_time, name, reason);
|
||||
|
||||
if((aconf = find_xline_mask(escapedname)) != NULL)
|
||||
if((aconf = find_xline_mask(name)) != NULL)
|
||||
{
|
||||
sendto_one(source_p, ":%s NOTICE %s :[%s] already X-Lined by [%s] - %s",
|
||||
me.name, source_p->name, escapedname, aconf->name, aconf->passwd);
|
||||
rb_free(escapedname);
|
||||
me.name, source_p->name, name, aconf->name, aconf->passwd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!valid_xline(source_p, escapedname, reason, temp_time))
|
||||
{
|
||||
rb_free(escapedname);
|
||||
if(!valid_xline(source_p, name, reason))
|
||||
return 0;
|
||||
}
|
||||
|
||||
apply_xline(source_p, escapedname, reason, temp_time);
|
||||
rb_free(escapedname);
|
||||
apply_xline(source_p, name, reason, temp_time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -196,8 +177,8 @@ mo_xline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
static int
|
||||
ms_xline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* source_p parv[1] parv[2] parv[3] parv[4]
|
||||
* oper target serv xline type reason
|
||||
/* parv[0] parv[1] parv[2] parv[3] parv[4]
|
||||
* oper target serv xline type reason
|
||||
*/
|
||||
propagate_xline(source_p, parv[1], 0, parv[2], parv[3], parv[4]);
|
||||
|
||||
|
@ -224,88 +205,54 @@ me_xline(struct Client *client_p, struct Client *source_p, int parc, const char
|
|||
}
|
||||
|
||||
static void
|
||||
handle_remote_xline(struct Client *source_p, int temp_time,
|
||||
const char *name, const char *reason)
|
||||
handle_remote_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
|
||||
{
|
||||
struct ConfItem *aconf;
|
||||
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name,
|
||||
(temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE))
|
||||
source_p->servptr->name,
|
||||
(temp_time > 0) ? SHARED_TXLINE : SHARED_PXLINE))
|
||||
return;
|
||||
|
||||
if(!valid_xline(source_p, name, reason, temp_time))
|
||||
if(!valid_xline(source_p, name, reason))
|
||||
return;
|
||||
|
||||
/* already xlined */
|
||||
if((aconf = find_xline_mask(name)) != NULL)
|
||||
{
|
||||
sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->name, aconf->passwd);
|
||||
sendto_one_notice(source_p, ":[%s] already X-Lined by [%s] - %s", name, aconf->name,
|
||||
aconf->passwd);
|
||||
return;
|
||||
}
|
||||
|
||||
apply_xline(source_p, name, reason, temp_time);
|
||||
}
|
||||
|
||||
/* escape_perm_xline()
|
||||
*
|
||||
* inputs - gecos
|
||||
* outputs - escaped gecos (allocated with rb_malloc())
|
||||
* side effects - none
|
||||
*/
|
||||
static char *
|
||||
escape_perm_xline(const char *gecos)
|
||||
{
|
||||
char *result;
|
||||
int i, j;
|
||||
|
||||
result = rb_malloc(2 * strlen(gecos) + 1);
|
||||
for (i = 0, j = 0; gecos[i] != '\0'; i++)
|
||||
{
|
||||
result[j++] = gecos[i];
|
||||
if (gecos[i] == '"' && gecos[i + 1] == ',')
|
||||
result[j++] = '\\';
|
||||
}
|
||||
result[j] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
/* valid_xline()
|
||||
*
|
||||
* inputs - client xlining, gecos, reason and temp time
|
||||
* inputs - client xlining, gecos, reason and whether to warn
|
||||
* outputs -
|
||||
* side effects - checks the xline for validity, erroring if needed
|
||||
*/
|
||||
static int
|
||||
valid_xline(struct Client *source_p, const char *gecos,
|
||||
const char *reason, int temp_time)
|
||||
valid_xline(struct Client *source_p, const char *gecos, const char *reason)
|
||||
{
|
||||
if(EmptyString(reason))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
|
||||
get_id(&me, source_p),
|
||||
get_id(source_p, source_p), "XLINE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(temp_time == 0 && strstr(gecos, "\",") != NULL)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character sequence '\",' in xline, please replace with '\"\\,'");
|
||||
get_id(&me, source_p), get_id(source_p, source_p), "XLINE");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strchr(reason, ':') != NULL)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character ':' in comment");
|
||||
sendto_one_notice(source_p, ":Invalid character ':' in comment");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strchr(reason, '"'))
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Invalid character '\"' in comment");
|
||||
sendto_one_notice(source_p, ":Invalid character '\"' in comment");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -322,67 +269,19 @@ valid_xline(struct Client *source_p, const char *gecos,
|
|||
}
|
||||
|
||||
void
|
||||
apply_xline(struct Client *source_p, const char *name, const char *reason,
|
||||
int temp_time)
|
||||
apply_xline(struct Client *source_p, const char *name, const char *reason, int temp_time)
|
||||
{
|
||||
struct ConfItem *aconf;
|
||||
|
||||
aconf = make_conf();
|
||||
aconf->status = CONF_XLINE;
|
||||
|
||||
aconf->name = rb_strdup(name);
|
||||
aconf->passwd = rb_strdup(reason);
|
||||
collapse(aconf->name);
|
||||
|
||||
if(temp_time > 0)
|
||||
if(strstr(name, "\\s"))
|
||||
{
|
||||
aconf->hold = rb_current_time() + temp_time;
|
||||
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. X-Line for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
aconf->name, reason);
|
||||
ilog(L_KLINE, "X %s %d %s %s",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
name, reason);
|
||||
sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]",
|
||||
temp_time / 60, aconf->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]",
|
||||
get_oper_name(source_p),
|
||||
aconf->name, aconf->passwd);
|
||||
sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]",
|
||||
aconf->name, aconf->passwd);
|
||||
write_xline(source_p, aconf);
|
||||
ilog(L_KLINE, "X %s 0 %s %s",
|
||||
get_oper_name(source_p), name, reason);
|
||||
}
|
||||
|
||||
rb_dlinkAddAlloc(aconf, &xline_conf_list);
|
||||
check_xlines();
|
||||
}
|
||||
|
||||
/* write_xline()
|
||||
*
|
||||
* inputs - gecos, reason, xline type
|
||||
* outputs - writes an xline to the config
|
||||
* side effects -
|
||||
*/
|
||||
static void
|
||||
write_xline(struct Client *source_p, struct ConfItem *aconf)
|
||||
{
|
||||
char buffer[BUFSIZE * 2];
|
||||
FILE *out;
|
||||
const char *filename;
|
||||
char *mangle_gecos;
|
||||
|
||||
if(strstr(aconf->name, "\\s"))
|
||||
{
|
||||
char *tmp = LOCAL_COPY(aconf->name);
|
||||
char *tmp = LOCAL_COPY(name);
|
||||
char *orig = tmp;
|
||||
char *new = tmp;
|
||||
char *new = tmp;
|
||||
|
||||
while(*orig)
|
||||
{
|
||||
if(*orig == '\\' && *(orig + 1) != '\0')
|
||||
|
@ -390,14 +289,14 @@ write_xline(struct Client *source_p, struct ConfItem *aconf)
|
|||
if(*(orig + 1) == 's')
|
||||
{
|
||||
*new++ = ' ';
|
||||
orig += 2;
|
||||
orig += 2;
|
||||
}
|
||||
/* otherwise skip that and the escaped
|
||||
* character after it, so we dont mistake
|
||||
* \\s as \s --fl
|
||||
*/
|
||||
else
|
||||
{
|
||||
{
|
||||
*new++ = *orig++;
|
||||
*new++ = *orig++;
|
||||
}
|
||||
|
@ -407,62 +306,61 @@ write_xline(struct Client *source_p, struct ConfItem *aconf)
|
|||
}
|
||||
|
||||
*new = '\0';
|
||||
mangle_gecos = tmp;
|
||||
} else
|
||||
mangle_gecos = aconf->name;
|
||||
aconf->name = rb_strdup(tmp);
|
||||
}
|
||||
else
|
||||
aconf->name = rb_strdup(name);
|
||||
|
||||
filename = ConfigFileEntry.xlinefile;
|
||||
aconf->passwd = rb_strdup(reason);
|
||||
collapse(aconf->name);
|
||||
|
||||
if((out = fopen(filename, "a")) == NULL)
|
||||
if(temp_time > 0)
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem opening %s ", filename);
|
||||
sendto_one_notice(source_p, ":*** Problem opening file, xline added temporarily only");
|
||||
return;
|
||||
aconf->hold = rb_current_time() + temp_time;
|
||||
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s added temporary %d min. X-Line for [%s] [%s]",
|
||||
get_oper_name(source_p), temp_time / 60,
|
||||
aconf->name, reason);
|
||||
ilog(L_KLINE, "X %s %d %s %s",
|
||||
get_oper_name(source_p), temp_time / 60, name, reason);
|
||||
sendto_one_notice(source_p, ":Added temporary %d min. X-Line [%s]",
|
||||
temp_time / 60, aconf->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s added X-Line for [%s] [%s]",
|
||||
get_oper_name(source_p), aconf->name, aconf->passwd);
|
||||
sendto_one_notice(source_p, ":Added X-Line for [%s] [%s]",
|
||||
aconf->name, aconf->passwd);
|
||||
|
||||
bandb_add(BANDB_XLINE, source_p, aconf->host, NULL, reason, NULL, 0);
|
||||
ilog(L_KLINE, "X %s 0 %s %s", get_oper_name(source_p), name, reason);
|
||||
}
|
||||
|
||||
rb_sprintf(buffer, "\"%s\",\"0\",\"%s\",\"%s\",%ld\n",
|
||||
mangle_gecos, aconf->passwd,
|
||||
get_oper_name(source_p), (long) rb_current_time());
|
||||
|
||||
if(fputs(buffer, out) == -1)
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
|
||||
sendto_one_notice(source_p, ":*** Problem writing to file, xline added temporarily only");
|
||||
fclose(out);
|
||||
return;
|
||||
}
|
||||
|
||||
if(fclose(out))
|
||||
{
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL, "*** Problem writing to %s", filename);
|
||||
sendto_one_notice(source_p, ":*** Problem writing to file, xline added temporarily only");
|
||||
return;
|
||||
}
|
||||
rb_dlinkAddAlloc(aconf, &xline_conf_list);
|
||||
check_xlines();
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
propagate_xline(struct Client *source_p, const char *target,
|
||||
int temp_time, const char *name, const char *type,
|
||||
const char *reason)
|
||||
int temp_time, const char *name, const char *type, const char *reason)
|
||||
{
|
||||
if(!temp_time)
|
||||
{
|
||||
sendto_match_servs(source_p, target, CAP_CLUSTER, NOCAPS,
|
||||
"XLINE %s %s %s :%s",
|
||||
target, name, type, reason);
|
||||
"XLINE %s %s %s :%s", target, name, type, reason);
|
||||
sendto_match_servs(source_p, target, CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s XLINE %d %s 2 :%s",
|
||||
target, temp_time, name, reason);
|
||||
"ENCAP %s XLINE %d %s 2 :%s", target, temp_time, name, reason);
|
||||
}
|
||||
else
|
||||
sendto_match_servs(source_p, target, CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s XLINE %d %s %s :%s",
|
||||
target, temp_time, name, type, reason);
|
||||
"ENCAP %s XLINE %d %s %s :%s",
|
||||
target, temp_time, name, type, reason);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
cluster_xline(struct Client *source_p, int temp_time, const char *name,
|
||||
const char *reason)
|
||||
cluster_xline(struct Client *source_p, int temp_time, const char *name, const char *reason)
|
||||
{
|
||||
struct remote_conf *shared_p;
|
||||
rb_dlink_node *ptr;
|
||||
|
@ -480,16 +378,15 @@ cluster_xline(struct Client *source_p, int temp_time, const char *name,
|
|||
continue;
|
||||
|
||||
sendto_match_servs(source_p, shared_p->server, CAP_CLUSTER, NOCAPS,
|
||||
"XLINE %s %s 2 :%s",
|
||||
shared_p->server, name, reason);
|
||||
"XLINE %s %s 2 :%s", shared_p->server, name, reason);
|
||||
sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, CAP_CLUSTER,
|
||||
"ENCAP %s XLINE 0 %s 2 :%s",
|
||||
shared_p->server, name, reason);
|
||||
"ENCAP %s XLINE 0 %s 2 :%s",
|
||||
shared_p->server, name, reason);
|
||||
}
|
||||
else if(shared_p->flags & SHARED_TXLINE)
|
||||
sendto_match_servs(source_p, shared_p->server, CAP_ENCAP, NOCAPS,
|
||||
"ENCAP %s XLINE %d %s 2 :%s",
|
||||
shared_p->server, temp_time, name, reason);
|
||||
"ENCAP %s XLINE %d %s 2 :%s",
|
||||
shared_p->server, temp_time, name, reason);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -502,8 +399,7 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
{
|
||||
if(!IsOperXline(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "xline");
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "xline");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -512,19 +408,17 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
if(!IsOperRemoteBan(source_p))
|
||||
{
|
||||
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
||||
me.name, source_p->name, "remoteban");
|
||||
me.name, source_p->name, "remoteban");
|
||||
return 0;
|
||||
}
|
||||
|
||||
propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER,
|
||||
"%s", parv[1]);
|
||||
propagate_generic(source_p, "UNXLINE", parv[3], CAP_CLUSTER, "%s", parv[1]);
|
||||
|
||||
if(match(parv[3], me.name) == 0)
|
||||
return 0;
|
||||
}
|
||||
else if(rb_dlink_list_length(&cluster_conf_list))
|
||||
cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER,
|
||||
"%s", parv[1]);
|
||||
cluster_generic(source_p, "UNXLINE", SHARED_UNXLINE, CAP_CLUSTER, "%s", parv[1]);
|
||||
|
||||
remove_xline(source_p, parv[1]);
|
||||
|
||||
|
@ -538,11 +432,10 @@ mo_unxline(struct Client *client_p, struct Client *source_p, int parc, const cha
|
|||
static int
|
||||
ms_unxline(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
||||
{
|
||||
/* source_p parv[1] parv[2]
|
||||
* oper target server gecos
|
||||
/* parv[0] parv[1] parv[2]
|
||||
* oper target server gecos
|
||||
*/
|
||||
propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER,
|
||||
"%s", parv[2]);
|
||||
propagate_generic(source_p, "UNXLINE", parv[1], CAP_CLUSTER, "%s", parv[2]);
|
||||
|
||||
if(!match(parv[1], me.name))
|
||||
return 0;
|
||||
|
@ -569,7 +462,7 @@ static void
|
|||
handle_remote_unxline(struct Client *source_p, const char *name)
|
||||
{
|
||||
if(!find_shared_conf(source_p->username, source_p->host,
|
||||
source_p->servptr->name, SHARED_UNXLINE))
|
||||
source_p->servptr->name, SHARED_UNXLINE))
|
||||
return;
|
||||
|
||||
remove_xline(source_p, name);
|
||||
|
@ -582,157 +475,40 @@ remove_xline(struct Client *source_p, const char *name)
|
|||
{
|
||||
struct ConfItem *aconf;
|
||||
rb_dlink_node *ptr;
|
||||
char *encoded;
|
||||
|
||||
encoded = xline_encode_spaces(name);
|
||||
|
||||
RB_DLINK_FOREACH(ptr, xline_conf_list.head)
|
||||
{
|
||||
aconf = ptr->data;
|
||||
|
||||
if(!irccmp(aconf->name, encoded))
|
||||
if(!irccmp(aconf->name, name))
|
||||
{
|
||||
if (!aconf->hold)
|
||||
if(!aconf->hold)
|
||||
{
|
||||
if (!remove_xline_from_file(source_p, encoded))
|
||||
return;
|
||||
bandb_del(BANDB_XLINE, aconf->host, NULL);
|
||||
|
||||
sendto_one_notice(source_p, ":X-Line for [%s] is removed", aconf->host);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the X-Line for: [%s]",
|
||||
get_oper_name(source_p), aconf->host);
|
||||
ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), aconf->host);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":X-Line for [%s] is removed",
|
||||
encoded);
|
||||
sendto_one_notice(source_p, ":X-Line for [%s] is removed", name);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the temporary X-Line for: [%s]",
|
||||
get_oper_name(source_p), encoded);
|
||||
ilog(L_KLINE, "UX %s %s",
|
||||
get_oper_name(source_p), encoded);
|
||||
"%s has removed the temporary X-Line for: [%s]",
|
||||
get_oper_name(source_p), name);
|
||||
ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), name);
|
||||
}
|
||||
|
||||
|
||||
remove_reject_mask(aconf->name, NULL);
|
||||
free_conf(aconf);
|
||||
rb_dlinkDestroy(ptr, &xline_conf_list);
|
||||
rb_free(encoded);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sendto_one_notice(source_p, ":No X-Line for %s", encoded);
|
||||
rb_free(encoded);
|
||||
sendto_one_notice(source_p, ":No X-Line for %s", name);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* remove_xline_from_file()
|
||||
*
|
||||
* inputs - gecos to remove
|
||||
* outputs -
|
||||
* side effects - removes xline from conf, if exists
|
||||
* - does not touch xline_conf_list
|
||||
*/
|
||||
static int
|
||||
remove_xline_from_file(struct Client *source_p, const char *huntgecos)
|
||||
{
|
||||
FILE *in, *out;
|
||||
char buf[BUFSIZE];
|
||||
char buff[BUFSIZE];
|
||||
char temppath[BUFSIZE];
|
||||
const char *filename;
|
||||
const char *gecos;
|
||||
mode_t oldumask;
|
||||
char *p;
|
||||
char *encoded;
|
||||
int error_on_write = 0;
|
||||
int found_xline = 0;
|
||||
|
||||
filename = ConfigFileEntry.xlinefile;
|
||||
rb_snprintf(temppath, sizeof(temppath),
|
||||
"%s.tmp", ConfigFileEntry.xlinefile);
|
||||
|
||||
if((in = fopen(filename, "r")) == NULL)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
oldumask = umask(0);
|
||||
|
||||
if((out = fopen(temppath, "w")) == NULL)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot open %s", temppath);
|
||||
fclose(in);
|
||||
umask(oldumask);
|
||||
return 0;
|
||||
}
|
||||
|
||||
umask(oldumask);
|
||||
|
||||
while (fgets(buf, sizeof(buf), in))
|
||||
{
|
||||
if(error_on_write)
|
||||
{
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
rb_strlcpy(buff, buf, sizeof(buff));
|
||||
|
||||
if((p = strchr(buff, '\n')) != NULL)
|
||||
*p = '\0';
|
||||
|
||||
if((*buff == '\0') || (*buff == '#'))
|
||||
{
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
continue;
|
||||
}
|
||||
|
||||
if((gecos = getfield(buff)) == NULL)
|
||||
{
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* matching.. */
|
||||
encoded = xline_encode_spaces(gecos);
|
||||
if(irccmp(encoded, huntgecos) == 0)
|
||||
found_xline++;
|
||||
else
|
||||
error_on_write = (fputs(buf, out) < 0) ? YES : NO;
|
||||
rb_free(encoded);
|
||||
}
|
||||
|
||||
fclose(in);
|
||||
if (fclose(out))
|
||||
error_on_write = YES;
|
||||
|
||||
if(error_on_write)
|
||||
{
|
||||
sendto_one_notice(source_p,
|
||||
":Couldn't write temp xline file, aborted");
|
||||
return 0;
|
||||
}
|
||||
else if(found_xline == 0)
|
||||
{
|
||||
sendto_one_notice(source_p, ":Cannot find X-Line for %s in file", huntgecos);
|
||||
|
||||
if(temppath != NULL)
|
||||
(void) unlink(temppath);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rename(temppath, filename))
|
||||
{
|
||||
sendto_one_notice(source_p, ":Couldn't rename temp file, aborted");
|
||||
return 0;
|
||||
}
|
||||
|
||||
sendto_one_notice(source_p, ":X-Line for [%s] is removed", huntgecos);
|
||||
sendto_realops_snomask(SNO_GENERAL, L_ALL,
|
||||
"%s has removed the X-Line for: [%s]",
|
||||
get_oper_name(source_p), huntgecos);
|
||||
ilog(L_KLINE, "UX %s %s", get_oper_name(source_p), huntgecos);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue