v0.1.2
This commit is contained in:
1 parent
6e57b9e1b8
commit
7b8c7e93fb
48 files changed
+1010
-116
No files matched your search
@@ -121,14 +121,10 @@ fn acl_contains(acl: &[IpNet], ip: IpAddr) -> bool {
|
||||
acl.iter().any(|n| n.contains(&ip))
|
||||
}
|
||||
|
||||
/// Default copy of a secondary zone: `<data_dir>/zones/secondary/<zone>.zone`.
|
||||
///
|
||||
/// Versions before 0.1.x-unreleased kept it in `<data_dir>/secondary/`. An existing old
|
||||
/// copy (with its `.meta.json`) is moved to the new place, so an upgrade keeps serving
|
||||
/// the zone from the local copy instead of transferring everything again.
|
||||
fn default_secondary_file(data_dir: &Path, zone_ascii: &str) -> PathBuf {
|
||||
let new = data_dir.join("zones").join("secondary").join(format!("{zone_ascii}zone"));
|
||||
let old = data_dir.join("secondary").join(format!("{zone_ascii}zone"));
|
||||
/// Move a server-written file from its pre-0.1.2 location to the current one (together
|
||||
/// with `<file>.meta.json` when present), so an upgrade keeps using it. Returns the path
|
||||
/// to use: the new one, or the old one when it could not be moved.
|
||||
fn migrate_default(new: PathBuf, old: PathBuf, what: &str) -> PathBuf {
|
||||
if !new.exists() && old.is_file() {
|
||||
let meta = |p: &Path| {
|
||||
let mut m = p.as_os_str().to_owned();
|
||||
@@ -141,9 +137,9 @@ fn default_secondary_file(data_dir: &Path, zone_ascii: &str) -> PathBuf {
|
||||
.and_then(|_| std::fs::rename(&old, &new))
|
||||
.and_then(|_| if meta(&old).exists() { std::fs::rename(meta(&old), meta(&new)) } else { Ok(()) });
|
||||
match moved {
|
||||
Ok(()) => tracing::info!(from = %old.display(), to = %new.display(), "moved secondary zone copy to the new location"),
|
||||
Ok(()) => tracing::info!(from = %old.display(), to = %new.display(), "moved {what} to the new location"),
|
||||
Err(e) => {
|
||||
tracing::warn!(path = %old.display(), error = %e, "could not move secondary zone copy; using the old location");
|
||||
tracing::warn!(path = %old.display(), error = %e, "could not move {what}; using the old location");
|
||||
return old;
|
||||
}
|
||||
}
|
||||
@@ -151,6 +147,31 @@ fn default_secondary_file(data_dir: &Path, zone_ascii: &str) -> PathBuf {
|
||||
new
|
||||
}
|
||||
|
||||
/// Default copy of a secondary zone: `<data_dir>/zones/secondary/<zone>.zone`.
|
||||
///
|
||||
/// Versions before 0.1.1 kept it in `<data_dir>/secondary/`. An existing old copy (with
|
||||
/// its `.meta.json`) is moved to the new place, so an upgrade keeps serving the zone from
|
||||
/// the local copy instead of transferring everything again.
|
||||
fn default_secondary_file(data_dir: &Path, zone_ascii: &str) -> PathBuf {
|
||||
migrate_default(
|
||||
data_dir.join("zones").join("secondary").join(format!("{zone_ascii}zone")),
|
||||
data_dir.join("secondary").join(format!("{zone_ascii}zone")),
|
||||
"secondary zone copy",
|
||||
)
|
||||
}
|
||||
|
||||
/// Last signed version of a DNSSEC zone: `<data_dir>/zones/signed/<zone>.zone`.
|
||||
///
|
||||
/// Versions before 0.1.2 kept it in `<data_dir>/signed/`; it is moved, so the first start
|
||||
/// after an upgrade reuses the signatures instead of re-signing under the same serial.
|
||||
fn default_signed_file(data_dir: &Path, zone_ascii: &str) -> PathBuf {
|
||||
migrate_default(
|
||||
data_dir.join("zones").join("signed").join(format!("{zone_ascii}zone")),
|
||||
data_dir.join("signed").join(format!("{zone_ascii}zone")),
|
||||
"signed zone",
|
||||
)
|
||||
}
|
||||
|
||||
impl ZoneEntry {
|
||||
fn new(cfg: &Config, zc: &ZoneConfig, ring: &KeyRing) -> Result<Self, String> {
|
||||
let name = dns_core::names::parse_name(&zc.name).map_err(|e| e.to_string())?;
|
||||
@@ -184,7 +205,7 @@ impl ZoneEntry {
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let signed_file = cfg.data_dir().join("signed").join(format!("{}zone", name.to_ascii()));
|
||||
let signed_file = default_signed_file(&cfg.data_dir(), &name.to_ascii());
|
||||
Ok(Self {
|
||||
signer: Mutex::new(signer),
|
||||
source: Mutex::new(None),
|
||||
@@ -612,4 +633,18 @@ mod migration_tests {
|
||||
assert_eq!(default_secondary_file(&d, "example.net."), d.join("zones/secondary/example.net.zone"));
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn old_signed_zone_is_moved_to_new_location() {
|
||||
let d = std::env::temp_dir().join(format!("edns-sig-mig-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
std::fs::create_dir_all(d.join("signed")).unwrap();
|
||||
std::fs::write(d.join("signed/example.com.zone"), "signed").unwrap();
|
||||
let p = default_signed_file(&d, "example.com.");
|
||||
assert_eq!(p, d.join("zones/signed/example.com.zone"));
|
||||
assert_eq!(std::fs::read_to_string(&p).unwrap(), "signed");
|
||||
assert!(!d.join("signed/example.com.zone").exists());
|
||||
assert_eq!(default_signed_file(&d, "example.net."), d.join("zones/signed/example.net.zone"));
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user