@@ -3080,7 +3080,7 @@ nc_server_config_map_type(const struct lyd_node *node, enum nc_operation UNUSED(
30803080 int ret = 0 ;
30813081 struct nc_ctn * ctn ;
30823082 struct nc_ch_client * ch_client = NULL ;
3083- const char * map_type , * name = NULL ;
3083+ const char * map_type ;
30843084 NC_TLS_CTN_MAPTYPE m_type ;
30853085
30863086 assert (!strcmp (LYD_NAME (node ), "map-type" ));
@@ -3097,10 +3097,6 @@ nc_server_config_map_type(const struct lyd_node *node, enum nc_operation UNUSED(
30973097 map_type = ((struct lyd_node_term * )node )-> value .ident -> name ;
30983098 if (!strcmp (map_type , "specified" )) {
30993099 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 );
31043100 } else if (!strcmp (map_type , "san-rfc822-name" )) {
31053101 m_type = NC_TLS_CTN_SAN_RFC822_NAME ;
31063102 } else if (!strcmp (map_type , "san-dns-name" )) {
@@ -3119,9 +3115,42 @@ nc_server_config_map_type(const struct lyd_node *node, enum nc_operation UNUSED(
31193115
31203116 /* mandatory node, no need to check the op */
31213117 ctn -> map_type = m_type ;
3122- if (name ) {
3123- ctn -> name = strdup (name );
3118+
3119+ cleanup :
3120+ return ret ;
3121+ }
3122+
3123+ static int
3124+ nc_server_config_name (const struct lyd_node * node , enum nc_operation op )
3125+ {
3126+ int ret = 0 ;
3127+ struct nc_ctn * ctn ;
3128+ struct nc_ch_client * ch_client = NULL ;
3129+
3130+ assert (!strcmp (LYD_NAME (node ), "name" ));
3131+
3132+ /* we only care about this node if it is a child of cert-to-name,
3133+ * because otherwise it is most likely a key of a list and such cases are handled together with the list */
3134+ if (!node -> parent || strcmp (LYD_NAME (node -> parent ), "cert-to-name" )) {
3135+ return 0 ;
3136+ }
3137+
3138+ if (is_ch (node ) && nc_server_config_get_ch_client (node , & ch_client )) {
3139+ return 1 ;
3140+ }
3141+
3142+ if (nc_server_config_get_ctn (node , ch_client , & ctn )) {
3143+ ret = 1 ;
3144+ goto cleanup ;
3145+ }
3146+
3147+ if ((op == NC_OP_CREATE ) || (op == NC_OP_REPLACE )) {
3148+ free (ctn -> name );
3149+ ctn -> name = strdup (lyd_get_value (node ));
31243150 NC_CHECK_ERRMEM_GOTO (!ctn -> name , ret = 1 , cleanup );
3151+ } else {
3152+ free (ctn -> name );
3153+ ctn -> name = NULL ;
31253154 }
31263155
31273156cleanup :
@@ -3649,6 +3678,8 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, enum nc_opera
36493678 ret = nc_server_config_map_type (node , op );
36503679 } else if (!strcmp (name , "max-probes" )) {
36513680 ret = nc_server_config_max_probes (node , op );
3681+ } else if (!strcmp (name , "name" )) {
3682+ ret = nc_server_config_name (node , op );
36523683 } else if (!strcmp (name , "none" )) {
36533684 ret = nc_server_config_none (node , op );
36543685 } else if (!strcmp (name , "password" )) {
0 commit comments