Commit Graph

238 Commits

Author SHA1 Message Date
Richard W.M. Jones
75abec1f70 include: Move lib/guestfs.h to include/guestfs.h
This brings libguestfs into line with other projects which have a
separate include/ directory for the public header.

It's also the case that <guestfs.h> has never particularly belonged in
the lib/ subdirectory.  Some tools add -Ilib/ but they only need
<guestfs.h> and not any other headers from that directory, and
separating out the public header allows us to clean those up.  This is
certainly the case for examples, and some language bindings and some
tests.

In future I'm hopeful we can use this as the basis to tease out other
dependencies, as a prelude to separating them out from the repo.
2020-09-21 18:38:28 +01:00
Richard W.M. Jones
5b29fba5b2 docs: Move shared POD for --keys-from-stdin to common code.
No functional change.
2020-07-30 14:06:45 +01:00
Pino Toscano
b25e3495f5 customize: port do_run to run_in_guest_command
Make use of the new helper function in Tools_utils to run commands in
the guest.
2020-05-07 14:04:56 +02: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
0e17236d7d Update copyright dates to 2020. 2020-03-06 19:32:32 +00:00
Richard W.M. Jones
815eab8a66 tests: Use explicit backing format for all backing disks.
Libvirt 6.0 now requires that every disk in the backing chain has an
explicit backing format.  For example this will be rejected by
libvirt:

  qemu-img create -f qcow2 -b backing-disk disk.qcow2

with the error:

  Original error from libvirt: Requested operation is not valid:
  format of backing image 'backing-disk' of image 'disk.qcow2' was not
  specified in the image metadata (See
  https://libvirt.org/kbase/backing_chains.html for troubleshooting)
  [code=55 int1=-1]

Instead you have to use the -F option to specify the format, eg:

  qemu-img create -f qcow2 -b backing-disk -F raw disk.qcow2
2020-02-06 16:06:19 +00:00
Pino Toscano
78a18b20e1 tests: fix srcdir references
Make sure to properly reference to files in the source directory.
2019-12-17 15:33:21 +01:00
Pino Toscano
c37673eaea tests: fix podcheck tests
Pass to the various podcheck invocations the paths with POD files that
are included.

Followup of commit 46e59e9535.
2019-12-11 14:24:01 +01:00
Richard W.M. Jones
8ba0457e9e options: Update documentation for --key SELECTOR.
Use the common/options/key-option.pod fragment to document the --key
option and selector instead of duplicating the same documentation
everywhere.
2019-11-28 13:28:49 +00:00
Richard W.M. Jones
435b70f564 customize, v2v: Remove existing file before copying.
The generator creates these files with 0444 mode, so they cannot be
overwritten by a simple ‘cp’ command.  We could use ‘cp -f’ or ‘rm -f’.

Fixes commit 15394cb4dd.
2019-10-15 13:34:39 +01:00
Richard W.M. Jones
20c2dfbe00 generator, customize, v2v: Only place generated files in libguestfs or common.
After the proposed split of the libguestfs repo, we will end up with
the following layout:

  libguestfs.git
      common -> git submodule libguestfs-common.git
      generator

  virt-v2v.git
      common -> git submodule libguestfs-common.git

  guestfs-tools.git
      common -> git submodule libguestfs-common.git

The generator will only be able to write to libguestfs directories and
the common directory/submodule.  This is mostly the case already with
only 6 exceptions:

  customize/customize-options.pod
  customize/customize-synopsis.pod
  customize/customize_cmdline.ml
  customize/customize_cmdline.mli
  v2v/uefi.ml
  v2v/uefi.mli

This commit moves these files around so they appear under common/ml*

It is somewhat unsatisfactory because it involves copying files
around, but there are some mitigating factors:

(1) Any changes now give us more freedom to develop faster and thus
clean things up in future.

(2) The v2v/uefi files ought to go away in future anyway.

This is simple code motion and should have no effect on the built
programs or tests.
2019-10-14 18:37:29 +01:00
Richard W.M. Jones
ddfec6a97d customize: Move Firstboot and SELinux_relabel modules to common/mlcustomize.
These two modules are a dependency of virt-v2v.  Since we intend to
split virt-v2v from the other OCaml virt-* programs, we cannot have a
dependency between virt-v2v and virt-customize.  Instead we must move
the modules to a common directory (common/mlcustomize) and have both
tools depending on the modules from there.

This is simple refactoring and should not affect how the programs work
or are tested.
2019-10-14 12:36:47 +01: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
Richard W.M. Jones
5067968297 common/mlstdutils: Add String.unix2dos function.
Simple string line ending replacement convenience function.
2019-04-15 11:41:29 +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
Richard W.M. Jones
d9f5e47f82 tests: Fix console for slow tests on Ubuntu 18.04.
Use the same fix as for Debian and Ubuntu 16.04.
2018-12-11 16:38:55 +00:00
Richard W.M. Jones
9c8d133455 Replace -nodefconfig with -no-user-config.
This option was removed from qemu for no apparent reason except to
break existing consumers.  It does the same as -no-user-config, added
in May 2012, so use that instead.
2018-11-30 12:18:01 +00: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
Pino Toscano
4b1e5b0c3f Introduce a --key option in tools that accept keys
The majority of the tools have already options (--echo-keys &
--keys-from-stdin) to deal with LUKS credentials, although there is no
way to automatically provide credentials.  --keys-from-stdin is
suboptimal, because it is a usable solution only when there is just one
device to open, and no other input passed via stdin to the tool (like
the commands for guestfish).

To overcome this limitation, introduce a new --key option in tools:
* --key /dev/device:file:/filename/with/key
* --key /dev/device:string:the-actual-key
this way it is possible to pass all the credentials needed for the
specific devices to open, with no risk of conflict with stdin, and also
in a secure way (when using the "file" way).

On the technical side: this adds a new "key_store" API for the C tools,
making sure it is used only when needed.  Partially mirror it also for
the OCaml tools, although there will be a conversion to the C API
because the decryption helpers used are in the common C parts.
2018-09-21 10:30:05 +02:00
Pino Toscano
ec438b7b85 mltools: create a cmdline_options struct
Instead of returning directly a Getopt.t handle, now
Tools_utils.create_standard_options returns a struct, which at the
moment contains only the Getopt.t handle.  This way, it will be easy to
add more data needed for handling standard command line options.

This is mostly refactoring, with no functional changes.
2018-09-20 17:52:53 +02:00
Richard W.M. Jones
4b6341072c customize: tests: Add slow test of Windows firstboot.
This requires that Windows guests have been created using the
procedure outlined here:

https://rwmj.wordpress.com/2018/09/13/creating-windows-templates-for-virt-builder/

For me:

PASS: test-firstboot-windows-6.2-server.sh
PASS: test-firstboot-windows-6.3-server.sh
PASS: test-firstboot-windows-10.0-server.sh

An incidental change is that we dump the firstboot log from the guest
(even on success).  If the firstboot fails this is very useful for
determining the real cause.
2018-09-14 14:39:46 +01:00
Richard W.M. Jones
d54be028a2 customize: Use set -x for test-firstboot.sh slow test.
Aids in debugging failed tests.
2018-09-14 13:49:54 +01:00
Sebastian Meyer
fd43730e2b Fix error with --uninstall option on SUSE
The `-l` option for some `zypper` subcommands is short for
`--auto-agree-with-licenses` and not available on the `zypper rm` command.
2018-08-23 18:05:04 +02:00
Richard W.M. Jones
7be88554af slow tests: Add slow tests of Ubuntu 18.04.
- firstboot
 - settings
 - password setting
 - console
 - v2v conversion
2018-04-27 14:58:28 +01: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
Kashyap Chamarthy
bb9636acac virt-builder.pod: Update Fedora versions
This is just a mechanincal change, so that the public documentation[*]
refers to the latest release Fedora versions, instead of the EOLed
versions.

While at it, also update the `virt-cutomize` Makefile.am

[*] http://libguestfs.org/virt-builder.1.html

Signed-off-by: Kashyap Chamarthy <kchamart@redhat.com>
2018-04-10 16:57:23 +01:00
Pino Toscano
5c5f69ef37 customize, sysprep, v2v: handle Kali Linux as Debian
Kali Linux is a Debian derivative, so add basic support for it by using
most of the Debian code paths.  The only exception is the crypto
algorithm for passwords in passwd, which is always assumed as SHA512
(as Kali Linux is relatively new).
2018-02-12 14:32:19 +01:00
Pino Toscano
8ce1373847 customize: avoid Array.mem for now
Since it is available only in OCaml >= 4.03, which is higher than our
requirement, add a simple reimplementation of it.

Fixes commit 719d68fa24.
2018-02-07 16:54:09 +01:00
Pino Toscano
719d68fa24 customize: allow missing SELINUXTYPE in SELinux config
libselinux defaults to "targeted" when no SELINUXTYPE is specified in
/etc/config/selinux.  Hence do the same here, instead of failing because
of the missing key.

Add a slow test for checking SELinux relabeling on a Fedora 27 guest,
both with no changes, and with a modified configuration.
2018-01-31 17:50:50 +01:00
Richard W.M. Jones
0c3d2d9430 customize: Correctly handle crypt(3) returning NULL (RHBZ#1539395).
In particular glibc's crypt will return NULL / errno == ENOSYS and
other implementations might do that in future too.

Reported by: David Hill
2018-01-30 14:18:35 +00:00
Richard W.M. Jones
b0df5f26fe customize: Use libxcrypt if available to provide crypt(3).
glibc 2.27 removes crypt(3) and suggests using libxcrypt.
libxcrypt requires <crypt.h> to be included.
2018-01-23 20:57:16 +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
0bbedd47c0 mltools: Move urandom module to common/mltools.
So that we can use it in virt-v2v code.
2017-12-09 21:11:52 +00:00
Richard W.M. Jones
c2898c50fd urandom: Fail if /dev/urandom returns EOF.
This is an unexpected error, so fail hard instead of leaking
End_of_file exception.

Nothing that calls into the Urandom module expects or handles
End_of_file.
2017-12-09 21:11:52 +00:00
Richard W.M. Jones
fd0bfba7b2 urandom: Use with_openfile. 2017-12-09 21:11:52 +00:00
Richard W.M. Jones
7960eb9bc6 urandom: Use O_CLOEXEC. 2017-12-09 21:11:52 +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
b92f74458f common/mlstdutils: Introduce Option submodule.
Inspired by ocaml-extlib, introduce a module for handling option
types.

We already had the ‘may’ function (which becomes ‘Option.may’).  This
adds also ‘Option.map’ (unused), and ‘Option.default’ functions.

Note this does *not* introduce the unsafe ‘Option.get’ function from
extlib.
2017-10-12 16:31:47 +01:00
Richard W.M. Jones
18a6766124 customize: In verbose mode, run dnf --verbose.
We should do the same for other package managers.  However apt-get
doesn't have a clear verbose mode (omitting -q doesn't do what we
want).
2017-10-11 17:58:15 +01:00
Richard W.M. Jones
0970bd0608 ocaml: Avoid Warning 52 for URI.parse_uri function.
This avoids warning 52 in OCaml code such as:

  try URI.parse_uri arg
  with Invalid_argument "URI.parse_uri" -> ...

which prints:

  Warning 52: Code should not depend on the actual values of
  this constructor's arguments. They are only for information
  and may change in future versions. (See manual section 8.5)

In the long term we need to change fish/uri.c so that we can throw
proper errors.
2017-10-05 11:32:54 +01:00
Richard W.M. Jones
c7651744da ocaml: Replace pattern matching { field = field } with { field }.
If you have a struct containing ‘field’, eg:

  type t = { field : int }

then previously to pattern-match on this type, eg. in function
parameters, you had to write:

  let f { field = field } =
    (* ... use field ... *)

In OCaml >= 3.12 it is possible to abbreviate cases where the field
being matched and the variable being bound have the same name, so now
you can just write:

  let f { field } =
    (* ... use field ... *)

(Similarly for a field prefixed by a Module name you can use
‘{ Module.field }’ instead of ‘{ Module.field = field }’).

This style is widely used inside the OCaml compiler sources, and is
briefer than the long form, so it makes sense to use it.  Furthermore
there was one place in virt-dib where we are already using this new
style, so the old code did not compile on OCaml < 3.12.

See also:
https://forge.ocamlcore.org/docman/view.php/77/112/leroy-cug2010.pdf
2017-10-05 11:32:54 +01:00
Richard W.M. Jones
cd304ad838 common/mltools: Rename Common_utils to Tools_utils.
Reflecting the purpose of this module now, which is to act as a place
for utility functions shared only by the OCaml virt tools.
2017-09-28 14:39:23 +01:00
Richard W.M. Jones
80fa8a91e3 Rename mllib -> common/mltools.
This directory which previously contained random modules and functions
now has an official purpose: to be the place for any OCaml utility
needed by the OCaml virt tools.

This is just code movement, I didn't (yet) rename or move any of the
modules.
2017-09-28 14:39:23 +01:00
Richard W.M. Jones
2b00983f23 common/mlgettext: Move common_gettext.ml{,i} to common/mlgettext.
Mostly just code motion, but common_gettext.mli was the same whether
or not ocaml-gettext exists, so instead of generating it, add the file
to git.
2017-09-28 14:39:22 +01:00
Richard W.M. Jones
d5ce659e2c customize: Unconditionally set the machine-id if not set already.
systemd defined an /etc/machine-id file which is supposed to contain a
unique, unchanging ID for the host.  This file is initially zero-sized
and is meant to be set by systemd on the first boot of the system.  In
virt-builder Fedora templates, the file is empty.

Unfortunately the Fedora kernel %post script requires the machine-id
to have been set, else the script exits with an error:

  Running scriptlet: kernel-core-4.12.13-300.fc26.x86_64        209/209
  Could not determine your machine ID from /etc/machine-id.
  Please run 'systemd-machine-id-setup' as root. See man:machine-id(5)
  warning: %posttrans(kernel-core-4.12.13-300.fc26.x86_64) scriptlet failed, exit status 1

This also leaves the kernel package half-installed.  The files are
present in the filesystem, but important initialization is not done,
in particular the vmlinuz file is not copied into /boot.

A simple reproducer for this problem is:

  $ virt-builder fedora-26 --update

which will leave the image with a half-installed kernel.  (Add -v -x
to see the error above amongst the debug output).

This change makes virt-customize set /etc/machine-id to a random value
if the file exists and is zero sized.  This is done unconditionally at
the same time as setting the random seed (a similar issue), and before
running any customize options such as installing or updating packages.
2017-09-28 14:39:22 +01:00
Richard W.M. Jones
508f3b29b8 customize: Remove use of Str module from virt-customize code. 2017-09-28 14:39:22 +01:00
Richard W.M. Jones
a706ecb8f7 Make sure every *.ml file has a corresponding *.mli file. 2017-09-21 18:05:07 +01:00
Richard W.M. Jones
692195c6ba build: Add a common script for generating OCaml dependencies correctly.
These are generated in many different ways in the various
subdirectories, and sometimes not generated correctly.  Introduce a
script to do this in one place, and hopefully correctly.

This is mostly simple refactoring, but I got rid of a couple of
things:

(1) The ‘make depend’ rule doesn't appear to be needed.  automake (or
make?)  seems to rebuild the ‘.depend’ file automatically just because
it is included.

(2) I got rid of the hairy path rewriting sed expression.  Possibly
that is needed for srcdir != builddir.
2017-08-09 14:45:48 +01:00
Jamie Iles
18db01490c Add missing oraclelinux cases.
oraclelinux is the same as redhat/centos/scientificlinux, so add it
where it is missing.  This fixes amongst other things, running sysprep
on an Oracle Linux image where it would previously fail operations like
setting the hostname, saying that it was not supported on that distro.
2017-08-01 16:06:48 +02:00
Richard W.M. Jones
db5e6bd221 customize: firstboot: Remove default.target.wants/guestfs-firstboot.service too.
This file could be left over from earlier use of the ‘--firstboot’
option.

Thanks: Pino Toscano.
2017-07-17 16:04:07 +01:00