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