Bump to 1.14.1
[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 "\""
37                       . store /((\\\\")?[^\\\n"]*)+/
38                       . Util.del_str "\""
39   in Build.key_value kv_re Sep.equal option_value
40    | Build.flag flag_re
41
42 (* View: key_options
43    A list of key <option>s *)
44 let key_options = [ label "options" . Build.opt_list option Sep.comma ]
45
46 (* View: key_type *)
47 let key_type =
48   let key_type_re = /ecdsa-sha2-nistp[0-9]+/ | /ssh-[a-z0-9]+/
49   in [ label "type" . store key_type_re ]
50
51 (* View: key_comment *)
52 let key_comment = [ label "comment" . store Rx.space_in ]
53
54 (* View: authorized_key *)
55 let authorized_key =
56    [ label "key"
57      . (key_options . Sep.space)?
58      . key_type . Sep.space
59      . store Rx.no_spaces
60      . (Sep.space . key_comment)?
61      . Util.eol ]
62
63 (* View: lns
64      The authorized_keys lens
65 *)
66 let lns = ( Util.empty | Util.comment | authorized_key)*
67
68 (* Variable: filter *)
69 let filter = incl (Sys.getenv("HOME") . "/.ssh/authorized_keys")
70
71 let xfm = transform lns filter
72