All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2)
@ 2012-01-12  8:54 Eryu Guan
  2012-01-12  8:54 ` [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2) Eryu Guan
  2012-01-19 18:12 ` [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Cyril Hrubis
  0 siblings, 2 replies; 5+ messages in thread
From: Eryu Guan @ 2012-01-12  8:54 UTC (permalink / raw)
  To: ltp-list; +Cc: Eryu Guan

[-- Attachment #1: Type: text/plain, Size: 44 bytes --]

This is a multi-part message in MIME format.

[-- Attachment #2: Type: text/plain, Size: 431 bytes --]


An empty buffer of size zero can be passed into getxattr(2) to return
the current size of the named extended attribute.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
 runtest/syscalls                                |    1 +
 testcases/kernel/syscalls/getxattr/getxattr03.c |  122 +++++++++++++++++++++++
 2 files changed, 123 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/getxattr/getxattr03.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-syscalls-getxattr03-new-testcase-to-test-getxattr-2.patch --]
[-- Type: text/x-patch; name="0001-syscalls-getxattr03-new-testcase-to-test-getxattr-2.patch", Size: 3692 bytes --]

diff --git a/runtest/syscalls b/runtest/syscalls
index 4aac38c..d786746 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -423,6 +423,7 @@ getuid03_16 getuid03_16
 
 getxattr01 getxattr01
 getxattr02 getxattr02
+getxattr03 getxattr03
 
 #Needs tty device.
 #ioctl01 ioctl01 -D /dev/tty0
diff --git a/testcases/kernel/syscalls/getxattr/getxattr03.c b/testcases/kernel/syscalls/getxattr/getxattr03.c
new file mode 100644
index 0000000..e282e78
--- /dev/null
+++ b/testcases/kernel/syscalls/getxattr/getxattr03.c
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * An empty buffer of size zero can be passed into getxattr(2) to return
+ * the current size of the named extended attribute.
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#endif
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "getxattr03";
+
+#ifdef HAVE_ATTR_XATTR_H
+#define XATTR_TEST_KEY "user.testkey"
+#define XATTR_TEST_VALUE "test value"
+#define TESTFILE "getxattr03testfile"
+
+static void setup(void);
+static void cleanup(void);
+
+int TST_TOTAL = 1;
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	char *msg;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+
+		TEST(getxattr(TESTFILE, XATTR_TEST_KEY, NULL, 0));
+
+		if (TEST_RETURN == strlen(XATTR_TEST_VALUE))
+			tst_resm(TPASS, "getxattr(2) returned correct value");
+		else
+			tst_resm(TFAIL | TTERRNO, "getxattr(2) failed");
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	int fd;
+
+	tst_require_root(NULL);
+
+	tst_tmpdir();
+
+	/* Test for xattr support and set attr value */
+	fd = creat(TESTFILE, 0644);
+	if (fd == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE);
+	close(fd);
+
+	if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE,
+	    strlen(XATTR_TEST_VALUE), XATTR_CREATE) == -1) {
+		if (errno == ENOTSUP)
+			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
+			    "mount without user_xattr option");
+		else
+			tst_brkm(TBROK | TERRNO, cleanup, "setxattr %s failed",
+			    TESTFILE);
+	}
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+	tst_rmdir();
+}
+#else /* HAVE_ATTR_XATTR_H */
+int main(int argc, char *argv[])
+{
+	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
+}
+#endif

