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) } }