diff --git a/Makefile.dep b/Makefile.dep index e0f6677..ec6463c 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1 +1 @@ -winix.src.files = ./templates/htmltextstream.cpp ./templates/textextstream.h ./templates/adduser.cpp ./templates/ipban.cpp ./templates/misc.cpp ./templates/indexpatterns.h ./templates/item.cpp ./templates/templates.cpp ./templates/winix.cpp ./templates/locale.h ./templates/slog.cpp ./templates/localefilter.cpp ./templates/config.cpp ./templates/patterns.h ./templates/changepatterns.h ./templates/stat.cpp ./templates/template.cpp ./templates/miscspace.h ./templates/sys.cpp ./templates/user.cpp ./templates/textextstream.cpp ./templates/upload.cpp ./templates/env.cpp ./templates/indexpatterns.cpp ./templates/patterncacher.h ./templates/htmltextstream.h ./templates/who.cpp ./templates/locale.cpp ./templates/misc.h ./templates/patterns.cpp ./templates/passwd.cpp ./templates/mount.cpp ./templates/last.cpp ./templates/templates.h ./templates/uptime.cpp ./templates/insert.cpp ./templates/doc.cpp ./templates/changepatterns.cpp ./templates/miscspace.cpp ./templates/filters.cpp ./templates/login.cpp ./templates/localefilter.h ./templates/man.cpp ./templates/dir.cpp ./templates/ls.cpp ./templates/rebus.cpp ./templates/priv.cpp ./templates/patterncacher.cpp ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/stats/init.cpp ./plugins/stats/stats.h ./plugins/stats/templates.h ./plugins/stats/bot.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/gallery/gallery.cpp ./plugins/gallery/galleryinfo.h ./plugins/gallery/init.cpp ./plugins/gallery/gallery.h ./plugins/gallery/galleryinfo.cpp ./plugins/gallery/templates.cpp ./plugins/export/exportthread.cpp ./plugins/export/message.h ./plugins/export/edb.cpp ./plugins/export/funexport.cpp ./plugins/export/exportinfo.cpp ./plugins/export/exportthread.h ./plugins/export/edb.h ./plugins/export/funexport.h ./plugins/export/exportinfo.h ./plugins/export/init.cpp ./plugins/export/export.h ./plugins/ticket/sessiondata.h ./plugins/ticket/ticket.h ./plugins/ticket/editticket.cpp ./plugins/ticket/funticket.cpp ./plugins/ticket/editticket.h ./plugins/ticket/templates.cpp ./plugins/ticket/ticketinfo.cpp ./plugins/ticket/funticket.h ./plugins/ticket/init.cpp ./plugins/ticket/ticketinfo.h ./plugins/ticket/createticket.cpp ./plugins/ticket/showtickets.cpp ./plugins/ticket/tdb.cpp ./plugins/ticket/pluginmsg.h ./plugins/ticket/createticket.h ./plugins/ticket/showtickets.h ./plugins/ticket/sessiondata.cpp ./plugins/ticket/tdb.h ./plugins/menu/cache.cpp ./plugins/menu/init.cpp ./plugins/menu/cache.h ./plugins/menu/templates.cpp ./plugins/thread/init.cpp ./plugins/thread/templates.h ./plugins/thread/tdb.cpp ./plugins/thread/pluginmsg.h ./plugins/thread/thread.h ./plugins/thread/tdb.h ./plugins/thread/funthread.cpp ./plugins/thread/threadinfo.cpp ./plugins/thread/funthread.h ./plugins/thread/threadinfo.h ./plugins/thread/createthread.cpp ./plugins/thread/reply.cpp ./plugins/thread/showthreads.cpp ./plugins/thread/templates.cpp ./plugins/thread/createthread.h ./plugins/thread/reply.h ./plugins/thread/showthreads.h ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./main/main.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./db/dbbase.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./core/users.h ./core/threadmanager.h ./core/slog.h ./core/pluginmsg.h ./core/config.h ./core/httpsimpleparser.h ./core/loadavg.cpp ./core/mountparser.cpp ./core/htmlfilter.h ./core/groups.cpp ./core/dircontainer.cpp ./core/timezones.h ./core/postmultiparser.h ./core/image.cpp ./core/requesttypes.h ./core/ugcontainer.h ./core/logmanipulators.h ./core/rebus.h ./core/synchro.cpp ./core/log.h ./core/session.h ./core/misc.cpp ./core/lock.h ./core/item.cpp ./core/cur.h ./core/dirs.cpp ./core/threadmanager.cpp ./core/slog.cpp ./core/httpsimpleparser.cpp ./core/postparser.h ./core/run.h ./core/htmlfilter.cpp ./core/lastcontainer.h ./core/rebus.cpp ./core/loadavg.h ./core/sessionmanager.h ./core/mountparser.h ./core/groups.h ./core/app.h ./core/dircontainer.h ./core/lock.cpp ./core/synchro.h ./core/compress.cpp ./core/plugindata.h ./core/misc.h ./core/crypt.cpp ./core/group.h ./core/run.cpp ./core/sessionparser.h ./core/lastcontainer.cpp ./core/dirs.h ./core/mount.h ./core/acceptbaseparser.cpp ./core/sessionmanager.cpp ./core/job.h ./core/app.cpp ./core/user.h ./core/mounts.cpp ./core/plugindata.cpp ./core/system.h ./core/version.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/bbcodeparser.cpp ./core/request.h ./core/ipban.h ./core/timezone.h ./core/compress.h ./core/sessionparser.cpp ./core/users.cpp ./core/ipbancontainer.h ./core/mount.cpp ./core/plugin.h ./core/config.cpp ./core/textstream.h ./core/crypt.h ./core/basethread.h ./core/job.cpp ./core/acceptbaseparser.h ./core/postmultiparser.cpp ./core/timezones.cpp ./core/user.cpp ./core/log.cpp ./core/session.cpp ./core/system.cpp ./core/sessioncontainer.cpp ./core/image.h ./core/request.cpp ./core/acceptencodingparser.h ./core/error.h ./core/timezone.cpp ./core/mounts.h ./core/ipbancontainer.cpp ./core/plugin.cpp ./core/bbcodeparser.h ./core/basethread.cpp ./core/item.h ./functions/node.h ./functions/account.cpp ./functions/emacs.h ./functions/env.h ./functions/subject.cpp ./functions/who.h ./functions/last.cpp ./functions/uptime.cpp ./functions/imgcrop.h ./functions/reload.cpp ./functions/cp.h ./functions/download.cpp ./functions/functions.cpp ./functions/logout.cpp ./functions/cat.h ./functions/login.h ./functions/rmuser.cpp ./functions/rm.cpp ./functions/priv.cpp ./functions/man.h ./functions/specialdefault.cpp ./functions/sort.cpp ./functions/emacs.cpp ./functions/env.cpp ./functions/timezone.h ./functions/chmod.h ./functions/imgcrop.cpp ./functions/cp.cpp ./functions/subject.h ./functions/uptime.h ./functions/last.h ./functions/login.cpp ./functions/run.h ./functions/ckeditor.h ./functions/template.cpp ./functions/stat.cpp ./functions/download.h ./functions/privchanger.h ./functions/logout.h ./functions/rmuser.h ./functions/ls.h ./functions/chown.h ./functions/adduser.cpp ./functions/ipban.cpp ./functions/chmod.cpp ./functions/specialdefault.h ./functions/timezone.cpp ./functions/pw.h ./functions/vim.cpp ./functions/sort.h ./functions/locale.cpp ./functions/passwd.cpp ./functions/ckeditor.cpp ./functions/run.cpp ./functions/uname.cpp ./functions/functionparser.h ./functions/mount.h ./functions/privchanger.cpp ./functions/ln.cpp ./functions/mkdir.h ./functions/tinymce.h ./functions/chown.cpp ./functions/ls.cpp ./functions/nicedit.cpp ./functions/template.h ./functions/stat.h ./functions/functionbase.h ./functions/node.cpp ./functions/pw.cpp ./functions/mv.h ./functions/upload.h ./functions/default.h ./functions/meta.h ./functions/adduser.h ./functions/who.cpp ./functions/ipban.h ./functions/vim.h ./functions/account.h ./functions/functionparser.cpp ./functions/mount.cpp ./functions/locale.h ./functions/mkdir.cpp ./functions/passwd.h ./functions/cat.cpp ./functions/tinymce.cpp ./functions/uname.h ./functions/man.cpp ./functions/reload.h ./functions/functions.h ./functions/ln.h ./functions/functionbase.cpp ./functions/mv.cpp ./functions/rm.h ./functions/nicedit.h ./functions/default.cpp ./functions/upload.cpp ./functions/priv.h ./functions/meta.cpp ./notify/notifythread.cpp ./notify/notifypool.cpp ./notify/notifythread.h ./notify/notifypool.h ./notify/templatesnotify.cpp ./notify/notify.cpp ./notify/templatesnotify.h ./notify/notify.h ../ezc/src/item.cpp ../ezc/src/stringconv.h ../ezc/src/pattern.h ../ezc/src/item.h ../ezc/src/ezc.h ../ezc/src/funinfo.h ../ezc/src/generator.h ../ezc/src/stringconv.cpp ../ezc/src/functions.h ../ezc/src/pattern.cpp ../tito/src/crypto.cpp ../tito/src/misc.h ../tito/src/base64.cpp ../tito/src/crypto.h ../tito/src/aes.cpp ../tito/src/base64.h ../tito/src/misc.cpp ../tito/src/aes.h ../pikotools/mainparser/sample/sample.cpp ../pikotools/mainparser/mainparser.cpp ../pikotools/mainparser/mainparser.h ../pikotools/space/space.h ../pikotools/space/spaceparser.cpp ../pikotools/space/space.cpp ../pikotools/space/spaceparser.h ../pikotools/space/jsontospaceparser.cpp ../pikotools/space/spacetojson.cpp ../pikotools/space/jsontospaceparser.h ../pikotools/space/spacetojson.h ../pikotools/date/date.h ../pikotools/date/date.cpp ../pikotools/membuffer/membuffer.h ../pikotools/utf8/utf8.cpp ../pikotools/utf8/utf8.h ../pikotools/textstream/textstream.h ../pikotools/textstream/types.h ../pikotools/convert/convert.h ../pikotools/convert/inttostr.h \ No newline at end of file +winix.src.files = ./main/main.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./db/dbbase.cpp ./core/synchro.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/misc.cpp ./core/item.cpp ./core/error.h ./core/timezone.h ./core/compress.h ./core/crypt.cpp ./core/dirs.cpp ./core/slog.cpp ./core/config.cpp ./core/lastcontainer.cpp ./core/users.h ./core/httpsimpleparser.cpp ./core/threadmanager.h ./core/postparser.h ./core/pluginmsg.h ./core/acceptbaseparser.h ./core/loadavg.cpp ./core/job.h ./core/mountparser.cpp ./core/timezones.h ./core/sessionmanager.h ./core/groups.h ./core/system.cpp ./core/synchro.cpp ./core/rebus.h ./core/lock.cpp ./core/acceptencodingparser.h ./core/version.h ./core/compress.cpp ./core/ipbancontainer.cpp ./core/request.h ./core/plugindata.h ./core/plugin.cpp ./core/sessionparser.cpp ./core/bbcodeparser.h ./core/users.cpp ./core/mount.cpp ./core/basethread.cpp ./core/item.h ./core/slog.h ./core/acceptbaseparser.cpp ./core/lastcontainer.h ./core/httpsimpleparser.h ./core/timezones.cpp ./core/groups.cpp ./core/requesttypes.h ./core/system.h ./core/bbcodeparser.cpp ./core/lock.h ./core/ipbancontainer.h ./core/group.h ./core/plugin.h ./core/run.cpp ./core/textstream.h ./core/sessionparser.h ./core/basethread.h ./core/mount.h ./core/htmlfilter.cpp ./core/user.cpp ./core/app.cpp ./core/image.cpp ./core/ugcontainer.h ./core/postmultiparser.h ./core/logmanipulators.h ./core/sessioncontainer.cpp ./core/dircontainer.h ./core/log.h ./core/session.h ./core/timezone.cpp ./core/mounts.h ./core/ipban.h ./core/cur.h ./core/misc.h ./core/threadmanager.cpp ./core/dirs.h ./core/crypt.h ./core/run.h ./core/config.h ./core/job.cpp ./core/postmultiparser.cpp ./core/sessionmanager.cpp ./core/htmlfilter.h ./core/rebus.cpp ./core/dircontainer.cpp ./core/log.cpp ./core/user.h ./core/loadavg.h ./core/session.cpp ./core/mountparser.h ./core/mounts.cpp ./core/app.h ./core/image.h ./core/plugindata.cpp ./core/request.cpp ./functions/upload.cpp ./functions/priv.h ./functions/env.cpp ./functions/default.h ./functions/node.h ./functions/specialdefault.h ./functions/timezone.cpp ./functions/pw.h ./functions/adduser.h ./functions/chmod.h ./functions/imgcrop.cpp ./functions/vim.h ./functions/account.h ./functions/mount.cpp ./functions/uptime.cpp ./functions/ckeditor.cpp ./functions/mkdir.cpp ./functions/reload.cpp ./functions/functionparser.h ./functions/logout.cpp ./functions/rmuser.cpp ./functions/rm.cpp ./functions/chown.h ./functions/nicedit.h ./functions/mv.h ./functions/node.cpp ./functions/specialdefault.cpp ./functions/adduser.cpp ./functions/upload.h ./functions/vim.cpp ./functions/env.h ./functions/timezone.h ./functions/who.h ./functions/cp.cpp ./functions/run.cpp ./functions/locale.h ./functions/imgcrop.h ./functions/passwd.h ./functions/mount.h ./functions/privchanger.cpp ./functions/functions.cpp ./functions/last.h ./functions/ckeditor.h ./functions/mkdir.h ./functions/reload.h ./functions/cat.h ./functions/download.h ./functions/ln.h ./functions/nicedit.cpp ./functions/functionbase.cpp ./functions/man.h ./functions/rm.h ./functions/meta.cpp ./functions/emacs.cpp ./functions/sort.h ./functions/who.cpp ./functions/ipban.h ./functions/locale.cpp ./functions/passwd.cpp ./functions/last.cpp ./functions/subject.h ./functions/download.cpp ./functions/cp.h ./functions/cat.cpp ./functions/login.cpp ./functions/tinymce.cpp ./functions/ln.cpp ./functions/run.h ./functions/uname.h ./functions/man.cpp ./functions/functions.h ./functions/privchanger.h ./functions/ls.cpp ./functions/template.h ./functions/stat.h ./functions/priv.cpp ./functions/default.cpp ./functions/functionbase.h ./functions/pw.cpp ./functions/sort.cpp ./functions/ipban.cpp ./functions/chmod.cpp ./functions/meta.h ./functions/account.cpp ./functions/emacs.h ./functions/subject.cpp ./functions/functionparser.cpp ./functions/uname.cpp ./functions/uptime.h ./functions/template.cpp ./functions/stat.cpp ./functions/tinymce.h ./functions/login.h ./functions/chown.cpp ./functions/logout.h ./functions/mv.cpp ./functions/rmuser.h ./functions/ls.h ./notify/notifypool.h ./notify/templatesnotify.cpp ./notify/notify.cpp ./notify/templatesnotify.h ./notify/notify.h ./notify/notifythread.cpp ./notify/notifypool.cpp ./notify/notifythread.h ./templates/who.cpp ./templates/item.cpp ./templates/mount.cpp ./templates/templates.h ./templates/locale.h ./templates/slog.cpp ./templates/doc.cpp ./templates/localefilter.cpp ./templates/config.cpp ./templates/patterns.h ./templates/miscspace.cpp ./templates/filters.cpp ./templates/login.cpp ./templates/man.cpp ./templates/changepatterns.h ./templates/stat.cpp ./templates/template.cpp ./templates/dir.cpp ./templates/user.cpp ./templates/rebus.cpp ./templates/patterncacher.cpp ./templates/upload.cpp ./templates/textextstream.h ./templates/adduser.cpp ./templates/ipban.cpp ./templates/htmltextstream.h ./templates/indexpatterns.h ./templates/templates.cpp ./templates/winix.cpp ./templates/locale.cpp ./templates/misc.h ./templates/patterns.cpp ./templates/passwd.cpp ./templates/last.cpp ./templates/uptime.cpp ./templates/insert.cpp ./templates/changepatterns.cpp ./templates/localefilter.h ./templates/miscspace.h ./templates/ls.cpp ./templates/sys.cpp ./templates/priv.cpp ./templates/textextstream.cpp ./templates/htmltextstream.cpp ./templates/env.cpp ./templates/indexpatterns.cpp ./templates/patterncacher.h ./templates/misc.cpp ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/stats/init.cpp ./plugins/stats/stats.h ./plugins/stats/templates.h ./plugins/stats/bot.cpp ./plugins/gallery/galleryinfo.cpp ./plugins/gallery/templates.cpp ./plugins/gallery/gallery.cpp ./plugins/gallery/galleryinfo.h ./plugins/gallery/init.cpp ./plugins/gallery/gallery.h ./plugins/export/init.cpp ./plugins/export/export.h ./plugins/export/exportthread.cpp ./plugins/export/message.h ./plugins/export/edb.cpp ./plugins/export/funexport.cpp ./plugins/export/exportinfo.cpp ./plugins/export/exportthread.h ./plugins/export/edb.h ./plugins/export/funexport.h ./plugins/export/exportinfo.h ./plugins/ticket/funticket.h ./plugins/ticket/init.cpp ./plugins/ticket/ticketinfo.h ./plugins/ticket/showtickets.cpp ./plugins/ticket/createticket.cpp ./plugins/ticket/tdb.cpp ./plugins/ticket/pluginmsg.h ./plugins/ticket/createticket.h ./plugins/ticket/showtickets.h ./plugins/ticket/sessiondata.cpp ./plugins/ticket/tdb.h ./plugins/ticket/sessiondata.h ./plugins/ticket/ticket.h ./plugins/ticket/editticket.cpp ./plugins/ticket/funticket.cpp ./plugins/ticket/templates.cpp ./plugins/ticket/editticket.h ./plugins/ticket/ticketinfo.cpp ./plugins/menu/cache.cpp ./plugins/menu/init.cpp ./plugins/menu/cache.h ./plugins/menu/templates.cpp ./plugins/thread/funthread.cpp ./plugins/thread/threadinfo.cpp ./plugins/thread/funthread.h ./plugins/thread/threadinfo.h ./plugins/thread/createthread.cpp ./plugins/thread/reply.cpp ./plugins/thread/showthreads.cpp ./plugins/thread/templates.cpp ./plugins/thread/createthread.h ./plugins/thread/reply.h ./plugins/thread/showthreads.h ./plugins/thread/init.cpp ./plugins/thread/templates.h ./plugins/thread/tdb.cpp ./plugins/thread/pluginmsg.h ./plugins/thread/thread.h ./plugins/thread/tdb.h ../ezc/src/item.cpp ../ezc/src/stringconv.h ../ezc/src/pattern.h ../ezc/src/item.h ../ezc/src/ezc.h ../ezc/src/funinfo.h ../ezc/src/generator.h ../ezc/src/stringconv.cpp ../ezc/src/functions.h ../ezc/src/pattern.cpp ../tito/src/crypto.cpp ../tito/src/misc.h ../tito/src/base64.cpp ../tito/src/crypto.h ../tito/src/aes.cpp ../tito/src/base64.h ../tito/src/misc.cpp ../tito/src/aes.h ../pikotools/mainparser/sample/sample.cpp ../pikotools/mainparser/mainparser.cpp ../pikotools/mainparser/mainparser.h ../pikotools/space/space.h ../pikotools/space/spaceparser.cpp ../pikotools/space/space.cpp ../pikotools/space/spaceparser.h ../pikotools/space/jsontospaceparser.cpp ../pikotools/space/spacetojson.cpp ../pikotools/space/jsontospaceparser.h ../pikotools/space/spacetojson.h ../pikotools/date/date.h ../pikotools/date/date.cpp ../pikotools/membuffer/membuffer.h ../pikotools/utf8/utf8.cpp ../pikotools/utf8/utf8.h ../pikotools/textstream/textstream.h ../pikotools/textstream/types.h ../pikotools/convert/convert.h ../pikotools/convert/inttostr.h \ No newline at end of file diff --git a/core/config.cpp b/core/config.cpp index 1a797c4..31d38f0 100755 --- a/core/config.cpp +++ b/core/config.cpp @@ -132,6 +132,7 @@ void Config::AssignValues(bool stdout_is_closed) NoLastSlash(upload_dir); NoLastSlash(common_dir); + upload_group = AText(L"upload_group"); upload_dirs_chmod = Int(L"upload_dirs_chmod", 0750); upload_files_chmod = Int(L"upload_files_chmod", 0640); 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); 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_loop_elements = Size(L"ezc_max_loop_elements", 5000); @@ -294,6 +295,8 @@ void Config::SetAdditionalVariables() if( locale_files.empty() ) locale_files.push_back(L"en"); + + upload_group_int = GetGroupId(upload_group); } diff --git a/core/config.h b/core/config.h index 69b91ef..11dcf4b 100755 --- a/core/config.h +++ b/core/config.h @@ -268,6 +268,14 @@ public: // default: empty 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) // default: 0750 int upload_dirs_chmod; diff --git a/core/image.cpp b/core/image.cpp index 0adaa67..f4233ad 100755 --- a/core/image.cpp +++ b/core/image.cpp @@ -514,10 +514,16 @@ void Image::SaveImage() item_work.type == WINIX_IMAGE_TYPE_CROP_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) ) { + // 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(); } else diff --git a/core/misc.cpp b/core/misc.cpp index cadd0ca..d946178 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #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); } diff --git a/core/misc.h b/core/misc.h index 81a0936..d5066e8 100755 --- a/core/misc.h +++ b/core/misc.h @@ -723,13 +723,19 @@ bool ValidateEmail(const std::wstring & email); bool IsFile(const wchar_t * file); bool IsFile(const std::wstring & file); -bool CreateDir(const wchar_t * dir, int priv); -bool CreateDir(const std::wstring & dir, int priv); +bool CreateDir(const wchar_t * dir, int priv, int group = -1); +bool CreateDir(const std::wstring & dir, int priv, int group = -1); // 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) -bool CreateDirs(const wchar_t * base_dir, const wchar_t * dirs, int priv = 0755, 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 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, 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(const wchar_t * src, const wchar_t * dst); diff --git a/core/system.cpp b/core/system.cpp index 4dc3495..c9656a0 100755 --- a/core/system.cpp +++ b/core/system.cpp @@ -852,7 +852,7 @@ return res; // making a global file path (in the unix file system) // 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(); @@ -882,7 +882,7 @@ bool System::MakeFilePath(const Item & item, std::wstring & path, bool thumb, bo 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; path += '/'; diff --git a/core/system.h b/core/system.h index 672db8a..672af6e 100755 --- a/core/system.h +++ b/core/system.h @@ -139,7 +139,7 @@ public: // creating item.file_path and item.file_fs (the mountpoint where the item is located) 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); diff --git a/functions/upload.cpp b/functions/upload.cpp index 8892f65..90bd7bf 100755 --- a/functions/upload.cpp +++ b/functions/upload.cpp @@ -76,7 +76,7 @@ return true; 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; return false; @@ -84,7 +84,15 @@ bool Upload::UploadSaveStaticFile(const Item & item, const std::wstring & tmp_fi 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; } else diff --git a/html/fun_subject.html b/html/fun_subject.html index 375349b..a0cb330 100755 --- a/html/fun_subject.html +++ b/html/fun_subject.html @@ -3,11 +3,11 @@

{subject_header}

-
+
- - + +
[if winix_function_param_is "postredirect"]