ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/newio/modules/m_whois.c
Revision: 2581
Committed: Wed Nov 20 20:54:42 2013 UTC (10 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 8912 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 "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|UMODE_SOFTCALLERID))
123 {
124 int callerid = !!HasUMode(target_p, UMODE_CALLERID);
125 sendto_one(source_p, form_str(RPL_TARGUMODEG),
126 me.name, source_p->name, target_p->name,
127 callerid ? "+g" : "+G",
128 callerid ? "server side ignore" :
129 "server side ignore with the exception of common channels");
130 }
131
132 if (HasUMode(target_p, UMODE_OPER))
133 if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
134 sendto_one(source_p, form_str(HasUMode(target_p, UMODE_ADMIN) ? RPL_WHOISADMIN :
135 RPL_WHOISOPERATOR),
136 me.name, source_p->name, target_p->name);
137
138 if (HasUMode(target_p, UMODE_WEBIRC))
139 sendto_one(source_p, form_str(RPL_WHOISTEXT),
140 me.name, source_p->name, target_p->name,
141 "User connected using a webirc gateway");
142
143 if (target_p->sockhost[0] && strcmp(target_p->sockhost, "0"))
144 {
145 if (HasUMode(source_p, UMODE_ADMIN) || source_p == target_p)
146 show_ip = 1;
147 else if (IsIPSpoof(target_p))
148 show_ip = (HasUMode(source_p, UMODE_OPER) && !ConfigFileEntry.hide_spoof_ips);
149 else
150 show_ip = 1;
151
152 sendto_one(source_p, form_str(RPL_WHOISACTUALLY),
153 me.name, source_p->name, target_p->name,
154 show_ip ? target_p->sockhost : "255.255.255.255");
155 }
156
157 if (HasUMode(target_p, UMODE_SSL))
158 sendto_one(source_p, form_str(RPL_WHOISSECURE), me.name,
159 source_p->name, target_p->name);
160
161 if (!EmptyString(target_p->certfp))
162 if (target_p == source_p || HasUMode(source_p, UMODE_ADMIN))
163 sendto_one(source_p, form_str(RPL_WHOISCERTFP), me.name,
164 source_p->name, target_p->name, target_p->certfp);
165
166 if (MyConnect(target_p))
167 {
168 sendto_one(source_p, form_str(RPL_WHOISIDLE),
169 me.name, source_p->name, target_p->name,
170 idle_time_get(source_p, target_p),
171 target_p->localClient->firsttime);
172
173 if (HasUMode(target_p, UMODE_OPER) && target_p != source_p)
174 if (HasUMode(target_p, UMODE_SPY))
175 sendto_one(target_p, ":%s NOTICE %s :*** Notice -- %s (%s@%s) [%s] is doing "
176 "a whois on you", me.name, target_p->name, source_p->name,
177 source_p->username, source_p->host, source_p->servptr->name);
178 }
179 }
180
181 /* do_whois()
182 *
183 * inputs - pointer to /whois source
184 * - number of parameters
185 * - pointer to parameters array
186 * output - pointer to void
187 * side effects - Does whois
188 */
189 static int
190 do_whois(struct Client *source_p, const char *name)
191 {
192 struct Client *target_p = NULL;
193
194 if ((target_p = hash_find_client(name)) && IsClient(target_p))
195 whois_person(source_p, target_p);
196 else if (!IsDigit(*name))
197 sendto_one(source_p, form_str(ERR_NOSUCHNICK),
198 me.name, source_p->name, name);
199
200 sendto_one(source_p, form_str(RPL_ENDOFWHOIS),
201 me.name, source_p->name, name);
202 return 0;
203 }
204
205 /*
206 ** m_whois
207 ** parv[0] = sender prefix
208 ** parv[1] = nickname masklist
209 */
210 static int
211 m_whois(struct Client *client_p, struct Client *source_p,
212 int parc, char *parv[])
213 {
214 static time_t last_used = 0;
215
216 if (parc < 2 || EmptyString(parv[1]))
217 {
218 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
219 me.name, source_p->name);
220 return 0;
221 }
222
223 if (parc > 2 && !EmptyString(parv[2]))
224 {
225 /* seeing as this is going across servers, we should limit it */
226 if ((last_used + ConfigFileEntry.pace_wait_simple) > CurrentTime)
227 {
228 sendto_one(source_p, form_str(RPL_LOAD2HI),
229 me.name, source_p->name);
230 return 0;
231 }
232
233 last_used = CurrentTime;
234
235 /*
236 * if we have serverhide enabled, they can either ask the clients
237 * server, or our server.. I dont see why they would need to ask
238 * anything else for info about the client.. --fl_
239 */
240 if (ConfigServerHide.disable_remote_commands)
241 parv[1] = parv[2];
242
243 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
244 parc, parv) != HUNTED_ISME)
245 return 0;
246
247 parv[1] = parv[2];
248 }
249
250 return do_whois(source_p, parv[1]);
251 }
252
253 /*
254 ** mo_whois
255 ** parv[0] = sender prefix
256 ** parv[1] = nickname masklist
257 */
258 static int
259 mo_whois(struct Client *client_p, struct Client *source_p,
260 int parc, char *parv[])
261 {
262 if (parc < 2 || EmptyString(parv[1]))
263 {
264 sendto_one(source_p, form_str(ERR_NONICKNAMEGIVEN),
265 me.name, source_p->name);
266 return 0;
267 }
268
269 if (parc > 2 && !EmptyString(parv[2]))
270 {
271 if (hunt_server(client_p, source_p, ":%s WHOIS %s :%s", 1,
272 parc, parv) != HUNTED_ISME)
273 return 0;
274
275 parv[1] = parv[2];
276 }
277
278 return do_whois(source_p, parv[1]);
279 }
280
281 static struct Message whois_msgtab =
282 {
283 "WHOIS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
284 { m_unregistered, m_whois, mo_whois, m_ignore, mo_whois, m_ignore }
285 };
286
287 static void
288 module_init(void)
289 {
290 mod_add_cmd(&whois_msgtab);
291 }
292
293 static void
294 module_exit(void)
295 {
296 mod_del_cmd(&whois_msgtab);
297 }
298
299 struct module module_entry =
300 {
301 .node = { NULL, NULL, NULL },
302 .name = NULL,
303 .version = "$Revision$",
304 .handle = NULL,
305 .modinit = module_init,
306 .modexit = module_exit,
307 .flags = 0
308 };

Properties

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