2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2012-01-25 00:03:36 +01:00
|
|
|
* Copyright (c) 2008-2012, Tomasz Sowa
|
2010-08-10 18:12:50 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mkdir.h"
|
|
|
|
#include "functions.h"
|
2012-02-24 13:09:38 +01:00
|
|
|
#include "core/plugin.h"
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Fun
|
|
|
|
{
|
|
|
|
|
|
|
|
Mkdir::Mkdir()
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
fun.url = L"mkdir";
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Mkdir::HasAccess(const Item & item)
|
|
|
|
{
|
|
|
|
// you can create a directory only in a directory
|
|
|
|
if( item.type != Item::dir )
|
|
|
|
return false;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->session->puser && cur->session->puser->super_user )
|
2010-08-10 18:12:50 +02:00
|
|
|
// super user can use mkdir everywhere
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if( !system->HasWriteAccess(item) )
|
|
|
|
return false;
|
|
|
|
|
2010-09-13 01:33:27 +02:00
|
|
|
if( !system->mounts.pmount->IsPar(system->mounts.MountParMkdirOn()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return true;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( system->mounts.pmount->IsArg(system->mounts.MountParMkdirOn(), cur->request->dir_tab.size()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Mkdir::HasAccess()
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->is_item || !HasAccess(*cur->request->dir_tab.back()) )
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-10 22:43:38 +02:00
|
|
|
void Mkdir::PostFunMkdir(bool add_to_dir_tab, int privileges)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
functions->ReadItem(cur->request->item, Item::dir);
|
|
|
|
functions->SetUser(cur->request->item);
|
|
|
|
cur->request->item.privileges = privileges;
|
2012-02-24 13:09:38 +01:00
|
|
|
Item * pdir;
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2012-02-24 13:09:38 +01:00
|
|
|
cur->request->status = system->dirs.AddDirectory(cur->request->item, add_to_dir_tab, &pdir);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2012-02-24 13:09:38 +01:00
|
|
|
if( pdir )
|
|
|
|
plugin.Call(WINIX_DIR_ADDED, pdir);
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
system->RedirectTo(cur->request->item);
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
log << log1 << "Content: PostFunMkdir: Error: " << cur->request->status << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Mkdir::MakePost()
|
|
|
|
{
|
2012-01-25 00:03:36 +01:00
|
|
|
PostFunMkdir(false, system->NewDirPrivileges());
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|