select_region regex not working since upgrade to 3.18.1

Xander Cage <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
hi,

i have this rather complex file edit stuff for aix stanza file editing and 
since
upgrading to 3.18.1 yesterday, it acts weird.

testpolicy (rather long, had to include all bundles):

body file control
{
  inputs => { "$(sys.libdir)/stdlib.cf", };
}


bundle agent parent_bundle
{


      vars:
        "sshaitsv[lpa_module]"    string =>   "/usr/lib/security/ssha";
        "sshaitsv[lpa_options]"   string =>   
"algorithm=sha512,cost_num=10,salt_len=24";
        #
        "usw[pwd_algorithm]"      string =>   "sshaitsv";

     # test files eare just empty touch files
      methods:
        "set_algo_stanza"  usebundle  => 
 set_stanza_test("/tmp/pwdalg_cfg_test.cfg", "sshaitsv", 
"$(this.bundle).sshaitsv");
        "set_algo_login"   usebundle  => 
 set_stanza_test("/tmp/cfe_testbed/login_cfg_test.cfg", "usw", 
"$(this.bundle).usw");
}

bundle agent set_stanza_test (file_to_edit, lpa_opts, values)
{

    vars:
        "file"             string => "$(file_to_edit)";
        "index"            slist  => getindices("$(values)");
        "cindex[$(index)]" string => canonify("$index");


    methods:
        "setting_passwd_algo" usebundle  => set_stanza_attrib_test($(file), 
$(lpa_opts), $(index), "$($(values)[$(index)])" ),
                              comment    => "set given values in given 
file",
                              classes    => 
if_repaired("PASSWD_ALGO_MODIFIED");

}

bundle agent set_stanza_attrib_test(config_file, stanza, attrib, value)
{
  files:
      "$(config_file)"
         edit_line => edit_add_stanza_test("$(config_file)", "$(stanza)");

      "$(config_file)"
         edit_line => replace_or_add_stanza_attrib_test("$(config_file)", 
"$(stanza)", "$(attrib)", "$(value)");
}

bundle edit_line replace_or_add_stanza_attrib_test(file, stanza, attrib, 
value)
# Ensures that an attribute in the specified stanza of the stanza-based
# config file, such as /etc/filesystems on AIX, exists and is set to the
# specified value. H/T to stdlib "replace_or_add."
{
  vars:
    "estanza"      string => escape("$(stanza)");
    "eattrib"      string => escape("$(attrib)");
    "evalue"       string => escape("$(value)");
    "replace_done" string => 
canonify("replaced_$(file)_$(stanza)_$(attrib)");
    # The replace_done flag class will be global since it is defined by a
    # promise outcome, so we need to include the file name in the class name
    # because two different files might have the same stanza and attribute.

  replace_patterns:
    "^(\h*)($(eattrib))(\h*)=\h*(?!$(evalue))\H*\h*$"
       select_region => select_stanza_test("$(estanza)", "no"),
        replace_with => replace_stanza_value_test("$(value)"),
             classes => always("$(replace_done)");

  insert_lines:
    "   $(attrib) = $(value)"
          ifvarclass => "$(replace_done)",
          comment    => "/Andi 2014-03-17: changed 4 * space to tab",
       select_region => select_stanza_test("$(estanza)", "no");
}

body select_region select_stanza_test(stanza, include_end)
{
  select_start            => "^$(stanza):\h*$";
  select_end              => "^(\h*|\H+:)$";
  include_start_delimiter => "yes";
  include_end_delimiter   => "$(include_end)";
}

body replace_with replace_stanza_value_test(value)
{
  replace_value => "$(match.1)$(match.2)$(match.3)= $(value)";
  occurrences   => "all";
}

bundle edit_line edit_add_stanza_test(file, stanza)
# Ensures that the specified stanza is present in the target file.
# If needed, creates an empty stanza with no attributes. Also adds a
# newline above the new stanza to separate it from any previous
# stanzas in the file.
{
  vars:
      "estanza"       string => escape("$(stanza)");
      "stanza_added"  string => canonify("stanza_added_$(file)_$(stanza)");
      "newline_added" string => 
canonify("stanza_added_$(file)_$(stanza)_nl");

  insert_lines:
      "$(stanza):"
         comment => "Add the stanza to the file",
         classes => if_repaired("$(stanza_added)");

      ""
               comment => "Insert a blank line above the stanza we just 
added",
            ifvarclass => "$(stanza_added).!$(newline_added)",
         select_region => select_stanza_test("$(estanza)", "no"),
              location => start,
               classes => if_repaired("$(newline_added)");
}



bundle agent __main__
{
  methods:
      "parent_bundle";
}

error:

  root@aixtest01: /root/cfe_testbed # /var/cfengine/bin/cf-agent -KIv -f 
./stanza_edit_test.cf | grep "The promised end pattern"
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'
 verbose: The promised end pattern '^(\h*|\H+:)$' was not found when 
selecting region to insert in '/tmp/pwdalg_cfg_test.cfg'

this results in in partial edits.

sshaitsv:

instead of

sshaitsv:
        lpa_module = /usr/lib/security/ssha
        lpa_options = algorithm=sha512,cost_num=10,salt_len=24

for example pwdalg_cfg_test.cfg 

i checked the regex with regex101 and it seem to match correctly there.

https://regex101.com/r/sUvBZ0/1

not sure whats wrong here, something changed in 3.18 maybe?

wbr

chris

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/12a1433a-5bd4-4282-995e-3533c35b345en%40googlegroups.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.