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