lib/replace: validate xattr namespace prefix on FreeBSD
authorRalph Boehme <slow@samba.org>
Fri, 3 Feb 2017 17:08:12 +0000 (18:08 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 10 Feb 2017 17:33:17 +0000 (18:33 +0100)
commit738797d8ad6908de457786cc948dcde151e2b9e1
treefdc127546618492a3d41f68ca8377e32f1522f61
parente4d1f8354f97ab9007e4c5f7d164937bdc5cd6f1
lib/replace: validate xattr namespace prefix on FreeBSD

We should validate the xattr name string ensuring it either begins with
"sytem." or "user.". If it doesn't, we should fail the request with
EINVAL.

The FreeBSD xattr API uses namespaces but doesn't put the namespace name
as a string prefix at the beginning of the xattr name. It gets passed as
an additional int arg instead.

On the other hand, our libreplace xattr API expects the caller to put a
namespace prefix into the xattr name.

Unfortunately the conversion and stripping of the namespace string prefix
from the xattr name gives the following unexpected result on FreeBSD:

rep_setxattr("foo.bar", ...) => xattr with name "bar"

The code checks if the name begins with "system.", if it doesn't find
it, it defaults to the user namespace and then does a strchr(name, '.')
which skips *any* leading string before the first dot.

Bug: https://bugzilla.samba.org/show_bug.cgi?id=12490

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/replace/xattr.c