Пример #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
unsigned long displaytrustgroupwithid(long unum, unsigned long showid, unsigned int showhosts) {
  long i; trustedhost *th; trustedgroup *tg; char tmps2[TMPSSIZE], tmps3[TMPSSIZE]; char * mycip;
  unsigned long linesshown=0;
  tg=findtrustgroupbyID(showid);
  if (tg==NULL) { return linesshown; }
  newmsgtouser(unum,"Trustgroup '%s' (ID #%lu) last changed by %s - currently online: %d",tg->name,tg->id,tg->creator,tg->currentlyon);
  longtoduration(tmps3,tg->expires - getnettime());
  newmsgtouser(unum,"Settings: Enforcing ident: %s - trusted for %d - %d per user - expires in %s",
    (tg->enforceident == 1) ? "yes" : "no ", tg->trustedfor, tg->maxperident, tmps3);
  newmsgtouser(unum,"Contact: %s - Comment: %s",tg->contact,tg->comment);
  longtoduration(tmps3,(getnettime() - tg->lastused)); strcat(tmps3," ago");
  longtoduration(tmps2,(getnettime() - tg->maxreset)); strcat(tmps2," ago");
  newmsgtouser(unum,"Last used: %s - Max usage: %lu - Last Maxuse reset: %s",
    (tg->currentlyon>0) ? "now" : ((tg->lastused==0) ? "never" : tmps3), tg->maxused, (tg->maxreset==0) ? "never" : tmps2);
  if (showhosts==0) { return 4; }
  tmps2[0]=0; linesshown=4;
  for (i=0;i<SIZEOFTL;i++) {
    th=trustedhosts[i];
    while (th!=NULL) {
      if (th->id==showid) {
        longtoduration(tmps3,(getnettime() - th->lastused)); strcat(tmps3," ago");
        mycip=printipv4(th->IPv4);
        if (tmps2[0]==0) {
          sprintf(tmps2,"%s (Cur: %lu Max: %lu Last: %s)",mycip,
            th->currentlyon,th->maxused,(th->currentlyon>0) ? "now" : ((th->lastused==0) ? "never" : tmps3));
        } else {
          newmsgtouser(unum,"|-%s",tmps2);
          linesshown++;
          sprintf(tmps2,"%s (Cur: %lu Max: %lu Last: %s)",mycip,
            th->currentlyon,th->maxused,(th->currentlyon>0) ? "now" : ((th->lastused==0) ? "never" : tmps3));
        }
        free(mycip);
      }
      th=(void *)th->next;
    }
  }
  if (tmps2[0]==0) {
    msgtouser(unum,"`- no hosts in that group");
  } else {
    newmsgtouser(unum,"`-%s",tmps2);
  }
  linesshown++;
  return linesshown;
}
Пример #3
0
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;
}
Пример #4
0
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);
  }
}
Пример #5
0
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);
}
Пример #6
0
/* 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;
}
Пример #7
0
void gline_free(searchCtx *ctx, struct searchNode *thenode) {
  struct gline_localdata *localdata;
  nick *np, *nnp;
  chanindex *cip, *ncip;
  whowas *ww;
  int i, j, hits, safe=0;
  time_t ti = time(NULL);
  glinebuf gbuf;

  localdata = thenode->localdata;

  if (localdata->count > NSMAX_GLINE_LIMIT) {
    /* need to warn the user that they have just tried to twat half the network ... */
    ctx->reply(senderNSExtern, "Warning: your pattern matches too many users (%d) - nothing done.", localdata->count);
    free(localdata);
    free(thenode);
    return;
  }

  glinebufinit(&gbuf, 0);

  if (ctx->searchcmd == reg_chansearch) {
    for (i=0;i<CHANNELHASHSIZE;i++) {
      for (cip=chantable[i];cip;cip=ncip) {
        ncip = cip->next;
        if (cip != NULL && cip->channel != NULL && cip->marker == localdata->marker) {
          for (j=0;j<cip->channel->users->hashsize;j++) {
            if (cip->channel->users->content[j]==nouser)
              continue;
    
            if ((np=getnickbynumeric(cip->channel->users->content[j]))) {
              if(!glineuser(&gbuf, np, localdata, ti))
                safe++;
            }
          }
        }
      }
    }
  } else if (ctx->searchcmd == reg_nicksearch) {
    for (i=0;i<NICKHASHSIZE;i++) {
      for (np=nicktable[i];np;np=nnp) {
        nnp = np->next;
        if (np->marker == localdata->marker) {
          if(!glineuser(&gbuf, np, localdata, ti))
            safe++;
        }
      }
    }
  } else {
    for (i = whowasoffset; i < whowasoffset + whowasmax; i++) {
      ww = &whowasrecs[i % whowasmax];

      if (ww->type == WHOWAS_UNUSED)
        continue;

      if (ww->marker == localdata->marker) {
        if(!glineuser(&gbuf, &ww->nick, localdata, ti))
          safe++;
      }
    }
  }

  glinebufcounthits(&gbuf, &hits, NULL);
  glinebufcommit(&gbuf, 1);

  if (safe)
    ctx->reply(senderNSExtern, "Warning: your pattern matched privileged users (%d in total) - these have not been touched.", safe);
  /* notify opers of the action */
  ctx->wall(NL_GLINES, "%s/%s glined %d %s via %s for %s [%d untouched].", senderNSExtern->nick, senderNSExtern->authname, (localdata->count - safe), 
    (localdata->count - safe) != 1 ? "users" : "user", (ctx->searchcmd == reg_chansearch) ? "chansearch" : "nicksearch", longtoduration(localdata->duration, 1), safe);
  free(localdata);
  free(thenode);
}
Пример #8
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.");
}
Пример #9
0
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;
}