]> jfr.im git - solanum.git/blame - extensions/m_omode.c
Merge pull request #302 from edk0/sasl-usercloak
[solanum.git] / extensions / m_omode.c
CommitLineData
212380e3
AC
1/*
2 * Charybdis: an advanced Internet Relay Chat Daemon(ircd).
3 * m_omode.c: allows oper mode hacking
4 *
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2004 ircd-ratbox development team
8 * Copyright (C) 2006 Charybdis development team
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
212380e3
AC
24 */
25
26#include "stdinc.h"
212380e3
AC
27#include "channel.h"
28#include "client.h"
29#include "hash.h"
4562c604 30#include "match.h"
212380e3
AC
31#include "ircd.h"
32#include "numeric.h"
33#include "s_user.h"
34#include "s_conf.h"
35#include "s_newconf.h"
36#include "s_serv.h"
37#include "send.h"
38#include "msg.h"
39#include "parse.h"
40#include "modules.h"
41#include "packet.h"
4f253f11 42#include "messages.h"
77d3d2db 43#include "logger.h"
212380e3 44
eeabf33a
EM
45static const char omode_desc[] = "Allow admins to forcibly change modes on channels with the OMODE command";
46
3c7d6fcc 47static void mo_omode(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
212380e3
AC
48
49struct Message omode_msgtab = {
7baa37a9 50 "OMODE", 0, 0, 0, 0,
212380e3
AC
51 {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_omode, 3}}
52};
53
54mapi_clist_av1 omode_clist[] = { &omode_msgtab, NULL };
55
02369fa7 56DECLARE_MODULE_AV2(omode, NULL, NULL, omode_clist, NULL, NULL, NULL, NULL, omode_desc);
212380e3
AC
57
58/*
59 * mo_omode - MODE command handler
212380e3
AC
60 * parv[1] - channel
61 */
3c7d6fcc 62static void
760bafda 63mo_omode(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
212380e3
AC
64{
65 struct Channel *chptr = NULL;
66 struct membership *msptr;
67 char params[512];
68 int i;
69 int wasonchannel;
70
71 /* admins only */
72 if(!IsOperAdmin(source_p))
73 {
74 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin");
3c7d6fcc 75 return;
212380e3
AC
76 }
77
78 /* Now, try to find the channel in question */
79 if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1]))
80 {
81 sendto_one_numeric(source_p, ERR_BADCHANNAME,
82 form_str(ERR_BADCHANNAME), parv[1]);
3c7d6fcc 83 return;
212380e3
AC
84 }
85
86 chptr = find_channel(parv[1]);
87
88 if(chptr == NULL)
89 {
90 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
91 form_str(ERR_NOSUCHCHANNEL), parv[1]);
3c7d6fcc 92 return;
212380e3
AC
93 }
94
95 /* Now know the channel exists */
96 msptr = find_channel_membership(chptr, source_p);
97 wasonchannel = msptr != NULL;
98
99 if (is_chanop(msptr))
100 {
101 sendto_one_notice(source_p, ":Use a normal MODE you idiot");
3c7d6fcc 102 return;
212380e3
AC
103 }
104
105 params[0] = '\0';
106 for (i = 2; i < parc; i++)
107 {
108 if (i != 2)
1f9de103
VY
109 rb_strlcat(params, " ", sizeof params);
110 rb_strlcat(params, parv[i], sizeof params);
212380e3
AC
111 }
112
55abcbb2 113 sendto_wallops_flags(UMODE_WALLOP, &me,
212380e3
AC
114 "OMODE called for [%s] [%s] by %s!%s@%s",
115 parv[1], params, source_p->name, source_p->username, source_p->host);
116 ilog(L_MAIN, "OMODE called for [%s] [%s] by %s",
117 parv[1], params, get_oper_name(source_p));
118
119 if(*chptr->chname != '&')
55abcbb2 120 sendto_server(NULL, NULL, NOCAPS, NOCAPS,
212380e3
AC
121 ":%s WALLOPS :OMODE called for [%s] [%s] by %s!%s@%s",
122 me.name, parv[1], params, source_p->name, source_p->username,
123 source_p->host);
124
125#if 0
55abcbb2 126 set_channel_mode(client_p, source_p->servptr, chptr, msptr,
212380e3
AC
127 parc - 2, parv + 2);
128#else
129 if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name))
130 {
131 /* Opping themselves */
132 if (!wasonchannel)
133 {
134 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
135 form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname);
3c7d6fcc 136 return;
212380e3 137 }
4b1cce65 138 sendto_channel_local(&me, ALL_MEMBERS, chptr, ":%s MODE %s +o %s",
212380e3
AC
139 me.name, parv[1], source_p->name);
140 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
141 ":%s TMODE %ld %s +o %s",
142 me.id, (long) chptr->channelts, parv[1],
143 source_p->id);
212380e3
AC
144 msptr->flags |= CHFL_CHANOP;
145 }
146 else
147 {
148 /* Hack it so set_channel_mode() will accept */
149 if (wasonchannel)
150 msptr->flags |= CHFL_CHANOP;
151 else
152 {
153 add_user_to_channel(chptr, source_p, CHFL_CHANOP);
154 msptr = find_channel_membership(chptr, source_p);
155 }
55abcbb2 156 set_channel_mode(client_p, source_p, chptr, msptr,
212380e3
AC
157 parc - 2, parv + 2);
158 /* We know they were not opped before and they can't have opped
159 * themselves as set_channel_mode() does not allow that
160 * -- jilles */
161 if (wasonchannel)
162 msptr->flags &= ~CHFL_CHANOP;
163 else
164 remove_user_from_channel(msptr);
165 }
166#endif
212380e3 167}