1 | use crate::{backend, io}; |
2 | |
3 | pub use crate::pid::{Pid, RawPid}; |
4 | pub use crate::ugid::{Gid, RawGid, RawUid, Uid}; |
5 | |
6 | /// `gettid()`—Returns the thread ID. |
7 | /// |
8 | /// This returns the OS thread ID, which is not necessarily the same as the |
9 | /// `rust::thread::Thread::id` or the pthread ID. |
10 | /// |
11 | /// # References |
12 | /// - [Linux] |
13 | /// |
14 | /// [Linux]: https://man7.org/linux/man-pages/man2/gettid.2.html |
15 | #[inline ] |
16 | #[must_use ] |
17 | pub fn gettid() -> Pid { |
18 | backend::thread::syscalls::gettid() |
19 | } |
20 | |
21 | /// `setuid(uid)` |
22 | /// |
23 | /// # Warning |
24 | /// |
25 | /// This is not the setxid you are looking for… POSIX requires xids to be |
26 | /// process granular, but on Linux they are per-thread. Thus, this call only |
27 | /// changes the xid for the current *thread*, not the entire process even |
28 | /// though that is in violation of the POSIX standard. |
29 | /// |
30 | /// For details on this distinction, see the C library vs. kernel differences |
31 | /// in the [manual page][linux_notes]. This call implements the kernel |
32 | /// behavior. |
33 | /// |
34 | /// # References |
35 | /// - [POSIX] |
36 | /// - [Linux] |
37 | /// |
38 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setuid.html |
39 | /// [Linux]: https://man7.org/linux/man-pages/man2/setuid.2.html |
40 | /// [linux_notes]: https://man7.org/linux/man-pages/man2/setuid.2.html#NOTES |
41 | #[inline ] |
42 | pub fn set_thread_uid(uid: Uid) -> io::Result<()> { |
43 | backend::thread::syscalls::setuid_thread(uid) |
44 | } |
45 | |
46 | /// `setresuid(ruid, euid, suid)` |
47 | /// |
48 | /// # Warning |
49 | /// |
50 | /// This is not the setresxid you are looking for… POSIX requires xids to be |
51 | /// process granular, but on Linux they are per-thread. Thus, this call only |
52 | /// changes the xid for the current *thread*, not the entire process even |
53 | /// though that is in violation of the POSIX standard. |
54 | /// |
55 | /// For details on this distinction, see the C library vs. kernel differences |
56 | /// in the [manual page][linux_notes] and the notes in [`set_thread_uid`]. This |
57 | /// call implements the kernel behavior. |
58 | /// |
59 | /// # References |
60 | /// - [Linux] |
61 | /// |
62 | /// [Linux]: https://man7.org/linux/man-pages/man2/setresuid.2.html |
63 | /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresuid.2.html#NOTES |
64 | #[inline ] |
65 | pub fn set_thread_res_uid(ruid: Uid, euid: Uid, suid: Uid) -> io::Result<()> { |
66 | backend::thread::syscalls::setresuid_thread(ruid, euid, suid) |
67 | } |
68 | |
69 | /// `setgid(gid)` |
70 | /// |
71 | /// # Warning |
72 | /// |
73 | /// This is not the setxid you are looking for… POSIX requires xids to be |
74 | /// process granular, but on Linux they are per-thread. Thus, this call only |
75 | /// changes the xid for the current *thread*, not the entire process even |
76 | /// though that is in violation of the POSIX standard. |
77 | /// |
78 | /// For details on this distinction, see the C library vs. kernel differences |
79 | /// in the [manual page][linux_notes]. This call implements the kernel |
80 | /// behavior. |
81 | /// |
82 | /// # References |
83 | /// - [POSIX] |
84 | /// - [Linux] |
85 | /// |
86 | /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/setgid.html |
87 | /// [Linux]: https://man7.org/linux/man-pages/man2/setgid.2.html |
88 | /// [linux_notes]: https://man7.org/linux/man-pages/man2/setgid.2.html#NOTES |
89 | #[inline ] |
90 | pub fn set_thread_gid(gid: Gid) -> io::Result<()> { |
91 | backend::thread::syscalls::setgid_thread(gid) |
92 | } |
93 | |
94 | /// `setresgid(rgid, egid, sgid)` |
95 | /// |
96 | /// # Warning |
97 | /// |
98 | /// This is not the setresxid you are looking for… POSIX requires xids to be |
99 | /// process granular, but on Linux they are per-thread. Thus, this call only |
100 | /// changes the xid for the current *thread*, not the entire process even |
101 | /// though that is in violation of the POSIX standard. |
102 | /// |
103 | /// For details on this distinction, see the C library vs. kernel differences |
104 | /// in the [manual page][linux_notes] and the notes in [`set_thread_gid`]. This |
105 | /// call implements the kernel behavior. |
106 | /// |
107 | /// # References |
108 | /// - [Linux] |
109 | /// |
110 | /// [Linux]: https://man7.org/linux/man-pages/man2/setresgid.2.html |
111 | /// [linux_notes]: https://man7.org/linux/man-pages/man2/setresgid.2.html#NOTES |
112 | #[inline ] |
113 | pub fn set_thread_res_gid(rgid: Gid, egid: Gid, sgid: Gid) -> io::Result<()> { |
114 | backend::thread::syscalls::setresgid_thread(rgid, egid, sgid) |
115 | } |
116 | |
117 | /// `setgroups(groups)`-Sets the supplementary group IDs for the calling thread. |
118 | /// |
119 | /// # References |
120 | /// - [Linux] |
121 | /// |
122 | /// [Linux]: https://man7.org/linux/man-pages/man2/setgroups.2.html |
123 | #[cfg (linux_kernel)] |
124 | #[inline ] |
125 | pub fn set_thread_groups(groups: &[Gid]) -> io::Result<()> { |
126 | backend::thread::syscalls::setgroups_thread(gids:groups) |
127 | } |
128 | |