ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_info.c
(Generate patch)

Comparing ircd-hybrid/trunk/modules/m_info.c (file contents):
Revision 2341 by michael, Wed Jul 3 13:54:23 2013 UTC vs.
Revision 3933 by michael, Mon Jun 9 17:56:42 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  m_info.c: Sends information about the server.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2005 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file m_info.c
23 > * \brief Includes required functions for processing the INFO command.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28   #include "list.h"
27 #include "channel.h"
29   #include "client.h"
29 #include "irc_string.h"
30   #include "ircd.h"
31   #include "numeric.h"
32 < #include "s_serv.h"
33 < #include "s_user.h"
32 > #include "misc.h"
33 > #include "server.h"
34   #include "send.h"
35   #include "conf.h"
36   #include "parse.h"
37   #include "modules.h"
38  
39  
40 + /* Types for output_type in InfoStruct */
41 + enum
42 + {
43 +  OUTPUT_STRING     = 1 << 0,  /* Output option as %s w/ dereference  */
44 +  OUTPUT_STRING_PTR = 1 << 1,  /* Output option as %s w/out deference */
45 +  OUTPUT_DECIMAL    = 1 << 2,  /* Output option as decimal (%d) */
46 +  OUTPUT_BOOLEAN    = 1 << 3,  /* Output option as "ON" or "OFF" */
47 +  OUTPUT_BOOLEAN_YN = 1 << 4,  /* Output option as "YES" or "NO" */
48 +  OUTPUT_BOOLEAN2   = 1 << 5   /* Output option as "YES/NO/MASKED" */
49 + };
50 +
51   /*
52   * jdc -- Structure for our configuration value table
53   */
54   struct InfoStruct
55   {
56 <  const char *name;         /* Displayed variable name           */
57 <  unsigned int output_type; /* See below #defines                */
58 <  void *option;             /* Pointer reference to the value    */
59 <  const char *desc;         /* ASCII description of the variable */
56 >  const char *name;  /* Displayed variable name */
57 >  const unsigned int output_type;  /* Type of output. See enum above */
58 >  const void *option;  /* Pointer reference to the value */
59 >  const char *desc;  /* ASCII description of the variable */
60   };
61  
51 /* Types for output_type in InfoStruct */
52 #define OUTPUT_STRING     0x0001  /* Output option as %s w/ dereference  */
53 #define OUTPUT_STRING_PTR 0x0002  /* Output option as %s w/out deference */
54 #define OUTPUT_DECIMAL    0x0004  /* Output option as decimal (%d)       */
55 #define OUTPUT_BOOLEAN    0x0008  /* Output option as "ON" or "OFF"      */
56 #define OUTPUT_BOOLEAN_YN 0x0010  /* Output option as "YES" or "NO"      */
57 #define OUTPUT_BOOLEAN2   0x0020  /* Output option as "YES/NO/MASKED"    */
58
62   static const struct InfoStruct info_table[] =
63   {
64    /* --[  START OF TABLE  ]-------------------------------------------- */
65  
66    {
64    "CPATH",
65    OUTPUT_STRING,
66    &ConfigFileEntry.configfile,
67    "Path to main configuration file"
68  },
69  {
67      "DPATH",
68      OUTPUT_STRING,
69      &ConfigFileEntry.dpath,
70      "Root directory of installation"
71    },
72    {
73 +    "SPATH",
74 +    OUTPUT_STRING,
75 +    &ConfigFileEntry.spath,
76 +    "Path to server executable"
77 +  },
78 +  {
79 +    "MPATH",
80 +    OUTPUT_STRING,
81 +    &ConfigFileEntry.mpath,
82 +    "Path to main motd (Message of the Day) file"
83 +  },
84 +  {
85 +    "CPATH",
86 +    OUTPUT_STRING,
87 +    &ConfigFileEntry.configfile,
88 +    "Path to main configuration file"
89 +  },
90 +  {
91      "DLPATH",
92      OUTPUT_STRING,
93      &ConfigFileEntry.dlinefile,
# Line 151 | Line 166 | static const struct InfoStruct info_tabl
166      "Forbids channels with special ASCII characters in their name"
167    },
168    {
169 <    "knock_delay",
169 >    "invite_client_count",
170      OUTPUT_DECIMAL,
171 <    &ConfigChannel.knock_delay,
172 <    "Delay between a users KNOCK attempts"
171 >    &ConfigChannel.invite_client_count,
172 >    "How many INVITE attempts are permitted in invite_client_time"
173 >  },
174 >
175 >  {
176 >    "invite_client_time",
177 >    OUTPUT_DECIMAL,
178 >    &ConfigChannel.invite_client_time,
179 >    "How many invite_client_count invites are allowed in this time"
180 >  },
181 >  {
182 >    "knock_client_count",
183 >    OUTPUT_DECIMAL,
184 >    &ConfigChannel.knock_client_count,
185 >    "How many KNOCK attempts are permitted in knock_client_time"
186 >  },
187 >  {
188 >    "knock_client_time",
189 >    OUTPUT_DECIMAL,
190 >    &ConfigChannel.knock_client_time,
191 >    "How many kknock_client_count knocks are allowed in this time"
192    },
193    {
194      "knock_delay_channel",
# Line 163 | Line 197 | static const struct InfoStruct info_tabl
197      "Delay between KNOCK attempts to a channel"
198    },
199    {
200 <    "max_chans_per_user",
200 >    "max_channels",
201      OUTPUT_DECIMAL,
202 <    &ConfigChannel.max_chans_per_user,
202 >    &ConfigChannel.max_channels,
203      "Maximum number of channels a user can join"
204    },
205    {
172    "max_chans_per_oper",
173    OUTPUT_DECIMAL,
174    &ConfigChannel.max_chans_per_oper,
175    "Maximum number of channels an oper can join"
176  },
177  {
206      "max_bans",
207      OUTPUT_DECIMAL,
208      &ConfigChannel.max_bans,
# Line 314 | Line 342 | static const struct InfoStruct info_tabl
342    },
343    {
344      "failed_oper_notice",
345 <    OUTPUT_BOOLEAN,
345 >    OUTPUT_BOOLEAN_YN,
346      &ConfigFileEntry.failed_oper_notice,
347      "Inform opers if someone tries to /oper with the wrong password"
348    },
# Line 344 | Line 372 | static const struct InfoStruct info_tabl
372    },
373    {
374      "anti_nick_flood",
375 <    OUTPUT_BOOLEAN,
375 >    OUTPUT_BOOLEAN_YN,
376      &ConfigFileEntry.anti_nick_flood,
377      "NICK flood protection"
378    },
# Line 379 | Line 407 | static const struct InfoStruct info_tabl
407      "Maximum permitted TS delta from another server"
408    },
409    {
410 <    "warn_no_nline",
411 <    OUTPUT_BOOLEAN,
412 <    &ConfigFileEntry.warn_no_nline,
413 <    "Display warning if connecting server lacks N-line"
410 >    "warn_no_connect_block",
411 >    OUTPUT_BOOLEAN_YN,
412 >    &ConfigFileEntry.warn_no_connect_block,
413 >    "Display warning if connecting server lacks a connect{} block"
414    },
415    {
416      "stats_e_disabled",
# Line 452 | Line 480 | static const struct InfoStruct info_tabl
480    },
481    {
482      "ping_cookie",
483 <    OUTPUT_BOOLEAN,
483 >    OUTPUT_BOOLEAN_YN,
484      &ConfigFileEntry.ping_cookie,
485      "Require ping cookies to connect"
486    },
487    {
488      "no_oper_flood",
489 <    OUTPUT_BOOLEAN,
489 >    OUTPUT_BOOLEAN_YN,
490      &ConfigFileEntry.no_oper_flood,
491      "Reduce flood control for operators"
492    },
493    {
494      "true_no_oper_flood",
495 <    OUTPUT_BOOLEAN,
495 >    OUTPUT_BOOLEAN_YN,
496      &ConfigFileEntry.true_no_oper_flood,
497      "Completely disable flood control for operators"
498    },
# Line 481 | Line 509 | static const struct InfoStruct info_tabl
509      "The maximum number of PRIVMSG/NOTICE targets"
510    },
511    {
512 +    "throttle_count",
513 +    OUTPUT_DECIMAL,
514 +    &ConfigFileEntry.throttle_count,
515 +    "Number of connects in throttle_time before connections are blocked"
516 +  },
517 +  {
518      "throttle_time",
519      OUTPUT_DECIMAL,
520      &ConfigFileEntry.throttle_time,
521      "Minimum time between client reconnects"
522    },
523    {
524 <    "glines",
525 <    OUTPUT_BOOLEAN,
524 >    "gline_enable",
525 >    OUTPUT_BOOLEAN_YN,
526      &ConfigFileEntry.glines,
527      "G-line (network-wide K-line) support"
528    },
# Line 523 | Line 557 | static const struct InfoStruct info_tabl
557   static void
558   send_birthdate_online_time(struct Client *source_p)
559   {
560 <  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
561 <    sendto_one(source_p, ":%s %d %s :On-line since %s",
562 <               me.id, RPL_INFO, source_p->id,
529 <               myctime(me.localClient->firsttime));
530 <  else
531 <    sendto_one(source_p, ":%s %d %s :On-line since %s",
532 <               me.name, RPL_INFO, source_p->name,
533 <               myctime(me.localClient->firsttime));
560 >  sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
561 >                     ":On-line since %s",
562 >                     myctime(me.localClient->firsttime));
563   }
564  
565   /* send_conf_options()
# Line 542 | Line 571 | send_birthdate_online_time(struct Client
571   static void
572   send_conf_options(struct Client *source_p)
573   {
545  const char *from, *to;
546  const struct InfoStruct *iptr = NULL;
547
548  /* Now send them a list of all our configuration options
549   * (mostly from defaults.h and config.h)
550   */
551  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
552  {
553    from = me.id;
554    to = source_p->id;
555  }
556  else
557  {
558    from = me.name;
559    to = source_p->name;
560  }
561
574    /*
575     * Parse the info_table[] and do the magic.
576     */
577 <  for (iptr = info_table; iptr->name; ++iptr)
577 >  for (const struct InfoStruct *iptr = info_table; iptr->name; ++iptr)
578    {
579      switch (iptr->output_type)
580      {
581        /* For "char *" references */
582        case OUTPUT_STRING:
583        {
584 <        const char *option = *((char **)iptr->option);
584 >        const char *option = *((const char *const *)iptr->option);
585  
586 <        sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]",
587 <                   from, RPL_INFO, to,
588 <                   iptr->name, option ? option : "NONE",
589 <                   iptr->desc ? iptr->desc : "<none>");
586 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
587 >                           ":%-30s %-5s [%-30s]",
588 >                           iptr->name, option ? option : "NONE",
589 >                           iptr->desc ? iptr->desc : "<none>");
590          break;
591        }
592  
# Line 583 | Line 595 | send_conf_options(struct Client *source_
595        {
596          const char *option = iptr->option;
597  
598 <        sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]",
599 <                   from, RPL_INFO, to,
600 <                   iptr->name, option ? option : "NONE",
601 <                   iptr->desc ? iptr->desc : "<none>");
598 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
599 >                           ":%-30s %-5s [%-30s]",
600 >                           iptr->name, option ? option : "NONE",
601 >                           iptr->desc ? iptr->desc : "<none>");
602          break;
603        }
604  
605        /* Output info_table[i].option as a decimal value. */
606        case OUTPUT_DECIMAL:
607        {
608 <        const int option = *((int *)iptr->option);
608 >        const int option = *((const int *const)iptr->option);
609  
610 <        sendto_one(source_p, ":%s %d %s :%-30s %-5d [%-30s]",
611 <                   from, RPL_INFO, to, iptr->name,
612 <                   option, iptr->desc ? iptr->desc : "<none>");
610 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
611 >                           ":%-30s %-5d [%-30s]",
612 >                           iptr->name, option, iptr->desc ? iptr->desc : "<none>");
613          break;
614        }
615  
616        /* Output info_table[i].option as "ON" or "OFF" */
617        case OUTPUT_BOOLEAN:
618        {
619 <        const int option = *((int *)iptr->option);
619 >        const int option = *((const int *const)iptr->option);
620  
621 <        sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]",
622 <                   from, RPL_INFO, to,
623 <                   iptr->name, option ? "ON" : "OFF",
624 <                   iptr->desc ? iptr->desc : "<none>");
621 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
622 >                           ":%-30s %-5s [%-30s]",
623 >                           iptr->name, option ? "ON" : "OFF",
624 >                           iptr->desc ? iptr->desc : "<none>");
625  
626          break;
627        }
# Line 617 | Line 629 | send_conf_options(struct Client *source_
629        /* Output info_table[i].option as "YES" or "NO" */
630        case OUTPUT_BOOLEAN_YN:
631        {
632 <        const int option = *((int *)iptr->option);
632 >        const int option = *((const int *const)iptr->option);
633  
634 <        sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]",
635 <                   from, RPL_INFO, to,
636 <                   iptr->name, option ? "YES" : "NO",
637 <                   iptr->desc ? iptr->desc : "<none>");
634 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
635 >                           ":%-30s %-5s [%-30s]",
636 >                           iptr->name, option ? "YES" : "NO",
637 >                           iptr->desc ? iptr->desc : "<none>");
638          break;
639        }
640  
641        case OUTPUT_BOOLEAN2:
642        {
643 <        const int option = *((int *)iptr->option);
643 >        const int option = *((const int *const)iptr->option);
644  
645 <        sendto_one(source_p, ":%s %d %s :%-30s %-5s [%-30s]",
646 <                   from, RPL_INFO, to,
647 <                   iptr->name, option ? ((option == 1) ? "MASK" : "YES") : "NO",
648 <                   iptr->desc ? iptr->desc : "<none>");
645 >        sendto_one_numeric(source_p, &me, RPL_INFO|SND_EXPLICIT,
646 >                           ":%-30s %-5s [%-30s]",
647 >                           iptr->name, option ? ((option == 1) ? "MASK" : "YES") : "NO",
648 >                           iptr->desc ? iptr->desc : "<none>");
649          break;
650        }
651      }
652    }
653  
654 <  sendto_one(source_p, form_str(RPL_INFO),
643 <             from, to, "");
654 >  sendto_one_numeric(source_p, &me, RPL_INFO, "");
655   }
656  
657   /* send_info_text()
# Line 652 | Line 663 | send_conf_options(struct Client *source_
663   static void
664   send_info_text(struct Client *source_p)
665   {
655  const char **text = infotext;
656  char *source, *target;
657
666    sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
667                         "INFO requested by %s (%s@%s) [%s]",
668                         source_p->name, source_p->username,
669                         source_p->host, source_p->servptr->name);
670  
671 <  if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) &&
664 <      HasID(source_p))
665 <    source = me.id, target = source_p->id;
666 <  else
667 <    source = me.name, target = source_p->name;
668 <
669 <  while (*text)
671 >  for (const char **text = infotext; *text; ++text)
672    {
673 <    const char *line = *text++;
673 >    const char *line = *text;
674  
675      if (*line == '\0')
676        line = " ";
677  
678 <    sendto_one(source_p, form_str(RPL_INFO),
677 <               source, target, line);
678 >    sendto_one_numeric(source_p, &me, RPL_INFO, line);
679    }
680  
681    if (HasUMode(source_p, UMODE_OPER))
# Line 682 | Line 683 | send_info_text(struct Client *source_p)
683  
684    send_birthdate_online_time(source_p);
685  
686 <  sendto_one(source_p, form_str(RPL_ENDOFINFO),
686 <             me.name, source_p->name);
686 >  sendto_one_numeric(source_p, &me, RPL_ENDOFINFO);
687   }
688  
689 < /*
690 < ** m_info()
691 < **  parv[0] = sender prefix
692 < **  parv[1] = servername
693 < */
694 < static void
695 < m_info(struct Client *client_p, struct Client *source_p,
696 <       int parc, char *parv[])
689 > /*! \brief INFO command handler
690 > *
691 > * \param source_p Pointer to allocated Client struct from which the message
692 > *                 originally comes from.  This can be a local or remote client.
693 > * \param parc     Integer holding the number of supplied arguments.
694 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
695 > *                 pointers.
696 > * \note Valid arguments for this command are:
697 > *      - parv[0] = command
698 > *      - parv[1] = nickname/servername
699 > */
700 > static int
701 > m_info(struct Client *source_p, int parc, char *parv[])
702   {
703    static time_t last_used = 0;
704  
705    if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
706    {
707 <    /* safe enough to give this on a local connect only */
708 <    sendto_one(source_p, form_str(RPL_LOAD2HI),
704 <               me.name, source_p->name);
705 <    return;
707 >    sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
708 >    return 0;
709    }
710  
711    last_used = CurrentTime;
712  
713    if (!ConfigServerHide.disable_remote_commands)
714 <    if (hunt_server(client_p,source_p, ":%s INFO :%s", 1,
714 >    if (hunt_server(source_p, ":%s INFO :%s", 1,
715                      parc, parv) != HUNTED_ISME)
716 <      return;
716 >      return 0;
717  
718    send_info_text(source_p);
719 +  return 0;
720   }
721  
722 < /*
723 < ** ms_info()
724 < **  parv[0] = sender prefix
725 < **  parv[1] = servername
726 < */
727 < static void
728 < ms_info(struct Client *client_p, struct Client *source_p,
729 <        int parc, char *parv[])
722 > /*! \brief INFO command handler
723 > *
724 > * \param source_p Pointer to allocated Client struct from which the message
725 > *                 originally comes from.  This can be a local or remote client.
726 > * \param parc     Integer holding the number of supplied arguments.
727 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
728 > *                 pointers.
729 > * \note Valid arguments for this command are:
730 > *      - parv[0] = command
731 > *      - parv[1] = nickname/servername
732 > */
733 > static int
734 > ms_info(struct Client *source_p, int parc, char *parv[])
735   {
736 <  if (hunt_server(client_p, source_p, ":%s INFO :%s", 1,
736 >  if (hunt_server(source_p, ":%s INFO :%s", 1,
737                    parc, parv) != HUNTED_ISME)
738 <    return;
738 >    return 0;
739  
740    send_info_text(source_p);
741 +  return 0;
742   }
743  
744 < static struct Message info_msgtab = {
744 > static struct Message info_msgtab =
745 > {
746    "INFO", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
747    { m_unregistered, m_info, ms_info, m_ignore, ms_info, m_ignore }
748   };
# Line 748 | Line 759 | module_exit(void)
759    mod_del_cmd(&info_msgtab);
760   }
761  
762 < struct module module_entry = {
762 > struct module module_entry =
763 > {
764    .node    = { NULL, NULL, NULL },
765    .name    = NULL,
766    .version = "$Revision$",

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)