* Use the new tr_parse_host() function
* Output more useful errors when parsing aaa servers
* Update Makefile.am
common/tr_dh.c \
common/tr_debug.c \
common/tr_util.c \
common/tr_dh.c \
common/tr_debug.c \
common/tr_util.c \
+ common/tr_inet_util.c \
common/tr_apc.c \
common/tr_comm.c \
common/tr_comm_encoders.c \
common/tr_apc.c \
common/tr_comm.c \
common/tr_comm_encoders.c \
common/tr_gss_names.c \
common/tr_debug.c \
common/tr_util.c \
common/tr_gss_names.c \
common/tr_debug.c \
common/tr_util.c \
common/tr_list.c \
trp/trp_route.c \
trp/trp_route_encoders.c \
common/tr_list.c \
trp/trp_route.c \
trp/trp_route_encoders.c \
include/trp_route.h include/trp_rtable.h \
include/tr_list.h \
include/tr_name_internal.h \
include/trp_route.h include/trp_rtable.h \
include/tr_list.h \
include/tr_name_internal.h \
- include/tr_util.h include/tr_json_util.h \
+ include/tr_util.h include/tr_json_util.h include/tr_inet_util.h\
include/tr_rand_id.h include/tr_socket.h \
include/tr_constraint_internal.h
include/tr_rand_id.h include/tr_socket.h \
include/tr_constraint_internal.h
#include <tr_aaa_server.h>
#include <trust_router/tid.h>
#include <tr_util.h>
#include <tr_aaa_server.h>
#include <trust_router/tid.h>
#include <tr_util.h>
+#include <tr_inet_util.h>
static int tr_aaa_server_destructor(void *obj)
{
static int tr_aaa_server_destructor(void *obj)
{
/**
* Allocate a AAA server record and fill it in by parsing a hostname:port string
*
/**
* Allocate a AAA server record and fill it in by parsing a hostname:port string
*
- * Does not validate hostname or port values. The port will be -1 if the port
- * could not be parsed properly.
+ * If hostname or port are invalid, hostname will be empty and port will be -1.
*
* @return newly allocated TR_AAA_SERVER in the mem_ctx context, or NULL on error
*/
*
* @return newly allocated TR_AAA_SERVER in the mem_ctx context, or NULL on error
*/
{
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
TR_AAA_SERVER *aaa = tr_aaa_server_new(tmp_ctx);
{
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
TR_AAA_SERVER *aaa = tr_aaa_server_new(tmp_ctx);
+ char *hostname;
+ int port;
if (aaa == NULL)
goto failed;
if (aaa == NULL)
goto failed;
- tr_aaa_server_set_hostname(aaa, tr_parse_hostname(s));
+ hostname = tr_parse_host(tmp_ctx, s, &port);
+ if (NULL == hostname) {
+ hostname = "";
+ port = -1;
+ }
+
+ tr_aaa_server_set_hostname(aaa, tr_new_name(hostname));
if (tr_aaa_server_get_hostname(aaa) == NULL)
goto failed;
if (tr_aaa_server_get_hostname(aaa) == NULL)
goto failed;
- tr_aaa_server_set_port(aaa, tr_parse_port(s));
+ tr_aaa_server_set_port(aaa, port); /* port = 0 uses default TID port */
talloc_steal(mem_ctx, aaa); /*put this in the caller's context */
goto succeeded;
talloc_steal(mem_ctx, aaa); /*put this in the caller's context */
goto succeeded;
#include <tr.h>
#include <trust_router/trp.h>
#include <tr_util.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"
#if JANSSON_VERSION_HEX < 0x020500
#include "jansson_iterators.h"
TR_GSS_NAMES *names=NULL;
TR_FILTER_SET *filt_set=NULL;
TR_CFG_RC rc=TR_CFG_ERROR;
TR_GSS_NAMES *names=NULL;
TR_FILTER_SET *filt_set=NULL;
TR_CFG_RC rc=TR_CFG_ERROR;
- TR_NAME *hostname=NULL;
- char *s_hostname=NULL;
int port;
jhost=json_object_get(jporg, "hostname");
int port;
jhost=json_object_get(jporg, "hostname");
- if (0 != tr_parse_hostname_and_port(json_string_value(jhost), &hostname, &port)) {
+ /* 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;
}
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) || (port > 65535)) {
tr_err("tr_cfg_parse_one_peer_org: invalid port (%s)", json_string_value(jhost));
rc=TR_CFG_NOPARSE;
goto cleanup;
tr_err("tr_cfg_parse_one_peer_org: invalid port (%s)", json_string_value(jhost));
rc=TR_CFG_NOPARSE;
goto cleanup;
port = TRP_PORT;
trp_peer_set_port(new_peer, port);
port = TRP_PORT;
trp_peer_set_port(new_peer, port);
-
- if (hostname->len == 0) {
- tr_err("tr_cfg_parse_one_peer_org: no hostname specified (%s)", json_string_value(jhost));
- rc=TR_CFG_NOPARSE;
- goto cleanup;
- }
-
- s_hostname = tr_name_strdup(hostname);
- if (s_hostname == NULL) {
- tr_err("tr_cfg_parse_one_peer_org: could not allocate hostname string.");
- rc = TR_CFG_NOMEM;
- goto cleanup;
- }
-
- trp_peer_set_server(new_peer, s_hostname); /* string is strdup'ed in _set_server() */
+ 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;
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;
rc=TR_CFG_SUCCESS;
cleanup:
rc=TR_CFG_SUCCESS;
cleanup:
- if (hostname)
- tr_free_name(hostname);
-
- if (s_hostname)
- free(s_hostname);
-
talloc_free(tmp_ctx);
return rc;
}
talloc_free(tmp_ctx);
return rc;
}
}
if (tr_aaa_server_get_hostname(aaa)->len == 0) {
}
if (tr_aaa_server_get_hostname(aaa)->len == 0) {
- tr_debug("tr_cfg_parse_one_aaa_server: Empty hostname for AAA server not allowed");
+ tr_debug("tr_cfg_parse_one_aaa_server: Invalid hostname for AAA server (%s)",
+ json_string_value(jaddr));
*rc = TR_CFG_NOPARSE;
goto cleanup;
}
if ((tr_aaa_server_get_port(aaa) <= 0)
|| (tr_aaa_server_get_port(aaa) > 65535)) {
*rc = TR_CFG_NOPARSE;
goto cleanup;
}
if ((tr_aaa_server_get_port(aaa) <= 0)
|| (tr_aaa_server_get_port(aaa) > 65535)) {
- tr_debug("tr_cfg_parse_one_aaa_server: Invalid AAA server port");
+ tr_debug("tr_cfg_parse_one_aaa_server: Invalid AAA server port (%s)",
+ json_string_value(jaddr));
*rc = TR_CFG_NOPARSE;
goto cleanup;
}
*rc = TR_CFG_NOPARSE;
goto cleanup;
}
#include <tr_filter.h>
#include <trp_internal.h>
#include <tid_internal.h>
#include <tr_filter.h>
#include <trp_internal.h>
#include <tid_internal.h>
+#include <tr_inet_util.h>
/* Function types for handling filter fields generally. All target values
* are represented as strings in a TR_NAME.
/* Function types for handling filter fields generally. All target values
* are represented as strings in a TR_NAME.
#include <trust_router/tr_constraint.h>
#include <trust_router/tr_dh.h>
#include <tr_debug.h>
#include <trust_router/tr_constraint.h>
#include <trust_router/tr_dh.h>
#include <tr_debug.h>
+#include <tr_inet_util.h>
/* JSON helpers */
/* Read attribute attr from msg as an integer. */
/* JSON helpers */
/* Read attribute attr from msg as an integer. */
TRP_RC rc=TRP_ERROR;
char *s=NULL;
TR_NAME *name;
TRP_RC rc=TRP_ERROR;
char *s=NULL;
TR_NAME *name;
if (rc != TRP_SUCCESS)
goto cleanup;
if (rc != TRP_SUCCESS)
goto cleanup;
- if (0 != tr_parse_hostname_and_port(s, &name, &port)) {
+ hostname = tr_parse_host(tmp_ctx, s, &port);
+ if ((NULL == hostname)
+ || (NULL == (name = tr_new_name(hostname)))
+ || (port < 0)) {
rc = TRP_ERROR;
goto cleanup;
}
talloc_free(s); s=NULL;
rc = TRP_ERROR;
goto cleanup;
}
talloc_free(s); s=NULL;
if (port == 0)
port = TRP_PORT;
if (port == 0)
port = TRP_PORT;
switch(tr_msg_get_json_string(jrecord, "next_hop", &s, tmp_ctx)) {
case TRP_SUCCESS:
/* we got a next_hop field */
switch(tr_msg_get_json_string(jrecord, "next_hop", &s, tmp_ctx)) {
case TRP_SUCCESS:
/* we got a next_hop field */
- if (0 != tr_parse_hostname_and_port(s, &name, &port)) {
+ hostname = tr_parse_host(tmp_ctx, s, &port);
+ if ((hostname == NULL)
+ || (NULL == (name = tr_new_name(hostname)))
+ || (port < 0)) {
rc = TRP_ERROR;
goto cleanup;
}
rc = TRP_ERROR;
goto cleanup;
}
#include <trust_router/trp.h>
#include <tr_util.h>
#include <tr_json_util.h>
#include <trust_router/trp.h>
#include <tr_util.h>
#include <tr_json_util.h>
+#include <tr_inet_util.h>
/* Pretty print a route table entry to a newly allocated string. If sep is NULL,
* returns comma+space separated string. */
/* Pretty print a route table entry to a newly allocated string. If sep is NULL,
* returns comma+space separated string. */