示例#1
0
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;
}
示例#2
0
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;
}
示例#3
0
struct searchNode *gline_parse(searchCtx *ctx, int argc, char **argv) {
  struct gline_localdata *localdata;
  struct searchNode *thenode;

  if (!(localdata = (struct gline_localdata *) malloc(sizeof(struct gline_localdata)))) {
    parseError = "malloc: could not allocate memory for this search.";
    return NULL;
  }
  localdata->count = 0;
  if (ctx->searchcmd == reg_chansearch)
    localdata->marker = nextchanmarker();
  else if (ctx->searchcmd == reg_nicksearch)
    localdata->marker = nextnickmarker();
  else if (ctx->searchcmd == reg_whowassearch)
    localdata->marker = nextwhowasmarker();
  else {
    free(localdata);
    parseError = "gline: invalid search type";
    return NULL;
  }

  /* default duration, default reason */
  if(argc == 0) {
    localdata->duration = NSGLINE_DURATION;
    strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason));
  } else if(argc > 2) {
    free(localdata);
    parseError = "gline: invalid number of arguments";
    return NULL;
  } else {
    char *argzerop, *reasonp, *durationp;
    struct searchNode *durationsn, *reasonsn, *argzerosn;
    
    if (!(argzerosn=argtoconststr("gline", ctx, argv[0], &argzerop))) {
      free(localdata);
      return NULL;
    }

    if(argc == 1) {
      durationp = reasonp = NULL;
      durationsn = reasonsn = NULL;
      
      /* if we have a space it's a reason */
      if(strchr(argzerop, ' ')) {
        reasonsn = argzerosn;
        reasonp = argzerop;
      } else {
        durationsn = argzerosn;
        durationp = argzerop;
      }
    } else {
      durationsn = argzerosn;
      durationp = argzerop;
      
      if (!(reasonsn=argtoconststr("gline", ctx, argv[1], &reasonp))) {
        durationsn->free(ctx, durationsn);
        free(localdata);
        return NULL;
      }      
    }
    
    if(!reasonp) {
      strlcpy(localdata->reason, defaultreason, sizeof(localdata->reason));
    } else {
      strlcpy(localdata->reason, reasonp, sizeof(localdata->reason));
      reasonsn->free(ctx, reasonsn);
    }

    if(!durationp) {
      localdata->duration = NSGLINE_DURATION;
    } else {
      localdata->duration = durationtolong(durationp);
      durationsn->free(ctx, durationsn);
      
      if (localdata->duration == 0) {
        parseError = "gline duration invalid.";
        free(localdata);
        return NULL;
      }
    }
  }

  if (!(thenode=(struct searchNode *)malloc(sizeof (struct searchNode)))) {
    /* couldn't malloc() memory for thenode, so free localdata to avoid leakage */
    parseError = "malloc: could not allocate memory for this search.";
    free(localdata);
    return NULL;
  }

  thenode->returntype = RETURNTYPE_BOOL;
  thenode->localdata = localdata;
  thenode->exe = gline_exe;
  thenode->free = gline_free;

  return thenode;
}
示例#4
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.");
}
示例#5
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);
}
示例#6
0
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);
}
示例#7
0
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);
}