Bug 208774 - bsdconfig bug when editing users
Summary: bsdconfig bug when editing users
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.3-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Devin Teske
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-04-13 12:35 UTC by Martin Waschbüsch
Modified: 2018-06-21 15:04 UTC (History)
2 users (show)

See Also:


Attachments
strip appended group name from _user_gid before using it with the pw command (412 bytes, patch)
2016-09-11 20:29 UTC, Martin Waschbüsch
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Waschbüsch 2016-04-13 12:35:53 UTC
Trying to edit any existing user with bsdconfig will result in the user's group being shown like "gid (group)". E.g. "1001 (martin)".
Unfortunately, when trying to save said user, bsdconfig will always complain with an error like this:

pw: group `1001 (martin)` does not exist

Probably because the group string "1001 (martin)" is taken literally when it should be parsed using something like /(\d+?)\s.+/
Comment 1 Martin Waschbüsch 2016-09-11 20:29:02 UTC
Created attachment 174664 [details]
strip appended group name from _user_gid before using it with the pw command

Although there is code that attempts to add the group name to the dialog display starting in line 1023 of user_input.subr:

        # Attempt to translate a numeric GID into `number (name)'
        if f_isinteger "$user_gid"; then
                local user_group
                user_group=$( pw groupshow -g "$user_gid" 2> /dev/null ) &&
                        user_gid="$user_gid (${user_group%%:*})"
        fi

I could not identify any existing code for bsdconfig that was meant to strip the (<groupname>) out again.

Albeit not elegant, the attached patch solves the problem for me (on 10.3-STABLE).
Comment 2 Martin Waschbüsch 2018-01-14 09:08:39 UTC
This bug still exists in 11.1-RELEASE.
Comment 3 commit-hook freebsd_committer freebsd_triage 2018-06-17 22:10:39 UTC
A commit references this bug:

Author: dteske
Date: Sun Jun 17 22:09:43 UTC 2018
New revision: 335308
URL: https://svnweb.freebsd.org/changeset/base/335308

Log:
  bsdconfig: Fix a bug when editing users

  The usermgmt API was stomping on a global ($user_gid to be specific)
  so things would appear to work fine until you tried to make a second
  pass into the API with the now-tainted variable contents.

  Fixed by localizing menu-specific contents as to not leak outside API.

  PR:		bin/208774
  Reported by:	Martin Waschbuesch <martin@waschbuesch.de>
  MFC after:	1 week
  X-MFC-to:	stable/11, stable/10
  Sponsored by:	Smule, Inc.

Changes:
  head/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
Comment 4 Devin Teske freebsd_committer freebsd_triage 2018-06-17 22:11:48 UTC
Can you check to see if the problem is fixed? Cheers!
Comment 5 Martin Waschbüsch 2018-06-18 06:27:29 UTC
(In reply to Devin Teske from comment #4)
It does fix this for me. Splendid!
Thanks and kudos,

Martin
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-06-21 14:55:45 UTC
A commit references this bug:

Author: dteske
Date: Thu Jun 21 14:55:26 UTC 2018
New revision: 335485
URL: https://svnweb.freebsd.org/changeset/base/335485

Log:
  MFC r335308: bsdconfig: Fix a bug when editing users

  The usermgmt API was stomping on a global ($user_gid to be specific)
  so things would appear to work fine until you tried to make a second
  pass into the API with the now-tainted variable contents.

  Fixed by localizing menu-specific contents as to not leak outside API.

  PR:		bin/208774
  Reported by:	Martin Waschbuesch <martin@waschbuesch.de>
  Sponsored by:	Smule, Inc.

Changes:
_U  stable/11/
  stable/11/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-06-21 15:02:53 UTC
A commit references this bug:

Author: dteske
Date: Thu Jun 21 15:02:18 UTC 2018
New revision: 335487
URL: https://svnweb.freebsd.org/changeset/base/335487

Log:
  MFC r335308: bsdconfig: Fix a bug when editing users

  The usermgmt API was stomping on a global ($user_gid to be specific)
  so things would appear to work fine until you tried to make a second
  pass into the API with the now-tainted variable contents.

  Fixed by localizing menu-specific contents as to not leak outside API.

  PR:		bin/208774
  Reported by:	Martin Waschbuesch <martin@waschbuesch.de>
  Sponsored by:	Smule, Inc.

Changes:
_U  stable/10/
  stable/10/usr.sbin/bsdconfig/usermgmt/share/user_input.subr
Comment 8 Devin Teske freebsd_committer freebsd_triage 2018-06-21 15:04:44 UTC
Thank you so very much for the bug report and your patience in waiting for a resolution. Cheers.