| 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., 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 "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_server_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, me.name, me.name, 0, me.info); |
| 95 |
|
| 96 |
DLINK_FOREACH(ptr, flatten_links.head) |
| 97 |
sendto_one_numeric(source_p, &me, RPL_LINKS|SND_EXPLICIT, "%s", ptr->data); |
| 98 |
sendto_one_numeric(source_p, &me, RPL_ENDOFLINKS, "*"); |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
static int |
| 103 |
mo_links(struct Client *source_p, int parc, char *parv[]) |
| 104 |
{ |
| 105 |
if (parc > 2) |
| 106 |
if (!ConfigServerHide.disable_remote_commands || HasUMode(source_p, UMODE_OPER)) |
| 107 |
if (hunt_server(source_p, ":%s LINKS %s :%s", 1, |
| 108 |
parc, parv) != HUNTED_ISME) |
| 109 |
return 0; |
| 110 |
|
| 111 |
do_links(source_p, parc, parv); |
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
/*! \brief LINKS command handler |
| 116 |
* |
| 117 |
* \param source_p Pointer to allocated Client struct from which the message |
| 118 |
* originally comes from. This can be a local or remote client. |
| 119 |
* \param parc Integer holding the number of supplied arguments. |
| 120 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 121 |
* pointers. |
| 122 |
* \note Valid arguments for this command are: |
| 123 |
* - parv[0] = command |
| 124 |
* - parv[1] = servername mask |
| 125 |
* or |
| 126 |
* - parv[0] = command |
| 127 |
* - parv[1] = server to query |
| 128 |
* - parv[2] = servername mask |
| 129 |
*/ |
| 130 |
static int |
| 131 |
m_links(struct Client *source_p, int parc, char *parv[]) |
| 132 |
{ |
| 133 |
static time_t last_used = 0; |
| 134 |
|
| 135 |
if ((last_used + ConfigGeneral.pace_wait) > CurrentTime) |
| 136 |
{ |
| 137 |
sendto_one_numeric(source_p, &me, RPL_LOAD2HI); |
| 138 |
return 0; |
| 139 |
} |
| 140 |
|
| 141 |
last_used = CurrentTime; |
| 142 |
|
| 143 |
if (!ConfigServerHide.flatten_links) |
| 144 |
return mo_links(source_p, parc, parv); |
| 145 |
|
| 146 |
do_links(source_p, parc, parv); |
| 147 |
return 0; |
| 148 |
} |
| 149 |
|
| 150 |
/*! \brief LINKS command handler |
| 151 |
* |
| 152 |
* \param source_p Pointer to allocated Client struct from which the message |
| 153 |
* originally comes from. This can be a local or remote client. |
| 154 |
* \param parc Integer holding the number of supplied arguments. |
| 155 |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 156 |
* pointers. |
| 157 |
* \note Valid arguments for this command are: |
| 158 |
* - parv[0] = command |
| 159 |
* - parv[1] = servername mask |
| 160 |
* or |
| 161 |
* - parv[0] = command |
| 162 |
* - parv[1] = server to query |
| 163 |
* - parv[2] = servername mask |
| 164 |
*/ |
| 165 |
static int |
| 166 |
ms_links(struct Client *source_p, int parc, char *parv[]) |
| 167 |
{ |
| 168 |
if (hunt_server(source_p, ":%s LINKS %s :%s", 1, parc, parv) != HUNTED_ISME) |
| 169 |
return 0; |
| 170 |
|
| 171 |
return m_links(source_p, parc, parv); |
| 172 |
} |
| 173 |
|
| 174 |
static struct Message links_msgtab = |
| 175 |
{ |
| 176 |
"LINKS", NULL, 0, 0, 0, MAXPARA, MFLG_SLOW, 0, |
| 177 |
{ m_unregistered, m_links, ms_links, m_ignore, mo_links, m_ignore } |
| 178 |
}; |
| 179 |
|
| 180 |
static void |
| 181 |
module_init(void) |
| 182 |
{ |
| 183 |
mod_add_cmd(&links_msgtab); |
| 184 |
} |
| 185 |
|
| 186 |
static void |
| 187 |
module_exit(void) |
| 188 |
{ |
| 189 |
mod_del_cmd(&links_msgtab); |
| 190 |
} |
| 191 |
|
| 192 |
struct module module_entry = |
| 193 |
{ |
| 194 |
.node = { NULL, NULL, NULL }, |
| 195 |
.name = NULL, |
| 196 |
.version = "$Revision$", |
| 197 |
.handle = NULL, |
| 198 |
.modinit = module_init, |
| 199 |
.modexit = module_exit, |
| 200 |
.flags = 0 |
| 201 |
}; |