summaryrefslogtreecommitdiffstats
path: root/libutil
Commit message (Collapse)AuthorAgeFilesLines
* Recommit everything, add chpass, improve history (except for a few files ↵Cameron Katri2021-05-027-32/+257
| | | | that git-filter-repo dislikes for some reason [_secure_path.c and login_cap.h])
* Add function getlocalbase() to libutil.Stefan Eßer2020-11-181-0/+2
| | | | | | | | | | | | | | | This function returns the path to the local software base directory, by default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h when building the world). The value returned can be overridden by 2 methods: - the LOCALBASE environment variable (ignored by SUID programs) - else a non-default user.localbase sysctl value Reviewed by: hps (earlier version) Relnotes: yes Differential Revision: https://reviews.freebsd.org/D27236
* Revert the whole getlocalbase() set of changes while a different design isScott Long2020-11-151-6/+0
| | | | hashed out.
* Fix a problem with r367686 related to the use of ssize_t. Not sure how thisScott Long2020-11-141-0/+5
| | | | | | escaped prior testing, but it should be better now. Reported by: lots
* Add the library function getlocalbase and its manual page. This helps toScott Long2020-11-141-0/+1
| | | | | | | | unify the retrieval of the various ways that the local software base directory, typically "/usr/local", is expressed in the system. Reviewed by: se Differential Revision: https://reviews.freebsd.org/D27022
* Make vipw error message less crypticPiotr Pawel Stefaniak2020-06-201-5/+8
| | | | | | | | | | | | | | | | | | | | | Unable to find an editor, vipw would give this error: # env EDITOR=fnord vipw vipw: pw_edit(): No such file or directory vigr or crontab do better: # env EDITOR=fnord crontab -e crontab: no crontab for root - using an empty one crontab: fnord: No such file or directory crontab: "fnord" exited with status 1 After this change, vipw behaves more like vigr or crontab: # env EDITOR=fnord vipw vipw: fnord: No such file or directory vipw: "fnord" exited with status 1 Reviewed by: rpokala, emaste MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25369
* libutil: remove extraneous ": " from error messagesPiotr Pawel Stefaniak2020-06-202-4/+4
| | | | Each of the err() family of functions already takes care of that.
* Make pw_scan(3) more compatible with getpwent(3) et. al. when processingIan Lepore2018-07-262-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | data from /etc/passwd rather than /etc/master.passwd. The libc getpwent(3) and related functions automatically read master.passwd when run by root, or passwd when run by a non-root user. When run by non- root, getpwent() copes with the missing data by setting the corresponding fields in the passwd struct to known values (zeroes for numbers, or a pointer to an empty string for literals). When libutil's pw_scan(3) was used to parse a line without the root-accessible data, it was leaving garbage in the corresponding fields. These changes rename the static pw_init() function used by getpwent() and friends to __pw_initpwd(), and move it into pw_scan.c so that common init code can be shared between libc and libutil. pw_scan(3) now calls __pw_initpwd() before __pw_scan(), just like the getpwent() family does, so that reading an arbitrary passwd file in either format and parsing it with pw_scan(3) returns the same results as getpwent(3) would. This also adds a new pw_initpwd(3) function to libutil, so that code which creates passwd structs from scratch in some manner that doesn't involve pw_scan() can initialize the struct to the values expected by lots of existing code, which doesn't expect to encounter NULL pointers or garbage values in some fields.
* Use __SCCSID() for SCCS IDs.John Baldwin2018-05-231-7/+3
| | | | | | - Define NO__SCCSID in CFLAGS to preserve existing behavior of omitting SCCS IDs by default. - While here, fix the $FreeBSD$ in pw_util.c to use __FBSDID.
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-264-1/+59
| | | | | | | | | | | | 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.
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-1/+3
| | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. 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. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point.
* Introduce the flopenat(3) function.Mariusz Zaborski2017-08-042-8/+29
| | | | | Reviewed by: des, emaste Differential Revision: https://reviews.freebsd.org/D11690
* lib: initial use of reallocarray(3).Pedro F. Giffuni2017-04-213-3/+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
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96
* Remove a death threat from the FreeBSD sourcesConrad Meyer2016-12-011-5/+9
| | | | | Reported by: koobs@, araujo@, linimon@, bjk@, emaste@, jhb@, ngie@, cem@ Maintainer timeout: des@
* Use malloc()ed buffers instead of stack buffers in gr_copy() and pw_copy().Dag-Erling Smørgrav2016-11-282-26/+48
| | | | | | | | | 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
* Add a warning against modifying this code without understanding it, andDag-Erling Smørgrav2016-11-241-0/+121
| | | | | an example of how not to make it more portable. I've had this lying around uncommitted since 2009...
* Speed up pw operations that edit /etc/group or /etc/passwdAlan Somers2016-11-182-2/+2
| | | | | | | | | | | | | | 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
* libutil: minor spelling fixes.Pedro F. Giffuni2016-05-181-1/+1
|
* Remove useless calls to basename().Ed Schouten2016-05-011-2/+1
| | | | | | | | | | | | | | There are a couple of places in the source three where we call basename() on constant strings. This is bad, because the prototype standardized by POSIX allows the implementation to use its argument as a storage buffer. This change eliminates some of these unportable calls to basename() in cases where it was only added for cosmetical reasons, namely to trim argv[0]. There's nothing wrong with setting argv[0] to the full path. Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D6093
* When passwd or group information is changed (by pw, vipw, chpass, ...)Renato Botelho2015-07-022-3/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* revert r283969,283970 not needed anymore after r283981Baptiste Daroussin2015-06-042-29/+3
|
* Add a pw_mkdb2(3) function which does the same thing as pw_mkdb(3) exceptBaptiste Daroussin2015-06-032-3/+29
| | | | | | | | it takes a new argument allowing to specify the endianness of the database to generate Differential Revision: https://reviews.freebsd.org/D2730 Reviewed by: ian
* Export a list of VM objects in the system via a sysctl. The list can beJohn Baldwin2015-05-271-0/+2
| | | | | | | | | | examined via 'vmstat -o'. It can be used to determine which files are using physical pages of memory and how much each is using. Differential Revision: https://reviews.freebsd.org/D2277 Reviewed by: alc, kib MFC after: 2 weeks Sponsored by: Norse Corp, Inc. (forward porting to HEAD/10)
* gr_equal(): Fix a crash that could occur if the first group's member listMark Johnston2015-01-251-15/+10
| | | | | | | | 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
* Fix renaming a group via the gr_copy functionBaptiste Daroussin2014-10-281-5/+12
| | | | | | | | | | 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
* libutil: Use O_CLOEXEC for internal file descriptors from open().Jilles Tjoelker2013-08-281-0/+819
|
* commit correct tested fix for gr_util.cDiane Bruce2013-03-091-46/+58
| | | | Approved by: theraven
* Cleanup gr_add() so it does not leak memDiane Bruce2013-03-072-53/+86
| | | | | | | | | This is part of ongoing work on sbin/pw M libutil.h M gr_util.c Approved by: theraven
* libutil: fix typo in comment for gr_fini.Mateusz Guzik2013-01-131-1/+1
| | | | Submitted by: Christoph Mallon <christoph.mallon gmx.de>
* libutil: utilize strsep instead of strcat in a loop in gr_makeMateusz Guzik2013-01-131-6/+10
| | | | Submitted by: Christoph Mallon <christoph.mallon gmx.de>
* libutil: move group_line_format into the scop of its only user.Mateusz Guzik2013-01-131-2/+1
| | | | Submitted by: Christoph Mallon <christoph.mallon gmx.de>
* libutil: eliminate 'found' variable in gr_equalMateusz Guzik2013-01-131-8/+5
| | | | Submitted by: Christoph Mallon <christoph.mallon gmx.de>
* Simplify pointing dst after the end of all the gr_mem pointers in newgrBaptiste Daroussin2012-12-281-2/+1
| | | | | Submitted by: pjd Reviewed by: db
* errno = ENOMEM was supposed to be removed not return (NULL);Baptiste Daroussin2012-12-281-1/+1
| | | | Submitted by: gcooper
* malloc() sets errno to ENOMEM already.Baptiste Daroussin2012-12-281-5/+1
| | | | Submitted by: Christoph Mallon <christoph.mallon@gmx.de>
* Do not leave parts of the new group uninitialized in gr_dup().Baptiste Daroussin2012-12-281-0/+4
| | | | | Submitted by: Christoph Mallon <christoph.mallon@gmx.de> Reported by: pjd
* avoid arithmetic on uintptr_tBaptiste Daroussin2012-12-271-1/+1
| | | | | Submitted by: pjd Reviewed by: jilles
* cast to uintptr_t to properly calculate offsetBaptiste Daroussin2012-12-271-1/+1
| | | | | Reported by: mdf Submitted by: db
* Add O_CLOEXEC to flopenBaptiste Daroussin2012-12-272-2/+2
| | | | Requested by: jilles
* gr_dup: simplify duplication of groupBaptiste Daroussin2012-12-271-21/+20
| | | | Submitted by: db
* - Clean up previous gr_add use malloc instead of callocBaptiste Daroussin2012-12-272-5/+4
| | | | | | - Fix tinderbox error Submitted by: db
* New gr_add function to provide a clean and safe method to append a new memberBaptiste Daroussin2012-12-272-0/+42
| | | | | | into an existing group. Submitted by: db
* Use flopen(3) instead of open(2) + flock(2)Baptiste Daroussin2012-12-272-9/+4
|
* only rename(2) after chmod(2) has succeedBaptiste Daroussin2012-11-201-7/+3
| | | | | | report error if chmod(2) fails Reported by: jh
* change mode the group file to 0644 after a successfull rename(2)Baptiste Daroussin2012-11-201-1/+8
|
* backout r242319, racy and not done in the right placeBaptiste Daroussin2012-10-292-18/+0
| | | | Reported by: Garrett Cooper <yanegomi@gmail.com>
* make pw_init and gr_init fail if the specified master password or group file isBaptiste Daroussin2012-10-292-0/+20
| | | | | | a directory. MFC after: 1 month
* Revert user comparison back to user names as some user can share uids (root/toorBaptiste Daroussin2012-06-191-6/+13
| | | | | | | | | | | for example) get the username information from old_pw structures to still allow renaming of a user. Reported by: Claude Buisson <clbuisson@orange.fr> Approved by: des (mentor) MFC after: 3 weeks
* Detect file modification properly by using tv_nsec.Ed Schouten2012-02-101-1/+2
| | | | | | | POSIX 2008 standardizes st_mtim, meaning we can simply use nanosecond precision to detect file modification. MFC after: 2 weeks