[-- Attachment #4: Type: text/plain, Size: 186 bytes --]

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2

[-- Attachment #5: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2)
  2012-01-12  8:54 [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Eryu Guan
@ 2012-01-12  8:54 ` Eryu Guan
  2012-01-19  6:58   ` Eryu Guan
  2012-01-19 18:16   ` Cyril Hrubis
  2012-01-19 18:12 ` [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Cyril Hrubis
  1 sibling, 2 replies; 5+ messages in thread
From: Eryu Guan @ 2012-01-12  8:54 UTC (permalink / raw)
  To: ltp-list

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]


setxattr(2) to immutable and append-only files should get EPERM

There are 2 test cases:
1. Set attribute to a immutable file, setxattr(2) should return -1
   and set errno to EPERM
2. Set attribute to a append-only file, setxattr(2) should return
   -1 and set errno to EPERM

Signed-off-by: Eryu Guan <eguan@redhat.com>
---
 runtest/syscalls                                |    1 +
 testcases/kernel/syscalls/setxattr/setxattr03.c |  222 +++++++++++++++++++++++
 2 files changed, 223 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/syscalls/setxattr/setxattr03.c


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-syscalls-setxattr03-net-testcase-to-test-setxattr-2.patch --]
[-- Type: text/x-patch; name="0002-syscalls-setxattr03-net-testcase-to-test-setxattr-2.patch", Size: 6178 bytes --]

diff --git a/runtest/syscalls b/runtest/syscalls
index d786746..37dfc7e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1027,6 +1027,7 @@ setuid04_16 setuid04_16
 
 setxattr01 setxattr01
 setxattr02 setxattr02
+setxattr03 setxattr03
 
 shmat01 shmat01
 shmat02 shmat02
diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
new file mode 100644
index 0000000..223bff7
--- /dev/null
+++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/*
+ * setxattr(2) to immutable and append-only files should get EPERM
+ *
+ * There are 2 test cases:
+ * 1. Set attribute to a immutable file, setxattr(2) should return -1
+ *    and set errno to EPERM
+ * 2. Set attribute to a append-only file, setxattr(2) should return
+ *    -1 and set errno to EPERM
+ */
+
+#include "config.h"
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#endif
+#include <linux/fs.h>
+
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "setxattr03";
+
+#ifdef HAVE_ATTR_XATTR_H
+#define XATTR_TEST_KEY "user.testkey"
+#define XATTR_TEST_VALUE "this is a test value"
+#define XATTR_TEST_VALUE_SIZE 20
+
+#define IMMU_FILE "setxattr03immutable"
+#define APPEND_FILE  "setxattr03appendonly"
+
+#define set_immutable_on(fd) fsetflag(fd, 1, 1)
+#define set_immutable_off(fd) fsetflag(fd, 0, 1)
+#define set_append_on(fd) fsetflag(fd, 1, 0)
+#define set_append_off(fd) fsetflag(fd, 0, 0)
+
+struct test_case {
+	char *desc;
+	char *fname;
+	char *key;
+	char *value;
+	size_t size;
+	int flags;
+	int exp_err;
+};
+static struct test_case tc[] = {
+	{	/* case 00, set attr to immutable file */
+		.desc = "Set attr to immutable file",
+		.fname = IMMU_FILE,
+		.key = XATTR_TEST_KEY,
+		.value = XATTR_TEST_VALUE,
+		.size = XATTR_TEST_VALUE_SIZE,
+		.flags = XATTR_CREATE,
+		.exp_err = EPERM,
+	},
+	{	/* case 01, set attr to append-only file */
+		.desc = "Set attr to append-only file",
+		.fname = APPEND_FILE,
+		.key = XATTR_TEST_KEY,
+		.value = XATTR_TEST_VALUE,
+		.size = XATTR_TEST_VALUE_SIZE,
+		.flags = XATTR_CREATE,
+		.exp_err = EPERM,
+	},
+};
+
+static void setup(void);
+static void cleanup(void);
+
+static int immu_fd;
+static int append_fd;
+
+int TST_TOTAL = sizeof(tc) / sizeof(tc[0]);
+
+int main(int argc, char *argv[])
+{
+	int lc;
+	int i;
+	char *msg;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+
+		for (i = 0; i < TST_TOTAL; i++)	{
+			TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value,
+			    tc[i].size, tc[i].flags));
+
+			if (TEST_ERRNO == tc[i].exp_err) {
+				tst_resm(TPASS | TTERRNO, tc[i].desc);
+			} else {
+				tst_resm(TFAIL | TTERRNO, "%s - expected errno"
+				    " %d - Got", tc[i].desc, tc[i].exp_err);
+			}
+		}
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static int fsetflag(int fd, int on, int immutable)
+{
+	int fsflags = 0;
+	int fsfl;
+
+	if (ioctl(fd, FS_IOC_GETFLAGS, &fsflags) < 0)
+		return 1;
+
+	if (immutable)
+		fsfl = FS_IMMUTABLE_FL;
+	else
+		fsfl = FS_APPEND_FL;
+
+	if (on)
+		fsflags |= fsfl;
+	else
+		fsflags &= ~fsfl;
+
+	if (ioctl(fd, FS_IOC_SETFLAGS, &fsflags) < 0)
+		return 1;
+
+	return 0;
+}
+
+static void setup(void)
+{
+	int fd;
+
+	tst_require_root(NULL);
+
+	tst_tmpdir();
+
+	/* Test for xattr support */
+	fd = creat("testfile", 0644);
+	if (fd == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
+	close(fd);
+	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
+		if (errno == ENOTSUP)
+			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
+			    "mount without user_xattr option");
+	unlink("testfile");
+
+	/* Create test files and set file immutable or append-only */
+	immu_fd = creat(IMMU_FILE, 0644);
+	if (immu_fd == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
+		    IMMU_FILE);
+	if (set_immutable_on(immu_fd))
+		tst_brkm(TBROK | TERRNO, cleanup, "Set %s immutable failed",
+		    IMMU_FILE);
+
+	append_fd = creat(APPEND_FILE, 0644);
+	if (append_fd == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
+		    APPEND_FILE);
+	if (set_append_on(append_fd))
+		tst_brkm(TBROK | TERRNO, cleanup, "Set %s append-only failed",
+		    APPEND_FILE);
+
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	if (set_immutable_off(immu_fd))
+		tst_resm(TWARN | TERRNO, "Unset %s immutable failed",
+		    IMMU_FILE);
+	if (set_append_off(append_fd))
+		tst_resm(TWARN | TERRNO, "Unset %s append-only failed",
+		    APPEND_FILE);
+	close(immu_fd);
+	close(append_fd);
+
+	TEST_CLEANUP;
+	tst_rmdir();
+}
+#else /* HAVE_ATTR_XATTR_H */
+int main(int argc, char *argv[])
+{
+	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
+}
+#endif /* HAVE_ATTR_XATTR_H */

[-- Attachment #3: Type: text/plain, Size: 186 bytes --]

------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2)
  2012-01-12  8:54 ` [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2) Eryu Guan
@ 2012-01-19  6:58   ` Eryu Guan
  2012-01-19 18:16   ` Cyril Hrubis
  1 sibling, 0 replies; 5+ messages in thread
From: Eryu Guan @ 2012-01-19  6:58 UTC (permalink / raw)
  To: ltp-list

Hi,

On Thu, Jan 12, 2012 at 04:54:48PM +0800, Eryu Guan wrote:
> 
> setxattr(2) to immutable and append-only files should get EPERM
> 
> There are 2 test cases:
> 1. Set attribute to a immutable file, setxattr(2) should return -1
>    and set errno to EPERM
> 2. Set attribute to a append-only file, setxattr(2) should return
>    -1 and set errno to EPERM

Any comments on the two patches?

Thanks,
Eryu Guan
> 
> Signed-off-by: Eryu Guan <eguan@redhat.com>
> ---
>  runtest/syscalls                                |    1 +
>  testcases/kernel/syscalls/setxattr/setxattr03.c |  222 +++++++++++++++++++++++
>  2 files changed, 223 insertions(+), 0 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/setxattr/setxattr03.c
> 

> diff --git a/runtest/syscalls b/runtest/syscalls
> index d786746..37dfc7e 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1027,6 +1027,7 @@ setuid04_16 setuid04_16
>  
>  setxattr01 setxattr01
>  setxattr02 setxattr02
> +setxattr03 setxattr03
>  
>  shmat01 shmat01
>  shmat02 shmat02
> diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
> new file mode 100644
> index 0000000..223bff7
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
> @@ -0,0 +1,222 @@
> +/*
> + * Copyright (C) 2011 Red Hat, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +/*
> + * setxattr(2) to immutable and append-only files should get EPERM
> + *
> + * There are 2 test cases:
> + * 1. Set attribute to a immutable file, setxattr(2) should return -1
> + *    and set errno to EPERM
> + * 2. Set attribute to a append-only file, setxattr(2) should return
> + *    -1 and set errno to EPERM
> + */
> +
> +#include "config.h"
> +#include <sys/ioctl.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#ifdef HAVE_ATTR_XATTR_H
> +#include <attr/xattr.h>
> +#endif
> +#include <linux/fs.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +
> +char *TCID = "setxattr03";
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#define XATTR_TEST_KEY "user.testkey"
> +#define XATTR_TEST_VALUE "this is a test value"
> +#define XATTR_TEST_VALUE_SIZE 20
> +
> +#define IMMU_FILE "setxattr03immutable"
> +#define APPEND_FILE  "setxattr03appendonly"
> +
> +#define set_immutable_on(fd) fsetflag(fd, 1, 1)
> +#define set_immutable_off(fd) fsetflag(fd, 0, 1)
> +#define set_append_on(fd) fsetflag(fd, 1, 0)
> +#define set_append_off(fd) fsetflag(fd, 0, 0)
> +
> +struct test_case {
> +	char *desc;
> +	char *fname;
> +	char *key;
> +	char *value;
> +	size_t size;
> +	int flags;
> +	int exp_err;
> +};
> +static struct test_case tc[] = {
> +	{	/* case 00, set attr to immutable file */
> +		.desc = "Set attr to immutable file",
> +		.fname = IMMU_FILE,
> +		.key = XATTR_TEST_KEY,
> +		.value = XATTR_TEST_VALUE,
> +		.size = XATTR_TEST_VALUE_SIZE,
> +		.flags = XATTR_CREATE,
> +		.exp_err = EPERM,
> +	},
> +	{	/* case 01, set attr to append-only file */
> +		.desc = "Set attr to append-only file",
> +		.fname = APPEND_FILE,
> +		.key = XATTR_TEST_KEY,
> +		.value = XATTR_TEST_VALUE,
> +		.size = XATTR_TEST_VALUE_SIZE,
> +		.flags = XATTR_CREATE,
> +		.exp_err = EPERM,
> +	},
> +};
> +
> +static void setup(void);
> +static void cleanup(void);
> +
> +static int immu_fd;
> +static int append_fd;
> +
> +int TST_TOTAL = sizeof(tc) / sizeof(tc[0]);
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	int i;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +
> +		for (i = 0; i < TST_TOTAL; i++)	{
> +			TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value,
> +			    tc[i].size, tc[i].flags));
> +
> +			if (TEST_ERRNO == tc[i].exp_err) {
> +				tst_resm(TPASS | TTERRNO, tc[i].desc);
> +			} else {
> +				tst_resm(TFAIL | TTERRNO, "%s - expected errno"
> +				    " %d - Got", tc[i].desc, tc[i].exp_err);
> +			}
> +		}
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static int fsetflag(int fd, int on, int immutable)
> +{
> +	int fsflags = 0;
> +	int fsfl;
> +
> +	if (ioctl(fd, FS_IOC_GETFLAGS, &fsflags) < 0)
> +		return 1;
> +
> +	if (immutable)
> +		fsfl = FS_IMMUTABLE_FL;
> +	else
> +		fsfl = FS_APPEND_FL;
> +
> +	if (on)
> +		fsflags |= fsfl;
> +	else
> +		fsflags &= ~fsfl;
> +
> +	if (ioctl(fd, FS_IOC_SETFLAGS, &fsflags) < 0)
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static void setup(void)
> +{
> +	int fd;
> +
> +	tst_require_root(NULL);
> +
> +	tst_tmpdir();
> +
> +	/* Test for xattr support */
> +	fd = creat("testfile", 0644);
> +	if (fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
> +	close(fd);
> +	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
> +		if (errno == ENOTSUP)
> +			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
> +			    "mount without user_xattr option");
> +	unlink("testfile");
> +
> +	/* Create test files and set file immutable or append-only */
> +	immu_fd = creat(IMMU_FILE, 0644);
> +	if (immu_fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
> +		    IMMU_FILE);
> +	if (set_immutable_on(immu_fd))
> +		tst_brkm(TBROK | TERRNO, cleanup, "Set %s immutable failed",
> +		    IMMU_FILE);
> +
> +	append_fd = creat(APPEND_FILE, 0644);
> +	if (append_fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
> +		    APPEND_FILE);
> +	if (set_append_on(append_fd))
> +		tst_brkm(TBROK | TERRNO, cleanup, "Set %s append-only failed",
> +		    APPEND_FILE);
> +
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (set_immutable_off(immu_fd))
> +		tst_resm(TWARN | TERRNO, "Unset %s immutable failed",
> +		    IMMU_FILE);
> +	if (set_append_off(append_fd))
> +		tst_resm(TWARN | TERRNO, "Unset %s append-only failed",
> +		    APPEND_FILE);
> +	close(immu_fd);
> +	close(append_fd);
> +
> +	TEST_CLEANUP;
> +	tst_rmdir();
> +}
> +#else /* HAVE_ATTR_XATTR_H */
> +int main(int argc, char *argv[])
> +{
> +	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
> +}
> +#endif /* HAVE_ATTR_XATTR_H */


------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2)
  2012-01-12  8:54 [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Eryu Guan
  2012-01-12  8:54 ` [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2) Eryu Guan
@ 2012-01-19 18:12 ` Cyril Hrubis
  1 sibling, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2012-01-19 18:12 UTC (permalink / raw)
  To: Eryu Guan; +Cc: ltp-list, Eryu Guan

Hi!
> +#include "config.h"
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#ifdef HAVE_ATTR_XATTR_H
> +#include <attr/xattr.h>
> +#endif
> +#include "test.h"
> +#include "usctest.h"
> +
> +char *TCID = "getxattr03";
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#define XATTR_TEST_KEY "user.testkey"
> +#define XATTR_TEST_VALUE "test value"
> +#define TESTFILE "getxattr03testfile"
> +
> +static void setup(void);
> +static void cleanup(void);
> +
> +int TST_TOTAL = 1;
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +
> +		TEST(getxattr(TESTFILE, XATTR_TEST_KEY, NULL, 0));
> +
> +		if (TEST_RETURN == strlen(XATTR_TEST_VALUE))

You could use sizeof(XATTR_TEST_VALUE) - 1, which would be computed at
compile time.

> +			tst_resm(TPASS, "getxattr(2) returned correct value");
> +		else
> +			tst_resm(TFAIL | TTERRNO, "getxattr(2) failed");
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +	int fd;
> +
> +	tst_require_root(NULL);
> +
> +	tst_tmpdir();
> +
> +	/* Test for xattr support and set attr value */
> +	fd = creat(TESTFILE, 0644);
> +	if (fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create %s failed", TESTFILE);
> +	close(fd);
> +
> +	if (setxattr(TESTFILE, XATTR_TEST_KEY, XATTR_TEST_VALUE,
> +	    strlen(XATTR_TEST_VALUE), XATTR_CREATE) == -1) {

Here too.

> +		if (errno == ENOTSUP)
> +			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
> +			    "mount without user_xattr option");

Should rather say ... of fs mounted without ...

> +		else
> +			tst_brkm(TBROK | TERRNO, cleanup, "setxattr %s failed",
> +			    TESTFILE);
> +	}
> +
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	TEST_CLEANUP;
> +	tst_rmdir();
> +}
> +#else /* HAVE_ATTR_XATTR_H */
> +int main(int argc, char *argv[])
> +{
> +	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
> +}
> +#endif

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2)
  2012-01-12  8:54 ` [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2) Eryu Guan
  2012-01-19  6:58   ` Eryu Guan
@ 2012-01-19 18:16   ` Cyril Hrubis
  1 sibling, 0 replies; 5+ messages in thread
From: Cyril Hrubis @ 2012-01-19 18:16 UTC (permalink / raw)
  To: Eryu Guan; +Cc: ltp-list

Hi!
> setxattr(2) to immutable and append-only files should get EPERM
> 
> There are 2 test cases:
> 1. Set attribute to a immutable file, setxattr(2) should return -1
>    and set errno to EPERM
> 2. Set attribute to a append-only file, setxattr(2) should return
>    -1 and set errno to EPERM
> 
> Signed-off-by: Eryu Guan <eguan@redhat.com>
> ---
>  runtest/syscalls                                |    1 +
>  testcases/kernel/syscalls/setxattr/setxattr03.c |  222 +++++++++++++++++++++++
>  2 files changed, 223 insertions(+), 0 deletions(-)
>  create mode 100644 testcases/kernel/syscalls/setxattr/setxattr03.c
> 

> diff --git a/runtest/syscalls b/runtest/syscalls
> index d786746..37dfc7e 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -1027,6 +1027,7 @@ setuid04_16 setuid04_16
>  
>  setxattr01 setxattr01
>  setxattr02 setxattr02
> +setxattr03 setxattr03
>  
>  shmat01 shmat01
>  shmat02 shmat02
> diff --git a/testcases/kernel/syscalls/setxattr/setxattr03.c b/testcases/kernel/syscalls/setxattr/setxattr03.c
> new file mode 100644
> index 0000000..223bff7
> --- /dev/null
> +++ b/testcases/kernel/syscalls/setxattr/setxattr03.c
> @@ -0,0 +1,222 @@
> +/*
> + * Copyright (C) 2011 Red Hat, Inc.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of version 2 of the GNU General Public
> + * License as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * Further, this software is distributed without any warranty that it
> + * is free of the rightful claim of any third person regarding
> + * infringement or the like.  Any license provided herein, whether
> + * implied or otherwise, applies only to this software file.  Patent
> + * licenses, if any, provided herein do not apply to combinations of
> + * this program with other software, or any other product whatsoever.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> + * 02110-1301, USA.
> + */
> +
> +/*
> + * setxattr(2) to immutable and append-only files should get EPERM
> + *
> + * There are 2 test cases:
> + * 1. Set attribute to a immutable file, setxattr(2) should return -1
> + *    and set errno to EPERM
> + * 2. Set attribute to a append-only file, setxattr(2) should return
> + *    -1 and set errno to EPERM
> + */
> +
> +#include "config.h"
> +#include <sys/ioctl.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/wait.h>
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <signal.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#ifdef HAVE_ATTR_XATTR_H
> +#include <attr/xattr.h>
> +#endif
> +#include <linux/fs.h>
> +
> +#include "test.h"
> +#include "usctest.h"
> +
> +char *TCID = "setxattr03";
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#define XATTR_TEST_KEY "user.testkey"
> +#define XATTR_TEST_VALUE "this is a test value"
> +#define XATTR_TEST_VALUE_SIZE 20

This one could be defined as (sizeof(XATTR_TEST_VALUE) - 1) as well, or
couldn't?

> +#define IMMU_FILE "setxattr03immutable"
> +#define APPEND_FILE  "setxattr03appendonly"
> +
> +#define set_immutable_on(fd) fsetflag(fd, 1, 1)
> +#define set_immutable_off(fd) fsetflag(fd, 0, 1)
> +#define set_append_on(fd) fsetflag(fd, 1, 0)
> +#define set_append_off(fd) fsetflag(fd, 0, 0)
> +
> +struct test_case {
> +	char *desc;
> +	char *fname;
> +	char *key;
> +	char *value;
> +	size_t size;
> +	int flags;
> +	int exp_err;
> +};
> +static struct test_case tc[] = {
> +	{	/* case 00, set attr to immutable file */
> +		.desc = "Set attr to immutable file",
> +		.fname = IMMU_FILE,
> +		.key = XATTR_TEST_KEY,
> +		.value = XATTR_TEST_VALUE,
> +		.size = XATTR_TEST_VALUE_SIZE,
> +		.flags = XATTR_CREATE,
> +		.exp_err = EPERM,
> +	},
> +	{	/* case 01, set attr to append-only file */
> +		.desc = "Set attr to append-only file",
> +		.fname = APPEND_FILE,
> +		.key = XATTR_TEST_KEY,
> +		.value = XATTR_TEST_VALUE,
> +		.size = XATTR_TEST_VALUE_SIZE,
> +		.flags = XATTR_CREATE,
> +		.exp_err = EPERM,
> +	},
> +};
> +
> +static void setup(void);
> +static void cleanup(void);
> +
> +static int immu_fd;
> +static int append_fd;
> +
> +int TST_TOTAL = sizeof(tc) / sizeof(tc[0]);
> +
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	int i;
> +	char *msg;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +
> +		for (i = 0; i < TST_TOTAL; i++)	{
> +			TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value,
> +			    tc[i].size, tc[i].flags));
> +
> +			if (TEST_ERRNO == tc[i].exp_err) {
> +				tst_resm(TPASS | TTERRNO, tc[i].desc);
> +			} else {
> +				tst_resm(TFAIL | TTERRNO, "%s - expected errno"
> +				    " %d - Got", tc[i].desc, tc[i].exp_err);
> +			}
> +		}
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static int fsetflag(int fd, int on, int immutable)
> +{
> +	int fsflags = 0;
> +	int fsfl;
> +
> +	if (ioctl(fd, FS_IOC_GETFLAGS, &fsflags) < 0)
> +		return 1;
> +
> +	if (immutable)
> +		fsfl = FS_IMMUTABLE_FL;
> +	else
> +		fsfl = FS_APPEND_FL;
> +
> +	if (on)
> +		fsflags |= fsfl;
> +	else
> +		fsflags &= ~fsfl;
> +
> +	if (ioctl(fd, FS_IOC_SETFLAGS, &fsflags) < 0)
> +		return 1;
> +
> +	return 0;
> +}
> +
> +static void setup(void)
> +{
> +	int fd;
> +
> +	tst_require_root(NULL);
> +
> +	tst_tmpdir();
> +
> +	/* Test for xattr support */
> +	fd = creat("testfile", 0644);
> +	if (fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create testfile failed");
> +	close(fd);
> +	if (setxattr("testfile", "user.test", "test", 4, XATTR_CREATE) == -1)
> +		if (errno == ENOTSUP)
> +			tst_brkm(TCONF, cleanup, "No xattr support in fs or "
> +			    "mount without user_xattr option");

Here as mounted well.

> +	unlink("testfile");
> +
> +	/* Create test files and set file immutable or append-only */
> +	immu_fd = creat(IMMU_FILE, 0644);
> +	if (immu_fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
> +		    IMMU_FILE);
> +	if (set_immutable_on(immu_fd))
> +		tst_brkm(TBROK | TERRNO, cleanup, "Set %s immutable failed",
> +		    IMMU_FILE);
> +
> +	append_fd = creat(APPEND_FILE, 0644);
> +	if (append_fd == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "Create test file(%s) failed",
> +		    APPEND_FILE);
> +	if (set_append_on(append_fd))
> +		tst_brkm(TBROK | TERRNO, cleanup, "Set %s append-only failed",
> +		    APPEND_FILE);
> +
> +	TEST_PAUSE;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (set_immutable_off(immu_fd))
> +		tst_resm(TWARN | TERRNO, "Unset %s immutable failed",
> +		    IMMU_FILE);
> +	if (set_append_off(append_fd))
> +		tst_resm(TWARN | TERRNO, "Unset %s append-only failed",
> +		    APPEND_FILE);
> +	close(immu_fd);
> +	close(append_fd);
> +
> +	TEST_CLEANUP;
> +	tst_rmdir();
> +}
> +#else /* HAVE_ATTR_XATTR_H */
> +int main(int argc, char *argv[])
> +{
> +	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
> +}
> +#endif /* HAVE_ATTR_XATTR_H */

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-19 18:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-12  8:54 [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Eryu Guan
2012-01-12  8:54 ` [LTP] [PATCH 2/2] syscalls/setxattr03: net testcase to test setxattr(2) Eryu Guan
2012-01-19  6:58   ` Eryu Guan
2012-01-19 18:16   ` Cyril Hrubis
2012-01-19 18:12 ` [LTP] [PATCH 1/2] syscalls/getxattr03: new testcase to test getxattr(2) Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.