Commit Graph

735 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav
a4aaee2120 forkpty: Avoid fd leak if fork() fails.
MFC after:	1 week
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D41491
2023-08-17 13:48:42 +00:00
Dag-Erling Smørgrav
e738085b94 Remove my middle name. 2023-08-17 15:08:30 +02:00
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Xin LI
9df529b8a1 login_getclassbyname(3): use calloc. 2023-07-23 11:18:24 -07:00
Jessica Clarke
3a46fe2261 getlocalbase: Make default path actually configurable
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
2023-07-11 21:49:22 +01:00
Jessica Clarke
bfc47586ac getlocalbase.3: Fix AUTHORS formatting
MFC after:	1 week
2023-07-11 18:50:32 +01:00
Jessica Clarke
f8cabe5550 libutil: Delete trailing whitespace 2023-07-11 18:45:23 +01:00
Ed Maste
ab2f6ae8d1 login.conf: document how to specify env var values with commas
As of f32db40650 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
2023-06-28 15:02:14 -04:00
Xin LI
6cc4a1c320 Fix build with gcc12. 2023-06-13 20:24:07 -07:00
Xin LI
08300d8494 expand_number: Tighten check of unit.
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
2023-06-12 21:08:32 -07:00
Baptiste Daroussin
8093646b0b cpuset(3): Add unit tests
Differential Revision:	https://reviews.freebsd.org/D13046
2023-06-01 23:27:45 +02:00
Baptiste Daroussin
04eeb364d4 cpuset(3): Move cpuset's parselist function into libutil
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
2023-06-01 23:16:01 +02:00
Warner Losh
4d846d260e 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
2023-05-12 10:44:03 -06:00
Sean Eric Fagan
f32db40650 Allow a comma-separated list in login class capabilities,
by adding a version of strcspn that allows quoting.
2023-01-14 10:48:29 -08:00
Gordon Bergling
816ca3d10f libutil: Fix mandoc warnings
- 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
2022-08-07 16:30:24 +02:00
Ed Maste
904c148f1c libutil: eliminate one syscall from kinfo_getproc
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
2022-05-06 20:06:09 -04:00
Mateusz Guzik
287451fd01 pidfile: add pidfile_signal
Differential Revision:	https://reviews.freebsd.org/D34681
2022-04-09 15:59:43 +00:00
Konstantin Belousov
f2069331e5 libutil: add kinfo_getswapvmobject(3)
which is the wrapper around the vm.swap_objects sysctl, same as
kinfo_getvmobject(3) wraps vm.objects.

Submitted by:	Yoshihiro Ota
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29754
2021-10-26 15:50:29 +03:00
Felix Johnson
e7f8f3b95e login.conf.5: Mark passwordtime as implemented
login.conf.5 listed passwordtime in RESERVED CAPABILITIES, which is a
section for capabilities not implemented in the base system. However,
passwordtime has been implemented in the base for several years now.

PR:		246099
Reported by:	avg
Reviewed by:	0mp
MFC after:	3 days
2021-10-06 22:51:22 +02:00
Konstantin Belousov
364790beaf pidfile test: guarantee nul termination of the read pid string
PR:	258701
Based on the submission by:	sigsys@gmail.com
MFC after:	1 week
2021-09-24 19:52:41 +03:00
Yuri Pankov
eeaf9d562f setclassenvironment: trim leading spaces in variable names
Trim leading spaces in variable names when the list is e.g.
pretty-formatted in /etc/login.conf or ~/.login_conf.

PR:		247947
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D25649
2021-04-12 01:05:10 +03:00
Stefan Eßer
6c2596f00c Change getlocalbase() to not allocate any heap memory
After the commit of the current version, Scott Long pointed out, that an
attacker might be able to cause a use-after-free access if this function
returned the value of the sysctl variable "user.localbase" by freeing
the allocated memory without the cached address being cleared in the
library function.

To resolve this issue, I have proposed the originally suggested version
with a statically allocated buffer in a review (D27370). There was no
feedback on this review and after waiting for more than 2 weeks, the
potential security issue is fixed by this commit. (There was no security
risk in practice, since none of the programs converted to use this
function attempted to free the buffer. The address could only have
pointed into the heap if user.localbase was set to a non-default value,
into r/o data or the environment, else.)

This version uses a static buffer of size LOCALBASE_CTL_LEN, which
defaults to MAXPATHLEN. This does not increase the memory footprint
of the library at this time, since its data segment grows from less
than 7 KB to less than 8 KB, i.e. it will get two 4 KB pages on typical
architectures, anyway.

Compiling with LOCALBASE_CTL_LEN defined as 0 will remove the code
that accesses the sysctl variable, values between 1 and MAXPATHLEN-1
will limit the maximum size of the prefix. When built with such a
value and if too large a value has been configured in user.localbase,
the value defined as ILLEGAL_PREFIX will be returned to cause any
file operations on that result to fail. (Default value is "/dev/null/",
the review contained "/\177", but I assume that "/dev/null" exists and
can not be accessed as a directory. Any other string that can be assumed
not be a valid path prefix could be used.)

I do suggest to use LOCALBASE_CTL_LEN to size the in-kernel buffer for
the user.localbase variable, too. Doing this would guarantee that the
result always fit into the buffer in this library function (unless run
on a kernel built with a different buffer size.)

The function always returns a valid string, and only in case it is built
with a small static buffer and run on a system with too large a value in
user.localbase, the ILLEGAL_PREFIX will be returned, effectively causing
the created path to be non-existent.

Differential Revision:	https://reviews.freebsd.org/D27370
2020-12-12 11:23:52 +00:00
Stefan Eßer
30d21d2795 Add function getlocalbase() to libutil.
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
2020-11-18 19:44:30 +00:00
Scott Long
8e1031086d Revert the whole getlocalbase() set of changes while a different design is
hashed out.
2020-11-15 20:24:59 +00:00
Scott Long
85a5fe290b Because getlocalbase() returns -1 on error, it needs to use a signed type
internally.  Do that, and make sure that conversations between signed and
unsigned don't overflow
2020-11-15 07:48:52 +00:00
Scott Long
bcf9ae2751 Fix a problem with r367686 related to the use of ssize_t. Not sure how this
escaped prior testing, but it should be better now.

Reported by:	lots
2020-11-14 19:04:36 +00:00
Scott Long
98b76d2227 Add the library function getlocalbase and its manual page. This helps to
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
2020-11-14 17:57:50 +00:00
Gordon Bergling
3d265fce43 Fix a few mandoc issues
- skipping paragraph macro: Pp after Sh
- sections out of conventional order: Sh EXAMPLES
- whitespace at end of input line
- normalizing date format
2020-10-09 19:12:44 +00:00
David Bright
9b934d4360 Add CAP_EVENT to pidfiles.
CAP_EVENT was omitted on pidfiles (in
pidfile_open()). There seems no reason why a process that creates
and writes a pidfile cannot monitor events on that file. This mod adds
the capability.

Reviewed by:	cem@
MFC after:	2 weeks
Sponsored by:	Dell EMC Isilon
Differential Revision:	https://reviews.freebsd.org/D25363
2020-06-25 21:34:43 +00:00
Piotr Pawel Stefaniak
830efe5539 Make vipw error message less cryptic
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
2020-06-20 06:20:00 +00:00
Piotr Pawel Stefaniak
39c64ed6d1 libutil: remove extraneous ": " from error messages
Each of the err() family of functions already takes care of that.
2020-06-20 06:10:42 +00:00
Gordon Bergling
bc89b58def libutil: Document function HISTORY within the manpages
Reviewed by:	bcr (mentor)
Approved by:	bcr (mentor)
MFC after:	7 days
Differential Revision:	https://reviews.freebsd.org/D24795
2020-06-14 05:35:02 +00:00
Kyle Evans
acf2957e49 login.conf(5): split MAIL env var out into a "mail" capability
This allows it to be easily suppressed in, e.g., the "daemon" class where it
will not be properly expanded.

This is a part of D21481.

Submitted by:	Andrew Gierth <andrew_tao173.riddles.org.uk>
2020-02-05 04:17:14 +00:00
Simon J. Gerraty
2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Emmanuel Vadot
a7b5a3d486 pkgbase: Put a lot of binaries and lib in FreeBSD-runtime
All of them are needed to be able to boot to single user and be able
to repair a existing FreeBSD installation so put them directly into
FreeBSD-runtime.

Reviewed by:    bapt, gjb
Differential Revision:  https://reviews.freebsd.org/D21503
2019-09-05 14:13:08 +00:00
Mateusz Guzik
ebea9e6d8f libutil: remove SIGSYS handling from setusercontext
It was a workaround for cases where the kernel lacks setloginclass(2),
added in the 9.x era.

Submitted by:	Pawel Biernacki
2019-09-02 13:55:31 +00:00
John Baldwin
72a52ef8c4 expand_number(3) parses suffixes, not prefixes.
While here, tidy the opening sentence a bit.

MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D20791
2019-07-20 16:03:54 +00:00
Mark Johnston
8e7299c08b Typo.
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2019-06-03 16:47:00 +00:00
Mariusz Zaborski
8a9e93bb21 Use funlinkat in pidfile to ensure we are removing the right file. 2019-04-06 11:24:43 +00:00
Mark Johnston
a273e09cb2 Fix pidfile_open(3) to handle relative paths with multiple components.
r322369's use of basename(3) was incorrect and worked by accident so
long as the pidfile path was absolute or consisted of a single
component.  Fix the basename() usage and add a regression test.

Reported by:	0mp
Reviewed by:	cem
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D19728
2019-03-27 19:40:18 +00:00
John Baldwin
2e43efd0bb Drop "All rights reserved" from my copyright statements.
Reviewed by:	rgrimes
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D19485
2019-03-06 22:11:45 +00:00
Sean Eric Fagan
18bb746b40 r343881 had an uninitialized error. This fixes that.
PR:             233849
Reported by:    Andre Albsmeier
MFC after:      1 month
Sponsored by:   iXsystems Inc
Differential Revision:  https://reviews.freebsd.org/D18785
2019-02-07 22:10:20 +00:00
Sean Eric Fagan
148d31b83d r339008 broke repquota for UFS. This rectifies that.
Refactor the function calls and tests so that, on UFS, the proper fields
are filled out.

PR:		233849
Reported by:	Andre Albsmeier
Reviewed by:	mav, delphij
MFC after:	1 month
Sponsored by:	iXsystems Inc
Differential Revision:	https://reviews.freebsd.org/D18785
2019-02-07 21:51:39 +00:00
Xin LI
1e4da04f06 Ensure buffer is nul-terminated.
MFC after:	2 weeks
2018-12-31 03:08:01 +00:00
Ian Lepore
757e8bdbea Stop exporting __pw_scan and __pw_initpwd as freebsd-private libc functions
for use in libutil, and instead compile the small amount of common code
directly into libutil with a .PATH reachover.

Discussed with: kib@
2018-07-27 19:47:42 +00:00