This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 10465a42 Add subcommand and permission check to RDB command (#1834)
10465a42 is described below
commit 10465a4255369165d8674dd2b57974099e5bd7af
Author: Twice <[email protected]>
AuthorDate: Wed Oct 18 23:00:50 2023 +0900
Add subcommand and permission check to RDB command (#1834)
---
src/commands/cmd_server.cc | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/commands/cmd_server.cc b/src/commands/cmd_server.cc
index 14ca00ee..f43f8937 100644
--- a/src/commands/cmd_server.cc
+++ b/src/commands/cmd_server.cc
@@ -1078,7 +1078,14 @@ class CommandRestore : public Commander {
class CommandRdb : public Commander {
public:
Status Parse(const std::vector<std::string> &args) override {
- CommandParser parser(args, 3);
+ CommandParser parser(args, 1);
+
+ type_ = GET_OR_RET(parser.TakeStr());
+ if (!util::EqualICase(type_, "load")) {
+ return {Status::RedisParseErr, "unknown subcommand"};
+ }
+
+ path_ = GET_OR_RET(parser.TakeStr());
while (parser.Good()) {
if (parser.EatEqICase("NX")) {
overwrite_exist_key_ = false;
@@ -1093,12 +1100,13 @@ class CommandRdb : public Commander {
}
Status Execute(Server *svr, Connection *conn, std::string *output) override {
- rocksdb::Status db_status;
+ if (!conn->IsAdmin()) {
+ return {Status::RedisExecErr, errAdminPermissionRequired};
+ }
+
redis::Database redis(svr->storage, conn->GetNamespace());
- auto type = args_[1];
- auto path = args_[2];
- auto stream_ptr = std::make_unique<RdbFileStream>(path);
+ auto stream_ptr = std::make_unique<RdbFileStream>(path_);
GET_OR_RET(stream_ptr->Open());
RDB rdb(svr->storage, conn->GetNamespace(), std::move(stream_ptr));
@@ -1109,6 +1117,8 @@ class CommandRdb : public Commander {
}
private:
+ std::string type_;
+ std::string path_;
bool overwrite_exist_key_ = true; // default overwrite exist key
uint32_t db_index_ = 0;
};