Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Nov 1996 01:21:51 +1100
From:      davidn@sdev.usn.blaze.net.au (David Nugent)
To:        dwhite@resnet.uoregon.edu
Cc:        freebsd-questions@freebsd.org
Subject:   Re: users & mail & group
Message-ID:  <Mutt.19961117012151.davidn@sdev>
In-Reply-To: <Pine.BSI.3.94.961114221200.28188i-100000@gdi.uoregon.edu>; from Doug White on Nov 14, 1996 22:13:44 -0800
References:  <3.0.32.19961113203227.00a0681c@scotty.masternet.it> <Pine.BSI.3.94.961114221200.28188i-100000@gdi.uoregon.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Doug White writes:
> > 1) Why adduser add the user name in /etc/group even if it isn't mandatory ?
> > I explain better . If I create the user "gmarco" that belongs to group 2000
> > (user) adduser add gmarco to 2000 group in /etc/group even if 2000 is the
> > default group of gmarco. I always have to delete the username after the
> > group by hand. It begin to be annoying :-)
> 
> Adduser enforces a type of system administration where everyone has their
> own login group and you add people to other groups for permissions.  It
> solves problems with the 1024 character limit / line in /etc/group and
> makes some sysadmin tasks really easy.

How does it solve that?

It seems that more than a couple of people are confused with
the concept of groups. A user is in A primary group, notated
in the gid field in the passwd file. A user's name does *not*
have to be in the corresonding group line in /etc/group.
usernames in /etc/group are for additional group memberships,
not primary group allocations. (If anyone disbelieves, make
sure your name is omitted from the primary group in
/etc/group, login, then type 'id').

Total members in a group is the union of the set of users named
in /etc/groups and those with the corresponding gid in /etc/passwd.

So adduser does not solve any problem in this regard since the
problem didn't exist in the first place except in the minds of
the confused. adduser does the correct thing, as you noted, by:

> Note that you can configure adduser to put the user in other groups,

Yep, these "other groups" are the user's "other" group
memberships that *do* have to be in /etc/group.

> and if you got really annoyed
> with it you could vi /usr/bin/adduser and fix it. :)

.. and you'd be making it do the incorrect thing, in this case.

> > 2) How I can send a mail to all the user of a group ? I.e. I'd like to send
> > a mail to all the users belong to 2000 group. Is it possible or I must use
> > an alias followed by all the names in the same line ? (I have 300 users to
> > administer and I think it isn't safe to add everyone to the line of the
> > group.)
> 
> Copy the group line into /etc/aliases, put a space after the :, save/quit,
> and run 'newaliases'.

Or write a few lines of perl - which I already sent to the
poster - where doing this sort of thing is as easy as falling
out of bed (and no, I don't do that often either :-)):

#!/usr/bin/perl
# Send mail to all members of a group
($group,$file,$subject) = @ARGV;
die "usage: mail [group] [filename] \"[subject]\"\n" if !$group || !$file || !$subject;
($grnam,$grpwd,$grgid,$grmembers) = getgrnam($group);
die "unknown group $group\n" if !$grnam;
# First add each user in the group to the list of recipients
@grmembers = split(/ /, $grmembers);
foreach $member (@grmembers) {
    $members{$member} = 1;
}
# Now add any user with their primary group set to $group
while (($nam,$uid,$gid,%quot,$cmmnt,$gecos,$dir,$sh) = getpwent()) {
    $members{$nam} = 1 if $gid == $grgid;
}
# Now, mail the file
foreach (keys %members) {
    $cmd = "mail -s \"$subject\" $_ <$file";
    print "$cmd\n";
    system($cmd);
}
exit 0;

Use of the hash rather than an array avoids duplicating the
mail to the same users if someone had (ahem) redundantly added
their names in /etc/group.

David Nugent, Unique Computing Pty Ltd - Melbourne, Australia
Voice +61-3-9791-9547 Data/BBS +61-3-9792-3507 3:632/348@fidonet
davidn@blaze.net.au http://www.blaze.net.au/~davidn



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Mutt.19961117012151.davidn>