https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=297712

            Bug ID: 297712
           Summary: share/mk: MK_INSTALL_AS_USER=yes leaves directory
                    group empty when make runs as root
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: bin
          Assignee: [email protected]
          Reporter: [email protected]

A regression in share/mk/bsd.dirs.mk causes directory installation to fail when
MK_INSTALL_AS_USER=yes and make runs as root.

  The problem was introduced by commit
541e6e2d516b6c9d3681b24464e9ef53c1f2579a:

 
https://cgit.freebsd.org/src/commit/?id=541e6e2d516b6c9d3681b24464e9ef53c1f2579a

  That commit changed bsd.dirs.mk to use _uid and _gid whenever
MK_INSTALL_AS_USER is enabled:

  .if ${MK_INSTALL_AS_USER} == "yes"
  ${dir}_OWN?=  ${_uid}
  ${dir}_GRP?=  ${_gid}
  .else
  ${dir}_OWN?=  root
  ${dir}_GRP?=  wheel
  .endif

  However, bsd.init.mk initializes _uid unconditionally but initializes _gid
only when _uid is nonzero:

  _uid!=        id -u

  .if ${_uid} != 0
  _gid!=        id -g
  ...
  .endif

  Consequently, when make runs as root, _uid is 0 while _gid remains undefined.
Directory installation then invokes install(1)
  with an empty group argument.

  I reproduced this with security/unix-selfauth-helper under poudriere on
FreeBSD 16.0-CURRENT, OSVERSION 1600020. The upstream
  Makefile sets:

  MK_INSTALL_AS_USER=yes
  DIRS+=        BINDIR

  The staging phase fails as follows:

  installing DIRS BINDIR
  install -d -m 0755 -o 0 -g
/wrkdirs/usr/ports/security/unix-selfauth-helper/work/stage/usr/local/libexec
  usage: install [-bCcpSsUv] [-f flags] [-g group] ...
  *** Error code 64

  The same port built successfully before the cited bsd.dirs.mk change. This is
not specific to the port: any Makefile combining
  MK_INSTALL_AS_USER=yes, DIRS, and a root-run installation can encounter it.

  Expected behavior:

  When installation runs as root, directory ownership should default to
root:wheel, as it did before the cited commit. When
  installation runs as a non-root user, _uid and _gid should continue to select
that user’s ownership.

  A consistent one-line correction would make the bsd.dirs.mk condition match
the existing logic in bsd.init.mk:

  diff --git a/share/mk/bsd.dirs.mk b/share/mk/bsd.dirs.mk
  --- a/share/mk/bsd.dirs.mk
  +++ b/share/mk/bsd.dirs.mk
  @@ -12,7 +12,7 @@ DIRS?=
   .    if defined(${dir}) && !empty(${dir})
   # Set default permissions for a directory
   ${dir}_MODE?=        0755
  -.if ${MK_INSTALL_AS_USER} == "yes"
  +.if ${MK_INSTALL_AS_USER} == "yes" && ${_uid} != 0
   ${dir}_OWN?= ${_uid}
   ${dir}_GRP?= ${_gid}
   .else

  This preserves install-as-user ownership for non-root builds while restoring
root:wheel defaults for root-run builds.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to