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