Imported Upstream version 1.3.0
[platform/upstream/augeas.git] / lenses / authorized_keys.aug
1 (*
2 Module: Authorized_Keys
3   Parses SSH authorized_keys
4
5 Author: Raphael Pinson <raphael.pinson@camptocamp.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man 5 authorized_keys` where possible.
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17    This lens applies to SSH authorized_keys. See <filter>.
18
19 About: Examples
20    The <Test_Authorized_Keys> file contains various examples and tests.
21 *)
22
23
24 module Authorized_Keys =
25
26 autoload xfm
27
28 (* View: option
29    A key option *)
30 let option =
31      let kv_re   = "command" | "environment" | "from"
32                  | "permitopen" | "principals" | "tunnel"
33   in let flag_re = "cert-authority" | "no-agent-forwarding"
34                  | "no-port-forwarding" | "no-pty" | "no-user-rc"
35                  | "no-X11-forwarding"
36   in let option_value = Util.del_str "\"" . store /[^\n"]+/ . Util.del_str "\""
37   in Build.key_value kv_re Sep.equal option_value
38    | Build.flag flag_re
39
40 (* View: key_options
41    A list of key <option>s *)
42 let key_options = [ label "options" . Build.opt_list option Sep.comma ]
43
44 (* View: key_type *)
45 let key_type =
46   let key_type_re = /ecdsa-sha2-nistp[0-9]+/ | /ssh-[a-z0-9]+/
47   in [ label "type" . store key_type_re ]
48
49 (* View: key_comment *)
50 let key_comment = [ label "comment" . store Rx.space_in ]
51
52 (* View: authorized_key *)
53 let authorized_key =
54    [ label "key"
55      . (key_options . Sep.space)?
56      . key_type . Sep.space
57      . store Rx.no_spaces
58      . (Sep.space . key_comment)?
59      . Util.eol ]
60
61 (* View: lns
62      The authorized_keys lens
63 *)
64 let lns = ( Util.empty | Util.comment | authorized_key)*
65
66 (* Variable: filter *)
67 let filter = incl (Sys.getenv("HOME") . "/.ssh/authorized_keys")
68
69 let xfm = transform lns filter
70