From nobody@FreeBSD.org  Mon Oct 22 20:52:32 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 81580886
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Oct 2012 20:52:32 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 69EEA8FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Oct 2012 20:52:32 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9MKqVaj022264
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 22 Oct 2012 20:52:31 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9MKqVW3022263;
	Mon, 22 Oct 2012 20:52:31 GMT
	(envelope-from nobody)
Message-Id: <201210222052.q9MKqVW3022263@red.freebsd.org>
Date: Mon, 22 Oct 2012 20:52:31 GMT
From: Jeff Lawson <jeff@bovine.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: pw useradd does not allow -g ""
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         172965
>Category:       bin
>Synopsis:       pw(8): pw useradd does not allow -g ""
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 22 21:00:00 UTC 2012
>Closed-Date:    
>Last-Modified:  Thu Feb 28 09:21:54 UTC 2013
>Originator:     Jeff Lawson
>Release:        9.1-PRERELEASE
>Organization:
>Environment:
FreeBSD sushi.hou.flightaware.com 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0: Fri Oct 19 02:12:36 UTC 2012     root@riata.hou.flightaware.com:/usr/obj/usr/src/sys/GENERIC-DTRACE  amd64

>Description:
Man page for "pw" indicates that -g "" is an acceptable option:

     -g group      Set the default group for new users.  If a blank group is
                   specified using -g "", then new users will be allocated
                   their own private primary group with the same name as their
                   login name.  If a group is supplied, either its name or uid
                   may be given as an argument.

However, attempting to do that produces an error:

