#include "ircd_alloc.h"
#include "ircd_chattr.h"
#include "ircd_log.h"
+#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "listener.h"
struct TRecord* tdata = NULL;
struct tm motd_tm;
-
-/*
- * is the K line field an interval or a comment? - Mmmm
- */
-static int is_comment(const char *comment)
-{
- unsigned int i;
- unsigned int len = strlen(comment);
- for (i = 0; i < len; ++i) {
- if (!IsKTimeChar(comment[i]))
- return 1;
- }
- return 0;
-}
-
-/*
- * check against a set of time intervals
- */
-static int check_time_interval(char *interval, char *reply)
-{
- struct tm* tptr;
- char* p;
- int perm_min_hours;
- int perm_min_minutes;
- int perm_max_hours;
- int perm_max_minutes;
- int nowm;
- int perm_min;
- int perm_max;
-
- tptr = localtime(&CurrentTime);
- nowm = tptr->tm_hour * 60 + tptr->tm_min;
-
- while (interval) {
- p = strchr(interval, ',');
- if (p)
- *p = '\0';
- if (sscanf(interval, "%2d%2d-%2d%2d", &perm_min_hours, &perm_min_minutes,
- &perm_max_hours, &perm_max_minutes) != 4)
- {
- if (p)
- *p = ',';
- return 0;
- }
- if (p)
- *(p++) = ',';
- perm_min = 60 * perm_min_hours + perm_min_minutes;
- perm_max = 60 * perm_max_hours + perm_max_minutes;
- /*
- * The following check allows intervals over midnight ...
- */
- if ((perm_min < perm_max)
- ? (perm_min <= nowm && nowm <= perm_max)
- : (perm_min <= nowm || nowm <= perm_max))
- {
- sprintf_irc(reply, ":%%s %%d %%s :%s %d:%02d to %d:%02d.",
- "You are not allowed to connect from",
- perm_min_hours, perm_min_minutes,
- perm_max_hours, perm_max_minutes);
- return (ERR_YOUREBANNEDCREEP);
- }
- if ((perm_min < perm_max)
- ? (perm_min <= nowm + 5 && nowm + 5 <= perm_max)
- : (perm_min <= nowm + 5 || nowm + 5 <= perm_max))
- {
- sprintf_irc(reply, ":%%s %%d %%s :%d minute%s%s",
- perm_min - nowm, (perm_min - nowm) > 1 ? "s " : " ",
- "and you will be denied for further access");
- return (ERR_YOUWILLBEBANNED);
- }
- interval = p;
- }
- return 0;
-}
+static struct LocalConf localConf;
+static struct MotdConf* motdConfList;
+static struct CRuleConf* cruleConfList;
+static struct ServerConf* serverConfList;
+static struct DenyConf* denyConfList;
/*
* output the reason for being k lined from a file - Mmmm
- * sptr is server
- * parv is the sender prefix
+ * sptr is client being dumped
* filename is the file that is to be output to the K lined client
*/
-static void killcomment(struct Client *sptr, char *parv, char *filename)
+static void killcomment(struct Client* sptr, const char* filename)
{
- FBFILE* file = NULL;
+ FBFILE* file = 0;
char line[80];
- char* tmp;
struct stat sb;
struct tm* tm;
if (NULL == (file = fbopen(filename, "r"))) {
- sendto_one(sptr, err_str(ERR_NOMOTD), me.name, parv);
- sendto_one(sptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, parv);
+ send_reply(sptr, ERR_NOMOTD);
+ send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
return;
}
fbstat(&sb, file);
tm = localtime((time_t*) &sb.st_mtime); /* NetBSD needs cast */
while (fbgets(line, sizeof(line) - 1, file)) {
- if ((tmp = strchr(line, '\n')))
- *tmp = '\0';
- if ((tmp = strchr(line, '\r')))
- *tmp = '\0';
- /* sendto_one(sptr,
- * ":%s %d %s : %s.",
- * me.name, ERR_YOUREBANNEDCREEP, parv,line); */
- sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv, line);
+ char* end = line + strlen(line);
+ while (end > line) {
+ --end;
+ if ('\n' == *end || '\r' == *end)
+ *end = '\0';
+ else
+ break;
+ }
+ send_reply(sptr, RPL_MOTD, line);
}
- sendto_one(sptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, parv);
+ send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
fbclose(file);
}
#ifdef DEBUGMODE
++GlobalConfCount;
#endif
+ memset(aconf, 0, sizeof(struct ConfItem));
aconf->status = CONF_ILLEGAL;
- aconf->clients = 0;
aconf->ipnum.s_addr = INADDR_NONE;
- aconf->host = 0;
- aconf->passwd = 0;
- aconf->name = 0;
- aconf->port = 0;
- aconf->hold = 0;
- aconf->dns_pending = 0;
- aconf->confClass = 0;
- aconf->next = 0;
return aconf;
}
;
bconf->next = aconf->next;
}
- aconf->next = NULL;
+ aconf->next = 0;
}
void free_conf(struct ConfItem *aconf)
#endif
}
+/*
+ * detach_conf - Disassociate configuration from the client.
+ */
+static void detach_conf(struct Client* cptr, struct ConfItem* aconf)
+{
+ struct SLink** lp;
+ struct SLink* tmp;
+
+ assert(0 != aconf);
+ assert(0 != cptr);
+ assert(0 < aconf->clients);
+
+ lp = &(cptr->confs);
+
+ while (*lp) {
+ if ((*lp)->value.aconf == aconf) {
+ if (aconf->conn_class && (aconf->status & CONF_CLIENT_MASK) && ConfLinks(aconf) > 0)
+ --ConfLinks(aconf);
+
+ assert(0 < aconf->clients);
+ if (0 == --aconf->clients && IsIllegal(aconf))
+ free_conf(aconf);
+ tmp = *lp;
+ *lp = tmp->next;
+ free_link(tmp);
+ return;
+ }
+ lp = &((*lp)->next);
+ }
+}
+
/*
* conf_dns_callback - called when resolver query finishes
* if the query resulted in a successful search, hp will contain
* Evaluate connection rules... If no rules found, allow the
* connect. Otherwise stop with the first true rule (ie: rules
* are ored together. Oper connects are effected only by D
- * lines (CRULEALL) not d lines (CRULEAUTO).
+ * lines (CRULE_ALL) not d lines (CRULE_AUTO).
*/
-const char* conf_eval_crule(struct ConfItem* conf)
+const char* conf_eval_crule(const char* name, int mask)
{
- struct ConfItem* rule;
- assert(0 != conf);
+ struct CRuleConf* p = cruleConfList;
+ assert(0 != name);
- for (rule = GlobalConfList; rule; rule = rule->next) {
- if ((CONF_CRULEALL == rule->status) && (0 == match(rule->host, conf->name))) {
- if (crule_eval(rule->passwd))
- return rule->name;
+ for ( ; p; p = p->next) {
+ if (0 != (p->type & mask) && 0 == match(p->hostmask, name)) {
+ if (crule_eval(p->node))
+ return p->rule;
}
}
return 0;
}
-
-/*
- * field breakup for ircd.conf file.
- */
-static char* getfield(char* newline, char fs)
-{
- static char* gfline = NULL;
- char* end;
- char* field;
-
- if (newline)
- gfline = newline;
-
- if (gfline == NULL)
- return NULL;
-
- end = field = gfline;
-
- if (fs != ':') {
- if (*end == fs)
- ++end;
- else
- fs = ':';
- }
- do {
- while (*end != fs) {
- if (!*end) {
- end = NULL;
- break;
- }
- ++end;
- }
- } while (end && fs != ':' && *++end != ':' && *end != '\n') ;
-
- if (end == NULL) {
- gfline = NULL;
- if ((end = strchr(field, '\n')) == NULL)
- end = field + strlen(field);
- }
- else
- gfline = end + 1;
-
- *end = '\0';
-
- return field;
-}
-
/*
* Remove all conf entries from the client except those which match
* the status field mask.
*/
-void det_confs_butmask(struct Client *cptr, int mask)
-{
- struct SLink *tmp, *tmp2;
-
- for (tmp = cptr->confs; tmp; tmp = tmp2) {
- tmp2 = tmp->next;
- if ((tmp->value.aconf->status & mask) == 0)
- detach_conf(cptr, tmp->value.aconf);
- }
-}
-
-/*
- * validate_hostent - make sure hostnames are valid in a hostent struct
- * XXX - this is terrible, what's worse is it used to be in the inner
- * loop of scanning all the I:lines --Bleep
- */
-static int validate_hostent(struct hostent* hp)
+void det_confs_butmask(struct Client* cptr, int mask)
{
- char fullname[HOSTLEN + 1];
- int i = 0;
- int error = 0;
- const char* hname;
-
- for (hname = hp->h_name; hname; hname = hp->h_aliases[i++]) {
- unsigned int fullnamelen = 0;
- unsigned int label_count = 0;
+ struct SLink* link;
+ struct SLink* next;
+ assert(0 != cptr);
- ircd_strncpy(fullname, hname, HOSTLEN);
- fullname[HOSTLEN] = '\0';
- /*
- * Disallow a hostname label to contain anything but a [-a-zA-Z0-9].
- * It may not start or end on a '.'.
- * A label may not end on a '-', the maximum length of a label is
- * 63 characters.
- * On top of that (which seems to be the RFC) we demand that the
- * top domain does not contain any digits.
- */
- error = (*hname == '.') ? 1 : 0; /* May not start with a '.' */
- if (!error) {
- char *p;
- for (p = fullname; *p; ++p, ++fullnamelen) {
- if (*p == '.') {
- /* Label may not end on '-' and May not end on a '.' */
- if (p[-1] == '-' || p[1] == 0) {
- error = 1;
- break;
- }
- label_count = 0;
- error = 0; /* Was not top domain */
- continue;
- }
- if (++label_count > 63) {
- /* Label not longer then 63 */
- error = 1;
- break;
- }
- if (*p >= '0' && *p <= '9') {
- /* In case this is top domain */
- error = 1;
- continue;
- }
- if (!(*p >= 'a' && *p <= 'z')
- && !(*p >= 'A' && *p <= 'Z') && *p != '-') {
- error = 1;
- break;
- }
- }
- }
- if (error)
- break;
+ for (link = cptr->confs; link; link = next) {
+ next = link->next;
+ if ((link->value.aconf->status & mask) == 0)
+ detach_conf(cptr, link->value.aconf);
}
- return (0 == error);
}
/*
* check_limit_and_attach - check client limits and attach I:line
+ *
+ * Made it accept 1 charactor, and 2 charactor limits (0->99 now),
+ * and dislallow more than 255 people here as well as in ipcheck.
+ * removed the old "ONE" scheme too.
+ * -- Isomer 2000-06-22
*/
-static int check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
+static enum AuthorizationCheckResult
+check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
{
+ int number = 255;
+
if (aconf->passwd) {
- /* Special case: exactly one digit */
- if (IsDigit(*aconf->passwd) && !aconf->passwd[1]) {
- /*
- * Refuse connections when there are already <digit>
- * clients connected with the same IP number
- */
- unsigned short nr = *aconf->passwd - '0';
- if (IPcheck_nr(cptr) > nr)
- return ACR_TOO_MANY_FROM_IP; /* Already got nr with that ip# */
- }
-#ifdef USEONE
- else if (0 == strcmp(aconf->passwd, "ONE")) {
- int i;
- for (i = HighestFd; i > -1; --i) {
- if (LocalClientArray[i] && MyUser(LocalClientArray[i]) &&
- LocalClientArray[i]->ip.s_addr == cptr->ip.s_addr)
- return ACR_TOO_MANY_FROM_IP; /* Already got one with that ip# */
- }
- }
-#endif
+ if (IsDigit(*aconf->passwd) && !aconf->passwd[1])
+ number = *aconf->passwd-'0';
+ else if (IsDigit(*aconf->passwd) && IsDigit(aconf->passwd[1]) &&
+ !aconf->passwd[2])
+ number = (*aconf->passwd-'0')*10+(aconf->passwd[1]-'0');
}
+ if (IPcheck_nr(cptr) > number)
+ return ACR_TOO_MANY_FROM_IP;
return attach_conf(cptr, aconf);
}
/*
* Find the first (best) I line to attach.
*/
-int attach_iline(struct Client* cptr)
+enum AuthorizationCheckResult attach_iline(struct Client* cptr)
{
struct ConfItem* aconf;
const char* hname;
static char fullname[HOSTLEN + 1];
struct hostent* hp = 0;
- if (cptr->dns_reply) {
+ assert(0 != cptr);
+
+ if (cptr->dns_reply)
hp = cptr->dns_reply->hp;
- if (!validate_hostent(hp))
- hp = 0;
- }
+
for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
if (aconf->status != CONF_CLIENT)
continue;
return ACR_NO_AUTHORIZATION;
}
-/*
- * detach_conf - Disassociate configuration from the client.
- */
-int detach_conf(struct Client *cptr, struct ConfItem *aconf)
-{
- struct SLink** lp;
- struct SLink* tmp;
-
- assert(0 != aconf);
- assert(0 != cptr);
- assert(0 < aconf->clients);
-
- lp = &(cptr->confs);
-
- while (*lp) {
- if ((*lp)->value.aconf == aconf) {
- if (aconf->confClass && (aconf->status & CONF_CLIENT_MASK) &&
- ConfLinks(aconf) > 0)
- --ConfLinks(aconf);
- if (0 == --aconf->clients && IsIllegal(aconf))
- free_conf(aconf);
- tmp = *lp;
- *lp = tmp->next;
- free_link(tmp);
- return 0;
- }
- else
- lp = &((*lp)->next);
- }
- return -1;
-}
-
static int is_attached(struct ConfItem *aconf, struct Client *cptr)
{
struct SLink *lp;
- for (lp = cptr->confs; lp; lp = lp->next)
+ for (lp = cptr->confs; lp; lp = lp->next) {
if (lp->value.aconf == aconf)
- break;
-
- return (lp) ? 1 : 0;
+ return 1;
+ }
+ return 0;
}
/*
* connection). Note, that this automaticly changes the
* attachment if there was an old one...
*/
-int attach_conf(struct Client *cptr, struct ConfItem *aconf)
+enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *aconf)
{
struct SLink *lp;
return ACR_OK;
}
-struct ConfItem *find_admin(void)
-{
- struct ConfItem *aconf;
-
- for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
- if (aconf->status & CONF_ADMIN)
- break;
- }
- return aconf;
-}
-
-struct ConfItem* find_me(void)
+const struct LocalConf* conf_get_local(void)
{
- struct ConfItem* aconf;
- for (aconf = GlobalConfList; aconf; aconf = aconf->next) {
- if (aconf->status & CONF_ME)
- break;
- }
- return aconf;
+ return &localConf;
}
/*
struct ConfItem *tmp;
char userhost[USERLEN + HOSTLEN + 3];
- /*
- * XXX - buffer overflow possible, unchecked variables
- */
if (user)
- sprintf_irc(userhost, "%s@%s", user, host);
+ ircd_snprintf(0, userhost, sizeof(userhost), "%s@%s", user, host);
else
ircd_strncpy(userhost, host, sizeof(userhost) - 1);
if (match(tmp->host, userhost))
continue;
if (tmp->status & (CONF_OPERATOR | CONF_LOCOP)) {
- if (tmp->clients < MaxLinks(tmp->confClass))
+ if (tmp->clients < MaxLinks(tmp->conn_class))
return tmp;
else
continue;
struct ConfItem* find_conf_byhost(struct SLink* lp, const char* host,
int statmask)
{
- struct ConfItem* tmp;
+ struct ConfItem* tmp = NULL;
assert(0 != host);
if (HOSTLEN < strlen(host))
return bconf;
}
+
/*
- * rehash
- *
- * Actual REHASH service routine. Called with sig == 0 if it has been called
- * as a result of an operator issuing this command, else assume it has been
- * called as a result of the server receiving a HUP signal.
+ * If conf line is a class definition, create a class entry
+ * for it and make the conf_line illegal and delete it.
*/
-int rehash(struct Client *cptr, int sig)
+void conf_add_class(const char* const* fields, int count)
{
- struct ConfItem** tmp = &GlobalConfList;
- struct ConfItem* tmp2;
- struct ConfClass* cltmp;
- struct Client* acptr;
- struct MotdItem* temp;
- int i;
- int ret = 0;
- int found_g = 0;
+ if (count < 6)
+ return;
+ add_class(atoi(fields[1]), atoi(fields[2]), atoi(fields[3]),
+ atoi(fields[4]), atoi(fields[5]));
+}
- if (1 == sig)
- sendto_ops("Got signal SIGHUP, reloading ircd conf. file");
+void conf_add_listener(const char* const* fields, int count)
+{
+ int is_server = 0;
+ int is_hidden = 0;
- while ((tmp2 = *tmp)) {
- if (tmp2->clients) {
- /*
- * Configuration entry is still in use by some
- * local clients, cannot delete it--mark it so
- * that it will be deleted when the last client
- * exits...
- */
- if (!(tmp2->status & CONF_CLIENT)) {
- *tmp = tmp2->next;
- tmp2->next = 0;
- }
- else
- tmp = &tmp2->next;
- tmp2->status |= CONF_ILLEGAL;
- }
- else {
- *tmp = tmp2->next;
- /* free expression trees of connect rules */
- if ((tmp2->status & (CONF_CRULEALL | CONF_CRULEAUTO)) &&
- (tmp2->passwd != NULL))
- crule_free(&(tmp2->passwd));
- free_conf(tmp2);
- }
+ /*
+ * need a port
+ */
+ if (count < 5 || EmptyString(fields[4]))
+ return;
+
+ if (!EmptyString(fields[3])) {
+ const char* x = fields[3];
+ if ('S' == ToUpper(*x))
+ is_server = 1;
+ ++x;
+ if ('H' == ToUpper(*x))
+ is_hidden = 1;
}
+ /* port vhost mask */
+ add_listener(atoi(fields[4]), fields[2], fields[1], is_server, is_hidden);
+}
+void conf_add_local(const char* const* fields, int count)
+{
+ if (count < 6 || EmptyString(fields[1]) || EmptyString(fields[5])) {
+ ircd_log(L_CRIT, "Your M: line must have 6 fields!\n");
+ return;
+ }
+ /*
+ * these two can only be set the first time
+ */
+ if (0 == localConf.name) {
+ if (string_is_hostname(fields[1]))
+ DupString(localConf.name, fields[1]);
+ }
+ if (0 == localConf.numeric) {
+ localConf.numeric = atoi(fields[5]);
+ if (0 == localConf.numeric)
+ ircd_log(L_WARNING, "Your M: line must have a Numeric value greater than 0\n");
+ }
+ /*
+ * these two can be changed while the server is running
+ */
+ if (string_is_address(fields[2])) {
+ if (INADDR_NONE == (localConf.vhost_address.s_addr = inet_addr(fields[2])))
+ localConf.vhost_address.s_addr = INADDR_ANY;
+ }
+ MyFree(localConf.description);
+ DupString(localConf.description, fields[3]);
/*
- * We don't delete the class table, rather mark all entries
- * for deletion. The table is cleaned up by check_class(). - avalon
+ * XXX - shouldn't be setting these directly here
*/
- for (cltmp = NextClass(FirstClass()); cltmp; cltmp = NextClass(cltmp))
- MarkDelete(cltmp);
+ ircd_strncpy(me.info, fields[3], REALLEN);
+ set_virtual_host(localConf.vhost_address);
+}
+void conf_add_admin(const char* const* fields, int count)
+{
/*
- * delete the juped nicks list
+ * if you have one, it MUST have 3 lines
*/
- clearNickJupes();
+ if (count < 4) {
+ ircd_log(L_CRIT, "Your A: line must have 4 fields!\n");
+ return;
+ }
+ MyFree(localConf.location1);
+ DupString(localConf.location1, fields[1]);
- if (sig != 2)
- flush_resolver_cache();
+ MyFree(localConf.location2);
+ DupString(localConf.location2, fields[2]);
- mark_listeners_closing();
+ MyFree(localConf.contact);
+ DupString(localConf.contact, fields[3]);
+}
- if (!conf_init()) /* This calls check_class(), */
- check_class(); /* unless it fails */
+void conf_add_motd(const char* const* fields, int count, struct MotdConf** list)
+{
+ struct MotdConf* conf;
+ if (count < 3 || EmptyString(fields[1]) || EmptyString(fields[2]))
+ return;
- /*
- * make sure that the server listener is re-added so it doesn't get
- * closed
- */
- close_listeners();
+ conf = (struct MotdConf*) MyMalloc(sizeof(struct MotdConf));
+ assert(0 != conf);
+ DupString(conf->hostmask, fields[1]);
+ collapse(conf->hostmask);
+
+ DupString(conf->path, fields[2]);
+
+ assert(0 != list);
+
+ conf->next = *list;
+ *list = conf;
+}
+
+void conf_erase_motd_list(struct MotdConf** list)
+{
+ struct MotdConf* p;
+ struct MotdConf* next;
+
+ assert(0 != list);
+
+ for (p = *list; p; p = next) {
+ next = p->next;
+ MyFree(p->hostmask);
+ MyFree(p->path);
+ MyFree(p);
+ }
+ *list = 0;
+}
+
+const struct MotdConf* conf_get_motd_list(void)
+{
+ return motdConfList;
+}
+
+/*
+ * conf_add_crule - Create expression tree from connect rule and add it
+ * to the crule list
+ */
+void conf_add_crule(const char* const* fields, int count, int type)
+{
+ struct CRuleNode* node;
+ assert(0 != fields);
+
+ if (count < 4 || EmptyString(fields[1]) || EmptyString(fields[3]))
+ return;
+
+ if ((node = crule_parse(fields[3]))) {
+ struct CRuleConf* p = (struct CRuleConf*) MyMalloc(sizeof(struct CRuleConf));
+ assert(0 != p);
+
+ DupString(p->hostmask, fields[1]);
+ collapse(p->hostmask);
+
+ DupString(p->rule, fields[3]);
+
+ p->type = type;
+ p->node = node;
+ p->next = cruleConfList;
+ cruleConfList = p;
+ }
+}
+
+void conf_erase_crule_list(void)
+{
+ struct CRuleConf* next;
+ struct CRuleConf* p = cruleConfList;
+
+ for ( ; p; p = next) {
+ next = p->next;
+ crule_free(&p->node);
+ MyFree(p->hostmask);
+ MyFree(p->rule);
+ MyFree(p);
+ }
+ cruleConfList = 0;
+}
+
+const struct CRuleConf* conf_get_crule_list(void)
+{
+ return cruleConfList;
+}
+
+void conf_add_server(const char* const* fields, int count)
+{
+ struct ServerConf* server;
+ struct in_addr addr;
+ assert(0 != fields);
/*
- * Flush out deleted I and P lines although still in use.
+ * missing host, password, or alias?
*/
- for (tmp = &GlobalConfList; (tmp2 = *tmp);) {
- if (!(tmp2->status & CONF_ILLEGAL))
- tmp = &tmp2->next;
- else
- {
- *tmp = tmp2->next;
- tmp2->next = NULL;
- if (!tmp2->clients)
- free_conf(tmp2);
+ if (count < 6 || EmptyString(fields[1]) || EmptyString(fields[2]) || EmptyString(fields[3]))
+ return;
+ /*
+ * check the host
+ */
+ if (string_is_hostname(fields[1]))
+ addr.s_addr = INADDR_NONE;
+ else if (INADDR_NONE == (addr.s_addr = inet_addr(fields[1])))
+ return;
+
+ server = (struct ServerConf*) MyMalloc(sizeof(struct ServerConf));
+ assert(0 != server);
+ DupString(server->hostname, fields[1]);
+ DupString(server->passwd, fields[2]);
+ DupString(server->alias, fields[3]);
+ server->address.s_addr = addr.s_addr;
+ server->port = atoi(fields[4]);
+ server->dns_pending = 0;
+ server->connected = 0;
+ server->hold = 0;
+ server->conn_class = find_class(atoi(fields[5]));
+
+ server->next = serverConfList;
+ serverConfList = server;
+
+ // if (INADDR_NONE == server->address.s_addr)
+ // lookup_confhost(server);
+}
+
+void conf_add_deny(const char* const* fields, int count, int ip_kill)
+{
+ struct DenyConf* conf;
+
+ if (count < 4 || EmptyString(fields[1]) || EmptyString(fields[3]))
+ return;
+
+ conf = (struct DenyConf*) MyMalloc(sizeof(struct DenyConf));
+ assert(0 != conf);
+ memset(conf, 0, sizeof(struct DenyConf));
+
+ DupString(conf->hostmask, fields[1]);
+ collapse(conf->hostmask);
+
+ if (!EmptyString(fields[2])) {
+ const char* p = fields[2];
+ if ('!' == *p) {
+ conf->is_file = 1;
+ ++p;
}
+ DupString(conf->message, p);
}
- for (i = 0; i <= HighestFd; i++) {
- if ((acptr = LocalClientArray[i])) {
- assert(!IsMe(acptr));
- if (IsServer(acptr)) {
- det_confs_butmask(acptr,
- ~(CONF_HUB | CONF_LEAF | CONF_UWORLD | CONF_ILLEGAL));
- attach_confs_byname(acptr, acptr->name,
- CONF_HUB | CONF_LEAF | CONF_UWORLD);
- }
- if ((found_g = find_kill(acptr))) {
- sendto_op_mask(found_g == -2 ? SNO_GLINE : SNO_OPERKILL,
- found_g == -2 ? "G-line active for %s" : "K-line active for %s",
- get_client_name(acptr, HIDE_IP));
- if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" :
- "K-lined") == CPTR_KILLED)
- ret = CPTR_KILLED;
- }
+ DupString(conf->usermask, fields[3]);
+ collapse(conf->usermask);
+
+ if (ip_kill) {
+ /*
+ * Here we use the same kludge as in listener.c to parse
+ * a.b.c.d, or a.b.c.*, or a.b.c.d/e.
+ */
+ int c_class;
+ char ipname[16];
+ int ad[4] = { 0 };
+ int bits2 = 0;
+ c_class = sscanf(conf->hostmask, "%d.%d.%d.%d/%d",
+ &ad[0], &ad[1], &ad[2], &ad[3], &bits2);
+ if (c_class != 5) {
+ conf->bits = c_class * 8;
}
+ else {
+ conf->bits = bits2;
+ }
+ sprintf_irc(ipname, "%d.%d.%d.%d", ad[0], ad[1], ad[2], ad[3]);
+
+ /*
+ * This ensures endian correctness
+ */
+ conf->s_addr = inet_addr(ipname);
+ Debug((DEBUG_DEBUG, "IPkill: %s = %08x/%i (%08x)", ipname,
+ conf->s_addr, conf->bits, NETMASK(conf->bits)));
}
- /*
- * free old motd structs
- */
- while (motd) {
- temp = motd->next;
- MyFree(motd);
- motd = temp;
- }
- while (rmotd) {
- temp = rmotd->next;
- MyFree(rmotd);
- rmotd = temp;
+ conf->next = denyConfList;
+ denyConfList = conf;
+}
+
+void conf_erase_deny_list(void)
+{
+ struct DenyConf* next;
+ struct DenyConf* p = denyConfList;
+ for ( ; p; p = next) {
+ next = p->next;
+ MyFree(p->hostmask);
+ MyFree(p->usermask);
+ MyFree(p->message);
+ MyFree(p);
}
- /* reload motd files */
- read_tlines();
- rmotd = read_motd(RPATH);
- motd = read_motd(MPATH);
- return ret;
+ denyConfList = 0;
+}
+
+const struct DenyConf* conf_get_deny_list(void)
+{
+ return denyConfList;
}
/*
- * conf_init
+ * read_configuration_file
*
* Read configuration file.
*
#define MAXCONFLINKS 150
-
-int conf_init(void)
+int read_configuration_file(void)
{
- static char quotes[9][2] = {
- {'b', '\b'},
- {'f', '\f'},
- {'n', '\n'},
- {'r', '\r'},
- {'t', '\t'},
- {'v', '\v'},
- {'\\', '\\'},
- {0, 0}
- };
- char *tmp, *s;
+ enum { MAX_FIELDS = 15 };
+
+ char* src;
+ char* dest;
+ int quoted;
FBFILE *file;
- int i;
char line[512];
int ccount = 0;
struct ConfItem *aconf = 0;
+
+ int field_count = 0;
+ const char* field_vector[MAX_FIELDS + 1];
- Debug((DEBUG_DEBUG, "conf_init: ircd.conf = %s", configfile));
+ Debug((DEBUG_DEBUG, "read_configuration_file: ircd.conf = %s", configfile));
if (0 == (file = fbopen(configfile, "r"))) {
return 0;
}
+
while (fbgets(line, sizeof(line) - 1, file)) {
- if ((tmp = strchr(line, '\n')))
- *tmp = '\0';
+ if ('#' == *line || IsSpace(*line))
+ continue;
+
+ if ((src = strchr(line, '\n')))
+ *src = '\0';
+
+ if (':' != line[1]) {
+ Debug((DEBUG_ERROR, "Bad config line: %s", line));
+ sendto_op_mask(SNO_OLDSNO,"Bad Config line");
+ continue;
+ }
+
/*
- * Do quoting of characters and # detection.
+ * do escapes, quoting, comments, and field breakup in place
+ * in one pass with a poor mans state machine
*/
- for (tmp = line; *tmp; tmp++) {
- if (*tmp == '\\') {
- for (i = 0; quotes[i][0]; i++) {
- if (quotes[i][0] == *(tmp + 1)) {
- *tmp = quotes[i][1];
- break;
- }
- }
- if (!quotes[i][0])
- *tmp = *(tmp + 1);
- if (!*(tmp + 1))
+ field_vector[0] = line;
+ field_count = 1;
+ quoted = 0;
+
+ for (src = line, dest = line; *src; ) {
+ switch (*src) {
+ case '\\':
+ ++src;
+ switch (*src) {
+ case 'b':
+ *dest++ = '\b';
+ ++src;
+ break;
+ case 'f':
+ *dest++ = '\f';
+ ++src;
+ break;
+ case 'n':
+ *dest++ = '\n';
+ ++src;
+ break;
+ case 'r':
+ *dest++ = '\r';
+ ++src;
+ break;
+ case 't':
+ *dest++ = '\t';
+ ++src;
+ break;
+ case 'v':
+ *dest++ = '\v';
+ ++src;
break;
+ case '\\':
+ *dest++ = '\\';
+ ++src;
+ break;
+ case '\0':
+ break;
+ default:
+ *dest++ = *src++;
+ break;
+ }
+ break;
+ case '"':
+ if (quoted)
+ quoted = 0;
+ else
+ quoted = 1;
+ /*
+ * strip quotes
+ */
+ ++src;
+ break;
+ case ':':
+ if (quoted)
+ *dest++ = *src++;
else {
- for (s = tmp; (*s = *(s + 1)); s++)
- ;
+ *dest++ = '\0';
+ field_vector[field_count++] = dest;
+ if (field_count > MAX_FIELDS)
+ *src = '\0';
+ else
+ ++src;
}
+ break;
+ case '#':
+ *src = '\0';
+ break;
+ default:
+ *dest++ = *src++;
+ break;
}
- else if (*tmp == '#')
- *tmp = '\0';
}
- if (!*line || line[0] == '#' || line[0] == '\n' ||
- line[0] == ' ' || line[0] == '\t')
- continue;
- /* Could we test if it's conf line at all? -Vesa */
- if (line[1] != ':') {
- Debug((DEBUG_ERROR, "Bad config line: %s", line));
+ *dest = '\0';
+
+ if (field_count < 2 || EmptyString(field_vector[0]))
continue;
- }
+
if (aconf)
free_conf(aconf);
+
aconf = make_conf();
- tmp = getfield(line, ':');
- if (!tmp)
- continue;
- switch (*tmp) {
+ switch (*field_vector[0]) {
case 'A': /* Name, e-mail address of administrator */
- case 'a': /* of this server. */
- aconf->status = CONF_ADMIN;
+ case 'a': /* of this server. CONF_ADMIN */
+ conf_add_admin(field_vector, field_count);
+ aconf->status = CONF_ILLEGAL;
break;
case 'C': /* Server where I should try to connect */
case 'c': /* in case of lp failures */
aconf->status = CONF_SERVER;
break;
/* Connect rule */
- case 'D':
- aconf->status = CONF_CRULEALL;
+ case 'D': /* CONF_CRULEALL */
+ conf_add_crule(field_vector, field_count, CRULE_ALL);
+ aconf->status = CONF_ILLEGAL;
break;
/* Connect rule - autos only */
- case 'd':
- aconf->status = CONF_CRULEAUTO;
+ case 'd': /* CONF_CRULEAUTO */
+ conf_add_crule(field_vector, field_count, CRULE_AUTO);
+ aconf->status = CONF_ILLEGAL;
break;
case 'H': /* Hub server line */
case 'h':
aconf->status = CONF_CLIENT;
break;
case 'K': /* Kill user line on irc.conf */
- aconf->status = CONF_KILL;
+ conf_add_deny(field_vector, field_count, 0);
+ aconf->status = CONF_ILLEGAL;
break;
case 'k': /* Kill user line based on IP in ircd.conf */
- aconf->status = CONF_IPKILL;
+ conf_add_deny(field_vector, field_count, 1);
+ aconf->status = CONF_ILLEGAL;
break;
/* Operator. Line should contain at least */
/* password and host where connection is */
/* Me. Host field is name used for this host */
/* and port number is the number of the port */
case 'M':
- case 'm':
- aconf->status = CONF_ME;
+ case 'm': /* CONF_ME */
+ conf_add_local(field_vector, field_count);
+ aconf->status = CONF_ILLEGAL;
break;
case 'O':
aconf->status = CONF_OPERATOR;
aconf->status = CONF_LOCOP;
break;
case 'P': /* listen port line */
- case 'p':
- aconf->status = CONF_LISTEN_PORT;
+ case 'p': /* CONF_LISTEN_PORT */
+ conf_add_listener(field_vector, field_count);
+ aconf->status = CONF_ILLEGAL;
break;
case 'T': /* print out different motd's */
- case 't': /* based on hostmask */
- aconf->status = CONF_TLINES;
+ case 't': /* based on hostmask - CONF_TLINES */
+ conf_add_motd(field_vector, field_count, &motdConfList);
+ aconf->status = CONF_ILLEGAL;
break;
case 'U': /* Underworld server, allowed to hack modes */
case 'u': /* *Every* server on the net must define the same !!! */
aconf->status = CONF_UWORLD;
break;
case 'Y':
- case 'y':
- aconf->status = CONF_CLASS;
+ case 'y': /* CONF_CLASS */
+ conf_add_class(field_vector, field_count);
+ aconf->status = CONF_ILLEGAL;
break;
default:
Debug((DEBUG_ERROR, "Error in config file: %s", line));
+ sendto_op_mask(SNO_OLDSNO,"Unknown prefix in config file: %c", *field_vector[0]);
+ aconf->status = CONF_ILLEGAL;
break;
}
if (IsIllegal(aconf))
continue;
- for (;;) { /* Fake loop, that I can use break here --msa */
- if ((tmp = getfield(NULL, ':')) == NULL)
- break;
- DupString(aconf->host, tmp);
- if ((tmp = getfield(NULL, (aconf->status == CONF_KILL
- || aconf->status == CONF_IPKILL) ? '"' : ':')) == NULL)
- break;
- DupString(aconf->passwd, tmp);
- if ((tmp = getfield(NULL, ':')) == NULL)
- break;
- DupString(aconf->name, tmp);
- if ((tmp = getfield(NULL, ':')) == NULL)
- break;
- aconf->port = atoi(tmp);
- tmp = getfield(NULL, ':');
- if (aconf->status & CONF_ME) {
- if (!tmp) {
- Debug((DEBUG_FATAL, "Your M: line must have the Numeric, "
- "assigned to you by routing-com, behind the port number!\n"));
- ircd_log(L_WARNING, "Your M: line must have the Numeric, "
- "assigned to you by routing-com, behind the port number!\n");
- exit(-1);
- }
- SetYXXServerName(&me, atoi(tmp)); /* Our Numeric Nick */
- }
- else if (tmp)
- aconf->confClass = find_class(atoi(tmp));
- break;
- }
- /*
- * If conf line is a class definition, create a class entry
- * for it and make the conf_line illegal and delete it.
- */
- if (aconf->status & CONF_CLASS) {
- add_class(atoi(aconf->host), atoi(aconf->passwd),
- atoi(aconf->name), aconf->port, tmp ? atoi(tmp) : 0);
- continue;
- }
+ if (!EmptyString(field_vector[1]))
+ DupString(aconf->host, field_vector[1]);
+
+ if (!EmptyString(field_vector[2]))
+ DupString(aconf->passwd, field_vector[2]);
+
+ if (field_count > 3 && !EmptyString(field_vector[3]))
+ DupString(aconf->name, field_vector[3]);
+
+ if (field_count > 4 && !EmptyString(field_vector[4]))
+ aconf->port = atoi(field_vector[4]);
+
+ if (field_count > 5 && !EmptyString(field_vector[5]))
+ aconf->conn_class = find_class(atoi(field_vector[5]));
+
/*
* Associate each conf line with a class by using a pointer
* to the correct class record. -avalon
*/
if (aconf->status & CONF_CLIENT_MASK) {
- if (aconf->confClass == 0)
- aconf->confClass = find_class(0);
+ if (aconf->conn_class == 0)
+ aconf->conn_class = find_class(0);
}
- if (aconf->status & CONF_LISTEN_PORT) {
- int is_server = 0;
- int is_hidden = 0;
- if (!EmptyString(aconf->name)) {
- const char* x = aconf->name;
- if ('S' == ToUpper(*x))
- is_server = 1;
- ++x;
- if ('H' == ToUpper(*x))
- is_hidden = 1;
- }
- add_listener(aconf->port, aconf->passwd, aconf->host,
- is_server, is_hidden);
- continue;
- }
if (aconf->status & CONF_CLIENT) {
struct ConfItem *bconf;
aconf->passwd = 0;
ConfLinks(bconf) -= bconf->clients;
- bconf->confClass = aconf->confClass;
- if (bconf->confClass)
+ bconf->conn_class = aconf->conn_class;
+ if (bconf->conn_class)
ConfLinks(bconf) += bconf->clients;
}
free_conf(aconf);
len += strlen(aconf->host);
newhost = (char*) MyMalloc(len);
assert(0 != newhost);
- sprintf_irc(newhost, "*@%s", aconf->host);
+ ircd_snprintf(0, newhost, len, "*@%s", aconf->host);
MyFree(aconf->host);
aconf->host = newhost;
}
continue;
lookup_confhost(aconf);
}
-
- /* Create expression tree from connect rule...
- * If there's a parsing error, nuke the conf structure */
- if (aconf->status & (CONF_CRULEALL | CONF_CRULEAUTO)) {
- MyFree(aconf->passwd);
- if ((aconf->passwd = (char *)crule_parse(aconf->name)) == NULL) {
- free_conf(aconf);
- aconf = NULL;
- continue;
- }
- }
-
- /*
- * Own port and name cannot be changed after the startup.
- * (or could be allowed, but only if all links are closed first).
- * Configuration info does not override the name and port
- * if previously defined. Note, that "info"-field can be
- * changed by "/rehash".
- */
- if (aconf->status == CONF_ME) {
- ircd_strncpy(me.info, aconf->name, REALLEN);
- }
-
/*
* Juped nicks are listed in the 'password' field of U:lines,
* the list is comma separated and might be empty and/or contain
if ((aconf->status == CONF_UWORLD) && (aconf->passwd) && (*aconf->passwd))
addNickJupes(aconf->passwd);
- if (aconf->status & CONF_ADMIN) {
- if (!aconf->host || !aconf->passwd || !aconf->name) {
- Debug((DEBUG_FATAL, "Your A: line must have 4 fields!\n"));
- ircd_log(L_WARNING, "Your A: line must have 4 fields!\n");
- exit(-1);
- }
- }
collapse(aconf->host);
collapse(aconf->name);
Debug((DEBUG_NOTICE,
"Read Init: (%d) (%s) (%s) (%s) (%u) (%p)",
aconf->status, aconf->host, aconf->passwd,
- aconf->name, aconf->port, aconf->confClass));
+ aconf->name, aconf->port, aconf->conn_class));
aconf->next = GlobalConfList;
GlobalConfList = aconf;
aconf = NULL;
if (aconf)
free_conf(aconf);
fbclose(file);
- check_class();
nextping = nextconnect = CurrentTime;
return 1;
}
+/*
+ * rehash
+ *
+ * Actual REHASH service routine. Called with sig == 0 if it has been called
+ * as a result of an operator issuing this command, else assume it has been
+ * called as a result of the server receiving a HUP signal.
+ */
+int rehash(struct Client *cptr, int sig)
+{
+ struct ConfItem** tmp = &GlobalConfList;
+ struct ConfItem* tmp2;
+ struct Client* acptr;
+ struct MotdItem* temp;
+ int i;
+ int ret = 0;
+ int found_g = 0;
+
+ if (1 == sig)
+ sendto_opmask_butone(0, SNO_OLDSNO,
+ "Got signal SIGHUP, reloading ircd conf. file");
+
+ while ((tmp2 = *tmp)) {
+ if (tmp2->clients) {
+ /*
+ * Configuration entry is still in use by some
+ * local clients, cannot delete it--mark it so
+ * that it will be deleted when the last client
+ * exits...
+ */
+ if (CONF_CLIENT == (tmp2->status & CONF_CLIENT))
+ tmp = &tmp2->next;
+ else {
+ *tmp = tmp2->next;
+ tmp2->next = 0;
+ }
+ tmp2->status |= CONF_ILLEGAL;
+ }
+ else {
+ *tmp = tmp2->next;
+ free_conf(tmp2);
+ }
+ }
+ conf_erase_motd_list(&motdConfList);
+ conf_erase_crule_list();
+ conf_erase_deny_list();
+
+ /*
+ * delete the juped nicks list
+ */
+ clearNickJupes();
+
+ if (sig != 2)
+ flush_resolver_cache();
+
+ class_mark_delete();
+ mark_listeners_closing();
+
+ read_configuration_file();
+
+ close_listeners();
+ class_delete_marked(); /* unless it fails */
+
+ /*
+ * Flush out deleted I and P lines although still in use.
+ */
+ for (tmp = &GlobalConfList; (tmp2 = *tmp);) {
+ if (CONF_ILLEGAL == (tmp2->status & CONF_ILLEGAL)) {
+ *tmp = tmp2->next;
+ tmp2->next = NULL;
+ if (!tmp2->clients)
+ free_conf(tmp2);
+ }
+ else
+ tmp = &tmp2->next;
+ }
+ for (i = 0; i <= HighestFd; i++) {
+ if ((acptr = LocalClientArray[i])) {
+ assert(!IsMe(acptr));
+ if (IsServer(acptr)) {
+ det_confs_butmask(acptr,
+ ~(CONF_HUB | CONF_LEAF | CONF_UWORLD | CONF_ILLEGAL));
+ attach_confs_byname(acptr, acptr->name,
+ CONF_HUB | CONF_LEAF | CONF_UWORLD);
+ }
+ /* Because admin's are getting so uppity about people managing to
+ * get past K/G's etc, we'll "fix" the bug by actually explaining
+ * whats going on.
+ */
+ if ((found_g = find_kill(acptr))) {
+ sendto_opmask_butone(0, found_g == -2 ? SNO_GLINE : SNO_OPERKILL,
+ found_g == -2 ? "G-line active for %s%s" :
+ "K-line active for %s%s",
+ IsUnknown(acptr) ? "Unregistered Client ":"",
+ get_client_name(acptr, HIDE_IP));
+ if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" :
+ "K-lined") == CPTR_KILLED)
+ ret = CPTR_KILLED;
+ }
+ }
+ }
+ /*
+ * free old motd structs
+ */
+ while (motd) {
+ temp = motd->next;
+ MyFree(motd);
+ motd = temp;
+ }
+ while (rmotd) {
+ temp = rmotd->next;
+ MyFree(rmotd);
+ rmotd = temp;
+ }
+ /* reload motd files */
+ read_tlines();
+ rmotd = read_motd(RPATH);
+ motd = read_motd(MPATH);
+ return ret;
+}
+
+/*
+ * init_conf
+ *
+ * Read configuration file.
+ *
+ * returns 0, if file cannot be opened
+ * 1, if file read
+ */
+
+int init_conf(void)
+{
+ if (read_configuration_file()) {
+ /*
+ * make sure we're sane to start if the config
+ * file read didn't get everything we need.
+ * XXX - should any of these abort the server?
+ * TODO: add warning messages
+ */
+ if (0 == localConf.name || 0 == localConf.numeric)
+ return 0;
+
+ if (0 == localConf.location1)
+ DupString(localConf.location1, "");
+ if (0 == localConf.location2)
+ DupString(localConf.location2, "");
+ if (0 == localConf.contact)
+ DupString(localConf.contact, "");
+
+ return 1;
+ }
+ return 0;
+}
+
+
/* read_tlines
* Read info from T:lines into TRecords which include the file
* timestamp, the hostmask, and the contents of the motd file
*/
void read_tlines()
{
- struct ConfItem *tmp;
+ struct MotdConf* conf;
struct TRecord *temp;
struct TRecord *last = NULL; /* Init. to avoid compiler warning */
struct MotdItem *amotd;
/* Free the old trecords and the associated motd contents first */
- while (tdata)
- {
+ while (tdata) {
last = tdata->next;
- while (tdata->tmotd)
- {
+ while (tdata->tmotd) {
amotd = tdata->tmotd->next;
MyFree(tdata->tmotd);
tdata->tmotd = amotd;
tdata = last;
}
- for (tmp = GlobalConfList; tmp; tmp = tmp->next) {
- if (tmp->status == CONF_TLINES && tmp->host && tmp->passwd) {
- temp = (struct TRecord*) MyMalloc(sizeof(struct TRecord));
- assert(0 != temp);
-
- temp->hostmask = tmp->host;
- temp->tmotd = read_motd(tmp->passwd);
- temp->tmotd_tm = motd_tm;
- temp->next = NULL;
- if (!tdata)
- tdata = temp;
- else
- last->next = temp;
- last = temp;
- }
+ for (conf = motdConfList; conf; conf = conf->next) {
+ temp = (struct TRecord*) MyMalloc(sizeof(struct TRecord));
+ assert(0 != temp);
+
+ temp->hostmask = conf->hostmask;
+ temp->tmotd = read_motd(conf->path);
+ temp->tmotd_tm = motd_tm;
+ temp->next = 0;
+
+ if (!tdata)
+ tdata = temp;
+ else
+ last->next = temp;
+ last = temp;
}
}
+/*
+ * find_kill
+ * input:
+ * client pointer
+ * returns:
+ * 0: Client may continue to try and connect
+ * -1: Client was K/k:'d - sideeffect: reason was sent.
+ * -2: Client was G/g:'d - sideeffect: reason was sent.
+ * sideeffects:
+ * Client may have been sent a reason why they are denied, as above.
+ */
int find_kill(struct Client *cptr)
{
- char reply[256];
const char* host;
const char* name;
- struct ConfItem* tmp;
+ struct DenyConf* deny;
struct Gline* agline = NULL;
assert(0 != cptr);
host = cptr->sockhost;
name = cptr->user->username;
-#if 0
- /*
- * whee :)
- * XXX - if this ever happens, we're already screwed
+ assert(strlen(host) <= HOSTLEN);
+ assert((name ? strlen(name) : 0) <= HOSTLEN);
+
+ /* 2000-07-14: Rewrote this loop for massive speed increases.
+ * -- Isomer
*/
- if (strlen(host) > HOSTLEN ||
- (name ? strlen(name) : 0) > HOSTLEN)
- return (0);
-#endif
-
- reply[0] = '\0';
-
- for (tmp = GlobalConfList; tmp; tmp = tmp->next) {
- /* Added a check against the user's IP address as well.
- * If the line is either CONF_KILL or CONF_IPKILL, check it; if and only
- * if it's CONF_IPKILL, check the IP address as well (the && below will
- * short circuit and the match won't even get run) -Kev
- */
- if ((tmp->status & CONF_KLINE) && tmp->host && tmp->name &&
- (match(tmp->host, host) == 0 ||
- ((tmp->status == CONF_IPKILL) &&
- match(tmp->host, ircd_ntoa((const char*) &cptr->ip)) == 0)) &&
- (!name || match(tmp->name, name) == 0) &&
- (!tmp->port || (tmp->port == cptr->listener->port)))
- {
- /*
- * Can short-circuit evaluation - not taking chances
- * because check_time_interval destroys tmp->passwd
- * - Mmmm
- */
- if (EmptyString(tmp->passwd))
- break;
- else if (is_comment(tmp->passwd))
- break;
- else if (check_time_interval(tmp->passwd, reply))
+ for (deny = denyConfList; deny; deny = deny->next) {
+ if (0 != match(deny->usermask, name))
+ continue;
+
+ if (EmptyString(deny->hostmask))
+ break;
+
+ if (deny->ip_kill) { /* k: by IP */
+ Debug((DEBUG_DEBUG, "ip: %08x network: %08x/%i mask: %08x",
+ cptr->ip.s_addr, deny->s_addr, deny->bits, NETMASK(deny->bits)));
+ if ((cptr->ip.s_addr & NETMASK(deny->bits)) == deny->s_addr)
break;
}
+ else if (0 == match(deny->hostmask, host))
+ break;
}
- if (reply[0])
- sendto_one(cptr, reply, me.name, ERR_YOUREBANNEDCREEP, cptr->name);
- else if (tmp) {
- if (EmptyString(tmp->passwd))
- sendto_one(cptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, cptr->name);
+ if (deny) {
+ if (EmptyString(deny->message))
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
else {
- if (*tmp->passwd == '"') {
- char *sbuf =
- sprintf_irc(sendbuf, ":%s %d %s :%s", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, &tmp->passwd[1]);
- sbuf[-1] = '.'; /* Overwrite last quote with a dot */
- sendbufto_one(cptr);
- }
- else if (*tmp->passwd == '!')
- killcomment(cptr, cptr->name, &tmp->passwd[1]);
+ if (deny->is_file)
+ killcomment(cptr, deny->message);
else
-#ifdef COMMENT_IS_FILE
- killcomment(cptr, cptr->name, tmp->passwd);
-#else
- sendto_one(cptr, ":%s %d %s :%s.", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, tmp->passwd);
-#endif
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", deny->message);
}
}
-
- /* find active glines */
- /* added a check against the user's IP address to find_gline() -Kev */
- else if ((agline = gline_find(cptr, 0)) && GlineIsActive(agline))
- sendto_one(cptr, ":%s %d %s :%s.", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, GlineReason(agline));
+ else if ((agline = gline_lookup(cptr, 0)) && GlineIsActive(agline)) {
+ /*
+ * find active glines
+ * added a check against the user's IP address to find_gline() -Kev
+ */
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.", GlineReason(agline));
+ }
else
- agline = NULL; /* if a gline was found, it was inactive */
+ agline = 0; /* if a gline was found, it was inactive */
- return (tmp ? -1 : (agline ? -2 : 0));
+ if (deny)
+ return -1;
+ if (agline)
+ return -2;
+
+ return 0;
}
struct MotdItem* read_motd(const char* motdfile)
*/
enum AuthorizationCheckResult conf_check_client(struct Client *cptr)
{
- int acr;
+ enum AuthorizationCheckResult acr = ACR_OK;
ClearAccess(cptr);
if (IsConnecting(cptr) || IsHandshake(cptr)) {
c_conf = find_conf_byname(lp, cptr->name, CONF_SERVER);
if (!c_conf) {
- sendto_ops("Connect Error: lost C:line for %s", cptr->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connect Error: lost C:line for %s",
+ cptr->name);
det_confs_butmask(cptr, 0);
return -1;
}