Ejemplo n.º 1
0
util::Error DirAllowed(const User& user, const fs::VirtualPath& path)
{
  if (path.IsEmpty()) return util::Error::Failure(EINVAL);
  if (path.ToString()[path.Length() - 1] != '/') 
    return InnerAllowed<type>(user, fs::VirtualPath(path.ToString() + '/'));
  else
    return InnerAllowed<type>(user, path);
}
Ejemplo n.º 2
0
 boost::optional<db::nuking::Nuke> LookupUnnuke()
 {
   boost::optional<db::nuking::Nuke> nuke;
   std::string id = GetNukeID(real);
   if (!id.empty()) nuke = db::nuking::LookupUnnukeByID(id);   
   if (!nuke) nuke = db::nuking::LookupUnnukeByPath(path.ToString());
   return nuke;
 }
Ejemplo n.º 3
0
bool STORCommand::CalcCRC(const fs::VirtualPath& path)
{
  for (auto& mask : cfg::Get().CalcCrc())
  {
    if (util::WildcardMatch(mask, path.ToString())) return true;
  }
  
  return false;
}
Ejemplo n.º 4
0
bool PrivatePath(const fs::VirtualPath& path, const User& user)
{
  auto info = user.ACLInfo();
  for (const auto& pp : cfg::Get().Privpath())
  {
    if (!path.ToString().compare(0, pp.Path().length(), pp.Path()))
      return !pp.ACL().Evaluate(info);
  }
  return false;
}
Ejemplo n.º 5
0
 db::nuking::Nuke LookupNuke()
 {
   boost::optional<db::nuking::Nuke> nuke;
   std::string id = GetNukeID(nukedPath);
   if (!id.empty()) nuke = db::nuking::LookupNukeByID(id);   
   if (!nuke)
   {
     nuke = db::nuking::LookupNukeByPath(path.ToString());
     if (!nuke) throw util::RuntimeError("Unable to locate nuke data");
   }
   return *nuke;      
 }
Ejemplo n.º 6
0
 DoNuke(const fs::VirtualPath& path, int multiplier, bool isPercent, 
        const std::string& reason, acl::UserID nukerUID) :
   config(cfg::Get()),
   path(path),
   real(fs::MakeReal(path)),
   multiplier(multiplier),
   isPercent(isPercent),
   reason(reason),
   nukerUID(nukerUID),
   modTime(0),
   totalKBytes(0),
   section(config.SectionMatch(path.ToString(), true))
 { }
Ejemplo n.º 7
0
void CHMODCommand::Process(fs::VirtualPath pathmask)
{
  auto flags = fs::GlobIterator::NoFlags;
  if (recursive) flags |= fs::GlobIterator::Recursive;

  try
  {
    for (auto& entry : fs::GlobContainer(client.User(), pathmask, flags))
    {
      fs::VirtualPath entryPath(pathmask.Dirname() / entry);
      try
      {
        util::path::Status status(fs::MakeReal(entryPath).ToString());
        util::Error e = fs::Chmod(client.User(), entryPath, *mode);
        if (!e)
        {
          ++failed;
          control.PartReply(ftp::CommandOkay, "CHOWN " +
              entryPath.ToString() + ": " + e.Message());
        }
        else
        if (status.IsDirectory()) ++dirs;
        else ++files;
      }
      catch (const util::SystemError& e)
      {
        ++failed;
        control.PartReply(ftp::CommandOkay, "CHOWN " +
            entryPath.ToString() + ": " + e.Message());
      }
    }
  }
  catch (const util::SystemError& e)
  {
    ++failed;
    control.PartReply(ftp::CommandOkay,
        "CHMOD " + pathmask.Dirname().ToString() + ": " + e.Message());
  }
}
Ejemplo n.º 8
0
 void UpdateDatabase()
 {
   std::vector<db::nuking::Nukee> nukees2;
   for (const auto& kv : nukees)
   {
     nukees2.emplace_back(kv.first, kv.second.kBytes, 
                          kv.second.files, kv.second.credits);
   }
   
   // remove old unnuke data if dir was unnuked in past
   auto unnuke = LookupUnnuke();
   if (unnuke) db::nuking::DelUnnuke(*unnuke);
   
   nuke = db::nuking::Nuke(path.ToString(), section ? section->Name() : "", 
                           reason, nukerUID, multiplier, isPercent, modTime, nukees2);
   db::nuking::AddNuke(*nuke);
 }
Ejemplo n.º 9
0
bool InsideHomeDir(const User& user, const fs::VirtualPath& path)
{
  if (user.HomeDir().empty()) return false;
  if (user.HomeDir().back() == '/') return util::StartsWith(path.ToString(), user.HomeDir());
  else return util::StartsWith(path.ToString(), user.HomeDir() + '/');
}