Skip to content

Commit

Permalink
fix InitUser
Browse files Browse the repository at this point in the history
  • Loading branch information
buzhimingyonghu committed Nov 7, 2024
1 parent 62754fa commit e643c87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,15 @@ void Acl::InitLimitUser(const std::string& bl, bool limit_exist) {
}
u->SetUser("on");
}
if (!pass.empty()) {
u->SetUser(">" + pass);
}
} else {
if (pass.empty()) {
u->SetUser("nopass");
} else {
u->SetUser(">" + pass);
}
u->SetUser("on");
u->SetUser("+@all");
u->SetUser("~*");
Expand All @@ -506,11 +514,6 @@ void Acl::InitLimitUser(const std::string& bl, bool limit_exist) {
u->SetUser("-" + cmd);
}
}
if (pass.empty()) {
u->SetUser("nopass");
} else {
u->SetUser(">" + pass);
}
}
// bool Acl::CheckUserCanExec(const std::shared_ptr<Cmd>& cmd, const PikaCmdArgsType& argv) { cmd->name(); }

Expand Down
11 changes: 7 additions & 4 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -541,24 +541,27 @@ void PikaClientConn::UnAuth(const std::shared_ptr<User>& user) {

bool PikaClientConn::IsAuthed() const { return authenticated_; }
void PikaClientConn::InitUser() {
if (g_pika_conf->requirepass().empty()) {
user_ = g_pika_server->Acl()->GetUserLock(Acl::DefaultUser);
} else {
if (!g_pika_conf->GetUserBlackList().empty()) {
user_ = g_pika_server->Acl()->GetUserLock(Acl::DefaultLimitUser);
} else {
user_ = g_pika_server->Acl()->GetUserLock(Acl::DefaultUser);
}
authenticated_ = user_->HasFlags(static_cast<uint32_t>(AclUserFlag::NO_PASS)) &&
!user_->HasFlags(static_cast<uint32_t>(AclUserFlag::DISABLED));
}
bool PikaClientConn::AuthRequired() const {
// If the user does not have a password, and the user is valid, then the user does not need authentication
// Otherwise, you need to determine whether go has been authenticated
if (IsAuthed()) {
return false;
}
if (user_->HasFlags(static_cast<uint32_t>(AclUserFlag::DISABLED))) {
return true;
}
if (user_->HasFlags(static_cast<uint32_t>(AclUserFlag::NO_PASS))) {
return false;
}
return !IsAuthed();
return true;
}
std::string PikaClientConn::UserName() const { return user_->Name(); }

Expand Down

0 comments on commit e643c87

Please sign in to comment.