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:
parent
f064ff6b3d
commit
e3284dcfbc
File diff suppressed because one or more lines are too long
|
@ -132,6 +132,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||||
NoLastSlash(upload_dir);
|
NoLastSlash(upload_dir);
|
||||||
NoLastSlash(common_dir);
|
NoLastSlash(common_dir);
|
||||||
|
|
||||||
|
upload_group = AText(L"upload_group");
|
||||||
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750);
|
||||||
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
upload_files_chmod = Int(L"upload_files_chmod", 0640);
|
||||||
ListText(L"static_dirs", static_dirs);
|
ListText(L"static_dirs", static_dirs);
|
||||||
|
@ -239,7 +240,7 @@ void Config::AssignValues(bool stdout_is_closed)
|
||||||
pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30);
|
pattern_cacher_how_many_delete = Size(L"pattern_cacher_how_many_delete", 30);
|
||||||
|
|
||||||
content_type_header = Int(L"content_type_header", 0);
|
content_type_header = Int(L"content_type_header", 0);
|
||||||
umask = Int(L"umask", 0222);
|
umask = Int(L"umask", 0222);
|
||||||
|
|
||||||
ezc_max_elements = Size(L"ezc_max_elements", 50000);
|
ezc_max_elements = Size(L"ezc_max_elements", 50000);
|
||||||
ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000);
|
ezc_max_loop_elements = Size(L"ezc_max_loop_elements", 5000);
|
||||||
|
@ -294,6 +295,8 @@ void Config::SetAdditionalVariables()
|
||||||
|
|
||||||
if( locale_files.empty() )
|
if( locale_files.empty() )
|
||||||
locale_files.push_back(L"en");
|
locale_files.push_back(L"en");
|
||||||
|
|
||||||
|
upload_group_int = GetGroupId(upload_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -268,6 +268,14 @@ public:
|
||||||
// default: empty
|
// default: empty
|
||||||
std::wstring common_dir;
|
std::wstring common_dir;
|
||||||
|
|
||||||
|
// system group's name for new uploaded files (created directories in the file system)
|
||||||
|
// it can be empty (it is not used then)
|
||||||
|
std::string upload_group;
|
||||||
|
|
||||||
|
// this value will be set based on upload_group
|
||||||
|
// will be -1 if upload_group is empty or if it is invalid
|
||||||
|
int upload_group_int;
|
||||||
|
|
||||||
// chmod of newly created directories (under upload_dir)
|
// chmod of newly created directories (under upload_dir)
|
||||||
// default: 0750
|
// default: 0750
|
||||||
int upload_dirs_chmod;
|
int upload_dirs_chmod;
|
||||||
|
|
|
@ -514,10 +514,16 @@ void Image::SaveImage()
|
||||||
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
item_work.type == WINIX_IMAGE_TYPE_CROP_THUMB ||
|
||||||
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
item_work.type == WINIX_IMAGE_TYPE_CREATE_CROP_NEW_THUMB );
|
||||||
|
|
||||||
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod) )
|
if( system->MakeFilePath(file_work, dst_path, thumb, true, config->upload_dirs_chmod, config->upload_group_int) )
|
||||||
{
|
{
|
||||||
if( RenameFile(stream_tmp_path.Str(), dst_path) )
|
if( RenameFile(stream_tmp_path.Str(), dst_path) )
|
||||||
{
|
{
|
||||||
|
// it doesn't matter for us if there is an error when chmod/chown on a file
|
||||||
|
// the admin (root) will correct it
|
||||||
|
std::string dst_patha; // IMPROVE ME temporary -- in the futere there'll be SetPriv() with std::wstring
|
||||||
|
PT::WideToUTF8(dst_path, dst_patha);
|
||||||
|
SetPriv(dst_patha, config->upload_files_chmod, config->upload_group_int);
|
||||||
|
|
||||||
ImageSavedCorrectly();
|
ImageSavedCorrectly();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <grp.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include "misc.h"
|
#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;
|
static std::string adir;
|
||||||
|
|
||||||
|
@ -788,27 +792,29 @@ static std::string adir;
|
||||||
{
|
{
|
||||||
PT::WideToUTF8(dir, 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;
|
log << log1 << "Can't create a directory on fs: " << adir << logend;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return SetPriv(adir, priv, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
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)
|
// creating directories (can be more than one)
|
||||||
// 'dirs' can begin with a slash (will be skipped)
|
// '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;
|
static std::wstring temp;
|
||||||
const wchar_t * p = dirs;
|
const wchar_t * p = dirs;
|
||||||
|
@ -834,7 +840,7 @@ const wchar_t * p = dirs;
|
||||||
temp += *p;
|
temp += *p;
|
||||||
|
|
||||||
if( !skip_last || *p!=0 )
|
if( !skip_last || *p!=0 )
|
||||||
if( !CreateDir(temp.c_str(), priv) )
|
if( !CreateDir(temp.c_str(), priv, group) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
temp += '/';
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
14
core/misc.h
14
core/misc.h
|
@ -723,13 +723,19 @@ bool ValidateEmail(const std::wstring & email);
|
||||||
|
|
||||||
bool IsFile(const wchar_t * file);
|
bool IsFile(const wchar_t * file);
|
||||||
bool IsFile(const std::wstring & file);
|
bool IsFile(const std::wstring & file);
|
||||||
bool CreateDir(const wchar_t * dir, int priv);
|
bool CreateDir(const wchar_t * dir, int priv, int group = -1);
|
||||||
bool CreateDir(const std::wstring & dir, int priv);
|
bool CreateDir(const std::wstring & dir, int priv, int group = -1);
|
||||||
|
|
||||||
// creating directories (dirs) under base_dir (base_dir must exist)
|
// creating directories (dirs) under base_dir (base_dir must exist)
|
||||||
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
|
// if skip_last == true then last part from dir is treated as a file (the last directory is not created)
|
||||||
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, bool skip_last = false);
|
bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, int group = -1, bool skip_last = false);
|
||||||
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, bool skip_last = false);
|
bool CreateDirs(const std::wstring & base_dir, const std::wstring & dirs, int priv = 0755, int group = -1, bool skip_last = false);
|
||||||
|
|
||||||
|
int GetGroupId(const char * name);
|
||||||
|
int GetGroupId(const std::string & name);
|
||||||
|
|
||||||
|
bool SetPriv(const char * name, int priv, int group = -1);
|
||||||
|
bool SetPriv(const std::string & name, int priv, int group = -1);
|
||||||
|
|
||||||
bool CopyFile(FILE * in, FILE * out);
|
bool CopyFile(FILE * in, FILE * out);
|
||||||
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
bool CopyFile(const wchar_t * src, const wchar_t * dst);
|
||||||
|
|
|
@ -852,7 +852,7 @@ return res;
|
||||||
|
|
||||||
// making a global file path (in the unix file system)
|
// making a global file path (in the unix file system)
|
||||||
// you should call CreateNewFile before
|
// you should call CreateNewFile before
|
||||||
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod)
|
bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bool create_dir, int chmod, int group)
|
||||||
{
|
{
|
||||||
path.clear();
|
path.clear();
|
||||||
|
|
||||||
|
@ -882,7 +882,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo
|
||||||
path += L"/normal";
|
path += L"/normal";
|
||||||
|
|
||||||
|
|
||||||
if( create_dir && !CreateDirs(path, item.file_path, chmod, true) )
|
if( create_dir && !CreateDirs(path, item.file_path, chmod, group, true) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
path += '/';
|
path += '/';
|
||||||
|
|
|
@ -139,7 +139,7 @@ public:
|
||||||
|
|
||||||
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
// creating item.file_path and item.file_fs (the mountpoint where the item is located)
|
||||||
bool CreateNewFile(Item & item);
|
bool CreateNewFile(Item & item);
|
||||||
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755);
|
bool MakeFilePath(const Item & item, std::wstring & path, bool thumb = false, bool create_dir = false, int chmod = 0755, int group = -1);
|
||||||
|
|
||||||
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
bool MakePath(const Item & item, std::wstring & path, bool clear_path = true);
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ return true;
|
||||||
|
|
||||||
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
|
bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_filename)
|
||||||
{
|
{
|
||||||
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod) )
|
if( !system->MakeFilePath(item, path, false, true, config->upload_dirs_chmod, config->upload_group_int) )
|
||||||
{
|
{
|
||||||
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||||
return false;
|
return false;
|
||||||
|
@ -84,7 +84,15 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi
|
||||||
|
|
||||||
if( RenameFile(tmp_filename, path) )
|
if( RenameFile(tmp_filename, path) )
|
||||||
{
|
{
|
||||||
log << log1 << "Upload: uploaded a new file: " << path << logend;
|
PT::WideToUTF8(path, patha);
|
||||||
|
|
||||||
|
if( !SetPriv(patha, config->upload_files_chmod, config->upload_group_int) )
|
||||||
|
{
|
||||||
|
cur->request->status = WINIX_ERR_PERMISSION_DENIED;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
log << log2 << "Upload: uploaded a new file: " << path << logend;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
<h1>{subject_header}</h1>
|
<h1>{subject_header}</h1>
|
||||||
|
|
||||||
|
|
||||||
<form id="additem" method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]subject">
|
<form method="post" action="[doc_base_url][dir][if-one item_is][item_url]/[end]subject">
|
||||||
|
|
||||||
<div class="winix_input_a">
|
<div class="winix_input_a">
|
||||||
<label>{title}</label>
|
<label for="winix_title_id">{title}</label>
|
||||||
<input type="text" name="subject" value="[if-one item_is][item_subject][else][dir_last_subject][end]">
|
<input id="winix_title_id" type="text" name="subject" value="[if-one item_is][item_subject][else][dir_last_subject][end]">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
[if winix_function_param_is "postredirect"]
|
[if winix_function_param_is "postredirect"]
|
||||||
|
|
Loading…
Reference in New Issue