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 7113a0179d71 include/channel.h
25 --- a/include/channel.h Wed Jan 21 16:44:50 2009 +0100
26 +++ b/include/channel.h Wed Jan 21 17:13:44 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);
60 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
61 extern void remove_user_from_all_channels(struct Client* cptr);
62 diff -r 7113a0179d71 ircd/channel.c
63 --- a/ircd/channel.c Wed Jan 21 16:44:50 2009 +0100
64 +++ b/ircd/channel.c Wed Jan 21 17:13:44 2009 +0100
66 * @param member The membership of the user
67 * @param reveal If true, the user will be "revealed" on a delayed
69 + * @param flags The bitmask of additional modes to check (besides +n +m +r +M +b)
70 + * @param text The message from the user, needed for modes +c and +C
71 + * @param target The number of targets the message is sent to, for +T
73 * @returns True if the client can speak on the channel.
75 -int member_can_send_to_channel(struct Membership* member, int reveal)
76 +int member_can_send_to_channel(struct Membership* member, int reveal,
77 + unsigned int flags, const char *text, const int target)
82 * temporary desynch, or maybe they are on an older server, but
83 * we do not want to send ERR_CANNOTSENDTOCHAN more than once.
85 - if (!MyUser(member->user))
87 + /* client on service server (+s) - let it through */
88 + if (IsService(cli_user(member->user)->server)) {
89 if (IsDelayedJoin(member) && reveal)
90 RevealDelayedJoin(member);
94 - /* +X user can always speak on the channel */
96 + /* +X exclude +X clients from modes +mMR and bans */
97 if (IsXtraOp(member->user)) {
98 + if (!can_send_to_channel(member->user, member->channel, flags, text, target))
100 if (IsDelayedJoin(member) && reveal)
101 RevealDelayedJoin(member);
105 /* If you have voice or ops, you can speak. */
106 if (IsVoicedOrOpped(member))
108 + return can_send_to_channel(member->user, member->channel, flags, text, target);
111 * If it's moderated, and you aren't a privileged user, you can't
114 /* If you're banned then you can't speak either. */
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 @@ -744,16 +767,22 @@
137 * @param chptr The channel to check
138 * @param reveal If the user should be revealed (see
139 * member_can_send_to_channel())
140 + * @param flags The bitmask of additional modes to check (besides +n +m +r +M +b)
141 + * @param text The message needed to check for +c and +C
142 + * @param target The number of targets the message is sent to, for +T
144 * @returns true if the client is allowed to speak on the channel, false
147 * @see member_can_send_to_channel()
149 -int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal)
150 +int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal,
151 + unsigned int flags, const char *text, const int target)
153 struct Membership *member;
159 * Servers can always speak on channels.
161 @@ -767,15 +796,90 @@
165 - if (IsXtraOp(cptr))
166 + /* client on service server (+s) - let it through */
167 + if (IsService(cli_user(cptr)->server))
169 - else if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED)) ||
170 - ((chptr->mode.mode & (MODE_REGONLY|MODE_MODERATENOREG)) && !IsAccount(cptr)))
171 + /* client with umode +X exempt from modes +nmrM and bans */
172 + if (!IsXtraOp(cptr)) {
173 + if ((chptr->mode.mode & (MODE_NOPRIVMSGS|MODE_MODERATED)) ||
174 + ((chptr->mode.mode & (MODE_REGONLY|MODE_MODERATENOREG)) && !IsAccount(cptr)))
176 + if (find_ban(cptr, chptr->banlist))
179 + /* check various other modes (like cCNT) */
180 + if (!can_send_to_channel(cptr, chptr, flags, text, target))
183 - return !find_ban(cptr, chptr->banlist);
185 - return member_can_send_to_channel(member, reveal);
186 + return member_can_send_to_channel(member, reveal, flags, text, target);
189 +/** Check if a client can send to a channel.
191 + * These checks are done for both clients on and off the channel.
193 + * @param cptr The client to check
194 + * @param chptr The channel to check
195 + * @param flags The bitmask of modes to check
196 + * @param text The message needed to check for +c and +C
197 + * @param target The number of targets the message is sent to, for +T
199 + * @returns true if the client is allowed to speak on the channel, false
202 + * @see client_can_send_to_channel()
203 + * @see member_can_send_to_channel()
205 +int can_send_to_channel(struct Client *cptr, struct Channel *chptr,
206 + unsigned int flags, const char *text, const int target)
209 + unsigned int modes;
210 + int controlcodes = 0;
213 + assert(0 != chptr);
215 + modes = chptr->mode.mode;
217 + /* only check these modes on local users */
221 + /* +T check for multi target message and they are not allowed */
222 + if ((flags & MODE_NOMULTITARGET) && (modes & MODE_NOMULTITARGET) &&
226 + /* +N check for channel wide notice and they are not allowed */
227 + if ((flags & MODE_NONOTICE) && (modes & MODE_NONOTICE))
230 + /* these last two checks should always be last
231 + * as they loop over the entire message in search for
232 + * CTCP char and control codes
234 + /* +C check for CTCP and CTCPs are not allowed */
235 + if ((flags & MODE_NOCTCP) && (modes & MODE_NOCTCP) && (text != NULL) &&
236 + ircd_strncmp(text,"\001ACTION ",8)) {
237 + for (ch=text;*ch;) {
240 + if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
245 + /* +c check for control codes and they are not allowed */
246 + if ((flags & MODE_NOCOLOUR) && (modes & MODE_NOCOLOUR) && (text != NULL)) {
247 + if (controlcodes) /* already found control codes */
249 + for (ch=text;*ch;ch++) {
250 + if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
257 /** Returns the name of a channel that prevents the user from changing nick.
258 @@ -3625,13 +3729,11 @@
259 /* Send notification to channel */
260 if (!(flags & (CHFL_ZOMBIE | CHFL_DELAYED)))
261 sendcmdto_channel_butserv_butone(jbuf->jb_source, CMD_PART, chan, NULL, 0,
262 - ((flags & CHFL_BANNED) || ((chan->mode.mode & MODE_NOQUITPARTS)
263 - && !IsChannelService(member->user)) || !jbuf->jb_comment) ?
264 + ((flags & CHFL_BANNED) || !jbuf->jb_comment) ?
265 "%H" : "%H :%s", chan, jbuf->jb_comment);
266 else if (MyUser(jbuf->jb_source))
267 sendcmdto_one(jbuf->jb_source, CMD_PART, jbuf->jb_source,
268 - ((flags & CHFL_BANNED) || (chan->mode.mode & MODE_NOQUITPARTS)
269 - || !jbuf->jb_comment) ?
270 + ((flags & CHFL_BANNED) || !jbuf->jb_comment) ?
271 ":%H" : "%H :%s", chan, jbuf->jb_comment);
272 /* XXX: Shouldn't we send a PART here anyway? */
273 /* to users on the channel? Why? From their POV, the user isn't on
274 diff -r 7113a0179d71 ircd/ircd_relay.c
275 --- a/ircd/ircd_relay.c Wed Jan 21 16:44:50 2009 +0100
276 +++ b/ircd/ircd_relay.c Wed Jan 21 17:13:44 2009 +0100
278 void relay_channel_message(struct Client* sptr, const char* name, const char* text, const int targetc)
280 struct Channel* chptr;
287 * This first: Almost never a server/service
289 - if (!client_can_send_to_channel(sptr, chptr, 1)) {
290 + if (!client_can_send_to_channel(sptr, chptr, 1,
291 + (MODE_NOCOLOUR | MODE_NOCTCP | MODE_NOMULTITARGET), text, targetc)) {
292 send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
295 + /* TODO: what is this again?
296 + * client_can_send_to_channel already reveals delayed join user
297 + * locally anyway, and now the message gets denied?
300 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
301 check_target_limit(sptr, chptr, chptr->chname, 0))
305 - if ((chptr->mode.mode & MODE_NOMULTITARGET) && (targetc > 1)) {
306 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
311 - if (chptr->mode.mode & MODE_NOCOLOUR)
312 - for (ch=text;*ch;ch++)
313 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
314 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
318 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(text,"\001ACTION ",8))
321 - send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
326 sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr),
327 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
329 void relay_channel_notice(struct Client* sptr, const char* name, const char* text, const int targetc)
331 struct Channel* chptr;
336 @@ -153,30 +135,14 @@
338 * This first: Almost never a server/service
340 - if (!client_can_send_to_channel(sptr, chptr, 1))
341 + if (!client_can_send_to_channel(sptr, chptr, 1,
342 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP | MODE_NOMULTITARGET), text, targetc))
345 + /* TODO: idem as in previous function */
346 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
347 check_target_limit(sptr, chptr, chptr->chname, 0))
350 - if ((chptr->mode.mode & MODE_NONOTICE))
354 - if ((chptr->mode.mode & MODE_NOMULTITARGET) && (targetc > 1))
358 - if (chptr->mode.mode & MODE_NOCOLOUR)
359 - for (ch=text;*ch;ch++)
360 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31)
363 - if (chptr->mode.mode & MODE_NOCTCP)
368 sendcmdto_channel_butone(sptr, CMD_NOTICE, chptr, cli_from(sptr),
369 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
371 * This first: Almost never a server/service
372 * Servers may have channel services, need to check for it here
374 - if (client_can_send_to_channel(sptr, chptr, 1) || IsChannelService(sptr)) {
375 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
376 sendcmdto_channel_butone(sptr, CMD_PRIVATE, chptr, cli_from(sptr),
377 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
380 * This first: Almost never a server/service
381 * Servers may have channel services, need to check for it here
383 - if (client_can_send_to_channel(sptr, chptr, 1) || IsChannelService(sptr)) {
384 + /* TODO: check how we get here */
385 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
386 sendcmdto_channel_butone(sptr, CMD_NOTICE, chptr, cli_from(sptr),
387 SKIP_DEAF | SKIP_BURST, "%H :%s", chptr, text);
389 diff -r 7113a0179d71 ircd/m_part.c
390 --- a/ircd/m_part.c Wed Jan 21 16:44:50 2009 +0100
391 +++ b/ircd/m_part.c Wed Jan 21 17:13:44 2009 +0100
394 assert(!IsZombie(member)); /* Local users should never zombie */
396 - if (!member_can_send_to_channel(member, 0))
397 + /* check +u here or later somewhere in channel.c ? */
398 + if (!member_can_send_to_channel(member, 0, MODE_NOQUITPARTS, NULL, 1))
400 flags |= CHFL_BANNED;
401 /* Remote clients don't want to see a comment either. */
402 diff -r 7113a0179d71 ircd/m_quit.c
403 --- a/ircd/m_quit.c Wed Jan 21 16:44:50 2009 +0100
404 +++ b/ircd/m_quit.c Wed Jan 21 17:13:44 2009 +0100
406 struct Membership* chan;
407 /* (slug for +u) removed !IsDelayedJoin(chan) as splidge said to */
408 for (chan = cli_user(sptr)->channel; chan; chan = chan->next_channel) {
409 - if (!IsZombie(chan) && (!member_can_send_to_channel(chan, 0)
410 - || (chan->channel->mode.mode & MODE_NOQUITPARTS)))
411 + if (!IsZombie(chan) && (!member_can_send_to_channel(chan, 0,
412 + MODE_NOQUITPARTS, NULL, 1)))
413 return exit_client(cptr, sptr, sptr, "Signed off");
416 diff -r 7113a0179d71 ircd/m_topic.c
417 --- a/ircd/m_topic.c Wed Jan 21 16:44:50 2009 +0100
418 +++ b/ircd/m_topic.c Wed Jan 21 17:13:44 2009 +0100
421 else if ((chptr->mode.mode & MODE_TOPICLIMIT) && !is_chan_op(sptr, chptr))
422 send_reply(sptr, ERR_CHANOPRIVSNEEDED, chptr->chname);
423 - else if (!client_can_send_to_channel(sptr, chptr, 1))
424 + else if (!client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1))
425 send_reply(sptr, ERR_CANNOTSENDTOCHAN, chptr->chname);
427 do_settopic(sptr,cptr,chptr,topic,0);
428 diff -r 7113a0179d71 ircd/m_wallchops.c
429 --- a/ircd/m_wallchops.c Wed Jan 21 16:44:50 2009 +0100
430 +++ b/ircd/m_wallchops.c Wed Jan 21 17:13:44 2009 +0100
433 struct Channel *chptr;
434 struct Membership* member;
438 assert(cptr == sptr);
439 @@ -117,23 +116,12 @@
440 return send_reply(sptr, ERR_NOTEXTTOSEND);
442 if (IsChannelName(parv[1]) && (chptr = FindChannel(parv[1]))) {
443 - if (client_can_send_to_channel(sptr, chptr, 0) && !(chptr->mode.mode & MODE_NONOTICE)) {
444 + /* check also for modes +N +c and +C */
445 + if (client_can_send_to_channel(sptr, chptr, 0,
446 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP), parv[parc - 1], 1)) {
447 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
448 check_target_limit(sptr, chptr, chptr->chname, 0))
452 - if (chptr->mode.mode & MODE_NOCOLOUR)
453 - for (ch=parv[parc - 1];*ch;ch++)
454 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
458 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(parv[parc - 1],"\001ACTION ",8))
459 - for (ch=parv[parc - 1];*ch;)
464 /* Reveal delayedjoin user */
465 if ((member = find_member_link(chptr, cptr)) && IsDelayedJoin(member))
469 if (!IsLocalChannel(parv[1]) && (chptr = FindChannel(parv[1]))) {
470 - if (client_can_send_to_channel(sptr, chptr, 1)) {
471 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
472 sendcmdto_channel_butone(sptr, CMD_WALLCHOPS, chptr, cptr,
473 SKIP_DEAF | SKIP_BURST | SKIP_NONOPS,
474 "%H :%s", chptr, parv[parc - 1]);
475 diff -r 7113a0179d71 ircd/m_wallvoices.c
476 --- a/ircd/m_wallvoices.c Wed Jan 21 16:44:50 2009 +0100
477 +++ b/ircd/m_wallvoices.c Wed Jan 21 17:13:44 2009 +0100
480 struct Channel *chptr;
481 struct Membership* member;
485 assert(cptr == sptr);
486 @@ -116,23 +115,11 @@
487 return send_reply(sptr, ERR_NOTEXTTOSEND);
489 if (IsChannelName(parv[1]) && (chptr = FindChannel(parv[1]))) {
490 - if (client_can_send_to_channel(sptr, chptr, 0) && !(chptr->mode.mode & MODE_NONOTICE)) {
491 + if (client_can_send_to_channel(sptr, chptr, 0,
492 + (MODE_NONOTICE | MODE_NOCOLOUR | MODE_NOCTCP), parv[parc - 1], 1)) {
493 if ((chptr->mode.mode & MODE_NOPRIVMSGS) &&
494 check_target_limit(sptr, chptr, chptr->chname, 0))
498 - if (chptr->mode.mode & MODE_NOCOLOUR)
499 - for (ch=parv[parc - 1];*ch;ch++)
500 - if (*ch==2 || *ch==3 || *ch==22 || *ch==27 || *ch==31) {
504 - if ((chptr->mode.mode & MODE_NOCTCP) && ircd_strncmp(parv[parc - 1],"\001ACTION ",8))
505 - for (ch=parv[parc - 1];*ch;)
510 /* Reveal delayedjoin user */
511 if ((member = find_member_link(chptr, cptr)) && IsDelayedJoin(member))
515 if (!IsLocalChannel(parv[1]) && (chptr = FindChannel(parv[1]))) {
516 - if (client_can_send_to_channel(sptr, chptr, 1)) {
517 + if (client_can_send_to_channel(sptr, chptr, 1, 0, NULL, 1)) {
518 sendcmdto_channel_butone(sptr, CMD_WALLVOICES, chptr, cptr,
519 SKIP_DEAF | SKIP_BURST | SKIP_NONVOICES,
520 "%H :%s", chptr, parv[parc - 1]);