From 2d455fee85598ccc0f217a0472f254ade652872d Mon Sep 17 00:00:00 2001 From: codemastr Date: Sun, 18 Feb 2001 16:03:34 +0000 Subject: [PATCH] bunch of changes --- Changes | 8 +- include/badwords.h | 3 - include/h.h | 2 + include/struct.h | 10 +++ src/badwords.c | 180 ++++++--------------------------------------- src/ircd.c | 12 --- src/s_conf2.c | 133 ++++++++++++++++++++++++++++++--- src/s_serv.c | 15 ---- src/s_user.c | 6 +- 9 files changed, 166 insertions(+), 203 deletions(-) diff --git a/Changes b/Changes index 0cb566b82..723ecf7c9 100644 --- a/Changes +++ b/Changes @@ -211,7 +211,13 @@ - Made tld {} get rehashed - Made listen/allow get validated - Finished up validate_conf() +<<<<<<< Changes +- Made badwords be in newconf (you can now specify a replace word for each word) +- Made vhosts and badwords rehash +- Fixed a bug in the rehash code +- Made it so set::auto-join and set::oper-auto-join can be excluded to mean no auto join +- Changed prefix_quit to prefix-quit (all others use - not _) +- Fixed a minor bug causing a mode without any flags to be sent - Finished up deny dcc {}. TODOs: dcc_del_wild_match doesn't work. dcc_wipe_services() either - Made deny_dcc get rehashed - \ No newline at end of file diff --git a/include/badwords.h b/include/badwords.h index 64698f94d..fc726dca4 100644 --- a/include/badwords.h +++ b/include/badwords.h @@ -13,13 +13,10 @@ #define MAX_MATCH 1 #define MAX_WORDLEN 64 -#define MAX_WORDS 50 #define PATTERN "\\w*%s\\w*" #define REPLACEWORD "" char *stripbadwords(char *, int); -int loadbadwords(char *, int); -void freebadwords(void); #endif diff --git a/include/h.h b/include/h.h index b5a344596..a85ce567d 100644 --- a/include/h.h +++ b/include/h.h @@ -64,6 +64,8 @@ extern ConfigItem_except *conf_except; extern ConfigItem_vhost *conf_vhost; extern ConfigItem_link *conf_link; extern ConfigItem_ban *conf_ban; +extern ConfigItem_badword *conf_badword_channel; +extern ConfigItem_badword *conf_badword_message; extern ConfigItem_deny_dcc *conf_deny_dcc; ConfigItem_class *Find_class(char *name); diff --git a/include/struct.h b/include/struct.h index 9a7738bd0..e4d38f5b8 100644 --- a/include/struct.h +++ b/include/struct.h @@ -85,6 +85,7 @@ typedef struct _configitem_vhost ConfigItem_vhost; typedef struct _configitem_except ConfigItem_except; typedef struct _configitem_link ConfigItem_link; typedef struct _configitem_ban ConfigItem_ban; +typedef struct _configitem_badword ConfigItem_badword; typedef struct _configitem_deny_dcc ConfigItem_deny_dcc; typedef struct Notify aNotify; @@ -950,6 +951,7 @@ struct _configflag_ban #define CONF_BAN_TYPE_TEMPORARY 2 + struct _configitem { ConfigFlag flag; ConfigItem *prev; @@ -1096,6 +1098,14 @@ struct _configitem_ban { char *reason; }; +struct _configitem_badword { + ConfigFlag flag; + ConfigItem *prev; + ConfigItem *next; + char *word; + char *replace; +}; + struct _configitem_deny_dcc { ConfigFlag_ban flag; ConfigItem *prev; diff --git a/src/badwords.c b/src/badwords.c index b1a0177e5..47d696db8 100644 --- a/src/badwords.c +++ b/src/badwords.c @@ -25,10 +25,11 @@ #ifdef STRIPBADWORDS #include "badwords.h" -static char *channelword[MAX_WORDS]; -static char *messageword[MAX_WORDS]; -static int channel_wordlist; -static int message_wordlist; +/* This was modified a bit in order to use newconf. The loading functions + * have been trashed and integrated into the config parser. The striping + * function now only uses REPLACEWORD if no word is specifically defined + * for the word found. Also the freeing function has been ditched. -- codemastr + */ /* * Returns a string, which has been filtered by the words loaded via @@ -47,9 +48,10 @@ char *stripbadwords_channel(char *str) static char cleanstr[4096]; char buf[4096]; char *ptr; - int errorcode, matchlen, stringlen, this_word; + int errorcode, matchlen, stringlen; + ConfigItem_badword *this_word; - if (!channel_wordlist) + if (!conf_badword_channel) return str; strncpy(cleanstr, str, sizeof(cleanstr) - 1); /* Let's work on a backup */ memset(&pmatch, 0, sizeof(pmatch)); @@ -57,10 +59,10 @@ char *stripbadwords_channel(char *str) matchlen = 0; buf[0] = '\0'; - for (this_word = 0; channelword[this_word] != NULL; this_word++) + for (this_word = conf_badword_channel; this_word; this_word = (ConfigItem_badword *)this_word->next) { if ((errorcode = - regcomp(&pcomp, channelword[this_word], REG_ICASE)) > 0) + regcomp(&pcomp, this_word->word, REG_ICASE)) > 0) { regfree(&pcomp); return cleanstr; @@ -74,7 +76,10 @@ char *stripbadwords_channel(char *str) break; matchlen += pmatch[0].rm_eo - pmatch[0].rm_so; strncat(buf, ptr, pmatch[0].rm_so); - strcat(buf, REPLACEWORD); /* Who's afraid of the big bad buffer overflow? */ + if (this_word->replace) + strcat(buf, this_word->replace); + else + strcat(buf, REPLACEWORD); ptr += pmatch[0].rm_eo; /* Set pointer after the match pos */ memset(&pmatch, 0, sizeof(pmatch)); } @@ -96,9 +101,10 @@ char *stripbadwords_message(char *str) static char cleanstr[4096]; char buf[4096]; char *ptr; - int errorcode, matchlen, stringlen, this_word; + ConfigItem_badword *this_word; + int errorcode, matchlen, stringlen; - if (!message_wordlist) + if (!conf_badword_message) return str; strncpy(cleanstr, str, sizeof(cleanstr) - 1); /* Let's work on a backup */ memset(&pmatch, 0, sizeof(pmatch)); @@ -106,10 +112,10 @@ char *stripbadwords_message(char *str) matchlen = 0; buf[0] = '\0'; - for (this_word = 0; messageword[this_word] != NULL; this_word++) + for (this_word = conf_badword_message; this_word; this_word = (ConfigItem_badword *)this_word->next) { if ((errorcode = - regcomp(&pcomp, messageword[this_word], REG_ICASE)) > 0) + regcomp(&pcomp, this_word->word, REG_ICASE)) > 0) { regfree(&pcomp); return cleanstr; @@ -123,7 +129,10 @@ char *stripbadwords_message(char *str) break; matchlen += pmatch[0].rm_eo - pmatch[0].rm_so; strncat(buf, ptr, pmatch[0].rm_so); - strcat(buf, REPLACEWORD); /* Who's afraid of the big bad buffer overflow? */ + if (this_word->replace) + strcat(buf, this_word->replace); + else + strcat(buf, REPLACEWORD); ptr += pmatch[0].rm_eo; /* Set pointer after the match pos */ memset(&pmatch, 0, sizeof(pmatch)); } @@ -138,147 +147,4 @@ char *stripbadwords_message(char *str) return (cleanstr); } -/* - * Loads bad words from a file, into a char array. This puts a limitation on - * how many words may be slurped (which is probably a good thing). The words - * are then called by stripbadwords, to filter unwanted (swear) words. - */ -int loadbadwords_channel(char *wordfile) -{ - FILE *fin; - char buf[MAX_WORDLEN]; - char *ptr; - int i, j, isregex; - - channel_wordlist = 0; - memset(channelword, 0, sizeof(messageword)); - - if ((fin = fopen(wordfile, "r")) == NULL) - return 0; - - for (i = 0; i < MAX_WORDS; i++) - { - if (fgets(buf, MAX_WORDLEN, fin) == NULL) - break; - if ((ptr = strchr(buf, '\r')) != NULL - || (ptr = strchr(buf, '\n')) != NULL) - *ptr = '\0'; - if (buf[0] == '\0') - { - i--; - continue; - } - if (buf[0] == '#') - { - i--; - continue; - } - for (j = 0, isregex = 0; j < strlen(buf); j++) - { - if ((int)buf[j] < 65 || (int)buf[j] > 123) - { - isregex++; /* Probably is */ - break; - } - } - - if (isregex) - { - /* We don't have to apply a pattern to the word because - * it already *is* a pattern. - */ - channelword[i] = (char *)MyMalloc(strlen(buf) + 1); - strncpy(channelword[i], buf, strlen(buf) + 1); - } - else - { - /* PATTERN contains the %s format specifier so we must - * remove 2 chars, and 1 for the \0, which gives us -1 - */ - channelword[i] = - (char *)MyMalloc(strlen(buf) + strlen(PATTERN) - 1); - ircsprintf(channelword[i], PATTERN, buf); - } - channel_wordlist++; - } - fclose(fin); - - return i; -} - -int loadbadwords_message(char *wordfile) -{ - FILE *fin; - char buf[MAX_WORDLEN]; - char *ptr; - int i, j, isregex; - - message_wordlist = 0; - memset(messageword, 0, sizeof(messageword)); - - if ((fin = fopen(wordfile, "r")) == NULL) - return 0; - - for (i = 0; i < MAX_WORDS; i++) - { - if (fgets(buf, MAX_WORDLEN, fin) == NULL) - break; - if ((ptr = strchr(buf, '\r')) != NULL - || (ptr = strchr(buf, '\n')) != NULL) - *ptr = '\0'; - if (buf[0] == '\0') - { - i--; - continue; - } - if (buf[0] == '#') - { - i--; - continue; - } - - for (j = 0, isregex = 0; j < strlen(buf); j++) - { - if ((int)buf[j] < 65 || (int)buf[j] > 123) - { - isregex++; /* Probably is */ - break; - } - } - - if (isregex) - { - /* We don't have to apply a pattern to the word because - * it already *is* a pattern. - */ - messageword[i] = (char *)MyMalloc(strlen(buf) + 1); - strncpy(messageword[i], buf, strlen(buf) + 1); - } - else - { - /* PATTERN contains the %s format specifier so we must - * remove 2 chars, and 1 for the \0, which gives us -1 - */ - messageword[i] = - (char *)MyMalloc(strlen(buf) + strlen(PATTERN) - 1); - ircsprintf(messageword[i], PATTERN, buf); - } - message_wordlist++; - } - fclose(fin); - - return i; -} - - -void freebadwords(void) -{ - int i; - - for (i = 0; channelword[i] != NULL && i < MAX_WORDS; i++) - free(channelword[i]); - for (i = 0; messageword[i] != NULL && i < MAX_WORDS; i++) - free(messageword[i]); - return; -} #endif diff --git a/src/ircd.c b/src/ircd.c index cc46d1337..12d06e015 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -1044,18 +1044,6 @@ int InitwIRCD(argc, argv) init_dynconf(); init_conf2(configfile); validate_configuration(); -#ifdef STRIPBADWORDS - if (loadbadwords_message("badwords.message.conf")) - { - fprintf(stderr, - "* Loaded badwords.message.conf (message filter words) ..\n"); - } - if (loadbadwords_channel("badwords.channel.conf")) - { - fprintf(stderr, - "* Loaded badwords.channel.conf (channel filter words) ..\n"); - } -#endif booted = TRUE; if (cr_loadconf() == 0) { diff --git a/src/s_conf2.c b/src/s_conf2.c index 6ae9d2590..e77ae0d6e 100644 --- a/src/s_conf2.c +++ b/src/s_conf2.c @@ -38,7 +38,9 @@ #include #endif #include - +#ifdef STRIPBADWORDS +#include "badwords.h" +#endif #include "h.h" extern char *my_itoa(long i); @@ -89,6 +91,9 @@ int _conf_vhost (ConfigFile *conf, ConfigEntry *ce); int _conf_link (ConfigFile *conf, ConfigEntry *ce); int _conf_ban (ConfigFile *conf, ConfigEntry *ce); int _conf_set (ConfigFile *conf, ConfigEntry *ce); +#ifdef STRIPBADWORDS +int _conf_badword (ConfigFile *conf, ConfigEntry *ce); +#endif int _conf_deny (ConfigFile *conf, ConfigEntry *ce); int _conf_deny_dcc (ConfigFile *conf, ConfigEntry *ce); @@ -110,6 +115,9 @@ static ConfigCommand _ConfigCommands[] = { { "link", _conf_link }, { "ban", _conf_ban }, { "set", _conf_set }, +#ifdef STRIPBADWORDS + { "badword", _conf_badword }, +#endif { "deny", _conf_deny }, { NULL, NULL } }; @@ -191,6 +199,10 @@ ConfigItem_except *conf_except = NULL; ConfigItem_vhost *conf_vhost = NULL; ConfigItem_link *conf_link = NULL; ConfigItem_ban *conf_ban = NULL; +#ifdef STRIPBADWORDS +ConfigItem_badword *conf_badword_channel = NULL; +ConfigItem_badword *conf_badword_message = NULL; +#endif ConfigItem_deny_dcc *conf_deny_dcc = NULL; /* @@ -1727,9 +1739,6 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cep->ce_varname, "oper-auto-join")) { ircstrdup(OPER_AUTO_JOIN_CHANS, cep->ce_vardata); } - else if (!strcmp(cep->ce_varname, "auto-join")) { - ircstrdup(AUTO_JOIN_CHANS, cep->ce_vardata); - } else if (!strcmp(cep->ce_varname, "socks")) { for (cepp = cep->ce_entries; cepp; cepp = cepp->ce_next) { if (!strcmp(cepp->ce_varname, "ban-message")) { @@ -1805,7 +1814,7 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) else if (!strcmp(cep->ce_varname, "ftp-site")) { ircstrdup(ftp_site, cep->ce_vardata); } - else if (!strcmp(cep->ce_varname, "prefix_quit")) { + else if (!strcmp(cep->ce_varname, "prefix-quit")) { ircstrdup(prefix_quit, cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "hosts")) { @@ -1841,6 +1850,73 @@ int _conf_set(ConfigFile *conf, ConfigEntry *ce) } } } +#ifdef STRIPBADWORDS +int _conf_badword(ConfigFile *conf, ConfigEntry *ce) +{ + ConfigEntry *cep; + ConfigItem_badword *ca; + char *tmp; + short regex = 0; + + ca = MyMallocEx(sizeof(ConfigItem_badword)); + if (!ce->ce_vardata) { + config_error("%s:%i: badword without type", + cep->ce_fileptr->cf_filename, + cep->ce_varlinenum); + return -1; + } + + for (cep = ce->ce_entries; cep; cep = cep->ce_next) + { + if (!cep->ce_varname) + { + config_error("%s:%i: blank badword item", + cep->ce_fileptr->cf_filename, + cep->ce_varlinenum); + continue; + } + if (!cep->ce_vardata) + { + config_error("%s:%i: missing parameter in badword::%s", + cep->ce_fileptr->cf_filename, cep->ce_varlinenum, + cep->ce_varname); + continue; + } + + if (!strcmp(cep->ce_varname, "word")) { + for (tmp = cep->ce_vardata; *tmp; tmp++) { + if ((int)*tmp < 65 || (int)*tmp > 123) { + regex = 1; + break; + } + } + if (regex) { + ircstrdup(ca->word, cep->ce_vardata); + } + else { + ca->word = MyMalloc(strlen(cep->ce_vardata) + strlen(PATTERN) -1); + ircsprintf(ca->word, PATTERN, cep->ce_vardata); + } + } + else if (!strcmp(cep->ce_varname, "replace")) { + ircstrdup(ca->replace, cep->ce_vardata); + } + else + { + config_status("%s:%i: unknown directive badword::%s", + cep->ce_fileptr->cf_filename, cep->ce_varlinenum, + cep->ce_varname); + } + } + if (!strcmp(ce->ce_vardata, "channel")) + add_ConfigItem((ConfigItem *)ca, (ConfigItem **) &conf_badword_channel); + else if (!strcmp(ce->ce_vardata, "message")) + add_ConfigItem((ConfigItem *)ca, (ConfigItem **) &conf_badword_message); + + +} +#endif + /* deny {} function */ int _conf_deny(ConfigFile *conf, ConfigEntry *ce) { @@ -2107,11 +2183,6 @@ void validate_configuration(void) "set::maxchannelsperuser is an invalid value, must be > 0"); if ((iNAH < 0) || (iNAH > 1)) Error("set::host-on-oper-op is an invalid value"); - if (AUTO_JOIN_CHANS == '\0') - Error("set::auto-join is an invalid value"); - if (OPER_AUTO_JOIN_CHANS == '\0') - Error( - "set::oper-auto-join is an invalid value"); if (HOST_TIMEOUT < 0 || HOST_TIMEOUT > 180) Error("set::dns::timeout is an invalid value"); if (HOST_RETRIES < 0 || HOST_RETRIES > 10) @@ -2272,6 +2343,8 @@ int rehash(aClient *cptr, aClient *sptr, int sig) ConfigItem_link *link_ptr; ConfigItem_listen *listen_ptr; ConfigItem_tld *tld_ptr; + ConfigItem_vhost *vhost_ptr; + ConfigItem_badword *badword_ptr; ConfigItem_deny_dcc *deny_dcc_ptr; ConfigItem t; @@ -2297,7 +2370,7 @@ int rehash(aClient *cptr, aClient *sptr, int sig) for (oper_from = (ConfigItem_oper_from *) oper_ptr->from; oper_from; oper_from = (ConfigItem_oper_from *) oper_from->next) { ircfree(oper_from->name); - t.next = del_ConfigItem((ConfigItem *)oper_ptr, (ConfigItem **)&oper_ptr->from); + t.next = del_ConfigItem((ConfigItem *)oper_from, (ConfigItem **)&oper_ptr->from); MyFree(oper_from); oper_from = (ConfigItem_oper_from *) &t; } @@ -2391,6 +2464,43 @@ int rehash(aClient *cptr, aClient *sptr, int sig) MyFree(tld_ptr); tld_ptr = (ConfigItem_tld *) &t; } + for (vhost_ptr = conf_vhost; vhost_ptr; vhost_ptr = (ConfigItem_vhost *) vhost_ptr->next) + { + ConfigItem_oper_from *vhost_from; + + ircfree(vhost_ptr->login); + ircfree(vhost_ptr->password); + ircfree(vhost_ptr->virthost); + for (vhost_from = (ConfigItem_oper_from *) vhost_ptr->from; vhost_from; + vhost_from = (ConfigItem_oper_from *) vhost_from->next) + { + ircfree(vhost_from->name); + t.next = del_ConfigItem((ConfigItem *)vhost_from, (ConfigItem **)&vhost_ptr->from); + MyFree(vhost_from); + vhost_from = (ConfigItem_oper_from *) &t; + } + t.next = del_ConfigItem((ConfigItem *)vhost_ptr, (ConfigItem **)&conf_vhost); + MyFree(vhost_ptr); + vhost_ptr = (ConfigItem_vhost *) &t; + } + + for (badword_ptr = conf_badword_channel; badword_ptr; + badword_ptr = (ConfigItem_badword *) badword_ptr->next) { + ircfree(badword_ptr->word); + ircfree(badword_ptr->replace); + t.next = del_ConfigItem((ConfigItem *) badword_ptr, (ConfigItem **)&conf_badword_channel); + MyFree(badword_ptr); + badword_ptr = (ConfigItem_badword *) &t; + } + for (badword_ptr = conf_badword_message; badword_ptr; + badword_ptr = (ConfigItem_badword *) badword_ptr->next) { + ircfree(badword_ptr->word); + ircfree(badword_ptr->replace); + t.next = del_ConfigItem((ConfigItem *) badword_ptr, (ConfigItem **)&conf_badword_message); + MyFree(badword_ptr); + badword_ptr = (ConfigItem_badword *) &t; + } + for (deny_dcc_ptr = conf_deny_dcc; deny_dcc_ptr; deny_dcc_ptr = (ConfigItem_deny_dcc *) deny_dcc_ptr->next) { if (deny_dcc_ptr->flag.type2 == CONF_BAN_TYPE_CONF) @@ -2402,7 +2512,6 @@ int rehash(aClient *cptr, aClient *sptr, int sig) deny_dcc_ptr = (ConfigItem_deny_dcc *) &t; } } - /* This space is for codemastr's upcoming vhost removal code. */ if (conf_drpass) { ircfree(conf_drpass->restart); diff --git a/src/s_serv.c b/src/s_serv.c index 8808141f3..44cc775b2 100644 --- a/src/s_serv.c +++ b/src/s_serv.c @@ -3882,21 +3882,6 @@ int m_rehash(cptr, sptr, parc, parv) vhost_rehash(); return 0; } -#endif -#ifdef STRIPBADWORDS - if (!strnicmp("-bad", parv[1], 4)) - { - if (!IsAdmin(sptr)) - return 0; - sendto_ops - ("%sRehashing badword configuration on request of %s", - cptr != sptr ? "Remotely " : "", - sptr->name); - freebadwords(); - loadbadwords_channel("badwords.channel.conf"); - loadbadwords_message("badwords.message.conf"); - return 0; - } #endif } } diff --git a/src/s_user.c b/src/s_user.c index 238b3496e..40870a3bc 100644 --- a/src/s_user.c +++ b/src/s_user.c @@ -1056,10 +1056,10 @@ static int register_user(cptr, sptr, nick, username, umode, virthost) (IsToken(nsptr->from) ? TOK_PRIVATE : MSG_PRIVATE), NickServ, SERVICES_NAME, sptr->passwd); /* Force the user to join the given chans -- codemastr */ - if (buf[1] != '\0') + if (buf[0] != '\0' && buf[1] != '\0') sendto_one(cptr,":%s MODE %s :%s", cptr->name, cptr->name, buf); - if (strcmp(AUTO_JOIN_CHANS, "0")) + if (!BadPtr(AUTO_JOIN_CHANS) && strcmp(AUTO_JOIN_CHANS, "0")) { char *chans[3] = { sptr->name, @@ -4035,7 +4035,7 @@ int m_oper(cptr, sptr, parc, parv) if (SHOWOPERMOTD == 1) m_opermotd(cptr, sptr, parc, parv); - if (strcmp(OPER_AUTO_JOIN_CHANS, "0")) + if (!BadPtr(OPER_AUTO_JOIN_CHANS) && strcmp(OPER_AUTO_JOIN_CHANS, "0")) { char *chans[3] = { sptr->name,