X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/f7163d9c994af13f0f72f49f7203b7ac3e281a1e..19684ed5aca4366468f3d9cac0848edd46a1d1cf:/projects/stargazer/plugins/store/files/file_store.cpp diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 1a16ed91..334824d9 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -77,15 +77,25 @@ return fsc.GetPlugin(); //----------------------------------------------------------------------------- FILES_STORE_SETTINGS::FILES_STORE_SETTINGS() : settings(NULL), + errorStr(), + workDir(), + usersDir(), + adminsDir(), + tariffsDir(), + statMode(0), + statUID(0), + statGID(0), + confMode(0), + confUID(0), + confGID(0), + userLogMode(0), + userLogUID(0), + userLogGID(0), removeBak(true), readBak(true) { } //----------------------------------------------------------------------------- -FILES_STORE_SETTINGS::~FILES_STORE_SETTINGS() -{ -} -//----------------------------------------------------------------------------- int FILES_STORE_SETTINGS::ParseOwner(const vector & moduleParams, const string & owner, uid_t * uid) { PARAM_VALUE pv; @@ -306,31 +316,6 @@ c = str[2] - '0'; return 0; } //----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetWorkDir() const -{ -return workDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetUsersDir() const -{ -return usersDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetAdminsDir() const -{ -return adminsDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetTariffsDir() const -{ -return tariffsDir; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetStatMode() const -{ -return statMode; -} -//----------------------------------------------------------------------------- mode_t FILES_STORE_SETTINGS::GetStatModeDir() const { mode_t mode = statMode; @@ -340,21 +325,6 @@ if (statMode & S_IROTH) mode |= S_IXOTH; return mode; } //----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetStatUID() const -{ -return statUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetStatGID() const -{ -return statGID; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetConfMode() const -{ -return confMode; -} -//----------------------------------------------------------------------------- mode_t FILES_STORE_SETTINGS::GetConfModeDir() const { mode_t mode = confMode; @@ -364,63 +334,22 @@ if (confMode & S_IROTH) mode |= S_IXOTH; return mode; } //----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetConfUID() const -{ -return confUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetConfGID() const -{ -return confGID; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetLogMode() const -{ -return userLogMode; -} -//----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetLogUID() const -{ -return userLogUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetLogGID() const -{ -return userLogGID; -} -//----------------------------------------------------------------------------- -bool FILES_STORE_SETTINGS::GetRemoveBak() const -{ -return removeBak; -} -//----------------------------------------------------------------------------- -bool FILES_STORE_SETTINGS::GetReadBak() const -{ -return readBak; -} -//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- FILES_STORE::FILES_STORE() + : errorStr(), + version("file_store v.1.04"), + storeSettings(), + settings(), + mutex(), + logger(GetPluginLogger(GetStgLogger(), "store_files")) { -version = "file_store v.1.04"; - pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mutex, &attr); }; //----------------------------------------------------------------------------- -FILES_STORE::~FILES_STORE() -{ - -}; -//----------------------------------------------------------------------------- -void FILES_STORE::SetSettings(const MODULE_SETTINGS & s) -{ -settings = s; -} -//----------------------------------------------------------------------------- int FILES_STORE::ParseSettings() { int ret = storeSettings.ParseSettings(settings); @@ -432,17 +361,6 @@ if (ret) return ret; } //----------------------------------------------------------------------------- -const string & FILES_STORE::GetStrError() const -{ -STG_LOCKER lock(&mutex, __FILE__, __LINE__); -return errorStr; -} -//----------------------------------------------------------------------------- -const string & FILES_STORE::GetVersion() const -{ -return version; -} -//----------------------------------------------------------------------------- int FILES_STORE::GetUsersList(vector * userList) const { vector files; @@ -532,6 +450,7 @@ while ((entry = readdir(d))) errorStr += strerror(errno); errorStr += "'"; printfd(__FILE__, "FILES_STORE::RemoveDir() - unlink failed. Message: '%s'\n", strerror(errno)); + closedir(d); return -1; } } @@ -540,6 +459,7 @@ while ((entry = readdir(d))) { if (RemoveDir(str.c_str())) { + closedir(d); return -1; } @@ -583,27 +503,6 @@ if (Touch(fileName)) printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } -/*f = fopen(fileName.c_str(), "wt"); -if (f) - { - if (fprintf(f, "\n") < 0) - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "fprintf failed. Message: '"; - errorStr += strerror(errno); - errorStr += "'"; - printfd(__FILE__, "FILES_STORE::AddUser - fprintf failed. Message: '%s'\n", strerror(errno)); - return -1; - } - fclose(f); - } -else - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Cannot create file \"" + fileName + "\'"; - printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); - return -1; - }*/ strprintf(&fileName, "%s%s/stat", storeSettings.GetUsersDir().c_str(), login.c_str()); if (Touch(fileName)) @@ -613,27 +512,6 @@ if (Touch(fileName)) printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } -/*f = fopen(fileName.c_str(), "wt"); -if (f) - { - if (fprintf(f, "\n") < 0) - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "fprintf failed. Message: '"; - errorStr += strerror(errno); - errorStr += "'"; - printfd(__FILE__, "FILES_STORE::AddUser - fprintf failed. Message: '%s'\n", strerror(errno)); - return -1; - } - fclose(f); - } -else - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Cannot create file \"" + fileName + "\'"; - printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); - return -1; - }*/ return 0; } //----------------------------------------------------------------------------- @@ -1179,10 +1057,10 @@ if (s2.Error()) for (size_t i = 0; i < DIR_NUM; i++) { char dirName[3]; - snprintf(dirName, 3, "U%d", i); + snprintf(dirName, 3, "U%llu", (unsigned long long)i); s.WriteInt(dirName, stat.up[i]); // Classic s2.WriteInt(dirName, stat.up[i]); // New - snprintf(dirName, 3, "D%d", i); + snprintf(dirName, 3, "D%llu", (unsigned long long)i); s.WriteInt(dirName, stat.down[i]); // Classic s2.WriteInt(dirName, stat.down[i]); // New } @@ -1280,6 +1158,8 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login cf.WriteInt("UsrAddDel", ac.priv.userAddDel); cf.WriteInt("ChgTariff", ac.priv.tariffChg); cf.WriteInt("ChgAdmin", ac.priv.adminChg); + cf.WriteInt("ChgService", ac.priv.serviceChg); + cf.WriteInt("ChgCorp", ac.priv.corpChg); } return 0; @@ -1407,6 +1287,16 @@ else return -1; } +if (cf.ReadInt("ChgService", &a, 0) == 0) + ac->priv.serviceChg = a; +else + ac->priv.serviceChg = 0; + +if (cf.ReadInt("ChgCorp", &a, 0) == 0) + ac->priv.corpChg = a; +else + ac->priv.corpChg = 0; + return 0; } //----------------------------------------------------------------------------- @@ -1864,10 +1754,6 @@ return 0; //----------------------------------------------------------------------------- int FILES_STORE::AddMessage(STG_MSG * msg, const string & login) const { -//ðÒÏ×ÅÒÉÔØ ÅÓÔØ ÌÉ ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÓÏÏÂÝÅÎÉÊ. åÓÌÉ ÎÅÔ - ÓÏÚÄÁÔØ. -//úÁÔÅÍ ÐÏÌÏÖÉÔØ ÓÏÏÂÝÅÎÉÅ Ó ÉÍÅÎÅÍ ÆÁÊÌÁ - ×ÒÅÍÅÎÎOÊ ÍÅÔËÏÊ. úÁÐÉÓÁÔØ ÔÕÄÁ -//ÔÅËÓÔ É ÐÒÉÏÒÉÔÅÔ. - string fn; string dn; struct timeval tv; @@ -1908,10 +1794,6 @@ return EditMessage(*msg, login); //----------------------------------------------------------------------------- int FILES_STORE::EditMessage(const STG_MSG & msg, const string & login) const { -//ðÒÏ×ÅÒÉÔØ ÅÓÌÔØ ÌÉ ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÓÏÏÂÝÅÎÉÊ. åÓÌÉ ÎÅÔ - ÓÏÚÄÁÔØ. -//úÁÔÅÍ ÐÏÌÏÖÉÔØ ÓÏÏÂÝÅÎÉÅ Ó ÉÍÅÎÅÍ ÆÁÊÌÁ - ×ÒÅÍÅÎÎOÊ ÍÅÔËÏÊ. úÁÐÉÓÁÔØ ÔÕÄÁ -//ÔÅËÓÔ É ÐÒÉÏÒÉÔÅÔ. - string fileName; FILE * msgFile; @@ -1993,8 +1875,6 @@ int FILES_STORE::GetMessageHdrs(vector * hdrsList, const string & l { string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); -//hdrsList->resize(messages.size()); - if (access(dn.c_str(), F_OK) != 0) { return 0; @@ -2146,8 +2026,6 @@ return -1; //----------------------------------------------------------------------------- int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext) { -// æÕÎËÃÉÑ ÐÒÏÓÍÁÔÒÉ×ÁÅÔ ÓÏÄÅÒÖÉÍÏÅ ÄÉÒÅËÔÏÒÉÉ - DIR * d = opendir(directory.c_str()); if (!d)