#include <tr_config.h>
#include <tr.h>
+#include <tr_filter.h>
void tr_print_config (FILE *stream, TR_CFG *cfg) {
fprintf(stream, "tr_print_config: Not yet implemented.\n");
return TR_CFG_SUCCESS;
}
-static TR_RP_CLIENT *tr_cfg_parse_one_rp_client (TR_INSTANCE *tr, json_t *jrp, TR_CFG_RC *rc)
+static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CFG_RC *rc)
+{
+ TR_FILTER *filt = NULL;
+ json_t *jftype = NULL;
+ json_t *jfls = NULL;
+ json_t *jfaction = NULL;
+ json_t *jfspecs = NULL;
+ json_t *jffield = NULL;
+ json_t *jfmatch = NULL;
+ int i = 0, j = 0;
+
+ if ((NULL == (jftype = json_object_get(jfilt, "type"))) ||
+ (!json_is_string(jftype))) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter type.\n");
+ *rc = TR_CFG_NOPARSE;
+ return NULL;
+ }
+
+ if ((NULL == (jfls = json_object_get(jfilt, "filter_lines"))) ||
+ (!json_is_array(jfls))) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter type.\n");
+ *rc = TR_CFG_NOPARSE;
+ return NULL;
+ }
+
+ if (TR_MAX_FILTER_LINES < json_array_size(jfls)) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Filter has too many filter_lines, maximimum of %d.\n", TR_MAX_FILTER_LINES);
+ *rc = TR_CFG_NOPARSE;
+ return NULL;
+ }
+
+ /* TBD -- optionally parse realm and domain constraints */
+
+ if (NULL == (filt = malloc(sizeof(TR_FILTER)))) {
+ fprintf(stderr, "tr_config_parse_one_filter: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ return NULL;
+ }
+
+ memset(filt, 0, sizeof(TR_FILTER));
+
+ if (!strcmp(json_string_value(jftype), "rp_permitted")) {
+ filt->type = TR_FILTER_TYPE_RP_PERMITTED;
+ }
+ else {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter type, unknown type '%s'.\n", json_string_value(jftype));
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ /* For each filter line... */
+ for (i = 0; i < json_array_size(jfls); i++) {
+
+ if ((NULL == (jfaction = json_object_get(json_array_get(jfls, i), "action"))) ||
+ (!json_is_string(jfaction))) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter action.\n");
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ /* TBD -- parse constraints */
+
+ if ((NULL == (jfspecs = json_object_get(json_array_get(jfls, i), "filter_specs"))) ||
+ (!json_is_array(jfspecs)) ||
+ (0 == json_array_size(jfspecs))) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter specs.\n");
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ if (TR_MAX_FILTER_SPECS < json_array_size(jfspecs)) {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Filter has too many filter_specs, maximimum of %d.\n", TR_MAX_FILTER_SPECS);
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ if (NULL == (filt->lines[i] = malloc(sizeof(TR_FLINE)))) {
+ fprintf(stderr, "tr_config_parse_one_filter: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ memset(filt->lines[i], 0, sizeof(TR_FLINE));
+
+ if (!strcmp(json_string_value(jfaction), "accept")) {
+ filt->lines[i]->action = TR_FILTER_ACTION_ACCEPT;
+ }
+ else if (!strcmp(json_string_value(jfaction), "reject")) {
+ filt->lines[i]->action = TR_FILTER_ACTION_REJECT;
+ }
+ else {
+ fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing filter action, unknown action' %s'.\n", json_string_value(jfaction));
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ /*For each filter spec within the filter line... */
+ for (j = 0; j <json_array_size(jfspecs); j++) {
+
+ if ((NULL == (jffield = json_object_get(json_array_get(jfspecs, j), "field"))) ||
+ (!json_is_string(jffield)) ||
+ (NULL == (jfmatch = json_object_get(json_array_get(jfspecs, j), "match"))) ||
+ (!json_is_string(jfmatch))) {
+ fprintf (stderr, "tr_cfg_parse_one_filter: Error parsing filter field and match for filter spec %d, filter line %d.\n", i, j);
+ *rc = TR_CFG_NOPARSE;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ if (NULL == (filt->lines[i]->specs[j] = malloc(sizeof(TR_FSPEC)))) {
+ fprintf(stderr, "tr_config_parse_one_filter: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ tr_filter_free(filt);
+ return NULL;
+ }
+
+ memset(filt->lines[i]->specs[j], 0, sizeof(TR_FSPEC));
+
+ if ((NULL == (filt->lines[i]->specs[j]->field = tr_new_name((char *)json_string_value(jffield)))) ||
+ (NULL == (filt->lines[i]->specs[j]->match = tr_new_name((char *)json_string_value(jfmatch))))) {
+ fprintf(stderr, "tr_config_parse_one_filter: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ tr_filter_free(filt);
+ return NULL;
+ }
+ }
+ }
+ return filt;
+}
+
+static TR_RP_CLIENT *tr_cfg_parse_one_rp_client (TR_INSTANCE *tr, json_t *jrp, TR_CFG_RC *rc)
{
TR_RP_CLIENT *rp = NULL;
json_t *jgns = NULL;
+ json_t *jfilt = NULL;
+ json_t *jftype = NULL;
int i = 0;
if ((!jrp) || (!rc)) {
return NULL;
}
- if (NULL == (rp = malloc(sizeof(TR_RP_CLIENT)))) {
- fprintf(stderr, "tr_config_parse_one_rp_realm: Out of memory.\n");
- *rc = TR_CFG_NOMEM;
+ if ((NULL == (jgns = json_object_get(jrp, "gss_names"))) ||
+ (!json_is_array(jgns))) {
+ fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client configuration, no GSS names.\n");
+ *rc = TR_CFG_NOPARSE;
return NULL;
}
-
- memset(rp, 0, sizeof(TR_RP_CLIENT));
-
- /* TBD parse filters and constraints */
- if ((NULL == (jgns = json_object_get(jrp, "gss_names"))) ||
- (!json_is_array(jgns))) {
- fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client configuration.\n");
- free(rp);
+ /* TBD -- Support more than one filter per RP client? */
+ if (NULL == (jfilt = json_object_get(jrp, "filter"))) {
+ fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client configuration, no filter.\n");
*rc = TR_CFG_NOPARSE;
return NULL;
}
- if (0 == json_array_size(jgns)) {
- fprintf(stderr, "tr_cfg_parse_one_rp_client: RP Client has no GSS Names.\n");
+ /* We only support rp_permitted filters for RP clients */
+ if ((NULL == (jftype = json_object_get(jfilt, "type"))) ||
+ (!json_is_string(jftype)) ||
+ (strcmp(json_string_value(jftype), "rp_permitted"))) {
+ fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing RP client filter type.\n");
*rc = TR_CFG_NOPARSE;
return NULL;
}
return NULL;
}
+ if (NULL == (rp = malloc(sizeof(TR_RP_CLIENT)))) {
+ fprintf(stderr, "tr_config_parse_one_rp_realm: Out of memory.\n");
+ *rc = TR_CFG_NOMEM;
+ return NULL;
+ }
+
+ memset(rp, 0, sizeof(TR_RP_CLIENT));
+
+ /* TBD -- support more than one filter entry per RP Client? */
+ if (NULL == (rp->filters[0] = tr_cfg_parse_one_filter(tr, jfilt, rc))) {
+ fprintf(stderr, "tr_cfg_parse_one_rp_client: Error parsing filter.\n");
+ free(rp);
+ *rc = TR_CFG_NOPARSE;
+ return NULL;
+ }
+
for (i = 0; i < json_array_size(jgns); i++) {
if (NULL == (rp->gss_names[i] = tr_new_name ((char *)json_string_value(json_array_get(jgns, i))))) {
fprintf(stderr, "tr_cfg_parse_one_rp_client: No memory for GSS Name.\n");
+ free(rp);
*rc = TR_CFG_NOMEM;
return NULL;
}
&rc))) {
return rc;
}
- fprintf(stderr, "tr_cfg_parse_rp_clients: RP client configured: %s.\n", rp->gss_names[0]->buf);
+ fprintf(stderr, "tr_cfg_parse_rp_clients: RP client configured -- first gss: %s", rp->gss_names[0]->buf);
rp->next = tr->new_cfg->rp_clients;
tr->new_cfg->rp_clients = rp;
}
(NULL == (jscfg = json_object_get(jidp, "shared_config"))) ||
(!json_is_string(jscfg)) ||
(NULL == (jsrvrs = json_object_get(jidp, "aaa_servers"))) ||
- (!json_is_array(jsrvrs)) ||
- (NULL == (japcs = json_object_get(jidp, "apcs"))) ||
- (!json_is_array(japcs))) {
+ (!json_is_array(jsrvrs))) {
fprintf(stderr, "tr_cfg_parse_one_idp_realm: Error parsing IDP realm configuration.\n");
free(idp);
*rc = TR_CFG_NOPARSE;
free(idp);
return NULL;
}
- if (NULL == (idp->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
- fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse APCs for realm %s .\n", idp->realm_id->buf);
- tr_free_name(idp->realm_id);
- /* TBD -- free aaa_servers */;
- free(idp);
- return NULL;
- }
-return idp;
+ if ((NULL != (japcs = json_object_get(jidp, "apcs"))) &&
+ (json_is_array(japcs))) {
+ if (NULL == (idp->apcs = tr_cfg_parse_apcs(tr, japcs, rc))) {
+ fprintf(stderr, "tr_cfg_parse_one_idp_realm: Can't parse APCs for realm %s .\n", idp->realm_id->buf);
+ tr_free_name(idp->realm_id);
+ /* TBD -- free aaa_servers */;
+ free(idp);
+ return NULL;
+ }
+ }
+ return idp;
}
static TR_CFG_RC tr_cfg_parse_idp_realms (TR_INSTANCE *tr, json_t *jcfg)
return rc;
}
-static TR_IDP_REALM *tr_cfg_find_idp (TR_INSTANCE *tr, TR_NAME *idp_id, TR_CFG_RC *rc)
-{
-
- TR_IDP_REALM *cfg_idp;
-
- if ((!tr) || (!idp_id)) {
- if (rc)
- *rc = TR_CFG_BAD_PARAMS;
- return NULL;
- }
-
- for (cfg_idp = tr->active_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
- if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
- fprintf(stderr, "tr_cfg_find_idp: Found %s.\n", idp_id->buf);
- return cfg_idp;
- }
- }
- /* if we didn't find one, return NULL */
- return NULL;
-}
-
static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_INSTANCE *tr, json_t *jidps, TR_CFG_RC *rc)
{
TR_IDP_REALM *idp = NULL;
}
for (i = 0; i < json_array_size(jidps); i++) {
- if (NULL == (temp_idp = (tr_cfg_find_idp(tr,
+ if (NULL == (temp_idp = (tr_cfg_find_idp(tr->new_cfg,
tr_new_name((char *)json_string_value(json_array_get(jidps, i))),
rc)))) {
fprintf(stderr, "tr_cfg_parse_comm_idps: Unknown IDP %s.\n",
return NULL;
}
- for (i = (json_array_size(jrps)-1); i >= 0; i++) {
+ for (i = (json_array_size(jrps)-1); i >= 0; i--) {
if (NULL == (temp_rp = malloc(sizeof(TR_RP_REALM)))) {
fprintf(stderr, "tr_cfg_parse_comm_rps: Can't allocate memory for RP Realm.\n");
if (rc)
return TR_CFG_SUCCESS;
}
-TR_RP_CLIENT *tr_cfg_find_rp (TR_INSTANCE *tr, TR_NAME *rp_gss, TR_CFG_RC *rc)
+TR_IDP_REALM *tr_cfg_find_idp (TR_CFG *tr_cfg, TR_NAME *idp_id, TR_CFG_RC *rc)
+{
+
+ TR_IDP_REALM *cfg_idp;
+
+ if ((!tr_cfg) || (!idp_id)) {
+ if (rc)
+ *rc = TR_CFG_BAD_PARAMS;
+ return NULL;
+ }
+
+ for (cfg_idp = tr_cfg->idp_realms; NULL != cfg_idp; cfg_idp = cfg_idp->next) {
+ if (!tr_name_cmp (idp_id, cfg_idp->realm_id)) {
+ fprintf(stderr, "tr_cfg_find_idp: Found %s.\n", idp_id->buf);
+ return cfg_idp;
+ }
+ }
+ /* if we didn't find one, return NULL */
+ return NULL;
+}
+
+TR_RP_CLIENT *tr_cfg_find_rp (TR_CFG *tr_cfg, TR_NAME *rp_gss, TR_CFG_RC *rc)
{
TR_RP_CLIENT *cfg_rp;
int i;
- if ((!tr) || (!rp_gss)) {
+ if ((!tr_cfg) || (!rp_gss)) {
if (rc)
*rc = TR_CFG_BAD_PARAMS;
return NULL;
}
- for (cfg_rp = tr->active_cfg->rp_clients; NULL != cfg_rp; cfg_rp = cfg_rp->next) {
+ for (cfg_rp = tr_cfg->rp_clients; NULL != cfg_rp; cfg_rp = cfg_rp->next) {
for (i = 0; i < TR_MAX_GSS_NAMES; i++) {
if (!tr_name_cmp (rp_gss, cfg_rp->gss_names[i])) {
fprintf(stderr, "tr_cfg_find_rp: Found %s.\n", rp_gss->buf);
return NULL;
}
+ /* TBD -- instead of using json_object_update, iterate through files for non-overlap config? */
if (!jcfg) {
jcfg = temp;
}else {