int ju_addjupe(void *source, int cargc, char **cargv) { nick *np = (nick*)source; int result, duration; if (cargc < 3) { return CMD_USAGE; } if (jupe_find(cargv[0]) != NULL) { controlreply(np, "There is already a jupe for that server."); return CMD_OK; } duration = durationtolong(cargv[1]); if (duration > JUPE_MAX_EXPIRE) { controlreply(np, "A jupe's maximum duration is %s. Could not create jupe.", longtoduration(JUPE_MAX_EXPIRE, 0)); return CMD_OK; } result = jupe_add(cargv[0], cargv[2], duration, JUPE_ACTIVE); if (result) { controlwall(NO_OPER, NL_MISC, "%s added JUPE for '%s' expiring in %s with reason %s", controlid(np), cargv[0], longtoduration(duration, 0), cargv[2]); controlreply(np, "Done."); } else controlreply(np, "Jupe could not be created."); return CMD_OK; }
int csa_doactivateuser(void *source, int cargc, char **cargv) { reguser *rup; nick *sender=(nick *)source; if(cargc<1) { controlreply(sender, "ACTIVATEUSER FALSE args"); return CMD_ERROR; } rup = findreguserbyID(atoi(cargv[0])); if(rup == NULL) { controlreply(sender, "ACTIVATEUSER FALSE useridnotexist"); return CMD_ERROR; } if(!UIsInactive(rup)) { controlreply(sender, "ACTIVATEUSER FALSE accountactive"); return CMD_ERROR; } UClearInactive(rup); csdb_updateuser(rup); cs_log(sender,"ACTIVATEUSER OK username %s",rup->username); controlreply(sender, "ACTIVATEUSER TRUE"); return CMD_OK; }
int csa_doresendemail(void *source, int cargc, char **cargv) { reguser *rup; nick *sender=(nick *)source; if(cargc<1) { controlreply(sender, "RESENDEMAIL FALSE args"); return CMD_ERROR; } rup = findreguserbyID(atoi(cargv[0])); if(rup == NULL) { controlreply(sender, "RESENDEMAIL FALSE useridnotexist"); return CMD_ERROR; } if(!UIsInactive(rup)) { controlreply(sender, "RESENDEMAIL FALSE accountactive"); return CMD_ERROR; } sendemail(rup); controlreply(sender, "RESENDEMAIL TRUE"); cs_log(sender,"RESENDEMAIL OK username %s",rup->username); return CMD_OK; }
int lua_forcegc(void *sender, int cargc, char **cargv) { nick *np = (nick *)sender; lua_list *l; int membefore = 0, memafter = 0; if(cargc == 0) { for(l=lua_head;l;l=l->next) { membefore+=lua_gc(l->l, LUA_GCCOUNT, 0); controlreply(np, "GC'ing %s. . .", l->name->content); lua_gc(l->l, LUA_GCCOLLECT, 0); memafter+=lua_gc(l->l, LUA_GCCOUNT, 0); } } else { l = lua_scriptloaded(cargv[0]); if(!l) { controlreply(np, "Script %s is not loaded.", cargv[0]); return CMD_ERROR; } membefore+=lua_gc(l->l, LUA_GCCOUNT, 0); lua_gc(l->l, LUA_GCCOLLECT, 0); memafter+=lua_gc(l->l, LUA_GCCOUNT, 0); } controlreply(np, "Done."); controlreply(np, "Freed: %dKb (%0.2f%% of %dKb) -- %dKb now in use.", membefore - memafter, ((double)membefore - (double)memafter) / (double)membefore * 100, membefore, memafter); return CMD_OK; }
int ca_carrot(void *source, int cargc, char **cargv) { nick *sender=(nick *)source; nick *victim; channel *cp; if (cargc<1) return CMD_USAGE; if ((victim=getnickbynick(cargv[0]))!=NULL) { controlreply(victim,"%cACTION ger %s en morot%c",1,victim->nick,1); controlreply(sender,"Gave %s a carrot.",victim->nick); } else if ((cp=findchannel(cargv[0]))!=NULL) { if (cargc>1) { controlchanmsg(cp,"%cACTION ger %s en morot%c",1,cargv[1],1); } else { controlchanmsg(cp,"%cACTION waves a carrot around menacingly.%c",1,1); } controlreply(sender,"Used carrot in %s.",cp->index->name->content); } else { controlreply(sender,"Couldn't find %s.",cargv[0]); } return CMD_OK; }
int spcmd_splitdel(void *source, int cargc, char **cargv) { nick *np = (nick*)source; int i, count; splitserver srv; if (cargc < 1) { controlreply(np, "Syntax: splitdel <pattern>"); return CMD_ERROR; } count = 0; for (i = splitlist.cursi - 1; i >= 0; i--) { srv = ((splitserver*)splitlist.content)[i]; if (match2strings(cargv[0], srv.name->content)) { sp_deletesplit(srv.name->content); /* inefficient .. but it doesn't matter */ count++; } } controlreply(np, "%d %s deleted.", count, count != 1 ? "splits" : "split"); return CMD_OK; }
int ju_deactivatejupe(void *source, int cargc, char **cargv) { nick *np = (nick*)source; jupe_t *jupe; if (cargc < 1) { return CMD_USAGE; } jupe = jupe_find(cargv[0]); if (jupe == NULL) { controlreply(np, "There is no such jupe."); return CMD_OK; } if ((jupe->ju_flags & JUPE_ACTIVE) == 0) { controlreply(np, "This jupe is already deactivated."); return CMD_OK; } jupe_deactivate(jupe); controlwall(NO_OPER, NL_MISC, "%s deactivated JUPE for '%s'", controlid(np), cargv[0]); controlreply(np, "Done."); return CMD_OK; }
static int pc_cmd_patrollist(void *source, int cargc, char **cargv) { nick *sender = source; patrolchannel *pc; for (pc = patrolchannels; pc; pc = pc->next) controlreply(sender, "%s - %s", pc->channel->content, pc->nick ? controlid(pc->nick) : "Not currently joined."); controlreply(sender, "End of list."); return CMD_OK; }
int lua_lslua(void *sender, int cargc, char **cargv) { nick *np = (nick *)sender; lua_list *l; controlreply(np, "Loaded scripts:"); for(l=lua_head;l;l=l->next) controlreply(np, "%s (mem: %dKb calls: %lu user: %0.2fs sys: %0.2fs)", l->name->content, lua_gc(l->l, LUA_GCCOUNT, 0), l->calls, (double)((double)l->ru_utime.tv_sec + (double)l->ru_utime.tv_usec / USEC_DIFFERENTIAL), (double)((double)l->ru_stime.tv_sec + (double)l->ru_stime.tv_usec / USEC_DIFFERENTIAL)); controlreply(np, "Done."); return CMD_OK; }
static int pc_cmd_patrolpart(void *source, int cargc, char **cargv) { nick *sender = source; if (cargc < 1) return CMD_USAGE; if (pc_part(cargv[0]) < 0) { controlreply(sender, "Could not join channel."); return CMD_ERROR; } controlreply(sender, "Done."); return CMD_OK; }
static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup, trusthost *th, int depth, int showchildren) { const char *cidrstr; char *prespacebuf, *postspacebuf, parentbuf[512]; if(th->marker != marker) return; cidrstr = CIDRtostr(th->ip, th->bits); calculatespaces(depth + 2, 30 + 1, cidrstr, &prespacebuf, &postspacebuf); if(th->group == originalgroup) { if(!showchildren && th->group == originalgroup && th->children) prespacebuf[0] = '*'; else prespacebuf[0] = ' '; prespacebuf[1] = '>'; parentbuf[0] = '\0'; } else { /* show the ids of other groups */ snprintf(parentbuf, sizeof(parentbuf), "%-10d %s", th->group->id, th->group->name->content); } controlreply(np, "%s%s%s %-10d %-10d %-21s %-15d /%-14d%s", prespacebuf, cidrstr, postspacebuf, th->count, th->maxusage, (th->count>0)?"(now)":((th->lastseen>0)?trusts_timetostr(th->lastseen):"(never)"), th->maxpernode, (irc_in_addr_is_ipv4(&th->ip))?(th->nodebits - 96):th->nodebits, parentbuf); /* Make sure we're not seeing this subtree again. */ th->marker = -1; for(th=th->children;th;th=th->nextbychild) outputtree(np, marker, originalgroup, th, depth + 1, showchildren); }
static int fakeadd(void *source, int cargc, char **cargv) { nick *sender = source; fakeuser *fake; char *nick, *ident, *realname; char host[HOSTLEN + 1]; if (cargc == 0) return CMD_USAGE; fake = findfakeuserbynick(cargv[0]); if (fake) { controlreply(sender, "Fake User with nick %s already found", cargv[0]); return CMD_ERROR; } nick = cargv[0]; if (cargc < 4) realname = cargv[0]; else realname = cargv[3]; if (cargc < 3) { strlcpy(host, cargv[0], NICKLEN + 1); strlcat(host, ".fakeusers.quakenet.org", HOSTLEN + 1); } else strlcpy(host, cargv[2], HOSTLEN + 1); if (cargc < 2) ident = cargv[0]; else ident = cargv[1]; fake = fake_create(nick, ident, host, realname); if (!fake) return CMD_ERROR; controlreply(sender, "Added fake user %s", fake->nick); controlwall(NO_OPER, NL_FAKEUSERS, "%s added fake user: %s!%s@%s (%s)", controlid(sender), fake->nick, fake->ident, fake->host, fake->realname); scheduleoneshot(time(NULL) + 1, &reconnectfakeuser, fake); return CMD_OK; }
int csa_dosetemail(void *source, int cargc, char **cargv) { char *email; char *error; reguser *rup; nick *sender=(nick *)source; if(cargc<3) { controlreply(sender, "SETEMAIL FALSE args"); return CMD_ERROR; } rup = findreguserbyID(atoi(cargv[0])); if(rup == NULL) { controlreply(sender, "SETEMAIL FALSE useridnotexist"); return CMD_ERROR; } if(UHasStaffPriv(rup)) { controlreply(sender, "SETEMAIL FALSE privuser"); return CMD_ERROR; } if(UHasSuspension(rup)) { controlreply(sender, "SETEMAIL FALSE suspended"); return CMD_ERROR; } if(rup->lastpasschange > atoi(cargv[1])) { controlreply(sender, "SETEMAIL FALSE passwordchanged"); return CMD_ERROR; } email = cargv[2]; if(!strcmp(email, rup->email->content)) { /* setting to the same thing? fine! */ controlreply(sender, "SETEMAIL TRUE"); return CMD_OK; } error = email_to_error(email); if(error) { controlreply(sender, "SETEMAIL FALSE %s", error); return CMD_ERROR; } freesstring(rup->email); rup->email=getsstring(email,EMAILLEN); cs_log(sender,"SETEMAIL OK username %s email %s",rup->username, rup->email->content); csdb_updateuser(rup); sendemail(rup); controlreply(sender, "SETEMAIL TRUE"); return CMD_OK; }
int lua_reloadlua(void *sender, int cargc, char **cargv) { if(cargc < 1) { controlreply((nick *)sender, "Usage: reloadlua <script>"); return CMD_ERROR; } lua_rmlua(sender, cargc, cargv); return lua_inslua(sender, cargc, cargv); }
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; }
static int fakelist(void *sender, int cargc, char **cargv) { fakeuser *fake; int fakeusercount = 0; for (fake = fakeuserlist; fake; fake = fake->next) { if (!fake->user) controlreply(sender, "%s!%s@%s (%s) - RECONNECTING", fake->nick, fake->ident, fake->host, fake->realname); else controlreply(sender, "%s!%s@%s (%s)", fake->nick, fake->ident, fake->host, fake->realname); fakeusercount++; } controlreply(sender, "%d fakeusers are currently connected", fakeusercount); return CMD_OK; }
int csa_doaddchan(void *source, int cargc, char **cargv) { nick *sender=(nick *)source; reguser *rup = getreguserfromnick(sender), *founder; chanindex *cip; short type; regchan *rcp; if(cargc<3) { controlreply(sender, "ADDCHAN FALSE args"); return CMD_ERROR; } if (*cargv[0] != '#' || strlen(cargv[0]) > CHANNELLEN) { controlreply(sender, "ADDCHAN FALSE invalidchannel"); return CMD_ERROR; } if (!(cip=findorcreatechanindex(cargv[0]))) { controlreply(sender, "ADDCHAN FALSE invalidchannel"); return CMD_ERROR; } founder = findreguserbyID(atoi(cargv[1])); if(founder == NULL) { controlreply(sender, "ADDCHAN FALSE useridnotexist"); return CMD_ERROR; } if(UIsInactive(founder)) { controlreply(sender, "ADDCHAN FALSE accountinactive"); return CMD_ERROR; } for(type=CHANTYPES-1;type;type--) if(!ircd_strcmp(chantypes[type]->content, cargv[2])) break; if(!type) { controlreply(sender, "ADDCHAN FALSE invalidchantype"); return CMD_ERROR; } rcp = cs_addchan(cip, sender, rup, founder, QCFLAG_JOINED | QCFLAG_AUTOOP | QCFLAG_BITCH | QCFLAG_FORCETOPIC | QCFLAG_PROTECT | QCFLAG_TOPICSAVE, CHANMODE_NOCTCP | CHANMODE_DELJOINS | CHANMODE_MODNOAUTH | CHANMODE_NONOTICE | CHANMODE_NOEXTMSG | CHANMODE_SINGLETARG | CHANMODE_TOPICLIMIT | CHANMODE_NOQUITMSG, 0, type); if(!rcp) { controlreply(sender, "ADDCHAN FALSE alreadyregistered"); return CMD_ERROR; } cs_log(sender, "ADDCHAN %s #%s %s %s", cip->name->content, founder->username, printflags(rcp->flags, rcflags), chantypes[type]->content); controlreply(sender, "ADDCHAN TRUE %u", rcp->ID); return CMD_OK; }
static int trusts_cmdtrustglinesuggest(void *source, int cargc, char **cargv) { nick *sender = source; char mask[512]; char *p, *user, *host; struct irc_in_addr ip; unsigned char bits; int count; glinebuf gbuf; char creator[32]; if(cargc < 1) return CMD_USAGE; strncpy(mask, cargv[0], sizeof(mask)); p = strchr(mask, '@'); if(!p) return CMD_USAGE; user = mask; host = p + 1; *p = '\0'; if(!ipmask_parse(host, &ip, &bits)) { controlreply(sender, "Invalid CIDR."); return CMD_ERROR; } snprintf(creator, sizeof(creator), "#%s", sender->authname); glinebufinit(&gbuf, 0); glinebufaddbyip(&gbuf, user, &ip, 128, 0, creator, "Simulate", getnettime(), getnettime(), getnettime()); glinebufcounthits(&gbuf, &count, NULL); glinebufspew(&gbuf, sender); glinebufabort(&gbuf); controlreply(sender, "Total hits: %d", count); return CMD_OK; }
int lua_rmlua(void *sender, int cargc, char **cargv) { nick *np = (nick *)sender; char *script = cargv[0]; lua_list *l; if(cargc < 1) { controlreply(np, "Usage: rmmod <script>"); return CMD_ERROR; } l = lua_scriptloaded(script); if(!l) { controlreply(np, "Script %s is not loaded.", script); return CMD_ERROR; } lua_unloadscript(l); controlreply(np, "Script %s unloaded.", script); return CMD_OK; }
static int fakekill(void *sender, int cargc, char **cargv) { fakeuser *fake; if (cargc == 0) return CMD_USAGE; fake = findfakeuserbynick(cargv[0]); if (!fake) { controlreply(sender, "No Fake User with nick %s found", cargv[0]); return CMD_ERROR; } controlreply(sender, "Killed fake user %s", fake->nick); controlwall(NO_OPER, NL_FAKEUSERS, "Fake user %s!%s@%s (%s) removed by %s/%s", fake->nick, fake->ident, fake->host, fake->realname, ((nick *)sender)->nick, ((nick *)sender)->authname); fake_remove(fake); return CMD_OK; }
int csa_docheckhashpass(void *source, int cargc, char **cargv) { nick *sender=(nick *)source; reguser *rup; char *flags; if(cargc<3) { controlreply(sender, "CHECKHASHPASS FAIL args"); return CMD_ERROR; } if (!(rup=findreguserbynick(cargv[0]))) { controlreply(sender, "CHECKHASHPASS FAIL user"); return CMD_OK; } flags = printflags(QUFLAG_ALL & rup->flags, ruflags); if(UHasSuspension(rup)) { controlreply(sender, "CHECKHASHPASS FAIL suspended %s %s %u", rup->username, flags, rup->ID); } else if(UIsInactive(rup)) { controlreply(sender, "CHECKHASHPASS FAIL inactive %s %s %u", rup->username, flags, rup->ID); } else if(!checkhashpass(rup, cargc<3?NULL:cargv[2], cargv[1])) { controlreply(sender, "CHECKHASHPASS FAIL digest %s %s %u", rup->username, flags, rup->ID); } else { controlreply(sender, "CHECKHASHPASS OK %s %s %u %s", rup->username, flags, rup->ID, rup->email?rup->email->content:"-"); } return CMD_OK; }
int csa_dosettempemail(void *source, int cargc, char **cargv) { char *email; char *error; reguser *rup; nick *sender=(nick *)source; if(cargc<2) { controlreply(sender, "SETTEMPEMAIL FALSE args"); return CMD_ERROR; } rup = findreguserbyID(atoi(cargv[0])); if(rup == NULL) { controlreply(sender, "SETTEMPEMAIL FALSE useridnotexist"); return CMD_ERROR; } if(!UIsInactive(rup)) { controlreply(sender, "SETTEMPEMAIL FALSE accountactive"); return CMD_ERROR; } email = cargv[1]; error = email_to_error(email); if(error) { controlreply(sender, "SETTEMPEMAIL FALSE %s", error); return CMD_ERROR; } freesstring(rup->email); rup->email=getsstring(email,EMAILLEN); cs_log(sender,"SETTEMPEMAIL OK username %s email %s",rup->username, rup->email->content); csdb_updateuser(rup); sendemail(rup); controlreply(sender, "SETTEMPEMAIL TRUE"); return CMD_OK; }
int lua_inslua(void *sender, int cargc, char **cargv) { nick *np = (nick *)sender; char *script = cargv[0]; if(cargc < 1) { controlreply(np, "Usage: inslua <script>"); return CMD_ERROR; } if(lua_scriptloaded(script)) { controlreply(np, "Script %s already loaded, or name not valid.", script); return CMD_ERROR; } if(lua_loadscript(script)) { controlreply(np, "Script %s loaded.", script); return CMD_OK; } else { controlreply(np, "Unable to load script %s.", script); return CMD_ERROR; } }
/* 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; }
int dofsck(void *source, int cargc, char **cargv) { int i,j; nick *sender=source, *np, *np2; host *hp; realname *rnp; unsigned int nickmarker; int errors=0; unsigned int nummask,mnum; /* Start off with strict nick consistency checks.. */ controlreply(sender,"- Performing nickname checks"); nickmarker=nextnickmarker(); for(i=0;i<HOSTHASHSIZE;i++) for(hp=hosttable[i];hp;hp=hp->next) hp->marker=0; for(i=0;i<REALNAMEHASHSIZE;i++) for(rnp=realnametable[i];rnp;rnp=rnp->next) rnp->marker=0; controlreply(sender," - Scanning nick hash table"); for (i=0;i<NICKHASHSIZE;i++) { for(np=nicktable[i];np;np=np->next) { if (np->marker==nickmarker) { controlreply(sender, "ERROR: bumped into the same nick %s/%s twice in hash table.",longtonumeric(np->numeric,5),np->nick); errors++; } /* Mark this nick so we can check we found them all */ np->marker=nickmarker; /* Check that we can find this nick with the lookup functions */ if (getnickbynick(np->nick) != np) { controlreply(sender, "ERROR: can't find %s/%s using getnickbynick().", longtonumeric(np->numeric,5),np->nick); errors++; } if (getnickbynumeric(np->numeric) != np) { controlreply(sender, "ERROR: can't find %s/%s using getnickbynumeric().", longtonumeric(np->numeric,5),np->nick); errors++; } /* Check that the nick appears in the list of nicks using its host */ if (findhost(np->host->name->content) != np->host) { controlreply(sender, "ERROR: can't find %s/%s's host (%s) using findhost().", longtonumeric(np->numeric,5),np->nick,np->host->name->content); errors++; } for(np2=np->host->nicks;np2;np2=np2->nextbyhost) if (np2==np) break; if (!np2) { controlreply(sender, "ERROR: can't find %s/%s (host=%s) on the host users list.", longtonumeric(np->numeric,5),np->nick,np->host->name->content); errors++; } np->host->marker++; /* Same for realnames */ if (findrealname(np->realname->name->content) != np->realname) { controlreply(sender, "ERROR: can't find %s/%s's realname (%s) using findrealname().", longtonumeric(np->numeric,5),np->nick,np->realname->name->content); errors++; } for(np2=np->realname->nicks;np2;np2=np2->nextbyrealname) if (np2==np) break; if (!np2) { controlreply(sender, "ERROR: can't find %s/%s (realname=%s) on the realname users list.", longtonumeric(np->numeric,5),np->nick,np->realname->name->content); errors++; } np->realname->marker++; if (IsAccount(np) && !np->authname[0]) { controlreply(sender, "ERROR: nick %s/%s is +r but no authname stored.", longtonumeric(np->numeric,5),np->nick); errors++; } /* if (!IsAccount(np) && np->authname[0]) { controlreply(sender, "ERROR: nick %s/%s is -r but carries authname '%s'.", longtonumeric(np->numeric,5),np->nick,np->authname); errors++; } */ if (IsSetHost(np) && (!np->sethost || !np->shident)) { controlreply(sender, "ERROR: nick %s/%s is +h but nick or hostname not set.", longtonumeric(np->numeric,5),np->nick); errors++; } if (!IsSetHost(np) && (np->sethost || np->shident)) { controlreply(sender, "ERROR: nick %s/%s is -h but has nick or hostname set.", longtonumeric(np->numeric,5),np->nick); errors++; } } } controlreply(sender," - Scanning server user tables"); for(i=0;i<MAXSERVERS;i++) { if (serverlist[i].linkstate != LS_INVALID) { nummask=((MAXSERVERS-1)<<18) | serverlist[i].maxusernum; for (j=0;j<=serverlist[i].maxusernum;j++) { if ((np=servernicks[i][j])) { mnum=(i<<18) | j; if ((np->numeric & nummask) != mnum) { controlreply(sender, "ERROR: nick %s/%s has wrong masked numeric.",longtonumeric(np->numeric,5),np->nick); errors++; } if (np->marker != nickmarker) { controlreply(sender, "ERROR: nick %s/%s in server user table but not hash!", longtonumeric(np->numeric,5),np->nick); errors++; } np->marker=0; } } } } controlreply(sender," - Scanning host and realname tables"); for (i=0;i<HOSTHASHSIZE;i++) { for (hp=hosttable[i];hp;hp=hp->next) { /* Check that the user counts match up */ if (hp->clonecount != hp->marker) { controlreply(sender, "ERROR: host %s has inconsistent clone count (stored=%d, measured=%u)", hp->name->content,hp->clonecount,hp->marker); errors++; } for (np=hp->nicks;np;np=np->nextbyhost) { if (np->host != hp) { controlreply(sender, "ERROR: nick %s/%s is in list for wrong host " "(in list for %s, actual host %s).", longtonumeric(np->numeric,5),np->nick,hp->name->content, np->host->name->content); errors++; } } hp->marker=0; } } for (i=0;i<REALNAMEHASHSIZE;i++) { for (rnp=realnametable[i];rnp;rnp=rnp->next) { if (rnp->usercount != rnp->marker) { controlreply(sender, "ERROR: realname '%s' has inconsistent clone count " "(stored=%d, measured=%d).", rnp->name->content,rnp->usercount,rnp->marker); errors++; } for (np=rnp->nicks;np;np=np->nextbyrealname) { if (np->realname != rnp) { controlreply(sender, "ERROR: nick %s/%s is in list for wrong realname " "(in list for '%s', actual realname '%s').", longtonumeric(np->numeric,5),np->nick, rnp->name->content, np->realname->name->content); errors++; } } rnp->marker=0; } } if (errors) controlreply(sender,"All checks complete. %d errors found.",errors); else controlreply(sender,"All checks complete. No errors found."); return CMD_OK; }
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); }
static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) { nick *sender = source; trustgroup *tg = NULL; int found = 0, remaining = 50; char *name; trusthost *th; struct irc_in_addr ip; unsigned char bits; int showchildren; char *cmpbuf; if(cargc < 1) return CMD_USAGE; if(strcmp(cargv[0], "-v") == 0) { if(cargc < 2) return CMD_USAGE; showchildren = 1; name = cargv[1]; } else { showchildren = 0; name = cargv[0]; } tg = tg_strtotg(name); if(tg) { displaygroup(sender, tg, showchildren); controlreply(sender, "End of list."); return CMD_OK; } if(ipmask_parse(name, &ip, &bits)) { th = th_getbyhost(&ip); if(!th) { controlreply(sender, "Specified IP address is not trusted."); return CMD_OK; } displaygroup(sender, th->group, showchildren); controlreply(sender, "End of list."); return CMD_OK; } if(name[0] == '&') { int size = strlen(name) + strlen("Qwhois") + 1; cmpbuf = alloca(size); snprintf(cmpbuf, size, "Qwhois%s", name); } else { cmpbuf = NULL; } for(tg=tglist;tg;tg=tg->next) { if(cmpbuf) { if(!tg->contact->content || strcasecmp(cmpbuf, tg->contact->content)) continue; } else if(match(name, tg->name->content)) { continue; } displaygroup(sender, tg, showchildren); if(--remaining == 0) { controlreply(sender, "Maximum number of matches reached."); return CMD_OK; } found = 1; } if(found) { controlreply(sender, "End of list."); } else { controlreply(sender, "No matches found."); } return CMD_OK; }
int csa_docreateaccount(void *source, int cargc, char **cargv) { nick *sender=(nick *)source; int execute; char *error_username = NULL, *error_password = NULL, *error_email = NULL; char *username = NULL, *password = NULL, *email = NULL; char account_info[512]; char passbuf[512]; int do_create; int activate; if(cargc<5) { controlreply(sender, "CREATEACCOUNT FALSE args"); return CMD_ERROR; } execute = cargv[0][0] == '1'; if(strcmp(cargv[1], "0")) username = cargv[1]; if(strcmp(cargv[2], "0")) email = cargv[2]; if(strcmp(cargv[3], "0")) { int errorcode = decrypt_password(createaccountsecret, KEY_BITS, passbuf, sizeof(passbuf), cargv[3]); if(errorcode) { Error("chanserv_relay",ERR_WARNING,"createaccount unable to decrypt password, error code: %d", errorcode); controlreply(sender, "CREATEACCOUNT FALSE args"); return CMD_ERROR; } password = passbuf; } activate = cargv[4][0] == '1'; if(username) { if (findreguserbynick(username)) { error_username = "******"; } else if(csa_checkaccountname_r(username)) { error_username = "******"; } } if(email) error_email = email_to_error(email); if(password) { int r = csa_checkpasswordquality(password); if(r == QM_PWTOSHORT) { error_password = "******"; } else if(r == QM_PWTOLONG) { error_password = "******"; } else if(r == QM_PWTOWEAK) { error_password = "******"; } else if(r == QM_PWINVALID) { error_password = "******"; } else if(r != -1) { error_password = "******"; } } if(execute && email && password && username && !error_email && !error_password && !error_username) { reguser *rup; do_create = 1; rup = csa_createaccount(username, password, email); if(!activate) USetInactive(rup); cs_log(sender,"CREATEACCOUNT created auth %s (%s) %s",rup->username,rup->email->content,activate?"(active)": "(inactive)"); csdb_createuser(rup); snprintf(account_info, sizeof(account_info), " %u %lu", rup->ID, (unsigned long)rup->lastpasschange); if(!activate) sendemail(rup); } else { account_info[0] = '\0'; do_create = 0; } controlreply(sender, "CREATEACCOUNT %s%s%s%s%s%s%s%s", do_create ? "TRUE" : "FALSE", account_info, email && error_email ? " " : "", email && error_email ? error_email : "", password && error_password ? " " : "", password && error_password ? error_password : "", username && error_username ? " " : "", username && error_username ? error_username : "" ); return CMD_OK; }
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; }
int settime_cmd(void *sender, int cargc, char **cargv) { controlreply(sender,"Sending Settime..."); settime_sendsettime(); controlreply(sender,"Done"); return CMD_OK; }