Esempio n. 1
0
void rehash_ip() {
  /* cache our ip on load instead of every 30 seconds */
  char *ip4 = NULL, *ip6 = NULL;

  if (cached_ip) {
    ip4 = strdup(myipstr(AF_INET));
    ip6 = strdup(myipstr(AF_INET6));
  }

  cache_my_ip();
  sdprintf("ip4: %s", myipstr(AF_INET));
  sdprintf("ip6: %s", myipstr(AF_INET6));

  /* Check if our ip changed during a rehash */
  if (ip4) {
    if (strcmp(ip4, myipstr(AF_INET)) || strcmp(ip6, myipstr(AF_INET6))) {
      if (tands > 0) {
        botnet_send_chat(-1, conf.bot->nick, "IP changed.");
        botnet_send_bye("IP changed.");
      }
      fatal("brb", 1);
    }

    free(ip4);
    free(ip6);
  }

  if (conf.bot->hub) {
    struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, conf.bot->u);
    listen_all(bi->telnet_port, 0, 1);
    my_port = bi->telnet_port;
  } else if (conf.bot->localhub) {
    // If not listening on the domain socket, open it up
    bool listening = 0;
    for (int i = 0; i < dcc_total; i++) {
      if (dcc[i].type && (dcc[i].type == &DCC_TELNET) && (!strcmp(dcc[i].host, conf.localhub_socket)) && (!strcmp(dcc[i].nick, "(unix_domain"))) {
        listening = 1;
        break;
      }
    }
    if (!listening) {
      // Listen on the unix domain socket
      port_t port;
      int i = open_listen_addr_by_af(conf.localhub_socket, &port, AF_UNIX);
      if (i < 0) {
        putlog(LOG_ERRORS, "*", "Can't listen on %s - %s", conf.localhub_socket, i == -1 ? "it's taken." : "couldn't assign file.");
      } else {
        /* now setup dcc entry */
        int idx = new_dcc(&DCC_TELNET, 0);
        dcc[idx].addr = 0L;
        strlcpy(dcc[idx].host, conf.localhub_socket, sizeof(dcc[idx].host));
        dcc[idx].port = 0;
        dcc[idx].sock = i;
        dcc[idx].timeval = now;
        strlcpy(dcc[idx].nick, "(unix_domain)", sizeof(dcc[idx].nick));
        putlog(LOG_DEBUG, "*", "Listening on telnet %s", conf.localhub_socket);
      }
    }
  }
}
Esempio n. 2
0
int runVM() {
    int reasonOfLeaving = setjmp(jmpBufEnter);
    
    sdprintf("runVM2");
	if (reasonOfLeaving == 0) {
     	printPhaseTime(2);
		interpret();
        sdprintf("interpret");
    }
	return reasonOfLeaving;
}
Esempio n. 3
0
static void
dns_reinit(int idx)
{
        sdprintf("Re-opening dns socket...");
        killsock(dcc[idx].sock);
        lostdcc(idx);
	dns_idx = -1;
        dns_sock = -1;
	dns_ip = NULL;

        if (!get_dns_idx())
          sdprintf("Successfully reopened dns socket");
        else
          sdprintf("Failed to reopen dns socket");
}
Esempio n. 4
0
static void add_dns_server(char *ip)
{
	servers = (dns_server_t *) my_realloc(servers, (nservers+1)*sizeof(*servers));
	servers[nservers].ip = strdup(ip);
	nservers++;
        sdprintf("Added NS: %s", ip);
}
Esempio n. 5
0
static void got_alarm(int z)
{
  sdprintf("SIGALARM");
  longjmp(alarmret, 1);

  /* -Never reached- */
}
Esempio n. 6
0
static void dns_on_eof(int idx)
{
        sdprintf("EOF on dns idx: %d sock: %d (%s)", idx, dcc[idx].sock, dcc[idx].host);
        dns_reinit(idx);

	return;
}
Esempio n. 7
0
static bool check_tempdir(bool do_mod)
{
  mkdir_p(tempdir);

  if (!can_stat(tempdir))
    return 0;

  if (do_mod && fixmod(tempdir))
    return 0;

  /* test tempdir: it's vital */
  Tempfile *testdir = new Tempfile("test");

  /* There was an error creating a file in this directory, return to move on in list of dirs */
  if (!testdir || testdir->error) {
    if (testdir)
      delete testdir;
    return 0;
  }

  fprintf(testdir->f, "\n");
  int result = fflush(testdir->f);
  delete testdir;
  if (result) {
    sdprintf("%s: %s", tempdir, strerror(errno));
    return 0;
  }
  return 1;
}
Esempio n. 8
0
//static int dns_on_read(void *client_data, int idx, char *buf, int len)
static void dns_on_read(int idx, char *buf, int atr)
{
        dcc[idx].timeval = now;

//	if (resend_on_read) {
//		resend_on_read = 0;
//		dns_resend_queries();
//		return;
//	}

        atr = read(dcc[idx].sock, buf, 512);

        if (atr == -1) {
          if (errno == EAGAIN)
            atr = read(dcc[idx].sock, buf, 512);
          if (atr == -1) {
            dns_on_eof(idx);
            return;
          }
        }
        sdprintf("SETTING TIMEOUT to 0");
        dns_handler.timeout_val = 0;
	if (parse_reply(buf, atr))
          dns_on_eof(idx);
	return;
}
Esempio n. 9
0
bool valid_dns_id(int idx, int id)
{
  if (id == -1)
    return 1;
  if (valid_idx(idx) && dcc[idx].dns_id && dcc[idx].dns_id == id)
    return 1;
  sdprintf("dns_id: %d is not associated with dead idx: %d", id, idx);
  return 0;
}
Esempio n. 10
0
static void
dns_timeout(int idx)
{
  sdprintf("DNS socket timed out");
  /*egg_dns_cancel(dcc[idx].u.dns_id, 1);*/
//  resend_on_read = 1;
  dns_reinit(idx);  
//  sleep(2);
//  dns_resend_queries();
}
Esempio n. 11
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;
}
Esempio n. 12
0
/* Perform an async dns lookup. This is host -> ip. For ip -> host, use
 * egg_dns_reverse(). We return a dns id that you can use to cancel the
 * lookup. */
int egg_dns_lookup(const char *host, interval_t timeout, dns_callback_t callback, void *client_data)
{
	dns_query_t *q = NULL;
	int i, cache_id;

	sdprintf("egg_dns_lookup(%s, %d)", host, timeout);

	if (is_dotted_ip(host)) {
		/* If it's already an ip, we're done. */
		dns_answer_t answer;

		answer_init(&answer);
		answer_add(&answer, host);
		callback(-1, client_data, host, answer.list);
		answer_free(&answer);
		return(-1);
	}

	/* Ok, now see if it's in our host cache. */
	for (i = 0; i < nhosts; i++) {
		if (!egg_strcasecmp(host, hosts[i].host)) {
			dns_answer_t answer;

			answer_init(&answer);
			answer_add(&answer, hosts[i].ip);
			callback(-1, client_data, host, answer.list);
			answer_free(&answer);
			return(-1);
		}
	}

	cache_id = cache_find(host);
	if (cache_id >= 0) {
		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
		callback(-1, client_data, host, cache[cache_id].answer.list);
		return(-1);
	}

	/* check if the query was already made */
        if (find_query(host))
          return(-2);

	/* Allocate our query struct. */
        q = alloc_query(client_data, callback, host);

        dns_send_query(q);

//        /* setup a timer to detect dead ns */
//	dns_create_timeout_timer(&q, host, timeout);

	/* Send the ipv4 query. */

	return(q->id);
}
Esempio n. 13
0
void egg_dns_send(char *query, int len)
{
        if (dns_idx >= 0 && dcc[dns_idx].sock == -1) {
          lostdcc(dns_idx);
          dns_idx = -1;
        }
	if (dns_idx < 0) {
		if (get_dns_idx()) {
                  sdprintf("get_dns_idx() failed in egg_dns_send");
                  return;
                }
	}
        if (!dns_handler.timeout_val) {
          dns_handler.timeout_val = &async_server_timeout;
          sdprintf("SETTING TIMEOUT to %d", async_server_timeout);
          dcc[dns_idx].timeval = now;
        }
        write(dcc[dns_idx].sock, query, len);
//	sockbuf_write(dns_idx, query, len);
}
Esempio n. 14
0
static int get_dns_idx()
{
	int i, sock;
       
	sock = -1;
	for (i = 0; i < nservers; i++) {
		if (!dns_ip) dns_ip = dns_next_server();
		sock = socket_create(dns_ip, DNS_PORT, NULL, 0, SOCKET_CLIENT | SOCKET_NONBLOCK | SOCKET_UDP);
		if (sock < 0) {
			/* Try the next server. */
			dns_ip = NULL;
		}
		else break;
	}
	if (i == nservers) return 1;
//	dns_idx = sockbuf_new();
//	sockbuf_set_handler(dns_idx, &dns_handler, NULL);
//	sockbuf_set_sock(dns_idx, sock, 0);
//        allocsock(sock, SOCK_CONNECT);

        if (sock >= 0 && dns_ip) {
          dns_idx = new_dcc(&dns_handler, 0);

          if (dns_idx < 0) {
           putlog(LOG_SERV, "*", "NO MORE DCC CONNECTIONS -- Can't create dns connection.");
           killsock(sock);
           return 1;
          }
          sdprintf("dns_idx: %d", dns_idx);
          dcc[dns_idx].sock = sock;
          dns_sock = sock;
          sdprintf("dns_sock: %d", dcc[dns_idx].sock);
          strlcpy(dcc[dns_idx].host, dns_ip, UHOSTLEN);
          strlcpy(dcc[dns_idx].nick, "(adns)", NICKLEN);
          sdprintf("dns_ip: %s", dns_ip);
          dcc[dns_idx].timeval = now;
          dns_handler.timeout_val = 0;
          return 0;
        }
	return 1;
}
Esempio n. 15
0
extern "C" void xprintf(const char *str, ...)
{
	if(Options.sdgecko)
		sdprintf(str);

	if(Options.wifigecko)
		wifi_printf(str);

	if(!Options.wifigecko && !Options.sdgecko)
		gprintf(str);

}
Esempio n. 16
0
void chanprog()
{
  struct utsname un;


  sdprintf("I am: %s", conf.bot->nick);

  /* Add the 'default' virtual channel.
     The flags will be overwritten when the userfile is loaded,
     but if there is no userfile yet, or no 'default' channel,
     then it will take on the properties of 'def_chanset',
     and then later save this to the userfile.
   */
  channel_add(NULL, "default", def_chanset, 1);

  if (conf.bot->hub) {
    simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
    loading = 1;
    checkchans(0);
    readuserfile(userfile, &userlist);
    checkchans(1);
    var_parse_my_botset();
    loading = 0;
  }

  load_internal_users();

  add_myself_to_userlist();

  if (conf.bot->localhub)
    add_child_bots();
  else if (!conf.bot->hub)
    add_localhub();

  rehash_ip();

  /* set our shell info */
  uname(&un);
  set_user(&USERENTRY_OS, conf.bot->u, un.sysname);
  set_user(&USERENTRY_USERNAME, conf.bot->u, conf.username);
  set_user(&USERENTRY_NODENAME, conf.bot->u, un.nodename);
  set_user(&USERENTRY_ARCH, conf.bot->u, un.machine);
  set_user(&USERENTRY_OSVER, conf.bot->u, un.release);

  var_parse_my_botset();

  /* We should be safe now */

  reaffirm_owners();
}
Esempio n. 17
0
static void got_cjoin(char *botnick, char *code, char *par)
{
  if (!par[0])
   return;

  char *chname = newsplit(&par), *options = NULL;
  struct chanset_t *chan = findchan_by_dname(chname);
  int match = 0;

  if (conf.bot->hub) {
    newsplit(&par);	/* hubs ignore the botmatch param */
    options = par;
  } else {
    /* ALL hubs should add the channel, leaf should check the list for a match */
    bool inactive = 0;
    char *bots = newsplit(&par);
    match = parsebots(bots, conf.bot->nick);

    if (strstr(par, "+inactive"))
      inactive = 1;

    if (chan && !match)
      return;

    if (!match) {
      size_t size = strlen(par) + 12 + 1;

      options = (char *) my_calloc(1, size);
      simple_snprintf(options, size, "%s +inactive", par);
    } else if (match && chan && !shouldjoin(chan)) {
      if (!inactive)
        do_chanset(NULL, chan, "-inactive", DO_LOCAL);
      return;
    } else
      options = par;
  }

  if (chan)
    return;
sdprintf("OPTIONS: %s", options);
  char result[RESULT_LEN] = "";

  if (channel_add(result, chname, options) == ERROR) /* drummer */
    putlog(LOG_BOTS, "@", "Invalid channel or channel options from %s for %s: %s", botnick, chname, result);
  if (conf.bot->hub)
    write_userfile(-1);
  if (!match && !conf.bot->hub)
    free(options);
}
Esempio n. 18
0
void check_maxfiles()
{
  int sock = -1, sock1 = -1 , bogus = 0, failed_close = 0;

#ifdef USE_IPV6
  sock1 = getsock(0, AF_INET);		/* fill up any lower avail */
  sock = getsock(0, AF_INET);
#else
  sock1 = getsock(0);
  sock = getsock(0);
#endif

  if (sock1 != -1)
    killsock(sock1);
  
  if (sock == -1) {
    return;
  } else
    killsock(sock);

  bogus = sock - socks_total - 4;	//4 for stdin/stdout/stderr/dns 
 
  if (bogus >= 50) {			/* Attempt to close them */
    sdprintf("SOCK: %d BOGUS: %d SOCKS_TOTAL: %d", sock, bogus, socks_total);

    for (int i = 10; i < sock; i++)	/* dont close lower sockets, they're probably legit */
      if (!findanysnum(i)) {
        if ((close(i)) == -1)			/* try to close the BOGUS fd (likely a KQUEUE) */
          failed_close++;
        else
          bogus--;
      }
    if (bogus >= 150 || failed_close >= 50) {
      if (tands > 0) {
        botnet_send_chat(-1, conf.bot->nick, "Max FD reached, restarting...");
        botnet_send_bye("Max FD reached, restarting...");
      }

      nuke_server("brb");
      cycle_time = 0;
      restart(-1);
    } else if (bogus >= 100 && (bogus % 10) == 0) {
      putlog(LOG_WARN, "*", "* WARNING: $b%d$b bogus file descriptors detected, auto restart at 150", bogus);
    }
  }
}
Esempio n. 19
0
int egg_dns_cancel(int id, int issue_callback)
{
	dns_query_t *q, *prev = NULL;

	for (q = query_head; q; q = q->next) {
		if (q->id == id) break;
		prev = q;
	}
	if (!q) return(-1);
	if (prev) prev->next = q->next;
	else query_head = q->next;
	sdprintf("Cancelling query: %s", q->query);
	if (issue_callback) q->callback(q->id, q->client_data, q->query, NULL);
	if (q->ip)
		free(q->ip);
	free(q->query);
	free(q);
	return(0);
}
Esempio n. 20
0
void clear_tmp()
{
  if (!clear_tmpdir)
    return;

  DIR *tmp = NULL;

  if (!(tmp = opendir(tempdir))) 
    return;

  struct dirent *dir_ent = NULL;
  char *file = NULL;
  size_t flen = 0;

  while ((dir_ent = readdir(tmp))) {
    if (strncmp(dir_ent->d_name, ".pid.", 4) && 
        strncmp(dir_ent->d_name, ".u", 2) && 
        strcmp(dir_ent->d_name, ".bin.old") && 
        strncmp(dir_ent->d_name, STR(".socks-"), 7) &&
        strcmp(dir_ent->d_name, ".") && 
        strcmp(dir_ent->d_name, ".un") && 
        strcmp(dir_ent->d_name, "..")) {

      flen = strlen(dir_ent->d_name) + strlen(tempdir) + 1;
      file = (char *) my_calloc(1, flen);

      strlcat(file, tempdir, flen);
      strlcat(file, dir_ent->d_name, flen);
      file[strlen(file)] = 0;
      sdprintf("clear_tmp: %s", file);
      unlink(file);
      free(file);
    }
  }
  closedir(tmp);
  return;
}
Esempio n. 21
0
void werr(int errnum)
{
/* [1]+  Done                    ls --color=auto -A -CF
   [1]+  Killed                  bash
*/
/*
  int x = 0;
  unsigned long job = randint(2) + 1; */

/*  printf("[%lu] %lu%lu%lu%lu%lu\n", job, randint(2) + 1, randint(8) + 1, randint(8) + 1, errnum); */

/*    printf("\n[%lu]+  Killed                  rm -rf /\r\n", job); */
  /*
  if (checkedpass) {
    printf("[%lu] %d\n", job, getpid());
  }
  */
  /*  printf("\n[%lu]+  Stopped                 %s\r\n", job, basename(binname)); */
  sdprintf(STR("Error %d: %s"), errnum, werr_tostr(errnum));
  printf(STR("*** Error code %d\n\n"), errnum);
  printf(STR("Segmentation fault\n"));
  fatal("", 0);
  exit(0);				//gcc is stupid :)
}
Esempio n. 22
0
static int parse_reply(char *response, size_t nbytes)
{
	dns_header_t header;
	dns_query_t *q = NULL, *prev = NULL;
	dns_rr_t reply;
	char result[512] = "";
	short rr;
	int r = -1;
	unsigned const char *eop = (unsigned char *) response + nbytes;
	unsigned char *ptr = (unsigned char *) response;

	egg_memcpy(&header, ptr, HEAD_SIZE);
	ptr += HEAD_SIZE;

	/* header.id is already in our order, echoed by the server */
	header.flags = ntohs(header.flags);
	header.question_count = ntohs(header.question_count);
	header.answer_count = ntohs(header.answer_count);
	header.ar_count = ntohs(header.ar_count);
	header.ns_count = ntohs(header.ns_count);

//	print_header(header);

	/* Find our copy of the query before proceeding. */
	for (q = query_head; q; q = q->next) {
		if (q->id == header.id) break;
		prev = q;
	}
	if (!q) return 0;
        
//        /* destroy our async timeout */
//        timer_destroy(q->timer_id);

	/* Pass over the questions. */
	for (rr = 0; rr < header.question_count; rr++) {
		ptr += skip_name(ptr);
		ptr += 4;
	}
	/* End of questions. */

//	for (rr = 0; rr < header.answer_count + header.ar_count + header.ns_count; rr++) {


	q->answers += header.answer_count;

	for (rr = 0; rr < header.answer_count; rr++) {
		result[0] = 0;
		/* Read in the answer. */
		ptr += skip_name(ptr);

		egg_memcpy(&reply, ptr, RR_SIZE);
		ptr += RR_SIZE;

		reply.type = ntohs(reply.type);
		reply.dclass = ntohs(reply.dclass);
		reply.rdlength = ntohs(reply.rdlength);
		reply.ttl = ntohl(reply.ttl);
		/* Save the lowest ttl */
		if (reply.ttl && ((!q->answer.ttl) || (q->answer.ttl > reply.ttl))) q->answer.ttl = reply.ttl;

//		print_reply(reply);

		switch (reply.type) {
		case DNS_A:
			egg_inet_ntop(AF_INET, ptr, result, 512);
			answer_add(&q->answer, result);
			break;
		case DNS_AAAA:
#ifdef USE_IPV6
			egg_inet_ntop(AF_INET6, ptr, result, 512);
			answer_add(&q->answer, result);
#endif /* USE_IPV6 */
			break;
		case DNS_PTR:
			r = my_dn_expand((const unsigned char *) response, eop, ptr, result, sizeof(result));

			if (r != -1 && result[0])
				answer_add(&q->answer, result);
			break;
		default:
			sdprintf("Unhandled DNS reply type: %d", reply.type);
			break;
		}

		ptr += reply.rdlength;
                if ((size_t) (ptr - (unsigned char*) response) > nbytes) {
                  sdprintf("MALFORMED/TRUNCATED DNS PACKET detected (need TCP).");
                  q->remaining = 0;
                  break;
                }
	}
	/* Don't continue if we haven't gotten all expected replies. */
	if (--q->remaining > 0) return 0;

        if (q->answer.len == 0) {
          sdprintf("Failed to get any answers for query");

          if (prev) prev->next = q->next;
          else query_head = q->next;

          q->callback(q->id, q->client_data, q->query, NULL);

          free(q->query);
          if (q->ip)
            free(q->ip);
          free(q);
          return 1;		/* get a new server */
        }

	/* Ok, we have, so now issue the callback with the answers. */
	if (prev) prev->next = q->next;
	else query_head = q->next;

	cache_add(q->query, &q->answer);

	q->callback(q->id, q->client_data, q->query, q->answer.list);
	answer_free(&q->answer);
	free(q->query);
        if (q->ip)
          free(q->ip);
	free(q);

	return(0);
}
Esempio n. 23
0
sd_ptr cb_parameters::get_filesdat_path( char *path_buf, size_t bufsz )
{
    // shouldn't we check if filesdat is absolute or relative? -- sgy 20150119
    return sdprintf( path_buf, bufsz, "%s/%s", datpath, filesdat );
}
Esempio n. 24
0
/* Perform an async dns reverse lookup. This does ip -> host. For host -> ip
 * use egg_dns_lookup(). We return a dns id that you can use to cancel the
 * lookup. */
