Skip to content

Commit

Permalink
Merge default.
Browse files Browse the repository at this point in the history
--HG--
branch : shroudtrusts
  • Loading branch information
gunnarbeutner committed Jul 14, 2013
2 parents 8dfe8ec + 09926cb commit 68a88a9
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 545 deletions.
16 changes: 14 additions & 2 deletions chanserv/chancmds/addchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
reguser *founder;
flag_t flags;
short type=0;
unsigned int i;
unsigned int i, count;
void *args[3];

if (!rup)
Expand Down Expand Up @@ -102,7 +102,19 @@ int csc_doaddchan(void *source, int cargc, char **cargv) {
chanservstdmessage(notify, QM_ALREADYREGISTERED, cip->name->content);
return CMD_ERROR;
}


count = 0;

for (rcup=founder->knownon;rcup;rcup=rcup->nextbyuser)
count++;

if (count > MAXCHANNELS) {
chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
if (notify)
chanservstdmessage(sender, QM_TOOMANYCHANNELS, cip->name->content);
return CMD_ERROR;
}

/* Initialise the channel */
rcp=getregchan();

Expand Down
19 changes: 14 additions & 5 deletions chanserv/chancmds/adduser.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
int csc_doadduser(void *source, int cargc, char **cargv) {
nick *sender=source;
chanindex *cip;
regchanuser *rcup, *rcuplist;
regchanuser *rcup, *trcup, *rcuplist;
regchan *rcp;
reguser *rup;
flag_t addflags;
char *flagbuf;
unsigned int count=0;
unsigned int chanlevcount=0, channelcount=0;
int added=0;
int i, foundflags=0;
void *args[3];
Expand Down Expand Up @@ -82,9 +82,9 @@ int csc_doadduser(void *source, int cargc, char **cargv) {
flagbuf=printflags(addflags, rcuflags);

/* ugh */
for (count=i=0;i<REGCHANUSERHASHSIZE;i++)
for (chanlevcount=i=0;i<REGCHANUSERHASHSIZE;i++)
for (rcuplist=rcp->regusers[i];rcuplist;rcuplist=rcuplist->nextbychan)
count++;
chanlevcount++;

/* If we found flags don't try to add them as a user as well.. */
for (i=1+foundflags;i<cargc;i++) {
Expand All @@ -96,12 +96,21 @@ int csc_doadduser(void *source, int cargc, char **cargv) {
continue;
}

if(count++ >= MAXCHANLEVS) {
if(chanlevcount++ >= MAXCHANLEVS) {
chanservstdmessage(sender, QM_TOOMANYCHANLEVS);
chanservstdmessage(sender, QM_DONE);
return CMD_OK;
}

channelcount=0;
for (trcup=rup->knownon;trcup;trcup=trcup->nextbyuser)
channelcount++;

if(channelcount >= MAXCHANNELS) {
chanservstdmessage(sender, QM_TOOMANYCHANNELS);
return CMD_ERROR;
}

rcup=getregchanuser();
rcup->chan=rcp;
rcup->user=rup;
Expand Down
21 changes: 15 additions & 6 deletions chanserv/chancmds/chanlev.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int csc_dochanlev(void *source, int cargc, char **cargv) {
nick *sender=source;
chanindex *cip;
regchan *rcp;
regchanuser *rcup, *rcuplist;
regchanuser *rcup, *trcup, *rcuplist;
regchanuser **rusers;
reguser *rup=getreguserfromnick(sender), *target;
char time1[TIMELEN],time2[TIMELEN];
Expand Down Expand Up @@ -267,17 +267,26 @@ int csc_dochanlev(void *source, int cargc, char **cargv) {

if (!rcuplist) {
/* new user, we could store a count instead... that's probably better... */
unsigned int count;
unsigned int chanlevcount, channelcount;

for (count=i=0;i<REGCHANUSERHASHSIZE;i++)
for (chanlevcount=i=0;i<REGCHANUSERHASHSIZE;i++)
for (rcuplist=rcp->regusers[i];rcuplist;rcuplist=rcuplist->nextbychan)
count++;
chanlevcount++;

if(count >= MAXCHANLEVS) {
if(chanlevcount >= MAXCHANLEVS) {
chanservstdmessage(sender, QM_TOOMANYCHANLEVS);
return CMD_ERROR;
}


channelcount=0;
for (trcup=target->knownon;trcup;trcup=trcup->nextbyuser)
channelcount++;

if(channelcount >= MAXCHANNELS) {
chanservstdmessage(sender, QM_TOOMANYCHANNELS);
return CMD_ERROR;
}

rcuplist=getregchanuser();
rcuplist->user=target;
rcuplist->chan=rcp;
Expand Down
3 changes: 3 additions & 0 deletions chanserv/chanserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
#define MAXCHANLEVS 500
#define MAXBANS 50

/* Maximum number of channels a user may be known on */
#define MAXCHANNELS 500

/* Sources of entropy and standard length defines */
#define ENTROPYSOURCE "/dev/urandom"
#define ENTROPYLEN 8
Expand Down
1 change: 1 addition & 0 deletions chanserv/chanserv_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ BeginMessages() {
msg(QM_NOCHANBANAUTOREMOVE, "Bans on $0 will not be automatically removed.", "s"),
msg(QM_INVALIDCHANNAME, "$0 is not a valid channel name.", "s"),
msg(QM_ALREADYREGISTERED, "$0 is already registered.", "s"),
msg(QM_TOOMANYCHANNELS, "User is known on too many channels.", ""),
msg(QM_CURUSERFLAGS, "User flags for $0: $1", "ss"),
msg(QM_WELCOMEMESSAGEIS, "Welcome message for $0: $1", "ss"),
msg(QM_GLOBALINFO, "Default info line: $0", "s"),
Expand Down
6 changes: 6 additions & 0 deletions invalidbans/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@include@ @includel@../build.mk@includel@

.PHONY: all
all: invalidbans.so

invalidbans.so: invalidbans.o
149 changes: 149 additions & 0 deletions invalidbans/invalidbans.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include <string.h>
#include "../core/schedule.h"
#include "../control/control.h"
#include "../lib/irc_string.h"
#include "../localuser/localuserchannel.h"
#include "../lib/version.h"

MODULE_VERSION("");

static int ib_nickext;

typedef struct ibnick {
time_t timeout;
void *sched;
} ibnick;

static void ib_clear_ext(void *arg) {
nick *np = arg;

if (!np->exts[ib_nickext])
return;

free(np->exts[ib_nickext]);
np->exts[ib_nickext] = NULL;
}

static void ib_hook_newnick(int hooknum, void *arg) {
nick *np = arg;
np->exts[ib_nickext] = NULL;
}

static void ib_hook_lostnick(int hooknum, void *arg) {
nick *np = arg;
ibnick *inp = np->exts[ib_nickext];

if (!inp)
return;

deleteschedule(inp->sched, ib_clear_ext, np);
free(np->exts[ib_nickext]);
}

static void ib_hook_modechange(int hooknum, void *arg) {
void **arglist=(void **)arg;
channel *cp=(channel *)arglist[0];
nick *np=(nick *)arglist[1];
long changeflags=(long)arglist[2];
chanban *cbp;
const char *p;
int colons, colonsnext;
modechanges changes;
ibnick *inp;
char *mask, *pos;
int slot, i;
array bans;

if (!(changeflags & MODECHANGE_BANS))
return;

inp = np->exts[ib_nickext];

/* Ignore the mode change if the same user has recently
* set/unset a channel ban. */
if (inp && inp->timeout > time(NULL))
return;

if (inp) {
deleteschedule(inp->sched, ib_clear_ext, np);
free(inp);
np->exts[ib_nickext] = NULL;
}

array_init(&bans, 512);

for (cbp = cp->bans; cbp; cbp = cbp->next) {
if (!cbp->host)
continue;

colons = 0;
colonsnext = 0;

for (p = cbp->host->content; *p; p++) {
if (*p == ':') {
colons++;

if (*(p + 1) == ':')
colonsnext = 1;
}
}

if (colons - colonsnext >= 8) {
slot = array_getfreeslot(&bans);
mask = ((char *)bans.content) + slot * 512;
strncpy(mask, bantostring(cbp), 512);
}
}

if (bans.cursi > 0) {
localsetmodeinit(&changes, cp, NULL);

for (i = 0; i < bans.cursi; i++) {
mask = ((char *)bans.content) + i * 512;

pos = strchr(mask, '@');

if (!pos)
continue; /* This should never happen. */

pos++; /* Skip over the @ sign. */

for (; *pos; pos++) {
if (*pos != ':') {
*pos = '?';
break;
}
}

localdosetmode_ban(&changes, mask, MCB_ADD);
}

localsetmodeflush(&changes, 1);

/* Ignore the user for a short amount of time. If it's a bot
* it'll probably try re-setting the ban immediately. */
inp = malloc(sizeof(ibnick));
inp->timeout = time(NULL) + 15;
inp->sched = scheduleoneshot(inp->timeout + 1, ib_clear_ext, np);
np->exts[ib_nickext] = inp;
}

array_free(&bans);
}

void _init() {
registerhook(HOOK_NICK_NEWNICK, &ib_hook_newnick);
registerhook(HOOK_NICK_LOSTNICK, &ib_hook_lostnick);
registerhook(HOOK_CHANNEL_MODECHANGE, &ib_hook_modechange);

ib_nickext = registernickext("invalidbans");
}

void _fini () {
deregisterhook(HOOK_NICK_NEWNICK, &ib_hook_newnick);
deregisterhook(HOOK_NICK_LOSTNICK, &ib_hook_lostnick);
deregisterhook(HOOK_CHANNEL_MODECHANGE, &ib_hook_modechange);

releasenickext(ib_nickext);
}

4 changes: 0 additions & 4 deletions nick/nickhandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ int handlenickmsg(void *source, int cargc, char **cargv) {
}

base64toip(cargv[cargc-3], &ipaddress);
if (!irc_in_addr_valid(&ipaddress)) {
Error("nick",ERR_ERROR,"Received NICK with invalid ipaddress for %s from %s.",cargv[0],sender);
return CMD_ERROR;
}

/* At this stage the nick is cleared to proceed */
np=newnick();
Expand Down
2 changes: 1 addition & 1 deletion request/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ LDFLAGS+=$(LIBPGSQL)
.PHONY: all
all: request.so

request.so: lrequest.o request.o request_block.o sqrequest.o user.o
request.so: lrequest.o request.o request_block.o request_fasttrack.o sqrequest.o
Loading

0 comments on commit 68a88a9

Please sign in to comment.