Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / sshd.aug
1 (*
2 Module: Sshd
3   Parses /etc/ssh/sshd_config
4
5 Author: David Lutterkort lutter@redhat.com
6         Dominique Dumont dominique.dumont@hp.com
7
8 About: Reference
9   sshd_config man page.
10   See http://www.openbsd.org/cgi-bin/man.cgi?query=sshd_config&sektion=5
11
12 About: License
13   This file is licensed under the LGPL v2+.
14
15 About: Lens Usage
16   Sample usage of this lens in augtool:
17
18     * Get your current setup
19       > print /files/etc/ssh/sshd_config
20       ...
21
22     * Set X11Forwarding to "no"
23       > set /files/etc/ssh/sshd_config/X11Forwarding "no"
24
25   More advanced usage:
26
27     * Set a Match section
28       > set /files/etc/ssh/sshd_config/Match[1]/Condition/User "foo"
29       > set /files/etc/ssh/sshd_config/Match[1]/Settings/X11Forwarding "yes"
30
31   Saving your file:
32
33       > save
34
35
36 About: CAVEATS
37
38   In sshd_config, Match blocks must be located at the end of the file.
39   This means that any new "global" parameters (i.e. outside of a Match
40   block) must be written before the first Match block. By default,
41   Augeas will write new parameters at the end of the file.
42
43   I.e. if you have a Match section and no ChrootDirectory parameter,
44   this command:
45
46      > set /files/etc/ssh/sshd_config/ChrootDirectory "foo"
47
48   will be stored in a new node after the Match section and Augeas will
49   refuse to save sshd_config file.
50
51   To create a new parameter as the right place, you must first create
52   a new Augeas node before the Match section:
53
54      > ins ChrootDirectory before /files/etc/ssh/sshd_config/Match
55
56   Then, you can set the parameter
57
58      > set /files/etc/ssh/sshd_config/ChrootDirectory "foo"
59
60
61 About: Configuration files
62   This lens applies to /etc/ssh/sshd_config
63
64 *)
65
66 module Sshd =
67    autoload xfm
68
69    let eol = del /[ \t]*\n/ "\n"
70
71    let sep = del /[ \t=]+/ " "
72
73    let indent = del /[ \t]*/ "  "
74
75    let key_re = /[A-Za-z0-9]+/
76          - /MACs|Match|AcceptEnv|Subsystem|Ciphers|((GSSAPI|)Kex|HostKey|CASignature|PubkeyAccepted)Algorithms|PubkeyAcceptedKeyTypes|(Allow|Deny)(Groups|Users)/i
77
78    let comment = Util.comment
79    let comment_noindent = Util.comment_noindent
80    let empty = Util.empty
81
82    let array_entry (kw:regexp) (sq:string) =
83      let bare = Quote.do_quote_opt_nil (store /[^"' \t\n=]+/) in
84      let quoted = Quote.do_quote (store /[^"'\n]*[ \t]+[^"'\n]*/) in
85      [ key kw
86        . ( [ sep . seq sq . bare ] | [ sep . seq sq . quoted ] )*
87        . eol ]
88
89    let other_entry =
90      let value = store /[^ \t\n=]+([ \t=]+[^ \t\n=]+)*/ in
91      [ key key_re . sep . value . eol ]
92
93    let accept_env = array_entry /AcceptEnv/i "AcceptEnv"
94
95    let allow_groups = array_entry /AllowGroups/i "AllowGroups"
96    let allow_users = array_entry /AllowUsers/i "AllowUsers"
97    let deny_groups = array_entry /DenyGroups/i "DenyGroups"
98    let deny_users = array_entry /DenyUsers/i "DenyUsers"
99
100    let subsystemvalue =
101      let value = store (/[^ \t\n=](.*[^ \t\n=])?/) in
102      [ key /[A-Za-z0-9\-]+/ . sep . value . eol ]
103
104    let subsystem =
105      [ key /Subsystem/i .  sep .  subsystemvalue ]
106
107    let list (kw:regexp) (sq:string) =
108      let value = store /[^, \t\n=]+/ in
109      [ key kw . sep .
110          [ seq sq . value ] .
111          ([ seq sq . Util.del_str "," . value])* .
112          eol ]
113
114    let macs = list /MACs/i "MACs"
115
116    let ciphers = list /Ciphers/i "Ciphers"
117
118    let kexalgorithms = list /KexAlgorithms/i "KexAlgorithms"
119
120    let hostkeyalgorithms = list /HostKeyAlgorithms/i "HostKeyAlgorithms"
121
122    let gssapikexalgorithms = list /GSSAPIKexAlgorithms/i "GSSAPIKexAlgorithms"
123
124    let casignaturealgorithms = list /CASignatureAlgorithms/i "CASignatureAlgorithms"
125
126    let pubkeyacceptedkeytypes = list /PubkeyAcceptedKeyTypes/i "PubkeyAcceptedKeyTypes"
127    
128    let pubkeyacceptedalgorithms = list /PubkeyAcceptedAlgorithms/i "PubkeyAcceptedAlgorithms"
129
130    let entry = accept_env | allow_groups | allow_users
131              | deny_groups | subsystem | deny_users
132              | macs | ciphers | kexalgorithms | hostkeyalgorithms
133              | gssapikexalgorithms | casignaturealgorithms
134              | pubkeyacceptedkeytypes | pubkeyacceptedalgorithms | other_entry
135
136    let condition_entry =
137     let k = /[A-Za-z0-9]+/ in
138     let no_spc = Quote.do_dquote_opt (store  /[^"' \t\n=]+/) in
139     let spc = Quote.do_quote (store /[^"'\t\n]* [^"'\t\n]*/) in
140       [ sep . key k . sep . no_spc ]
141     | [ sep . key k . sep . spc ]
142
143    let match_cond =
144      [ label "Condition" . condition_entry+ . eol ]
145
146    let match_entry = indent . (entry | comment_noindent)
147                    | empty
148
149    let match =
150      [ key /Match/i . match_cond
151         . [ label "Settings" .  match_entry+ ]
152      ]
153
154   let lns = (entry | comment | empty)* . match*
155
156   let filter = (incl "/etc/ssh/sshd_config" )
157                . ( incl "/etc/ssh/sshd_config.d/*.conf" )
158
159   let xfm = transform lns filter
160
161 (* Local Variables: *)
162 (* mode: caml       *)
163 (* End:             *)