source: appstream-generator/build/girepo/gio/Credentials.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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