# pw useradd moo -g ""
pw: group `' is not defined

>How-To-Repeat:
pw useradd moo -g ""

>Fix:


>Release-Note:
>Audit-Trail:

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jeff@bovine.net
Cc:  
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Mon, 22 Oct 2012 23:35:49 +0200

 You took it out of context.
 
 $ man pw
 ...
      The useradd command also has the ability to set new user and group
      defaults by using the -D option.  Instead of adding a new user, pw writes
      a new set of defaults to its configuration file, /etc/pw.conf.  When
      using the -D option, you must not use either -n name or -u uid or an
      error will result.  Use of -D changes the meaning of several command line
      switches in the useradd command.  These are:
 
      -D            Set default values in /etc/pw.conf configuration file, or a
                    different named configuration file if the -C config option
                    is used.
 ...
 
 # pw useradd -D -g ""
 # cat /etc/pw.conf
 ...
 # Default group (leave blank for new group per user)
 defaultgroup = ""
 ...
 # pw useradd moo3
 # grep -i moo3 /etc/passwd
 moo3:*:1005:1005:User &:/home/moo3:/bin/sh
 
 # pw useradd -D -g "nobody"
 # cat /etc/pw.conf
 ...
 # Default group (leave blank for new group per user)
 defaultgroup = "nobody"
 ...
 # pw useradd moo4
 # grep -i moo4 /etc/passwd
 moo4:*:1006:65534:User &:/home/moo4:/bin/sh
 
 jb

From: Jeff Lawson <jeff@bovine.net>
To: J B <jb.1234abcd@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Mon, 22 Oct 2012 16:54:58 -0500

 --047d7b2ee77164a6e004ccace9c2
 Content-Type: text/plain; charset=UTF-8
 
 Very well, but it seems that it might be useful for the normal -g (without
 -D) to also accept "" so that you can perform a one-time override of any
 possible default group that had been established.
 
 --047d7b2ee77164a6e004ccace9c2--

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jeff@bovine.net
Cc:  
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Tue, 23 Oct 2012 00:17:12 +0200

 And what that one-time override would be ?
 "" ? Impossible, it has to be a valid group (it goes to /etc/passwd).
 # pw useradd moo4
 # pw useradd moo5 -g nobody
 # pw useradd moo6 -g moo6
 pw: group `moo6' does not exist
 # pw useradd moo7 -g ""
 pw: group `' is not defined
 # grep -i moo /etc/passwd
 moo4:*:1003:1003:User &:/home/moo4:/bin/sh
 moo5:*:1004:65534:User &:/home/moo5:/bin/sh

From: Jeff Lawson <jeff@bovine.net>
To: J B <jb.1234abcd@gmail.com>
Cc: bug-followup@freebsd.org
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Tue, 23 Oct 2012 15:42:43 -0500

 --047d7b10cc4fd2ec9804ccc00461
 Content-Type: text/plain; charset=UTF-8
 
 Yes, I agree that "" is currently impossible by the current version of
 "pw".  However, attached is a diff to /usr/src/usr.sbin/pw/pw_user.c
 that implements the change I am proposing to allow such a one-time
 override.  For example:
 
 # pw useradd moo4
 # pw useradd -D -g "nobody"
 # pw useradd moo5
 # pw useradd moo6 -g ""
 
 # grep moo /etc/passwd
 moo4:*:8005:8005:User &:/home/moo4:/bin/sh
 moo5:*:8006:65534:User &:/home/moo5:/bin/sh
 moo6:*:8007:8007:User &:/home/moo6:/bin/sh
 
 In effect, -g "" acts as if there is no default set by -D -g.
 
 --047d7b10cc4fd2ec9804ccc00461
 Content-Type: application/octet-stream; name="pw_user.c.diff"
 Content-Disposition: attachment; filename="pw_user.c.diff"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_h8nh70u00
 
 ZGlmZiAtLWdpdCBhL3B3X3VzZXIuYy5vcmlnIGIvcHdfdXNlci5jCmluZGV4IDhlMmZhM2IuLjIw
 OTEyNTMgMTAwNjQ0Ci0tLSBhL3B3X3VzZXIuYy5vcmlnCisrKyBiL3B3X3VzZXIuYwpAQCAtODYy
 LDggKzg2MiwxMSBAQCBwd19naWRwb2xpY3koc3RydWN0IHVzZXJjb25mICogY25mLCBzdHJ1Y3Qg
 Y2FyZ3MgKiBhcmdzLCBjaGFyICpuYW0sIGdpZF90IHByZWZlcgogCiAJLyoKIAkgKiBJZiBubyBh
 cmcgZ2l2ZW4sIHNlZSBpZiBkZWZhdWx0IGNhbiBoZWxwIG91dAorCSAqIHVubGVzcyB0aGUgdXNl
 ciBleHBsaWNpdGx5IHNwZWNpZmllZCBhIGJsYW5rIHN0cmluZy4KIAkgKi8KLQlpZiAoYV9naWQg
 PT0gTlVMTCAmJiBjbmYtPmRlZmF1bHRfZ3JvdXAgJiYgKmNuZi0+ZGVmYXVsdF9ncm91cCkKKwlp
 ZiAoYV9naWQgIT0gTlVMTCAmJiAhKmFfZ2lkLT52YWwpCisJCWFfZ2lkID0gTlVMTDsKKwllbHNl
 IGlmIChhX2dpZCA9PSBOVUxMICYmIGNuZi0+ZGVmYXVsdF9ncm91cCAmJiAqY25mLT5kZWZhdWx0
 X2dyb3VwKQogCQlhX2dpZCA9IGFkZGFyZyhhcmdzLCAnZycsIGNuZi0+ZGVmYXVsdF9ncm91cCk7
 CiAKIAkvKgo=
 --047d7b10cc4fd2ec9804ccc00461--

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jeff@bovine.net
Cc:  
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Tue, 23 Oct 2012 23:38:19 +0200

 > # pw useradd moo6 -g ""
 
 Make sure that the new group is added to /etc/group"
 # grep -i moo /etc/group
 moo6:*:8007:
 
 jb

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jeff@bovine.net
Cc:  
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Wed, 24 Oct 2012 00:26:58 +0200

 What about 'pw usermod' ?
 
 Wow !
 I just tested (btw, without your patch):
 # pw usermod moo4 -g "nobody"
 # pw usermod moo4 -g ""
 Segmentation fault: 11 (core dumped)
 #
 
 I opened PR#:
 http://www.freebsd.org/cgi/query-pr.cgi?pr=173005
 
 With regard to your changes:
 make sure you test 'pw useradd' and 'pw usermod' entries, both old and new
 (override with -g "") syntax, with "-N" option.
 
 jb

From: J B <jb.1234abcd@gmail.com>
To: bug-followup@FreeBSD.org, jeff@bovine.net
Cc:  
Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
Date: Fri, 26 Oct 2012 20:58:46 +0200

 I am presenting a summary that would suggest better solution.
 
 pw(8):
 ...
 USER OPTIONS
      The following options apply to the useradd and usermod commands:
 ...
      -g group      Set the account's primary group to the given group.  group
                    may be defined by either its name or group number.
 ...
      The useradd command also has the ability to set new user and group
      defaults by using the -D option.  Instead of adding a new user, pw writes
      a new set of defaults to its configuration file, /etc/pw.conf.  When
      using the -D option, you must not use either -n name or -u uid or an
      error will result.  Use of -D changes the meaning of several command line
      switches in the useradd command.  These are:
 
      -D            Set default values in /etc/pw.conf configuration file, or a
                    different named configuration file if the -C config option
                    is used.
 ...
      -g group      Set the default group for new users.  If a blank group is
                    specified using -g "", then new users will be allocated
                    their own private primary group with the same name as their
                    login name.  If a group is supplied, either its name or uid
                    may be given as an argument.
 ...
 
 Now, let's review it once again.
 # pw useradd moo -g moo
 pw: group `moo' does not exist
 # pw useradd moo -g boo
 pw: group `boo' does not exist
 # pw useradd moo -g ""
 pw: group `' is not defined
 
 You want to make a one-time override of any default group as established in
 /etc/pw.conf by "-D -g" options:
 # pw useradd moo -g ""
 moo:*:8007:8007:User &:/home/moo:/bin/sh
 
 But, the below does the same but by checking if user name/id is equal to
 primary group name/id as entered:
 # pw useradd moo -g moo
 moo:*:8007:8007:User &:/home/moo:/bin/sh
 which clearly reflects user's intentions as entered.
 By contrast, your solution is less clear about the user's intentions; also,
 it introduces blank group specification -g "" to entry whose context is
 an immediate and particular account setup, but which is specific to -D -g ""
 type of entry whose context is setting up system defaults for any accounts
 setup.

