ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 1997
Committed: Sat May 11 17:35:07 2013 UTC (13 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 8077 byte(s)
Log Message:
- Mostly style cleanups & whitespace changes

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

Properties

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