1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

The chown builtin should fail with the same error consistently (#378)

This bug was first reported at <https://www.illumos.org/issues/3782>.
The chown builtin when used on illumos can fail with different error
messages after running the same command twice:

  $ touch /tmp/x
  $ /opt/ast/bin/chown -h 433:434 /tmp/px
  chown: /tmp/x: cannot change owner and group [Not owner]
  $ /opt/ast/bin/chown -h 433:434 /tmp/px
  chown: /tmp/x: cannot change owner and group [Invalid argument]

The error messages differ because the libast struid and strgid
functions will return -2 if the same nonexistent ID is used twice.

The fix for this bug has been ported from here:
4162633a7c

src/lib/libcmd/chgrp.c:
- Remove NOID macro and check for a < 0 error status instead.
  This is different from the Illumos fix at
  <4162633a7c>
  which added another macro.

src/lib/libast/man/{strgid,struid}.3:
- Correct errors in the strgid and struid documentation.
- Document that the strgid and struid functions will return -2 if
  the same invalid name is used twice.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-12-14 01:22:30 -08:00 committed by Martijn Dekker
parent c0354a869f
commit 61fa1b68bf
4 changed files with 38 additions and 25 deletions

View file

@ -38,16 +38,21 @@
..
.TH STRGID 3
.SH NAME
strgid \- return group name given group number
strgid \- return group ID number for given group name
.SH SYNOPSIS
.L "char* strgid(int gid)"
.L "int strgid(const char* name)"
.SH DESCRIPTION
.I strgid
returns the group id name string given the group number
.IR gid .
returns the group ID number for the given group name.
.I strgid
maintains an internal cache to avoid repeated password database scans
by the low level
.IR getgrgid (3).
On the first error for a given name,
.I strgid
returns -1.
Subsequent errors for the same name will result in
.I strgid
returning -2 instead.
.SH "SEE ALSO"
getgrent(3)

View file

@ -38,16 +38,21 @@
..
.TH STRUID 3
.SH NAME
struid \- return user name given user number
struid \- return user ID number for given user name
.SH SYNOPSIS
.L "char* struid(int uid)"
.L "int struid(const char* name)"
.SH DESCRIPTION
.I struid
returns the user id name string given the user number
.IR uid .
returns the user ID number for the given user name.
.I struid
maintains an internal cache to avoid repeated password database scans
by the low level
.IR getpwuid (3).
On the first error for a given name,
.I struid
returns -1.
Subsequent errors for the same name will result in
.I struid
returning -2 instead.
.SH "SEE ALSO"
getpwent(3)