#include <tr_gss_names.h>
#include <tr_debug.h>
#include <tr_filter.h>
-#include <trust_router/tr_constraint.h>
+#include <tr_constraint_internal.h>
#include <tr_idp.h>
#include <tr.h>
#include <trust_router/trp.h>
#endif
-TR_GSS_NAMES *tr_cfg_parse_gss_names(TALLOC_CTX *mem_ctx, json_t *jgss_names, TR_CFG_RC *rc)
+TR_CFG_RC tr_cfg_parse_gss_names(TALLOC_CTX *mem_ctx, json_t *jgss_names, TR_GSS_NAMES **gssn_out)
{
TALLOC_CTX *tmp_ctx=talloc_new(NULL);
TR_GSS_NAMES *gn=NULL;
json_t *jname=NULL;
- int ii=0;
+ size_t ii=0;
TR_NAME *name=NULL;
+ TR_CFG_RC rc = TR_CFG_ERROR;
- if ((rc==NULL) || (jgss_names==NULL)) {
+ if (jgss_names==NULL) {
tr_err("tr_cfg_parse_gss_names: Bad parameters.");
- *rc=TR_CFG_BAD_PARAMS;
-
+ rc=TR_CFG_BAD_PARAMS;
+ goto cleanup;
}
if (!json_is_array(jgss_names)) {
tr_err("tr_cfg_parse_gss_names: gss_names not an array.");
- *rc=TR_CFG_NOPARSE;
+ rc=TR_CFG_NOPARSE;
goto cleanup;
}
jname=json_array_get(jgss_names, ii);
if (!json_is_string(jname)) {
tr_err("tr_cfg_parse_gss_names: Encountered non-string gss name.");
- *rc=TR_CFG_NOPARSE;
+ rc=TR_CFG_NOPARSE;
goto cleanup;
}
name=tr_new_name(json_string_value(jname));
if (name==NULL) {
tr_err("tr_cfg_parse_gss_names: Out of memory allocating gss name.");
- *rc=TR_CFG_NOMEM;
+ rc=TR_CFG_NOMEM;
goto cleanup;
}
if (tr_gss_names_add(gn, name)!=0) {
tr_free_name(name);
tr_err("tr_cfg_parse_gss_names: Unable to add gss name to RP client.");
- *rc=TR_CFG_ERROR;
+ rc=TR_CFG_ERROR;
goto cleanup;
}
}
- talloc_steal(mem_ctx, gn);
- *rc=TR_CFG_SUCCESS;
+ *gssn_out = gn;
+ talloc_steal(mem_ctx, *gssn_out);
+ rc=TR_CFG_SUCCESS;
cleanup:
talloc_free(tmp_ctx);
- if ((*rc!=TR_CFG_SUCCESS) && (gn!=NULL))
- gn=NULL;
- return gn;
+ return rc;
}
/* default filter accepts realm and *.realm */
{
TALLOC_CTX *tmp_ctx=talloc_new(NULL);
TR_FILTER *filt=NULL;
+ TR_FLINE *fline = NULL;
+ TR_FSPEC *fspec = NULL;
TR_FILTER_SET *filt_set=NULL;
TR_CONSTRAINT *cons=NULL;
TR_NAME *name=NULL;
goto cleanup;
}
tr_filter_set_type(filt, TR_FILTER_TYPE_TID_INBOUND);
- filt->lines[0]=tr_fline_new(filt);
- if (filt->lines[0]==NULL) {
+
+ fline = tr_fline_new(tmp_ctx);
+ if (fline==NULL) {
tr_debug("tr_cfg_default_filters: could not allocate filter line.");
*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_1;
+ fline->action=TR_FILTER_ACTION_ACCEPT;
+
+ fspec=tr_fspec_new(tmp_ctx);
+ fspec->field=n_rp_realm_1;
n_rp_realm_1=NULL; /* we don't own this name any more */
name=tr_dup_name(realm);
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- tr_fspec_add_match(filt->lines[0]->specs[0], name);
+ tr_fspec_add_match(fspec, name);
name=NULL; /* we no longer own the name */
+ if (tr_fline_add_spec(fline, fspec) == NULL) {
+ tr_debug("tr_cfg_default_filters: could not add first spec to filter line");
+ *rc = TR_CFG_NOMEM;
+ goto cleanup;
+ }
+
/* 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;
+ fspec=tr_fspec_new(tmp_ctx);
+ fspec->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))) {
goto cleanup;
}
- tr_fspec_add_match(filt->lines[0]->specs[1], name);
+ tr_fspec_add_match(fspec, name);
name=NULL; /* we no longer own the name */
+ if (tr_fline_add_spec(fline, fspec) == NULL) {
+ tr_debug("tr_cfg_default_filters: could not add second spec to filter line");
+ *rc = TR_CFG_NOMEM;
+ goto cleanup;
+ }
+
/* domain constraint */
- if (NULL==(cons=tr_constraint_new(filt->lines[0]))) {
+ if (NULL==(cons=tr_constraint_new(fline))) {
tr_debug("tr_cfg_default_filters: could not allocate domain constraint.");
*rc=TR_CFG_NOMEM;
goto cleanup;
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- cons->matches[0]=name;
+ if (NULL == tr_constraint_add_match(cons, name)) {
+ tr_debug("tr_cfg_default_filters: could not add realm name for domain constraint.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
+ }
name=tr_name_cat(n_prefix, realm);
if (name==NULL) {
tr_debug("tr_cfg_default_filters: could not allocate wildcard realm name for domain constraint.");
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- cons->matches[1]=name;
+ if (NULL == tr_constraint_add_match(cons, name)) {
+ tr_debug("tr_cfg_default_filters: could not add wildcard realm name for domain constraint.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
+ }
name=NULL;
- filt->lines[0]->domain_cons=cons;
+ fline->domain_cons=cons;
/* realm constraint */
- if (NULL==(cons=tr_constraint_new(filt->lines[0]))) {
+ if (NULL==(cons=tr_constraint_new(fline))) {
tr_debug("tr_cfg_default_filters: could not allocate realm constraint.");
*rc=TR_CFG_NOMEM;
goto cleanup;
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- cons->matches[0]=name;
+ if (NULL == tr_constraint_add_match(cons, name)) {
+ tr_debug("tr_cfg_default_filters: could not add realm name for realm constraint.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
+ }
name=tr_name_cat(n_prefix, realm);
if (name==NULL) {
tr_debug("tr_cfg_default_filters: could not allocate wildcard realm name for realm constraint.");
*rc=TR_CFG_NOMEM;
goto cleanup;
}
- cons->matches[1]=name;
+ if (NULL == tr_constraint_add_match(cons, name)) {
+ tr_debug("tr_cfg_default_filters: could not add wildcard realm name for realm constraint.");
+ *rc=TR_CFG_NOMEM;
+ goto cleanup;
+ }
name=NULL;
- filt->lines[0]->realm_cons=cons;
+ fline->realm_cons=cons;
+
+ /* put the fline in the filter */
+ if (NULL == tr_filter_add_line(filt, fline)) {
+ tr_debug("tr_cfg_default_filters: could not add line to filter.");
+ *rc = TR_CFG_NOMEM;
+ goto cleanup;
+ }
/* put the filter in a set */
filt_set=tr_filter_set_new(tmp_ctx);
goto cleanup;
}
- client->gss_names=tr_cfg_parse_gss_names(client, json_object_get(jrealm, "gss_names"), &call_rc);
+ call_rc = tr_cfg_parse_gss_names(client, json_object_get(jrealm, "gss_names"), &(client->gss_names));
if (call_rc!=TR_CFG_SUCCESS) {
tr_err("tr_cfg_parse_one_rp_client: could not parse gss_names.");