[augeas-devel] augeas: master - Lens and test for /etc/services

David Lutterkort lutter at fedoraproject.org
Wed Feb 11 21:43:19 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=e27190fbc420aafe7e969e40199affec4b80e488
Commit:        e27190fbc420aafe7e969e40199affec4b80e488
Parent:        4750356efb6a70ff13ea536d19996e4181aa2578
Author:        Raphael Pinson <raphink at gmail.com>
AuthorDate:    Wed Feb 11 10:38:19 2009 -0800
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Feb 11 10:38:19 2009 -0800

Lens and test for /etc/services

---
 doc/naturaldocs/conf/lenses/Menu.txt |    1 +
 lenses/services.aug                  |   87 ++++++++++++++++++++++++++++++++++
 lenses/tests/test_services.aug       |   33 +++++++++++++
 3 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/doc/naturaldocs/conf/lenses/Menu.txt b/doc/naturaldocs/conf/lenses/Menu.txt
index 08c1392..d41ca9e 100644
--- a/doc/naturaldocs/conf/lenses/Menu.txt
+++ b/doc/naturaldocs/conf/lenses/Menu.txt
@@ -55,6 +55,7 @@ Group: Specific Modules  {
 
    File: Dpkg  (dpkg.aug)
    File: Exports  (exports.aug)
+   File: Services  (services.aug)
    File: Sshd  (sshd.aug)
    File: Sudoers  (sudoers.aug)
    File: Xinetd  (xinetd.aug)
diff --git a/lenses/services.aug b/lenses/services.aug
new file mode 100644
index 0000000..c8c4e8f
--- /dev/null
+++ b/lenses/services.aug
@@ -0,0 +1,87 @@
+(*
+Module: Services
+ Parses /etc/services
+
+Author: Raphael Pinson <raphink at gmail.com>
+
+About: Reference
+ This lens tries to keep as close as possible to 'man services' where possible.
+
+The definitions from 'man services' are put as commentaries for reference
+throughout the file. More information can be found in the manual.
+
+About: License
+  This file is licensed under the GPL.
+
+About: Lens Usage
+  Sample usage of this lens in augtool
+
+    * Get the name of the service running on port 22 with protocol tcp
+      > match "/files/etc/services/service-name[port = '22'][protocol = 'tcp']"
+    * Remove the tcp entry for "domain" service
+      > rm "/files/etc/services/service-name[. = 'domain'][protocol = 'tcp']"
+    * Add a tcp service named "myservice" on port 55234
+      > ins service-name after /files/etc/services/service-name[last()]
+      > set /files/etc/services/service-name[last()] "myservice"
+      > set "/files/etc/services/service-name[. = 'myservice']/port" "55234"
+      > set "/files/etc/services/service-name[. = 'myservice']/protocol" "tcp"
+
+About: Configuration files
+  This lens applies to /etc/services. See <filter>.
+*)
+
+module Services =
+  autoload xfm
+
+
+(************************************************************************
+ * Group:                 USEFUL PRIMITIVES
+ *************************************************************************)
+
+(* Group: Generic primitives *)
+
+(* Variable: eol *)
+let eol         = Util.eol
+let indent      = Util.indent
+let comment     = Util.comment
+let empty       = Util.empty
+let protocol_re = /[a-zA-Z]+/
+let word_re     = /[a-zA-Z0-9_-]+/
+let num_re      = /[0-9]+/
+
+(* Group: Separators *)
+let sep_spc = Util.del_ws_spc
+
+
+(************************************************************************
+ * Group:                 LENSES
+ *************************************************************************)
+
+(* View: port *)
+let port = [ label "port" . store num_re ]
+
+(* View: protocol *)
+let protocol = [ label "protocol" . store protocol_re ]
+
+(* View: alias *)
+let alias = [ label "alias" . store word_re ]
+
+(*
+ * View: record
+ *   A standard /etc/services record
+ *   TODO: make sure a space is added before a comment on new nodes
+ *)
+let record = [ label "service-name" . store word_re . sep_spc . port
+                 . del "/" "/" . protocol . ( sep_spc . alias )*
+                 . (comment|eol) ]
+
+(* View: lns *)
+let lns = ( empty | comment | record )*
+
+
+(* Variable: filter *)
+let filter = (incl "/etc/services")
+
+let xfm = transform lns filter
+
+
diff --git a/lenses/tests/test_services.aug b/lenses/tests/test_services.aug
new file mode 100644
index 0000000..dc01ef5
--- /dev/null
+++ b/lenses/tests/test_services.aug
@@ -0,0 +1,33 @@
+(* Tests for the Services module *)
+
+module Test_services =
+
+  let example = "# a comment
+
+tcpmux          1/tcp                           # TCP port service multiplexer
+echo            7/udp
+discard         9/tcp           sink null
+systat          11/tcp          users
+# another comment
+"
+
+  test Services.lns get example =
+    { "#comment" = "a comment" }
+    { }
+    { "service-name" = "tcpmux"
+       { "port"     = "1" }
+       { "protocol" = "tcp" }
+       { "#comment" = "TCP port service multiplexer" } }
+    { "service-name" = "echo"
+       { "port"     = "7" }
+       { "protocol" = "udp" } }
+    { "service-name" = "discard"
+       { "port"     = "9" }
+       { "protocol" = "tcp" }
+       { "alias"    = "sink" }
+       { "alias"    = "null" } }
+    { "service-name" = "systat"
+       { "port"     = "11" }
+       { "protocol" = "tcp" }
+       { "alias"    = "users" } }
+    { "#comment" = "another comment" }




More information about the augeas-devel mailing list