1 attempt to move checks for chanmodes c C N T u into
2 the *_can_send_to_channel() functions in channel.c where ircu by default has its chanmode checks
4 instead of having them in each of the places used (m_wallchops, m_wallvoices, ircd_relay.c, etc.)
7 client_can_send_to_channel()
9 member_can_send_to_channel()
11 move our cCNT mode checks to new function can_send_to_channel() used
12 from the two functions above
13 now the checks for cCNT modes are in one place.
14 check for +u remains in member_can_send_to_chan() - as quit from non-member does not show
16 need to verify handling of remote users, services, servers etc.
18 possible problem discovered (ircu):
19 in some places *_can_send_to_channel() is first called with reveal delayedjoin user ON
20 but the code then proceeds to check target limits, which upon refusal means the delayedjoin
21 user is revealed (locally) without actually sending anything to the channel...
22 ...that seems wrong/weird
24 diff -r e5a9f5ebb56d include/channel.h
25 --- a/include/channel.h Sat Jan 31 18:37:49 2009 +0100
26 +++ b/include/channel.h Sat Jan 31 18:40:26 2009 +0100
28 #define MODE_DELJOINS 0x1000 /**< New join messages are delayed */
29 #define MODE_REGISTERED 0x2000 /**< Channel marked as registered
30 * (for future semantic expansion) */
31 -#define MODE_NOCOLOUR 0x4000 /**< No mIRC/ANSI colors/bold */
32 -#define MODE_NOCTCP 0x8000 /**< No channel CTCPs */
33 -#define MODE_NONOTICE 0x10000 /**< No channel notices */
34 +#define MODE_NOCOLOUR 0x4000 /**< +c No mIRC/ANSI colors/bold */
35 +#define MODE_NOCTCP 0x8000 /**< +C No channel CTCPs */
36 +#define MODE_NONOTICE 0x10000 /**< +N No channel notices */
37 #define MODE_SAVE 0x20000 /**< save this mode-with-arg 'til
39 #define MODE_FREE 0x40000 /**< string needs to be passed to
41 #define MODE_APASS 0x200000
42 #define MODE_WASDELJOINS 0x400000 /**< Not DELJOINS, but some joins
44 -#define MODE_NOQUITPARTS 0x800000
45 +#define MODE_NOQUITPARTS 0x800000 /**< +u No user defined quit or part messages */
47 #define MODE_NOMULTITARGET 0x1000000 /**< +T No multiple targets */
48 #define MODE_MODERATENOREG 0x2000000 /**< +M Moderate unauthed users */
51 extern const char* find_no_nickchange_channel(struct Client* cptr);
52 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
53 -extern int member_can_send_to_channel(struct Membership* member, int reveal);
54 -extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
55 +extern int member_can_send_to_channel(struct Membership* member, int reveal,
56 + unsigned int flags, const char *text, const int target);
57 +extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr,
58 + int reveal, unsigned int flags, const char *text, const int target);
59 +extern int can_send_to_channel(struct Client *cptr, struct Channel *chptr,
60 + unsigned int flags, const char *text, const int target);
62 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
63 extern void remove_user_from_all_channels(struct Client* cptr);
64 diff -r e5a9f5ebb56d ircd/channel.c
65 --- a/ircd/channel.c Sat Jan 31 18:37:49 2009 +0100
66 +++ b/ircd/channel.c Sat Jan 31 18:40:26 2009 +0100
68 * @param member The membership of the user
69 * @param reveal If true, the user will be "revealed" on a delayed
71 + * @param flags The bitmask of additional modes to check (besides +n +m +r +M +b)
72 + * @param text The message from the user, needed for modes +c and +C
73 + * @param target The number of targets the message is sent to, for +T
75 * @returns True if the client can speak on the channel.
77 -int member_can_send_to_channel(struct Membership* member, int reveal)
78 +int member_can_send_to_channel(struct Membership* member, int reveal,
79 + unsigned int flags, const char *text, const int target)
84 * temporary desynch, or maybe they are on an older server, but
85 * we do not want to send ERR_CANNOTSENDTOCHAN more than once.
87 - if (!MyUser(member->user))
89 + /* client on service server (+s) - let it through */
90 + if (IsService(cli_user(member->user)->server)) {
91 if (IsDelayedJoin(member) && reveal)
92 RevealDelayedJoin(member);
96 - /* +X user can always speak on the channel */
98 + /* +X exclude +X clients from modes +mMR and bans */
99 if (IsXtraOp(member->user)) {
100 + if (!can_send_to_channel(member->user, member->channel, flags, text, target))
102 if (IsDelayedJoin(member) && reveal)
103 RevealDelayedJoin(member);
107 /* If you have voice or ops, you can speak. */
108 if (IsVoicedOrOpped(member))
110 + return can_send_to_channel(member->user, member->channel, flags, text, target);
113 * If it's moderated, and you aren't a privileged user, you can't
115 if (is_banned(member))
118 + /* enough checked for remote users */
119 + if (!MyUser(member->user)) {
120 + if (IsDelayedJoin(member) && reveal)
121 + RevealDelayedJoin(member);
125 + /* +u check for user defined quit and part messages,
126 + * and they are not allowed
128 + if ((flags & MODE_NOQUITPARTS) && (member->channel->mode.mode & MODE_NOQUITPARTS))
131 + /* check various other modes (like cCNT) */
132 + if (!can_send_to_channel(member->user, member->channel, flags, text, target))
135 if (IsDelayedJoin(member) && reveal)
136 RevealDelayedJoin(member);
138 @@ -746,16 +769,22 @@
139 * @param chptr The channel to check
140 * @param reveal If the user should be revealed (see
141 * member_can_send_to_channel())
142 + * @param flags The bitmask of additional modes to check (besides +n +m +r +M +b)
143 + * @param text The message needed to check for +c and +C
144 + * @param target The number of targets the message is sent to, for +T
146 * @returns true if the client is allowed to speak on the channel, false
149 * @see member_can_send_to_channel()
151 -int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal)
152 +int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal,
153 + unsigned int flags, const char *text, const int target)
155 struct Membership *member;
161 * Servers can always speak on channels.
163 @@ -769,15 +798,90 @@
167 - if (IsXtraOp(cptr))
168 + /* client on service server (+s) - let it through */
169 + if (IsService(cli_user(cptr)->server))
171 - else if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED)) ||
172 - ((chptr->mode.mode & (MODE_REGONLY|MODE_MODERATENOREG)) && !IsAccount(cptr)))
173 + /* client with umode +X exempt from modes +nmrM and bans */
174 + if (!IsXtraOp(cptr)) {
175 + if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED)) ||
176 + ((chptr->mode.mode & (MODE_REGONLY|MODE_MODERATENOREG)) && !IsAccount(cptr)))
178 + if (find_ban(cptr, chptr->banlist))
181 + /* check various other modes (like cCNT) */
182 + if (!can_send_to_channel(cptr, chptr, flags, text, target))
185 - return !find_ban(cptr, chptr->banlist);
187 - return member_can_send_to_channel(member, reveal);
188 + return member_can_send_to_channel(member, reveal, flags, text, target);
191 +/** Check if a client can send to a channel.
193 + * These checks are done for both clients on and off the channel.
195 + * @param cptr The client to check
196 + * @param chptr The channel to check
197 + * @param flags The bitmask of modes to check
198 + * @param text The message needed to check for +c and +C
199 + * @param target The number of targets the message is sent to, for +T
201 + * @returns true if the client is allowed to speak on the channel, false
204 + * @see client_can_send_to_channel()
205 + * @see member_can_send_to_channel()
207 +int can_send_to_channel(struct Client *cptr, struct Channel *chptr,
208 + unsigned int flags, const char *text, const int target)
211 + unsigned int modes;
212 + int controlcodes = 0;
215 + assert(0 != chptr);
217 + modes = chptr->mode.mode;
219 + /* only check these modes on local users */
223 + /* +T check for multi target message and they are not allowed */
224 + if ((flags & MODE_NOMULTITARGET) && (modes & MODE_NOMULTITARGET) &&
228 + /* +N check for channel wide notice and they are not allowed */
229 + if ((flags & MODE_NONOTICE) && (modes & MODE_NONOTICE))
232 + /* these last two checks should always be last
233 + * as they loop over the entire message in search for
234 + * CTCP char and control codes
236 + /* +C check for CTCP and CTCPs are not allowed */
237 + if ((flags & MODE_NOCTCP) && (modes & MODE_NOCTCP) && (text != NULL) &&
238 + ircd_strncmp(text,"\001ACTION ",8)) {
239 + for (ch=text;*ch;) {
242 + if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
247 + /* +c check for control codes and they are not allowed */
248 + if ((flags & MODE_NOCOLOUR) && (modes & MODE_NOCOLOUR) && (text != NULL)) {
249 + if (controlcodes) /* already found control codes */
251 + for (ch=text;*ch;ch++) {
252 + if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
259 /** Returns the name of a channel that prevents the user from changing nick.
260 @@ -3627,13 +3731,11 @@
261 /* Send notification to channel */
262 if (!(flags & (CHFL_ZOMBIE | CHFL_DELAYED)))
263 sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_PART, chan, NULL, 0,
264 - ((flags & CHFL_BANNED) || ((chan->mode.mode & MODE_NOQUITPARTS)
265 - && !IsChannelService(member->user)) || !jbuf->jb_comment) ?
266 + ((flags & CHFL_BANNED) || !jbuf->jb_comment) ?
267 "%H" : "%H :%s", chan, jbuf->jb_comment);
268 else if (MyUser(jbuf->jb_source))
269 sendcmdto_one(jbuf->jb_source, CMD_PART, jbuf->jb_source,
270 - ((flags & CHFL_BANNED) || (chan->mode.mode & MODE_NOQUITPARTS)
271 - || !jbuf->jb_comment) ?
272 + ((flags & CHFL_BANNED) || !jbuf->jb_comment) ?
273 ":%H" : "%H :%s", chan, jbuf->jb_comment);
274 /* XXX: Shouldn't we send a PART here anyway? */
275 /* to users on the channel? Why? From their POV, the user isn't on
276 diff -r e5a9f5ebb56d ircd/ircd_relay.c
277 --- a/ircd/ircd_relay.c Sat Jan 31 18:37:49 2009 +0100
278 +++ b/ircd/ircd_relay.c Sat Jan 31 18:40:26 2009 +0100
280 void relay_channel_message(struct Client* sptr, const char* name, const char* text, const int targetc)
282 struct Channel* chptr;
289 * This first: Almost never a server/service
291 - if (!client_can_send_to_channel(sptr, chptr, 1)) {
292 + if (!client_can_send_to_channel(sptr, chptr, 1,
293 + (MODE_NOCOLOUR | MODE_NOCTCP | MODE_NOMULTITARGET), text, targetc)) {
294 send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
297 + /* TODO: what is this again?
298 + * client_can_send_to_channel already reveals delayed join user
299 + * locally anyway, and now the message gets denied?
302 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
303 check_target_limit(sptr, chptr, chptr->chname, 0))
307 - if ((chptr->mode.mode & MODE_NOMULTITARGET) && (targetc > 1)) {
308 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
313 - if (chptr->mode.mode & MODE_NOCOLOUR)
314 - for (ch=text;*ch;ch++)
315 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
316 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
320 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(text,"\001ACTION ",8))
323 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
328 sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr),
329 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
331 void relay_channel_notice(struct Client* sptr, const char* name, const char* text, const int targetc)
333 struct Channel* chptr;
338 @@ -153,31 +135,15 @@
340 * This first: Almost never a server/service
342 - if (!client_can_send_to_channel(sptr, chptr, 1))
343 + if (!client_can_send_to_channel(sptr, chptr, 1,
344 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP | MODE_NOMULTITARGET), text, targetc))
347 + /* TODO: idem as in previous function */
348 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
349 check_target_limit(sptr, chptr, chptr->chname, 0))
352 - if ((chptr->mode.mode & MODE_NONOTICE))
356 - if ((chptr->mode.mode & MODE_NOMULTITARGET) && (targetc > 1))
360 - if (chptr->mode.mode & MODE_NOCOLOUR)
361 - for (ch=text;*ch;ch++)
362 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
365 - if (chptr->mode.mode & MODE_NOCTCP)
370 sendcmdto_channel_butone(sptr, CMD_NOTICE, chptr, cli_from(sptr),
371 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
374 * This first: Almost never a server/service
375 * Servers may have channel services, need to check for it here
377 - if (client_can_send_to_channel(sptr, chptr, 1) || IsChannelService(sptr)) {
378 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
379 sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr),
380 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
383 * This first: Almost never a server/service
384 * Servers may have channel services, need to check for it here
386 - if (client_can_send_to_channel(sptr, chptr, 1) || IsChannelService(sptr)) {
387 + /* TODO: check how we get here */
388 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
389 sendcmdto_channel_butone(sptr, CMD_NOTICE, chptr, cli_from(sptr),
390 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
392 diff -r e5a9f5ebb56d ircd/m_part.c
393 --- a/ircd/m_part.c Sat Jan 31 18:37:49 2009 +0100
394 +++ b/ircd/m_part.c Sat Jan 31 18:40:26 2009 +0100
397 assert(!IsZombie(member)); /* Local users should never zombie */
399 - if (!member_can_send_to_channel(member, 0))
400 + /* check +u here or later somewhere in channel.c ? */
401 + if (!member_can_send_to_channel(member, 0, MODE_NOQUITPARTS, NULL, 1))
403 flags |= CHFL_BANNED;
404 /* Remote clients don't want to see a comment either. */
405 diff -r e5a9f5ebb56d ircd/m_quit.c
406 --- a/ircd/m_quit.c Sat Jan 31 18:37:49 2009 +0100
407 +++ b/ircd/m_quit.c Sat Jan 31 18:40:26 2009 +0100
409 struct Membership* chan;
410 /* (slug for +u) removed !IsDelayedJoin(chan) as splidge said to */
411 for (chan = cli_user(sptr)->channel; chan; chan = chan->next_channel) {
412 - if (!IsZombie(chan) && (!member_can_send_to_channel(chan, 0)
413 - || (chan->channel->mode.mode & MODE_NOQUITPARTS)))
414 + if (!IsZombie(chan) && (!member_can_send_to_channel(chan, 0,
415 + MODE_NOQUITPARTS, NULL, 1)))
416 return exit_client(cptr, sptr, sptr, "Signed off");
419 diff -r e5a9f5ebb56d ircd/m_topic.c
420 --- a/ircd/m_topic.c Sat Jan 31 18:37:49 2009 +0100
421 +++ b/ircd/m_topic.c Sat Jan 31 18:40:26 2009 +0100
424 else if ((chptr->mode.mode & MODE_TOPICLIMIT) && !is_chan_op(sptr, chptr))
425 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
426 - else if (!client_can_send_to_channel(sptr, chptr, 1))
427 + else if (!client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1))
428 send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
430 do_settopic(sptr,cptr,chptr,topic,0);
431 diff -r e5a9f5ebb56d ircd/m_wallchops.c
432 --- a/ircd/m_wallchops.c Sat Jan 31 18:37:49 2009 +0100
433 +++ b/ircd/m_wallchops.c Sat Jan 31 18:40:26 2009 +0100
436 struct Channel *chptr;
437 struct Membership* member;
441 assert(cptr == sptr);
442 @@ -117,24 +116,13 @@
443 return send_reply(sptr, ERR_NOTEXTTOSEND);
445 if (IsChannelName(parv[1]) && (chptr = FindChannel(parv[1]))) {
446 - if (client_can_send_to_channel(sptr, chptr, 0) && !(chptr->mode.mode & MODE_NONOTICE)) {
447 + /* check also for modes +N +c and +C */
448 + if (client_can_send_to_channel(sptr, chptr, 0,
449 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP), parv[parc - 1], 1)) {
450 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
451 check_target_limit(sptr, chptr, chptr->chname, 0))
455 - if (chptr->mode.mode & MODE_NOCOLOUR)
456 - for (ch=parv[parc - 1];*ch;ch++)
457 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
461 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(parv[parc - 1],"\001ACTION ",8))
462 - for (ch=parv[parc - 1];*ch;)
467 /* Reveal delayedjoin user */
468 if ((member = find_member_link(chptr, cptr)) && IsDelayedJoin(member))
469 RevealDelayedJoin(member);
473 if (!IsLocalChannel(parv[1]) && (chptr = FindChannel(parv[1]))) {
474 - if (client_can_send_to_channel(sptr, chptr, 1)) {
475 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
476 sendcmdto_channel_butone(sptr, CMD_WALLCHOPS, chptr, cptr,
477 SKIP_DEAF | SKIP_BURST | SKIP_NONOPS,
478 "%H :%s", chptr, parv[parc - 1]);
479 diff -r e5a9f5ebb56d ircd/m_wallvoices.c
480 --- a/ircd/m_wallvoices.c Sat Jan 31 18:37:49 2009 +0100
481 +++ b/ircd/m_wallvoices.c Sat Jan 31 18:40:26 2009 +0100
484 struct Channel *chptr;
485 struct Membership* member;
489 assert(cptr == sptr);
490 @@ -116,24 +115,12 @@
491 return send_reply(sptr, ERR_NOTEXTTOSEND);
493 if (IsChannelName(parv[1]) && (chptr = FindChannel(parv[1]))) {
494 - if (client_can_send_to_channel(sptr, chptr, 0) && !(chptr->mode.mode & MODE_NONOTICE)) {
495 + if (client_can_send_to_channel(sptr, chptr, 0,
496 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP), parv[parc - 1], 1)) {
497 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
498 check_target_limit(sptr, chptr, chptr->chname, 0))
502 - if (chptr->mode.mode & MODE_NOCOLOUR)
503 - for (ch=parv[parc - 1];*ch;ch++)
504 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
508 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(parv[parc - 1],"\001ACTION ",8))
509 - for (ch=parv[parc - 1];*ch;)
514 /* Reveal delayedjoin user */
515 if ((member = find_member_link(chptr, cptr)) && IsDelayedJoin(member))
516 RevealDelayedJoin(member);
520 if (!IsLocalChannel(parv[1]) && (chptr = FindChannel(parv[1]))) {
521 - if (client_can_send_to_channel(sptr, chptr, 1)) {
522 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
523 sendcmdto_channel_butone(sptr, CMD_WALLVOICES, chptr, cptr,
524 SKIP_DEAF | SKIP_BURST | SKIP_NONVOICES,
525 "%H :%s", chptr, parv[parc - 1]);