1 /*
2  *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3  *
4  *  Copyright (c) 1997-2021 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
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19  *  USA
20  */
21 
22 /*! \file m_motd.c
23  * \brief Includes required functions for processing the MOTD command.
24  * \version $Id: m_motd.c 9858 2021-01-01 04:43:42Z michael $
25  */
26 
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "motd.h"
31 #include "ircd.h"
32 #include "send.h"
33 #include "numeric.h"
34 #include "server.h"
35 #include "parse.h"
36 #include "modules.h"
37 #include "conf.h"
38 
39 
40 /*! \brief Sends the "message of the day" and notifies irc-operators
41  *         about the MOTD request
42  *
43  * \param source_p Pointer to client to report to
44  */
45 static void
do_motd(struct Client * source_p)46 do_motd(struct Client *source_p)
47 {
48   sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE,
49                        "MOTD requested by %s (%s@%s) [%s]",
50                        source_p->name, source_p->username,
51                        source_p->host, source_p->servptr->name);
52   motd_send(source_p);
53 }
54 
55 /*! \brief MOTD command handler
56  *
57  * \param source_p Pointer to allocated Client struct from which the message
58  *                 originally comes from.  This can be a local or remote client.
59  * \param parc     Integer holding the number of supplied arguments.
60  * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
61  *                 pointers.
62  * \note Valid arguments for this command are:
63  *      - parv[0] = command
64  *      - parv[1] = nickname/servername
65  */
66 static void
m_motd(struct Client * source_p,int parc,char * parv[])67 m_motd(struct Client *source_p, int parc, char *parv[])
68 {
69   static uintmax_t last_used = 0;
70 
71   if ((last_used + ConfigGeneral.pace_wait) > event_base->time.sec_monotonic)
72   {
73     sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "MOTD");
74     return;
75   }
76 
77   last_used = event_base->time.sec_monotonic;
78 
79   if (ConfigServerHide.disable_remote_commands == 0)
80     if (server_hunt(source_p, ":%s MOTD :%s", 1, parv)->ret != HUNTED_ISME)
81       return;
82 
83   do_motd(source_p);
84 }
85 
86 /*! \brief MOTD command handler
87  *
88  * \param source_p Pointer to allocated Client struct from which the message
89  *                 originally comes from.  This can be a local or remote client.
90  * \param parc     Integer holding the number of supplied arguments.
91  * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
92  *                 pointers.
93  * \note Valid arguments for this command are:
94  *      - parv[0] = command
95  *      - parv[1] = nickname/servername
96  */
97 static void
ms_motd(struct Client * source_p,int parc,char * parv[])98 ms_motd(struct Client *source_p, int parc, char *parv[])
99 {
100   if (server_hunt(source_p, ":%s MOTD :%s", 1, parv)->ret != HUNTED_ISME)
101     return;
102 
103   do_motd(source_p);
104 }
105 
106 static struct Message motd_msgtab =
107 {
108   .cmd = "MOTD",
109   .handlers[UNREGISTERED_HANDLER] = { .handler = m_unregistered },
110   .handlers[CLIENT_HANDLER] = { .handler = m_motd },
111   .handlers[SERVER_HANDLER] = { .handler = ms_motd },
112   .handlers[ENCAP_HANDLER] = { .handler = m_ignore },
113   .handlers[OPER_HANDLER] = { .handler = ms_motd }
114 };
115 
116 static void
module_init(void)117 module_init(void)
118 {
119   mod_add_cmd(&motd_msgtab);
120 }
121 
122 static void
module_exit(void)123 module_exit(void)
124 {
125   mod_del_cmd(&motd_msgtab);
126 }
127 
128 struct module module_entry =
129 {
130   .version = "$Revision: 9858 $",
131   .modinit = module_init,
132   .modexit = module_exit,
133 };
134