|
5 | 5 |
|
6 | 6 | #include "include/pika_admin.h" |
7 | 7 |
|
| 8 | +#include <sys/statvfs.h> |
8 | 9 | #include <sys/time.h> |
9 | 10 | #include <sys/utsname.h> |
10 | | -#include <sys/statvfs.h> |
11 | 11 |
|
12 | 12 | #include <algorithm> |
13 | 13 | #include <unordered_map> |
@@ -60,10 +60,12 @@ enum AuthResult { |
60 | 60 | }; |
61 | 61 |
|
62 | 62 | static AuthResult AuthenticateUser(const std::string& userName, const std::string& pwd, |
63 | | - const std::shared_ptr<net::NetConn>& conn) { |
64 | | - std::string root_password(g_pika_conf->requirepass()); |
65 | | - if (userName == Acl::DefaultUser && root_password.empty()) { |
66 | | - return AuthResult::NO_REQUIRE_PASS; |
| 63 | + const std::shared_ptr<net::NetConn>& conn, bool defaultAuth) { |
| 64 | + if (defaultAuth) { |
| 65 | + auto defaultUser = g_pika_server->Acl()->GetUser(Acl::DefaultUser, true); |
| 66 | + if (defaultUser->HasFlags(static_cast<uint32_t>(AclUserFlag::NO_PASS))) { |
| 67 | + return AuthResult::NO_REQUIRE_PASS; |
| 68 | + } |
67 | 69 | } |
68 | 70 |
|
69 | 71 | auto user = g_pika_server->Acl()->Auth(userName, pwd); |
@@ -261,22 +263,24 @@ void AuthCmd::Do(std::shared_ptr<Slot> slot) { |
261 | 263 |
|
262 | 264 | std::string userName = ""; |
263 | 265 | std::string pwd = ""; |
| 266 | + bool defaultAuth = false; |
264 | 267 | if (argv_.size() == 2) { |
265 | 268 | userName = Acl::DefaultUser; |
266 | 269 | pwd = argv_[1]; |
| 270 | + defaultAuth = true; |
267 | 271 | } else { |
268 | 272 | userName = argv_[1]; |
269 | 273 | pwd = argv_[2]; |
270 | 274 | } |
271 | 275 |
|
272 | | - auto authResult = AuthenticateUser(userName, pwd, conn); |
| 276 | + auto authResult = AuthenticateUser(userName, pwd, conn, defaultAuth); |
273 | 277 |
|
274 | 278 | switch (authResult) { |
275 | 279 | case AuthResult::INVALID_CONN: |
276 | 280 | res_.SetRes(CmdRes::kErrOther, kCmdNamePing); |
277 | 281 | return; |
278 | 282 | case AuthResult::INVALID_PASSWORD: |
279 | | - res_.SetRes(CmdRes::kInvalidPwd); |
| 283 | + res_.SetRes(CmdRes::kErrOther, "WRONGPASS invalid username-password pair or user is disabled"); |
280 | 284 | return; |
281 | 285 | case AuthResult::NO_REQUIRE_PASS: |
282 | 286 | res_.SetRes(CmdRes::kErrOther, "Client sent AUTH, but no password is set"); |
@@ -858,8 +862,10 @@ void InfoCmd::InfoStats(std::string& info) { |
858 | 862 | tmp_stream << "total_commands_processed:" << g_pika_server->ServerQueryNum() << "\r\n"; |
859 | 863 |
|
860 | 864 | // Network stats |
861 | | - tmp_stream << "total_net_input_bytes:" << g_pika_server->NetInputBytes() + g_pika_server->NetReplInputBytes() << "\r\n"; |
862 | | - tmp_stream << "total_net_output_bytes:" << g_pika_server->NetOutputBytes() + g_pika_server->NetReplOutputBytes() << "\r\n"; |
| 865 | + tmp_stream << "total_net_input_bytes:" << g_pika_server->NetInputBytes() + g_pika_server->NetReplInputBytes() |
| 866 | + << "\r\n"; |
| 867 | + tmp_stream << "total_net_output_bytes:" << g_pika_server->NetOutputBytes() + g_pika_server->NetReplOutputBytes() |
| 868 | + << "\r\n"; |
863 | 869 | tmp_stream << "total_net_repl_input_bytes:" << g_pika_server->NetReplInputBytes() << "\r\n"; |
864 | 870 | tmp_stream << "total_net_repl_output_bytes:" << g_pika_server->NetReplOutputBytes() << "\r\n"; |
865 | 871 | tmp_stream << "instantaneous_input_kbps:" << g_pika_server->InstantaneousInputKbps() << "\r\n"; |
@@ -1263,25 +1269,24 @@ void InfoCmd::InfoDebug(std::string& info) { |
1263 | 1269 | } |
1264 | 1270 |
|
1265 | 1271 | void InfoCmd::InfoCommandStats(std::string& info) { |
1266 | | - std::stringstream tmp_stream; |
1267 | | - tmp_stream.precision(2); |
1268 | | - tmp_stream.setf(std::ios::fixed); |
1269 | | - tmp_stream << "# Commandstats" << "\r\n"; |
1270 | | - for (auto iter : *g_pika_server->GetCommandStatMap()) { |
1271 | | - if (iter.second.cmd_count != 0) { |
1272 | | - tmp_stream << iter.first << ":" |
1273 | | - << "calls=" << iter.second.cmd_count << ", usec=" |
1274 | | - << MethodofTotalTimeCalculation(iter.second.cmd_time_consuming) |
1275 | | - << ", usec_per_call="; |
1276 | | - if (!iter.second.cmd_time_consuming) { |
1277 | | - tmp_stream << 0 << "\r\n"; |
1278 | | - } else { |
1279 | | - tmp_stream << MethodofCommandStatistics(iter.second.cmd_time_consuming, iter.second.cmd_count) |
1280 | | - << "\r\n"; |
1281 | | - } |
| 1272 | + std::stringstream tmp_stream; |
| 1273 | + tmp_stream.precision(2); |
| 1274 | + tmp_stream.setf(std::ios::fixed); |
| 1275 | + tmp_stream << "# Commandstats" |
| 1276 | + << "\r\n"; |
| 1277 | + for (auto iter : *g_pika_server->GetCommandStatMap()) { |
| 1278 | + if (iter.second.cmd_count != 0) { |
| 1279 | + tmp_stream << iter.first << ":" |
| 1280 | + << "calls=" << iter.second.cmd_count |
| 1281 | + << ", usec=" << MethodofTotalTimeCalculation(iter.second.cmd_time_consuming) << ", usec_per_call="; |
| 1282 | + if (!iter.second.cmd_time_consuming) { |
| 1283 | + tmp_stream << 0 << "\r\n"; |
| 1284 | + } else { |
| 1285 | + tmp_stream << MethodofCommandStatistics(iter.second.cmd_time_consuming, iter.second.cmd_count) << "\r\n"; |
1282 | 1286 | } |
1283 | 1287 | } |
1284 | | - info.append(tmp_stream.str()); |
| 1288 | + } |
| 1289 | + info.append(tmp_stream.str()); |
1285 | 1290 | } |
1286 | 1291 |
|
1287 | 1292 | void ConfigCmd::DoInitial() { |
@@ -1344,7 +1349,7 @@ static void EncodeString(std::string* dst, const std::string& value) { |
1344 | 1349 | dst->append(kNewLine); |
1345 | 1350 | } |
1346 | 1351 |
|
1347 | | -template<class T> |
| 1352 | +template <class T> |
1348 | 1353 | static void EncodeNumber(std::string* dst, const T v) { |
1349 | 1354 | std::string vstr = std::to_string(v); |
1350 | 1355 | dst->append("$"); |
@@ -2236,7 +2241,7 @@ void ConfigCmd::ConfigRewrite(std::string& ret) { |
2236 | 2241 | } |
2237 | 2242 | } |
2238 | 2243 |
|
2239 | | -void ConfigCmd::ConfigRewriteReplicationID(std::string &ret) { |
| 2244 | +void ConfigCmd::ConfigRewriteReplicationID(std::string& ret) { |
2240 | 2245 | if (g_pika_conf->ConfigRewriteReplicationID() != 0) { |
2241 | 2246 | ret = "+OK\r\n"; |
2242 | 2247 | } else { |
@@ -2552,13 +2557,13 @@ void HelloCmd::Do(std::shared_ptr<Slot> slot) { |
2552 | 2557 | const std::string opt = argv_[next_arg]; |
2553 | 2558 | if ((strcasecmp(opt.data(), "AUTH") == 0) && (more_args != 0U)) { |
2554 | 2559 | const std::string pwd = argv_[next_arg + 1]; |
2555 | | - auto authResult = AuthenticateUser(Acl::DefaultUser, pwd, conn); |
| 2560 | + auto authResult = AuthenticateUser(Acl::DefaultUser, pwd, conn, true); |
2556 | 2561 | switch (authResult) { |
2557 | 2562 | case AuthResult::INVALID_CONN: |
2558 | 2563 | res_.SetRes(CmdRes::kErrOther, kCmdNamePing); |
2559 | 2564 | return; |
2560 | 2565 | case AuthResult::INVALID_PASSWORD: |
2561 | | - res_.SetRes(CmdRes::kInvalidPwd); |
| 2566 | + res_.SetRes(CmdRes::kErrOther, "WRONGPASS invalid username-password pair or user is disabled"); |
2562 | 2567 | return; |
2563 | 2568 | case AuthResult::NO_REQUIRE_PASS: |
2564 | 2569 | res_.SetRes(CmdRes::kErrOther, "Client sent AUTH, but no password is set"); |
@@ -2650,12 +2655,12 @@ void DiskRecoveryCmd::Do(std::shared_ptr<Slot> slot) { |
2650 | 2655 | db_item.second->SetBinlogIoErrorrelieve(); |
2651 | 2656 | std::shared_lock slot_rwl(slots_rw); |
2652 | 2657 | // loop every slot |
2653 | | - for (const auto &slot_item: db_item.second->GetSlots()) { |
| 2658 | + for (const auto& slot_item : db_item.second->GetSlots()) { |
2654 | 2659 | background_errors_.clear(); |
2655 | 2660 | slot_item.second->DbRWLockReader(); |
2656 | 2661 | slot_item.second->db()->GetUsage(storage::PROPERTY_TYPE_ROCKSDB_BACKGROUND_ERRORS, &background_errors_); |
2657 | 2662 | slot_item.second->DbRWUnLock(); |
2658 | | - for (const auto &item: background_errors_) { |
| 2663 | + for (const auto& item : background_errors_) { |
2659 | 2664 | if (item.second != 0) { |
2660 | 2665 | rocksdb::Status s = slot_item.second->db()->GetDBByType(item.first)->Resume(); |
2661 | 2666 | if (!s.ok()) { |
|
0 commit comments