Пример #1
0
static int cmd_onwire(struct userrec *u, int idx, char *par)
{
  wire_list *w, *w2;
  char wiretmp[512], wirecmd[512], idxtmp[512];
  char idle[20], *enctmp;
  time_t now2 = now;

  w = wirelist;
  while (w) {
    if (w->sock == dcc[idx].sock)
      break;
    w = w->next;
  }
  if (!w) {
    dprintf(idx, "%s\n", WIRE_NOTONWIRE);
    return 0;
  }
  dprintf(idx, "----- %s '%s':\n", WIRE_CURRENTLYON, w->key);
  dprintf(idx, "----- Nick       Bot        Host\n");
  dprintf(idx, "----- ---------- ---------- ------------------------------\n");
  enctmp = encrypt_string(w->key, "wire");
  sprintf(wirecmd, "!wire%s", enctmp);
  nfree(enctmp);
  enctmp = encrypt_string(w->key, dcc[idx].nick);
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  simple_sprintf(idxtmp, "!wirereq %d %s", dcc[idx].sock, wiretmp);
  botnet_send_zapf_broad(-1, botnetnick, wirecmd, idxtmp);
  w2 = wirelist;
  while (w2) {
    if (!strcmp(w2->key, w->key)) {
      int idx2 = findanyidx(w2->sock);

      if (now2 - dcc[idx2].timeval > 300) {
        unsigned long Days, hrs, mins;

        Days = (now2 - dcc[idx2].timeval) / 86400;
        hrs = ((now2 - dcc[idx2].timeval) - (Days * 86400)) / 3600;
        mins = ((now2 - dcc[idx2].timeval) - (hrs * 3600)) / 60;
        if (Days > 0)
          sprintf(idle, " [%s %lud%luh]", WIRE_IDLE, Days, hrs);
        else if (hrs > 0)
          sprintf(idle, " [%s %luh%lum]", WIRE_IDLE, hrs, mins);
        else
          sprintf(idle, " [%s %lum]", WIRE_IDLE, mins);
      } else
        idle[0] = 0;
      dprintf(idx, "----- %c%-9s %-9s  %s%s\n",
              geticon(idx2), dcc[idx2].nick, botnetnick, dcc[idx2].host, idle);
      if (dcc[idx2].u.chat->away)
        dprintf(idx, "-----    %s: %s\n", WIRE_AWAY, dcc[idx2].u.chat->away);
    }
    w2 = w2->next;
  }
  return 0;
}
Пример #2
0
static int tcl_putallbots(ClientData cd, Tcl_Interp *irp,
                          int argc, char *argv[])
{
  char msg[401];

  BADARGS(2, 2, " message");

  strncpyz(msg, argv[1], sizeof msg);
  botnet_send_zapf_broad(-1, botnetnick, NULL, msg);
  return TCL_OK;
}
Пример #3
0
/* Used to send a global msg from Tcl on one bot to every other bot
 * zapf-broad <frombot> <code [param]>
 */
