Imported Upstream version 0.10.0
[platform/upstream/augeas.git] / lenses / ssh.aug
1 (*
2 Module: Ssh
3   Parses ssh client configuration
4
5 Author: Jiri Suchomel <jsuchome@suse.cz>
6
7 About: Reference
8     ssh_config man page
9
10 About: License
11     This file is licensed under the GPL.
12
13 About: Lens Usage
14   Sample usage of this lens in augtool
15
16 augtool> set /files/etc/ssh/ssh_config/Host example.com
17 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/RemoteForward/machine1:1234 machine2:5678
18 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/Ciphers/1 aes128-ctr
19 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/Ciphers/2 aes192-ctr
20
21 *)
22
23 module Ssh =
24     autoload xfm
25
26     let eol = del /[ \t]*\n/ "\n"
27     let spc = Util.del_ws_spc
28
29     let key_re = /[A-Za-z0-9]+/
30                - /SendEnv|Host|ProxyCommand|RemoteForward|LocalForward|MACs|Ciphers/
31
32     let comment = Util.comment
33     let empty = Util.empty
34     let comma = Util.del_str ","
35     let indent = Util.indent
36     let value_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
37     let value_to_spc = store /[^ \t\n]+/
38     let value_to_comma = store /[^, \t\n]+/
39
40     let array_entry (k:string) =
41         [ indent . key k . counter k . [ spc . seq k . value_to_spc]* . eol ]
42
43     let commas_entry (k:string) =
44         [ key k . counter k . spc .
45             [ seq k . value_to_comma] . ([ seq k . comma . value_to_comma])* . eol ]
46
47     let send_env = array_entry "SendEnv"
48
49     let proxy_command = [ indent . key "ProxyCommand" . spc . value_to_eol . eol ]
50
51     let fw_entry (k:string) = [ indent . key k . spc .
52         [ key /[^ \t\n\/]+/ . spc . value_to_eol . eol ]]
53
54     let remote_fw = fw_entry "RemoteForward"
55     let local_fw = fw_entry "LocalForward"
56
57     let ciphers = commas_entry "Ciphers"
58     let macs    = commas_entry "MACs"
59
60     let other_entry =
61         [ indent . key key_re . spc . value_to_spc . eol ]
62
63     let entry = (comment | empty
64         | send_env
65         | proxy_command
66         | remote_fw
67         | local_fw
68         | macs
69         | ciphers
70         | other_entry)
71
72     let host = [ key "Host" . spc . value_to_eol . eol . entry* ]
73
74     let lns = entry* . host*
75
76     let xfm = transform lns (incl "/etc/ssh/ssh_config" .
77                              incl "~/.ssh/config")