Exemplo n.º 1
0
int
main(int argc, const char *argv[])
{
  Socket* serverSock, *controlSock;
  int c;

  poptContext optCon = poptGetContext(NULL, argc, argv, options, 0);
  poptSetOtherOptionHelp(optCon, "configFile");

  while ((c = poptGetNextOpt(optCon)) >= 0) {
    switch (c) {
    case 'v':
      printf(V_STRING, VERSION);
      printf(COPYRIGHT);
      return 0;
    }
  }

  setup_logging (logfile_name, log_level);

  if (c < -1) {
    /* an error occurred during option processing */
    fprintf(stderr, "%s: %s\n",
      poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
      poptStrerror(c));
    return -1;
  }

  loginfo (V_STRING, VERSION);
  loginfo (COPYRIGHT);

  struct sigaction new_action, old_action;
  new_action.sa_handler = sigpipe_handler;
  sigemptyset (&new_action.sa_mask);
  new_action.sa_flags = 0;
  sigaction (SIGPIPE, NULL, &old_action);
  if (old_action.sa_handler != SIG_IGN)
    sigaction (SIGPIPE, &new_action, NULL);

  prepare_stdin(NULL);

  eventloop_init();
  session = (Session*) malloc(sizeof(Session));
  memset(session, 0, sizeof(Session));

  session->state = ProxyState_PAUSED;

  serverSock = socket_server_new("proxy_server", listen_port, on_connect, NULL);
  controlSock = socket_server_new("proxy_server_control", listen_port + 1, on_control_connect, NULL);

  eventloop_on_stdin(stdin_handler, session);
  eventloop_run();

  socket_free(serverSock);
  socket_free(controlSock);

  return(0);
}
Exemplo n.º 2
0
int main(int argc, const char **argv)
{
  int c, len;
#ifdef HAVE_LIBPQ
  char *pass_replace = "--pg-pass=WITHHELD", *conninfo_replace = "--pg-connect=WITHHELD";
#endif

  oml_setup(&argc, argv);

  poptContext optCon = poptGetContext(NULL, argc, (const char**) argv, options, 0);

  while ((c = poptGetNextOpt(optCon)) >= 0) {
    switch (c) {
    case 'v':
      printf(V_STRING, VERSION);
      printf("OML Protocol V%d--%d\n", MIN_PROTOCOL_VERSION, MAX_PROTOCOL_VERSION);
      printf(COPYRIGHT);
      return 0;
    }
  }

#ifdef HAVE_LIBPQ
  /* Cleanup command line to avoid showing credentials in ps(1) output, amongst
   * others.
   *
   * XXX: This is a poor man's security measure, as this creates a race
   * condition where, prior to doing the following, the credentials are still
   * visible to everybody.
   */
  if (pg_pass || pg_conninfo) {
    for(c=1; c<argc; c++) {
      len = strlen(argv[c]);
      if(pg_pass && !strncmp(argv[c],"--pg-pass", 9)) {
        strncpy((char*)argv[c], pass_replace, len);
        ((char*)argv[c])[len] = 0;
      }

      if(pg_conninfo && !strncmp(argv[c],"--pg-connect", 12)) {
        strncpy((char*)argv[c], conninfo_replace, len);
        ((char*)argv[c])[len] = 0;
      }
    }
  }
#endif /* HAVE_LIBPQ */

  logging_setup (logfile_name, log_level);

  if (c < -1) {
    die ("%s: %s\n", poptBadOption (optCon, POPT_BADOPTION_NOALIAS), poptStrerror (c));
  }

  loginfo(V_STRING, VERSION);
  loginfo("OML Protocol V%d--%d\n", MIN_PROTOCOL_VERSION, MAX_PROTOCOL_VERSION);
  loginfo(COPYRIGHT);

  eventloop_init();
  eventloop_set_socket_timeout(socket_timeout);

  Socket* server_sock;
  server_sock = socket_server_new("server", NULL, listen_service, on_connect, NULL);

  if (!server_sock) {
    die ("Failed to create listening socket for service %s\n", listen_service);
  }

  drop_privileges (uidstr, gidstr);

  /* Important that this comes after drop_privileges(). */
  if(database_setup_backend(dbbackend)) {
      die("Failed to setup database backend '%s'\n", dbbackend);
  }

  signal_setup();

  hook_setup();

  eventloop_run();

  signal_cleanup();

  hook_cleanup();

  oml_cleanup();

  oml_memreport(O_LOG_INFO);

  return 0;
}