1488 Commits

Author SHA1 Message Date
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
Nikolay Ivanets
eaa9c8cbc6 daemon: consider /etc/mdadm/mdadm.conf while inspecting mountpoints.
Inspection code checks /etc/mdadm.conf to map MD device paths listed in
mdadm.conf to MD device paths in the guestfs appliance. However on some
operating systems (e.g. Ubuntu) mdadm.conf has alternative location:
/etc/mdadm/mdadm.conf.

This patch consider an alternative location of mdadm.conf as well.
2018-09-13 09:17:21 +01:00
Pino Toscano
a3e8871705 daemon: utils: add a couple of checks for split_device_partition
Mostly to check the behaviour of the function with cases like in
RHBZ#1611690.
2018-08-09 12:14:04 +02:00
Pino Toscano
31ee088812 btrfs_balance_status: delay allocation of 'ret'
Allocate 'ret' as late as possible, so there is no risk that early
returns will leak it.
2018-08-06 15:36:46 +02:00
Pino Toscano
67c36779c3 daemon: inspect: ignore fstab devs that cannot be resolved (RHBZ#1608131)
If the /etc/fstab of a guest contains devices specified with UUID or
LABEL, then the new OCaml inspection code will report the findfs failure
as general failure of the inspection.  OTOH, the old C inspection code
simply ignored all the devices that cannot be resolved.

Hence, restore the old behaviour by ignoring unresolvable devices.
2018-07-27 15:07:00 +02:00
Richard W.M. Jones
55dfcb2211 New API: lvm_scan, deprecate vgscan (RHBZ#1602353).
The old vgscan API literally ran vgscan.  When we switched to using
lvmetad (in commit dd162d2cd5) this
stopped working because lvmetad now ignores plain *scan commands
without the --cache option.

We documented that vgscan would rescan PVs, VGs and LVs, but without
activating them.

I have introduced a new API (lvm_scan) which scans or rescans PVs, VGs
and LVs.  It has an optional activate parameter allowing activation of
any new LVs that are found.

With lvmetad this nicely maps to the single command:

 pvscan --cache [--activate ay]
2018-07-26 12:02:59 +01:00
Richard W.M. Jones
83fb657bec Revert "lvm: do not pass --cache to vgscan"
This reverts commit 19b0ae6c65.
2018-07-26 12:02:59 +01:00
Richard W.M. Jones
2add3c6995 utils: Factor out hexdump code used by --enable-packet-dump.
Factor out the common code used to hexdump the protocol when
./configure --enable-packet-dump is used.

It's not quite a straight refactor because I had to fix some
signedness bugs in the code which were not revealed before because
this code is usually disabled.
2018-06-04 05:36:56 -04:00
Mykola Ivanets
b699111e04 daemon: list-filesystems: Filter out MBR extended partitions.
Extended MBR partitions cannot hold filesystems - filter them out.

RWMJ:

* Simplify is_mbr_extended function.

* Fix regression test rhbz1285847:

  The test assumed that list-filesystems would return an extended MBR
  partition (as "unknown").  However such partitions only contain
  logical partitions inside them, not filesystems.

* Some minor whitespace changes.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
0a2f276be0 daemon: list-filesystems: Filter out Microsoft Reserved and Windows Snapshot partitions.
Filter out Microsoft Reserved Partition and Windows Snapshot Partition.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
16192ad953 daemon: list-filesystems: Change the way we filter out LDM partitions.
1. Now we use GPT partition type to filter out LDM partitions.
2. We also check for filesystems on LDM volumes because LDM partitions
doesn't contain filesystems (list_ldm_partitions is not called anymore).
3. Obvious repetitive comments are moved to a function description.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
b316a33264 daemon: list-filesystems: Ignore partitioned MD devices.
Ignore partitioned MD devices the same way we ignore regular partitioned
devices because they cannot contain filesystems as well.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
55abc820cd daemon: Changing the way that we detect if a device contains partitions.
Instead of using part_to_dev to find such devices we open the device's
directory under /sys/block/<dev_name> and look for entries starting with
<dev_name>, eg. /sys/block/sda/sda1.
2018-06-01 15:09:34 +01:00
Mykola Ivanets
7b4d13626f daemon: inspect: better handling windows drive mapping.
I saw several Windows disk images which contains strange registry entry
for mapped drives:

"\\DosDevices\\Y:"=hex(3):00,00,00,00,00,00,00,00,00,00,00,00

Which is decoded something like diskID = 0x0, partition starts at 0
bytes offset from the start of the disk.  In addition to a Windows disk
image, I have attached dummy disk and made xfs file system on a whole
device without partitioning it.  I mount xfs file system to a "/" and
then mkdir and mount other found file systems inside (/fs1, /fs2 etc.).

When we decode drive mappings we are looking for a disk with ID 0x0 (it
is 4 bytes somewhere LBA0).  It is appeared that dummy non-partitioned
disk with xfs file system has zeros by offset where diskID is expected
to be).  So the disk is considered as a candidate to search for
partition at offset 0. part-list command (and "parted" which is used
under the hood) reports there is 1 partition on "dummy" disk which
starts exactly at offset 0.  And thus dummy device name and partition
number are simply concatenated together and corresponding drive mapping
is returned: Y => /dev/sdX1.  But /dev/sdX1 is not existing block
device.

No matter either it is a bug in "parted" (or it works this way
by-design), let's protect ourself from this situation: in addition we
look for msdos partition table on a disk before making any further
assumptions.
2018-06-01 15:09:34 +01:00
Richard W.M. Jones
dd162d2cd5 daemon: Move lvmetad to early in the appliance boot process.
When the daemon starts up it creates a fresh (empty) LVM configuration
and starts up lvmetad (which depends on the LVM configuration).

However this appears to cause problems: Some types of PV seem to
require lvmetad and don't work without it
(https://bugzilla.redhat.com/show_bug.cgi?id=1581810).  If we don't
start lvmetad earlier, the device nodes are not created.

Therefore move the whole initialization step into appliance/init.

Two further changes had to be made:

Now we are using lvmetad all the time, using vgchange is incorrect.
With lvmetad activated early we must use ‘pvscan --cache --activate ay’
to scan all disks for PVs and activate any VGs on them (although the
documentation is complex, confusing and contradictory so I'm not
completely sure about this).

The ‘lvm_system_dir’ local variable in ‘daemon/lvm-filter.c’
previously contained the path of the directory above $LVM_SYSTEM_DIR
(eg. $LVM_SYSTEM_DIR = "/etc/lvm", lvm_system_dir = "/etc").  As this
was highly confusing, I have changed it so the local variable and the
environment variable have identical contents.  This involved removing
the ‘lvm/’ component from a couple of paths since it is now included
in the local variable.
2018-05-29 20:38:40 +01:00
Adam Robinson
431d8c8c1e macOS: Include <rpc/types.h> before <rpc/xdr.h>.
The ordering of includes is required on this platform.
2018-05-15 11:15:54 +01:00
Pino Toscano
3151d5e927 daemon: tweak regexp for file type detection (RHBZ#1575640)
Newer versions of file slightly changed the output, removing the comma
between the type, and the architecture string.

Tweak the regular expression so:
- the comma is optional, but if missing then only the architecture
  string will follow
- the architecture string has no commas
2018-05-07 17:06:11 +02:00
Nikolay Ivanets
994ca1f8eb daemon: Reimplement 'part_get_mbr_part_type' API in OCaml.
Instead of parsing 'parted' output OCaml implementation relies on the following facts:

1. MBR partition table can hold up to 4 "primary" partitions.
2. Partition with number greater then 4 is "logical" partition.
3. Partition with number less then or equal to 4 with MBR ID 0x05 or 0x0f is "extended" partition (http://thestarman.pcministry.com/asm/mbr/PartTypes.htm; https://en.wikipedia.org/wiki/Partition_type) or "primary" otherwise.
2018-05-02 12:07:16 +01:00
Pino Toscano
9667587366 daemon: simplify string allocation
When creating an helper string for do_aug_match(), use a simpler
asprintf() with manual free(), since the code block is small enough.

This slightly helps static code analyzers.
2018-05-01 17:26:16 +01:00
Pino Toscano
fced132718 daemon: upload: fix fd leak on lseek failure
Make sure to not leak the file descriptor in the upload() function, in
case lseek() fails.
2018-05-01 17:26:16 +01:00
Pino Toscano
d00e860ef0 New API: f2fs_expand
Expose the resize.f2fs utility from f2fs-tools, to expand a f2fs
filesystem.
2018-04-19 11:30:29 +02:00
Hilko Bengen
802c5d2055 Fix out-of-tree builds of OCaml components
- Add $(srcdir), $(builddir) to Makefiles where required
- Post-process ocamldep output
- generate ocaml/.depends
2018-04-12 11:43:56 +02:00
Pino Toscano
e655676157 daemon: autogenerate OCaml interfaces
Add a way to generate OCaml interfaces for all the modules in the
daemon that implement APIs: this makes sure that for them the
interface of each function matches the actual API specified in the
generator.
2018-04-10 12:55:37 +02:00
Pino Toscano
6c13d2356e daemon: move Mount.umount_all to new Mount_utils module
This way the Mount module contains only the OCaml implementations of
mount-related daemon APIs.

This is simple refactoring, with no functional changes.
2018-04-10 12:12:10 +02:00
Pino Toscano
2bdc7b83ce daemon: move Lvm.lv_canonical to new Lvm_utils module
This way the Lvm module contains only the OCaml implementations of LVM
daemon APIs.

This is simple refactoring, with no functional changes.
2018-04-10 12:12:09 +02:00
Pino Toscano
188e995d32 daemon: use the structs from the Structs module
No need to redeclare them again in few modules, just use them from the
Structs module.
2018-04-10 12:12:09 +02:00
Pino Toscano
a43bdb9379 daemon: directly use Optgroups
Avoid extra module variables, and just use Optgroups directly.
2018-04-10 12:12:09 +02:00
Richard W.M. Jones
07ead43cbb daemon: Fix type signature of mount_vfs (RHBZ#1564983).
Reported-by: Yongkui Guo.

Fixes commit 82bbd9c8a5.
2018-04-09 13:31:40 +01:00
Pino Toscano
1c996bf314 daemon: tsk: handle new enum values in sleuthkit 4.5
Resort to a version check for them, as they do not exist in older
versions.
2018-02-19 17:14:18 +01:00
Pino Toscano
535a4471f3 inspect: use check_tests also for detecting Hurd
Even though the list of checks is very short, at least this migrates
from imperative checks to a "declarative" one.

There should be no behaviour change, other than using os-release if it
contains all the needed information.
2018-02-14 17:19:52 +01:00
Pino Toscano
1dd11d2276 inspect: recognize the Kali Linux distribution (RHBZ#1544227)
Read the information from os-release, and make it behave like a
Debian distribution (i.e. using dpkg, and apt).
2018-02-12 14:32:19 +01:00
Pino Toscano
bd1c5c9f4d Switch from YAJL to Jansson
While YAJL mostly works fine, it did not see any active development in
the last 3 years.  OTOH, Jansson is another JSON C implementation, with
a very liberal license, and a much nicer API.

Hence, switch all of libguestfs from YAJL to Jansson:
- configure checks, and buildsystem in general
- packages pulled in the appliance
- actual implementations
- contrib scripts
- documentation

This also makes use of the better APIs available (e.g. json_object_get,
json_array_foreach, and json_object_foreach).  This does not change the
API of our OCaml Yajl module.
2018-02-12 11:24:06 +01:00
Daniel P. Berrangé
3c7bbf97e2 daemon: add inspector support for MS-DOS distro
An installation of MS-DOS has various files in a /DOS directory,
which COMMAND.COM looking like a reasonable signal that its MS-DOS
or a very close relative there-of.

This is validated with an MS-DOS 6.22 install.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-02-07 18:18:27 +00:00
Pino Toscano
82fbf294fd daemon: build also without Hivex.OPEN_UNSAFE (RHBZ#1493048)
Do a configure check for the OPEN_UNSAFE flag in the OCaml binding of
Hivex, using it only when available.  This makes it possible to use
hivex < 1.3.14 to build libguestfs (the daemon, actually).

Amend the building documentation accordingly, bringing the minimum
version of hivex back as it was before
commit 64f49df747.
2018-02-06 17:27:23 +01:00
Cédric Bosdonnat
c5fdc4f764 New APIs: part_set_gpt_attributes and part_get_gpt_attributes
Allow reading and setting the GPT partition attribute flags.
2018-01-16 13:03:39 +00:00
Cédric Bosdonnat
5f26f70262 daemon: make sgdisk_info_extract_uuid_field more generic
Rename the sgdisk_info_extract_uuid_field to
sgdisk_info_extract_field in order to reuse it for other field types.
Just like its C ancestor, it now needs an extractor function to be
passed as parameter.
2018-01-16 12:51:46 +00:00
Richard W.M. Jones
4ac3be3d04 daemon: tests: Compile tests with compiler warnings.
And fix the problems.
2018-01-09 12:17:53 +00:00
Richard W.M. Jones
04031269f6 tests: Further instances of $(RPC_CFLAGS). 2018-01-09 12:17:53 +00:00
Richard W.M. Jones
212762c593 Update copyright dates for 2018.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2017/$1-2018/g' `git ls-files`
2018-01-04 15:30:10 +00:00
Richard W.M. Jones
a93a06dc59 daemon: Rewrite inspection code using ‘return’ statements.
When rewriting this, I revisited the original C code and changed the
OCaml code so it's now reasonably similar to the original.
2017-12-08 16:22:14 +00:00
Richard W.M. Jones
0eb23230fa common/mlstdutils: Move list functions into extended List module.
However some existing functions had names which shadowed existing
functions in the List module, so I had to rename them:

  assoc -> List.assoc_lbl
  append -> List.push_back_list
  prepend -> List.push_front_list

This is an extension of the previous commit.
2017-12-08 16:22:11 +00:00
Richard W.M. Jones
3ef6794b09 common/mlstdutils: Add with_openfile function.
This safe wrapper around Unix.openfile ensures that exceptions
escaping cannot leave unclosed files.

There are only a few places in the code where this wrapper can be used
currently.  There are other occurences of Unix.openfile but they are
not suitable for replacement.
2017-11-16 12:32:58 +00:00