Anope IRC Services  Version 1.8
cs_ban.c
Go to the documentation of this file.
1 /* ChanServ core functions
2  *
3  * (C) 2003-2014 Anope Team
4  * Contact us at team@anope.org
5  *
6  * Please read COPYING and README for further details.
7  *
8  * Based on the original code of Epona by Lara.
9  * Based on the original code of Services by Andy Church.
10  *
11  *
12  */
13 /*************************************************************************/
14 
15 #include "module.h"
16 
17 static int do_unban(User * u);
18 static int do_ban(User * u);
19 static void myChanServHelp(User * u);
20 
27 int AnopeInit(int argc, char **argv)
28 {
29  Command *c;
30 
31  moduleAddAuthor("Anope");
32  moduleAddVersion(VERSION_STRING);
34 
35  c = createCommand("BAN", do_ban, NULL, CHAN_HELP_BAN, -1, -1, -1, -1);
37  c = createCommand("UNBAN", do_unban, NULL, CHAN_HELP_UNBAN, -1, -1, -1,
38  -1);
40 
42 
43  return MOD_CONT;
44 }
45 
49 void AnopeFini(void)
50 {
51 
52 }
53 
54 
55 
60 static void myChanServHelp(User * u)
61 {
62  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_BAN);
63  notice_lang(s_ChanServ, u, CHAN_HELP_CMD_UNBAN);
64 }
65 
71 static int do_ban(User * u)
72 {
73  char *chan = strtok(NULL, " ");
74  char *params = strtok(NULL, " ");
75  char *reason = strtok(NULL, "");
76 
77  Channel *c;
78  ChannelInfo *ci;
79  User *u2;
80 
81  int is_same;
82 
83  if (!reason) {
84  reason = "Requested";
85  } else {
86  if (strlen(reason) > 200)
87  reason[200] = '\0';
88  }
89 
90  if (!chan) {
91  struct u_chanlist *uc, *next;
92 
93  /* Bans the user on every channels he is on. */
94 
95  for (uc = u->chans; uc; uc = next) {
96  next = uc->next;
97  if ((ci = uc->chan->ci) && !(ci->flags & CI_VERBOTEN)
98  && check_access(u, ci, CA_BANME)) {
99  char *av[3];
100  char mask[BUFSIZE];
101 
102  /*
103  * Dont ban/kick the user on channels where he is excepted
104  * to prevent services <-> server wars.
105  */
106  if (ircd->except) {
107  if (is_excepted(ci, u))
108  notice_lang(s_ChanServ, u, CHAN_EXCEPTED,
109  u->nick, ci->name);
110  continue;
111  }
112  if (is_protected(u)) {
113  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
114  continue;
115  }
116 
117  av[0] = sstrdup("+b");
118  get_idealban(ci, u, mask, sizeof(mask));
119  av[1] = mask;
120  anope_cmd_mode(whosends(ci), uc->chan->name, "+b %s",
121  av[1]);
122  chan_set_modes(s_ChanServ, uc->chan, 2, av, 1);
123  free(av[0]);
124 
125  if ((ci->flags & CI_SIGNKICK)
126  || ((ci->flags & CI_SIGNKICK_LEVEL)
127  && !check_access(u, ci, CA_SIGNKICK)))
128  anope_cmd_kick(whosends(ci), ci->name, u->nick,
129  "%s (%s)", reason, u->nick);
130  else
131  anope_cmd_kick(whosends(ci), ci->name, u->nick, "%s",
132  reason);
133  av[0] = ci->name;
134  av[1] = u->nick;
135  av[2] = reason;
136  do_kick(s_ChanServ, 3, av);
137  }
138  }
139 
140  return MOD_CONT;
141  } else if (!params) {
142  params = u->nick;
143  }
144 
145  is_same = (params == u->nick) ? 1 : (stricmp(params, u->nick) == 0);
146 
147  if (!(c = findchan(chan))) {
148  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
149  } else if (!(ci = c->ci)) {
150  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
151  } else if (ci->flags & CI_VERBOTEN) {
152  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
153  } else if (is_same ? !(u2 = u) : !(u2 = finduser(params))) {
154  notice_lang(s_ChanServ, u, NICK_X_NOT_IN_USE, params);
155  } else if (!is_same ? !check_access(u, ci, CA_BAN) :
156  !check_access(u, ci, CA_BANME)) {
157  notice_lang(s_ChanServ, u, ACCESS_DENIED);
158  } else if (!is_same && (ci->flags & CI_PEACE)
159  && (get_access(u2, ci) >= get_access(u, ci))) {
160  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
161  /*
162  * Dont ban/kick the user on channels where he is excepted
163  * to prevent services <-> server wars.
164  */
165  } else if (ircd->except && is_excepted(ci, u2)) {
166  notice_lang(s_ChanServ, u, CHAN_EXCEPTED, u2->nick, ci->name);
167  } else if (ircd->protectedumode && is_protected(u2)) {
168  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
169  } else {
170  char *av[3];
171  char mask[BUFSIZE];
172 
173  av[0] = sstrdup("+b");
174  get_idealban(ci, u2, mask, sizeof(mask));
175  av[1] = mask;
176  anope_cmd_mode(whosends(ci), c->name, "+b %s", av[1]);
177  chan_set_modes(s_ChanServ, c, 2, av, 1);
178  free(av[0]);
179 
180  /* We still allow host banning while not allowing to kick */
181  if (!is_on_chan(c, u2))
182  return MOD_CONT;
183 
184  if ((ci->flags & CI_SIGNKICK)
185  || ((ci->flags & CI_SIGNKICK_LEVEL)
186  && !check_access(u, ci, CA_SIGNKICK)))
187  anope_cmd_kick(whosends(ci), ci->name, params, "%s (%s)",
188  reason, u->nick);
189  else
190  anope_cmd_kick(whosends(ci), ci->name, params, "%s", reason);
191 
192  av[0] = ci->name;
193  av[1] = params;
194  av[2] = reason;
195  do_kick(s_ChanServ, 3, av);
196  }
197  return MOD_CONT;
198 }
199 
205 static int do_unban(User * u)
206 {
207  char *chan = strtok(NULL, " ");
208  Channel *c;
209  ChannelInfo *ci;
210 
211  if (!chan) {
212  syntax_error(s_ChanServ, u, "UNBAN", CHAN_UNBAN_SYNTAX);
213  } else if (!(c = findchan(chan))) {
214  notice_lang(s_ChanServ, u, CHAN_X_NOT_IN_USE, chan);
215  } else if (!(ci = c->ci)) {
216  notice_lang(s_ChanServ, u, CHAN_X_NOT_REGISTERED, chan);
217  } else if (ci->flags & CI_VERBOTEN) {
218  notice_lang(s_ChanServ, u, CHAN_X_FORBIDDEN, chan);
219  } else if (!check_access(u, ci, CA_UNBAN)) {
220  notice_lang(s_ChanServ, u, PERMISSION_DENIED);
221  } else {
222  common_unban_full(ci, u->nick, true);
223  notice_lang(s_ChanServ, u, CHAN_UNBANNED, chan);
224  }
225  return MOD_CONT;
226 }
char nick[NICKMAX]
Definition: services.h:875
E IRCDVar * ircd
Definition: extern.h:39
E void do_kick(const char *source, int ac, char **av)
Definition: channels.c:638
E int check_access(User *user, ChannelInfo *ci, int what)
Definition: chanserv.c:1974
int AnopeInit(int argc, char **argv)
Definition: cs_ban.c:27
E int stricmp(const char *s1, const char *s2)
Definition: compat.c:58
#define CA_BAN
Definition: services.h:786
#define CI_VERBOTEN
Definition: services.h:725
E void chan_set_modes(const char *source, Channel *chan, int ac, char **av, int check)
Definition: channels.c:161
struct user_::u_chanlist * chans
#define CA_SIGNKICK
Definition: services.h:780
E int is_on_chan(Channel *c, User *u)
Definition: channels.c:517
E int is_protected(User *user)
Definition: users.c:924
MDE void moduleAddAuthor(const char *author)
Definition: modules.c:1772
ChannelInfo * ci
Definition: services.h:1001
E void syntax_error(char *service, User *u, const char *command, int msgnum)
Definition: language.c:295
char name[CHANMAX]
Definition: services.h:654
int except
Definition: services.h:320
static int do_ban(User *u)
Definition: cs_ban.c:71
E void notice_lang(char *source, User *dest, int message,...)
Definition: send.c:169
MDE void moduleSetType(MODType type)
Definition: modules.c:818
E int is_excepted(ChannelInfo *ci, User *user)
Definition: users.c:950
E Channel * findchan(const char *chan)
Definition: channels.c:394
E char * sstrdup(const char *s)
Definition: memory.c:105
#define CI_PEACE
Definition: services.h:721
E int get_idealban(ChannelInfo *ci, User *u, char *ret, int retlen)
Definition: chanserv.c:2380
E void anope_cmd_kick(char *source, char *chan, char *user, const char *fmt,...)
Definition: ircd.c:230
#define CA_UNBAN
Definition: services.h:752
uint32 flags
Definition: services.h:669
E User * finduser(const char *nick)
Definition: users.c:323
uint32 protectedumode
Definition: services.h:323
MDE void moduleAddVersion(const char *version)
Definition: modules.c:1760
E void common_unban_full(ChannelInfo *ci, char *nick, boolean full)
Definition: actions.c:214
MDE void moduleSetChanHelp(void(*func)(User *u))
Definition: modules.c:2090
Command * c
Definition: ns_recover.c:17
#define CHANSERV
Definition: modules.h:60
User * next
Definition: services.h:873
static void myChanServHelp(User *u)
Definition: cs_ban.c:60
#define MOD_CONT
Definition: modules.h:54
#define CI_SIGNKICK
Definition: services.h:737
#define CI_SIGNKICK_LEVEL
Definition: services.h:739
#define whosends(ci)
Definition: extern.h:163
E void anope_cmd_mode(char *source, char *dest, const char *fmt,...)
Definition: ircd.c:211
Definition: modules.h:99
MDE Command * createCommand(const char *name, int(*func)(User *u), int(*has_priv)(User *u), int help_all, int help_reg, int help_oper, int help_admin, int help_root)
Definition: modules.c:987
static int do_unban(User *u)
Definition: cs_ban.c:205
char name[CHANMAX]
Definition: services.h:1000
E char * s_ChanServ
Definition: extern.h:285
E int get_access(User *user, ChannelInfo *ci)
Definition: chanserv.c:2332
#define CA_BANME
Definition: services.h:785
MDE int moduleAddCommand(CommandHash *cmdTable[], Command *c, int pos)
Definition: modules.c:1082
void AnopeFini(void)
Definition: cs_ban.c:49
#define BUFSIZE
Definition: config.h:47
#define MOD_UNIQUE
Definition: module.h:11