irom static app_action_t application_function_config_dump(const string_t *src, string_t *dst)
{
	static config_t tmpconfig;
	config_read(&tmpconfig);
	config_dump(dst, &tmpconfig);
	return(app_action_normal);
}
Ejemplo n.º 2
0
/** Write the persistent state to disk. Return 0 for success, <0 on failure. */
int
or_state_save(time_t now)
{
  char *state, *contents;
  char tbuf[ISO_TIME_LEN+1];
  char *fname;

  tor_assert(global_state);

  if (global_state->next_write > now)
    return 0;

  /* Call everything else that might dirty the state even more, in order
   * to avoid redundant writes. */
  entry_guards_update_state(global_state);
  rep_hist_update_state(global_state);
  circuit_build_times_update_state(&circ_times, global_state);
  if (accounting_is_enabled(get_options()))
    accounting_run_housekeeping(now);

  global_state->LastWritten = now;

  tor_free(global_state->TorVersion);
  tor_asprintf(&global_state->TorVersion, "Tor %s", get_version());

  state = config_dump(&state_format, NULL, global_state, 1, 0);
  format_local_iso_time(tbuf, now);
  tor_asprintf(&contents,
               "# Tor state file last generated on %s local time\n"
               "# Other times below are in GMT\n"
               "# You *do not* need to edit this file.\n\n%s",
               tbuf, state);
  tor_free(state);
  fname = get_datadir_fname("state");
  if (write_str_to_file(fname, contents, 0)<0) {
    log_warn(LD_FS, "Unable to write state to file \"%s\"; "
             "will try again later", fname);
    last_state_file_write_failed = 1;
    tor_free(fname);
    tor_free(contents);
    /* Try again after STATE_WRITE_RETRY_INTERVAL (or sooner, if the state
     * changes sooner). */
    global_state->next_write = now + STATE_WRITE_RETRY_INTERVAL;
    return -1;
  }

  last_state_file_write_failed = 0;
  log_info(LD_GENERAL, "Saved state to \"%s\"", fname);
  tor_free(fname);
  tor_free(contents);

  if (server_mode(get_options()))
    global_state->next_write = now + STATE_RELAY_CHECKPOINT_INTERVAL;
  else
    global_state->next_write = TIME_MAX;

  return 0;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[]) {
  int exitcode = EXIT_FAILURE;

  init_early_config(argc, argv, BB_RUN_APP);

  /* Setup signal handling before anything else */
  signal(SIGHUP, handle_signal);
  signal(SIGTERM, handle_signal);
  signal(SIGINT, handle_signal);
  signal(SIGQUIT, handle_signal);

  bb_init_log();

  /* Initializing configuration */
  init_config(argc, argv);
  bbconfig_parse_opts(argc, argv, PARSE_STAGE_PRECONF);
  GKeyFile *bbcfg = bbconfig_parse_conf();
  /* XXX load the driver (or even better, the ldpath) through the protocol */
  bbconfig_parse_opts(argc, argv, PARSE_STAGE_DRIVER);
  driver_detect();
  if (bbcfg) {
    bbconfig_parse_conf_driver(bbcfg, bb_config.driver);
    g_key_file_free(bbcfg);
  }
  bbconfig_parse_opts(argc, argv, PARSE_STAGE_OTHER);
  config_dump();

  bb_log(LOG_DEBUG, "%s version %s starting...\n", "optirun", GITVERSION);

  /* Connect to listening daemon */
  bb_status.bb_socket = socketConnect(bb_config.socket_path, SOCK_NOBLOCK);
  if (bb_status.bb_socket < 0) {
    bb_log(LOG_ERR, "Could not connect to bumblebee daemon - is it running?\n");
    run_fallback(argv + optind);
    bb_closelog();
    return exitcode;
  }

  /* Request status */
  if (bb_status.runmode == BB_RUN_STATUS) {
    exitcode = report_daemon_status();
  }

  /* Run given application */
  if (bb_status.runmode == BB_RUN_APP) {
    if (optind >= argc) {
      bb_log(LOG_ERR, "Missing argument: application to run\n");
      print_usage(EXIT_FAILURE);
    } else {
      exitcode = run_app(argc, argv);
    }
  }

  bb_closelog();
  bb_stop_all(); //stop any started processes that are left
  return exitcode;
}
Ejemplo n.º 4
0
/*
 * aconfig
 *
 * Usage: aconfig variable value
 *
 *   sets the config variable 'variable' to 'value'
 */
