Blame SOURCES/0006-Sshd-revert-Sshd-module-to-1.1.0-compatible-add-Sshd.patch

91858b
From 1c936bb38d39b238001364e1a7ee5479bdfff053 Mon Sep 17 00:00:00 2001
91858b
From: Dominic Cleal <dcleal@redhat.com>
91858b
Date: Fri, 12 Jun 2015 11:01:57 +0100
91858b
Subject: [PATCH] Sshd: revert Sshd module to 1.1.0-compatible, add Sshd_140
91858b
91858b
In order to keep the default sshd config lens compatible with 1.1.0,
91858b
the lens from 1.4.0 has been kept in the Sshd_140 module and is not
91858b
loaded by default.  Use aug_transform, augtool --transform etc. to use
91858b
it instead of Sshd.
91858b
---
91858b
 lenses/sshd.aug                |  52 +++++-------
91858b
 lenses/sshd_140.aug            | 141 +++++++++++++++++++++++++++++++++
91858b
 lenses/tests/test_sshd.aug     |  56 -------------
91858b
 lenses/tests/test_sshd_140.aug | 136 +++++++++++++++++++++++++++++++
91858b
 tests/Makefile.am              |   1 +
91858b
 5 files changed, 298 insertions(+), 88 deletions(-)
91858b
 create mode 100644 lenses/sshd_140.aug
91858b
 create mode 100644 lenses/tests/test_sshd_140.aug
91858b
91858b
diff --git a/lenses/sshd.aug b/lenses/sshd.aug
91858b
index 55f6c4f7..785102ec 100644
91858b
--- a/lenses/sshd.aug
91858b
+++ b/lenses/sshd.aug
91858b
@@ -70,55 +70,41 @@ module Sshd =
91858b
 
91858b
    let sep = Util.del_ws_spc
91858b
 
91858b
-   let indent = del /[ \t]*/ "  "
91858b
-
91858b
    let key_re = /[A-Za-z0-9]+/
91858b
-         - /MACs|Match|AcceptEnv|Subsystem|Ciphers|KexAlgorithms|(Allow|Deny)(Groups|Users)/i
91858b
+         - /MACs|Match|AcceptEnv|Subsystem|(Allow|Deny)(Groups|Users)/
91858b
 
91858b
    let comment = Util.comment
91858b
-   let comment_noindent = Util.comment_noindent
91858b
    let empty = Util.empty
91858b
 
91858b
-   let array_entry (kw:regexp) (sq:string) =
91858b
+   let array_entry (k:string) =
91858b
      let value = store /[^ \t\n]+/ in
91858b
-     [ key kw . [ sep . seq sq . value]* . eol ]
91858b
+     [ key k . [ sep . seq k . value]* . eol ]
91858b
 
91858b
    let other_entry =
91858b
      let value = store /[^ \t\n]+([ \t]+[^ \t\n]+)*/ in
91858b
      [ key key_re . sep . value . eol ]
91858b
 
91858b
-   let accept_env = array_entry /AcceptEnv/i "AcceptEnv"
91858b
+   let accept_env = array_entry "AcceptEnv"
91858b
 
91858b
-   let allow_groups = array_entry /AllowGroups/i "AllowGroups"
91858b
-   let allow_users = array_entry /AllowUsers/i "AllowUsers"
91858b
-   let deny_groups = array_entry /DenyGroups/i "DenyGroups"
91858b
-   let deny_users = array_entry /DenyUsers/i "DenyUsers"
91858b
+   let allow_groups = array_entry "AllowGroups"
91858b
+   let allow_users = array_entry "AllowUsers"
91858b
+   let deny_groups = array_entry "DenyGroups"
91858b
+   let deny_users = array_entry "DenyUsers"
91858b
 
91858b
    let subsystemvalue =
91858b
      let value = store (/[^ \t\n](.*[^ \t\n])?/) in
91858b
      [ key /[A-Za-z0-9\-]+/ . sep . value . eol ]
91858b
 
91858b
    let subsystem =
