1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gio.DBusAuthObserver; 26 27 private import gio.Credentials; 28 private import gio.IOStream; 29 private import gio.c.functions; 30 public import gio.c.types; 31 private import glib.ConstructionException; 32 private import glib.Str; 33 private import gobject.ObjectG; 34 private import gobject.Signals; 35 private import std.algorithm; 36 37 38 /** 39 * The #GDBusAuthObserver type provides a mechanism for participating 40 * in how a #GDBusServer (or a #GDBusConnection) authenticates remote 41 * peers. Simply instantiate a #GDBusAuthObserver and connect to the 42 * signals you are interested in. Note that new signals may be added 43 * in the future 44 * 45 * ## Controlling Authentication Mechanisms 46 * 47 * By default, a #GDBusServer or server-side #GDBusConnection will allow 48 * any authentication mechanism to be used. If you only 49 * want to allow D-Bus connections with the `EXTERNAL` mechanism, 50 * which makes use of credentials passing and is the recommended 51 * mechanism for modern Unix platforms such as Linux and the BSD family, 52 * you would use a signal handler like this: 53 * 54 * |[<!-- language="C" --> 55 * static gboolean 56 * on_allow_mechanism (GDBusAuthObserver *observer, 57 * const gchar *mechanism, 58 * gpointer user_data) 59 * { 60 * if (g_strcmp0 (mechanism, "EXTERNAL") == 0) 61 * { 62 * return TRUE; 63 * } 64 * 65 * return FALSE; 66 * } 67 * ]| 68 * 69 * ## Controlling Authorization # {#auth-observer} 70 * 71 * By default, a #GDBusServer or server-side #GDBusConnection will accept 72 * connections from any successfully authenticated user (but not from 73 * anonymous connections using the `ANONYMOUS` mechanism). If you only 74 * want to allow D-Bus connections from processes owned by the same uid 75 * as the server, since GLib 2.68, you should use the 76 * %G_DBUS_SERVER_FLAGS_AUTHENTICATION_REQUIRE_SAME_USER flag. It’s equivalent 77 * to the following signal handler: 78 * 79 * |[<!-- language="C" --> 80 * static gboolean 81 * on_authorize_authenticated_peer (GDBusAuthObserver *observer, 82 * GIOStream *stream, 83 * GCredentials *credentials, 84 * gpointer user_data) 85 * { 86 * gboolean authorized; 87 * 88 * authorized = FALSE; 89 * if (credentials != NULL) 90 * { 91 * GCredentials *own_credentials; 92 * own_credentials = g_credentials_new (); 93 * if (g_credentials_is_same_user (credentials, own_credentials, NULL)) 94 * authorized = TRUE; 95 * g_object_unref (own_credentials); 96 * } 97 * 98 * return authorized; 99 * } 100 * ]| 101 * 102 * Since: 2.26 103 */ 104 public class DBusAuthObserver : ObjectG 105 { 106 /** the main Gtk struct */ 107 protected GDBusAuthObserver* gDBusAuthObserver; 108 109 /** Get the main Gtk struct */ 110 public GDBusAuthObserver* getDBusAuthObserverStruct(bool transferOwnership = false) 111 { 112 if (transferOwnership) 113 ownedRef = false; 114 return gDBusAuthObserver; 115 } 116 117 /** the main Gtk struct as a void* */ 118 protected override void* getStruct() 119 { 120 return cast(void*)gDBusAuthObserver; 121 } 122 123 /** 124 * Sets our main struct and passes it to the parent class. 125 */ 126 public this (GDBusAuthObserver* gDBusAuthObserver, bool ownedRef = false) 127 { 128 this.gDBusAuthObserver = gDBusAuthObserver; 129 super(cast(GObject*)gDBusAuthObserver, ownedRef); 130 } 131 132 133 /** */ 134 public static GType getType() 135 { 136 return g_dbus_auth_observer_get_type(); 137 } 138 139 /** 140 * Creates a new #GDBusAuthObserver object. 141 * 142 * Returns: A #GDBusAuthObserver. Free with g_object_unref(). 143 * 144 * Since: 2.26 145 * 146 * Throws: ConstructionException GTK+ fails to create the object. 147 */ 148 public this() 149 { 150 auto __p = g_dbus_auth_observer_new(); 151 152 if(__p is null) 153 { 154 throw new ConstructionException("null returned by new"); 155 } 156 157 this(cast(GDBusAuthObserver*) __p, true); 158 } 159 160 /** 161 * Emits the #GDBusAuthObserver::allow-mechanism signal on @observer. 162 * 163 * Params: 164 * mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`. 165 * 166 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not. 167 * 168 * Since: 2.34 169 */ 170 public bool allowMechanism(string mechanism) 171 { 172 return g_dbus_auth_observer_allow_mechanism(gDBusAuthObserver, Str.toStringz(mechanism)) != 0; 173 } 174 175 /** 176 * Emits the #GDBusAuthObserver::authorize-authenticated-peer signal on @observer. 177 * 178 * Params: 179 * stream = A #GIOStream for the #GDBusConnection. 180 * credentials = Credentials received from the peer or %NULL. 181 * 182 * Returns: %TRUE if the peer is authorized, %FALSE if not. 183 * 184 * Since: 2.26 185 */ 186 public bool authorizeAuthenticatedPeer(IOStream stream, Credentials credentials) 187 { 188 return g_dbus_auth_observer_authorize_authenticated_peer(gDBusAuthObserver, (stream is null) ? null : stream.getIOStreamStruct(), (credentials is null) ? null : credentials.getCredentialsStruct()) != 0; 189 } 190 191 /** 192 * Emitted to check if @mechanism is allowed to be used. 193 * 194 * Params: 195 * mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`. 196 * 197 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not. 198 * 199 * Since: 2.34 200 */ 201 gulong addOnAllowMechanism(bool delegate(string, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 202 { 203 return Signals.connect(this, "allow-mechanism", dlg, connectFlags ^ ConnectFlags.SWAPPED); 204 } 205 206 /** 207 * Emitted to check if a peer that is successfully authenticated 208 * is authorized. 209 * 210 * Params: 211 * stream = A #GIOStream for the #GDBusConnection. 212 * credentials = Credentials received from the peer or %NULL. 213 * 214 * Returns: %TRUE if the peer is authorized, %FALSE if not. 215 * 216 * Since: 2.26 217 */ 218 gulong addOnAuthorizeAuthenticatedPeer(bool delegate(IOStream, Credentials, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 219 { 220 return Signals.connect(this, "authorize-authenticated-peer", dlg, connectFlags ^ ConnectFlags.SWAPPED); 221 } 222 }