Skip to content

Commit e703c6f

Browse files
committed
server config BUGFIX handling ctn changes
Fixes #542
1 parent d200a06 commit e703c6f

File tree

1 file changed

+60
-48
lines changed

1 file changed

+60
-48
lines changed

src/server_config.c

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2967,9 +2967,7 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv
29672967
int ret = 0;
29682968
struct lyd_node *n;
29692969
struct nc_ctn *new, *iter;
2970-
const char *map_type, *name = NULL;
29712970
uint32_t id;
2972-
NC_TLS_CTN_MAPTYPE m_type;
29732971

29742972
assert(!strcmp(LYD_NAME(node), "cert-to-name"));
29752973

@@ -2978,39 +2976,6 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv
29782976
assert(n);
29792977
id = ((struct lyd_node_term *)n)->value.uint32;
29802978

2981-
/* get CTN map-type */
2982-
if (lyd_find_path(node, "map-type", 0, &n)) {
2983-
ERR(NULL, "Missing CTN map-type.");
2984-
ret = 1;
2985-
goto cleanup;
2986-
}
2987-
map_type = ((struct lyd_node_term *)n)->value.ident->name;
2988-
if (!strcmp(map_type, "specified")) {
2989-
m_type = NC_TLS_CTN_SPECIFIED;
2990-
2991-
/* get CTN name */
2992-
if (lyd_find_path(node, "name", 0, &n)) {
2993-
ERR(NULL, "Missing CTN \"specified\" user name.");
2994-
ret = 1;
2995-
goto cleanup;
2996-
}
2997-
name = lyd_get_value(n);
2998-
} else if (!strcmp(map_type, "san-rfc822-name")) {
2999-
m_type = NC_TLS_CTN_SAN_RFC822_NAME;
3000-
} else if (!strcmp(map_type, "san-dns-name")) {
3001-
m_type = NC_TLS_CTN_SAN_DNS_NAME;
3002-
} else if (!strcmp(map_type, "san-ip-address")) {
3003-
m_type = NC_TLS_CTN_SAN_IP_ADDRESS;
3004-
} else if (!strcmp(map_type, "san-any")) {
3005-
m_type = NC_TLS_CTN_SAN_ANY;
3006-
} else if (!strcmp(map_type, "common-name")) {
3007-
m_type = NC_TLS_CTN_COMMON_NAME;
3008-
} else {
3009-
ERR(NULL, "CTN map-type \"%s\" not supported.", map_type);
3010-
ret = 1;
3011-
goto cleanup;
3012-
}
3013-
30142979
/* create new ctn */
30152980
new = calloc(1, sizeof *new);
30162981
NC_CHECK_ERRMEM_GOTO(!new, ret = 1, cleanup);
@@ -3038,13 +3003,8 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv
30383003
}
30393004
}
30403005

3041-
/* insert the right data */
3006+
/* set the id, the other members will be filled later */
30423007
new->id = id;
3043-
if (name) {
3044-
new->name = strdup(name);
3045-
NC_CHECK_ERRMEM_GOTO(!new->name, ret = 1, cleanup);
3046-
}
3047-
new->map_type = m_type;
30483008

30493009
cleanup:
30503010
return ret;
@@ -3088,7 +3048,7 @@ nc_server_config_cert_to_name(const struct lyd_node *node, enum nc_operation op)
30883048
}
30893049

30903050
static int
3091-
nc_server_config_fingerprint(const struct lyd_node *node, enum nc_operation op)
3051+
nc_server_config_fingerprint(const struct lyd_node *node, enum nc_operation UNUSED(op))
30923052
{
30933053
int ret = 0;
30943054
struct nc_ctn *ctn;
@@ -3105,13 +3065,63 @@ nc_server_config_fingerprint(const struct lyd_node *node, enum nc_operation op)
31053065
goto cleanup;
31063066
}
31073067

3108-
if ((op == NC_OP_CREATE) || (op == NC_OP_REPLACE)) {
3109-
free(ctn->fingerprint);
3110-
ctn->fingerprint = strdup(lyd_get_value(node));
3111-
NC_CHECK_ERRMEM_GOTO(!ctn->fingerprint, ret = 1, cleanup);
3068+
/* mandatory node, no need to check the op */
3069+
free(ctn->fingerprint);
3070+
ctn->fingerprint = strdup(lyd_get_value(node));
3071+
NC_CHECK_ERRMEM_GOTO(!ctn->fingerprint, ret = 1, cleanup);
3072+
3073+
cleanup:
3074+
return ret;
3075+
}
3076+
3077+
static int
3078+
nc_server_config_map_type(const struct lyd_node *node, enum nc_operation UNUSED(op))
3079+
{
3080+
int ret = 0;
3081+
struct nc_ctn *ctn;
3082+
struct nc_ch_client *ch_client = NULL;
3083+
const char *map_type, *name = NULL;
3084+
NC_TLS_CTN_MAPTYPE m_type;
3085+
3086+
assert(!strcmp(LYD_NAME(node), "map-type"));
3087+
3088+
if (is_ch(node) && nc_server_config_get_ch_client(node, &ch_client)) {
3089+
return 1;
3090+
}
3091+
3092+
if (nc_server_config_get_ctn(node, ch_client, &ctn)) {
3093+
ret = 1;
3094+
goto cleanup;
3095+
}
3096+
3097+
map_type = ((struct lyd_node_term *)node)->value.ident->name;
3098+
if (!strcmp(map_type, "specified")) {
3099+
m_type = NC_TLS_CTN_SPECIFIED;
3100+
3101+
/* get CTN name */
3102+
assert(!strcmp(LYD_NAME(node->next), "name"));
3103+
name = lyd_get_value(node->next);
3104+
} else if (!strcmp(map_type, "san-rfc822-name")) {
3105+
m_type = NC_TLS_CTN_SAN_RFC822_NAME;
3106+
} else if (!strcmp(map_type, "san-dns-name")) {
3107+
m_type = NC_TLS_CTN_SAN_DNS_NAME;
3108+
} else if (!strcmp(map_type, "san-ip-address")) {
3109+
m_type = NC_TLS_CTN_SAN_IP_ADDRESS;
3110+
} else if (!strcmp(map_type, "san-any")) {
3111+
m_type = NC_TLS_CTN_SAN_ANY;
3112+
} else if (!strcmp(map_type, "common-name")) {
3113+
m_type = NC_TLS_CTN_COMMON_NAME;
31123114
} else {
3113-
free(ctn->fingerprint);
3114-
ctn->fingerprint = NULL;
3115+
ERR(NULL, "CTN map-type \"%s\" not supported.", map_type);
3116+
ret = 1;
3117+
goto cleanup;
3118+
}
3119+
3120+
/* mandatory node, no need to check the op */
3121+
ctn->map_type = m_type;
3122+
if (name) {
3123+
ctn->name = strdup(name);
3124+
NC_CHECK_ERRMEM_GOTO(!ctn->name, ret = 1, cleanup);
31153125
}
31163126

31173127
cleanup:
@@ -3635,6 +3645,8 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, enum nc_opera
36353645
ret = nc_server_config_local_port(node, op);
36363646
} else if (!strcmp(name, "mac-alg")) {
36373647
ret = nc_server_config_mac_alg(node, op);
3648+
} else if (!strcmp(name, "map-type")) {
3649+
ret = nc_server_config_map_type(node, op);
36383650
} else if (!strcmp(name, "max-probes")) {
36393651
ret = nc_server_config_max_probes(node, op);
36403652
} else if (!strcmp(name, "none")) {

0 commit comments

Comments
 (0)