1/* Copyright (C) 2010 The giomm Development Team 2 * 3 * This library is free software; you can redistribute it and/or 4 * modify it under the terms of the GNU Lesser General Public 5 * License as published by the Free Software Foundation; either 6 * version 2.1 of the License, or (at your option) any later version. 7 * 8 * This library 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 GNU 11 * Lesser General Public License for more details. 12 * 13 * You should have received a copy of the GNU Lesser General Public 14 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17#include <glibmm/object.h> 18#include <giomm/credentials.h> 19#include <giomm/iostream.h> 20 21_DEFS(giomm,gio) 22_PINCLUDE(glibmm/private/object_p.h) 23 24namespace Gio 25{ 26 27namespace DBus 28{ 29 30_GMMPROC_EXTRA_NAMESPACE(DBus) 31 32/** AuthObserver - An object used for authenticating connections. 33 * The AuthObserver type provides a mechanism for participating in how a 34 * Server (or a Connection) authenticates remote peers. Simply 35 * instantiate an AuthObserver and connect to the signals you are 36 * interested in. Note that new signals may be added in the future. 37 * 38 * For example, if you only want to allow D-Bus connections from 39 * processes owned by the same uid as the server, you would use a 40 * signal handler like the following: 41 * @code 42 * bool on_authorize_authenticated_peer( 43 * const Glib::RefPtr<const Gio::IOStream>&, 44 * const Glib::RefPtr<const Gio::Credentials>& credentials) 45 * { 46 * bool authorized = false; 47 * 48 * if (credentials) 49 * { 50 * Glib::RefPtr<Gio::Credentials> own_credentials = Gio::Credentials::create(); 51 * try 52 * { 53 * if (credentials->is_same_user(own_credentials)) 54 * authorized = true; 55 * } 56 * catch (const Gio::Error& ex) 57 * { 58 * std::cerr << "Gio::Error: " << ex.what() << std::endl; 59 * } 60 * } 61 * 62 * return authorized; 63 * } 64 * @endcode 65 * 66 * @newin{2,28} 67 * @ingroup DBus 68 */ 69class GIOMM_API AuthObserver : public Glib::Object 70{ 71 _CLASS_GOBJECT(AuthObserver, GDBusAuthObserver, G_DBUS_AUTH_OBSERVER, Glib::Object, GObject, , , GIOMM_API) 72 73protected: 74 _CTOR_DEFAULT 75 _IGNORE(g_dbus_auth_observer_new) 76 77public: 78 _WRAP_CREATE() 79 80 _WRAP_METHOD(bool authorize_authenticated_peer(const Glib::RefPtr<const IOStream>& stream, const Glib::RefPtr<const Credentials>& credentials), g_dbus_auth_observer_authorize_authenticated_peer) 81 _WRAP_METHOD(bool allow_mechanism(const std::string& mechanism), g_dbus_auth_observer_allow_mechanism) 82 83#m4 _CONVERSION(`GIOStream*', `const Glib::RefPtr<const IOStream>&', `Glib::wrap($3, true)') 84#m4 _CONVERSION(`GCredentials*', `const Glib::RefPtr<const Credentials>&', `Glib::wrap($3, true)') 85 _WRAP_SIGNAL(bool authorize_authenticated_peer(const Glib::RefPtr<const IOStream>& stream, const Glib::RefPtr<const Credentials>& credentials), "authorize-authenticated-peer", no_default_handler) 86 87 _WRAP_SIGNAL(bool allow_mechanism(const std::string& mechanism), allow_mechanism, no_default_handler) 88}; 89 90} //namespace DBus 91 92} // namespace Gio 93