I am trying to write a Linux property to match the contain of the file /etc/nsswitch.conf
Example : in /etc/nsswitch.conf we have passwd: files nis
How do i write a correct property and audit the file configuration matching the above mention. We do have scenerio that some systems contain might contain addition spacing such as
But when i try to put into a analysis property, example :
(parenthesized parts of matches (regex "^passwd:[ ]*(
A-Za-z0-9
+)$") of it ) of lines of file “/etc/nsswitch.conf” as string = “files nis”
It returnes : A singular expression is required.
I wonder why ?
Actually i wanted to do something like this.
if no exists file “/etc/nsswitch.conf” then “Missing file” else if exists file “/etc/nsswitch.conf” and (parenthesized parts of matches (regex "^passwd:[ ]*(
A-Za-z0-9
+)$") of it ) of lines of file “/etc/nsswitch.conf” as string = “files nis” then “PASS” else “Wrong setting”
The issue with the “singular expression is required” is that you have a plural expression 'parenthesized part
s
', and plural values can’t be compared to a singular value.
You can rewrite it slightly to handle this using a ‘whose’ clause:
(parenthesized parts whose (it as string = “files nis”) of matches (regex “^passwd:[ ]*(A-Za-z0-9 +)$”) of it ) of lines of file “/etc/nsswitch.conf”
And to put it all together:
if (not exists file “/etc/nsswitch.conf”) then “Missing file” else if (exists file “/etc/nsswitch.conf” and (parenthesized parts whose (it as string = “files nis”) of matches (regex “^passwd:[ ]*(A-Za-z0-9 +)$”) of it ) of lines of file “/etc/nsswitch.conf”) then “PASS” else “Wrong setting”
Oops… I think I forgot the “exists” in the second if clause… sorry… Try this:
if (not exists file “/etc/nsswitch.conf”) then “Missing file” else if ((exists file “/etc/nsswitch.conf”) and (exists (parenthesized parts whose (it as string = “files nis”) of matches (regex “^passwd:[ ]*(A-Za-z0-9 +)$”) of it ) of lines of file “/etc/nsswitch.conf”)) then “PASS” else “Wrong setting”
Hopefully I got that right… I don’t have a linux computer to test on at the moment…