From 179a9f7199a63c64b7c8145575646e4dea3eb4c9 Mon Sep 17 00:00:00 2001 From: Wang Zhiyong Date: Fri, 19 Jul 2024 03:57:37 +0000 Subject: [PATCH] update --- src/cypher/procedure/procedure.cpp | 19 +++++++++++++++++++ src/cypher/procedure/procedure.h | 9 +++++++++ src/server/bolt_handler.cpp | 4 ++++ src/server/bolt_session.h | 1 + 4 files changed, 33 insertions(+) diff --git a/src/cypher/procedure/procedure.cpp b/src/cypher/procedure/procedure.cpp index 80b58cb401..8f4c830c00 100644 --- a/src/cypher/procedure/procedure.cpp +++ b/src/cypher/procedure/procedure.cpp @@ -30,6 +30,7 @@ #include "cypher/monitor/memory_monitor_allocator.h" #include "fma-common/encrypt.h" #include "import/import_v3.h" +#include "server/bolt_session.h" namespace cypher { @@ -1646,6 +1647,24 @@ void BuiltinProcedure::DbmsMetaRefreshCount(RTContext *ctx, const Record *record ac_db.RefreshCount(); } +void BuiltinProcedure::DbmsSecurityIsDefaultUserPassword(RTContext *ctx, const cypher::Record *record, + const cypher::VEC_EXPR &args, + const cypher::VEC_STR &yield_items, + std::vector *records) { + CYPHER_ARG_CHECK( + args.size() == 0, + "need 0 parameters, e.g. dbms.security.isDefaultUserPassword()") + if (ctx->txn_) ctx->txn_->Abort(); + bool is_default_user_password = false; + if (ctx->bolt_conn_) { + auto session = (bolt::BoltSession*)(ctx->bolt_conn_->GetContext()); + is_default_user_password = session->using_default_user_password; + } + Record r; + r.AddConstant(lgraph::FieldData(is_default_user_password)); + records->emplace_back(r.Snapshot()); +} + void BuiltinProcedure::DbmsSecurityChangePassword(RTContext *ctx, const cypher::Record *record, const cypher::VEC_EXPR &args, const cypher::VEC_STR &yield_items, diff --git a/src/cypher/procedure/procedure.h b/src/cypher/procedure/procedure.h index 03d44cd91e..6e6d32d7b8 100644 --- a/src/cypher/procedure/procedure.h +++ b/src/cypher/procedure/procedure.h @@ -183,6 +183,10 @@ class BuiltinProcedure { static void DbmsMetaRefreshCount(RTContext *ctx, const Record *record, const VEC_EXPR &args, const VEC_STR &yield_items, std::vector *records); + static void DbmsSecurityIsDefaultUserPassword(RTContext *ctx, const Record *record, + const VEC_EXPR &args, const VEC_STR &yield_items, + std::vector *records); + static void DbmsSecurityChangePassword(RTContext *ctx, const Record *record, const VEC_EXPR &args, const VEC_STR &yield_items, std::vector *records); @@ -728,6 +732,11 @@ static std::vector global_procedures = { Procedure("dbms.meta.refreshCount", BuiltinProcedure::DbmsMetaRefreshCount, Procedure::SIG_SPEC{}, Procedure::SIG_SPEC{{"", {0, lgraph_api::LGraphType::NUL}}}, false, true), + Procedure("dbms.security.isDefaultUserPassword", BuiltinProcedure::DbmsSecurityIsDefaultUserPassword, + Procedure::SIG_SPEC{}, + Procedure::SIG_SPEC{ + {"isDefaultUserPassword", {0, lgraph_api::LGraphType::BOOLEAN}} + }, true, false), Procedure("dbms.security.changePassword", BuiltinProcedure::DbmsSecurityChangePassword, Procedure::SIG_SPEC{ {"current_password", {0, lgraph_api::LGraphType::STRING}}, diff --git a/src/server/bolt_handler.cpp b/src/server/bolt_handler.cpp index 50116a2d6a..63521da396 100644 --- a/src/server/bolt_handler.cpp +++ b/src/server/bolt_handler.cpp @@ -225,6 +225,10 @@ std::functionpython_driver = true; } } + if (principal == lgraph::_detail::DEFAULT_ADMIN_NAME && + credentials == lgraph::_detail::DEFAULT_ADMIN_PASS) { + session->using_default_user_password = true; + } session->state = SessionState::READY; session->user = principal; session->fsm_thread = std::thread(BoltFSM, conn.shared_from_this()); diff --git a/src/server/bolt_session.h b/src/server/bolt_session.h index 0615565a89..cbc412c4f1 100644 --- a/src/server/bolt_session.h +++ b/src/server/bolt_session.h @@ -46,6 +46,7 @@ struct BoltSession { BlockingQueue msgs; std::thread fsm_thread; bool python_driver = false; + bool using_default_user_password = false; }; } // namespace bolt