1 |
/* |
2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
* |
4 |
* Copyright (c) 1997-2014 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
* USA |
20 |
*/ |
21 |
|
22 |
/*! \file m_links.c |
23 |
* \brief Includes required functions for processing the LINKS command. |
24 |
* \version $Id$ |
25 |
*/ |
26 |
|
27 |
#include "stdinc.h" |
28 |
#include "client.h" |
29 |
#include "irc_string.h" |
30 |
#include "ircd.h" |
31 |
#include "numeric.h" |
32 |
#include "s_serv.h" |
33 |
#include "send.h" |
34 |
#include "conf.h" |
35 |
#include "motd.h" |
36 |
#include "parse.h" |
37 |
#include "modules.h" |
38 |
|
39 |
|
40 |
/*! \brief Shows a list of linked servers and notifies irc-operators |
41 |
* about the LINKS request |
42 |
* |
43 |
* \param source_p Pointer to client to report to |
44 |
*/ |
45 |
static void |
46 |
do_links(struct Client *source_p, int parc, char *parv[]) |
47 |
{ |
48 |
dlink_node *ptr = NULL; |
49 |
|
50 |
sendto_realops_flags(UMODE_SPY, L_ALL, SEND_NOTICE, |
51 |
"LINKS requested by %s (%s@%s) [%s]", |
52 |
source_p->name, |
53 |
source_p->username, source_p->host, |
54 |
source_p->servptr->name); |
55 |
|
56 |
if (HasUMode(source_p, UMODE_OPER) || !ConfigServerHide.flatten_links) |
57 |
{ |
58 |
const char *mask = (parc > 2 ? parv[2] : parv[1]); |
59 |
|
60 |
DLINK_FOREACH(ptr, global_serv_list.head) |
61 |
{ |
62 |
struct Client *target_p = ptr->data; |
63 |
|
64 |
/* skip hidden servers */ |
65 |
if (IsHidden(target_p)) |
66 |
if (!HasUMode(source_p, UMODE_OPER)) |
67 |
continue; |
68 |
|
69 |
if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services) |
70 |
if (!HasUMode(source_p, UMODE_OPER)) |
71 |
continue; |
72 |
|
73 |
if (!EmptyString(mask) && match(mask, target_p->name)) |
74 |
continue; |
75 |
|
76 |
/* |
77 |
* We just send the reply, as if they are here there's either no SHIDE, |
78 |
* or they're an oper.. |
79 |
*/ |
80 |
sendto_one_numeric(source_p, &me, RPL_LINKS, |
81 |
target_p->name, target_p->servptr->name, |
82 |
target_p->hopcount, target_p->info); |
83 |
} |
84 |
|
85 |
sendto_one_numeric(source_p, &me, RPL_ENDOFLINKS, |
86 |
EmptyString(mask) ? "*" : mask); |
87 |
} |
88 |
else |
89 |
{ |
90 |
/* |
91 |
* Print our own info so at least it looks like a normal links |
92 |
* then print out the file (which may or may not be empty) |
93 |
*/ |
94 |
sendto_one_numeric(source_p, &me, RPL_LINKS, |
95 |
me.name, me.name, 0, me.info); |
96 |
|
97 |
DLINK_FOREACH(ptr, flatten_links.head) |
98 |
sendto_one(source_p, ":%s %d %s %s", |
99 |
ID_or_name(&me, source_p), RPL_LINKS, |
100 |
ID_or_name(source_p, source_p), |
101 |
ptr->data); |
102 |
sendto_one_numeric(source_p, &me, RPL_ENDOFLINKS, "*"); |
103 |
} |
104 |
} |
105 |
|
106 |
static int |
107 |
mo_links(struct Client *source_p, int parc, char *parv[]) |
108 |
{ |
109 |
if (parc > 2) |
110 |
if (!ConfigServerHide.disable_remote_commands || HasUMode(source_p, UMODE_OPER)) |
111 |
if (hunt_server(source_p, ":%s LINKS %s :%s", 1, |
112 |
parc, parv) != HUNTED_ISME) |
113 |
return 0; |
114 |
|
115 |
do_links(source_p, parc, parv); |
116 |
return 0; |
117 |
} |
118 |
|
119 |
/*! \brief LINKS command handler |
120 |
* |
121 |
* \param source_p Pointer to allocated Client struct from which the message |
122 |
* originally comes from. This can be a local or remote client. |
123 |
* \param parc Integer holding the number of supplied arguments. |
124 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
125 |
* pointers. |
126 |
* \note Valid arguments for this command are: |
127 |
* - parv[0] = command |
128 |
* - parv[1] = servername mask |
129 |
* or |
130 |
* - parv[0] = command |
131 |
* - parv[1] = server to query |
132 |
* - parv[2] = servername mask |
133 |
*/ |
134 |
static int |
135 |
m_links(struct Client *source_p, int parc, char *parv[]) |
136 |
{ |
137 |
static time_t last_used = 0; |
138 |
|
139 |
if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime) |
140 |
{ |
141 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
142 |
return 0; |
143 |
} |
144 |
|
145 |
last_used = CurrentTime; |
146 |
|
147 |
if (!ConfigServerHide.flatten_links) |
148 |
return mo_links(source_p, parc, parv); |
149 |
|
150 |
do_links(source_p, parc, parv); |
151 |
return 0; |
152 |
} |
153 |
|
154 |
/*! \brief LINKS command handler |
155 |
* |
156 |
* \param source_p Pointer to allocated Client struct from which the message |
157 |
* originally comes from. This can be a local or remote client. |
158 |
* \param parc Integer holding the number of supplied arguments. |
159 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
160 |
* pointers. |
161 |
* \note Valid arguments for this command are: |
162 |
* - parv[0] = command |
163 |
* - parv[1] = servername mask |
164 |
* or |
165 |
* - parv[0] = command |
166 |
* - parv[1] = server to query |
167 |
* - parv[2] = servername mask |
168 |
*/ |
169 |
static int |
170 |
ms_links(struct Client *source_p, int parc, char *parv[]) |
171 |
{ |
172 |
if (hunt_server(source_p, ":%s LINKS %s :%s", 1, |
173 |
parc, parv) != HUNTED_ISME) |
174 |
return 0; |
175 |
|
176 |
return m_links(source_p, parc, parv); |
177 |
} |
178 |
|
179 |
static struct Message links_msgtab = |
180 |
{ |
181 |
"LINKS", 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
182 |
{ m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore } |
183 |
}; |
184 |
|
185 |
static void |
186 |
module_init(void) |
187 |
{ |
188 |
mod_add_cmd(&links_msgtab); |
189 |
} |
190 |
|
191 |
static void |
192 |
module_exit(void) |
193 |
{ |
194 |
mod_del_cmd(&links_msgtab); |
195 |
} |
196 |
|
197 |
struct module module_entry = |
198 |
{ |
199 |
.node = { NULL, NULL, NULL }, |
200 |
.name = NULL, |
201 |
.version = "$Revision$", |
202 |
.handle = NULL, |
203 |
.modinit = module_init, |
204 |
.modexit = module_exit, |
205 |
.flags = 0 |
206 |
}; |