Commit graph

3275 commits

Author SHA1 Message Date
Kyle Evans
3f0e109209 flua: fbsd: allow stdout to be captured for exec() processes
This allows us to do things like:

```
local fp = assert(fbsd.exec({"ls", "-l"}, true))
local fpout = assert(fp:stdout())

while true do
        local line = fpout:read("l")
        if not line then break end
        print("Read: " .. line)
end

fp:close()
```

The makeman lua rewrite will use it to capture `make showconfig` output
for processing.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D50539
2025-07-09 00:12:32 -05:00
Kyle Evans
6a2c624b35 flua: fbsd: return a process handle to operate on when we exec()
This gives us some way to be able to write to stdin if we want to, or
as a future improvement, will allow us to extract stdout from the
process.  The handle is setup to close and waitpid() on close/gc so that
existing users wouldn't necessarily leak for the lifetime of the script
if they weren't adopted to the new model.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D50538
2025-07-09 00:12:31 -05:00
Kyle Evans
0610ba6cdb flua: fbsd: avoid leaking stdin pipes on error
Additionally, there's no way to get to the end without a valid
stdin_pipe[1] at the moment, so don't check for it.  stdin_pipe[0] is
closed earlier, as the parent shouldn't need the read-side of the pipe.

While we're here, also free the file actions earlier and on error --
they're not necessary once posix_spawnp() has returned.

Reviewed by:	bapt
Differential Revision:	https://reviews.freebsd.org/D50537
2025-07-09 00:12:31 -05:00
Mark Johnston
eda96744b4 lposix: Clean up the posix namespace definitions
The posix module is subdivided according to C headers; for instance,
posix.unistd contains routines available from unistd.h, such as
chown(2).

A quirk of our implementation is that each of the modules is a direct
entry in the global table.  That is, there is no "posix" table.
Instead, "posix.foo" and "posix.bar.baz" are both top-level tables.
This is surprising and goes against Lua's shorthand of using "." to
access keys in a table.  lua-posix also doesn't work this way.

Rework things so that "posix" and "posix.sys" are proper tables.
Existing flua code which uses require() to bind posix submodules to a
name will be unaffected.  Code which accesses them directly using
something like _G["posix.sys.utsname"].uname() will be broken, but I
don't think anything like that exists.  In particular, it is now
possible to call posix.sys.utsname.uname() without any require
statements.

Reviewed by:	imp, bapt
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D51158
2025-07-07 15:43:27 +00:00
Mark Johnston
667ef8875b nuageinit: Add wrappers for chmod and chown
In the wrappers, check for errors and abort if one is raised.  At some
point it may be useful to have a mechanism to ignore errors, but I'm not
sure yet how that should look.

For chmod, let the mode be specified as an octal number, otherwise it's
hard to understand what's happening.  Note that this must be specified
as a string, otherwise tonumber() will raise an error.

Reviewed by:	bapt
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D51159
2025-07-05 14:54:07 +00:00
Mark Johnston
88d94ead7f lposix: Use reentrant passwd and group lookup functions
The implementation of chown() in the posix module handles user and group
names as well as numeric IDs.  When resolving names, be sure to use
reentrant lookup functions rather than assuming it's safe to clobber the
internal buffers used by getpwnam() and getgrnam().

Fix some style nits while here.

Reviewed by:	imp, bapt
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D46555
2025-07-04 20:11:12 +00:00
Eugene Grosbein
24e8ed535f network.subr: correct return code in case of bad call to ifisup()
This is rather cosmetic correction.

PR:		287872
MFC-after:	2 weeks
X-MFC-With:	6d3bc576ab
2025-07-01 21:33:19 +07:00
Eugene Grosbein
6d3bc576ab libexec/rc: improve performance of pccard_ether script
Replace "ifconfig -ul" with "ifconfig -n" because netlink-enabled
/sbin/ifconfig utility has sub-optimal performance for listing.

Combined with the commit b1b17432aa,
these changes mostly eliminate performance regression of the command
"service devd start" for a system having hundreds of network interfaces
created before devd starts, after FreeBSD 14+ switched
/sbin/ifconfig to netlink(4)

PR:		287872
MFC-after:	2 weeks
2025-07-01 21:13:10 +07:00
Mark Johnston
9c014cc25c Revert "rc: Disable pathname expansion when calling run_rc_command()"
At least nuageinit is broken after this commit, breaking some downstream
CI systems.  It also disables globbing for rc.local scripts, which is
likely to break users in surprising ways.

This reverts commit 4deb9760a9.
2025-06-27 20:18:36 +00:00
Mark Johnston
d783591a7d Revert "rc: Fix scripts that need pathname expansion"
The commit which motivated this is being reverted.

This reverts commit 7faddeb395.
2025-06-27 20:18:24 +00:00
Sebastien Baylocq
7ad574b3e3 nuageinit: fix log name 2025-06-27 16:35:55 +02:00
Baptiste Daroussin
b56d2195f1 nuageinit: enhance sudo support
from the cloudinit specification sudo rules can be a string or an
array of string
2025-06-26 14:34:51 +02:00
Baptiste Daroussin
3969965c7f nuageinit: fix setting owner when only the user is set 2025-06-26 14:34:51 +02:00
Baptiste Daroussin
d9a4c24df1 nuageinit: write_files fix typo breaking tests 2025-06-26 14:34:51 +02:00
joyu liaonull
0804e60df1 ftpd: Provide an option to turn off FTP anonymous usage
ftpd provides the -n option to disable anonymous FTP access, meaning the
username 'ftp' cannot log in to the FTP server without a password stored
in the password database. This feature helps prevent users who lack the
background knowledge of how this special username 'ftp' conventionally
works in FTP from mistakenly creating an account with the username
'ftp,' assuming it behaves like other usernames that require a password
to log in to the FTP server, which it does not.

Differential Revision:	https://reviews.freebsd.org/D46547
2025-06-26 14:10:14 +02:00
Baptiste Daroussin
19a7ea3cc4 nuageinit: implement write_files
write_files is a list of files that should be created at the first boot

each file content can be either plain text or encoded in base64 (note
that cloudinit specify that gzip is supported, but we do not support it
yet.)

All other specifier from cloudinit should work:
by default all files will juste overwrite exesiting files except if
"append" is set to true, permissions, ownership can be specified.
The files are create before packages are being installed and user
created.

if "defer" is set to true then the file is being created after packages
installation and package manupulation.

This feature is requested for KDE's CI.
2025-06-26 13:47:37 +02:00
Sebastien Baylocq
dba00b1c6b nuageinit: launch post network script with postnet citype
Sponsored by:	OVHCloud
2025-06-26 09:26:11 +02:00
Baptiste Daroussin
40dafa08b2 nuageinit: use lyaml to parse yaml files
This fixes case where vendors or cloudinit consumers are using all
features from yaml.

KDE is using reference for its CI for example.
lima-vm uses syntax for which our previous yaml.lua has bug in the
parser (https://github.com/lima-vm/lima/issues/1508)
2025-06-26 09:24:15 +02:00
Baptiste Daroussin
2bc180ef04 lyaml: vendor import lua bindings for libyaml 2025-06-26 09:15:08 +02:00
Andrew Turner
28fd9bceba rtld-elf: Add Add AT_HWCAP3 and AT_HWCAP4
Add the AT_HWCAP3 and AT_HWCAP4 format strings to auxfmt.

Reviewed by:	brooks, kib
Sponsored by:	Arm Ltd
Differential Revision:	https://reviews.freebsd.org/D51007
2025-06-24 17:26:40 +01:00
Siva Mahadevan
7067bab893
nuageinit(7) tests: Fix extra space in test output expectation
This fixes the test case libexec.nuageinit.nuageinit.config2_userdata_packages

Signed-off-by: Siva Mahadevan <me@svmhdvn.name>

Event:		Kitchener-Waterloo Hackathon 202506
Sponsored by:	The FreeBSD Foundation
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1734
2025-06-20 17:01:25 -04:00
Maxim Konovalov
b78b7fa01f nuageinit.7: language and grammar improvements
Reviewed by:	bapt
2025-06-19 13:14:33 +00:00
Cy Schubert
abd3c20a03 mountcritlocal: Check only first byte for comment
Check for a "#" at the start of the line regardless whether it is its
own token or not. We avoid unecessary calls to rc.d/zpool.

Suggested by:	ivy
Fixes:		b6e33f0cd5
2025-06-17 12:59:36 -07:00
Maxim Konovalov
1049c079c0 nuageinit.7: language and grammar fixes mostly 2025-06-17 07:59:57 +00:00
Baptiste Daroussin
5ec727ea1a nuageinit: write a documentation
Reviewed by:	imp, ziaee (both a previous version)
Differential Revision:	https://reviews.freebsd.org/D50878
2025-06-17 08:54:39 +02:00
Baptiste Daroussin
dba559e806 nuageinit: fix typo 2025-06-16 15:52:47 +02:00
Baptiste Daroussin
2a05d577ab nuageinit: add a post network script
refactor nuageinit to allow a 3rd execution point during boot:
1. nuageinit is invoked before NETWORKING with a minimalistic network setup
   for openstrack and potentially other network config setup. it tries
   to configure everything which is not requiring any network.
2. nuageinit is invoked again post NETWORKING but pre SERVERS, in the
   phase it does all that requires network, like dealing with packages.
   Note that creating users have been moved to this phase to allow the
   installation of shells like bash or zsh prior the creation of the
   users, before that the user creation was failing if a non installed
   shell was requested.
3. nuageinit will execute at the rc.local time all the specified scripts
   and commands.

MFC After: 1 week
2025-06-16 10:29:19 +02:00
Cy Schubert
4103f8dd57 rc.d: Add MIT KRB5 krb5kdc support
MIT KRB5 krb5kdc differs from the Heimdal kdc.

- The MIT kdc is named krb5kdc while the Heimdal one is named kdc.
- krb5kdc -d flag has a different meaning. krb5kdc -d specifies a
  database name. While the Heimdal kdc uses the -d flag to daemonize
  it. krb5kdc automaticially daemonizes itself unless the -n flag is
  specified.

We do this by looking at the name of the kdc program to determine if
we assume it's a Heimdal kdc or the MIT krb5kdc.

Sponsored by:		The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D50813
2025-06-15 19:49:37 -07:00
Baptiste Daroussin
6a54f886be nuageinit: add support for sudo 2025-06-15 17:18:48 +02:00
Cy Schubert
b6e33f0cd5 rc.d/mountcritlocal: Make sure zpools are imported for legacy ZFS
Legacy ZFS uses fstab to mount its datasets. In an attempt to fix
another problem 900bc02063 broke legacy ZFS in fstab(5). This
comit works around the problem by mountcritlocal scanning /etc/fstab
for zfs mountpoint and if any are found invoke /etc/rc.d/zpool start.

Reviewed by:		imp
Differential Revision:	https://reviews.freebsd.org/D50844
2025-06-14 21:39:36 -07:00
Hiroki Sato
7faddeb395
rc: Fix scripts that need pathname expansion
Reported by:	Kenneth Raplee
Differential Revision:	https://reviews.freebsd.org/D45855
2025-06-15 05:24:41 +09:00
Baptiste Daroussin
f1dd507b2c nuageinit: support "fqdn" and "hostname" 2025-06-14 20:56:59 +02:00
Siva Mahadevan
900bc02063 rc.d/zpool: change mountcritlocal dep from BEFORE to REQUIRE
In cases where the `/boot` directory is mounted from a different disk,
`/boot/zfs/zpool.cache` will not be found during a `rc.d/zpool`
run. This is because `/etc/fstab` mounts are mounted in
`rc.d/mountcritlocal`, which currently runs AFTER (i.e. `REQUIRE:`)
`rc.d/zpool`.

This change swaps the `rcorder` of `rc.d/zpool`'s dependency on
`mountcritlocal` from `BEFORE:` to `REQUIRE:`. This will ensure that
`/boot` (or even `/etc/` in some configurations) to be visible while
searching for `zpool.cache`.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1614
Closes: https://github.com/freebsd/freebsd-src/pull/1614
2025-06-13 09:47:25 -06:00
Baptiste Daroussin
cae3d6c8d4 nuageinit: fix typo
PR:	287503
Reported by:	crest@rlwinm.de
2025-06-13 17:33:53 +02:00
Hiroki Sato
4deb9760a9
rc: Disable pathname expansion when calling run_rc_command()
Variables for command-line options like $foo_flags can contain characters
that perform pathname expansions, such as '[', ']', and '*'.  They were
passed without escaping, and the matched entries in the working directory
affected the command-line options.  This change turns off the expansion
when run_rc_command() is called.

While this changes the current behavior, an invocation of a service
program should not depend on entries in the working directory.

Differential Revision:	https://reviews.freebsd.org/D45855
2025-06-13 03:19:32 +09:00
Baptiste Daroussin
f678c47590 nuageinit: pet luacheck
Rename path into ni_path (ni stands for nuageinit) which is more
understandable and avoid a shadowing warning because we also use a
variable named path later.

Add a missing local
2025-06-10 11:32:06 +02:00
Baptiste Daroussin
8feca60d6e nuageinit: runcmd should also be executed late
Execute the runcmd specified in cloudinit at the same moment as the
user_data script aka late in the boot process, to respect cloudinit
specifications
2025-06-10 11:28:49 +02:00
Baptiste Daroussin
09545628f0 nuageinit: fix using user_data as a script
In official cloudinit, when a user_data file starts with '#!' it
should be execute late in the boot process. To respect this nuageinit
now copy the user_data script into a /var/cache/nuageinit/user_data if
found and a new "firsboot" rcscript anchored to the 'local' rc script is
responsible to execute it if found.

Note by doing this, we fix another issue we had with nuageinit, if the
cloudinit provider provides the user_data scriptout with the executable
permission, previous implementation was not working, like apparently
what Digital Ocean is doing.

PR:		287183
Reported by:	olgeni@
2025-06-10 09:20:23 +02:00
Sebastien Baylocq
682af9601a nuageinit: more package related functions
Implement package_update and package_upgrade, which allows to launch
an update of the metadata and an upgrade of the packages.

Sponsored by:	OVHCloud
2025-06-06 18:26:41 +02:00
Sebastien Baylocq
076fec1b88 nuageinit: implement packages
Installs a list of packages

Sponsored by:	OVHCloud
2025-06-06 18:26:40 +02:00
Sebastien Baylocq
43b82d69b2 nuageinit: add a function to bootstrap pkg if needed
Sponsored by:	OVHCloud
2025-06-06 18:26:38 +02:00
Sebastien Baylocq
2f35a52183 nuageinit: implement runcmd
runcmd contains a list of string, each item will be executed in order.

Sponsored by:	OVHCloud
2025-06-06 18:26:37 +02:00
Sebastien Baylocq
e38f521f53 nuageinit: helper function to setup adduser
To carry out the userdata unit tests, you need to set up the environment in
order to skip adding the default user (nuage.adduser(default_user)

Sponsored by:	OVHCloud
2025-06-06 18:26:35 +02:00
Baptiste Daroussin
9a62e1d98d nuageinit: log nuageinit execution
Sponsored by:	OVHCloud
2025-06-06 13:07:32 +02:00
Lexi Winter
08419bf194 don't gate ctl{d,adm} behind MK_ISCSI
These are no longer specific to iSCSI; always build them.

Reviewed by:	kevans, jhb
Approved by:	kevans (mentor)
Differential Revision:	https://reviews.freebsd.org/D50625
2025-06-01 03:08:40 +01:00
Dag-Erling Smørgrav
83a1ee578c atf, kyua: Implement require.kmods.
This adds a metadata variable, require.kmods, and corresponding functions
or methods in C, C++, and shell, which allow a test to specify that it
requires particular kernel modules to run.  If the kernel modules are not
present, the test is skipped.  One might want to consider a kyua option
which makes it attempt to load the modules instead.

Differential Revision:	https://reviews.freebsd.org/D47470
2025-05-31 14:27:30 +02:00
Jessica Clarke
48fd084579 rtld-elf: Pass TCB to allocate_module_tls to avoid re-getting
The only caller already has the current TCB to hand, so just pass it
down rather than get it again. This also makes it clear in the caller
that it depends on the (current) TCB, rather than being storage that
could be assigned to any thread (concurrency issues aside).

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D50594
2025-05-29 17:07:02 +01:00
Jessica Clarke
960f40b892 rtld-elf: Pass struct tcb * around rather than struct dtv **
When this code was first written we didn't have even a struct tcb, so to
make it MI a pointer to the DTV pointer in the TCB was passed around.
Now that we have a struct tcb we can simplify the code by instead
passing around a pointer to that, and the MI code can access the tcb_dtv
member wherever it happens to be in the layout. This reduces boilerplate
in all the various callers of tls_get_addr_common/slow and makes it
clearer that tls_get_addr_common/slow are operating on the TCB, rather
than obfuscating it slightly through the double pointer.

Whilst here, clarify the comments in aarch64's TLSDESC dynamic resolver,
which were using tp without clarifying what this was for (previously a
pointer to the DTV pointer, now a pointer to the TCB, which happen to be
the same thing for Variant I TLS, and in the case of AArch64 are what
TPIDR_EL0 point to directly, with no offset/bias).

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D50591
2025-05-29 17:06:49 +01:00
Jessica Clarke
ccfb1c50e4 Revert "rtld: fix allocate_module_tls() variant I fallback to static allocation"
This was applying a NetBSD fix to FreeBSD. However, the original code
was correct for FreeBSD. NetBSD's obj->tlsoffset is relative to the end
of the TCB, not the TCB itself, whilst ours is relative to the TCB[1]
itself. For example, our allocate_tls uses (char *)tcb + obj->tlsoffset
for the memcpy and memset calls.

Without this reverted, for dynamically loaded shared objects, Initial
Exec accesses to TLS variables on variant I architectures (non-x86) use
the correct address, whilst General Dynamic and dlsym(3) use the
incorrect address (TLS_TCB_SIZE past the start). Note that, on arm64,
LLVM only supports TLSDESC (including LLD) and TLSDESC will use the
static resolver if the variable ends up allocated to the static TLS
block, even in the presence of dlopen(3), so only dlsym(3) shows the
discrepancy there.

Whilst here, add a comment to explain this difference to try and avoid
the same mistake being made in future.

[1] In the case of variant II, it's the amount to subtract, so still
    positive

This reverts commit e9a38ed2fa.

Reviewed by:	kib (prior version)
Fixes:		e9a38ed2fa ("rtld: fix allocate_module_tls() variant I fallback to static allocation")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D50565
2025-05-28 21:24:52 +01:00
Jessica Clarke
03801d449a rtld-elf/riscv: Don't allocate static TLS for dynamic TLS relocations
Provided you don't run out of extra static TLS space this should work,
but it's wholly unnecessary and not how things are supposed to be done.
Only static TLS relocations should allocate static TLS.

Reviewed by:	kib
Fixes:		4b1859c0e9 ("Add support for RISC-V architecture.")
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D50563
2025-05-28 21:22:15 +01:00