]>
Commit | Line | Data |
---|---|---|
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 | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "channel.h" | |
29 | #include "client.h" | |
30 | #include "hash.h" | |
31 | #include "match.h" | |
32 | #include "ircd.h" | |
33 | #include "numeric.h" | |
34 | #include "s_user.h" | |
35 | #include "s_conf.h" | |
36 | #include "s_newconf.h" | |
37 | #include "s_serv.h" | |
38 | #include "send.h" | |
39 | #include "msg.h" | |
40 | #include "parse.h" | |
41 | #include "modules.h" | |
42 | #include "packet.h" | |
43 | ||
44 | static int mo_omode(struct Client *, struct Client *, int, const char **); | |
45 | ||
46 | struct Message omode_msgtab = { | |
47 | "OMODE", 0, 0, 0, MFLG_SLOW, | |
48 | {mg_unreg, mg_not_oper, mg_ignore, mg_ignore, mg_ignore, {mo_omode, 3}} | |
49 | }; | |
50 | ||
51 | mapi_clist_av1 omode_clist[] = { &omode_msgtab, NULL }; | |
52 | ||
53 | DECLARE_MODULE_AV1(omode, NULL, NULL, omode_clist, NULL, NULL, "$Revision: 3121 $"); | |
54 | ||
55 | /* | |
56 | * mo_omode - MODE command handler | |
57 | * parv[1] - channel | |
58 | */ | |
59 | static int | |
60 | mo_omode(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
61 | { | |
62 | struct Channel *chptr = NULL; | |
63 | struct membership *msptr; | |
64 | char params[512]; | |
65 | int i; | |
66 | int wasonchannel; | |
67 | ||
68 | /* admins only */ | |
69 | if(!IsOperAdmin(source_p)) | |
70 | { | |
71 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, source_p->name, "admin"); | |
72 | return 0; | |
73 | } | |
74 | ||
75 | /* Now, try to find the channel in question */ | |
76 | if(!IsChanPrefix(parv[1][0]) || !check_channel_name(parv[1])) | |
77 | { | |
78 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
79 | form_str(ERR_BADCHANNAME), parv[1]); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | chptr = find_channel(parv[1]); | |
84 | ||
85 | if(chptr == NULL) | |
86 | { | |
87 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
88 | form_str(ERR_NOSUCHCHANNEL), parv[1]); | |
89 | return 0; | |
90 | } | |
91 | ||
92 | /* Now know the channel exists */ | |
93 | msptr = find_channel_membership(chptr, source_p); | |
94 | wasonchannel = msptr != NULL; | |
95 | ||
96 | if (is_any_op(msptr)) | |
97 | { | |
98 | sendto_one_notice(source_p, ":Use a normal MODE you idiot"); | |
99 | return 0; | |
100 | } | |
101 | ||
102 | params[0] = '\0'; | |
103 | for (i = 2; i < parc; i++) | |
104 | { | |
105 | if (i != 2) | |
106 | rb_strlcat(params, " ", sizeof params); | |
107 | rb_strlcat(params, parv[i], sizeof params); | |
108 | } | |
109 | ||
110 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
111 | "OMODE called for [%s] [%s] by %s!%s@%s", | |
112 | parv[1], params, source_p->name, source_p->username, source_p->host); | |
113 | ilog(L_MAIN, "OMODE called for [%s] [%s] by %s", | |
114 | parv[1], params, get_oper_name(source_p)); | |
115 | ||
116 | if(*chptr->chname != '&') | |
117 | sendto_server(NULL, NULL, NOCAPS, NOCAPS, | |
118 | ":%s WALLOPS :OMODE called for [%s] [%s] by %s!%s@%s", | |
119 | me.name, parv[1], params, source_p->name, source_p->username, | |
120 | source_p->host); | |
121 | ||
122 | #if 0 | |
123 | set_channel_mode(client_p, source_p->servptr, chptr, msptr, | |
124 | parc - 2, parv + 2); | |
125 | #else | |
126 | if (parc == 4 && !strcmp(parv[2], "+a") && !irccmp(parv[3], source_p->name)) | |
127 | { | |
128 | /* Admining themselves */ | |
129 | if (!wasonchannel) | |
130 | { | |
131 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
132 | form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); | |
133 | return 0; | |
134 | } | |
135 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +a %s", | |
136 | me.name, parv[1], source_p->name); | |
137 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
138 | ":%s TMODE %ld %s +a %s", | |
139 | me.id, (long) chptr->channelts, parv[1], | |
140 | source_p->id); | |
141 | msptr->flags |= CHFL_ADMIN; | |
142 | } | |
143 | else if (parc == 4 && !strcmp(parv[2], "+o") && !irccmp(parv[3], source_p->name)) | |
144 | { | |
145 | /* Opping themselves */ | |
146 | if (!wasonchannel) | |
147 | { | |
148 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
149 | form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); | |
150 | return 0; | |
151 | } | |
152 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +o %s", | |
153 | me.name, parv[1], source_p->name); | |
154 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
155 | ":%s TMODE %ld %s +o %s", | |
156 | me.id, (long) chptr->channelts, parv[1], | |
157 | source_p->id); | |
158 | msptr->flags |= CHFL_CHANOP; | |
159 | } | |
160 | else if (parc == 4 && !strcmp(parv[2], "+h") && !irccmp(parv[3], source_p->name)) | |
161 | { | |
162 | /* Halfopping themselves */ | |
163 | if (!wasonchannel) | |
164 | { | |
165 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
166 | form_str(ERR_USERNOTINCHANNEL), parv[3], chptr->chname); | |
167 | return 0; | |
168 | } | |
169 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s +h %s", | |
170 | me.name, parv[1], source_p->name); | |
171 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
172 | ":%s TMODE %ld %s +h %s", | |
173 | me.id, (long) chptr->channelts, parv[1], | |
174 | source_p->id); | |
175 | msptr->flags |= CHFL_HALFOP; | |
176 | } | |
177 | else if (ConfigChannel.use_admin) | |
178 | { | |
179 | /* Hack it so set_channel_mode() will accept */ | |
180 | if (wasonchannel) | |
181 | msptr->flags |= CHFL_ADMIN; | |
182 | else | |
183 | { | |
184 | add_user_to_channel(chptr, source_p, CHFL_CHANOP); | |
185 | msptr = find_channel_membership(chptr, source_p); | |
186 | } | |
187 | set_channel_mode(client_p, source_p, chptr, msptr, | |
188 | parc - 2, parv + 2); | |
189 | /* We know they were not opped before and they can't have opped | |
190 | * themselves as set_channel_mode() does not allow that | |
191 | * -- jilles */ | |
192 | if (wasonchannel) | |
193 | msptr->flags &= ~CHFL_ADMIN; | |
194 | else | |
195 | remove_user_from_channel(msptr); | |
196 | } | |
197 | else | |
198 | { | |
199 | /* CHFL_ADMIN is only useful if admin is enabled | |
200 | * so hack it with op if it is not. */ | |
201 | if (wasonchannel) | |
202 | msptr->flags |= CHFL_CHANOP; | |
203 | else | |
204 | { | |
205 | add_user_to_channel(chptr, source_p, CHFL_CHANOP); | |
206 | msptr = find_channel_membership(chptr, source_p); | |
207 | } | |
208 | set_channel_mode(client_p, source_p, chptr, msptr, | |
209 | parc - 2, parv + 2); | |
210 | /* We know they were not opped before and they can't have opped | |
211 | * themselves as set_channel_mode() does not allow that | |
212 | * -- jilles */ | |
213 | if (wasonchannel) | |
214 | msptr->flags &= ~CHFL_CHANOP; | |
215 | else | |
216 | remove_user_from_channel(msptr); | |
217 | } | |
218 | #endif | |
219 | return 0; | |
220 | } |