bool TPath::HasAccess(const TCred &cred, enum Access mask) const { struct stat st; int mode; if (!cred.Uid && !access(c_str(), mask & TPath::RWX)) return true; if (stat(c_str(), &st)) { if (!(mask & TPath::P) || errno != ENOENT) return false; TPath dir = DirName(); while (stat(dir.c_str(), &st)) { if (errno != ENOENT) return false; if (dir.Path.size() <= 1) return false; dir = dir.DirName(); } } if ((mask & TPath::U) && cred.Uid == st.st_uid) return true; if (cred.Uid == st.st_uid) mode = st.st_mode >> 6; else if (cred.IsMemberOf(st.st_gid))
void BootstrapCommand(const std::string &cmd, const TPath &path, bool remove) { if (remove) (void)path.RemoveAll(); vector<string> lines; ExpectSuccess(Popen("ldd " + cmd, lines)); for (auto &line : lines) { vector<string> tokens; TError error = SplitString(line, ' ', tokens); if (error) throw error.GetMsg(); TPath from; string name; if (tokens.size() == 2) { from = StringTrim(tokens[0]); TPath p(tokens[0]); name = p.BaseName(); } else if (tokens.size() == 4) { if (tokens[2] == "") continue; from = StringTrim(tokens[2]); name = StringTrim(tokens[0]); } else { continue; } TPath dest = path / from.DirName(); if (!dest.Exists()) { error = dest.MkdirAll(0755); if (error) throw error.GetMsg(); } Expect(system(("cp " + from.ToString() + " " + dest.ToString() + "/" + name).c_str()) == 0); } Expect(system(("cp " + cmd + " " + path.ToString()).c_str()) == 0); }