Skip to content

Commit

Permalink
feature: add player.[serverID] principal to player contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
blattersturm committed Apr 19, 2020
1 parent 39eabb6 commit fd3fae9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
22 changes: 20 additions & 2 deletions code/client/citicore/se/Security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,19 @@ extern "C" se::Context* seGetCurrentContext()
}
else
{
console::Printf("security", "Access type needs to be 'allow' or 'deny'.");
console::Printf("security", "Access type needs to be 'allow' or 'deny'.\n");
return;
}

for (auto& principalRef : se::g_principalStack)
{
if (principalRef.get().GetIdentifier() == principal)
{
console::Printf("security", "Changing ones own access is not permitted.\n");
return;
}
}

seGetCurrentContext()->AddAccessControlEntry(se::Principal{ principal }, se::Object{ object }, type);
});

Expand All @@ -306,10 +315,19 @@ extern "C" se::Context* seGetCurrentContext()
}
else
{
console::Printf("security", "Access type needs to be 'allow' or 'deny'.");
console::Printf("security", "Access type needs to be 'allow' or 'deny'.\n");
return;
}

for (auto& principalRef : se::g_principalStack)
{
if (principalRef.get().GetIdentifier() == principal)
{
console::Printf("security", "Changing ones own access is not permitted.\n");
return;
}
}

seGetCurrentContext()->RemoveAccessControlEntry(se::Principal{ principal }, se::Object{ object }, type);
});

Expand Down
2 changes: 2 additions & 0 deletions code/components/citizen-server-impl/include/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ namespace fx
{
m_principals.emplace_back(se::Principal{ fmt::sprintf("identifier.%s", identifier) });
}

m_principals.emplace_back(se::Principal{ fmt::sprintf("player.%d", m_netId) });
}

private:
Expand Down
2 changes: 2 additions & 0 deletions code/components/citizen-server-impl/src/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ namespace fx
m_netId = netId;

OnAssignNetId();

UpdateCachedPrincipalValues();
}

void Client::SetTcpEndPoint(const std::string& value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,7 @@ static void CreatePlayerCommands()
const char* object = context.CheckArgument<const char*>(1);

se::ScopedPrincipalReset reset;

std::vector<std::unique_ptr<se::ScopedPrincipal>> principals;

for (auto& identifier : client->GetIdentifiers())
{
principals.emplace_back(std::make_unique<se::ScopedPrincipal>(se::Principal{ fmt::sprintf("identifier.%s", identifier) }));
}
auto principalScope = client->EnterPrincipalScope();

return seCheckPrivilege(object);
}));
Expand Down

0 comments on commit fd3fae9

Please sign in to comment.