blob: c869acaa06bf2e8c1bf73b13664244134b35c2a8 [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 =
Willy Tu523e2d12023-09-05 11:36:48 -070015 sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053016using 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