@@ -770,42 +770,6 @@ nc_server_config_del_endpt_ssh(struct nc_endpt *endpt, struct nc_bind *bind)
770770 }
771771}
772772
773- #endif /* NC_ENABLED_SSH_TLS */
774-
775- void
776- nc_server_config_del_unix_socket_opts (struct nc_bind * bind , struct nc_server_unix_opts * opts )
777- {
778- if (bind -> sock > -1 ) {
779- close (bind -> sock );
780- }
781-
782- unlink (bind -> address );
783- free (bind -> address );
784- free (opts -> address );
785-
786- free (opts );
787- }
788-
789- void
790- nc_server_config_del_endpt_unix_socket (struct nc_endpt * endpt , struct nc_bind * bind )
791- {
792- free (endpt -> name );
793- nc_server_config_del_unix_socket_opts (bind , endpt -> opts .unixsock );
794-
795- server_opts .endpt_count -- ;
796- if (!server_opts .endpt_count ) {
797- free (server_opts .endpts );
798- free (server_opts .binds );
799- server_opts .endpts = NULL ;
800- server_opts .binds = NULL ;
801- } else if (endpt != & server_opts .endpts [server_opts .endpt_count ]) {
802- memcpy (endpt , & server_opts .endpts [server_opts .endpt_count ], sizeof * server_opts .endpts );
803- memcpy (bind , & server_opts .binds [server_opts .endpt_count ], sizeof * server_opts .binds );
804- }
805- }
806-
807- #ifdef NC_ENABLED_SSH_TLS
808-
809773static void
810774nc_server_config_del_cert (struct nc_cert_grouping * certs , struct nc_certificate * cert )
811775{
@@ -1060,7 +1024,7 @@ nc_server_config_listen(const struct lyd_node *node, NC_OPERATION op)
10601024 break ;
10611025#endif /* NC_ENABLED_SSH_TLS */
10621026 case NC_TI_UNIX :
1063- nc_server_config_del_endpt_unix_socket (& server_opts .endpts [i ], & server_opts .binds [i ]);
1027+ _nc_server_del_endpt_unix_socket (& server_opts .endpts [i ], & server_opts .binds [i ]);
10641028 break ;
10651029 case NC_TI_NONE :
10661030 case NC_TI_FD :
@@ -1234,7 +1198,7 @@ nc_server_config_endpoint(const struct lyd_node *node, NC_OPERATION op)
12341198 break ;
12351199#endif /* NC_ENABLED_SSH_TLS */
12361200 case NC_TI_UNIX :
1237- nc_server_config_del_endpt_unix_socket (endpt , bind );
1201+ _nc_server_del_endpt_unix_socket (endpt , bind );
12381202 break ;
12391203 case NC_TI_NONE :
12401204 case NC_TI_FD :
@@ -1429,73 +1393,6 @@ nc_server_config_tls(const struct lyd_node *node, NC_OPERATION op)
14291393 return ret ;
14301394}
14311395
1432- #endif /* NC_ENABLED_SSH_TLS */
1433-
1434- static int
1435- nc_server_config_set_address_port (struct nc_endpt * endpt , struct nc_bind * bind , const char * address , uint16_t port )
1436- {
1437- int sock = -1 , set_addr , ret = 0 ;
1438-
1439- assert ((address && !port ) || (!address && port ) || (endpt -> ti == NC_TI_UNIX ));
1440-
1441- if (address ) {
1442- set_addr = 1 ;
1443- } else {
1444- set_addr = 0 ;
1445- }
1446-
1447- if (set_addr ) {
1448- port = bind -> port ;
1449- } else {
1450- address = bind -> address ;
1451- }
1452-
1453- /* we have all the information we need to create a listening socket */
1454- if ((address && port ) || (endpt -> ti == NC_TI_UNIX )) {
1455- /* create new socket, close the old one */
1456- if (endpt -> ti == NC_TI_UNIX ) {
1457- sock = nc_sock_listen_unix (endpt -> opts .unixsock );
1458- } else {
1459- sock = nc_sock_listen_inet (address , port , & endpt -> ka );
1460- }
1461-
1462- if (sock == -1 ) {
1463- ret = 1 ;
1464- goto cleanup ;
1465- }
1466-
1467- if (bind -> sock > -1 ) {
1468- close (bind -> sock );
1469- }
1470- bind -> sock = sock ;
1471- }
1472-
1473- if (sock > -1 ) {
1474- switch (endpt -> ti ) {
1475- case NC_TI_UNIX :
1476- VRB (NULL , "Listening on %s for UNIX connections." , endpt -> opts .unixsock -> address );
1477- break ;
1478- #ifdef NC_ENABLED_SSH_TLS
1479- case NC_TI_LIBSSH :
1480- VRB (NULL , "Listening on %s:%u for SSH connections." , address , port );
1481- break ;
1482- case NC_TI_OPENSSL :
1483- VRB (NULL , "Listening on %s:%u for TLS connections." , address , port );
1484- break ;
1485- #endif /* NC_ENABLED_SSH_TLS */
1486- default :
1487- ERRINT ;
1488- ret = 1 ;
1489- break ;
1490- }
1491- }
1492-
1493- cleanup :
1494- return ret ;
1495- }
1496-
1497- #ifdef NC_ENABLED_SSH_TLS
1498-
14991396/* mandatory leaf */
15001397static int
15011398nc_server_config_local_address (const struct lyd_node * node , NC_OPERATION op )
@@ -1518,7 +1415,7 @@ nc_server_config_local_address(const struct lyd_node *node, NC_OPERATION op)
15181415 bind -> address = strdup (lyd_get_value (node ));
15191416 NC_CHECK_ERRMEM_GOTO (!bind -> address , ret = 1 , cleanup );
15201417
1521- ret = nc_server_config_set_address_port (endpt , bind , lyd_get_value (node ), 0 );
1418+ ret = nc_server_set_address_port (endpt , bind , lyd_get_value (node ), 0 );
15221419 if (ret ) {
15231420 goto cleanup ;
15241421 }
@@ -1551,7 +1448,7 @@ nc_server_config_local_port(const struct lyd_node *node, NC_OPERATION op)
15511448 bind -> port = 0 ;
15521449 }
15531450
1554- ret = nc_server_config_set_address_port (endpt , bind , NULL , bind -> port );
1451+ ret = nc_server_set_address_port (endpt , bind , NULL , bind -> port );
15551452 if (ret ) {
15561453 goto cleanup ;
15571454 }
@@ -2790,89 +2687,6 @@ nc_server_config_mac_alg(const struct lyd_node *node, NC_OPERATION op)
27902687 return ret ;
27912688}
27922689
2793- #endif /* NC_ENABLED_SSH_TLS */
2794-
2795- static int
2796- nc_server_config_create_unix_socket (struct nc_endpt * endpt )
2797- {
2798- endpt -> ti = NC_TI_UNIX ;
2799- endpt -> opts .unixsock = calloc (1 , sizeof * endpt -> opts .unixsock );
2800- NC_CHECK_ERRMEM_RET (!endpt -> opts .unixsock , 1 );
2801-
2802- /* set default values */
2803- endpt -> opts .unixsock -> mode = -1 ;
2804- endpt -> opts .unixsock -> uid = -1 ;
2805- endpt -> opts .unixsock -> gid = -1 ;
2806-
2807- return 0 ;
2808- }
2809-
2810- static int
2811- nc_server_config_unix_socket (const struct lyd_node * node , NC_OPERATION op )
2812- {
2813- int ret = 0 ;
2814- uint32_t log_options = 0 ;
2815- struct nc_endpt * endpt ;
2816- struct nc_bind * bind ;
2817- struct nc_server_unix_opts * opts ;
2818- struct lyd_node * data = NULL ;
2819-
2820- assert (!strcmp (LYD_NAME (node ), "unix-socket" ));
2821-
2822- if (nc_server_config_get_endpt (node , & endpt , & bind )) {
2823- ret = 1 ;
2824- goto cleanup ;
2825- }
2826-
2827- if (op == NC_OP_CREATE ) {
2828- if (nc_server_config_create_unix_socket (endpt )) {
2829- ret = 1 ;
2830- goto cleanup ;
2831- }
2832-
2833- opts = endpt -> opts .unixsock ;
2834-
2835- lyd_find_path (node , "path" , 0 , & data );
2836- assert (data );
2837-
2838- opts -> address = strdup (lyd_get_value (data ));
2839- bind -> address = strdup (lyd_get_value (data ));
2840- NC_CHECK_ERRMEM_GOTO (!opts -> address || !bind -> address , ret = 1 , cleanup );
2841-
2842- /* silently search for non-mandatory parameters */
2843- ly_temp_log_options (& log_options );
2844- ret = lyd_find_path (node , "mode" , 0 , & data );
2845- if (!ret ) {
2846- opts -> mode = strtol (lyd_get_value (data ), NULL , 8 );
2847- }
2848-
2849- ret = lyd_find_path (node , "uid" , 0 , & data );
2850- if (!ret ) {
2851- opts -> uid = strtol (lyd_get_value (data ), NULL , 10 );
2852- }
2853-
2854- ret = lyd_find_path (node , "gid" , 0 , & data );
2855- if (!ret ) {
2856- opts -> gid = strtol (lyd_get_value (data ), NULL , 10 );
2857- }
2858-
2859- /* reset the logging options */
2860- ly_temp_log_options (NULL );
2861-
2862- ret = nc_server_config_set_address_port (endpt , bind , NULL , 0 );
2863- if (ret ) {
2864- goto cleanup ;
2865- }
2866- } else if (op == NC_OP_DELETE ) {
2867- nc_server_config_del_unix_socket_opts (bind , endpt -> opts .unixsock );
2868- }
2869-
2870- cleanup :
2871- return ret ;
2872- }
2873-
2874- #ifdef NC_ENABLED_SSH_TLS
2875-
28762690static int
28772691nc_server_config_check_endpt_reference_cycle (struct nc_endpt * original , struct nc_endpt * next )
28782692{
@@ -4063,8 +3877,6 @@ nc_server_config_parse_netconf_server(const struct lyd_node *node, NC_OPERATION
40633877 ret = nc_server_config_hello_timeout (node , op );
40643878 } else if (!strcmp (name , "endpoint" )) {
40653879 ret = nc_server_config_endpoint (node , op );
4066- } else if (!strcmp (name , "unix-socket" )) {
4067- ret = nc_server_config_unix_socket (node , op );
40683880 }
40693881#ifdef NC_ENABLED_SSH_TLS
40703882 else if (!strcmp (name , "ssh ")) {
0 commit comments