@@ -2055,14 +2055,20 @@ nc_get_uid(int sock, uid_t *uid)
2055
2055
2056
2056
#endif
2057
2057
2058
+ /**
2059
+ * @brief Fully accept a session on a connected UNIX socket.
2060
+ *
2061
+ * @param[in] session Session to use.
2062
+ * @param[in] sock Connected socket.
2063
+ * @return 1 on success.
2064
+ * @return -1 on error.
2065
+ */
2058
2066
static int
2059
- nc_accept_unix (struct nc_session * session , int sock )
2067
+ nc_accept_unix_session (struct nc_session * session , int sock )
2060
2068
{
2061
2069
#if defined (SO_PEERCRED ) || defined (HAVE_GETPEEREID )
2062
2070
struct passwd * pw , pw_buf ;
2063
2071
char * username ;
2064
-
2065
- session -> ti_type = NC_TI_UNIX ;
2066
2072
uid_t uid = 0 ;
2067
2073
char * buf = NULL ;
2068
2074
size_t buf_len = 0 ;
@@ -2074,7 +2080,7 @@ nc_accept_unix(struct nc_session *session, int sock)
2074
2080
2075
2081
pw = nc_getpw (uid , NULL , & pw_buf , & buf , & buf_len );
2076
2082
if (pw == NULL ) {
2077
- ERR (NULL , "Failed to find username for uid=%u (%s).\n " , uid , strerror (errno ));
2083
+ ERR (session , "Failed to find username for uid=%u (%s)." , uid , strerror (errno ));
2078
2084
close (sock );
2079
2085
return -1 ;
2080
2086
}
@@ -2086,15 +2092,17 @@ nc_accept_unix(struct nc_session *session, int sock)
2086
2092
close (sock );
2087
2093
return -1 ;
2088
2094
}
2089
- session -> username = username ;
2090
2095
2096
+ session -> username = username ;
2097
+ session -> ti_type = NC_TI_UNIX ;
2091
2098
session -> ti .unixsock .sock = sock ;
2092
2099
2093
2100
return 1 ;
2094
2101
#else
2095
2102
(void )session ;
2096
2103
(void )sock ;
2097
2104
2105
+ ERR (session , "Unable to learn the identity of the client connected to the UNIX socket, terminating." );
2098
2106
return -1 ;
2099
2107
#endif
2100
2108
}
@@ -2317,7 +2325,7 @@ nc_accept(int timeout, const struct ly_ctx *ctx, struct nc_session **session)
2317
2325
#endif /* NC_ENABLED_SSH_TLS */
2318
2326
if (server_opts .endpts [bind_idx ].ti == NC_TI_UNIX ) {
2319
2327
(* session )-> data = server_opts .endpts [bind_idx ].opts .unixsock ;
2320
- ret = nc_accept_unix (* session , sock );
2328
+ ret = nc_accept_unix_session (* session , sock );
2321
2329
sock = -1 ;
2322
2330
if (ret < 0 ) {
2323
2331
msgtype = NC_MSG_ERROR ;
0 commit comments