Esempio n. 1
0
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;
}
Esempio n. 2
0
void *match_exe(searchCtx *ctx, struct searchNode *thenode, void *theinput) {
  struct match_localdata *localdata;
  char *pattern, *target;

  localdata = thenode->localdata;
  
  pattern = (char *)(localdata->patnode->exe) (ctx, localdata->patnode, theinput);
  target  = (char *)(localdata->targnode->exe)(ctx, localdata->targnode,theinput);

  return (void *)(long)match2strings(pattern, target);
}
Esempio n. 3
0
int xsb_isservice(server *service) {
  int i;
  sstring **servicemasks;
  char *name = service->name->content;

  if(!(service->flags & SMODE_SERVICE))
    return 0;

  for(i=getservicemasks(&servicemasks)-1;i>=0;i--)
    if(match2strings(servicemasks[i]->content, name))
      return 1;

  return 0;
}
Esempio n. 4
0
void dochannellist(struct user *usr_ptr, char *ptrn)
{
  int i, j;
  int match = 0;
  char tmp[80];
  struct reggedchannel *wrk_ptr;

  if (NULL == ptrn) {
    NoticeToUser(usr_ptr, "Usage: channellist pattern");
    NoticeToUser(usr_ptr, "where  pattern is the searchpattern to match the channel name ");
    return;
  }
  for (i = 0; i < HASHMAX; i++) {
    wrk_ptr = channelhashtable[i];
    while (NULL != wrk_ptr) {

      if (match2strings(ptrn, wrk_ptr->channelname)) {
        /* match */
        if (!match) {
          NoticeToUser(usr_ptr, "channel                         added by          owner");
          NoticeToUser(usr_ptr, "-------------------------------------------------------------------------------");
        }
        match++;
        if (100 < match) {
          NoticeToUser(usr_ptr, "More than 100 results, please make a more specific search");
          return;
        }
        memset(tmp, ' ', 79);
        sprintf(tmp, "%s%n", wrk_ptr->channelname, &j);
        tmp[j] = ' ';           /* remove NULL */
        sprintf(tmp + 32, "%s%n", wrk_ptr->addedby, &j);
        tmp[j + 32] = ' ';      /* remove NULL */
        if (NULL == wrk_ptr->founder)
          sprintf(tmp + 50, "Unknown");
        else
          sprintf(tmp + 50, "%.29s", wrk_ptr->founder->authname);
        NoticeToUser(usr_ptr, "%s", tmp);
      }
      wrk_ptr = wrk_ptr->nextbychannelname;
    }
  }
  if (!match)
    NoticeToUser(usr_ptr, "Sorry no channels match %s.", ptrn);
}
Esempio n. 5
0
/* trace_server
 *   return number of matched servers
 */
static int trace_server(char *sourcenum, char *target, int doall) {

  /* do not show all and no match for my hub */
  if (!doall && !match2strings(target, serverlist[myhub].name->content))
    return 0;

  /*
   * 206 RPL_TRACESERVER "source 206 target Serv class NS NC server connected_by last_parse connected_for"
   *                     "irc.netsplit.net 206 foobar Server 2S 6C irc.netsplit.net *!user@host 34 92988"
   *
   *  note: no info available on how many servers or clients are linked through this server link -> 0S 0C
   *        no info available on who/what established the link, pretend it is by us -> *!*@myservername
   *        no info available on how long ago we last parsed something from this link -> 0
   *        no info available on how long this server has been linked -> 0
   */
  irc_send("%s 206 %s Serv servers 0S 0C %s *!*@%s 0 0", getmynumeric(), sourcenum,
    serverlist[myhub].name->content, myserver->content);

  return 1;
}
Esempio n. 6
0
void versionscan_handler(nick* me, int type, void** args) {
  nick* sender;
  Command* cmd;
  char* cargv[50];
  int cargc;
  vspattern* v;
  char* p;

  switch (type) {
  case LU_PRIVMSG:
  case LU_SECUREMSG:
    /* nick */
    sender=args[0];
    
    if (!strncmp("\001VERSION", args[1], 8)) {
      sendnoticetouser(versionscan_nick, sender, "\001VERSION QuakeNet %s v%s.\001", VS_RNDESC, VS_VERSION);
      return;
    }
    
    cargc=splitline((char*)args[1], cargv, 50, 0);
    
    cmd=findcommandintree(versionscan_commands, cargv[0], 1);
    if (!cmd) {
      sendnoticetouser(versionscan_nick, sender, "Unknown command.");
      return;
    }
    
    if ((cmd->level & VS_AUTHED) && !IsAccount(sender)) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you need to be authed to use this command.");
      return;
    }
    
    if ((cmd->level & VS_OPER) && !IsOper(sender)) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you need to be opered to use this command.");
      return;
    }
    
    if (((cmd->level & VS_STAFF) && !IsVersionscanStaff(sender)) || 
        ((cmd->level & VS_GLINE) && !IsVersionscanGlineAccess(sender)) || 
        ((cmd->level & VS_ADMIN) && !IsVersionscanAdmin(sender))) {
      sendnoticetouser(versionscan_nick, sender, "Sorry, you do not have access to this command.");
      return;
    }
    
    if (cmd->maxparams < (cargc-1)) {
      /* We need to do some rejoining */
      rejoinline(cargv[cmd->maxparams], cargc-(cmd->maxparams));
      cargc=(cmd->maxparams)+1;
    }
    
    (cmd->handler)((void*)sender, cargc-1, &(cargv[1]));
    break;
  case LU_PRIVNOTICE:
    sender=args[0];
    
    if (strncmp("\001VERSION ", args[1], 9)) {
      break;
    }
    if ((p=strchr((char *)args[1] + 9, '\001'))) {
      *p++='\0';
    }
    if (versionscan_mode == VS_SCAN) {
      if (IsOper(sender)) {
        break;
      }
      for (v=vspatterns; v; v=v->next) {
        if (match2strings(v->pattern, (char *)args[1] + 9)) {
          v->hitcount++;
          hcount++;
          switch (v->action) {
          case VS_WARN:
            sendnoticetouser(versionscan_nick, sender, "%s", v->data);
            wcount++;
            break;
          case VS_KILL:
            killuser(versionscan_nick, sender, "%s", v->data);
            kcount++;
            break;
          case VS_GLUSER:
            glinebynick(sender, 3600, v->data, GLINE_ALWAYS_USER, "versionscan");
            gcount++;
            break;
          case VS_GLHOST:
            glinebynick(sender, 3600, v->data, 0, "versionscan");
            gcount++;
            break;
          default:
            /* oh dear, something's f****d */
            break;
          }
         break;
        }
      }
    }
    else if (versionscan_mode == VS_STAT) {
      versionscan_addstat((char *)args[1] + 9);
    }
    break;
  case LU_KILLED:
    versionscan_nick=NULL;
    scheduleoneshot(time(NULL)+1, &versionscan_createfakeuser, NULL);
    break;
  }
}
Esempio n. 7
0
/* handle remote trace request
 *
 * <source numeric> TRACE/TR <target> <target server numeric>
 *
 * cargv[0] = target
 *            as given by source, can be a nick or a server (may contain wildcards)
 * cargv[1] = target server numeric
 * 
 */
int handletracemsg(void *source, int cargc, char **cargv) {

  nick *snick;                        /* struct nick for source nick */
  nick *tnick;                        /* struct nick for target nick */
  nick **lnick;                       /* struct nick for looping local users */
  int c;                              /* loop variable */
  int opers = 0;                      /* number of operators */
  int users = 0;                      /* number of users */
  int servers = 0;                    /* number of servers */
  int doall, wilds, dow;              /* determine what to show */
  char *sourcenum = (char *)source;   /* source user numeric */
  char *target;                       /* target parameter - as given by the source user */


  /* check parameters */
  if (cargc < 2) {
    miscreply_needmoreparams(sourcenum, "TRACE");
    return CMD_OK;
  }

  /* get the parameters */
  target = cargv[0];

  /* find source user */ 
  if (!(snick = miscreply_finduser(sourcenum, "TRACE")))
    return CMD_OK;

  /* doall, wilds, dow */
  doall = match2strings(target, myserver->content);
  wilds = strchr(target, '*') || strchr(target, '?');
  dow = wilds || doall;


  /* find target user */
  if ((tnick = getnickbynick(target))) {

    /* my user */
    if (mylongnum == homeserver(tnick->numeric))
      trace_user(sourcenum, tnick);
  }


  /* source user is an operator */
  else if (IsOper(snick)) {

    /* show servers */
    servers = trace_server(sourcenum, target, doall);

    /* do all or wilds */
    if (dow) {

      /* loop over all local users */
      lnick = servernicks[mylongnum];
      for (c = 0; c < serverlist[mylongnum].maxusernum; c++) {

        if (lnick[c] == NULL)   /* no user */
          continue;

        /* target is invisible (mode +i), target is not an operator */
        if (IsInvisible(lnick[c]) && dow && !IsOper(lnick[c]))
          continue;

        /* dont show all, do wildcards and no match */
        if (!doall && wilds && !match2strings(target, lnick[c]->nick))
          continue;

        if (IsOper(lnick[c]))
          opers++;
        else
          users++;
        trace_user(sourcenum, lnick[c]);
      }
      /*
       * class has no meaning here,
       * but showing the total count for users/opers/servers might be useful anyway
       *
       * 209 RPL_TRACECLASS "source 209 target Class class count"
       *                    "irc.netsplit.net 209 foobar Class users 2"
       */
      if (users)
        irc_send("%s 209 %s Class users %d", getmynumeric(), sourcenum, users);
      if (opers)
        irc_send("%s 209 %s Class opers %d", getmynumeric(), sourcenum, opers);
      if (servers)
        irc_send("%s 209 %s Class servers %d", getmynumeric(), sourcenum, servers);
    }
  }


  /*
   * 262 RPL_TRACEEND "source 262 target :End of TRACE"
   *                  "irc.netsplit.net 262 foobar :End of TRACE"
   */
  irc_send("%s 262 %s :End of TRACE", getmynumeric(), sourcenum);

  return CMD_OK;
}
Esempio 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);
}
Esempio 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);
}
Esempio 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);
}