1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
/*
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
*
* Copyright (c) 1997-2014 ircd-hybrid development team
*
* 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 2 of the License, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
/*! \file m_whois.c
* \brief Includes required functions for processing the WHOIS command.
* \version $Id$
*/
#include "stdinc.h"
#include "list.h"
#include "client.h"
#include "hash.h"
#include "channel.h"
#include "channel_mode.h"
#include "ircd.h"
#include "numeric.h"
#include "conf.h"
#include "s_misc.h"
#include "s_serv.h"
#include "s_user.h"
#include "send.h"
#include "irc_string.h"
#include "parse.h"
#include "modules.h"
/* whois_person()
*
* inputs - source_p client to report to
* - target_p client to report on
* output - NONE
* side effects -
*/
static void
whois_person(struct Client *source_p, struct Client *target_p)
{
char buf[IRCD_BUFSIZE] = { '\0' };
const dlink_node *lp = NULL;
char *t = NULL;
int cur_len = 0;
int show_ip = 0;
int mlen = 0;
int tlen = 0;
int reply_to_send = 0;
sendto_one(source_p, form_str(RPL_WHOISUSER), me.name,
source_p->name, target_p->name,
target_p->username, target_p->host, target_p->info);
cur_len = mlen = snprintf(buf, sizeof(buf), form_str(RPL_WHOISCHANNELS),
me.name, source_p->name, target_p->name, "");
t = buf + mlen;
DLINK_FOREACH(lp, target_p->channel.head)
{
const struct Membership *ms = lp->data;
int show = ShowChannel(source_p, ms->chptr);
if (show || HasUMode(source_p, UMODE_ADMIN))
{
if ((cur_len + 4 + strlen(ms->chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
{
*(t - 1) = '\0';
sendto_one(source_p, "%s", buf);
cur_len = mlen;
t = buf + mlen;
}
tlen = sprintf(t, "%s%s%s ", show ? "" : "~", get_member_status(ms, 1),
ms->chptr->chname);
t += tlen;
cur_len += tlen;
reply_to_send = 1;
}
}
if (reply_to_send)
{
*(t - 1) = '\0';
sendto_one(source_p, "%s", buf);
}
if ((ConfigServerHide.hide_servers || IsHidden(target_p->servptr)) &&
!(HasUMode(source_p, UMODE_OPER) || target_p == source_p))
sendto_one(source_p, form_str(RPL_WHOISSERVER),
me.name, source_p->name, target_p->name,
ConfigServerHide.hidden_name,
ServerInfo.network_desc);
else
sendto_one(source_p, form_str(RPL_WHOISSERVER),
me.name, source_p->name, target_p->name,
target_p->servptr->name, target_p->servptr->info);
if (HasUMode(target_p, UMODE_REGISTERED))
sendto_one(source_p, form_str(RPL_WHOISREGNICK),
me.name, source_p->name, target_p->name);
if (!IsDigit(target_p->svid[0]))
sendto_one(source_p, form_str(RPL_WHOISACCOUNT),
me.name, source_p->name, target_p->name,
target_p->svid);
if (target_p->away[0])
sendto_one(source_p, form_str(RPL_AWAY),
me.name, source_p->name, target_p->name,
target_p->away);
if (HasUMode(target_p, UMODE_CALLERID|UMODE_SOFTCALLERID))
{
int callerid = !!HasUMode(target_p, UMODE_CALLERID);
sendto_one(source_p, form_str(RPL_TARGUMODEG),
me.name, source_p->name, target_p->name,
callerid ? "+g" : "+G",
callerid ? "server side ignore" :
"server side ignore with the exception of common channels");
}
if (HasUMode(target_p, UMODE_OPER))
if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
sendto_one(source_p, form_str(RPL_WHOISOPERATOR), me.name,
source_p->name, target_p->name,
HasUMode(target_p, UMODE_ADMIN) ? "is a Server Administrator" :
"is an IRC Operator");
if (HasUMode(target_p, UMODE_WEBIRC))
sendto_one(source_p, form_str(RPL_WHOISTEXT),
me.name, source_p->name, target_p->name,
"User connected using a webirc gateway");
if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
{
unsigned int i = 0;
char *m = buf;
*m++ = '+';
for (i = 0; i < 128; ++i)
if (HasUMode(target_p, user_modes[i]))
*m++ = (char)i;
*m = '\0';
sendto_one(source_p, form_str(RPL_WHOISMODES), me.name,
source_p->name, target_p->name, buf);
}
if (target_p->sockhost[0] && strcmp(target_p->sockhost, "0"))
{
if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
show_ip = 1;
else if (IsIPSpoof(target_p))
show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips);
else
show_ip = 1;
sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
me.name, source_p->name, target_p->name,
show_ip ? target_p->sockhost : "255.255.255.255");
}
if (HasUMode(target_p, UMODE_SSL))
sendto_one(source_p, form_str(RPL_WHOISSECURE), me.name,
source_p->name, target_p->name);
if (!EmptyString(target_p->certfp))
if (target_p == source_p || HasUMode(source_p, UMODE_ADMIN))
sendto_one(source_p, form_str(RPL_WHOISCERTFP), me.name,
source_p->name, target_p->name, target_p->certfp);
if (MyConnect(target_p))
sendto_one(source_p, form_str(RPL_WHOISIDLE),
me.name, source_p->name, target_p->name,
idle_time_get(source_p, target_p),
target_p->localClient->firsttime);
}
/* do_whois()
*
* inputs - pointer to /whois source
* - number of parameters
* - pointer to parameters array
* output - pointer to void
* side effects - Does whois
*/
static void
do_whois(struct Client *source_p, const char *name)
{
struct Client *target_p = NULL;
if ((target_p = find_person(source_p->from, name)))
whois_person(source_p, target_p);
else if (!IsDigit(*name))
sendto_one(source_p, form_str(ERR_NOSUCHNICK),
me.name, source_p->name, name);
sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
me.name, source_p->name, name);
}
/*
** m_whois
** parv[0] = sender prefix
** parv[1] = nickname masklist
*/
static int
m_whois(struct Client *client_p, struct Client *source_p,
int parc, char *parv[])
{
static time_t last_used = 0;
if (parc < 2 || EmptyString(parv[1]))
{
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
me.name, source_p->name);
return 0;
}
if (parc > 2 && !EmptyString(parv[2]))
{
/* seeing as this is going across servers, we should limit it */
if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
{
sendto_one(source_p, form_str(RPL_LOAD2HI),
me.name, source_p->name);
return 0;
}
last_used = CurrentTime;
/*
* if we have serverhide enabled, they can either ask the clients
* server, or our server.. I dont see why they would need to ask
* anything else for info about the client.. --fl_
*/
if (ConfigServerHide.disable_remote_commands)
parv[1] = parv[2];
if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
parc, parv) != HUNTED_ISME)
return 0;
parv[1] = parv[2];
}
do_whois(source_p, parv[1]);
return 0;
}
/*
** mo_whois
** parv[0] = sender prefix
** parv[1] = nickname masklist
*/
static int
mo_whois(struct Client *client_p, struct Client *source_p,
int parc, char *parv[])
{
if (parc < 2 || EmptyString(parv[1]))
{
sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
me.name, source_p->name);
return 0;
}
if (parc > 2 && !EmptyString(parv[2]))
{
if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
parc, parv) != HUNTED_ISME)
return 0;
parv[1] = parv[2];
}
do_whois(source_p, parv[1]);
return 0;
}
static struct Message whois_msgtab =
{
"WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
{ m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
};
static void
module_init(void)
{
mod_add_cmd(&whois_msgtab);
}
static void
module_exit(void)
{
mod_del_cmd(&whois_msgtab);
}
struct module module_entry =
{
.node = { NULL, NULL, NULL },
.name = NULL,
.version = "$Revision$",
.handle = NULL,
.modinit = module_init,
.modexit = module_exit,
.flags = 0
};
|