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 
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 	 * Return: 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 an 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 	 * Return: The pointer to native credentials or %NULL if the
144 	 *     operation there is no #GCredentials support for the OS or if
145 	 *     @native_type isn't supported by the OS. Do not free the returned
146 	 *     data, it is owned 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.
162 	 *
163 	 * Return: The UNIX process ID, or -1 if @error is set.
164 	 *
165 	 * Since: 2.36
166 	 *
167 	 * Throws: GException on failure.
168 	 */
169 	public pid_t getUnixPid()
170 	{
171 		GError* err = null;
172 		
173 		auto p = g_credentials_get_unix_pid(gCredentials, &err);
174 		
175 		if (err !is null)
176 		{
177 			throw new GException( new ErrorG(err) );
178 		}
179 		
180 		return p;
181 	}
182 
183 	/**
184 	 * Tries to get the UNIX user identifier from @credentials. This
185 	 * method is only available on UNIX platforms.
186 	 *
187 	 * This operation can fail if #GCredentials is not supported on the
188 	 * OS or if the native credentials type does not contain information
189 	 * about the UNIX user.
190 	 *
191 	 * Return: The UNIX user identifier or -1 if @error is set.
192 	 *
193 	 * Since: 2.26
194 	 *
195 	 * Throws: GException on failure.
196 	 */
197 	public uid_t getUnixUser()
198 	{
199 		GError* err = null;
200 		
201 		auto p = g_credentials_get_unix_user(gCredentials, &err);
202 		
203 		if (err !is null)
204 		{
205 			throw new GException( new ErrorG(err) );
206 		}
207 		
208 		return p;
209 	}
210 
211 	/**
212 	 * Checks if @credentials and @other_credentials is the same user.
213 	 *
214 	 * This operation can fail if #GCredentials is not supported on the
215 	 * the OS.
216 	 *
217 	 * Params:
218 	 *     otherCredentials = A #GCredentials.
219 	 *
220 	 * Return: %TRUE if @credentials and @other_credentials has the same
221 	 *     user, %FALSE otherwise or if @error is set.
222 	 *
223 	 * Since: 2.26
224 	 *
225 	 * Throws: GException on failure.
226 	 */
227 	public bool isSameUser(Credentials otherCredentials)
228 	{
229 		GError* err = null;
230 		
231 		auto p = g_credentials_is_same_user(gCredentials, (otherCredentials is null) ? null : otherCredentials.getCredentialsStruct(), &err) != 0;
232 		
233 		if (err !is null)
234 		{
235 			throw new GException( new ErrorG(err) );
236 		}
237 		
238 		return p;
239 	}
240 
241 	/**
242 	 * Copies the native credentials of type @native_type from @native
243 	 * into @credentials.
244 	 *
245 	 * It is a programming error (which will cause an warning to be
246 	 * logged) to use this method if there is no #GCredentials support for
247 	 * the OS or if @native_type isn't supported by the OS.
248 	 *
249 	 * Params:
250 	 *     nativeType = The type of native credentials to set.
251 	 *     native = A pointer to native credentials.
252 	 *
253 	 * Since: 2.26
254 	 */
255 	public void setNative(GCredentialsType nativeType, void* native)
256 	{
257 		g_credentials_set_native(gCredentials, nativeType, native);
258 	}
259 
260 	/**
261 	 * Tries to set the UNIX user identifier on @credentials. This method
262 	 * is only available on UNIX platforms.
263 	 *
264 	 * This operation can fail if #GCredentials is not supported on the
265 	 * OS or if the native credentials type does not contain information
266 	 * about the UNIX user. It can also fail if the OS does not allow the
267 	 * use of "spoofed" credentials.
268 	 *
269 	 * Params:
270 	 *     uid = The UNIX user identifier to set.
271 	 *
272 	 * Return: %TRUE if @uid was set, %FALSE if error is set.
273 	 *
274 	 * Since: 2.26
275 	 *
276 	 * Throws: GException on failure.
277 	 */
278 	public bool setUnixUser(uid_t uid)
279 	{
280 		GError* err = null;
281 		
282 		auto p = g_credentials_set_unix_user(gCredentials, uid, &err) != 0;
283 		
284 		if (err !is null)
285 		{
286 			throw new GException( new ErrorG(err) );
287 		}
288 		
289 		return p;
290 	}
291 
292 	/**
293 	 * Creates a human-readable textual representation of @credentials
294 	 * that can be used in logging and debug messages. The format of the
295 	 * returned string may change in future GLib release.
296 	 *
297 	 * Return: A string that should be freed with g_free().
298 	 *
299 	 * Since: 2.26
300 	 */
301 	public override string toString()
302 	{
303 		return Str.toString(g_credentials_to_string(gCredentials));
304 	}
305 }