Skip to contentSkip to conversation

syscalls/add_key05: Add userdel and groupdel before useradd

PATCH zhaogongyi via ltp 1 participant 1 message Oct 11, 2022

lore
Share & tools
lore
#0 lore raw

Hi,

Thanks for your review! I have resubmit the patch as your suggestions. Please see: https://patchwork.ozlabs.org/project/ltp/patch/[email protected]/

Regards,
Gongyi

Quoted 76 lines

Hi Zhao

Quoted 6 lines

If the test exit abnormal, some user/group will be left, and the next running of the test will fail and report:

tst_buffers.c:55: TINFO: Test is using guarded buffers tst_test.c:1526: TINFO: Timeout per run is 0h 00m 30s
useradd: group ltp_add_key05_0 exists - if you want to add this user

to that group, use -g.

Quoted 3 lines
   add_key05.c:41: TBROK: useradd failed (9)
   userdel: user 'ltp_add_key05_0' does not exist
   add_key05.c:56: TWARN: 'userdel -r ltp_add_key05_0' failed:

ENOENT

Quoted 13 lines

(2)

---
  testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
  1 file changed, 5 insertions(+)
testcases/kernel/syscalls/add_key/add_key05.c +0 -0
index 71a88d1a8..42ad04eec 100644

testcases/kernel/syscalls/add_key/add_key05.c static void add_user(char n) · line 36

Quoted 3 lines
testcases/kernel/syscalls/add_key/add_key05.c +0 -0
@@ -34,8 +34,13 @@ static void add_user(char n)
  {
  	char username[] = "ltp_add_key05_n";
  	const char *const cmd_useradd[] = {"useradd", username,

NULL};

testcases/kernel/syscalls/add_key/add_key05.c static void add_user(char n) · line 42

Quoted 6 lines
testcases/kernel/syscalls/add_key/add_key05.c +4 -0
+	const char *const cmd_userdel[] = {"userdel", "-r", username, NULL};
+	const char *const cmd_groupdel[] = {"groupdel", username, NULL};
  	struct passwd *pw;
 
+	tst_cmd(cmd_userdel, NULL, NULL, TST_CMD_PASS_RETVAL);
+	tst_cmd(cmd_groupdel, NULL, NULL, TST_CMD_PASS_RETVAL);

If so, it always uses ltp_add_key05_n instead of ltp_add_key05_0 or 1.

tst_buffers.c:55: TINFO: Test is using guarded buffers tst_test.c:1528: TINFO: Timeout per run is 0h 00m 30s
userdel: user 'ltp_add_key05_n' does not exist
groupdel: group 'ltp_add_key05_n' does not exist add_key05.c:49: TINFO: Created user ltp_add_key05_0 add_key05.c:190: TINFO: User: 0, UID: 1005
add_key05.c:87: TINFO: test max bytes under unprivileged user add_key05.c:112: TPASS: add_key(test_inv) failed as expected: EDQUOT
(122)
add_key05.c:135: TPASS: add_key(test_max) succeeded as expected add_key05.c:138: TPASS: allow reaching the max bytes exactly
userdel: user 'ltp_add_key05_n' does not exist
groupdel: group 'ltp_add_key05_n' does not exist add_key05.c:49: TINFO: Created user ltp_add_key05_1 add_key05.c:190: TINFO: User: 1, UID: 1006 add_key05.c:148: TINFO: test max keys under unprivileged user add_key05.c:166: TPASS: add_key(test_invalid_key) failed as expected:
EDQUOT (122)
add_key05.c:173: TPASS: allow reaching the max key(200) exactly

Also, I think we should ignore this "userdel: user 'ltp_add_key05_n' does not exist" noise on those system that doesn't hit this problem.

So we can use tst_cmd(cmd_userdel, NULL, "/dev/null", TST_CMD_PASS_RETVAL).

Best Regards
Yang Xu

Quoted 8 lines
testcases/kernel/syscalls/add_key/add_key05.c +1 -1
+
  	username[sizeof(username) - 2] = '0' + n;
 
  	SAFE_CMD(cmd_useradd, NULL, NULL);
--

2.17.1

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp