|
1 | 1 | use core::sync::atomic::{AtomicI32, Ordering}; |
2 | 2 |
|
| 3 | +use starry_core::shm::IpcPerm; |
| 4 | + |
3 | 5 | static IPC_ID: AtomicI32 = AtomicI32::new(0); |
4 | 6 |
|
5 | 7 | fn next_ipc_id() -> i32 { |
6 | 8 | IPC_ID.fetch_add(1, Ordering::Relaxed) |
7 | 9 | } |
8 | 10 |
|
| 11 | +mod msg; |
9 | 12 | mod shm; |
| 13 | +pub use self::{msg::*, shm::*}; |
| 14 | + |
| 15 | +// IPC command constants |
| 16 | +const IPC_PRIVATE: i32 = 0; |
| 17 | +const IPC_CREAT: i32 = 0o1000; |
| 18 | +const IPC_EXCL: i32 = 0o2000; |
| 19 | +const IPC_RMID: i32 = 0; |
| 20 | +const IPC_SET: i32 = 1; |
| 21 | +const IPC_STAT: i32 = 2; |
| 22 | +const IPC_INFO: i32 = 3; |
| 23 | +const MSG_STAT: i32 = 11; |
| 24 | +const MSG_INFO: i32 = 12; |
| 25 | + |
| 26 | +// Permission bits |
| 27 | +const USER_READ: u32 = 0o400; |
| 28 | +const USER_WRITE: u32 = 0o200; |
| 29 | +const GROUP_READ: u32 = 0o040; |
| 30 | +const GROUP_WRITE: u32 = 0o020; |
| 31 | +const OTHER_READ: u32 = 0o004; |
| 32 | +const OTHER_WRITE: u32 = 0o002; |
10 | 33 |
|
11 | | -pub use self::shm::*; |
| 34 | +// add a helper function to check IPC permissions |
| 35 | +fn has_ipc_permission(perm: &IpcPerm, current_uid: u32, current_gid: u32, is_write: bool) -> bool { |
| 36 | + // root user has all permissions |
| 37 | + if current_uid == 0 { |
| 38 | + return true; |
| 39 | + } |
| 40 | + |
| 41 | + if perm.uid == current_uid { |
| 42 | + (perm.mode & if is_write { USER_WRITE } else { USER_READ }) != 0 |
| 43 | + } else if perm.gid == current_gid { |
| 44 | + (perm.mode & if is_write { GROUP_WRITE } else { GROUP_READ }) != 0 |
| 45 | + } else { |
| 46 | + (perm.mode & if is_write { OTHER_WRITE } else { OTHER_READ }) != 0 |
| 47 | + } |
| 48 | +} |
0 commit comments