aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
Commit message (Collapse)AuthorAgeFilesLines
* libutil: support RLIMIT_PIPEBUFKonstantin Belousov2024-09-203-0/+3
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D46619
* Remove residual blank line at start of MakefileWarner Losh2024-07-152-2/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* include: ssp: round out fortification of current set of headersKyle Evans2024-07-132-2/+6
| | | | | | | | | | | | | | | | | | | | ssp/ssp.h needed some improvements: - `len` isn't always a size_t, it may need casted - In some cases we may want to use a len that isn't specified as a parameter (e.g., L_ctermid), so __ssp_redirect() should be more flexible. - In other cases we may want additional checking, so pull all of the declaration bits out of __ssp_redirect_raw() so that some functions can implement the body themselves. strlcat/strlcpy should be the last of the fortified functions that get their own __*_chk symbols, and these cases are only done to be consistent with the rest of the str*() set. Reviewed by: markj Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D45679
* fparseln: Update licensePedro F. Giffuni2024-06-152-15/+4
| | | | | | Remove 3rd and 4th clauses in christos' license. OK christos. Obtained from: NetBSD
* Revert "fparseln: Update NetBSD version strings"Pedro F. Giffuni2024-06-152-2/+2
| | | | | | | | This reverts commit 1a968da448b0795184884ffe428fb24d7e695628. I was mistakenly looking at the version strings in the CVS attic but the function was moved to libc/stdio where it matches the current string.
* fparseln: Update NetBSD version stringsPedro F. Giffuni2024-06-152-2/+2
| | | | | | | The correponding changes (mostly ANSIfication) were done long ago locally. No functional change. Obtained from: NetBSD (libutil CVS Attic)
* libutil: move ftime to libutilMariusz Zaborski2024-05-293-3/+134
| | | | | | | | | | | | | | | | It seems that there are still some applications that use ftime(3) (for example, science/siconos and sysutils/lcdproc). The issue is that we don't build libcompat as a shared library anymore. The easiest solution is to move it to libutil, until we deprecate it for good. This solution was proposed by kib@ in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=257789. PR: 257789 MFC after: 1 month Reviewed by: kib (ages ago) Differential Revision: https://reviews.freebsd.org/D39994
* login_cap.h: Remove LOGIN_DEFPRIOlivier Certner2024-01-292-2/+1
| | | | | | | | | | | | | | | | | | | This is an implementation detail which is likely to become irrelevant in the future, as we move to not resetting the priority if the corresponding capability is not present in the configuration file ('/etc/login.conf'). GitHub's code search and Google show no use of this public constant, and it doesn't exist in OpenBSD and NetBSD. So, remove this definition and its sole use in-tree. PR: 276570 (exp-run) Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43609
* login_cap.h: Remove LOGIN_DEFUMASKOlivier Certner2024-01-291-1/+0
| | | | | | | | | | | | | | | | This public constant has not been used in-tree since 1997 (this was noticed while working on previous commit "setusercontext(): umask: Set it only once (in the common case)"). Since it was an implementation detail and GitHub's code search and Google show no use of this symbol today, simply remove it. PR: 276570 (exp-run) Reviewed by: emaste, kib (earlier version, then part of D40344) Approved by: emaste (mentor) MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D43608
* setusercontext(): Set priority from '~/.login_conf' as wellOlivier Certner2024-01-291-0/+2
| | | | | | | | | | | | | | | | Setting the process priority is done only when the current process' effective UID corresponds to that for which context is to be set. Consequently, setting priority is done with appropriate credentials and will fail if the target user tries to raise it unduly via his '~/.login_conf'. PR: 271751 Reviewed by: kib, Andrew Gierth <andrew_tao173.riddles.org.uk> Approved by: emaste (mentor) MFC after: 3 days Relnotes: yes Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40352
* login.conf(5): Document priority's special value 'inherit'Olivier Certner2024-01-291-0/+3
| | | | | | | | Reviewed by: emaste, yuripv (older version) Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40691
* setclasspriority(): New possible value 'inherit'Olivier Certner2024-01-291-1/+7
| | | | | | | | | | | | | | It indicates to the login.conf machinery (setusercontext() / setclasscontext()) to leave priority alone, effectively inheriting it from the parent process. PR: 271749 Reviewed by: emaste, yuripv Approved by: emaste (mentor) MFC after: 3 days Relnotes: yes Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40690
* setusercontext(): Move priority setting in new setclasspriority()Olivier Certner2024-01-291-45/+52
| | | | | | | | | | | | | In preparation for setting priorities from '~/.login_conf' and to ease reading of setusercontext(). No functional change. Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40350
* login.conf(5): Document priority's default and possible valuesOlivier Certner2024-01-291-1/+15
| | | | | | | | | | | | | | Priority is reset to 0 if not explicitly specified. While here, be more explicit about what "Initial priority (nice) level" means and document that it is possible to set real-time or idle class' priorities with this capability. Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40689
* setusercontext(): Better error messages when priority is not set correctlyOlivier Certner2024-01-291-17/+34
| | | | | | | | | | | | | | | | Polish the syslog messages to contain readily useful information. Behavior of capability 'priority' is inconsistent with what is done for all other contexts: 'umask', 'cpumask', resource limits, etc., where an absence of capability means to inherit the value. It is currently preserved for compatibility, but is subject to change on a future major release. Reviewed by: emaste, kib (older version) Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40349
* login.conf(5): Default values: Rename column, elaborate on absence of suchOlivier Certner2024-01-291-4/+10
| | | | | | | | | | | | | | | Column "Notes" in fact only contains default values for capabilities, so make this clear by renaming it to "Default". Add a small introductory text mentioning it, and what an absence of default value means (inheritance). PR: 271748 Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40347
* setlogincontext(): Comply to style(9)Olivier Certner2024-01-291-17/+22
| | | | | | | | | | | Remove indentation by inverting the big 'if (lc)' and using 'return'. Use explicit binary operators to produce booleans. Reviewed by: emaste, kib, dchagin Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40346
* login.conf(5): Document umask's special value 'inherit'Olivier Certner2024-01-291-0/+3
| | | | | | | | Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40688
* setclassumask(): Accept 'inherit' as a valueOlivier Certner2024-01-291-1/+12
| | | | | | | | | | | 'inherit' explicitly indicates that the umask should not be changed. Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Relnotes: yes Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40687
* setusercontext(): Set umask in a separate function, setclassumask()Olivier Certner2024-01-291-26/+33
| | | | | | | | Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40686
* login_cap(3): Document login_getcapenum()Olivier Certner2024-01-291-0/+28
| | | | | | | | Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40685
* New login_getcapenum(): Allows to read named enum valuesOlivier Certner2024-01-292-0/+48
| | | | | | | | Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40684
* login.conf(5): umask has no default valueOlivier Certner2024-01-291-1/+1
| | | | | | | | | | | | The umask is simply left unchanged if no explicit value is specified in the login class capabilities database. PR: 271747 Reviewed by: emaste Approved by: emaste (mentor) MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40345
* setusercontext(): umask: Set it only once (in the common case)Olivier Certner2024-01-291-14/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | Simplify the code and make it more coherent (umask was the only context setting not modified by setlogincontext() directly). Preserve the current behavior of not changing the umask if none is specified in the login class capabilities database, but without the superfluous umask() dance. (The only exception to this is that a special value no user is likely to input in the database now stands for no specification.) If some user has a 'umask' override in its '~/.login_conf', the umask will still be set twice as before (as is the case for all other context settings overriden in '~/.login_conf'). Log a warning in case of an invalid umask specification. This change makes it apparent that the value of LOGIN_DEFUMASK doesn't matter. It will be removed in a subsequent commit. PR: 271747 Reviewed by: emaste, kib (earlier version) Approved by: emaste MFC after: 3 days Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40344
* lib: Automated cleanup of cdefs and other formattingWarner Losh2023-11-2725-25/+0
| | | | | | | | | | | | | | | | 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
* lib: Remove ancient SCCS tags.Warner Losh2023-11-276-11/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* setusercontext(): Apply personal settings only on matching effective UIDOlivier Certner2023-10-101-1/+1
| | | | | | | | | | | | | | | | Commit 35305a8dc114 (r211393) added a check on whether 'uid' was equal to getuid() before calling setlogincontext(). Doing so still allows a setuid program to apply resource limits and priorities specified in a user-controlled configuration file ('~/.login_conf') where a non-setuid program could not. Plug the hole by checking instead that the process' effective UID is the target one (which is likely what was meant in the initial commit). PR: 271750 Reviewed by: kib, des MFC after: 2 weeks Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40351
* login_cap.c: Don't set errno to ERANGE on memory allocation failureOlivier Certner2023-10-021-13/+8
| | | | | | | | | | | | | | | | | Modified functions: login_getcaptime(), login_getcapnum(), login_getcapsize(). They all call cgetstr(), which returns -2 on such conditions and already sets errno to ENOMEM, arguably the appropriate value for these functions as well. No in-tree consumer currently checks for errno on error reported by these functions, so this change has no other code impact. Reviewed by: kib MFC after: 2 weeks Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40342
* setusercontext(): Fix gap when setting a realtime-class priorityOlivier Certner2023-10-021-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | The login.conf's "priority" capability allows to set priorities in the idle or realtime classes in addition to the classical nice values (-20 to 20), through a natural extension where values greater than 20 put the processes in the idle class (with priority adjusted within RTP_PRIO_MIN and RTP_PRIO_MAX, 21 being converted to 0, 22 to 1, etc.) and values lower than -20 put the process in the realtime class (with priority adjusted within RTP_PRIO_MIN and RTP_PRIO_MAX, -21 being converted to RTP_PRIO_MAX (31), -22 to 30, etc.). Before this fix, in the latter case (realtime class), -21 was converted to 30, and RTP_PRIO_MAX (31) could never be specified. While here, change the priority computation for the idle-class case to be symmetrical and use RTP_PRIO_MIN (in practice, this changes nothing at all, since RTP_PRIO_MIN is 0; but this is the correct theoretical formula, which would work as well with other values of RTP_PRIO_MIN). PR: 271727 Reviewed by: imp, kib MFC after: 2 weeks Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40339
* forkpty: Avoid fd leak if fork() fails.Dag-Erling Smørgrav2023-08-173-0/+60
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D41491
* Remove my middle name.Dag-Erling Smørgrav2023-08-178-8/+8
|
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-162-2/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: two-line nroff patternWarner Losh2023-08-1628-56/+0
| | | | Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-164-4/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-1636-68/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: two-line .h patternWarner Losh2023-08-166-12/+0
| | | | Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
* login_getclassbyname(3): use calloc.Xin LI2023-07-231-4/+1
|
* getlocalbase: Make default path actually configurableJessica Clarke2023-07-112-9/+9
| | | | | | | | | | | | | | | We include paths.h in getlocalbase.c, which defines _PATH_LOCALBASE. This will override a definition on the command line, meaning it is impossible to override like how the manpage says you can, and it means the code to provide a fallback default is dead as the macro is always defined. Instead, introduce a new LOCALBASE_PATH macro like LOCALBASE_CTL_LEN that can be set on the command line and will default to the system's existing _PATH_LOCALBASE to avoid duplicating the default here. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D40975
* getlocalbase.3: Fix AUTHORS formattingJessica Clarke2023-07-111-1/+4
| | | | MFC after: 1 week
* libutil: Delete trailing whitespaceJessica Clarke2023-07-111-1/+1
|
* login.conf: document how to specify env var values with commasEd Maste2023-06-281-1/+2
| | | | | | | | | | As of f32db406504e quotes may be used to specify login class capabilities that include commas. This is true in general but is particularly relevant for setenv, a comma-separated list of environment variables and values, so mention it there. PR: 236204 Sponsored by: The FreeBSD Foundation
* Fix build with gcc12.Xin LI2023-06-141-7/+6
|
* expand_number: Tighten check of unit.Xin LI2023-06-134-1/+112
| | | | | | | | | | | | | | | | The current code silently ignores characters after the unit as long the unit themselves were recognized. This commit makes expand_number(3) to fail with EINVAL if buf did not terminate after the unit character. Historically, the function accepts and ignores "B" as a SI unit, this behavior is preserved and e.g. KB, MB are still accepted as aliases of K and M, document this behavior in the manual page. While I am there, also write a few test cases to validate the behavior. Reviewed-by: emaste MFC-after: 2 weeks Differential Revision: https://reviews.freebsd.org/D40482
* cpuset(3): Add unit testsBaptiste Daroussin2023-06-012-0/+74
| | | | Differential Revision: https://reviews.freebsd.org/D13046
* cpuset(3): Move cpuset's parselist function into libutilBaptiste Daroussin2023-06-014-2/+204
| | | | | | | | | | | | | | In order to allow to add cpuset(2) functionality to more utilities than just cpuset(1) move the parselist code into libutil While here, make the code a little more "library" friendly, by returning a range of various errors so that the consumer can check for them and report appropriate error message to the users (One of the planed usage is the jail(8) utility) Reviewed by: jilles Differential Revision: https://reviews.freebsd.org/D12873
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-1216-16/+16
| | | | | | | | | 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
* Allow a comma-separated list in login class capabilities,Sean Eric Fagan2023-01-141-2/+107
| | | | by adding a version of strcspn that allows quoting.
* libutil: Fix mandoc warningsGordon Bergling2022-08-076-27/+22
| | | | | | | | | | - missing comma before name - possible typo in section name: Sh CAVEAT instead of CAVEATS - useless macro: Tn - blank line in fill mode, using .sp - no blank before trailing delimiter: Dv NULL? MFC after: 3 days
* libutil: eliminate one syscall from kinfo_getprocEd Maste2022-05-071-7/+5
| | | | | | | | | | | | | | | Previously we invoked the sysctl with a NULL buffer to query the size, allocated a buffer, then invoked it again to fetch the data. As we only handle the case where the sysctl provides data of the expected size we can just allocate a correctly-sized buffer to begin with. Reported by: Thomas Hurst via Twitter Reviewed by: kevans MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D35140