void tr_print_config (TR_CFG *cfg) {
tr_notice("tr_print_config: Logging running trust router configuration.");
- tr_print_comms(cfg->comms);
+ tr_print_comms(cfg->ctable);
}
-void tr_print_comms (TR_COMM *comm_list) {
+void tr_print_comms (TR_COMM_TABLE *ctab)
+{
TR_COMM *comm = NULL;
- for (comm = comm_list; NULL != comm; comm = comm->next) {
+ for (comm = ctab->comms; NULL != comm; comm = comm->next) {
tr_notice("tr_print_config: Community %s:", comm->id->buf);
tr_notice("tr_print_config: - Member IdPs:");
- tr_print_comm_idps(comm->idp_realms);
+ tr_print_comm_idps(ctab, comm);
tr_notice("tr_print_config: - Member RPs:");
- tr_print_comm_rps(comm->rp_realms);
+ tr_print_comm_rps(ctab, comm);
}
}
-void tr_print_comm_idps (TR_IDP_REALM *idp_list) {
+void tr_print_comm_idps(TR_COMM_TABLE *ctab, TR_COMM *comm)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ TR_COMM_ITER *iter=NULL;
TR_IDP_REALM *idp = NULL;
+ char *s=NULL;
- for (idp = idp_list; NULL != idp; idp = idp->comm_next) {
- tr_notice("tr_print_config: - @%s", idp->realm_id->buf);
+ iter=tr_comm_iter_new(tmp_ctx);
+ if (iter==NULL) {
+ tr_notice("tr_print_config: unable to allocate IdP iterator.");
+ talloc_free(tmp_ctx);
+ return;
+ }
+
+ for (idp=tr_idp_realm_iter_first(iter, ctab, tr_comm_get_id(comm));
+ NULL!=idp;
+ idp=tr_idp_realm_iter_next(iter)) {
+ s=tr_idp_realm_to_str(tmp_ctx, idp);
+ if (s!=NULL)
+ tr_notice("tr_print_config: - @%s", s);
+ else
+ tr_notice("tr_print_config: unable to allocate IdP output string.");
}
+ talloc_free(tmp_ctx);
}
-void tr_print_comm_rps(TR_RP_REALM *rp_list) {
+void tr_print_comm_rps(TR_COMM_TABLE *ctab, TR_COMM *comm)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ TR_COMM_ITER *iter=NULL;
TR_RP_REALM *rp = NULL;
+ char *s=NULL;
- for (rp = rp_list; NULL != rp; rp = rp->next) {
- tr_notice("tr_print_config: - %s", rp->realm_name->buf);
+ iter=tr_comm_iter_new(tmp_ctx);
+ if (iter==NULL) {
+ tr_notice("tr_print_config: unable to allocate RP iterator.");
+ talloc_free(tmp_ctx);
+ return;
}
+
+ for (rp=tr_rp_realm_iter_first(iter, ctab, tr_comm_get_id(comm));
+ NULL!=rp;
+ rp=tr_rp_realm_iter_next(iter)) {
+ s=tr_rp_realm_to_str(tmp_ctx, rp);
+ if (s!=NULL)
+ tr_notice("tr_print_config: - @%s", s);
+ else
+ tr_notice("tr_print_config: unable to allocate RP output string.");
+ }
+ talloc_free(tmp_ctx);
}
TR_CFG *tr_cfg_new(TALLOC_CTX *mem_ctx)
{
- return talloc_zero(mem_ctx, TR_CFG);
+ TR_CFG *cfg=talloc(mem_ctx, TR_CFG);
+ if (cfg!=NULL) {
+ cfg->internal=NULL;
+ cfg->rp_clients=NULL;
+ cfg->peers=NULL;
+ cfg->default_servers=NULL;
+ cfg->ctable=tr_comm_table_new(cfg);
+ if (cfg->ctable==NULL) {
+ talloc_free(cfg);
+ cfg=NULL;
+ }
+ }
+ return cfg;
}
-void tr_cfg_free (TR_CFG *cfg) {
+void tr_cfg_free (TR_CFG *cfg)
+{
talloc_free(cfg);
}
json_t *jfaction=NULL;
json_t *jfspecs=NULL;
json_t *jffield=NULL;
- json_t *jfmatches=NULL;
json_t *jfmatch=NULL;
json_t *jrc=NULL;
json_t *jdc=NULL;
TR_NAME *name=NULL;
- int i=0, j=0, k=0;
+ int i=0, j=0;
*rc=TR_CFG_ERROR;
}
/* check that we have a match attribute */
- if (NULL==(jfmatches=json_object_get(json_array_get(jfspecs, j), "match"))) {
+ if (NULL==(jfmatch=json_object_get(json_array_get(jfspecs, j), "match"))) {
tr_debug("tr_cfg_parse_one_filter: Error parsing filter: missing match for filer spec %d, filter line %d.", i, j);
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
- /* check that match is an array */
- if (!json_is_array(jfmatches)) {
- tr_debug("tr_cfg_parse_one_filter: Error parsing filter: match not an array for filter spec %d, filter line %d.", i, j);
+ /* check that match is a string */
+ if (!json_is_string(jfmatch)) {
+ tr_debug("tr_cfg_parse_one_filter: Error parsing filter: match not a string for filter spec %d, filter line %d.", i, j);
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
}
/* fill in the matches */
- for (k=0; k<json_array_size(jfmatches); k++) {
- if (NULL==(jfmatch=json_array_get(jfmatches, k))) {
- tr_debug("tr_cfg_parse_one_filter: Error parsing filter: unable to load match %d for filter spec %d, filter line %d.", k, i, j);
- *rc=TR_CFG_NOPARSE;
- goto cleanup;
- }
- if (NULL==(name=tr_new_name(json_string_value(jfmatch)))) {
- tr_debug("tr_cfg_parse_one_filter: Out of memory.");
- *rc=TR_CFG_NOMEM;
- goto cleanup;
- }
- if (0!=tr_fspec_add_match(filt->lines[i]->specs[j], name)) {
- tr_debug("tr_cfg_parse_one_filter: Could not add match %d to filter spec %d, filter line %d.", k, i, j);
- tr_free_name(name);
- *rc=TR_CFG_ERROR;
- goto cleanup;
- }
+ if (NULL==(name=tr_new_name(json_string_value(jfmatch)))) {
+ tr_debug("tr_cfg_parse_one_filter: Out of memory.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
}
-
+ tr_fspec_set_match(filt->lines[i]->specs[j], name);
}
}
*rc=TR_CFG_SUCCESS;
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
- apcs=tr_apc_add(apcs, new_apc);
+ tr_apc_add(apcs, new_apc);
}
talloc_steal(mem_ctx, apcs);
return -1;
}
+static TR_REALM_ORIGIN tr_cfg_realm_origin(json_t *jrealm)
+{
+ json_t *jremote=json_object_get(jrealm, "remote");
+ const char *s=NULL;
+
+ if (jremote==NULL)
+ return TR_REALM_LOCAL;
+ if (!json_is_string(jremote)) {
+ tr_warning("tr_cfg_realm_origin: \"remote\" is not a string, assuming this is a local realm.");
+ return TR_REALM_LOCAL;
+ }
+ s=json_string_value(jremote);
+ if (strcasecmp(s, "yes")==0)
+ return TR_REALM_REMOTE_INCOMPLETE;
+ else if (strcasecmp(s, "no")!=0)
+ tr_warning("tr_cfg_realm_origin: \"remote\" is neither 'yes' nor 'no', assuming this is a local realm.");
+
+ return TR_REALM_LOCAL;
+}
+
/* Parse the identity provider object from a realm and fill in the given TR_IDP_REALM. */
static TR_CFG_RC tr_cfg_parse_idp(TR_IDP_REALM *idp, json_t *jidp)
{
TR_APC *apcs=NULL;
TR_AAA_SERVER *aaa=NULL;
TR_CFG_RC rc=TR_CFG_ERROR;
-
+
if (jidp==NULL)
goto cleanup;
- idp->origin=TR_REALM_LOCAL; /* if we're parsing it from a config file, it's local */
idp->shared_config=tr_cfg_parse_shared_config(json_object_get(jidp, "shared_config"), &rc);
if (rc!=TR_CFG_SUCCESS) {
tr_err("tr_cfg_parse_idp: missing or malformed shared_config specification");
rc=TR_CFG_NOPARSE;
goto cleanup;
}
- tr_debug("tr_cfg_parse_idp: APC=\"%.*s\"",
- apcs->id->len,
- apcs->id->buf);
-
+
aaa=tr_cfg_parse_aaa_servers(idp, json_object_get(jidp, "aaa_servers"), &rc);
if (rc!=TR_CFG_SUCCESS) {
tr_err("tr_cfg_parse_idp: unable to parse AAA servers");
rc=TR_CFG_NOPARSE;
goto cleanup;
}
-
+
+ tr_debug("tr_cfg_parse_idp: APC=\"%.*s\"",
+ apcs->id->len,
+ apcs->id->buf);
+
/* done, fill in the idp structures */
idp->apcs=apcs;
talloc_steal(idp, apcs);
idp->aaa_servers=aaa;
rc=TR_CFG_SUCCESS;
-
- cleanup:
+
+cleanup:
if (rc!=TR_CFG_SUCCESS) {
if (apcs!=NULL)
tr_apc_free(apcs);
if (aaa!=NULL)
tr_aaa_server_free(aaa);
}
-
+
talloc_free(tmp_ctx);
return rc;
}
goto cleanup;
}
+ realm->origin=tr_cfg_realm_origin(jrealm);
+ if (realm->origin!=TR_REALM_LOCAL) {
+ tr_debug("tr_cfg_parse_one_idp_realm: realm is remote, should not have full IdP info.");
+ *rc=TR_CFG_NOPARSE;
+ goto cleanup;
+ }
+
/* must have a name */
realm->realm_id=tr_cfg_parse_name(realm,
json_object_get(jrealm, "realm"),
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
-
+
*rc=TR_CFG_SUCCESS;
- cleanup:
- if (*rc==TR_CFG_SUCCESS)
- talloc_steal(mem_ctx, realm);
- else {
- talloc_free(realm);
- realm=NULL;
- }
-
- talloc_free(tmp_ctx);
- return realm;
+cleanup:
+ if (*rc==TR_CFG_SUCCESS)
+ talloc_steal(mem_ctx, realm);
+ else {
+ talloc_free(realm);
+ realm=NULL;
}
+
+ talloc_free(tmp_ctx);
+ return realm;
+}
/* Determine whether the realm is an IDP realm */
static int tr_cfg_is_idp_realm(json_t *jrealm)
return 0;
}
+static TR_IDP_REALM *tr_cfg_parse_one_remote_realm(TALLOC_CTX *mem_ctx, json_t *jrealm, TR_CFG_RC *rc)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ TR_IDP_REALM *realm=talloc(mem_ctx, TR_IDP_REALM);
+
+ *rc=TR_CFG_ERROR; /* default to error if not set */
+
+ if ((!jrealm) || (!rc)) {
+ tr_err("tr_cfg_parse_one_remote_realm: Bad parameters.");
+ if (rc)
+ *rc=TR_CFG_BAD_PARAMS;
+ goto cleanup;
+ }
+
+ if (NULL==(realm=tr_idp_realm_new(tmp_ctx))) {
+ tr_err("tr_cfg_parse_one_remote_realm: could not allocate idp realm.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
+ }
+
+ /* must have a name */
+ realm->realm_id=tr_cfg_parse_name(realm,
+ json_object_get(jrealm, "realm"),
+ rc);
+ if ((*rc!=TR_CFG_SUCCESS) || (realm->realm_id==NULL)) {
+ tr_err("tr_cfg_parse_one_remote_realm: could not parse realm name");
+ *rc=TR_CFG_NOPARSE;
+ goto cleanup;
+ }
+ tr_debug("tr_cfg_parse_one_remote_realm: realm_id=\"%.*s\"",
+ realm->realm_id->len,
+ realm->realm_id->buf);
+
+ realm->origin=tr_cfg_realm_origin(jrealm);
+ *rc=TR_CFG_SUCCESS;
+
+cleanup:
+ if (*rc==TR_CFG_SUCCESS)
+ talloc_steal(mem_ctx, realm);
+ else {
+ talloc_free(realm);
+ realm=NULL;
+ }
+
+ talloc_free(tmp_ctx);
+ return realm;
+}
+
+static int tr_cfg_is_remote_realm(json_t *jrealm)
+{
+ return (tr_cfg_realm_origin(jrealm)!=TR_REALM_LOCAL);
+}
+
/* Parse any idp realms in the j_realms object. Ignores other realm types. */
static TR_IDP_REALM *tr_cfg_parse_idp_realms(TALLOC_CTX *mem_ctx, json_t *jrealms, TR_CFG_RC *rc)
{
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
- realms=tr_idp_realm_add(realms, new_realm);
+ tr_idp_realm_add(realms, new_realm);
+ } else if (tr_cfg_is_remote_realm(this_jrealm)) {
+ new_realm=tr_cfg_parse_one_remote_realm(tmp_ctx, this_jrealm, rc);
+ if ((*rc)!=TR_CFG_SUCCESS) {
+ tr_err("tr_cfg_parse_idp_realms: error decoding remote realm entry %d", ii+1);
+ *rc=TR_CFG_NOPARSE;
+ goto cleanup;
+ }
+ tr_idp_realm_add(realms, new_realm);
}
}
TR_CONSTRAINT *cons=NULL;
TR_NAME *name=NULL;
TR_NAME *n_prefix=tr_new_name("*.");
- TR_NAME *n_rp_realm=tr_new_name("rp_realm");
+ TR_NAME *n_rp_realm_1=tr_new_name("rp_realm");
+ TR_NAME *n_rp_realm_2=tr_new_name("rp_realm");
TR_NAME *n_domain=tr_new_name("domain");
TR_NAME *n_realm=tr_new_name("realm");
goto cleanup;
}
- if ((n_prefix==NULL) || (n_rp_realm==NULL) || (n_domain==NULL) || (n_realm==NULL)) {
+ if ((n_prefix==NULL) ||
+ (n_rp_realm_1==NULL) ||
+ (n_rp_realm_2==NULL) ||
+ (n_domain==NULL) ||
+ (n_realm==NULL)) {
tr_debug("tr_cfg_default_filter: unable to allocate names.");
*rc=TR_CFG_NOMEM;
goto cleanup;
filt->lines[0]->action=TR_FILTER_ACTION_ACCEPT;
filt->lines[0]->specs[0]=tr_fspec_new(filt->lines[0]);
- filt->lines[0]->specs[0]->field=n_rp_realm;
- n_rp_realm=NULL; /* we don't own this name any more */
+ filt->lines[0]->specs[0]->field=n_rp_realm_1;
+ n_rp_realm_1=NULL; /* we don't own this name any more */
name=tr_dup_name(realm);
if (name==NULL) {
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- if (0!=tr_fspec_add_match(filt->lines[0]->specs[0], name)) {
- tr_debug("tr_cfg_default_filter: could not add realm name to filter spec.");
- *rc=TR_CFG_NOMEM;
- goto cleanup;
- }
+ tr_fspec_set_match(filt->lines[0]->specs[0], name);
name=NULL; /* we no longer own the name */
+ /* now do the wildcard name */
+ filt->lines[0]->specs[1]=tr_fspec_new(filt->lines[0]);
+ filt->lines[0]->specs[1]->field=n_rp_realm_2;
+ n_rp_realm_2=NULL; /* we don't own this name any more */
+
if (NULL==(name=tr_name_cat(n_prefix, realm))) {
tr_debug("tr_cfg_default_filter: could not allocate wildcard realm name.");
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- if (0!=tr_fspec_add_match(filt->lines[0]->specs[0], name)) {
- tr_debug("tr_cfg_default_filter: could not add wildcard realm name to filter spec.");
- *rc=TR_CFG_NOMEM;
- goto cleanup;
- }
+ tr_fspec_set_match(filt->lines[0]->specs[1], name);
name=NULL; /* we no longer own the name */
/* domain constraint */
if (n_prefix!=NULL)
tr_free_name(n_prefix);
- if (n_rp_realm!=NULL)
- tr_free_name(n_rp_realm);
+ if (n_rp_realm_1!=NULL)
+ tr_free_name(n_rp_realm_1);
+ if (n_rp_realm_2!=NULL)
+ tr_free_name(n_rp_realm_2);
if (n_realm!=NULL)
tr_free_name(n_realm);
if (n_domain!=NULL)
*rc=TR_CFG_NOPARSE;
goto cleanup;
}
- clients=tr_rp_client_add(clients, new_client);
+ tr_rp_client_add(clients, new_client);
}
}
}
#if 0
+/* TODO: are we using this? JLR */
/* Update the community information with data from a new batch of IDP realms.
* May partially add realms if there is a failure, no guarantees.
* Call like comms=tr_comm_idp_update(comms, new_realms, &rc) */
-static TR_COMM *tr_cfg_comm_idp_update(TALLOC_CTX *mem_ctx, TR_COMM *comms, TR_IDP_REALM *new_realms, TR_CFG_RC *rc)
+static TR_COMM *tr_cfg_comm_idp_update(TALLOC_CTX *mem_ctx,
+ TR_COMM_TABLE *ctab,
+ TR_IDP_REALM *new_realms,
+ TR_CFG_RC *rc)
{
TALLOC_CTX *tmp_ctx=talloc_new(NULL);
TR_COMM *comm=NULL; /* community looked up in comms table */
/* fill in the community with info */
comm->type=TR_COMM_APC; /* realms added this way are in APCs */
comm->expiration_interval=TR_DEFAULT_APC_EXPIRATION_INTERVAL;
- comm->id=tr_dup_name(apc->id);
+ tr_comm_set_id(comm, tr_dup_name(apc->id));
tr_comm_add_idp_realm(comm, realm);
- new_comms=tr_comm_add(new_comms, comm);
+ tr_comm_add(new_comms, comm);
} else {
/* add this realm to the comm */
tr_comm_add_idp_realm(comm, realm);
}
/* we successfully built a list, add it to the other list */
- comms=tr_comm_add(comms, new_comms);
+ tr_comm_add(comms, new_comms);
talloc_steal(mem_ctx, comms);
cleanup:
talloc_free(tmp_ctx);
/* if we succeeded, link things to the configuration and move out of tmp context */
if (retval==TR_CFG_SUCCESS) {
if (new_idp_realms!=NULL) {
- trc->idp_realms=tr_idp_realm_add(trc->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
- talloc_steal(trc, trc->idp_realms); /* make sure the head is in the right context */
+ tr_idp_realm_add(trc->ctable->idp_realms, new_idp_realms); /* fixes talloc contexts except for head*/
+ talloc_steal(trc, trc->ctable->idp_realms); /* make sure the head is in the right context */
}
if (new_rp_clients!=NULL) {
- trc->rp_clients=tr_rp_client_add(trc->rp_clients, new_rp_clients); /* fixes talloc contexts */
+ tr_rp_client_add(trc->rp_clients, new_rp_clients); /* fixes talloc contexts */
talloc_steal(trc, trc->rp_clients); /* make sure head is in the right context */
}
}
return rc;
}
-static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_CFG *trc, json_t *jidps, TR_CFG_RC *rc)
+static void tr_cfg_parse_comm_idps(TR_CFG *trc, json_t *jidps, TR_COMM *comm, TR_CFG_RC *rc)
{
- TR_IDP_REALM *idp = NULL;
- TR_IDP_REALM *found_idp = NULL;
- TR_IDP_REALM *temp_idp = NULL;
+ TR_IDP_REALM *found_idp=NULL;
int i = 0;
if ((!trc) ||
(!json_is_array(jidps))) {
if (rc)
*rc = TR_CFG_BAD_PARAMS;
- return NULL;
+ return;
}
- for (i = 0; i < json_array_size(jidps); i++) {
- if (NULL == (temp_idp = talloc(trc, TR_IDP_REALM))) {
- tr_debug("tr_cfg_parse_comm_idps: Can't allocate memory for IdP Realm.");
- if (rc)
- *rc = TR_CFG_NOMEM;
- return NULL;
- }
- memset (temp_idp, 0, sizeof(TR_IDP_REALM));
-
- if (NULL == (found_idp = (tr_cfg_find_idp(trc,
- tr_new_name((char *)json_string_value(json_array_get(jidps, i))),
- rc)))) {
+ for (i=0; i < json_array_size(jidps); i++) {
+ found_idp=tr_cfg_find_idp(trc,
+ tr_new_name((char *)json_string_value(json_array_get(jidps, i))),
+ rc);
+ if ((found_idp==NULL) || (*rc!=TR_CFG_SUCCESS)) {
tr_debug("tr_cfg_parse_comm_idps: Unknown IDP %s.",
(char *)json_string_value(json_array_get(jidps, i)));
- return NULL;
+ *rc=TR_CFG_ERROR;
+ return;
}
-
- // We *MUST* do a dereferenced copy here or the second community will corrupt the linked list we create here.
- *temp_idp = *found_idp;
-
- temp_idp->comm_next = idp;
- idp = temp_idp;
+ tr_comm_add_idp_realm(trc->ctable, comm, found_idp, 0, NULL, NULL); /* no provenance, never expires */
}
- return idp;
+ *rc=TR_CFG_SUCCESS;
+ return;
}
-static TR_RP_REALM *tr_cfg_parse_comm_rps (TR_CFG *trc, json_t *jrps, TR_CFG_RC *rc)
+static void tr_cfg_parse_comm_rps(TR_CFG *trc, json_t *jrps, TR_COMM *comm, TR_CFG_RC *rc)
{
- TR_RP_REALM *rp = NULL;
- TR_RP_REALM *temp_rp = NULL;
- int i = 0;
+ TR_RP_REALM *found_rp=NULL;
+ TR_RP_REALM *new_rp=NULL;
+ TR_NAME *rp_name=NULL;
+ const char *s=NULL;
+ int ii=0;
if ((!trc) ||
(!jrps) ||
(!json_is_array(jrps))) {
if (rc)
*rc = TR_CFG_BAD_PARAMS;
- return NULL;
+ return;
}
- for (i = (json_array_size(jrps)-1); i >= 0; i--) {
- if (NULL == (temp_rp = talloc_zero(trc, TR_RP_REALM))) {
- tr_debug("tr_cfg_parse_comm_rps: Can't allocate memory for RP Realm.");
- if (rc)
- *rc = TR_CFG_NOMEM;
- return NULL;
+ for (ii=0; ii<json_array_size(jrps); ii++) {
+ /* get the RP name as a string */
+ s=json_string_value(json_array_get(jrps, ii));
+ if (s==NULL) {
+ tr_notice("tr_cfg_parse_comm_rps: null RP found in community %.*s, ignoring.",
+ tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
+ continue;
}
- if (NULL == (temp_rp->realm_name = tr_new_name((char *)json_string_value(json_array_get(jrps, i))))) {
- tr_debug("tr_cfg_parse_comm_rps: No memory for RP Realm Name.");
- if (rc)
- *rc = TR_CFG_NOMEM;
- return NULL;
+ /* convert string to TR_NAME */
+ rp_name=tr_new_name(s);
+ if (rp_name==NULL) {
+ tr_err("tr_cfg_parse_comm_rps: unable to allocate RP name for %s in community %.*s.",
+ s, tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
}
- temp_rp->next = rp;
- rp = temp_rp;
- }
+ /* see if we already have this RP in this community */
+ found_rp=tr_comm_find_rp(trc->ctable, comm, rp_name);
+ if (found_rp!=NULL) {
+ tr_notice("tr_cfg_parse_comm_rps: RP %s repeated in community %.*s.",
+ s, tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
+ tr_free_name(rp_name);
+ continue;
+ }
- return rp;
+ /* Add the RP to the community, first see if we have the RP in any community */
+ found_rp=tr_rp_realm_lookup(trc->ctable->rp_realms, rp_name);
+ if (found_rp!=NULL) {
+ tr_debug("tr_cfg_parse_comm_rps: RP realm %s already exists.", s);
+ new_rp=found_rp; /* use it rather than creating a new realm record */
+ } else {
+ new_rp=tr_rp_realm_new(NULL);
+ if (new_rp==NULL) {
+ tr_err("tr_cfg_parse_comm_rps: unable to allocate RP record for %s in community %.*s.",
+ s, tr_comm_get_id(comm)->len, tr_comm_get_id(comm)->buf);
+ }
+ tr_debug("tr_cfg_parse_comm_rps: setting name to %s", rp_name->buf);
+ tr_rp_realm_set_id(new_rp, rp_name);
+ rp_name=NULL; /* rp_name no longer belongs to us */
+ tr_rp_realm_add(trc->ctable->rp_realms, new_rp);
+ talloc_steal(trc->ctable, trc->ctable->rp_realms); /* make sure head is in the right context */
+ }
+ tr_comm_add_rp_realm(trc->ctable, comm, new_rp, 0, NULL, NULL);
+ }
}
-static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc) {
+static TR_COMM *tr_cfg_parse_one_comm (TALLOC_CTX *mem_ctx, TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
TR_COMM *comm = NULL;
json_t *jid = NULL;
json_t *jtype = NULL;
tr_debug("tr_cfg_parse_one_comm: Bad parameters.");
if (rc)
*rc = TR_CFG_BAD_PARAMS;
- return NULL;
+ goto cleanup;
}
- if (NULL == (comm = talloc_zero(trc, TR_COMM))) {
+ comm=tr_comm_new(tmp_ctx);
+ if (comm==NULL) {
tr_crit("tr_cfg_parse_one_comm: Out of memory.");
*rc = TR_CFG_NOMEM;
- return NULL;
+ goto cleanup;
}
(!json_is_array(jrps))) {
tr_debug("tr_cfg_parse_one_comm: Error parsing Communities configuration.");
*rc = TR_CFG_NOPARSE;
- return NULL;
+ comm=NULL;
+ goto cleanup;
}
- if (NULL == (comm->id = tr_new_name((char *)json_string_value(jid)))) {
+ tr_comm_set_id(comm, tr_new_name(json_string_value(jid)));
+ if (NULL == tr_comm_get_id(comm)) {
tr_debug("tr_cfg_parse_one_comm: No memory for community id.");
*rc = TR_CFG_NOMEM;
- return NULL;
+ comm=NULL;
+ goto cleanup;
}
if (0 == strcmp(json_string_value(jtype), "apc")) {
} else if (0 == strcmp(json_string_value(jtype), "coi")) {
comm->type = TR_COMM_COI;
if (NULL == (comm->apcs = tr_cfg_parse_apcs(trc, japcs, rc))) {
- tr_debug("tr_cfg_parse_one_comm: Can't parse APCs for COI %s.", comm->id->buf);
- tr_free_name(comm->id);
- return NULL;
+ tr_debug("tr_cfg_parse_one_comm: Can't parse APCs for COI %s.",
+ tr_comm_get_id(comm)->buf);
+ comm=NULL;
+ goto cleanup;
}
} else {
- tr_debug("tr_cfg_parse_one_comm: Invalid community type, comm = %s, type = %s", comm->id->buf, json_string_value(jtype));
- tr_free_name(comm->id);
+ tr_debug("tr_cfg_parse_one_comm: Invalid community type, comm = %s, type = %s",
+ tr_comm_get_id(comm)->buf, json_string_value(jtype));
*rc = TR_CFG_NOPARSE;
- return NULL;
+ comm=NULL;
+ goto cleanup;
}
- comm->idp_realms = tr_cfg_parse_comm_idps(trc, jidps, rc);
+ tr_cfg_parse_comm_idps(trc, jidps, comm, rc);
if (TR_CFG_SUCCESS != *rc) {
- tr_debug("tr_cfg_parse_one_comm: Can't parse IDP realms for comm %s.", comm->id->buf);
- tr_free_name(comm->id);
- return NULL;
+ tr_debug("tr_cfg_parse_one_comm: Can't parse IDP realms for comm %s.",
+ tr_comm_get_id(comm)->buf);
+ comm=NULL;
+ goto cleanup;
}
- comm->rp_realms = tr_cfg_parse_comm_rps(trc, jrps, rc);
+ tr_cfg_parse_comm_rps(trc, jrps, comm, rc);
if (TR_CFG_SUCCESS != *rc) {
- tr_debug("tr_cfg_parse_comm: Can't parse RP realms for comm %s .", comm->id->buf);
- tr_free_name(comm->id);
- return NULL;
+ tr_debug("tr_cfg_parse_one_comm: Can't parse RP realms for comm %s .",
+ tr_comm_get_id(comm)->buf);
+ comm=NULL;
+ goto cleanup;
}
if (TR_COMM_APC == comm->type) {
comm->expiration_interval = 43200; /*30 days*/
if (jexpire) {
if (!json_is_integer(jexpire)) {
- fprintf(stderr, "tr_parse_comm: expirae_interval is not an integer\n");
- return NULL;
+ fprintf(stderr, "tr_parse_one_comm: expiration_interval is not an integer\n");
+ comm=NULL;
+ goto cleanup;
}
comm->expiration_interval = json_integer_value(jexpire);
if (comm->expiration_interval <= 10)
comm->expiration_interval = 129600;
}
}
-
+
+cleanup:
+ if (comm!=NULL)
+ talloc_steal(mem_ctx, comm);
+ talloc_free(tmp_ctx);
return comm;
}
}
for (i = 0; i < json_array_size(jcomms); i++) {
- if (NULL == (comm = tr_cfg_parse_one_comm(trc,
- json_array_get(jcomms, i),
- &rc))) {
- return rc;
+ if (NULL == (comm = tr_cfg_parse_one_comm(NULL, /* TODO: use a talloc context */
+ trc,
+ json_array_get(jcomms, i),
+ &rc))) {
+ return rc;
}
- tr_debug("tr_cfg_parse_comms: Community configured: %s.", comm->id->buf);
- comm->next = trc->comms;
- trc->comms = comm;
+ tr_debug("tr_cfg_parse_comms: Community configured: %s.",
+ tr_comm_get_id(comm)->buf);
+
+ tr_comm_table_add_comm(trc->ctable, comm);
}
}
tr_debug("tr_cfg_parse_comms: Finished (rc=%d)", rc);
rc = TR_CFG_ERROR;
}
- if (NULL == trc->comms) {
+ if (0==tr_comm_table_size(trc->ctable)) {
tr_debug("tr_cfg_validate: Error: No Communities configured");
rc = TR_CFG_ERROR;
}
- if ((NULL == trc->default_servers) && (NULL == trc->idp_realms)) {
+ if ((NULL == trc->default_servers) && (NULL == trc->ctable->idp_realms)) {
tr_debug("tr_cfg_validate: Error: No default servers or IDPs configured.");
rc = TR_CFG_ERROR;
}
return talloc_asprintf(mem_ctx, "%s/%s", p1, p2); /* returns NULL on a failure */
}
+static void tr_cfg_log_json_error(const char *label, json_error_t *rc)
+{
+ tr_debug("%s: JSON parse error on line %d: %s",
+ label,
+ rc->line,
+ rc->text);
+}
+
TR_CFG_RC tr_cfg_parse_one_config_file(TR_CFG *cfg, const char *file_with_path)
{
json_t *jcfg=NULL;
if (NULL==(jcfg=json_load_file(file_with_path,
JSON_DISABLE_EOF_CHECK, &rc))) {
- tr_debug("tr_parse_one_config_file: Error parsing config file %s.",
+ tr_debug("tr_cfg_parse_one_config_file: Error parsing config file %s.",
file_with_path);
+ tr_cfg_log_json_error("tr_cfg_parse_one_config_file", &rc);
return TR_CFG_NOPARSE;
}
return NULL;
}
- for (cfg_idp = tr_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
+ for (cfg_idp = tr_cfg->ctable->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
tr_debug("tr_cfg_find_idp: Found %s.", idp_id->buf);
return cfg_idp;