ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 2508
Committed: Sun Oct 27 16:32:15 2013 UTC (12 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 8459 byte(s)
Log Message:
- Admins may now see +s channels a user is in with /WHOIS

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 /* whois_person()
43 *
44 * inputs - source_p client to report to
45 * - target_p client to report on
46 * output - NONE
47 * side effects -
48 */
49 static void
50 whois_person(struct Client *source_p, struct Client *target_p)
51 {
52 char buf[IRCD_BUFSIZE] = { '\0' };
53 const dlink_node *lp = NULL;
54 char *t = NULL;
55 int cur_len = 0;
56 int show_ip = 0;
57 int mlen = 0;
58 int tlen = 0;
59 int reply_to_send = 0;
60
61 sendto_one(source_p, form_str(RPL_WHOISUSER), me.name,
62 source_p->name, target_p->name,
63 target_p->username, target_p->host, target_p->info);
64
65 cur_len = mlen = snprintf(buf, sizeof(buf), form_str(RPL_WHOISCHANNELS),
66 me.name, source_p->name, target_p->name, "");
67 t = buf + mlen;
68
69 DLINK_FOREACH(lp, target_p->channel.head)
70 {
71 const struct Membership *ms = lp->data;
72 int show = ShowChannel(source_p, ms->chptr);
73
74 if (show || HasUMode(source_p, UMODE_ADMIN))
75 {
76 if ((cur_len + 4 + strlen(ms->chptr->chname) + 1) > (IRCD_BUFSIZE - 2))
77 {
78 *(t - 1) = '\0';
79 sendto_one(source_p, "%s", buf);
80 cur_len = mlen;
81 t = buf + mlen;
82 }
83
84 tlen = sprintf(t, "%s%s%s ", show ? "" : "~", get_member_status(ms, 1),
85 ms->chptr->chname);
86 t += tlen;
87 cur_len += tlen;
88 reply_to_send = 1;
89 }
90 }
91
92 if (reply_to_send)
93 {
94 *(t - 1) = '\0';
95 sendto_one(source_p, "%s", buf);
96 }
97
98 if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.hide_servers || target_p == source_p)
99 sendto_one(source_p, form_str(RPL_WHOISSERVER),
100 me.name, source_p->name, target_p->name,
101 target_p->servptr->name, target_p->servptr->info);
102 else
103 sendto_one(source_p, form_str(RPL_WHOISSERVER),
104 me.name, source_p->name, target_p->name,
105 ConfigServerHide.hidden_name,
106 ServerInfo.network_desc);
107
108 if (HasUMode(target_p, UMODE_REGISTERED))
109 sendto_one(source_p, form_str(RPL_WHOISREGNICK),
110 me.name, source_p->name, target_p->name);
111
112 if (!IsDigit(target_p->svid[0]))
113 sendto_one(source_p, form_str(RPL_WHOISACCOUNT),
114 me.name, source_p->name, target_p->name,
115 target_p->svid);
116
117 if (target_p->away[0])
118 sendto_one(source_p, form_str(RPL_AWAY),
119 me.name, source_p->name, target_p->name,
120 target_p->away);
121
122 if (HasUMode(target_p, UMODE_CALLERID) && !HasUMode(target_p, UMODE_SOFTCALLERID))
123 sendto_one(source_p, form_str(RPL_TARGUMODEG),
124 me.name, source_p->name, target_p->name);
125
126 if (HasUMode(target_p, UMODE_OPER))
127 if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
128 sendto_one(source_p, form_str(HasUMode(target_p, UMODE_ADMIN) ? RPL_WHOISADMIN :
129 RPL_WHOISOPERATOR),
130 me.name, source_p->name, target_p->name);
131
132 if (target_p->sockhost[0] && strcmp(target_p->sockhost, "0"))
133 {
134 if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
135 show_ip = 1;
136 else if (IsIPSpoof(target_p))
137 show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips);
138 else
139 show_ip = 1;
140
141 sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
142 me.name, source_p->name, target_p->name,
143 show_ip ? target_p->sockhost : "255.255.255.255");
144 }
145
146 if (HasUMode(target_p, UMODE_SSL))
147 sendto_one(source_p, form_str(RPL_WHOISSECURE), me.name,
148 source_p->name, target_p->name);
149
150 if (!EmptyString(target_p->certfp))
151 if (target_p == source_p || HasUMode(source_p, UMODE_OPER))
152 sendto_one(source_p, form_str(RPL_WHOISCERTFP), me.name,
153 source_p->name, target_p->name, target_p->certfp);
154
155 if (MyConnect(target_p))
156 {
157 sendto_one(source_p, form_str(RPL_WHOISIDLE),
158 me.name, source_p->name, target_p->name,
159 idle_time_get(source_p, target_p),
160 target_p->localClient->firsttime);
161
162 if (HasUMode(target_p, UMODE_OPER) && target_p != source_p)
163 if (HasUMode(target_p, UMODE_SPY))
164 sendto_one(target_p, ":%s NOTICE %s :*** Notice -- %s (%s@%s) [%s] is doing "
165 "a whois on you", me.name, target_p->name, source_p->name,
166 source_p->username, source_p->host, source_p->servptr->name);
167 }
168 }
169
170 /* do_whois()
171 *
172 * inputs - pointer to /whois source
173 * - number of parameters
174 * - pointer to parameters array
175 * output - pointer to void
176 * side effects - Does whois
177 */
178 static void
179 do_whois(struct Client *source_p, const char *name)
180 {
181 struct Client *target_p = NULL;
182
183 if ((target_p = hash_find_client(name)) && IsClient(target_p))
184 whois_person(source_p, target_p);
185 else if (!IsDigit(*name))
186 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
187 me.name, source_p->name, name);
188
189 sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
190 me.name, source_p->name, name);
191 }
192
193 /*
194 ** m_whois
195 ** parv[0] = sender prefix
196 ** parv[1] = nickname masklist
197 */
198 static void
199 m_whois(struct Client *client_p, struct Client *source_p,
200 int parc, char *parv[])
201 {
202 static time_t last_used = 0;
203
204 if (parc < 2 || EmptyString(parv[1]))
205 {
206 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
207 me.name, source_p->name);
208 return;
209 }
210
211 if (parc > 2 && !EmptyString(parv[2]))
212 {
213 /* seeing as this is going across servers, we should limit it */
214 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
215 {
216 sendto_one(source_p, form_str(RPL_LOAD2HI),
217 me.name, source_p->name);
218 return;
219 }
220
221 last_used = CurrentTime;
222
223 /*
224 * if we have serverhide enabled, they can either ask the clients
225 * server, or our server.. I dont see why they would need to ask
226 * anything else for info about the client.. --fl_
227 */
228 if (ConfigServerHide.disable_remote_commands)
229 parv[1] = parv[2];
230
231 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
232 parc, parv) != HUNTED_ISME)
233 return;
234
235 parv[1] = parv[2];
236 }
237
238 do_whois(source_p, parv[1]);
239 }
240
241 /*
242 ** mo_whois
243 ** parv[0] = sender prefix
244 ** parv[1] = nickname masklist
245 */
246 static void
247 mo_whois(struct Client *client_p, struct Client *source_p,
248 int parc, char *parv[])
249 {
250 if (parc < 2 || EmptyString(parv[1]))
251 {
252 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
253 me.name, source_p->name);
254 return;
255 }
256
257 if (parc > 2 && !EmptyString(parv[2]))
258 {
259 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
260 parc, parv) != HUNTED_ISME)
261 return;
262
263 parv[1] = parv[2];
264 }
265
266 do_whois(source_p, parv[1]);
267 }
268
269 static struct Message whois_msgtab = {
270 "WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
271 { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
272 };
273
274 static void
275 module_init(void)
276 {
277 mod_add_cmd(&whois_msgtab);
278 }
279
280 static void
281 module_exit(void)
282 {
283 mod_del_cmd(&whois_msgtab);
284 }
285
286 struct module module_entry = {
287 .node = { NULL, NULL, NULL },
288 .name = NULL,
289 .version = "$Revision$",
290 .handle = NULL,
291 .modinit = module_init,
292 .modexit = module_exit,
293 .flags = 0
294 };

Properties

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