Code to parse communities in config, so that we can check membership.
authorMargaret Wasserman <margaret@moonshot-proxy>
Tue, 2 Jul 2013 12:30:20 +0000 (08:30 -0400)
committerMargaret Wasserman <margaret@moonshot-proxy>
Tue, 2 Jul 2013 12:30:20 +0000 (08:30 -0400)
common/tr_config.c
include/tr_idp.h
include/tr_rp.h

index 09333c4..c038ab4 100644 (file)
@@ -90,10 +90,85 @@ static TR_CFG_RC tr_cfg_parse_internal (TR_INSTANCE *tr, json_t *jcfg) {
   return TR_CFG_SUCCESS;
 }
 
-static TR_CFG_RC tr_cfg_parse_rp_clients (TR_INSTANCE *tr, json_t *jcfg) {
-  //  json_t *jrpr = NULL;
+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;
+  int i = 0;
+
+  if ((!jrp) || (!rc)) {
+    fprintf(stderr, "tr_cfg_parse_one_rp_realm: Bad parameters.\n");
+    if (rc)
+      *rc = TR_CFG_BAD_PARAMS;
+    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;
+  }
   
-  return TR_CFG_SUCCESS;
+  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);
+    *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");
+    *rc = TR_CFG_NOPARSE;
+    return NULL;
+  }
+
+  if (TR_MAX_GSS_NAMES < json_array_size(jgns)) {
+    fprintf(stderr, "tr_cfg_parse_one_rp_client: RP Client has too many GSS Names.\n");
+    *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");
+      *rc = TR_CFG_NOMEM;
+      return NULL;
+    }
+  }
+  
+  return rp;
+}
+
+static TR_CFG_RC tr_cfg_parse_rp_clients (TR_INSTANCE *tr, json_t *jcfg) {
+  json_t *jrps = NULL;
+  TR_CFG_RC rc = TR_CFG_SUCCESS;
+  TR_RP_CLIENT *rp = NULL;
+  int i = 0;
+
+  if ((!tr) || (!tr->new_cfg) || (!jcfg))
+    return TR_CFG_BAD_PARAMS;
+
+  if ((NULL == (jrps = json_object_get(jcfg, "rp_clients"))) ||
+      (!json_is_array(jrps))) {
+    return TR_CFG_NOPARSE;
+  }
+
+  for (i = 0; i < json_array_size(jrps); i++) {
+    if (NULL == (rp = tr_cfg_parse_one_rp_client(tr, 
+                                                json_array_get(jrps, i), 
+                                                &rc))) {
+       return rc;
+    }
+    fprintf(stderr, "tr_cfg_parse_rp_clients: RP client configured: %s.\n", rp->gss_names[0]->buf);
+    rp->next = tr->new_cfg->rp_clients;
+    tr->new_cfg->rp_clients = rp;
+  }
+  return rc;
 }
 
 static TR_AAA_SERVER *tr_cfg_parse_one_aaa_server (TR_INSTANCE *tr, json_t *jaddr, TR_CFG_RC *rc) {
@@ -267,18 +342,108 @@ static TR_CFG_RC tr_cfg_parse_idp_realms (TR_INSTANCE *tr, json_t *jcfg)
   return rc;
 }
 
-static TR_IDP_REALM *tr_cfg_parse_comm_idps (TR_INSTANCE *tr, json_t *idps, TR_CFG_RC *rc)
+static TR_IDP_REALM *tr_cfg_find_idp (TR_INSTANCE *tr, TR_NAME *idp_id, TR_CFG_RC *rc)
 {
-  TR_IDP_REALM *idp;
 
-  return (idp = malloc(sizeof(TR_IDP_REALM)));
+  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_RP_CLIENT *tr_cfg_find_rp (TR_INSTANCE *tr, TR_NAME *rp_id, TR_CFG_RC *rc)
+{
+  TR_RP_CLIENT *cfg_rp;
+  int i;
+
+  if ((!tr) || (!rp_id)) {
+    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 (i = 0; i < TR_MAX_GSS_NAMES; i++) {
+      if (!tr_name_cmp (rp_id, cfg_rp->gss_names[i])) {
+       fprintf(stderr, "tr_cfg_find_rp: Found %s.\n", rp_id->buf);
+       return cfg_rp;
+      }
+    }
+  }
+  /* 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;
+  TR_IDP_REALM *temp_idp = NULL;
+  int i = 0;
+
+  if ((!tr) ||
+      (!jidps) ||
+      (!json_is_array(jidps))) {
+    if (rc)
+      *rc = TR_CFG_BAD_PARAMS;
+    return NULL;
+  }
+
+  for (i = 0; i < json_array_size(jidps); i++) {
+    if (NULL == (temp_idp = (tr_cfg_find_idp(tr, 
+                                            tr_new_name((char *)json_string_value(json_array_get(jidps, i))), 
+                                            rc)))) {
+      fprintf(stderr, "tr_cfg_parse_comm_idps: Unknown IDP %s.\n", 
+             (char *)json_string_value(json_array_get(jidps, i)));
+      return NULL;
+    }
+
+    temp_idp->comm_next = idp;
+    idp = temp_idp;
+  }
+
+  return idp;
 }
 
-static TR_RP_REALM *tr_cfg_parse_comm_rps (TR_INSTANCE *tr, json_t *rps, TR_CFG_RC *rc)
+static TR_RP_CLIENT *tr_cfg_parse_comm_rps (TR_INSTANCE *tr, json_t *jrps, TR_CFG_RC *rc)
 {
-  TR_RP_REALM *rp;
+  TR_RP_CLIENT *rp = NULL;
+  TR_RP_CLIENT *temp_rp = NULL;
+  int i = 0;
+
+  if ((!tr) ||
+      (!jrps) ||
+      (!json_is_array(jrps))) {
+    if (rc)
+      *rc = TR_CFG_BAD_PARAMS;
+    return NULL;
+  }
+
+  for (i = 0; i < json_array_size(jrps); i++) {
+    if (NULL == (temp_rp = (tr_cfg_find_rp(tr, 
+                                          tr_new_name((char *)json_string_value(json_array_get(jrps, i))), 
+                                          rc)))) {
+      fprintf(stderr, "tr_cfg_parse_comm_rps: Unknown RP %s.\n", 
+             (char *)json_string_value(json_array_get(jrps, i)));
+      return NULL;
+    }
+
+    temp_rp->comm_next = rp;
+    rp = temp_rp;
+  }
 
-  return (rp = malloc(sizeof(TR_RP_REALM)));
+  return rp;
 }
 
 static TR_COMM *tr_cfg_parse_one_comm (TR_INSTANCE *tr, json_t *jcomm, TR_CFG_RC *rc) {
index 8f68b67..c6807cd 100644 (file)
@@ -46,6 +46,7 @@ typedef struct tr_aaa_server {
 
 typedef struct tr_idp_realm {
   struct tr_idp_realm *next;
+  struct tr_idp_realm *comm_next; /* for link list in comm config */
   TR_NAME *realm_id;
   int shared_config;
   TR_AAA_SERVER *aaa_servers;
index edeeead..afb4175 100644 (file)
 
 #define TR_MAX_GSS_NAMES 5
 
-/* TBD -- should these two structures be unified or linked? */
-
 typedef struct tr_rp_client {
   struct tr_rp_client *next;
-  TR_NAME gss_name[TR_MAX_GSS_NAMES];
+  struct tr_rp_client *comm_next;
+  TR_NAME *gss_names[TR_MAX_GSS_NAMES];
   // TR_FILTER *filters;
 } TR_RP_CLIENT;
 
+/* Structure to make a link list of RP realms by name for community config */
 typedef struct tr_rp_realm {
   struct tr_rp_realm *next;
-  TR_NAME *realm_id;
+  TR_NAME *realm_name;
 } TR_RP_REALM;
 
 #endif