Ejemplo n.º 1
0
void _init(void) {
  const char **p;
  array *servicemasks;

  controlnum[0] = '\0';
  
  cmds = newcommandtree();
  if(!cmds)
    return;
  
  registerhook(HOOK_NICK_MASKPRIVMSG, &handlemaskprivmsg);
  registerhook(HOOK_CONTROL_REGISTERED, &handlecontrolregistered);
  
  array_init(&defaultservicemasks_a, sizeof(sstring *));

  for(p=DEFAULT_SERVICE_MASKS;*p;p++) {
    int i = array_getfreeslot(&defaultservicemasks_a);
    defaultservicemasks = (sstring **)defaultservicemasks_a.content;

    defaultservicemasks[i] = getsstring(*p, strlen(*p));
  }

  servicemasks = getconfigitems("xsb", "servicemask");
  if(!servicemasks || !servicemasks->cursi)
    Error("xsb", ERR_WARNING, "No service masks in config file (xsb/servicemask), using defaults.");
}
Ejemplo n.º 2
0
void sp_addsplit(const char *name, time_t ts, flag_t type) {
  int slot;
  splitserver *srv;

  slot = array_getfreeslot(&splitlist);

  srv = &(((splitserver*)splitlist.content)[slot]);

  srv->name = getsstring(name, HOSTLEN);
  srv->ts = ts;
  srv->type = type;
}
Ejemplo n.º 3
0
void dotrustungline(long unum, char *tail) {
  int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE];
  trustedgroup *tg; trustedhost *th; int i; array listofths;
  res=sscanf(tail, "%s %s %s",tmps2,tmps3,tmps4);
  if (res<3) {
    msgtouser(unum,"Syntax: trustungline <groupname OR #groupID> user");
    msgtouser(unum,"user may contain wildcards");
    return;
  }
  tmps4[USERLEN+2]='\0';
  toLowerCase(tmps3); toLowerCase(tmps4);
  if (tmps3[0]=='#') {
    tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10));
  } else {
    tg=findtrustgroupbyname(tmps3);
  }
  if (tg==NULL) {
    sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name");
    msgtouser(unum,tmps2); return;
  }
  /* First, create a list of all hosts in that trustgroup... */
  array_init(&listofths,sizeof(unsigned long));
  for (i=0;i<SIZEOFTL;i++) {
    th=trustedhosts[i];
    while (th!=NULL) {
      if (th->id==tg->id) { /* mmkay, that one belongs to our group */
        long j;
        j=array_getfreeslot(&listofths);
        ((unsigned long *)listofths.content)[j]=th->IPv4;
      }
      th=(void *)th->next;
    }
  }
  if (listofths.cursi==0) {
    msgtouser(unum,"There are no hosts in that trustgroup.");
    array_free(&listofths);
    return;
  }
  /* starting ungline.. */
  for (i=0;i<listofths.cursi;i++) {
    char * mycip;
    mycip=printipv4(((unsigned long *)listofths.content)[i]);
    sprintf(tmps2,"%s@%s",tmps4,mycip);
    free(mycip);
    remgline(tmps2,1);
  }
  numtonick(unum,tmps5);
  sprintf(tmps2,"Removed GLINE for %s @ trustgroup %s (#%lu)",tmps4,tg->name,tg->id);
  msgtouser(unum,tmps2);
  sprintf(tmps2,"GLINE %s @ trustgroup %s (#%lu) removed by %s",tmps4, tg->name,tg->id,tmps5);
  sendtonoticemask(NM_GLINE,tmps2);
  array_free(&listofths);
}
Ejemplo n.º 4
0
static void insertth(array *parents, trusthost *th) {
  int i;
  trusthost **p2 = (trusthost **)(parents->content);

  /* this eliminates common subtrees */
  for(i=0;i<parents->cursi;i++)
    if(p2[i] == th)
      break;

  if(i == parents->cursi) {
    int pos = array_getfreeslot(parents);
    ((trusthost **)(parents->content))[pos] = th;
  }
}
Ejemplo n.º 5
0
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 (!np || !(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);
}
Ejemplo n.º 6
0
int insmod(char *modulename) {
  int i;
  module *mods;
  char buf[1024], modulebuf[1024];
  const char *(*verinfo)(const char **);
  struct module_dep *mdp;

  strlcpy(modulebuf, modulename, sizeof(modulebuf));
  delchars(modulebuf,"./\\;");
  
  if (isloaded(modulebuf)) {
    Error("core",ERR_DEBUG,"Tried to load already loaded module: %s",modulebuf);
    return 1;
  }
  
  if (strlen(modulebuf)>100) {
    Error("core",ERR_WARNING,"Module name too long: %s",modulebuf);  
    return 1;
  }

  if ((mdp=getmoduledep(modulebuf))) {
    for (i=0;i<mdp->numparents;i++) {
      if (!isloaded(mdp->parents[i]->name->content)) {
        if (insmod(mdp->parents[i]->name->content)) {
          Error("core",ERR_WARNING,"Error loading dependant module %s (needed by %s)",
                   mdp->parents[i]->name->content,modulebuf);
          return 1;
        }
      }
    }
  } else {
    Error("core",ERR_WARNING,"Loading module %s without dependency information.",modulebuf);
  }

  i=array_getfreeslot(&modules);
  mods=(module *)(modules.content);

  sprintf(buf,"%s/%s%s",moddir->content,modulebuf,modsuffix->content);
  
  mods[i].handle=dlopen(buf,RTLD_NOW|RTLD_GLOBAL);
  
  if(mods[i].handle==NULL) {
    Error("core",ERR_ERROR,"Loading module %s failed: %s",modulebuf,dlerror());
    array_delslot(&modules,i);
    return -1;
  }

  mods[i].name=getsstring(modulebuf,MODULENAMELEN);

  verinfo=dlsym(mods[i].handle,"_version");
  if(verinfo) {
    mods[i].buildid=verinfo(&mods[i].version);
  } else {
    mods[i].version=NULL;
    mods[i].buildid=NULL;
  }

  mods[i].loadedsince = time(NULL);
  Error("core",ERR_INFO,"Loaded module %s OK.",modulebuf);
  
  return 0;
}
Ejemplo n.º 7
0
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.");
}
Ejemplo n.º 8
0
void dotrustspew(long unum, char *tail) {
  int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE];
  trustedgroup *tg; trustedhost *th; int i; userdata *ud; long k, l;
  array listofths; int iamtired;
  res=sscanf(tail, "%s %s %s",tmps2,tmps3,tmps4);
  if (res<2) {
    msgtouser(unum,"Syntax: trustspew <groupname OR #groupID> [user]");
    return;
  }
  if (res==2) { strcpy(tmps4,"*"); }
  tmps4[USERLEN+2]='\0';
  toLowerCase(tmps3); toLowerCase(tmps4);
  if (tmps3[0]=='#') {
    tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10));
  } else {
    tg=findtrustgroupbyname(tmps3);
  }
  if (tg==NULL) {
    sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name");
    msgtouser(unum,tmps2); return;
  }
  /* First, create a list of all hosts in that trustgroup... */
  array_init(&listofths,sizeof(unsigned long));
  for (i=0;i<SIZEOFTL;i++) {
    th=trustedhosts[i];
    while (th!=NULL) {
      if (th->id==tg->id) { /* mmkay, that one belongs to our group */
        long j;
        j=array_getfreeslot(&listofths);
        ((unsigned long *)listofths.content)[j]=th->IPv4;
      }
      th=(void *)th->next;
    }
  }
  if (listofths.cursi==0) {
    msgtouser(unum,"There are no hosts in that trustgroup.");
    array_free(&listofths);
    return;
  }
  /* We have the list - scan through the whole userlist, and match against our
     hostlist, and if that matches, match again against the username */
  sprintf(tmps2,"Users in Trustgroup %s (#%lu) matching %s",tg->name,tg->id,tmps4);
  msgtouser(unum,tmps2);
  l=0;
  for (i=0;i<SIZEOFUL;i++) {
    ud=uls[i];
    while (ud!=NULL) {
      for (k=0;k<listofths.cursi;k++) {
        if (((unsigned long *)listofths.content)[k]==ud->realip) {
          /* Host matches, check username */
          strcpy(tmps5,ud->ident);
          toLowerCase(tmps5);
          if (match2strings(tmps4,tmps5)) {
            /* yay ident matches too - list that loser */
            channel **d; int chanmodes; char * mycip;
            l++; /* inc counter of number of users found */
            mycip=printipv4(ud->realip);
            sprintf(tmps2,"%s!%s@%s(=%s) (%s)",ud->nick,ud->ident,ud->host,mycip,ud->realname);
            msgtouser(unum,tmps2);
            if (ud->chans.cursi>0) {
              if (ud->chans.cursi==1) {
                strcpy(tmps2,"On channel:");
              } else {
                strcpy(tmps2,"On channels:");
              }
              for (iamtired=0;iamtired<(ud->chans.cursi);iamtired++) {
                d=(channel **)(ud->chans.content);
                if ((strlen(d[iamtired]->name)+strlen(tmps2))>400) {
                  strcat(tmps2," [...]"); break;
                } else {
                  chanmodes=getchanmode2(d[iamtired],ud->numeric);
                  strcat(tmps2," ");
                  if (chanmodes<0) {
                    strcat(tmps2,"?");
                  } else {
                    if (isflagset(chanmodes,um_o)) { strcat(tmps2,"@"); } else { strcat(tmps2," "); }
                  }
                  strcat(tmps2,d[iamtired]->name);
                }
              }
            } else {
              strcpy(tmps2,"Not on any (nonlocal-)channels");
            }
            msgtouser(unum,tmps2);
          }
        }
      }
      ud=(void *)ud->next;
    }
  }
  sprintf(tmps2,"--- End of list - %ld matches ---",l);
  msgtouser(unum,tmps2);
  array_free(&listofths);
}
Ejemplo n.º 9
0
void dotrustgline(long unum, char *tail) {
  int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE], tmps5[TMPSSIZE];
  char tmps6[TMPSSIZE]; long r2; userdata *a;
  trustedgroup *tg; trustedhost *th; int i, j; long l; array listofths;
  res=sscanf(tail, "%s %s %s %s %[^\n]",tmps2,tmps3,tmps4,tmps5,tmps6);
  if (res<4) {
    msgtouser(unum,"Syntax: trustgline <groupname OR #groupID> user duration [reason]");
    msgtouser(unum,"user may contain wildcards");
    return;
  }
  if (res==4) {
    numtonick(unum,tmps2);
    sprintf(tmps6,"requested by %s",tmps2);
  }
  tmps4[USERLEN+2]='\0';
  toLowerCase(tmps3); toLowerCase(tmps4);
  r2=durationtolong(tmps5);
  if (r2<=0) {
    sprintf(tmps2,"The duration you gave is invalid.");
    msgtouser(unum,tmps2);
    return;
  }
  if (tmps3[0]=='#') {
    tg=findtrustgroupbyID(strtol(&tmps3[1],NULL,10));
  } else {
    tg=findtrustgroupbyname(tmps3);
  }
  if (tg==NULL) {
    sprintf(tmps2,"A trustgroup with that %s does not exist.",(tmps3[0]=='#') ? "ID" : "name");
    msgtouser(unum,tmps2); return;
  }
  /* First, create a list of all hosts in that trustgroup... */
  array_init(&listofths,sizeof(unsigned long));
  for (i=0;i<SIZEOFTL;i++) {
    th=trustedhosts[i];
    while (th!=NULL) {
      if (th->id==tg->id) { /* mmkay, that one belongs to our group */
        long j;
        j=array_getfreeslot(&listofths);
        ((unsigned long *)listofths.content)[j]=th->IPv4;
      }
      th=th->next;
    }
  }
  if (listofths.cursi==0) {
    msgtouser(unum,"There are no hosts in that trustgroup.");
    array_free(&listofths);
    return;
  }
  /* Now that we have the list: count number of users hit */
  l=0;
  for (j=0;j<SIZEOFUL;j++) {
    a=uls[j];
    while (a!=NULL) {
      char tmpu[USERLEN+1];
      strcpy(tmpu,a->ident);
      toLowerCase(tmpu);
      for (i=0;i<listofths.cursi;i++) {
        unsigned long *bla;
        bla=(unsigned long *)listofths.content;
        if (bla[i]==a->realip) {
          if (match2strings(tmps4,tmpu)) {
            l++; break;
          }
        }
      }
      a=(void *)a->next;
    }
  }
  if (l>GLINEMAXHIT) {
    newmsgtouser(unum,"That gline would hit more than %d (%d) Users/Channels. You probably mistyped something.",GLINEMAXHIT,l);
    if ((l<(GLINEMAXHIT*10)) && (getauthlevel(unum)>=999)) {
      msgtouser(unum,"However, your authlevel is >=999, so I hope you know what you're doing... Executing command.");
    } else {
      array_free(&listofths); return;
    }
  }
  /* OK, safety checks done - now gline the fuckers */
  numtonick(unum,tmps5);
  for (i=0;i<listofths.cursi;i++) {
    unsigned long *bla; char * mycip;
    bla=(unsigned long *)listofths.content;
    mycip=printipv4(bla[i]);
    sprintf(tmps2,"%s@%s",tmps4,mycip);
    free(mycip);
    addgline(tmps2,tmps6,tmps5,r2,1);
  }
  sprintf(tmps2,"Added GLINE for %s @ trustgroup %s (#%lu), caused %lu glines, hit %ld users",tmps4,tg->name,tg->id,
    listofths.cursi,l);
  msgtouser(unum,tmps2);
  sprintf(tmps2,"GLINE %s @ trustgroup %s (#%lu) by %s, caused %lu glines, hit %ld users",tmps4,
    tg->name,tg->id,tmps5,listofths.cursi,l);
  sendtonoticemask(NM_GLINE,tmps2);
  array_free(&listofths);
}
Ejemplo n.º 10
0
void dotrustlist(long unum, char *tail) {
  int res; char tmps2[TMPSSIZE], tmps3[TMPSSIZE], tmps4[TMPSSIZE];
  array listofids; long i; trustedgroup *tg; trustedhost *th; long j;
  unsigned long lastshown, showid; unsigned long numshown=0;
  char tmps5[TMPSSIZE]; unsigned int showhosts=65000;
  res=sscanf(tail,"%s %s %s",tmps2,tmps3,tmps4);
  if (res>3) {
    msgtouser(unum,"Syntax: trustlist [-h] [pattern]");
    return;
  }
  if (res>=2) {
    toLowerCase(tmps3);
    if (strcmp(tmps3,"-h")==0) {
      showhosts=0;
      if (res<3) {
        strcpy(tmps3,"*");
      } else {
        strcpy(tmps3,tmps4);
      }
    } else {
      if (res==3) {
        msgtouser(unum,"Invalid parameter");
        return;
      }
    }
  }
  if (res==1) { strcpy(tmps3,"*"); }
  toLowerCase(tmps3);
  trustgroupexpire();
  if (tmps3[0]=='#') {
    if ((!ischarinstr('*',tmps3)) && (!ischarinstr('?',tmps3))) {
      newmsgtouser(unum,"Searching trustgroup with ID %lu...",strtoul(&tmps3[1],NULL,10));
      numshown=displaytrustgroupwithid(unum,strtoul(&tmps3[1],NULL,10),showhosts);
      if (numshown==0) {
        msgtouser(unum,"A trustgroup with that ID does not exist.");
      }
      return;
    }
  }
  array_init(&listofids,sizeof(unsigned long));
  for (i=0;i<SIZEOFIDMAP;i++) {
    tg=trustedgroups[i];
    while (tg!=NULL) {
      strcpy(tmps4,tg->name); toLowerCase(tmps4);
      sprintf(tmps5,"#%lu",tg->id);
      if ((match2strings(tmps3,tmps4)) || (match2strings(tmps3,tmps5))) {
        j=array_getfreeslot(&listofids);
        ((unsigned long *)listofids.content)[j]=tg->id;
      }
      tg=(void *)tg->next;
    }
  }
  for (i=0;i<SIZEOFTL;i++) {
    th=trustedhosts[i];
    while (th!=NULL) {
      char * mycip=printipv4(th->IPv4);
      if (match2strings(tmps3,mycip)) {
        j=array_getfreeslot(&listofids);
        ((unsigned long *)listofids.content)[j]=th->id;
      }
      free(mycip);
      th=(void *)th->next;
    }
  }
  if (listofids.cursi==0) {
    msgtouser(unum,"No matches.");
    array_free(&listofids);
    return;
  }
  qsort(listofids.content, listofids.cursi, sizeof(unsigned long), trustlistsorthelper);
  lastshown=0;
  for (i=0;i<listofids.cursi;i++) {
    showid=((unsigned long *)(listofids.content))[i];
    if (showid!=lastshown) {
      lastshown=showid;
      numshown+=displaytrustgroupwithid(unum,showid,showhosts);
      if (numshown>500) {
        newmsgtouser(unum,"More than 500 lines (%lu) already shown - aborting now.",numshown);
        break;
      }
    }
  }
  array_free(&listofids);
  newmsgtouser(unum,"--- End of list - %lu lines returned from query ---",numshown);
}