fix: fix su's lexer

This commit is contained in:
2023-12-14 04:18:29 +00:00
parent 4cfbbc2991
commit 2628177746
2 changed files with 3 additions and 1 deletions

View File

@ -115,8 +115,10 @@ std::vector<std::string> BookStoreEngineClass::ExecuteSu(
std::string user_id, password; std::string user_id, password;
if (!CommandSuLexer(cmd, user_id, password)) if (!CommandSuLexer(cmd, user_id, password))
return std::vector<std::string>({"Invalid"}); return std::vector<std::string>({"Invalid"});
// debugPrint("su", user_id, " ", password);
if (login_stack.size() > 0 && if (login_stack.size() > 0 &&
user_data_base.GetPrevilege(login_stack.top().first) == 7) { user_data_base.GetPrevilege(login_stack.top().first) == 7) {
// debugPrint("has root previlege");
if (user_data_base.GetPrevilege(user_id) == -1) if (user_data_base.GetPrevilege(user_id) == -1)
return std::vector<std::string>({"Invalid"}); return std::vector<std::string>({"Invalid"});
login_stack.push(std::make_pair(user_id, "")); login_stack.push(std::make_pair(user_id, ""));

View File

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