#pragma once #include "logger.hpp" #include "utils.hpp" #include #include #include namespace fs = std::filesystem; class SmbShare { public: SmbShare(const fs::path& mountDir) : mountDir(mountDir) { } bool mount(const fs::path& remote, bool rw, const std::unique_ptr& credentials) { LogMsg(Logger::Debug, "Trying to mount remote : ", remote); const std::string params = "nolock,sec=ntlmsspi,seal,vers=3.0"; const std::string perm = rw ? "rw" : "ro"; auto options = params + "," + perm; LogMsg(Logger::Debug, "Mounting with options: ", options); std::string credentialsOpt; if (!credentials) { LogMsg(Logger::Info, "Mounting as Guest"); credentialsOpt = "guest,user=OpenBmc"; } else { LogMsg(Logger::Info, "Authenticating as ", credentials->user()); credentialsOpt = "user=" + credentials->user() + ",password=" + credentials->password(); } options += "," + credentialsOpt; auto ec = ::mount(remote.c_str(), mountDir.c_str(), "cifs", 0, options.c_str()); utils::secureCleanup(options); utils::secureCleanup(credentialsOpt); if (ec) { LogMsg(Logger::Error, "Mount failed with ec = ", ec, " errno = ", errno); return false; } return true; } private: std::string mountDir; };