int com_aconfig(int p, param_list param)
{
	if (param[0].type == TYPE_NULL) {
		/* if no parameters are given then dump the current config */
		config_dump(p);
		return COM_OK;
	}

	if (config_set(param[0].val.word, param[1].val.string) != 0) {
		return COM_FAILED;
	}
  
	return COM_OK;
}
Ejemplo n.º 5
0
/* Save the disk state to disk but before that update it from the current
 * state so we always have the latest. Return 0 on success else -1. */
static int
disk_state_save_to_disk(void)
{
  int ret;
  char *state, *content = NULL, *fname = NULL;
  char tbuf[ISO_TIME_LEN + 1];
  time_t now = time(NULL);

  /* If we didn't have the opportunity to setup an internal disk state,
   * don't bother saving something to disk. */
  if (sr_disk_state == NULL) {
    ret = 0;
    goto done;
  }

  /* Make sure that our disk state is up to date with our memory state
   * before saving it to disk. */
  disk_state_update();
  state = config_dump(&state_format, NULL, sr_disk_state, 0, 0);
  format_local_iso_time(tbuf, now);
  tor_asprintf(&content,
               "# Tor shared random state file last generated on %s "
               "local time\n"
               "# Other times below are in UTC\n"
               "# Please *do not* edit this file.\n\n%s",
               tbuf, state);
  tor_free(state);
  fname = get_datadir_fname(default_fname);
  if (write_str_to_file(fname, content, 0) < 0) {
    log_warn(LD_FS, "SR: Unable to write SR state to file %s", fname);
    ret = -1;
    goto done;
  }
  ret = 0;
  log_debug(LD_DIR, "SR: Saved state to file %s", fname);

 done:
  tor_free(fname);
  tor_free(content);
  return ret;
}
irom static app_action_t application_function_current_config_dump(const string_t *src, string_t *dst)
{
	config_dump(dst, &config);

	return(app_action_normal);
}
Ejemplo n.º 7
0
OPENVPN_EXPORT openvpn_plugin_handle_t
openvpn_plugin_open_v2 (unsigned int *type_mask, const char *argv[], const char *envp[], struct openvpn_plugin_string_list **return_list)
{

  ldap_context_t *context;
  const char *daemon_string = NULL;
  const char *log_redirect = NULL;

  const char *configfile = NULL;
  int rc = 0;
  uint8_t     allow_core_files = 0;

  /* Are we in daemonized mode? If so, are we redirecting the logs? */
  daemon_string = get_env ("daemon", envp);
  use_syslog = 0;
  if( daemon_string && daemon_string[0] == '1'){
    log_redirect = get_env ("daemon_log_redirect", envp);
    if( !(log_redirect && log_redirect[0] == '1'))
      use_syslog = 1;
  }
  /*
   * Allocate our context
   */
  context = ldap_context_new( );
  if( !context ){
    LOGERROR( "Failed to initialize ldap_context, no memory available?" );
    goto error;
  }
  /*
   * Intercept the --auth-user-pass-verify callback.
   */
  *type_mask = OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY);

   while ( ( rc = getopt ( string_array_len (argv), (char **)argv, ":H:D:c:t:WZC" ) ) != - 1 ){
    switch( rc ) {
      case 'H':
        context->config->ldap->uri = strdup(optarg);
        break;
      case 'Z':
        context->config->ldap->ssl = strdup("start_tls");
        break;
      case 'D':
        context->config->ldap->binddn = strdup(optarg);
        break;
      case 'W':
        context->config->ldap->bindpw = get_passwd("BindPW Password: "******"Password is %s: length: %d\n", config->bindpw, strlen(config->bindpw) );
        break;
      case 'c':
        configfile = optarg;
        break;
      case 't':
        context->config->ldap->timeout = atoi( optarg );
        break;
      case 'C':
        LOGDEBUG("Core file generation requested");
        allow_core_files = 1;
        break;
      case '?':
        LOGERROR("Unknown Option -%c !!", optopt );
        break;
      case ':':
        LOGERROR ("Missing argument for option -%c !!", optopt );
        break;
      default:
        LOGERROR ("?? getopt returned character code 0%o ??", rc);
        abort();
    }
  }

#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE)
  if (allow_core_files){
    LOGDEBUG ("Setting core file");
    unlimit_core_size();
  }
#endif

  /**
   * Parse configuration file is -c filename is provided
   * If not provided, use a default config file OCONFIG
   * This file must exists even though it might be empty
   */
  if( configfile == NULL) {
    configfile = OCONFIG;
  }

  if( config_parse_file( configfile, context->config ) ){
    goto error;
  }
  /**
   * Set default config values
   */
  config_set_default( context->config );


  /* when ldap userconf is define, we need to hook onto those callbacks */
  if( config_is_pf_enabled( context->config )){
    *type_mask |= OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_ENABLE_PF);
  }
#ifdef ENABLE_LDAPUSERCONF
  *type_mask |= OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_CLIENT_CONNECT_V2)
                | OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_CLIENT_DISCONNECT);
#else
  if( config_is_redirect_gw_enabled( context->config ) ){
    *type_mask |= OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_CLIENT_CONNECT_V2);
  }
#endif

  /*
   * Get verbosity level from environment
   */
  const char *verb_string = get_env ("verb", envp);
  if (verb_string)
    context->verb = atoi (verb_string);

  if( DODEBUG( context->verb ) )
      config_dump( context->config );


  /* set up mutex/cond */
  pthread_mutex_init (&action_mutex, NULL);
  pthread_cond_init (&action_cond, NULL);

  /* start our authentication thread */
  pthread_attr_setdetachstate(&action_thread_attr, PTHREAD_CREATE_JOINABLE);
  rc = pthread_create(&action_thread, &action_thread_attr, action_thread_main_loop, context);

  switch( rc ){
    case EAGAIN:
      LOGERROR( "pthread_create returned EAGAIN: lacking resources" );
      break;
    case EINVAL:
      LOGERROR( "pthread_create returned EINVAL: invalid attributes" );
      break;
    case EPERM:
      LOGERROR( "pthread_create returned EPERM: no permission to create thread" );
      break;
    case 0:
      break;
    default:
      LOGERROR( "pthread_create returned an unhandled value: %d", rc );
  }
  if( rc == 0)
    return (openvpn_plugin_handle_t) context;

  /* Failed to initialize, free resources */
  pthread_attr_destroy( &action_thread_attr );
  pthread_mutex_destroy( &action_mutex );
  pthread_cond_destroy( &action_cond );

error:
  if ( context ){
    ldap_context_free (context);
  }
  return NULL;
}
Ejemplo n.º 8
0
int main (int argc, char *argv[])
{
    int ch;
    flux_conf_t cf;
    char *cmd;
    bool vopt = false;
    flux_t h = NULL;
    char *confdir = NULL;

    log_init ("flux-config");

    while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
        switch (ch) {
            case 'v': /* --verbose */
                vopt=  true;
                break;
            default:
                usage ();
                break;
        }
    }
    if (optind == argc)
        usage ();
    cmd = argv[optind++];

    /* Process config from the KVS if running in a session and not
     * forced to use a config file by the command line.
     */
    cf = flux_conf_create ();
    if ((confdir = getenv ("FLUX_CONF_DIRECTORY")))
        flux_conf_set_directory (cf, confdir);
    if (getenv ("FLUX_CONF_USEFILE")) {
        if (vopt)
            msg ("Loading config from %s", flux_conf_get_directory (cf));
        if (flux_conf_load (cf) < 0)
            err_exit ("%s", flux_conf_get_directory (cf));
    } else if (getenv ("FLUX_URI")) {
        if (vopt)
            msg ("Loading config from KVS");
        if (!(h = flux_open (NULL, 0)))
            err_exit ("flux_open");
        if (kvs_conf_load (h, cf) < 0)
            err_exit ("could not load config from KVS");
    }

    if (!strcmp (cmd, "get"))
        config_get (cf, argc - optind, argv + optind);
    else if (!strcmp (cmd, "dump"))
        config_dump (cf, argc - optind, argv + optind);
    else if (!strcmp (cmd, "put"))
        config_put (cf, h, vopt, argc - optind, argv + optind);
    else if (!strcmp (cmd, "save"))
        config_save (cf, vopt, argc - optind, argv + optind);
    else
        usage ();

    if (h)
        flux_close (h);
    flux_conf_destroy (cf);
    log_fini();
    exit (0);
}
int main(int argc, char *argv[])
{
	if (argc > 0)
		config_read_file(argv[1]);
	config_dump();
}
Ejemplo n.º 10
0
int main(int argc, char *argv[]) {
  int exitcode = EXIT_FAILURE;

  init_early_config(argc, argv, BB_RUN_APP);

  /* Setup signal handling before anything else */
  signal(SIGHUP, handle_signal);
  signal(SIGTERM, handle_signal);
  signal(SIGINT, handle_signal);
  signal(SIGQUIT, handle_signal);

  bb_init_log();

  /* Initializing configuration */
  init_config(argc, argv);
  bbconfig_parse_opts(argc, argv, PARSE_STAGE_PRECONF);
  __unused GKeyFile *bbcfg = bbconfig_parse_conf();


  /* Connect to listening daemon */
  bb_status.bb_socket = socketConnect(bb_config.socket_path, SOCK_BLOCK);
  if (bb_status.bb_socket < 0) {
    bb_log(LOG_ERR, "Could not connect to bumblebee daemon - is it running?\n");
    run_fallback(argv + optind);
    bb_closelog();
    return exitcode;
  }

  free_and_set_value(&bb_config.ld_path, malloc(BUFFER_SIZE));
  if (bbsocket_query("LibraryPath", bb_config.ld_path, BUFFER_SIZE)) {
    bb_log(LOG_ERR, "Failed to retrieve LibraryPath setting.\n");
    return EXIT_FAILURE;
  }
  free_and_set_value(&bb_config.x_display, malloc(BUFFER_SIZE));
  if (bbsocket_query("VirtualDisplay", bb_config.x_display, BUFFER_SIZE)) {
    bb_log(LOG_ERR, "Failed to retrieve VirtualDisplay setting.\n");
    return EXIT_FAILURE;
  }

  /* parse remaining common and optirun-specific options */
  bbconfig_parse_opts(argc, argv, PARSE_STAGE_OTHER);
  bb_log(LOG_DEBUG, "%s version %s starting...\n", "optirun", GITVERSION);
  config_dump();

  /* Request status */
  if (bb_status.runmode == BB_RUN_STATUS) {
    exitcode = report_daemon_status();
  }

  /* Run given application */
  if (bb_status.runmode == BB_RUN_APP) {
    if (optind >= argc) {
      bb_log(LOG_ERR, "Missing argument: application to run\n");
      print_usage(EXIT_FAILURE);
    } else {
      exitcode = run_app(argc, argv);
    }
  }

  bb_closelog();
  bb_stop_all(); //stop any started processes that are left
  return exitcode;
}
irom static app_action_t application_function_config_dump(application_parameters_t ap)
{
	config_dump(ap.size, ap.dst);

	return(app_action_normal);
}