Esempio n. 1
0
/* Bot next share?
 */
static void bot_update(int idx, char *par)
{
  char *bot = NULL, x, *vversion = NULL, *vcommit = NULL;
  int vlocalhub = 0;
  time_t vbuildts = 0L;

  bot = newsplit(&par);
  x = par[0];
  if (x)
    par++;

  newsplit(&par);		/* vnum */

  if (par[0])
    vlocalhub = atoi(newsplit(&par));
  if (par[0])
    vbuildts = atol(newsplit(&par));
  if (par[0])
    vcommit = newsplit(&par);
  if (par[0])
    vversion = newsplit(&par);

  if (in_chain(bot))
    updatebot(idx, bot, x, vlocalhub, vbuildts, vcommit, vversion);
}
Esempio n. 2
0
/* Bot next share?
 */
static void bot_update(int idx, char *par)
{
  char *bot, x;
  int vnum;

  bot = newsplit(&par);
  x = par[0];
  if (x)
    par++;
#ifndef NO_OLD_BOTNET
  if (dcc[idx].u.bot->numver < NEAT_BOTNET)
    vnum = atoi(par);
  else
#endif
    vnum = base64_to_int(par);
  if (in_chain(bot))
    updatebot(idx, bot, x, vnum);
}
Esempio n. 3
0
struct feature *pick_feature(struct id3_node *root){
  struct feature *f;
  struct feature *top=NULL;
  double highest=0;
  if(depth(root)>9){
    return NULL;
  }
  for(f=get_features();f!=NULL;f=f->hh.next){
    double gain=0;
    if(f->count<50) continue;
    if(in_chain(f,root)) continue;
    gain=expected_change(&root->score,f);
    if(gain>highest){
      top=f;
      highest=gain;
    }
  }
  
  return top;
}
Esempio n. 4
0
/* Newbot next share?
 */
static void bot_nlinked(int idx, char *par)
{
  char *newbot = NULL, *next = NULL, *p = NULL, s[1024] = "", x = 0, *vversion = NULL, *vcommit = NULL;
  int i, vlocalhub = 0;
  time_t vbuildts = 0L;
  bool bogus = 0;

  newbot = newsplit(&par);
  next = newsplit(&par);
  s[0] = 0;
  if (!next[0]) {
    putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)", dcc[idx].nick);
    simple_snprintf(s, sizeof(s), "Disconnected %s (invalid bot)", dcc[idx].nick);
    dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
  } else if ((in_chain(newbot)) || (!strcasecmp(newbot, conf.bot->nick))) {
    /* Loop! */
    putlog(LOG_BOTS, "*", "Loop detected %s (mutual: %s)", dcc[idx].nick, newbot);
    simple_snprintf(s, sizeof(s), "Detected loop: two bots exist named %s: disconnecting %s", newbot, dcc[idx].nick);
    dprintf(idx, "error Loop (%s)\n", newbot);
  }
  if (!s[0]) {
    for (p = newbot; *p; p++)
      if ((*p < 32) || (*p == 127))
	bogus = 1;
    i = nextbot(next);
    if (i != idx)
      bogus = 1;

    if (bogus) {
      putlog(LOG_BOTS, "*", "Bogus link notice from %s!  (%s -> %s)", dcc[idx].nick, next, newbot);
      simple_snprintf(s, sizeof(s), "Bogus link notice from: %s Disconnected", dcc[idx].nick);
      dprintf(idx, "error Bogus link notice from (%s -> %s)\n", next, newbot);
    }
  }

  if (s[0]) {
    chatout("*** %s\n", s);
    botnet_send_unlinked(idx, dcc[idx].nick, s);
    dprintf(idx, "bye %s\n", s);
    killsock(dcc[idx].sock);
    lostdcc(idx);
    return;
  }
  x = par[0];
  if (x)
    par++;
  else
    x = '-';

  if (par[0])
    newsplit(&par);		/* vnum */
  if (par[0])
    vlocalhub = atoi(newsplit(&par));
  if (par[0])
    vbuildts = atol(newsplit(&par));
  if (par[0])
    vcommit = newsplit(&par);
  if (par[0])
    vversion = newsplit(&par);
  botnet_send_nlinked(idx, newbot, next, x, vlocalhub, vbuildts, vcommit, vversion);
  
  if (x == '!') {
    if (conf.bot->hub)
      chatout("*** (%s) %s %s.\n", next, "Linked to", newbot);
    else
      chatout("*** %s linked to botnet.\n", newbot);
    x = '-';
  }
  addbot(newbot, dcc[idx].nick, next, x, vlocalhub, vbuildts, vcommit, vversion ? vversion : (char *) "");
}
Esempio n. 5
0
/* Newbot next share?
 */
