ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.1.x/modules/m_whois.c
Revision: 2512
Committed: Sun Oct 27 18:59:49 2013 UTC (11 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 8663 byte(s)
Log Message:
- Added usermode +W. Users connected via a webirc gateway get this
  mode set by servers.
- /WHOIS now shows whether a client is connected via a webirc
  gateway

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

Properties

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