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