-
Notifications
You must be signed in to change notification settings - Fork 111
feat(core): support building for iOS targets #1246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| //! iOS: no user database is accessible from within the app sandbox; identity | ||
| //! comes from uid/gid syscalls and the process environment. | ||
|
|
||
| use crate::error; | ||
| use std::path::PathBuf; | ||
|
|
||
| pub(crate) const fn is_root() -> bool { | ||
| false | ||
| } | ||
|
|
||
| pub(crate) fn get_user_home_dir(username: &str) -> Option<PathBuf> { | ||
| // Only the current (sandboxed) user is resolvable. | ||
| if get_current_username().is_ok_and(|current| current == username) { | ||
| get_current_user_home_dir() | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn get_current_user_home_dir() -> Option<PathBuf> { | ||
| std::env::var_os("HOME").map(PathBuf::from) | ||
| } | ||
|
|
||
| pub(crate) const fn get_current_user_default_shell() -> Option<PathBuf> { | ||
| None | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_current_uid() -> Result<u32, error::Error> { | ||
| // SAFETY: getuid is always successful and has no preconditions. | ||
| Ok(unsafe { libc::getuid() }) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_current_gid() -> Result<u32, error::Error> { | ||
| // SAFETY: getgid is always successful and has no preconditions. | ||
| Ok(unsafe { libc::getgid() }) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_effective_uid() -> Result<u32, error::Error> { | ||
| // SAFETY: geteuid is always successful and has no preconditions. | ||
| Ok(unsafe { libc::geteuid() }) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_effective_gid() -> Result<u32, error::Error> { | ||
| // SAFETY: getegid is always successful and has no preconditions. | ||
| Ok(unsafe { libc::getegid() }) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_current_username() -> Result<String, error::Error> { | ||
| Ok(std::env::var("USER").unwrap_or_else(|_| "mobile".to_owned())) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_user_group_ids() -> Result<Vec<u32>, error::Error> { | ||
| // SAFETY: getgid is always successful and has no preconditions. | ||
| Ok(vec![unsafe { libc::getgid() }]) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While these are straightforward, we prefer using the |
||
| } | ||
|
|
||
| pub(crate) fn get_all_users() -> Result<Vec<String>, error::Error> { | ||
| Ok(vec![get_current_username()?]) | ||
| } | ||
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_all_groups() -> Result<Vec<String>, error::Error> { | ||
| Ok(vec!["mobile".to_owned()]) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you find a case where it's important to return at least one group instead of just returning an empty vector? |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
USERtypically set in the iOS targets you've tested with? If so, I'm tempted to avoid a hard-coded fake fallback.