[augeas-devel] escaping special characters in the path sent to aug_get()

Laine Stump laine at redhat.com
Fri Dec 5 18:02:17 UTC 2014


I want to sanitize the path sent to aug_get(aug, path, &result) (and
probably other functions, and it's not clear to me what characters are
considered "special", nor how to escape them in the string. An example
of this, let's say I want to know the mac address of a user-supplied
network interface, so I do this: 

  sprintf(&path, "/files/sys/class/net/%s/address/content", intf)

  r = aug_match(aug, path, &mac);

If the interface name contains special characters interpreted by
aug_match's "xpath-like" parser, then I won't necessarily get back the
results I expected.

So what I would like to do is precede this with a call to
"aug_escape(intf, &sanitized_intf)" which would escape any characters
having a special meaning to augeas. An API in augeas would be very nice,
but since that doesn't exist, can someone point me at some documentation
that is easier to understand than the comments in augeas.c? :-o


========== Side Topic

One person suggested creating an augeas variable whose value was the
contents of intf, then referencing that variable in the path sent to
aug_match(); unfortunately, having a path string like this:

    /files/sys/class/net/$interface/address/content

seems to never work. For that matter, defining a variable that contains
the entire path, then calling aug_get(aug, "$interface", &mac) doesn't
even do what I want - variable substitution does work when the *entire
path string* is "$variableName", but the xpath-like evaluation still
takes place, so the special characters are still interpreted and acted on.
 




More information about the augeas-devel mailing list