コード例 #1
0
ファイル: parser.c プロジェクト: Anakros/tsocks
int read_config (char *filename, struct parsedfile *config) {
	FILE *conf;
	char line[MAXLINE];
	int rc = 0;
	int lineno = 1;
	struct serverent *server;

   /* Clear out the structure */
   memset(config, 0x0, sizeof(*config));

	/* Initialization */
   currentcontext = &(config->defaultserver);

	/* If a filename wasn't provided, use the default */
	if (filename == NULL) {
		strncpy(line, CONF_FILE, sizeof(line) - 1);
		/* Insure null termination */
		line[sizeof(line) - 1] = (char) 0;
		filename = line;
	}

	/* Read the configuration file */
	if ((conf = fopen(filename, "r")) == NULL) {
		show_msg(MSGERR, "Could not open socks configuration file "
			   "(%s), assuming all networks local\n", filename);
      handle_local(config, 0, "0.0.0.0/0.0.0.0");
		rc = 1; /* Severe errors reading configuration */
	}	
	else {
      memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));

		while (NULL != fgets(line, MAXLINE, conf)) {
			/* This line _SHOULD_ end in \n so we  */
			/* just chop off the \n and hand it on */
			if (strlen(line) > 0)
				line[strlen(line) - 1] = '\0';
			handle_line(config, line, lineno);
			lineno++;
		} 
		fclose(conf);

		/* Always add the 127.0.0.1/255.0.0.0 subnet to local */
		handle_local(config, 0, "127.0.0.0/255.0.0.0");

		/* Check default server */
		check_server(&(config->defaultserver));
		server = (config->paths);
		while (server != NULL) {
			check_server(server);
			server = server->next;
		}

	}

	return(rc);
}
static void
test_empathy_irc_server_new (void)
{
  EmpathyIrcServer *server;

  server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
  check_server (server, "test.localhost", 6667, TRUE);

  g_object_unref (server);
}
コード例 #3
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::list_channels_enable() {
	try {
		check_server();
		channels_stat_ = impl_->init_channels_stat();
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
コード例 #4
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::attach_response_handler(py::object const &impl) {
	try {
		check_server();
		boost::intrusive_ptr<response_handler> m(new python_handler(impl));
		impl_->attach_response_handler(m);
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
コード例 #5
0
int			check_select(Uint32 timeout)
{
  SOCKET		maxfd;
  int			retval;
  struct timeval	tv;
  struct timeval	before;
  struct timeval	left;
  fd_set		maskr;
  fd_set		maskw;
  int			done;

  check_dead();
  FD_ZERO(&maskr);
  FD_ZERO(&maskw);
  maxfd = fill_fd(&maskr, &maskw); 
  tv.tv_sec = timeout / 1000;
  tv.tv_usec = (timeout % 1000) * 1000;
  done = 0;
  while (!done)
    {
      cnt->select_recv = 0;
      gettimeofday(&before, NULL);
      retval = select((int)maxfd + 1, &maskr, &maskw, NULL, &tv);
      done = 0;
      if (retval > 0 && check_clients(&maskr, &maskw, &retval))
	done += 1;
      if (retval > 0 && check_server(&maskr, &maskw, &retval))
	done += 8;
      if (retval)
	{
	  if (retval < 0 && errno != EINTR)
	    fprintf(stderr, "select: %s", strerror(errno));
	  else
	    fprintf(stderr, "select: on m'aurait mentit (reste:%d) ?\n",
		    retval);
	  exit(-1);
	}
      check_dead();
      if (!timeout)
	return (done);
      gettimeofday(&left, NULL);
      left.tv_sec -= before.tv_sec;
      left.tv_usec -= before.tv_usec;
      if (cnt->select_recv &&
	  left.tv_sec < tv.tv_sec && left.tv_usec < tv.tv_usec)
	{
	  done = 0;
	  memcpy(&tv, &left, sizeof(left));
	}
    }
  return (done);
}
コード例 #6
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::init(py::object const &impl) {
	try {
		check_server();
		python_settings settings(impl);
		interpreter_thread_lock thread_lock;
		impl_->init(settings);
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
コード例 #7
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::add_connection_listener(py::object const &impl) {

	try {
		check_server();
		boost::intrusive_ptr<connection_listener> l(new python_listener(impl));
		impl_->add_connection_listener(l);
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
コード例 #8
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::attach_formatter_creator(std::string const &fmt_id, py::object const &impl) {

	try {
		check_server();
		boost::intrusive_ptr<formatter_creator> f(new python_formatter_creator(impl, cleanup_));
		impl_->attach_formatter_creator(fmt_id, f);
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
コード例 #9
0
ファイル: python_server.cpp プロジェクト: GunioRobot/xiva
void
python_server::start() {
	try {
		check_server();
		{
			interpreter_thread_lock thread_lock;
			cleanup_list_auto cleanup_auto(cleanup_);
			logger_->start();
			impl_->start();
		}
	}
	catch (std::exception const &e) {
		PyErr_SetString(PyExc_RuntimeError, e.what());
		boost::python::throw_error_already_set();
	}
}
static void
test_property_change (void)
{
  EmpathyIrcServer *server;

  server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
  g_assert (server != NULL);

  g_object_set (server,
      "address", "test2.localhost",
      "port", 6668,
      "ssl", FALSE,
      NULL);

  check_server (server, "test2.localhost", 6668, FALSE);

  g_object_unref (server);
}
コード例 #11
0
END_TEST

START_TEST (test_property_change)
{
  EmpathyIrcServer *server;

  server = empathy_irc_server_new ("test.localhost", 6667, TRUE);
  fail_if (server == NULL);

  g_object_set (server,
      "address", "test2.localhost",
      "port", 6668,
      "ssl", FALSE,
      NULL);

  check_server (server, "test2.localhost", 6668, FALSE);

  g_object_unref (server);
}
コード例 #12
0
/* work starts here */
int main (int argc, char **argv) {
    int opt;
    int result;

    mod_gm_opt = gm_malloc(sizeof(mod_gm_opt_t));
    set_default_options(mod_gm_opt);

    /*
     * and parse command line
     */
    while((opt = getopt(argc, argv, "vVhaH:t:w:c:W:C:q:s:e:p:u:")) != -1) {
        switch(opt) {
            case 'h':   print_usage();
                        break;
            case 'v':   opt_verbose++;
                        break;
            case 'V':   print_version();
                        break;
            case 't':   opt_timeout = atoi(optarg);
                        break;
            case 'w':   opt_job_warning = atoi(optarg);
                        break;
            case 'c':   opt_job_critical = atoi(optarg);
                        break;
            case 'W':   opt_worker_warning = atoi(optarg);
                        break;
            case 'C':   opt_worker_critical = atoi(optarg);
                        break;
            case 'H':   add_server(&server_list_num, server_list, optarg);
                        break;
            case 's':   opt_send = optarg;
                        break;
            case 'a':   send_async = 1;
                        break;
            case 'e':   opt_expect = optarg;
                        break;
            case 'q':   opt_queue = optarg;
                        break;
            case 'u':   opt_unique_id = optarg;
                        break;
            case '?':   printf("Error - No such option: `%c'\n\n", optopt);
                        print_usage();
                        break;
        }
    }
    mod_gm_opt->debug_level = opt_verbose;
    mod_gm_opt->logmode     = GM_LOG_MODE_TOOLS;

    if(server_list_num == 0) {
        printf("Error - no hostname given\n\n");
        print_usage();
    }

    if(opt_send != NULL && opt_queue == NULL) {
        printf("Error - need queue (-q) when sending job\n\n");
        print_usage();
    }

    /* set alarm signal handler */
    signal(SIGALRM, alarm_sighandler);

    if(opt_send != NULL ) {
        alarm(opt_timeout);
        result = check_worker(opt_queue, opt_send, opt_expect);
    }
    else {
        /* get gearman server statistics */
        alarm(opt_timeout);
        result = check_server(server_list[server_list_num-1]->host, server_list[server_list_num-1]->port);
    }
    alarm(0);

    exit( result );
}
コード例 #13
0
ファイル: parser.c プロジェクト: khKhKhEtelKhKhkh/torsocks
int read_config (char *filename, struct parsedfile *config) {
    FILE *conf;
    char line[MAXLINE];
    int rc = 0;
    int lineno = 1;
    struct serverent *server;

   /* Clear out the structure */
   memset(config, 0x0, sizeof(*config));

   /* Initialization */
   currentcontext = &(config->defaultserver);

   /* Tordns defaults */
   config->tordns_cache_size = 256;
   config->tordns_enabled = 1;


    /* If a filename wasn't provided, use the default */
    if (filename == NULL) {
        strncpy(line, CONF_FILE, sizeof(line) - 1);
        /* Insure null termination */
        line[sizeof(line) - 1] = (char) 0;
        filename = line;
        show_msg(MSGWARN, "Configuration file not provided by TORSOCKS_CONF_FILE "
                "environment variable, attempting to use defaults in %s.\n", filename);
    }

    /* If there is no configuration file use reasonable defaults for Tor */
    if ((conf = fopen(filename, "r")) == NULL) {
        show_msg(MSGERR, "Could not open socks configuration file "
                "(%s) errno (%d), assuming sensible defaults for Tor.\n", filename, errno);
        memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));
        check_server(&(config->defaultserver));
        handle_local(config, 0, "127.0.0.0/255.0.0.0");
        handle_local(config, 0, "10.0.0.0/255.0.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");
        handle_local(config, 0, "172.16.0.0/255.240.0.0");
        handle_local(config, 0, "169.254.0.0/255.255.0.0");
        rc = 1; /* Severe errors reading configuration */
    } else {
        memset(&(config->defaultserver), 0x0, sizeof(config->defaultserver));

        while (NULL != fgets(line, MAXLINE, conf)) {
            /* This line _SHOULD_ end in \n so we  */
            /* just chop off the \n and hand it on */
            if (strlen(line) > 0)
                line[strlen(line) - 1] = '\0';
            handle_line(config, line, lineno);
            lineno++;
        }
        fclose(conf);

        /* Always add the 127.0.0.1/255.0.0.0 subnet to local */
        handle_local(config, 0, "127.0.0.0/255.0.0.0");
        /* We always consider this local, because many users' dsl
          routers act as their DNS. */
        handle_local(config, 0, "10.0.0.0/255.0.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");
        handle_local(config, 0, "172.16.0.0/255.240.0.0");
        handle_local(config, 0, "169.254.0.0/255.255.0.0");
        handle_local(config, 0, "192.168.0.0/255.255.0.0");

        /* Check default server */
        check_server(&(config->defaultserver));
        server = (config->paths);
        while (server != NULL) {
            check_server(server);
            server = server->next;
        }
    }

    /* Initialize tordns deadpool_range if not supplied */
    if(config->tordns_deadpool_range == NULL) {
        handle_tordns_deadpool_range(config, 0, "127.0.69.0/255.255.255.0");
    }

    return(rc);
}
コード例 #14
0
/*
 * cryptlink_serv - CRYPTLINK SERV message handler
 *        parv[0] == CRYPTLINK
 *        parv[1] == SERV
 *        parv[2] == server name
 *        parv[3] == keyphrase
 *        parv[4] == :server info (M-line)
 */
static void
cryptlink_serv(struct Client *client_p, struct Client *source_p,
               int parc, char *parv[])
{
  char info[REALLEN + 1];
  char *name;
  struct Client *target_p;
  char *key = client_p->localClient->out_key;
  unsigned char *b64_key;
  struct ConfItem *conf;
  struct AccessItem *aconf;
  char *encrypted;
  const char *p;
  int enc_len;

  /*
  if (client_p->name[0] != 0)
  return;
  */

  if ((parc < 5) || (*parv[4] == '\0'))
  {
    cryptlink_error(client_p, "SERV", "Invalid params",
                    "CRYPTLINK SERV - Invalid params");
    return;
  }

  if ((name = parse_cryptserv_args(client_p, parv, parc, info, key)) == NULL)
  {
    cryptlink_error(client_p, "SERV", "Invalid params",
                    "CRYPTLINK SERV - Invalid params");
    return;
  }

  /* CRYPTLINK SERV support => TS support */
  client_p->tsinfo = TS_DOESTS;

  if (bogus_host(name))
  {
    exit_client(client_p, client_p, "Bogus server name");
    return;
  }

  /* Now we just have to call check_server and everything should be
   * checked for us... -A1kmm. */
  switch (check_server(name, client_p, CHECK_SERVER_CRYPTLINK))
  {
    case -1:
      if (ConfigFileEntry.warn_no_nline)
      {
        cryptlink_error(client_p, "SERV",
          "Unauthorized server connection attempt: No entry for server",
          NULL);
      }
      exit_client(client_p, client_p, "Invalid server name");
      return;
      break;
    case -2:
      cryptlink_error(client_p, "SERV",
        "Unauthorized server connection attempt: CRYPTLINK not "
                                      "enabled on remote server",
        "CRYPTLINK not enabled");
      return;
      break;
    case -3:
      cryptlink_error(client_p, "SERV",
        "Unauthorized server connection attempt: Invalid host",
        "Invalid host");
      return;
      break;
  }

  if ((target_p = find_server(name)))
  {
    /*
     * This link is trying feed me a server that I already have
     * access through another path -- multiple paths not accepted
     * currently, kill this link immediately!!
     *
     * Rather than KILL the link which introduced it, KILL the
     * youngest of the two links. -avalon
     *
     * Definitely don't do that here. This is from an unregistered
     * connect - A1kmm.
     */
    cryptlink_error(client_p, "SERV",
                    "Attempt to re-introduce existing server",
                    "Server Exists");
    return;
  }

  if (ServerInfo.hub && IsCapable(client_p, CAP_LL))
  {
      if (IsCapable(client_p, CAP_HUB))
      {
          ClearCap(client_p,CAP_LL);
          sendto_realops_flags(UMODE_ALL, L_ALL,
               "*** LazyLinks to a hub from a hub, that's a no-no.");
      }
      else
      {
          client_p->localClient->serverMask = nextFreeMask();

          if(!client_p->localClient->serverMask)
          {
              sendto_realops_flags(UMODE_ALL, L_ALL,
                                   "serverMask is full!");
              /* try and negotiate a non LL connect */
              ClearCap(client_p,CAP_LL);
          }
      }
  }
  else if (IsCapable(client_p, CAP_LL))
  {
      if (!IsCapable(client_p, CAP_HUB))
      {
        ClearCap(client_p,CAP_LL);
        sendto_realops_flags(UMODE_ALL, L_ALL,
          "*** LazyLinks to a leaf from a leaf, that's a no-no.");
      }
  }

  conf = find_conf_name(&client_p->localClient->confs,
			name, SERVER_TYPE);
  if (conf == NULL)
  {
    cryptlink_error(client_p, "AUTH",
                    "Lost C-line for server",
                    "Lost C-line" );
    return;
  }

  /*
   * if we are connecting (Handshake), we already have the name from the
   * connect {} block in client_p->name
   */
  strlcpy(client_p->name, name, sizeof(client_p->name));

  p = info;

  if (!strncmp(info, "(H)", 3))
  {
    SetHidden(client_p);

    if ((p = strchr(info, ' ')) != NULL)
    {
      p++;
      if (*p == '\0')
        p = "(Unknown Location)";
    }
    else
      p = "(Unknown Location)";
  }

  strlcpy(client_p->info, p, sizeof(client_p->info));
  client_p->hopcount = 0;

  aconf = (struct AccessItem *)map_to_conf(conf);

  if (!(client_p->localClient->out_cipher ||
      (client_p->localClient->out_cipher = check_cipher(client_p, aconf))))
  {
    cryptlink_error(client_p, "AUTH",
                    "Couldn't find compatible cipher",
                    "Couldn't find compatible cipher");
    return;
  }

  encrypted = MyMalloc(RSA_size(ServerInfo.rsa_private_key));
  enc_len   = RSA_public_encrypt(client_p->localClient->out_cipher->keylen,
                               (unsigned char *)key,
                               (unsigned char *)encrypted,
                               aconf->rsa_public_key,
                               RSA_PKCS1_PADDING);

  if (enc_len <= 0)
  {
    report_crypto_errors();
    MyFree(encrypted);
    cryptlink_error(client_p, "AUTH",
                    "Couldn't encrypt data",
                    "Couldn't encrypt data");
    return;
  }

  base64_block(&b64_key, encrypted, enc_len);

  MyFree(encrypted);

  if (!IsWaitAuth(client_p))
  {
    cryptlink_init(client_p, conf, NULL);
  }

  sendto_one(client_p, "CRYPTLINK AUTH %s %s",
             client_p->localClient->out_cipher->name,
             b64_key);

  /* needed for old servers that can't shove data back into slink */
  send_queued_write(client_p);

  SetCryptOut(client_p);
  MyFree(b64_key);
}
コード例 #15
0
ファイル: m_server.c プロジェクト: Cloudxtreme/ircd-3
/*
 * mr_server - SERVER message handler
 *      parv[0] = sender prefix
 *      parv[1] = servername
 *      parv[2] = serverinfo/hopcount
 *      parv[3] = serverinfo
 */
static void mr_server(struct Client *client_p, struct Client *source_p,
                      int parc, char *parv[])
{
  char             info[REALLEN + 1];
  char             *name;
  struct Client    *target_p;
  int hop;

  if (parc < 4)
    {
      sendto_one(client_p,"ERROR :No servername");
      exit_client(client_p, client_p, client_p, "Wrong number of args");
      return;
    }

  name = parv[1];
  hop = atoi(parv[2]);
  strlcpy(info, parv[3], REALLEN);

  /* 
   * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo
   */
  if (!DoesTS(client_p))
    {
      sendto_realops_flags(FLAGS_ALL, L_ADMIN,"Link %s dropped, non-TS server",
			   get_client_name(client_p, HIDE_IP));
      sendto_realops_flags(FLAGS_ALL, L_OPER,"Link %s dropped, non-TS server",
			   get_client_name(client_p, MASK_IP));
      exit_client(client_p, client_p, client_p, "Non-TS server");
      return;
    }

  if (bogus_host(name))
  {
    exit_client(client_p, client_p, client_p, "Bogus server name");
    return;
  }

  /* Now we just have to call check_server and everything should be
   * check for us... -A1kmm. */
  switch (check_server(name, client_p, CHECK_SERVER_NOCRYPTLINK))
  {
    case -1:
      if (ConfigFileEntry.warn_no_nline)
      {
        sendto_realops_flags(FLAGS_ALL, L_ADMIN,
           "Unauthorized server connection attempt from %s: No entry for "
           "servername %s", get_client_name(client_p, HIDE_IP), name);

        sendto_realops_flags(FLAGS_ALL, L_OPER,
           "Unauthorized server connection attempt from %s: No entry for "
           "servername %s", get_client_name(client_p, MASK_IP), name);
      }
      
      exit_client(client_p, client_p, client_p, "Invalid servername.");
      return;
      /* NOT REACHED */
      break;
      
    case -2:
      sendto_realops_flags(FLAGS_ALL, L_ADMIN,
           "Unauthorized server connection attempt from %s: Bad password "
           "for server %s", get_client_name(client_p, HIDE_IP), name);

      sendto_realops_flags(FLAGS_ALL, L_OPER,
           "Unauthorized server connection attempt from %s: Bad password "
           "for server %s", get_client_name(client_p, MASK_IP), name);

      exit_client(client_p, client_p, client_p, "Invalid password.");
      return;
      /* NOT REACHED */
      break;
      
    case -3:
      sendto_realops_flags(FLAGS_ALL, L_ADMIN,
           "Unauthorized server connection attempt from %s: Invalid host "
           "for server %s", get_client_name(client_p, HIDE_IP), name);

      sendto_realops_flags(FLAGS_ALL, L_OPER,
           "Unauthorized server connection attempt from %s: Invalid host "
           "for server %s", get_client_name(client_p, MASK_IP), name);

      exit_client(client_p, client_p, client_p, "Invalid host.");
      return;
      /* NOT REACHED */
      break;
    
    /* servername is > HOSTLEN */
    case -4:
      sendto_realops_flags(FLAGS_ALL, L_ADMIN,
                           "Invalid servername %s from %s",
			   name, get_client_name(client_p, HIDE_IP));
      sendto_realops_flags(FLAGS_ALL, L_OPER,
		           "Invalid servername %s from %s",
			   name, get_client_name(client_p, MASK_IP));

      exit_client(client_p, client_p, client_p, "Invalid servername.");
      return;
      /* NOT REACHED */
      break;
  }
    
  if ((target_p = server_exists(name)))
    {
      /*
       * This link is trying feed me a server that I already have
       * access through another path -- multiple paths not accepted
       * currently, kill this link immediately!!
       *
       * Rather than KILL the link which introduced it, KILL the
       * youngest of the two links. -avalon
       *
       * Definitely don't do that here. This is from an unregistered
       * connect - A1kmm.
       */
      sendto_realops_flags(FLAGS_ALL, L_ADMIN,
         "Attempt to re-introduce server %s from %s", name,
         get_client_name(client_p, HIDE_IP));

      sendto_realops_flags(FLAGS_ALL, L_OPER,
         "Attempt to re-introduce server %s from %s", name,
         get_client_name(client_p, MASK_IP));

      sendto_one(client_p, "ERROR :Server already exists.");
      exit_client(client_p, client_p, client_p, "Server Exists");
      return;
    }

  if(ServerInfo.hub && IsCapable(client_p, CAP_LL))
    {
      if(IsCapable(client_p, CAP_HUB))
        {
          ClearCap(client_p,CAP_LL);
          sendto_realops_flags(FLAGS_ALL, L_ALL,
               "*** LazyLinks to a hub from a hub, thats a no-no.");
        }
      else
        {
          client_p->localClient->serverMask = nextFreeMask();

          if(!client_p->localClient->serverMask)
            {
              sendto_realops_flags(FLAGS_ALL, L_ALL,
                                   "serverMask is full!");
              /* try and negotiate a non LL connect */
              ClearCap(client_p,CAP_LL);
            }
        }
    }
  else if (IsCapable(client_p, CAP_LL))
    {
      if(!IsCapable(client_p, CAP_HUB))
        {
          ClearCap(client_p,CAP_LL);
          sendto_realops_flags(FLAGS_ALL, L_ALL,
               "*** LazyLinks to a leaf from a leaf, thats a no-no.");
        }
    }

  /*
   * if we are connecting (Handshake), we already have the name from the
   * C:line in client_p->name
   */

  strlcpy(client_p->name, name, HOSTLEN+1);
  set_server_gecos(client_p, info);
  client_p->hopcount = hop;
  server_estab(client_p);
}