Skip to content

Commit

Permalink
Refactor setresgit04 test
Browse files Browse the repository at this point in the history
Simplify the overall structure using newest LTP API.

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Andrea Cervesato <[email protected]>
[ pvorel: setresgid(...) => SETRESGID(...) to keep check for 16-bit support ]
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
acerv authored and pevik committed Jan 3, 2025
1 parent 23ccd76 commit 7aea2ce
Showing 1 changed file with 25 additions and 79 deletions.
104 changes: 25 additions & 79 deletions testcases/kernel/syscalls/setresgid/setresgid04.c
Original file line number Diff line number Diff line change
@@ -1,101 +1,47 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2014 Fujitsu Ltd.
* Author: Zeng Linggang <[email protected]>
*
* 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.
*
* 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.
* Copyright (c) Zeng Linggang <[email protected]>
* Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
*/
/*
* Test Description:
* Verify that,
* File system GID is always set to the same value as the (possibly new)
* effective GID.

/*\
* [Description]
*
* Verify that setresgid() syscall always sets the file system GID to the same
* value as the new effective GID.
*/

#define _GNU_SOURCE

#include <errno.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/stat.h>
#include "test.h"
#include "safe_macros.h"
#include "compat_16.h"
#include "tst_test.h"
#include "compat_tst_16.h"

TCID_DEFINE(setresgid04);
int TST_TOTAL = 1;
static struct passwd *ltpuser;
static void setup(void);
static void setresgid_verify(void);
static void cleanup(void);

int main(int argc, char **argv)
static void run(void)
{
int i, lc;

tst_parse_opts(argc, argv, NULL, NULL);
struct stat buf;

setup();
TST_EXP_PASS(SETRESGID(-1, ltpuser->pw_gid, -1));

for (lc = 0; TEST_LOOPING(lc); lc++) {
tst_count = 0;
for (i = 0; i < TST_TOTAL; i++)
setresgid_verify();
}
SAFE_TOUCH("test_file", 0644, NULL);
SAFE_STAT("test_file", &buf);

cleanup();
tst_exit();
TST_EXP_EQ_LI(ltpuser->pw_gid, buf.st_gid);
}

static void setup(void)
{
tst_require_root();

tst_sig(NOFORK, DEF_HANDLER, cleanup);

TEST_PAUSE;

tst_tmpdir();

ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
ltpuser = SAFE_GETPWNAM("nobody");

GID16_CHECK(ltpuser->pw_gid, "setresgid", cleanup)
GID16_CHECK(ltpuser->pw_gid, "setresgid");
}

static void setresgid_verify(void)
{
struct stat buf;

TEST(SETRESGID(cleanup, -1, ltpuser->pw_gid, -1));

if (TEST_RETURN != 0) {
tst_resm(TFAIL | TTERRNO, "setresgid failed unexpectedly");
return;
}

SAFE_TOUCH(cleanup, "test_file", 0644, NULL);

SAFE_STAT(cleanup, "test_file", &buf);

if (ltpuser->pw_gid == buf.st_gid) {
tst_resm(TPASS, "setresgid succeeded as expected");
} else {
tst_resm(TFAIL,
"setresgid failed unexpectedly; egid(%d) - st_gid(%d)",
ltpuser->pw_gid, buf.st_gid);
}
}

static void cleanup(void)
{
tst_rmdir();
}
static struct tst_test test = {
.test_all = run,
.setup = setup,
.needs_root = 1,
.needs_tmpdir = 1,
};

0 comments on commit 7aea2ce

Please sign in to comment.