/* Copyright (c) 2016, Antonio SJ Musumeci Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include "fuse_getattr.hpp" #include "config.hpp" #include "errno.hpp" #include "fs_fstat.hpp" #include "fs_inode.hpp" #include "fs_lstat.hpp" #include "fs_path.hpp" #include "fs_stat.hpp" #include "fuse_fgetattr.hpp" #include "state.hpp" #include "str.hpp" #include "symlinkify.hpp" #include "ugid.hpp" #include "fuse.h" #include #include static int _getattr_fake_root(struct stat *st_) { st_->st_dev = 0; st_->st_ino = 0; st_->st_mode = (S_IFDIR|S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); st_->st_nlink = 2; st_->st_uid = 0; st_->st_gid = 0; st_->st_rdev = 0; st_->st_size = 0; st_->st_blksize = 512; st_->st_blocks = 0; st_->st_atime = 0; st_->st_mtime = 0; st_->st_ctime = 0; return 0; } static int _getattr_controlfile(struct stat *st_) { static const uid_t uid = ::getuid(); static const gid_t gid = ::getgid(); static const time_t now = ::time(NULL); st_->st_dev = 0; st_->st_ino = 0; st_->st_mode = (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH); st_->st_nlink = 1; st_->st_uid = uid; st_->st_gid = gid; st_->st_rdev = 0; st_->st_size = 0; st_->st_blksize = 512; st_->st_blocks = 0; st_->st_atime = now; st_->st_mtime = now; st_->st_ctime = now; return 0; } static bool should_break(const fs::path &fusepath_) { fs::path f = fusepath_.filename(); if(f == "_callImplicitHook 0 envHostHostHook") return false; if(f == "envHostHostHook") return false; if(f == "_callImplicitHook 0 preHook") return false; if(f == "preHook") return false; if(f == "addInputsHook") return false; if(f == "_callImplicitHook 0 envBuildBuildHook") return false; if(f == "envBuildBuildHook") return false; if(f == "_callImplicitHook 0 envBuildTargetHook") return false; if(f == "envBuildTargetHook") return false; return true; } int _getattr(const fs::path &fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) { int rv; rv = cfg.getattr(cfg.branches, fusepath_, st_, cfg.follow_symlinks, cfg.symlinkify_timeout); if(rv < 0) { fmt::println("getattr: {}\n" " uid: {}\n" " gid: {}\n" " err: {}\n" , fusepath_.string(), geteuid(), getegid(), strerror(-rv) ); if(should_break(fusepath_)) raise(SIGTRAP); } if((rv < 0) && Config::is_rootdir(fusepath_)) return ::_getattr_fake_root(st_); timeout_->entry = ((rv >= 0) ? cfg.cache_entry : cfg.cache_negative_entry); timeout_->attr = cfg.cache_attr; return rv; } int FUSE::getattr(const fuse_req_ctx_t *ctx_, const char *fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) { const fs::path fusepath{fusepath_}; return FUSE::getattr(ctx_,fusepath,st_,timeout_); } int FUSE::getattr(const fuse_req_ctx_t *ctx_, const fs::path &fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) { // const ugid::Set ugid(ctx_); const ugid::SetRootGuard _; return FUSE::getattr(fusepath_,st_,timeout_); } int FUSE::getattr(const fs::path &fusepath_, struct stat *st_, fuse_timeouts_t *timeout_) { if(Config::is_ctrl_file(fusepath_)) return ::_getattr_controlfile(st_); return ::_getattr(fusepath_,st_,timeout_); }