1212 *
1313 * https://opensource.org/licenses/BSD-3-Clause
1414 */
15- #define _QNX_SOURCE /* getpeereid */
16- #define _GNU_SOURCE /* threads, SO_PEERCRED */
15+ #define _GNU_SOURCE /* threads */
1716
1817#include <arpa/inet.h>
1918#include <assert.h>
@@ -2325,43 +2324,6 @@ nc_server_set_address_port(struct nc_endpt *endpt, struct nc_bind *bind, const c
23252324 return ret ;
23262325}
23272326
2328- #if defined (SO_PEERCRED ) || defined (HAVE_GETPEEREID )
2329-
2330- /**
2331- * @brief Get UID of the owner of a socket.
2332- *
2333- * @param[in] sock Socket to analyze.
2334- * @param[out] uid Socket owner UID.
2335- * @return 0 on success,
2336- * @return -1 on error.
2337- */
2338- static int
2339- nc_get_uid (int sock , uid_t * uid )
2340- {
2341- int r ;
2342-
2343- #ifdef SO_PEERCRED
2344- struct ucred ucred ;
2345- socklen_t len ;
2346-
2347- len = sizeof (ucred );
2348- r = getsockopt (sock , SOL_SOCKET , SO_PEERCRED , & ucred , & len );
2349- if (!r ) {
2350- * uid = ucred .uid ;
2351- }
2352- #else
2353- r = getpeereid (sock , uid , NULL );
2354- #endif
2355-
2356- if (r < 0 ) {
2357- ERR (NULL , "Failed to get owner UID of a UNIX socket (%s)." , strerror (errno ));
2358- return -1 ;
2359- }
2360- return 0 ;
2361- }
2362-
2363- #endif
2364-
23652327/**
23662328 * @brief Fully accept a session on a connected UNIX socket.
23672329 *
@@ -2373,14 +2335,13 @@ nc_get_uid(int sock, uid_t *uid)
23732335static int
23742336nc_accept_unix_session (struct nc_session * session , int sock )
23752337{
2376- #if defined (SO_PEERCRED ) || defined (HAVE_GETPEEREID )
23772338 struct passwd * pw , pw_buf ;
23782339 char * username ;
23792340 uid_t uid = 0 ;
23802341 char * buf = NULL ;
23812342 size_t buf_len = 0 ;
23822343
2383- if (nc_get_uid (sock , & uid )) {
2344+ if (unsock_get_uid (sock , & uid )) {
23842345 close (sock );
23852346 return -1 ;
23862347 }
@@ -2405,13 +2366,6 @@ nc_accept_unix_session(struct nc_session *session, int sock)
24052366 session -> ti .unixsock .sock = sock ;
24062367
24072368 return 1 ;
2408- #else
2409- (void )session ;
2410- (void )sock ;
2411-
2412- ERR (session , "Unable to learn the identity of the client connected to the UNIX socket, terminating." );
2413- return -1 ;
2414- #endif
24152369}
24162370
24172371API int
0 commit comments