summaryrefslogtreecommitdiffstats
path: root/shadowlock.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'shadowlock.hpp')
-rw-r--r--shadowlock.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/shadowlock.hpp b/shadowlock.hpp
new file mode 100644
index 0000000..dc17b5a
--- /dev/null
+++ b/shadowlock.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <stdio.h>
+#include <cassert>
+#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
+#include <phosphor-logging/elog-errors.hpp>
+namespace phosphor
+{
+namespace user
+{
+namespace shadow
+{
+
+using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
+ Error::InternalFailure;
+using namespace phosphor::logging;
+
+/** @class Lock
+ * @brief Responsible for locking and unlocking /etc/shadow
+ */
+class Lock
+{
+ public:
+ Lock(const Lock&) = delete;
+ Lock& operator=(const Lock&) = delete;
+ Lock(Lock&&) = delete;
+ Lock& operator=(Lock&&) = delete;
+
+ /** @brief Default constructor that just locks the shadow file */
+ Lock()
+ {
+ if (!lckpwdf())
+ {
+ log<level::ERR>("Locking Shadow failed");
+ elog<InternalFailure>();
+ }
+ }
+ ~Lock()
+ {
+ if(!ulckpwdf())
+ {
+ log<level::ERR>("Un-Locking Shadow failed");
+ elog<InternalFailure>();
+ }
+ }
+};
+
+} // namespace shadow
+} // namespace user
+} // namespace phosphor
OpenPOWER on IntegriCloud