From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: add new testcase
Date: Wed, 10 Feb 2016 15:04:15 +0100 [thread overview]
Message-ID: <20160210140414.GD10106@rei.lan> (raw)
In-Reply-To: <1454058489-25625-1-git-send-email-yangx.jy@cn.fujitsu.com>
Hi!
> +#ifdef HAVE_ATTR_XATTR_H
> +#define SECURITY_KEY "security.symtest"
^
Why symtest, I would preffere to have 'ltp'
substring in everything that testcases create
so that is clear where it came from
> +#define SECURITY_KEY_INIT "security.selinux"
> +#define VALUE "test"
> +#define VALUE_SIZE 4
> +#define KEY_SIZE 17
> +static void verify_llistxattr(void)
> +{
> + int n;
> + int se = 1;
> + int size = 64;
> + char buf[size];
> + char cmp_buf1[size];
> + char cmp_buf2[size];
> +
> + /* check selinux initialized attr */
> + n = lgetxattr("symlink", SECURITY_KEY_INIT, NULL, 0);
> + if (n == -1) {
> + if (errno == ENOATTR) {
> + se = 0;
> + } else {
> + tst_brkm(TFAIL | TERRNO, cleanup,
> + "lgetxattr() failed");
> + }
> + }
I do not like the special case for seliux here. What we should do
instead is to:
* Create file/symlink and store it's attribute list
* Add an attribute
* Check that the list has exactly one more attribute
* Remove the file/symlink
And there should be a comment that selinux adds default attribute to
newly created files/symlinks.
> + TEST(llistxattr("symlink", buf, size));
> + if (TEST_RETURN == -1) {
> + tst_resm(TFAIL | TTERRNO, "llistxattr() failed");
> + return;
> + }
> +
> + if (TEST_RETURN != KEY_SIZE*(1 + se)) {
> + tst_resm(TFAIL, "llistxattr() retrieved %li bytes, "
> + "expected %i", TEST_RETURN, KEY_SIZE*2);
> + return;
> + }
> +
> + /*
> + * The list of names is returned as an unordered array of
> + * NULL-terminated character strings.
> + */
> + if (se == 1) {
> + memcpy(cmp_buf1, SECURITY_KEY, KEY_SIZE);
> + memcpy(cmp_buf1+KEY_SIZE, SECURITY_KEY_INIT, KEY_SIZE);
> + memcpy(cmp_buf2, SECURITY_KEY_INIT, KEY_SIZE);
> + memcpy(cmp_buf2+KEY_SIZE, SECURITY_KEY, KEY_SIZE);
> +
> + if (memcmp(buf, cmp_buf1, KEY_SIZE*(1 + se)) && memcmp(buf, cmp_buf2, KEY_SIZE*(1 + se))) {
> + tst_resm(TFAIL, "name list mismatched");
> + return;
> + }
> + } else {
> + if (memcmp(buf, SECURITY_KEY, KEY_SIZE*(1 + se))) {
> + tst_resm(TFAIL, "name list mismatched");
> + return;
> + }
> + }
If you have actually checked that the list has 2 attributes all you
need to do here is to check that it includes both attributes.
All you need is a function that takes attribute list and checks that
there is attribute included, i.e.
int has_attribute(const char *list, unsigned int llen, const char *attr)
{
unsigned int i;
for (i = 0; i < llen; i += strlen(list + i) + 1) {
if (!strcmp(list+i, attr))
return 1;
}
return 0;
}
...
if (!has_attribute(buf, size, attr_1)) {
tst_resm(TFAIL, "Missing attribute %s", attr_1);
return;
}
if (!has_attribute(buf, size, attr_2)) {
...
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2016-02-10 14:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-29 9:08 [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: add new testcase Xiao Yang
2016-01-29 9:08 ` [LTP] [PATCH 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-10 13:41 ` Cyril Hrubis
2016-01-29 9:08 ` [LTP] [PATCH 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-10 14:12 ` Cyril Hrubis
2016-02-10 14:04 ` Cyril Hrubis [this message]
2016-02-18 10:02 ` [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: " Xiao Yang
2016-02-18 12:03 ` Cyril Hrubis
2016-02-19 4:55 ` [LTP] [PATCH v2 " Xiao Yang
2016-02-19 4:55 ` [LTP] [PATCH v2 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-24 13:54 ` Cyril Hrubis
2016-02-19 4:55 ` [LTP] [PATCH v2 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-24 14:28 ` Cyril Hrubis
2016-02-25 3:55 ` [LTP] [PATCH v3] " Xiao Yang
2016-02-25 11:21 ` Cyril Hrubis
2016-02-24 13:38 ` [LTP] [PATCH v2 1/3] llistxattr/llistxattr01.c: " Cyril Hrubis
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=20160210140414.GD10106@rei.lan \
--to=chrubis@suse.cz \
--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