91858b
-     [ key /Subsystem/i .  sep .  subsystemvalue ]
91858b
+     [ key "Subsystem" .  sep .  subsystemvalue ]
91858b
 
91858b
-   let list (kw:regexp) (sq:string) =
91858b
-     let value = store /[^, \t\n]+/ in
91858b
-     [ key kw . sep .
91858b
-         [ seq sq . value ] .
91858b
-         ([ seq sq . Util.del_str "," . value])* .
91858b
+   let macs =
91858b
+     let mac_value = store /[^, \t\n]+/ in
91858b
+     [ key "MACs" . sep .
91858b
+         [ seq "macs" . mac_value ] .
91858b
+         ([ seq "macs" . Util.del_str "," . mac_value])* .
91858b
          eol ]
91858b
 
91858b
-   let macs = list /MACs/i "MACs"
91858b
-
91858b
-   let ciphers = list /Ciphers/i "Ciphers"
91858b
-
91858b
-   let kexalgorithms = list /KexAlgorithms/i "KexAlgorithms"
91858b
-
91858b
-   let entry = accept_env | allow_groups | allow_users
91858b
-             | deny_groups | subsystem | deny_users
91858b
-             | macs | ciphers | kexalgorithms
91858b
-             | other_entry
91858b
-
91858b
    let condition_entry =
91858b
     let value = store  /[^ \t\n]+/ in
91858b
     [ sep . key /[A-Za-z0-9]+/ . sep . value ]
91858b
@@ -126,15 +112,17 @@ module Sshd =
91858b
    let match_cond =
91858b
      [ label "Condition" . condition_entry+ . eol ]
91858b
 
91858b
-   let match_entry = indent . (entry | comment_noindent)
91858b
-                   | empty 
91858b
+   let match_entry =
91858b
+     ( comment | empty | (Util.indent . other_entry) )
91858b
 
91858b
    let match =
91858b
-     [ key /Match/i . match_cond
91858b
+     [ key "Match" . match_cond
91858b
         . [ label "Settings" .  match_entry+ ]
91858b
      ]
91858b
 
91858b
-  let lns = (entry | comment | empty)* . match* 
91858b
+  let lns = (comment | empty | accept_env | allow_groups | allow_users
91858b
+          | deny_groups | subsystem | deny_users | macs
91858b
+          | other_entry ) * . match*
91858b
 
91858b
   let xfm = transform lns (incl "/etc/ssh/sshd_config")
91858b
 
91858b
diff --git a/lenses/sshd_140.aug b/lenses/sshd_140.aug
91858b
new file mode 100644
91858b
index 00000000..8a7f176f
91858b
--- /dev/null
91858b
+++ b/lenses/sshd_140.aug
91858b
@@ -0,0 +1,141 @@
91858b
+(*
91858b
+Module: Sshd_140
91858b
+  Parses /etc/ssh/sshd_config
91858b
+
91858b
+  This module is compatible with Augeas 1.4.0, but is not loaded by default.
91858b
+
91858b
+Author: David Lutterkort lutter@redhat.com
91858b
+        Dominique Dumont dominique.dumont@hp.com
91858b
+
91858b
+About: Reference
91858b
+  sshd_config man page.
91858b
+  See http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config&sektion=5
91858b
+
91858b
+About: License
91858b
+  This file is licensed under the LGPL v2+.
91858b
+
91858b
+About: Lens Usage
91858b
+  Sample usage of this lens in augtool:
91858b
+
91858b
+    * Get your current setup
91858b
+      > print /files/etc/ssh/sshd_config
91858b
+      ...
91858b
+
91858b
+    * Set X11Forwarding to "no"
91858b
+      > set /files/etc/ssh/sshd_config/X11Forwarding "no"
91858b
+
91858b
+  More advanced usage:
91858b
+
91858b
+    * Set a Match section
91858b
+      > set /files/etc/ssh/sshd_config/Match[1]/Condition/User "foo"
91858b
+      > set /files/etc/ssh/sshd_config/Match[1]/Settings/X11Forwarding "yes"
91858b
+
91858b
+  Saving your file:
91858b
+
91858b
+      > save
91858b
+
91858b
+
91858b
+About: CAVEATS
91858b
+
91858b
+  In sshd_config, Match blocks must be located at the end of the file.
91858b
+  This means that any new "global" parameters (i.e. outside of a Match
91858b
+  block) must be written before the first Match block. By default,
91858b
+  Augeas will write new parameters at the end of the file.
91858b
+
91858b
+  I.e. if you have a Match section and no ChrootDirectory parameter,
91858b
+  this command:
91858b
+
91858b
+     > set /files/etc/ssh/sshd_config/ChrootDirectory "foo"
91858b
+
91858b
+  will be stored in a new node after the Match section and Augeas will
91858b
+  refuse to save sshd_config file.
91858b
+
91858b
+  To create a new parameter as the right place, you must first create
91858b
+  a new Augeas node before the Match section:
91858b
+
91858b
+     > ins ChrootDirectory before /files/etc/ssh/sshd_config/Match
91858b
+
91858b
+  Then, you can set the parameter
91858b
+
91858b
+     > set /files/etc/ssh/sshd_config/ChrootDirectory "foo"
91858b
+
91858b
+
91858b
+About: Configuration files
91858b
+  This lens applies to /etc/ssh/sshd_config
91858b
+
91858b
+*)
91858b
+
91858b
+module Sshd_140 =
91858b
+   let eol = del /[ \t]*\n/ "\n"
91858b
+
91858b
+   let sep = Util.del_ws_spc
91858b
+
91858b
+   let indent = del /[ \t]*/ "  "
91858b
+
91858b
+   let key_re = /[A-Za-z0-9]+/
91858b
+         - /MACs|Match|AcceptEnv|Subsystem|Ciphers|KexAlgorithms|(Allow|Deny)(Groups|Users)/i
91858b
+
91858b
+   let comment = Util.comment
91858b
+   let comment_noindent = Util.comment_noindent
91858b
+   let empty = Util.empty
91858b
+
91858b
+   let array_entry (kw:regexp) (sq:string) =
91858b
+     let value = store /[^ \t\n]+/ in
91858b
+     [ key kw . [ sep . seq sq . value]* . eol ]
91858b
+
91858b
+   let other_entry =
91858b
+     let value = store /[^ \t\n]+([ \t]+[^ \t\n]+)*/ in
91858b
+     [ key key_re . sep . value . eol ]
91858b
+
91858b
+   let accept_env = array_entry /AcceptEnv/i "AcceptEnv"
91858b
+
91858b
+   let allow_groups = array_entry /AllowGroups/i "AllowGroups"
91858b
+   let allow_users = array_entry /AllowUsers/i "AllowUsers"
91858b
+   let deny_groups = array_entry /DenyGroups/i "DenyGroups"
91858b
+   let deny_users = array_entry /DenyUsers/i "DenyUsers"
91858b
+
91858b
+   let subsystemvalue =
91858b
+     let value = store (/[^ \t\n](.*[^ \t\n])?/) in
91858b
+     [ key /[A-Za-z0-9\-]+/ . sep . value . eol ]
91858b
+
91858b
+   let subsystem =
91858b
+     [ key /Subsystem/i .  sep .  subsystemvalue ]
91858b
+
91858b
+   let list (kw:regexp) (sq:string) =
91858b
+     let value = store /[^, \t\n]+/ in
91858b
+     [ key kw . sep .
91858b
+         [ seq sq . value ] .
91858b
+         ([ seq sq . Util.del_str "," . value])* .
91858b
+         eol ]
91858b
+
91858b
+   let macs = list /MACs/i "MACs"
91858b
+
91858b
+   let ciphers = list /Ciphers/i "Ciphers"
91858b
+
91858b
+   let kexalgorithms = list /KexAlgorithms/i "KexAlgorithms"
91858b
+
91858b
+   let entry = accept_env | allow_groups | allow_users
91858b
+             | deny_groups | subsystem | deny_users
91858b
+             | macs | ciphers | kexalgorithms
91858b
+             | other_entry
91858b
+
91858b
+   let condition_entry =
91858b
+    let value = store  /[^ \t\n]+/ in
91858b
+    [ sep . key /[A-Za-z0-9]+/ . sep . value ]
91858b
+
91858b
+   let match_cond =
91858b
+     [ label "Condition" . condition_entry+ . eol ]
91858b
+
91858b
+   let match_entry = indent . (entry | comment_noindent)
91858b
+                   | empty 
91858b
+
91858b
+   let match =
91858b
+     [ key /Match/i . match_cond
91858b
+        . [ label "Settings" .  match_entry+ ]
91858b
+     ]
91858b
+
91858b
+  let lns = (entry | comment | empty)* . match* 
91858b
+
91858b
+(* Local Variables: *)
91858b
+(* mode: caml       *)
91858b
+(* End:             *)
91858b
diff --git a/lenses/tests/test_sshd.aug b/lenses/tests/test_sshd.aug
91858b
index 5954e16f..788a12f0 100644
91858b
--- a/lenses/tests/test_sshd.aug
91858b
+++ b/lenses/tests/test_sshd.aug
91858b
@@ -1,4 +1,3 @@
91858b
-(* Module: Test_sshd *)
91858b
 module Test_sshd =
91858b
 
91858b
   let accept_env = "Protocol 2
91858b
@@ -75,61 +74,6 @@ Match User sarko Group pres.*
91858b
 Match User bush Group pres.* Host white.house.*
91858b
 Banner /etc/welcome.txt\n"
91858b
 
91858b
-(* Test: Sshd.lns
91858b
-   Indent when adding to a Match group *)
91858b
-  test Sshd.lns put match_blocks after
91858b
-    set "Match[1]/Settings/PermitRootLogin" "yes";
91858b
-    set "Match[1]/Settings/#comment" "a comment" =
91858b
-"X11Forwarding yes
91858b
-Match User sarko Group pres.*
91858b
-  Banner /etc/bienvenue.txt
91858b
-  X11Forwarding no
91858b
-  PermitRootLogin yes
91858b
-  # a comment
91858b
-Match User bush Group pres.* Host white.house.*
91858b
-Banner /etc/welcome.txt\n"
91858b
-
91858b
-
91858b
-(* Test: Sshd.lns
91858b
-     Parse Ciphers and KexAlgorithms as lists (GH issue #69) *)
91858b
-test Sshd.lns get "Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
91858b
-KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1\n" =
91858b
-  { "Ciphers"
91858b
-    { "1" = "aes256-gcm@openssh.com" }
91858b
-    { "2" = "aes128-gcm@openssh.com" }
91858b
-    { "3" = "aes256-ctr" }
91858b
-    { "4" = "aes128-ctr" }
91858b
-  }
91858b
-  { "KexAlgorithms"
91858b
-    { "1" = "diffie-hellman-group-exchange-sha256" }
91858b
-    { "2" = "diffie-hellman-group14-sha1" }
91858b
-    { "3" = "diffie-hellman-group-exchange-sha1" }
91858b
-  }
91858b
-
91858b
-(* Test: Sshd.lns
91858b
-     Keys are case-insensitive *)
91858b
-test Sshd.lns get "ciPheRs aes256-gcm@openssh.com,aes128-ctr
91858b
-maTcH User foo
91858b
-  x11forwarding no\n" =
91858b
-  { "ciPheRs"
91858b
-    { "1" = "aes256-gcm@openssh.com" }
91858b
-    { "2" = "aes128-ctr" }
91858b
-  }
91858b
-  { "maTcH"
91858b
-    { "Condition"
91858b
-      { "User" = "foo" }
91858b
-    }
91858b
-    { "Settings"
91858b
-      { "x11forwarding" = "no" }
91858b
-    }
91858b
-  }
91858b
-
91858b
-(* Test: Sshd.lns
91858b
-     Allow AllowGroups in Match groups (GH issue #75) *)
91858b
-test Sshd.lns get "Match User foo
91858b
-AllowGroups users\n" =
91858b
-  { "Match" { "Condition" { "User" = "foo" } }
91858b
-    { "Settings" { "AllowGroups" { "1" = "users" } } } }
91858b
 
91858b
 (* Local Variables: *)
91858b
 (* mode: caml       *)
91858b
diff --git a/lenses/tests/test_sshd_140.aug b/lenses/tests/test_sshd_140.aug
91858b
new file mode 100644
91858b
index 00000000..056c53f9
91858b
--- /dev/null
91858b
+++ b/lenses/tests/test_sshd_140.aug
91858b
@@ -0,0 +1,136 @@
91858b
+(* Module: Test_sshd_140 *)
91858b
+module Test_sshd_140 =
91858b
+
91858b
+  let accept_env = "Protocol 2
91858b
+AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
91858b
+AcceptEnv LC_IDENTIFICATION LC_ALL\n"
91858b
+
91858b
+  test Sshd_140.lns get accept_env =
91858b
+    { "Protocol" = "2" }
91858b
+    { "AcceptEnv"
91858b
+        { "1" = "LC_PAPER" }
91858b
+        { "2" = "LC_NAME" }
91858b
+        { "3" = "LC_ADDRESS" }
91858b
+        { "4" = "LC_TELEPHONE" }
91858b
+        { "5" = "LC_MEASUREMENT" } }
91858b
+    { "AcceptEnv"
91858b
+        { "6" = "LC_IDENTIFICATION" }
91858b
+        { "7" = "LC_ALL" } }
91858b
+
91858b
+
91858b
+  test Sshd_140.lns get "HostKey /etc/ssh/ssh_host_rsa_key
91858b
+HostKey /etc/ssh/ssh_host_dsa_key\n" =
91858b
+    { "HostKey" = "/etc/ssh/ssh_host_rsa_key" }
91858b
+    { "HostKey" = "/etc/ssh/ssh_host_dsa_key" }
91858b
+
91858b
+
91858b
+  test Sshd_140.lns put accept_env after
91858b
+      rm "AcceptEnv";
91858b
+      rm "AcceptEnv";
91858b
+      set "Protocol" "1.5";
91858b
+      set "X11Forwarding" "yes"
91858b
+   = "Protocol 1.5\nX11Forwarding yes\n"
91858b
+
91858b
+  test Sshd_140.lns get "AuthorizedKeysFile  %h/.ssh/authorized_keys\n" =
91858b
+    { "AuthorizedKeysFile" = "%h/.ssh/authorized_keys" }
91858b
+
91858b
+  test Sshd_140.lns get "Subsystem sftp /usr/lib/openssh/sftp-server\n" =
91858b
+    { "Subsystem"
91858b
+	{ "sftp" = "/usr/lib/openssh/sftp-server" } }
91858b
+
91858b
+  test Sshd_140.lns get "Subsystem sftp-test /usr/lib/openssh/sftp-server\n" =
91858b
+    { "Subsystem"
91858b
+	{ "sftp-test" = "/usr/lib/openssh/sftp-server" } }
91858b
+
91858b
+
91858b
+
91858b
+  let match_blocks = "X11Forwarding yes
91858b
+Match User sarko Group pres.*
91858b
+  Banner /etc/bienvenue.txt
91858b
+  X11Forwarding no
91858b
+Match User bush Group pres.* Host white.house.*
91858b
+Banner /etc/welcome.txt
91858b
+"
91858b
+  test Sshd_140.lns get match_blocks =
91858b
+    { "X11Forwarding" = "yes"}
91858b
+      { "Match"
91858b
+	  { "Condition" { "User" = "sarko"   }
91858b
+	                { "Group" = "pres.*" } }
91858b
+	  { "Settings"  { "Banner" = "/etc/bienvenue.txt" }
91858b
+       	                { "X11Forwarding" = "no" } } }
91858b
+      { "Match"
91858b
+	  { "Condition" { "User" = "bush"    }
91858b
+	                { "Group" = "pres.*" }
91858b
+	                { "Host"  = "white.house.*" } }
91858b
+	  { "Settings"  { "Banner" = "/etc/welcome.txt" } } }
91858b
+
91858b
+  test Sshd_140.lns put match_blocks after
91858b
+    insb "Subsystem" "/Match[1]";
91858b
+    set "/Subsystem/sftp" "/usr/libexec/openssh/sftp-server"
91858b
+  = "X11Forwarding yes
91858b
+Subsystem sftp /usr/libexec/openssh/sftp-server
91858b
+Match User sarko Group pres.*
91858b
+  Banner /etc/bienvenue.txt
91858b
+  X11Forwarding no
91858b
+Match User bush Group pres.* Host white.house.*
91858b
+Banner /etc/welcome.txt\n"
91858b
+
91858b
+(* Test: Sshd_140.lns
91858b
+   Indent when adding to a Match group *)
91858b
+  test Sshd_140.lns put match_blocks after
91858b
+    set "Match[1]/Settings/PermitRootLogin" "yes";
91858b
+    set "Match[1]/Settings/#comment" "a comment" =
91858b
+"X11Forwarding yes
91858b
+Match User sarko Group pres.*
91858b
+  Banner /etc/bienvenue.txt
91858b
+  X11Forwarding no
91858b
+  PermitRootLogin yes
91858b
+  # a comment
91858b
+Match User bush Group pres.* Host white.house.*
91858b
+Banner /etc/welcome.txt\n"
91858b
+
91858b
+
91858b
+(* Test: Sshd_140.lns
91858b
+     Parse Ciphers and KexAlgorithms as lists (GH issue #69) *)
91858b
+test Sshd_140.lns get "Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes128-ctr
91858b
+KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1\n" =
91858b
+  { "Ciphers"
91858b
+    { "1" = "aes256-gcm@openssh.com" }
91858b
+    { "2" = "aes128-gcm@openssh.com" }
91858b
+    { "3" = "aes256-ctr" }
91858b
+    { "4" = "aes128-ctr" }
91858b
+  }
91858b
+  { "KexAlgorithms"
91858b
+    { "1" = "diffie-hellman-group-exchange-sha256" }
91858b
+    { "2" = "diffie-hellman-group14-sha1" }
91858b
+    { "3" = "diffie-hellman-group-exchange-sha1" }
91858b
+  }
91858b
+
91858b
+(* Test: Sshd_140.lns
91858b
+     Keys are case-insensitive *)
91858b
+test Sshd_140.lns get "ciPheRs aes256-gcm@openssh.com,aes128-ctr
91858b
+maTcH User foo
91858b
+  x11forwarding no\n" =
91858b
+  { "ciPheRs"
91858b
+    { "1" = "aes256-gcm@openssh.com" }
91858b
+    { "2" = "aes128-ctr" }
91858b
+  }
91858b
+  { "maTcH"
91858b
+    { "Condition"
91858b
+      { "User" = "foo" }
91858b
+    }
91858b
+    { "Settings"
91858b
+      { "x11forwarding" = "no" }
91858b
+    }
91858b
+  }
91858b
+
91858b
+(* Test: Sshd_140.lns
91858b
+     Allow AllowGroups in Match groups (GH issue #75) *)
91858b
+test Sshd_140.lns get "Match User foo
91858b
+AllowGroups users\n" =
91858b
+  { "Match" { "Condition" { "User" = "foo" } }
91858b
+    { "Settings" { "AllowGroups" { "1" = "users" } } } }
91858b
+
91858b
+(* Local Variables: *)
91858b
+(* mode: caml       *)
91858b
+(* End:             *)
91858b
diff --git a/tests/Makefile.am b/tests/Makefile.am
91858b
index b4563540..387ac7d2 100644
91858b
--- a/tests/Makefile.am
91858b
+++ b/tests/Makefile.am
91858b
@@ -189,6 +189,7 @@ lens_tests =			\
91858b
   lens-squid.sh			\
91858b
   lens-ssh.sh			\
91858b
   lens-sshd.sh			\
91858b
+  lens-sshd_140.sh			\
91858b
   lens-sssd.sh			\
91858b
   lens-stunnel.sh			\
91858b
   lens-subversion.sh		\
91858b
-- 
91858b
2.17.2
91858b