History log of /freebsd-current/lib/libutil/gr_util.c
Revision Date Author Comments
# a2f733ab 24-Nov-2023 Warner Losh <imp@FreeBSD.org>

lib: Automated cleanup of cdefs and other formatting

Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by: Netflix


# 1d386b48 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# 39c64ed6 20-Jun-2020 Piotr Pawel Stefaniak <pstef@FreeBSD.org>

libutil: remove extraneous ": " from error messages

Each of the err() family of functions already takes care of that.


# 5e53a4f9 25-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

lib: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# efa8af7c 21-Apr-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

lib: initial use of reallocarray(3).

Make some use of reallocarray, attempting to limit it to cases where the
parameters are unsigned and there is some theoretical chance of overflow.

MFC afer: 2 weeks
Differential Revision: https://reviews.freebsd.org/D9980


# e68bca50 28-Nov-2016 Dag-Erling Smørgrav <des@FreeBSD.org>

Use malloc()ed buffers instead of stack buffers in gr_copy() and pw_copy().
This allows pw(8) to operate on passwd and group files with longer lines
than could be accomodated by a stack buffer. It doesn't take more than a
few hundred users to exceed 8192 bytes in /etc/group.

MFC after: 3 weeks
Sponsored by: The University of Oslo


# cbaba16b 18-Nov-2016 Alan Somers <asomers@FreeBSD.org>

Speed up pw operations that edit /etc/group or /etc/passwd

r285050 fixed a bug in pw that could lead to /etc/passwd or /etc/group
corruption on power loss. However, it fixed it by opening those files with
O_SYNC, which is very slow, especially on ZFS. This change replaces O_SYNC
with appropriately placed fsync()s instead, which is much faster. Using a
ZFS tmpdir, the time to run pw's kyua tests drops from 245s to 35s.

Reviewed by: allanjude, bapt, vangyzen, garga
Tested on pfSense by: garga
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D8319


# d32a66b2 02-Jul-2015 Renato Botelho <garga@FreeBSD.org>

When passwd or group information is changed (by pw, vipw, chpass, ...)
temporary file is created and then a rename() call move it to official file.
This operation didn't have any check to make sure data was written to disk
and if a power cycle happens system could end up with a 0 length passwd
or group database.

There is a pfSense bug with more infor about it:

https://redmine.pfsense.org/issues/4523

The following changes were made to protect passwd and group operations:

* lib/libutil/gr_util.c:
- Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file
- After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.c
- Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file

* usr.sbin/pwd_mkdb/pwd_mkdb.c
- Added O_SYNC flag on dbopen() calls
- After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.3
- pw_lock() returns a file descriptor to master password file on success

Differential Revision: https://reviews.freebsd.org/D2978
Approved by: bapt
Sponsored by: Netgate


# f8c88390 24-Jan-2015 Mark Johnston <markj@FreeBSD.org>

gr_equal(): Fix a crash that could occur if the first group's member list
was longer than the second's. There is no need to compute and compare the
member list lengths in a separate pass, since we now just return false when
comparing member names if the list lengths are not equal.

MFC after: 2 weeks


# 6e6c53f0 28-Oct-2014 Baptiste Daroussin <bapt@FreeBSD.org>

Fix renaming a group via the gr_copy function

Add a regression test to pw(8) because the bug was discovered via using:
pw groupmod

PR: 187189
Reported by: mcdouga9@egr.msu.edu
Tested by: mcdouga9@egr.msu.edu
Patch by: Marc de la Gueronniere


# 5e879837 09-Mar-2013 Diane Bruce <db@FreeBSD.org>

commit correct tested fix for gr_util.c

Approved by: theraven


# 86e2f99d 07-Mar-2013 Diane Bruce <db@FreeBSD.org>

Cleanup gr_add() so it does not leak mem
This is part of ongoing work on sbin/pw

M libutil.h
M gr_util.c

Approved by: theraven


# 08ecf0cc 13-Jan-2013 Mateusz Guzik <mjg@FreeBSD.org>

libutil: fix typo in comment for gr_fini.

Submitted by: Christoph Mallon <christoph.mallon gmx.de>


# 49013fb4 13-Jan-2013 Mateusz Guzik <mjg@FreeBSD.org>

libutil: utilize strsep instead of strcat in a loop in gr_make

Submitted by: Christoph Mallon <christoph.mallon gmx.de>


# fe75b0f0 13-Jan-2013 Mateusz Guzik <mjg@FreeBSD.org>

libutil: move group_line_format into the scop of its only user.

Submitted by: Christoph Mallon <christoph.mallon gmx.de>


# 29365f02 13-Jan-2013 Mateusz Guzik <mjg@FreeBSD.org>

libutil: eliminate 'found' variable in gr_equal

Submitted by: Christoph Mallon <christoph.mallon gmx.de>


