| 1 |
/* |
| 2 |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
| 3 |
* |
| 4 |
* Copyright (c) 1997-2017 ircd-hybrid development team |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation; either version 2 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
| 19 |
* USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/*! \file channel_mode.c |
| 23 |
* \brief Controls modes on channels. |
| 24 |
* \version $Id$ |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "stdinc.h" |
| 28 |
#include "list.h" |
| 29 |
#include "channel.h" |
| 30 |
#include "channel_mode.h" |
| 31 |
#include "client.h" |
| 32 |
#include "conf.h" |
| 33 |
#include "hostmask.h" |
| 34 |
#include "irc_string.h" |
| 35 |
#include "ircd.h" |
| 36 |
#include "numeric.h" |
| 37 |
#include "server.h" |
| 38 |
#include "send.h" |
| 39 |
#include "memory.h" |
| 40 |
#include "mempool.h" |
| 41 |
#include "parse.h" |
| 42 |
|
| 43 |
|
| 44 |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
| 45 |
static struct ChModeChange mode_changes[IRCD_BUFSIZE]; |
| 46 |
static unsigned int mode_count; |
| 47 |
static unsigned int mode_limit; /* number of modes set other than simple */ |
| 48 |
static unsigned int simple_modes_mask; /* bit mask of simple modes already set */ |
| 49 |
extern mp_pool_t *ban_pool; |
| 50 |
|
| 51 |
|
| 52 |
/* check_string() |
| 53 |
* |
| 54 |
* inputs - string to check |
| 55 |
* output - pointer to modified string |
| 56 |
* side effects - Fixes a string so that the first white space found |
| 57 |
* becomes an end of string marker (`\0`). |
| 58 |
* returns the 'fixed' string or "*" if the string |
| 59 |
* was NULL length or a NULL pointer. |
| 60 |
*/ |
| 61 |
static char * |
| 62 |
check_string(char *s) |
| 63 |
{ |
| 64 |
char *const str = s; |
| 65 |
static char star[] = "*"; |
| 66 |
|
| 67 |
if (EmptyString(str)) |
| 68 |
return star; |
| 69 |
|
| 70 |
for (; *s; ++s) |
| 71 |
{ |
| 72 |
if (IsSpace(*s)) |
| 73 |
{ |
| 74 |
*s = '\0'; |
| 75 |
break; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
return EmptyString(str) ? star : str; |
| 80 |
} |
| 81 |
|
| 82 |
/* |
| 83 |
* Ban functions to work with mode +b/e/I |
| 84 |
*/ |
| 85 |
/* add the specified ID to the channel. |
| 86 |
* -is 8/9/00 |
| 87 |
*/ |
| 88 |
|
| 89 |
int |
| 90 |
add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type) |
| 91 |
{ |
| 92 |
dlink_list *list; |
| 93 |
dlink_node *node; |
| 94 |
char name[NICKLEN + 1] = ""; |
| 95 |
char user[USERLEN + 1] = ""; |
| 96 |
char host[HOSTLEN + 1] = ""; |
| 97 |
struct split_nuh_item nuh; |
| 98 |
|
| 99 |
if (MyClient(client_p)) |
| 100 |
{ |
| 101 |
unsigned int num_mask = dlink_list_length(&chptr->banlist) + |
| 102 |
dlink_list_length(&chptr->exceptlist) + |
| 103 |
dlink_list_length(&chptr->invexlist); |
| 104 |
|
| 105 |
/* Don't let local clients overflow the b/e/I lists */ |
| 106 |
if (num_mask >= ((HasCMode(chptr, MODE_EXTLIMIT)) ? ConfigChannel.max_bans_large : |
| 107 |
ConfigChannel.max_bans)) |
| 108 |
{ |
| 109 |
sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->name, banid); |
| 110 |
return 0; |
| 111 |
} |
| 112 |
|
| 113 |
collapse(banid); |
| 114 |
} |
| 115 |
|
| 116 |
nuh.nuhmask = check_string(banid); |
| 117 |
nuh.nickptr = name; |
| 118 |
nuh.userptr = user; |
| 119 |
nuh.hostptr = host; |
| 120 |
|
| 121 |
nuh.nicksize = sizeof(name); |
| 122 |
nuh.usersize = sizeof(user); |
| 123 |
nuh.hostsize = sizeof(host); |
| 124 |
|
| 125 |
split_nuh(&nuh); |
| 126 |
|
| 127 |
/* |
| 128 |
* Re-assemble a new n!u@h and print it back to banid for sending |
| 129 |
* the mode to the channel. |
| 130 |
*/ |
| 131 |
size_t len = snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
| 132 |
|
| 133 |
switch (type) |
| 134 |
{ |
| 135 |
case CHFL_BAN: |
| 136 |
list = &chptr->banlist; |
| 137 |
clear_ban_cache_list(&chptr->locmembers); |
| 138 |
break; |
| 139 |
case CHFL_EXCEPTION: |
| 140 |
list = &chptr->exceptlist; |
| 141 |
clear_ban_cache_list(&chptr->locmembers); |
| 142 |
break; |
| 143 |
case CHFL_INVEX: |
| 144 |
list = &chptr->invexlist; |
| 145 |
break; |
| 146 |
default: |
| 147 |
list = NULL; /* Let it crash */ |
| 148 |
} |
| 149 |
|
| 150 |
DLINK_FOREACH(node, list->head) |
| 151 |
{ |
| 152 |
const struct Ban *ban = node->data; |
| 153 |
|
| 154 |
if (!irccmp(ban->name, name) && |
| 155 |
!irccmp(ban->user, user) && |
| 156 |
!irccmp(ban->host, host)) |
| 157 |
return 0; |
| 158 |
} |
| 159 |
|
| 160 |
struct Ban *ban = mp_pool_get(ban_pool); |
| 161 |
ban->when = CurrentTime; |
| 162 |
ban->len = len - 2; /* -2 for ! + @ */ |
| 163 |
ban->type = parse_netmask(host, &ban->addr, &ban->bits); |
| 164 |
strlcpy(ban->name, name, sizeof(ban->name)); |
| 165 |
strlcpy(ban->user, user, sizeof(ban->user)); |
| 166 |
strlcpy(ban->host, host, sizeof(ban->host)); |
| 167 |
|
| 168 |
if (IsClient(client_p)) |
| 169 |
snprintf(ban->who, sizeof(ban->who), "%s!%s@%s", client_p->name, |
| 170 |
client_p->username, client_p->host); |
| 171 |
else if (IsHidden(client_p) || ConfigServerHide.hide_servers) |
| 172 |
strlcpy(ban->who, me.name, sizeof(ban->who)); |
| 173 |
else |
| 174 |
strlcpy(ban->who, client_p->name, sizeof(ban->who)); |
| 175 |
|
| 176 |
dlinkAdd(ban, &ban->node, list); |
| 177 |
|
| 178 |
return 1; |
| 179 |
} |
| 180 |
|
| 181 |
/* |
| 182 |
* inputs - pointer to channel |
| 183 |
* - pointer to ban id |
| 184 |
* - type of ban, i.e. ban, exception, invex |
| 185 |
* output - 0 for failure, 1 for success |
| 186 |
* side effects - |
| 187 |
*/ |
| 188 |
static int |
| 189 |
del_id(struct Channel *chptr, char *banid, unsigned int type) |
| 190 |
{ |
| 191 |
dlink_list *list; |
| 192 |
dlink_node *node; |
| 193 |
char name[NICKLEN + 1] = ""; |
| 194 |
char user[USERLEN + 1] = ""; |
| 195 |
char host[HOSTLEN + 1] = ""; |
| 196 |
struct split_nuh_item nuh; |
| 197 |
|
| 198 |
assert(banid); |
| 199 |
|
| 200 |
nuh.nuhmask = check_string(banid); |
| 201 |
nuh.nickptr = name; |
| 202 |
nuh.userptr = user; |
| 203 |
nuh.hostptr = host; |
| 204 |
|
| 205 |
nuh.nicksize = sizeof(name); |
| 206 |
nuh.usersize = sizeof(user); |
| 207 |
nuh.hostsize = sizeof(host); |
| 208 |
|
| 209 |
split_nuh(&nuh); |
| 210 |
|
| 211 |
/* |
| 212 |
* Re-assemble a new n!u@h and print it back to banid for sending |
| 213 |
* the mode to the channel. |
| 214 |
*/ |
| 215 |
snprintf(banid, IRCD_BUFSIZE, "%s!%s@%s", name, user, host); |
| 216 |
|
| 217 |
switch (type) |
| 218 |
{ |
| 219 |
case CHFL_BAN: |
| 220 |
list = &chptr->banlist; |
| 221 |
clear_ban_cache_list(&chptr->locmembers); |
| 222 |
break; |
| 223 |
case CHFL_EXCEPTION: |
| 224 |
list = &chptr->exceptlist; |
| 225 |
clear_ban_cache_list(&chptr->locmembers); |
| 226 |
break; |
| 227 |
case CHFL_INVEX: |
| 228 |
list = &chptr->invexlist; |
| 229 |
break; |
| 230 |
default: |
| 231 |
list = NULL; /* Let it crash */ |
| 232 |
} |
| 233 |
|
| 234 |
DLINK_FOREACH(node, list->head) |
| 235 |
{ |
| 236 |
struct Ban *ban = node->data; |
| 237 |
|
| 238 |
if (!irccmp(name, ban->name) && |
| 239 |
!irccmp(user, ban->user) && |
| 240 |
!irccmp(host, ban->host)) |
| 241 |
{ |
| 242 |
remove_ban(ban, list); |
| 243 |
return 1; |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
return 0; |
| 248 |
} |
| 249 |
|
| 250 |
/* channel_modes() |
| 251 |
* |
| 252 |
* inputs - pointer to channel |
| 253 |
* - pointer to client |
| 254 |
* - pointer to mode buf |
| 255 |
* - pointer to parameter buf |
| 256 |
* output - NONE |
| 257 |
* side effects - write the "simple" list of channel modes for channel |
| 258 |
* chptr onto buffer mbuf with the parameters in pbuf. |
| 259 |
*/ |
| 260 |
void |
| 261 |
channel_modes(struct Channel *chptr, struct Client *client_p, char *mbuf, char *pbuf) |
| 262 |
{ |
| 263 |
*mbuf++ = '+'; |
| 264 |
*pbuf = '\0'; |
| 265 |
|
| 266 |
for (const struct chan_mode *tab = cmode_tab; tab->mode; ++tab) |
| 267 |
if (tab->mode && HasCMode(chptr, tab->mode)) |
| 268 |
*mbuf++ = tab->letter; |
| 269 |
|
| 270 |
if (chptr->mode.limit) |
| 271 |
{ |
| 272 |
*mbuf++ = 'l'; |
| 273 |
|
| 274 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
| 275 |
pbuf += sprintf(pbuf, "%u ", chptr->mode.limit); |
| 276 |
} |
| 277 |
|
| 278 |
if (chptr->mode.key[0]) |
| 279 |
{ |
| 280 |
*mbuf++ = 'k'; |
| 281 |
|
| 282 |
if (IsServer(client_p) || IsMember(client_p, chptr)) |
| 283 |
sprintf(pbuf, "%s ", chptr->mode.key); |
| 284 |
} |
| 285 |
|
| 286 |
*mbuf = '\0'; |
| 287 |
} |
| 288 |
|
| 289 |
/* fix_key() |
| 290 |
* |
| 291 |
* inputs - pointer to key to clean up |
| 292 |
* output - pointer to cleaned up key |
| 293 |
* side effects - input string is modified |
| 294 |
* |
| 295 |
* stolen from Undernet's ircd -orabidoo |
| 296 |
*/ |
| 297 |
static char * |
| 298 |
fix_key(char *arg) |
| 299 |
{ |
| 300 |
unsigned char *s, *t, c; |
| 301 |
|
| 302 |
for (s = t = (unsigned char *)arg; (c = *s) && s - (unsigned char *)arg < KEYLEN; ++s) |
| 303 |
{ |
| 304 |
c &= 0x7f; |
| 305 |
|
| 306 |
if (c != ':' && c > ' ' && c != ',') |
| 307 |
*t++ = c; |
| 308 |
} |
| 309 |
|
| 310 |
*t = '\0'; |
| 311 |
return arg; |
| 312 |
} |
| 313 |
|
| 314 |
/* |
| 315 |
* inputs - pointer to channel |
| 316 |
* output - none |
| 317 |
* side effects - clear ban cache |
| 318 |
*/ |
| 319 |
void |
| 320 |
clear_ban_cache_list(dlink_list *list) |
| 321 |
{ |
| 322 |
dlink_node *node; |
| 323 |
|
| 324 |
DLINK_FOREACH(node, list->head) |
| 325 |
{ |
| 326 |
struct Membership *member = node->data; |
| 327 |
member->flags &= ~(CHFL_BAN_SILENCED | CHFL_BAN_CHECKED); |
| 328 |
} |
| 329 |
} |
| 330 |
|
| 331 |
/* |
| 332 |
* Bitmasks for various error returns that set_channel_mode should only return |
| 333 |
* once per call -orabidoo |
| 334 |
*/ |
| 335 |
enum |
| 336 |
{ |
| 337 |
SM_ERR_NOOPS = 1 << 0, /* No chan ops */ |
| 338 |
SM_ERR_UNKNOWN = 1 << 1, |
| 339 |
SM_ERR_RPL_B = 1 << 2, |
| 340 |
SM_ERR_RPL_E = 1 << 3, |
| 341 |
SM_ERR_RPL_I = 1 << 4, |
| 342 |
SM_ERR_NOTONCHANNEL = 1 << 5, /* Client is not on channel */ |
| 343 |
SM_ERR_NOTOPER = 1 << 6, /* Only irc-operators can change that mode */ |
| 344 |
SM_ERR_ONLYSERVER = 1 << 7 /* Only servers or services can change that mode */ |
| 345 |
}; |
| 346 |
|
| 347 |
/* Mode functions handle mode changes for a particular mode... */ |
| 348 |
static void |
| 349 |
chm_nosuch(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 350 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 351 |
{ |
| 352 |
if (*errors & SM_ERR_UNKNOWN) |
| 353 |
return; |
| 354 |
|
| 355 |
*errors |= SM_ERR_UNKNOWN; |
| 356 |
sendto_one_numeric(source_p, &me, ERR_UNKNOWNMODE, c); |
| 357 |
} |
| 358 |
|
| 359 |
static void |
| 360 |
chm_simple(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 361 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 362 |
{ |
| 363 |
if (mode->only_opers) |
| 364 |
{ |
| 365 |
if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
| 366 |
{ |
| 367 |
if (!(*errors & SM_ERR_NOTOPER)) |
| 368 |
sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES); |
| 369 |
|
| 370 |
*errors |= SM_ERR_NOTOPER; |
| 371 |
return; |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
if (mode->only_servers) |
| 376 |
{ |
| 377 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
| 378 |
{ |
| 379 |
if (!(*errors & SM_ERR_ONLYSERVER)) |
| 380 |
sendto_one_numeric(source_p, &me, |
| 381 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 382 |
ERR_ONLYSERVERSCANCHANGE, chptr->name); |
| 383 |
|
| 384 |
*errors |= SM_ERR_ONLYSERVER; |
| 385 |
return; |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
if (alev < CHACCESS_HALFOP) |
| 390 |
{ |
| 391 |
if (!(*errors & SM_ERR_NOOPS)) |
| 392 |
sendto_one_numeric(source_p, &me, |
| 393 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 394 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 395 |
|
| 396 |
*errors |= SM_ERR_NOOPS; |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
/* If have already dealt with this simple mode, ignore it */ |
| 401 |
if (simple_modes_mask & mode->mode) |
| 402 |
return; |
| 403 |
|
| 404 |
simple_modes_mask |= mode->mode; |
| 405 |
|
| 406 |
if (dir == MODE_ADD) /* setting + */ |
| 407 |
{ |
| 408 |
if (MyClient(source_p) && HasCMode(chptr, mode->mode)) |
| 409 |
return; |
| 410 |
|
| 411 |
AddCMode(chptr, mode->mode); |
| 412 |
} |
| 413 |
else if (dir == MODE_DEL) /* setting - */ |
| 414 |
{ |
| 415 |
if (MyClient(source_p) && !HasCMode(chptr, mode->mode)) |
| 416 |
return; |
| 417 |
|
| 418 |
DelCMode(chptr, mode->mode); |
| 419 |
} |
| 420 |
|
| 421 |
mode_changes[mode_count].letter = mode->letter; |
| 422 |
mode_changes[mode_count].arg = NULL; |
| 423 |
mode_changes[mode_count].id = NULL; |
| 424 |
mode_changes[mode_count].flags = 0; |
| 425 |
mode_changes[mode_count++].dir = dir; |
| 426 |
} |
| 427 |
|
| 428 |
static void |
| 429 |
chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 430 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 431 |
{ |
| 432 |
if (dir == MODE_QUERY || parc <= *parn) |
| 433 |
{ |
| 434 |
dlink_node *node; |
| 435 |
|
| 436 |
if (*errors & SM_ERR_RPL_B) |
| 437 |
return; |
| 438 |
|
| 439 |
*errors |= SM_ERR_RPL_B; |
| 440 |
|
| 441 |
DLINK_FOREACH(node, chptr->banlist.head) |
| 442 |
{ |
| 443 |
const struct Ban *ban = node->data; |
| 444 |
|
| 445 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
| 446 |
sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name, |
| 447 |
ban->name, ban->user, ban->host, |
| 448 |
ban->who, ban->when); |
| 449 |
} |
| 450 |
|
| 451 |
sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name); |
| 452 |
return; |
| 453 |
} |
| 454 |
|
| 455 |
if (alev < CHACCESS_HALFOP) |
| 456 |
{ |
| 457 |
if (!(*errors & SM_ERR_NOOPS)) |
| 458 |
sendto_one_numeric(source_p, &me, |
| 459 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 460 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 461 |
|
| 462 |
*errors |= SM_ERR_NOOPS; |
| 463 |
return; |
| 464 |
} |
| 465 |
|
| 466 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 467 |
return; |
| 468 |
|
| 469 |
char *const mask = nuh_mask[*parn]; |
| 470 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 471 |
++(*parn); |
| 472 |
|
| 473 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
| 474 |
return; |
| 475 |
|
| 476 |
if (dir == MODE_ADD) /* setting + */ |
| 477 |
{ |
| 478 |
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
| 479 |
return; |
| 480 |
} |
| 481 |
else if (dir == MODE_DEL) /* setting - */ |
| 482 |
{ |
| 483 |
if (!del_id(chptr, mask, CHFL_BAN)) |
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
mode_changes[mode_count].letter = mode->letter; |
| 488 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
| 489 |
mode_changes[mode_count].id = NULL; |
| 490 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
| 491 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
| 492 |
else |
| 493 |
mode_changes[mode_count].flags = 0; |
| 494 |
mode_changes[mode_count++].dir = dir; |
| 495 |
} |
| 496 |
|
| 497 |
static void |
| 498 |
chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 499 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 500 |
{ |
| 501 |
if (dir == MODE_QUERY || parc <= *parn) |
| 502 |
{ |
| 503 |
dlink_node *node; |
| 504 |
|
| 505 |
if (*errors & SM_ERR_RPL_E) |
| 506 |
return; |
| 507 |
|
| 508 |
*errors |= SM_ERR_RPL_E; |
| 509 |
|
| 510 |
DLINK_FOREACH(node, chptr->exceptlist.head) |
| 511 |
{ |
| 512 |
const struct Ban *ban = node->data; |
| 513 |
|
| 514 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
| 515 |
sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name, |
| 516 |
ban->name, ban->user, ban->host, |
| 517 |
ban->who, ban->when); |
| 518 |
} |
| 519 |
|
| 520 |
sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name); |
| 521 |
return; |
| 522 |
} |
| 523 |
|
| 524 |
if (alev < CHACCESS_HALFOP) |
| 525 |
{ |
| 526 |
if (!(*errors & SM_ERR_NOOPS)) |
| 527 |
sendto_one_numeric(source_p, &me, |
| 528 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 529 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 530 |
|
| 531 |
*errors |= SM_ERR_NOOPS; |
| 532 |
return; |
| 533 |
} |
| 534 |
|
| 535 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 536 |
return; |
| 537 |
|
| 538 |
char *const mask = nuh_mask[*parn]; |
| 539 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 540 |
++(*parn); |
| 541 |
|
| 542 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
| 543 |
return; |
| 544 |
|
| 545 |
if (dir == MODE_ADD) /* setting + */ |
| 546 |
{ |
| 547 |
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
| 548 |
return; |
| 549 |
} |
| 550 |
else if (dir == MODE_DEL) /* setting - */ |
| 551 |
{ |
| 552 |
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
| 553 |
return; |
| 554 |
} |
| 555 |
|
| 556 |
mode_changes[mode_count].letter = mode->letter; |
| 557 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
| 558 |
mode_changes[mode_count].id = NULL; |
| 559 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
| 560 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
| 561 |
else |
| 562 |
mode_changes[mode_count].flags = 0; |
| 563 |
mode_changes[mode_count++].dir = dir; |
| 564 |
} |
| 565 |
|
| 566 |
static void |
| 567 |
chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 568 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 569 |
{ |
| 570 |
if (dir == MODE_QUERY || parc <= *parn) |
| 571 |
{ |
| 572 |
dlink_node *node; |
| 573 |
|
| 574 |
if (*errors & SM_ERR_RPL_I) |
| 575 |
return; |
| 576 |
|
| 577 |
*errors |= SM_ERR_RPL_I; |
| 578 |
|
| 579 |
DLINK_FOREACH(node, chptr->invexlist.head) |
| 580 |
{ |
| 581 |
const struct Ban *ban = node->data; |
| 582 |
|
| 583 |
if (!HasCMode(chptr, MODE_HIDEBMASKS) || alev >= CHACCESS_HALFOP) |
| 584 |
sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name, |
| 585 |
ban->name, ban->user, ban->host, |
| 586 |
ban->who, ban->when); |
| 587 |
} |
| 588 |
|
| 589 |
sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name); |
| 590 |
return; |
| 591 |
} |
| 592 |
|
| 593 |
if (alev < CHACCESS_HALFOP) |
| 594 |
{ |
| 595 |
if (!(*errors & SM_ERR_NOOPS)) |
| 596 |
sendto_one_numeric(source_p, &me, |
| 597 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 598 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 599 |
|
| 600 |
*errors |= SM_ERR_NOOPS; |
| 601 |
return; |
| 602 |
} |
| 603 |
|
| 604 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 605 |
return; |
| 606 |
|
| 607 |
char *const mask = nuh_mask[*parn]; |
| 608 |
strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 609 |
++(*parn); |
| 610 |
|
| 611 |
if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' '))) |
| 612 |
return; |
| 613 |
|
| 614 |
if (dir == MODE_ADD) /* setting + */ |
| 615 |
{ |
| 616 |
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
| 617 |
return; |
| 618 |
} |
| 619 |
else if (dir == MODE_DEL) /* setting - */ |
| 620 |
{ |
| 621 |
if (!del_id(chptr, mask, CHFL_INVEX)) |
| 622 |
return; |
| 623 |
} |
| 624 |
|
| 625 |
mode_changes[mode_count].letter = mode->letter; |
| 626 |
mode_changes[mode_count].arg = mask; /* At this point 'mask' is no longer than NICKLEN + USERLEN + HOSTLEN + 3 */ |
| 627 |
mode_changes[mode_count].id = NULL; |
| 628 |
if (HasCMode(chptr, MODE_HIDEBMASKS)) |
| 629 |
mode_changes[mode_count].flags = CHFL_CHANOP | CHFL_HALFOP; |
| 630 |
else |
| 631 |
mode_changes[mode_count].flags = 0; |
| 632 |
mode_changes[mode_count++].dir = dir; |
| 633 |
} |
| 634 |
|
| 635 |
static void |
| 636 |
chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 637 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 638 |
{ |
| 639 |
struct Client *target_p; |
| 640 |
struct Membership *member; |
| 641 |
|
| 642 |
if (alev < CHACCESS_HALFOP) |
| 643 |
{ |
| 644 |
if (!(*errors & SM_ERR_NOOPS)) |
| 645 |
sendto_one_numeric(source_p, &me, |
| 646 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 647 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 648 |
|
| 649 |
*errors |= SM_ERR_NOOPS; |
| 650 |
return; |
| 651 |
} |
| 652 |
|
| 653 |
if (dir == MODE_QUERY || parc <= *parn) |
| 654 |
return; |
| 655 |
|
| 656 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
| 657 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
| 658 |
|
| 659 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
| 660 |
{ |
| 661 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
| 662 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
| 663 |
|
| 664 |
*errors |= SM_ERR_NOTONCHANNEL; |
| 665 |
return; |
| 666 |
} |
| 667 |
|
| 668 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 669 |
return; |
| 670 |
|
| 671 |
if (dir == MODE_ADD) /* setting + */ |
| 672 |
{ |
| 673 |
if (has_member_flags(member, CHFL_VOICE)) |
| 674 |
return; /* No redundant mode changes */ |
| 675 |
|
| 676 |
AddMemberFlag(member, CHFL_VOICE); |
| 677 |
} |
| 678 |
else if (dir == MODE_DEL) /* setting - */ |
| 679 |
{ |
| 680 |
if (!has_member_flags(member, CHFL_VOICE)) |
| 681 |
return; /* No redundant mode changes */ |
| 682 |
|
| 683 |
DelMemberFlag(member, CHFL_VOICE); |
| 684 |
} |
| 685 |
|
| 686 |
mode_changes[mode_count].letter = mode->letter; |
| 687 |
mode_changes[mode_count].arg = target_p->name; |
| 688 |
mode_changes[mode_count].id = target_p->id; |
| 689 |
mode_changes[mode_count].flags = 0; |
| 690 |
mode_changes[mode_count++].dir = dir; |
| 691 |
} |
| 692 |
|
| 693 |
static void |
| 694 |
chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 695 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 696 |
{ |
| 697 |
struct Client *target_p; |
| 698 |
struct Membership *member; |
| 699 |
|
| 700 |
if (alev < CHACCESS_CHANOP) |
| 701 |
{ |
| 702 |
if (!(*errors & SM_ERR_NOOPS)) |
| 703 |
sendto_one_numeric(source_p, &me, |
| 704 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 705 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 706 |
|
| 707 |
*errors |= SM_ERR_NOOPS; |
| 708 |
return; |
| 709 |
} |
| 710 |
|
| 711 |
if (dir == MODE_QUERY || parc <= *parn) |
| 712 |
return; |
| 713 |
|
| 714 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
| 715 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
| 716 |
|
| 717 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
| 718 |
{ |
| 719 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
| 720 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
| 721 |
|
| 722 |
*errors |= SM_ERR_NOTONCHANNEL; |
| 723 |
return; |
| 724 |
} |
| 725 |
|
| 726 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 727 |
return; |
| 728 |
|
| 729 |
if (dir == MODE_ADD) /* setting + */ |
| 730 |
{ |
| 731 |
if (has_member_flags(member, CHFL_HALFOP)) |
| 732 |
return; /* No redundant mode changes */ |
| 733 |
|
| 734 |
AddMemberFlag(member, CHFL_HALFOP); |
| 735 |
} |
| 736 |
else if (dir == MODE_DEL) /* setting - */ |
| 737 |
{ |
| 738 |
if (!has_member_flags(member, CHFL_HALFOP)) |
| 739 |
return; /* No redundant mode changes */ |
| 740 |
|
| 741 |
DelMemberFlag(member, CHFL_HALFOP); |
| 742 |
} |
| 743 |
|
| 744 |
mode_changes[mode_count].letter = mode->letter; |
| 745 |
mode_changes[mode_count].arg = target_p->name; |
| 746 |
mode_changes[mode_count].id = target_p->id; |
| 747 |
mode_changes[mode_count].flags = 0; |
| 748 |
mode_changes[mode_count++].dir = dir; |
| 749 |
} |
| 750 |
|
| 751 |
static void |
| 752 |
chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 753 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 754 |
{ |
| 755 |
struct Client *target_p; |
| 756 |
struct Membership *member; |
| 757 |
|
| 758 |
if (alev < CHACCESS_CHANOP) |
| 759 |
{ |
| 760 |
if (!(*errors & SM_ERR_NOOPS)) |
| 761 |
sendto_one_numeric(source_p, &me, |
| 762 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 763 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 764 |
|
| 765 |
*errors |= SM_ERR_NOOPS; |
| 766 |
return; |
| 767 |
} |
| 768 |
|
| 769 |
if (dir == MODE_QUERY || parc <= *parn) |
| 770 |
return; |
| 771 |
|
| 772 |
if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL) |
| 773 |
return; /* find_chasing sends ERR_NOSUCHNICK */ |
| 774 |
|
| 775 |
if ((member = find_channel_link(target_p, chptr)) == NULL) |
| 776 |
{ |
| 777 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
| 778 |
sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name); |
| 779 |
|
| 780 |
*errors |= SM_ERR_NOTONCHANNEL; |
| 781 |
return; |
| 782 |
} |
| 783 |
|
| 784 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 785 |
return; |
| 786 |
|
| 787 |
if (dir == MODE_ADD) /* setting + */ |
| 788 |
{ |
| 789 |
if (has_member_flags(member, CHFL_CHANOP)) |
| 790 |
return; /* No redundant mode changes */ |
| 791 |
|
| 792 |
AddMemberFlag(member, CHFL_CHANOP); |
| 793 |
} |
| 794 |
else if (dir == MODE_DEL) /* setting - */ |
| 795 |
{ |
| 796 |
if (!has_member_flags(member, CHFL_CHANOP)) |
| 797 |
return; /* No redundant mode changes */ |
| 798 |
|
| 799 |
DelMemberFlag(member, CHFL_CHANOP); |
| 800 |
} |
| 801 |
|
| 802 |
mode_changes[mode_count].letter = mode->letter; |
| 803 |
mode_changes[mode_count].arg = target_p->name; |
| 804 |
mode_changes[mode_count].id = target_p->id; |
| 805 |
mode_changes[mode_count].flags = 0; |
| 806 |
mode_changes[mode_count++].dir = dir; |
| 807 |
} |
| 808 |
|
| 809 |
static void |
| 810 |
chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 811 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 812 |
{ |
| 813 |
if (alev < CHACCESS_HALFOP) |
| 814 |
{ |
| 815 |
if (!(*errors & SM_ERR_NOOPS)) |
| 816 |
sendto_one_numeric(source_p, &me, |
| 817 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 818 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 819 |
*errors |= SM_ERR_NOOPS; |
| 820 |
return; |
| 821 |
} |
| 822 |
|
| 823 |
if (dir == MODE_QUERY) |
| 824 |
return; |
| 825 |
|
| 826 |
if (dir == MODE_ADD && parc > *parn) |
| 827 |
{ |
| 828 |
char *const lstr = parv[(*parn)++]; |
| 829 |
int limit = 0; |
| 830 |
|
| 831 |
if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0) |
| 832 |
return; |
| 833 |
|
| 834 |
sprintf(lstr, "%d", limit); |
| 835 |
|
| 836 |
/* If somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
| 837 |
for (unsigned int i = 0; i < mode_count; ++i) |
| 838 |
if (mode_changes[i].letter == mode->letter && mode_changes[i].dir == MODE_ADD) |
| 839 |
mode_changes[i].letter = 0; |
| 840 |
|
| 841 |
mode_changes[mode_count].letter = mode->letter; |
| 842 |
mode_changes[mode_count].arg = lstr; |
| 843 |
mode_changes[mode_count].id = NULL; |
| 844 |
mode_changes[mode_count].flags = 0; |
| 845 |
mode_changes[mode_count++].dir = dir; |
| 846 |
|
| 847 |
chptr->mode.limit = limit; |
| 848 |
} |
| 849 |
else if (dir == MODE_DEL) |
| 850 |
{ |
| 851 |
if (!chptr->mode.limit) |
| 852 |
return; |
| 853 |
|
| 854 |
chptr->mode.limit = 0; |
| 855 |
|
| 856 |
mode_changes[mode_count].letter = mode->letter; |
| 857 |
mode_changes[mode_count].arg = NULL; |
| 858 |
mode_changes[mode_count].id = NULL; |
| 859 |
mode_changes[mode_count].flags = 0; |
| 860 |
mode_changes[mode_count++].dir = dir; |
| 861 |
} |
| 862 |
} |
| 863 |
|
| 864 |
static void |
| 865 |
chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn, char **parv, |
| 866 |
int *errors, int alev, int dir, const char c, const struct chan_mode *mode) |
| 867 |
{ |
| 868 |
if (alev < CHACCESS_HALFOP) |
| 869 |
{ |
| 870 |
if (!(*errors & SM_ERR_NOOPS)) |
| 871 |
sendto_one_numeric(source_p, &me, |
| 872 |
alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL : |
| 873 |
ERR_CHANOPRIVSNEEDED, chptr->name); |
| 874 |
*errors |= SM_ERR_NOOPS; |
| 875 |
return; |
| 876 |
} |
| 877 |
|
| 878 |
if (dir == MODE_QUERY) |
| 879 |
return; |
| 880 |
|
| 881 |
if (dir == MODE_ADD && parc > *parn) |
| 882 |
{ |
| 883 |
char *const key = fix_key(parv[(*parn)++]); |
| 884 |
|
| 885 |
if (EmptyString(key)) |
| 886 |
return; |
| 887 |
|
| 888 |
assert(key[0] != ' '); |
| 889 |
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
| 890 |
|
| 891 |
/* If somebody does MODE #channel +kk a b, accept latter --fl */ |
| 892 |
for (unsigned int i = 0; i < mode_count; ++i) |
| 893 |
if (mode_changes[i].letter == mode->letter && mode_changes[i].dir == MODE_ADD) |
| 894 |
mode_changes[i].letter = 0; |
| 895 |
|
| 896 |
mode_changes[mode_count].letter = mode->letter; |
| 897 |
mode_changes[mode_count].arg = key; |
| 898 |
mode_changes[mode_count].id = NULL; |
| 899 |
mode_changes[mode_count].flags = 0; |
| 900 |
mode_changes[mode_count++].dir = dir; |
| 901 |
} |
| 902 |
else if (dir == MODE_DEL) |
| 903 |
{ |
| 904 |
if (parc > *parn) |
| 905 |
++(*parn); |
| 906 |
|
| 907 |
if (chptr->mode.key[0] == '\0') |
| 908 |
return; |
| 909 |
|
| 910 |
chptr->mode.key[0] = '\0'; |
| 911 |
|
| 912 |
mode_changes[mode_count].letter = mode->letter; |
| 913 |
mode_changes[mode_count].arg = "*"; |
| 914 |
mode_changes[mode_count].id = NULL; |
| 915 |
mode_changes[mode_count].flags = 0; |
| 916 |
mode_changes[mode_count++].dir = dir; |
| 917 |
} |
| 918 |
} |
| 919 |
|
| 920 |
/* get_channel_access() |
| 921 |
* |
| 922 |
* inputs - pointer to Client struct |
| 923 |
* - pointer to Membership struct |
| 924 |
* output - CHACCESS_CHANOP if we should let them have |
| 925 |
* chanop level access, 0 for peon level access. |
| 926 |
* side effects - NONE |
| 927 |
*/ |
| 928 |
static int |
| 929 |
get_channel_access(const struct Client *source_p, |
| 930 |
const struct Membership *member) |
| 931 |
{ |
| 932 |
/* Let hacked servers in for now... */ |
| 933 |
if (!MyClient(source_p)) |
| 934 |
return CHACCESS_REMOTE; |
| 935 |
|
| 936 |
if (!member) |
| 937 |
return CHACCESS_NOTONCHAN; |
| 938 |
|
| 939 |
/* Just to be sure.. */ |
| 940 |
assert(source_p == member->client_p); |
| 941 |
|
| 942 |
if (has_member_flags(member, CHFL_CHANOP)) |
| 943 |
return CHACCESS_CHANOP; |
| 944 |
|
| 945 |
if (has_member_flags(member, CHFL_HALFOP)) |
| 946 |
return CHACCESS_HALFOP; |
| 947 |
|
| 948 |
return CHACCESS_PEON; |
| 949 |
} |
| 950 |
|
| 951 |
/* send_mode_changes_server() |
| 952 |
* Input: the source client(source_p), |
| 953 |
* the channel to send mode changes for(chptr) |
| 954 |
* Output: None. |
| 955 |
* Side-effects: Sends the appropriate mode changes to servers. |
| 956 |
* |
| 957 |
*/ |
| 958 |
static void |
| 959 |
send_mode_changes_server(struct Client *source_p, struct Channel *chptr) |
| 960 |
{ |
| 961 |
char modebuf[IRCD_BUFSIZE] = ""; |
| 962 |
char parabuf[IRCD_BUFSIZE] = ""; |
| 963 |
char *parptr = parabuf; |
| 964 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
| 965 |
unsigned int dir = MODE_QUERY; |
| 966 |
|
| 967 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
| 968 |
source_p->id, chptr->creationtime, chptr->name); |
| 969 |
|
| 970 |
/* Loop the list of modes we have */ |
| 971 |
for (unsigned int i = 0; i < mode_count; ++i) |
| 972 |
{ |
| 973 |
if (mode_changes[i].letter == 0) |
| 974 |
continue; |
| 975 |
|
| 976 |
const char *arg; |
| 977 |
if (mode_changes[i].id) |
| 978 |
arg = mode_changes[i].id; |
| 979 |
else |
| 980 |
arg = mode_changes[i].arg; |
| 981 |
|
| 982 |
if (arg) |
| 983 |
arglen = strlen(arg); |
| 984 |
else |
| 985 |
arglen = 0; |
| 986 |
|
| 987 |
/* |
| 988 |
* If we're creeping past the buf size, we need to send it and make |
| 989 |
* another line for the other modes |
| 990 |
*/ |
| 991 |
if ((paracount == MAXMODEPARAMS) || |
| 992 |
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
| 993 |
{ |
| 994 |
if (modecount) |
| 995 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
| 996 |
|
| 997 |
modecount = 0; |
| 998 |
paracount = 0; |
| 999 |
|
| 1000 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", |
| 1001 |
source_p->id, chptr->creationtime, chptr->name); |
| 1002 |
|
| 1003 |
pbl = 0; |
| 1004 |
parabuf[0] = '\0'; |
| 1005 |
parptr = parabuf; |
| 1006 |
dir = MODE_QUERY; |
| 1007 |
} |
| 1008 |
|
| 1009 |
if (dir != mode_changes[i].dir) |
| 1010 |
{ |
| 1011 |
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
| 1012 |
dir = mode_changes[i].dir; |
| 1013 |
} |
| 1014 |
|
| 1015 |
modebuf[mbl++] = mode_changes[i].letter; |
| 1016 |
modebuf[mbl] = '\0'; |
| 1017 |
++modecount; |
| 1018 |
|
| 1019 |
if (arg) |
| 1020 |
{ |
| 1021 |
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
| 1022 |
pbl += len; |
| 1023 |
parptr += len; |
| 1024 |
++paracount; |
| 1025 |
} |
| 1026 |
} |
| 1027 |
|
| 1028 |
if (modecount) |
| 1029 |
sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf); |
| 1030 |
} |
| 1031 |
|
| 1032 |
/* void send_mode_changes(struct Client *client_p, |
| 1033 |
* struct Client *source_p, |
| 1034 |
* struct Channel *chptr) |
| 1035 |
* Input: The client sending(client_p), the source client(source_p), |
| 1036 |
* the channel to send mode changes for(chptr), |
| 1037 |
* mode change globals. |
| 1038 |
* Output: None. |
| 1039 |
* Side-effects: Sends the appropriate mode changes to other clients |
| 1040 |
* and propagates to servers. |
| 1041 |
*/ |
| 1042 |
static void |
| 1043 |
send_mode_changes_client(struct Client *source_p, struct Channel *chptr) |
| 1044 |
{ |
| 1045 |
unsigned int flags = 0; |
| 1046 |
|
| 1047 |
for (unsigned int pass = 2; pass--; flags = CHFL_CHANOP | CHFL_HALFOP) |
| 1048 |
{ |
| 1049 |
char modebuf[IRCD_BUFSIZE] = ""; |
| 1050 |
char parabuf[IRCD_BUFSIZE] = ""; |
| 1051 |
char *parptr = parabuf; |
| 1052 |
unsigned int mbl = 0, pbl = 0, arglen = 0, modecount = 0, paracount = 0; |
| 1053 |
unsigned int dir = MODE_QUERY; |
| 1054 |
|
| 1055 |
if (IsServer(source_p)) |
| 1056 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
| 1057 |
ConfigServerHide.hide_servers) ? |
| 1058 |
me.name : source_p->name, chptr->name); |
| 1059 |
else |
| 1060 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
| 1061 |
source_p->username, source_p->host, chptr->name); |
| 1062 |
|
| 1063 |
for (unsigned int i = 0; i < mode_count; ++i) |
| 1064 |
{ |
| 1065 |
if (mode_changes[i].letter == 0 || mode_changes[i].flags != flags) |
| 1066 |
continue; |
| 1067 |
|
| 1068 |
const char *arg = mode_changes[i].arg; |
| 1069 |
if (arg) |
| 1070 |
arglen = strlen(arg); |
| 1071 |
else |
| 1072 |
arglen = 0; |
| 1073 |
|
| 1074 |
if ((paracount == MAXMODEPARAMS) || |
| 1075 |
((arglen + mbl + pbl + 2 /* +2 for /r/n */ ) > IRCD_BUFSIZE)) |
| 1076 |
{ |
| 1077 |
if (modecount) |
| 1078 |
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
| 1079 |
|
| 1080 |
modecount = 0; |
| 1081 |
paracount = 0; |
| 1082 |
|
| 1083 |
if (IsServer(source_p)) |
| 1084 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) || |
| 1085 |
ConfigServerHide.hide_servers) ? |
| 1086 |
me.name : source_p->name, chptr->name); |
| 1087 |
else |
| 1088 |
mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name, |
| 1089 |
source_p->username, source_p->host, chptr->name); |
| 1090 |
|
| 1091 |
pbl = 0; |
| 1092 |
parabuf[0] = '\0'; |
| 1093 |
parptr = parabuf; |
| 1094 |
dir = MODE_QUERY; |
| 1095 |
} |
| 1096 |
|
| 1097 |
if (dir != mode_changes[i].dir) |
| 1098 |
{ |
| 1099 |
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
| 1100 |
dir = mode_changes[i].dir; |
| 1101 |
} |
| 1102 |
|
| 1103 |
modebuf[mbl++] = mode_changes[i].letter; |
| 1104 |
modebuf[mbl] = '\0'; |
| 1105 |
++modecount; |
| 1106 |
|
| 1107 |
if (arg) |
| 1108 |
{ |
| 1109 |
int len = sprintf(parptr, (pbl == 0) ? "%s" : " %s", arg); |
| 1110 |
pbl += len; |
| 1111 |
parptr += len; |
| 1112 |
++paracount; |
| 1113 |
} |
| 1114 |
} |
| 1115 |
|
| 1116 |
if (modecount) |
| 1117 |
sendto_channel_local(NULL, chptr, flags, 0, 0, "%s %s", modebuf, parabuf); |
| 1118 |
} |
| 1119 |
} |
| 1120 |
|
| 1121 |
const struct chan_mode *cmode_map[256]; |
| 1122 |
const struct chan_mode cmode_tab[] = |
| 1123 |
{ |
| 1124 |
{ .letter = 'b', .func = chm_ban }, |
| 1125 |
{ .letter = 'c', .mode = MODE_NOCTRL, .func = chm_simple }, |
| 1126 |
{ .letter = 'e', .func = chm_except }, |
| 1127 |
{ .letter = 'h', .func = chm_hop }, |
| 1128 |
{ .letter = 'i', .mode = MODE_INVITEONLY, .func = chm_simple }, |
| 1129 |
{ .letter = 'k', .func = chm_key }, |
| 1130 |
{ .letter = 'l', .func = chm_limit }, |
| 1131 |
{ .letter = 'm', .mode = MODE_MODERATED, .func = chm_simple }, |
| 1132 |
{ .letter = 'n', .mode = MODE_NOPRIVMSGS, .func = chm_simple }, |
| 1133 |
{ .letter = 'o', .func = chm_op }, |
| 1134 |
{ .letter = 'p', .mode = MODE_PRIVATE, .func = chm_simple }, |
| 1135 |
{ .letter = 'r', .mode = MODE_REGISTERED, .only_servers = 1, .func = chm_simple }, |
| 1136 |
{ .letter = 's', .mode = MODE_SECRET, .func = chm_simple }, |
| 1137 |
{ .letter = 't', .mode = MODE_TOPICLIMIT, .func = chm_simple }, |
| 1138 |
{ .letter = 'u', .mode = MODE_HIDEBMASKS, .func = chm_simple }, |
| 1139 |
{ .letter = 'v', .func = chm_voice }, |
| 1140 |
{ .letter = 'C', .mode = MODE_NOCTCP, .func = chm_simple }, |
| 1141 |
{ .letter = 'I', .func = chm_invex }, |
| 1142 |
{ .letter = 'L', .mode = MODE_EXTLIMIT, .only_opers = 1, .func = chm_simple }, |
| 1143 |
{ .letter = 'M', .mode = MODE_MODREG, .func = chm_simple }, |
| 1144 |
{ .letter = 'O', .mode = MODE_OPERONLY, .only_opers = 1, .func = chm_simple }, |
| 1145 |
{ .letter = 'R', .mode = MODE_REGONLY, .func = chm_simple }, |
| 1146 |
{ .letter = 'S', .mode = MODE_SSLONLY, .func = chm_simple }, |
| 1147 |
{ .letter = 'T', .mode = MODE_NONOTICE, .func = chm_simple }, |
| 1148 |
{ .letter = '\0', .mode = 0 } |
| 1149 |
}; |
| 1150 |
|
| 1151 |
void |
| 1152 |
channel_mode_init(void) |
| 1153 |
{ |
| 1154 |
for (const struct chan_mode *tab = cmode_tab; tab->letter; ++tab) |
| 1155 |
cmode_map[tab->letter] = tab; |
| 1156 |
} |
| 1157 |
|
| 1158 |
/* |
| 1159 |
* Input: The the client this originated |
| 1160 |
* from, the channel, the parameter count starting at the modes, |
| 1161 |
* the parameters, the channel name. |
| 1162 |
* Output: None. |
| 1163 |
* Side-effects: Changes the channel membership and modes appropriately, |
| 1164 |
* sends the appropriate MODE messages to the appropriate |
| 1165 |
* clients. |
| 1166 |
*/ |
| 1167 |
void |
| 1168 |
set_channel_mode(struct Client *source_p, struct Channel *chptr, |
| 1169 |
struct Membership *member, int parc, char *parv[]) |
| 1170 |
{ |
| 1171 |
int dir = MODE_ADD; |
| 1172 |
int parn = 1; |
| 1173 |
int alevel = 0, errors = 0; |
| 1174 |
|
| 1175 |
mode_count = 0; |
| 1176 |
mode_limit = 0; |
| 1177 |
simple_modes_mask = 0; |
| 1178 |
|
| 1179 |
alevel = get_channel_access(source_p, member); |
| 1180 |
|
| 1181 |
for (const char *ml = parv[0]; *ml; ++ml) |
| 1182 |
{ |
| 1183 |
switch (*ml) |
| 1184 |
{ |
| 1185 |
case '+': |
| 1186 |
dir = MODE_ADD; |
| 1187 |
break; |
| 1188 |
case '-': |
| 1189 |
dir = MODE_DEL; |
| 1190 |
break; |
| 1191 |
case '=': |
| 1192 |
dir = MODE_QUERY; |
| 1193 |
break; |
| 1194 |
default: |
| 1195 |
{ |
| 1196 |
const struct chan_mode *mode = cmode_map[(unsigned char)*ml]; |
| 1197 |
|
| 1198 |
if (mode) |
| 1199 |
mode->func(source_p, chptr, parc, &parn, parv, &errors, alevel, dir, *ml, mode); |
| 1200 |
else |
| 1201 |
chm_nosuch(source_p, chptr, parc, &parn, parv, &errors, alevel, dir, *ml, mode); |
| 1202 |
break; |
| 1203 |
} |
| 1204 |
} |
| 1205 |
} |
| 1206 |
|
| 1207 |
/* Bail out if we have nothing to do... */ |
| 1208 |
if (!mode_count) |
| 1209 |
return; |
| 1210 |
|
| 1211 |
send_mode_changes_client(source_p, chptr); |
| 1212 |
send_mode_changes_server(source_p, chptr); |
| 1213 |
} |