The theoretical right way to check if an account is in a Unix groupAugust 24, 2012
If you are checking once to see if an account is in a group, there is a simple and obvious approach (omitting some details):
There is just one problem
with this: on many systems, In theory, the better check is simple. Instead of getting the login's
group list and seeing if the group's GID is in there, you work the other
way around: you get the group's membership (as part of getting the group
entry itself) and then see if the login either has the group's GID as
it's primary group or appears on the list of group members. This avoids
(repeatedly) parsing all of However, these two checks are not equivalent and now you have to decide what you care about. The first version checks to see if a login has the group ID of a particular group. The second version checks to see if a login has the group name of a particular group. To see the difference, consider the following group entries: wheel:x:10:jane cog:x:10:fred Here is the question: is (If you are designing the software, you can decide to make it whichever is more convenient and useful to you.) The corollary is that if you really do need the GID version and you want
to be fast for a large number of checks, in theory you need to build
some sort of full in-memory index of (The fully general version is to scan (2 comments.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |