Exemplo n.º 1
0
char *shell_escape(const char *path)
{
  static char ret1[DIRMAX] = "", ret2[DIRMAX] = "", *ret = NULL;
  static bool alt = 0;
  char *c = NULL;

  if (alt) {
    alt = 0;
    ret = ret1;
  } else {
    alt = 1;
    ret = ret2;
  }

  ret[0] = 0;

  for (c = (char *) path; c && *c; ++c) {
    if (strchr(ESCAPESHELL, *c))
      simple_snprintf(ret, sizeof(ret1), "%s\\%c", ret[0] ? ret : "", *c);
    else
      simple_snprintf(ret, sizeof(ret1), "%s%c", ret[0] ? ret : "", *c);
  }

  return ret;
}
Exemplo n.º 2
0
char *homedir(bool useconf)
{
  static char homedir_buf[DIRMAX] = "";

  if (!homedir_buf[0]) {
    char tmp[DIRMAX] = "";

    if (conf.homedir && useconf)
      simple_snprintf(tmp, sizeof tmp, "%s", conf.homedir);
    else {
#ifdef CYGWIN_HACKS
      simple_snprintf(tmp, sizeof tmp, "%s", dirname(binname));
#else /* !CYGWIN_HACKS */
      struct passwd *pw = NULL;
 
      ContextNote(STR("getpwuid()"));
      pw = getpwuid(myuid);
      if (pw)
        simple_snprintf(tmp, sizeof tmp, "%s", pw->pw_dir);
      ContextNote(STR("getpwuid(): Success"));
#endif /* CYGWIN_HACKS */
    }
    ContextNote(STR("realpath()"));
    if (tmp[0])
      realpath(tmp, homedir_buf); /* this will convert lame home dirs of /home/blah->/usr/home/blah */
    ContextNote(STR("realpath(): Success"));
  }
  return homedir_buf[0] ? homedir_buf : NULL;
}
Exemplo n.º 3
0
static void hosts_display(int idx, struct user_entry *e, struct userrec *u)
{
  /* if this is a su, dont show hosts
   * otherwise, let users see their own hosts */
  if (conf.bot->hub || 
     (!conf.bot->hub && (dcc[idx].simul || (!strcmp(u->handle,dcc[idx].nick) && !dcc[idx].u.chat->su_nick)))) { 
    char s[1024] = "";
    struct list_type *q = NULL;

    strlcpy(s, "  HOSTS: ", sizeof(s));
    for (q = e->u.list; q; q = q->next) {
      if (s[0] && !s[9])
        strlcat(s, q->extra, sizeof(s));
      else if (!s[0])
        simple_snprintf(s, sizeof(s), "         %s", q->extra);
      else {
        if (strlen(s) + strlen(q->extra) + 2 > 65) {
  	  dprintf(idx, "%s\n", s);
  	  simple_snprintf(s, sizeof(s), "         %s", q->extra);
        } else {
  	  strlcat(s, ", ", sizeof(s));
  	  strlcat(s, q->extra, sizeof(s));
        }
      }
    }
    if (s[0])
      dprintf(idx, "%s\n", s);
  } else if (!conf.bot->hub) {
    dprintf(idx, "  HOSTS:          Hidden on leaf bots.");
    if (dcc[idx].u.chat->su_nick)
      dprintf(idx, " Nice try, %s.", dcc[idx].u.chat->su_nick);
    dprintf(idx, "\n");
  }
}
Exemplo n.º 4
0
void check_last() {
  if (login == DET_IGNORE)
    return;

  if (conf.username) {
    char *out = NULL, buf[50] = "";

    simple_snprintf(buf, sizeof(buf), STR("last -10 %s"), conf.username);
    if (shell_exec(buf, NULL, &out, NULL)) {
      if (out) {
        char *p = NULL;

        p = strchr(out, '\n');
        if (p)
          *p = 0;
        if (strlen(out) > 10) {
          if (last_buf[0]) {
            if (strncmp(last_buf, out, sizeof(last_buf))) {
              char *work = NULL;
              size_t siz = strlen(out) + 7 + 2 + 1;

              work = (char *) my_calloc(1, siz);

              simple_snprintf(work, siz, STR("Login: %s"), out);
              detected(DETECT_LOGIN, work);
              free(work);
            }
          }
          strlcpy(last_buf, out, sizeof(last_buf));
        }
        free(out);
      }
    }
  }
}
Exemplo n.º 5
0
Arquivo: crypt.c Projeto: vap0r/wraith
char *salted_sha1(const char *in, const char* saltin)
{
  char *tmp = NULL, buf[101] = "", *ret = NULL;
  size_t ret_size = 0;


  /* Create a 5 byte salt */
  char salt[SHA1_SALT_LEN + 1] = "";
  if (saltin) {
    strlcpy(salt, saltin, sizeof(salt));
  } else {
    make_rand_str(salt, sizeof(salt) - 1);
  }

  /* SHA1 the salt+password */
  simple_snprintf(buf, sizeof(buf), STR("%s%s"), salt, in);
  tmp = SHA1(buf);

  ret_size = SHA1_SALTED_LEN + 1;
  ret = (char *) my_calloc(1, ret_size);
  simple_snprintf(ret, ret_size, STR("+%s$%s"), salt, tmp);

  /* Wipe cleartext pass from sha1 buffers/tmp */
  SHA1(NULL);

  return ret;
}
Exemplo n.º 6
0
static void pls_chan(int idx, char *par, char *bot)
{
  char *chname = NULL, result[RESULT_LEN] = "", buf[2048] = "";
  struct chanset_t *chan = NULL;

  if (!bot)
    putlog(LOG_CMDS, "*", "#%s# +chan %s", dcc[idx].nick, par);

  if (!par[0]) {
    dprintf(idx, "Usage: +chan [%s]<channel> [options]\n", CHANMETA);
    return;
  }

  chname = newsplit(&par);
  simple_snprintf(buf, sizeof(buf), "cjoin %s %s", chname, bot ? bot : "*");		/* +chan makes all bots join */
  if (par[0]) {
    strlcat(buf, " ", sizeof(buf));
    strlcat(buf, par, sizeof(buf));
    strlcat(buf, " ", sizeof(buf));
  }
    
  if (!bot && findchan_by_dname(chname)) {
    dprintf(idx, "That channel already exists!\n");
    return;
  } else if ((chan = findchan(chname)) && !bot) {
    dprintf(idx, "That channel already exists as %s!\n", chan->dname);
    return;
  } else if (strchr(CHANMETA, chname[0]) == NULL) {
    dprintf(idx, "Invalid channel prefix.\n");
    return;
  } else if (strchr(chname, ',') != NULL) {
    dprintf(idx, "Invalid channel name.\n");
    return;
  }
  if (!chan && !findchan_by_dname(chname) && channel_add(result, chname, par) == ERROR) {
    dprintf(idx, "Invalid channel or channel options.\n");
    if (result[0])
      dprintf(idx, " %s\n", result);
  } else {
    if ((chan = findchan_by_dname(chname))) {
      char tmp[51] = "";

      simple_snprintf(tmp, sizeof(tmp), "addedby %s addedts %li", dcc[idx].nick, (long) now);
      if (buf[0]) {
        strlcat(buf, " ", sizeof(buf));
        strlcat(buf, tmp, sizeof(buf));
      }
      do_chanset(NULL, chan, buf[0] ? buf : tmp, DO_LOCAL);
      if (!bot) {
        dprintf(idx, "Channel %s added to the botnet.\n", chname);
      } else {
        dprintf(idx, "Channel %s added to the bot: %s\n", chname, bot);
      }
      putallbots(buf);
    }
    if (conf.bot->hub)
      write_userfile(-1);
  }
}
Exemplo n.º 7
0
char *move_bin(const char *ipath, const char *file, bool run)
{
  char *path = strdup(ipath);

  expand_tilde(&path);

  /* move the binary to the correct place */
  static char newbin[DIRMAX] = "";
  char real[DIRMAX] = "";

  simple_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);

  ContextNote(STR("realpath()"));
  realpath(binname, real);            /* get the realpath of binname */
  ContextNote(STR("realpath(): Success"));
  /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
  sdprintf(STR("binname: %s"), binname);
  sdprintf(STR("newbin: %s"), newbin);
  sdprintf(STR("real: %s"), real);
  if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
    bool ok = 1;

    sdprintf(STR("wrong dir, is: %s :: %s"), binname, newbin);

    unlink(newbin);
    if (copyfile(binname, newbin))
      ok = 0;

    if (ok && !can_stat(newbin)) {
       unlink(newbin);
       ok = 0;
    }

    if (ok && fixmod(newbin)) {
        unlink(newbin);
        ok = 0;
    }

    if (ok) {
      sdprintf(STR("Binary successfully moved to: %s"), newbin);
      unlink(binname);
      if (run) {
        simple_snprintf(newbin, sizeof newbin, "%s%s%s", 
                        path, path[strlen(path) - 1] == '/' ? "" : "/", shell_escape(file));
        system(newbin);
        sdprintf(STR("exiting to let new binary run..."));
        exit(0);
      }
    } else {
      if (run)
        werr(ERR_WRONGBINDIR);
      sdprintf(STR("Binary move failed to: %s"), newbin);
      return binname;
    }
  }
  return newbin;
}
Exemplo n.º 8
0
void detected(int code, const char *msg)
{
  char tmp[512] = "";
  struct flag_record fr = { FR_GLOBAL, 0, 0, 0 };
  int act = DET_WARN, do_fatal = 0, killbots = 0;
  
  if (code == DETECT_LOGIN)
    act = login;
  if (code == DETECT_TRACE)
    act = trace;
  if (code == DETECT_PROMISC)
    act = promisc;
#ifdef NOT_USED
  if (code == DETECT_PROCESS)
    act = badprocess;
#endif
  if (code == DETECT_HIJACK)
    act = hijack;

  switch (act) {
  case DET_IGNORE:
    break;
  case DET_WARN:
    putlog(LOG_WARN, "*", msg);
    break;
  case DET_REJECT:
    do_fork();
    putlog(LOG_WARN, "*", STR("Setting myself +d: %s"), msg);
    simple_snprintf(tmp, sizeof(tmp), "+d: %s", msg);
    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
    fr.global = USER_DEOP;
    fr.bot = 1;
    set_user_flagrec(conf.bot->u, &fr, 0);
    sleep(1);
    break;
  case DET_DIE:
    putlog(LOG_WARN, "*", STR("Dying: %s"), msg);
    simple_snprintf(tmp, sizeof(tmp), STR("Dying: %s"), msg);
    set_user(&USERENTRY_COMMENT, conf.bot->u, tmp);
    if (!conf.bot->hub)
      nuke_server(STR("BBL"));
    sleep(1);
    killbots++;
    do_fatal++;
    break;
  case DET_SUICIDE:
    suicide(msg);
    break;
  }
  if (killbots && conf.bot->localhub) {
    conf_checkpids(conf.bots);
    conf_killbot(conf.bots, NULL, NULL, SIGKILL);
  }
  if (do_fatal)
    fatal(msg, 0);
}
Exemplo n.º 9
0
void Tempfile::AllocTempfile()
{
  len = strlen(tempdir) + 1 + plen + 1 + 6 + 1;
  file = new char[len];

  if (prefix)
    simple_snprintf(file, len, "%s.%s-XXXXXX", tempdir, prefix);
  else
    simple_snprintf(file, len, "%s.XXXXXX", tempdir);

  MakeTemp();
}
Exemplo n.º 10
0
Arquivo: misc.c Projeto: kirune/wraith
int goodpass(const char *pass, int idx, char *nick)
{
  if (!pass[0]) 
    return 0;

  char tell[201] = "", last = 0;
  int nalpha = 0, lcase = 0, ucase = 0, ocase = 0, tc, repeats = 0, score = 0;
  size_t length = strlen(pass);

  if (strchr(BADPASSCHARS, pass[0])) {
    simple_snprintf(tell, sizeof(tell), "Passes may not begin with '-'");
    goto fail;
  }

  for (int i = 0; i < (signed) length; i++) {
    if (pass[i] == last)
      repeats++;

    tc = (int) pass[i];
    if (tc < 58 && tc > 47)
      ocase++; /* number */
    else if (tc < 91 && tc > 64)
      ucase++; /* upper case */
    else if (tc < 123 && tc > 96)
      lcase++; /* lower case */
    else
       nalpha++; /* non-alphabet/number */
    last = pass[i];
  }

  score += ocase * 3;
  score += nalpha * 2;
  score += ucase * 2;
  score += lcase * 1;
  score += length * 1;
  score -= repeats * 1;
  
  simple_snprintf(tell, sizeof(tell), "Password NOT set due to being too weak. Try more characters, numbers, capitals");

  if (score < 16) {
    fail:

    if (idx)
      dprintf(idx, "%s\n", tell);
    else if (nick[0])
      notice(nick, tell, DP_HELP);
    return 0;
  }
  return 1;
}
Exemplo n.º 11
0
void tell_verbose_uptime(int idx)
{
  char s[256] = "", s1[121] = "", s2[81] = "", outbuf[501] = "";
  time_t total, hr, min;
#if HAVE_GETRUSAGE
  struct rusage ru;
#else
# if HAVE_CLOCK
  clock_t cl;
# endif
#endif /* HAVE_GETRUSAGE */

  daysdur(now, online_since, s, sizeof(s));

  if (backgrd)
    strlcpy(s1, "background", sizeof(s1));
  else {
    if (term_z)
      strlcpy(s1, "terminal mode", sizeof(s1));
    else
      strlcpy(s1, "log dump mode", sizeof(s1));
  }
  simple_snprintf(outbuf, sizeof(outbuf), "Online for %s", s);
  if (restart_time) {
    daysdur(now, restart_time, s, sizeof(s));
    size_t olen = strlen(outbuf);
    simple_snprintf(&outbuf[olen], sizeof(outbuf) - olen, " (%s %s)", restart_was_update ? "updated" : "restarted", s);
  }

#if HAVE_GETRUSAGE
  getrusage(RUSAGE_SELF, &ru);
  total = ru.ru_utime.tv_sec + ru.ru_stime.tv_sec;
  hr = (int) (total / 60);
  min = (int) (total - (hr * 60));
  egg_snprintf(s2, sizeof(s2), "CPU %02d:%02d (load avg %3.1f%%)", (int) hr, (int) min, 100.0 * ((float) total / (float) (now - online_since)));
#else
# if HAVE_CLOCK
  cl = (clock() / CLOCKS_PER_SEC);
  hr = (int) (cl / 60);
  min = (int) (cl - (hr * 60));
  egg_snprintf(s2, sizeof(s2), "CPU %02d:%02d (load avg %3.1f%%)", (int) hr, (int) min,  100.0 * ((float) cl / (float) (now - online_since)));
# else
  simple_snprintf(s2, sizeof(s2), "CPU ???");
# endif
#endif /* HAVE_GETRUSAGE */
  dprintf(idx, "%s  (%s)  %s  cache hit %4.1f%%\n",
          outbuf, s1, s2,
          100.0 * ((float) cache_hit) / ((float) (cache_hit + cache_miss)));

}
Exemplo n.º 12
0
void baduname(char *confhas, char *myuname) {
  char *tmpFile = NULL;
  int tosend = 0, make = 0;
  size_t siz = strlen(tempdir) + 3 + 1;

  tmpFile = (char *) my_calloc(1, siz);

  simple_snprintf(tmpFile, siz, STR("%s/.un"), conf.datadir);
  if (is_file(tmpFile)) {
    struct stat ss;
    time_t diff;

    stat(tmpFile, &ss);
    diff = now - ss.st_mtime;
    if (diff >= 86400) {
      tosend++;          		/* only send once a day */
      unlink(tmpFile);		/* remove file */
      make++;			/* make a new one at thie time. */
    }
  } else {
    make++;
  }

  if (make) {
    FILE *fp = NULL;
    if ((fp = fopen(tmpFile, "w"))) {
      fprintf(fp, "\n");
      fflush(fp);
      fclose(fp);
      tosend++;           /* only send if we could write the file. */
    }
  }

  if (tosend) {
    struct utsname un;
    char msg[1024] = "", subject[31] = "";

    uname(&un);
    simple_snprintf(subject, sizeof subject, STR("CONF/UNAME() mismatch notice"));
    simple_snprintf(msg, sizeof msg, STR("This is an auto email from a wraith bot which has you in it's OWNER_EMAIL list..\n \nThe uname() output on this box has changed, probably due to a kernel upgrade...\nMy login is: %s\nMy binary is: %s\nLocalhub: %s\nConf   : %s\nUname(): %s\n \nThis email will only be sent once a day while this error is present.\nYou need to login to my shell (%s) and fix my local config.\n"), 
                                  conf.username ? conf.username : "******", 
                                  binname,
                                  conf.bots && conf.bots->nick ? conf.bots->nick : origbotname,
                                  confhas, myuname, un.nodename);
    email(subject, msg, EMAIL_OWNERS);
  }
  free(tmpFile);
}
Exemplo n.º 13
0
/* chan <from> <chan> <text>
 */
