int main(int argc, char *argv[]) { const char *path, *error; master_service = master_service_init("config", 0, &argc, &argv, ""); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; master_service_init_log(master_service, "config: "); restrict_access_by_env(NULL, FALSE); restrict_access_allow_coredumps(TRUE); config_parse_load_modules(); path = master_service_get_config_path(master_service); if (config_parse_file(path, TRUE, NULL, &error) <= 0) i_fatal("%s", error); /* notify about our success only after successfully parsing the config file, so if the parsing fails, master won't immediately just recreate this process (and fail again and so on). */ master_service_init_finish(master_service); master_service_run(master_service, client_connected); config_connections_destroy_all(); config_filter_deinit(&config_filter); module_dir_unload(&modules); master_service_deinit(&master_service); return 0; }
int main(int argc, char *argv[]) { const char *path, *error; master_service = master_service_init("config", 0, &argc, &argv, NULL); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; master_service_init_log(master_service, "config: "); restrict_access_by_env(NULL, FALSE); restrict_access_allow_coredumps(TRUE); master_service_init_finish(master_service); config_parse_load_modules(); path = master_service_get_config_path(master_service); if (config_parse_file(path, TRUE, "", &error) <= 0) i_fatal("%s", error); master_service_run(master_service, client_connected); config_connections_destroy_all(); config_filter_deinit(&config_filter); module_dir_unload(&modules); master_service_deinit(&master_service); return 0; }
int config_open_defaults(config_t *config, const char *file) { if (!config) return CONFIG_ERROR; return config_parse_file(&config->defaults, file, false); }
static int syslog_init(void) { /* FIXME: error handling */ config_parse_file("SYSLOG", &level_ce); if (!strcmp(facility_ce.u.string, "LOG_DAEMON")) syslog_facility = LOG_DAEMON; else if (!strcmp(facility_ce.u.string, "LOG_KERN")) syslog_facility = LOG_KERN; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL0")) syslog_facility = LOG_LOCAL0; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL1")) syslog_facility = LOG_LOCAL1; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL2")) syslog_facility = LOG_LOCAL2; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL3")) syslog_facility = LOG_LOCAL3; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL4")) syslog_facility = LOG_LOCAL4; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL5")) syslog_facility = LOG_LOCAL5; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL6")) syslog_facility = LOG_LOCAL6; else if (!strcmp(facility_ce.u.string, "LOG_LOCAL7")) syslog_facility = LOG_LOCAL7; else if (!strcmp(facility_ce.u.string, "LOG_USER")) syslog_facility = LOG_USER; else { ulogd_log(ULOGD_FATAL, "unknown facility '%s'\n", facility_ce.u.string); exit(2); } if (!strcmp(level_ce.u.string, "LOG_EMERG")) syslog_level = LOG_EMERG; else if (!strcmp(level_ce.u.string, "LOG_ALERT")) syslog_level = LOG_ALERT; else if (!strcmp(level_ce.u.string, "LOG_CRIT")) syslog_level = LOG_CRIT; else if (!strcmp(level_ce.u.string, "LOG_ERR")) syslog_level = LOG_ERR; else if (!strcmp(level_ce.u.string, "LOG_WARNING")) syslog_level = LOG_WARNING; else if (!strcmp(level_ce.u.string, "LOG_NOTICE")) syslog_level = LOG_NOTICE; else if (!strcmp(level_ce.u.string, "LOG_INFO")) syslog_level = LOG_INFO; else if (!strcmp(level_ce.u.string, "LOG_DEBUG")) syslog_level = LOG_DEBUG; else { ulogd_log(ULOGD_FATAL, "unknown level '%s'\n", level_ce.u.string); exit(2); } openlog("ulogd", LOG_NDELAY|LOG_PID, syslog_facility); return 0; }
static int configure(struct ulogd_pluginstance *upi, struct ulogd_pluginstance_stack *stack) { ulogd_log(ULOGD_DEBUG, "parsing config file section `%s', " "plugin `%s'\n", upi->id, upi->plugin->name); config_parse_file(upi->id, upi->config_kset); return 0; }
int config_parse_opt_line(int argc, char *argv[], mme_config_t *mme_config_p) { int c; mme_config_init(mme_config_p); /* Parsing command line */ while ((c = getopt (argc, argv, "O:c:hi:K:v:V")) != -1) { switch (c) { case 'O': case 'c': { /* Store the given configuration file. If no file is given, * then the default values will be used. */ int config_file_len = 0; config_file_len = strlen(optarg); mme_config_p->config_file = malloc(sizeof(char) * (config_file_len + 1)); memcpy(mme_config_p->config_file, optarg, config_file_len); mme_config_p->config_file[config_file_len] = '\0'; } break; case 'v': { mme_config_p->verbosity_level = atoi(optarg); } break; case 'V': { fprintf(stdout, "==== EURECOM %s v%s ====\n" "Please report any bug to: %s\n", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_BUGREPORT); exit(0); nwGtpv1uDisplayBanner(); } break; case 'K': mme_config_p->itti_config.log_file = strdup(optarg); break; case 'h': /* Fall through */ default: usage(); exit(0); } } /* Parse the configuration file using libconfig */ if (config_parse_file(mme_config_p) != 0) { return -1; } /* Display the configuration */ config_display(mme_config_p); return 0; }
int main(int argc, char *argv[]) { int ret; if (argc != 5) { printf("Usage: %s HOST PORT EVENT_NAME CONFIG_FILE\n", argv[0]); return 1; } settings.smsalarm = 0; //settings.logfname = "-"; log_init(); if (config_parse_file(argv[4], &g_cfg) != 1) { printf("parse config file %s failure", argv[3]); return 1; } mevent_t *evt = mevent_init(argv[3]); if (evt == NULL) { printf("init error\n"); SMS_ALARM("mevent_init error"); return 1; } struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 800000; mevent_add_udp_server(evt, argv[1], atoi(argv[2]), NULL, &tv); ret = mevent_trigger(evt, NULL, REQ_CMD_STATS, FLAGS_SYNC); if (PROCESS_OK(ret)) { hdf_dump(evt->hdfrcv, NULL); } else { int try = 0; redo: sleep(10); ret = mevent_trigger(evt, NULL, REQ_CMD_STATS, FLAGS_SYNC); if (PROCESS_NOK(ret) && try < 3) { try++; goto redo; } if (PROCESS_NOK(ret) && try >= 3) { printf("process failure %d\n", ret); SMS_ALARM("process failure %d, restarted", ret); system("killall -9 mevent; sleep 2; /usr/local/revive/xport/daemon/mevent -c /usr/local/revive/xport/conf/server.hdf"); } else { printf("process temproray error %d, %d", ret, try); } } mevent_free(evt); return 0; }
void config_parse_spec(const char *pathspec) { size_t len; char *filename; if (pathspec[0] == PANDORA_PROFILE_CHAR) { ++pathspec; len = sizeof(DATADIR) + sizeof(PACKAGE) + strlen(pathspec); filename = xcalloc(len, sizeof(char)); strcpy(filename, DATADIR "/" PACKAGE "/"); strcat(filename, pathspec); config_parse_file(filename); free(filename); } else config_parse_file(pathspec); }
void event_config_read (void) { int ret; ice_config_t *config; ice_config_t new_config, old_config; /* reread config file */ INFO0("Re-reading XML"); config = config_grab_config(); /* Both to get the lock, and to be able to find out the config filename */ xmlSetGenericErrorFunc (config->config_filename, log_parse_failure); xmlSetStructuredErrorFunc ("conf/file", config_xml_parse_failure); ret = config_parse_file(config->config_filename, &new_config); if(ret < 0) { ERROR0("Error parsing config, not replacing existing config"); switch(ret) { case CONFIG_EINSANE: ERROR0("Config filename null or blank"); break; case CONFIG_ENOROOT: ERROR1("Root element not found in %s", config->config_filename); break; case CONFIG_EBADROOT: ERROR1("Not an icecast2 config file: %s", config->config_filename); break; default: ERROR1("Parse error in reading %s", config->config_filename); break; } config_release_config(); } else { restart_logging (&new_config); config_set_config (&new_config, &old_config); config_release_config(); connection_thread_shutdown(); redirector_clearall(); fserve_scan ((time_t)0); config = config_get_config(); yp_recheck_config (config); fserve_recheck_mime_types (config); stats_global (config); workers_adjust (config->workers_count); connection_listen_sockets_close (config, 0); redirector_setup (config); update_relays (config); config_release_config(); slave_restart(); config_clear (&old_config); } }
static int binbasic_init(void) { #ifdef DEBUG of = stdout; #else config_parse_file("BINBASIC", &outf_ce); of = fopen(outf_ce.u.string, "a"); if (!of) { ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n", strerror(errno)); exit(2); } #endif return 0; }
int parse_filename(char * filename, struct configobj ** newcfg) { struct configobj * mycfg; mycfg = config_new(NULL); *newcfg = mycfg; config_parse_file(mycfg, filename); printf("\nDumping has table key/value pairs.\n"); dump_string_ht(mycfg->config_options); printf("\n"); /* config_destroy(mycfg); */ return 0; }
int main(void) { ice_config_t *config; config_initialize(); config_parse_file("icecast.xml"); config = config_get_config_unlocked(); _dump_config(config); config_shutdown(); return 0; }
/* called at startup, after init_func's */ void config_load() { #ifdef CONFIG_CONFIG_FILE config_selected = 1; config_preset_name = config_choose_startup_preset(); if (config_preset_name) { NotifyBox(2000, "Config: %s", config_preset_name); if (!DISPLAY_IS_ON) beep(); } char config_file[0x80]; snprintf(config_file, sizeof(config_file), "%smagic.cfg", get_config_dir()); config_parse_file(config_file); #endif config_ok = 1; }
void event_config_read(void *arg) { int ret; ice_config_t *config; ice_config_t new_config; /* reread config file */ config = config_grab_config(); /* Both to get the lock, and to be able to find out the config filename */ xmlSetGenericErrorFunc ("config", log_parse_failure); ret = config_parse_file(config->config_filename, &new_config); if(ret < 0) { ICECAST_LOG_ERROR("Error parsing config, not replacing existing config"); switch(ret) { case CONFIG_EINSANE: ICECAST_LOG_ERROR("Config filename null or blank"); break; case CONFIG_ENOROOT: ICECAST_LOG_ERROR("Root element not found in %s", config->config_filename); break; case CONFIG_EBADROOT: ICECAST_LOG_ERROR("Not an icecast2 config file: %s", config->config_filename); break; default: ICECAST_LOG_ERROR("Parse error in reading %s", config->config_filename); break; } config_release_config(); } else { config_clear(config); config_set_config(&new_config); config = config_get_config_unlocked(); restart_logging (config); yp_recheck_config (config); fserve_recheck_mime_types (config); stats_global (config); config_release_config(); slave_update_all_mounts(); } }
int calipso_main() { /*load all modules true by default*/ int load_mod_flag = 1; calipso_config_t *config = NULL; /* init server */ calipso_init(); #ifdef USE_SSL calipso_ssl_init(); #endif /* init coniguration */ TRACE("Calipso init...\n"); config = calipso_config_alloc(); config_parse_file( config , CALIPSO_DEFAULT_CONFIG); //#if 0 calipso_set_config(config); /* init signal handlers */ calipso_init_all_signal_handlers(); /* loading modules */ calipso_modules_init(config, load_mod_flag); /* HOOKS init all modules */ calipso_trigger_hook(HOOK_INIT); calipso_trigger_hook(HOOK_CONFIGURE); //calipso_suppress_stdio(); /* init events */ cpo_events_init(); /* config should not be used anymore*/ config_unalloc(calipso->config); calipso->config = NULL; /* main loop */ //cpo_events_loop(); //#endif return 0; }
int config_open(config_t **config, const char *file, enum config_open_type open_type) { int errorcode; bool always_open = open_type == CONFIG_OPEN_ALWAYS; if (!config) return CONFIG_ERROR; *config = bzalloc(sizeof(struct config_data)); if (!*config) return CONFIG_ERROR; (*config)->file = bstrdup(file); errorcode = config_parse_file(&(*config)->sections, file, always_open); if (errorcode != CONFIG_SUCCESS) { config_close(*config); *config = NULL; } return errorcode; }
/* ** Perform a reduce action and the shift that must immediately ** follow the reduce. */ static void yy_reduce( yyParser *yypParser, /* The parser */ int yyruleno /* Number of the rule by which to reduce */ ){ int yygoto; /* The next state */ int yyact; /* The next action */ YYMINORTYPE yygotominor; /* The LHS of the rule reduced */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ configparserARG_FETCH; yymsp = &yypParser->yystack[yypParser->yyidx]; #ifndef NDEBUG if( yyTraceFILE && yyruleno>=0 && yyruleno<sizeof(yyRuleName)/sizeof(yyRuleName[0]) ){ fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt, yyRuleName[yyruleno]); } #endif /* NDEBUG */ switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example ** follows: ** case 0: ** #line <lineno> <grammarfile> ** { ... } // User supplied code ** #line <lineno> <thisfile> ** break; */ case 0: /* No destructor defined for metalines */ break; case 1: /* No destructor defined for metalines */ /* No destructor defined for metaline */ break; case 2: break; case 3: /* No destructor defined for varline */ break; case 4: /* No destructor defined for global */ break; case 5: #line 115 "./configparser.y" { yymsp[-1].minor.yy78 = NULL; } #line 822 "configparser.c" yy_destructor(1,&yymsp[0].minor); break; case 6: /* No destructor defined for include */ break; case 7: /* No destructor defined for include_shell */ break; case 8: yy_destructor(1,&yymsp[0].minor); break; case 9: #line 144 "./configparser.y" { if (ctx->ok) { buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43); if (strncmp(yymsp[-2].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) { fprintf(stderr, "Setting env variable is not supported in conditional %d %s: %s\n", ctx->current->context_ndx, ctx->current->key->ptr, yymsp[-2].minor.yy43->ptr); ctx->ok = 0; } else if (NULL == array_get_element(ctx->current->value, yymsp[0].minor.yy41->key->ptr)) { array_insert_unique(ctx->current->value, yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } else { fprintf(stderr, "Duplicate config variable in conditional %d %s: %s\n", ctx->current->context_ndx, ctx->current->key->ptr, yymsp[0].minor.yy41->key->ptr); ctx->ok = 0; yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } } buffer_free(yymsp[-2].minor.yy43); yymsp[-2].minor.yy43 = NULL; } #line 859 "configparser.c" yy_destructor(2,&yymsp[-1].minor); break; case 10: #line 168 "./configparser.y" { array *vars = ctx->current->value; data_unset *du; if (strncmp(yymsp[-2].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) { fprintf(stderr, "Appending env variable is not supported in conditional %d %s: %s\n", ctx->current->context_ndx, ctx->current->key->ptr, yymsp[-2].minor.yy43->ptr); ctx->ok = 0; } else if (NULL != (du = array_get_element(vars, yymsp[-2].minor.yy43->ptr))) { /* exists in current block */ du = configparser_merge_data(du, yymsp[0].minor.yy41); if (NULL == du) { ctx->ok = 0; } else { buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43); array_replace(vars, du); } yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); } else if (NULL != (du = configparser_get_variable(ctx, yymsp[-2].minor.yy43))) { du = configparser_merge_data(du, yymsp[0].minor.yy41); if (NULL == du) { ctx->ok = 0; du->free(du); } else { buffer_copy_string_buffer(du->key, yymsp[-2].minor.yy43); array_insert_unique(ctx->current->value, du); } yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); } else { buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43); array_insert_unique(ctx->current->value, yymsp[0].minor.yy41); } buffer_free(yymsp[-2].minor.yy43); yymsp[-2].minor.yy43 = NULL; yymsp[0].minor.yy41 = NULL; } #line 903 "configparser.c" yy_destructor(3,&yymsp[-1].minor); break; case 11: #line 208 "./configparser.y" { if (strchr(yymsp[0].minor.yy0->ptr, '.') == NULL) { yygotominor.yy43 = buffer_init_string("var."); buffer_append_string_buffer(yygotominor.yy43, yymsp[0].minor.yy0); buffer_free(yymsp[0].minor.yy0); yymsp[0].minor.yy0 = NULL; } else { yygotominor.yy43 = yymsp[0].minor.yy0; yymsp[0].minor.yy0 = NULL; } } #line 919 "configparser.c" break; case 12: #line 220 "./configparser.y" { yygotominor.yy41 = configparser_merge_data(yymsp[-2].minor.yy41, yymsp[0].minor.yy41); if (NULL == yygotominor.yy41) { ctx->ok = 0; } yymsp[-2].minor.yy41 = NULL; yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } #line 932 "configparser.c" yy_destructor(5,&yymsp[-1].minor); break; case 13: #line 230 "./configparser.y" { yygotominor.yy41 = yymsp[0].minor.yy41; yymsp[0].minor.yy41 = NULL; } #line 941 "configparser.c" break; case 14: #line 235 "./configparser.y" { yygotominor.yy41 = NULL; if (strncmp(yymsp[0].minor.yy43->ptr, "env.", sizeof("env.") - 1) == 0) { char *env; if (NULL != (env = getenv(yymsp[0].minor.yy43->ptr + 4))) { data_string *ds; ds = data_string_init(); buffer_append_string(ds->value, env); yygotominor.yy41 = (data_unset *)ds; } else { fprintf(stderr, "Undefined env variable: %s\n", yymsp[0].minor.yy43->ptr + 4); ctx->ok = 0; } } else if (NULL == (yygotominor.yy41 = configparser_get_variable(ctx, yymsp[0].minor.yy43))) { fprintf(stderr, "Undefined config variable: %s\n", yymsp[0].minor.yy43->ptr); ctx->ok = 0; } if (!yygotominor.yy41) { /* make a dummy so it won't crash */ yygotominor.yy41 = (data_unset *)data_string_init(); } buffer_free(yymsp[0].minor.yy43); yymsp[0].minor.yy43 = NULL; } #line 971 "configparser.c" break; case 15: #line 262 "./configparser.y" { yygotominor.yy41 = (data_unset *)data_string_init(); buffer_copy_string_buffer(((data_string *)(yygotominor.yy41))->value, yymsp[0].minor.yy0); buffer_free(yymsp[0].minor.yy0); yymsp[0].minor.yy0 = NULL; } #line 981 "configparser.c" break; case 16: #line 269 "./configparser.y" { yygotominor.yy41 = (data_unset *)data_integer_init(); ((data_integer *)(yygotominor.yy41))->value = strtol(yymsp[0].minor.yy0->ptr, NULL, 10); buffer_free(yymsp[0].minor.yy0); yymsp[0].minor.yy0 = NULL; } #line 991 "configparser.c" break; case 17: #line 275 "./configparser.y" { yygotominor.yy41 = (data_unset *)data_array_init(); array_free(((data_array *)(yygotominor.yy41))->value); ((data_array *)(yygotominor.yy41))->value = yymsp[0].minor.yy40; yymsp[0].minor.yy40 = NULL; } #line 1001 "configparser.c" break; case 18: #line 281 "./configparser.y" { yygotominor.yy40 = array_init(); } #line 1008 "configparser.c" yy_destructor(8,&yymsp[-1].minor); yy_destructor(9,&yymsp[0].minor); break; case 19: #line 284 "./configparser.y" { yygotominor.yy40 = yymsp[-1].minor.yy40; yymsp[-1].minor.yy40 = NULL; } #line 1018 "configparser.c" yy_destructor(8,&yymsp[-2].minor); yy_destructor(9,&yymsp[0].minor); break; case 20: #line 289 "./configparser.y" { if (buffer_is_empty(yymsp[0].minor.yy41->key) || NULL == array_get_element(yymsp[-2].minor.yy40, yymsp[0].minor.yy41->key->ptr)) { array_insert_unique(yymsp[-2].minor.yy40, yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } else { fprintf(stderr, "Duplicate array-key: %s\n", yymsp[0].minor.yy41->key->ptr); ctx->ok = 0; yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } yygotominor.yy40 = yymsp[-2].minor.yy40; yymsp[-2].minor.yy40 = NULL; } #line 1040 "configparser.c" yy_destructor(10,&yymsp[-1].minor); break; case 21: #line 306 "./configparser.y" { yygotominor.yy40 = yymsp[-1].minor.yy40; yymsp[-1].minor.yy40 = NULL; } #line 1049 "configparser.c" yy_destructor(10,&yymsp[0].minor); break; case 22: #line 311 "./configparser.y" { yygotominor.yy40 = array_init(); array_insert_unique(yygotominor.yy40, yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } #line 1059 "configparser.c" break; case 23: #line 317 "./configparser.y" { yygotominor.yy41 = yymsp[0].minor.yy41; yymsp[0].minor.yy41 = NULL; } #line 1067 "configparser.c" break; case 24: #line 321 "./configparser.y" { buffer_copy_string_buffer(yymsp[0].minor.yy41->key, yymsp[-2].minor.yy43); buffer_free(yymsp[-2].minor.yy43); yymsp[-2].minor.yy43 = NULL; yygotominor.yy41 = yymsp[0].minor.yy41; yymsp[0].minor.yy41 = NULL; } #line 1079 "configparser.c" yy_destructor(11,&yymsp[-1].minor); break; case 25: yy_destructor(1,&yymsp[0].minor); break; case 26: break; case 27: #line 333 "./configparser.y" { data_config *dc; dc = (data_config *)array_get_element(ctx->srv->config_context, "global"); assert(dc); configparser_push(ctx, dc, 0); } #line 1095 "configparser.c" yy_destructor(12,&yymsp[0].minor); break; case 28: #line 340 "./configparser.y" { data_config *cur; cur = ctx->current; configparser_pop(ctx); assert(cur && ctx->current); yygotominor.yy78 = cur; } #line 1110 "configparser.c" /* No destructor defined for globalstart */ yy_destructor(13,&yymsp[-2].minor); /* No destructor defined for metalines */ yy_destructor(14,&yymsp[0].minor); break; case 29: #line 351 "./configparser.y" { assert(yymsp[-3].minor.yy78->context_ndx < yymsp[0].minor.yy78->context_ndx); yymsp[0].minor.yy78->prev = yymsp[-3].minor.yy78; yymsp[-3].minor.yy78->next = yymsp[0].minor.yy78; yygotominor.yy78 = yymsp[0].minor.yy78; yymsp[-3].minor.yy78 = NULL; yymsp[0].minor.yy78 = NULL; } #line 1126 "configparser.c" /* No destructor defined for eols */ yy_destructor(15,&yymsp[-1].minor); break; case 30: #line 360 "./configparser.y" { yygotominor.yy78 = yymsp[0].minor.yy78; yymsp[0].minor.yy78 = NULL; } #line 1136 "configparser.c" break; case 31: #line 365 "./configparser.y" { data_config *cur; cur = ctx->current; configparser_pop(ctx); assert(cur && ctx->current); yygotominor.yy78 = cur; } #line 1150 "configparser.c" /* No destructor defined for context */ yy_destructor(13,&yymsp[-2].minor); /* No destructor defined for metalines */ yy_destructor(14,&yymsp[0].minor); break; case 32: #line 376 "./configparser.y" { data_config *dc; buffer *b, *rvalue, *op; if (ctx->ok && yymsp[0].minor.yy41->type != TYPE_STRING) { fprintf(stderr, "rvalue must be string"); ctx->ok = 0; } switch(yymsp[-1].minor.yy27) { case CONFIG_COND_NE: op = buffer_init_string("!="); break; case CONFIG_COND_EQ: op = buffer_init_string("=="); break; case CONFIG_COND_NOMATCH: op = buffer_init_string("!~"); break; case CONFIG_COND_MATCH: op = buffer_init_string("=~"); break; default: assert(0); return; } b = buffer_init(); buffer_copy_string_buffer(b, ctx->current->key); buffer_append_string(b, "/"); buffer_append_string_buffer(b, yymsp[-5].minor.yy0); buffer_append_string_buffer(b, yymsp[-3].minor.yy43); buffer_append_string_buffer(b, op); rvalue = ((data_string*)yymsp[0].minor.yy41)->value; buffer_append_string_buffer(b, rvalue); if (NULL != (dc = (data_config *)array_get_element(ctx->all_configs, b->ptr))) { configparser_push(ctx, dc, 0); } else { struct { comp_key_t comp; char *comp_key; size_t len; } comps[] = { { COMP_SERVER_SOCKET, CONST_STR_LEN("SERVER[\"socket\"]" ) }, { COMP_HTTP_URL, CONST_STR_LEN("HTTP[\"url\"]" ) }, { COMP_HTTP_HOST, CONST_STR_LEN("HTTP[\"host\"]" ) }, { COMP_HTTP_REFERER, CONST_STR_LEN("HTTP[\"referer\"]" ) }, { COMP_HTTP_USER_AGENT, CONST_STR_LEN("HTTP[\"useragent\"]" ) }, { COMP_HTTP_USER_AGENT, CONST_STR_LEN("HTTP[\"user-agent\"]" ) }, { COMP_HTTP_COOKIE, CONST_STR_LEN("HTTP[\"cookie\"]" ) }, { COMP_HTTP_REMOTE_IP, CONST_STR_LEN("HTTP[\"remoteip\"]" ) }, { COMP_HTTP_REMOTE_IP, CONST_STR_LEN("HTTP[\"remote-ip\"]" ) }, { COMP_HTTP_QUERY_STRING, CONST_STR_LEN("HTTP[\"querystring\"]") }, { COMP_HTTP_QUERY_STRING, CONST_STR_LEN("HTTP[\"query-string\"]") }, { COMP_HTTP_REQUEST_METHOD, CONST_STR_LEN("HTTP[\"request-method\"]") }, { COMP_HTTP_SCHEME, CONST_STR_LEN("HTTP[\"scheme\"]" ) }, { COMP_UNSET, NULL, 0 }, }; size_t i; dc = data_config_init(); buffer_copy_string_buffer(dc->key, b); buffer_copy_string_buffer(dc->op, op); buffer_copy_string_buffer(dc->comp_key, yymsp[-5].minor.yy0); buffer_append_string_len(dc->comp_key, CONST_STR_LEN("[\"")); buffer_append_string_buffer(dc->comp_key, yymsp[-3].minor.yy43); buffer_append_string_len(dc->comp_key, CONST_STR_LEN("\"]")); dc->cond = yymsp[-1].minor.yy27; for (i = 0; comps[i].comp_key; i ++) { if (buffer_is_equal_string( dc->comp_key, comps[i].comp_key, comps[i].len)) { dc->comp = comps[i].comp; break; } } if (COMP_UNSET == dc->comp) { fprintf(stderr, "error comp_key %s", dc->comp_key->ptr); ctx->ok = 0; } switch(yymsp[-1].minor.yy27) { case CONFIG_COND_NE: case CONFIG_COND_EQ: dc->string = buffer_init_buffer(rvalue); break; case CONFIG_COND_NOMATCH: case CONFIG_COND_MATCH: { #ifdef HAVE_PCRE_H const char *errptr; int erroff; if (NULL == (dc->regex = pcre_compile(rvalue->ptr, 0, &errptr, &erroff, NULL))) { dc->string = buffer_init_string(errptr); dc->cond = CONFIG_COND_UNSET; fprintf(stderr, "parsing regex failed: %s -> %s at offset %d\n", rvalue->ptr, errptr, erroff); ctx->ok = 0; } else if (NULL == (dc->regex_study = pcre_study(dc->regex, 0, &errptr)) && errptr != NULL) { fprintf(stderr, "studying regex failed: %s -> %s\n", rvalue->ptr, errptr); ctx->ok = 0; } else { dc->string = buffer_init_buffer(rvalue); } #else fprintf(stderr, "can't handle '$%s[%s] =~ ...' as you compiled without pcre support. \n" "(perhaps just a missing pcre-devel package ?) \n", yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr); ctx->ok = 0; #endif break; } default: fprintf(stderr, "unknown condition for $%s[%s]\n", yymsp[-5].minor.yy0->ptr, yymsp[-3].minor.yy43->ptr); ctx->ok = 0; break; } configparser_push(ctx, dc, 1); } buffer_free(b); buffer_free(op); buffer_free(yymsp[-5].minor.yy0); yymsp[-5].minor.yy0 = NULL; buffer_free(yymsp[-3].minor.yy43); yymsp[-3].minor.yy43 = NULL; yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } #line 1298 "configparser.c" yy_destructor(16,&yymsp[-6].minor); yy_destructor(18,&yymsp[-4].minor); yy_destructor(19,&yymsp[-2].minor); break; case 33: #line 516 "./configparser.y" { yygotominor.yy27 = CONFIG_COND_EQ; } #line 1308 "configparser.c" yy_destructor(20,&yymsp[0].minor); break; case 34: #line 519 "./configparser.y" { yygotominor.yy27 = CONFIG_COND_MATCH; } #line 1316 "configparser.c" yy_destructor(21,&yymsp[0].minor); break; case 35: #line 522 "./configparser.y" { yygotominor.yy27 = CONFIG_COND_NE; } #line 1324 "configparser.c" yy_destructor(22,&yymsp[0].minor); break; case 36: #line 525 "./configparser.y" { yygotominor.yy27 = CONFIG_COND_NOMATCH; } #line 1332 "configparser.c" yy_destructor(23,&yymsp[0].minor); break; case 37: #line 529 "./configparser.y" { yygotominor.yy43 = NULL; if (ctx->ok) { if (yymsp[0].minor.yy41->type == TYPE_STRING) { yygotominor.yy43 = buffer_init_buffer(((data_string*)yymsp[0].minor.yy41)->value); } else if (yymsp[0].minor.yy41->type == TYPE_INTEGER) { yygotominor.yy43 = buffer_init(); buffer_copy_long(yygotominor.yy43, ((data_integer *)yymsp[0].minor.yy41)->value); } else { fprintf(stderr, "operand must be string"); ctx->ok = 0; } } yymsp[0].minor.yy41->free(yymsp[0].minor.yy41); yymsp[0].minor.yy41 = NULL; } #line 1353 "configparser.c" break; case 38: #line 546 "./configparser.y" { if (ctx->ok) { if (0 != config_parse_file(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) { ctx->ok = 0; } buffer_free(yymsp[0].minor.yy43); yymsp[0].minor.yy43 = NULL; } } #line 1366 "configparser.c" yy_destructor(24,&yymsp[-1].minor); break; case 39: #line 556 "./configparser.y" { if (ctx->ok) { if (0 != config_parse_cmd(ctx->srv, ctx, yymsp[0].minor.yy43->ptr)) { ctx->ok = 0; } buffer_free(yymsp[0].minor.yy43); yymsp[0].minor.yy43 = NULL; } } #line 1380 "configparser.c" yy_destructor(25,&yymsp[-1].minor); break; }; yygoto = yyRuleInfo[yyruleno].lhs; yysize = yyRuleInfo[yyruleno].nrhs; yypParser->yyidx -= yysize; yyact = yy_find_reduce_action(yypParser,yygoto); if( yyact < YYNSTATE ){ yy_shift(yypParser,yyact,yygoto,&yygotominor); }else if( yyact == YYNSTATE + YYNRULE + 1 ){ yy_accept(yypParser); } }
int config_read(server *srv, const char *fn) { config_t context; data_config *dc; data_integer *dpid; data_string *dcwd; int ret; char *pos; data_array *modules; context_init(srv, &context); context.all_configs = srv->config_context; #ifdef __WIN32 pos = strrchr(fn, '\\'); #else pos = strrchr(fn, '/'); #endif if (pos) { buffer_copy_string_len(context.basedir, fn, pos - fn + 1); fn = pos + 1; } dc = data_config_init(); buffer_copy_string_len(dc->key, CONST_STR_LEN("global")); assert(context.all_configs->used == 0); dc->context_ndx = context.all_configs->used; array_insert_unique(context.all_configs, (data_unset *)dc); context.current = dc; /* default context */ srv->config = dc->value; dpid = data_integer_init(); dpid->value = getpid(); buffer_copy_string_len(dpid->key, CONST_STR_LEN("var.PID")); array_insert_unique(srv->config, (data_unset *)dpid); dcwd = data_string_init(); buffer_prepare_copy(dcwd->value, 1024); if (NULL != getcwd(dcwd->value->ptr, dcwd->value->size - 1)) { dcwd->value->used = strlen(dcwd->value->ptr) + 1; buffer_copy_string_len(dcwd->key, CONST_STR_LEN("var.CWD")); array_insert_unique(srv->config, (data_unset *)dcwd); } ret = config_parse_file(srv, &context, fn); /* remains nothing if parser is ok */ assert(!(0 == ret && context.ok && 0 != context.configs_stack->used)); context_free(&context); if (0 != ret) { return ret; } if (NULL != (dc = (data_config *)array_get_element(srv->config_context, "global"))) { srv->config = dc->value; } else { return -1; } if (NULL != (modules = (data_array *)array_get_element(srv->config, "server.modules"))) { data_string *ds; data_array *prepends; if (modules->type != TYPE_ARRAY) { fprintf(stderr, "server.modules must be an array"); return -1; } prepends = data_array_init(); /* prepend default modules */ if (NULL == array_get_element(modules->value, "mod_indexfile")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(prepends->value, (data_unset *)ds); } prepends = (data_array *)configparser_merge_data((data_unset *)prepends, (data_unset *)modules); buffer_copy_string_buffer(prepends->key, modules->key); array_replace(srv->config, (data_unset *)prepends); modules->free((data_unset *)modules); modules = prepends; /* append default modules */ if (NULL == array_get_element(modules->value, "mod_dirlisting")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); } if (NULL == array_get_element(modules->value, "mod_staticfile")) { ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); } } else { data_string *ds; modules = data_array_init(); /* server.modules is not set */ ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_indexfile")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_dirlisting")); array_insert_unique(modules->value, (data_unset *)ds); ds = data_string_init(); buffer_copy_string_len(ds->value, CONST_STR_LEN("mod_staticfile")); array_insert_unique(modules->value, (data_unset *)ds); buffer_copy_string_len(modules->key, CONST_STR_LEN("server.modules")); array_insert_unique(srv->config, (data_unset *)modules); } if (0 != config_insert(srv)) { return -1; } return 0; }
static int config_connection_request(struct config_connection *conn, const char *const *args) { struct config_export_context *ctx; struct master_service_settings_output output; struct config_filter filter; const char *path, *error, *module = ""; /* [<args>] */ memset(&filter, 0, sizeof(filter)); for (; *args != NULL; args++) { if (strncmp(*args, "service=", 8) == 0) filter.service = *args + 8; else if (strncmp(*args, "module=", 7) == 0) module = *args + 7; else if (strncmp(*args, "lname=", 6) == 0) filter.local_name = *args + 6; else if (strncmp(*args, "lip=", 4) == 0) { if (net_addr2ip(*args + 4, &filter.local_net) == 0) { filter.local_bits = IPADDR_IS_V4(&filter.local_net) ? 32 : 128; } } else if (strncmp(*args, "rip=", 4) == 0) { if (net_addr2ip(*args + 4, &filter.remote_net) == 0) { filter.remote_bits = IPADDR_IS_V4(&filter.remote_net) ? 32 : 128; } } } if (strcmp(module, "master") == 0) { /* master reads configuration only when reloading settings */ path = master_service_get_config_path(master_service); if (config_parse_file(path, TRUE, "", &error) <= 0) { o_stream_send_str(conn->output, t_strconcat("ERROR ", error, "\n", NULL)); config_connection_destroy(conn); return -1; } } o_stream_cork(conn->output); ctx = config_export_init(module, CONFIG_DUMP_SCOPE_SET, 0, config_request_output, conn->output); config_export_by_filter(ctx, &filter); config_export_get_output(ctx, &output); if (output.specific_services != NULL) { const char *const *s; for (s = output.specific_services; *s != NULL; s++) { o_stream_send_str(conn->output, t_strdup_printf("service=%s\t", *s)); } } if (output.service_uses_local) o_stream_send_str(conn->output, "service-uses-local\t"); if (output.service_uses_remote) o_stream_send_str(conn->output, "service-uses-remote\t"); if (output.used_local) o_stream_send_str(conn->output, "used-local\t"); if (output.used_remote) o_stream_send_str(conn->output, "used-remote\t"); o_stream_send_str(conn->output, "\n"); if (config_export_finish(&ctx) < 0) { config_connection_destroy(conn); return -1; } o_stream_send_str(conn->output, "\n"); o_stream_uncork(conn->output); return 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; }
int config_initial_parse_file(const char *filename) { /* Since we're already pointing at it, we don't need to copy it in place */ return config_parse_file(filename, &_current_configuration); }