Skip to content

Commit

Permalink
default & limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiaoshuai123 committed Mar 7, 2024
1 parent e950156 commit 86250b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
5 changes: 2 additions & 3 deletions include/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ class Acl {

void UpdateDefaultUserPassword(const std::string& pass);

void InitAdminUser();
void InitDefaultUser(const std::string& bl);
void InitLimitUser(const std::string& bl);

// After the user channel is modified, determine whether the current channel needs to be disconnected
void KillPubsubClientsIfNeeded(const std::shared_ptr<User>& origin, const std::shared_ptr<User>& newUser);
Expand All @@ -383,7 +382,7 @@ class Acl {
static std::vector<std::string> GetAllCategoryName();

static const std::string DefaultUser;
static const std::string Admin;
static const std::string Limit;
static const int64_t LogGroupingMaxTimeDelta;

// Adds a new entry in the ACL log, making sure to delete the old entry
Expand Down
29 changes: 12 additions & 17 deletions src/acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,14 @@ std::vector<std::string> User::AllChannelKey() {
// class Acl
pstd::Status Acl::Initialization() {
AddUser(CreateDefaultUser());
UpdateDefaultUserPassword(g_pika_conf->userpass());
UpdateDefaultUserPassword(g_pika_conf->requirepass());

AddUser(CreatedUser(Admin));
InitAdminUser();
AddUser(CreatedUser(Limit));
InitLimitUser(g_pika_conf->GetUserBlackList());
auto status = LoadUsersAtStartup();
if (!status.ok()) {
return status;
}
InitDefaultUser(g_pika_conf->GetUserBlackList());
return status;
}

Expand Down Expand Up @@ -476,31 +475,27 @@ void Acl::UpdateDefaultUserPassword(const std::string& pass) {
}
}

void Acl::InitAdminUser() {
auto pass = g_pika_conf->requirepass();
void Acl::InitLimitUser(const std::string& bl) {
auto pass = g_pika_conf->userpass();
std::vector<std::string> blacklist;
pstd::StringSplit(bl, ',', blacklist);
std::unique_lock wl(mutex_);
auto u = GetUser(Admin);
auto u = GetUser(Limit);
if (pass.empty()) {
u->SetUser("nopass");
} else {
u->SetUser(">"+pass);
}
u->SetUser("on");
u->SetUser("+@all");
u->SetUser("~*");
u->SetUser("&*");
u->SetUser("on");
}

void Acl::InitDefaultUser(const std::string& bl) {
std::unique_lock wl(mutex_);
auto defaultUser = GetUser(DefaultUser);
std::vector<std::string> blacklist;
pstd::StringSplit(bl, ',', blacklist);
for(auto& i : blacklist) {
defaultUser->SetUser("-"+i);
u->SetUser("-"+i);
}
}

}
// bool Acl::CheckUserCanExec(const std::shared_ptr<Cmd>& cmd, const PikaCmdArgsType& argv) { cmd->name(); }

std::shared_ptr<User> Acl::CreateDefaultUser() {
Expand Down Expand Up @@ -754,7 +749,7 @@ std::array<std::pair<std::string, uint32_t>, 3> Acl::SelectorFlags = {{
}};

const std::string Acl::DefaultUser = "default";
const std::string Acl::Admin = "admin";
const std::string Acl::Limit = "limit";
const int64_t Acl::LogGroupingMaxTimeDelta = 60000;

void Acl::AddLogEntry(int32_t reason, int32_t context, const std::string& username, const std::string& object,
Expand Down
8 changes: 4 additions & 4 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ void AuthCmd::Do() {

AuthResult authResult;
if (userName == "") {
// admin
authResult = AuthenticateUser(name(), Acl::Admin, pwd, conn, defaultAuth);
// default
authResult = AuthenticateUser(name(), Acl::DefaultUser, pwd, conn, true);
if (authResult != AuthResult::OK) {
// default。
authResult = AuthenticateUser(name(), Acl::DefaultUser, pwd, conn, true);
// Limit
authResult = AuthenticateUser(name(), Acl::Limit, pwd, conn, defaultAuth);
}
} else {
authResult = AuthenticateUser(name(), userName, pwd, conn, defaultAuth);
Expand Down

0 comments on commit 86250b0

Please sign in to comment.