static void bot_chan2(int idx, char *msg)
{
  char *from = NULL, *p = NULL;
  int i, chan;

  from = newsplit(&msg);
  p = newsplit(&msg);
  chan = base64_to_int(p);
  /* Strip annoying control chars */
  for (p = from; *p;) {
    if ((*p < 32) || (*p == 127))
      memmove(p, p + 1, strlen(p));
    else
      p++;
  }
  p = strchr(from, '@');
  if (p) {
    if (!conf.bot->hub) { /* Need to strip out the hub nick */
      char *q = NULL, newfrom[HANDLEN + 9 + 1]; /* HANDLEN@[botnet] */
   
      strlcpy(newfrom, from, sizeof(newfrom));
      q = strchr(newfrom, '@');
      *q = 0;
      simple_snprintf(TBUF, sizeof(TBUF), "<%s@[botnet]> %s", newfrom, msg);
    } else
      simple_snprintf(TBUF, sizeof(TBUF), "<%s> %s", from, msg);
    *p = 0;
    if (!partyidle(p + 1, from)) {
      *p = '@';
      fake_alert(idx, "user", from, "chan2_i");
      return;
    }
    *p = '@';
    p++;
  } else {
    simple_snprintf(TBUF, sizeof(TBUF), "*** (%s) %s", from, msg);
    p = from;
  }
  i = nextbot(p);
  if (i != idx) {
    fake_alert(idx, "direction", p, "chan2_ii");
  } else {
    chanout_but(-1, chan, "%s\n", TBUF);
    /* Send to new version bots */
    if (i >= 0)
      botnet_send_chan(idx, from, NULL, chan, msg);
  }
}
Exemplo n.º 14
0
static void cmd_cycle(int idx, char *par)
{
  char *chname = NULL;
  int delay = 10;
  struct chanset_t *chan = NULL;

  putlog(LOG_CMDS, "*", "#%s# cycle %s", dcc[idx].nick, par);

  if (!par[0]) {
    dprintf(idx, "Usage: cycle [%s]<channel> [delay]\n", CHANMETA);
    dprintf(idx, "rejoin delay defaults to '10'\n");
    return;
  }

  chname = newsplit(&par);
  chan = findchan_by_dname(chname);
  if (!chan) {
    dprintf(idx, "%s is not a valid channel.\n", chname);
    return;
  }
  if (par[0])
    delay = atoi(newsplit(&par));

  if (conf.bot->hub) {
    char buf2[201] = "";

    simple_snprintf(buf2, sizeof(buf2), "cycle %s %d", chname, delay); /* this just makes the bot PART */
    putallbots(buf2);
  } else {
    do_chanset(NULL, chan, "+inactive", DO_LOCAL);
    dprintf(DP_SERVER, "PART %s\n", chan->name);
    chan->channel.jointime = ((now + delay) - server_lag);
  }
  dprintf(idx, "Cycling %s for %d seconds.\n", chan->dname, delay);
}
Exemplo n.º 15
0
void update_mod(char *handle, char *nick, char *cmd, char *par)
{
  char tmp[100] = "";

  simple_snprintf(tmp, sizeof tmp, "%li, %s (%s %s)", (long) now, nick, cmd, (par && par[0]) ? par : "");
  set_user(&USERENTRY_MODIFIED, get_user_by_handle(userlist, handle), tmp);
}
Exemplo n.º 16
0
static bool
console_set(struct userrec *u, struct user_entry *e, void *buf)
{
  struct console_info *ci = (struct console_info *) e->u.extra;

  if (!ci && !buf)
    return 1;

  if (ci != buf) {
    if (ci) {
      free(ci->channel);
      free(ci);
    }
    ci = (struct console_info *) buf;
    e->u.extra = (struct console_info *) buf;
  }

  if (!noshare && !u->bot) {
    char string[501] = "";

    simple_snprintf(string, sizeof string, "%s %s %s %d %d %d %d %d %d %d %d", ci->channel,
                 masktype(ci->conflags), stripmasktype(ci->stripflags), ci->echoflags, ci->page, ci->conchan,
                 ci->color, ci->banner, ci->channels, ci->bots, ci->whom);
    /* shareout("c %s %s %s\n", e->type->name, u->handle, string); */
    shareout("c CONSOLE %s %s\n", u->handle, string);
  }
  return 1;
}
Exemplo n.º 17
0
Arquivo: ctcp.c Projeto: vap0r/wraith
static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
{

  if (!ischanhub()) 
    return BIND_RET_LOG;

    if (u_pass_match(u, "-")) {
      strlcat(ctcp_reply, "\001ERROR no password set\001", sizeof(ctcp_reply));
      return BIND_RET_BREAK;
    }

    int ix = -1, i = 0;

    for (i = 0; i < dcc_total; i++) {
      if (dcc[i].type && (dcc[i].type->flags & DCT_LISTEN) && (!strcmp(dcc[i].nick, "(telnet)")))
        ix = i;
    }
    if (!iptolong(getmyip())) {
      simple_snprintf(&ctcp_reply[strlen(ctcp_reply)], sizeof(ctcp_reply) - strlen(ctcp_reply), "\001ERROR no ipv4 ip defined. Use /dcc chat %s\001", botname);
    } else if (dcc_total == max_dcc || (ix < 0 && (ix = listen_all(0, 0, 0)) < 0))
      strlcat(ctcp_reply, "\001ERROR no telnet port\001", sizeof(ctcp_reply));
    else {
      if (listen_time <= 2)
        listen_time++;
      /* do me a favour and don't change this back to a CTCP reply,
       * CTCP replies are NOTICE's this has to be a PRIVMSG
       * -poptix 5/1/1997 */
      bd::String msg;
      msg = bd::String::printf("\001DCC CHAT chat %lu %u\001", iptolong(getmyip()), dcc[ix].port);
      privmsg(nick, msg.c_str(), DP_SERVER);
    }
    return BIND_RET_BREAK;
}
Exemplo n.º 18
0
static int msg_pls_auth(char *nick, char *host, struct userrec *u, char *par)
{
  if (strlen(auth_key) && get_user(&USERENTRY_SECPASS, u)) {
    if (match_my_nick(nick))
      return BIND_RET_BREAK;
    if (u && u->bot)
      return BIND_RET_BREAK;

    Auth *auth = Auth::Find(host);

    if (!auth || auth->Status() != AUTH_HASH)
      return BIND_RET_BREAK;

    if (!strcmp(auth->hash, par)) { /* good hash! */
      AuthFinish(auth);
    } else { /* bad hash! */
      char s[300] = "";

      putlog(LOG_CMDS, "*", STR("(%s!%s) !%s! failed +AUTH"), nick, host, u->handle);
      notice(nick, STR("Invalid hash."), DP_HELP);
      simple_snprintf(s, sizeof(s), "*!%s", host);
      addignore(s, origbotname, STR("Invalid auth hash."), now + (60 * ignore_time));
      delete auth;
    } 
    return BIND_RET_BREAK;
  }
  return BIND_RET_LOG;
}
Exemplo n.º 19
0
static void cmd_down(int idx, char *par)
{
  char *chname = NULL, buf2[201] = "";
  struct chanset_t *chan = NULL;

  putlog(LOG_CMDS, "*", "#%s# down %s", dcc[idx].nick, par);

  if (!par[0]) {
    dprintf(idx, "Usage: down [%s]<channel>\n", CHANMETA);
    return;
  }

  chname = newsplit(&par);
  chan = findchan_by_dname(chname);
  if (!chan) {
    dprintf(idx, "%s is not a valid channel.\n", chname);
    return;
  }
  
  simple_snprintf(buf2, sizeof(buf2), "down %s", chan->dname);
  putallbots(buf2);
  if (!conf.bot->hub) {
    add_mode(chan, '-', 'o', botname);
    chan->channel.no_op = (now + 10);
  }
}
Exemplo n.º 20
0
static void show_flag(int idx, char *work, int *cnt, const char *name, unsigned int state, size_t worksiz)
{
  char tmp[101] = "", chr_state[15] = "";
  /* empty buffer if no (char *) name */
  if (((*cnt) < (FLAG_COLS - 1)) && (!name || (name && !name[0]))) (*cnt) = (FLAG_COLS - 1); 
  (*cnt)++;
  if (*cnt > FLAG_COLS) {
    *cnt = 1;
    work[0] = 0;
  }
  if (!work[0])
    strlcpy(work, "  ", worksiz);
  if (name && name[0]) {
    chr_state[0] = 0;
    if (state) {
      strlcat(chr_state, GREEN(idx), sizeof(chr_state));
      strlcat(chr_state, "+", sizeof(chr_state));
    } else {
      strlcat(chr_state, RED(idx), sizeof(chr_state));
      strlcat(chr_state, "-", sizeof(chr_state));
    }
    strlcat(chr_state, COLOR_END(idx), sizeof(chr_state));
    simple_snprintf(tmp, sizeof tmp, "%s%-17s", chr_state, name);
    strlcat(work, tmp, worksiz);
  }
  if (*cnt >= FLAG_COLS)
    dprintf(idx, "%s\n", work);
}
Exemplo n.º 21
0
void stats_add(struct userrec *u, int islogin, int op)
{
  if (!u || u->bot)
    return;

  char *s = (char *) get_user(&USERENTRY_STATS, u), s2[50] = "";
  int sl, so;

  if (s) {
    strlcpy(s2, s, sizeof(s2));
  } else
    strlcpy(s2, "0 0", sizeof(s2));
  s = strchr(s2, ' ');
  if (s) {
    s++;
    so = atoi(s);
  } else
    so = 0;
  sl = atoi(s2);
  if (islogin)
    sl++;
  if (op)
    so++;
  simple_snprintf(s2, sizeof(s2), "%i %i", sl, so);
  set_user(&USERENTRY_STATS, u, s2);
}
Exemplo n.º 22
0
Arquivo: misc.c Projeto: kirune/wraith
/* Return an allocated buffer which contains a copy of the string
 * 'str', with all 'div' characters escaped by 'mask'. 'mask'
 * characters are escaped too.
 *
 * Remember to free the returned memory block.
 */
