diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-21 21:14:40 +0100 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-11-21 21:14:40 +0100 |
commit | 48c2945172b88c35c187d298a35bf26716af4e91 (patch) | |
tree | 2af21ddb4dcacd191e07fef156609b7c1488ebaf /src/cmd/init.rs | |
parent | 6ed535387df0dffa72a10e601b8ea37c99345d84 (diff) |
Switch to varlink as IPC protocol
This is a lot! Whole new design on top of a statefult varlink interface.
You can now handle multiple request response cycles over a single
connection.
The error responses are lot more refined than just status codes with
optional messages and finally part of the protocol.
TODO: A lot of error handling needs to be improved.
Diffstat (limited to 'src/cmd/init.rs')
-rw-r--r-- | src/cmd/init.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cmd/init.rs b/src/cmd/init.rs new file mode 100644 index 0000000..167d028 --- /dev/null +++ b/src/cmd/init.rs @@ -0,0 +1,35 @@ +use std::ffi::CString; + +use crate::cmd::MailStorage; +use crate::de_jmhoffmann_jwebmail_mailstorage::Call_Init; + +pub fn init( + ms: &MailStorage, + call: &mut dyn Call_Init, + unix_user: String, + mailbox_path: String, +) -> varlink::Result<()> { + unsafe { + *libc::__errno_location() = 0; + } + if let Ok(c_sys_user) = CString::new(unix_user.clone()) { + let user_info: *const libc::passwd = unsafe { libc::getpwnam(c_sys_user.as_ptr()) }; + let err = unsafe { *libc::__errno_location() }; + if err != 0 { + return call.reply_invalid_user(unix_user); + } + if user_info.is_null() { + return call.reply_invalid_user(unix_user); + } + let rc = unsafe { libc::setuid((*user_info).pw_uid) }; + if rc != 0 { + return call.reply_invalid_user(unix_user); + } + + *ms.maildir_path.write().unwrap() = Some(mailbox_path.into()); + + call.reply() + } else { + call.reply_invalid_user(unix_user) + } +} |