glineinfo *glinebynickex(nick *np, int duration, const char *reason, int flags, const char *creator) { static glineinfo info; glinebuf gbuf; glinebufinit(&gbuf, 0); glinebufcommentf(&gbuf, "on nick %s!%s@%s, set by %s", np->nick, np->ident, np->host->name->content, creator); info.mask = glinebufaddbynick(&gbuf, np, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration); glinebufcounthits(&gbuf, &info.hits, NULL); if (flags & GLINE_SIMULATE) glinebufabort(&gbuf); else glinebufcommit(&gbuf, 1); return &info; }
int glinebyip(const char *user, struct irc_in_addr *ip, unsigned char bits, int duration, const char *reason, int flags, const char *creator) { glinebuf gbuf; int hits; glinebufinit(&gbuf, 0); glinebufcommentf(&gbuf, "on IP mask %s@%s, set by %s", user, CIDRtostr(*ip, bits), creator); glinebufaddbyip(&gbuf, user, ip, bits, flags, creator, reason, getnettime() + duration, getnettime(), getnettime() + duration); glinebufcounthits(&gbuf, &hits, NULL); if (flags & GLINE_SIMULATE) glinebufabort(&gbuf); else glinebufcommit(&gbuf, 1); return hits; }
void trusts_flush(void (*thflush)(trusthost *), void (*tgflush)(trustgroup *)) { trustgroup *tg; trusthost *th; time_t t = getnettime(); for(tg=tglist;tg;tg=tg->next) { if(tg->count > 0) tg->lastseen = t; tgflush(tg); for(th=tg->hosts;th;th=th->next) { if(th->count > 0) th->lastseen = t; thflush(th); } } }
int csc_dorollbackchan(void *source, int cargc, char **cargv) { nick *sender=source; chanindex *cip; reguser *rup, *trup=NULL; regchan *rcp; time_t starttime=getnettime(); long duration; if (!(rup=getreguserfromnick(sender))) return CMD_ERROR; if (cargc < 2) { chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "rollbackchan"); return CMD_ERROR; } if (!(cip=cs_checkaccess(sender, cargv[0], 0, NULL, NULL, 0, 0))) return CMD_ERROR; rcp=(regchan*)cip->exts[chanservext]; if (cargc > 2) { duration=durationtolong(cargv[2]); if (!(trup=findreguser(sender, cargv[1]))) return CMD_ERROR; } else duration=durationtolong(cargv[1]); if (!duration) { chanservsendmessage(sender, "Invalid duration."); return CMD_ERROR; } starttime-=duration; cs_log(sender,"ROLLBACKCHAN %s #%s %s", cip->name->content, rup->username, cargv[1]); csdb_rollbackchanlevhistory(sender, rcp, trup, starttime); return CMD_OK; }
void dotrustdenylist(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE]; long i, j; trustdeny *td; unsigned long snet, smask; char * mycip; res=sscanf(tail,"%s %s",tmps2,tmps3); if (res<2) { strcpy(tmps3,"0.0.0.0/0"); } if (!ischarinstr('/',tmps3)) { smask=32; snet=parseipv4(tmps3); } else { char h1[TMPSSIZE]; char h2[TMPSSIZE]; char dumc; int r2; r2=sscanf(tmps3,"%[0-9.]%c%[0-9]",h1,&dumc,h2); if (r2!=3) { msgtouser(unum,"Invalid subnetmask."); return; } snet=parseipv4(h1); smask=strtoul(h2,NULL,10); if (smask>32) { msgtouser(unum,"Invalid subnetmask."); return; } } trustdenyexpire(); td=(trustdeny *)deniedtrusts.content; j=0; for (i=0;i<deniedtrusts.cursi;i++) { if (((td[i].v4net&netmasks[smask])==(snet&netmasks[smask])) || ((td[i].v4net&netmasks[td[i].v4mask])==(snet&netmasks[td[i].v4mask]))) { if (j==0) { newmsgtouser(unum,"%-30s %-15s %-17s %-1s %s","IP/mask","by","expires in","t","Reason"); } longtoduration(tmps2,td[i].expires-getnettime()); mycip=printipv4(td[i].v4net); newmsgtouser(unum,"%-27s/%02u %-15s %-17s %s %s",mycip,td[i].v4mask,td[i].creator, tmps2,(td[i].type==TRUSTDENY_DENY) ? "D" : "W", td[i].reason); free(mycip); j++; } } if (j==0) { msgtouser(unum,"--- No matches ---"); } else { newmsgtouser(unum,"--- End of list - %ld matches ---",j); } }
static void pc_check(void) { patrolchannel *pc; channel *cp; for (pc = patrolchannels; pc; pc = pc->next) { if (pc->nick && pc->nick->timestamp > getnettime() - 900) continue; if (pc->nick) deregisterlocaluser(pc->nick, NULL); cp = findchannel(pc->channel->content); if (!cp) { pc->nick = NULL; continue; } pc->nick = patrol_generateclone(0, patroluserhandler); localjoinchannel(pc->nick, cp); } }
static void displaygroup(nick *sender, trustgroup *tg, int showchildren) { trusthost *th, **p2; unsigned int marker; array parents; int i; time_t t = getnettime(); /* abusing the ternary operator a bit :( */ controlreply(sender, "Name : %s", tg->name->content); controlreply(sender, "Trusted for : %s", formatlimit(tg->trustedfor)); controlreply(sender, "Currently using : %d", tg->count); controlreply(sender, "Clients per user : %s", formatlimit(tg->maxperident)); controlreply(sender, "Flags : %s", formatflags(tg->flags)); controlreply(sender, "Contact : %s", tg->contact->content); controlreply(sender, "Expires in : %s", (tg->expires)?((tg->expires>t)?longtoduration(tg->expires - t, 2):"the past (will be removed during next cleanup)"):"never"); controlreply(sender, "Created by : %s", tg->createdby->content); controlreply(sender, "Comment : %s", tg->comment->content); controlreply(sender, "ID : %u", tg->id); controlreply(sender, "Last used : %s", (tg->count>0)?"(now)":((tg->lastseen>0)?trusts_timetostr(tg->lastseen):"(never)")); controlreply(sender, "Max usage : %d", tg->maxusage); controlreply(sender, "Last max reset : %s", tg->lastmaxusereset?trusts_timetostr(tg->lastmaxusereset):"(never)"); controlreply(sender, "---"); controlreply(sender, "Attributes: * (has hidden children, show with -v), > (belongs to this trust group)"); controlreply(sender, "Host Current Max Last seen Max per Node Node Mask Group ID Group name"); marker = nextthmarker(); array_init(&parents, sizeof(trusthost *)); for(th=tg->hosts;th;th=th->next) marktree(&parents, marker, th, showchildren); p2 = (trusthost **)(parents.content); for(i=0;i<parents.cursi;i++) outputtree(sender, marker, tg, p2[i], 0, showchildren); array_free(&parents); }
/* todo: add RELINK status */ int spcmd_splitlist(void *source, int cargc, char **cargv) { nick *np = (nick*)source; int i; splitserver srv; if (splitlist.cursi == 0) { controlreply(np, "There currently aren't any registered splits."); return CMD_OK; } controlreply(np, "Server Status Split for"); for (i = 0; i < splitlist.cursi; i++) { srv = ((splitserver*)splitlist.content)[i]; controlreply(np, "%s M.I.A. %s (%s)", srv.name->content, longtoduration(getnettime() - srv.ts, 1), printflags(srv.type, servertypeflags)); } controlreply(np, "--- End of splitlist"); return CMD_OK; }
static void sphook_lostserver(int hook, void *arg) { server *server = &serverlist[(long)arg]; sp_addsplit(server->name->content, getnettime(), getservertype(server)); }
int ju_jupelist(void *source, int cargc, char **cargv) { nick *np = (nick*)source; jupe_t *jupe; jupe_expire(); jupe = jupes; controlreply(np, "Server Reason Expires Status"); while (jupe) { controlreply(np, "%s %s %s %s", JupeServer(jupe), JupeReason(jupe), longtoduration(jupe->ju_expire - getnettime(), 0), (jupe->ju_flags & JUPE_ACTIVE) ? "activated" : "deactivated"); jupe = jupe->ju_next; } controlreply(np, "--- End of JUPE list."); return CMD_OK; }
void dotrustdenyadd(long unum, char *tail) { int res; long i; trustdeny *td; long expires; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE], tmps6[TMPSSIZE]; unsigned long snet, smask; res=sscanf(tail,"%s %s %s %s %[^\n]",tmps2,tmps3,tmps4,tmps5,tmps6); if (res<5) { msgtouser(unum,"Syntax: trustdenyadd warn|deny subnet[/netmask] duration reason"); msgtouser(unum,"if netmask is omitted, then /32 (a single IP) is assumed."); return; } toLowerCase(tmps3); if (strcmp(tmps3,"warn")==0) { res=TRUSTDENY_WARN; } if (strcmp(tmps3,"deny")==0) { res=TRUSTDENY_DENY; } if ((res!=TRUSTDENY_WARN) && (res!=TRUSTDENY_DENY)) { msgtouser(unum,"You can only warn or deny."); return; } if (!ischarinstr('/',tmps4)) { smask=32; snet=parseipv4(tmps4); } else { char h1[TMPSSIZE]; char h2[TMPSSIZE]; char dumc; int r2; r2=sscanf(tmps4,"%[0-9.]%c%[0-9]",h1,&dumc,h2); if (r2!=3) { msgtouser(unum,"Invalid subnetmask."); return; } snet=parseipv4(h1); smask=strtoul(h2,NULL,10); if (smask>32) { msgtouser(unum,"Invalid subnetmask."); return; } } expires=durationtolong(tmps5); if (expires<1) { msgtouser(unum,"Invalid duration."); return; } expires+=getnettime(); td=(trustdeny *)deniedtrusts.content; for (i=0;i<deniedtrusts.cursi;i++) { if ((td[i].v4net==snet) && (td[i].v4mask=smask)) { longtoduration(tmps2,getnettime()-td[i].created); longtoduration(tmps3,td[i].expires-getnettime()); msgtouser(unum,"a trustdeny for that hostmask already exists - replacing values"); newmsgtouser(unum,"Old one was created by %s %s ago, expiring in %s and mode %s", td[i].creator,tmps2,tmps3,(td[i].type==TRUSTDENY_WARN) ? "WARN" : "DENY"); getauthedas(tmps2,unum); mystrncpy(td[i].creator,tmps2,AUTHUSERLEN); mystrncpy(td[i].reason,tmps6,RNGREAS); td[i].expires=expires; td[i].created=getnettime(); td[i].type=res; msgtouser(unum,"Done."); return; } } /* Not existing yet - allocate new entry */ i=array_getfreeslot(&deniedtrusts); td=(trustdeny *)deniedtrusts.content; getauthedas(tmps2,unum); mystrncpy(td[i].creator,tmps2,AUTHUSERLEN); mystrncpy(td[i].reason,tmps6,RNGREAS); td[i].expires=expires; td[i].created=getnettime(); td[i].v4net=snet; td[i].v4mask=smask; td[i].type=res; recreateimpsntrusts(); msgtouser(unum,"Done."); }
void dotrustgroupadd(long unum, char *tail) { int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE]; char tmps6[TMPSSIZE], tmps7[TMPSSIZE], tmps8[TMPSSIZE], tmps9[TMPSSIZE]; long dur; trustedgroup *tg; res=sscanf(tail,"%s %s %s %s %s %s %s %[^\n]",tmps2,tmps3,tmps4,tmps5,tmps6,tmps7,tmps8,tmps9); if ((res<7) || (res>8)) { msgtouser(unum,"Syntax: trustgroupadd name howmany howlong maxperident enforceident contact [comment]"); msgtouser(unum,"where name is a unique name for that group"); msgtouser(unum," howmany gives the number of clones allowed from that group"); msgtouser(unum," howlong gives how long the trust will last (e.g. '1y')"); msgtouser(unum," maxperident sets how many clones are allowed from a single user."); msgtouser(unum," 0 means unlimited"); msgtouser(unum," enforceident if set to 1 will kill all clients without idents"); msgtouser(unum," in that group"); msgtouser(unum," contact is one or more contact-emails, seperated by commas,"); msgtouser(unum," WITH NO SPACES!!!"); msgtouser(unum," comment is an optional comment"); return; } if (res==7) { strcpy(tmps9,"[no comment]"); } if (strlen(tmps3)>TRUSTNAMELEN) { msgtouser(unum,"The name you gave is too long"); return; } if (tmps3[0]=='#') { msgtouser(unum,"Trustgroupname must not start with a '#'"); return; } if (strlen(tmps8)>TRUSTCONTACTLEN) { msgtouser(unum,"contact-email is too long"); return; } if (strlen(tmps9)>TRUSTCOMLEN) { msgtouser(unum,"comment is too long"); return; } dur=durationtolong(tmps5); if (dur<1) { msgtouser(unum,"Invalid duration given"); return; } if (((tmps7[0]!='0') && (tmps7[0]!='1')) || (tmps7[1]!='\0')) { msgtouser(unum,"enforceident is a boolean setting, that means it can only be 0 or 1"); return; } toLowerCase(tmps3); tg=findtrustgroupbyname(tmps3); if (tg!=NULL) { /* This group exists, modify it */ sprintf(tmps2,"Trustgroup %s already exists, replacing values.",tmps3); msgtouser(unum,tmps2); sprintf(tmps2,"Old settings were: trusted for %lu users, max. clones per user %lu, %senforcing ident", tg->trustedfor,tg->maxperident,(tg->enforceident==0) ? "not " : ""); msgtouser(unum,tmps2); sprintf(tmps2,"Contact-eMail: %s",tg->contact); msgtouser(unum,tmps2); sprintf(tmps2,"Comment: %s",tg->comment); msgtouser(unum,tmps2); } else { /* New group */ unsigned long newID; tg=(trustedgroup *)malloc(sizeof(trustedgroup)); if (tg==NULL) { printf("!!! Out of memory in dotrustgroupadd !!!\n"); exit(0); } newID=getfreetgid(); tg->id=newID; tg->currentlyon=0; tg->lastused=0; tg->maxused=0; tg->maxreset=0; tg->next=(void *)trustedgroups[tgshash(newID)]; trustedgroups[tgshash(newID)]=tg; array_init(&(tg->identcounts),sizeof(identcounter)); } tg->enforceident=(tmps7[0]=='1'); strcpy(tg->name,tmps3); strcpy(tg->contact,tmps8); strcpy(tg->comment,tmps9); tg->trustedfor=strtol(tmps4,NULL,10); tg->maxperident=strtol(tmps6,NULL,10); tg->expires=getnettime()+dur; numtonick(unum,tmps2); mystrncpy(tg->creator,tmps2,AUTHUSERLEN); sprintf(tmps2,"%s created/updated Trustgroup %s (#%ld) - %lu / %lu / %d", tg->creator,tg->name,tg->id,tg->trustedfor,tg->maxperident,tg->enforceident); sendtonoticemask(NM_TRUSTS,tmps2); sprintf(tmps2,"Trustgroup %s (#%ld) created/updated",tg->name,tg->id); msgtouser(unum,tmps2); }
void dotrustgroupmodify(long unum, char *tail) { int res; signed long newv, previous; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE]; trustedgroup *tg; char whats[4][20] = {"Maxclones","Maxperuser","Expiration","Enforceident"}; int whatwedo; res = sscanf(tail, "%s %s %30[^+-=1234567890]%30[^\n]", tmps2, tmps3, tmps5, tmps4); if (res==2) { res=sscanf(tail,"%s %s %s",tmps2,tmps3,tmps5); } if (res < 3) { msgtouser(unum, "Syntax: trustgroupmodify <groupname OR #groupid> [what][+|-|=]number"); msgtouser(unum, " for the number, +20 means add 20, -15 means subtract 15,"); msgtouser(unum, " =35 means it to 35, 20 means add 20."); msgtouser(unum, " what can be one of: maxclones, maxperuser, expire, enforceident"); msgtouser(unum, " and defaults to maxclones."); return; } toLowerCase(tmps3); if (tmps3[0] == '#') { tg = findtrustgroupbyID(strtol(&tmps3[1], NULL, 10)); } else { tg = findtrustgroupbyname(tmps3); } if (tg == NULL) { newmsgtouser(unum, "A trustgroup with that %s does not exist.", (tmps3[0] == '#') ? "ID" : "name"); return; } if (tg->id == 0) { msgtouser(unum, "Internal error: Trustgroup has ID 0"); return; } if (res==3) { /* No "what" argument, we assume maxclones */ strcpy(tmps4,tmps5); strcpy(tmps5,"maxclones"); } toLowerCase(tmps5); whatwedo=-1; if (strcmp(tmps5,"maxclones")==0) { whatwedo=0; } if (strcmp(tmps5,"maxperuser")==0) { whatwedo=1; } if (strncmp(tmps5,"expir",5)==0) { whatwedo=2; } if (strcmp(tmps5,"maxperident")==0) { whatwedo=1; } if (strcmp(tmps5,"enforceident")==0) { whatwedo=3; } if (whatwedo<0) { newmsgtouser(unum,"Don't know what %s is (and of course not how to change it either).",tmps5); return; } switch (whatwedo) { case 0: previous = tg->trustedfor; break; case 1: previous = tg->maxperident; break; case 2: previous = tg->expires; break; case 3: previous = tg->enforceident; break; default: msgtouser(unum,"Internal error: programmer too dumb."); return; } if (tmps4[0] == '=') { if (whatwedo==2) { newv = durationtolong(tmps4 + 1); if (newv<=0) { msgtouser(unum,"Invalid duration."); return; } newv+=getnettime(); } else { newv = strtol(tmps4 + 1, NULL, 10); } if (newv > previous) { tmps4[0] = '+'; } else { tmps4[0] = '-'; } } else { if (whatwedo==2) { if ((tmps4[0]=='-') || (tmps4[0]=='+')) { if (tmps4[0]=='-') { newv = previous-durationtolong(tmps4 + 1); } else { newv = previous+durationtolong(tmps4 + 1); } } else { newv=previous+durationtolong(tmps4); } } else { newv = previous + strtol(tmps4, NULL, 10); } } if ((newv<0) || ((newv <= 0) && (whatwedo==1))) { msgtouser(unum, "That would make it less or equal to 0 (zero)."); return; } if (whatwedo==3) { newv=newv%2; } switch (whatwedo) { case 0: tg->trustedfor = newv; break; case 1: tg->maxperident = newv; break; case 2: tg->expires = newv; break; case 3: tg->enforceident = newv; break; default: msgtouser(unum,"Internal error: programmer too dumb #2."); return; } getauthedas(tg->creator,unum); newmsgtouser(unum, "%s %s from %d to %d.", whats[whatwedo], (tmps4[0] == '-') ? "lowered" : "raised", previous, newv); sprintf(tmps2,"%s created/updated Trustgroup %s (#%ld) - %lu / %lu / %d", tg->creator,tg->name,tg->id,tg->trustedfor,tg->maxperident,tg->enforceident); sendtonoticemask(NM_TRUSTS,tmps2); }
void csdb_chanlevhistory_insert(regchan *rcp, nick *np, reguser *trup, flag_t oldflags, flag_t newflags) { reguser *rup=getreguserfromnick(np); assert(rup != NULL); dbquery("INSERT INTO chanserv.chanlevhistory (userID, channelID, targetID, changetime, authtime, " "oldflags, newflags) VALUES (%u, %u, %u, %lu, %lu, %u, %u)", rup->ID, rcp->ID, trup->ID, getnettime(), np->accountts, oldflags, newflags); }
int spcmd_splitadd(void *source, int cargc, char **cargv) { nick *np = (nick*)source; unsigned long long num; char *end; flag_t servertype = 0; char *servername; size_t servernamelen; time_t splittime; server fake; if (cargc < 1) { controlreply(np, "Usage: splitadd <servername> [+flags] [split time as unix timestamp]"); return CMD_ERROR; } servername = cargv[0]; servernamelen = strlen(servername); if (findserver(servername) != -1) { controlreply(np, "Server %s is linked right now, refusing to add split.", servername); return CMD_ERROR; } if (doessplitalreadyexist(servername)) { controlreply(np, "There is a split for %s already.", servername); return CMD_ERROR; } if (servernamelen > SERVERLEN) { controlreply(np, "Server name %s is too long (max: %d characters)", servername, SERVERLEN); return CMD_ERROR; } /* Handle flags */ if (cargc > 1) { if (setflags(&servertype, (flag_t)-1, cargv[1], servertypeflags, REJECT_UNKNOWN) != REJECT_NONE) { controlreply(np, "Flag string %s contained invalid flags.", cargv[1]); return CMD_ERROR; } } else { /* Set up a fake server for getservertype. */ memset(&fake, 0, sizeof(fake)); fake.name = getsstring(servername, servernamelen); servertype = getservertype(&fake); freesstring(fake.name); } /* Handle timestamp */ if (cargc < 3) { splittime = getnettime(); } else { errno = 0; num = strtoull(cargv[2], &end, 10); if (errno == ERANGE) { controlreply(np, "%s is out of range for a timestamp.", cargv[2]); return CMD_ERROR; } /* Truncation may happen here. * However, there's no way to get the max time_t value, so we'll just try to * find out after the fact. */ splittime = (time_t)num; if ((unsigned long long)splittime < num) { controlreply(np, "Tried to use %llu as split time value, but it's too " "large for the system to handle", num); return CMD_ERROR; } } sp_addsplit(servername, splittime, servertype); controlreply(np, "Added split for %s (%s ago) with flags %s.", servername, longtoduration(getnettime() - splittime, 1), printflags(servertype, servertypeflags)); return CMD_OK; }