From: Joseph Bongaarts Date: Thu, 13 Apr 2000 22:13:52 +0000 (+0000) Subject: Author: Ghostwolf X-Git-Url: http://git.pk910.de/?p=ircu2.10.12-pk.git;a=commitdiff_plain;h=093e1bca4fe08bda4246f752b76183ef2559497c Author: Ghostwolf Log message: Lots of stuff... Part 1 of the m_stats changes, a slew of bug fixes, cleanups for kev's G:line changes. m_stats still has more changes coming, but I wanted to make things compilable again. Added s_stats.c/h for stats helper functions. The tree compiles now, but probably won't work. There is at least 1 bug in the gline code left. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@164 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- diff --git a/ircd/Makefile.in b/ircd/Makefile.in index 6c12eee..5a29202 100644 --- a/ircd/Makefile.in +++ b/ircd/Makefile.in @@ -161,6 +161,7 @@ SRC = \ s_misc.c \ s_numeric.c \ s_serv.c \ + s_stats.c \ s_user.c \ send.c \ sprintf_irc.c \ @@ -723,7 +724,7 @@ m_stats.o: m_stats.c ../include/channel.h ../config/config.h \ ../include/numnicks.h ../include/opercmds.h ../include/s_bsd.h \ ../include/s_conf.h ../include/s_debug.h ../include/s_misc.h \ ../include/s_serv.h ../include/s_user.h ../include/send.h \ - ../include/userload.h + ../include/userload.h ../include/s_stats.h m_time.o: m_time.c ../include/client.h ../include/dbuf.h \ ../include/ircd_defs.h ../include/ircd_handler.h ../include/ircd.h \ ../config/config.h ../config/setup.h ../include/struct.h \ diff --git a/ircd/gline.c b/ircd/gline.c index 33e72a3..b09d607 100644 --- a/ircd/gline.c +++ b/ircd/gline.c @@ -23,6 +23,7 @@ #include "client.h" #include "ircd.h" #include "ircd_alloc.h" +#include "ircd_reply.h" #include "ircd_string.h" #include "match.h" #include "numeric.h" @@ -30,9 +31,14 @@ #include "s_misc.h" #include "send.h" #include "struct.h" +#include "support.h" +#include "msg.h" +#include "numnicks.h" +#include "numeric.h" #include "sys.h" /* FALSE bleah */ #include +#include struct Gline* GlobalGlineList = 0; struct Gline* BadChanGlineList = 0; @@ -56,11 +62,11 @@ static struct Gline * make_gline(char *userhost, char *reason, time_t expire, time_t lastmod, unsigned int flags) { - struct Gline *agline; + struct Gline *gline; char *user, *host; - agline = (struct Gline *)MyMalloc(sizeof(struct Gline)); /* alloc memory */ - assert(0 != agline); + gline = (struct Gline *)MyMalloc(sizeof(struct Gline)); /* alloc memory */ + assert(0 != gline); gline->gl_expire = expire; /* initialize gline... */ gline->gl_lastmod = lastmod; @@ -73,8 +79,8 @@ make_gline(char *userhost, char *reason, time_t expire, time_t lastmod, gline->gl_next = BadChanGlineList; /* then link it into list */ gline->gl_prev_p = &BadChanGlineList; if (BadChanGlineList) - BadChanGlineList->gl_prev_p = &agline->gl_next; - BadChanGlineList = agline; + BadChanGlineList->gl_prev_p = &gline->gl_next; + BadChanGlineList = gline; } else { canon_userhost(userhost, &user, &host, "*"); /* find user and host */ @@ -87,11 +93,11 @@ make_gline(char *userhost, char *reason, time_t expire, time_t lastmod, gline->gl_next = GlobalGlineList; /* then link it into list */ gline->gl_prev_p = &GlobalGlineList; if (GlobalGlineList) - GlobalGlineList->gl_prev_p = &agline->gl_next; - GlobalGlineList = agline; + GlobalGlineList->gl_prev_p = &gline->gl_next; + GlobalGlineList = gline; } - return agline; + return gline; } static int @@ -111,13 +117,13 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline) if (!acptr->user) continue; - if ((GlineIsIpMask(gline) ? match(gline->host, acptr->sock_ip) : - match(gline->host, acptr->sockhost)) == 0 && + if ((GlineIsIpMask(gline) ? match(gline->gl_host, acptr->sock_ip) : + match(gline->gl_host, acptr->sockhost)) == 0 && (!acptr->user->username || - match(gline->name, acptr->user->username) == 0)) { + match(gline->gl_user, acptr->user->username) == 0)) { /* ok, here's one that got G-lined */ sendto_one(acptr, ":%s %d %s :*** %s.", me.name, ERR_YOUREBANNEDCREEP, - acptr->name, gline->reason); + acptr->name, gline->gl_reason); /* let the ops know about it */ sendto_op_mask(SNO_GLINE, "G-line active for %s", @@ -125,7 +131,7 @@ do_gline(struct Client *cptr, struct Client *sptr, struct Gline *gline) /* and get rid of him */ if ((tval = exit_client_msg(cptr, acptr, &me, "G-lined (%s)", - gline->reason))) + gline->gl_reason))) retval = tval; /* retain killed status */ } } @@ -363,9 +369,9 @@ gline_find(char *userhost, unsigned int flags) if (gline->gl_expire <= TStime()) gline_free(gline); - else if (match(gline->host, host) == 0 && - ((!user && ircd_strcmp(gline->user, "*") == 0) || - match(gline->user, user) == 0)) + else if (match(gline->gl_host, host) == 0 && + ((!user && ircd_strcmp(gline->gl_user, "*") == 0) || + match(gline->gl_user, user) == 0)) break; } @@ -470,7 +476,7 @@ gline_list(struct Client *sptr, char *userhost) } /* send gline information along */ - sendto_one(sptr, rpl_str(GLIST), me.name, sptr->name, gline->gl_user, + sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name, gline->gl_user, GlineIsBadChan(gline) ? "" : "@", GlineIsBadChan(gline) ? "" : gline->gl_host, gline->gl_expire, GlineIsLocal(gline) ? me.name : "*", @@ -482,7 +488,7 @@ gline_list(struct Client *sptr, char *userhost) if (gline->gl_expire <= TStime()) gline_free(gline); else - sendto_one(sptr, rpl_str(GLIST), me.name, sptr->name, gline->gl_user, + sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name, gline->gl_user, "@", gline->gl_host, gline->gl_expire, GlineIsLocal(gline) ? me.name : "*", GlineIsActive(gline) ? '+' : '-', gline->gl_reason); @@ -494,7 +500,7 @@ gline_list(struct Client *sptr, char *userhost) if (gline->gl_expire <= TStime()) gline_free(gline); else - sendto_one(sptr, rpl_str(GLIST), me.name, sptr->name, gline->gl_user, + sendto_one(sptr, rpl_str(RPL_GLIST), me.name, sptr->name, gline->gl_user, "", "", gline->gl_expire, GlineIsLocal(gline) ? me.name : "*", GlineIsActive(gline) ? '+' : '-', gline->gl_reason); @@ -502,7 +508,7 @@ gline_list(struct Client *sptr, char *userhost) } /* end of gline information */ - sendto_one(cptr, rpl_str(RPL_ENDOFGLIST), me.name, sptr->name); + sendto_one(sptr, rpl_str(RPL_ENDOFGLIST), me.name, sptr->name); return 0; } diff --git a/ircd/m_gline.c b/ircd/m_gline.c index c2980c1..96761e7 100644 --- a/ircd/m_gline.c +++ b/ircd/m_gline.c @@ -167,11 +167,11 @@ ms_gline(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) flags |= GLINE_LOCAL; } - if (*server == '-') - server++; - else if (*server == '+') { + if (*mask == '-') + mask++; + else if (*mask == '+') { flags |= GLINE_ACTIVE; - server++; + mask++; } else flags |= GLINE_ACTIVE; diff --git a/ircd/m_join.c b/ircd/m_join.c index d1408d9..f7b0342 100644 --- a/ircd/m_join.c +++ b/ircd/m_join.c @@ -406,7 +406,6 @@ int ms_join(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) struct Channel* chptr; char* name; char* keysOrTS = NULL; - int i = 0; int zombie = 0; int sendcreate = 0; unsigned int flags = 0; diff --git a/ircd/m_stats.c b/ircd/m_stats.c index 98daef7..1078891 100644 --- a/ircd/m_stats.c +++ b/ircd/m_stats.c @@ -90,6 +90,7 @@ /* * XXX - ack!!! */ +#include "s_stats.h" #include "channel.h" #include "class.h" #include "client.h" @@ -121,32 +122,6 @@ #include #include -/* - * Help info displayed when user provides no stats parameter. --Gte - */ -const char *statsinfo[] = { - "The following statistics are available:", - "U - Service server & nick jupes information.", - "u - Current uptime & highest connection count.", - "p - Listening ports.", - "i - Connection authorisation lines.", - "y - Connection classes.", - "c - Remote server connection lines.", - "h - Hubs information (Oper only).", - "d - Dynamic routing configuration.", - "l - Current connections information.", - "g - Global bans (G-lines).", - "k - Local bans (K-Lines).", - "o - Operator information.", - "m - Message usage information.", - "t - Local connection statistics (Total SND/RCV, etc).", - "w - Userload statistics.", - "M - Memory allocation & leak monitoring.", - "z - Memory/Structure allocation information.", - "r - System resource usage (Debug only).", - "x - List usage information (Debug only).", - 0, -}; /* * m_stats - generic message handler @@ -178,84 +153,13 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT; struct Message *mptr; struct Client *acptr; - struct Gline* gline; struct ConfItem *aconf; char stat = parc > 1 ? parv[1][0] : '\0'; const char **infotext = statsinfo; int i; -/* 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. - * -Ghostwolf - */ - switch (stat) - { - /* open to all, standard # of params */ - case 'U': - case 'u': - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* open to all, varying # of params */ - case 'k': - case 'K': - case 'i': - case 'I': - case 'p': - case 'P': - { - if (parc > 3) - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - break; - } - - /* oper only, varying # of params */ - case 'l': - case 'L': - case 'M': - { - if (parc == 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else if (parc > 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, - parv) != HUNTED_ISME) - return 0; - } - else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* oper only, standard # of params */ - default: - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - } + if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME) + return 0; switch (stat) { @@ -292,13 +196,8 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) /* Don't return clients when this is a request for `all' */ if (doall && IsUser(acptr)) continue; - /* Don't show invisible people to unauthorized people when using - * wildcards -- Is this still needed now /stats is oper only ? - * Yeah it is -- non opers can /stats l, just not remotely. - */ - if (IsInvisible(acptr) && (doall || wilds) && - !(MyConnect(sptr) && IsOper(sptr)) && - !IsAnOper(acptr) && (acptr != sptr)) + /* Don't show invisible people to non opers unless they know the nick */ + if (IsInvisible(acptr) && (doall || wilds) && !IsAnOper(acptr) && (acptr != sptr)) continue; /* Only show the ones that match the given mask - if any */ if (!doall && wilds && match(name, acptr->name)) @@ -319,15 +218,11 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) break; case 'G': case 'g': /* send glines */ - gline_remove_expired(TStime()); - for (gline = GlobalGlineList; gline; gline = gline->next) { - sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, - sptr->name, 'G', gline->name, gline->host, - gline->expire, gline->reason); - } + gline_stats(sptr); break; case 'H': case 'h': + report_configured_links(sptr, CONF_HUB | CONF_LEAF); break; case 'I': case 'i': @@ -338,14 +233,11 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) int wilds, count; char *user, *host, *p; int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT; - if ((MyUser(sptr) || IsOper(sptr)) && parc < 4) + if (parc < 4) { report_configured_links(sptr, conf_status); break; } - if (parc < 4 || *parv[3] == '\0') - return need_more_params(sptr, - (conf_status & CONF_KLINE) ? "STATS K" : "STATS I"); wilds = 0; for (p = parv[3]; *p; p++) @@ -362,13 +254,8 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) break; } } - if (!(MyConnect(sptr) || IsOper(sptr))) - { - wilds = 0; - count = 3; - } - else - count = 1000; + + count = 1000; if (conf_status == CONF_CLIENT) { @@ -402,7 +289,8 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) (!user || !mmatch(user, aconf->name)))) { sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name, - sptr->name, 'K', aconf->host, aconf->passwd, aconf->name, + sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k', + aconf->host, aconf->passwd, aconf->name, aconf->port, get_conf_class(aconf)); if (--count == 0) break; @@ -461,11 +349,9 @@ int m_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) /* * show listener ports * show hidden ports to opers, if there are more than 3 parameters, - * interpret the fourth parameter as the port number, limit non-local - * or non-oper results to 8 ports. + * interpret the fourth parameter as the port number. */ - show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, - (MyUser(sptr) || IsOper(sptr)) ? 100 : 8); + show_ports(sptr, 0, (parc > 3) ? atoi(parv[3]) : 0, 100); break; case 'R': case 'r': @@ -556,83 +442,12 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT; struct Message *mptr; struct Client *acptr; - struct Gline* gline; struct ConfItem *aconf; char stat = parc > 1 ? parv[1][0] : '\0'; int i; -/* 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. - * -Ghostwolf - */ - switch (stat) - { - /* open to all, standard # of params */ - case 'U': - case 'u': - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* open to all, varying # of params */ - case 'k': - case 'K': - case 'i': - case 'I': - case 'p': - case 'P': - { - if (parc > 3) - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - break; - } - - /* oper only, varying # of params */ - case 'l': - case 'L': - case 'M': - { - if (parc == 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else if (parc > 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, - parv) != HUNTED_ISME) - return 0; - } - else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* oper only, standard # of params */ - default: - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - } + if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME) + return 0; switch (stat) { @@ -670,11 +485,9 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) if (doall && IsUser(acptr)) continue; /* Don't show invisible people to unauthorized people when using - * wildcards -- Is this still needed now /stats is oper only ? */ - if (IsInvisible(acptr) && (doall || wilds) && - !(MyConnect(sptr) && IsOper(sptr)) && - !IsAnOper(acptr) && (acptr != sptr)) - continue; + * wildcards -- Is this still needed now /stats is oper only ? + * Not here, because ms_stats is specifically a remote command, + * thus the check was removed. -Ghostwolf */ /* Only show the ones that match the given mask - if any */ if (!doall && wilds && match(name, acptr->name)) continue; @@ -690,17 +503,11 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) } case 'C': case 'c': - if (IsAnOper(sptr)) - report_configured_links(sptr, CONF_SERVER); + report_configured_links(sptr, CONF_SERVER); break; case 'G': case 'g': /* send glines */ - gline_remove_expired(TStime()); - for (gline = GlobalGlineList; gline; gline = gline->next) { - sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, - sptr->name, 'G', gline->name, gline->host, - gline->expire, gline->reason); - } + gline_stats(sptr); break; case 'H': case 'h': @@ -715,7 +522,7 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) int wilds, count; char *user, *host, *p; int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT; - if ((MyUser(sptr) || IsOper(sptr)) && parc < 4) + if (IsOper(sptr) && parc < 4) { report_configured_links(sptr, conf_status); break; @@ -739,7 +546,7 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) break; } } - if (!(MyConnect(sptr) || IsOper(sptr))) + if (!IsOper(sptr)) { wilds = 0; count = 3; @@ -779,7 +586,8 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) (!user || !mmatch(user, aconf->name)))) { sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name, - sptr->name, 'K', aconf->host, aconf->passwd, aconf->name, + sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k', + aconf->host, aconf->passwd, aconf->name, aconf->port, get_conf_class(aconf)); if (--count == 0) break; @@ -841,8 +649,7 @@ int ms_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * interpret the fourth parameter as the port number, limit non-local * or non-oper results to 8 ports. */ - show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, - (MyUser(sptr) || IsOper(sptr)) ? 100 : 8); + show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, IsOper(sptr) ? 100 : 8); break; case 'R': case 'r': @@ -932,84 +739,13 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) static char Lformat[] = ":%s %d %s %s %u %u %u %u %u :" TIME_T_FMT; struct Message *mptr; struct Client *acptr; - struct Gline* gline; struct ConfItem *aconf; char stat = parc > 1 ? parv[1][0] : '\0'; const char **infotext = statsinfo; int i; -/* 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. - * -Ghostwolf - */ - switch (stat) - { - /* open to all, standard # of params */ - case 'U': - case 'u': - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* open to all, varying # of params */ - case 'k': - case 'K': - case 'i': - case 'I': - case 'p': - case 'P': - { - if (parc > 3) - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else - { - if (hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - break; - } - - /* oper only, varying # of params */ - case 'l': - case 'L': - case 'M': - { - if (parc == 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - } - else if (parc > 4) - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, - parv) != HUNTED_ISME) - return 0; - } - else if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - - /* oper only, standard # of params */ - default: - { - if (hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv) - != HUNTED_ISME) - return 0; - break; - } - } + if (hunt_stats(cptr, sptr, parc, parv, stat) != HUNTED_ISME) + return 0; switch (stat) { @@ -1046,12 +782,6 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) /* Don't return clients when this is a request for `all' */ if (doall && IsUser(acptr)) continue; - /* Don't show invisible people to unauthorized people when using - * wildcards -- Is this still needed now /stats is oper only ? */ - if (IsInvisible(acptr) && (doall || wilds) && - !(MyConnect(sptr) && IsOper(sptr)) && - !IsAnOper(acptr) && (acptr != sptr)) - continue; /* Only show the ones that match the given mask - if any */ if (!doall && wilds && match(name, acptr->name)) continue; @@ -1071,12 +801,7 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) break; case 'G': case 'g': /* send glines */ - gline_remove_expired(TStime()); - for (gline = GlobalGlineList; gline; gline = gline->next) { - sendto_one(sptr, rpl_str(RPL_STATSGLINE), me.name, - sptr->name, 'G', gline->name, gline->host, - gline->expire, gline->reason); - } + gline_stats(sptr); break; case 'H': case 'h': @@ -1091,14 +816,11 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) int wilds, count; char *user, *host, *p; int conf_status = (stat == 'k' || stat == 'K') ? CONF_KLINE : CONF_CLIENT; - if ((MyUser(sptr) || IsOper(sptr)) && parc < 4) + if (parc < 4) { report_configured_links(sptr, conf_status); break; } - if (parc < 4 || *parv[3] == '\0') - return need_more_params(sptr, - (conf_status & CONF_KLINE) ? "STATS K" : "STATS I"); wilds = 0; for (p = parv[3]; *p; p++) @@ -1115,13 +837,8 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) break; } } - if (!(MyConnect(sptr) || IsOper(sptr))) - { - wilds = 0; - count = 3; - } - else - count = 1000; + + count = 1000; if (conf_status == CONF_CLIENT) { @@ -1155,7 +872,8 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) (!user || !mmatch(user, aconf->name)))) { sendto_one(sptr, rpl_str(RPL_STATSKLINE), me.name, - sptr->name, 'K', aconf->host, aconf->passwd, aconf->name, + sptr->name, (aconf->status & CONF_KILL) ? 'K' : 'k', + aconf->host, aconf->passwd, aconf->name, aconf->port, get_conf_class(aconf)); if (--count == 0) break; @@ -1217,8 +935,7 @@ int mo_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * interpret the fourth parameter as the port number, limit non-local * or non-oper results to 8 ports. */ - show_ports(sptr, IsOper(sptr), (parc > 3) ? atoi(parv[3]) : 0, - (MyUser(sptr) || IsOper(sptr)) ? 100 : 8); + show_ports(sptr, 1, (parc > 3) ? atoi(parv[3]) : 0, 100); break; case 'R': case 'r': @@ -1656,3 +1373,5 @@ int m_stats(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) return 0; } #endif /* 0 */ + + diff --git a/ircd/map.c b/ircd/map.c index c4914ad..10401ed 100644 --- a/ircd/map.c +++ b/ircd/map.c @@ -29,6 +29,7 @@ #include "send.h" #include "struct.h" +#include /* sprintf */ void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length) { diff --git a/ircd/opercmds.c b/ircd/opercmds.c index bbc4cec..74049be 100644 --- a/ircd/opercmds.c +++ b/ircd/opercmds.c @@ -43,84 +43,6 @@ #include #include -/* - * m_stats/stats_conf - * - * Report N/C-configuration lines from this server. This could - * report other configuration lines too, but converting the - * status back to "char" is a bit akward--not worth the code - * it needs... - * - * Note: The info is reported in the order the server uses - * it--not reversed as in ircd.conf! - */ - -static unsigned int report_array[17][3] = { - {CONF_SERVER, RPL_STATSCLINE, 'C'}, - {CONF_CLIENT, RPL_STATSILINE, 'I'}, - {CONF_KILL, RPL_STATSKLINE, 'K'}, - {CONF_IPKILL, RPL_STATSKLINE, 'k'}, - {CONF_LEAF, RPL_STATSLLINE, 'L'}, - {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} -}; - -void report_configured_links(struct Client *sptr, int mask) -{ - static char null[] = ""; - struct ConfItem *tmp; - unsigned int *p; - unsigned short int port; - char c, *host, *pass, *name; - - for (tmp = GlobalConfList; tmp; tmp = tmp->next) { - if ((tmp->status & mask)) - { - for (p = &report_array[0][0]; *p; p += 3) - if (*p == tmp->status) - break; - if (!*p) - continue; - c = (char)*(p + 2); - host = BadPtr(tmp->host) ? null : tmp->host; - pass = BadPtr(tmp->passwd) ? null : tmp->passwd; - name = BadPtr(tmp->name) ? null : tmp->name; - port = tmp->port; - /* - * On K line the passwd contents can be - * displayed on STATS reply. -Vesa - */ - /* Special-case 'k' or 'K' lines as appropriate... -Kev */ - if ((tmp->status & CONF_KLINE)) - sendto_one(sptr, rpl_str(p[1]), me.name, - sptr->name, c, host, pass, name, port, get_conf_class(tmp)); - /* - * connect rules are classless - */ - else if ((tmp->status & CONF_CRULE)) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name); - else if ((tmp->status & CONF_TLINES)) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, pass); - else if ((tmp->status & CONF_UWORLD)) - sendto_one(sptr, rpl_str(p[1]), - me.name, sptr->name, c, host, pass, name, port, - get_conf_class(tmp)); - else if ((tmp->status & (CONF_SERVER | CONF_HUB))) - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, "*", name, - port, get_conf_class(tmp)); - else - sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name, - port, get_conf_class(tmp)); - } - } -} - char *militime(char* sec, char* usec) { struct timeval tv; diff --git a/ircd/s_conf.c b/ircd/s_conf.c index a7013eb..772463d 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -1445,6 +1445,7 @@ int find_kill(struct Client *cptr) /* find active glines */ /* added a check against the user's IP address to find_gline() -Kev */ + /* FIX ME KEV! gline_find take char *userhost not struct Client! -GW */ else if ((agline = gline_find(cptr, 0)) && GlineIsActive(agline)) sendto_one(cptr, ":%s %d %s :%s.", me.name, ERR_YOUREBANNEDCREEP, cptr->name, GlineReason(agline)); diff --git a/ircd/s_stats.c b/ircd/s_stats.c new file mode 100644 index 0000000..4c37675 --- /dev/null +++ b/ircd/s_stats.c @@ -0,0 +1,199 @@ +/* + * IRC - Internet Relay Chat, ircd/s_stats.c + * Copyright (C) 2000 Joseph Bongaarts + * + * See file AUTHORS in IRC package for additional names of + * the programmers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ + +#include "s_stats.h" +#include "class.h" +#include "client.h" +#include "crule.h" +#include "ircd.h" +#include "ircd_chattr.h" +#include "ircd_reply.h" +#include "ircd_string.h" +#include "listener.h" +#include "match.h" +#include "msg.h" +#include "numeric.h" +#include "numnicks.h" +#include "s_conf.h" +#include "s_user.h" +#include "send.h" +#include "struct.h" + +#include +#include +#include + + +/* + * m_stats/s_stats + * + * Report configuration lines and other statistics from this + * server. + * + * Note: The info is reported in the order the server uses + * it--not reversed as in ircd.conf! + */ + +/* + * Help info displayed when user provides no stats parameter. --Gte + */ +const char *statsinfo[] = { + "The following statistics are available:", + "U - Service server & nick jupes information.", + "u - Current uptime & highest connection count.", + "p - Listening ports.", + "i - Connection authorisation lines.", + "y - Connection classes.", + "c - Remote server connection lines.", + "h - Hubs information.", + "d - Dynamic routing configuration.", + "l - Current connections information.", + "g - Global bans (G-lines).", + "k - Local bans (K-Lines).", + "o - Operator information.", + "m - Message usage information.", + "t - Local connection statistics (Total SND/RCV, etc).", + "w - Userload statistics.", + "M - Memory allocation & leak monitoring.", + "z - Memory/Structure allocation information.", + "r - System resource usage (Debug only).", + "x - List usage information (Debug only).", + 0, +}; + +static unsigned int report_array[17][3] = { + {CONF_SERVER, RPL_STATSCLINE, 'C'}, + {CONF_CLIENT, RPL_STATSILINE, 'I'}, + {CONF_KILL, RPL_STATSKLINE, 'K'}, + {CONF_IPKILL, RPL_STATSKLINE, 'k'}, + {CONF_LEAF, RPL_STATSLLINE, 'L'}, + {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} +}; + +void report_configured_links(struct Client *sptr, int mask) +{ + static char null[] = ""; + struct ConfItem *tmp; + unsigned int *p; + unsigned short int port; + char c, *host, *pass, *name; + + + for (tmp = GlobalConfList; tmp; tmp = tmp->next) + { + if ((tmp->status & mask)) + { + for (p = &report_array[0][0]; *p; p += 3) + if (*p == tmp->status) + break; + if (!*p) + continue; + c = (char)*(p + 2); + host = BadPtr(tmp->host) ? null : tmp->host; + pass = BadPtr(tmp->passwd) ? null : tmp->passwd; + name = BadPtr(tmp->name) ? null : tmp->name; + port = tmp->port; + /* + * On K line the passwd contents can be + * displayed on STATS reply. -Vesa + */ + /* Special-case 'k' or 'K' lines as appropriate... -Kev */ + if ((tmp->status & CONF_KLINE)) + sendto_one(sptr, rpl_str(p[1]), me.name, + sptr->name, c, host, pass, name, port, get_conf_class(tmp)); + /* + * connect rules are classless + */ + else if ((tmp->status & CONF_CRULE)) + sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name); + else if ((tmp->status & CONF_TLINES)) + sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, pass); + else if ((tmp->status & CONF_UWORLD)) + sendto_one(sptr, rpl_str(p[1]), + me.name, sptr->name, c, host, pass, name, port, + get_conf_class(tmp)); + else if ((tmp->status & (CONF_SERVER | CONF_HUB))) + sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, "*", name, + port, get_conf_class(tmp)); + else + sendto_one(sptr, rpl_str(p[1]), me.name, sptr->name, c, host, name, + port, get_conf_class(tmp)); + } + } +} + +/* 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. + * -Ghostwolf + */ +int hunt_stats(struct Client* cptr, struct Client* sptr, int parc, char* parv[], char stat) +{ + switch (stat) + { + /* open to all, standard # of params */ + case 'U': + case 'u': + return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv); + + /* open to all, varying # of params */ + case 'k': + case 'K': + case 'i': + case 'I': + case 'p': + case 'P': + { + if (parc > 3) + return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv); + else + return hunt_server(0, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv); + } + + /* oper only, varying # of params */ + case 'l': + case 'L': + case 'M': + { + if (parc == 4) + return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s :%s", 2, parc, parv); + else if (parc > 4) + return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s %s %s :%s", 2, parc, parv); + else + return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv); + } + + /* oper only, standard # of params */ + default: + return hunt_server(1, cptr, sptr, "%s%s " TOK_STATS " %s :%s", 2, parc, parv); + } +} + diff --git a/ircd/s_user.c b/ircd/s_user.c index b2f3cd4..39bb074 100644 --- a/ircd/s_user.c +++ b/ircd/s_user.c @@ -58,6 +58,8 @@ #include "version.h" #include "whowas.h" +#include "handlers.h" /* m_motd and m_lusers */ + #include #include #include