Configuration code for realm and domain constraints.
authorMargaret Wasserman <mrw@painless-security.com>
Thu, 30 Jan 2014 10:45:30 +0000 (05:45 -0500)
committerMargaret Wasserman <mrw@painless-security.com>
Thu, 30 Jan 2014 10:45:30 +0000 (05:45 -0500)
common/tr_config.c
common/tr_constraint.c [new file with mode: 0644]
common/tr_filter.c
include/tr_constraint.h [new file with mode: 0644]
include/tr_filter.h

index f227796..d101d9b 100644 (file)
@@ -109,6 +109,19 @@ static TR_CFG_RC tr_cfg_parse_internal (TR_INSTANCE *tr, json_t *jcfg) {
   }
 }
 
+static TR_CONSTRAINT *tr_cfg_parse_one_constraint (TR_INSTANCE *tr, const char *ctype, json_t *jdc, TR_CFG_RC *rc)
+{
+  if (NULL == (cons = malloc(sizeof(TR_CONSTRAINT)))) {
+    fprintf(stderr, "tr_cfg_parse_one_constraint: Out of memory.\n");
+    *rc = TR_CFG_NOMEM;
+    return NULL;
+  }
+
+  memset(filt, 0, sizeof(TR_FILTER));
+
+  
+}
+
 static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CFG_RC *rc)
 {
   TR_FILTER *filt = NULL;
@@ -118,6 +131,8 @@ static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CF
   json_t *jfspecs = NULL;
   json_t *jffield = NULL;
   json_t *jfmatch = NULL;
+  json_t *jrc = NULL;
+  json_t *jdc = NULL;
   int i = 0, j = 0;
 
   if ((NULL == (jftype = json_object_get(jfilt, "type"))) ||
@@ -140,8 +155,6 @@ static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CF
     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;
@@ -171,7 +184,25 @@ static TR_FILTER *tr_cfg_parse_one_filter (TR_INSTANCE *tr, json_t *jfilt, TR_CF
       return NULL;
     }
  
-    /* TBD -- parse constraints */
+    if ((NULL != (jrc = json_object_get(json_array_get(jfls, i), "realm_constraints"))) &&
+       (json_is_array(jrc)) &&
+       (0 != json_array_size(jrc)) &&
+       (TR_MAX_CONST_MATCHES >= json_array_size(jrc))) {
+      if (NULL == (filt->realm_cons = tr_cfg_parse_one_constraint(tr, "realm", jrc, rc)))
+       fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing realm constraint");
+      tr_filter_free(filt);
+      return NULL;
+    }
+
+    if ((NULL != (jdc = json_object_get(json_array_get(jfls, i), "domain_constraints"))) &&
+       (json_is_array(jdc)) &&
+       (0 != json_array_size(jdc)) &&
+       (TR_MAX_CONST_MATCHES >= json_array_size(jdc))) {
+      if (NULL == (filt->realm_cons = tr_cfg_parse_one_constraint(tr, "domain", jdc, rc)))
+       fprintf(stderr, "tr_cfg_parse_one_filter: Error parsing domain constraint");
+      tr_filter_free(filt);
+      return NULL;
+    }
 
     if ((NULL == (jfspecs = json_object_get(json_array_get(jfls, i), "filter_specs"))) ||
        (!json_is_array(jfspecs)) ||
diff --git a/common/tr_constraint.c b/common/tr_constraint.c
new file mode 100644 (file)
index 0000000..0910d76
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <jansson.h>
+
index a05b0d9..5b13e0e 100644 (file)
@@ -109,6 +109,11 @@ void tr_filter_free (TR_FILTER *filt) {
        if (filt->lines[i]->specs[j])
          free(filt->lines[i]->specs[j]);
       }
+      if (filt->lines[i]->realm_cons)
+       free(filt->lines[i]->realm_cons);
+      if (filt->lines[i]->domain_cons)
+       free(filt->lines[i]->domain_cons);
+
       free(filt->lines[i]);
     }
   }
diff --git a/include/tr_constraint.h b/include/tr_constraint.h
new file mode 100644 (file)
index 0000000..7245d33
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012, JANET(UK)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of JANET(UK) nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <jansson.h>
+
+#define TR_MAX_CONST_MATCHES 24;
+
+typedef json_t TR_CONSTRAINT_SET;
+
+typedef tr_constraint {
+  TR_NAME type;
+  TR_NAME matches[TR_MAX_CONST_MATCHES];
+} TR_CONSTRAINT;
index 08eb51c..b391f64 100644 (file)
 #define TR_FILTER_H
 
 #include <trust_router/tr_name.h>
+#include <tr_constraint.h>
 #include <jansson.h>
 
 #define TR_MAX_FILTERS 5
 #define TR_MAX_FILTER_LINES 8
 #define TR_MAX_FILTER_SPECS 8
-#define TR_MAX_CONS_VALUES  8
 
 /* Filter actions */
 #define TR_FILTER_ACTION_REJECT 0
 #define TR_FILTER_TYPE_RP_PERMITTED 0
 /* Other types TBD */
 
-typedef json_t TR_CONSTRAINT_SET;
-
-typedef struct tr_constraint {
-  TR_NAME values[TR_MAX_CONS_VALUES];
-} TR_CONSTRAINT;
-
 typedef struct tr_fspec {
   TR_NAME *field;
   TR_NAME *match;
@@ -69,7 +63,8 @@ typedef struct tr_fspec {
 typedef struct tr_fline {
   int action;
   TR_FSPEC *specs[TR_MAX_FILTER_SPECS];
-  TR_CONSTRAINT_SET *constraints;
+  TR_CONSTRAINT realm_cons;
+  TR_CONSTRAINT domain_cons;
 } TR_FLINE;
   
 typedef struct tr_filter {