Imported Upstream version 1.3.0
[platform/upstream/augeas.git] / lenses / services.aug
1 (*
2 Module: Services
3  Parses /etc/services
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8  This lens tries to keep as close as possible to 'man services' where possible.
9
10 The definitions from 'man services' are put as commentaries for reference
11 throughout the file. More information can be found in the manual.
12
13 About: License
14   This file is licensed under the LGPL v2+, like the rest of Augeas.
15
16 About: Lens Usage
17   Sample usage of this lens in augtool
18
19     * Get the name of the service running on port 22 with protocol tcp
20       > match "/files/etc/services/service-name[port = '22'][protocol = 'tcp']"
21     * Remove the tcp entry for "domain" service
22       > rm "/files/etc/services/service-name[. = 'domain'][protocol = 'tcp']"
23     * Add a tcp service named "myservice" on port 55234
24       > ins service-name after /files/etc/services/service-name[last()]
25       > set /files/etc/services/service-name[last()] "myservice"
26       > set "/files/etc/services/service-name[. = 'myservice']/port" "55234"
27       > set "/files/etc/services/service-name[. = 'myservice']/protocol" "tcp"
28
29 About: Configuration files
30   This lens applies to /etc/services. See <filter>.
31 *)
32
33 module Services =
34   autoload xfm
35
36
37 (************************************************************************
38  * Group:                 USEFUL PRIMITIVES
39  *************************************************************************)
40
41 (* Group: Generic primitives *)
42
43 (* Variable: eol *)
44 let eol         = del /[ \t]*(#)?[ \t]*\n/ "\n"
45 let indent      = Util.indent
46 let comment     = Util.comment
47 let comment_or_eol = Util.comment_or_eol
48 let empty       = Util.empty
49 let protocol_re = /[a-zA-Z]+/
50 let word_re     = /[a-zA-Z0-9_.+*\/:-]+/
51 let num_re      = /[0-9]+/
52
53 (* Group: Separators *)
54 let sep_spc = Util.del_ws_spc
55
56
57 (************************************************************************
58  * Group:                 LENSES
59  *************************************************************************)
60
61 (* View: port *)
62 let port = [ label "port" . store num_re ]
63
64 (* View: port_range *)
65 let port_range = [ label "start" . store num_re ]
66                    . Util.del_str "-"
67                    . [ label "end" . store num_re ]
68
69 (* View: protocol *)
70 let protocol = [ label "protocol" . store protocol_re ]
71
72 (* View: alias *)
73 let alias = [ label "alias" . store word_re ]
74
75 (*
76  * View: record
77  *   A standard /etc/services record
78  *   TODO: make sure a space is added before a comment on new nodes
79  *)
80 let record = [ label "service-name" . store word_re
81                  . sep_spc . (port | port_range)
82                  . del "/" "/" . protocol . ( sep_spc . alias )*
83                  . comment_or_eol ]
84
85 (* View: lns
86     The services lens is either <empty>, <comment> or <record> *)
87 let lns = ( empty | comment | record )*
88
89
90 (* View: filter *)
91 let filter = (incl "/etc/services")
92
93 let xfm = transform lns filter