26 #include "IDobbyUtils.h"
57 bool repair)
const override;
59 const std::string& fsType)
const override;
62 int runE2fsTool(
int dirFd, std::list<std::string>* consoleOutput,
63 const char* e2fsTool, ...)
const;
66 bool mkdirRecursive(
const std::string& path, mode_t mode)
const override;
67 bool mkdirRecursive(
int dirFd,
const std::string& path, mode_t mode)
const override;
70 bool rmdirRecursive(
int dirFd,
const std::string& path)
const override;
73 bool rmdirContents(
int dirFd,
const std::string& path)
const override;
77 const std::string& logTag)
const override;
87 const std::function<
bool()>& func)
const override;
90 const std::function<
bool()>& func)
const override;
92 void nsThread(
int newNsFd,
int nsType,
bool* success,
93 std::function<
bool()>& func)
const;
97 const std::string& str,
98 int flags, mode_t mode)
const override;
100 const std::string& str,
101 int flags, mode_t mode)
const override;
104 size_t maxLen)
const override;
106 size_t maxLen)
const override;
115 const std::function<
bool()>& handler)
const override;
117 std::shared_ptr<DobbyTimer> mTimerQueue;
127 std::set<dev_t> mDeviceWhitelist;
129 mutable std::mutex mMajorNumberLock;
130 mutable std::map<std::string, unsigned int> mMajorNumberCache;
135 int getIntegerMetaData(
const ContainerId &
id,
const std::string &key,
136 int defaultValue)
const override;
139 const std::string &value)
override;
140 std::string getStringMetaData(
const ContainerId &
id,
const std::string &key,
141 const std::string &defaultValue)
const override;
150 bool executeCommand(
const std::string &command)
const;
151 int getGIDorUID(pid_t pid,
const std::string& idType)
const;
154 uid_t
getUID(pid_t pid)
const override;
155 gid_t
getGID(pid_t pid)
const override;
158 std::mutex mMetaDataLock;
159 std::map<std::pair<ContainerId, std::string>,
int> mIntegerMetaData;
160 std::map<std::pair<ContainerId, std::string>, std::string> mStringMetaData;
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition: ContainerId.h:41
Utility object that can be used to register a callback function to execute in the future.
Definition: DobbyTimer.h:58
Utility methods for hooks and the general containiser daemon.
Definition: DobbyUtils.h:43
bool deleteEbtablesRule(const std::string &args) const override
Deletes the given ebtables rule from the existing set.
Definition: DobbyUtils.cpp:1631
void nsThread(int newNsFd, int nsType, bool *success, std::function< bool()> &func) const
Thread helper function that implements the setns syscall.
Definition: DobbyUtils.cpp:543
int startTimerImpl(const std::chrono::milliseconds &timeout, bool oneShot, const std::function< bool()> &handler) const override
Adds a new timer to the timer queue.
Definition: DobbyUtils.cpp:1360
void buildDeviceWhitelist()
Builds the whitelist of allowed device numbers.
Definition: DobbyUtils.cpp:1487
int openLoopDevice(std::string *loopDevice) const
Attempts to open an available loop device.
Definition: DobbyUtils.cpp:712
bool writeTextFileAt(int dirFd, const std::string &path, const std::string &str, int flags, mode_t mode) const override
Simply writes a string into a file.
Definition: DobbyUtils.cpp:1223
void clearContainerMetaData(const ContainerId &id) override
Clears all the meta data stored for a given container.
Definition: DobbyUtils.cpp:1576
std::string readTextFileAt(int dirFd, const std::string &path, size_t maxLen) const override
Simply read a string from a file.
Definition: DobbyUtils.cpp:1288
int getGIDorUID(pid_t pid, const std::string &idType) const
Returns the effective GID or UID for the given PID by parsing /proc/<PID>/status.
Definition: DobbyUtils.cpp:1674
int runE2fsTool(int dirFd, std::list< std::string > *consoleOutput, const char *e2fsTool,...) const
Run the E2FS tool inside the given directory with given args.
Definition: DobbyUtils.cpp:890
bool callInNamespaceImpl(pid_t pid, int nsType, const std::function< bool()> &func) const override
Utility function to run some code in a specific namespace of the container.
Definition: DobbyUtils.cpp:629
bool attachFileToLoopDevice(int loopFd, int fileFd) const
Attempts to attach the file to the loop device.
Definition: DobbyUtils.cpp:794
bool insertEbtablesRule(const std::string &args) const override
Inserts the given ebtables rule to the existing set.
Definition: DobbyUtils.cpp:1614
static bool deleteRecursive(int dirfd, int depth)
Recursive function that deletes everything within the supplied directory (as a descriptor).
Definition: DobbyUtils.cpp:180
Third version of the interface containing extra functions for working with ebtables.
Definition: IDobbyUtils.h:637
virtual unsigned int getDriverMajorNumber(const std::string &driverName) const=0
Returns the major number assigned to a given driver.
virtual bool formatExtImageFile(int dirFd, const std::string &imageFileName, const std::string &fsType="ext4") const=0
Runs the mke2fs tool to format a file system image.
virtual bool mkdirRecursive(const std::string &path, mode_t mode) const=0
Makes a directory and all parent directories as needed.
virtual bool rmdirRecursive(const std::string &path) const=0
Removes a directory and all it's contents.
virtual void setIntegerMetaData(const ContainerId &id, const std::string &key, int value)=0
Sets / Gets integer meta data for the given container.
virtual bool rmdirContents(const std::string &path) const=0
Removes the contents of a directory but leave the actual directory in place.
virtual void cleanMountLostAndFound(const std::string &mountPoint, const std::string &logTag=std::string()) const=0
Logs and deletes any files found in the lost+found directory of the mount point.
virtual gid_t getGID(pid_t pid) const=0
Returns the GID for the given PID.
virtual bool writeTextFile(const std::string &path, const std::string &str, int flags, mode_t mode=0644) const=0
Simply writes a string into a file.
virtual int getNamespaceFd(pid_t pid, int nsType) const=0
Returns a file descriptor to the given namespace of the process.
virtual std::string readTextFile(const std::string &path, size_t maxLen=4096) const=0
Simply read a string from a file.
virtual bool checkExtImageFile(int dirFd, const std::string &imageFileName, bool repair=true) const=0
Runs the e2fsck tool on a file system image to check it's integrity.
virtual bool deviceAllowed(dev_t device) const=0
Returns true if the given device is allowed in the container.
virtual bool cancelTimer(int timerId) const=0
Removes the given timer from the timer queue.
virtual void setStringMetaData(const ContainerId &id, const std::string &key, const std::string &value)=0
Sets / Gets string meta data for the given container.
virtual uid_t getUID(pid_t pid) const=0
Returns the UID for the given PID.
virtual int loopDeviceAssociate(int fileFd, std::string *loopDevPath=nullptr) const=0
Associates a give file descriptor with a loop device.