chiark / gitweb /
config: Use SKL::None for `link` and fix `server=`
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 17:35:06 +0000 (18:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 18:46:01 +0000 (19:46 +0100)
We don't want to allow `link=` in the actual config files at all, so we
should set its SKL to None.

Conversely, `server` needs to be tolerated in the special `ServerName`
section even though it doesn't appear in the InstanceConfig struct.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs

index d771a105b499ebadee0be00e5d9d0625b936cb43..1dab223469242be67c2a824ff4aa7cfcf9305179 100644 (file)
@@ -10,7 +10,7 @@ use configparser::ini::Ini; // xxx ignores empty sections, fix or replace
 #[derive(Debug,Clone)]
 pub struct InstanceConfig {
   // Exceptional settings
-  #[special(special_link, SKL::ServerName)] pub   link:   LinkName,
+  #[special(special_link, SKL::None)]      pub    link:   LinkName,
   pub                                             secret: Secret,
   #[special(special_ipif, SKL::PerClient)] pub    ipif:   String,
 
@@ -260,9 +260,13 @@ impl Aggregate {
       let sn = sn.parse().dcontext(&sn)?;
 
       for key in vars.keys() {
-        let skl = self.keys_allowed.get(key.as_str()).ok_or_else(
-          || anyhow!("unknown configuration key {:?}", key)
-        )?;
+        let skl = if key == "server" {
+          SKL::ServerName
+        } else {
+          *self.keys_allowed.get(key.as_str()).ok_or_else(
+            || anyhow!("unknown configuration key {:?}", key)
+          )?
+        };
         if ! skl.contains(&sn) {
           throw!(anyhow!("configuration key {:?} not applicable \
                           in this kind of section: {}", key, &sn))
@@ -672,7 +676,8 @@ impl<'c> ResolveContext<'c> {
   }
 
   #[throws(AE)]
-  pub fn special_link(&self, _key: &'static str, _skl: SKL) -> LinkName {
+  pub fn special_link(&self, _key: &'static str, skl: SKL) -> LinkName {
+    assert_eq!(skl, SKL::None);
     self.link.clone()
   }
 }