diff options
author | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-09-04 19:56:54 +0000 |
---|---|---|
committer | Gerald Begumisa <ben_g@users.sourceforge.net> | 2007-09-04 19:56:54 +0000 |
commit | 13d24d7f97fe6e739c47388279c63b961a7b8bc3 (patch) | |
tree | fe88e699741858ae0459d5b43e1c7b2422cd7dc0 /orkbasecxx/Utils.cpp | |
parent | 01240e01f8e4e63cbbdfebfb8b566e61e454cc7a (diff) |
Ownership and permissions for MCF files now set at creation time, ownership and permissions code moved to Utils.cpp/h
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@479 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/Utils.cpp')
-rw-r--r-- | orkbasecxx/Utils.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/orkbasecxx/Utils.cpp b/orkbasecxx/Utils.cpp index d1139ba..fa670e4 100644 --- a/orkbasecxx/Utils.cpp +++ b/orkbasecxx/Utils.cpp @@ -3,6 +3,11 @@ #include "ace/OS_NS_arpa_inet.h" #include "ace/OS_NS_sys_stat.h" +#ifndef WIN32 +#include <pwd.h> +#include <grp.h> +#endif + //======================================================== // file related stuff @@ -85,6 +90,55 @@ void FileRecursiveMkdir(CStdString& path) } } +int FileSetPermissions(CStdString filename, int permissions) +{ + int res = 0; + +#ifndef WIN32 + res = chmod(filename.c_str(), permissions); +#endif + + return res; +} + +int FileSetOwnership(CStdString filename, CStdString owner, CStdString group) +{ + int res = 0; + +#ifndef WIN32 + struct group fileGroup, *fgP = NULL; + struct passwd fileUser, *fuP = NULL; + char infoGroupBuf[4096], infoUserBuf[4096]; + + memset(infoGroupBuf, 0, sizeof(infoGroupBuf)); + memset(infoUserBuf, 0, sizeof(infoUserBuf)); + memset(&fileGroup, 0, sizeof(fileGroup)); + memset(&fileUser, 0, sizeof(fileUser)); + + if(!getgrnam_r(group.c_str(), &fileGroup, infoGroupBuf, sizeof(infoGroupBuf), &fgP)) + { + if(!getpwnam_r(owner.c_str(), &fileUser, infoUserBuf, sizeof(infoUserBuf), &fuP)) + { + if(chown(filename.c_str(), fileUser.pw_uid, fileGroup.gr_gid)) + { + res = -1; + } + } + else + { + res = -1; + } + } + else + { + res = -1; + } +#endif + + return res; +} + + //===================================================== // Network related stuff |