2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_links.c: Shows what servers are currently connected.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* $Id: m_links.c 254 2005-09-21 23:35:12Z nenolod $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "client.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "hook.h"
|
2007-11-23 21:11:25 +00:00
|
|
|
#include "scache.h"
|
2013-09-10 05:35:56 +00:00
|
|
|
#include "s_assert.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-02-11 02:54:17 +00:00
|
|
|
static int m_links(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int mo_links(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2008-04-20 05:35:22 +00:00
|
|
|
static char * clean_string(char *dest, const unsigned char *src, size_t len);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
struct Message links_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"LINKS", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_unreg, {m_links, 0}, {mo_links, 0}, mg_ignore, mg_ignore, {mo_links, 0}}
|
|
|
|
};
|
|
|
|
|
|
|
|
int doing_links_hook;
|
|
|
|
|
|
|
|
mapi_clist_av1 links_clist[] = { &links_msgtab, NULL };
|
|
|
|
mapi_hlist_av1 links_hlist[] = {
|
|
|
|
{ "doing_links", &doing_links_hook },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
DECLARE_MODULE_AV1(links, NULL, NULL, links_clist, links_hlist, NULL, "$Revision: 254 $");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* m_links - LINKS message handler
|
|
|
|
* parv[1] = servername mask
|
|
|
|
* or
|
2014-03-03 04:25:47 +00:00
|
|
|
* parv[1] = server to query
|
2007-01-25 06:40:21 +00:00
|
|
|
* parv[2] = servername mask
|
|
|
|
*/
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
m_links(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
if(ConfigServerHide.flatten_links && !IsExemptShide(source_p))
|
2007-11-23 21:11:25 +00:00
|
|
|
scache_send_flattened_links(source_p);
|
2007-01-25 06:40:21 +00:00
|
|
|
else
|
2016-02-11 02:54:17 +00:00
|
|
|
mo_links(msgbuf_p, client_p, source_p, parc, parv);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
mo_links(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
const char *mask = "";
|
|
|
|
struct Client *target_p;
|
|
|
|
char clean_mask[2 * HOSTLEN + 4];
|
2016-02-20 23:44:13 +00:00
|
|
|
hook_cdata hd;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_node *ptr;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(parc > 2)
|
|
|
|
{
|
2010-01-27 20:05:10 +00:00
|
|
|
if(strlen(parv[2]) > HOSTLEN)
|
|
|
|
return 0;
|
2007-01-25 06:40:21 +00:00
|
|
|
if(hunt_server(client_p, source_p, ":%s LINKS %s :%s", 1, parc, parv)
|
|
|
|
!= HUNTED_ISME)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mask = parv[2];
|
|
|
|
}
|
|
|
|
else if(parc == 2)
|
|
|
|
mask = parv[1];
|
|
|
|
|
|
|
|
if(*mask) /* only necessary if there is a mask */
|
|
|
|
mask = collapse(clean_string
|
|
|
|
(clean_mask, (const unsigned char *) mask, 2 * HOSTLEN));
|
|
|
|
|
|
|
|
hd.client = source_p;
|
|
|
|
hd.arg1 = mask;
|
|
|
|
hd.arg2 = NULL;
|
|
|
|
|
|
|
|
call_hook(doing_links_hook, &hd);
|
|
|
|
|
2008-04-01 20:18:48 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, global_serv_list.head)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
target_p = ptr->data;
|
|
|
|
|
|
|
|
if(*mask && !match(mask, target_p->name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* We just send the reply, as if theyre here theres either no SHIDE,
|
2014-03-03 04:25:47 +00:00
|
|
|
* or theyre an oper..
|
2007-01-25 06:40:21 +00:00
|
|
|
*/
|
|
|
|
sendto_one_numeric(source_p, RPL_LINKS, form_str(RPL_LINKS),
|
2007-11-21 23:38:13 +00:00
|
|
|
target_p->name, target_p->servptr->name,
|
2007-01-25 06:40:21 +00:00
|
|
|
target_p->hopcount,
|
|
|
|
target_p->info[0] ? target_p->info : "(Unknown Location)");
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one_numeric(source_p, RPL_ENDOFLINKS, form_str(RPL_ENDOFLINKS),
|
|
|
|
EmptyString(mask) ? "*" : mask);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-20 05:35:22 +00:00
|
|
|
static char *
|
|
|
|
clean_string(char *dest, const unsigned char *src, size_t len)
|
|
|
|
{
|
|
|
|
char *d = dest;
|
|
|
|
s_assert(0 != dest);
|
|
|
|
s_assert(0 != src);
|
|
|
|
|
|
|
|
if(dest == NULL || src == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-01-27 20:05:10 +00:00
|
|
|
while (*src && (len > 1))
|
2008-04-20 05:35:22 +00:00
|
|
|
{
|
|
|
|
if(*src & 0x80) /* if high bit is set */
|
|
|
|
{
|
|
|
|
*d++ = '.';
|
|
|
|
--len;
|
2010-01-27 20:05:10 +00:00
|
|
|
if(len <= 1)
|
|
|
|
break;
|
2008-04-20 05:35:22 +00:00
|
|
|
}
|
|
|
|
else if(!IsPrint(*src)) /* if NOT printable */
|
|
|
|
{
|
|
|
|
*d++ = '^';
|
|
|
|
--len;
|
2010-01-27 20:05:10 +00:00
|
|
|
if(len <= 1)
|
|
|
|
break;
|
2008-04-20 05:35:22 +00:00
|
|
|
*d++ = 0x40 + *src; /* turn it into a printable */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*d++ = *src;
|
|
|
|
++src;
|
|
|
|
--len;
|
|
|
|
}
|
|
|
|
*d = '\0';
|
|
|
|
return dest;
|
|
|
|
}
|