1 #pragma once
2 
3 #include <shadow.h>
4 
5 #include <phosphor-logging/elog-errors.hpp>
6 #include <xyz/openbmc_project/Common/error.hpp>
7 namespace phosphor
8 {
9 namespace user
10 {
11 namespace shadow
12 {
13 
14 using InternalFailure =
15     sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
16 using namespace phosphor::logging;
17 
18 /** @class Lock
19  *  @brief Responsible for locking and unlocking /etc/shadow
20  */
21 class 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 */
Lock()30     Lock()
31     {
32         if (!lckpwdf())
33         {
34             log<level::ERR>("Locking Shadow failed");
35             elog<InternalFailure>();
36         }
37     }
~Lock()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
51