All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd
@ 2022-10-12  3:01 zhaogongyi via ltp
  2022-10-12  3:23 ` xuyang2018.jy
  0 siblings, 1 reply; 4+ messages in thread
From: zhaogongyi via ltp @ 2022-10-12  3:01 UTC (permalink / raw)
  To: xuyang2018.jy, ltp; +Cc: zhangerying

Hi,


> 
> Hi Zhao
> 
> 
> > 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.
> >    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
> > (2)
> >
> > Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> > ---
> >   testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
> >   1 file changed, 5 insertions(+)
> >
> > diff --git a/testcases/kernel/syscalls/add_key/add_key05.c
> > b/testcases/kernel/syscalls/add_key/add_key05.c
> > index 71a88d1a8..e8d249040 100644
> > --- a/testcases/kernel/syscalls/add_key/add_key05.c
> > +++ b/testcases/kernel/syscalls/add_key/add_key05.c
> > @@ -34,10 +34,15 @@ static void add_user(char n)
> >   {
> >   	char username[] = "ltp_add_key05_n";
> >   	const char *const cmd_useradd[] = {"useradd", username,
> NULL};
> > +	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
> 
> 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



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd
  2022-10-12  3:01 [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd zhaogongyi via ltp
@ 2022-10-12  3:23 ` xuyang2018.jy
  0 siblings, 0 replies; 4+ messages in thread
From: xuyang2018.jy @ 2022-10-12  3:23 UTC (permalink / raw)
  To: zhaogongyi, ltp; +Cc: zhangerying

Hi Zhao

> Hi,
> 
> 
>>
>> Hi Zhao
>>
>>
>>> 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.
>>>     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
>>> (2)
>>>
>>> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
>>> ---
>>>    testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
>>>    1 file changed, 5 insertions(+)
>>>
>>> diff --git a/testcases/kernel/syscalls/add_key/add_key05.c
>>> b/testcases/kernel/syscalls/add_key/add_key05.c
>>> index 71a88d1a8..e8d249040 100644
>>> --- a/testcases/kernel/syscalls/add_key/add_key05.c
>>> +++ b/testcases/kernel/syscalls/add_key/add_key05.c
>>> @@ -34,10 +34,15 @@ static void add_user(char n)
>>>    {
>>>    	char username[] = "ltp_add_key05_n";
>>>    	const char *const cmd_useradd[] = {"useradd", username,
>> NULL};
>>> +	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
>>
>> 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
> 
> 
> Regards,
> Gongyi
> 
> 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd
  2022-10-11 12:46 Zhao Gongyi via ltp
@ 2022-10-12  1:33 ` xuyang2018.jy
  0 siblings, 0 replies; 4+ messages in thread
From: xuyang2018.jy @ 2022-10-12  1:33 UTC (permalink / raw)
  To: Zhao Gongyi, ltp

Hi Zhao


> 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.
>    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 (2)
> 
> Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
> ---
>   testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/testcases/kernel/syscalls/add_key/add_key05.c b/testcases/kernel/syscalls/add_key/add_key05.c
> index 71a88d1a8..e8d249040 100644
> --- a/testcases/kernel/syscalls/add_key/add_key05.c
> +++ b/testcases/kernel/syscalls/add_key/add_key05.c
> @@ -34,10 +34,15 @@ static void add_user(char n)
>   {
>   	char username[] = "ltp_add_key05_n";
>   	const char *const cmd_useradd[] = {"useradd", username, NULL};
> +	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

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


Best Regards
Yang Xu
> +	tst_cmd(cmd_groupdel, NULL, "/dev/null", TST_CMD_PASS_RETVAL);
> +
>   	SAFE_CMD(cmd_useradd, NULL, NULL);
>   	pw = SAFE_GETPWNAM(username);
>   	ltpuser[(unsigned int)n] = pw->pw_uid;
> --
> 2.17.1
> 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd
@ 2022-10-11 12:46 Zhao Gongyi via ltp
  2022-10-12  1:33 ` xuyang2018.jy
  0 siblings, 1 reply; 4+ messages in thread
From: Zhao Gongyi via ltp @ 2022-10-11 12:46 UTC (permalink / raw)
  To: ltp

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.
  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 (2)

Signed-off-by: Zhao Gongyi <zhaogongyi@huawei.com>
---
 testcases/kernel/syscalls/add_key/add_key05.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/testcases/kernel/syscalls/add_key/add_key05.c b/testcases/kernel/syscalls/add_key/add_key05.c
index 71a88d1a8..e8d249040 100644
--- a/testcases/kernel/syscalls/add_key/add_key05.c
+++ b/testcases/kernel/syscalls/add_key/add_key05.c
@@ -34,10 +34,15 @@ static void add_user(char n)
 {
 	char username[] = "ltp_add_key05_n";
 	const char *const cmd_useradd[] = {"useradd", username, NULL};
+	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);
+	tst_cmd(cmd_groupdel, NULL, "/dev/null", TST_CMD_PASS_RETVAL);
+
 	SAFE_CMD(cmd_useradd, NULL, NULL);
 	pw = SAFE_GETPWNAM(username);
 	ltpuser[(unsigned int)n] = pw->pw_uid;
--
2.17.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-10-12  3:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12  3:01 [LTP] [PATCH v2] syscalls/add_key05: Add userdel and groupdel before useradd zhaogongyi via ltp
2022-10-12  3:23 ` xuyang2018.jy
  -- strict thread matches above, loose matches on Subject: below --
2022-10-11 12:46 Zhao Gongyi via ltp
2022-10-12  1:33 ` xuyang2018.jy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.