Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding new switch -rG to usermod #421

Merged
merged 1 commit into from Dec 14, 2021
Merged

Conversation

AZaugg
Copy link
Contributor

@AZaugg AZaugg commented Sep 23, 2021

Adding a new switch -rG, which provides a similar feature set to -aG, allowing a person to list exactly what groups to remove a user from.

As we can see user tester is part of test[1..4]

[a@localhost src]$ tail /etc/group ; sudo tail /etc/gshadow
tester1:x:1003:
test1:x:1004:tester1
test2:x:1005:tester1
test3:x:1006:tester1
test4:x:1007:tester1
tester1:!::
test1:!::tester1
test2:!::tester1
test3:!::tester1
test4:!::tester1

Running with -rG, we can now see that we have removed user tester1 from the named groups, while leaving the unnamed groups untouched
[a@localhost src]$ sudo ./usermod -rG test1,test2 tester1
[a@localhost src]$ tail /etc/group ; sudo tail /etc/gshadow
tester1:x:1003:
test1:x:1004:
test2:x:1005:
test3:x:1006:tester1
test4:x:1007:tester1
tester1:!::
test1:!::
test2:!::
test3:!::tester1
test4:!::tester1

Testing -G flag to see if we broke anything,
[a@localhost src]$ sudo ./usermod -G test1,test2 tester1
[a@localhost src]$ tail /etc/group ; sudo tail /etc/gshadow
tester1:x:1003:
test1:x:1004:tester1
test2:x:1005:tester1
test3:x:1006:
test4:x:1007:
tester1:!::
test1:!::tester1
test2:!::tester1
test3:!::
test4:!::

Works as expected, lets test -aG see if we broke that
[a@localhost src]$ sudo ./usermod -aG test3,test4 tester1
[a@localhost src]$ tail /etc/group ; sudo tail /etc/gshadow
tester1:x:1003:
test1:x:1004:tester1
test2:x:1005:tester1
test3:x:1006:tester1
test4:x:1007:tester1
tester1:!::
test1:!::tester1
test2:!::tester1
test3:!::tester1
test4:!::tester1

Closes #337

Copy link
Collaborator

@ikerexxe ikerexxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the code review perspective I've only seen a little error.

I still would like to test the change though, to see that everything works as expected. By the way, have you considered automating the tests?

src/usermod.c Outdated
@@ -424,6 +425,9 @@ static /*@noreturn@*/void usage (int status)
(void) fputs (_(" -a, --append append the user to the supplemental GROUPS\n"
" mentioned by the -G option without removing\n"
" the user from other groups\n"), usageout);
(void) fputs (_(" -r, --remove remove the user from only the supplemental GROUPS\n"
" mentioned by the -G option without removing\n"
" the user from theother groups\n"), usageout);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with -a option you should remove the.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ikerexxe I fixed the grammatical error.

In regards to writing tests. Would need to look at how the tests are setup. Never looked at it before so. might have a few questions. Are the tests cases a hard requirement for this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my point of view no, it's not necessary, but the last word is up to the maintainers.

That reminds me that I haven't tested this PR. I'll try to do that today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ikerexxe I fixed the grammatical error.

In regards to writing tests. Would need to look at how the tests are setup. Never looked at it before so. might have a few questions. Are the tests cases a hard requirement for this PR?

I do worry that if you don't write them now, they'll never get written :) So if you have time in the next week, that would be great. They'd go under tests/usertools/, one test per directory.

Unfortunately I haven't yet ported the github repo from travis to github actions, so currently the tests aren't being run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try write the tests at a later time and in another commit.

@ikerexxe
Copy link
Collaborator

I've been able to test the changes with satisfactory results. Thanks for the changes!

Initial state:

$ id testuser1
uid=1001(testuser1) gid=1001(testuser1) groups=1001(testuser1)
$ id testuser2
uid=1002(testuser2) gid=1002(testuser2) groups=1002(testuser2)
$ getent group testgroup
testgroup:x:1009:
$ getent group anothergroup
anothergroup:x:1010:

Testing -G option:

$ sudo usermod -G testgroup testuser1
$ id testuser1
uid=1001(testuser1) gid=1001(testuser1) groups=1001(testuser1),1009(testgroup)
$ getent group testgroup 
testgroup:x:1009:testuser1
$ sudo usermod -G testgroup testuser2
$ id testuser2
uid=1002(testuser2) gid=1002(testuser2) groups=1002(testuser2),1009(testgroup)
$ getent group testgroup 
testgroup:x:1009:testuser1,testuser2

Testing aG options:

$ sudo usermod -aG anothergroup testuser1
$ sudo usermod -aG anothergroup testuser2
$ id testuser1
uid=1001(testuser1) gid=1001(testuser1) groups=1001(testuser1),1009(testgroup),1010(anothergroup)
$ id testuser2
uid=1002(testuser2) gid=1002(testuser2) groups=1002(testuser2),1009(testgroup),1010(anothergroup)
$ getent group testgroup 
testgroup:x:1009:testuser1,testuser2
$ getent group anothergroup
anothergroup:x:1010:testuser2,testuser1

Testing the new rG options:

$ sudo usermod -rG anothergroup testuser1
$ id testuser1
uid=1001(testuser1) gid=1001(testuser1) groups=1001(testuser1),1009(testgroup)
$ getent group testgroup 
testgroup:x:1009:testuser1,testuser2
$ getent group anothergroup
anothergroup:x:1010:testuser2
$ sudo usermod -rG testgroup testuser1
$ id testuser1
uid=1001(testuser1) gid=1001(testuser1) groups=1001(testuser1)
$ getent group anothergroup
anothergroup:x:1010:testuser2
$ getent group testgroup 
testgroup:x:1009:testuser2

@hallyn
Copy link
Member

hallyn commented Sep 28, 2021

Thanks for the contribution, @AZaugg , and thanks @ikerexxe for testing.

src/usermod.c Show resolved Hide resolved
src/usermod.c Outdated Show resolved Hide resolved
src/usermod.c Show resolved Hide resolved
Copy link

@jfhaugh jfhaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a nice thing to fix.

src/usermod.c Outdated Show resolved Hide resolved
@hallyn
Copy link
Member

hallyn commented Dec 11, 2021

@AZaugg please rebase and either just squash these two commits into one, or split out the code change from the second patch into the first.

@ikerexxe did you get a chance to test this?

@ikerexxe
Copy link
Collaborator

@ikerexxe did you get a chance to test this?

No, I didn't have time to test the latest update. I may have time this week but I can't promise.

@ikerexxe
Copy link
Collaborator

I've been able to find some minutes to test it and everything looks good from my side.

@AZaugg
Copy link
Contributor Author

AZaugg commented Dec 13, 2021

Ok, I rebased from and collapsed the commits into a single commit.

src/usermod.c Outdated Show resolved Hide resolved
Adding a new switch -rG, which provides a similar feature set to
-aG, allowing a person to list exactly what groups to remove a
user from.

shadow-maint#337
@hallyn hallyn merged commit f2e8294 into shadow-maint:master Dec 14, 2021
@hallyn
Copy link
Member

hallyn commented Dec 14, 2021

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFE: would be good to have a -rG option for symmetry with -aG in usermod
4 participants