Commit graph

3071 commits

Author SHA1 Message Date
Cy Schubert
94f4140860 Revert "ntpd: Use the ntpd -u option in preference to the rc su plumbing"
Using the ntpd -u option to set the credentials ntpd is to run under
while still using rc(8) to invoke causes some FreeBSD installs to fail
to load mac_ntp. The fact that that can_run_nonroot() does not
indicate why failures occur leaves people on the mailing lists
guessing as to why there are failures. Let's revert back to using
the rc(8) provided su. The ntpd rc script will be rewritten when
the ntpd chroot will be implemented.

Reported on:	freebsd-stable@

This reverts commit 521f66715afb312b356afafc68cbc044a436a753.

(cherry picked from commit 5ca7754519e8c618968d8acbf54d653b6e968829)
2025-03-11 10:59:10 -07:00
Cy Schubert
23ad1f4bb7 var_run: Clean up style
Clean up style and make more consistent.

Replace test with if-then-else to make the script more legible.

Replace the call to dirname with the shell %/* operator avoiding a
fork & exec.

Reorder the test for $var_run_autosave before the test for /var/run on
tmpfs. This avoids gratuitously scanning the mount table for a tmpfs
/var/run.

Initial concept by and in discussion with:
	Harry Schmalzbauer <freebsd@omnilan.de>

No functional change intended.

Differnential revision:	https://reviews.freebsd.org/D47773

(cherry picked from commit ed9712f8943573136fa92a0e61c8e7c10952eeb0)
2025-03-06 16:32:53 -08:00
Konstantin Belousov
69b6dc0b92 libc/gen: split user-visible opendir()-like functions into separate source files
(cherry picked from commit d40daefca64750c1076822bdbd3c409a9519f513)
2025-03-04 06:19:08 +02:00
Cy Schubert
1a241a911d ntpd: Use the ntpd -u option in preference to the rc su plumbing
Using the rc plumbing to setuid(2) is preferred as it allows the user
to use the -i option in ntpd_flags to chroot ntpd.

Chrooting ntpd by default will be a 2025 project.

Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D48191

(cherry picked from commit 521f66715afb312b356afafc68cbc044a436a753)
2025-02-24 16:37:46 -08:00
Navdeep Parhar
03bbfb01cc rc.d/iovctl: Start the iovctl service after kld.
Drivers, including those that support SR-IOV, can be loaded via kld_list
and it makes sense to process iovctl configuration files afer all
drivers have been loaded.

Sponsored by:	Chelsio Communications
Reviewed by:	0mp, jhb
Differential Revision:	https://reviews.freebsd.org/D47937

(cherry picked from commit 41594021fa8bf02468407e8fc48c2e7a13de1a2f)
2025-02-13 20:57:54 -08:00
Konstantin Belousov
068de5be49 rtld: clear any holes in the struct utrace_rtld passed to kernel logger
PR:	284563

(cherry picked from commit e917958c36670131ab42e8f2c849b708a3216e37)
2025-02-08 02:26:55 +02:00
Gordon Bergling
676794ac4b bootptest: Fix a typo in a source code comment
- s/tralier/trailer/

(cherry picked from commit 5da0eee3d842bd0bef2c95553e75e462cda27ee6)
2025-01-29 06:56:40 +01:00
Minsoo Choo
880f1dee7e tcp_wrappers: Use default C standard version
Reviewed by:	emaste, arichardson, jhb
Differential Revision: https://reviews.freebsd.org/D43236

(cherry picked from commit 2cadbe468a8e8aef193429565b729d34ec48b266)
2025-01-24 14:50:38 -05:00
Konstantin Belousov
f10a06556f rtld-elf/{amd64,i386}/reloc.c: remove unneeded #ifdef dbg
(cherry picked from commit e3035c52f25356299abc8e08be9221032967554d)
2025-01-23 11:46:58 +02:00
Konstantin Belousov
57820508a0 rtld-elf/rtld.c: fix typo in comment
(cherry picked from commit dd1d72961b8d343b29480b74afcfe4292fd166af)
2025-01-23 11:46:57 +02:00
Baptiste Daroussin
68f025feeb nuageinit: use io.popen instead of pipes in shell for password
using echo in a sh(1) command line, requires many escaping to be done
right, using io.popen we don't need to do this escaping anymore.

(cherry picked from commit 3e502866073f8d922eecb9016920a56b90c35e38)
2025-01-15 10:53:39 +01:00
Baptiste Daroussin
707a34afe1 nuageinit: remove redundant mkdirs
(cherry picked from commit f3b371f4d938c09c4cdc8fd95b4b52e1d8dd41dd)
2025-01-15 10:51:27 +01:00
Mark Johnston
1c7f325e76 rc: Document rtadvd_flags
PR:		283696
MFC after:	1 week

(cherry picked from commit 872686b17e70636f031436b458262eb7dacc5832)
2025-01-14 14:14:24 +00:00
Tijl Coosemans
fb3408bb6e rc.d/sendmail: Fix error with some configurations
The sendmail startup script can run 4 daemons: sendmail, sendmail_submit,
sendmail_outbound, and sendmail_msp_queue.  Of the first 3 at most one
can be enabled.  There's a run_rc_command call for each and the ones for
sendmail and sendmail_msp_queue run unconditionally.  For some rc
commands this triggers warnings or errors when sendmail_enable="NO" or
sendmail_msp_queue_enable="NO".  Since d2e7bb630b83 these errors are
propagated and the whole script fails.

Fix this by first determining which daemons are enabled, setting ${name}
and ${rcvar} accordingly, and then always calling run_rc_command
conditionally.

Also replace ${name}.cf with sendmail.cf because ${name} isn't always
sendmail.

PR:		282585
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D47757

(cherry picked from commit 6b17d944a1d448dbb797c5fa5b0778242ba02e52)
2024-12-31 14:16:10 +01:00
Baptiste Daroussin
c062d3ec60 nuageinit: implement ssh_keys support
MFC After:	1 week
Sponsored by:	OVHCloud

(cherry picked from commit 41fe9d53005ef213ff16d9b095c0a88e3f2fb296)
2024-12-12 16:52:25 +01:00
Ed Maste
30bcbf8a2f comsat: move uid/gid setting earlier
It's good to reduce privilege as early as possible.

Suggested by:	jlduran
Reviewed by:	jlduran
Obtained from:	NetBSD
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47869

(cherry picked from commit 91629228e3df14997df12ffc6e7be6b9964e5463)
2024-12-04 13:38:31 -05:00
Ed Maste
bb9678f1ff comsat: Use initgroups and setgid not just setuid
PR:		270404
Reviewed by:	jlduran
Obtained from:	NetBSD
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47828

(cherry picked from commit d4dd9e22c13896e6b5e2a6fc78dad4f8496cc14d)
2024-12-04 13:38:31 -05:00
Cy Schubert
a7f33b5019 rc.d/var_run: Add missing $(dirname)
We intend to create the containing directory here. Fix this typo.

PR:		282939

(cherry picked from commit 4d58cf6ff905377dbca1ecf004f53133e6b57a46)
2024-12-04 09:08:27 -08:00
Ed Maste
957f7a2a58 comsat: Improve use of setuid()
Just return from jkfprintf if either (a) user lookup fails (that is,
getpwnam fails) or (b) setuid() to the user's uid fails.  If comsat is
invoked from inetd using the default of tty:tty we will now return due
to setuid() failing rather than fopen() failing.

PR:		270404
Reviewed by:	kevans
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D47823

(cherry picked from commit 062b69ba045dc0fef3d9b8d73365d2798c05a480)
2024-12-02 16:10:31 -05:00
Franco Fichtner
03fdd4f38d atf: Guard libexec/atf with WITH_TESTS_SUPPORT
Other atf components are guarded by WITH_TESTS_SUPPORT already.
WITH_TESTS is for actual tests.

Reviewed by:	markj
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47660

(cherry picked from commit 43e045c1733d50fad79f3a53e05140b8dc0d7fa6)
2024-11-28 14:38:16 +00:00
Konstantin Belousov
73cc71607d rtld: drop RTLD_INIT_PAGESIZES_EARLY
(cherry picked from commit 5bc24fd7a21ffd98fe978b4eb09a383c09edbe37)
2024-11-27 13:31:55 +02:00
Kyle Evans
708106fb80 rtld: implement _dl_iterate_phdr_locked
Some sanitizers need to be able to use dl_iterate_phdr() after stopping
the rest of the process, but it's very hard to do so reliably as a
non-participant in the main logic of the program.

Introduce _dl_iterate_phdr_locked to bypass the locking that's normally
required for dl_iterate_phdr() and slap some scary warning on it.  It
will remain undocumented and probably shouldn't be used for anything
else.

Reviewed by:	kib

(cherry picked from commit 1426fd6cff0603f0ee275b99f2ba35dc36f3d0c2)
2024-11-26 19:15:56 -06:00
R. Christian McDonald
d39e0bdc6b rtld/arm: fix initial-exec (IE) thread-local storage relocation
net/frr[89] revealed an interesting edge-case on arm when dynamically
linking a shared library that declares more than one static TLS variable
with at least one  using the "initial-exec" TLS model. In the case
of frr[89], this library was libfrr.so which essentially does the
following:

	#include <stdio.h>

	#include "lib.h"

	static __thread int *a
		__attribute__((tls_model("initial-exec")));

	void lib_test()
	{
		static __thread int b = -1;

		printf("&a = %p\n", &a);
		printf(" a = %p\n", a);

		printf("\n");

		printf("&b = %p\n", &b);
		printf(" b = %d\n", b);
	}

Allocates a file scoped `static __thread` pointer with
tls_model("initial-exec") and later a block scoped TLS int. Notice in
the above minimal reproducer, `b == -1`. The relocation process does
the wrong thing and ends up pointing both `a` and `b` at the same place
in memory.

The output of the above in the broken state is:

	&a = 0x4009c018
	 a = 0xffffffff

	&b = 0x4009c018
	 b = -1

With the patch applied, the output becomes:

	&a = 0x4009c01c
	 a = 0x0

	&b = 0x4009c018
	 b = -1

Reviewed by:	kib
Approved by:    kp (mentor)
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D42415/

(cherry picked from commit 98fd69f0090da73d9d0451bd769d7752468284c6)
2024-11-22 10:35:06 -05:00
Mark Johnston
b837ead1d4 tftpd: Address flaky tests
The tftpd tests all follow the same pattern:
1. open a UDP socket,
2. fork a child to exec tftpd, which subsequently handles requests on
   the socket,
3. use a client socket to send some message to the tftpd daemon.

However, tftpd's first action is to mark its socket as non-blocking and
then read a request from it.  If no data is present in the socket, tftpd
exits immediately with an error.  So, there is a race; we often see
tftpd test timeouts when running tests in parallel.  These timeouts also
arise periodically in CI runs.

One solution is to restructure each test to create the server socket,
then write the request to the client socket, then fork tftpd.  This
closes the race.  However, this involves a lot of churn.

This patch fixes the problem a different way, by adding a new -b flag to
tftpd which makes it block to read the initial request.  Each test is
modified to use -b, closing the race.

Reviewed by:	imp, asomers
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D47404

(cherry picked from commit 79c342aaf86feb4efbd15383f54e4fe7bdc9da7b)
2024-11-19 14:15:06 +00:00
Cy Schubert
3b032c0698 ipfilter: Set ipf -T optionlist at boot
There is no easy way to set ipfilter optionlist variables during boot.
Add plumbing to the rc script to support this.

PR:			130555
Reviewed by:		jlduran
Differential Revision:	https://reviews.freebsd.org/D47346

(cherry picked from commit 8d6feaaaa26f444abb209360e52b993e39cb81bb)
2024-11-18 16:26:04 -08:00
Jose Luis Duran
f6d94e23d1
rc: Update ipfilter example rules location
It was originally /usr/src/contrib/ipfilter/rules and moved to
/usr/src/share/examples/ipfilter/rules in 41edb306f0.

Point to users to /usr/src/share/examples/ipfilter instead, as the base
directory also contains example rules.

Reviewed by:	emaste
Approved by:	emaste (mentor)
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D47392

(cherry picked from commit 8934526be1843ba033e1423f6ecd8b3b3f2a9c23)
2024-11-14 03:21:25 +00:00
Konstantin Belousov
dcdc0d7167 rtld.1: cross-reference rtld_get_var.3
(cherry picked from commit 16d000bdac54d7153f33a0d050bcc4307b702751)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
86a2abab0a rtld: add rtld_{get,set}_var
(cherry picked from commit c56df6ce71ae96f00b088790d3ad2e0ebebdd59a)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
db21e6980b rtld: make it easier to add sparce non-default members to ld_env_var_desc
(cherry picked from commit d7214577ff00221ac84a85e61794a5e126b952dd)
2024-11-14 02:42:17 +02:00
Konstantin Belousov
8ee3da8e73 rtld: 1-bit for bool is enough
(cherry picked from commit 450e684e0fea2785b5770241f51e897070c86726)
2024-11-14 02:42:17 +02:00
Mark Johnston
fc3c731bbf rc.d/kld: Print modules being loaded, take three
Some kernel modules will print informative messages when they are
loaded, making the output confusing.  Print everything up front instead.

Fixes:	152382e6613d ("rc.d/kld: Print the kernel modules being loaded")

(cherry picked from commit 3e55170e0fa2695f6d662e3ab67201138a6f8698)
2024-11-09 01:09:50 +00:00
Mark Johnston
2cb615d015 rc.d/kld: Avoid printing a trailing space
Fixes:		152382e6613d ("rc.d/kld: Print the kernel modules being loaded")
Reported by:	jrtc27

(cherry picked from commit cdb3cda6fd53b89c2bba0308d21aa8edf782dc34)
2024-11-09 01:09:47 +00:00
Mark Felder
bba8c461b9 rc.d/kld: Print the kernel modules being loaded
PR:		282269
MFC after:	2 weeks

(cherry picked from commit 152382e6613d7998fe6f5233767df54d3fdec329)
2024-11-09 01:09:29 +00:00
Baptiste Daroussin
6c682f5c38 nuageinit: add support for OpenStack network config
Add naive support for openstack network config.
if no config driver have been found, try to detect that we are running a
VM on openstack via the smbios information, use the first iface
available and temporary activate dhcp on it, to be able to fetch the
necessary informations for cloudinit.

While here make the rc script execute after devmatch, some ethernet
device might be attached via devmatch and may be needed for cloudinit.

Tested on OVHCloud Public Cloud.

MFC after:	3 weeks
Sponsored by:	OVHCloud

(cherry picked from commit 2775b9b0bcc278dd4183b57784953c26a3fcdc89)
2024-11-06 09:36:12 +01:00
Graham Percival
cdffbea57c manuals: Fix dates
These were reported by `mandoc -T lint ...` as warnings.

Signed-off-by:	Graham Percival <gperciva@tarsnap.com>
Reviewed by:	mhorne
MFC after:	3 days
Sponsored by:	Tarsnap Backup Inc.
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1475

(cherry picked from commit b74aaa1a2199261f9078247d29481a994b6b5e42)
2024-11-04 12:16:22 -04:00
Mateusz Piotrowski
4ff71ffaa7 rc.d/sendmail: Return non-zero if the daemon fails to start or is not running
If you have a mail server that is running sendmail daemon
(sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES)
and the sendmail daemon dies, /etc/rc.d/sendmail status does see the
daemon is not running but returns 0 as the exit code.  This prevents
other programs (like puppet) from restarting sendmail to fix the issue.

Make sure that the exit code is propagated towards the end of the script
if any of the sendmail services fail.

This patch does not call exit directly but instead just sets the exit
status code by calling exit in a subshell. This way we do not exit the
current shell in case the service script is sourced (e.g., when
rc_fast_and_loose is active).

PR:		223132
MFC after:	2 weeks
Reported by:	pirzyk
Discussed with:	jilles, eugen
Reviewed by:	christos, gshapiro (previous version), markj
Approved by:	christos (mentor), markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D46862
Co-authored-by: Jim Pirzyk <pirzyk@FreeBSD.org>

(cherry picked from commit d2e7bb630b83848a774d8213014a9e0747775019)
2024-11-04 15:55:40 +01:00
Robert William Vesterman
6fb03ddbce libexec/rc/rc.d/netif: Typo fix
Just fixing a typo ("configuriing" => "configuring").

Pull Request:	https://github.com/freebsd/freebsd-src/pull/1484

(cherry picked from commit 65691b2dafda23691c3989749def755a98e731ec)
2024-10-30 17:49:57 -07:00
Mateusz Piotrowski
025535f945 rc/tests: Skip oomprotect tests in a jail
oomprotect cannot be used in a jail.

Reviewed by:	bnovkov, christos, markj
Approved by:	bnovkov (mentor), christos (mentor), markj (mentor)
MFC after:	1 week

(cherry picked from commit 6fa42b91ca3f481912af98c4d49c44507eb1b8e1)
2024-10-21 11:59:16 +02:00
Mateusz Piotrowski
f94127e3ee rc.d/sendmail: Fix stopping service during shutdown
The sendmail service script needs to be stopped during shutdown
to ensure a clean shutdown of active SMTP connections (and writing
any in memory queue files).

rcorder(8) requires the rcorder block to be an uninterrupted sequence of
REQUIRE, PROVIDE, BEFORE, and KEYWORD lines. Having a comment in between
REQUIRE and KEYWORD makes rcorder stop parsing the block when it reaches
the comment.

Fix that by moving the comment out from the rcorder block.

Reviewed by:	bnovkov, christos, gshapiro, markj
Approved by:	bnovkov (mentor), christos (mentor), markj (mentor)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D46924

(cherry picked from commit 8751fbe36ff02ed695f02132ee6eac723d2bbe3f)
2024-10-14 12:23:46 +02:00
Mark Johnston
cde4ab289d flua: Add wrappers for sys/utsname.h
This allows one to invoke uname from lua scripts.

Reviewed by:	bapt, kevans, emaste
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D42017

(cherry picked from commit 1726db7af6b3738eb04d962b351d7f4017e1fc77)
2024-10-10 20:28:20 +00:00
Jose Luis Duran
e573007af2 nuageinit: tests: Cleanup
- Export NUAGE_FAKE_ROOTDIR only once
- Use the header section of the test to require the root user
- Use the PWD environment variable
- Set the root/sys shell as /bin/sh
- Use RFC 5737 reserved IP addresses

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit e72457c4f5166eef2a27249e02f3c1e9a1cf852d)
2024-10-08 09:04:02 +02:00
Jose Luis Duran
9881d68b1e nuageinit: Fix passwords
The hashed password usually contains a "$" sign, which, when used on a
shell, must be escaped.  Also, the plain text password may contain
special characters that require escaping.

Add a quick fix by enclosing it in single quotes.  Note that if the
plain text password contains a "'", it will still fail.  This will be
properly fixed in later commits.

Some here documents require the document to be a string literal,
especially when passing invalid characters.  Enclose it in single
quotes.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit b9ce743c5447e90c2c97f4d49e048c301f708527)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
03abe3ac40 nuageinit: Standardize user-facing error messages
Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 38bb6f79e39a14ea99f559f59129a4cadf92b569)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
182ff41e84 nuageinit: Standardize warning/error messages
Standardize the utilities from nuage.lua, to return nil on failure, plus
an error message as a second result, and some value different from nil
on success.

Make warnmsg() and errmsg() append "nuageinit: " by default.  Pass an
optional second parameter as false to avoid printing this tag.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 945632ca76117029e7bd1f46d17ccb378973daf7)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
1eaf3331ea nuageinit: Replace os.execute with Lua libraries
Prefer posix.sys.stat's chmod() to os.execute().  While here, change the
name of the locals to be more descriptive.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 9b2d92addc31ba6f5696c85d184a45d43e9073dc)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
c96dbfbd1b nuageinit: Silence an fstyp(8) warning
Silence a warning emitted by fread(3) in fstyp(8)'s read_buf(), when
detecting the file system type of the cloud-init device:

    % fstyp /dev/iso9660/cidata
    fstyp: fread: Invalid argument
    cd9660

Also rephrase slightly a comment while here.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit d71e2c037c942dbe2a9fd2630d5cf155dd1bf7db)
2024-10-08 09:04:01 +02:00
Jose Luis Duran
68c7c28d0e nuageinit: Lua check and lint files
Mostly white space, style, and luacheck compliance.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
(cherry picked from commit 504981357aa36365784458cfe8d9e23097bfac7b)
2024-10-08 09:04:01 +02:00
Mateusz Piotrowski
e3b57f1485 rc.subr: Consistently use an absolute path for sysrc
MFC after:	2 weeks
Approved by:	christos

(cherry picked from commit 401516dbc54e4a4cba3085cd605fbf6cf8293b79)
2024-10-02 11:27:00 +02:00
Mateusz Piotrowski
2ab84513e9 rc.d/dnctl: Chmod +x for consistency with other rc scripts
MFC after:	1 week
Approved by:	bnovkov

(cherry picked from commit 91fac46bf7cff03c3471422c67281041c5fa0f1f)
2024-10-02 11:11:20 +02:00
Bjoern A. Zeeb
d60a0ffecf rc: network.subr update consitency with older change (v6/v4 order)
As of 1b5be7204e we setup parts of IPv6
before IPv4 if configured.  For consistency change a case in ifn_start()
calling ipv6_up() before ipv4_up() and reverse in ifn_stop().

Reviewed by:	zlei
Differential Revision: https://reviews.freebsd.org/D33426

(cherry picked from commit ed4d2a54fc7a0397c2042f496f176305ca03ebdd)
2024-09-28 10:35:11 +00:00