From: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 5/5] setregid04: Convert to newlib
Date: Mon, 10 Sep 2018 16:19:01 +0200 [thread overview]
Message-ID: <20180910141901.20541-5-cfamullaconrad@suse.de> (raw)
In-Reply-To: <20180910141901.20541-1-cfamullaconrad@suse.de>
Signed-off-by: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
---
testcases/kernel/syscalls/setregid/setregid04.c | 116 ++++++------------------
1 file changed, 27 insertions(+), 89 deletions(-)
diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c
index bf744ff05..e0f1853a1 100644
--- a/testcases/kernel/syscalls/setregid/setregid04.c
+++ b/testcases/kernel/syscalls/setregid/setregid04.c
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) International Business Machines Corp., 2001
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
* Ported by John George
*/
@@ -22,16 +9,8 @@
* Test setregid() when executed by root.
*/
-#include <errno.h>
-#include <pwd.h>
-#include <grp.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "test.h"
-#include "compat_16.h"
-
-TCID_DEFINE(setregid04);
+#include "tst_test.h"
+#include "compat_tst_16.h"
static gid_t neg_one = -1;
@@ -70,88 +49,47 @@ struct test_data_t {
"After setregid(-1, nobody)"}
};
-int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
-
static void setup(void);
-static void cleanup(void);
static void gid_verify(struct group *ru, struct group *eu, const char *when);
-int main(int ac, char **av)
+static void run(unsigned int i)
{
- int lc;
+ /* Set the real or effective group id */
+ TEST(SETREGID(*test_data[i].real_gid, *test_data[i].eff_gid));
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- int i;
-
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; i++) {
- /* Set the real or effective group id */
- TEST(SETREGID(cleanup, *test_data[i].real_gid,
- *test_data[i].eff_gid));
-
- if (TEST_RETURN == -1) {
- tst_resm(TBROK, "setregid(%d, %d) failed",
- *test_data[i].real_gid,
- *test_data[i].eff_gid);
- } else {
- gid_verify(test_data[i].exp_real_usr,
- test_data[i].exp_eff_usr,
- test_data[i].test_msg);
- }
- }
+ if (TST_RET == -1) {
+ tst_res(TBROK | TTERRNO, "setregid(%d, %d) failed",
+ *test_data[i].real_gid, *test_data[i].eff_gid);
+ } else {
+ gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr,
+ test_data[i].test_msg);
}
-
- cleanup();
- tst_exit();
}
-#define SAFE_GETGROUP(GROUPNAME) \
- if (getgrnam(#GROUPNAME) == NULL) { \
- tst_brkm(TBROK, NULL, "Couldn't find the `" #GROUPNAME "' group"); \
- } \
- GROUPNAME ## _gr = *(getgrnam(#GROUPNAME));
-
-#define SAFE_GETGROUP_FALLBACK(GROUPNAME, GROUPNAME2) \
- if (getgrnam(#GROUPNAME) != NULL) \
- GROUPNAME ## _gr = *(getgrnam(#GROUPNAME)); \
- else if (getgrnam(#GROUPNAME2) != NULL) { \
- GROUPNAME ## _gr = *(getgrnam(#GROUPNAME2)); \
- tst_resm(TINFO, "`" #GROUPNAME "' group not found, trying fallback `" #GROUPNAME2 "' group"); \
- } else \
- tst_brkm(TBROK, NULL, "Couldn't find neither`" #GROUPNAME "' `" #GROUPNAME2 "' nor group");
-
static void setup(void)
{
- tst_require_root();
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- SAFE_GETGROUP(root);
- SAFE_GETGROUP_FALLBACK(nobody, nogroup);
- SAFE_GETGROUP(daemon);
- SAFE_GETGROUP(bin);
-
- TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
+ root_gr = *SAFE_GETGRNAM("root");
+ nobody_gr = *SAFE_GETGRNAM_FALLBACK("nobody", "nogroup");
+ daemon_gr = *SAFE_GETGRNAM("daemon");
+ bin_gr = *SAFE_GETGRNAM("bin");
}
static void gid_verify(struct group *rg, struct group *eg, const char *when)
{
if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
- tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
+ tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
when, getgid(), getegid());
- tst_resm(TINFO, "Expected: real gid = %d; effective gid = %d",
+ tst_res(TINFO, "Expected: real gid = %d; effective gid = %d",
rg->gr_gid, eg->gr_gid);
} else {
- tst_resm(TPASS, "real or effective gid was modified as "
- "expected");
+ tst_res(TPASS,
+ "real or effective gid was modified as expected");
}
}
+
+static struct tst_test test = {
+ .tcnt = ARRAY_SIZE(test_data),
+ .needs_root = 1,
+ .test = run,
+ .setup = setup,
+};
--
2.16.4
next prev parent reply other threads:[~2018-09-10 14:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-10 14:18 [LTP] [PATCH v2 1/5] setregid01: Convert to newlib Clemens Famulla-Conrad
2018-09-10 14:18 ` [LTP] [PATCH v2 2/5] tst_safe_macros: add SAFE_GETGRGID() Clemens Famulla-Conrad
2018-10-02 14:20 ` Cyril Hrubis
2018-10-02 23:23 ` Clemens Famulla-Conrad
2018-10-03 7:46 ` Cyril Hrubis
2018-09-10 14:18 ` [LTP] [PATCH v2 3/5] setregid02: Convert to newlib Clemens Famulla-Conrad
2018-09-10 14:19 ` [LTP] [PATCH v2 4/5] tst_safe_macros: add SAFE_GETGRNAM_FALLBACK() Clemens Famulla-Conrad
2018-09-10 14:19 ` Clemens Famulla-Conrad [this message]
2018-09-11 7:42 ` [LTP] [PATCH v2 1/5] setregid01: Convert to newlib Richard Palethorpe
2018-10-02 14:07 ` 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=20180910141901.20541-5-cfamullaconrad@suse.de \
--to=cfamullaconrad@suse.de \
--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