public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Rafael David Tinoco <rafael.tinoco@linaro.org>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 2/2] syscalls/lremovexattr: Add lremovexattr() test
Date: Thu,  8 Nov 2018 16:33:20 -0200	[thread overview]
Message-ID: <20181108183320.11262-2-rafael.tinoco@linaro.org> (raw)
In-Reply-To: <20181108183320.11262-1-rafael.tinoco@linaro.org>

Fixes: #276

This commit implements a test for lremovexattr(). According to attr(5),
extended attributes are interpreted differently among files, directories
and symbolic links. User attributes are only allowed for regular files
and directories, thus the need to test security.* attributes being
removed from symbolic links.

Signed-off-by: Rafael David Tinoco <rafael.tinoco@linaro.org>
---
 runtest/syscalls                              |   2 +
 .../kernel/syscalls/lremovexattr/.gitignore   |   1 +
 .../kernel/syscalls/lremovexattr/Makefile     |   8 ++
 .../syscalls/lremovexattr/lremovexattr01.c    | 132 ++++++++++++++++++
 4 files changed, 143 insertions(+)
 create mode 100644 testcases/kernel/syscalls/lremovexattr/.gitignore
 create mode 100644 testcases/kernel/syscalls/lremovexattr/Makefile
 create mode 100644 testcases/kernel/syscalls/lremovexattr/lremovexattr01.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 24110b623..26c142bf8 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -582,6 +582,8 @@ llseek01 llseek01
 llseek02 llseek02
 llseek03 llseek03
 
+lremovexattr01 lremovexattr01
+
 lseek01 lseek01
 lseek02 lseek02
 lseek07 lseek07
diff --git a/testcases/kernel/syscalls/lremovexattr/.gitignore b/testcases/kernel/syscalls/lremovexattr/.gitignore
new file mode 100644
index 000000000..810f86214
--- /dev/null
+++ b/testcases/kernel/syscalls/lremovexattr/.gitignore
@@ -0,0 +1 @@
+lremovexattr01
diff --git a/testcases/kernel/syscalls/lremovexattr/Makefile b/testcases/kernel/syscalls/lremovexattr/Makefile
new file mode 100644
index 000000000..f71e4fc25
--- /dev/null
+++ b/testcases/kernel/syscalls/lremovexattr/Makefile
@@ -0,0 +1,8 @@
+# Copyright (c) 2018 - Linaro Limited. All rights reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
\ No newline at end of file
diff --git a/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c b/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c
new file mode 100644
index 000000000..2cf46ebdf
--- /dev/null
+++ b/testcases/kernel/syscalls/lremovexattr/lremovexattr01.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Linaro Limited. All rights reserved.
+ * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
+ */
+
+/*
+ * Test Name: lremovexattr01
+ *
+ * Description:
+ * lremovexattr(2) removes the extended attribute identified by a name and
+ * associated with a given path in the filesystem. Unlike removexattr(2),
+ * lremovexattr(2) removes the attribute from the symbolic link only, and not
+ * the file. This test verifies that a simple call to lremovexattr(2) removes,
+ * indeed, a previously set attribute key/value from a symbolic link, and the
+ * symbolic link _only_.
+ *
+ * Note:
+ * According to attr(5), extended attributes are interpreted differently from
+ * regular files, directories and symbolic links. User attributes are only
+ * allowed for regular files and directories, thus the need of using security.*
+ * attributes for this test.
+ */
+
+#include "config.h"
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#ifdef HAVE_SYS_XATTR_H
+# include <sys/xattr.h>
+#endif
+
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_XATTR_H
+
+#define ENOATTR ENODATA
+
+#define XATTR_KEY		"security.key1"
+#define XATTR_VALUE		"file and link"
+#define XATTR_VALUE_SIZE	13
+
+#define MNTPOINT "mntpoint"
+#define FILENAME MNTPOINT"/lremovexattr01testfile"
+#define SYMLINK  MNTPOINT"/lremovexattr01symlink"
+
+static char got_value[XATTR_VALUE_SIZE];
+
+static void verify_lremovexattr(void)
+{
+	/* set attribute on both: file and symlink */
+
+	SAFE_SETXATTR(FILENAME, XATTR_KEY, XATTR_VALUE, XATTR_VALUE_SIZE,
+			XATTR_CREATE);
+
+	SAFE_LSETXATTR(SYMLINK, XATTR_KEY, XATTR_VALUE, XATTR_VALUE_SIZE,
+			XATTR_CREATE);
+
+	/* remove attribute from symlink only */
+
+	TEST(lremovexattr(SYMLINK, XATTR_KEY));
+
+	if (TST_RET != 0) {
+		tst_res(TFAIL | TTERRNO, "lremovexattr(2) failed");
+		return;
+	}
+
+	/* make sure attribute is gone from symlink */
+
+	memset(&got_value, 0, XATTR_VALUE_SIZE);
+
+	TEST(lgetxattr(SYMLINK, XATTR_KEY, &got_value, XATTR_VALUE_SIZE));
+
+	if (TST_RET >= 0) {
+		tst_res(TFAIL, "lremovexattr(2) did not work");
+		return;
+	}
+
+	if (TST_RET < 0 && TST_ERR != ENOATTR) {
+		tst_brk(TBROK, "lgetxattr(2) failed unexpectedly");
+		return;
+	}
+
+	/* check if file is unchanged, like it should be */
+
+	memset(&got_value, 0, XATTR_VALUE_SIZE);
+
+	TEST(getxattr(FILENAME, XATTR_KEY, &got_value, XATTR_VALUE_SIZE));
+
+	if (TST_RET <= 0) {
+		tst_res(TFAIL, "lremovexattr(2) deleted file attribute");
+		return;
+	}
+
+	if (strcmp(got_value, XATTR_VALUE)) {
+		tst_res(TFAIL, "lremovexattr(2) changed file attribute");
+		return;
+	}
+
+	/* cleanup file attribute for iteration */
+
+	SAFE_REMOVEXATTR(FILENAME, XATTR_KEY);
+
+	tst_res(TPASS, "lremovexattr(2) removed attribute as expected");
+}
+
+static void setup(void)
+{
+	SAFE_TOUCH(FILENAME, 0644, NULL);
+
+	if (symlink(FILENAME, SYMLINK) < 0) {
+		tst_brk(TCONF, "symlink() not supported");
+		return;
+	}
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_lremovexattr,
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
+
+#else /* HAVE_SYS_XATTR_H */
+TST_TEST_TCONF("<sys/xattr.h> does not exist");
+#endif
-- 
2.19.1


  reply	other threads:[~2018-11-08 18:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-01 22:05 [LTP] [PATCH] syscalls/fremovexattr: Add fremovexattr() tests Rafael David Tinoco
2018-11-04 23:45 ` Rafael David Tinoco
2018-11-05  0:25   ` [LTP] [PATCH v2 1/2] " Rafael David Tinoco
2018-11-05  0:25     ` [LTP] [PATCH v2 2/2] syscalls/lremovexattr: Add lremovexattr() test Rafael David Tinoco
2018-11-07 15:38     ` [LTP] [PATCH v2 1/2] syscalls/fremovexattr: Add fremovexattr() tests Cyril Hrubis
2018-11-07 15:50       ` Rafael David Tinoco
2018-11-08 18:33       ` [LTP] [PATCH v3 " Rafael David Tinoco
2018-11-08 18:33         ` Rafael David Tinoco [this message]
2018-11-16 19:37           ` [LTP] [PATCH v3 2/2] syscalls/lremovexattr: Add lremovexattr() test Cyril Hrubis
2018-11-18 13:37             ` Rafael David Tinoco
2018-11-15 16:33         ` [LTP] [PATCH v3 1/2] syscalls/fremovexattr: Add fremovexattr() tests Cyril Hrubis
2018-11-16  0:33           ` Rafael David Tinoco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181108183320.11262-2-rafael.tinoco@linaro.org \
    --to=rafael.tinoco@linaro.org \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox