2007-01-25 07:40:21 +01:00
|
|
|
/*
|
|
|
|
* charybdis: an advanced Internet Relay Chat Daemon(ircd).
|
|
|
|
* m_scan.c: Provides information about various targets on various topics
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 William Pitcock <nenolod -at- nenolod.net>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1.Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2.Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3.The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "class.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "hash.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "hash.h"
|
2008-04-20 07:47:38 +02:00
|
|
|
#include "match.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
#include "ircd.h"
|
|
|
|
#include "numeric.h"
|
|
|
|
#include "s_serv.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "s_user.h"
|
|
|
|
#include "send.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
2013-09-10 07:35:56 +02:00
|
|
|
#include "logger.h"
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-07 09:05:28 +01:00
|
|
|
static const char scan_desc[] =
|
|
|
|
"Provides the SCAN command to show users that have a mode set or cleared";
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void mo_scan(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static void scan_umodes(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
struct Message scan_msgtab = {
|
2016-02-19 23:42:40 +01:00
|
|
|
"SCAN", 0, 0, 0, 0,
|
2007-01-25 07:40:21 +01:00
|
|
|
{mg_ignore, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_scan, 2}}
|
|
|
|
};
|
|
|
|
|
|
|
|
mapi_clist_av1 scan_clist[] = { &scan_msgtab, NULL };
|
2016-03-09 08:29:41 +01:00
|
|
|
|
2016-03-07 09:05:28 +01:00
|
|
|
DECLARE_MODULE_AV2(scan, NULL, NULL, scan_clist, NULL, NULL, NULL, NULL, scan_desc);
|
2007-01-25 07:40:21 +01:00
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
typedef void (*scan_handler)(struct MsgBuf *, struct Client *, struct Client *, int,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char **);
|
|
|
|
|
|
|
|
struct scan_cmd {
|
|
|
|
const char *name;
|
|
|
|
int operlevel;
|
|
|
|
scan_handler handler;
|
|
|
|
} scan_cmds[] = {
|
|
|
|
{"UMODES", L_OPER, scan_umodes},
|
|
|
|
{NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *empty_sockhost = "255.255.255.255";
|
|
|
|
static const char *spoofed_sockhost = "0";
|
|
|
|
|
|
|
|
/*
|
|
|
|
* m_scan
|
|
|
|
* parv[1] = options [or target]
|
|
|
|
* parv[2] = [target]
|
|
|
|
*/
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
mo_scan(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *parv[])
|
|
|
|
{
|
|
|
|
struct scan_cmd *sptr;
|
|
|
|
|
|
|
|
for (sptr = scan_cmds; sptr->name != NULL; sptr++)
|
|
|
|
{
|
|
|
|
if (!irccmp(sptr->name, parv[1]))
|
|
|
|
{
|
2016-03-09 08:37:03 +01:00
|
|
|
if (!(sptr->operlevel == L_ADMIN && !IsOperAdmin(source_p)))
|
|
|
|
sptr->handler(msgbuf_p, client_p, source_p, parc, parv);
|
|
|
|
|
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one_notice(source_p, ":*** %s is not an implemented SCAN target",
|
|
|
|
parv[1]);
|
|
|
|
}
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
static void
|
2016-02-11 03:54:17 +01:00
|
|
|
scan_umodes(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc,
|
2007-01-25 07:40:21 +01:00
|
|
|
const char *parv[])
|
|
|
|
{
|
|
|
|
unsigned int allowed_umodes = 0, disallowed_umodes = 0;
|
|
|
|
int what = MODE_ADD;
|
|
|
|
int mode;
|
2016-03-09 08:37:03 +01:00
|
|
|
bool list_users = true;
|
2010-01-01 22:55:25 +01:00
|
|
|
int list_max = 500;
|
2007-01-25 07:40:21 +01:00
|
|
|
int list_count = 0, count = 0;
|
|
|
|
const char *mask = NULL;
|
|
|
|
const char *c;
|
|
|
|
struct Client *target_p;
|
2008-04-01 22:18:48 +02:00
|
|
|
rb_dlink_list *target_list = &lclient_list; /* local clients only by default */
|
|
|
|
rb_dlink_node *tn;
|
2007-01-25 07:40:21 +01:00
|
|
|
int i;
|
|
|
|
const char *sockhost;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
if (parc < 3)
|
|
|
|
{
|
|
|
|
if (MyClient(source_p))
|
|
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
|
|
|
|
me.name, source_p->name, "SCAN UMODES");
|
|
|
|
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
|
2009-01-16 18:33:38 +01:00
|
|
|
if (parv[2][0] != '+' && parv[2][0] != '-')
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":SCAN UMODES: umodes parameter must start with '+' or '-'");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2009-01-16 18:33:38 +01:00
|
|
|
}
|
|
|
|
|
2007-01-25 07:40:21 +01:00
|
|
|
for (c = parv[2]; *c; c++)
|
|
|
|
{
|
|
|
|
switch(*c)
|
|
|
|
{
|
|
|
|
case '+':
|
|
|
|
what = MODE_ADD;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
what = MODE_DEL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if ((mode = user_modes[(unsigned char) *c]) != 0)
|
|
|
|
{
|
|
|
|
if (what == MODE_ADD)
|
|
|
|
allowed_umodes |= mode;
|
|
|
|
else
|
|
|
|
disallowed_umodes |= mode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 3; i < parc; i++)
|
|
|
|
{
|
|
|
|
if (!irccmp(parv[i], "no-list"))
|
2016-03-09 08:37:03 +01:00
|
|
|
list_users = false;
|
2007-01-25 07:40:21 +01:00
|
|
|
else if (!irccmp(parv[i], "list"))
|
2016-03-09 08:37:03 +01:00
|
|
|
list_users = true;
|
2007-01-25 07:40:21 +01:00
|
|
|
else if (!irccmp(parv[i], "global"))
|
|
|
|
target_list = &global_client_list;
|
|
|
|
else if (i < (parc - 1))
|
|
|
|
{
|
|
|
|
if (!irccmp(parv[i], "list-max"))
|
|
|
|
list_max = atoi(parv[++i]);
|
|
|
|
else if (!irccmp(parv[i], "mask"))
|
|
|
|
mask = parv[++i];
|
2009-01-16 18:33:38 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2009-01-16 18:33:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_one_notice(source_p, ":SCAN UMODES: invalid parameters");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
2009-01-01 20:32:30 +01:00
|
|
|
if (target_list == &global_client_list && list_users)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
if (IsOperSpy(source_p))
|
|
|
|
{
|
|
|
|
if (!ConfigFileEntry.operspy_dont_care_user_info)
|
|
|
|
{
|
2008-04-20 06:40:40 +02:00
|
|
|
rb_strlcpy(buf, "UMODES", sizeof buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
for (i = 2; i < parc; i++)
|
|
|
|
{
|
2008-04-20 06:44:04 +02:00
|
|
|
rb_strlcat(buf, " ", sizeof buf);
|
|
|
|
rb_strlcat(buf, parv[i], sizeof buf);
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
report_operspy(source_p, "SCAN", buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NOPRIVS),
|
|
|
|
me.name, source_p->name, "oper_spy");
|
2016-03-09 08:37:03 +01:00
|
|
|
return;
|
2007-01-25 07:40:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-01 22:18:48 +02:00
|
|
|
RB_DLINK_FOREACH(tn, target_list->head)
|
2007-01-25 07:40:21 +01:00
|
|
|
{
|
|
|
|
unsigned int working_umodes = 0;
|
|
|
|
char maskbuf[BUFSIZE];
|
|
|
|
|
|
|
|
target_p = tn->data;
|
|
|
|
|
|
|
|
if (!IsClient(target_p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(EmptyString(target_p->sockhost))
|
|
|
|
sockhost = empty_sockhost;
|
|
|
|
else if(!show_ip(source_p, target_p))
|
|
|
|
sockhost = spoofed_sockhost;
|
|
|
|
else
|
|
|
|
sockhost = target_p->sockhost;
|
|
|
|
|
|
|
|
working_umodes = target_p->umodes;
|
|
|
|
|
|
|
|
/* require that we have the allowed umodes... */
|
|
|
|
if ((working_umodes & allowed_umodes) != allowed_umodes)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* require that we have NONE of the disallowed ones */
|
|
|
|
if ((working_umodes & disallowed_umodes) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (mask != NULL)
|
|
|
|
{
|
2016-02-10 02:25:32 +01:00
|
|
|
snprintf(maskbuf, BUFSIZE, "%s!%s@%s",
|
2007-01-25 07:40:21 +01:00
|
|
|
target_p->name, target_p->username, target_p->host);
|
|
|
|
|
|
|
|
if (!match(mask, maskbuf))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (list_users && (!list_max || (list_count < list_max)))
|
|
|
|
{
|
|
|
|
char modebuf[BUFSIZE];
|
|
|
|
char *m = modebuf;
|
|
|
|
|
|
|
|
*m++ = '+';
|
|
|
|
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
{
|
|
|
|
if (target_p->umodes & user_modes[i])
|
|
|
|
*m++ = (char) i;
|
|
|
|
}
|
|
|
|
|
|
|
|
*m++ = '\0';
|
|
|
|
|
|
|
|
list_count++;
|
|
|
|
|
|
|
|
sendto_one_numeric(source_p, RPL_SCANUMODES,
|
|
|
|
form_str(RPL_SCANUMODES),
|
|
|
|
target_p->name, target_p->username,
|
2014-03-03 05:25:47 +01:00
|
|
|
target_p->host, sockhost,
|
2007-01-25 07:40:21 +01:00
|
|
|
target_p->servptr->name, modebuf,
|
|
|
|
target_p->info);
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_one_numeric(source_p, RPL_SCANMATCHED,
|
|
|
|
form_str(RPL_SCANMATCHED), count);
|
|
|
|
}
|