2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* m_mode.c: Sets a user or channel mode.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
|
|
|
#include "channel.h"
|
|
|
|
#include "client.h"
|
|
|
|
#include "hash.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_user.h"
|
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_serv.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "send.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "modules.h"
|
|
|
|
#include "packet.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
|
2016-02-11 02:54:17 +00:00
|
|
|
static int m_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int ms_mode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int ms_tmode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int ms_mlock(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
|
|
|
static int ms_bmask(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
struct Message mode_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"MODE", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_unreg, {m_mode, 2}, {m_mode, 3}, {ms_mode, 3}, mg_ignore, {m_mode, 2}}
|
|
|
|
};
|
|
|
|
struct Message tmode_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"TMODE", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_ignore, mg_ignore, {ms_tmode, 4}, {ms_tmode, 4}, mg_ignore, mg_ignore}
|
|
|
|
};
|
2010-03-08 05:13:39 +00:00
|
|
|
struct Message mlock_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"MLOCK", 0, 0, 0, 0,
|
2010-05-02 19:42:46 +00:00
|
|
|
{mg_ignore, mg_ignore, {ms_mlock, 3}, {ms_mlock, 3}, mg_ignore, mg_ignore}
|
2010-03-08 05:13:39 +00:00
|
|
|
};
|
2007-01-25 06:40:21 +00:00
|
|
|
struct Message bmask_msgtab = {
|
2016-02-19 22:42:40 +00:00
|
|
|
"BMASK", 0, 0, 0, 0,
|
2007-01-25 06:40:21 +00:00
|
|
|
{mg_ignore, mg_ignore, mg_ignore, {ms_bmask, 5}, mg_ignore, mg_ignore}
|
|
|
|
};
|
|
|
|
|
2010-03-08 05:13:39 +00:00
|
|
|
mapi_clist_av1 mode_clist[] = { &mode_msgtab, &tmode_msgtab, &mlock_msgtab, &bmask_msgtab, NULL };
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2016-03-07 06:03:39 +00:00
|
|
|
DECLARE_MODULE_AV2(mode, NULL, NULL, mode_clist, NULL, NULL, NULL, NULL, NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* m_mode - MODE command handler
|
|
|
|
* parv[1] - channel
|
|
|
|
*/
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
m_mode(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
|
|
|
{
|
|
|
|
struct Channel *chptr = NULL;
|
|
|
|
struct membership *msptr;
|
|
|
|
int n = 2;
|
|
|
|
const char *dest;
|
|
|
|
int operspy = 0;
|
|
|
|
|
|
|
|
dest = parv[1];
|
|
|
|
|
|
|
|
if(IsOperSpy(source_p) && *dest == '!')
|
|
|
|
{
|
|
|
|
dest++;
|
|
|
|
operspy = 1;
|
|
|
|
|
|
|
|
if(EmptyString(dest))
|
|
|
|
{
|
|
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
|
|
|
|
me.name, source_p->name, "MODE");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, try to find the channel in question */
|
|
|
|
if(!IsChanPrefix(*dest))
|
|
|
|
{
|
|
|
|
/* if here, it has to be a non-channel name */
|
|
|
|
user_mode(client_p, source_p, parc, parv);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!check_channel_name(dest))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chptr = find_channel(dest);
|
|
|
|
|
|
|
|
if(chptr == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), parv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now know the channel exists */
|
|
|
|
if(parc < n + 1)
|
|
|
|
{
|
|
|
|
if(operspy)
|
|
|
|
report_operspy(source_p, "MODE", chptr->chname);
|
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_CHANNELMODEIS),
|
|
|
|
me.name, source_p->name, parv[1],
|
|
|
|
operspy ? channel_modes(chptr, &me) : channel_modes(chptr, source_p));
|
|
|
|
|
|
|
|
sendto_one(source_p, form_str(RPL_CREATIONTIME),
|
|
|
|
me.name, source_p->name, parv[1], chptr->channelts);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msptr = find_channel_membership(chptr, source_p);
|
|
|
|
|
|
|
|
/* Finish the flood grace period... */
|
|
|
|
if(MyClient(source_p) && !IsFloodDone(source_p))
|
|
|
|
{
|
2015-12-28 06:48:46 +00:00
|
|
|
if(!((parc == 3) && (parv[2][0] == 'b' || parv[2][0] == 'q') && (parv[2][1] == '\0')))
|
2007-01-25 06:40:21 +00:00
|
|
|
flood_endgrace(source_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_channel_mode(client_p, source_p, chptr, msptr, parc - n, parv + n);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
ms_mode(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
|
|
|
{
|
|
|
|
struct Channel *chptr;
|
|
|
|
|
|
|
|
chptr = find_channel(parv[1]);
|
|
|
|
|
|
|
|
if(chptr == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), parv[1]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_channel_mode(client_p, source_p, chptr, NULL, parc - 2, parv + 2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
ms_tmode(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
|
|
|
{
|
|
|
|
struct Channel *chptr = NULL;
|
|
|
|
struct membership *msptr;
|
|
|
|
|
|
|
|
/* Now, try to find the channel in question */
|
|
|
|
if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chptr = find_channel(parv[2]);
|
|
|
|
|
|
|
|
if(chptr == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), parv[2]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TS is higher, drop it. */
|
|
|
|
if(atol(parv[1]) > chptr->channelts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(IsServer(source_p))
|
|
|
|
{
|
|
|
|
set_channel_mode(client_p, source_p, chptr, NULL, parc - 3, parv + 3);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msptr = find_channel_membership(chptr, source_p);
|
|
|
|
|
|
|
|
set_channel_mode(client_p, source_p, chptr, msptr, parc - 3, parv + 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-08 05:13:39 +00:00
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
ms_mlock(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
|
2010-03-08 05:13:39 +00:00
|
|
|
{
|
|
|
|
struct Channel *chptr = NULL;
|
|
|
|
|
|
|
|
/* Now, try to find the channel in question */
|
|
|
|
if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), parv[2]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
chptr = find_channel(parv[2]);
|
|
|
|
|
|
|
|
if(chptr == NULL)
|
|
|
|
{
|
|
|
|
sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
|
|
|
|
form_str(ERR_NOSUCHCHANNEL), parv[2]);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TS is higher, drop it. */
|
|
|
|
if(atol(parv[1]) > chptr->channelts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(IsServer(source_p))
|
2010-08-24 01:22:59 +00:00
|
|
|
set_channel_mlock(client_p, source_p, chptr, parv[3], TRUE);
|
2010-03-08 05:13:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-03 22:45:52 +00:00
|
|
|
static void
|
|
|
|
possibly_remove_lower_forward(struct Client *fakesource_p, int mems,
|
|
|
|
struct Channel *chptr, rb_dlink_list *banlist, int mchar,
|
|
|
|
const char *mask, const char *forward)
|
|
|
|
{
|
|
|
|
struct Ban *actualBan;
|
|
|
|
rb_dlink_node *ptr;
|
|
|
|
|
|
|
|
RB_DLINK_FOREACH(ptr, banlist->head)
|
|
|
|
{
|
|
|
|
actualBan = ptr->data;
|
|
|
|
if(!irccmp(actualBan->banstr, mask) &&
|
|
|
|
(actualBan->forward == NULL ||
|
|
|
|
irccmp(actualBan->forward, forward) < 0))
|
|
|
|
{
|
|
|
|
sendto_channel_local(mems, chptr, ":%s MODE %s -%c %s%s%s",
|
|
|
|
fakesource_p->name,
|
|
|
|
chptr->chname,
|
|
|
|
mchar,
|
|
|
|
actualBan->banstr,
|
|
|
|
actualBan->forward ? "$" : "",
|
|
|
|
actualBan->forward ? actualBan->forward : "");
|
|
|
|
rb_dlinkDelete(&actualBan->node, banlist);
|
|
|
|
free_ban(actualBan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
static int
|
2016-02-11 02:54:17 +00:00
|
|
|
ms_bmask(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
|
|
|
{
|
|
|
|
static char modebuf[BUFSIZE];
|
|
|
|
static char parabuf[BUFSIZE];
|
|
|
|
struct Channel *chptr;
|
2008-04-01 20:18:48 +00:00
|
|
|
rb_dlink_list *banlist;
|
2011-08-13 00:33:10 +00:00
|
|
|
char *s, *forward;
|
2007-01-25 06:40:21 +00:00
|
|
|
char *t;
|
|
|
|
char *mbuf;
|
|
|
|
char *pbuf;
|
|
|
|
long mode_type;
|
|
|
|
int mlen;
|
|
|
|
int plen = 0;
|
|
|
|
int tlen;
|
|
|
|
int arglen;
|
|
|
|
int modecount = 0;
|
|
|
|
int needcap = NOCAPS;
|
|
|
|
int mems;
|
|
|
|
struct Client *fakesource_p;
|
|
|
|
|
|
|
|
if(!IsChanPrefix(parv[2][0]) || !check_channel_name(parv[2]))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if((chptr = find_channel(parv[2])) == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* TS is higher, drop it. */
|
|
|
|
if(atol(parv[1]) > chptr->channelts)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (parv[3][0])
|
|
|
|
{
|
|
|
|
case 'b':
|
|
|
|
banlist = &chptr->banlist;
|
|
|
|
mode_type = CHFL_BAN;
|
|
|
|
mems = ALL_MEMBERS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
banlist = &chptr->exceptlist;
|
|
|
|
mode_type = CHFL_EXCEPTION;
|
|
|
|
needcap = CAP_EX;
|
|
|
|
mems = ONLY_CHANOPS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
banlist = &chptr->invexlist;
|
|
|
|
mode_type = CHFL_INVEX;
|
|
|
|
needcap = CAP_IE;
|
|
|
|
mems = ONLY_CHANOPS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
|
|
|
banlist = &chptr->quietlist;
|
|
|
|
mode_type = CHFL_QUIET;
|
|
|
|
mems = ALL_MEMBERS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* maybe we should just blindly propagate this? */
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
parabuf[0] = '\0';
|
|
|
|
s = LOCAL_COPY(parv[4]);
|
|
|
|
|
|
|
|
/* Hide connecting server on netburst -- jilles */
|
|
|
|
if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
|
|
|
|
fakesource_p = &me;
|
|
|
|
else
|
|
|
|
fakesource_p = source_p;
|
2016-02-10 01:25:32 +00:00
|
|
|
mlen = sprintf(modebuf, ":%s MODE %s +", fakesource_p->name, chptr->chname);
|
2007-01-25 06:40:21 +00:00
|
|
|
mbuf = modebuf + mlen;
|
|
|
|
pbuf = parabuf;
|
|
|
|
|
|
|
|
while(*s == ' ')
|
|
|
|
s++;
|
|
|
|
|
|
|
|
/* next char isnt a space, point t to the next one */
|
|
|
|
if((t = strchr(s, ' ')) != NULL)
|
|
|
|
{
|
|
|
|
*t++ = '\0';
|
|
|
|
|
|
|
|
/* double spaces will break the parser */
|
|
|
|
while(*t == ' ')
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* couldve skipped spaces and got nothing.. */
|
|
|
|
while(!EmptyString(s))
|
|
|
|
{
|
|
|
|
/* ban with a leading ':' -- this will break the protocol */
|
|
|
|
if(*s == ':')
|
|
|
|
goto nextban;
|
|
|
|
|
|
|
|
tlen = strlen(s);
|
|
|
|
|
|
|
|
/* I dont even want to begin parsing this.. */
|
|
|
|
if(tlen > MODEBUFLEN)
|
|
|
|
break;
|
|
|
|
|
2011-08-13 00:33:10 +00:00
|
|
|
if((forward = strchr(s+1, '$')) != NULL)
|
|
|
|
{
|
|
|
|
*forward++ = '\0';
|
|
|
|
if(*forward == '\0')
|
2012-02-16 23:09:39 +00:00
|
|
|
tlen--, forward = NULL;
|
2014-03-02 23:01:56 +00:00
|
|
|
else
|
|
|
|
possibly_remove_lower_forward(fakesource_p,
|
|
|
|
mems, chptr, banlist,
|
|
|
|
parv[3][0], s, forward);
|
2011-08-13 00:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(add_id(fakesource_p, chptr, s, forward, banlist, mode_type))
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
/* this new one wont fit.. */
|
|
|
|
if(mlen + MAXMODEPARAMS + plen + tlen > BUFSIZE - 5 ||
|
|
|
|
modecount >= MAXMODEPARAMS)
|
|
|
|
{
|
|
|
|
*mbuf = '\0';
|
|
|
|
*(pbuf - 1) = '\0';
|
|
|
|
sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
|
|
|
|
|
|
|
|
mbuf = modebuf + mlen;
|
|
|
|
pbuf = parabuf;
|
|
|
|
plen = modecount = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 23:09:39 +00:00
|
|
|
if (forward != NULL)
|
|
|
|
forward[-1] = '$';
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
*mbuf++ = parv[3][0];
|
2016-02-10 01:25:32 +00:00
|
|
|
arglen = sprintf(pbuf, "%s ", s);
|
2007-01-25 06:40:21 +00:00
|
|
|
pbuf += arglen;
|
|
|
|
plen += arglen;
|
|
|
|
modecount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nextban:
|
|
|
|
s = t;
|
|
|
|
|
|
|
|
if(s != NULL)
|
|
|
|
{
|
|
|
|
if((t = strchr(s, ' ')) != NULL)
|
|
|
|
{
|
|
|
|
*t++ = '\0';
|
|
|
|
|
|
|
|
while(*t == ' ')
|
|
|
|
t++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(modecount)
|
|
|
|
{
|
|
|
|
*mbuf = '\0';
|
|
|
|
*(pbuf - 1) = '\0';
|
|
|
|
sendto_channel_local(mems, chptr, "%s %s", modebuf, parabuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
sendto_server(client_p, chptr, CAP_TS6 | needcap, NOCAPS, ":%s BMASK %ld %s %s :%s",
|
|
|
|
source_p->id, (long) chptr->channelts, chptr->chname, parv[3], parv[4]);
|
|
|
|
return 0;
|
|
|
|
}
|