From: Maxim Mamontov Date: Sun, 18 Nov 2012 18:02:47 +0000 (+0200) Subject: Fixed admin provoledges reseting after password change. Fixes #28. X-Git-Tag: 2.409~401 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/0fc9896e27b94093ccde0b8566e2b8109ae8f657 Fixed admin provoledges reseting after password change. Fixes #28. --- diff --git a/projects/stargazer/admins_impl.cpp b/projects/stargazer/admins_impl.cpp index cef8682d..7d73dde1 100644 --- a/projects/stargazer/admins_impl.cpp +++ b/projects/stargazer/admins_impl.cpp @@ -219,7 +219,7 @@ assert(admin != NULL && "Pointer to admin is not null"); STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (data.empty()) { - printfd(__FILE__, "no admin in system!\n"); + printfd(__FILE__, "No admin in system!\n"); *admin = &noAdmin; return false; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp index a87c1dbf..5bc68d2a 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp @@ -212,49 +212,44 @@ void PARSER_CHG_ADMIN::CreateAnswer() { answerList->erase(answerList->begin(), answerList->end()); -ADMIN_CONF conf; -conf.login = login; + if (!login.res_empty()) { - string s; - //if (admins->FindAdmin(login.data()) != NULL) - // { - if (!password.res_empty()) - conf.password = password.data(); + ADMIN * origAdmin = NULL; - if (!privAsString.res_empty()) - { - int p = 0; - if (str2x(privAsString.data().c_str(), p) < 0) - { - strprintf(&s, "" ); - answerList->push_back(s); - return; - } - //memcpy(&conf.priv, &p, sizeof(conf.priv)); - conf.priv.userStat = (p & 0x0003) >> 0x00; // 1+2 - conf.priv.userConf = (p & 0x000C) >> 0x02; // 4+8 - conf.priv.userCash = (p & 0x0030) >> 0x04; // 10+20 - conf.priv.userPasswd = (p & 0x00C0) >> 0x06; // 40+80 - conf.priv.userAddDel = (p & 0x0300) >> 0x08; // 100+200 - conf.priv.adminChg = (p & 0x0C00) >> 0x0A; // 400+800 - conf.priv.tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 - } + if (admins->Find(login, &origAdmin)) + { + answerList->push_back(std::string(""); + return; + } - if (admins->Change(conf, currAdmin) != 0) - { - strprintf(&s, "", admins->GetStrError().c_str()); - answerList->push_back(s); - } - else + ADMIN_CONF conf(origAdmin->GetConf()); + + if (!password.res_empty()) + conf.password = password.data(); + + if (!privAsString.res_empty()) + { + int p = 0; + if (str2x(privAsString.data().c_str(), p) < 0) { - answerList->push_back(""); + answerList->push_back(""); + return; } - return; - // } - //strprintf(&s, "", admins->GetStrError().c_str()); - //answerList->push_back(s); - //return; + + conf.priv.FromInt(p); + } + + if (admins->Change(conf, currAdmin) != 0) + { + string s; + strprintf(&s, "", admins->GetStrError().c_str()); + answerList->push_back(s); + } + else + { + answerList->push_back(""); + } } else {