summaryrefslogtreecommitdiff
path: root/special-mode-mgr/include/file.hpp
diff options
context:
space:
mode:
authorRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2020-01-30 19:41:20 +0300
committerRichard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>2020-01-30 20:01:04 +0300
commit8f3c2240f6dd48888e8552e905945ffcd62900a6 (patch)
tree7c1a0a602371cfc576f91a89a476a5c92f4c3c1f /special-mode-mgr/include/file.hpp
parentde66bb8fdc5fcd0df7f75af71155852d0182d5c8 (diff)
downloadprovingground-8f3c2240f6dd48888e8552e905945ffcd62900a6.tar.xz
Configure special user, if not set and in mfg mode
Configure special user with default passwod 0penBmc1, when the root user is not set with any password, and mark the password as expired, so that it will be forced to update on first login. This method can be used when Host interface is not available and we still need to enable root user. Note: This feature is under VALIDATION_UNSECURE flag, and hence will be available for reference only image. Tested: 1. Built the image without debug-tweaks and flashed the same 2. Confirmed that root user is not enabled during regular boot 3. Pressed power button for 15 seconds during AC Cycle, and entered manufacturing mode 4. Able to login to root user with password "0penBmc1" and updated the password to the new one, due to force password update 5. Verified upon rebooting, the newly configured password can be used to login to the serial console Change-Id: I53e68ebbe24110a116816a29fe1bf5b3142b8bc2 Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Diffstat (limited to 'special-mode-mgr/include/file.hpp')
-rw-r--r--special-mode-mgr/include/file.hpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/special-mode-mgr/include/file.hpp b/special-mode-mgr/include/file.hpp
new file mode 100644
index 0000000..3ea0d50
--- /dev/null
+++ b/special-mode-mgr/include/file.hpp
@@ -0,0 +1,79 @@
+#pragma once
+
+#include <stdio.h>
+
+#include <filesystem>
+
+/** @class File
+ * @brief Responsible for handling file pointer
+ * Needed by putspent(3)
+ */
+class File
+{
+ private:
+ /** @brief handler for operating on file */
+ FILE* fp = NULL;
+
+ /** @brief File name. Needed in the case where the temp
+ * needs to be removed
+ */
+ const std::string& name;
+
+ /** @brief Should the file be removed at exit */
+ bool removeOnExit = false;
+
+ public:
+ File() = delete;
+ File(const File&) = delete;
+ File& operator=(const File&) = delete;
+ File(File&&) = delete;
+ File& operator=(File&&) = delete;
+
+ /** @brief Opens file and uses it to do file operation
+ *
+ * @param[in] name - File name
+ * @param[in] mode - File open mode
+ * @param[in] removeOnExit - File to be removed at exit or no
+ */
+ File(const std::string& filename, const std::string& mode,
+ bool removeExit = false) :
+ name(filename),
+ removeOnExit(removeExit)
+ {
+ fp = fopen(name.c_str(), mode.c_str());
+ }
+
+ /** @brief Opens file using provided file descriptor
+ *
+ * @param[in] fd - File descriptor
+ * @param[in] name - File name
+ * @param[in] mode - File open mode
+ * @param[in] removeOnExit - File to be removed at exit or no
+ */
+ File(int fd, const std::string& filename, const std::string& mode,
+ bool removeExit = false) :
+ name(filename),
+ removeOnExit(removeExit)
+ {
+ fp = fdopen(fd, mode.c_str());
+ }
+
+ ~File()
+ {
+ if (fp)
+ {
+ fclose(fp);
+ }
+
+ // Needed for exception safety
+ if (removeOnExit && std::filesystem::exists(name))
+ {
+ std::filesystem::remove(name);
+ }
+ }
+
+ auto operator()()
+ {
+ return fp;
+ }
+};