# 7780953e 28-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

Simplify pointing dst after the end of all the gr_mem pointers in newgr

Submitted by: pjd
Reviewed by: db


# fe390747 28-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

errno = ENOMEM was supposed to be removed not return (NULL);

Submitted by: gcooper


# d00489b7 28-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

malloc() sets errno to ENOMEM already.

Submitted by: Christoph Mallon <christoph.mallon@gmx.de>


# 167145a1 28-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

Do not leave parts of the new group uninitialized in gr_dup().

Submitted by: Christoph Mallon <christoph.mallon@gmx.de>
Reported by: pjd


# 50197475 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

avoid arithmetic on uintptr_t

Submitted by: pjd
Reviewed by: jilles


# 7d900198 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

cast to uintptr_t to properly calculate offset

Reported by: mdf
Submitted by: db


# ede89d5d 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

Add O_CLOEXEC to flopen

Requested by: jilles


# 1067c64a 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

gr_dup: simplify duplication of group

Submitted by: db


# 2bfeb4fe 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

- Clean up previous gr_add use malloc instead of calloc
- Fix tinderbox error

Submitted by: db


# be49c830 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

New gr_add function to provide a clean and safe method to append a new member
into an existing group.

Submitted by: db


# 98e79fb1 27-Dec-2012 Baptiste Daroussin <bapt@FreeBSD.org>

Use flopen(3) instead of open(2) + flock(2)


# 09259e6c 20-Nov-2012 Baptiste Daroussin <bapt@FreeBSD.org>

only rename(2) after chmod(2) has succeed
report error if chmod(2) fails

Reported by: jh


# 2d2b6ad7 20-Nov-2012 Baptiste Daroussin <bapt@FreeBSD.org>

change mode the group file to 0644 after a successfull rename(2)


# b3d9795c 29-Oct-2012 Baptiste Daroussin <bapt@FreeBSD.org>

backout r242319, racy and not done in the right place

Reported by: Garrett Cooper <yanegomi@gmail.com>


# 29e57550 29-Oct-2012 Baptiste Daroussin <bapt@FreeBSD.org>

make pw_init and gr_init fail if the specified master password or group file is
a directory.

MFC after: 1 month


# 1926f2f6 15-Dec-2011 Baptiste Daroussin <bapt@FreeBSD.org>

Modify pw_copy:
- if pw is NULL and oldpw is not NULL then the oldpw is deleted
- if pw->pw_name != oldpw->pw_name but pw->pw_uid == oldpw->pw_uid
then it renames the user

add new gr_* functions so now gr_util API is similar to pw_util API,
this allow to manipulate groups in a safe way.

Reviewed by: des
Approved by: des
MFC after: 1 month


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# fe0506d7 09-Mar-2010 Marcel Moolenaar <marcel@FreeBSD.org>

Create the altix project branch. The altix project will add support
for the SGI Altix 350 to FreeBSD/ia64. The hardware used for porting
is a two-module system, consisting of a base compute module and a
CPU expansion module. SGI's NUMAFlex architecture can be an excellent
platform to test CPU affinity and NUMA-aware features in FreeBSD.


# 08c59cc3 18-Dec-2009 Sean Farley <scf@FreeBSD.org>

Merge from head to stable/8:

r200423:
Remove a dead store.


# 0dd84a53 11-Dec-2009 Sean Farley <scf@FreeBSD.org>

Remove a dead store.

MFC after: 5 days


# 805da51a 23-Nov-2008 Sean Farley <scf@FreeBSD.org>

Fixed style issues with variable ordering and naming, spacing and
parentheses.

Fixed alignment issue in gr_dup() in its assignment of gr_mem using a
struct to force alignment without performing alignment mathematics. This
was noticed recently with libutil was built with WARNS=6 on platform such
as sparc64.

Added checks to gr_dup(), gr_equal() and gr_make() to prevent segfaults
when examining struct group's with the struct members pointing to NULL's.

With fix of alignment issue, restore WARNS?=6.

Reviewed by: des
MFC after: 1 week


# a0671723 10-Nov-2008 Sean Farley <scf@FreeBSD.org>

style(9) fixes.

MFC after: 1 week


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# 0b5e8899 22-Apr-2008 Sean Farley <scf@FreeBSD.org>

Add four utility functions related to struct grp processing modeled in-part
after similar calls related to struct pwd in libutil/pw_util.c:
- gr_equal()
Perform a deep comparison of two struct grp's. It does a thorough, yet
unoptimized comparison of all the members regardless of order.

- gr_make()
Create a string (see group(5)) from a struct grp.

- gr_dup()
Duplicate a struct grp. Returns a value that is a single contiguous
block of memory.

- gr_scan()
Create a struct grp from a string (as produced by gr_make()).

MFC after: 3 weeks