Commit graph

3106 commits

Author SHA1 Message Date
Kyle Evans
aad507854e Fix the cross-build after recent commits
- Provide a sys/md4.h in the cross-build environment to fix bootstrap
    of libmd.
- flua now exposes WTRAPPED which isn't incredibly common- make it
    conditional, we probably won't be using it in any bootstrap context
    any time soon.

Fixes:	442e0975ee ("Consolidate md4 implementations written in C")
Fixes:	c2caf3b331 ("flua: posix: add more useful functions [...]")
2024-09-30 00:08:49 -05:00
Kyle Evans
c2caf3b331 flua: lposix: add more useful functions for general purpose scripts
unistd:
- _exit
- close
- fork
- getpid
- pipe
- read
- write

libgen:
- basename, dirname

stdlib:
- realpath

These are sufficient for a number of real world scenarios.  In our first
application of them, we use the libgen+stdlib additions to grab the
script dir based on argv[0].  The unistd assortment is then used to
outsource a bunch of work to forks and report back to the main process.

Reviewed by:	emaste, imp
Differential Revision:	https://reviews.freebsd.org/D39083
2024-09-29 22:52:20 -05:00
Jose Luis Duran
e72457c4f5 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>
2024-09-26 13:00:16 +02:00
Jose Luis Duran
b9ce743c54 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>
2024-09-26 12:59:56 +02:00
Jose Luis Duran
38bb6f79e3 nuageinit: Standardize user-facing error messages
Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:59:24 +02:00
Jose Luis Duran
945632ca76 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>
2024-09-26 12:59:14 +02:00
Jose Luis Duran
9b2d92addc 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>
2024-09-26 12:59:00 +02:00
Jose Luis Duran
d71e2c037c 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>
2024-09-26 12:58:42 +02:00
Jose Luis Duran
504981357a nuageinit: Lua check and lint files
Mostly white space, style, and luacheck compliance.

Signed-off-by: Jose Luis Duran <jlduran@gmail.com>
2024-09-26 12:58:00 +02:00
Mateusz Piotrowski
91fac46bf7 rc.d/dnctl: Chmod +x for consistency with other rc scripts
MFC after:	1 week
Approved by:	bnovkov
2024-09-22 19:24:39 +01:00
Warner Losh
f5a8f6f71a rtld: Catch up to 07d90ee0a6 in subr_prf.c: Fix '+' conversion handling
Sponsored by:		Netflix
2024-09-22 10:52:11 -06:00
Mateusz Piotrowski
401516dbc5 rc.subr: Consistently use an absolute path for sysrc
MFC after:	2 weeks
Approved by:	christos
2024-09-20 19:28:59 +01:00
Baptiste Daroussin
696922fbfa flua: add freebsd.kenv, kenv(2) bindings
Add bindings for kenv(2) right now only get() has been created
it allows do dump into a key/value table the kernel environement if
no argument is passed, or it returns the value associated to the
provided key.

Reviewed by:	imp, kevans, markj
Accepted by:	imp, kevans
Differential Revision:	https://reviews.freebsd.org/D46654
2024-09-14 07:43:50 +02:00
R. Christian McDonald
4269d1a2e4 rc.subr: fix typo "save_dot" -> "safe_dot"
Reviewed by:	sjg
Approved by:	kp
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D46644
2024-09-13 16:51:40 -04:00
Baptiste Daroussin
fa4b5aa51f freebsd.sys.linker: remove license to only keep SPDX line 2024-09-13 07:07:23 +02:00
Doug Ambrisko
408087f128 zfskeys: allow prompt to entered during boot up
If the ZFS key is setup in prompt mode, use zfs to prompt to load the key
during boot to unlock it.

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D36081
2024-09-12 08:46:49 -07:00
Baptiste Daroussin
cbf53f5e37 flua: install linker in the right patch
When moving the freebsd.sys.linker sources the installation path
was lost.

Fixes 7899f917b1
2024-09-12 14:43:56 +02:00
Baptiste Daroussin
7899f917b1 flua: move modules source into the main source directory
Follow the path of what is done with bsnmp, build the modules along
with the main binary, this allows to build the modules at a moment
where all needed libraries are already built and available in the
linker path instead of having to declare all the libraries which a
flua module will be linked to in _prebuild_libs.

Discused with:	markj
Reviewed by:	markj, jrtc27, kevans, imp
Accepted by:	kevans, imp
Differential Revision:	https://reviews.freebsd.org/D46610
2024-09-12 09:03:44 +02:00
Simon J. Gerraty
7e1c014a9e debug.sh take advantage of hooks.sh
Allow Debug{On,Off} to run associated hooks.
This makes it feasible to collect extra debug info at runtime
without needing to modify any potentially verified and hence immutable
scripts.

Like debug.sh, hooks.sh is extremely handy and used extensively
in many parts of Junos and its build environment.
It is provided here in the hope that others may benefit.

We do not dot hooks.sh by default to reduce overhead, but it can
but done from rc.conf et al using

$_HOOKS_SH . /libexec/hooks.sh

to avoid including more than once.

Reviewed by:	stevek
Sponsored by:	Juniper Networks, Inc.
Differential Revision:	https://reviews.freebsd.org/D46552
2024-09-10 12:04:15 -07:00
R. Christian McDonald
b5f6beefa0 rc.subr: ensure run_rc_script return code is not masked by DebugOff
Ensure that run_rc_script returns the true return code of the
rc command and not the return code of DebugOff

Reviewed by:	sjg
Approved by:	kp
MFC after:	1 week
Sponsored by:	Rubicon Communications, LLC ("Netgate")
Differential Revision:	https://reviews.freebsd.org/D46626
2024-09-10 14:58:47 -04:00
Baptiste Daroussin
bb2d016afb flua: make the ucl module a dynamic module
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D46569
2024-09-06 17:21:29 +02:00
Bjoern A. Zeeb
ed4d2a54fc 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().

MFC after:	10 days
Reviewed by:	zlei
Differential Revision: https://reviews.freebsd.org/D33426
2024-09-05 19:53:57 +00:00
Mark Johnston
1726db7af6 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
2024-09-05 15:53:52 +00:00
Jessica Clarke
62775aebf7 rc.d/devmatch: Silence sysctl hw.bus.devctl_nomatch_enabled=1
As with various other rc scripts, we don't want the output from this
being visible in the boot log.

Fixes:		6437872c1d ("New sysctl to disable NOMATCH until devmatch runs")
MFC after:	1 week
2024-08-29 00:26:26 +01:00
Alex Richardson
04262ed78d rtld-elf: Add CFI annotation for .rtld_start on RISC-V
Without this change, unwinders such as LLVM libunwind will attempt to
unwind beyond the start of RTLD and get stuck in an infinite loop or
crash (depending on the current values on the stack).
This fixes an infinite loop in the LLVM libunwind test suite on RISC-V.

See also https://reviews.freebsd.org/D40844 for AArch64

Reviewed By:	#riscv, jhb
MFC After:	2 weeks
Differential Revision: https://reviews.freebsd.org/D46406
2024-08-25 21:51:55 -07:00
Jessica Clarke
729d2b16b7 rtld-elf: Support IFUNCs on riscv
GNU/Linux has historically had the following two resolver prototypes:

  1. Elf_Addr(uint64_t, void *)
  2. Elf_Addr(uint64_t, void *, void *)

For the former, AT_HWCAP is passed in the first argument, and NULL in
the second. For the latter, AT_HWCAP is still passed, and the second
argument is a pointer to their home-grown __riscv_hwprobe function.
Should they want to use the third argument in future, they'll have to
introduce yet another prototype to allow for later expansion, and then
all users will have to check whether the second argument is NULL to know
if the third argument really exists. This is all rather silly and will
surely prove fun in the face of type-checking CFI.

Instead, be like arm64 and just define all 8 possible general purpose
register arguments up front. To naive source code that forgets non-Linux
OSes exist this will be compatible with prototype 1 above, since the
second argument will be 0 and it won't look further (though should we
start using the second argument for something that wouldn't be true any
more and it might think it's __riscv_hwprobe, but that incompatibility
is one we can defer committing to, and can choose to never adopt).

Until the standard interface for querying extension information[1] is
settled and implemented in FreeBSD there's not much you can do in a
resolver other than use HWCAP_ISA_B, but this gets the infrastructure in
place for when that day comes.

[1] https://github.com/riscv-non-isa/riscv-c-api-doc/pull/74

Reviewed by:	kib, mhorne
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D46278
2024-08-22 20:36:44 +01:00
Jessica Clarke
33658afd4e rtld-elf: Pass parsed aux_info to ifunc_init
Currently we pass the raw pointer to the on-stack auxargs. This can
legitimately have fewer than AT_COUNT entries, so the use of
__min_size(AT_COUNT), i.e. static AT_COUNT, is inaccurate, and also
needlessly forces the callee to iterate over the elements to find the
entry for a given type. Instead we can just pass aux_info like we use
for everything else.

Note that the argument has been left unused by every callee since its
introduction in 4352999e0e ("Pass CPUID[1] %edx (cpu_feature), %ecx
(cpu_feature2) and CPUID[7].%ebx (cpu_stdext_feature), %ecx
(cpu_stdext_feature2) to the ifunc resolvers on x86.")

Reviewed by:	kib
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D46276
2024-08-22 20:36:44 +01:00
Baptiste Daroussin
a6ecbf2b35 nuageinit: improve debugging when mkdir fails 2024-08-20 12:09:43 +02:00
Baptiste Daroussin
19fb9ad746 nuageinit: readd ssh key parsing when key is in meta_data.json
in openstack when no user is specified but a sshkey is provided
the information is stored in meta_data.json under "public_keys"

PR:	280461
Reported by:	tdb
2024-08-20 12:08:29 +02:00
Simon J. Gerraty
35399f68c8 safe_dot check file is a file
Since we are being paranoid, check that each arg to safe_dot is
actually a file as well as non-empty.

Check for white-space in filenames - these require special handling.
2024-08-16 13:15:20 -07:00
Simon J. Gerraty
82cb2a4158 Update safe_eval.sh to support --export
This update allows

safe_dot --export file ...

to export any variables that get set.

Reviewed by: obrien
2024-08-15 15:42:39 -07:00
Isaac Cilia Attard
503adcdf1d dhclient: rc.conf option to disable ARP resolution
Introduce a new rc.conf option to not wait for ARP resolution within
dhclient. This is plausible on many modern networks where it is possible
to trust the DHCP server to know whether an IP address is available.

Sponsored by:	Google LLC (GSoC 2024)
Signed-off-by:	Isaac Cilia Attard <icattard@FreeBSD.org>
MFC after:	10 days
Reviwed by:	cperciva, brooks, Tom Hukins, Alexander Ziaee
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1368
2024-08-09 14:49:51 -07:00
Simon J. Gerraty
6502c60c22 Move fetch of DEBUG_SH from kenv to rc
We only need to check kenv for DEBUG_SH once.
We also need to export DEBUG_SH to be useful.

Sponsored by:	Juniper Networks, Inc.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D46219
2024-08-03 10:56:48 -07:00
Ed Maste
5c2bc3db20 Remove "All Rights Reserved" from FreeBSD Foundation copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder.

Sponsored by:	The FreeBSD Foundation
2024-07-30 12:16:36 -04:00
Konstantin Belousov
860c4d94ac rtld: add LD_NO_DL_ITERATE_PHDR_AFTER_FORK env var
which makes threaded fork ignore the phdr rtld lock, in particular
allowing the dl_iterate_phdr() to block in callback.  The cost is that
the image started in this mode cannot use dl_iterate_phdr() after fork.

PR:	280318
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-07-30 02:57:33 +03:00
Konstantin Belousov
47315d6d35 rtld: make ld_get_env_var() usable for all rtld source files
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-07-30 02:57:33 +03:00
Konstantin Belousov
bc25bc6850 rtld(1): Spell value as VALUE, not NAME
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2024-07-30 02:57:33 +03:00
Jose Luis Duran
8edd6c07c8 nuageinit: Fix tests
Commit 07d17ca189 set the recommended
permissions for the SSH authorized keys file and directory.  The tests,
however, were failing on CI.

Use stat to check for the proper permissions.

Fixes:	07d17ca189 nuageinit: Set recommended SSH permissions
Reported by:	Jenkins
2024-07-25 11:15:29 +02:00
Jose Luis Duran
7aecd689e3 nuageinit: Fix the homedir variable name
cloud-init uses homedir, not home.
2024-07-25 11:15:29 +02:00
Jose Luis Duran
07d17ca189 nuageinit: Set recommended SSH permissions
As stated in sshd(8), the recommended permissions for ~/.ssh are
read/write/execute for the user, and not accessible by others; and the
recommended permissions for ~/.ssh/authorized_keys are read/write for
the user, and not accessible by others.
2024-07-23 15:02:28 +02:00
Jose Luis Duran
7b73ecfe64 nuageinit: Accept plain text passwords
Per pw(8), when -H is set, the password should be supplied already
encrypted in a form suitable for writing directly to the password
database (passwd in cloud-init tems); -h provides a special interface by
which interactive scripts can set an account password using pw(8) in
plain text (plain_text_passwd in cloud-init terms).

The default user (freebsd) is defined with a plain_text_passwd
(freebsd), not with an encrypted one.
2024-07-23 15:01:54 +02:00
Cy Schubert
66f360515d rc.conf: Leap-seconds sources: Add IANA back
11da791920 switched Leap-seconds source from IANA to IERS, as IERS
is the canonoical source. The problem ist that IERS is not accessible
from IPv6 only networks. To work around this we must add IANA back in
order to provide IPv6-only users a source for leap-seconds fetch.

PR:		279413
Fixes:		11da791920
MFC after:	3 days
2024-07-19 11:24:31 -07:00
Warner Losh
e9ac41698b Remove residual blank line at start of Makefile
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
2024-07-15 16:43:39 -06:00
Warner Losh
82dfbaf7e7 rtld-elf: Fix signed conversion for %hh
While char is signed on some of FreeBSD's architecutres, it's unsigned
on others. So the naked 'char' cast here needs to be 'signed char'
because in this context, we want the signed interpretation.

We don't really use %hh conversions in the run time linker, so this is
likely a nop. However, for correctness, we need this, like we did in the
kernel in fc3e5334ab. It's a nop on x86 and riscv due to defaults as
well, but does fix a bug on arm and powerpc where char is unsigned.

Suggested by: kib
Sponsored by: Netflix
2024-07-14 12:01:43 -06:00
Dag-Erling Smørgrav
c15290fb9d tftpd: Code cleanup.
MFC after:	3 days
Sponsored by:	Klara, Inc.
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D45871
2024-07-06 00:05:49 +02:00
Alexander Ziaee
088cc7d221 man filesystems: fix more xrefs after move to s4
Fixes: 1a720cbec5
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1282
2024-06-27 18:32:05 -06:00
Baptiste Daroussin
cde6642431 nuageinit: check for both user_data and user-data
openstack, ec2 and other implementation of cloudinit disagrees on the
name of the file "user-data" or "user_data", test both and use the first
found

PR:	279876
2024-06-27 10:32:14 +02:00
Eugene Grosbein
af1b0aa5b9 rc.subr: improve description for ${name}_offcmd
Clarify that ${name}_offcmd is for method start.

MFC after:	3 days
2024-06-18 16:13:51 +07:00
Alexander Leidinger
2d08f6b577 rc.subr: add some sanity checks for service jails
Add some sanity checks when service jails are used in jails:
 - children.max > 0
 - children.max - children.cur > 0

The nesting is too deep at those places to have a sane formatting, so no
line wrapping at the usual column.
If someone has a better idea how to format this: feel free to go ahead.
2024-06-14 20:15:46 +02:00
Alexander Leidinger
a70ecfb117 rc.subr: add new sysv option for service jails
Clarify that the "sysvipc" svcj option inherits from the host / parent.
Add "sysvipcnew" which creates a new SysV namespace for the service
jail.
Sanity check that only one of them is used.
2024-06-14 20:15:45 +02:00