static void bot_zapfbroad(int idx, char *par)
{
  char *from = NULL, *opcode = NULL;
  int i;

  from = newsplit(&par);
  opcode = newsplit(&par);

  i = nextbot(from);
  if (i != idx) {
    fake_alert(idx, "direction", from, "zapfb");
    return;
  }
  check_bind_bot(from, opcode, par);
  botnet_send_zapf_broad(idx, from, opcode, par);
}
Пример #4
0
static char *cmd_putwire(int idx, char *message)
{
  wire_list *w = wirelist;
  wire_list *w2 = wirelist;
  int wiretype;
  char wirecmd[512];
  char wiremsg[512];
  char wiretmp[512];
  char wiretmp2[512];
  char *enctmp;

  while (w) {
    if (w->sock == dcc[idx].sock)
      break;
    w = w->next;
  }
  if (!w)
    return "";
  if (!message[1])
    return "";
  if ((strlen(message) > 3) && !strncmp(&message[1], "me", 2) &&
      (message[3] == ' ')) {
    sprintf(wiretmp2, "!%s@%s", dcc[idx].nick, botnetnick);
    enctmp = encrypt_string(w->key, &message[3]);
    wiretype = 1;
  } else {
    sprintf(wiretmp2, "%s@%s", dcc[idx].nick, botnetnick);
    enctmp = encrypt_string(w->key, &message[1]);
    wiretype = 0;
  }
  strcpy(wiremsg, enctmp);
  nfree(enctmp);
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  sprintf(wirecmd, "!wire%s", wiretmp);
  sprintf(wiretmp, "%s %s", wiretmp2, wiremsg);
  botnet_send_zapf_broad(-1, botnetnick, wirecmd, wiretmp);
  sprintf(wiretmp, "%s%s", wiretype ? "!" : "", dcc[findanyidx(w->sock)].nick);
  while (w2) {
    if (!strcmp(w2->key, w->key))
      wire_display(findanyidx(w2->sock), w2->key, wiretmp, wiremsg);
    w2 = w2->next;
  }
  return "";
}
Пример #5
0
static void wire_leave(int sock)
{
  char wirecmd[513];
  char wiremsg[513];
  char wiretmp[513];
  char *enctmp;
  wire_list *w = wirelist;
  wire_list *w2 = wirelist;
  wire_list *wlast = wirelist;

  while (w) {
    if (w->sock == sock)
      break;
    w = w->next;
  }
  if (!w)
    return;
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wirecmd, enctmp);
  nfree(enctmp);
  sprintf(wiretmp, "%s left the wire.", dcc[findanyidx(w->sock)].nick);
  enctmp = encrypt_string(w->key, wiretmp);
  strcpy(wiremsg, enctmp);
  nfree(enctmp);
  {
    char x[1024];

    simple_sprintf(x, "!wire%s %s", wirecmd, botnetnick);
    botnet_send_zapf_broad(-1, botnetnick, x, wiremsg);
  }
  w2 = wirelist;
  while (w2) {
    if (w2->sock != sock && !strcmp(w2->key, w->key)) {
      dprintf(findanyidx(w2->sock), "----- %s %s\n",
              dcc[findanyidx(w->sock)].nick, WIRE_LEFT);
    }
    w2 = w2->next;
  }
  /* Check to see if someone else is using this wire key.
   * If so, then don't remove the wire filter binding.
   */
  w2 = wirelist;
  while (w2) {
    if (w2 != w && !strcmp(w2->key, w->key))
      break;
    w2 = w2->next;
  }
  if (!w2) {                    /* Someone else is NOT using this key */
    wire_bot[0].name = wirecmd;
    wire_bot[0].flags = "";
    wire_bot[0].func = (IntFunc) wire_filter;
    rem_builtins(H_bot, wire_bot);
  }
  w2 = wirelist;
  wlast = 0;
  while (w2) {
    if (w2 == w)
      break;
    wlast = w2;
    w2 = w2->next;
  }
  if (wlast) {
    if (w->next)
      wlast->next = w->next;
    else
      wlast->next = 0;
  } else if (!w->next)
    wirelist = 0;
  else
    wirelist = w->next;
  nfree(w->crypt);
  nfree(w->key);
  nfree(w);
}
Пример #6
0
static void wire_join(int idx, char *key)
{
  char wirecmd[512];
  char wiremsg[512];
  char wiretmp[512];
  char *enctmp;
  wire_list *w = wirelist, *w2;

  while (w) {
    if (w->next == 0)
      break;
    w = w->next;
  }
  if (!wirelist) {
    wirelist = nmalloc(sizeof *wirelist);
    w = wirelist;
  } else {
    w->next = nmalloc(sizeof *w->next);
    w = w->next;
  }
  w->sock = dcc[idx].sock;
  w->key = nmalloc(strlen(key) + 1);
  strcpy(w->key, key);
  w->next = 0;
  enctmp = encrypt_string(w->key, "wire");
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  w->crypt = nmalloc(strlen(wiretmp) + 1);
  strcpy(w->crypt, wiretmp);
  sprintf(wirecmd, "!wire%s", wiretmp);
  sprintf(wiremsg, "%s joined wire '%s'", dcc[idx].nick, key);
  enctmp = encrypt_string(w->key, wiremsg);
  strcpy(wiretmp, enctmp);
  nfree(enctmp);
  {
    char x[1024];

    simple_sprintf(x, "%s %s", botnetnick, wiretmp);
    botnet_send_zapf_broad(-1, botnetnick, wirecmd, x);
  }
  w2 = wirelist;
  while (w2) {
    if (!strcmp(w2->key, w->key))
      dprintf(findanyidx(w2->sock), "----- %s %s '%s'.\n",
              dcc[findanyidx(w->sock)].nick, WIRE_JOINED, w2->key);
    w2 = w2->next;
  }
  w2 = wirelist;
  while (w2) {                  /* Is someone using this key here already? */
    if (w2 != w)
      if (!strcmp(w2->key, w->key))
        break;
    w2 = w2->next;
  }
  if (!w2) {                    /* Someone else is NOT using this key, so
                                 * we add a bind */
    wire_bot[0].name = wirecmd;
    wire_bot[0].flags = "";
    wire_bot[0].func = (IntFunc) wire_filter;
    add_builtins(H_bot, wire_bot);
  }
}
Пример #7
0
/* do_seen(): Checks if someone matches the mask, and returns the reply
 * mask : first paramater (e.g. "G`Quann", "G`Quann", "*!*@*.isp.de", ...)
 * nick : nick of the one, who triggered the command
 * uhost: user@host of nick
 * chan : chan, where the command was triggered
 * bns  :
 *        1 : do a botnet-seen if no matches are found
 *        0 : don't do a botnet-seen
 *       -1 : return NULL instead of text, if no matches were found
 *            (necessary for botnet seen)
 */
