X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/143b6cc1e4a8faa8181301bf43ddafecab3237cc..745237f166ea43fc90e52cd6783551cced063cdc:/modules/m_dline.c diff --git a/modules/m_dline.c b/modules/m_dline.c index e54bacf..5ac171b 100644 --- a/modules/m_dline.c +++ b/modules/m_dline.c @@ -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,27 @@ 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); + + if(EmptyString(oper_reason)) + { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added D-Line for [%s] [%s]", + get_oper_name(source_p), aconf->host, reason); + ilog(L_KLINE, "D %s 0 %s %s", + get_oper_name(source_p), aconf->host, reason); + } + else + { + sendto_realops_snomask(SNO_GENERAL, L_ALL, + "%s added D-Line for [%s] [%s|%s]", + get_oper_name(source_p), aconf->host, reason, oper_reason); + ilog(L_KLINE, "D %s 0 %s %s|%s", + get_oper_name(source_p), + aconf->host, reason, oper_reason); + } } return 0; @@ -350,12 +367,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 +376,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 +390,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); - - 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; - } + bandb_del(BANDB_DLINE, aconf->host, NULL); - 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 +427,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 +439,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);