| 29 |
|
#include "client.h" |
| 30 |
|
#include "common.h" |
| 31 |
|
#include "hash.h" |
| 32 |
+ |
#include "hostmask.h" |
| 33 |
|
#include "irc_string.h" |
| 34 |
|
#include "sprintf_irc.h" |
| 35 |
|
#include "ircd.h" |
| 44 |
|
#include "memory.h" |
| 45 |
|
#include "balloc.h" |
| 46 |
|
#include "s_log.h" |
| 47 |
+ |
#include "msg.h" |
| 48 |
|
|
| 49 |
|
/* some small utility functions */ |
| 50 |
|
static char *check_string(char *); |
| 92 |
|
#define NCHCAPS (sizeof(channel_capabs)/sizeof(int)) |
| 93 |
|
#define NCHCAP_COMBOS (1 << NCHCAPS) |
| 94 |
|
|
| 95 |
+ |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
| 96 |
|
/* some buffers for rebuilding channel/nick lists with ,'s */ |
| 97 |
|
static char modebuf[IRCD_BUFSIZE]; |
| 98 |
|
static char parabuf[MODEBUFLEN]; |
| 100 |
|
static int mode_count; |
| 101 |
|
static int mode_limit; /* number of modes set other than simple */ |
| 102 |
|
static int simple_modes_mask; /* bit mask of simple modes already set */ |
| 103 |
+ |
#ifdef HALFOPS |
| 104 |
+ |
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6, CAP_HOPS }; |
| 105 |
+ |
#else |
| 106 |
|
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6 }; |
| 107 |
+ |
#endif |
| 108 |
|
static struct ChCapCombo chcap_combos[NCHCAP_COMBOS]; |
| 109 |
|
extern BlockHeap *ban_heap; |
| 110 |
|
|
| 126 |
|
static char star[] = "*"; |
| 127 |
|
|
| 128 |
|
if (EmptyString(s)) |
| 129 |
< |
return (star); |
| 129 |
> |
return star; |
| 130 |
|
|
| 131 |
|
for (; *s; ++s) |
| 132 |
|
{ |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
|
| 140 |
< |
return (str); |
| 140 |
> |
return str; |
| 141 |
|
} |
| 142 |
|
|
| 143 |
|
/* |
| 150 |
|
int |
| 151 |
|
add_id(struct Client *client_p, struct Channel *chptr, char *banid, int type) |
| 152 |
|
{ |
| 153 |
< |
dlink_list *list; |
| 154 |
< |
dlink_node *ban; |
| 153 |
> |
dlink_list *list = NULL; |
| 154 |
> |
dlink_node *ban = NULL; |
| 155 |
|
size_t len = 0; |
| 156 |
< |
struct Ban *actualBan; |
| 156 |
> |
struct Ban *ban_p = NULL; |
| 157 |
|
unsigned int num_mask; |
| 158 |
< |
char *name = NULL, *user = NULL, *host = NULL; |
| 158 |
> |
char name[NICKLEN]; |
| 159 |
> |
char user[USERLEN + 1]; |
| 160 |
> |
char host[HOSTLEN + 1]; |
| 161 |
> |
struct split_nuh_item nuh; |
| 162 |
|
|
| 163 |
|
/* dont let local clients overflow the b/e/I lists */ |
| 164 |
|
if (MyClient(client_p)) |
| 177 |
|
collapse(banid); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
< |
split_nuh(check_string(banid), &name, &user, &host); |
| 180 |
> |
nuh.nuhmask = check_string(banid); |
| 181 |
> |
nuh.nickptr = name; |
| 182 |
> |
nuh.userptr = user; |
| 183 |
> |
nuh.hostptr = host; |
| 184 |
> |
|
| 185 |
> |
nuh.nicksize = sizeof(name); |
| 186 |
> |
nuh.usersize = sizeof(user); |
| 187 |
> |
nuh.hostsize = sizeof(host); |
| 188 |
> |
|
| 189 |
> |
split_nuh(&nuh); |
| 190 |
|
|
| 191 |
|
/* |
| 192 |
< |
* Assemble a n!u@h and print it back to banid for sending |
| 192 |
> |
* Re-assemble a new n!u@h and print it back to banid for sending |
| 193 |
|
* the mode to the channel. |
| 194 |
|
*/ |
| 195 |
|
len = ircsprintf(banid, "%s!%s@%s", name, user, host); |
| 214 |
|
|
| 215 |
|
DLINK_FOREACH(ban, list->head) |
| 216 |
|
{ |
| 217 |
< |
actualBan = ban->data; |
| 218 |
< |
if (!irccmp(actualBan->name, name) && |
| 219 |
< |
!irccmp(actualBan->username, user) && |
| 220 |
< |
!irccmp(actualBan->host, host)) |
| 217 |
> |
ban_p = ban->data; |
| 218 |
> |
if (!irccmp(ban_p->name, name) && |
| 219 |
> |
!irccmp(ban_p->username, user) && |
| 220 |
> |
!irccmp(ban_p->host, host)) |
| 221 |
|
{ |
| 203 |
– |
MyFree(name); |
| 204 |
– |
MyFree(user); |
| 205 |
– |
MyFree(host); |
| 222 |
|
return 0; |
| 223 |
|
} |
| 224 |
|
} |
| 225 |
|
|
| 226 |
< |
actualBan = BlockHeapAlloc(ban_heap); |
| 227 |
< |
actualBan->when = CurrentTime; |
| 228 |
< |
actualBan->name = name; |
| 229 |
< |
actualBan->username = user; |
| 230 |
< |
actualBan->host = host; |
| 231 |
< |
actualBan->len = len-2; /* -2 for @ and ! */ |
| 226 |
> |
ban_p = BlockHeapAlloc(ban_heap); |
| 227 |
> |
|
| 228 |
> |
DupString(ban_p->name, name); |
| 229 |
> |
DupString(ban_p->username, user); |
| 230 |
> |
DupString(ban_p->host, host); |
| 231 |
> |
|
| 232 |
> |
ban_p->when = CurrentTime; |
| 233 |
> |
ban_p->len = len - 2; /* -2 for @ and ! */ |
| 234 |
> |
ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits); |
| 235 |
|
|
| 236 |
|
if (IsClient(client_p)) |
| 237 |
|
{ |
| 238 |
< |
actualBan->who = |
| 239 |
< |
MyMalloc(strlen(client_p->name) + |
| 240 |
< |
strlen(client_p->username) + |
| 241 |
< |
strlen(client_p->host) + 3); |
| 242 |
< |
ircsprintf(actualBan->who, "%s!%s@%s", |
| 224 |
< |
client_p->name, client_p->username, client_p->host); |
| 238 |
> |
ban_p->who = MyMalloc(strlen(client_p->name) + |
| 239 |
> |
strlen(client_p->username) + |
| 240 |
> |
strlen(client_p->host) + 3); |
| 241 |
> |
ircsprintf(ban_p->who, "%s!%s@%s", client_p->name, |
| 242 |
> |
client_p->username, client_p->host); |
| 243 |
|
} |
| 244 |
|
else |
| 245 |
< |
DupString(actualBan->who, client_p->name); |
| 245 |
> |
DupString(ban_p->who, client_p->name); |
| 246 |
|
|
| 247 |
< |
dlinkAdd(actualBan, &actualBan->node, list); |
| 247 |
> |
dlinkAdd(ban_p, &ban_p->node, list); |
| 248 |
|
|
| 249 |
|
return 1; |
| 250 |
|
} |
| 262 |
|
dlink_list *list; |
| 263 |
|
dlink_node *ban; |
| 264 |
|
struct Ban *banptr; |
| 265 |
< |
char *name = NULL, *user = NULL, *host = NULL; |
| 265 |
> |
char name[NICKLEN]; |
| 266 |
> |
char user[USERLEN + 1]; |
| 267 |
> |
char host[HOSTLEN + 1]; |
| 268 |
> |
struct split_nuh_item nuh; |
| 269 |
|
|
| 270 |
|
if (banid == NULL) |
| 271 |
|
return 0; |
| 272 |
|
|
| 273 |
< |
split_nuh(check_string(banid), &name, &user, &host); |
| 273 |
> |
nuh.nuhmask = check_string(banid); |
| 274 |
> |
nuh.nickptr = name; |
| 275 |
> |
nuh.userptr = user; |
| 276 |
> |
nuh.hostptr = host; |
| 277 |
> |
|
| 278 |
> |
nuh.nicksize = sizeof(name); |
| 279 |
> |
nuh.usersize = sizeof(user); |
| 280 |
> |
nuh.hostsize = sizeof(host); |
| 281 |
> |
|
| 282 |
> |
split_nuh(&nuh); |
| 283 |
|
|
| 284 |
|
/* |
| 285 |
< |
* Assemble a n!u@h and print it back to banid for sending |
| 285 |
> |
* Re-assemble a new n!u@h and print it back to banid for sending |
| 286 |
|
* the mode to the channel. |
| 287 |
|
*/ |
| 288 |
|
ircsprintf(banid, "%s!%s@%s", name, user, host); |
| 303 |
|
default: |
| 304 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
| 305 |
|
"del_id() called with unknown ban type %d!", type); |
| 306 |
< |
MyFree(name); |
| 277 |
< |
MyFree(user); |
| 278 |
< |
MyFree(host); |
| 279 |
< |
return(0); |
| 306 |
> |
return 0; |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
DLINK_FOREACH(ban, list->head) |
| 311 |
|
banptr = ban->data; |
| 312 |
|
|
| 313 |
|
if (!irccmp(name, banptr->name) && |
| 314 |
< |
!irccmp(user, banptr->username) && |
| 315 |
< |
!irccmp(host, banptr->host)) |
| 314 |
> |
!irccmp(user, banptr->username) && |
| 315 |
> |
!irccmp(host, banptr->host)) |
| 316 |
|
{ |
| 317 |
|
remove_ban(banptr, list); |
| 291 |
– |
MyFree(name); |
| 292 |
– |
MyFree(user); |
| 293 |
– |
MyFree(host); |
| 318 |
|
return 1; |
| 319 |
|
} |
| 320 |
|
} |
| 321 |
|
|
| 298 |
– |
MyFree(name); |
| 299 |
– |
MyFree(user); |
| 300 |
– |
MyFree(host); |
| 322 |
|
return 0; |
| 323 |
|
} |
| 324 |
|
|
| 656 |
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 657 |
|
return; |
| 658 |
|
|
| 659 |
< |
mask = parv[(*parn)++]; |
| 660 |
< |
|
| 659 |
> |
mask = nuh_mask[*parn]; |
| 660 |
> |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 661 |
> |
++*parn; |
| 662 |
> |
|
| 663 |
|
if (IsServer(client_p)) |
| 664 |
|
if (strchr(mask, ' ')) |
| 665 |
|
return; |
| 753 |
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 754 |
|
return; |
| 755 |
|
|
| 756 |
< |
mask = parv[(*parn)++]; |
| 756 |
> |
mask = nuh_mask[*parn]; |
| 757 |
> |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 758 |
> |
++*parn; |
| 759 |
|
|
| 760 |
|
if (IsServer(client_p)) |
| 761 |
|
if (strchr(mask, ' ')) |
| 847 |
|
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
| 848 |
|
return; |
| 849 |
|
|
| 850 |
< |
mask = parv[(*parn)++]; |
| 850 |
> |
mask = nuh_mask[*parn]; |
| 851 |
> |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
| 852 |
> |
++*parn; |
| 853 |
|
|
| 854 |
|
if (IsServer(client_p)) |
| 855 |
|
if (strchr(mask, ' ')) |
| 893 |
|
{ |
| 894 |
|
dlink_node *ptr = NULL; |
| 895 |
|
|
| 896 |
< |
DLINK_FOREACH(ptr, chptr->locmembers.head) |
| 896 |
> |
DLINK_FOREACH(ptr, chptr->members.head) |
| 897 |
> |
{ |
| 898 |
> |
struct Membership *ms = ptr->data; |
| 899 |
> |
|
| 900 |
> |
if (MyConnect(ms->client_p)) |
| 901 |
> |
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
| 902 |
> |
} |
| 903 |
> |
} |
| 904 |
> |
|
| 905 |
> |
void |
| 906 |
> |
clear_ban_cache_client(struct Client *client_p) |
| 907 |
> |
{ |
| 908 |
> |
dlink_node *ptr = NULL; |
| 909 |
> |
|
| 910 |
> |
DLINK_FOREACH(ptr, client_p->channels.head) |
| 911 |
|
{ |
| 912 |
|
struct Membership *ms = ptr->data; |
| 913 |
|
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
| 923 |
|
char *opnick; |
| 924 |
|
struct Client *targ_p; |
| 925 |
|
struct Membership *member; |
| 926 |
+ |
int caps = 0; |
| 927 |
|
|
| 928 |
|
if (alev < CHACCESS_CHANOP) |
| 929 |
|
{ |
| 961 |
|
if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP)) |
| 962 |
|
return; |
| 963 |
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP)) |
| 964 |
+ |
{ |
| 965 |
+ |
#ifdef HALFOPS |
| 966 |
+ |
if (has_member_flags(member, CHFL_HALFOP)) |
| 967 |
+ |
chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev, |
| 968 |
+ |
dir, c, d, chname); |
| 969 |
+ |
#endif |
| 970 |
|
return; |
| 971 |
+ |
} |
| 972 |
+ |
|
| 973 |
+ |
#ifdef HALFOPS |
| 974 |
+ |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP)) |
| 975 |
+ |
{ |
| 976 |
+ |
/* promoting from % to @ is visible only to CAP_HOPS servers */ |
| 977 |
+ |
mode_changes[mode_count].letter = 'h'; |
| 978 |
+ |
mode_changes[mode_count].dir = MODE_DEL; |
| 979 |
+ |
mode_changes[mode_count].caps = caps = CAP_HOPS; |
| 980 |
+ |
mode_changes[mode_count].nocaps = 0; |
| 981 |
+ |
mode_changes[mode_count].mems = ALL_MEMBERS; |
| 982 |
+ |
mode_changes[mode_count].id = NULL; |
| 983 |
+ |
mode_changes[mode_count].arg = targ_p->name; |
| 984 |
+ |
mode_changes[mode_count++].client = targ_p; |
| 985 |
+ |
} |
| 986 |
+ |
#endif |
| 987 |
|
|
| 988 |
|
mode_changes[mode_count].letter = 'o'; |
| 989 |
|
mode_changes[mode_count].dir = dir; |
| 990 |
< |
mode_changes[mode_count].caps = 0; |
| 990 |
> |
mode_changes[mode_count].caps = caps; |
| 991 |
|
mode_changes[mode_count].nocaps = 0; |
| 992 |
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
| 993 |
|
mode_changes[mode_count].id = targ_p->id; |
| 997 |
|
if (dir == MODE_ADD) |
| 998 |
|
{ |
| 999 |
|
AddMemberFlag(member, CHFL_CHANOP); |
| 1000 |
< |
DelMemberFlag(member, CHFL_DEOPPED); |
| 1000 |
> |
DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP); |
| 1001 |
|
} |
| 1002 |
|
else |
| 1003 |
|
DelMemberFlag(member, CHFL_CHANOP); |
| 1061 |
|
return; |
| 1062 |
|
|
| 1063 |
|
/* no redundant mode changes */ |
| 1064 |
< |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP)) |
| 1064 |
> |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP)) |
| 1065 |
|
return; |
| 1066 |
|
if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP)) |
| 1067 |
|
return; |
| 1068 |
|
|
| 1069 |
|
mode_changes[mode_count].letter = 'h'; |
| 1070 |
|
mode_changes[mode_count].dir = dir; |
| 1071 |
< |
mode_changes[mode_count].caps = 0; |
| 1071 |
> |
mode_changes[mode_count].caps = CAP_HOPS; |
| 1072 |
|
mode_changes[mode_count].nocaps = 0; |
| 1073 |
|
mode_changes[mode_count].mems = ALL_MEMBERS; |
| 1074 |
|
mode_changes[mode_count].id = targ_p->id; |
| 1075 |
|
mode_changes[mode_count].arg = targ_p->name; |
| 1076 |
|
mode_changes[mode_count++].client = targ_p; |
| 1077 |
+ |
|
| 1078 |
+ |
mode_changes[mode_count].letter = 'o'; |
| 1079 |
+ |
mode_changes[mode_count].dir = dir; |
| 1080 |
+ |
mode_changes[mode_count].caps = 0; |
| 1081 |
+ |
mode_changes[mode_count].nocaps = CAP_HOPS; |
| 1082 |
+ |
mode_changes[mode_count].mems = ONLY_SERVERS; |
| 1083 |
+ |
mode_changes[mode_count].id = targ_p->id; |
| 1084 |
+ |
mode_changes[mode_count].arg = targ_p->name; |
| 1085 |
+ |
mode_changes[mode_count++].client = targ_p; |
| 1086 |
|
|
| 1087 |
|
if (dir == MODE_ADD) |
| 1088 |
|
{ |