blob: 1dc5f3b66034e76feac2669eb76b1486a67845a3 [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>
George Liu82844ef2024-07-17 17:03:56 +08006#include <phosphor-logging/lg2.hpp>
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +05307#include <xyz/openbmc_project/Common/error.hpp>
8namespace phosphor
9{
10namespace user
11{
12namespace shadow
13{
14
15using InternalFailure =
Willy Tu523e2d12023-09-05 11:36:48 -070016 sdbusplus::error::xyz::openbmc_project::common::InternalFailure;
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053017using namespace phosphor::logging;
18
19/** @class Lock
20 * @brief Responsible for locking and unlocking /etc/shadow
21 */
22class 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 */
31 Lock()
32 {
33 if (!lckpwdf())
34 {
George Liu82844ef2024-07-17 17:03:56 +080035 lg2::error("Locking Shadow failed");
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053036 elog<InternalFailure>();
37 }
38 }
39 ~Lock()
40 {
41 if (!ulckpwdf())
42 {
George Liu82844ef2024-07-17 17:03:56 +080043 lg2::error("Un-Locking Shadow failed");
Richard Marian Thomaiyar4654d992018-04-19 05:38:37 +053044 elog<InternalFailure>();
45 }
46 }
47};
48
49} // namespace shadow
50} // namespace user
51} // namespace phosphor