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