Skip to contentSkip to conversation

syscalls/add_key05: Add userdel and groupdel before useradd

PATCH zhaogongyi via ltp 2 participants 2 messages Oct 12, 2022

lore
Share & tools
lore
#0 lore raw

Hi,

Quoted 46 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..e8d249040 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,10 +34,15 @@ 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 43

Quoted 7 lines
testcases/kernel/syscalls/add_key/add_key05.c +3 -0
+	const char *const cmd_userdel[] = {"userdel", "-r", username, NULL};
+	const char *const cmd_groupdel[] = {"groupdel", username, NULL};
  	struct passwd *pw;
 
  	username[sizeof(username) - 2] = '0' + n;
 
+	tst_cmd(cmd_userdel, NULL, "/dev/null", TST_CMD_PASS_RETVAL);

I do a test on my system
#useradd test
#userdel -r test
#groupdel test
groupdel: group 'test' does not exist

Quoted 3 lines

so I guess we can only using cmd_userdel is enough because it seems userdel will remove the corresponding group.

If username is not exist, userdel can not remove the group with the same name.

I have seen the case on my system, but I cannot reproduce it now.

Regards,
Gongyi

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

Hi Zhao

Quoted 49 lines

Hi,

Quoted 46 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..e8d249040 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,10 +34,15 @@ 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 43

Quoted 7 lines
testcases/kernel/syscalls/add_key/add_key05.c +3 -0
+	const char *const cmd_userdel[] = {"userdel", "-r", username, NULL};
+	const char *const cmd_groupdel[] = {"groupdel", username, NULL};
   	struct passwd *pw;
 
   	username[sizeof(username) - 2] = '0' + n;
 
+	tst_cmd(cmd_userdel, NULL, "/dev/null", TST_CMD_PASS_RETVAL);

I do a test on my system
#useradd test
#userdel -r test
#groupdel test
groupdel: group 'test' does not exist

Quoted 7 lines
Quoted 3 lines

so I guess we can only using cmd_userdel is enough because it seems userdel will remove the corresponding group.

If username is not exist, userdel can not remove the group with the same name.

I have seen the case on my system, but I cannot reproduce it now.

Oh yes, you are right. I look the source code[1]

[1]https://github.com/shadow-maint/shadow/blob/master/src/userdel.c#L1145

I will add a groupdel cmd check in tst_test struct and merge this patch.

Best Regards
Yang Xu

Quoted 6 lines

Regards,
Gongyi

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