1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 2004-2016 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_etrace.c |
23 |
* \brief Includes required functions for processing the ETRACE command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "list.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "irc_string.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "send.h" |
35 |
#include "parse.h" |
36 |
#include "modules.h" |
37 |
#include "conf.h" |
38 |
|
39 |
|
40 |
/* report_this_status() |
41 |
* |
42 |
* inputs - pointer to client to report to |
43 |
* - pointer to client to report about |
44 |
* - flag full etrace or not |
45 |
* output - NONE |
46 |
* side effects - NONE |
47 |
*/ |
48 |
static void |
49 |
report_this_status(struct Client *source_p, const struct Client *target_p) |
50 |
{ |
51 |
if (target_p->status != STAT_CLIENT) |
52 |
return; |
53 |
|
54 |
sendto_one_numeric(source_p, &me, RPL_ETRACE, |
55 |
HasUMode(target_p, UMODE_OPER) ? "Oper" : "User", |
56 |
get_client_class(&target_p->connection->confs), |
57 |
target_p->name, |
58 |
target_p->username, |
59 |
target_p->host, |
60 |
target_p->sockhost, |
61 |
target_p->info); |
62 |
} |
63 |
|
64 |
/* |
65 |
* do_etrace() |
66 |
*/ |
67 |
static void |
68 |
do_etrace(struct Client *source_p, const char *arg) |
69 |
{ |
70 |
const char *tname = NULL; |
71 |
unsigned int wilds = 0, do_all = 0; |
72 |
const dlink_node *node = NULL; |
73 |
|
74 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
75 |
"ETRACE requested by %s (%s@%s) [%s]", |
76 |
source_p->name, source_p->username, |
77 |
source_p->host, source_p->servptr->name); |
78 |
|
79 |
if (!EmptyString(arg)) |
80 |
{ |
81 |
tname = arg; |
82 |
wilds = has_wildcards(tname); |
83 |
} |
84 |
else |
85 |
{ |
86 |
do_all = 1; |
87 |
tname = "*"; |
88 |
} |
89 |
|
90 |
if (!wilds && !do_all) |
91 |
{ |
92 |
const struct Client *target_p = find_person(source_p, tname); |
93 |
|
94 |
if (target_p && MyConnect(target_p)) |
95 |
report_this_status(source_p, target_p); |
96 |
|
97 |
sendto_one_numeric(source_p, &me, RPL_TRACEEND, tname); |
98 |
return; |
99 |
} |
100 |
|
101 |
DLINK_FOREACH(node, local_client_list.head) |
102 |
{ |
103 |
const struct Client *target_p = node->data; |
104 |
|
105 |
if (!wilds || !match(tname, target_p->name)) |
106 |
report_this_status(source_p, target_p); |
107 |
} |
108 |
|
109 |
sendto_one_numeric(source_p, &me, RPL_TRACEEND, tname); |
110 |
} |
111 |
|
112 |
/* mo_etrace() |
113 |
* parv[0] = command |
114 |
* parv[1] = servername |
115 |
*/ |
116 |
static int |
117 |
mo_etrace(struct Client *source_p, int parc, char *parv[]) |
118 |
{ |
119 |
do_etrace(source_p, parv[1]); |
120 |
return 0; |
121 |
} |
122 |
|
123 |
static struct Message etrace_msgtab = |
124 |
{ |
125 |
.cmd = "ETRACE", |
126 |
.args_max = MAXPARA, |
127 |
.handlers[UNREGISTERED_HANDLER] = m_unregistered, |
128 |
.handlers[CLIENT_HANDLER] = m_not_oper, |
129 |
.handlers[SERVER_HANDLER] = m_ignore, |
130 |
.handlers[ENCAP_HANDLER] = m_ignore, |
131 |
.handlers[OPER_HANDLER] = mo_etrace |
132 |
}; |
133 |
|
134 |
static void |
135 |
module_init(void) |
136 |
{ |
137 |
mod_add_cmd(&etrace_msgtab); |
138 |
} |
139 |
|
140 |
static void |
141 |
module_exit(void) |
142 |
{ |
143 |
mod_del_cmd(&etrace_msgtab); |
144 |
} |
145 |
|
146 |
struct module module_entry = |
147 |
{ |
148 |
.version = "$Revision$", |
149 |
.modinit = module_init, |
150 |
.modexit = module_exit, |
151 |
}; |