From: Jennifer Richards Date: Mon, 20 Jun 2016 17:39:31 +0000 (-0400) Subject: Merge branch 'jennifer/march2016-patches' X-Git-Tag: v1.5.2~2 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=trust_router.git;a=commitdiff_plain;h=5aeb22471d8d6d4a6c2348af8b221a8ff9b62184 Merge branch 'jennifer/march2016-patches' Conflicts (both trivial): common/tr_config.c common/tr_name.c --- 5aeb22471d8d6d4a6c2348af8b221a8ff9b62184 diff --cc common/tr_config.c index fbd5027,629b0a1..587a47c --- a/common/tr_config.c +++ b/common/tr_config.c @@@ -866,19 -908,12 +908,20 @@@ TR_CFG_RC tr_cfg_validate (TR_CFG *trc return rc; } -TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, int n, struct dirent **cfg_files) { +/* Join two paths and return a pointer to the result. This should be freed + * via talloc_free. Returns NULL on failure. */ +static char *join_paths(const char *p1, const char *p2) { + return talloc_asprintf(NULL, "%s/%s", p1, p2); /* returns NULL on a failure */ +} + +/* Reads configuration files in config_dir ("" or "./" will use the current directory) */ +TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, const char *config_dir, int n, struct dirent **cfg_files) { json_t *jcfg; + json_t *jser; json_error_t rc; + char *file_with_path; - if ((!tr) || (!cfg_files)) + if ((!tr) || (!cfg_files) || (n<=0)) return TR_CFG_BAD_PARAMS; /* If there is a partial/abandoned config lying around, free it */ @@@ -892,26 -927,28 +935,35 @@@ /* Parse configuration information from each config file */ while (n--) { - tr_debug("tr_read_config: Parsing %s.", cfg_files[n]->d_name); - if (NULL == (jcfg = json_load_file(cfg_files[n]->d_name, - JSON_DISABLE_EOF_CHECK, &rc))) { - tr_debug("tr_read_config: Error parsing config file %s.", - cfg_files[n]->d_name); + file_with_path=join_paths(config_dir, cfg_files[n]->d_name); /* must free result with talloc_free */ + if(file_with_path == NULL) { + tr_crit("tr_parse_config: error joining path."); + return TR_CFG_NOMEM; + } + tr_debug("tr_parse_config: Parsing %s.", cfg_files[n]->d_name); /* print the filename without the path */ + if (NULL == (jcfg = json_load_file(file_with_path, + JSON_DISABLE_EOF_CHECK, &rc))) { + tr_debug("tr_parse_config: Error parsing config file %s.", + cfg_files[n]->d_name); + talloc_free(file_with_path); return TR_CFG_NOPARSE; } + talloc_free(file_with_path); /* done with filename */ + // Look for serial number and log it if it exists + if (NULL != (jser = json_object_get(jcfg, "serial_number"))) { + if (json_is_number(jser)) { + tr_notice("tr_read_config: Attempting to load revision %i of %s.", + (int *) json_integer_value(jser), + cfg_files[n]->d_name); + } + } + if ((TR_CFG_SUCCESS != tr_cfg_parse_internal(tr->new_cfg, jcfg)) || - (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr->new_cfg, jcfg)) || - (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr->new_cfg, jcfg)) || - (TR_CFG_SUCCESS != tr_cfg_parse_default_servers(tr->new_cfg, jcfg)) || - (TR_CFG_SUCCESS != tr_cfg_parse_comms(tr->new_cfg, jcfg))) { + (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr->new_cfg, jcfg)) || + (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr->new_cfg, jcfg)) || + (TR_CFG_SUCCESS != tr_cfg_parse_default_servers(tr->new_cfg, jcfg)) || + (TR_CFG_SUCCESS != tr_cfg_parse_comms(tr->new_cfg, jcfg))) { tr_cfg_free(tr->new_cfg); return TR_CFG_ERROR; }