From: František Dvořák Date: Sat, 19 Oct 2013 19:17:26 +0000 (+0200) Subject: Let authorization plugin working but only silently suffer (with LOG_NOTICE), when... X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=6f4acc6f638982932b30fb19d3bbfc3b7d93d89d;p=dmlite-plugins-vfs.git Let authorization plugin working but only silently suffer (with LOG_NOTICE), when data files can't be created. Try to save them again on destroy. --- diff --git a/src/VfsAuthn.cpp b/src/VfsAuthn.cpp index a9e37c2..0bb916b 100644 --- a/src/VfsAuthn.cpp +++ b/src/VfsAuthn.cpp @@ -24,6 +24,8 @@ VfsAuthn::VfsAuthn(const std::string& prefix) throw (DmException) this->nextGid_ = VFS_GID_START; this->noSync_ = false; + this->dirtyUsers_ = false; + this->dirtyGroups_ = false; vfsReload(); } @@ -32,6 +34,8 @@ VfsAuthn::VfsAuthn(const std::string& prefix) throw (DmException) VfsAuthn::~VfsAuthn() { + if (dirtyUsers_) vfsSaveUsers(); + if (dirtyGroups_) vfsSaveGroups(); } @@ -77,7 +81,7 @@ void VfsAuthn::getIdMap(const std::string &userName, const std::vectornoSync_ = false; - if (ngroups != this->groups_.size()) + if (ngroups != this->groups_.size() || this->dirtyGroups_) vfsSaveGroups(); } @@ -98,6 +102,7 @@ void VfsAuthn::vfsNewGroup(const std::string& groupName) throw (DmException) { this->groups_.push_back(gi); this->gids_.insert(gid); this->nextGid_ = gid + 1; + this->dirtyGroups_ = true; debug("new group '%s', gid %d", groupName.c_str(), gid); } @@ -119,6 +124,7 @@ void VfsAuthn::vfsNewUser(const std::string& userName) throw (DmException) { this->users_.push_back(ui); this->uids_.insert(uid); this->nextUid_ = uid + 1; + this->dirtyUsers_ = true; debug("new user '%s', uid %d", userName.c_str(), uid); } @@ -217,6 +223,7 @@ void VfsAuthn::deleteGroup(const std::string& groupName) throw (DmException) this->groups_.erase(this->groups_.begin() + i); this->gids_.erase(gid); //not needed immediately: if (this->nextGid_ > gid) this->nextGid_ = gid; + this->dirtyGroups_ = true; vfsSaveGroups(); } @@ -314,6 +321,7 @@ void VfsAuthn::deleteUser(const std::string& userName) throw (DmException) this->users_.erase(this->users_.begin() + i); this->uids_.erase(uid); //not needed immediately: if (this->nextUid_ > uid) this->nextUid_ = uid; + this->dirtyUsers_ = true; vfsSaveUsers(); } @@ -391,14 +399,20 @@ void VfsAuthn::vfsSaveUsers() throw (DmException) { std::ofstream f; std::string newName, name; - if (this->noSync_) return; + if (this->noSync_) { + this->dirtyUsers_ = true; + return; + } name = this->prefix_ + VFS_USERS_FILE; newName = this->prefix_ + ".new" + VFS_USERS_FILE; f.open(newName.c_str()); - if (!f) - vfsThrow(EIO, "could not create new version of users file"); + if (!f) { + log(LOG_NOTICE, "could not create new version of users file in '%s'", this->prefix_.c_str()); + this->dirtyUsers_ = true; + return; + } for (size_t i = 0; i < this->users_.size(); i++) { f << this->users_[i].getUnsigned("uid") << "\t"; @@ -408,6 +422,8 @@ void VfsAuthn::vfsSaveUsers() throw (DmException) { f.close(); wrapCall(rename(newName.c_str(), name.c_str()), "could not save users file"); + + this->dirtyUsers_ = false; } @@ -416,14 +432,20 @@ void VfsAuthn::vfsSaveGroups() throw (DmException) { std::ofstream f; std::string newName, name; - if (this->noSync_) return; + if (this->noSync_) { + this->dirtyGroups_ = true; + return; + } name = this->prefix_ + VFS_GROUPS_FILE; newName = this->prefix_ + ".new" + VFS_GROUPS_FILE; f.open(newName.c_str()); - if (!f) - vfsThrow(EIO, "could not create new version of groups file"); + if (!f) { + log(LOG_NOTICE, "could not create new version of groups file in '%s'", this->prefix_.c_str()); + this->dirtyGroups_ = true; + return; + } for (size_t i = 0; i < this->groups_.size(); i++) { f << this->groups_[i].getUnsigned("gid") << "\t"; @@ -433,4 +455,6 @@ void VfsAuthn::vfsSaveGroups() throw (DmException) { f.close(); wrapCall(rename(newName.c_str(), name.c_str()), "could not save groups file"); + + this->dirtyGroups_ = false; } diff --git a/src/VfsAuthn.h b/src/VfsAuthn.h index 396b519..8e7cf24 100644 --- a/src/VfsAuthn.h +++ b/src/VfsAuthn.h @@ -47,6 +47,7 @@ namespace dmlite { std::set uids_, gids_; /// helper sets with UID/GID unsigned int nextUid_, nextGid_; /// next UID/GID after the one last inserted bool noSync_; /// saving users/groups disabled + bool dirtyUsers_, dirtyGroups_; /// data which need to be saved }; };