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 (NULL == (japcs = json_object_get(jidp, "apcs"))) ||
333 (!json_is_array(japcs))) {
334 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Error parsing IDP realm configuration.\n");
336 *rc = TR_CFG_NOPARSE;
340 if (0 == strcmp(json_string_value(jscfg), "no")) {
341 idp->shared_config = 0;
343 idp->shared_config = 1;
346 if (NULL == (idp->realm_id = tr_new_name((char *)json_string_value(jrid)))) {
348 fprintf(stderr, "tr_cfg_parse_one_idp_realm: No memory for realm id.\n");
353 if (NULL == (idp->aaa_servers = tr_cfg_parse_aaa_servers(tr, jsrvrs, rc))) {
354 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse AAA servers for realm %s.\n", idp->realm_id->buf);
355 tr_free_name(idp->realm_id);
359 if (NULL == (idp->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
360 fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse APCs for realm %s .\n", idp->realm_id->buf);
361 tr_free_name(idp->realm_id);
362 /* TBD -- free aaa_servers */;
370 static TR_CFG_RC tr_cfg_parse_idp_realms (TR_INSTANCE *tr, json_t *jcfg)
372 json_t *jidps = NULL;
373 TR_CFG_RC rc = TR_CFG_SUCCESS;
374 TR_IDP_REALM *idp = NULL;
377 if ((!tr) || (!tr->new_cfg) || (!jcfg))
378 return TR_CFG_BAD_PARAMS;
380 if ((NULL == (jidps = json_object_get(jcfg, "idp_realms"))) ||
381 (!json_is_array(jidps))) {
382 return TR_CFG_NOPARSE;
385 for (i = 0; i < json_array_size(jidps); i++) {
386 if (NULL == (idp = tr_cfg_parse_one_idp_realm(tr,
387 json_array_get(jidps, i),
391 fprintf(stderr, "tr_cfg_parse_idp_realms: IDP realm configured: %s.\n", idp->realm_id->buf);
392 idp->next = tr->new_cfg->idp_realms;
393 tr->new_cfg->idp_realms = idp;
398 static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_INSTANCE *tr, json_t *jidps, TR_CFG_RC *rc)
400 TR_IDP_REALM *idp = NULL;
401 TR_IDP_REALM *temp_idp = NULL;
406 (!json_is_array(jidps))) {
408 *rc = TR_CFG_BAD_PARAMS;
412 for (i = 0; i < json_array_size(jidps); i++) {
413 if (NULL == (temp_idp = (tr_cfg_find_idp(tr->new_cfg,
414 tr_new_name((char *)json_string_value(json_array_get(jidps, i))),
416 fprintf(stderr, "tr_cfg_parse_comm_idps: Unknown IDP %s.\n",
417 (char *)json_string_value(json_array_get(jidps, i)));
421 temp_idp->comm_next = idp;
428 static TR_RP_REALM *tr_cfg_parse_comm_rps (TR_INSTANCE *tr, json_t *jrps, TR_CFG_RC *rc)
430 TR_RP_REALM *rp = NULL;
431 TR_RP_REALM *temp_rp = NULL;
436 (!json_is_array(jrps))) {
438 *rc = TR_CFG_BAD_PARAMS;
442 for (i = (json_array_size(jrps)-1); i >= 0; i--) {
443 if (NULL == (temp_rp = malloc(sizeof(TR_RP_REALM)))) {
444 fprintf(stderr, "tr_cfg_parse_comm_rps: Can't allocate memory for RP Realm.\n");
449 memset (temp_rp, 0, sizeof(TR_RP_REALM));
451 if (NULL == (temp_rp->realm_name = tr_new_name((char *)json_string_value(json_array_get(jrps, i))))) {
452 fprintf(stderr, "tr_cfg_parse_comm_rps: No memory for RP Realm Name.\n");
465 static TR_COMM *tr_cfg_parse_one_comm (TR_INSTANCE *tr, json_t *jcomm, TR_CFG_RC *rc) {
466 TR_COMM *comm = NULL;
468 json_t *jtype = NULL;
469 json_t *japcs = NULL;
470 json_t *jidps = NULL;
473 if ((!jcomm) || (!rc)) {
474 fprintf(stderr, "tr_cfg_parse_one_comm: Bad parameters.\n");
476 *rc = TR_CFG_BAD_PARAMS;
480 if (NULL == (comm = malloc(sizeof(TR_COMM)))) {
481 fprintf(stderr, "tr_config_parse_one_comm: Out of memory.\n");
486 memset(comm, 0, sizeof(TR_COMM));
488 if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
489 (!json_is_string(jid)) ||
490 (NULL == (jtype = json_object_get(jcomm, "type"))) ||
491 (!json_is_string(jtype)) ||
492 (NULL == (japcs = json_object_get(jcomm, "apcs"))) ||
493 (!json_is_array(japcs)) ||
494 (NULL == (jidps = json_object_get(jcomm, "idp_realms"))) ||
495 (!json_is_array(jidps)) ||
496 (NULL == (jrps = json_object_get(jcomm, "rp_realms"))) ||
497 (!json_is_array(jrps))) {
498 fprintf(stderr, "tr_cfg_parse_one_comm: Error parsing Communities configuration.\n");
500 *rc = TR_CFG_NOPARSE;
504 if (NULL == (comm->id = tr_new_name((char *)json_string_value(jid)))) {
506 fprintf(stderr, "tr_cfg_parse_one_comm: No memory for community id.\n");
511 if (0 == strcmp(json_string_value(jtype), "apc")) {
512 comm->type = TR_COMM_APC;
513 } else if (0 == strcmp(json_string_value(jtype), "coi")) {
514 comm->type = TR_COMM_COI;
515 if (NULL == (comm->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
516 fprintf(stderr, "tr_cfg_parse_one_comm: Can't parse APCs for COI %s.\n", comm->id->buf);
517 tr_free_name(comm->id);
522 fprintf(stderr, "tr_cfg_parse_one_comm: Invalid community type, comm = %s, type = %s\n", comm->id->buf, json_string_value(jtype));
523 tr_free_name(comm->id);
525 *rc = TR_CFG_NOPARSE;
529 comm->idp_realms = tr_cfg_parse_comm_idps(tr, jidps, rc);
530 if (TR_CFG_SUCCESS != *rc) {
531 fprintf(stderr, "tr_cfg_parse_one_comm: Can't parse IDP realms for comm %s.\n", comm->id->buf);
532 tr_free_name(comm->id);
537 comm->rp_realms = tr_cfg_parse_comm_rps(tr, jrps, rc);
538 if (TR_CFG_SUCCESS != *rc) {
539 fprintf(stderr, "tr_cfg_parse_comm: Can't parse RP realms for comm %s .\n", comm->id->buf);
540 tr_free_name(comm->id);
541 /* TBD -- free idps? */;
549 static TR_CFG_RC tr_cfg_parse_comms (TR_INSTANCE *tr, json_t *jcfg)
551 json_t *jcomms = NULL;
552 TR_CFG_RC rc = TR_CFG_SUCCESS;
553 TR_COMM *comm = NULL;
556 if ((!tr) || (!tr->new_cfg) || (!jcfg)) {
557 fprintf(stderr, "tr_config_parse_comms: Bad Parameters.\n");
558 return TR_CFG_BAD_PARAMS;
561 if (NULL == (comm = malloc(sizeof(TR_COMM)))) {
562 fprintf(stderr, "tr_cfg_parse_comms: Out of Memory\n");
565 memset (comm, 0, sizeof(TR_COMM));
567 if ((NULL == (jcomms = json_object_get(jcfg, "communities"))) ||
568 (!json_is_array(jcomms))) {
569 return TR_CFG_NOPARSE;
572 for (i = 0; i < json_array_size(jcomms); i++) {
573 if (NULL == (comm = tr_cfg_parse_one_comm(tr,
574 json_array_get(jcomms, i),
578 fprintf(stderr, "tr_cfg_parse_comms: Community configured: %s.\n", comm->id->buf);
579 comm->next = tr->new_cfg->comms;
580 tr->new_cfg->comms = comm;
585 TR_CFG_RC tr_parse_config (TR_INSTANCE *tr, json_t *jcfg) {
587 /* If there is a partial/abandoned config lying around, free it */
589 tr_cfg_free(tr->new_cfg);
592 if (NULL == (tr->new_cfg = malloc(sizeof(TR_CFG))))
595 memset(tr->new_cfg, 0, sizeof(TR_CFG));
597 if ((TR_CFG_SUCCESS != tr_cfg_parse_internal(tr, jcfg)) ||
598 (TR_CFG_SUCCESS != tr_cfg_parse_rp_clients(tr, jcfg)) ||
599 (TR_CFG_SUCCESS != tr_cfg_parse_idp_realms(tr, jcfg)) ||
600 (TR_CFG_SUCCESS != tr_cfg_parse_comms(tr, jcfg))) {
601 tr_cfg_free(tr->new_cfg);
604 return TR_CFG_SUCCESS;
607 TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc)
610 TR_IDP_REALM *cfg_idp;
612 if ((!tr_cfg) || (!idp_id)) {
614 *rc = TR_CFG_BAD_PARAMS;
618 for (cfg_idp = tr_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
619 if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
620 fprintf(stderr, "tr_cfg_find_idp: Found %s.\n", idp_id->buf);
624 /* if we didn't find one, return NULL */
628 TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *tr_cfg, TR_NAME *rp_gss, TR_CFG_RC *rc)
630 TR_RP_CLIENT *cfg_rp;
633 if ((!tr_cfg) || (!rp_gss)) {
635 *rc = TR_CFG_BAD_PARAMS;
639 for (cfg_rp = tr_cfg->rp_clients; NULL != cfg_rp; cfg_rp = cfg_rp->next) {
640 for (i = 0; i < TR_MAX_GSS_NAMES; i++) {
641 if (!tr_name_cmp (rp_gss, cfg_rp->gss_names[i])) {
642 fprintf(stderr, "tr_cfg_find_rp: Found %s.\n", rp_gss->buf);
647 /* if we didn't find one, return NULL */
651 json_t *tr_read_config (int n, struct dirent **cfg_files) {
660 fprintf(stderr, "tr_read_config: Parsing %s.\n", cfg_files[n]->d_name);
661 if (NULL == (temp = json_load_file(cfg_files[n]->d_name, JSON_DISABLE_EOF_CHECK, &err))) {
662 fprintf (stderr, "tr_read_config: Error parsing config file %s.\n", cfg_files[n]->d_name);
666 /* TBD -- instead of using json_object_update, iterate through files for non-overlap config? */
670 if (-1 == json_object_update(jcfg, temp)) {
671 fprintf(stderr, "tr_read_config: Error merging config information.\n");
677 // fprintf(stderr, "tr_read_config: Merged configuration complete:\n%s\n", json_dumps(jcfg, 0));
682 static int is_cfg_file(const struct dirent *dent) {
685 /* if the last four letters of the filename are .cfg, return true. */
686 if ((4 <= (n = strlen(dent->d_name))) &&
687 (0 == strcmp(&(dent->d_name[n-4]), ".cfg"))) {
691 /* otherwise, return false. */
695 int tr_find_config_files (struct dirent ***cfg_files) {
698 n = scandir(".", cfg_files, &is_cfg_file, 0);
702 fprintf(stderr, "tr_find_config: scandir error.\n");
707 fprintf (stderr, "tr_find_config: No config files found.\n");
713 fprintf(stderr, "tr_find_config: Config file found (%s).\n", (*cfg_files)[i]->d_name);