1 #pragma once 2 3 #include <stdio.h> 4 #include <cassert> 5 #include <shadow.h> 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 17 using InternalFailure = 18 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; 19 using namespace phosphor::logging; 20 21 /** @class Lock 22 * @brief Responsible for locking and unlocking /etc/shadow 23 */ 24 class Lock 25 { 26 public: 27 Lock(const Lock&) = delete; 28 Lock& operator=(const Lock&) = delete; 29 Lock(Lock&&) = delete; 30 Lock& operator=(Lock&&) = delete; 31 32 /** @brief Default constructor that just locks the shadow file */ 33 Lock() 34 { 35 if (!lckpwdf()) 36 { 37 log<level::ERR>("Locking Shadow failed"); 38 elog<InternalFailure>(); 39 } 40 } 41 ~Lock() 42 { 43 if (!ulckpwdf()) 44 { 45 log<level::ERR>("Un-Locking Shadow failed"); 46 elog<InternalFailure>(); 47 } 48 } 49 }; 50 51 } // namespace shadow 52 } // namespace user 53 } // namespace phosphor 54