Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <shadow.h> |
| 4 | |
| 5 | #include <phosphor-logging/elog-errors.hpp> |
George Liu | 82844ef | 2024-07-17 17:03:56 +0800 | [diff] [blame] | 6 | #include <phosphor-logging/lg2.hpp> |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 7 | #include <xyz/openbmc_project/Common/error.hpp> |
| 8 | namespace phosphor |
| 9 | { |
| 10 | namespace user |
| 11 | { |
| 12 | namespace shadow |
| 13 | { |
| 14 | |
| 15 | using InternalFailure = |
Willy Tu | 523e2d1 | 2023-09-05 11:36:48 -0700 | [diff] [blame] | 16 | sdbusplus::error::xyz::openbmc_project::common::InternalFailure; |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 17 | using namespace phosphor::logging; |
| 18 | |
| 19 | /** @class Lock |
| 20 | * @brief Responsible for locking and unlocking /etc/shadow |
| 21 | */ |
| 22 | class 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 Liu | 82844ef | 2024-07-17 17:03:56 +0800 | [diff] [blame] | 35 | lg2::error("Locking Shadow failed"); |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 36 | elog<InternalFailure>(); |
| 37 | } |
| 38 | } |
| 39 | ~Lock() |
| 40 | { |
| 41 | if (!ulckpwdf()) |
| 42 | { |
George Liu | 82844ef | 2024-07-17 17:03:56 +0800 | [diff] [blame] | 43 | lg2::error("Un-Locking Shadow failed"); |
Richard Marian Thomaiyar | 4654d99 | 2018-04-19 05:38:37 +0530 | [diff] [blame] | 44 | elog<InternalFailure>(); |
| 45 | } |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | } // namespace shadow |
| 50 | } // namespace user |
| 51 | } // namespace phosphor |