aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
Commit message (Collapse)AuthorAgeFilesLines
* libutil: Fix login_setcryptfmt()Dag-Erling Smørgrav6 hours1-0/+8
| | | | | | | | | | | Our dummy crypt_set_format() needs to be exported, otherwise it will be resolved at link time instead of load time, preventing the real crypt_set_format() in libcrypt from replacing it when present. PR: 288677 Fixes: 0c381b7f0570 Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D51746
* libutil: Backward compatibility for expand_number()Dag-Erling Smørgrav6 hours5-10/+181
| | | | | | | | | | Reimplement expand_number() in terms of expand_unsigned(), which takes a pointer to uint64_t like expand_number() did before. Provide a macro that picks the correct version based on the type of the argument. Fixes: 2e0caa7c7e14 Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D51723
* libutil: Add missing MLINKsDag-Erling Smørgrav3 days2-65/+115
| | | | | | MFC after: 1 week Reviewed by: olce, imp, emaste Differential Revision: https://reviews.freebsd.org/D51706
* libutil: Document pidfile_signal()Dag-Erling Smørgrav3 days1-4/+64
| | | | | | | Fixes: 287451fd0192 MFC after: 1 week Reviewed by: pauamma_gundo.com, emaste Differential Revision: https://reviews.freebsd.org/D51705
* libutil: Drop auth_getval()Dag-Erling Smørgrav4 days4-47/+1
| | | | | | | | | This function has been an empty stub for years; now that we're bumping the library version, we can finally get rid of it. Fixes: 0c381b7f0570 Reviewed by: kib, emaste Differential Revision: https://reviews.freebsd.org/D51704
* libutil: Better tests for expand_number(3)Dag-Erling Smørgrav5 days1-44/+175
| | | | | | | | Replace the current tests with jhb's earlier, more extensive proposal, updated to take into account the switch back to signed integers. Reviewed by: pstef Differential Revision: https://reviews.freebsd.org/D20796
* libutil: Really fix expand_number(3)Dag-Erling Smørgrav5 days3-43/+97
| | | | | | | | | | | | | | | | | | It is unclear whether this function was originally intended to support negative numbers. The original implementation used signed integers, but actually giving it a negative number as input would have invoked undefined behavior, and the comments (since removed) only mentioned positive numbers. Fifteen years ago, I “fixed” this by changing the type from signed to unsigned. However, it would still have accepted an input with a leading minus sign (though it would have returned its absolute value). Fifteen years on, change the type back to signed and fix the logic so it correctly handles both positive and negative numbers without invoking undefined behavior. This makes it a better match for humanize_number(3), which it is supposed to complement. Fixes: bbb2703b4f46 Reviewed by: jhb Differential Revision: https://reviews.freebsd.org/D51542
* libutil: Add symbol versioningDag-Erling Smørgrav5 days2-1/+131
| | | | | Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D51694
* libutil: Move cpuset(1) domain policy parsing code into libutilBojan Novković10 days4-22/+136
| | | | | | | | | | | | | | cpuset(1) implements a domainset(9) policy parser that is used to translate a <policy>:<domain_list> string into a domainset_t mask and a valid domainset policy. This change moves the domainset parsing code into a new cpuset.c function - 'domainset_parselist'. The existing cpuset.c code was refactored into a generalized list parsing function which is now used to parse both CPU sets and domain sets. This is the same approach used in cpuset(1). Reviewed by: markj, ziaee (manpages) Differential Revision: https://reviews.freebsd.org/D46607
* Search for mntopts.h globally, not locallyBrooks Davis2025-04-221-2/+1
| | | | | | | | | Change the include directives to use <mntopts.h> instead of "mntopts.h" now that it's installed by libutil (the latter option was dubious regardless since a -I${SRCTOP}/sbin/mount was required anyway). Reviewed by: olce, imp, dim, emaste Differential Revision: https://reviews.freebsd.org/D49952
* Move mntopts(3) suppport into libutilBrooks Davis2025-04-224-2/+804
| | | | | | | | | | | | | | | | | Many programs use this functionality so it should be available centrally rather than compiled into each program independently. This has the modest downside of adding libutil dependencies to some mount_<foo> programs, but many (plus mount(8)) already have those depndencies so this shouldn't be a major imposition. In commit 906c312bbf74, Kirk said this could be done once the change was merged to FreeBSD 13. That happened in commit 668dfa016698 in 2023. While here perform related tidying including removing SRCS where the only entry is ${PROG}.c rendering it unnecessary. Reviewed by: olce, dim, emaste Differential Revision: https://reviews.freebsd.org/D49951
* kinfo_getfile: Add a comment explaining 4/3 ratioEd Maste2025-04-111-0/+4
| | | | | | | | We first get the expected size of the data from the kern.proc.filedesc sysctl, allocate 4/3 of that size, and then fetch the data. Add a comment about the reason (the fd table may grow between the two calls). Sponsored by: The FreeBSD Foundation
* login.conf.5: remove a stray quoteMaxim Konovalov2024-12-111-1/+1
| | | | PR: 282858
* hexdump.3: Add missing LIBRARY sectionDavid Gilbert2024-11-211-0/+2
| | | | | | | | | | All the other libutil section 3 manpages document this, and although it's heavily implied by the libutil.h header in the synopsis, we should still be explicit and consistent. PR: 280078 Reviewed by: jrtc27 MFC after: 1 week
* ftime.3: fix typo in spelling of libutilKeith White2024-10-181-1/+1
| | | | | PR: 282171 MFC after: 3 days
* 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/