| 1 | // Copyright (C) Microsoft Corporation. All rights reserved. |
| 2 | #pragma once |
| 3 | |
| 4 | #include "p9errors.h" |
| 5 | |
| 6 | namespace p9fs::util { |
| 7 | |
| 8 | constexpr uid_t c_InvalidUid = std::numeric_limits<uid_t>::max(); |
| 9 | constexpr gid_t c_InvalidGid = std::numeric_limits<gid_t>::max(); |
| 10 | |
| 11 | Expected<wil::unique_fd> Reopen(int fd, int openFlags); |
| 12 | |
| 13 | Expected<wil::unique_fd> OpenAt(int dirfd, const std::string& name, int openFlags, mode_t mode = 0600); |
| 14 | |
| 15 | std::string GetFdPath(int fd); |
| 16 | |
| 17 | LX_INT AccessHelper(int fd, const std::string& path, int mode); |
| 18 | |
| 19 | LX_INT CheckFOwnerCapability(); |
| 20 | |
| 21 | gid_t GetUserGroupId(uid_t uid); |
| 22 | |
| 23 | gid_t GetGroupIdByName(const char* name); |
| 24 | |
| 25 | // Changes the effective uid and gid of the current thread for the lifetime of this object. |
| 26 | class FsUserContext final |
| 27 | { |
| 28 | public: |
| 29 | FsUserContext(uid_t uid, gid_t gid, const std::vector<gid_t>& groups); |
| 30 | ~FsUserContext(); |
| 31 | |
| 32 | private: |
| 33 | bool m_Restore{}; |
| 34 | bool m_restoreGroups{}; |
| 35 | }; |
| 36 | |
| 37 | } // namespace p9fs::util |