ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whowas.c
Revision: 5638
Committed: Sun Mar 1 15:33:06 2015 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 5581 byte(s)
Log Message:
- Fixed bug that would allow remote clients to bypass the hard
  limit of max WHOWAS entries to be returned

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2820 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 5347 * Copyright (c) 1997-2015 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 2820 /*! \file m_whowas.c
23     * \brief Includes required functions for processing the WHOWAS command.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1358 #include "list.h"
29 adx 30 #include "whowas.h"
30     #include "client.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "ircd.h"
34     #include "ircd_defs.h"
35     #include "numeric.h"
36 michael 3347 #include "misc.h"
37     #include "server.h"
38 adx 30 #include "send.h"
39 michael 1309 #include "conf.h"
40 adx 30 #include "parse.h"
41     #include "modules.h"
42    
43    
44 michael 5638 #define WHOWAS_MAX_REPLIES 20 /* Does only apply to remote clients */
45    
46 adx 30 static void
47 michael 3338 do_whowas(struct Client *source_p, const int parc, char *parv[])
48 adx 30 {
49     int cur = 0;
50     int max = -1;
51 michael 4815 const dlink_node *node = NULL;
52 adx 30
53 michael 2076 if (parc > 2 && !EmptyString(parv[2]))
54 michael 5638 max = atoi(parv[2]);
55 adx 30
56 michael 5638 if (!MyConnect(source_p) && (max <= 0 || max > WHOWAS_MAX_REPLIES))
57     max = WHOWAS_MAX_REPLIES;
58    
59 michael 4815 DLINK_FOREACH(node, WHOWASHASH[strhash(parv[1])].head)
60 michael 1358 {
61 michael 4815 const struct Whowas *temp = node->data;
62 adx 30
63 michael 2076 if (!irccmp(parv[1], temp->name))
64 adx 30 {
65 michael 3109 sendto_one_numeric(source_p, &me, RPL_WHOWASUSER, temp->name,
66     temp->username, temp->hostname,
67     temp->realname);
68 adx 30
69 michael 5631 if (HasUMode(source_p, UMODE_OPER))
70     if (strcmp(temp->sockhost, "0")) /* XXX: TBR */
71     sendto_one_numeric(source_p, &me, RPL_WHOISACTUALLY, temp->name,
72     temp->username, temp->hostname,
73     temp->sockhost);
74    
75 michael 4819 if (!IsDigit(temp->account[0]) && temp->account[0] != '*')
76     sendto_one_numeric(source_p, &me, RPL_WHOISACCOUNT, temp->name, temp->account, "was");
77 michael 4767
78 michael 2748 if ((temp->shide || ConfigServerHide.hide_servers) && !HasUMode(source_p, UMODE_OPER))
79 michael 3109 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name,
80 michael 4340 ConfigServerInfo.network_name, myctime(temp->logoff));
81 adx 30 else
82 michael 3109 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, temp->name,
83     temp->servername, myctime(temp->logoff));
84 michael 1358 ++cur;
85 adx 30 }
86    
87     if (max > 0 && cur >= max)
88     break;
89     }
90    
91     if (!cur)
92 michael 3109 sendto_one_numeric(source_p, &me, ERR_WASNOSUCHNICK, parv[1]);
93 adx 30
94 michael 3109 sendto_one_numeric(source_p, &me, RPL_ENDOFWHOWAS, parv[1]);
95 adx 30 }
96 michael 1230
97 michael 3295 /*! \brief WHOWAS command handler
98     *
99     * \param source_p Pointer to allocated Client struct from which the message
100     * originally comes from. This can be a local or remote client.
101     * \param parc Integer holding the number of supplied arguments.
102     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
103     * pointers.
104     * \note Valid arguments for this command are:
105     * - parv[0] = command
106     * - parv[1] = nickname
107     * - parv[2] = count
108     * - parv[3] = nickname/servername
109     */
110 michael 2820 static int
111 michael 3156 m_whowas(struct Client *source_p, int parc, char *parv[])
112 michael 1230 {
113     static time_t last_used = 0;
114    
115     if (parc < 2 || EmptyString(parv[1]))
116     {
117 michael 3109 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
118 michael 2820 return 0;
119 michael 1230 }
120    
121 michael 4340 if ((last_used + ConfigGeneral.pace_wait) > CurrentTime)
122 michael 1230 {
123 michael 4759 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "WHOWAS");
124 michael 2820 return 0;
125 michael 1230 }
126    
127     last_used = CurrentTime;
128    
129 michael 4720 if (!ConfigServerHide.disable_remote_commands)
130     if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME)
131 michael 2986 return 0;
132    
133 michael 3338 do_whowas(source_p, parc, parv);
134 michael 2820 return 0;
135 michael 1230 }
136    
137 michael 3295 /*! \brief WHOWAS command handler
138     *
139     * \param source_p Pointer to allocated Client struct from which the message
140     * originally comes from. This can be a local or remote client.
141     * \param parc Integer holding the number of supplied arguments.
142     * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
143     * pointers.
144     * \note Valid arguments for this command are:
145     * - parv[0] = command
146     * - parv[1] = nickname
147     * - parv[2] = count
148     * - parv[3] = nickname/servername
149     */
150 michael 2820 static int
151 michael 3346 ms_whowas(struct Client *source_p, int parc, char *parv[])
152 michael 1230 {
153     if (parc < 2 || EmptyString(parv[1]))
154     {
155 michael 3109 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
156 michael 2820 return 0;
157 michael 1230 }
158    
159 michael 4720 if (hunt_server(source_p, ":%s WHOWAS %s %s :%s", 3, parc, parv) != HUNTED_ISME)
160     return 0;
161 michael 2986
162 michael 3338 do_whowas(source_p, parc, parv);
163 michael 2820 return 0;
164 michael 1230 }
165    
166 michael 2820 static struct Message whowas_msgtab =
167     {
168 michael 4545 "WHOWAS", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
169 michael 3346 { m_unregistered, m_whowas, ms_whowas, m_ignore, ms_whowas, m_ignore }
170 michael 1230 };
171    
172     static void
173     module_init(void)
174     {
175     mod_add_cmd(&whowas_msgtab);
176     }
177    
178     static void
179     module_exit(void)
180     {
181     mod_del_cmd(&whowas_msgtab);
182     }
183    
184 michael 2820 struct module module_entry =
185     {
186 michael 1230 .node = { NULL, NULL, NULL },
187     .name = NULL,
188     .version = "$Revision$",
189     .handle = NULL,
190     .modinit = module_init,
191     .modexit = module_exit,
192     .flags = 0
193     };

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision