[srvx-commits] CVS: services/src chanserv.c,1.343,1.344
Brought to you by:
entrope
|
From: Zoot <zo...@us...> - 2003-02-28 22:15:57
|
Update of /cvsroot/srvx/services/src
In directory sc8-pr-cvs1:/tmp/cvs-serv13835/src
Modified Files:
chanserv.c
Log Message:
Make ChanServ enforce specific keys and limits; fix ChanServ sending out mode strings that aren't totally valid.
Index: chanserv.c
===================================================================
RCS file: /cvsroot/srvx/services/src/chanserv.c,v
retrieving revision 1.343
retrieving revision 1.344
diff -C2 -r1.343 -r1.344
*** chanserv.c 21 Feb 2003 17:14:25 -0000 1.343
--- chanserv.c 28 Feb 2003 22:15:51 -0000 1.344
***************
*** 985,992 ****
static void
! create_mode_lock(unsigned char *buffer, struct chanData *channel)
{
int pos = 0, n;
long mode = channel->mode_on;
for(n=0; n<2; n++)
--- 985,993 ----
static void
! create_mode_lock(unsigned char *buffer, struct chanData *channel, int display)
{
int pos = 0, n;
long mode = channel->mode_on;
+ char *key = NULL;
for(n=0; n<2; n++)
***************
*** 1013,1017 ****
/* parse_mode_lock() restricts limit to positive numbers. */
if(mode & MODE_LIMIT) buffer[pos++] = 'l';
! if(mode & MODE_KEY) buffer[pos++] = 'k';
mode = channel->mode_off;
--- 1014,1053 ----
/* parse_mode_lock() restricts limit to positive numbers. */
if(mode & MODE_LIMIT) buffer[pos++] = 'l';
!
! /* Figure out if the 'k' character should be included in
! the mode string and if a key should be appended. */
! if(mode & MODE_KEY)
! {
! if(mode == channel->mode_on || display)
! {
! /* If the key is getting locked on, or if the mode
! string is getting displayed (key locked on or
! off), include the 'k' character. */
! buffer[pos++] = 'k';
! if(mode == channel->mode_on)
! {
! /* If the key is getting locked on, include the
! actual key (whether the mode's displayed or
! not). */
! key = channel->key;
! }
! }
! else
! {
! /* The key is locked off and the mode string isn't
! displayed, so add in the 'k' and key if there's
! a key to remove. If not and the key is the only
! mode locked off, back up over the '-'. */
! if(channel->channel && channel->channel->key[0])
! {
! buffer[pos++] = 'k';
! key = channel->channel->key;
! }
! else if(mode == MODE_KEY)
! {
! pos--;
! }
! }
! }
mode = channel->mode_off;
***************
*** 1025,1034 ****
}
! if((channel->mode_on & MODE_KEY) && channel->key)
{
! int len = strlen(channel->key);
buffer[pos++] = ' ';
! memcpy(buffer + pos, channel->key, len);
pos += len;
}
--- 1061,1070 ----
}
! if(key)
{
! int len = strlen(key);
buffer[pos++] = ' ';
! memcpy(buffer + pos, key, len);
pos += len;
}
***************
*** 1038,1041 ****
--- 1074,1105 ----
static int
+ mode_lock_violated(struct chanNode *channel)
+ {
+ chan_mode_t on, off;
+
+ on = channel->channel_info->mode_on;
+ off = channel->channel_info->mode_off;
+
+ if((on & (channel->modes ^ on)) || (channel->modes & off))
+ {
+ return 1;
+ }
+
+ if(on & MODE_KEY)
+ {
+ if(strcmp(channel->key, channel->channel_info->key))
+ return 1;
+ }
+
+ if(on & MODE_LIMIT)
+ {
+ if(channel->limit != channel->channel_info->limit)
+ return 1;
+ }
+
+ return 0;
+ }
+
+ static int
append_entry(const char *key, void *data, void *extra)
{
***************
*** 3973,3977 ****
if(channel->channel_info->mode_on || channel->channel_info->mode_off)
{
! create_mode_lock(modes, channel->channel_info);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
--- 4037,4041 ----
if(channel->channel_info->mode_on || channel->channel_info->mode_off)
{
! create_mode_lock(modes, channel->channel_info, 0);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
***************
*** 3994,4006 ****
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
{
! chan_mode_t on = channel->channel_info->mode_on;
!
! if((on && ((channel->modes & on) != on)) || (channel->modes & channel->channel_info->mode_off))
{
! create_mode_lock(modes, channel->channel_info);
!
mod_chanmode(channel, chanserv, modes);
- irc_mode(chanserv, channel, modes);
chanserv_notice(user, CSMSG_MODE_LOCKED, modes, channel->name);
return 0;
--- 4058,4070 ----
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
{
! if(mode_lock_violated(channel))
{
! /* verify_mod_chanmode() modified srvx's channel mode data
! but didn't send it out, so just undo it and don't worry
! about sending the corrections out. */
! create_mode_lock(modes, channel->channel_info, 0);
mod_chanmode(channel, chanserv, modes);
+ create_mode_lock(modes, channel->channel_info, 1);
chanserv_notice(user, CSMSG_MODE_LOCKED, modes, channel->name);
return 0;
***************
*** 4190,4194 ****
if(uData && uData->access >= ulOp)
{
! create_mode_lock(modes, cData);
chanserv_notice(user, CSMSG_CHANNEL_TOPIC, cData->topic);
chanserv_notice(user, CSMSG_CHANNEL_MODES, modes[0] ? modes : "None.");
--- 4254,4258 ----
if(uData && uData->access >= ulOp)
{
! create_mode_lock(modes, cData, 1);
chanserv_notice(user, CSMSG_CHANNEL_TOPIC, cData->topic);
chanserv_notice(user, CSMSG_CHANNEL_MODES, modes[0] ? modes : "None.");
***************
*** 5265,5278 ****
}
! create_mode_lock(modes, channel->channel_info);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
}
}
- else
- {
- create_mode_lock(modes, channel->channel_info);
- }
chanserv_notice(user, CSMSG_STRING_VALUE, "Modes ", strlen(modes) ? modes : "None.");
return 1;
--- 5329,5339 ----
}
! create_mode_lock(modes, channel->channel_info, 0);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
}
}
+ create_mode_lock(modes, channel->channel_info, 1);
chanserv_notice(user, CSMSG_STRING_VALUE, "Modes ", strlen(modes) ? modes : "None.");
return 1;
***************
*** 6063,6067 ****
{
char modes[MODELEN];
! create_mode_lock(modes, cData);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
--- 6124,6128 ----
{
char modes[MODELEN];
! create_mode_lock(modes, cData, 0);
mod_chanmode(channel, chanserv, modes);
irc_mode(chanserv, channel, modes);
***************
*** 6411,6428 ****
if(change_type == MODE_CHANGE_MISC)
{
- chan_mode_t on;
(void)change;
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
{
! on = channel->channel_info->mode_on;
! if((on && ((channel->modes & on) != on)) || (channel->modes & channel->channel_info->mode_off))
{
char correct[MODELEN];
- create_mode_lock(correct, channel->channel_info);
mod_chanmode(channel, chanserv, correct);
irc_mode(chanserv, channel, correct);
chanserv_notice(user, CSMSG_MODE_LOCKED, correct, channel->name);
}
--- 6472,6488 ----
if(change_type == MODE_CHANGE_MISC)
{
(void)change;
if(!check_user_level(user, channel, channel->channel_info->options[optEnfModes], 1, 0))
{
! if(mode_lock_violated(channel))
{
char correct[MODELEN];
+ create_mode_lock(correct, channel->channel_info, 0);
mod_chanmode(channel, chanserv, correct);
irc_mode(chanserv, channel, correct);
+ create_mode_lock(correct, channel->channel_info, 1);
chanserv_notice(user, CSMSG_MODE_LOCKED, correct, channel->name);
}
***************
*** 7109,7113 ****
if(channel->mode_on || channel->mode_off)
{
! create_mode_lock(buf, channel);
saxdb_write_string(ctx, KEY_MODES, buf);
}
--- 7169,7173 ----
if(channel->mode_on || channel->mode_off)
{
! create_mode_lock(buf, channel, 1);
saxdb_write_string(ctx, KEY_MODES, buf);
}
|