2 * IRC - Internet Relay Chat, ircd/m_trace.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * See file AUTHORS in IRC package for additional names of
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 1, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * m_functions execute protocol messages on this server:
29 * cptr is always NON-NULL, pointing to a *LOCAL* client
30 * structure (with an open socket connected!). This
31 * identifies the physical socket where the message
32 * originated (or which caused the m_function to be
33 * executed--some m_functions may call others...).
35 * sptr is the source of the message, defined by the
36 * prefix part of the message if present. If not
37 * or prefix not found, then sptr==cptr.
39 * (!IsServer(cptr)) => (cptr == sptr), because
40 * prefixes are taken *only* from servers...
43 * (sptr == cptr) => the message didn't
46 * (sptr != cptr && IsServer(sptr) means
47 * the prefix specified servername. (?)
49 * (sptr != cptr && !IsServer(sptr) means
50 * that message originated from a remote
55 * (!IsServer(sptr)) means that, sptr can safely
56 * taken as defining the target structure of the
57 * message in this server.
59 * *Always* true (if 'parse' and others are working correct):
61 * 1) sptr->from == cptr (note: cptr->from == cptr)
63 * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
64 * *cannot* be a local connection, unless it's
65 * actually cptr!). [MyConnect(x) should probably
66 * be defined as (x == x->from) --msa ]
68 * parc number of variable parameter strings (if zero,
69 * parv is allowed to be NULL)
71 * parv a NULL terminated list of parameter pointers,
73 * parv[0], sender (prefix string), if not present
74 * this points to an empty string.
75 * parv[1]...parv[parc-1]
76 * pointers to additional parameters
77 * parv[parc] == NULL, *always*
79 * note: it is guaranteed that parv[0]..parv[parc-1] are all
88 #include "ircd_features.h"
89 #include "ircd_reply.h"
90 #include "ircd_string.h"
104 void do_trace(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
107 struct Client *acptr;
108 const struct ConnectionClass* cl;
111 int link_s[MAXCONNECTIONS];
112 int link_u[MAXCONNECTIONS];
117 if (parc < 2 || BadPtr(parv[1]))
119 /* just "TRACE" without parameters. Must be from local client */
122 tname = cli_name(&me);
125 else if (parc < 3 || BadPtr(parv[2]))
127 /* No target specified. Make one before propagating. */
130 if ((acptr = find_match_server(parv[1])) ||
131 ((acptr = FindClient(parv[1])) && !MyUser(acptr)))
134 parv[2] = cli_name(cli_user(acptr)->server);
136 parv[2] = cli_name(acptr);
139 if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, IsServer(acptr),
140 "%s :%C", 2, parc, parv)) == HUNTED_NOSUCH)
146 /* Got "TRACE <tname> :<target>" */
148 if (MyUser(sptr) || Protocol(cptr) < 10)
149 acptr = find_match_server(parv[2]);
151 acptr = FindNServer(parv[2]);
152 if ((i = hunt_server_cmd(sptr, CMD_TRACE, cptr, 0, "%s :%C", 2, parc,
153 parv)) == HUNTED_NOSUCH)
158 if (i == HUNTED_PASS) {
160 acptr = next_client(GlobalClientList, tname);
162 acptr = cli_from(acptr);
163 send_reply(sptr, RPL_TRACELINK,
164 version, debugmode, tname,
165 acptr ? cli_name(cli_from(acptr)) : "<No_match>");
169 doall = (parv[1] && (parc > 1)) ? !match(tname, cli_name(&me)) : 1;
170 wilds = !parv[1] || strchr(tname, '*') || strchr(tname, '?');
171 dow = wilds || doall;
173 /* Don't give (long) remote listings to lusers */
174 if (dow && !MyConnect(sptr) && !IsAnOper(sptr)) {
175 send_reply(sptr, RPL_TRACEEND);
179 for (i = 0; i < MAXCONNECTIONS; i++)
180 link_s[i] = 0, link_u[i] = 0;
183 for (acptr = GlobalClientList; acptr; acptr = cli_next(acptr)) {
185 link_u[cli_fd(cli_from(acptr))]++;
186 else if (IsServer(acptr))
187 link_s[cli_fd(cli_from(acptr))]++;
191 /* report all direct connections */
193 for (i = 0; i <= HighestFd; i++) {
194 const char *conClass;
196 if (!(acptr = LocalClientArray[i])) /* Local Connection? */
198 if (IsInvisible(acptr) && dow && !(MyConnect(sptr) && IsOper(sptr)) &&
199 !IsAnOper(acptr) && (acptr != sptr))
201 if (!doall && wilds && match(tname, cli_name(acptr)))
203 if (!dow && 0 != ircd_strcmp(tname, cli_name(acptr)))
206 conClass = get_client_class(acptr);
208 switch (cli_status(acptr)) {
209 case STAT_CONNECTING:
210 send_reply(sptr, RPL_TRACECONNECTING, conClass, cli_name(acptr));
214 send_reply(sptr, RPL_TRACEHANDSHAKE, conClass, cli_name(acptr));
220 case STAT_UNKNOWN_USER:
221 send_reply(sptr, RPL_TRACEUNKNOWN, conClass,
222 get_client_name(acptr, HIDE_IP));
225 case STAT_UNKNOWN_SERVER:
226 send_reply(sptr, RPL_TRACEUNKNOWN, conClass, "Unknown Server");
230 /* Only opers see users if there is a wildcard
231 but anyone can see all the opers. */
232 if ((IsAnOper(sptr) && (MyUser(sptr) ||
233 !(dow && IsInvisible(acptr)))) || !dow || IsAnOper(acptr)) {
235 send_reply(sptr, RPL_TRACEOPERATOR, conClass,
236 get_client_name(acptr, SHOW_IP),
237 CurrentTime - cli_lasttime(acptr));
239 send_reply(sptr, RPL_TRACEUSER, conClass,
240 get_client_name(acptr, SHOW_IP),
241 CurrentTime - cli_lasttime(acptr));
246 * Connection is a server
248 * Serv <class> <nS> <nC> <name> <ConnBy> <last> <age>
250 * class Class the server is in
251 * nS Number of servers reached via this link
252 * nC Number of clients reached via this link
253 * name Name of the server linked
254 * ConnBy Who established this link
255 * last Seconds since we got something from this link
256 * age Seconds this link has been alive
258 * Additional comments etc...... -Cym-<cym@acrux.net>
262 if (cli_serv(acptr)->user)
263 send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
264 link_u[i], cli_name(acptr),
265 (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*",
266 cli_serv(acptr)->user->username, cli_serv(acptr)->user->host,
267 CurrentTime - cli_lasttime(acptr),
268 CurrentTime - cli_serv(acptr)->timestamp);
270 send_reply(sptr, RPL_TRACESERVER, conClass, link_s[i],
271 link_u[i], cli_name(acptr),
272 (*(cli_serv(acptr))->by) ? cli_serv(acptr)->by : "*", "*",
273 cli_name(&me), CurrentTime - cli_lasttime(acptr),
274 CurrentTime - cli_serv(acptr)->timestamp);
277 default: /* We actually shouldn't come here, -msa */
278 send_reply(sptr, RPL_TRACENEWTYPE, get_client_name(acptr, HIDE_IP));
284 * Add these lines to summarize the above which can get rather long
285 * and messy when done remotely - Avalon
287 if (IsAnOper(sptr) && doall) {
288 for (cl = get_class_list(); cl; cl = cl->next) {
290 send_reply(sptr, RPL_TRACECLASS, ConClass(cl), Links(cl));
293 send_reply(sptr, RPL_TRACEEND);
297 * m_trace - generic message handler
299 * parv[0] = sender prefix
300 * parv[1] = nick or servername
301 * parv[2] = 'target' servername
303 int m_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
305 if (feature_bool(FEAT_HIS_TRACE))
306 return send_reply(cptr, ERR_NOPRIVILEGES);
307 do_trace(cptr, sptr, parc, parv);
312 * ms_trace - server message handler
314 * parv[0] = sender prefix
315 * parv[1] = nick or servername
316 * parv[2] = 'target' servername
318 int ms_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
320 do_trace(cptr, sptr, parc, parv);
325 * mo_trace - oper message handler
327 * parv[0] = sender prefix
328 * parv[1] = nick or servername
329 * parv[2] = 'target' servername
331 int mo_trace(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
333 if (feature_bool(FEAT_HIS_TRACE) && !IsAnOper(sptr))
334 return send_reply(cptr, ERR_NOPRIVILEGES);
335 do_trace(cptr, sptr, parc, parv);