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 checkExtImageFile(int dirFd, const std::string &imageFileName, bool repair) const override
Runs the e2fsck tool on a file system image to check it's integrity.
Definition DobbyUtils.cpp:1074
 
bool deleteEbtablesRule(const std::string &args) const override
Deletes the given ebtables rule from the existing set.
Definition DobbyUtils.cpp:1646
 
void setStringMetaData(const ContainerId &id, const std::string &key, const std::string &value) override
Sets / Gets string meta data for the given container.
Definition DobbyUtils.cpp:1565
 
bool rmdirContents(const std::string &path) const override
Removes the contents of a directory but leave the actual directory in place.
Definition DobbyUtils.cpp:346
 
void setIntegerMetaData(const ContainerId &id, const std::string &key, int value) override
Sets / Gets integer meta data for the given container.
Definition DobbyUtils.cpp:1537
 
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
 
std::string readTextFile(const std::string &path, size_t maxLen) const override
Simply read a string from a file.
Definition DobbyUtils.cpp:1345
 
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:1375
 
uid_t getUID(pid_t pid) const override
Returns the UID for the given PID.
Definition DobbyUtils.cpp:1744
 
void buildDeviceWhitelist()
Builds the whitelist of allowed device numbers.
Definition DobbyUtils.cpp:1502
 
bool cancelTimer(int timerId) const override
Removes the given timer from the timer queue.
Definition DobbyUtils.cpp:1399
 
bool rmdirRecursive(const std::string &path) const override
Removes a directory and all it's contents.
Definition DobbyUtils.cpp:298
 
gid_t getGID(pid_t pid) const override
Returns the GID for the given PID.
Definition DobbyUtils.cpp:1732
 
int openLoopDevice(std::string *loopDevice) const
Attempts to open an available loop device.
Definition DobbyUtils.cpp:712
 
bool formatExtImageFile(int dirFd, const std::string &imageFileName, const std::string &fsType) const override
Runs the mke2fs tool to format a file system image.
Definition DobbyUtils.cpp:1171
 
bool mkdirRecursive(const std::string &path, mode_t mode) const override
Makes a directory and all parent directories as needed.
Definition DobbyUtils.cpp:166
 
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:1230
 
int getNamespaceFd(pid_t pid, int nsType) const override
Returns a file descriptor to the given namespace of the process.
Definition DobbyUtils.cpp:488
 
void clearContainerMetaData(const ContainerId &id) override
Clears all the meta data stored for a given container.
Definition DobbyUtils.cpp:1591
 
std::string readTextFileAt(int dirFd, const std::string &path, size_t maxLen) const override
Simply read a string from a file.
Definition DobbyUtils.cpp:1303
 
bool deviceAllowed(dev_t device) const override
Returns true if the given device is allowed in the container.
Definition DobbyUtils.cpp:1485
 
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:1689
 
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 writeTextFile(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:1278
 
void cleanMountLostAndFound(const std::string &mountPoint, const std::string &logTag) const override
Logs and deletes any files found in the lost+found directory of the mount point.
Definition DobbyUtils.cpp:388
 
bool insertEbtablesRule(const std::string &args) const override
Inserts the given ebtables rule to the existing set.
Definition DobbyUtils.cpp:1629
 
static bool deleteRecursive(int dirfd, int depth)
Recursive function that deletes everything within the supplied directory (as a descriptor).
Definition DobbyUtils.cpp:180
 
int loopDeviceAssociate(int fileFd, std::string *loopDevPath) const override
Associates a give file descriptor with a loop device.
Definition DobbyUtils.cpp:844
 
unsigned int getDriverMajorNumber(const std::string &driverName) const override
Returns the major number assigned to a given driver.
Definition DobbyUtils.cpp:1419
 
Third version of the interface containing extra functions for working with ebtables.
Definition IDobbyUtils.h:637