summaryrefslogtreecommitdiff
path: root/virtual-media/src/smb.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'virtual-media/src/smb.hpp')
-rw-r--r--virtual-media/src/smb.hpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/virtual-media/src/smb.hpp b/virtual-media/src/smb.hpp
index 3189770..62c3a44 100644
--- a/virtual-media/src/smb.hpp
+++ b/virtual-media/src/smb.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "logger.hpp"
+#include "utils.hpp"
#include <sys/mount.h>
@@ -16,7 +17,8 @@ class SmbShare
{
}
- bool mount(const fs::path& remote, bool rw)
+ bool mount(const fs::path& remote, bool rw,
+ const std::unique_ptr<utils::CredentialsProvider>& credentials)
{
LogMsg(Logger::Debug, "Trying to mount remote : ", remote);
@@ -25,8 +27,27 @@ class SmbShare
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,