Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to write out a literal backslash character? #507

Closed
bodgit opened this issue Sep 28, 2017 · 9 comments
Closed

How to write out a literal backslash character? #507

bodgit opened this issue Sep 28, 2017 · 9 comments

Comments

@bodgit
Copy link
Contributor

bodgit commented Sep 28, 2017

As part of #274 (which I'm trying to revive and get working), I have the fundamental problem that I cannot get Augeas to write out a literal \ character as part of a separator implemented with del.

My lens contains the following:

let sep = del /:([ \t]*\\\\\n[ \t]*:)?/ ":\\\n\t:"

which (if I've got it right) should match in the get direction at least a colon, optionally followed by any amount of whitespace, a backslash, a newline, any amount of whitespace and finally another colon. On create it should always write a colon, a backslash, a newline, a tab and another colon.

This reads in existing entries correctly but new entries are always written out minus the backslash, i.e. just the colon, newline, tab and colon. The backslash has somehow been swallowed.

I'm not sure if I'm over-escaping the backslashes or not, but if I change them on either side from what's above then I tend to get a lens error of the form:

exception: del: the default value ':\\\n\t:' does not match /:([ \t]*\\\n[ \t]*:)?/

Is this a bug perhaps? How do I write out a literal backslash?

@lutter
Copy link
Member

lutter commented Sep 28, 2017

That indeed seems strange. Just for my clarification, I put together this test; the put test is the behavior you are looking for, right ? I'll have a look at what is happening there.

module T =

let sep = del /:([ \t]*\\\\\n[ \t]*:)?/ ":\\\n\t:"

let lns = [ label "entry" . sep . store /[a-z]+/ ]*

test lns get ":a:\\\n:b" =
  { "entry" = "a" }
  { "entry" = "b" }

test lns put ":a" after
  set "/entry[last()+1]" "b" = ":a:\\\n\t:b"

@lutter
Copy link
Member

lutter commented Sep 28, 2017

Found the problem - backslashes in those strings were indeed interpreted twice. PR should be up in a minute

lutter added a commit to lutter/augeas that referenced this issue Sep 28, 2017
…t out

We already unescape the default for a del when we read the lens file. Doing
it during put will cause two rounds of unescaping to happen, which is
wrong.

Fixes: hercules-team#507
lutter added a commit to lutter/augeas that referenced this issue Sep 29, 2017
…t out

We already unescape the default for a del when we read the lens file. Doing
it during put will cause two rounds of unescaping to happen, which is
wrong.

Fixes: hercules-team#507
@bodgit
Copy link
Contributor Author

bodgit commented Sep 29, 2017

Yep, I've just tested my lens against your PR changes and it now creates new entries correctly.

@bodgit
Copy link
Contributor Author

bodgit commented Sep 29, 2017

I think this same issue is present elsewhere in the codebase, consider this test case (also from #274):

module Test_getcap =

  (* Taken from the standard /etc/login.conf *)
  let login_conf = "# Default allowed authentication styles
auth-defaults:auth=passwd,skey:

#
# The default values
# To alter the default authentication types change the line:
#       :tc=auth-defaults:\\
# to be read something like: (enables passwd, \"myauth\", and activ)
#       :auth=passwd,myauth,activ:\\
# Any value changed in the daemon class should be reset in default
# class.
#
default:\
        :path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin:\
        :umask=022:\
        :datasize-max=512M:\
        :datasize-cur=512M:\
        :maxproc-max=256:\
        :maxproc-cur=128:\
        :openfiles-cur=512:\
        :stacksize-cur=4M:\
        :localcipher=blowfish,8:\
        :ypcipher=old:\
        :tc=auth-defaults:\
        :tc=auth-ftp-defaults:
"

test Getcap.lns get login_conf =
  { "#comment" = "Default allowed authentication styles" }
  { "record"
    { "name" = "auth-defaults" }
    { "capability" = "auth=passwd,skey" }
  }
  {  }
  {  }
  { "#comment" = "The default values" }
  { "#comment" = "To alter the default authentication types change the line:" }
  { "#comment" = ":tc=auth-defaults:\\" }
  { "#comment" = "to be read something like: (enables passwd, \"myauth\", and activ)" }
  { "#comment" = ":auth=passwd,myauth,activ:\\" }
  { "#comment" = "Any value changed in the daemon class should be reset in default" }
  { "#comment" = "class." }
  {  }
  { "record"
    { "name" = "default" }
    { "capability" = "path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin /usr/local/sbin" }
    { "capability" = "umask=022" }
    { "capability" = "datasize-max=512M" }
    { "capability" = "datasize-cur=512M" }
    { "capability" = "maxproc-max=256" }
    { "capability" = "maxproc-cur=128" }
    { "capability" = "openfiles-cur=512" }
    { "capability" = "stacksize-cur=4M" }
    { "capability" = "localcipher=blowfish,8" }
    { "capability" = "ypcipher=old" }
    { "capability" = "tc=auth-defaults" }
    { "capability" = "tc=auth-ftp-defaults" }
  }

I've backslash-escaped the \ and " characters in the comments from the original file as I figured at least the " characters will need them. However I can't seem to specify the backslashes in the expected output such as this line:

  { "#comment" = ":tc=auth-defaults:\\" }

I get errors like:

.../test_getcap.aug:42:17: Unexpected character #
.../test_getcap.aug:41.17-42.8:syntax error, unexpected LIDENT, expecting '}'
.../test_getcap.aug:syntax error

If I take the backslashes out of the expected output then there are no syntax errors but of course the test fails because actual/expected don't match.

@lutter
Copy link
Member

lutter commented Sep 29, 2017

I'll look into it. Could you rebase #274 onto the HEAD of master and make sure it has your latest changes to the lens and tests ? That'll make it easier for me to understand what's happening - I'll try in the meantime to repro this with a small example.

@lutter
Copy link
Member

lutter commented Sep 29, 2017

This is a manifestation of the bug fixed in 244c0ed; what happens is that the \\" on line 41 gets parsed as \ + \", and so augeas thinks the string on that line isn't terminated, and keeps reading until it finds the quotes on the next line starting "#comment" so that it thinks the # is outside a string. Things go south from there.

bodgit added a commit to bodgit/augeas that referenced this issue Sep 29, 2017
Now that we know hercules-team#507 is a thing just leave the smallest set of test cases
present. The termcap monsters will need to be added back and the lens is
currently broken for rtadvd.conf which contains quoted :'s.
@bodgit
Copy link
Contributor Author

bodgit commented Sep 29, 2017

I'm afraid I initially just merged your PR into my very ancient branch without also rebasing it onto the HEAD of master.

I've rebased my branch and for now pared down the tests so the only thing currently failing is the above test case and its backslashes.

@lutter
Copy link
Member

lutter commented Sep 30, 2017

The backslash part of the tests now work (in the sense that they do not cause syntax errors) What's failing now seem to be 'normal' typecheck errors.

@bodgit
Copy link
Contributor Author

bodgit commented Oct 1, 2017

Yeah, I made the mistake of not using the compiled augparse from the source tree and instead using the one from the binary distribution I had installed. Now the tests are a bit more reliable I can debug and test the lens much easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants