Commit f647935f authored by MrMan's avatar MrMan

Compiling & theoretically working

parent 94b07a07
Pipeline #50029185 passed with stage
in 6 minutes and 38 seconds
......@@ -104,6 +104,19 @@ session_cache_db = "btree:/var/lib/postfix/smtpd_tls_session_cache.db"
log_level = 1
session_cache_timeout_seconds = 3600
###########
# Dovecot #
###########
[dovecot]
bin_path = "/usr/sbin/dovecot"
doveadm_bin_path = "/usr/bin/doveadm"
config_output_dir = "/etc/dovecot"
mail_location = "/var/mail"
unix_socket_path = "/var/spool/postfix/private/auth"
#############
# Web Admin #
#############
......
......@@ -101,6 +101,19 @@ session_cache_db = "btree:/var/lib/postfix/smtpd_tls_session_cache.db"
log_level = 1
session_cache_timeout_seconds = 3600
###########
# Dovecot #
###########
[dovecot]
bin_path = "/usr/sbin/dovecot"
doveadm_bin_path = "/usr/bin/doveadm"
config_output_dir = "/etc/dovecot"
mail_location = "/var/mail"
unix_socket_path = "/var/spool/postfix/private/auth"
#############
# Web Admin #
#############
......
......@@ -204,15 +204,35 @@ impl SupportsVMailboxLookup for DB {
// TODO: this can probably be generalized in the future to SupportsAuth<T> when Dovecot auth is added
pub trait SupportsDovecotAuth where Self: MailboxDB {
/// Generate/Retrieve settings for dovecot to use to connecto the DB
fn dovecot_db_settings(&self) -> Result<DovecotDBSettings, Error>;
/// Dovecot userdb settings
fn dovecot_userdb_settings(&self) -> Result<DovecotDBSettings, Error>;
/// Dovecot passdb settings
fn dovecot_passdb_settings(&self) -> Result<DovecotDBSettings, Error>;
/// Get the driver for dovecot
fn dovecot_driver_type(&self) -> Result<DBType, Error>;
}
impl SupportsDovecotAuth for DB {
fn dovecot_db_settings(&self) -> Result<DovecotDBSettings, Error> {
fn dovecot_userdb_settings(&self) -> Result<DovecotDBSettings, Error> {
match self {
DB::SQLite(db) => db.dovecot_db_settings(),
_ => Err(Error::NotSupported)
DB::SQLite(db) => db.dovecot_userdb_settings(),
_ => Err(Error::NotSupported),
}
}
fn dovecot_passdb_settings(&self) -> Result<DovecotDBSettings, Error> {
match self {
DB::SQLite(db) => db.dovecot_passdb_settings(),
_ => Err(Error::NotSupported),
}
}
fn dovecot_driver_type(&self) -> Result<DBType, Error> {
match self {
DB::SQLite(db) => db.dovecot_driver_type(),
_ => Err(Error::NotSupported),
}
}
}
......@@ -278,11 +278,45 @@ impl SupportsVMailboxLookup for SQLiteDB {
}
}
// FIXME: mailbox_users table name is hardcoded here
const DEFAULT_USERDB_QUERY: &'static str = "
SELECT home, uid, gid \
FROM users \
WHERE username = '%n' AND domain = '%d'
";
// FIXME: mailbox_users table name is hardcoded here
const DEFAULT_PASSDB_QUERY: &'static str = "
SELECT username, domain, password \
FROM mailbox_users \
WHERE username = '%n' AND domain = '%d'
";
// FIXME: users table is hardcoded here
const DEFAULT_ITERATE_QUERY: &'static str = "SELECT username, domain FROM users";
impl SupportsDovecotAuth for SQLiteDB {
fn dovecot_db_settings(&self) -> Result<DovecotDBSettings, Error> {
// TODO: generate the DB settings for dovecot based on this backend
Err(Error::NotSupported)
fn dovecot_userdb_settings(&self) -> Result<DovecotDBSettings, Error> {
// Generate the DB settings for dovecot based on this backend
Ok(DovecotDBSettings {
driver: self.dovecot_driver_type()?,
connect: self.cfg.path.clone(),
query: String::from(DEFAULT_USERDB_QUERY),
iterate_query: String::from(DEFAULT_ITERATE_QUERY),
})
}
fn dovecot_passdb_settings(&self) -> Result<DovecotDBSettings, Error> {
// Generate the DB settings for dovecot based on this backend
Ok(DovecotDBSettings {
driver: self.dovecot_driver_type()?,
connect: self.cfg.path.clone(),
query: String::from(DEFAULT_PASSDB_QUERY),
iterate_query: String::from(DEFAULT_ITERATE_QUERY),
})
}
fn dovecot_driver_type(&self) -> Result<DBType, Error> { Ok(DBType::SQLite) }
}
#[cfg(test)]
......
......@@ -209,7 +209,6 @@ struct DovecotUserDBConfTemplate<'a> {
struct DovecotPassDBConfTemplate<'a> {
filename: &'a str,
generation_time: String,
settings: &'a DovecotDBSettings,
}
......@@ -221,6 +220,18 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
let dir = dir.unwrap_or(self.config_dir_path());
ensure_directory(&dir)?;
// Generate file paths for the dovecot.conf file
let output_dir = Path::new(&self.cfg.config_output_dir);
let main_conf_path = output_dir.join(DOVECOT_CONF_FILENAME);
let main_conf_abs_path = make_absolute_path(main_conf_path.to_path_buf())?;
// Generate *possible* file path for userdb/passdb configuration
let userdb_conf_path = output_dir.join(DOVECOT_USERDB_CONF_FILENAME);
let passdb_conf_path = output_dir.join(DOVECOT_PASSDB_CONF_FILENAME);
let userdb_conf_abs_path = make_absolute_path(userdb_conf_path.to_path_buf())?;
let passdb_conf_abs_path = make_absolute_path(passdb_conf_path.to_path_buf())?;
// Build dovecot conf template
let main_conf_tmpl = DovecotConfTemplate {
filename: DOVECOT_CONF_FILENAME,
......@@ -229,17 +240,13 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
mail_location: &self.cfg.mail_location,
unix_socket_path: &self.cfg.unix_socket_path,
userdb: &self.cfg.userdb,
userdb_conf_abs_path: String::from(""),
userdb: &self.cfg.userdb_settings,
userdb_conf_abs_path: userdb_conf_abs_path,
passdb: &self.cfg.passdb,
passdb_conf_abs_path: String::from(""),
passdb: &self.cfg.passdb_settings,
passdb_conf_abs_path: passdb_conf_abs_path,
};
// Generate file paths for the dovecot.conf file
let output_dir = Path::new(&self.cfg.config_output_dir);
let main_conf_path = output_dir.join(DOVECOT_CONF_FILENAME);
let main_conf_abs_path = make_absolute_path(main_conf_path.to_path_buf())?;
// Render the main config
debug!("{} will be written to [{}]", &main_conf_tmpl.filename, &main_conf_abs_path);
......@@ -247,7 +254,7 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
main_conf_file.write_all(main_conf_tmpl.render()?.as_bytes())?;
// Write the userdb sql conf if settings were specified
if let Some(settings) = &self.cfg.userdb {
if let Some(settings) = &self.cfg.userdb_settings {
// Build userdb SQL configuration template
let tmpl = DovecotUserDBConfTemplate {
filename: DOVECOT_USERDB_CONF_FILENAME,
......@@ -265,7 +272,7 @@ impl FileConfigurable<DovecotCfg> for Dovecot {
}
// Write the passdb sql conf if settings were specified
if let Some(settings) = &self.cfg.passdb {
if let Some(settings) = &self.cfg.passdb_settings {
// Build passdb SQL configuration template
let tmpl = DovecotPassDBConfTemplate {
filename: DOVECOT_PASSDB_CONF_FILENAME,
......
......@@ -24,7 +24,8 @@ pub struct Postfix {
pid: Option<u32>,
command: Option<Command>,
process: Option<ChildProcess>,
pub db: DB
pub db: DB,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
......@@ -51,7 +52,7 @@ impl Postfix {
pid: None,
command: None,
process: None,
db
db: db,
})
}
}
......
......@@ -235,8 +235,8 @@ pub struct DovecotCfg {
pub unix_socket_path: String,
pub userdb: Option<DovecotDBSettings>,
pub passdb: Option<DovecotDBSettings>,
pub userdb_settings: Option<DovecotDBSettings>,
pub passdb_settings: Option<DovecotDBSettings>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
......
......@@ -3,7 +3,7 @@ extern crate fern;
extern crate postmgr;
use std::thread;
use postmgr::components::db::{MailboxDB, Connectable};
use postmgr::components::db::{MailboxDB, Connectable, SupportsDovecotAuth};
use postmgr::components::web_admin::WebAdmin;
use postmgr::components::postfix::Postfix;
use postmgr::components::dovecot::Dovecot;
......@@ -26,8 +26,18 @@ fn main() {
// Create Postfix component
let mut postfix = Postfix::new(app_cfg.postfix.clone(), None).expect("postfix component init failed");
// Create Dovecot config using the db from postfix
// Use userdb/passdb settings from postfix's internal DB if no explicit settings provided
let mut dovecot_cfg = app_cfg.dovecot.clone();
if dovecot_cfg.userdb_settings.is_none() {
if let Ok(s) = postfix.db.dovecot_userdb_settings() { dovecot_cfg.userdb_settings = Some(s);}
}
if dovecot_cfg.passdb_settings.is_none() {
if let Ok(s) = postfix.db.dovecot_passdb_settings() { dovecot_cfg.passdb_settings = Some(s);}
}
// Create Dovecot component
let mut dovecot = Dovecot::new(app_cfg.dovecot.clone()).expect("dovecot component init failed");
let mut dovecot = Dovecot::new(dovecot_cfg).expect("dovecot component init failed");
// Create Web Admin component
let postfix_tx = postfix.get_cmd_bus_tx().expect("failed to create WebAdmin -> Postfix communication channel");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment