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