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