Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Where does usermod store a user's default gid for files?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 544
Location: New Zealand

PostPosted: Wed Feb 03, 2021 7:46 pm    Post subject: Where does usermod store a user's default gid for files? Reply with quote

A very basic question, but after browsing through the files listed by man usermod, and Googling, I still can't see it (maybe just a case of not enough coffee yet and it's staring me in the face). I had a situation where /etc/group looked fine and yet the user's new files were being created with a different group ownership. I fixed this with
Code:
usermod -g name name
...in reponse to which usermod lied and said
Code:
usermod: no changes
...and yet the problem *was* fixed by this.

Where can I look to see if there's a mismatch between /etc/group and wherever the system looks when it creates new files? Obviously the system was retrieving the wrong gid from somewhere, and usermod edited that file to fix things (a persistent file somewhere, as the problem has been permanently fixed)...but what did it actually edit?
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Wed Feb 03, 2021 8:26 pm    Post subject: Reply with quote

I don't fully understand your post...
Quote:
I had a situation where /etc/group looked fine and yet the user's new files were being created with a different group ownership.

First of all, a user's primary group is defined in /etc/passwd, not in /etc/group.

Then you could read the man page of open(2):
Quote:
The group ownership (group ID) of the new file is set either to the effective group ID of the process (System V semantics) or to the group ID of the parent directory (BSD semantics). On Linux, the behavior depends on whether the set-group-ID mode bit is set on the parent directory: if that bit is set, then BSD semantics apply; otherwise, System V semantics apply. For some filesystems, the behavior also depends on the bsdgroups and sysvgroups mount options described in mount( 8 ).

Does this help?
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 544
Location: New Zealand

PostPosted: Thu Feb 04, 2021 12:24 am    Post subject: Reply with quote

Well, the setgid process described in your quote was working, but assigning the wrong gid. I thought I'd checked /etc/passwd (along with every other file mentioned in man usermod) but I was badly under-caffeinated at the time so perhaps just missed the change...I should have tested with diff instead of examining stuff manually. So you're saying that if a user's "touch foo" results in foo's having permissions name:users rather than name:name, the output of
Code:
grep name /etc/passwd | cut -f 4 -d ':'
is definitely going to be the gid for users rather than name, and that's the only thing that usermod edited? I still don't understand why it claims "no changes" though...if the wrong gid in /etc/passwd was replaced with the correct one, why didn't it just do its job quietly without the "no changes" report? [Edit]I'll do some more testing now that I know how things are meant to work...thanks for your help.
Back to top
View user's profile Send private message
psycho
Guru
Guru


Joined: 22 Jun 2007
Posts: 544
Location: New Zealand

PostPosted: Thu Feb 04, 2021 12:53 am    Post subject: Reply with quote

Actually now that I think about it, newgrp does roughly what I was accusing usermod of doing: it *does* change the gid of files created by the user, but *doesn't* edit /etc/passwd. So there must be something else involved? I realise these are very basic questions, but I just haven't had any need to understand this stuff before...whatever numerical gid I could see for a user's group in /etc/group seemed always to be the gid assigned to files created by that user.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum