fix: bug in passwd's lexer

This commit is contained in:
2023-12-13 10:31:13 +00:00
parent e620762102
commit 702f8072dc
2 changed files with 5 additions and 2 deletions

View File

@ -17,7 +17,8 @@ BookStoreEngineClass::BookStoreEngineClass(std::string __config_dir,
if (user_data_base.GetPrevilege("root") == -1) {
// debugPrint("Creating root user");
user_data_base.AddUser("root", "sjtu", "root", 7);
// debugPrint("Now root's previlege is", user_data_base.GetPrevilege("root"));
// debugPrint("Now root's previlege is",
// user_data_base.GetPrevilege("root"));
}
}
std::vector<std::string> BookStoreEngineClass::Execute(
@ -150,8 +151,10 @@ std::vector<std::string> BookStoreEngineClass::ExecutePasswd(
std::string user_id, current_password, new_password;
if (!CommandPasswdLexer(cmd, user_id, current_password, new_password))
return std::vector<std::string>({"Invalid"});
// debugPrint("sucessfully lexed passwd");
if (user_data_base.GetPrevilege(user_id) == -1)
return std::vector<std::string>({"Invalid"});
// debugPrint("begin checing authority");
if (login_stack.size() > 0 &&
user_data_base.GetPrevilege(login_stack.top().first) == 7) {
user_data_base.ChangePassword(user_id, new_password);

View File

@ -102,7 +102,7 @@ bool CommandRegisterLexer(const std::string &command, std::string &user_id,
bool CommandPasswdLexer(const std::string &command, std::string &user_id,
std::string &old_password, std::string &new_password) {
static std::basic_regex main_pattern(
R"(^ *passwd +(?:[0-9a-zA-Z_]{1,30}) +(?:[0-9a-zA-Z_]{1,30})? +(?:[0-9a-zA-Z_]{1,30}) *$)",
R"(^ *passwd +(?:[0-9a-zA-Z_]{1,30})(?: +(?:[0-9a-zA-Z_]{1,30}))? +(?:[0-9a-zA-Z_]{1,30}) *$)",
std::regex_constants::optimize);
if (std::regex_match(command, main_pattern)) {
std::stringstream ss(command);