gio/
credentials.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ffi, Credentials, CredentialsType};
6
7impl Credentials {
8    #[doc(alias = "g_credentials_get_native")]
9    #[doc(alias = "get_native")]
10    pub fn native(&self, native_type: CredentialsType) -> glib::ffi::gpointer {
11        unsafe { ffi::g_credentials_get_native(self.to_glib_none().0, native_type.into_glib()) }
12    }
13
14    #[cfg(unix)]
15    #[cfg_attr(docsrs, doc(cfg(unix)))]
16    #[doc(alias = "g_credentials_get_unix_pid")]
17    #[doc(alias = "get_unix_pid")]
18    pub fn unix_pid(&self) -> Result<libc::pid_t, glib::Error> {
19        unsafe {
20            let mut error = std::ptr::null_mut();
21            let ret = ffi::g_credentials_get_unix_pid(self.to_glib_none().0, &mut error);
22            if error.is_null() {
23                Ok(ret)
24            } else {
25                Err(from_glib_full(error))
26            }
27        }
28    }
29
30    #[cfg(unix)]
31    #[cfg_attr(docsrs, doc(cfg(unix)))]
32    #[doc(alias = "g_credentials_get_unix_user")]
33    #[doc(alias = "get_unix_user")]
34    pub fn unix_user(&self) -> Result<libc::uid_t, glib::Error> {
35        unsafe {
36            let mut error = std::ptr::null_mut();
37            let ret = ffi::g_credentials_get_unix_user(self.to_glib_none().0, &mut error);
38            if error.is_null() {
39                Ok(ret)
40            } else {
41                Err(from_glib_full(error))
42            }
43        }
44    }
45
46    #[doc(alias = "g_credentials_set_native")]
47    pub unsafe fn set_native(&self, native_type: CredentialsType, native: glib::ffi::gpointer) {
48        unsafe {
49            ffi::g_credentials_set_native(self.to_glib_none().0, native_type.into_glib(), native)
50        }
51    }
52
53    #[cfg(unix)]
54    #[cfg_attr(docsrs, doc(cfg(unix)))]
55    #[doc(alias = "g_credentials_set_unix_user")]
56    pub fn set_unix_user(&self, uid: libc::uid_t) -> Result<(), glib::Error> {
57        unsafe {
58            let mut error = std::ptr::null_mut();
59            let is_ok = ffi::g_credentials_set_unix_user(self.to_glib_none().0, uid, &mut error);
60            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
61            if error.is_null() {
62                Ok(())
63            } else {
64                Err(from_glib_full(error))
65            }
66        }
67    }
68}