event/ServerSocket: move GetPeerCredentials() call to ClientListener::OnAccept()

This commit is contained in:
Max Kellermann 2025-01-29 19:29:21 +01:00
parent a0825e6ce0
commit 7adda0aa66
8 changed files with 11 additions and 21 deletions

@ -4,6 +4,7 @@
#include "Listener.hxx" #include "Listener.hxx"
#include "Client.hxx" #include "Client.hxx"
#include "Permission.hxx" #include "Permission.hxx"
#include "net/PeerCredentials.hxx"
#include "net/UniqueSocketDescriptor.hxx" #include "net/UniqueSocketDescriptor.hxx"
#include "net/SocketAddress.hxx" #include "net/SocketAddress.hxx"
#include "config.h" #include "config.h"
@ -29,8 +30,10 @@ GetPermissions(SocketAddress address, int uid) noexcept
void void
ClientListener::OnAccept(UniqueSocketDescriptor fd, ClientListener::OnAccept(UniqueSocketDescriptor fd,
SocketAddress address, int uid) noexcept SocketAddress address) noexcept
{ {
const auto cred = fd.GetPeerCredentials();
const int uid = cred.IsDefined() ? static_cast<int>(cred.GetUid()) : -1;
client_new(GetEventLoop(), partition, client_new(GetEventLoop(), partition,
std::move(fd), address, uid, std::move(fd), address, uid,

@ -17,7 +17,7 @@ public:
private: private:
void OnAccept(UniqueSocketDescriptor fd, void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address, int uid) noexcept override; SocketAddress address) noexcept override;
}; };
#endif #endif

@ -9,7 +9,6 @@
#include "net/IPv6Address.hxx" #include "net/IPv6Address.hxx"
#include "net/StaticSocketAddress.hxx" #include "net/StaticSocketAddress.hxx"
#include "net/AllocatedSocketAddress.hxx" #include "net/AllocatedSocketAddress.hxx"
#include "net/PeerCredentials.hxx"
#include "net/SocketUtil.hxx" #include "net/SocketUtil.hxx"
#include "net/SocketError.hxx" #include "net/SocketError.hxx"
#include "net/UniqueSocketDescriptor.hxx" #include "net/UniqueSocketDescriptor.hxx"
@ -102,16 +101,6 @@ private:
static constexpr Domain server_socket_domain("server_socket"); static constexpr Domain server_socket_domain("server_socket");
static int
get_remote_uid(SocketDescriptor s) noexcept
{
const auto cred = s.GetPeerCredentials();
if (!cred.IsDefined())
return -1;
return cred.GetUid();
}
inline void inline void
ServerSocket::OneServerSocket::Accept() noexcept ServerSocket::OneServerSocket::Accept() noexcept
{ {
@ -131,9 +120,7 @@ ServerSocket::OneServerSocket::Accept() noexcept
(const char *)msg); (const char *)msg);
} }
const auto uid = get_remote_uid(peer_fd); parent.OnAccept(std::move(peer_fd), peer_address);
parent.OnAccept(std::move(peer_fd), peer_address, uid);
} }
void void

@ -134,7 +134,7 @@ public:
protected: protected:
virtual void OnAccept(UniqueSocketDescriptor fd, virtual void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address, int uid) noexcept = 0; SocketAddress address) noexcept = 0;
}; };
#endif #endif

@ -251,7 +251,7 @@ private:
void OnDeferredBroadcast() noexcept; void OnDeferredBroadcast() noexcept;
void OnAccept(UniqueSocketDescriptor fd, void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address, int uid) noexcept override; SocketAddress address) noexcept override;
}; };
extern const class Domain httpd_output_domain; extern const class Domain httpd_output_domain;

@ -113,7 +113,7 @@ HttpdOutput::OnDeferredBroadcast() noexcept
void void
HttpdOutput::OnAccept(UniqueSocketDescriptor fd, HttpdOutput::OnAccept(UniqueSocketDescriptor fd,
SocketAddress, [[maybe_unused]] int uid) noexcept SocketAddress) noexcept
{ {
/* the listener socket has become readable - a client has /* the listener socket has become readable - a client has
connected */ connected */

@ -184,7 +184,7 @@ private:
/* virtual methods from class ServerSocket */ /* virtual methods from class ServerSocket */
void OnAccept(UniqueSocketDescriptor fd, void OnAccept(UniqueSocketDescriptor fd,
SocketAddress address, int uid) noexcept override; SocketAddress address) noexcept override;
}; };
#endif #endif

@ -95,7 +95,7 @@ SnapcastOutput::AddClient(UniqueSocketDescriptor fd) noexcept
void void
SnapcastOutput::OnAccept(UniqueSocketDescriptor fd, SnapcastOutput::OnAccept(UniqueSocketDescriptor fd,
SocketAddress, int) noexcept SocketAddress) noexcept
{ {
/* the listener socket has become readable - a client has /* the listener socket has become readable - a client has
connected */ connected */