X-Git-Url: https://jfr.im/git/irc/rqf/shadowircd.git/blobdiff_plain/212380e3f42f585dc1ea927402252eb943f91f7b..8e43b0b4146cdbacec61e83e8b8251c0b5a090c9:/modules/m_dline.c diff --git a/modules/m_dline.c b/modules/m_dline.c index e5bd03d..9bc7def 100644 --- a/modules/m_dline.c +++ b/modules/m_dline.c @@ -21,11 +21,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * - * $Id: m_dline.c 3051 2006-12-27 00:02:32Z jilles $ + * $Id: m_dline.c 3225 2007-03-04 23:42:55Z jilles $ */ #include "stdinc.h" -#include "tools.h" #include "channel.h" #include "class.h" #include "client.h" @@ -35,7 +34,6 @@ #include "ircd.h" #include "hostmask.h" #include "numeric.h" -#include "commio.h" #include "s_conf.h" #include "s_newconf.h" #include "s_log.h" @@ -59,11 +57,11 @@ struct Message undline_msgtab = { }; mapi_clist_av1 dline_clist[] = { &dline_msgtab, &undline_msgtab, NULL }; -DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision: 3051 $"); +DECLARE_MODULE_AV1(dline, NULL, NULL, dline_clist, NULL, NULL, "$Revision: 3225 $"); static int valid_comment(char *comment); static int flush_write(struct Client *, FILE *, char *, char *); -static int remove_temp_dline(const char *); +static int remove_temp_dline(struct ConfItem *); /* mo_dline() * @@ -202,7 +200,7 @@ mo_dline(struct Client *client_p, struct Client *source_p, if(tdline_time > 0) { - ircsnprintf(dlbuffer, sizeof(dlbuffer), + rb_snprintf(dlbuffer, sizeof(dlbuffer), "Temporary D-line %d min. - %s (%s)", (int) (tdline_time / 60), reason, current_date); DupString(aconf->passwd, dlbuffer); @@ -235,7 +233,7 @@ mo_dline(struct Client *client_p, struct Client *source_p, } else { - ircsnprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date); + rb_snprintf(dlbuffer, sizeof(dlbuffer), "%s (%s)", reason, current_date); DupString(aconf->passwd, dlbuffer); add_conf_by_address(aconf->host, CONF_DLINE, NULL, aconf); write_confitem(DLINE_TYPE, source_p, NULL, aconf->host, reason, @@ -258,10 +256,11 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha char buf[BUFSIZE], buff[BUFSIZE], temppath[BUFSIZE], *p; const char *filename, *found_cidr; const char *cidr; + struct ConfItem *aconf; int pairme = NO, error_on_write = NO; mode_t oldumask; - ircsnprintf(temppath, sizeof(temppath), "%s.tmp", ConfigFileEntry.dlinefile); + rb_snprintf(temppath, sizeof(temppath), "%s.tmp", ConfigFileEntry.dlinefile); if(!IsOperUnkline(source_p)) { @@ -274,20 +273,27 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha if(parse_netmask(cidr, NULL, NULL) == HM_HOST) { - sendto_one(source_p, ":%s NOTICE %s :Invalid D-Line", - me.name, source_p->name); + sendto_one_notice(source_p, ":Invalid D-Line"); + return 0; + } + + aconf = find_exact_conf_by_address(cidr, CONF_DLINE, NULL); + if(aconf == NULL) + { + sendto_one_notice(source_p, ":No D-Line for %s", cidr); return 0; } - if(remove_temp_dline(cidr)) + strlcpy(buf, aconf->host, sizeof buf); + if(remove_temp_dline(aconf)) { sendto_one(source_p, ":%s NOTICE %s :Un-dlined [%s] from temporary D-lines", - me.name, parv[0], cidr); + me.name, parv[0], buf); sendto_realops_snomask(SNO_GENERAL, L_ALL, "%s has removed the temporary D-Line for: [%s]", - get_oper_name(source_p), cidr); - ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), cidr); + get_oper_name(source_p), buf); + ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), buf); return 0; } @@ -331,7 +337,7 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha continue; } - if(irccmp(found_cidr, cidr) == 0) + if(irccmp(found_cidr, aconf->host) == 0) { pairme++; } @@ -356,8 +362,8 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha } else if(!pairme) { - sendto_one(source_p, ":%s NOTICE %s :No D-Line for %s", - me.name, parv[0], cidr); + sendto_one_notice(source_p, ":Cannot find D-Line for %s in file", + aconf->host); if(temppath != NULL) (void) unlink(temppath); @@ -370,13 +376,13 @@ mo_undline(struct Client *client_p, struct Client *source_p, int parc, const cha sendto_one_notice(source_p, ":Couldn't rename temp file, aborted"); return 0; } - rehash_bans(0); - - sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, parv[0], cidr); + sendto_one(source_p, ":%s NOTICE %s :D-Line for [%s] is removed", me.name, parv[0], aconf->host); sendto_realops_snomask(SNO_GENERAL, L_ALL, - "%s has removed the D-Line for: [%s]", get_oper_name(source_p), cidr); - ilog(L_KLINE, "UD %s %s", get_oper_name(source_p), cidr); + "%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); return 0; } @@ -394,8 +400,8 @@ valid_comment(char *comment) if(strchr(comment, '"')) return 0; - if(strlen(comment) > REASONLEN) - comment[REASONLEN] = '\0'; + if(strlen(comment) > BANREASONLEN) + comment[BANREASONLEN] = '\0'; return 1; } @@ -426,8 +432,7 @@ flush_write(struct Client *source_p, FILE * out, char *buf, char *temppath) if(error_on_write) { - sendto_one(source_p, ":%s NOTICE %s :Unable to write to %s", - me.name, source_p->name, temppath); + sendto_one_notice(source_p, ":Unable to write to %s", temppath); fclose(out); if(temppath != NULL) (void) unlink(temppath); @@ -437,32 +442,23 @@ flush_write(struct Client *source_p, FILE * out, char *buf, char *temppath) /* remove_temp_dline() * - * inputs - hostname to undline + * inputs - confitem to undline * outputs - * side effects - tries to undline anything that matches */ static int -remove_temp_dline(const char *host) +remove_temp_dline(struct ConfItem *aconf) { - struct ConfItem *aconf; - dlink_node *ptr; - struct irc_sockaddr_storage addr, caddr; - int bits, cbits; + rb_dlink_node *ptr; int i; - parse_netmask(host, (struct sockaddr *)&addr, &bits); - for (i = 0; i < LAST_TEMP_TYPE; i++) { - DLINK_FOREACH(ptr, temp_dlines[i].head) + RB_DLINK_FOREACH(ptr, temp_dlines[i].head) { - aconf = ptr->data; - - parse_netmask(aconf->host, (struct sockaddr *)&caddr, &cbits); - - if(comp_with_mask_sock((struct sockaddr *)&addr, (struct sockaddr *)&caddr, bits) && bits == cbits) + if (aconf == ptr->data) { - dlinkDestroy(ptr, &temp_dlines[i]); + rb_dlinkDestroy(ptr, &temp_dlines[i]); delete_one_address_conf(aconf->host, aconf); return YES; }