@@ -2967,9 +2967,7 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv
2967
2967
int ret = 0 ;
2968
2968
struct lyd_node * n ;
2969
2969
struct nc_ctn * new , * iter ;
2970
- const char * map_type , * name = NULL ;
2971
2970
uint32_t id ;
2972
- NC_TLS_CTN_MAPTYPE m_type ;
2973
2971
2974
2972
assert (!strcmp (LYD_NAME (node ), "cert-to-name" ));
2975
2973
@@ -2978,39 +2976,6 @@ nc_server_config_create_cert_to_name(const struct lyd_node *node, struct nc_serv
2978
2976
assert (n );
2979
2977
id = ((struct lyd_node_term * )n )-> value .uint32 ;
2980
2978
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
-
3014
2979
/* create new ctn */
3015
2980
new = calloc (1 , sizeof * new );
3016
2981
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
3038
3003
}
3039
3004
}
3040
3005
3041
- /* insert the right data */
3006
+ /* set the id, the other members will be filled later */
3042
3007
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 ;
3048
3008
3049
3009
cleanup :
3050
3010
return ret ;
@@ -3088,7 +3048,7 @@ nc_server_config_cert_to_name(const struct lyd_node *node, enum nc_operation op)
3088
3048
}
3089
3049
3090
3050
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 ) )
3092
3052
{
3093
3053
int ret = 0 ;
3094
3054
struct nc_ctn * ctn ;
@@ -3105,13 +3065,63 @@ nc_server_config_fingerprint(const struct lyd_node *node, enum nc_operation op)
3105
3065
goto cleanup ;
3106
3066
}
3107
3067
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 ;
3112
3114
} 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 );
3115
3125
}
3116
3126
3117
3127
cleanup :
@@ -3635,6 +3645,8 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, enum nc_opera
3635
3645
ret = nc_server_config_local_port (node , op );
3636
3646
} else if (!strcmp (name , "mac-alg" )) {
3637
3647
ret = nc_server_config_mac_alg (node , op );
3648
+ } else if (!strcmp (name , "map-type" )) {
3649
+ ret = nc_server_config_map_type (node , op );
3638
3650
} else if (!strcmp (name , "max-probes" )) {
3639
3651
ret = nc_server_config_max_probes (node , op );
3640
3652
} else if (!strcmp (name , "none" )) {
0 commit comments