static void bot_nlinked(int idx, char *par)
{
  char *newbot, *next, *p, s[1024], x;
  int bogus = 0, i;
  struct userrec *u;

  newbot = newsplit(&par);
  next = newsplit(&par);
  s[0] = 0;
  if (!next[0]) {
    putlog(LOG_BOTS, "*", "Invalid eggnet protocol from %s (zapfing)",
           dcc[idx].nick);
    simple_sprintf(s, "%s %s (%s)", MISC_DISCONNECTED, dcc[idx].nick,
                   MISC_INVALIDBOT);
    dprintf(idx, "error invalid eggnet protocol for 'nlinked'\n");
  } else if ((in_chain(newbot)) || (!egg_strcasecmp(newbot, botnetnick))) {
    /* Loop! */
    putlog(LOG_BOTS, "*", "%s %s (mutual: %s)",
           BOT_LOOPDETECT, dcc[idx].nick, newbot);
    simple_sprintf(s, "%s %s: disconnecting %s", MISC_LOOP, newbot,
                   dcc[idx].nick);
    dprintf(idx, "error Loop (%s)\n", newbot);
  }
  if (!s[0]) {
    for (p = newbot; *p; p++)
      if ((*p < 32) || (*p == 127) || ((p - newbot) >= HANDLEN))
        bogus = 1;
    i = nextbot(next);
    if (i != idx)
      bogus = 1;
  }
  if (bogus) {
    putlog(LOG_BOTS, "*", "%s %s!  (%s -> %s)", BOT_BOGUSLINK, dcc[idx].nick,
           next, newbot);
    simple_sprintf(s, "%s: %s %s", BOT_BOGUSLINK, dcc[idx].nick,
                   MISC_DISCONNECTED);
    dprintf(idx, "error %s (%s -> %s)\n", BOT_BOGUSLINK, next, newbot);
  }
  if (bot_flags(dcc[idx].user) & BOT_LEAF) {
    putlog(LOG_BOTS, "*", "%s %s  (%s %s)",
           BOT_DISCONNLEAF, dcc[idx].nick, newbot, BOT_LINKEDTO);
    simple_sprintf(s, "%s %s (to %s): %s",
                   BOT_ILLEGALLINK, dcc[idx].nick, newbot, MISC_DISCONNECTED);
    dprintf(idx, "error %s\n", BOT_YOUREALEAF);
  }
  if (s[0]) {
    chatout("*** %s\n", s);
    botnet_send_unlinked(idx, dcc[idx].nick, s);
    dprintf(idx, "bye %s\n", BOT_ILLEGALLINK);
    killsock(dcc[idx].sock);
    lostdcc(idx);
    return;
  }
  x = par[0];
  if (x)
    par++;
  else
    x = '-';
#ifndef NO_OLD_BOTNET
  if (dcc[idx].u.bot->numver < NEAT_BOTNET)
    i = atoi(par);
  else
#endif
    i = base64_to_int(par);
  botnet_send_nlinked(idx, newbot, next, x, i);
  if (x == '!') {
    chatout("*** (%s) %s %s.\n", next, NET_LINKEDTO, newbot);
    x = '-';
  }
  addbot(newbot, dcc[idx].nick, next, x, i);
  check_tcl_link(newbot, next);
  u = get_user_by_handle(userlist, newbot);
  if (bot_flags(u) & BOT_REJECT) {
    botnet_send_reject(idx, botnetnick, NULL, newbot, NULL, NULL);
    putlog(LOG_BOTS, "*", "%s %s %s %s", BOT_REJECTING,
           newbot, MISC_FROM, dcc[idx].nick);
  }
}
Esempio n. 6
0
/* link to another bot */
int botlink(char *linker, int idx, char *nick)
{
  struct bot_addr *bi;
  struct userrec *u;
  register int i;

  Context;
  u = get_user_by_handle(userlist, nick);
  if (!u || !(u->flags & USER_BOT)) {
    if (idx >= 0)
      dprintf(idx, "%s %s\n", nick, BOT_BOTUNKNOWN);
  } else if (!strcasecmp(nick, botnetnick)) {
    if (idx >= 0)
      dprintf(idx, "%s\n", BOT_CANTLINKMYSELF);
  } else if (in_chain(nick) && (idx != -3)) {
    if (idx >= 0)
      dprintf(idx, "%s\n", BOT_ALREADYLINKED);
  } else {
    for (i = 0; i < dcc_total; i++)
      if ((dcc[i].user == u) &&
	  ((dcc[i].type == &DCC_FORK_BOT) ||
	   (dcc[i].type == &DCC_BOT_NEW))) {
	if (idx >= 0)
	  dprintf(idx, "%s\n", BOT_ALREADYLINKING);
	return 0;
      }
    /* address to connect to is in 'info' */
    bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
    if (!bi || !strlen(bi->address) || !bi->telnet_port) {
      if (idx >= 0) {
	dprintf(idx, "%s '%s'.\n", BOT_NOTELNETADDY, nick);
	dprintf(idx, "%s .chaddr %s %s\n",
		MISC_USEFORMAT, nick, MISC_CHADDRFORMAT);
      }
    } else if (dcc_total == max_dcc) {
      if (idx >= 0)
	dprintf(idx, "%s\n", DCC_TOOMANYDCCS1);
    } else {
      Context;
      correct_handle(nick);
      i = new_dcc(&DCC_FORK_BOT, sizeof(struct bot_info));

      dcc[i].port = bi->telnet_port;
      strcpy(dcc[i].nick, nick);
      strcpy(dcc[i].host, bi->address);
      dcc[i].timeval = now;
      strcpy(dcc[i].u.bot->linker, linker);
      strcpy(dcc[i].u.bot->version, "(primitive bot)");
      if (idx > -2)
	putlog(LOG_BOTS, "*", "%s %s at %s:%d ...", BOT_LINKING, nick,
	       bi->address, bi->telnet_port);
      dcc[i].u.bot->numver = idx;
      dcc[i].timeval = now;
      dcc[i].u.bot->port = dcc[i].port;		/* remember where i started */
      dcc[i].sock = getsock(SOCK_STRONGCONN);
      dcc[i].user = u;
      if (open_telnet_raw(dcc[i].sock, bi->address, dcc[i].port) < 0)
	failed_link(i);
      return 1;
    }
  }
  return 0;
}
Esempio n. 7
0
static int 
ProcessDocs (query_data * qd, int num, int verbatim,
	     char OutputType, FILE * Output)
{
  int max_buf = 0;
  int DocCount = 0;
  char *doc_sepstr = NULL;
  char *para_sepstr = NULL;
  char *para_start = NULL;
  int heads_length = atoi (GetDefEnv ("heads_length", "50"));
  char QueryType = get_query_type ();
  int need_text = (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE ||
	       OutputType == OUTPUT_HEADERS || OutputType == OUTPUT_SILENT);

  if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE)
    {
      if (QueryType == QUERY_APPROX || QueryType == QUERY_RANKED)
	{
	  doc_sepstr = de_escape_string (
				    Xstrdup (GetDefEnv ("ranked_doc_sepstr",
			   "---------------------------------- %n %w\\n")));
	}
      else
	{
	  doc_sepstr = de_escape_string (
					  Xstrdup (GetDefEnv ("doc_sepstr",
			      "---------------------------------- %n\\n")));
	}
      para_sepstr = de_escape_string (
				       Xstrdup (GetDefEnv ("para_sepstr",
				  "\\n######## PARAGRAPH %n ########\\n")));

      para_start = de_escape_string (
				      Xstrdup (GetDefEnv ("para_start",
					    "***** Weight = %w *****\\n")));
    }

  if (need_text)
    {
      max_buf = atoi (GetDefEnv ("buffer", "1048576"));
    }

  do
    {
      u_char *UDoc = NULL;
      unsigned long ULen;

      if (need_text)
	{
	  /* load the compressed text */
	  if (LoadCompressedText (qd, max_buf))
	    {
	      Message ("Unable to load compressed text.");
	      FatalError (1, "This is probably due to lack of memory.");
	    }

	  /* uncompress the loaded text */
	  UDoc = GetDocText (qd, &ULen);
	  if (UDoc == NULL)
	    FatalError (1, "UDoc is unexpectedly NULL");
	}


      if (!UDoc || PostProc ((char *) UDoc, verbatim))
	{
	  switch (OutputType)
	    {
	    case OUTPUT_COUNT:
	    case OUTPUT_SILENT:
	      break;
	    case OUTPUT_DOCNUMS:	/* This prints out the docnums string */
	      if (PagerRunning)
		fprintf (Output, "%8d   %6.4f   %7lu\n", GetDocNum (qd),
			 GetDocWeight (qd), GetDocCompLength (qd));
	      break;
	    case OUTPUT_HEADERS:	/* This prints out the headers of the documents */
	      if (PagerRunning)
		fprintf (Output, "%d ", GetDocNum (qd));
	      HeaderOut (Output, UDoc, ULen, heads_length);
	      if (PagerRunning)
		fputc ('\n', Output);
	      break;
#if TREC_MODE
	    case OUTPUT_EXTRAS:	/* This prints out the docnums string */
	      if (PagerRunning && trec_ids)
		{
		  long DN, PN = GetDocNum (qd) - 1;
		  if (trec_paras)
		    DN = trec_paras[PN];
		  else
		    DN = PN;
		  fprintf (Output, "%-14.14s  %8ld  %10.5f\n",
			   &trec_ids[DN * 14], PN + 1, GetDocWeight (qd));
		}
	      break;
#endif
	    case OUTPUT_TEXT:
	    case OUTPUT_HILITE:
	      {
		int j, para = -1, curr_para = 0;
		int init_para = -1;
		DocEntry *de, *doc_chain = NULL;
		int p_on = 0;
		register char ch = ' ';
		register char lch = '\n';
		if (PagerRunning)
		  {
		    StringOut (Output, doc_sepstr,
			       1, GetDocNum (qd),
			       QueryType == 'A' || QueryType == 'R',
			       GetDocWeight (qd));
		  }
		if (qd->id->ifh.InvfLevel == 3)
		  {
		    init_para = FetchInitialParagraph (qd->td, GetDocNum (qd));
		    doc_chain = GetDocChain (qd);
		    para = GetDocNum (qd) - init_para;

		    StringOut (Output, para_sepstr,
			       1, curr_para + 1,
			       0, 0);

		    if ((de = in_chain (0, init_para, doc_chain)))
		      StringOut (Output, para_start,
				 0, 0,
				 1, de->Weight);

		    if (doc_chain->DocNum - init_para == 0)
		      p_on = 1;
		  }
		for (j = 0; j < ULen; j++)
		  {
		    ch = UDoc[j];
		    switch (ch)
		      {
		      case '\02':
			break;
		      case '\01':
			ch = '\n';
		      case '\03':
			p_on = 0;
			curr_para++;
			StringOut (Output, para_sepstr,
				   1, curr_para + 1,
				   0, 0);
			lch = *(strchr (para_sepstr, '\0') - 1);
			if ((de = in_chain (curr_para, init_para, doc_chain)))
			  StringOut (Output, para_start,
				     0, 0,
				     1, de->Weight);
			if (doc_chain &&
			    doc_chain->DocNum - init_para == curr_para)
			  p_on = 1;
			break;
		      default:
			{
			  if (PagerRunning)
			    {
			      fputc (ch, Output);
			      if (p_on && isprint (ch))
				{
				  fputc ('\b', Output);
				  fputc ('_', Output);
				}
			    }

			  lch = ch;
			}
		      }
		  }
		if (PagerRunning && lch != '\n')
		  fputc ('\n', Output);
		p_on = 0;
	      }
	    }
	  if (PagerRunning)
	    fflush (Output);
	}
      DocCount++;

    }
  while (NextDoc (qd) && PagerRunning && (!Ctrl_C));

  if (need_text)
    {
      FreeTextBuffer (qd);
    }

  if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE)
    {
      Xfree (doc_sepstr);
      Xfree (para_sepstr);
      Xfree (para_start);
    }

  return (DocCount);
}