client/New: pass SocketPeerCredentials to client_new()
This commit is contained in:
parent
7adda0aa66
commit
95c0e2505c
src/client
@ -21,6 +21,7 @@
|
||||
#include <string>
|
||||
|
||||
class SocketAddress;
|
||||
class SocketPeerCredentials;
|
||||
class UniqueSocketDescriptor;
|
||||
class EventLoop;
|
||||
class Path;
|
||||
@ -300,5 +301,6 @@ struct ClientPerPartitionListHook
|
||||
|
||||
void
|
||||
client_new(EventLoop &loop, Partition &partition,
|
||||
UniqueSocketDescriptor fd, SocketAddress address, int uid,
|
||||
UniqueSocketDescriptor fd, SocketAddress address,
|
||||
SocketPeerCredentials cred,
|
||||
unsigned permission) noexcept;
|
||||
|
@ -10,9 +10,9 @@
|
||||
#include "config.h"
|
||||
|
||||
static unsigned
|
||||
GetPermissions(SocketAddress address, int uid) noexcept
|
||||
GetPermissions(SocketAddress address, const SocketPeerCredentials cred) noexcept
|
||||
{
|
||||
(void)uid; // TODO: implement option to derive permissions from uid
|
||||
(void)cred; // TODO: implement option to derive permissions from uid
|
||||
|
||||
#ifdef HAVE_UN
|
||||
if (address.GetFamily() == AF_LOCAL)
|
||||
@ -33,9 +33,8 @@ ClientListener::OnAccept(UniqueSocketDescriptor fd,
|
||||
SocketAddress address) noexcept
|
||||
{
|
||||
const auto cred = fd.GetPeerCredentials();
|
||||
const int uid = cred.IsDefined() ? static_cast<int>(cred.GetUid()) : -1;
|
||||
|
||||
client_new(GetEventLoop(), partition,
|
||||
std::move(fd), address, uid,
|
||||
GetPermissions(address, uid));
|
||||
std::move(fd), address, cred,
|
||||
GetPermissions(address, cred));
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "Partition.hxx"
|
||||
#include "Instance.hxx"
|
||||
#include "lib/fmt/SocketAddressFormatter.hxx"
|
||||
#include "net/PeerCredentials.hxx"
|
||||
#include "net/UniqueSocketDescriptor.hxx"
|
||||
#include "net/SocketAddress.hxx"
|
||||
#include "util/SpanCast.hxx"
|
||||
@ -39,7 +40,8 @@ Client::Client(EventLoop &_loop, Partition &_partition,
|
||||
|
||||
void
|
||||
client_new(EventLoop &loop, Partition &partition,
|
||||
UniqueSocketDescriptor fd, SocketAddress remote_address, int uid,
|
||||
UniqueSocketDescriptor fd, SocketAddress remote_address,
|
||||
SocketPeerCredentials cred,
|
||||
unsigned permission) noexcept
|
||||
{
|
||||
static unsigned int next_client_num;
|
||||
@ -54,6 +56,8 @@ client_new(EventLoop &loop, Partition &partition,
|
||||
|
||||
(void)fd.WriteNoWait(AsBytes(GREETING));
|
||||
|
||||
const int uid = cred.IsDefined() ? static_cast<int>(cred.GetUid()) : -1;
|
||||
|
||||
const unsigned num = next_client_num++;
|
||||
auto *client = new Client(loop, partition, std::move(fd), uid,
|
||||
permission,
|
||||
|
Loading…
x
Reference in New Issue
Block a user