Commit Graph

1329 Commits

Author SHA1 Message Date
Richard W.M. Jones
e0a1106103 daemon: Don't return bogus failure from readdir.
This was returning "readdir: Invalid argument" which is actually
impossible (readdir(3) cannot fail with EINVAL).  It turns out that
the problem is just errno from some other place leaking out.
2021-03-22 14:56:10 +00:00
Richard W.M. Jones
9108ad152d daemon/btrfs.c: Ignore mkfs.btrfs allocstart option.
This was deprecated in btrfs 4.14.1 and recently removed (see
btrfs-progs commit 4bd94dba8a "btrfs-progs: mkfs: remove alloc start
options and docs").  If the option is set simply ignore it.
2021-03-22 14:26:57 +00:00
Richard W.M. Jones
82493579f3 Port libguestfs to use pcre2 instead of pcre.
https://bugzilla.redhat.com/show_bug.cgi?id=1938982
2021-03-16 11:24:37 +00:00
Richard W.M. Jones
fbf573d2c9 daemon/daemon-c.c: Fix whitespace. 2021-03-16 11:24:37 +00:00
Richard W.M. Jones
733d2182b6 Remove the tools.
These have now moved to a new repository.  Provisionally it is here:

https://github.com/rwmjones/guestfs-tools/

but this is not the final location, as it will eventually be hosted on
gitlab.com.

The tarballs are here:

https://download.libguestfs.org/guestfs-tools/
2021-03-11 13:58:41 +00:00
Richard W.M. Jones
21cd97732c daemon: lvm: Use lvcreate --yes to avoid interactive prompts.
See https://bugzilla.redhat.com/show_bug.cgi?id=1930996#c1

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1930996
2021-02-22 11:04:15 +00:00
Richard W.M. Jones
001c1dc09f daemon/tar.c: Avoid bogus GCC analyzer warning.
See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99196
2021-02-22 10:38:19 +00:00
Richard W.M. Jones
4af1c631a2 daemon/command.c daemon/debug.c df/main.c: Ignore bogus GCC analyzer warnings
See upstream bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99193
2021-02-22 10:37:49 +00:00
Richard W.M. Jones
4bbbf03b8b Ignore completely bogus GCC 11 warnings.
Various varieties of this:

           |   45 |   tempfile = strdup ("/tmp/luksXXXXXX");
           |      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~
           |      |              |
           |      |              (19) this call could return NULL
           |   46 |   if (!tempfile) {
           |      |      ~
           |      |      |
           |      |      (20) following 'false' branch (when 'tempfile' is non-NULL)...
           |......
           |   51 |   fd = mkstemp (tempfile);
           |      |   ~~   ~~~~~~~~~~~~~~~~~~
           |      |   |    |
           |      |   |    (22) argument 1 ('tempfile') from (19) could be NULL where non-null expected
           |      |   (21) ...to here
2021-01-05 10:31:00 +00:00
Richard W.M. Jones
6d0ab14b56 tar-in: Add workaround because tar doesn't restore capabilities (RHBZ#1384241).
Current GNU tar does not restore all extended attributes.  In
particular only user.* capabilities are restored (although all
are saved in the tarball).

To restore capabilities, SELinux security attributes, and other things
we need to use --xattrs-include=*

For further information on the tar bug, see:
https://bugzilla.redhat.com/show_bug.cgi?id=771927
2020-12-11 10:23:21 +00:00
Richard W.M. Jones
5631106a73 daemon: lvm_canonical_lv_name: Return EINVAL if called with non-LV.
Previously callers were unable to distinguish a regular error (like an
I/O error) from the case where you call this API on something which is
valid but not a logical volume.  Set errno to a known value in this
case.
2020-10-12 10:44:29 +01:00
Richard W.M. Jones
86577ee388 daemon: Search device-mapper devices for list-filesystems API.
In case any bare filesystems were decrypted using cryptsetup-open,
they would appear as /dev/mapper/name devices.  Since list-filesystems
did not consider those when searching for filesystems, the unencrypted
filesystems would not be returned.

Note that previously this worked for LUKS because the common case
(eg. for Fedora) was that whole devices were encrypted and thoes
devices contained LVs, so luks-open + vgactivate would activate the
LVs which would then be found by list-filesystems.  For Windows
BitLocker, the common case seems to be that each separate NTFS
filesystem is contained in a separate BitLocker wrapper.
2020-10-12 10:44:29 +01:00
Richard W.M. Jones
79f3d451a8 daemon: Reimplement list_dm_devices API in OCaml.
Simple refactoring.  The only annoying point is requiring an extra
module because of OCaml module dependency restrictions.
2020-10-12 10:44:29 +01:00
Richard W.M. Jones
41cbc89330 daemon: Ignore BitLocker disks in list-filesystems API. 2020-10-12 10:44:29 +01:00
Richard W.M. Jones
6e870a8e43 daemon: Rewrite list-filesystems implementation imperatively.
Simple refactoring to make the code clearer, should have no other
effect.
2020-10-12 10:44:29 +01:00
Richard W.M. Jones
c456ea0332 New APIs: cryptsetup-open and cryptsetup-close.
This commit deprecates luks-open/luks-open-ro/luks-close for the more
generic sounding names cryptsetup-open/cryptsetup-close, which also
correspond directly to the cryptsetup commands.

The optional cryptsetup-open readonly flag is used to replace the
functionality of luks-open-ro.

The optional cryptsetup-open crypttype parameter can be used to select
the type (corresponding to cryptsetup open --type), which allows us to
open BitLocker-encrypted disks with no extra effort.  As a convenience
the crypttype parameter may be omitted, and libguestfs will use a
heuristic (based on vfs-type output) to try to determine the correct
type to use.

The deprecated functions and the new functions are all (re-)written in
OCaml.

There is no new test here, unfortunately.  It would be nice to test
Windows BitLocker support in this new API, however the Linux tools do
not support creating BitLocker disks, and while it is possible to
create one under Windows, the smallest compressed disk I could create
is 37M because of a mixture of the minimum support size for BitLocker
disks and the fact that encrypted parts of NTFS cannot be compressed.

Also synchronise with common module.
2020-10-12 10:44:08 +01:00
Richard W.M. Jones
0b8ef5a98d daemon/debug.c: Use __builtin_trap to cause segfault.
I couldn't get GCC 10.1 to ignore this warning any longer, possibly
because I am using LTO.  In any case dereferencing a pointer is
undefined behaviour, so let's use GCC's __builtin_trap() function
instead (also supported by clang).

debug.c: In function 'debug_segv':
debug.c:1002:8: error: null pointer dereference [-Werror=null-dereference]
 1002 |   *ptr = 1;
      |        ^
2020-08-01 07:27:17 +01:00
Richard W.M. Jones
eb78e990ac daemon, lib: Replace deprecated security_context_t with char *.
This gives deprecation warnings.  It always was simply a char *, and
the recommendation upstream is to replace uses with char *:

9eb9c93275
2020-07-30 13:58:35 +01:00
Geoff Toole
ef2761eaa0 build: Fix linking of OCaml components when srcdir != builddir
ocaml-link.sh is a generated file, so run it from the build directory.
Remove it from EXTRA_DIST and also adjust docs/guestfs-hacking.pod
accordingly.
2020-04-20 09:31:35 +01:00
Richard W.M. Jones
c2c11382bb daemon: xattr: Filter out user.WofCompressedData from xattrs (RHBZ#1811539).
See comment in code for justification.

Thanks: Yongkui Guo for finding the bug.
2020-03-30 10:40:13 +01:00
Richard W.M. Jones
af8ed266a2 daemon: Add filter_list utility function.
For filtering lists of strings based on a predicate.
2020-03-30 10:40:13 +01:00
Richard W.M. Jones
5c175fe732 daemon: xattr: Refactor code which splits attr names from the kernel.
The kernel returns xattr names in a slightly peculiar format.  We
parsed this format several times in the code.  Refactor this parsing
so we only do it in one place.
2020-03-30 10:40:13 +01:00
Richard W.M. Jones
0e17236d7d Update copyright dates to 2020. 2020-03-06 19:32:32 +00:00
Richard W.M. Jones
a06262e199 daemon: Print device names when they are translated.
This helps to debug problems with the new device name translation
code.  We can think about removing this later when the code is known
to work well.
2020-03-06 19:03:03 +00:00
Richard W.M. Jones
bca9b94fc5 daemon: Translate device names if Linux device ordering is unstable (RHBZ#1804207).
Linux from around 5.6 now enumerates individual disks in any order
(whereas previously it enumerated only drivers in parallel).  This
means that /dev/sdX ordering is no longer stable - in particular we
cannot be sure that /dev/sda inside the guest is the first disk that
was attached to the appliance, /dev/sdb the second disk and so on.

However we can still use SCSI PCI device numbering as found in
/dev/disk/by-path.  Use this to translate device names in and out of
the appliance.

Thanks: Vitaly Kuznetsov, Paolo Bonzini, Dan Berrangé.
2020-03-06 19:03:03 +00:00
Richard W.M. Jones
6ff1055f40 daemon: 9p: modprobe 9pnet_virtio before 9pfs operations.
Recent Linux kernels seem to require this, for unclear reasons.
2020-03-06 14:50:37 +00:00
Richard W.M. Jones
3cea2cfe04 lib: Move guestfs_device_index impl from daemon to library.
This function doesn't work reliably with the proposed change to device
name translation.  The reason is that strings returned by
Devsparts.list_devices contained translated names, so their indexes
did not correspond to the untranslated names used outside the
appliance..

We can avoid this and make the function much simpler and faster by
implementing it on the library side instead.
2020-03-05 13:18:27 +00:00
Pino Toscano
b3ef101a0f daemon: fix/enhance error reporting of Augeas exceptions
The current code was broken, as the field 1 of the exception value is
the error code (int), not an error string, and thus it would have
crashed.  This did not happen in practice, as all the usage of
ocaml-augeas were only in the inspection code with ad-hoc exception
catching blocks.

Other than fixing the aforementioned issue, enhance the error reporting
to be as close as possible to what the current AUGEAS_ERROR() macro
does: error message, error minor message (if available), error details
(if available).
2020-01-27 14:53:35 +01:00
Pino Toscano
a420e535d5 daemon: reorder internal static libs to fix linking
Move the interal static libraries as the last items in the list of
libraries of guestfsd, to make sure their symbols are used for all the
other libraries.  This is because GCC resolves the symbols looking at
the arguments from the beginning to the end of the command line.
This currently does not cause failures, however it "just works" because
of the tricky situation set up.

The situation is the following:

1) common/utils contains few utility sources: one of them is utils.c,
which contains various functions -- for example
guestfs_int_free_string_list and guestfs_int_drive_name --, it is built
as utils.o, and bundled in the static library libutils.a

2) common/mlutils builds a OCaml library with bindings for some utility
functions in libutils.a, in particular guestfs_int_drive_name (but not
guestfs_int_free_string_list); there are two versions of this library,
one OCaml library (dllmlcutils.so) that links with libutils.a, and one
static library (libmlcutils.a), which cannot specify the libraries it
links to (as it is static)

3) when the daemon is linked, the command line was the following
(simplified):
  $ gcc [...] -o guestfsd guestfsd-9p.o other_daemon_object.o [...] \
      ../common/utils/.libs/libutils.a [...] -lmlcutils [...]
Some of the objects of the daemon itself use
guestfs_int_free_string_list, and thus the compiler opens libutils.a
(it is after the objects in the command line) and picks utils.o, which
contains also guestfs_int_drive_name (not used directly in the daemon);
when linking later on with libmlcutils.a, the symbols for this static
library (like guestfs_int_drive_name) are already resolved, and thus
all the symbols are resolved, and the linking succeeds

This fragile situation can be easily broken by moving e.g.
guestfs_int_drive_name out of common/utils/utils.c to a new source (say
utils2.c) still built as part of libutils.a: since nothing before
-lmlcutils actually needs to pick utils2.o from libutils.a for symbols,
then GCC will not be able to resolve all the symbols in libmlcutils.a.

As solution, move libutils.a (and other internal static libraries) as
last libraries to link guestfsd to: this way, GCC knows where to find
all the symbols needed by all the objects and libraries specified in
the command line.
2019-12-19 13:10:41 +01:00
Pino Toscano
fb7e21be96 build: switch embedded copy of ocaml-augeas
Use the newer copy shipped locally as bundled, instead of the one in
the common submodule, as the latter copy will go away soon.
2019-12-16 18:33:49 +01:00
Pino Toscano
323909d92e build: stop shipping files generated by configure
They will be generated by configure.
2019-12-12 18:01:32 +01:00
Pino Toscano
206ce8bbf1 New API: luks_uuid
Return the UUID of a LUKS device.
2019-11-29 12:04:55 +01:00
Pino Toscano
72d83cc6eb build: remove unused gnulib modules
Remove gnulib modules that provide stuff clearly not used within
libguestfs (library, daemon, and C tools).  Among directly and
indirectly modules used previous (and now no more), they are:

  cycle-check
  d-ino
  dev-ino
  dup3
  dup3-tests
  fcntl-safer
  fcntl-safer-tests
  fdopendir
  fdopendir-tests
  filevercmp
  filevercmp-tests
  ftell
  ftell-tests
  ftello
  ftello-tests
  fts
  getaddrinfo
  getaddrinfo-tests
  getcwd
  getcwd-tests
  gnu-make
  hostent
  i-ring
  i-ring-tests
  iconv
  iconv-tests
  inet_ntop
  inet_ntop-tests
  isatty
  isatty-tests
  openat-safer
  openat-safer-tests
  opendirat
  ptsname_r
  ptsname_r-tests
  read-file
  read-file-tests
  rewinddir
  servent
  ttyname_r
  ttyname_r-tests
  xgetcwd

Some of the removed modules are still used pulled indirectly as
dependency of other modules.  There should be no behaviour change on
recent Linux distros, although older distros were not tested (adding
a module back is easy, anyway).

Remove accordingly unused automake variables, and ignored files.
2019-11-28 13:09:21 +01:00
Pino Toscano
86d5ddc296 daemon: remove unused include 2019-11-28 13:09:21 +01:00
Pino Toscano
b87e20ccf1 daemon: switch from read_file to read_whole_file
Since we have already an helper to read a file, use it instead of the
gnulib function.
2019-11-28 13:09:21 +01:00
Pino Toscano
73a58394a9 daemon: move read_whole_file to common utils
Move the read_whole_file function to the common utilities of the daemon,
so other parts can use it.  For this purpose, add an out parameter to
get the amount of bytes read.

Except from the parameter addition, this should be just refactoring.
2019-11-28 13:09:21 +01:00
Richard W.M. Jones
0177552375 daemon: btrfs: Fix parsing for new output from btrfs scrub.
The format changed at some point breaking our existing parsing code.
Typical example of the new format is below.

UUID:             b8604449-c7b5-4d3b-9fad-56114e8594f5
Scrub started:    Wed Oct  2 12:54:06 2019
Status:           finished
Duration:         0:00:00
\tdata_extents_scrubbed: 0
\ttree_extents_scrubbed: 16
\tdata_bytes_scrubbed: 0
\ttree_bytes_scrubbed: 262144
\tread_errors: 0
\tcsum_errors: 0
\tverify_errors: 0
\tno_csum: 0
\tcsum_discards: 0
\tsuper_errors: 0
\tmalloc_errors: 0
\tuncorrectable_errors: 0
\tunverified_errors: 0
\tcorrected_errors: 0
\tlast_physical: 253493248
2019-10-02 14:29:35 +01:00
Pino Toscano
8eb696f827 appliance: remove custom Shadow augeas lens
Now that augeas 1.2.0 is required, assume the Shadow lens is available
there, and thus drop the local copy.
2019-05-30 09:12:32 +02:00
Pino Toscano
0cafcc0e88 build: build C sources using OCaml API with CAML_NAME_SPACE
This way no non-namespaced OCaml C symbols are used, reducing the risk
of clashes with other code.

The only exception is ocaml-augeas, which does not build with
CAML_NAME_SPACE; it will be fixed upstream, and it affects only
ocaml-augeas itself.
2019-05-28 11:39:20 +02:00
Denis Plotnikov
4cfc071a84 daemon: drop error message check in do_part_expand_gpt
part-expand-gpt takes extreme cautions and doesn't proceed to writing
to the disk if the preliminary dry run of sgdisk has generated any
warnings on stdout.

This blocks the use of part-expand-gpt on disk shrink (with disk
resize being the main usecase for part-expand-gpt), because sgdisk dry
run produces a warning in that case.

So remove the excessive safety check, and leave it up to the caller.

Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
Reviewed-by: Roman Kagan <rkagan@virtuozzo.com>
2019-04-16 09:32:02 +01:00
Pino Toscano
aee4a96ce2 inspect: fully detect Arch Linux from os-release
Consider Arch Linux as rolling distribution, so it is recognized using
/etc/os-release.

The end result does not change, although this makes Arch Linux inspected
using os-release only, instead of getting inspection details mixed from
both os-release and lsb-release.
2019-04-04 10:25:03 +02:00
Pino Toscano
c0155f5823 inspect: detect Gentoo from os-release
Add "gentoo" as recognized ID in /etc/os-release, and consider it as
rolling distribution (so without VERSION_ID in os-release).

This avoids using a not-useful version read from /etc/gentoo-release,
e.g. "Gentoo Base System release 2.6".
2019-04-04 10:25:03 +02:00
Pino Toscano
a6db759a72 inspect: factorize list of rolling distros
Use a static list of rolling distros, so it is easier to handle them
differently; use this list for handling the lack of VERSION_ID in
os-release files.

This is just refactoring, no behaviour changes.
2019-04-04 10:25:03 +02:00
Bernhard Rosenkränzer
a4ef6716b4 Add OpenMandriva support as guest and host (RHBZ#1694268). 2019-04-03 13:08:08 +01:00
Pino Toscano
cf6b527824 inspect: fix inspection of partition-less devices (RHBZ#1661038)
When parsing "xdev"-kind devices, do not assume that the partition
number can be converted to integer: re_xdev accepts an empty part of the
partition number, so just handle as it is, as string.

This fixes a regression due to the conversion of the inspection code to
OCaml, as the old C version did not have this issue.
2019-01-14 17:29:13 +01:00
Richard W.M. Jones
05d4fcb64d Update copyright dates for 2019.
This command run over the source:

perl -pi.bak -e 's/(20[01][0-9])-2018/$1-2019/g' `git ls-files`
2019-01-08 11:58:30 +00:00
Pino Toscano
28bd06227b inspect: handle os-release "opensuse-tumbleweed" as opensuse
Followup of commit 70407cd622 for openSUSE
Thumbleweed.
2018-11-30 13:44:19 +01:00
Martin Kletzander
d3478036a8 Fix include for xattr.h
The proper file that should be included is `sys/xattr.h` as that comes from
`glibc` and not `attr/xattr.h` which ships with the `attr` utility.

New enough `attr` utility (at least 2.4.48 in my case) even includes a #warning
in `attr/xattr.h` for projects that still have this mistake in the code.
2018-11-23 08:34:16 +00:00
Richard W.M. Jones
70407cd622 inspection: Parse os-release "opensuse-leap" as opensuse (RHBZ#1634248). 2018-10-01 11:17:13 +01:00
Richard W.M. Jones
34c23403c5 tools: Ensure CFLAGS and LDFLAGS are passed to all OCaml binaries (RHBZ#1624130).
After this commit, all annocheck errors are fixed except for:

  Hardened: virt-get-kernel: MAYB: Gaps were detected in the annobin coverage.  Run with -v to list.

After discussion with the annocheck maintainers this gap in coverage
(which corresponds to the OCaml runtime) seems to be caused either by
the runtime not being linked with the right flags, or might be a bug
in annocheck itself.  In any case it's not something that can be
resolved within the scope of libguestfs.
2018-09-21 10:16:34 +01:00