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 public import gtkc.giotypes; 36 private import std.algorithm; 37 38 39 /** 40 * The #GDBusAuthObserver type provides a mechanism for participating 41 * in how a #GDBusServer (or a #GDBusConnection) authenticates remote 42 * peers. Simply instantiate a #GDBusAuthObserver and connect to the 43 * signals you are interested in. Note that new signals may be added 44 * in the future 45 * 46 * ## Controlling Authentication Mechanisms 47 * 48 * By default, a #GDBusServer or server-side #GDBusConnection will allow 49 * any authentication mechanism to be used. If you only 50 * want to allow D-Bus connections with the `EXTERNAL` mechanism, 51 * which makes use of credentials passing and is the recommended 52 * mechanism for modern Unix platforms such as Linux and the BSD family, 53 * you would use a signal handler like this: 54 * 55 * |[<!-- language="C" --> 56 * static gboolean 57 * on_allow_mechanism (GDBusAuthObserver *observer, 58 * const gchar *mechanism, 59 * gpointer user_data) 60 * { 61 * if (g_strcmp0 (mechanism, "EXTERNAL") == 0) 62 * { 63 * return TRUE; 64 * } 65 * 66 * return FALSE; 67 * } 68 * ]| 69 * 70 * ## Controlling Authorization # {#auth-observer} 71 * 72 * By default, a #GDBusServer or server-side #GDBusConnection will accept 73 * connections from any successfully authenticated user (but not from 74 * anonymous connections using the `ANONYMOUS` mechanism). If you only 75 * want to allow D-Bus connections from processes owned by the same uid 76 * as the server, you would use a signal handler like the following: 77 * 78 * |[<!-- language="C" --> 79 * static gboolean 80 * on_authorize_authenticated_peer (GDBusAuthObserver *observer, 81 * GIOStream *stream, 82 * GCredentials *credentials, 83 * gpointer user_data) 84 * { 85 * gboolean authorized; 86 * 87 * authorized = FALSE; 88 * if (credentials != NULL) 89 * { 90 * GCredentials *own_credentials; 91 * own_credentials = g_credentials_new (); 92 * if (g_credentials_is_same_user (credentials, own_credentials, NULL)) 93 * authorized = TRUE; 94 * g_object_unref (own_credentials); 95 * } 96 * 97 * return authorized; 98 * } 99 * ]| 100 * 101 * Since: 2.26 102 */ 103 public class DBusAuthObserver : ObjectG 104 { 105 /** the main Gtk struct */ 106 protected GDBusAuthObserver* gDBusAuthObserver; 107 108 /** Get the main Gtk struct */ 109 public GDBusAuthObserver* getDBusAuthObserverStruct(bool transferOwnership = false) 110 { 111 if (transferOwnership) 112 ownedRef = false; 113 return gDBusAuthObserver; 114 } 115 116 /** the main Gtk struct as a void* */ 117 protected override void* getStruct() 118 { 119 return cast(void*)gDBusAuthObserver; 120 } 121 122 /** 123 * Sets our main struct and passes it to the parent class. 124 */ 125 public this (GDBusAuthObserver* gDBusAuthObserver, bool ownedRef = false) 126 { 127 this.gDBusAuthObserver = gDBusAuthObserver; 128 super(cast(GObject*)gDBusAuthObserver, ownedRef); 129 } 130 131 132 /** */ 133 public static GType getType() 134 { 135 return g_dbus_auth_observer_get_type(); 136 } 137 138 /** 139 * Creates a new #GDBusAuthObserver object. 140 * 141 * Returns: A #GDBusAuthObserver. Free with g_object_unref(). 142 * 143 * Since: 2.26 144 * 145 * Throws: ConstructionException GTK+ fails to create the object. 146 */ 147 public this() 148 { 149 auto __p = g_dbus_auth_observer_new(); 150 151 if(__p is null) 152 { 153 throw new ConstructionException("null returned by new"); 154 } 155 156 this(cast(GDBusAuthObserver*) __p, true); 157 } 158 159 /** 160 * Emits the #GDBusAuthObserver::allow-mechanism signal on @observer. 161 * 162 * Params: 163 * mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`. 164 * 165 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not. 166 * 167 * Since: 2.34 168 */ 169 public bool allowMechanism(string mechanism) 170 { 171 return g_dbus_auth_observer_allow_mechanism(gDBusAuthObserver, Str.toStringz(mechanism)) != 0; 172 } 173 174 /** 175 * Emits the #GDBusAuthObserver::authorize-authenticated-peer signal on @observer. 176 * 177 * Params: 178 * stream = A #GIOStream for the #GDBusConnection. 179 * credentials = Credentials received from the peer or %NULL. 180 * 181 * Returns: %TRUE if the peer is authorized, %FALSE if not. 182 * 183 * Since: 2.26 184 */ 185 public bool authorizeAuthenticatedPeer(IOStream stream, Credentials credentials) 186 { 187 return g_dbus_auth_observer_authorize_authenticated_peer(gDBusAuthObserver, (stream is null) ? null : stream.getIOStreamStruct(), (credentials is null) ? null : credentials.getCredentialsStruct()) != 0; 188 } 189 190 /** 191 * Emitted to check if @mechanism is allowed to be used. 192 * 193 * Params: 194 * mechanism = The name of the mechanism, e.g. `DBUS_COOKIE_SHA1`. 195 * 196 * Returns: %TRUE if @mechanism can be used to authenticate the other peer, %FALSE if not. 197 * 198 * Since: 2.34 199 */ 200 gulong addOnAllowMechanism(bool delegate(string, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 201 { 202 return Signals.connect(this, "allow-mechanism", dlg, connectFlags ^ ConnectFlags.SWAPPED); 203 } 204 205 /** 206 * Emitted to check if a peer that is successfully authenticated 207 * is authorized. 208 * 209 * Params: 210 * stream = A #GIOStream for the #GDBusConnection. 211 * credentials = Credentials received from the peer or %NULL. 212 * 213 * Returns: %TRUE if the peer is authorized, %FALSE if not. 214 * 215 * Since: 2.26 216 */ 217 gulong addOnAuthorizeAuthenticatedPeer(bool delegate(IOStream, Credentials, DBusAuthObserver) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 218 { 219 return Signals.connect(this, "authorize-authenticated-peer", dlg, connectFlags ^ ConnectFlags.SWAPPED); 220 } 221 }