fixed: winix incorrectly used config options: upload_dirs_chmod and upload_files_chmod
added: to config: upload_group a group name for newly uploaded files (and created necessary directories in the file system) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@961 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <grp.h>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include "misc.h"
|
||||
@@ -780,7 +781,10 @@ bool IsFile(const std::wstring & file)
|
||||
}
|
||||
|
||||
|
||||
bool CreateDir(const wchar_t * dir, int priv)
|
||||
/*
|
||||
* group can be -1 (it is not used then)
|
||||
*/
|
||||
bool CreateDir(const wchar_t * dir, int priv, int group)
|
||||
{
|
||||
static std::string adir;
|
||||
|
||||
@@ -788,27 +792,29 @@ static std::string adir;
|
||||
{
|
||||
PT::WideToUTF8(dir, adir);
|
||||
|
||||
if( mkdir(adir.c_str(), priv) < 0 )
|
||||
if( mkdir(adir.c_str(), 0777) < 0 )
|
||||
{
|
||||
log << log1 << "Can't create a directory on fs: " << adir << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return SetPriv(adir, priv, group);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CreateDir(const std::wstring & dir, int priv)
|
||||
bool CreateDir(const std::wstring & dir, int priv, int group)
|
||||
{
|
||||
return CreateDir(dir.c_str(), priv);
|
||||
return CreateDir(dir.c_str(), priv, group);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// creating directories (can be more than one)
|
||||
// 'dirs' can begin with a slash (will be skipped)
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, bool skip_last)
|
||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv, int group, bool skip_last)
|
||||
{
|
||||
static std::wstring temp;
|
||||
const wchar_t * p = dirs;
|
||||
@@ -834,7 +840,7 @@ const wchar_t * p = dirs;
|
||||
temp += *p;
|
||||
|
||||
if( !skip_last || *p!=0 )
|
||||
if( !CreateDir(temp.c_str(), priv) )
|
||||
if( !CreateDir(temp.c_str(), priv, group) )
|
||||
return false;
|
||||
|
||||
temp += '/';
|
||||
@@ -845,9 +851,72 @@ return true;
|
||||
|
||||
|
||||
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, bool skip_last)
|
||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv, int group, bool skip_last)
|
||||
{
|
||||
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, skip_last);
|
||||
return CreateDirs(base_dir.c_str(), dirs.c_str(), priv, group, skip_last);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int GetGroupId(const char * name)
|
||||
{
|
||||
struct group gr;
|
||||
struct group * result;
|
||||
char buffer[512];
|
||||
|
||||
if( getgrnam_r(name, &gr, buffer, sizeof(buffer)/sizeof(char), &result) != 0 )
|
||||
{
|
||||
log << log1 << "I cannot get the group_id for group name: " << name << logend;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* there is no such a group in /etc/group
|
||||
*/
|
||||
if( result == 0 )
|
||||
{
|
||||
log << log1 << "There is no a group with name: " << name << logend;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return gr.gr_gid;
|
||||
}
|
||||
|
||||
|
||||
int GetGroupId(const std::string & name)
|
||||
{
|
||||
return GetGroupId(name.c_str());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* setting priveleges and a group id on a file or on a directory
|
||||
* group can be -1 (it is not used then)
|
||||
*/
|
||||
bool SetPriv(const char * name, int priv, int group)
|
||||
{
|
||||
if( chmod(name, priv) < 0 )
|
||||
{
|
||||
log << log1 << "Can't set proper fs privileges on: " << name << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( group != -1 )
|
||||
{
|
||||
if( chown(name, geteuid(), group) < 0 )
|
||||
{
|
||||
log << log1 << "Can't set proper fs group on: " << name << logend;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetPriv(const std::string & name, int priv, int group)
|
||||
{
|
||||
return SetPriv(name.c_str(), priv, group);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user