+2000-09-16 Thomas Helvey <helveytw@home.com>
+ * ircd/s_conf.c: add code for new crule data structs, strip quotes
+ * ircd/crule.c: clean up scary casting a bit, type safety stuff
+ * include/s_conf.h: add CRuleConf struct and support, remove
+ unused constants
+ * include/crule.h: type safety cleanups
+ * ircd/*.c: fixup code that depended on stuff I changed
+
2000-09-15 Thomas Helvey <helveytw@home.com>
* ircd/s_conf.c: start adding code for new conf data structs, changed
listeners, admin line, motd lines, class lines. Move validate_hostent
#
# ChangeLog for ircu2.10.11
#
-# $Id: ChangeLog,v 1.162 2000-09-15 07:27:08 bleep Exp $
+# $Id: ChangeLog,v 1.163 2000-09-16 05:35:01 bleep Exp $
#
# Insert new changes at beginning of the change list.
#
* Proto types
*/
-extern void crule_free(char **elem);
-extern int crule_eval(char *rule);
-extern char *crule_parse(char *rule);
+/*
+ * opaque node pointer
+ */
+struct CRuleNode;
+
+extern void crule_free(struct CRuleNode** elem);
+extern int crule_eval(struct CRuleNode* rule);
+extern struct CRuleNode* crule_parse(const char* rule);
#endif /* INCLUDED_crule_h */
#define CONF_OPERATOR 0x0020
#define CONF_ME 0x0040
#define CONF_KILL 0x0080
-#define CONF_ADMIN 0x0100
-#define CONF_CLASS 0x0400
#define CONF_LEAF 0x1000
-#define CONF_LISTEN_PORT 0x2000
#define CONF_HUB 0x4000
#define CONF_UWORLD 0x8000
-#define CONF_CRULEALL 0x00200000
-#define CONF_CRULEAUTO 0x00400000
-#define CONF_TLINES 0x00800000
#define CONF_IPKILL 0x00010000
#define CONF_OPS (CONF_OPERATOR | CONF_LOCOP)
#define CONF_CLIENT_MASK (CONF_CLIENT | CONF_OPS | CONF_SERVER)
-#define CONF_CRULE (CONF_CRULEALL | CONF_CRULEAUTO)
#define CONF_KLINE (CONF_KILL | CONF_IPKILL)
#define IsIllegal(x) ((x)->status & CONF_ILLEGAL)
char* path;
struct MotdConf* next;
};
-
+
+enum {
+ CRULE_AUTO = 1,
+ CRULE_ALL = 2,
+ CRULE_MASK = 3
+};
+
+struct CRuleNode;
+
+struct CRuleConf {
+ char* hostmask;
+ char* rule;
+ int type;
+ struct CRuleNode* node;
+ struct CRuleConf* next;
+};
+
struct TRecord {
char *hostmask;
struct MotdItem *tmotd;
*/
extern const struct LocalConf* conf_get_local(void);
-extern const struct MotdConf* conf_get_motd_list(void);
+extern const struct MotdConf* conf_get_motd_list(void);
+extern const struct CRuleConf* conf_get_crule_list(void);
+
+extern const char* conf_crule_eval(const char* host, int mask);
extern struct ConfItem* attach_confs_byhost(struct Client* cptr,
const char* host, int statmask);
extern struct ConfItem* find_conf_byname(struct SLink* lp, const char *name,
int statmask);
extern struct ConfItem* conf_find_server(const char* name);
-const char* conf_eval_crule(struct ConfItem* conf);
+const char* conf_eval_crule(const char* name, int mask);
extern void det_confs_butmask(struct Client *cptr, int mask);
extern int detach_conf(struct Client *cptr, struct ConfItem *aconf);
extern void report_stats(struct Client *sptr, char stat);
extern void report_configured_links(struct Client *sptr, int mask);
extern int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat);
+extern void report_crule_list(struct Client* to, int mask);
+extern void report_motd_list(struct Client* to);
#endif /* INCLUDED_s_stats_h */
#include <sys/stat.h>
#include <unistd.h>
+/*
+ * stuff that isn't used by s_conf.c anymore
+ */
+#define CONF_ADMIN 0x0100
+#define CONF_CLASS 0x0400
+#define CONF_LISTEN_PORT 0x2000
+#define CONF_CRULEALL 0x00200000
+#define CONF_CRULEAUTO 0x00400000
+#define CONF_TLINES 0x00800000
+
+
+#define CONF_CRULE (CONF_CRULEALL | CONF_CRULEAUTO)
+
/*
* For the connect rule patch.. these really should be in a header,
* but i see h.h isn't included for some reason.. so they're here.
*/
-char *crule_parse(char *rule);
-void crule_free(char **elem);
+struct CRuleNode;
+
+struct CRuleNode* crule_parse(const char* rule);
+void crule_free(struct CRuleNode** elem);
static void new_class(int cn);
static char confchar(unsigned int status);
static struct ConfItem *chk_initconf(void)
{
FBFILE *file;
- char line[512], *tmp, *crule;
+ char line[512];
+ char *tmp;
+ struct CRuleNode* crule;
int ccount = 0, flags = 0;
struct ConfItem *aconf = NULL, *ctop = NULL;
* any allocated storage immediately -- we're just looking
* for errors.. */
if (aconf->status & CONF_CRULE)
- if ((crule = (char *)crule_parse(aconf->name)) != NULL)
+ if ((crule = crule_parse(aconf->name)) != NULL)
crule_free(&crule);
if (!aconf->confClass)
*/
typedef int (*crule_funcptr) (int, void **);
-struct crule_treestruct {
+struct CRuleNode {
crule_funcptr funcptr;
int numargs;
void *arg[CR_MAXARGS]; /* For operators arg points to a tree element;
for functions arg points to a char string. */
};
-typedef struct crule_treestruct crule_treeelem;
-typedef crule_treeelem *crule_treeptr;
+typedef struct CRuleNode* CRuleNodePtr;
/* local rule function prototypes */
static int crule_connected(int, void **);
static int crule__not(int, void **);
/* local parsing function prototypes */
-static int crule_gettoken(int *, char **);
-static void crule_getword(char *, int *, size_t, char **);
-static int crule_parseandexpr(crule_treeptr *, int *, char **);
-static int crule_parseorexpr(crule_treeptr *, int *, char **);
-static int crule_parseprimary(crule_treeptr *, int *, char **);
-static int crule_parsefunction(crule_treeptr *, int *, char **);
-static int crule_parsearglist(crule_treeptr, int *, char **);
+static int crule_gettoken(int* token, const char** str);
+static void crule_getword(char*, int*, size_t, const char**);
+static int crule_parseandexpr(CRuleNodePtr*, int *, const char**);
+static int crule_parseorexpr(CRuleNodePtr*, int *, const char**);
+static int crule_parseprimary(CRuleNodePtr*, int *, const char**);
+static int crule_parsefunction(CRuleNodePtr*, int *, const char**);
+static int crule_parsearglist(CRuleNodePtr, int *, const char**);
#if defined(CR_DEBUG) || defined(CR_CHKCONF)
/*
* Prototypes for the test parser; if not debugging,
* these are defined in h.h
*/
-char *crule_parse(char *);
-void crule_free(char **);
+struct CRuleNode* crule_parse(const char*);
+void crule_free(struct CRuleNode**);
#ifdef CR_DEBUG
-void print_tree(crule_treeptr);
+void print_tree(CRuleNodePtr);
#endif
#endif
{
int result1;
- result1 = ((crule_treeptr) crulearg[0])->funcptr
- (((crule_treeptr) crulearg[0])->numargs,
- ((crule_treeptr) crulearg[0])->arg);
+ result1 = ((CRuleNodePtr) crulearg[0])->funcptr
+ (((CRuleNodePtr) crulearg[0])->numargs,
+ ((CRuleNodePtr) crulearg[0])->arg);
if (crulearg[2]) /* or */
return (result1 ||
- ((crule_treeptr) crulearg[1])->funcptr
- (((crule_treeptr) crulearg[1])->numargs,
- ((crule_treeptr) crulearg[1])->arg));
+ ((CRuleNodePtr) crulearg[1])->funcptr
+ (((CRuleNodePtr) crulearg[1])->numargs,
+ ((CRuleNodePtr) crulearg[1])->arg));
else
return (result1 &&
- ((crule_treeptr) crulearg[1])->funcptr
- (((crule_treeptr) crulearg[1])->numargs,
- ((crule_treeptr) crulearg[1])->arg));
+ ((CRuleNodePtr) crulearg[1])->funcptr
+ (((CRuleNodePtr) crulearg[1])->numargs,
+ ((CRuleNodePtr) crulearg[1])->arg));
}
static int crule__not(int numargs, void *crulearg[])
{
- return (!((crule_treeptr) crulearg[0])->funcptr
- (((crule_treeptr) crulearg[0])->numargs,
- ((crule_treeptr) crulearg[0])->arg));
+ return (!((CRuleNodePtr) crulearg[0])->funcptr
+ (((CRuleNodePtr) crulearg[0])->numargs,
+ ((CRuleNodePtr) crulearg[0])->arg));
}
#if !defined(CR_DEBUG) && !defined(CR_CHKCONF)
-int crule_eval(char *rule)
+int crule_eval(struct CRuleNode* rule)
{
- return (((crule_treeptr) rule)->funcptr
- (((crule_treeptr) rule)->numargs, ((crule_treeptr) rule)->arg));
+ return (rule->funcptr(rule->numargs, rule->arg));
}
#endif
-static int crule_gettoken(int *next_tokp, char **ruleptr)
+static int crule_gettoken(int* next_tokp, const char** ruleptr)
{
char pending = '\0';
return CR_NOERR;
}
-static void crule_getword(char *word, int *wordlenp, size_t maxlen,
- char **ruleptr)
+static void crule_getword(char* word, int* wordlenp, size_t maxlen, const char** ruleptr)
{
char *word_ptr;
* word
* word , arglist
*/
-char *crule_parse(char *rule)
+struct CRuleNode* crule_parse(const char *rule)
{
- char *ruleptr = rule;
+ const char* ruleptr = rule;
int next_tok;
- crule_treeptr ruleroot = NULL;
+ struct CRuleNode* ruleroot = 0;
int errcode = CR_NOERR;
- if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR)
- {
- if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr))
- == CR_NOERR)
- {
- if (ruleroot != NULL)
- {
+ if ((errcode = crule_gettoken(&next_tok, &ruleptr)) == CR_NOERR) {
+ if ((errcode = crule_parseorexpr(&ruleroot, &next_tok, &ruleptr)) == CR_NOERR) {
+ if (ruleroot != NULL) {
if (next_tok == CR_END)
- return ((char *)ruleroot);
+ return (ruleroot);
else
errcode = CR_UNEXPCTTOK;
}
}
}
if (ruleroot != NULL)
- crule_free((char **)&ruleroot);
+ crule_free(&ruleroot);
#if !defined(CR_DEBUG) && !defined(CR_CHKCONF)
Debug((DEBUG_ERROR, "%s in rule: %s", crule_errstr[errcode], rule));
#else
fprintf(stderr, "%s in rule: %s\n", crule_errstr[errcode], rule);
#endif
- return NULL;
+ return 0;
}
-static int crule_parseorexpr(crule_treeptr * orrootp, int *next_tokp,
- char **ruleptr)
+static int crule_parseorexpr(CRuleNodePtr * orrootp, int *next_tokp, const char** ruleptr)
{
int errcode = CR_NOERR;
- crule_treeptr andexpr;
- crule_treeptr orptr;
+ CRuleNodePtr andexpr;
+ CRuleNodePtr orptr;
*orrootp = NULL;
while (errcode == CR_NOERR)
errcode = crule_parseandexpr(&andexpr, next_tokp, ruleptr);
if ((errcode == CR_NOERR) && (*next_tokp == CR_OR))
{
- orptr = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+ orptr = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
#ifdef CR_DEBUG
fprintf(stderr, "allocating or element at %ld\n", orptr);
#endif
return (errcode);
}
-static int crule_parseandexpr(crule_treeptr * androotp, int *next_tokp,
- char **ruleptr)
+static int crule_parseandexpr(CRuleNodePtr * androotp, int *next_tokp, const char** ruleptr)
{
int errcode = CR_NOERR;
- crule_treeptr primary;
- crule_treeptr andptr;
+ CRuleNodePtr primary;
+ CRuleNodePtr andptr;
*androotp = NULL;
while (errcode == CR_NOERR)
errcode = crule_parseprimary(&primary, next_tokp, ruleptr);
if ((errcode == CR_NOERR) && (*next_tokp == CR_AND))
{
- andptr = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+ andptr = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
#ifdef CR_DEBUG
fprintf(stderr, "allocating and element at %ld\n", andptr);
#endif
return (errcode);
}
-static int crule_parseprimary(crule_treeptr * primrootp,
- int *next_tokp, char **ruleptr)
+static int crule_parseprimary(CRuleNodePtr* primrootp, int *next_tokp, const char** ruleptr)
{
- crule_treeptr *insertionp;
+ CRuleNodePtr *insertionp;
int errcode = CR_NOERR;
*primrootp = NULL;
case CR_OPENPAREN:
if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
break;
- if ((errcode = crule_parseorexpr(insertionp, next_tokp,
- ruleptr)) != CR_NOERR)
+ if ((errcode = crule_parseorexpr(insertionp, next_tokp, ruleptr)) != CR_NOERR)
break;
if (*insertionp == NULL)
{
errcode = crule_gettoken(next_tokp, ruleptr);
break;
case CR_NOT:
- *insertionp = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+ *insertionp = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
#ifdef CR_DEBUG
fprintf(stderr, "allocating primary element at %ld\n", *insertionp);
#endif
(*insertionp)->funcptr = crule__not;
(*insertionp)->numargs = 1;
(*insertionp)->arg[0] = NULL;
- insertionp = (crule_treeptr *) & ((*insertionp)->arg[0]);
+ insertionp = (CRuleNodePtr *) & ((*insertionp)->arg[0]);
if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
break;
continue;
return (errcode);
}
-static int crule_parsefunction(crule_treeptr * funcrootp,
- int *next_tokp, char **ruleptr)
+static int crule_parsefunction(CRuleNodePtr* funcrootp, int* next_tokp, const char** ruleptr)
{
int errcode = CR_NOERR;
char funcname[CR_MAXARGLEN];
}
if ((errcode = crule_gettoken(next_tokp, ruleptr)) != CR_NOERR)
return (errcode);
- *funcrootp = (crule_treeptr) MyMalloc(sizeof(crule_treeelem));
+ *funcrootp = (CRuleNodePtr) MyMalloc(sizeof(struct CRuleNode));
#ifdef CR_DEBUG
fprintf(stderr, "allocating function element at %ld\n", *funcrootp);
#endif
return (CR_EXPCTOPEN);
}
-static int crule_parsearglist(crule_treeptr argrootp, int *next_tokp,
- char **ruleptr)
+static int crule_parsearglist(CRuleNodePtr argrootp, int *next_tokp, const char** ruleptr)
{
int errcode = CR_NOERR;
char *argelemp = NULL;
* DO NOT CALL THIS FUNTION WITH A POINTER TO A NULL POINTER
* (ie: If *elem is NULL, you're doing it wrong - seg fault)
*/
-void crule_free(char **elem)
+void crule_free(struct CRuleNode** elem)
{
int arg, numargs;
- if ((*((crule_treeptr *) elem))->funcptr == crule__not)
+ if ((*(elem))->funcptr == crule__not)
{
/* type conversions and ()'s are fun! ;) here have an asprin.. */
- if ((*((crule_treeptr *) elem))->arg[0] != NULL)
- crule_free((char **)&((*((crule_treeptr *) elem))->arg[0]));
+ if ((*(elem))->arg[0] != NULL)
+ crule_free((struct CRuleNode**) &((*(elem))->arg[0]));
}
- else if ((*((crule_treeptr *) elem))->funcptr == crule__andor)
+ else if ((*(elem))->funcptr == crule__andor)
{
- crule_free((char **)&((*((crule_treeptr *) elem))->arg[0]));
- if ((*((crule_treeptr *) elem))->arg[1] != NULL)
- crule_free((char **)&((*((crule_treeptr *) elem))->arg[1]));
+ crule_free((struct CRuleNode**) &((*(elem))->arg[0]));
+ if ((*(elem))->arg[1] != NULL)
+ crule_free((struct CRuleNode**) &((*(elem))->arg[1]));
}
else
{
- numargs = (*((crule_treeptr *) elem))->numargs;
+ numargs = (*(elem))->numargs;
for (arg = 0; arg < numargs; arg++)
- MyFree((*((crule_treeptr *) elem))->arg[arg]);
+ MyFree((*(elem))->arg[arg]);
}
#ifdef CR_DEBUG
fprintf(stderr, "freeing element at %ld\n", *elem);
#endif
MyFree(*elem);
- *elem = NULL;
+ *elem = 0;
}
#ifdef CR_DEBUG
-static void print_tree(crule_treeptr printelem)
+static void print_tree(CRuleNodePtr printelem)
{
int funcnum, arg;
if (printelem->funcptr == crule__not)
{
printf("!( ");
- print_tree((crule_treeptr) printelem->arg[0]);
+ print_tree((CRuleNodePtr) printelem->arg[0]);
printf(") ");
}
else if (printelem->funcptr == crule__andor)
{
printf("( ");
- print_tree((crule_treeptr) printelem->arg[0]);
+ print_tree((CRuleNodePtr) printelem->arg[0]);
if (printelem->arg[2])
printf("|| ");
else
printf("&& ");
- print_tree((crule_treeptr) printelem->arg[1]);
+ print_tree((CRuleNodePtr) printelem->arg[1]);
printf(") ");
}
else
int main(void)
{
char indata[256];
- char *rule;
+ CRuleNode* rule;
printf("rule: ");
while (fgets(indata, 256, stdin) != NULL)
if ((rule = crule_parse(indata)) != NULL)
{
printf("equivalent rule: ");
- print_tree((crule_treeptr) rule);
+ print_tree((CRuleNodePtr) rule);
printf("\n");
crule_free(&rule);
}
* is called earlier or later...)
*--------------------------------------------------------------------------*/
static time_t try_connections(void) {
- struct ConfItem *aconf;
- struct Client *cptr;
- struct ConfItem **pconf;
- int connecting;
- int confrq;
- time_t next = 0;
- struct ConfClass *cltmp;
- struct ConfItem *cconf;
- struct ConfItem *con_conf = NULL;
- struct Jupe *ajupe;
- unsigned int con_class = 0;
+ struct ConfItem* aconf;
+ struct Client* cptr;
+ struct ConfItem** pconf;
+ int connecting;
+ int confrq;
+ time_t next = 0;
+ struct ConfClass* cltmp;
+ struct ConfItem* con_conf = 0;
+ struct Jupe* ajupe;
+ unsigned int con_class = 0;
connecting = FALSE;
Debug((DEBUG_NOTICE, "Connection check at : %s", myctime(CurrentTime)));
if (!cptr && (Links(cltmp) < MaxLinks(cltmp)) &&
(!connecting || (ConClass(cltmp) > con_class))) {
- /* Check connect rules to see if we're allowed to try */
- for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
- if ((cconf->status & CONF_CRULE) && !match(cconf->host, aconf->name))
- if (crule_eval(cconf->passwd))
- break;
- }
- if (!cconf) {
+ /*
+ * Check connect rules to see if we're allowed to try
+ */
+ if (0 == conf_eval_crule(aconf->name, CRULE_MASK)) {
con_class = ConClass(cltmp);
con_conf = aconf;
/* We connect only one at time... */
{
unsigned short port;
unsigned short tmpport;
- const char* crule_name;
+ const char* rule;
struct ConfItem* aconf;
struct Client* acptr;
struct Jupe* ajupe;
* are ored together. Oper connects are effected only by D
* lines (CRULEALL) not d lines (CRULEAUTO).
*/
- if ((crule_name = conf_eval_crule(aconf))) {
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s",
- sptr, crule_name);
+ if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
return 0;
}
/*
{
unsigned short port;
unsigned short tmpport;
- const char* crule_name;
+ const char* rule;
struct ConfItem* aconf;
struct Client* acptr;
struct Jupe* ajupe;
* are ored together. Oper connects are effected only by D
* lines (CRULEALL) not d lines (CRULEAUTO).
*/
- if ((crule_name = conf_eval_crule(aconf))) {
- sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s",
- sptr, crule_name);
+ if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+ sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule);
return 0;
}
/*
struct ConfItem* cconf;
struct Client* acptr;
struct Jupe* ajupe;
+ const char* rule;
if (!IsPrivileged(sptr)) {
sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); /* XXX DEAD */
* are ored together. Oper connects are effected only by D
* lines (CRULEALL) not d lines (CRULEAUTO).
*/
- for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
- if ((CONF_CRULEALL == cconf->status) &&
- (0 == match(cconf->host, aconf->name))) {
- if (crule_eval(cconf->passwd)) {
- if (MyUser(sptr))
- sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", /* XXX DEAD */
- me.name, parv[0], cconf->name);
- else
- sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", /* XXX DEAD */
- NumServ(&me), NumNick(sptr), cconf->name);
- return 0;
- }
- }
+ if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) {
+ if (MyUser(sptr))
+ sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", /* XXX DEAD */
+ me.name, parv[0], cconf->name);
+ else
+ sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", /* XXX DEAD */
+ NumServ(&me), NumNick(sptr), cconf->name);
+ return 0;
}
/*
* Check to see if the server is juped; if it is, disallow the connect
#include "handlers.h"
#endif /* 0 */
#include "client.h"
-#include "crule.h"
#include "hash.h"
#include "ircd.h"
#include "ircd_log.h"
struct Client* bcptr;
struct Client* LHcptr = 0;
struct ConfItem* aconf = 0;
- struct ConfItem* cconf;
struct ConfItem* lhconf = 0;
struct Jupe* ajupe = 0;
int hop;
cptr->hopcount = hop;
/* check connection rules */
- for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
- if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
- if (crule_eval(cconf->passwd)) {
- ServerStats->is_ref++;
- sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.",
- cptr->name);
- return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
- }
- }
+ if (0 != conf_eval_crule(host, CRULE_ALL)) {
+ ServerStats->is_ref++;
+ sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+ return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
}
+
if (conf_check_server(cptr)) {
++ServerStats->is_ref;
sendto_opmask_butone(0, SNO_OLDSNO, "Received unauthorized connection "
struct Client* bcptr;
struct Client* LHcptr = 0;
struct ConfItem* aconf = 0;
- struct ConfItem* cconf;
struct ConfItem* lhconf = 0;
struct Jupe* ajupe = 0;
int hop;
cptr->hopcount = hop;
/* check connection rules */
- for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
- if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
- if (crule_eval(cconf->passwd))
- {
- ServerStats->is_ref++;
- sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.",
- cptr->name);
- return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
- }
- }
+ if (0 != conf_eval_crule(host, CRULE_ALL)) {
+ ServerStats->is_ref++;
+ sendto_opmask_butone(0, SNO_OLDSNO, "Refused connection from %s.", cptr->name);
+ return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
}
if (conf_check_server(cptr)) {
++ServerStats->is_ref;
struct Client* bcptr;
struct Client* LHcptr = 0;
struct ConfItem* aconf = 0;
- struct ConfItem* cconf;
struct ConfItem* lhconf = 0;
struct Jupe* ajupe = 0;
int hop;
cptr->hopcount = hop;
/* check connection rules */
- for (cconf = GlobalConfList; cconf; cconf = cconf->next) {
- if ((cconf->status == CONF_CRULEALL) && (match(cconf->host, host) == 0)) {
- if (crule_eval(cconf->passwd))
- {
- ServerStats->is_ref++;
- sendto_ops("Refused connection from %s.", cptr->name); /* XXX DEAD */
- return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
- }
- }
+ if (0 != conf_eval_crule(host, CRULE_ALL)) {
+ ServerStats->is_ref++;
+ sendto_ops("Refused connection from %s.", cptr->name); /* XXX DEAD */
+ return exit_client(cptr, cptr, &me, "Disallowed by connection rule");
}
if (conf_check_server(cptr)) {
++ServerStats->is_ref;
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
#endif
break;
case 'D':
- report_configured_links(sptr, CONF_CRULEALL);
+ report_crule_list(sptr, CRULE_ALL);
break;
case 'd':
- report_configured_links(sptr, CONF_CRULE);
+ report_crule_list(sptr, CRULE_MASK);
break;
case 't':
tstats(sptr, parv[0]);
#include "opercmds.h"
#include "class.h"
#include "client.h"
-#include "crule.h"
#include "ircd.h"
#include "ircd_chattr.h"
#include "ircd_reply.h"
static struct LocalConf localConf;
static struct MotdConf* motdConfList;
+static struct CRuleConf* cruleConfList;
/*
* output the reason for being k lined from a file - Mmmm
* 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;
*list = conf;
}
-void erase_motd_conf_list(struct MotdConf** list)
+void conf_erase_motd_list(struct MotdConf** list)
{
struct MotdConf* p;
struct MotdConf* next;
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;
+}
+
/*
* read_configuration_file
*
quoted = 0;
else
quoted = 1;
- *dest++ = *src++;
+ /*
+ * strip quotes
+ */
+ ++src;
break;
case ':':
if (quoted)
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':
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).
}
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);
}
}
- erase_motd_conf_list(&motdConfList);
+ conf_erase_motd_list(&motdConfList);
+ conf_erase_crule_list();
+
/*
* We don't delete the class table, rather mark all entries
* for deletion. The table is cleaned up by check_class(). - avalon
if (!read_configuration_file()) /* This calls check_class(), */
check_class(); /* unless it fails */
- /*
- * make sure that the server listener is re-added so it doesn't get
- * closed
- */
close_listeners();
/*
#include "IPcheck.h"
#include "channel.h"
#include "client.h"
-#include "crule.h"
#include "gline.h"
#include "hash.h"
#include "ircd.h"
#include "s_stats.h"
#include "class.h"
#include "client.h"
-#include "crule.h"
#include "ircd.h"
#include "ircd_chattr.h"
#include "ircd_reply.h"
{CONF_OPERATOR, RPL_STATSOLINE, 'O'},
{CONF_HUB, RPL_STATSHLINE, 'H'},
{CONF_LOCOP, RPL_STATSOLINE, 'o'},
- {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
- {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
{CONF_UWORLD, RPL_STATSULINE, 'U'},
- {CONF_TLINES, RPL_STATSTLINE, 'T'},
{0, 0}
};
/* Special-case 'k' or 'K' lines as appropriate... -Kev */
if ((tmp->status & CONF_KLINE))
send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
- /*
- * connect rules are classless
- */
- else if ((tmp->status & CONF_CRULE))
- send_reply(sptr, p[1], c, host, name);
else if ((tmp->status & CONF_UWORLD))
send_reply(sptr, p[1], c, host, pass, name, port, get_conf_class(tmp));
else if ((tmp->status & (CONF_SERVER | CONF_HUB)))
send_reply(to, RPL_STATSTLINE, 'T', conf->hostmask, conf->path);
}
+/*
+ * {CONF_CRULEALL, RPL_STATSDLINE, 'D'},
+ * {CONF_CRULEAUTO, RPL_STATSDLINE, 'd'},
+ */
+void report_crule_list(struct Client* to, int mask)
+{
+ const struct CRuleConf* p = conf_get_crule_list();
+ for ( ; p; p = p->next) {
+ if (0 != (p->type & mask))
+ send_reply(to, RPL_STATSDLINE, (CRULE_ALL == p->type) ? 'D' : 'd', p->hostmask, p->rule);
+ }
+}
+
/* m_stats is so obnoxiously full of special cases that the different
* hunt_server() possiblites were becoming very messy. It now uses a
* switch() so as to be easier to read and update as params change.
case 'P':
{
if (parc > 3)
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc,
- parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s %C :%s", 2, parc, parv);
else
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc,
- parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 0, "%s :%C", 2, parc, parv);
}
/* oper only, varying # of params */
case 'M':
{
if (parc == 4)
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc,
- parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C :%s", 2, parc, parv);
else if (parc > 4)
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2,
- parc, parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s %C %s :%s", 2, parc, parv);
else
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
- parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
}
/* oper only, standard # of params */
default:
- return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc,
- parv);
+ return hunt_server_cmd(sptr, CMD_STATS, cptr, 1, "%s :%C", 2, parc, parv);
}
}