static char *do_seen(char *mask, char *nick, char *uhost, char *chan, int bns)
{
  char hostbuf[UHOSTLEN + 1], *host, *newhost, *tmp, *dur;
  seendat *l;
  gseenres *r;
  int wild, nr;
  char bnquery[256];
  struct userrec *u;
  struct laston_info *li;
  struct chanset_t *ch;

  Context;
  start_seentime_calc();
  if (seen_reply) {
    nfree(seen_reply);
    seen_reply = NULL;
  }
  l = NULL;
  li = NULL;
  host = hostbuf;
  newhost = NULL;
  mask = newsplit(&mask);
  glob_query = mask;
  while (mask[0] == ' ')
    mask++;
  if (!mask[0]) {
    return SLNOPARAM;
  }
  if (strchr(mask, '?') || strchr(mask, '*')) {
    // if wildcard-searches ares not allowed, then either return
    // NULL (for botnet-seen), or a appropriate warning
    if (!wildcard_search) {
      if (bns == -1)
        return NULL;
      else
        return SLNOWILDCARDS;
    } else
      wild = 1;
  } else {
    if (strlen(mask) > seen_nick_len) // don't process if requested nick is too long
      return SLTOOLONGNICK;      // (e.g. stop stupid jokes)
    if (!strcasecmp(mask, nick)) {
      return SLMIRROR;
    }
    // check if the nick is on the current channel
    if (onchan(mask, chan))
      return SLONCHAN;
    if ((glob_othernick = handonchan(mask, chan)))
      return SLHANDONCHAN;
    // check if it is on any other channel
    if ((ch = onanychan(mask))) {
#if EGG_IS_MIN_VER(10500)
      if (!secretchan(ch->dname)) {
	glob_otherchan = ch->dname;
        return SLONOTHERCHAN;
      }
#else
      if (!secretchan(ch->name)) {
	glob_otherchan = ch->name;
        return SLONOTHERCHAN;
      }
#endif
    }
    // check if the user who uses this handle is on the channel under
    // a different nick
    if ((ch = handonanychan(mask))) {
#if EGG_IS_MIN_VER(10500)
      if (!secretchan(ch->dname)) {
        glob_otherchan = ch->dname;
        return SLONOTHERCHAN;
      }
#else
      if (!secretchan(ch->name)) {
        glob_otherchan = ch->name;
        return SLONOTHERCHAN;
      }
#endif
    }
    add_seenreq(mask, nick, uhost, chan, now);
    wild = 0;
    l = findseen(mask);
    // if there's a result, and if we don't want to search for the same user
    // under a different nick, just make a do_seennick on the result
    if (l && !fuzzy_search) {
      tmp = do_seennick(l);
      end_seentime_calc();
      return tmp;
    }
    if (!l) {
      u = get_user_by_handle(userlist, mask);
      if (u) {
        li = get_user(&USERENTRY_LASTON, u);
      }
      if (!u || !li) {
        if (bns == -1) {       // if bns is 0, then do_seen() was triggered by
          end_seentime_calc(); // a botnet seen function, which needs a clear
          return NULL;         // NULL to detect if there was a result or not
        }
        tmp = SLNOTSEEN;
        if (bns && ((strlen(mask) + strlen(nick) + strlen(uhost)
            + strlen(chan) + 20) < 255)) {
          debug0("trying botnet seen");
          if (bnsnick)
            nfree(bnsnick);
          if (bnschan)
            nfree(bnschan);
          bnsnick = nmalloc(strlen(nick) + 1);
          strcpy(bnsnick, nick);
          bnschan = nmalloc(strlen(chan) + 1);
          strcpy(bnschan, chan);
          sprintf(bnquery, "gseen_req %s %s %s %s", mask, nick, uhost, chan);
          botnet_send_zapf_broad(-1, botnetnick, NULL, bnquery);
        }
      } else {
        // we have a matching handle, no seen-entry, but a laston entry
        // in the userbase, so let's just return that one.
        dur = gseen_duration(now - li->laston);
        glob_laston = dur;
        tmp = SLPOORSEEN;
        seen_reply = nmalloc(strlen(tmp) + 1);
        strcpy(seen_reply, tmp);
        end_seentime_calc();
        return seen_reply;
      }
      end_seentime_calc();
      return tmp;
    }
    // now prepare the host for fuzzy-search
    if (strlen(l->host) < UHOSTLEN) {
      maskstricthost(l->host, host);
      host = strchr(host, '!') + 1; // strip nick from host for faster search
    } else {
      end_seentime_calc();
      return "error, too long host";
    }
  }
  if (l && (l->type == SEEN_CHPT)) {
    tmp = do_seennick(l);
    end_seentime_calc();
    return tmp;
  }
  numresults = 0;
  // wildmatch_seens uses a global var to store hosts in it
  // (to prevent massive nmalloc/nfree-usage), so don't forget
  // to initialize and free it
  temp_wildmatch_host = my_malloc(1);
  wildmatch_seens(host, mask, wild);
  my_free(temp_wildmatch_host);
  temp_wildmatch_host = NULL;
  if (!results) {
    end_seentime_calc();
    if (bns == -1)
      return NULL; // let the botnet seen function know, that seen failed
    return SLNOMATCH;
  }
  if (numresults >= max_matches) {
    end_seentime_calc();
    free_seenresults();
    return SLTOOMANYMATCHES;
  }
  sortresults();
  if (strcasecmp(results->seen->nick, mask)) {
    // if the user's latest nick is not the nick for which we were searching,
    // say that there were multiple matches and display the latest one
    if (numresults == 1)
      tmp = SLONEMATCH;
    else if (numresults <= 20)
      tmp = SLLITTLEMATCHES;
    else
      tmp = SLMANYMATCHES;
    seen_reply = nmalloc(strlen(tmp) + 1);
    strcpy(seen_reply, tmp);
    nr = 0;
    for (r = results; (r && (nr < 20)); r = r->next) {
      nr++;
      if (nr > 1) {
        seen_reply = nrealloc(seen_reply, 1 + strlen(seen_reply) + 1 + strlen(r->seen->nick) + 1);
        strcat(seen_reply, ", ");
      } else {
	seen_reply = nrealloc(seen_reply, 1 + strlen(seen_reply) + strlen(r->seen->nick) + 1);
        strcat(seen_reply, " ");
      }
      strcat(seen_reply, r->seen->nick);
    }
    tmp = do_seennick(results->seen);
    seen_reply = nrealloc(seen_reply, 2 + strlen(seen_reply) + strlen(tmp) + 1);
    sprintf(seen_reply, "%s. %s", seen_reply, tmp);
  } else { // first result is the nick which we were searching for
    // just return the info for this nick and don't care about other results
    tmp = do_seennick(results->seen);
    seen_reply = nmalloc(strlen(tmp) + 1);
    strcpy(seen_reply, tmp);
  }
  free_seenresults();
  end_seentime_calc();
  return seen_reply;
}