3 Parses ssh client configuration
5 Author: Jiri Suchomel <jsuchome@suse.cz>
11 This file is licensed under the GPL.
14 Sample usage of this lens in augtool
17 augtool> set /files/etc/ssh/ssh_config/Host example.com
18 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/RemoteForward/machine1:1234 machine2:5678
19 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/Ciphers/1 aes128-ctr
20 augtool> set /files/etc/ssh/ssh_config/Host[.='example.com']/Ciphers/2 aes192-ctr
28 (************************************************************************
29 * Group: USEFUL PRIMITIVES
30 *************************************************************************)
33 let spc = Util.del_ws_spc
35 let comment = Util.comment
36 let empty = Util.empty
37 let comma = Util.del_str ","
38 let indent = Util.indent
39 let value_to_eol = store Rx.space_in
40 let value_to_spc = store Rx.no_spaces
41 let value_to_comma = store /[^, \t\r\n]+/
44 (************************************************************************
46 *************************************************************************)
48 let array_entry (k:regexp) =
49 [ indent . key k . counter "array_entry"
50 . [ spc . seq "array_entry" . value_to_spc]* . eol ]
52 let commas_entry (k:regexp) =
53 let value = [ seq "commas_entry" . value_to_comma]
54 in [ indent . key k . counter "commas_entry" . spc .
55 Build.opt_list value comma . eol ]
57 let spaces_entry (k:regexp) =
58 let value = [ seq "spaces_entry" . value_to_spc ]
59 in [ indent . key k . counter "spaces_entry" . spc .
60 Build.opt_list value spc . eol ]
62 let fw_entry (k:regexp) = [ indent . key k . spc .
63 [ key /[^ \t\r\n\/]+/ . spc . value_to_eol . eol ]]
65 let send_env = array_entry /SendEnv/i
67 let proxy_command = [ indent . key /ProxyCommand/i . spc . value_to_eol . eol ]
69 let remote_fw = fw_entry /RemoteForward/i
70 let local_fw = fw_entry /LocalForward/i
72 let ciphers = commas_entry /Ciphers/i
73 let macs = commas_entry /MACs/i
74 let algorithms = commas_entry /(HostKey|Kex)Algorithms/i
75 let pubkey_accepted_key_types = commas_entry /PubkeyAcceptedKeyTypes/i
77 let global_knownhosts_file = spaces_entry /GlobalKnownHostsFile/i
79 let special_entry = send_env
86 | pubkey_accepted_key_types
87 | global_knownhosts_file
89 let key_re = /[A-Za-z0-9]+/
90 - /SendEnv|Host|ProxyCommand|RemoteForward|LocalForward|MACs|Ciphers|(HostKey|Kex)Algorithms|PubkeyAcceptedKeyTypes|GlobalKnownHostsFile/i
93 let other_entry = [ indent . key key_re
94 . spc . value_to_spc . eol ]
96 let entry = comment | empty
100 let host = [ key /Host/i . spc . value_to_eol . eol . entry* ]
103 (************************************************************************
105 *************************************************************************)
107 let lns = entry* . host*
109 let xfm = transform lns (incl "/etc/ssh/ssh_config" .
110 incl (Sys.getenv("HOME") . "/.ssh/config") .
111 incl "/etc/ssh/ssh_config.d/*.conf")