Exemple #1
0
const char *get_ether_from_netcardno (int netcardno)
{
   if (netcardno == 0) {
      return (get_ether_from_ip(get_ip_from_name("localhost") , 1));
   } else {
      if (netcardno < __sysinfo.si_nnetworks) {
         return (&__sysinfo.si_networks[netcardno].ether_addr[0]);
      }
   }

   return (NULL);
}
Exemple #2
0
static int
control_channel_handler(int connfd)
{
  char *password;
  data_endpoint_t *ep;
  sslutil_connection_t ssl_conn;

  linfo("Connection handler started. Initiating SSL handshake.");

  ssl_conn = sslutil_connect(connfd, server);
  if (ssl_conn == 0) {
    linfo("Unable to start SSL session");
    return EXIT_SSL_ERROR;
  }

  if (!ivpn_protocol_handshake(ssl_conn))
    return EXIT_PROTO_ERROR;

  linfo ("IVPN Protocol handshake completed successfully.");

  ep = start_data_endpoint(NULL);

  assert(ep != 0);

  if (relinquish_superuser(NULL) == 0) {
    lerr("Unable to relinquish privileges. Quitting.");
    return EXIT_FAILURE;
  }

  usleep(100000); // 100 ms

  password = get_password("Password:"******"Authentication failed.");
    return EXIT_AUTH_ERROR;
  }
  memset(password, 0, strlen(password)); // clear plain text password

  linfo ("Authenticated with server. Data port is %u", ep->peer_port);

  ep->peer_ip = inet_addr(get_ip_from_name(server));

  if (write(ep->write_fd, &ep->peer_ip, sizeof(ep->peer_ip)) == -1 ||
      write(ep->write_fd, &ep->peer_port, sizeof(ep->peer_port)) == -1) {
    lerr("Unable to write to UDP process pipe. Quitting.", strerror(errno));
    return EXIT_FAILURE;
  }

  usleep(100000); // 100 ms

  while (1) {
    char command[64];
    fprintf(stdout, "ivpn> ");
    fflush(stdout);
    if (fgets(command, sizeof(command) - 1, stdin) == 0) {
      linfo("End of input. Terminating...");
      break;
    }

    if (strcmp(command, "quit\n") == 0) {
      linfo("Quit command. Terminating...");
      break;
    }

    if (strcmp(command, "changekey\n") == 0) {
      char key[IVPN_KEY_LENGTH];

      linfo("Performing key change.");
      generate_true_random(key, sizeof(key));

      /* send key to local UDP process first */
      if (write(ep->write_fd, key, sizeof(key)) != sizeof(key)) {
        lerr("Unable to send key to local UDP process : %s. Quitting...", strerror(errno));
        break;
      } else
      {
        linfo("New key sent to local UDP process");
      }

      /* send key to VPN server */
      cm_setkey_t *cm = create_cm_setkey(key);
      if (cm == 0) {
        lerr ("Unable to generate command for sending to VPN server. Quitting...");
        break;
      }

      if (send_control_message(ssl_conn, (cm_header_t *)cm) == 0) {
        lerr ("Unable to sending command to VPN server. Quitting...");
        break;
      }

      cm_header_t *rsp = recv_control_message(ssl_conn);
      if (rsp == 0) {
        lerr ("Unable to receive command from VPN server. Quitting...");
        break;
      }

      if (rsp->cm_type == CM_TYPE_OK) {
        linfo("Setting new key in server succeeded");
      } else
      {
        lerr("Setting new key in server failed. Quitting...");
        break;
      }
    }

  }


  return 0;
}
Exemple #3
0
void AmMailDeamon::run()
{
  queue<AmMail*> n_event_fifo;
  while(1){

    _run_cond.wait_for();
    sleep(5);

    string server_address = get_ip_from_name(AmConfig::SmtpServerAddress);
    if(server_address.empty()){
      WARN("Mail deamon could not resolv SMTP server address <%s>\n",
	   AmConfig::SmtpServerAddress.c_str());
      continue;
    }

    AmSmtpClient smtp;
    if (smtp.connect(server_address,AmConfig::SmtpServerPort)) {
	    
      WARN("Mail deamon could not connect to SMTP server at <%s:%i>\n",
	   server_address.c_str(),AmConfig::SmtpServerPort);
      continue;
    }

    event_fifo_mut.lock();
    DBG("Mail deamon starting its work\n");

    while(!event_fifo.empty()){

      AmMail* cur_mail = event_fifo.front();
      event_fifo.pop();

      event_fifo_mut.unlock();

      bool err = true;
      try{
	err = smtp.send(*cur_mail);
      }
      catch(...){}

      if(err && (cur_mail->error_count < 3)){
	n_event_fifo.push(cur_mail);
	cur_mail->error_count++;
      }
      else {
	if(cur_mail->clean_up)
	  (*(cur_mail->clean_up))(cur_mail);
	delete cur_mail;
      }
      event_fifo_mut.lock();
    }

    event_fifo_mut.unlock();
    smtp.disconnect();
    smtp.close();

    if(n_event_fifo.empty()){
      _run_cond.set(false);
    }
    else {
      while(!n_event_fifo.empty())
	n_event_fifo.pop();
    }

    DBG("Mail deamon finished\n");
  }
}