blob: 8b09f21b4e6baa305185fbded1183b685845cb2a [file] [log] [blame]
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +05301#pragma once
2
3#include <shadow.h>
4
5#include <phosphor-logging/elog-errors.hpp>
6#include <xyz/openbmc_project/Common/error.hpp>
7namespace phosphor
8{
9namespace user
10{
11namespace shadow
12{
13
14using InternalFailure =
15 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
16using namespace phosphor::logging;
17
18/** @class Lock
19 * @brief Responsible for locking and unlocking /etc/shadow
20 */
21class Lock
22{
23 public:
24 Lock(const Lock&) = delete;
25 Lock& operator=(const Lock&) = delete;
26 Lock(Lock&&) = delete;
27 Lock& operator=(Lock&&) = delete;
28
29 /** @brief Default constructor that just locks the shadow file */
30 Lock()
31 {
32 if (!lckpwdf())
33 {
34 log<level::ERR>("Locking Shadow failed");
35 elog<InternalFailure>();
36 }
37 }
38 ~Lock()
39 {
40 if (!ulckpwdf())
41 {
42 log<level::ERR>("Un-Locking Shadow failed");
43 elog<InternalFailure>();
44 }
45 }
46};
47
48} // namespace shadow
49} // namespace user
50} // namespace phosphor