[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] Help regarding union.put overlap with INI-like format



Hi,

I'm writing a new lens to parse the configuration file
/etc/selinux/semanage.conf, currently handled by the Simplevars lens.
The problem is that this file does not have anymore a simple foo=var
syntax, and grew INI-like "groups" which Simplevars does not handle.

The syntax is like (attached there is the default file in Fedora):

foo=var
# comment
[name of group]
var = value
[end]  # yes, a group is ended like this

I tried to model a new lens that would return the very same structure
that Simplevars exposed, just with the additional subtrees for the
groups, to not break existing users.  The lens (attached) seems to
work fine, although the typechecking with augparse shows union.put
overlapping issues:

$ augparse --nostdinc -I lenses/ lenses/tests/test_semanage.aug 
Syntax error in lens definition
lenses/semanage.aug:36.0-.27:Failed to compile lns
lenses/semanage.aug:36.10-.25:exception: overlapping lenses in tree union.put
    Example matched by both:  { "AA" }
    First lens: lenses/semanage.aug:30.12-31.17:
    Second lens: lenses/semanage.aug:34.13-.60:

lenses/tests/test_semanage.aug:16.5-.17:Could not load module Semanage for Semanage.lns
lenses/tests/test_semanage.aug:16.5-.17:Undefined variable Semanage.lns
lenses/tests/test_semanage.aug:25.5-.17:Undefined variable Semanage.lns
lenses/tests/test_semanage.aug:30.5-.17:Undefined variable Semanage.lns
lenses/tests/test_semanage.aug:56.5-.17:Undefined variable Semanage.lns

I tried to debug this a bit, and I understand (thanks to the
documentation!) what is the issue reported... although I do not get why
actually augeas finds an overlap here. Any hints?

Thanks,
-- 
Pino Toscano
# Authors: Jason Tang <jtang tresys com>
#
# Copyright (C) 2004-2005 Tresys Technology, LLC
#
#  This library is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public
#  License as published by the Free Software Foundation; either
#  version 2.1 of the License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this library; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Specify how libsemanage will interact with a SELinux policy manager.
# The four options are:
#
#  "source"     - libsemanage manipulates a source SELinux policy
#  "direct"     - libsemanage will write directly to a module store.
#  /foo/bar     - Write by way of a policy management server, whose
#                 named socket is at /foo/bar.  The path must begin
#                 with a '/'.
#  foo.com:4242 - Establish a TCP connection to a remote policy
#                 management server at foo.com.  If there is a colon
#                 then the remainder is interpreted as a port number;
#                 otherwise default to port 4242.
module-store = direct

# When generating the final linked and expanded policy, by default
# semanage will set the policy version to POLICYDB_VERSION_MAX, as
# given in <sepol/policydb.h>.  Change this setting if a different
# version is necessary.
#policy-version = 19

# expand-check check neverallow rules when executing all semanage
# commands. There might be a penalty in execution time if this
# option is enabled.
expand-check=0

# usepasswd check tells semanage to scan all pass word records for home directories
# and setup the labeling correctly.  If this is turned off, SELinux will label /home 
# correctly only.  You will need to use semanage fcontext command.  
# For example, if you had home dirs in /althome directory you would have to execute
# semanage fcontext -a -e /home /althome
usepasswd=False
bzip-small=true
bzip-blocksize=5
ignoredirs=/root

[sefcontext_compile]
path = /usr/sbin/sefcontext_compile
args = -r $@
[end]
(*
Module: Simplevars
  Parses simple key = value conffiles

Author: Raphael Pinson <raphink gmail com>

About: License
   This file is licenced under the LGPL v2+, like the rest of Augeas.

About: Lens Usage
   To be documented

About: Examples
   The <Test_Simplevars> file contains various examples and tests.
*)

module Simplevars =

autoload xfm

(* Variable: to_comment_re
   The regexp to match the value *)
let to_comment_re =
     let to_comment_squote = /'[^\n']*'/
  in let to_comment_dquote = /"[^\n"]*"/
  in let to_comment_noquote = /[^\n \t'"#][^\n#]*[^\n \t#]|[^\n \t'"#]/
  in to_comment_squote | to_comment_dquote | to_comment_noquote

(* View: entry *)
let entry =
     let some_value = Sep.space_equal . store to_comment_re
     (* Avoid ambiguity in tree by making a subtree here *)
  in let empty_value = [del /[ \t]*=/ "="] . store ""
  in [ Util.indent . key Rx.word
            . (some_value? | empty_value)
            . (Util.eol | Util.comment_eol) ]

(* View: lns *)
let lns = (Util.empty | Util.comment | entry)*

(* Variable: filter *)
let filter = incl "/etc/kernel-img.conf"
           . incl "/etc/kerneloops.conf"
           . incl "/etc/wgetrc"
           . incl "/etc/zabbix/*.conf"
           . incl "/etc/audit/auditd.conf"
           . incl "/etc/mixerctl.conf"
           . incl "/etc/wsconsctlctl.conf"

let xfm = transform lns filter
(*
Module: Test_Semanage
  Provides unit tests and examples for the <Semanage> lens.
*)

module Test_Semanage =

(* Variable: phony_conf *)
let phony_conf = "# this is a comment

mykey = myvalue # eol comment
anotherkey = another value
"

(* Test: Semanage.lns *)
test Semanage.lns get phony_conf =
   { "#comment" = "this is a comment" }
   { }
   { "mykey" = "myvalue"
     { "#comment" = "eol comment" } }
   { "anotherkey" = "another value" }

(* Test: Semanage.lns
   Quotes are OK in variables that do not begin with a quote *)
test Semanage.lns get "UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}'\n" =
     { "UserParameter" = "custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}'" }

(* Test: Semanage.lns
     Support empty values *)
test Semanage.lns get "foo =\n" =
  { "foo" = "" { } }

(* Variable: conf *)
let conf = "module-store = direct

#policy-version = 19

expand-check=0

usepasswd=False
bzip-small=true
bzip-blocksize=5
ignoredirs=/root

[sefcontext_compile]
path = /usr/sbin/sefcontext_compile
args = -r $@
[end]

[verify module]
test=value
[end]
"

(* Test: Semanage.lns *)
test Semanage.lns get conf =
   { "module-store" = "direct" }
   { }
   { "#comment" = "policy-version = 19" }
   { }
   { "usepasswd" = "False" }
   { "bzip-small" = "true" }
   { "bzip-blocksize" = "5" }
   { "ignoredirs" = "/root" }
   { }
   { "sefcontext_compile"
     { "path" = "/usr/sbin/sefcontext_compile" }
     { "args" = "-r $@" } }
   { }
   { "verify module"
     { "test" = "value" } }

Attachment: signature.asc
Description: This is a digitally signed message part.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]