#include <tr_idp.h>
#include <tr.h>
#include <trust_router/trp.h>
+#include <tr_util.h>
+#include <tr_inet_util.h>
#if JANSSON_VERSION_HEX < 0x020500
#include "jansson_iterators.h"
{
TALLOC_CTX *tmp_ctx=talloc_new(NULL);
json_t *jhost=NULL;
- json_t *jport=NULL;
json_t *jgss=NULL;
json_t *jfilt=NULL;
TRP_PEER *new_peer=NULL;
TR_GSS_NAMES *names=NULL;
TR_FILTER_SET *filt_set=NULL;
TR_CFG_RC rc=TR_CFG_ERROR;
+ char *hostname=NULL;
+ int port;
jhost=json_object_get(jporg, "hostname");
- jport=json_object_get(jporg, "port");
jgss=json_object_get(jporg, "gss_names");
jfilt=json_object_get(jporg, "filters");
goto cleanup;
}
- if ((jport!=NULL) && (!json_is_number(jport))) {
- /* note that not specifying the port is allowed, but if set it must be a number */
- tr_err("tr_cfg_parse_one_peer_org: port is not a number.");
- rc=TR_CFG_NOPARSE;
- goto cleanup;
- }
-
if ((jgss==NULL) || (!json_is_array(jgss))) {
tr_err("tr_cfg_parse_one_peer_org: gss_names not specified or not an array.");
rc=TR_CFG_NOPARSE;
goto cleanup;
}
- trp_peer_set_server(new_peer, json_string_value(jhost)); /* string is strdup'ed in _set_server() */
- if (jport==NULL)
- trp_peer_set_port(new_peer, TRP_PORT);
- else
- trp_peer_set_port(new_peer, json_integer_value(jport));
+ /* parse / validate the hostname and port */
+ hostname = tr_parse_host(tmp_ctx, json_string_value(jhost), &port);
+ if (NULL == hostname) {
+ tr_err("tr_cfg_parse_one_peer_org: error parsing hostname (%s)", json_string_value(jhost));
+ rc=TR_CFG_NOPARSE;
+ goto cleanup;
+ }
+
+ if (port < 0) {
+ tr_err("tr_cfg_parse_one_peer_org: invalid port (%s)", json_string_value(jhost));
+ rc=TR_CFG_NOPARSE;
+ goto cleanup;
+ }
+
+ if (port == 0)
+ port = TRP_PORT;
+ trp_peer_set_port(new_peer, port);
+
+ trp_peer_set_server(new_peer, hostname); /* string is strdup'ed in _set_server() */
+ if (trp_peer_get_server(new_peer) == NULL) {
+ tr_err("tr_cfg_parse_one_peer: could not set server hostname for new peer");
+ rc = TR_CFG_NOMEM;
+ goto cleanup;
+ }
rc = tr_cfg_parse_gss_names(tmp_ctx, jgss, &names);
if (rc!=TR_CFG_SUCCESS) {