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