Vishwanatha Subbanna | 070a3e4 | 2017-09-06 11:40:45 +0530 | [diff] [blame^] | 1 | #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> |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace user |
| 12 | { |
| 13 | namespace shadow |
| 14 | { |
| 15 | |
| 16 | using InternalFailure = sdbusplus::xyz::openbmc_project::Common:: |
| 17 | Error::InternalFailure; |
| 18 | using namespace phosphor::logging; |
| 19 | |
| 20 | /** @class Lock |
| 21 | * @brief Responsible for locking and unlocking /etc/shadow |
| 22 | */ |
| 23 | class 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 |