ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 2580
Committed: Wed Nov 20 20:46:57 2013 UTC (12 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 9259 byte(s)
Log Message:
- Better distinguishing between usermode +g and +G in both /whois and /privmsg
  as suggested by Adam <adam@anope.org>

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

Properties

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