From b765068e2a6ee8e6d7c007bdd99e105d25ee484d Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:24:47 +0000 Subject: [PATCH 01/12] =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81report?= =?UTF-8?q?=E5=92=8Clog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 6d9b1f9..7cc9008 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -99,9 +99,11 @@ std::vector BookStoreEngineClass::Execute( return ExecuteBuy(cmd, login_stack); } case OperationType::__Kreport: { + return std::vector({"Invalid"}); return ExecuteReport(cmd, login_stack); } case OperationType::__Klog: { + return std::vector({"Invalid"}); return ExecuteLog(cmd, login_stack); } } From c5a17dd70cd0ef75dda4a53ccb3af9e0579a80ce Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:33:55 +0000 Subject: [PATCH 02/12] add check for report and log --- backend/src/engine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 7cc9008..97116b0 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -99,11 +99,11 @@ std::vector BookStoreEngineClass::Execute( return ExecuteBuy(cmd, login_stack); } case OperationType::__Kreport: { - return std::vector({"Invalid"}); + // return std::vector({"Invalid"}); return ExecuteReport(cmd, login_stack); } case OperationType::__Klog: { - return std::vector({"Invalid"}); + // return std::vector({"Invalid"}); return ExecuteLog(cmd, login_stack); } } From 7fcaaa534e892e23d8b3901b880e3583b0df0dbb Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:34:49 +0000 Subject: [PATCH 03/12] 111 --- backend/src/engine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 97116b0..2c803ff 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -315,7 +315,7 @@ std::vector BookStoreEngineClass::ExecuteMOdify( return std::vector({"Invalid"}); // debugPrint("successfully lexed modify"); // debugPrint("modify", new_ISBN, ' ', name, ' ', author, ' ', keyword, ' ', - // price); + // price); if (login_stack.empty() || user_data_base.GetPrevilege(login_stack.top().first) < 3) return std::vector({"Invalid"}); @@ -394,11 +394,19 @@ std::vector BookStoreEngineClass::ExecuteShowFinance( std::vector BookStoreEngineClass::ExecuteLog( const std::string &cmd, std::stack> &login_stack) { + static std::basic_regex log_regex( + R"(^ *log *$)", std::regex_constants::optimize); + if(!std::regex_match(cmd, log_regex)) + return std::vector({"Invalid"}); return std::vector(); } std::vector BookStoreEngineClass::ExecuteReport( const std::string &cmd, std::stack> &login_stack) { + static std::basic_regex report_regex( + R"(^ *report( +finance| +employee) *$)", std::regex_constants::optimize); + if (!std::regex_match(cmd, report_regex)) + return std::vector({"Invalid"}); return std::vector(); } \ No newline at end of file From 8f5279dd9fc420ab55592f9a952daaccb5a5f17e Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:40:48 +0000 Subject: [PATCH 04/12] =?UTF-8?q?=E7=BB=99exit=E5=92=8Cquit=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 2c803ff..1745531 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -46,6 +46,10 @@ std::vector BookStoreEngineClass::Execute( std::string head = ""; ss >> head; if (head == "quit" || head == "exit") { + static std::basic_regex quit_regex(R"(^ *(quit|exit) *$)", + std::regex_constants::optimize); + if (!std::regex_match(cmd, quit_regex)) + return std::vector({"Invalid"}); while (login_stack.size()) { login_count[login_stack.top().first]--; login_stack.pop(); @@ -394,9 +398,9 @@ std::vector BookStoreEngineClass::ExecuteShowFinance( std::vector BookStoreEngineClass::ExecuteLog( const std::string &cmd, std::stack> &login_stack) { - static std::basic_regex log_regex( - R"(^ *log *$)", std::regex_constants::optimize); - if(!std::regex_match(cmd, log_regex)) + static std::basic_regex log_regex(R"(^ *log *$)", + std::regex_constants::optimize); + if (!std::regex_match(cmd, log_regex)) return std::vector({"Invalid"}); return std::vector(); } From 62c71115378250927d627ab7142051603dcc71e1 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:45:12 +0000 Subject: [PATCH 05/12] =?UTF-8?q?=E6=89=A9=E5=A4=A7=E4=BA=86=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E5=AD=97=E6=AE=B5=E7=9A=84=E5=A4=A7=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/include/bs-utility.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/include/bs-utility.h b/backend/include/bs-utility.h index f093bd4..6acecca 100644 --- a/backend/include/bs-utility.h +++ b/backend/include/bs-utility.h @@ -116,13 +116,13 @@ void Respond(BlockingStringStream *output_ptr, std::string SessionToken, class UserItemClass { public: - char user_id[31], password[31], user_name[31]; + char user_id[35], password[35], user_name[35]; unsigned char privilege; }; class BookItemClass { public: - char ISBN[21], name[61], author[61], keyword[61]; + char ISBN[25], name[65], author[65], keyword[65]; double price; int quantity_remain; int bid; From 21793ba0e63fe69b8dab574b8760370e4542d292 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 06:50:38 +0000 Subject: [PATCH 06/12] =?UTF-8?q?=E7=BB=99passwd=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 1745531..2519fcf 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -171,7 +171,10 @@ std::vector BookStoreEngineClass::ExecutePasswd( if (!CommandPasswdLexer(cmd, user_id, current_password, new_password)) return std::vector({"Invalid"}); // debugPrint("sucessfully lexed passwd"); - if (user_data_base.GetPrevilege(user_id) < 1) + if (user_data_base.GetPrevilege(user_id) == -1) + return std::vector({"Invalid"}); + if (login_stack.empty() || + user_data_base.GetPrevilege(login_stack.top().first) < 1) return std::vector({"Invalid"}); // debugPrint("begin checing authority"); if (login_stack.size() > 0 && From f0f524dde17e93ca0c9c6e3a02cafe89b5638d8e Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 07:18:41 +0000 Subject: [PATCH 07/12] =?UTF-8?q?=E7=BB=99show=E6=B7=BB=E5=8A=A0=E4=BA=86?= =?UTF-8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/lexer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index cab8ca1..8980500 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -212,7 +212,7 @@ bool CommandShowLexer(const std::string &command, std::string &ISBN, std::string &name, std::string &author, std::string &keyword) { static std::basic_regex main_pattern( - R"(^ *show(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\")* *$)", + R"(^ *show(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\")? *$)", std::regex_constants::optimize); bool has_ISBN = false; From 583db1f1274a9c0c46ecbf9009cdde109312ecb0 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 07:25:58 +0000 Subject: [PATCH 08/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=85=E8=BF=87?= =?UTF-8?q?=E4=B8=A4=E4=BD=8D=E5=B0=8F=E6=95=B0=E7=9A=84=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/lexer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index 8980500..3950bc7 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -337,7 +337,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, std::string &name, std::string &author, std::string &keyword, double &price) { static std::basic_regex main_pattern( - R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}(?:\.[0-9]{1,2})?)+ *$)", + R"(^ *modify(?: +-ISBN=(?:\S{1,20})| +-name=\"(?:[^\s"]{1,60})\"| +-author=\"(?:[^\s"]{1,60})\"| +-keyword=\"(?:[^\s"]{1,60})\"| +-price=[0-9]{1,10}(?:\.[0-9]+)?)+ *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command); @@ -385,7 +385,7 @@ bool CommandModifyLexer(const std::string &command, std::string &ISBN, bool CommandImportLexer(const std::string &command, int &quantity, double &total_cost) { static std::basic_regex main_pattern( - R"(^ *import +[0-9]{1,10} +[0-9]{1,10}(?:\.[0-9]{1,2})? *$)", + R"(^ *import +[0-9]{1,10} +[0-9]{1,10}(?:\.[0-9]+)? *$)", std::regex_constants::optimize); if (std::regex_match(command, main_pattern)) { std::stringstream ss(command); From ad94c130c0582f1533af1620ce798011f1a19ec6 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 07:31:34 +0000 Subject: [PATCH 09/12] =?UTF-8?q?=E4=B8=8D=E5=86=8D=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9D=83=E9=99=90=E4=B8=BA0=E7=9A=84?= =?UTF-8?q?=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/lexer.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/lexer.cpp b/backend/src/lexer.cpp index 3950bc7..ce7021c 100644 --- a/backend/src/lexer.cpp +++ b/backend/src/lexer.cpp @@ -157,8 +157,7 @@ bool CommandUseraddLexer(const std::string &command, std::string &user_id, ss >> password; ss >> privilege; ss >> username; - if (privilege != 0 && privilege != 1 && privilege != 3 && privilege != 7) - return false; + if (privilege != 1 && privilege != 3 && privilege != 7) return false; return true; } else return false; From 2ef45c09ca014827841e1313a692c1d4b83fdd86 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 07:44:22 +0000 Subject: [PATCH 10/12] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=AB=98=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=85=8D=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 2519fcf..8512d0c 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -122,11 +122,12 @@ std::vector BookStoreEngineClass::ExecuteSu( if (!CommandSuLexer(cmd, user_id, password)) return std::vector({"Invalid"}); // debugPrint("su", user_id, " ", password); + if (user_data_base.GetPrevilege(user_id) == -1) + return std::vector({"Invalid"}); if (login_stack.size() > 0 && - user_data_base.GetPrevilege(login_stack.top().first) == 7) { + user_data_base.GetPrevilege(login_stack.top().first) > + user_data_base.GetPrevilege(user_id)) { // debugPrint("has root previlege"); - if (user_data_base.GetPrevilege(user_id) == -1) - return std::vector({"Invalid"}); login_stack.push(std::make_pair(user_id, 0)); login_count[user_id]++; return std::vector(); From 91e1161a58b18ebdc9584818013e83a67ab2e5b4 Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 07:46:48 +0000 Subject: [PATCH 11/12] =?UTF-8?q?=E9=AB=98=E6=9D=83=E9=99=90=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E9=94=99=E8=AF=AF=E4=B8=8D=E8=B1=81=E5=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 8512d0c..414afb2 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -127,6 +127,8 @@ std::vector BookStoreEngineClass::ExecuteSu( if (login_stack.size() > 0 && user_data_base.GetPrevilege(login_stack.top().first) > user_data_base.GetPrevilege(user_id)) { + if (password != "" && !user_data_base.PAM(user_id, password)) + return std::vector({"Invalid"}); // debugPrint("has root previlege"); login_stack.push(std::make_pair(user_id, 0)); login_count[user_id]++; From ae8240839c54de4bc91177d72ef1f7b57cb6ab2e Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Thu, 14 Dec 2023 08:08:10 +0000 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E9=87=8D=E5=A4=8D=E6=B3=A8=E5=86=8C=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/engine.cpp b/backend/src/engine.cpp index 414afb2..e4152d3 100644 --- a/backend/src/engine.cpp +++ b/backend/src/engine.cpp @@ -161,7 +161,7 @@ std::vector BookStoreEngineClass::ExecuteRegister( std::string user_id, password, user_name; if (!CommandRegisterLexer(cmd, user_id, password, user_name)) return std::vector({"Invalid"}); - if (user_data_base.GetPrevilege(cmd) != -1) + if (user_data_base.GetPrevilege(user_id) != -1) return std::vector({"Invalid"}); user_data_base.AddUser(user_id, password, user_name, 1); return std::vector();