ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_whois.c
Revision: 8481
Committed: Wed Apr 4 14:18:04 2018 UTC (7 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 10720 byte(s)
Log Message:
- m_whois.c:whois_person(): services clients are now tagged with 'is a Network Service' in "WHOIS"

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2018 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_whois.c
23 * \brief Includes required functions for processing the WHOIS command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "hash.h"
31 #include "channel.h"
32 #include "channel_mode.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "conf.h"
36 #include "misc.h"
37 #include "server.h"
38 #include "user.h"
39 #include "send.h"
40 #include "irc_string.h"
41 #include "parse.h"
42 #include "modules.h"
43
44
45 static int
46 whois_can_see_channels(struct Channel *chptr,
47 struct Client *source_p,
48 struct Client *target_p)
49 {
50 if (PubChannel(chptr) && !HasUMode(target_p, UMODE_HIDECHANS))
51 return 1;
52
53 if (source_p == target_p || IsMember(source_p, chptr))
54 return 1;
55
56 if (HasUMode(source_p, UMODE_OPER))
57 return 2;
58 return 0;
59 }
60
61 /* whois_person()
62 *
63 * inputs - source_p client to report to
64 * - target_p client to report on
65 * output - NONE
66 * side effects -
67 */
68 static void
69 whois_person(struct Client *source_p, struct Client *target_p)
70 {
71 char buf[IRCD_BUFSIZE] = "";
72 dlink_node *node;
73 const struct ServicesTag *svstag = NULL;
74 char *t = NULL;
75 int cur_len = 0;
76 int mlen = 0;
77 int tlen = 0;
78 int reply_to_send = 0;
79
80 sendto_one_numeric(source_p, &me, RPL_WHOISUSER, target_p->name,
81 target_p->username, target_p->host,
82 target_p->info);
83
84 cur_len = mlen = snprintf(buf, sizeof(buf), numeric_form(RPL_WHOISCHANNELS),
85 me.name, source_p->name, target_p->name, "");
86 t = buf + mlen;
87
88 DLINK_FOREACH(node, target_p->channel.head)
89 {
90 const struct Membership *member = node->data;
91 int show = whois_can_see_channels(member->chptr, source_p, target_p);
92
93 if (show)
94 {
95 if ((cur_len + 4 + member->chptr->name_len + 1) > (IRCD_BUFSIZE - 2))
96 {
97 *(t - 1) = '\0';
98 sendto_one(source_p, "%s", buf);
99 cur_len = mlen;
100 t = buf + mlen;
101 }
102
103 tlen = sprintf(t, "%s%s%s ", show == 2 ? "~" : "", get_member_status(member, 1),
104 member->chptr->name);
105 t += tlen;
106 cur_len += tlen;
107 reply_to_send = 1;
108 }
109 }
110
111 if (reply_to_send)
112 {
113 *(t - 1) = '\0';
114 sendto_one(source_p, "%s", buf);
115 }
116
117 if ((ConfigServerHide.hide_servers || IsHidden(target_p->servptr)) &&
118 !(HasUMode(source_p, UMODE_OPER) || source_p == target_p))
119 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, target_p->name,
120 ConfigServerHide.hidden_name,
121 ConfigServerInfo.network_desc);
122 else
123 sendto_one_numeric(source_p, &me, RPL_WHOISSERVER, target_p->name,
124 target_p->servptr->name, target_p->servptr->info);
125
126 if (HasUMode(target_p, UMODE_REGISTERED))
127 sendto_one_numeric(source_p, &me, RPL_WHOISREGNICK, target_p->name);
128
129 if (strcmp(target_p->account, "*"))
130 sendto_one_numeric(source_p, &me, RPL_WHOISACCOUNT, target_p->name,
131 target_p->account, "is");
132
133 if (target_p->away[0])
134 sendto_one_numeric(source_p, &me, RPL_AWAY, target_p->name,
135 target_p->away);
136
137 if (HasUMode(target_p, UMODE_CALLERID | UMODE_SOFTCALLERID))
138 {
139 const int callerid = !!HasUMode(target_p, UMODE_CALLERID);
140
141 sendto_one_numeric(source_p, &me, RPL_TARGUMODEG, target_p->name,
142 callerid ? "+g" : "+G",
143 callerid ? "server side ignore" :
144 "server side ignore with the exception of common channels");
145 }
146
147 if (HasUMode(target_p, UMODE_OPER) || HasFlag(target_p, FLAGS_SERVICE))
148 {
149 if (!HasUMode(target_p, UMODE_HIDDEN) || HasUMode(source_p, UMODE_OPER))
150 {
151 if (target_p->svstags.head)
152 svstag = target_p->svstags.head->data;
153
154 if (!svstag || svstag->numeric != RPL_WHOISOPERATOR)
155 {
156 const char *text;
157 if (HasFlag(target_p, FLAGS_SERVICE))
158 text = "is a Network Service";
159 else if (HasUMode(target_p, UMODE_ADMIN))
160 text = "is a Server Administrator";
161 else /* HasUMode(target_p, UMODE_OPER) == true */
162 text = "is an IRC Operator";
163 sendto_one_numeric(source_p, &me, RPL_WHOISOPERATOR, target_p->name, text);
164 }
165 }
166 }
167
168 DLINK_FOREACH(node, target_p->svstags.head)
169 {
170 svstag = node->data;
171
172 if (svstag->numeric == RPL_WHOISOPERATOR)
173 if (HasUMode(target_p, UMODE_HIDDEN) && !HasUMode(source_p, UMODE_OPER))
174 continue;
175
176 if (svstag->umodes == 0 || HasUMode(source_p, svstag->umodes))
177 sendto_one_numeric(source_p, &me, svstag->numeric | SND_EXPLICIT, "%s :%s",
178 target_p->name, svstag->tag);
179 }
180
181 if (HasUMode(target_p, UMODE_WEBIRC))
182 sendto_one_numeric(source_p, &me, RPL_WHOISTEXT, target_p->name,
183 "User connected using a webirc gateway");
184
185 if (HasUMode(source_p, UMODE_OPER) || source_p == target_p)
186 {
187 char *m = buf;
188 *m++ = '+';
189
190 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
191 if (HasUMode(target_p, tab->flag))
192 *m++ = tab->c;
193 *m = '\0';
194
195 sendto_one_numeric(source_p, &me, RPL_WHOISMODES, target_p->name, buf);
196 }
197
198 if (HasUMode(source_p, UMODE_OPER) || source_p == target_p)
199 sendto_one_numeric(source_p, &me, RPL_WHOISACTUALLY, target_p->name,
200 target_p->username, target_p->realhost,
201 target_p->sockhost);
202
203 if (HasUMode(target_p, UMODE_SSL))
204 sendto_one_numeric(source_p, &me, RPL_WHOISSECURE, target_p->name);
205
206 if (!EmptyString(target_p->certfp))
207 if (HasUMode(source_p, UMODE_OPER) || target_p == source_p)
208 sendto_one_numeric(source_p, &me, RPL_WHOISCERTFP, target_p->name, target_p->certfp);
209
210 if (MyConnect(target_p))
211 if (!HasUMode(target_p, UMODE_HIDEIDLE) || HasUMode(source_p, UMODE_OPER) ||
212 source_p == target_p)
213 sendto_one_numeric(source_p, &me, RPL_WHOISIDLE, target_p->name,
214 client_get_idle_time(source_p, target_p),
215 target_p->connection->firsttime);
216
217 if (HasUMode(target_p, UMODE_SPY) && source_p != target_p)
218 sendto_one_notice(target_p, &me, ":*** Notice -- %s (%s@%s) [%s] is doing a /whois on you",
219 source_p->name, source_p->username, source_p->host, source_p->servptr->name);
220 }
221
222 /* do_whois()
223 *
224 * inputs - pointer to /whois source
225 * - number of parameters
226 * - pointer to parameters array
227 * output - pointer to void
228 * side effects - Does whois
229 */
230 static void
231 do_whois(struct Client *source_p, const char *name)
232 {
233 struct Client *target_p;
234
235 if ((target_p = hash_find_client(name)) && IsClient(target_p))
236 whois_person(source_p, target_p);
237 else
238 sendto_one_numeric(source_p, &me, ERR_NOSUCHNICK, name);
239
240 sendto_one_numeric(source_p, &me, RPL_ENDOFWHOIS, name);
241 }
242
243 /*! \brief WHOIS command handler
244 *
245 * \param source_p Pointer to allocated Client struct from which the message
246 * originally comes from. This can be a local or remote client.
247 * \param parc Integer holding the number of supplied arguments.
248 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
249 * pointers.
250 * \note Valid arguments for this command are:
251 * - parv[0] = command
252 * - parv[1] = nickname/servername
253 * - parv[2] = nickname
254 */
255 static int
256 m_whois(struct Client *source_p, int parc, char *parv[])
257 {
258 static uintmax_t last_used = 0;
259
260 if (parc < 2 || EmptyString(parv[1]))
261 {
262 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
263 return 0;
264 }
265
266 if (parc > 2 && !EmptyString(parv[2]))
267 {
268 /* seeing as this is going across servers, we should limit it */
269 if ((last_used + ConfigGeneral.pace_wait_simple) > CurrentTime)
270 {
271 sendto_one_numeric(source_p, &me, RPL_LOAD2HI, "WHOIS");
272 return 0;
273 }
274
275 last_used = CurrentTime;
276
277 /*
278 * if we have serverhide enabled, they can either ask the clients
279 * server, or our server.. I don't see why they would need to ask
280 * anything else for info about the client.. --fl_
281 */
282 if (ConfigServerHide.disable_remote_commands)
283 parv[1] = parv[2];
284
285 if (server_hunt(source_p, ":%s WHOIS %s :%s", 1, parc, parv)->ret != HUNTED_ISME)
286 return 0;
287
288 parv[1] = parv[2];
289 }
290
291 do_whois(source_p, parv[1]);
292 return 0;
293 }
294
295 /*! \brief WHOIS command handler
296 *
297 * \param source_p Pointer to allocated Client struct from which the message
298 * originally comes from. This can be a local or remote client.
299 * \param parc Integer holding the number of supplied arguments.
300 * \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL
301 * pointers.
302 * \note Valid arguments for this command are:
303 * - parv[0] = command
304 * - parv[1] = nickname/servername
305 * - parv[2] = nickname
306 */
307 static int
308 mo_whois(struct Client *source_p, int parc, char *parv[])
309 {
310 if (parc < 2 || EmptyString(parv[1]))
311 {
312 sendto_one_numeric(source_p, &me, ERR_NONICKNAMEGIVEN);
313 return 0;
314 }
315
316 if (parc > 2 && !EmptyString(parv[2]))
317 {
318 if (server_hunt(source_p, ":%s WHOIS %s :%s", 1, parc, parv)->ret != HUNTED_ISME)
319 return 0;
320
321 parv[1] = parv[2];
322 }
323
324 do_whois(source_p, parv[1]);
325 return 0;
326 }
327
328 static struct Message whois_msgtab =
329 {
330 .cmd = "WHOIS",
331 .args_max = MAXPARA,
332 .handlers[UNREGISTERED_HANDLER] = m_unregistered,
333 .handlers[CLIENT_HANDLER] = m_whois,
334 .handlers[SERVER_HANDLER] = mo_whois,
335 .handlers[ENCAP_HANDLER] = m_ignore,
336 .handlers[OPER_HANDLER] = mo_whois
337 };
338
339 static void
340 module_init(void)
341 {
342 mod_add_cmd(&whois_msgtab);
343 }
344
345 static void
346 module_exit(void)
347 {
348 mod_del_cmd(&whois_msgtab);
349 }
350
351 struct module module_entry =
352 {
353 .version = "$Revision$",
354 .modinit = module_init,
355 .modexit = module_exit,
356 };

Properties

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