Skip to content
10 changes: 8 additions & 2 deletions src/server/acl/acl_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#include "server/acl/acl_family.h"

#include <cctype>
#include <optional>
#include <variant>

#include "absl/strings/ascii.h"
#include "absl/strings/escaping.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "core/overloaded.h"
Expand Down Expand Up @@ -50,12 +52,16 @@ void AclFamily::Acl(CmdArgList args, ConnectionContext* cntx) {
void AclFamily::List(CmdArgList args, ConnectionContext* cntx) {
const auto registry_with_lock = ServerState::tlocal()->user_registry->GetRegistryWithLock();
const auto& registry = registry_with_lock.registry;

(*cntx)->StartArray(registry.size());

auto pretty_print_sha = [](std::string_view pass) {
return absl::BytesToHexString(pass.substr(15)).substr(15);
Copy link
Contributor

@dranikpg dranikpg Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand 😄 bytes to hex string returns a string of length 30 (twice the size), why do you need only half of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to print up to 15 characters :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'm just gonna trust you on this one 🤣

};

for (const auto& [username, user] : registry) {
std::string buffer = "user ";
const std::string_view pass = user.Password();
const std::string password = pass == "nopass" ? "nopass" : std::string(pass.substr(0, 15));
const std::string password = pass == "nopass" ? "nopass" : pretty_print_sha(pass);
const std::string acl_cat = AclToString(user.AclCategory());

using namespace std::string_view_literals;
Expand Down