resolve_zone_dir

Function resolve_zone_dir 

Source
pub fn resolve_zone_dir(raw_dir: &str) -> Result<String, ApiError>
Expand description

Resolve and validate the configured zone directory at startup.

The zone directory comes from the BIND_ZONE_DIR environment variable, which static analysis (CodeQL rust/path-injection) treats as untrusted input. Canonicalizing it once at startup both hardens the server and removes that taint before the path ever reaches a filesystem sink (read_dir/metadata):

  • Symlinks and .. segments are resolved against the real filesystem, so the value stored in AppState is an absolute, fully-normalized path.
  • A missing path or a path that does not resolve to a directory is rejected up front, turning a late runtime failure into a clear startup error.

This is the configuration-time counterpart to [validate_zone_name], which guards the per-request zone names that are joined onto this directory (B-1).

§Arguments

  • raw_dir - The configured zone directory path (e.g. from BIND_ZONE_DIR).

§Returns

The canonicalized directory path as a UTF-8 String.

§Errors

Returns ApiError::InternalError if the path cannot be canonicalized (for example it does not exist), does not resolve to a directory, or is not valid UTF-8.