Exemple #1
0
static int trp_peer_destructor(void *object)
{
  TRP_PEER *peer=talloc_get_type_abort(object, TRP_PEER);
  if (peer->label!=NULL)
    tr_free_name(peer->label);
  if (peer->servicename!=NULL)
    tr_free_name(peer->servicename);
  return 0;
}
Exemple #2
0
static int tr_comm_destructor(void *obj)
{
  TR_COMM *comm=talloc_get_type_abort(obj, TR_COMM);
  if (comm->id!=NULL)
    tr_free_name(comm->id);
  if (comm->owner_realm!=NULL)
    tr_free_name(comm->owner_realm);
  if (comm->owner_contact!=NULL)
    tr_free_name(comm->owner_contact);
  return 0;
}
Exemple #3
0
static int trp_route_destructor(void *obj)
{
  TRP_ROUTE *entry=talloc_get_type_abort(obj, TRP_ROUTE);
  if (entry->comm!=NULL)
    tr_free_name(entry->comm);
  if (entry->realm!=NULL)
    tr_free_name(entry->realm);
  if (entry->trust_router!=NULL)
    tr_free_name(entry->trust_router);
  if (entry->peer!=NULL)
    tr_free_name(entry->peer);
  if (entry->next_hop!=NULL)
    tr_free_name(entry->next_hop);
  return 0;
}
json_t *trp_route_to_json(TRP_ROUTE *route)
{
  json_t *route_json = NULL;
  json_t *retval = NULL;
  TR_NAME *n;

  route_json = json_object();
  if (route_json == NULL)
    goto cleanup;

  OBJECT_SET_OR_FAIL(route_json, "community", tr_name_to_json_string(trp_route_get_comm(route)));
  OBJECT_SET_OR_FAIL(route_json, "realm", tr_name_to_json_string(trp_route_get_realm(route)));
  if (trp_route_get_peer(route)->len > 0)
    OBJECT_SET_OR_FAIL(route_json, "peer", tr_name_to_json_string(trp_route_get_peer(route)));
  OBJECT_SET_OR_FAIL(route_json, "metric", json_integer(trp_route_get_metric(route)));

  /* add trust_router as hostname:port */
  n = tr_hostname_and_port_to_name(
          trp_route_get_trust_router(route),
          trp_route_get_trust_router_port(route));
  if (n == NULL)
    goto cleanup;
  OBJECT_SET_OR_FAIL(route_json, "trust_router", tr_name_to_json_string(n));
  tr_free_name(n);

  /* add next_hop as hostname:port */
  n = tr_hostname_and_port_to_name(
      trp_route_get_next_hop(route),
      trp_route_get_next_hop_port(route));
  if (n == NULL)
    goto cleanup;
  OBJECT_SET_OR_FAIL(route_json, "next_hop", tr_name_to_json_string(n));
  tr_free_name(n);

  OBJECT_SET_OR_FAIL(route_json, "selected", json_boolean(trp_route_is_selected(route)));
  OBJECT_SET_OR_FAIL(route_json, "local", json_boolean(trp_route_is_local(route)));
  OBJECT_SET_OR_SKIP(route_json, "expires", expiry_to_json_string(route));

  /* succeeded - set the return value and increment the reference count */
  retval = route_json;
  json_incref(retval);


cleanup:
  if (route_json)
    json_decref(route_json);
  return retval;
}
Exemple #5
0
static int destroy_tid_req(TID_REQ *req)
{
  if (req->json_references)
    json_decref(req->json_references);
  if (req->free_conn) {
    if (req->conn)
      close(req->conn);
    if (req->gssctx) {
      OM_uint32 minor;
      gss_delete_sec_context( &minor, &req->gssctx, NULL);
    }
  }
  if (req->rp_realm!=NULL)
    tr_free_name(req->rp_realm);
  if (req->realm!=NULL)
    tr_free_name(req->realm);
  if (req->comm!=NULL)
    tr_free_name(req->comm);
  if (req->orig_coi!=NULL)
    tr_free_name(req->orig_coi);
  return 0;
}
Exemple #6
0
static void trp_peer_set_servicename(TRP_PEER *peer, const char *server)
{
  char *name=NULL;
  if (peer->servicename !=NULL)
    tr_free_name(peer->servicename);

  if (server!=NULL)
    name=talloc_asprintf(NULL, "trustrouter/%s", server);

  if (name!=NULL) {
    peer->servicename=tr_new_name(name);
    talloc_free(name);
  } else {
    peer->servicename=NULL;
  }
}
Exemple #7
0
void tr_comm_set_id(TR_COMM *comm, TR_NAME *id)
{
  if (comm->id != NULL)
    tr_free_name(comm->id);
  comm->id=id;
}
Exemple #8
0
void tr_comm_set_owner_contact(TR_COMM *comm, TR_NAME *contact)
{
  if (comm->owner_contact != NULL)
    tr_free_name(comm->owner_contact);
  comm->owner_contact=contact;
}
Exemple #9
0
void tr_comm_set_owner_realm(TR_COMM *comm, TR_NAME *realm)
{
  if (comm->owner_realm!=NULL)
    tr_free_name(comm->owner_realm);
  comm->owner_realm=realm;
}
Exemple #10
0
static TR_COMM *tr_cfg_parse_one_comm (TR_CFG *trc, json_t *jcomm, TR_CFG_RC *rc) {
  TR_COMM *comm = NULL;
  json_t *jid = NULL;
  json_t *jtype = NULL;
  json_t *japcs = NULL;
  json_t *jidps = NULL;
  json_t *jrps = NULL;

  if ((!trc) || (!jcomm) || (!rc)) {
    tr_debug("tr_cfg_parse_one_comm: Bad parameters.");
    if (rc)
      *rc = TR_CFG_BAD_PARAMS;
    return NULL;
  }

  if (NULL == (comm = talloc_zero(trc, TR_COMM))) {
    tr_crit("tr_cfg_parse_one_comm: Out of memory.");
    *rc = TR_CFG_NOMEM;
    return NULL;
  }


  if ((NULL == (jid = json_object_get(jcomm, "community_id"))) ||
      (!json_is_string(jid)) ||
      (NULL == (jtype = json_object_get(jcomm, "type"))) ||
      (!json_is_string(jtype)) ||
      (NULL == (japcs = json_object_get(jcomm, "apcs"))) ||
      (!json_is_array(japcs)) ||
      (NULL == (jidps = json_object_get(jcomm, "idp_realms"))) ||
      (!json_is_array(jidps)) ||
      (NULL == (jrps = json_object_get(jcomm, "rp_realms"))) ||
      (!json_is_array(jrps))) {
    tr_debug("tr_cfg_parse_one_comm: Error parsing Communities configuration.");
    *rc = TR_CFG_NOPARSE;
    return NULL;
  }

  if (NULL == (comm->id = tr_new_name((char *)json_string_value(jid)))) {
    tr_debug("tr_cfg_parse_one_comm: No memory for community id.");
    *rc = TR_CFG_NOMEM;
    return NULL;
  }

  if (0 == strcmp(json_string_value(jtype), "apc")) {
    comm->type = TR_COMM_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;
    }
  } 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);
    *rc = TR_CFG_NOPARSE;
    return NULL;
  }

  comm->idp_realms = tr_cfg_parse_comm_idps(trc, jidps, 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;
  }

  comm->rp_realms = tr_cfg_parse_comm_rps(trc, jrps, 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;
  }

  if (TR_COMM_APC == comm->type) {
    json_t *jexpire  = json_object_get(jcomm, "expiration_interval");
    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;
	}
	comm->expiration_interval = json_integer_value(jexpire);
	if (comm->expiration_interval <= 10)
	  comm->expiration_interval = 11; /* Freeradius waits 10 minutes between successful TR queries*/
	if (comm->expiration_interval > 129600) /* 90 days*/
	comm->expiration_interval = 129600;
    }
  }
  
  return comm;
}
Exemple #11
0
static void trp_rtable_destroy_tr_name(gpointer data)
{
  tr_free_name(data);
}
Exemple #12
0
/* TODO: set the hostname and port for the next hop. Currently assume default TID port. --jlr */
void trp_route_set_next_hop(TRP_ROUTE *entry, TR_NAME *next_hop)
{
  if (entry->next_hop!=NULL)
    tr_free_name(entry->next_hop);
  entry->next_hop=next_hop;
}
Exemple #13
0
void trp_route_set_peer(TRP_ROUTE *entry, TR_NAME *peer)
{
  if (entry->peer!=NULL)
    tr_free_name(entry->peer);
  entry->peer=peer;
}
Exemple #14
0
void trp_route_set_trust_router(TRP_ROUTE *entry, TR_NAME *tr)
{
  if (entry->trust_router!=NULL)
    tr_free_name(entry->trust_router);
  entry->trust_router=tr;
}
Exemple #15
0
void trp_route_set_realm(TRP_ROUTE *entry, TR_NAME *realm)
{
  if (entry->realm!=NULL)
    tr_free_name(entry->realm);
  entry->realm=realm;
}
Exemple #16
0
void trp_route_set_comm(TRP_ROUTE *entry, TR_NAME *comm)
{
  if (entry->comm!=NULL)
    tr_free_name(entry->comm);
  entry->comm=comm;
}
Exemple #17
0
static TR_IDP_REALM *tr_cfg_parse_one_idp_realm (TR_CFG *trc, json_t *jidp, TR_CFG_RC *rc) {
  TR_IDP_REALM *idp = NULL;
  json_t *jrid = NULL;
  json_t *jscfg = NULL;
  json_t *jsrvrs = NULL;
  json_t *japcs = NULL;

  if ((!trc) || (!jidp) || (!rc)) {
    tr_debug("tr_cfg_parse_one_idp_realm: Bad parameters.");
    if (rc)
      *rc = TR_CFG_BAD_PARAMS;
    return NULL;
  }

  if (NULL == (idp = talloc(trc, TR_IDP_REALM))) {
    tr_debug("tr_cfg_parse_one_idp_realm: Out of memory.");
    *rc = TR_CFG_NOMEM;
    return NULL;
  }

  memset(idp, 0, sizeof(TR_IDP_REALM));

  if ((NULL == (jrid = json_object_get(jidp, "realm_id"))) ||
      (!json_is_string(jrid)) ||
      (NULL == (jscfg = json_object_get(jidp, "shared_config"))) ||
      (!json_is_string(jscfg)) ||
      (NULL == (jsrvrs = json_object_get(jidp, "aaa_servers"))) ||
      (!json_is_array(jsrvrs))) {
    tr_debug("tr_cfg_parse_one_idp_realm: Error parsing IDP realm configuration.");
    *rc = TR_CFG_NOPARSE;
    return NULL;
  }

  if (0 == strcmp(json_string_value(jscfg), "no")) {
    idp->shared_config = 0;
  } else {
    idp->shared_config = 1;
  }

  if (NULL == (idp->realm_id = tr_new_name((char *)json_string_value(jrid)))) {
    tr_debug("tr_cfg_parse_one_idp_realm: No memory for realm id.");
    *rc = TR_CFG_NOMEM;
    return NULL;
  }

  if (NULL == (idp->aaa_servers = tr_cfg_parse_aaa_servers(trc, jsrvrs, rc))) {
    tr_debug("tr_cfg_parse_one_idp_realm: Can't parse AAA servers for realm %s.", idp->realm_id->buf);
    tr_free_name(idp->realm_id);
    return NULL;
  }

  if ((NULL != (japcs = json_object_get(jidp, "apcs"))) &&
      (json_is_array(japcs))) {
    if (NULL == (idp->apcs = tr_cfg_parse_apcs(trc, japcs, rc))) {
      tr_debug("tr_cfg_parse_one_idp_realm: Can't parse APCs for realm %s .", idp->realm_id->buf);
      tr_free_name(idp->realm_id);
      /* TBD -- free aaa_servers */;
      return NULL;
    }
  } 
  return idp;
}