diff options
author | Jeff Mahoney <jeffm@suse.com> | 2015-12-02 11:09:52 -0500 |
---|---|---|
committer | Andreas Gruenbacher <agruenba@redhat.com> | 2015-12-05 23:16:38 +0100 |
commit | b6ba5c29a2ad9dcaac4191e81d2b497d396fa7d1 (patch) | |
tree | 3a2210ff76c4fbeaf47a7c2e774ea8f356c8942f /libmisc | |
parent | f2feb94748bd3c64ed153461afa51aebbd717821 (diff) | |
download | acl-b6ba5c29a2ad9dcaac4191e81d2b497d396fa7d1.tar.gz |
quote: escape literal backslashes
The octal unquote code can't handle escaping backslashes except by
specifying the octal code for the backslash. That's not exactly a
user-friendly interface for a scenario that may not be that uncommon.
The unquote code isn't documented in the man page and can result in
confusion when specifying names via a Windows domain that are entirely
numeric (e.g. WINDOM\1234).
This patch adds handling to allow literal escaping of the backslash (\\)
as both input and output and documents the quoting rules in the setfacl
man page. Also included are test cases for escaped backslashes followed
by letters, escaped backslashes followed by numbers, and the original
use case of escaped character literals.
[Minor fixes by Andreas Gruenbacher.]
Diffstat (limited to 'libmisc')
-rw-r--r-- | libmisc/quote.c | 5 | ||||
-rw-r--r-- | libmisc/unquote.c | 2 |
2 files changed, 6 insertions, 1 deletions
diff --git a/libmisc/quote.c b/libmisc/quote.c index a28800c..a24c958 100644 --- a/libmisc/quote.c +++ b/libmisc/quote.c @@ -44,11 +44,14 @@ const char *__acl_quote(const char *str, const char *quote_chars) (s - (unsigned char *)str) + nonpr * 3 + 1)) return NULL; for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) { - if (*s == '\\' || strchr(quote_chars, *s)) { + if (strchr(quote_chars, *s)) { *q++ = '\\'; *q++ = '0' + ((*s >> 6) ); *q++ = '0' + ((*s >> 3) & 7); *q++ = '0' + ((*s ) & 7); + } else if (*s == '\\') { + *q++ = '\\'; + *q++ = '\\'; } else *q++ = *s; } diff --git a/libmisc/unquote.c b/libmisc/unquote.c index 4f4ce7c..b8b3505 100644 --- a/libmisc/unquote.c +++ b/libmisc/unquote.c @@ -46,6 +46,8 @@ char *__acl_unquote(char *str) ((*(s+2) - '0') << 3) + ((*(s+3) - '0') ); s += 3; + } else if (*s == '\\' && *(s+1) == '\\') { + *t++ = *s++; } else *t++ = *s; } while (*s++ != '\0'); |