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