int egg_dns_reverse(const char *ip, interval_t timeout, dns_callback_t callback, void *client_data)
{
	dns_query_t *q;
	int i, cache_id;

	sdprintf("egg_dns_reverse(%s, %d)", ip, timeout);

	if (!is_dotted_ip(ip)) {
		/* If it's not a valid ip, don't even make the request. */
		callback(-1, client_data, ip, NULL);
		return(-1);
	}

	/* Ok, see if we have it in our host cache. */
	for (i = 0; i < nhosts; i++) {
		if (!egg_strcasecmp(hosts[i].ip, ip)) {
			dns_answer_t answer;

			answer_init(&answer);
			answer_add(&answer, hosts[i].host);
			callback(-1, client_data, ip, answer.list);
			answer_free(&answer);
			return(-1);
		}
	}

	cache_id = cache_find(ip);
        if (cache_id >= 0) {
		shuffleArray(cache[cache_id].answer.list, cache[cache_id].answer.len);
		callback(-1, client_data, ip, cache[cache_id].answer.list);
		return(-1);
	}

	/* check if the query was already made */
        if (find_query(ip))
          return(-1);

	q = alloc_query(client_data, callback, ip);

	/* We need to transform the ip address into the proper form
	 * for reverse lookup. */
	if (strchr(ip, ':')) {
		char temp[128] = "";

		socket_ipv6_to_dots(ip, temp);
sdprintf("dots: %s", temp);
		size_t iplen = strlen(temp) + 9 + 1;
		q->ip = (char *) my_calloc(1, iplen);
//		reverse_ip(temp, q->ip);
		strlcat(q->ip, temp, iplen);
		strlcat(q->ip, "ip6.arpa", iplen);
sdprintf("reversed ipv6 ip: %s", q->ip);
	}
	else {
		size_t iplen = strlen(ip) + 13 + 1;
		q->ip = (char *) my_calloc(1, iplen);
		reverse_ip(ip, q->ip);
		strlcat(q->ip, ".in-addr.arpa", iplen);
	}

        dns_send_query(q);

//	/* setup timer to detect dead ns */
//	dns_create_timeout_timer(&q, ip, timeout);

	return(q->id);
}
Esempio n. 25
0
int primNativeLog(char *fmt) {
    return sdprintf(fmt);
}
Esempio n. 26
0
File: misc.c Progetto: kirune/wraith
void
restart(int idx)
{
  const char *reason = updating ? STR("Updating...") : STR("Restarting...");
  Tempfile *socks = new Tempfile("socks");
  int fd = 0;

  sdprintf("%s", reason); 

  if (tands > 0) {
    botnet_send_chat(-1, conf.bot->nick, (char *) reason);
    botnet_send_bye(reason);
  }

  /* kill all connections except STDOUT/server */
  for (fd = 0; fd < dcc_total; fd++) {
    if (dcc[fd].type && dcc[fd].type != &SERVER_SOCKET && dcc[fd].sock != STDOUT) {
      if (dcc[fd].sock >= 0)
        killsock(dcc[fd].sock);
      lostdcc(fd);
    }
  }

  const char salt1[] = SALT1;
  EncryptedStream stream(salt1);

  /* write out all leftover dcc[] entries */
  for (fd = 0; fd < dcc_total; fd++)
    if (dcc[fd].type && dcc[fd].sock != STDOUT)
      dcc_write(stream, fd);

  /* write out all leftover socklist[] entries */
  for (fd = 0; fd < MAXSOCKS; fd++)
    if (socklist[fd].sock != STDOUT)
      sock_write(stream, fd);

  if (server_online) {
    if (botname[0])
      stream << bd::String::printf(STR("+botname %s\n"), botname);
    if (rolls)
      stream << bd::String::printf(STR("+rolls %d\n"), rolls);
    if (altnick_char)
      stream << bd::String::printf(STR("+altnick_char %c\n"), altnick_char);
    if (burst)
      stream << bd::String::printf(STR("+burst %d\n"), burst);
    if (flood_count)
      stream << bd::String::printf(STR("+flood_count %d\n"), flood_count);
    if (my_cookie_counter)
      stream << bd::String::printf(STR("+my_cookie_counter %lu\n"), my_cookie_counter);
    stream << bd::String::printf(STR("+server_online %li\n"), (long)server_online);
  }
  stream << bd::String::printf(STR("+online_since %li\n"), (long)online_since);
  if (floodless)
    stream << bd::String::printf(STR("+server_floodless %d\n"), floodless);
  if (in_deaf)
    stream << bd::String::printf(STR("+in_deaf\n"));
  if (in_callerid)
    stream << bd::String::printf(STR("+in_callerid\n"));
  for (struct chanset_t *chan = chanset; chan; chan = chan->next)
    if (shouldjoin(chan) && (channel_active(chan) || channel_pending(chan)))
      stream << bd::String::printf(STR("+chan %s\n"), chan->dname);
  stream << bd::String::printf(STR("+buildts %li\n"), (long)buildts);
  stream << bd::String::printf(STR("+ip4 %s\n"), myipstr(AF_INET));
  stream << bd::String::printf(STR("+ip6 %s\n"), myipstr(AF_INET6));
  replay_cache(-1, &stream);

  stream.writeFile(socks->fd);

  socks->my_close();

  write_userfile(idx);
/*
  if (server_online) {
    do_chanset(NULL, NULL, STR("+inactive"), DO_LOCAL);
    dprintf(DP_DUMP, STR("JOIN 0\n"));
  }
*/
  fixmod(binname);

  /* replace image now */
  char *argv[4] = { NULL, NULL, NULL, NULL };

  argv[0] = strdup(binname);

  if (!backgrd || term_z || sdebug) {
    char shit[7] = "";

    simple_snprintf(shit, sizeof(shit), STR("-%s%s%s"), !backgrd ? "n" : "", term_z ? "t" : "", sdebug ? "D" : "");
    argv[1] = strdup(shit);
    argv[2] = strdup(conf.bot->nick);
  } else {
    argv[1] = strdup(conf.bot->nick);
  }

  unlink(conf.bot->pid_file);
  FILE *fp = NULL;
  if (!(fp = fopen(conf.bot->pid_file, "w")))
    return;
  fprintf(fp, "%d %s\n", getpid(), socks->file);
  fclose(fp);

  execvp(argv[0], &argv[0]);

  /* hopefully this is never reached */
  putlog(LOG_MISC, "*", STR("Could not restart: %s"), strerror(errno));
  return;
}