char *str_escape(const char *str, const char divc, const char mask)
{
  const size_t	 len = strlen(str);
  size_t	 buflen = (2 * len), blen = 0;
  char		*buf = NULL, *b = NULL;
  const char	*s = NULL;

  b = buf = (char *) my_calloc(1, buflen + 1);

  for (s = str; *s; s++) {
    /* Resize buffer. */
    if ((buflen - blen) <= 3) {
      buflen <<= 1;		/* * 2 */
      buf = (char *) my_realloc(buf, buflen + 1);
      if (!buf)
	return NULL;
      b = buf + blen;
    }

    if (*s == divc || *s == mask) {
      simple_snprintf(b, buflen, "%c%02x", mask, *s);
      b += 3;
      blen += 3;
    } else {
      *(b++) = *s;
      blen++;
    }
  }
  *b = 0;
  return buf;
}
Exemplo n.º 23
0
Arquivo: misc.c Projeto: kirune/wraith
void show_channels(int idx, char *handle)
{
  struct userrec *u = NULL;
  size_t maxChannelLength = 0;
  bd::Array<bd::String> channelNames;
  bd::HashTable<bd::String, struct chanset_t*> channels;
  bd::String group;

  if (handle && handle[0] != '%') {
    u = get_user_by_handle(userlist, handle);
  } else {
    u = dcc[idx].user;
    if (handle && handle[0] == '%') {
      group = handle + 1;
    }
  }

  for (struct chanset_t* chan = chanset; chan; chan = chan->next) {
    struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
    const bd::String chname(chan->dname);
    // If a group was passed, ensure it matches
    if (group.length() && chan->groups->find(group) == chan->groups->npos) {
      continue;
    }
    get_user_flagrec(u, &fr, chan->dname);
    if (group.length() || real_chk_op(fr, chan, 0)) {
      if (maxChannelLength < chname.length()) {
        maxChannelLength = chname.length();
      }
      channelNames << chname;
      channels[chname] = chan;
    }
  }

  if (channelNames.length()) {
    char format[120] = "";
    simple_snprintf(format, sizeof(format), "  %%c%%-%zus %%-s%%-s%%-s%%-s%%-s%%-s\n", (maxChannelLength+2));
    if (group.length()) {
      dprintf(idx, "group '%s' is in %zu channel%s:\n", group.c_str(), channelNames.length(), (channelNames.length() > 1) ? "s" : "");
    } else {
      dprintf(idx, "%s %s access to %zu channel%s:\n", handle ? u->handle : "You", handle ? "has" : "have", channelNames.length(), (channelNames.length() > 1) ? "s" : "");
    }

    for (size_t i = 0; i < channelNames.length(); ++i) {
      const bd::String chname(channelNames[i]);
      const struct chanset_t* chan = channels[chname];
      dprintf(idx, format, !conf.bot->hub && me_op(chan) ? '@' : ' ', chan->dname, ((conf.bot->hub && channel_inactive(chan)) || (!conf.bot->hub && !shouldjoin(chan))) ? "(inactive) " : "",
          channel_privchan(chan) ? "(private)  " : "", chan->manop ? "(no manop) " : "", 
          channel_bitch(chan) && !channel_botbitch(chan) ? "(bitch)    " : channel_botbitch(chan) ? "(botbitch) " : "",
          channel_closed(chan) ?  "(closed) " : "", channel_backup(chan) ? "(backup)" : "");
    }
  } else {
    if (group.length()) {
      dprintf(idx, "No channels found for group '%s'\n", group.c_str());
    } else {
      dprintf(idx, "%s %s not have access to any channels.\n", handle ? u->handle : "You", handle ? "does" : "do");
    }
  }
}
Exemplo n.º 24
0
void send_remote_simul(int idx, char *bot, char *cmd, char *par)
{
  char msg[SGRAB - 110] = "";

  simple_snprintf(msg, sizeof msg, "r-s %d %s %d %s %lu %s %s", idx, dcc[idx].nick, dcc[idx].u.chat->con_flags, 
               dcc[idx].u.chat->con_chan, dcc[idx].status, cmd, par);
  putbot(bot, msg);
}
Exemplo n.º 25
0
/* idx nick conmask cmd par */
static void bot_rsim(char *botnick, char *code, char *msg)
{
  int ridx = -1, idx = -1, i = 0, rconmask;
  unsigned long status = 0;
  char *nick = NULL, *cmd = NULL, *rconchan = NULL, buf[UHOSTMAX] = "", *par = NULL, *parp = NULL;
  struct userrec *u = get_user_by_handle(userlist, botnick);

  if (bot_hublevel(u) == 999) {
    putlog(LOG_WARN, "*", "BOTCMD received from a leaf. HIJACK.");
    return;
  }

  par = parp = strdup(msg);
  ridx = atoi(newsplit(&par));
  nick = newsplit(&par);
  rconmask = atoi(newsplit(&par));
  rconchan = newsplit(&par);
  if (egg_isdigit(par[0]))
    status = (unsigned long) atoi(newsplit(&par));
  cmd = newsplit(&par);
  if (ridx < 0 || !nick || !cmd) {
    free(parp);
    return;
  }

  for (i = 0; i < dcc_total; i++) {
   /* See if we can find a simul-idx for the same ridx/nick */
   if (dcc[i].type && dcc[i].simul == ridx && !strcasecmp(dcc[i].nick, nick)) {
     putlog(LOG_DEBUG, "*", "Simul found old idx for %s: %d (ridx: %d)", nick, i, ridx);
     dcc[i].simultime = now;
     idx = i;
     break;
   }
  }

  if (idx < 0) {
    idx = new_dcc(&DCC_CHAT, sizeof(struct chat_info));
    putlog(LOG_DEBUG, "*", "Making new idx for %s@%s: %d ridx: %d", nick, botnick, idx, ridx);
    dcc[idx].sock = -1;
    dcc[idx].timeval = now;
    dcc[idx].simultime = now;
    dcc[idx].simul = ridx;
    dcc[idx].status = status;
    strlcpy(dcc[idx].simulbot, botnick, sizeof(dcc[idx].simulbot));
    dcc[idx].u.chat->con_flags = rconmask;
    struct chat_info dummy;
    strlcpy(dcc[idx].u.chat->con_chan, rconchan, sizeof(dummy.con_chan));
    dcc[idx].u.chat->strip_flags = STRIP_ALL;
    strlcpy(dcc[idx].nick, nick, sizeof(dcc[idx].nick));
    simple_snprintf(buf, sizeof buf, "%s@%s", nick, botnick);
    strlcpy(dcc[idx].host, buf, sizeof(dcc[idx].host));
    dcc[idx].addr = 0L;
    dcc[idx].user = get_user_by_handle(userlist, nick);
  }
  rmspace(par);
  check_bind_dcc(cmd, idx, par);
  free(parp);
}
Exemplo n.º 26
0
static void write_debug()
{
  char tmpout[150] = "";

  simple_snprintf(tmpout, sizeof tmpout, "* Last 3 contexts: %s/%d [%s], %s/%d [%s], %s/%d [%s]",
                                  CX(cx_ptr - 2), CX(cx_ptr - 1), CX(cx_ptr));
  putlog(LOG_MISC, "*", "%s (Paste to bryan)", tmpout);
  printf("%s\n", tmpout);
}
Exemplo n.º 27
0
void crontab_del() {
  char *tmpFile = NULL, *p = NULL, buf[2048] = "";

  size_t tmplen = strlen(binname) + 100;
  tmpFile = (char *) my_calloc(1, tmplen);

  strlcpy(tmpFile, shell_escape(binname), tmplen);
  if (!(p = strrchr(tmpFile, '/')))
    return;
  p++;
  strcpy(p, STR(".ctb"));
  simple_snprintf(buf, sizeof(buf), STR("crontab -l | grep -v '%s' | grep -v \"^#\" | grep -v \"^\\$\" > %s"), binname, tmpFile);
  if (shell_exec(buf, NULL, NULL, NULL)) {
    simple_snprintf(buf, sizeof(buf), STR("crontab %s"), tmpFile);
    shell_exec(buf, NULL, NULL, NULL);
  }
  unlink(tmpFile);
}
Exemplo n.º 28
0
static void write_debug(bool fatal = 1)
{
  if (fatal) {
    segfaulted = 1;
    alarm(0);		/* dont let anything jump out of this signal! */
  }

  putlog(LOG_MISC, "*", "** Paste to bryan:");
  putlog(LOG_MISC, "*", "Version: %s", egg_version);
  const size_t cur_buf = (current_get_buf == 0) ? GET_BUFS - 1 : current_get_buf - 1;
  for (size_t i = 0; i < GET_BUFS; i++)
    putlog(LOG_MISC, "*", "%c %02zu: %s", i == cur_buf ? '*' : '_', i, get_buf[i]);
  putlog(LOG_MISC, "*", "** end");

#ifdef DEBUG
  if (fatal) {
    /* Write GDB backtrace */
    char gdb[1024] = "", btfile[256] = "", std_in[101] = "", *out = NULL;

    simple_snprintf(btfile, sizeof(btfile), ".gdb-backtrace-%d", (int)getpid());

    FILE *f = fopen(btfile, "w");

    if (f) {
      strlcpy(std_in, "bt 100\nbt 100 full\ndetach\nquit\n", sizeof(std_in));
      //simple_snprintf(stdin, sizeof(stdin), "detach\n");
      //simple_snprintf(stdin, sizeof(stdin), "q\n");

      simple_snprintf(gdb, sizeof(gdb), "gdb --pid=%d %s", (int)getpid(), binname);
      shell_exec(gdb, std_in, &out, NULL);
      fprintf(f, "%s\n", out);
      fclose(f);
      free(out);
    }

    //enabling core dumps
    struct rlimit limit;
    if (!getrlimit(RLIMIT_CORE, &limit)) {
      limit.rlim_cur = limit.rlim_max;
      setrlimit(RLIMIT_CORE, &limit);
    }
  }
#endif
}
Exemplo n.º 29
0
Arquivo: misc.c Projeto: kirune/wraith
/* Convert an interval (in seconds) to one of:
 * "19 days ago", "1 day ago", "18:12"
 */
void daysago(time_t mynow, time_t then, char *out, size_t outsiz)
{
  if (mynow - then > 86400) {
    int mydays = (mynow - then) / 86400;

    simple_snprintf(out, outsiz, "%d day%s ago", mydays, (mydays == 1) ? "" : "s");
    return;
  }
  strftime(out, 6, "%H:%M", gmtime(&then));
}
Exemplo n.º 30
0
Arquivo: misc.c Projeto: kirune/wraith
/* Convert an interval (in seconds) to one of:
 * "in 19 days", "in 1 day", "at 18:12"
 */
void days(time_t mynow, time_t then, char *out, size_t outsiz)
{
  if (mynow - then > 86400) {
    int mydays = (mynow - then) / 86400;

    simple_snprintf(out, outsiz, "in %d day%s", mydays, (mydays == 1) ? "" : "s");
    return;
  }
  strftime(out, 9, "at %H:%M", gmtime(&now));
}