[augeas-devel] [PATCH] passwd lens
free at 64studio.com
free at 64studio.com
Mon Dec 22 11:25:22 UTC 2008
commit 8b63d15bda77561b6e1fa6fe80588b1a0260c658
Author: Free Ekanayaka <free at 64studio.com>
Date: Mon Dec 22 01:48:10 2008 +0000
Add lens and test for /etc/passwd
diff --git a/lenses/passwd.aug b/lenses/passwd.aug
new file mode 100644
index 0000000..7d1a9fa
--- /dev/null
+++ b/lenses/passwd.aug
@@ -0,0 +1,52 @@
+(* Passwd module for Augeas
+ Author: Free Ekanayaka <free at 64studio.com>
+
+ Reference: man 5 passwd
+
+*)
+
+module Passwd =
+
+ autoload xfm
+
+(************************************************************************
+ * USEFUL PRIMITIVES
+ *************************************************************************)
+
+let eol = Util.eol
+let comment = Util.comment
+let empty = Util.empty
+
+let colon = del /:/ ":"
+
+let sto_to_col = store /[^:\n]+/
+let sto_to_eol = store /([^ \t\n].*[^ \t\n]|[^ \t\n])/
+
+let word = /[A-Za-z0-9_.-]+/
+let integer = /[0-9]+/
+
+(************************************************************************
+ * ENTRIES
+ *************************************************************************)
+
+let entry = [ key word
+ . colon
+ . [ label "password" . store word . colon ]
+ . [ label "uid" . store integer . colon ]
+ . [ label "gid" . store integer . colon ]
+ . [ label "name" . sto_to_col? . colon ]
+ . [ label "home" . sto_to_col? . colon ]
+ . [ label "shell" . sto_to_eol? ]
+ . eol ]
+
+(************************************************************************
+ * LENS
+ *************************************************************************)
+
+let lns = (comment|empty|entry) *
+
+let filter
+ = incl "/etc/passwd"
+ . Util.stdexcl
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_passwd.aug b/lenses/tests/test_passwd.aug
new file mode 100644
index 0000000..0b91b30
--- /dev/null
+++ b/lenses/tests/test_passwd.aug
@@ -0,0 +1,29 @@
+module Test_Passwd =
+
+let conf = "root:x:0:0:root:/root:/bin/bash
+libuuid:x:100:101::/var/lib/libuuid:/bin/sh
+free:x:1000:1000:Free Ekanayaka,,,:/home/free:/bin/bash
+"
+
+test Passwd.lns get conf =
+ { "root"
+ { "password" = "x" }
+ { "uid" = "0" }
+ { "gid" = "0" }
+ { "name" = "root" }
+ { "home" = "/root" }
+ { "shell" = "/bin/bash" } }
+ { "libuuid"
+ { "password" = "x" }
+ { "uid" = "100" }
+ { "gid" = "101" }
+ { "name" }
+ { "home" = "/var/lib/libuuid" }
+ { "shell" = "/bin/sh" } }
+ { "free"
+ { "password" = "x" }
+ { "uid" = "1000" }
+ { "gid" = "1000" }
+ { "name" = "Free Ekanayaka,,," }
+ { "home" = "/home/free" }
+ { "shell" = "/bin/bash" } }
More information about the augeas-devel
mailing list