From: Eitan Adler <lists@eitanadler.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: bin/172965: pw useradd does not allow -g &quot;&quot;
Date: Sat, 27 Oct 2012 15:20:09 -0400

 ---------- Forwarded message ----------
 From: J B <jb.1234abcd@gmail.com>
 Date: 26 October 2012 15:00
 Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
 To: freebsd-bugs@freebsd.org
 
 
 The following reply was made to PR misc/172965; it has been noted by GNATS.
 
 From: J B <jb.1234abcd@gmail.com>
 To: bug-followup@FreeBSD.org, jeff@bovine.net
 Cc:
 Subject: Re: misc/172965: pw useradd does not allow -g &quot;&quot;
 Date: Fri, 26 Oct 2012 20:58:46 +0200
 
  I am presenting a summary that would suggest better solution.
 
  pw(8):
  ...
  USER OPTIONS
       The following options apply to the useradd and usermod commands:
  ...
       -g group      Set the account's primary group to the given group.  group
                     may be defined by either its name or group number.
  ...
       The useradd command also has the ability to set new user and group
       defaults by using the -D option.  Instead of adding a new user, pw writes
       a new set of defaults to its configuration file, /etc/pw.conf.  When
       using the -D option, you must not use either -n name or -u uid or an
       error will result.  Use of -D changes the meaning of several command line
       switches in the useradd command.  These are:
 
       -D            Set default values in /etc/pw.conf configuration file, or a
                     different named configuration file if the -C config option
                     is used.
  ...
       -g group      Set the default group for new users.  If a blank group is
                     specified using -g "", then new users will be allocated
                     their own private primary group with the same name as their
                     login name.  If a group is supplied, either its name or uid
                     may be given as an argument.
  ...
 
  Now, let's review it once again.
  # pw useradd moo -g moo
  pw: group `moo' does not exist
  # pw useradd moo -g boo
  pw: group `boo' does not exist
  # pw useradd moo -g ""
  pw: group `' is not defined
 
  You want to make a one-time override of any default group as established in
  /etc/pw.conf by "-D -g" options:
  # pw useradd moo -g ""
  moo:*:8007:8007:User &:/home/moo:/bin/sh
 
  But, the below does the same but by checking if user name/id is equal to
  primary group name/id as entered:
  # pw useradd moo -g moo
  moo:*:8007:8007:User &:/home/moo:/bin/sh
  which clearly reflects user's intentions as entered.
  By contrast, your solution is less clear about the user's intentions; also,
  it introduces blank group specification -g "" to entry whose context is
  an immediate and particular account setup, but which is specific to -D -g ""
  type of entry whose context is setting up system defaults for any accounts
  setup.
 _______________________________________________
 freebsd-bugs@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
 To unsubscribe, send any mail to "freebsd-bugs-unsubscribe@freebsd.org"
 
 
 -- 
 Eitan Adler
>Unformatted:
