/** * Initialize the configuration tree related to the agent. */ void agent_initialize_config_tree(void) { char *value; /* TLS */ if ((value = config_get("tls certificate-store WORD")) == NULL) { config_set_default("tls certificate-store WORD", (char *) DEFAULT_TLS_CERTIFICATE_STORE); value = config_get("tls certificate-store WORD"); } session_tls_ca_dir_set(value); if ((value = config_get("tls certificate-file WORD")) == NULL) { config_set_default("tls certificate-file WORD", (char *) DEFAULT_TLS_CERTIFICATE_FILE); value = config_get("tls certificate-file WORD"); } session_tls_cert_set(value); if ((value = config_get("tls private-key WORD")) == NULL) { config_set_default("tls private-key WORD", (char *) DEFAULT_TLS_PRIVATE_KEY); value = config_get("tls private-key WORD"); } session_tls_key_set(value); if ((value = config_get("tls trust-point-conf WORD")) == NULL) { config_set_default("tls trust-point-conf WORD", (char *) DEFAULT_TLS_TRUST_POINT_CONF); value = config_get("tls trust-point-conf WORD"); } agent_check_certificates_set_config_file(value); }
/* * rpmemd_config_read -- read config from cl and config files * * cl param overwrites configuration from any config file. Config file are read * in order: * 1. Global config file * 2. User config file * or * cl provided config file */ int rpmemd_config_read(struct rpmemd_config *config, int argc, char *argv[]) { const char *cl_config_file = NULL; char user_config_file[PATH_MAX]; char home_dir[PATH_MAX]; uint64_t cl_options = 0; get_home_dir(home_dir, PATH_MAX); config_set_default(config, home_dir); parse_cl_args(argc, argv, config, &cl_config_file, &cl_options); if (cl_config_file) { if (parse_config_file(cl_config_file, config, cl_options, 1)) return 1; } else { if (parse_config_file(RPMEMD_GLOBAL_CONFIG_FILE, config, cl_options, 0)) return 1; concat_dir_and_file_name(user_config_file, PATH_MAX, home_dir, RPMEMD_USER_CONFIG_FILE); if (parse_config_file(user_config_file, config, cl_options, 0)) return 1; } config->poolset_dir = str_replace_home(config->poolset_dir, home_dir); return 0; }
int parse_strategy (struct symtab *symtab, const char *text) { str_t workdir; int status; str_init (workdir, 64); str_getcwd (workdir); clean_error_msgs (); lexer_init (text); symbol_table_clean (symtab); config_set_default (symtab->config_table); status = yyparse (symtab); chdir (CSTR(workdir)); str_free (workdir); if (status != 0) symbol_table_clean (symtab); return status; }
void rrddim_set_name(RRDSET *st, RRDDIM *rd, const char *name) { debug(D_RRD_CALLS, "rrddim_set_name() %s.%s", st->name, rd->name); char varname[CONFIG_MAX_NAME + 1]; snprintfz(varname, CONFIG_MAX_NAME, "dim %s name", rd->id); config_set_default(st->id, varname, name); }
G_MODULE_EXPORT void on_prefs_reset_clicked(GtkWidget* widget, void* user) { config_set_default(); utils_copy_file(C_DEFAULTTEXT, C_WELCOMETEXT, NULL); set_all_tab_settings(gui->prefsgui); }
gboolean config_init(int argc, char* argv[]) { memset(&g_config, 0, sizeof(g_config)); config_from_argv(argc, argv); config_from_file(); config_set_default(); g_print("interval = %d\nrest_time = %d\nmax_idle_time = %d\n", g_config.interval, g_config.rest_time, g_config.max_idle_time); g_print("font = %s\ncolor = %s\nformat = %s\nx = %d\ny = %d\n", g_config.font, g_config.color, g_config.format, g_config.x_coordinate, g_config.y_coordinate); return TRUE; }
static void initialize_internal(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; void *logger_client_arg = NULL; char *master_agentx_socket = NULL; char *ping_interval_string = NULL; uint16_t ping_interval = 0; state = SNMPMGR_NONE; /* `is_thread` is able to be changed only once here */ is_thread = is_thread_dummy; if (is_thread == false && thdptr_dummy != NULL) { *thdptr_dummy = NULL; } else if (thdptr_dummy != NULL) { *thdptr_dummy = &snmpmgr; } else { /* never reached! */ return; } if (lagopus_mutex_create(&snmp_lock) != LAGOPUS_RESULT_OK) { return; } if (lagopus_mutex_create(&snmp_state_lock) != LAGOPUS_RESULT_OK) { return; } snmp_set_do_debugging(false); /* setup Net-SNMP logger to use the lagopus logging function */ if (snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_LOGGING, snmp_log_callback_wrapper, logger_client_arg) != SNMPERR_SUCCESS) { return; } snmp_enable_calllog(); /* setup the SNMP module to be Agentx subagent */ netsnmp_enable_subagent(); #ifdef THE_CONFSYS_ERA master_agentx_socket = config_get("snmp master-agentx-socket WORD"); if (master_agentx_socket == NULL) { config_set_default("snmp master-agentx-socket WORD", (char *)DEFAULT_SNMPMGR_AGENTX_SOCKET); master_agentx_socket = config_get("snmp master-agentx-socket WORD"); } #else /* * FIXME: * Fetch it from the datastore. */ master_agentx_socket = (char *)DEFAULT_SNMPMGR_AGENTX_SOCKET; #endif /* THE_CONFSYS_ERA */ lagopus_msg_debug(25, "master agentx socket is %s\n", master_agentx_socket); if (netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, master_agentx_socket) != SNMPERR_SUCCESS) { initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR; return; } /* don't read/write configuration files */ if (netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, true) != SNMPERR_SUCCESS) { initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR; return; } if (netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DISABLE_PERSISTENT_LOAD, true) != SNMPERR_SUCCESS) { initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR; return; } /* the interval [sec] to send ping to AgentX master agent */ #ifdef THE_CONFSYS_ERA ping_interval_string = config_get("snmp ping-interval-second 1-255"); if (ping_interval_string != NULL && (ret = check_ping_interval(ping_interval_string, &ping_interval)) != LAGOPUS_RESULT_OK) { config_set_default("snmp ping-interval-second 1-255", (char *) __STR__(DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC)); ping_interval_string = config_get("snmp ping-interval-second 1-255"); ping_interval = DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC; /* default value */ } #else /* * FIXME: * Fetch it from the datastore. */ ping_interval = DEFAULT_SNMPMGR_AGENTX_PING_INTERVAL_SEC; #endif /* THE_CONFSYS_ERA */ if (netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, (int)ping_interval) != SNMPERR_SUCCESS) { initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR; return; } if (init_agent(SNMP_TYPE) != SNMPERR_SUCCESS) { initialize_ret = LAGOPUS_RESULT_SNMP_API_ERROR; return; } if ((ret = lagopus_hashmap_create(&iftable_entry_hash, LAGOPUS_HASHMAP_TYPE_STRING, delete_entry)) != LAGOPUS_RESULT_OK) { lagopus_perror(ret); exit(1); } init_ifTable(); init_ifNumber(); init_dot1dBaseBridgeAddress(); init_dot1dBaseNumPorts(); init_dot1dBasePortTable(); init_dot1dBaseType(); if (is_thread == false) { initialize_ret = LAGOPUS_RESULT_OK; } else { keep_running = true; initialize_ret = lagopus_thread_create(&snmpmgr, snmpmgr_thread_loop, snmpmgr_thread_finally_called, NULL, "snmpmgr", NULL); } lagopus_msg_info("SNMP manager initialized.\n"); }
int main(int argc, char **argv) { int i; int config_loaded = 0; int dont_fork = 0; size_t default_stacksize; // set the name for logging program_name = "netdata"; // parse depercated options // TODO: Remove this block with the next major release. { i = 1; while(i < argc) { if(strcmp(argv[i], "-pidfile") == 0 && (i+1) < argc) { strncpyz(pidfile, argv[i+1], FILENAME_MAX); fprintf(stderr, "%s: deprecated option -- %s -- please use -P instead.\n", argv[0], argv[i]); remove_option(i, &argc, argv); } else if(strcmp(argv[i], "-nodaemon") == 0 || strcmp(argv[i], "-nd") == 0) { dont_fork = 1; fprintf(stderr, "%s: deprecated option -- %s -- please use -D instead.\n ", argv[0], argv[i]); remove_option(i, &argc, argv); } else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) { config_set(CONFIG_SECTION_GLOBAL, "host access prefix", argv[i+1]); fprintf(stderr, "%s: deprecated option -- %s -- please use -s instead.\n", argv[0], argv[i]); remove_option(i, &argc, argv); } else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) { config_set(CONFIG_SECTION_GLOBAL, "history", argv[i+1]); fprintf(stderr, "%s: deprecated option -- %s -- This option will be removed with V2.*.\n", argv[0], argv[i]); remove_option(i, &argc, argv); } else i++; } } // parse options { int num_opts = sizeof(option_definitions) / sizeof(struct option_def); char optstring[(num_opts * 2) + 1]; int string_i = 0; for( i = 0; i < num_opts; i++ ) { optstring[string_i] = option_definitions[i].val; string_i++; if(option_definitions[i].arg_name) { optstring[string_i] = ':'; string_i++; } } // terminate optstring optstring[string_i] ='\0'; optstring[(num_opts *2)] ='\0'; int opt; while( (opt = getopt(argc, argv, optstring)) != -1 ) { switch(opt) { case 'c': if(config_load(optarg, 1) != 1) { error("Cannot load configuration file %s.", optarg); return 1; } else { debug(D_OPTIONS, "Configuration loaded from %s.", optarg); config_loaded = 1; } break; case 'D': dont_fork = 1; break; case 'h': return help(0); case 'i': config_set(CONFIG_SECTION_WEB, "bind to", optarg); break; case 'P': strncpy(pidfile, optarg, FILENAME_MAX); pidfile[FILENAME_MAX] = '\0'; break; case 'p': config_set(CONFIG_SECTION_GLOBAL, "default port", optarg); break; case 's': config_set(CONFIG_SECTION_GLOBAL, "host access prefix", optarg); break; case 't': config_set(CONFIG_SECTION_GLOBAL, "update every", optarg); break; case 'u': config_set(CONFIG_SECTION_GLOBAL, "run as user", optarg); break; case 'v': case 'V': printf("%s %s\n", program_name, program_version); return 0; case 'W': { char* stacksize_string = "stacksize="; char* debug_flags_string = "debug_flags="; if(strcmp(optarg, "unittest") == 0) { if(unit_test_buffer()) return 1; if(unit_test_str2ld()) return 1; //default_rrd_update_every = 1; //default_rrd_memory_mode = RRD_MEMORY_MODE_RAM; //if(!config_loaded) config_load(NULL, 0); get_netdata_configured_variables(); default_rrd_update_every = 1; default_rrd_memory_mode = RRD_MEMORY_MODE_RAM; default_health_enabled = 0; rrd_init("unittest"); default_rrdpush_enabled = 0; if(run_all_mockup_tests()) return 1; if(unit_test_storage()) return 1; fprintf(stderr, "\n\nALL TESTS PASSED\n\n"); return 0; } else if(strcmp(optarg, "simple-pattern") == 0) { if(optind + 2 > argc) { fprintf(stderr, "%s", "\nUSAGE: -W simple-pattern 'pattern' 'string'\n\n" " Checks if 'pattern' matches the given 'string'.\n" " - 'pattern' can be one or more space separated words.\n" " - each 'word' can contain one or more asterisks.\n" " - words starting with '!' give negative matches.\n" " - words are processed left to right\n" "\n" "Examples:\n" "\n" " > match all veth interfaces, except veth0:\n" "\n" " -W simple-pattern '!veth0 veth*' 'veth12'\n" "\n" "\n" " > match all *.ext files directly in /path/:\n" " (this will not match *.ext files in a subdir of /path/)\n" "\n" " -W simple-pattern '!/path/*/*.ext /path/*.ext' '/path/test.ext'\n" "\n" ); return 1; } const char *heystack = argv[optind]; const char *needle = argv[optind + 1]; size_t len = strlen(needle) + 1; char wildcarded[len]; SIMPLE_PATTERN *p = simple_pattern_create(heystack, NULL, SIMPLE_PATTERN_EXACT); int ret = simple_pattern_matches_extract(p, needle, wildcarded, len); simple_pattern_free(p); if(ret) { fprintf(stdout, "RESULT: MATCHED - pattern '%s' matches '%s', wildcarded '%s'\n", heystack, needle, wildcarded); return 0; } else { fprintf(stdout, "RESULT: NOT MATCHED - pattern '%s' does not match '%s', wildcarded '%s'\n", heystack, needle, wildcarded); return 1; } } else if(strncmp(optarg, stacksize_string, strlen(stacksize_string)) == 0) { optarg += strlen(stacksize_string); config_set(CONFIG_SECTION_GLOBAL, "pthread stack size", optarg); } else if(strncmp(optarg, debug_flags_string, strlen(debug_flags_string)) == 0) { optarg += strlen(debug_flags_string); config_set(CONFIG_SECTION_GLOBAL, "debug flags", optarg); debug_flags = strtoull(optarg, NULL, 0); } else if(strcmp(optarg, "set") == 0) { if(optind + 3 > argc) { fprintf(stderr, "%s", "\nUSAGE: -W set 'section' 'key' 'value'\n\n" " Overwrites settings of netdata.conf.\n" "\n" " These options interact with: -c netdata.conf\n" " If -c netdata.conf is given on the command line,\n" " before -W set... the user may overwrite command\n" " line parameters at netdata.conf\n" " If -c netdata.conf is given after (or missing)\n" " -W set... the user cannot overwrite the command line\n" " parameters." "\n" ); return 1; } const char *section = argv[optind]; const char *key = argv[optind + 1]; const char *value = argv[optind + 2]; optind += 3; // set this one as the default // only if it is not already set in the config file // so the caller can use -c netdata.conf before or // after this parameter to prevent or allow overwriting // variables at netdata.conf config_set_default(section, key, value); // fprintf(stderr, "SET section '%s', key '%s', value '%s'\n", section, key, value); } else if(strcmp(optarg, "get") == 0) { if(optind + 3 > argc) { fprintf(stderr, "%s", "\nUSAGE: -W get 'section' 'key' 'value'\n\n" " Prints settings of netdata.conf.\n" "\n" " These options interact with: -c netdata.conf\n" " -c netdata.conf has to be given before -W get.\n" "\n" ); return 1; } if(!config_loaded) { fprintf(stderr, "warning: no configuration file has been loaded. Use -c CONFIG_FILE, before -W get. Using default config.\n"); config_load(NULL, 0); } backwards_compatible_config(); get_netdata_configured_variables(); const char *section = argv[optind]; const char *key = argv[optind + 1]; const char *def = argv[optind + 2]; const char *value = config_get(section, key, def); printf("%s\n", value); return 0; } else { fprintf(stderr, "Unknown -W parameter '%s'\n", optarg); return help(1); } } break; default: /* ? */ fprintf(stderr, "Unknown parameter '%c'\n", opt); return help(1); } } } #ifdef _SC_OPEN_MAX // close all open file descriptors, except the standard ones // the caller may have left open files (lxc-attach has this issue) { int fd; for(fd = (int) (sysconf(_SC_OPEN_MAX) - 1); fd > 2; fd--) if(fd_is_valid(fd)) close(fd); } #endif if(!config_loaded) config_load(NULL, 0); // ------------------------------------------------------------------------ // initialize netdata { char *pmax = config_get(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for plugins", "1"); if(pmax && *pmax) setenv("MALLOC_ARENA_MAX", pmax, 1); #if defined(HAVE_C_MALLOPT) i = (int)config_get_number(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for netdata", 1); if(i > 0) mallopt(M_ARENA_MAX, 1); #endif // prepare configuration environment variables for the plugins get_netdata_configured_variables(); set_global_environment(); // work while we are cd into config_dir // to allow the plugins refer to their config // files using relative filenames if(chdir(netdata_configured_config_dir) == -1) fatal("Cannot cd to '%s'", netdata_configured_config_dir); } char *user = NULL; { // -------------------------------------------------------------------- // get the debugging flags from the configuration file char *flags = config_get(CONFIG_SECTION_GLOBAL, "debug flags", "0x0000000000000000"); setenv("NETDATA_DEBUG_FLAGS", flags, 1); debug_flags = strtoull(flags, NULL, 0); debug(D_OPTIONS, "Debug flags set to '0x%" PRIX64 "'.", debug_flags); if(debug_flags != 0) { struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; if(setrlimit(RLIMIT_CORE, &rl) != 0) error("Cannot request unlimited core dumps for debugging... Proceeding anyway..."); #ifdef HAVE_SYS_PRCTL_H prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); #endif } // -------------------------------------------------------------------- // get log filenames and settings log_init(); error_log_limit_unlimited(); // -------------------------------------------------------------------- // load stream.conf { char filename[FILENAME_MAX + 1]; snprintfz(filename, FILENAME_MAX, "%s/stream.conf", netdata_configured_config_dir); appconfig_load(&stream_config, filename, 0); } // -------------------------------------------------------------------- // setup process signals // block signals while initializing threads. // this causes the threads to block signals. signals_block(); // setup the signals we want to use signals_init(); // setup threads configs default_stacksize = netdata_threads_init(); // -------------------------------------------------------------------- // check which threads are enabled and initialize them for (i = 0; static_threads[i].name != NULL ; i++) { struct netdata_static_thread *st = &static_threads[i]; if(st->config_name) st->enabled = config_get_boolean(st->config_section, st->config_name, st->enabled); if(st->enabled && st->init_routine) st->init_routine(); } // -------------------------------------------------------------------- // get the user we should run // IMPORTANT: this is required before web_files_uid() if(getuid() == 0) { user = config_get(CONFIG_SECTION_GLOBAL, "run as user", NETDATA_USER); } else { struct passwd *passwd = getpwuid(getuid()); user = config_get(CONFIG_SECTION_GLOBAL, "run as user", (passwd && passwd->pw_name)?passwd->pw_name:""); } // -------------------------------------------------------------------- // create the listening sockets web_client_api_v1_init(); web_server_threading_selection(); if(web_server_mode != WEB_SERVER_MODE_NONE) api_listen_sockets_setup(); } // initialize the log files open_all_log_files(); #ifdef NETDATA_INTERNAL_CHECKS if(debug_flags != 0) { struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; if(setrlimit(RLIMIT_CORE, &rl) != 0) error("Cannot request unlimited core dumps for debugging... Proceeding anyway..."); #ifdef HAVE_SYS_PRCTL_H prctl(PR_SET_DUMPABLE, 1, 0, 0, 0); #endif } #endif /* NETDATA_INTERNAL_CHECKS */ // get the max file limit if(getrlimit(RLIMIT_NOFILE, &rlimit_nofile) != 0) error("getrlimit(RLIMIT_NOFILE) failed"); else info("resources control: allowed file descriptors: soft = %zu, max = %zu", rlimit_nofile.rlim_cur, rlimit_nofile.rlim_max); // fork, switch user, create pid file, set process priority if(become_daemon(dont_fork, user) == -1) fatal("Cannot daemonize myself."); info("netdata started on pid %d.", getpid()); // IMPORTANT: these have to run once, while single threaded // but after we have switched user web_files_uid(); web_files_gid(); netdata_threads_init_after_fork((size_t)config_get_number(CONFIG_SECTION_GLOBAL, "pthread stack size", (long)default_stacksize)); // ------------------------------------------------------------------------ // initialize rrd, registry, health, rrdpush, etc. rrd_init(netdata_configured_hostname); // ------------------------------------------------------------------------ // enable log flood protection error_log_limit_reset(); // ------------------------------------------------------------------------ // spawn the threads web_server_config_options(); for (i = 0; static_threads[i].name != NULL ; i++) { struct netdata_static_thread *st = &static_threads[i]; if(st->enabled) { st->thread = mallocz(sizeof(netdata_thread_t)); debug(D_SYSTEM, "Starting thread %s.", st->name); netdata_thread_create(st->thread, st->name, NETDATA_THREAD_OPTION_DEFAULT, st->start_routine, st); } else debug(D_SYSTEM, "Not starting thread %s.", st->name); } info("netdata initialization completed. Enjoy real-time performance monitoring!"); // ------------------------------------------------------------------------ // unblock signals signals_unblock(); // ------------------------------------------------------------------------ // Handle signals signals_handle(); // should never reach this point // but we need it for rpmlint #2752 return 1; }
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; }
static void parse_arguments(int argc, char *argv[], struct afb_config *config) { char* programName = argv [0]; int optionIndex = 0; int optc, ind; int nbcmd; struct option *gnuOptions; // ------------------ Process Command Line ----------------------- // if no argument print help and return if (argc < 2) { printHelp(stderr, programName); exit(1); } // build GNU getopt info from cliOptions nbcmd = sizeof (cliOptions) / sizeof (AFB_options); gnuOptions = malloc (sizeof (*gnuOptions) * (unsigned)nbcmd); for (ind=0; ind < nbcmd;ind++) { gnuOptions [ind].name = cliOptions[ind].name; gnuOptions [ind].has_arg = cliOptions[ind].has_arg; gnuOptions [ind].flag = 0; gnuOptions [ind].val = cliOptions[ind].val; } // get all options from command line while ((optc = getopt_long (argc, argv, "vsp?", gnuOptions, &optionIndex)) != EOF) { switch (optc) { case SET_VERBOSE: verbosity++; break; case SET_TCP_PORT: if (optarg == 0) goto needValueForOption; if (!sscanf (optarg, "%d", &config->httpdPort)) goto notAnInteger; break; case SET_APITIMEOUT: if (optarg == 0) goto needValueForOption; if (!sscanf (optarg, "%d", &config->apiTimeout)) goto notAnInteger; break; case SET_CNTXTIMEOUT: if (optarg == 0) goto needValueForOption; if (!sscanf (optarg, "%d", &config->cntxTimeout)) goto notAnInteger; break; case SET_ROOT_DIR: if (optarg == 0) goto needValueForOption; config->rootdir = optarg; INFO("Forcing Rootdir=%s",config->rootdir); break; case SET_ROOT_BASE: if (optarg == 0) goto needValueForOption; config->rootbase = optarg; INFO("Forcing Rootbase=%s",config->rootbase); break; case SET_ROOT_API: if (optarg == 0) goto needValueForOption; config->rootapi = optarg; INFO("Forcing Rootapi=%s",config->rootapi); break; case SET_ALIAS: if (optarg == 0) goto needValueForOption; if ((unsigned)config->aliascount < sizeof (config->aliasdir) / sizeof (config->aliasdir[0])) { config->aliasdir[config->aliascount].url = strsep(&optarg,":"); if (optarg == NULL) { ERROR("missing ':' in alias %s, ignored", config->aliasdir[config->aliascount].url); } else { config->aliasdir[config->aliascount].path = optarg; INFO("Alias url=%s path=%s", config->aliasdir[config->aliascount].url, config->aliasdir[config->aliascount].path); config->aliascount++; } } else { ERROR("Too many aliases [max:%d] %s ignored", MAX_ALIAS, optarg); } break; case SET_AUTH_TOKEN: if (optarg == 0) goto needValueForOption; config->token = optarg; break; case SET_LDPATH: if (optarg == 0) goto needValueForOption; config->ldpaths = optarg; break; case SET_SESSION_DIR: if (optarg == 0) goto needValueForOption; config->sessiondir = optarg; break; case SET_CACHE_TIMEOUT: if (optarg == 0) goto needValueForOption; if (!sscanf (optarg, "%d", &config->cacheTimeout)) goto notAnInteger; break; case SET_FORGROUND: if (optarg != 0) goto noValueForOption; config->background = 0; break; case SET_BACKGROUND: if (optarg != 0) goto noValueForOption; config->background = 1; break; case SET_MODE: if (optarg == 0) goto needValueForOption; if (!strcmp(optarg, "local")) config->mode = AFB_MODE_LOCAL; else if (!strcmp(optarg, "remote")) config->mode = AFB_MODE_REMOTE; else if (!strcmp(optarg, "global")) config->mode = AFB_MODE_GLOBAL; else goto badMode; break; case SET_READYFD: if (optarg == 0) goto needValueForOption; if (!sscanf (optarg, "%u", &config->readyfd)) goto notAnInteger; break; case DBUS_CLIENT: case DBUS_SERVICE: case SO_PLUGIN: if (optarg == 0) goto needValueForOption; add_item(config, optc, optarg); break; case DISPLAY_VERSION: if (optarg != 0) goto noValueForOption; printVersion(stdout); break; case DISPLAY_HELP: default: printHelp(stdout, programName); exit(0); } } free(gnuOptions); config_set_default (config); return; needValueForOption: ERROR("AFB-daemon option [--%s] need a value i.e. --%s=xxx" ,gnuOptions[optionIndex].name, gnuOptions[optionIndex].name); exit (1); notAnInteger: ERROR("AFB-daemon option [--%s] requirer an interger i.e. --%s=9" ,gnuOptions[optionIndex].name, gnuOptions[optionIndex].name); exit (1); noValueForOption: ERROR("AFB-daemon option [--%s] don't take value" ,gnuOptions[optionIndex].name); exit (1); badMode: ERROR("AFB-daemon option [--%s] only accepts local, global or remote." ,gnuOptions[optionIndex].name); exit (1); }