2 * Copyright (c) 2012, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <tr_config.h>
43 void tr_print_config (FILE *stream, TR_CFG *cfg) {
44 fprintf(stream, "tr_print_config: Not yet implemented.\n");
48 void tr_cfg_free (TR_CFG *cfg) {
49 /* TBD -- need to deallocate memory as part of dynamic config */
53 TR_CFG_RC tr_apply_new_config (TR_INSTANCE *tr) {
56 return TR_CFG_BAD_PARAMS;
59 tr_cfg_free(tr->active_cfg);
61 tr->active_cfg = tr->new_cfg;
62 return TR_CFG_SUCCESS;
65 static TR_CFG_RC tr_cfg_parse_internal (TR_INSTANCE *tr, json_t *jcfg) {
69 if ((!tr) || (!tr->new_cfg) || (!jcfg))
70 return TR_CFG_BAD_PARAMS;
72 if (NULL == (tr->new_cfg->internal = malloc(sizeof(TR_CFG_INTERNAL))))
75 memset(tr->new_cfg->internal, 0, sizeof(TR_CFG_INTERNAL));
77 if ((NULL != (jint = json_object_get(jcfg, "tr_internal"))) &&
78 (NULL != (jmtd = json_object_get(jint, "max_tree_depth")))) {
79 if (json_is_number(jmtd)) {
80 tr->new_cfg->internal->max_tree_depth = json_integer_value(jmtd);
82 fprintf(stderr,"tr_cfg_parse_internal: Parsing error, max_tree_depth is not a number.\n");
83 return TR_CFG_NOPARSE;
86 /* If not configured, use the default */
87 tr->new_cfg->internal->max_tree_depth = TR_DEFAULT_MAX_TREE_DEPTH;
89 fprintf(stderr, "tr_cfg_parse_internal: Internal config parsed.\n");
90 return TR_CFG_SUCCESS;
93 static TR_RP_CLIENT *tr_cfg_parse_one_rp_client (TR_INSTANCE *tr, json_t *jrp, TR_CFG_RC *rc)
95 TR_RP_CLIENT *rp = NULL;
99 json_t *jftype = NULL;
100 json_t *jfact = NULL;
101 json_t *jfspecs = NULL;
102 json_t *jffield = NULL;
103 json_t *jfrealm = NULL;
106 if ((!jrp) || (!rc)) {
107 fprintf(stderr, "tr_cfg_parse_one_rp_realm: Bad parameters.\n");
109 *rc = TR_CFG_BAD_PARAMS;
113 if (NULL == (rp = malloc(sizeof(TR_RP_CLIENT)))) {
114 fprintf(stderr, "tr_config_parse_one_rp_realm: Out of memory.\n");
119 memset(rp, 0, sizeof(TR_RP_CLIENT));
121 if ((NULL == (jfilt = json_object_get(jrp, "filter"))) ||
122 (NULL == (jfls = json_object_get(jfilt, "filter_lines"))) ||
123 (!json_is_array(jfls)) ||
124 (NULL == (jgns = json_object_get(jrp, "gss_names"))) ||
125 (!json_is_array(jgns))) {
126 fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client configuration.\n");
128 *rc = TR_CFG_NOPARSE;
132 if (0 == json_array_size(jfls)) {
133 fprintf(stderr, "tr_cfg_parse_one_rp_client: RP Client has no filter lines.\n");
134 *rc = TR_CFG_NOPARSE;
138 if ((NULL == (jftype = json_object_get(jfilt, "type"))) ||
139 (!json_is_string(jftype)) ||
140 (strcmp(json_string_value(jftype), "rp_permitted"))) {
141 fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client filter type.\n");
142 *rc = TR_CFG_NOPARSE;
147 /* Right now, we only accept one type of filter, and we only care
148 * about one per rp_client. */
149 if ((NULL == (jfact = json_object_get(json_array_get(jfls, 0), "action"))) ||
150 (!json_is_string(jfact)) ||
151 (strcmp(json_string_value(jfact), "accept"))) {
152 fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client filter action.\n");
153 *rc = TR_CFG_NOPARSE;
157 if ((NULL == (jfspecs = json_object_get(json_array_get(jfls, 0), "filter_specs"))) ||
158 (!json_is_array(jfspecs)) ||
159 (0 == json_array_size(jfspecs))) {
160 fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client filter specs.\n");
161 *rc = TR_CFG_NOPARSE;
165 if ((NULL == (jffield = json_object_get(json_array_get(jfspecs, 0), "field"))) ||
166 (!json_is_string(jffield)) ||
167 (strcmp(json_string_value(jffield), "rp_realm")) ||
168 (NULL == (jfrealm = json_object_get(json_array_get(jfspecs, 0), "match"))) ||
169 (!json_is_string(jfrealm))) {
170 fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client filter field and match.\n");
171 *rc = TR_CFG_NOPARSE;
175 rp->rp_match = tr_new_name((char *)json_string_value(jfrealm));
177 if (0 == json_array_size(jgns)) {
178 fprintf(stderr, "tr_cfg_parse_one_rp_client: RP Client has no GSS Names.\n");
179 *rc = TR_CFG_NOPARSE;
183 if (TR_MAX_GSS_NAMES < json_array_size(jgns)) {
184 fprintf(stderr, "tr_cfg_parse_one_rp_client: RP Client has too many GSS Names.\n");
185 *rc = TR_CFG_NOPARSE;
189 for (i = 0; i < json_array_size(jgns); i++) {
190 if (NULL == (rp->gss_names[i] = tr_new_name ((char *)json_string_value(json_array_get(jgns, i))))) {
191 fprintf(stderr, "tr_cfg_parse_one_rp_client: No memory for GSS Name.\n");
200 static TR_CFG_RC tr_cfg_parse_rp_clients (TR_INSTANCE *tr, json_t *jcfg) {
202 TR_RP_CLIENT *rp = NULL;
203 TR_CFG_RC rc = TR_CFG_SUCCESS;
206 if ((!tr) || (!tr->new_cfg) || (!jcfg))
207 return TR_CFG_BAD_PARAMS;
209 if ((NULL == (jrps = json_object_get(jcfg, "rp_clients"))) ||
210 (!json_is_array(jrps))) {
211 return TR_CFG_NOPARSE;
214 for (i = 0; i < json_array_size(jrps); i++) {
215 if (NULL == (rp = tr_cfg_parse_one_rp_client(tr,
216 json_array_get(jrps, i),
220 fprintf(stderr, "tr_cfg_parse_rp_clients: RP client configured -- first gss: %s, rp_realm: %s\n", rp->gss_names[0]->buf, rp->rp_match->buf);
221 rp->next = tr->new_cfg->rp_clients;
222 tr->new_cfg->rp_clients = rp;
227 static TR_AAA_SERVER *tr_cfg_parse_one_aaa_server (TR_INSTANCE *tr, json_t *jaddr, TR_CFG_RC *rc) {
228 TR_AAA_SERVER *aaa = NULL;
230 if ((!tr) || (!tr->new_cfg) || (!jaddr) || (!json_is_string(jaddr))) {
231 fprintf(stderr, "tr_cfg_parse_one_aaa_server: Bad parameters.\n");
232 *rc = TR_CFG_BAD_PARAMS;
236 if (NULL == (aaa = malloc(sizeof(TR_AAA_SERVER)))) {
237 fprintf(stderr, "tr_config_parse_one_aaa_server: Out of memory.\n");
242 memset(aaa, 0, sizeof(TR_AAA_SERVER));
244 /* TBD -- Handle IPv6 addresses */
245 inet_aton(json_string_value(jaddr), &(aaa->aaa_server_addr));
251 static TR_AAA_SERVER *tr_cfg_parse_aaa_servers (TR_INSTANCE *tr, json_t *jaaas, TR_CFG_RC *rc)
253 TR_AAA_SERVER *aaa = NULL;
254 TR_AAA_SERVER *temp_aaa = NULL;
257 for (i = 0; i < json_array_size(jaaas); i++) {
258 if (NULL == (temp_aaa = tr_cfg_parse_one_aaa_server(tr, json_array_get(jaaas, i), rc))) {
261 /* TBD -- IPv6 addresses */
262 // fprintf(stderr, "tr_cfg_parse_aaa_servers: Configuring AAA Server: ip_addr = %s.\n", inet_ntoa(temp_aaa->aaa_server_addr));
263 temp_aaa->next = aaa;
269 static TR_APC *tr_cfg_parse_apcs (TR_INSTANCE *tr, json_t *japcs, TR_CFG_RC *rc)
273 *rc = TR_CFG_SUCCESS; /* presume success */
275 if ((!japcs) || (!rc)) {
276 fprintf(stderr, "tr_cfg_parse_apcs: Bad parameters.\n");
278 *rc = TR_CFG_BAD_PARAMS;
282 if (NULL == (apc = malloc(sizeof(TR_APC)))) {
283 fprintf (stderr, "tr_cfg_parse_apcs: Out of memory.\n");
288 memset(apc, 0, sizeof(TR_APC));
290 /* TBD, deal with more than one APC. In the meantime, though... */
291 /* Only parse the first APC, because we only know how to deal with one, anyway. */
292 if (0 == json_array_size(japcs))
295 if (NULL == (apc->id = tr_new_name((char *)json_string_value(json_array_get(japcs, 0))))) {
296 fprintf(stderr, "tr_cfg_parse_apcs: No memory for APC name.\n");
304 static TR_IDP_REALM *tr_cfg_parse_one_idp_realm (TR_INSTANCE *tr, json_t *jidp, TR_CFG_RC *rc) {
305 TR_IDP_REALM *idp = NULL;
307 json_t *jscfg = NULL;
308 json_t *jsrvrs = NULL;
309 json_t *japcs = NULL;
311 if ((!jidp) || (!rc)) {
312 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Bad parameters.\n");
314 *rc = TR_CFG_BAD_PARAMS;
318 if (NULL == (idp = malloc(sizeof(TR_IDP_REALM)))) {
319 fprintf(stderr, "tr_config_parse_one_idp_realm: Out of memory.\n");
324 memset(idp, 0, sizeof(TR_IDP_REALM));
326 if ((NULL == (jrid = json_object_get(jidp, "realm_id"))) ||
327 (!json_is_string(jrid)) ||
328 (NULL == (jscfg = json_object_get(jidp, "shared_config"))) ||
329 (!json_is_string(jscfg)) ||
330 (NULL == (jsrvrs = json_object_get(jidp, "aaa_servers"))) ||
331 (!json_is_array(jsrvrs))) {
332 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Error parsing IDP realm configuration.\n");
334 *rc = TR_CFG_NOPARSE;
338 if (0 == strcmp(json_string_value(jscfg), "no")) {
339 idp->shared_config = 0;
341 idp->shared_config = 1;
344 if (NULL == (idp->realm_id = tr_new_name((char *)json_string_value(jrid)))) {
346 fprintf(stderr, "tr_cfg_parse_one_idp_realm: No memory for realm id.\n");
351 if (NULL == (idp->aaa_servers = tr_cfg_parse_aaa_servers(tr, jsrvrs, rc))) {
352 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse AAA servers for realm %s.\n", idp->realm_id->buf);
353 tr_free_name(idp->realm_id);
358 if ((NULL != (japcs = json_object_get(jidp, "apcs"))) &&
359 (json_is_array(japcs))) {
360 if (NULL == (idp->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
361 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse APCs for realm %s .\n", idp->realm_id->buf);
362 tr_free_name(idp->realm_id);
363 /* TBD -- free aaa_servers */;
371 static TR_CFG_RC tr_cfg_parse_idp_realms (TR_INSTANCE *tr, json_t *jcfg)
373 json_t *jidps = NULL;
374 TR_CFG_RC rc = TR_CFG_SUCCESS;
375 TR_IDP_REALM *idp = NULL;
378 if ((!tr) || (!tr->new_cfg) || (!jcfg))
379 return TR_CFG_BAD_PARAMS;
381 if ((NULL == (jidps = json_object_get(jcfg, "idp_realms"))) ||
382 (!json_is_array(jidps))) {
383 return TR_CFG_NOPARSE;
386 for (i = 0; i < json_array_size(jidps); i++) {
387 if (NULL == (idp = tr_cfg_parse_one_idp_realm(tr,
388 json_array_get(jidps, i),
392 fprintf(stderr, "tr_cfg_parse_idp_realms: IDP realm configured: %s.\n", idp->realm_id->buf);
393 idp->next = tr->new_cfg->idp_realms;
394 tr->new_cfg->idp_realms = idp;
399 static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_INSTANCE *tr, json_t *jidps, TR_CFG_RC *rc)
401 TR_IDP_REALM *idp = NULL;
402 TR_IDP_REALM *temp_idp = NULL;
407 (!json_is_array(jidps))) {
409 *rc = TR_CFG_BAD_PARAMS;
413 for (i = 0; i < json_array_size(jidps); i++) {
414 if (NULL == (temp_idp = (tr_cfg_find_idp(tr->new_cfg,
415 tr_new_name((char *)json_string_value(json_array_get(jidps, i))),
417 fprintf(stderr, "tr_cfg_parse_comm_idps: Unknown IDP %s.\n",
418 (char *)json_string_value(json_array_get(jidps, i)));
422 temp_idp->comm_next = idp;
429 static TR_RP_REALM *tr_cfg_parse_comm_rps (TR_INSTANCE *tr, json_t *jrps, TR_CFG_RC *rc)
431 TR_RP_REALM *rp = NULL;
432 TR_RP_REALM *temp_rp = NULL;
437 (!json_is_array(jrps))) {
439 *rc = TR_CFG_BAD_PARAMS;
443 for (i = (json_array_size(jrps)-1); i >= 0; i--) {
444 if (NULL == (temp_rp = malloc(sizeof(TR_RP_REALM)))) {
445 fprintf(stderr, "tr_cfg_parse_comm_rps: Can't allocate memory for RP Realm.\n");
450 memset (temp_rp, 0, sizeof(TR_RP_REALM));
452 if (NULL == (temp_rp->realm_name = tr_new_name((char *)json_string_value(json_array_get(jrps, i))))) {
453 fprintf(stderr, "tr_cfg_parse_comm_rps: No memory for RP Realm Name.\n");
466 static TR_COMM *tr_cfg_parse_one_comm (TR_INSTANCE *tr, json_t *jcomm, TR_CFG_RC *rc) {
467 TR_COMM *comm = NULL;
469 json_t *jtype = NULL;
470 json_t *japcs = NULL;
471 json_t *jidps = NULL;
474 if ((!jcomm) || (!rc)) {
475 fprintf(stderr, "tr_cfg_parse_one_comm: Bad parameters.\n");
477 *rc = TR_CFG_BAD_PARAMS;
481 if (NULL == (comm = malloc(sizeof(TR_COMM)))) {
482 fprintf(stderr, "tr_config_parse_one_comm: Out of memory.\n");
487 memset(comm, 0, sizeof(TR_COMM));
489 if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
490 (!json_is_string(jid)) ||
491 (NULL == (jtype = json_object_get(jcomm, "type"))) ||
492 (!json_is_string(jtype)) ||
493 (NULL == (japcs = json_object_get(jcomm, "apcs"))) ||
494 (!json_is_array(japcs)) ||
495 (NULL == (jidps = json_object_get(jcomm, "idp_realms"))) ||
496 (!json_is_array(jidps)) ||
497 (NULL == (jrps = json_object_get(jcomm, "rp_realms"))) ||
498 (!json_is_array(jrps))) {
499 fprintf(stderr, "tr_cfg_parse_one_comm: Error parsing Communities configuration.\n");
501 *rc = TR_CFG_NOPARSE;
505 if (NULL == (comm->id = tr_new_name((char *)json_string_value(jid)))) {
507 fprintf(stderr, "tr_cfg_parse_one_comm: No memory for community id.\n");
512 if (0 == strcmp(json_string_value(jtype), "apc")) {
513 comm->type = TR_COMM_APC;
514 } else if (0 == strcmp(json_string_value(jtype), "coi")) {
515 comm->type = TR_COMM_COI;
516 if (NULL == (comm->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
517 fprintf(stderr, "tr_cfg_parse_one_comm: Can't parse APCs for COI %s.\n", comm->id->buf);
518 tr_free_name(comm->id);
523 fprintf(stderr, "tr_cfg_parse_one_comm: Invalid community type, comm = %s, type = %s\n", comm->id->buf, json_string_value(jtype));
524 tr_free_name(comm->id);
526 *rc = TR_CFG_NOPARSE;
530 comm->idp_realms = tr_cfg_parse_comm_idps(tr, jidps, rc);
531 if (TR_CFG_SUCCESS != *rc) {
532 fprintf(stderr, "tr_cfg_parse_one_comm: Can't parse IDP realms for comm %s.\n", comm->id->buf);
533 tr_free_name(comm->id);
538 comm->rp_realms = tr_cfg_parse_comm_rps(tr, jrps, rc);
539 if (TR_CFG_SUCCESS != *rc) {
540 fprintf(stderr, "tr_cfg_parse_comm: Can't parse RP realms for comm %s .\n", comm->id->buf);
541 tr_free_name(comm->id);
542 /* TBD -- free idps? */;
550 static TR_CFG_RC tr_cfg_parse_comms (TR_INSTANCE *tr, json_t *jcfg)
552 json_t *jcomms = NULL;
553 TR_CFG_RC rc = TR_CFG_SUCCESS;
554 TR_COMM *comm = NULL;
557 if ((!tr) || (!tr->new_cfg) || (!jcfg)) {
558 fprintf(stderr, "tr_config_parse_comms: Bad Parameters.\n");
559 return TR_CFG_BAD_PARAMS;
562 if (NULL == (comm = malloc(sizeof(TR_COMM)))) {
563 fprintf(stderr, "tr_cfg_parse_comms: Out of Memory\n");
566 memset (comm, 0, sizeof(TR_COMM));
568 if ((NULL == (jcomms = json_object_get(jcfg, "communities"))) ||
569 (!json_is_array(jcomms))) {
570 return TR_CFG_NOPARSE;
573 for (i = 0; i < json_array_size(jcomms); i++) {
574 if (NULL == (comm = tr_cfg_parse_one_comm(tr,
575 json_array_get(jcomms, i),
579 fprintf(stderr, "tr_cfg_parse_comms: Community configured: %s.\n", comm->id->buf);
580 comm->next = tr->new_cfg->comms;
581 tr->new_cfg->comms = comm;
586 TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, json_t *jcfg) {
588 /* If there is a partial/abandoned config lying around, free it */
590 tr_cfg_free(tr->new_cfg);
593 if (NULL == (tr->new_cfg = malloc(sizeof(TR_CFG))))
596 memset(tr->new_cfg, 0, sizeof(TR_CFG));
598 if ((TR_CFG_SUCCESS != tr_cfg_parse_internal(tr, jcfg)) ||
599 (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr, jcfg)) ||
600 (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr, jcfg)) ||
601 (TR_CFG_SUCCESS != tr_cfg_parse_comms(tr, jcfg))) {
602 tr_cfg_free(tr->new_cfg);
605 return TR_CFG_SUCCESS;
608 TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc)
611 TR_IDP_REALM *cfg_idp;
613 if ((!tr_cfg) || (!idp_id)) {
615 *rc = TR_CFG_BAD_PARAMS;
619 for (cfg_idp = tr_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
620 if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
621 fprintf(stderr, "tr_cfg_find_idp: Found %s.\n", idp_id->buf);
625 /* if we didn't find one, return NULL */
629 TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *tr_cfg, TR_NAME *rp_gss, TR_CFG_RC *rc)
631 TR_RP_CLIENT *cfg_rp;
634 if ((!tr_cfg) || (!rp_gss)) {
636 *rc = TR_CFG_BAD_PARAMS;
640 for (cfg_rp = tr_cfg->rp_clients; NULL != cfg_rp; cfg_rp = cfg_rp->next) {
641 for (i = 0; i < TR_MAX_GSS_NAMES; i++) {
642 if (!tr_name_cmp (rp_gss, cfg_rp->gss_names[i])) {
643 fprintf(stderr, "tr_cfg_find_rp: Found %s.\n", rp_gss->buf);
648 /* if we didn't find one, return NULL */
652 json_t *tr_read_config (int n, struct dirent **cfg_files) {
661 fprintf(stderr, "tr_read_config: Parsing %s.\n", cfg_files[n]->d_name);
662 if (NULL == (temp = json_load_file(cfg_files[n]->d_name, JSON_DISABLE_EOF_CHECK, &err))) {
663 fprintf (stderr, "tr_read_config: Error parsing config file %s.\n", cfg_files[n]->d_name);
667 /* TBD -- instead of using json_object_update, iterate through files for non-overlap config? */
671 if (-1 == json_object_update(jcfg, temp)) {
672 fprintf(stderr, "tr_read_config: Error merging config information.\n");
678 // fprintf(stderr, "tr_read_config: Merged configuration complete:\n%s\n", json_dumps(jcfg, 0));
683 static int is_cfg_file(const struct dirent *dent) {
686 /* if the last four letters of the filename are .cfg, return true. */
687 if ((4 <= (n = strlen(dent->d_name))) &&
688 (0 == strcmp(&(dent->d_name[n-4]), ".cfg"))) {
692 /* otherwise, return false. */
696 int tr_find_config_files (struct dirent ***cfg_files) {
699 n = scandir(".", cfg_files, &is_cfg_file, 0);
703 fprintf(stderr, "tr_find_config: scandir error.\n");
708 fprintf (stderr, "tr_find_config: No config files found.\n");
714 fprintf(stderr, "tr_find_config: Config file found (%s).\n", (*cfg_files)[i]->d_name);