ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 1874
Committed: Sat Apr 27 09:27:34 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 8207 byte(s)
Log Message:
- WHOIS may no longer accept wildcards

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_whois.c: Shows who a user is.
4 *
5 * Copyright (C) 2005 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "client.h"
28 #include "hash.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "ircd.h"
32 #include "numeric.h"
33 #include "conf.h"
34 #include "s_misc.h"
35 #include "s_serv.h"
36 #include "send.h"
37 #include "irc_string.h"
38 #include "parse.h"
39 #include "modules.h"
40
41
42 static void do_whois(struct Client *, int, char *[]);
43 static void whois_person(struct Client *, struct Client *);
44
45
46 /*
47 ** m_whois
48 ** parv[0] = sender prefix
49 ** parv[1] = nickname masklist
50 */
51 static void
52 m_whois(struct Client *client_p, struct Client *source_p,
53 int parc, char *parv[])
54 {
55 static time_t last_used = 0;
56
57 if (parc < 2 || EmptyString(parv[1]))
58 {
59 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
60 me.name, source_p->name);
61 return;
62 }
63
64 if (parc > 2 && !EmptyString(parv[2]))
65 {
66 /* seeing as this is going across servers, we should limit it */
67 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
68 {
69 sendto_one(source_p, form_str(RPL_LOAD2HI),
70 me.name, source_p->name);
71 return;
72 }
73
74 last_used = CurrentTime;
75
76 /* if we have serverhide enabled, they can either ask the clients
77 * server, or our server.. I dont see why they would need to ask
78 * anything else for info about the client.. --fl_
79 */
80 if (ConfigFileEntry.disable_remote)
81 parv[1] = parv[2];
82
83 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
84 parc, parv) != HUNTED_ISME)
85 return;
86
87 parv[1] = parv[2];
88 }
89
90 do_whois(source_p, parc, parv);
91 }
92
93 /*
94 ** mo_whois
95 ** parv[0] = sender prefix
96 ** parv[1] = nickname masklist
97 */
98 static void
99 mo_whois(struct Client *client_p, struct Client *source_p,
100 int parc, char *parv[])
101 {
102 if (parc < 2 || EmptyString(parv[1]))
103 {
104 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
105 me.name, source_p->name);
106 return;
107 }
108
109 if (parc > 2 && !EmptyString(parv[2]))
110 {
111 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
112 parc, parv) != HUNTED_ISME)
113 return;
114
115 parv[1] = parv[2];
116 }
117
118 do_whois(source_p, parc, parv);
119 }
120
121 /* do_whois()
122 *
123 * inputs - pointer to /whois source
124 * - number of parameters
125 * - pointer to parameters array
126 * output - pointer to void
127 * side effects - Does whois
128 */
129 static void
130 do_whois(struct Client *source_p, int parc, char *parv[])
131 {
132 struct Client *target_p = NULL;
133 char *nick = parv[1];
134 char *p = NULL;
135
136 if ((p = strchr(nick, ',')) != NULL)
137 *p = '\0';
138 if (*nick == '\0')
139 return;
140
141 if ((target_p = hash_find_client(nick)) && IsClient(target_p))
142 whois_person(source_p, target_p);
143 else if (!IsDigit(*nick))
144 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
145 me.name, source_p->name, nick);
146
147 sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
148 me.name, source_p->name, nick);
149 }
150
151 /* whois_person()
152 *
153 * inputs - source_p client to report to
154 * - target_p client to report on
155 * output - NONE
156 * side effects -
157 */
158 static void
159 whois_person(struct Client *source_p, struct Client *target_p)
160 {
161 char buf[IRCD_BUFSIZE];
162 const dlink_node *lp = NULL;
163 char *t = NULL;
164 int cur_len = 0;
165 int show_ip = 0;
166 int mlen = 0;
167 int tlen = 0;
168 int reply_to_send = 0;
169
170 sendto_one(source_p, form_str(RPL_WHOISUSER), me.name,
171 source_p->name, target_p->name,
172 target_p->username, target_p->host, target_p->info);
173
174 cur_len = mlen = snprintf(buf, sizeof(buf), form_str(RPL_WHOISCHANNELS),
175 me.name, source_p->name, target_p->name, "");
176 t = buf + mlen;
177
178 DLINK_FOREACH(lp, target_p->channel.head)
179 {
180 const struct Membership *ms = lp->data;
181
182 if (ShowChannel(source_p, ms->chptr))
183 {
184 if ((cur_len + 3 + strlen(ms->chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
185 {
186 *(t - 1) = '\0';
187 sendto_one(source_p, "%s", buf);
188 cur_len = mlen;
189 t = buf + mlen;
190 }
191
192 tlen = sprintf(t, "%s%s ", get_member_status(ms, 1), ms->chptr->chname);
193 t += tlen;
194 cur_len += tlen;
195 reply_to_send = 1;
196 }
197 }
198
199 if (reply_to_send)
200 {
201 *(t - 1) = '\0';
202 sendto_one(source_p, "%s", buf);
203 }
204
205 if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.hide_servers || target_p == source_p)
206 sendto_one(source_p, form_str(RPL_WHOISSERVER),
207 me.name, source_p->name, target_p->name,
208 target_p->servptr->name, target_p->servptr->info);
209 else
210 sendto_one(source_p, form_str(RPL_WHOISSERVER),
211 me.name, source_p->name, target_p->name,
212 ConfigServerHide.hidden_name,
213 ServerInfo.network_desc);
214
215 if (HasUMode(target_p, UMODE_REGISTERED))
216 sendto_one(source_p, form_str(RPL_WHOISREGNICK),
217 me.name, source_p->name, target_p->name);
218
219 if (target_p->away[0])
220 sendto_one(source_p, form_str(RPL_AWAY),
221 me.name, source_p->name, target_p->name,
222 target_p->away);
223
224 if (HasUMode(target_p, UMODE_CALLERID) && !HasUMode(target_p, UMODE_SOFTCALLERID))
225 sendto_one(source_p, form_str(RPL_TARGUMODEG),
226 me.name, source_p->name, target_p->name);
227
228 if (HasUMode(target_p, UMODE_OPER))
229 if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
230 sendto_one(source_p, form_str(HasUMode(target_p, UMODE_ADMIN) ? RPL_WHOISADMIN :
231 RPL_WHOISOPERATOR),
232 me.name, source_p->name, target_p->name);
233
234 if (target_p->sockhost[0] && strcmp(target_p->sockhost, "0"))
235 {
236 if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
237 show_ip = 1;
238 else if (IsIPSpoof(target_p))
239 show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips);
240 else
241 show_ip = 1;
242
243 sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
244 me.name, source_p->name, target_p->name,
245 show_ip ? target_p->sockhost : "255.255.255.255");
246 }
247
248 if (MyConnect(target_p)) /* Can't do any of this if not local! db */
249 {
250 #ifdef HAVE_LIBCRYPTO
251 if (target_p->localClient->fd.ssl)
252 sendto_one(source_p, form_str(RPL_WHOISSECURE),
253 me.name, source_p->name, target_p->name);
254 #endif
255 sendto_one(source_p, form_str(RPL_WHOISIDLE),
256 me.name, source_p->name, target_p->name,
257 idle_time_get(source_p, target_p),
258 target_p->localClient->firsttime);
259
260 if (HasUMode(target_p, UMODE_OPER) && target_p != source_p)
261 if (HasUMode(target_p, UMODE_SPY))
262 sendto_one(target_p, ":%s NOTICE %s :*** Notice -- %s (%s@%s) [%s] is doing "
263 "a whois on you", me.name, target_p->name, source_p->name,
264 source_p->username, source_p->host, source_p->servptr->name);
265 }
266 }
267
268 static struct Message whois_msgtab = {
269 "WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
270 { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
271 };
272
273 static void
274 module_init(void)
275 {
276 mod_add_cmd(&whois_msgtab);
277 }
278
279 static void
280 module_exit(void)
281 {
282 mod_del_cmd(&whois_msgtab);
283 }
284
285 struct module module_entry = {
286 .node = { NULL, NULL, NULL },
287 .name = NULL,
288 .version = "$Revision$",
289 .handle = NULL,
290 .modinit = module_init,
291 .modexit = module_exit,
292 .flags = 0
293 };

Properties

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