xref: /openbmc/bmcweb/include/user_monitor.hpp (revision d78572018fc2022091ff8b8eb5a7fef2172ba3d6)
1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #pragma once
4 #include "dbus_singleton.hpp"
5 #include "sessions.hpp"
6 
7 #include <sdbusplus/bus/match.hpp>
8 #include <sdbusplus/message.hpp>
9 #include <sdbusplus/message/native_types.hpp>
10 
11 #include <string>
12 
13 namespace bmcweb
14 {
15 
onUserRemoved(sdbusplus::message_t & msg)16 inline void onUserRemoved(sdbusplus::message_t& msg)
17 {
18     sdbusplus::message::object_path p;
19     msg.read(p);
20     std::string username = p.filename();
21     persistent_data::SessionStore::getInstance().removeSessionsByUsername(
22         username);
23 }
24 
registerUserRemovedSignal()25 inline void registerUserRemovedSignal()
26 {
27     std::string userRemovedMatchStr =
28         sdbusplus::bus::match::rules::interfacesRemoved(
29             "/xyz/openbmc_project/user");
30 
31     static sdbusplus::bus::match_t userRemovedMatch(
32         *crow::connections::systemBus, userRemovedMatchStr, onUserRemoved);
33 }
34 } // namespace bmcweb
35