Music Hub  ..
A session-wide music playback service
apparmor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013-2014 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Author: Jim Hodapp <jim.hodapp@canonical.com>
17  */
18 
19 #ifndef APPARMOR_DBUS_H_
20 #define APPARMOR_DBUS_H_
21 
22 #include <core/dbus/macros.h>
23 #include <core/dbus/object.h>
24 #include <core/dbus/service.h>
25 
26 #include <string>
27 #include <chrono>
28 
29 // TODO(tvoss): This really should live in trust-store, providing a straightforward
30 // way for parties involved in managing trust relationships to query peers' apparmor
31 // profiles. Please see https://bugs.launchpad.net/trust-store/+bug/1350736 for the
32 // related bug
33 namespace org
34 {
35 namespace freedesktop
36 {
37 namespace dbus
38 {
39 struct DBus
40 {
41  static const std::string& name()
42  {
43  static const std::string s = "org.freedesktop.DBus";
44  return s;
45  }
46 
47  // Gets the AppArmor confinement string associated with the unique connection name. If
48  // D-Bus is not performing AppArmor mediation, the
49  // org.freedesktop.DBus.Error.AppArmorSecurityContextUnknown error is returned.
50  DBUS_CPP_METHOD_DEF(GetConnectionAppArmorSecurityContext, DBus)
51 
52  struct Stub
53  {
54  // Creates a new stub instance for the given object to access
55  // DBus functionality.
56  Stub(const core::dbus::Object::Ptr& object) : object{object}
57  {
58  }
59 
60  // Creates a new stub instance for the given bus connection
61  Stub(const core::dbus::Bus::Ptr& bus)
62  : object
63  {
64  core::dbus::Service::use_service<org::freedesktop::dbus::DBus>(bus)
65  ->object_for_path(core::dbus::types::ObjectPath{"/org/freedesktop/DBus"})
66  }
67  {
68  }
69 
70  // Gets the AppArmor confinement string associated with the unique connection name. If
71  // D-Bus is not performing AppArmor mediation, the
72  // org.freedesktop.DBus.Error.AppArmorSecurityContextUnknown error is returned.
73  //
74  // Invokes the given handler on completion.
76  const std::string& name,
77  std::function<void(const std::string&)> handler)
78  {
79  object->invoke_method_asynchronously_with_callback<GetConnectionAppArmorSecurityContext, std::string>(
80  [handler](const core::dbus::Result<std::string>& result)
81  {
82  if (not result.is_error()) handler(result.value());
83  }, name);
84  }
85 
86  core::dbus::Object::Ptr object;
87  };
88 };
89 }
90 }
91 }
92 
93 #endif // APPARMOR_DBUS_H_
Stub(const core::dbus::Bus::Ptr &bus)
Definition: apparmor.h:61
core::dbus::Object::Ptr object
Definition: apparmor.h:86
Definition: apparmor.h:33
Stub(const core::dbus::Object::Ptr &object)
Definition: apparmor.h:56
void get_connection_app_armor_security_async(const std::string &name, std::function< void(const std::string &)> handler)
Definition: apparmor.h:75
static const std::string & name()
Definition: apparmor.h:41