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 * Conversion parameters: 26 * inFile = GCredentials.html 27 * outPack = gio 28 * outFile = Credentials 29 * strct = GCredentials 30 * realStrct= 31 * ctorStrct= 32 * clss = Credentials 33 * interf = 34 * class Code: No 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - g_credentials_ 41 * omit structs: 42 * omit prefixes: 43 * omit code: 44 * omit signals: 45 * imports: 46 * - glib.Str 47 * - glib.ErrorG 48 * - glib.GException 49 * structWrap: 50 * - GCredentials* -> Credentials 51 * module aliases: 52 * local aliases: 53 * overrides: 54 * - toString 55 */ 56 57 module gio.Credentials; 58 59 public import gtkc.giotypes; 60 61 private import gtkc.gio; 62 private import glib.ConstructionException; 63 private import gobject.ObjectG; 64 65 66 private import glib.Str; 67 private import glib.ErrorG; 68 private import glib.GException; 69 70 71 72 private import gobject.ObjectG; 73 74 /** 75 * The GCredentials type is a reference-counted wrapper for native 76 * credentials. This information is typically used for identifying, 77 * authenticating and authorizing other processes. 78 * 79 * Some operating systems supports looking up the credentials of the 80 * remote peer of a communication endpoint - see e.g. 81 * g_socket_get_credentials(). 82 * 83 * Some operating systems supports securely sending and receiving 84 * credentials over a Unix Domain Socket, see 85 * GUnixCredentialsMessage, g_unix_connection_send_credentials() and 86 * g_unix_connection_receive_credentials() for details. 87 * 88 * On Linux, the native credential type is a struct ucred 89 * 90 * see the 91 * unix(7) 92 * man page for details. This corresponds to 93 * G_CREDENTIALS_TYPE_LINUX_UCRED. 94 * 95 * On FreeBSD, the native credential type is a struct cmsgcred. 96 * This corresponds to G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED. 97 * 98 * On OpenBSD, the native credential type is a struct sockpeercred. 99 * This corresponds to G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED. 100 */ 101 public class Credentials : ObjectG 102 { 103 104 /** the main Gtk struct */ 105 protected GCredentials* gCredentials; 106 107 108 public GCredentials* getCredentialsStruct() 109 { 110 return gCredentials; 111 } 112 113 114 /** the main Gtk struct as a void* */ 115 protected override void* getStruct() 116 { 117 return cast(void*)gCredentials; 118 } 119 120 /** 121 * Sets our main struct and passes it to the parent class 122 */ 123 public this (GCredentials* gCredentials) 124 { 125 super(cast(GObject*)gCredentials); 126 this.gCredentials = gCredentials; 127 } 128 129 protected override void setStruct(GObject* obj) 130 { 131 super.setStruct(obj); 132 gCredentials = cast(GCredentials*)obj; 133 } 134 135 /** 136 */ 137 138 /** 139 * Creates a new GCredentials object with credentials matching the 140 * the current process. 141 * Since 2.26 142 * Throws: ConstructionException GTK+ fails to create the object. 143 */ 144 public this () 145 { 146 // GCredentials * g_credentials_new (void); 147 auto p = g_credentials_new(); 148 if(p is null) 149 { 150 throw new ConstructionException("null returned by g_credentials_new()"); 151 } 152 this(cast(GCredentials*) p); 153 } 154 155 /** 156 * Creates a human-readable textual representation of credentials 157 * that can be used in logging and debug messages. The format of the 158 * returned string may change in future GLib release. 159 * Since 2.26 160 * Returns: A string that should be freed with g_free(). 161 */ 162 public override string toString() 163 { 164 // gchar * g_credentials_to_string (GCredentials *credentials); 165 return Str.toString(g_credentials_to_string(gCredentials)); 166 } 167 168 /** 169 * Gets a pointer to native credentials of type native_type from 170 * credentials. 171 * It is a programming error (which will cause an warning to be 172 * logged) to use this method if there is no GCredentials support for 173 * the OS or if native_type isn't supported by the OS. 174 * Since 2.26 175 * Params: 176 * nativeType = The type of native credentials to get. 177 * Returns: The pointer to native credentials or NULL if the operation there is no GCredentials support for the OS or if native_type isn't supported by the OS. Do not free the returned data, it is owned by credentials. 178 */ 179 public void* getNative(GCredentialsType nativeType) 180 { 181 // gpointer g_credentials_get_native (GCredentials *credentials, GCredentialsType native_type); 182 return g_credentials_get_native(gCredentials, nativeType); 183 } 184 185 /** 186 * Copies the native credentials of type native_type from native 187 * into credentials. 188 * It is a programming error (which will cause an warning to be 189 * logged) to use this method if there is no GCredentials support for 190 * the OS or if native_type isn't supported by the OS. 191 * Since 2.26 192 * Params: 193 * nativeType = The type of native credentials to set. 194 * native = A pointer to native credentials. 195 */ 196 public void setNative(GCredentialsType nativeType, void* native) 197 { 198 // void g_credentials_set_native (GCredentials *credentials, GCredentialsType native_type, gpointer native); 199 g_credentials_set_native(gCredentials, nativeType, native); 200 } 201 202 /** 203 * Checks if credentials and other_credentials is the same user. 204 * This operation can fail if GCredentials is not supported on the 205 * the OS. 206 * Since 2.26 207 * Params: 208 * otherCredentials = A GCredentials. 209 * Returns: TRUE if credentials and other_credentials has the same user, FALSE otherwise or if error is set. 210 * Throws: GException on failure. 211 */ 212 public int isSameUser(Credentials otherCredentials) 213 { 214 // gboolean g_credentials_is_same_user (GCredentials *credentials, GCredentials *other_credentials, GError **error); 215 GError* err = null; 216 217 auto p = g_credentials_is_same_user(gCredentials, (otherCredentials is null) ? null : otherCredentials.getCredentialsStruct(), &err); 218 219 if (err !is null) 220 { 221 throw new GException( new ErrorG(err) ); 222 } 223 224 return p; 225 } 226 227 /** 228 * Tries to get the UNIX user identifier from credentials. This 229 * method is only available on UNIX platforms. 230 * This operation can fail if GCredentials is not supported on the 231 * OS or if the native credentials type does not contain information 232 * about the UNIX user. 233 * Since 2.26 234 * Returns: The UNIX user identifier or -1 if error is set. 235 * Throws: GException on failure. 236 */ 237 public uid_t getUnixUser() 238 { 239 // uid_t g_credentials_get_unix_user (GCredentials *credentials, GError **error); 240 GError* err = null; 241 242 auto p = g_credentials_get_unix_user(gCredentials, &err); 243 244 if (err !is null) 245 { 246 throw new GException( new ErrorG(err) ); 247 } 248 249 return p; 250 } 251 252 /** 253 * Tries to set the UNIX user identifier on credentials. This method 254 * is only available on UNIX platforms. 255 * This operation can fail if GCredentials is not supported on the 256 * OS or if the native credentials type does not contain information 257 * about the UNIX user. 258 * Since 2.26 259 * Params: 260 * uid = The UNIX user identifier to set. 261 * Returns: TRUE if uid was set, FALSE if error is set. 262 * Throws: GException on failure. 263 */ 264 public int setUnixUser(uid_t uid) 265 { 266 // gboolean g_credentials_set_unix_user (GCredentials *credentials, uid_t uid, GError **error); 267 GError* err = null; 268 269 auto p = g_credentials_set_unix_user(gCredentials, uid, &err); 270 271 if (err !is null) 272 { 273 throw new GException( new ErrorG(err) ); 274 } 275 276 return p; 277 } 278 279 /** 280 * Tries to get the UNIX process identifier from credentials. This 281 * method is only available on UNIX platforms. 282 * This operation can fail if GCredentials is not supported on the 283 * OS or if the native credentials type does not contain information 284 * about the UNIX process ID. 285 * Since 2.36 286 * Returns: The UNIX process ID, or -1 if error is set. 287 * Throws: GException on failure. 288 */ 289 public pid_t getUnixPid() 290 { 291 // pid_t g_credentials_get_unix_pid (GCredentials *credentials, GError **error); 292 GError* err = null; 293 294 auto p = g_credentials_get_unix_pid(gCredentials, &err); 295 296 if (err !is null) 297 { 298 throw new GException( new ErrorG(err) ); 299 } 300 301 return p; 302 } 303 }