#include "module.h" #define AUTHOR "Strike" #define VERSION "1.01" /*************************************************************************/ /* hs_nodots.c - 28 March 2004 by Strike */ /* This module will allow you to set vhosts via hostserv otherwise */ /* not allowed due to a lack of dots. You now can set vhosts like */ /* "Strike@Anope" instead of "Strike@Anope.org". */ /* WARNING: THIS MODULE IS AGAINST RFC AND MAY CAUSE COMPATIBILITY */ /* PROBLEMS WITH YOUR IRCD. PLEASE BACKUP NICK DATABASES BEFORE */ /* ATTEMPTING TO INSTALL ON IRCD's THIS HAS NOT BEEN TESTED ON. */ /* DO NOT ATTEMPT TO INSTALL WHEN USING UNREAL3.1 OR ULTIMATEIRCD!!!*/ /* Tested on: */ /* 1) Unreal3.2 */ /* Special thanks to: GeniusDex, Keith */ /* Changes: */ /* 1.00 - Works */ /* 1.01 - Fixed error in SET command. */ /*************************************************************************/ extern void addHostCore(char *nick, char *vIdent, char *vhost, char *creator, int32 tmp_time); extern int is_host_setter(User * u); extern int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask, char *creator, time_t time); int is_host_setter(User * u); int do_hset(User * u); int do_hsetall(User * u); int AnopeInit(int argc, char **argv) { Command *c; c = createCommand("set", do_hset, is_host_setter, -1, -1, -1, -1, -1); moduleAddCommand(HOSTSERV, c, MOD_HEAD); alog("hs_nodots: Add command 'set' status: %d", moduleAddCommand(HELPSERV, c, MOD_HEAD)); c = createCommand("setall", do_hsetall, is_host_setter, -1, -1, -1, -1, -1); moduleAddCommand(HOSTSERV, c, MOD_HEAD); alog("hs_nodots: Add command 'setall' status: %d", moduleAddCommand(HELPSERV, c, MOD_HEAD)); moduleAddAuthor("Strike"); moduleAddVersion("1.0"); alog("Loaded module hs_nodots by Strike"); return MOD_CONT; } int doValidVHost(const char *host, int type) { int idx = 0; int len = 0; int sec_len = 0; int dots = 1; if (type != 1 && type != 2) { return 0; } if (!host) { return 0; } len = strlen(host); if (len > HOSTMAX) { return 0; } switch (type) { case 1: for (idx = 0; idx < len; idx++) { if (isdigit(host[idx])) { if (sec_len < 3) { sec_len++; } else { return 0; } } else { if (idx == 0) { return 0; } /* cant start with a non-digit */ if (host[idx] != '.') { return 0; } /* only . is a valid non-digit */ if (sec_len > 3) { return 0; } /* sections cant be more than 3 digits */ sec_len = 0; dots++; } } if (dots != 4) { return 0; } break; case 2: dots = 0; for (idx = 0; idx < len; idx++) { if (!isalnum(host[idx])) { if (idx == 0) { return 0; } if ((host[idx] != '.') && (host[idx] != '-')) { return 0; } if (host[idx] == '.') { dots++; } } } if (host[len - 1] == '.') { return 0; } break; } return 1; } int isValidVHost(const char *host, int type) { int status = 0; if (type == 3) { if (!(status = doValidVHost(host, 1))) { status = doValidVHost(host, 2); } } else { status = doValidVHost(host, type); } return status; } int do_hset(User * u) { char *nick = strtok(NULL, " "); char *rawhostmask = strtok(NULL, " "); char *hostmask = smalloc(HOSTMAX); NickAlias *na; int32 tmp_time; char *s; char *vIdent = NULL; if (!nick || !rawhostmask) { notice_lang(s_HostServ, u, HOST_SET_SYNTAX, s_HostServ); return MOD_CONT; } vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); if (vIdent) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); if (!rawhostmask) { notice_lang(s_HostServ, u, HOST_SET_SYNTAX, s_HostServ); return MOD_CONT; } if (strlen(vIdent) > USERMAX - 1) { notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); return MOD_CONT; } else { for (s = vIdent; *s; s++) { if (!isvalidchar(*s)) { notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR); return MOD_CONT; } } } #ifndef HAS_VIDENT notice_lang(s_HostServ, u, HOST_NO_VIDENT); return MOD_CONT; #endif } if (strlen(rawhostmask) < HOSTMAX - 1) snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); else { notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); return MOD_CONT; } if (!isValidVHost(hostmask, 3)) { notice_lang(s_HostServ, u, HOST_SET_ERROR); return MOD_CONT; } tmp_time = time(NULL); if ((na = findnick(nick))) { alog("vHost for user \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); addHostCore(nick, vIdent, hostmask, u->nick, tmp_time); if (vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_SET, nick, vIdent, hostmask); } else { notice_lang(s_HostServ, u, HOST_SET, nick, hostmask); } } else { notice_lang(s_HostServ, u, HOST_NOREG, nick); } free(hostmask); return MOD_STOP; } int do_hsetall(User * u) { char *nick = strtok(NULL, " "); char *rawhostmask = strtok(NULL, " "); char *hostmask = smalloc(HOSTMAX); NickAlias *na; int32 tmp_time; char *s; char *vIdent = NULL; if (!nick || !rawhostmask) { notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ); return MOD_CONT; } vIdent = myStrGetOnlyToken(rawhostmask, '@', 0); if (vIdent) { rawhostmask = myStrGetTokenRemainder(rawhostmask, '@', 1); if (!rawhostmask) { notice_lang(s_HostServ, u, HOST_SETALL_SYNTAX, s_HostServ); return MOD_CONT; } if (strlen(vIdent) > USERMAX - 1) { notice_lang(s_HostServ, u, HOST_SET_IDENTTOOLONG, USERMAX); return MOD_CONT; } else { for (s = vIdent; *s; s++) { if (!isvalidchar(*s)) { notice_lang(s_HostServ, u, HOST_SET_IDENT_ERROR); return MOD_CONT; } } } #ifndef HAS_VIDENT notice_lang(s_HostServ, u, HOST_NO_VIDENT); return MOD_CONT; #endif } if (strlen(rawhostmask) < HOSTMAX - 1) snprintf(hostmask, HOSTMAX - 1, "%s", rawhostmask); else { notice_lang(s_HostServ, u, HOST_SET_TOOLONG, HOSTMAX); return MOD_CONT; } if (!isValidVHost(hostmask, 3)) { notice_lang(s_HostServ, u, HOST_SET_ERROR); return MOD_CONT; } tmp_time = time(NULL); if ((na = findnick(nick))) { alog("vHost for all nicks in group \002%s\002 set to \002%s\002 by oper \002%s\002", nick, hostmask, u->nick); do_hs_sync(na->nc, vIdent, hostmask, u->nick, tmp_time); if (vIdent) { notice_lang(s_HostServ, u, HOST_IDENT_SETALL, nick, vIdent, hostmask); } else { notice_lang(s_HostServ, u, HOST_SETALL, nick, hostmask); } } else { notice_lang(s_HostServ, u, HOST_NOREG, nick); } free(hostmask); return MOD_STOP; } /* EOF */