summaryrefslogtreecommitdiffstats
path: root/shadowlock.hpp
blob: dc17b5a8d21d1f342af0ffaca6b8ccc78b61a5df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once

#include <stdio.h>
#include <cassert>
#include <phosphor-logging/log.hpp>
#include <phosphor-logging/elog.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
#include <phosphor-logging/elog-errors.hpp>
namespace phosphor
{
namespace user
{
namespace shadow
{

using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
                            Error::InternalFailure;
using namespace phosphor::logging;

/** @class Lock
 *  @brief Responsible for locking and unlocking /etc/shadow
 */
class Lock
{
    public:
        Lock(const Lock&) = delete;
        Lock& operator=(const Lock&) = delete;
        Lock(Lock&&) = delete;
        Lock& operator=(Lock&&) = delete;

        /** @brief Default constructor that just locks the shadow file */
        Lock()
        {
            if (!lckpwdf())
            {
                log<level::ERR>("Locking Shadow failed");
                elog<InternalFailure>();
            }
        }
        ~Lock()
        {
            if(!ulckpwdf())
            {
                log<level::ERR>("Un-Locking Shadow failed");
                elog<InternalFailure>();
            }
        }
};

} // namespace shadow
} // namespace user
} // namespace phosphor
OpenPOWER on IntegriCloud