diff --git a/src/modules/webirc.c b/src/modules/webirc.c index 477db5333..954298ff0 100644 --- a/src/modules/webirc.c +++ b/src/modules/webirc.c @@ -28,9 +28,8 @@ typedef enum { struct _configitem_webirc { ConfigItem_webirc *prev, *next; ConfigFlag flag; + ConfigItem_mask *mask; WEBIRCType type; - char *username; - char *hostname; anAuthStruct *auth; }; @@ -112,7 +111,7 @@ DLLFUNC int MOD_UNLOAD(webirc)(int module_unload) void webirc_free_conf(void) { - ConfigItem_webirc *webirc_ptr, *next; + ConfigItem_webirc *webirc_ptr, *next; for (webirc_ptr = conf_webirc; webirc_ptr; webirc_ptr = next) { @@ -124,11 +123,9 @@ void webirc_free_conf(void) void delete_webircblock(ConfigItem_webirc *e) { - Debug((DEBUG_ERROR, "delete_webircblock: deleting %s", e->hostname)); + unreal_delete_masks(e->mask); if (e->auth) Auth_DeleteAuthStruct(e->auth); - ircfree(e->hostname); - ircfree(e->username); DelListItem(e, conf_webirc); MyFree(e); } @@ -136,12 +133,11 @@ void delete_webircblock(ConfigItem_webirc *e) DLLFUNC int webirc_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs) { ConfigEntry *cep, *cepp; - int errors = 0; - char has_username = 0; /* dup checking only, not mandatory */ - char has_type = 0; /* mandatory */ - char has_hostname = 0; /* mandatory */ + int errors = 0; + char has_mask = 0; /* mandatory */ char has_password = 0; /* mandatory */ - WEBIRCType webirc_type; + char has_type = 0; /* optional (used for dup checking) */ + WEBIRCType webirc_type = WEBIRC_WEBIRC; /* the default */ if (type != CONFIG_MAIN) return 0; @@ -178,48 +174,10 @@ DLLFUNC int webirc_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *e errors++; continue; } - if (!strcmp(cep->ce_varname, "username")) + if (!strcmp(cep->ce_varname, "mask")) { - if (has_username) - { - config_warn_duplicate(cep->ce_fileptr->cf_filename, - cep->ce_varlinenum, "webirc::username"); - continue; - } - has_username = 1; - } - else if (!strcmp(cep->ce_varname, "hostname")) - { - if (has_hostname) - { - config_warn_duplicate(cep->ce_fileptr->cf_filename, - cep->ce_varlinenum, "webirc::hostname"); - continue; - } - has_hostname = 1; -#ifdef INET6 - /* I'm nice... I'll help those poor ipv6 users. -- Syzop */ - /* [ not null && len>6 && has not a : in it && last character is a digit ] */ - if (cep->ce_vardata && (strlen(cep->ce_vardata) > 6) && !strchr(cep->ce_vardata, ':') && - isdigit(cep->ce_vardata[strlen(cep->ce_vardata)-1])) - { - char crap[32]; - if (inet_pton(AF_INET, cep->ce_vardata, crap) != 0) - { - char ipv6buf[48]; - snprintf(ipv6buf, sizeof(ipv6buf), "::ffff:%s", cep->ce_vardata); - MyFree(cep->ce_vardata); - cep->ce_vardata = strdup(ipv6buf); - } else { - /* Insert IPv6 validation here */ - config_error( "%s:%i: webirc::hostname: '%s' looks like " - "it might be IPv4, but is not a valid address.", - ce->ce_fileptr->cf_filename, ce->ce_varlinenum, - cep->ce_vardata); - errors++; - } - } -#endif + if (cep->ce_vardata || cep->ce_entries) + has_mask = 1; } else if (!strcmp(cep->ce_varname, "password")) { @@ -259,33 +217,27 @@ DLLFUNC int webirc_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *e errors++; } } - if (!has_hostname) + if (!has_mask) { config_error_missing(ce->ce_fileptr->cf_filename, ce->ce_varlinenum, - "webirc::hostname"); + "webirc::mask"); errors++; } - if (!has_type) + + if (!has_password && (webirc_type == WEBIRC_WEBIRC)) { config_error_missing(ce->ce_fileptr->cf_filename, ce->ce_varlinenum, - "webirc::type"); + "webirc::password"); errors++; - } else + } + + if (has_password && (webirc_type == WEBIRC_PASS)) { - if (!has_password && (webirc_type == WEBIRC_WEBIRC)) - { - config_error_missing(ce->ce_fileptr->cf_filename, ce->ce_varlinenum, - "webirc::password"); - errors++; - } else - if (has_password && (webirc_type == WEBIRC_PASS)) - { - config_error("%s:%i: webirc block has type set to 'old' but has a password set. " - "Passwords are not used with type 'old'. Either remove the password or " - "use the 'webirc' method instead.", - ce->ce_fileptr->cf_filename, ce->ce_varlinenum); - errors++; - } + config_error("%s:%i: webirc block has type set to 'old' but has a password set. " + "Passwords are not used with type 'old'. Either remove the password or " + "use the 'webirc' method instead.", + ce->ce_fileptr->cf_filename, ce->ce_varlinenum); + errors++; } *errs = errors; @@ -305,13 +257,12 @@ DLLFUNC int webirc_config_run(ConfigFile *cf, ConfigEntry *ce, int type) return 0; /* not interested */ webirc = (ConfigItem_webirc *) MyMallocEx(sizeof(ConfigItem_webirc)); + webirc->type = WEBIRC_WEBIRC; /* default */ for (cep = ce->ce_entries; cep; cep = cep->ce_next) { - if (!strcmp(cep->ce_varname, "username")) - webirc->username = strdup(cep->ce_vardata); - else if (!strcmp(cep->ce_varname, "hostname")) - webirc->hostname = strdup(cep->ce_vardata); + if (!strcmp(cep->ce_varname, "mask")) + unreal_add_masks(&webirc->mask, cep); else if (!strcmp(cep->ce_varname, "password")) webirc->auth = Auth_ConvertConf2AuthStruct(cep); else if (!strcmp(cep->ce_varname, "type")) @@ -336,17 +287,13 @@ void webirc_md_free(ModData *md) md->l = 0; } -ConfigItem_webirc *Find_webirc(char *username, char *hostname, char *ip, WEBIRCType type) +ConfigItem_webirc *Find_webirc(aClient *sptr, WEBIRCType type) { -ConfigItem_webirc *e; + ConfigItem_webirc *e; - if (!username || !hostname || !ip) - return NULL; - - for (e = conf_webirc; e; e = (ConfigItem_webirc *)e->next) + for (e = conf_webirc; e; e = e->next) { - if ((e->type == type) && (!e->username || !match(e->username, username)) && - (!match(e->hostname, hostname) || !match(e->hostname, ip) || !match_ip46(e->hostname, ip))) + if ((e->type == type) && unreal_mask_match(sptr, e->mask)) return e; } @@ -428,9 +375,9 @@ int dowebirc(aClient *cptr, char *ip, char *host) /* WEBIRC "cgiirc" */ int m_webirc(aClient *cptr, aClient *sptr, int parc, char *parv[]) { -char *ip, *host, *password; -size_t ourlen; -ConfigItem_webirc *e; + char *ip, *host, *password; + size_t ourlen; + ConfigItem_webirc *e; if ((parc < 5) || BadPtr(parv[4])) { @@ -443,7 +390,7 @@ ConfigItem_webirc *e; ip = parv[4]; /* Check if allowed host */ - e = Find_webirc(sptr->username, sptr->sockhost, GetIP(sptr), WEBIRC_WEBIRC); + e = Find_webirc(sptr, WEBIRC_WEBIRC); if (!e) return exit_client(cptr, sptr, &me, "CGI:IRC -- No access"); @@ -474,7 +421,7 @@ int webirc_local_pass(aClient *sptr, char *password) char *ip, *host; ConfigItem_webirc *e; - e = Find_webirc(sptr->username, sptr->sockhost, GetIP(sptr), WEBIRC_PASS); + e = Find_webirc(sptr, WEBIRC_PASS); if (e) { /* Ok now we got that sorted out, proceed: