Commit Graph

1410 Commits

Author SHA1 Message Date
Richard W.M. Jones
5ea1e899e0 daemon/ldm.c: Replace jansson with json-c 2024-10-22 11:02:38 +01:00
Richard W.M. Jones
e37768d889 build: Assume __attribute__((cleanup)) always works
All recent compilers support this (except MS compilers which we don't
care about).  Assume it is supported.  We test it in ./configure and
hard fail if it doesn't work.

We still define HAVE_ATTRIBUTE_CLEANUP but you can now assume it is
always defined and don't have to check it.
2024-10-18 21:55:21 +01:00
Richard W.M. Jones
e55eac12d4 docs: Update libguestfs email address in a couple more places
Reported-by: Julian Euler
2024-09-12 12:45:54 +01:00
Wang Guoquan
1d8924c343 libguestfs: Support openEuler
openEuler is simliar to CentOS, but the ID is not lower-case string,
as below:

    NAME="openEuler"
    VERSION="24.03 (LTS)"
    ID="openEuler"
    VERSION_ID="24.03"
    PRETTY_NAME="openEuler 24.03 (LTS)"
    ANSI_COLOR="0;31"

Signed-off-by: Wang Guoquan <wangguoquan03@foxmail.com>
2024-09-10 11:33:20 +01:00
Richard W.M. Jones
3d2061b83c daemon/inspect_fs.ml: Sort lists of distros
No change, just tidying up the lists.
2024-07-11 13:12:41 +01:00
grass-lu
a429ab3319 Kylin is centos derivative
Acked-by: Richard W.M. Jones <rjones@redhat.com>
2024-07-11 13:12:24 +01:00
Richard W.M. Jones
e616c8f286 inspection: Resolve PARTUUID= and PARTLABEL= in /etc/fstab
Fixes: https://issues.redhat.com/browse/RHEL-46596
2024-07-08 14:44:01 +01:00
Richard W.M. Jones
1816651f3c New APIs: findfs_partuuid and findfs_partlabel
These search for partitions by UUID or label (name).  They only work
for GPT.
2024-07-08 14:44:01 +01:00
Richard W.M. Jones
4c5c0782af daemon/findfs.ml: Fix whitespace 2024-07-08 14:37:06 +01:00
Richard W.M. Jones
24c1f7b03a daemon: Fix parsing in part_get_gpt_attributes
The actual output of sfdisk --part-attrs is bizarre and doesn't match
the documentation.  After looking at the source from util-linux, fix
the parsing to match what sfdisk produces.

Reported-by: Yongkui Guo
Fixes: commit c6c266a85d
Fixes: https://issues.redhat.com/browse/RHEL-35998
2024-06-28 09:42:20 +01:00
Jonatan Pålsson
465be22d9b daemon: cryptsetup_open: Add --cipher
This allows passing the --cipher argument to cryptsetup as an optional
parameter.
2024-06-20 07:42:55 +02:00
Richard W.M. Jones
c6c266a85d daemon: Reimplement partition GPT functions using sfdisk
sfdisk can now do everything with GPT that sgdisk was needed for
before.  In particular we are able to reimplement the following
functions using sfdisk:

- part_set_disk_guid   (replace with sfdisk --disk-id)
- part_get_disk_guid
- part_set_disk_guid_random
- part_set_gpt_attributes           (sfdisk --part-attrs)
- part_get_gpt_attributes
- part_set_gpt_guid                 (sfdisk --part-uuid)
- part_get_gpt_guid
- part_set_gpt_type                 (sfdisk --part-type)
- part_get_gpt_type

This allows us to drop the requirement for gdisk in many cases.

There is only one API remaining which requires gdisk, part_expand_gpt,
which we do not use in our tools.  In a prior commit I already moved
this solitary function to a new source file (daemon/gdisk.c).

Fixes: https://issues.redhat.com/browse/RHEL-35998
2024-05-10 16:25:13 +01:00
Richard W.M. Jones
a25f419802 daemon: Add an OCaml binding for get_random_uuid function 2024-05-10 16:07:20 +01:00
Richard W.M. Jones
d5c6e15180 daemon: Move gdisk function to a new file
After subsequent commits, this will be the only remaining use of
gdisk, so put it in its own file now.
2024-05-10 15:36:03 +01:00
Richard W.M. Jones
2811e42b43 daemon: part_get_gpt_type: Remove unhelpful MBR fallback behaviour
This was an accident of the parted implementation, and wasn't really
used anywhere.  Remove it.
2024-05-10 15:29:07 +01:00
Richard W.M. Jones
857615d6d2 daemon/parted: Assume sfdisk --part-type exists
This "new" parameter was added in 2014:

  commit 8eab3194ce1737a167812d5e84d83b0dfc253fac
  Author: Karel Zak <kzak@redhat.com>
  Date:   Mon Sep 15 12:37:52 2014 +0200

    sfdisk: add --parttype

    The patch also makes --{id,change-id,print-id} deprecated in favour
    of --parttype. The original --id is too generic option name and the
    --print-id and --change-id are unnecessary and inconsistent with
    another sfdisk options (e.g. we don't have --change-bootable)

Also remove an extraneous / incorrect comment about parted.  As
history has played out, sfdisk proves to be the better tool and parted
is a PITA.
2024-05-10 15:29:07 +01:00
Richard W.M. Jones
37d2379be2 daemon: Fix file architecture translation for LoongArch
Fixes: commit 729d6d55ea
2024-03-07 16:50:29 +00:00
Richard W.M. Jones
c8cefa6f0f daemon: parted: Print field we are extracting in error message 2024-03-07 14:17:45 +00:00
Bella Zhang
72f99817c7 Add detection support for Circle Linux 2024-02-06 12:22:00 +00:00
Alexey Shabalin
f878f72430 daemon: Add gost checksum command support
gostsum - generates or checks GOST R34.11-94 message digests
gost12sum - generates or checks GOST R34.11-2012 message digests

A reference implementation https://github.com/gost-engine/engine

Fixes: https://github.com/libguestfs/libguestfs/pull/132
Signed-off-by: Alexey Shabalin <shaba@altlinux.org>

[RWMJ: Added documentation, and added gostsum package to
the appliance]
2024-01-25 13:28:22 +00:00
Juergen Hoetzel
102e503648 daemon/btrfs: Use new syntax for balance command
Support for the obsolete short syntax 'btrfs balance /path' was
removed in btrfs-progs 6.6.
2023-12-14 16:53:50 +00:00
Richard W.M. Jones
f8cbd71400 daemon: Find -lcamlstr{nat,byt} and -lunix{nat,byt}, and require -lzstd
OCaml 5.1 changes the names of these libraries for some reason.

Also in OCaml 5.1, if using those libraries you must link with -lzstd.
Since zstd was already described as "required" (although we only used
it in the appliance), there is no official change to the requirements,
but I have added a configure time check for the library.

Thanks: Jerry James <loganjerry@gmail.com>
2023-10-06 11:23:52 +01:00
Richard W.M. Jones
c95d8c4cf6 daemon: Omit 'file -S' option on older distros that lack support
OpenSUSE LEAP 15 lacks support for this option, so test for it before
using it.

See also:
https://listman.redhat.com/archives/libguestfs/2023-September/032613.html

Reported-by: Olaf Hering
Fixes: commit 23986d3c4f
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2023-09-21 15:09:14 +01:00
cunshunxia
188c5f7d93 support OpencloudOS
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
Fixes: https://github.com/libguestfs/libguestfs/pull/125
2023-09-19 11:02:23 +01:00
Richard W.M. Jones
32cb5b45cf daemon: lvm: Do reverse device name translation on pvs_full device fields
Intermittent test failures in virt-filesystems showed that when using
the pvs_full API, the pv_name field in the returned list of structures
was not being reverse translated.  As a result internal partition
names could appear in the output of virt-filesystems.

See: https://listman.redhat.com/archives/libguestfs/2023-July/032058.html
2023-07-20 11:15:26 +01:00
Richard W.M. Jones
3cb094083e Replace Pervasives.* with Stdlib.*
Since OCaml 4.07 (released 2018-07-10) the always-loaded standard
library module has been called Stdlib.  The old Pervasives module was
finally removed in OCaml 5.

$ perl -pi.bak -e 's/Pervasives\./Stdlib./g' -- `git ls-files`

OCaml >= 4.07 is now required.

Also update the common submodule with:

  commit d61cd820b49e403848d15c5deaccbf8dd7045370
  Author: Jürgen Hötzel
  Date:   Sat May 20 18:16:40 2023 +0200

    Add support for OCaml 5.0
2023-05-22 16:42:31 +01:00
Zixun LI
692802bf96 daemon/tar: support more compression methods.
Add support for lzma and zstd compression methods.

Signed-off-by: Zixun LI <admin@hifiphile.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2023-05-02 11:15:02 +01:00
Andrey Drobyshev
d0d8e67384 daemon/selinux-relabel: run setfiles with "-T 0", if supported
Since SELinux userspace v3.4 [1], setfiles command supports "-T nthreads"
option, which allows parallel execution.  "-T 0" allows using as many
threads as there're available CPU cores.  This might speed up the process
of filesystem relabeling in case the appliance is being run with multiple
vCPUs.  The latter is true for at least v2v starting from d2b64ecc67
("v2v: Set the number of vCPUs to same as host number of pCPUs.").

For instance, when running virt-v2v-in-place on my 12-core Xeon host
with SSD, with appliance being run with 8 vCPUs (the upper limit specified
in d2b64ecc67), and on the ~150GiB disk VM (physical size on the host),
I get the following results:

./in-place/virt-v2v-in-place -i libvirt fedora37-vm -v -x

Without this patch:
...
commandrvf: setfiles -F -e /sysroot/dev -e /sysroot/proc -e /sysroot/sys -m -C -r /sysroot -v /sysroot/etc/selinux/targeted/contexts/files/file_contexts /sysroot/^M
libguestfs: trace: v2v: selinux_relabel = 0
libguestfs: trace: v2v: rm_f "/.autorelabel"
guestfsd: => selinux_relabel (0x1d3) took 17.94 secs
...

With this patch:
...
commandrvf: setfiles -F -e /sysroot/dev -e /sysroot/proc -e /sysroot/sys -m -C -T 0 -r /sysroot -v /sysroot/etc/selinux/targeted/contexts/files/file_contexts /sysroot/^M
libguestfs: trace: v2v: selinux_relabel = 0
libguestfs: trace: v2v: rm_f "/.autorelabel"
guestfsd: => selinux_relabel (0x1d3) took 5.88 secs
...

So in my scenario it's getting 3 times faster.

[1] https://github.com/SELinuxProject/selinux/releases/tag/3.4

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2023-04-27 15:22:02 +01:00
Andrey Drobyshev
152d6e4bdf daemon/selinux-relabel: search for "invalid option" in setfiles output
'X' in the setiles' stderr doesn't necessarily mean that option 'X'
doesn't exist.  For instance, when passing '-T' we get: "setfiles:
option requires an argument -- 'T'".

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2023-04-27 15:21:54 +01:00
Andrey Drobyshev
9ced5fac8c daemon/selinux-relabel: don't exclude "/selinux" if it's non-existent
Since RHBZ#726528, filesystem.rpm doesn't include /selinux.  setfiles
then gives us the warning: "Can't stat exclude path "/sysroot/selinux",
No such file or directory - ignoring."

Though the warning is harmless, let's get rid of it by checking the
existence of /selinux directory.

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2023-04-27 15:21:35 +01:00
Richard W.M. Jones
250ee85839 Rework Std_utils.Option so it works like the OCaml stdlib module
OCaml 4.08 introduces a stdlib Option module which looks a bit like
ours but has a number of differences.  In particular our functions
Option.may and Option.default have no corresponding functions in
stdlib, although there are close enough equivalents.

This change was automated using this command:

$ perl -pi.bak \
  -e 's/Option.may/Option.iter/g; s/Option.default /Option.value ~default:/g' \
  `git ls-files`

Update common module to include:

  commit cffa077323fafcdfcf78e230c022afa891a6b3ff
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Mon Feb 20 12:11:51 2023 +0000

    mlstdutils: Rework the Option module to be compatible with stdlib
2023-02-20 12:14:08 +00:00
Richard W.M. Jones
e2c7bddf10 Update copyright dates for 2023
Run this command across the source:

  perl -pi.bak -e 's/(20[012][0-9])-20[12][012]/$1-2023/g' `git ls-files`

and remove changes to po{,-docs}/*.po{,t} (these will be regenerated
later when we run 'make dist').
2023-02-07 10:50:48 +00:00
Richard W.M. Jones
fbf7fe8793 build: Remove bundled copy of ocaml-augeas
This is now an external dependency.
2023-01-19 23:00:23 +00:00
Richard W.M. Jones
f3dd67affe New API: inspect_get_build_id
Add an API to return the build ID of the guest.  This to allow a
future change to be able to distinguish between Windows 10 and Windows 11
which can only be done using the build ID.

For Windows we can read the CurrentBuildNumber key from the registry.
For Linux there happens to be a BUILD_ID field in /etc/os-release.
I've never seen a Linux distro that actually uses this.

Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2022-12-02 10:16:57 +00:00
Richard W.M. Jones
23986d3c4f file: Use -S option with -z
The file(1) manual suggests using -S (disable seccomp) with -z since
the set of system calls provided by the seccomp policy does not allow
the subprocess to run.  This is obvious when you use file -z on a
compressed file on a Linux distro that enables file's seccomp policy
(Arch does this, Fedora does not):

  $ file -zbsL lib-i586.so.zst
  Bad system call

I also fixed some incorrect text in the manual.

Thanks: Toolybird for pointing to this fix
Reported-by: David Runge
Fixes: https://github.com/libguestfs/libguestfs/issues/100
2022-11-28 10:21:00 +00:00
Richard W.M. Jones
001683e885 appliance: Remove LD_PRELOAD=libSegFault.so
This feature was removed in glibc 2.35:
https://savannah.gnu.org/forum/forum.php?forum_id=10111
2022-10-24 10:41:09 +01:00
Richard W.M. Jones
c2dd84b263 daemon: Make vg_scan and lvm_scan no-ops if no LVM feature
If the LVM ("lvm2") feature is not available, these calls would fail.
Really they ought to be part of the "lvm2" optgroup which would cause
the generator to call reply_with_unavailable_feature and generate the
correct ENOTSUP error.  When vgscan was originally added in 2010 it
was not added to the optgroup, and when lvm_scan was later added in
2018 and deprecating vgscan, the same mistake was copied.

Before this commit they will try to run the lvm pvscan command which
will fail returning some other error (instead of ENOTSUP).

Fix this by turning the calls into no-ops if the LVM feature is not
available, since scanning for LVM objects when there is no LVM can be
safely turned into a no-op.

See also
https://listman.redhat.com/archives/libguestfs/2022-September/thread.html#29908

Also this updates the common module to pick up a related fix:

  commit 4b4a5b84647b1496d034bcdff910930ca5f5c486
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Fri Sep 23 15:18:43 2022 +0100

    options: Don't attempt to scan LVs if "lvm2" feature is not available

Reported-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Fixes: 55dfcb2211 ("New API: lvm_scan, deprecate vgscan")
Fixes: 9752039e52 ("New API: vgscan")
2022-09-27 15:53:48 +01:00
Richard W.M. Jones
0b3c6cc0c0 daemon: Remove remaining uses of custom printf %Q and %R
We have traditionally used custom printf formatters %Q and %R, where
%Q replaces the argument with a shell-quoted string, and %R replaces
the argument with a sysroot-prefixed shell-quoted string.  They are
actually pretty useful, but unfortunately only supported by glibc.

We only used them in about a dozen places in the daemon (much code
having been replaced by OCaml which does not need them).

In every remaining case we were constructing a command using code like
this:

  asprintf_nowarn (&cmd,
         "cd %Q && find -print0 | %s -0 -o -H %s --quiet", ...);

We can replace this with:

  char *cmd;
  size_t cmd_size;
  fp = open_memstream (&cmd, &cmd_size);
  fprintf (fp, "cd ");
  shell_quote (dir, fp);
  fprintf (fp, " && find -print0 | %s -0 -o -H %s --quiet", ...);
  fclose (fp);
2022-08-16 10:39:01 +01:00
Richard W.M. Jones
ad8b1b09ee daemon: grub: Remove incorrect use of printf specifier %R
This code is attempting to construct a grub-install command like:

  grub-install --root-directory=/sysroot/boot /dev/sda

In fact it was adding quoting to the --root-directory parameter where
it was not needed (because our "command" function uses exec).

Remove use of %R here (to avoid the extra quoting) and just use the
sysroot prefix directly.
2022-08-16 10:21:33 +01:00
Richard W.M. Jones
0e784824e8 daemon: Add zstd support to guestfs_file_architecture
This is required so we can determine the file architecture of
zstd-compressed Linux kernel modules as used by OpenSUSE and maybe
other distros in future.

Note that zstd becomes a required package, but it is widely available
in current Linux distros.

The package names come from https://pkgs.org/download/zstd and my own
research.
2022-08-09 19:04:41 +01:00
Richard W.M. Jones
4a517601c7 daemon: Parse /etc/hostname files containing comments
Thanks: Dawid Zamirski
Link: https://www.freedesktop.org/software/systemd/man/hostname.html
Acked-by: Laszlo Ersek <lersek@redhat.com>
2022-07-20 13:22:39 +01:00
Laszlo Ersek
9a3e9a6c03 introduce the "clevis_luks_unlock" API
Introduce a new guestfs API called "clevis_luks_unlock". At the libguestfs
level, it is quite simple; it wraps the "clevis luks unlock" guest command
(implemented by the "clevis-luks-unlock" executable, which is in fact a
shell script).

The complexity is instead in the network-based disk encryption
(Clevis/Tang) scheme. Useful documentation:

- https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/security_hardening/index#configuring-automated-unlocking-of-encrypted-volumes-using-policy-based-decryption_security-hardening
- https://github.com/latchset/clevis#clevis
- https://github.com/latchset/tang#tang

The package providing "clevis-luks-unlock" is usually called
"clevis-luks", occasionally "clevis". Some distros don't package clevis at
all. Add the new API under a new option group (which may not be available)
called "clevisluks".

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1809453
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220630122048.19335-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2022-07-01 15:07:26 +02:00
Richard W.M. Jones
1087d314cc daemon: Remove workaround for -Wanalyzer-mismatching-deallocation
On older GCC:

debug.c:116:32: error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]
  116 | #pragma GCC diagnostic ignored "-Wanalyzer-mismatching-deallocation"
      |                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[3]: *** [Makefile:2039: guestfsd-debug.o] Error 1

The upstream bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99193)
has now been fixed so the workaround is not necessary with the latest
GCC, so just delete the workaround.
2022-06-17 13:24:19 +01:00
Laszlo Ersek
8fc4d16715 appliance, daemon: disable lvm2 devicesfile
In guestfs-tools commit 4fe8a03cd2d3 ('sysprep: remove lvm2's default
"system.devices" file', 2022-04-11), we disabled the use of LVM2's new
"devicesfile" feature, which could interfere with the cloning of virtual
machines.

We suspected in

  https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c6

that the same lvm2 feature could affect the libguestfs appliance itself,
but decided in

  https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c8
  https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c10

that this would not be the case, because "appliance/init" already
constructed a pristine LVM_SYSTEM_DIR.

Unfortunately, that's not enough: due to the "use_devicesfile=1" default
(on RHEL9 anyway), some "lvm" invocation, possibly inside the
lvm-set-filter API, *creates* "$LVM_SYSTEM_DIR/devices/system.devices".
And then we get (minimally) warnings such as

> Please remove the lvm.conf global_filter, it is ignored with the devices
> file.
> Please remove the lvm.conf filter, it is ignored with the devices file.

when using the lvm-set-filter API.

Explicitly disable the "devices file" in "appliance/init", and also
whenever we rewrite "lvm.conf" -- that is, in set_filter()
[daemon/lvm-filter.c]. In the former, check for the feature by locating
the devicesfile-related utilities "lvmdevices" and "vgimportdevices". In
the C code, invoke the utilities with the "--help" option instead. (In
"appliance/init",  I thought it was best not to call any lvm2 utilities
even with "--help", with our lvm2.conf still under construction there.) If
either utility is available, set "use_devicesfile = 0".

Cc: David Teigland <teigland@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1965941
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220530141027.16167-1-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
[lersek@redhat.com: style fix: break "devicesfile_feature" in the function
 definition to a new line]
2022-05-31 08:47:58 +02:00
Richard W.M. Jones
488245ed6c daemon: rpm: Check return values from librpm calls
We previously didn't bother to check the return values from any librpm
calls.  In some cases where possibly the RPM database is faulty, this
caused us to return a zero-length list of installed applications (but
no error indication).

One way to reproduce this is given below.  Note this reproducer will
only work when run on a RHEL 8 host (or more specifically, with
rpm <= 4.16):

$ virt-builder fedora-28
$ guestfish -a fedora-28.img -i rm /var/lib/rpm/Packages
$ guestfish --ro -a fedora-28.img -i inspect-list-applications /dev/sda4 -vx
...
chroot: /sysroot: running 'librpm'
error: cannot open Packages index using db5 - Read-only file system (30)
error: cannot open Packages database in
error: cannot open Packages index using db5 - Read-only file system (30)
error: cannot open Packages database in
librpm returned 0 installed packages
...

With this commit we get an error instead:

...
chroot: /sysroot: running 'librpm'
error: cannot open Packages index using db5 - Read-only file system (30)
error: cannot open Packages database in
ocaml_exn: 'internal_list_rpm_applications' raised 'Failure' exception
guestfsd: error: rpmtsInitIterator
guestfsd: => internal_list_rpm_applications (0x1fe) took 0.01 secs
libguestfs: trace: internal_list_rpm_applications = NULL (error)
libguestfs: error: internal_list_rpm_applications: rpmtsInitIterator
libguestfs: trace: inspect_list_applications2 = NULL (error)
libguestfs: trace: inspect_list_applications = NULL (error)
...

Not in this case, but in some cases of corrupt RPM databases it is
possible to recover them by running "rpmdb --rebuilddb" as a guest
command (ie. with guestfs_sh).

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=2089623#c12
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2089623
Fixes: commit c9ee831aff
Reported-by: Xiaodai Wang
Reported-by: Ming Xie
Acked-by: Laszlo Ersek <lersek@redhat.com>
2022-05-26 10:16:21 +01:00
Laszlo Ersek
a39b79f607 daemon/selinux-relabel: tolerate relabeling errors
Option "-C" of setfiles(8) causes setfiles(8) to exit with status 1 rather
than status 255 if it encounters relabeling errors, but no other (fatal)
error. Pass "-C" to setfiles(8) in "selinux-relabel", because we don't
want the "selinux-relabel" API to fail if setfiles(8) only encounters
relabeling errors.

(NB even without "-C", setfiles(8) continues traversing the directory
tree(s) and relabeling files across relabeling errors, so this change is
specifically about the exit status.)

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1794518
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220511122345.14208-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2022-05-11 17:02:17 +02:00
Laszlo Ersek
5345d42635 daemon/selinux-relabel: generalize setfiles_has_m_option()
Allow the caller to pass in the option to check for, and to store the
result in a (usually static) variable of their choice.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1794518
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220511122345.14208-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2022-05-11 17:01:57 +02:00
Laszlo Ersek
4864d21cb8 guestfs_readdir(): minimize the number of send_file_write() calls
In guestfs_readdir(), the daemon currently sends each XDR-encoded
"guestfs_int_dirent" to the library with a separate send_file_write()
call.

Determine the largest encoded size (from the longest filename that a
"guestfs_int_dirent" could carry, from readdir()'s "struct dirent"), and
batch up the XDR encodings until the next encoding might not fit in
GUESTFS_MAX_CHUNK_SIZE. Call send_file_write() only then.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1674392
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220502085601.15012-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2022-05-03 10:54:00 +02:00
Laszlo Ersek
45b7f1736b guestfs_readdir(): rewrite with FileOut transfer, to lift protocol limit
Currently the guestfs_readdir() API can not list long directories, due to
it sending back the whole directory listing in a single guestfs protocol
response, which is limited to GUESTFS_MESSAGE_MAX (approx. 4MB) in size.

Introduce the "internal_readdir" action, for transferring the directory
listing from the daemon to the library through a FileOut parameter.
Rewrite guestfs_readdir() on top of this new internal function:

- The new "internal_readdir" action is a daemon action. Do not repurpose
  the "readdir" proc_nr (138) for "internal_readdir", as some distros ship
  the binary appliance to their users, and reusing the proc_nr could
  create a mismatch between library & appliance with obscure symptoms.
  Replace the old proc_nr (138) with a new proc_nr (511) instead; a
  mismatch would then produce a clear error message. Assume the new action
  will first be released in libguestfs-1.48.2.

- Turn "readdir" from a daemon action into a non-daemon one. Call the
  daemon action guestfs_internal_readdir() manually, receive the FileOut
  parameter into a temp file, then deserialize the dirents array from the
  temp file.

This patch sneakily fixes an independent bug, too. In the pre-patch
do_readdir() function [daemon/readdir.c], when readdir() returns NULL, we
don't distinguish "end of directory stream" from "readdir() failed". This
rewrite fixes this problem -- I didn't see much value separating out the
fix for the original do_readdir().

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1674392
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220502085601.15012-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
2022-05-03 10:53:48 +02:00
Richard W.M. Jones
bc96e0b7d7 daemon: Fix compilation with older rpm that lacks RPMVSF_MASK_NOSIGNATURES
On RHEL 7 (rpm-devel-4.11.3-45.el7.x86_64):

rpm-c.c: In function ‘guestfs_int_daemon_rpm_start_iterator’:
rpm-c.c:97:44: error: ‘RPMVSF_MASK_NOSIGNATURES’ undeclared (first use in this function)
   rpmtsSetVSFlags (ts, rpmtsVSFlags (ts) | RPMVSF_MASK_NOSIGNATURES);
                                            ^
rpm-c.c:97:44: note: each undeclared identifier is reported only once for each function it appears in

Fixes: commit aa6f8038f8
2022-04-25 16:40:12 +01:00