Commit Graph

209 Commits

Author SHA1 Message Date
Richard W.M. Jones
fbf044a11c m4: Rename guestfs_*.m4 to guestfs-*.m4.
For consistency with other code.
2017-10-06 14:36:16 +01:00
Richard W.M. Jones
2cdd2eb795 build: Require OCaml >= 4.01.
RHEL 6, Debian <= 7 and Ubuntu < 14.04 are no longer supported
(unless OCaml and other components are upgraded).

See: https://www.redhat.com/archives/libguestfs/2017-September/msg00203.html
2017-10-05 11:32:54 +01:00
Richard W.M. Jones
bbd54295d3 daemon: Reimplement statvfs API in OCaml, drop gnulib fallback.
common/mlutils: Unix_utils.StatVFS.statvfs: This commit implements a
full-featured binding for the statvfs(3) function.

We then use this to reimplement the daemon statvfs API in OCaml.

Note that the Gnulib fallback is dropped in this commit.  It
previously referenced non-existent field names in the fs_usage struct
so it didn't work.  Also it's not necessary as POSIX has supported
statvfs(3) since 2001, it's supported in *BSD, macOS > 10.4, and there
is already a Windows fallback.
2017-10-04 15:25:32 +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
Pino Toscano
531316cc3f build: improve and simplify distro detection
Add a --with-distro=ID argument for configure, so it is possible to
manually specify the distro to use for the packages (in case os-release
does not provide ID=.., or the ID is not recognized yet).

In the case when --with-distro is not set, keep doing the autodetection,
but using os-release only, i.e. dropping the checks for all the other
-release files -- since there is --with-distro, older distros with no
os-release can still be used.

RWMJ: Add documentation to guestfs-building(1).
2017-09-25 14:49:17 +01:00
Richard W.M. Jones
41df9aaf90 lib: Move guestfs_int_download_to_tmp and remove inspect.c.
Move the last remaining function ‘guestfs_int_download_to_tmp’ to
lib/inspect-icon.c (the main, but not only user of this function).
Then remove lib/inspect.c entirely.

This is not quite code motion because I updated the comment for the
function to reflect what it does in reality.
2017-09-21 18:05:07 +01:00
Richard W.M. Jones
64f49df747 docs: hivex >= 1.3.14 is required (RHBZ#1493048).
Bug reported by Jean-Christophe Manciot.
2017-09-20 17:57:47 +01:00
Richard W.M. Jones
3a00c4d179 Remove inspection from the C library and switch to daemon/OCaml implementation. 2017-09-16 22:27:16 +01:00
Richard W.M. Jones
19940fc2bd New API: Deprecate hivex_value_utf8 and replace with hivex_value_string.
hivex has a function hivex_value_string.  We were not calling it under
the mistaken belief that because hivex implements this using iconv,
the function wouldn't work inside the daemon.  Instead we
reimplemented the functionality in the library.

This commit deprecates hivex_value_utf8 and removes the library side
code.  It replaces it with a plain wrapper around hivex_value_string.

Thanks: Pino Toscano
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
2ffb8a6b25 common: Bundle the ocaml-augeas library for use by the daemon.
This commit bundles the ocaml-augeas library (upstream here:
http://git.annexia.org/?p=ocaml-augeas.git;a=summary).  It's identical
to the upstream version and should remain so.

We can work towards using system ocaml-augeas, when it's more widely
available.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
65cfecb0f5 inspection: Deprecate APIs and remove support for inspecting installer CDs.
This just duplicated libosinfo information, and because it was never
tested it didn't work most of the time.
2017-09-16 22:27:16 +01:00
Richard W.M. Jones
0bf521cfcb daemon: Deduplicate some utility functions.
The following functions were previously reimplemented in OCaml.  This
commit replaces them with calls to the C functions:

 - is_root_device
 - prog_exists
 - udev_settle

plus the internal get_verbose_flag function.

However note that we cannot do this for every utility function.  In
particular the C function must not call any reply* functions.
2017-08-08 16:23:42 +01:00
Richard W.M. Jones
089ade6f95 Version 1.37.20. 2017-08-03 18:49:01 +01:00
Richard W.M. Jones
f33db99edf common: Add a lightweight OCaml binding for PCRE.
This uses the gnulib TLS macros.
2017-08-03 17:36:09 +01:00
Richard W.M. Jones
85d9c9325c docs: guestfs-hacking: Reorder directory names into alphabetical order. 2017-08-01 09:20:02 +01:00
Richard W.M. Jones
4d3601eb4e docs: ocaml-hivex is now required to build the daemon.
Fixes commit d5b6f1df5f.
2017-07-29 08:29:22 +01:00
Richard W.M. Jones
1e956dfc7d daemon: Reimplement ‘realpath’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
c37c8e770d daemon: Reimplement ‘findfs_uuid’ and ‘findfs_label’ APIs in OCaml.
This also reimplements the lv_canonical function in OCaml.  We cannot
call the original C function because it calls reply_with_perror which
would break the OCaml bindings.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
4052f613d2 daemon: Reimplement ‘list_filesystems’ API in the daemon, in OCaml.
Move the list_filesystems API into the daemon, reimplementing it in
OCaml.  Since this API makes many other API calls, it runs a lot
faster in the daemon.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
b48da89dd6 daemon: Reimplement ‘file_architecture’ API in OCaml.
The previously library-side ‘file_architecture’ API is reimplemented
in the daemon, in OCaml.

There are some significant differences compared to the C
implementation:

 - The C code used libmagic.  That is replaced by calling the ‘file’
   command (because that is simpler than using the library).

 - The C code had extra cases to deal with compressed files.  This is
   not necessary since the ‘file’ command supports the ‘-z’ option
   which transparently looks inside compressed content (this is a
   consequence of the change above).

This commit demonstrates a number of techniques which will be useful
for moving inspection code to the daemon:

 - Moving an API from the C library to the OCaml daemon.

 - Calling from one OCaml API inside the daemon to another (from
   ‘Filearch.file_architecture’ to ‘File.file’).  This can be done and
   is done with C daemon APIs but correct reply_with_error handling is
   more difficult in C.

 - Use of Str for regular expression matching within the appliance.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
7a084269ef daemon: Add unit tests of the ‘Utils’ module. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
d5b6f1df5f daemon: Allow parts of the daemon and APIs to be written in OCaml.
This change allows parts of the daemon to be written in the OCaml
programming language.  I am using the ‘Main Program in C’ method along
with ‘-output-obj’ to create an object file from the OCaml code /
runtime, as described here:
https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html

Furthermore, change the generator to allow individual APIs to be
implemented in OCaml.  This is picked by setting:

  impl = OCaml <ocaml_function>;

The generator creates ‘do_function’ (the same one you would have to
write by hand in C), with the function calling the named
‘ocaml_function’ and dealing with marshalling/unmarshalling the OCaml
parameters.
2017-07-27 22:31:22 +01:00
Richard W.M. Jones
318ca68408 build: Make OCaml compiler required for all builds.
Previously the OCaml compiler was only required if building from git
but was at least theoretically optional if building from tarballs
(although this was never tested).  Since we want to write parts of the
daemon in OCaml, this makes OCaml required for all builds.

Note that the ‘--disable-ocaml’ option remains, but it now only
disables OCaml bindings and OCaml virt tools.  Using this option does
not disable the OCaml compiler requirement.

Also note that ‘HAVE_OCAML’ changes meaning slightly, so it now means
"build OCaml bindings and tools" (analogous to ‘HAVE_PERL’ and
others).  The generator, daemon [in a future commit], and some utility
libraries needed by the generator or daemon do not test for this macro
because we can assume OCaml compiler availability.
2017-07-18 18:37:35 +01:00
Richard W.M. Jones
981d3c9630 docs: Add info about how the stable tarballs are signed. 2017-07-16 21:36:19 +01:00
Richard W.M. Jones
f60f8c47cc lib: Move implementation of ‘hivex_value_utf8’ to new file ‘lib/hivex.c’.
Just a code movement, no change.
2017-07-14 14:35:37 +01:00
Richard W.M. Jones
09b14a6076 Version 1.37.17. 2017-07-10 22:06:45 +01:00
Richard W.M. Jones
f30b2065a2 gobject: Add outline guestfs-gobject(3) manual page.
Since we removed gtk doc, we might as well replace it with a
manual page explaining the basics of how to run gjs.
2017-07-10 17:03:19 +01:00
Richard W.M. Jones
707f5bcfe0 daemon: Link guestfsd with libutils.
After the previous refactoring, we are able to link the daemon to
common/utils, and also remove some of the "duplicate" functions that
the daemon carried ("duplicate" in quotes because they were often not
exact duplicates).

Also this removes the duplicate reimplementation of (most) cleanup
functions in the daemon, since those are provided by libutils now.

It also allows us in future (but not in this commit) to move utility
functions from the daemon into libutils.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
e6c89f9631 utils: Rename ‘guestfs-internal-frontend.h’ to ‘guestfs-utils.h’.
The reason it's not just ‘utils.h’ is because Pino is worried that we
might pick up /usr/include/utils.h from a rogue library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
8be72935dc mllib, v2v: Split out OCaml utils bindings ‘common/mlutils’.
Create a module ‘C_utils’ containing functions like ‘drive_name’ and
‘shell_unquote’ which come from the C utilities.

The new directory ‘common/mlutils’ also contains the ‘Unix_utils’
wrappers around POSIX functions missing from the OCaml stdlib.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
5efebd8c7e utils: Split out structs cleanups and printing into common/structs.
These won't be used by the daemon, so interferes with us using
common/utils in the daemon, so they are moved to a different library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
b2469a6d96 common/utils: Refactor stdlib, gnulib and libxml2 cleanup functions.
This refactoring change just moves the cleanup functions around in the
common/utils directory.

libxml2 cleanups are moved to a separate object file, so that we can
still link to libutils even if the main program is not using libxml2
anywhere.  Similarly gnulib cleanups.

cleanup.c is renamed to cleanups.c.

A new header file cleanups.h is introduced which will replace
guestfs-internal-frontend-cleanups.h (fully replaced in a later commit).
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
7489d22843 common/utils: Move ‘uefi.c’ to ‘lib/’.
This was only used inside the library, so move it there.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
61d4891ef4 mllib: Split ‘Common_utils’ into ‘Std_utils’ + ‘Common_utils’.
The new module ‘Std_utils’ contains only functions which are pure
OCaml and depend only on the OCaml stdlib.  Therefore these functions
may be used by the generator.

The new module is moved to ‘common/mlstdutils’.

This also removes the "<stdlib>" hack, and the code which copied the
library around.

Also ‘Guestfs_config’, ‘Libdir’ and ‘StringMap’ modules are moved
since these are essentially the same.

The bulk of this change is just updating files which use
‘open Common_utils’ to add ‘open Std_utils’ where necessary.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
989292c146 mllib: Move Xml (libxml2) OCaml bindings to common/mlxml.
The ‘Xml’ module is a self-contained library of bindings for libxml2,
with no other dependencies.

Move it to a separate ‘common/mlxml’ directory.

This is not pure refactoring.  For unclear reasons, the previous
version of ‘Xml.parse_file’ read the whole file into memory and then
called ‘xmlReadMemory’.  This was quite inefficient, and unnecessary
because we could use ‘xmlReadFile’ to read and parse the file
efficiently.  Changing the code to use ‘xmlReadFile’ also removes the
unnecessary dependency on ‘Common_utils.read_whole_file’.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
9254c8f152 mllib: Move Progress OCaml bindings to common/mlprogress.
The ‘Progress’ module is a self-contained library with the only
dependencies being:

 - the C ‘progress’ implementation

Move it to a separate ‘common/mlprogress’ directory.

This change is pure code refactoring.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
746a87cbf8 mllib: Move Visit OCaml bindings to common/mlvisit.
The ‘Visit’ module is a self-contained library with the only
dependencies being:

 - the C ‘visit’ implementation

 - the guestfs OCaml bindings

Move it to a separate ‘common/mlvisit’ directory.

This change is not entirely refactoring.  Two other fixes are made:

 - remove unsafe use of CLEANUP_FREE from a function which could
   raise an OCaml exception (cleanup handlers would not be called
   correctly if the exception is thrown)

 - don't link directly to common/visit/visit.c, but instead use
   the library (common/visit/libvisit.la)
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
4e05ad9e1c docs: Document common/qemuopts subdirectory. 2017-06-08 19:18:06 +01:00
Richard W.M. Jones
613c6fb900 Version 1.37.13. 2017-05-08 14:08:12 +01:00
Richard W.M. Jones
bb5ffd7497 configure: Drop --with-qemu-options / QEMU_OPTIONS.
In its current form this is very hard to implement because it requires
us to "unparse" the options, including removing any shell quoting.

It wasn't implemented at all for the libvirt backend.

Also contrary to the documentation, the configure script did not use
these options for testing, but constructed its own set of qemu test
options.
2017-05-08 11:14:46 +01:00
Matteo Cafasso
e7a0face42 New API: yara_scan
The yara_scan API parses the file generated by the daemon counterpart
function and returns the list of yara_detection structs to the user.

It writes the daemon's command output on a temporary file and parses it,
deserialising the XDR formatted yara_detection structs.

It returns to the caller the list of yara_detection structs generated by
the internal_yara_scan command.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:34:43 +01:00
Matteo Cafasso
27f175b717 New API: yara_load
The yara_load API allows to load a set of Yara rules contained within a
file on the host.

Rules can be in binary format, as when compiled with yarac command, or
in source code format. In the latter case, the rules will be first
compiled and then loaded.

Subsequent calls of the yara_load API will result in the discard of the
previously loaded rules.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:34:42 +01:00
Matteo Cafasso
2e24129da3 appliance: add yara dependency
libyara3 on Debian/Ubuntu
yara on SUSE/RedHat

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:01:11 +01:00
Richard W.M. Jones
311eb4c7e1 Version 1.37.12. 2017-04-25 22:52:47 +01:00
Richard W.M. Jones
069eb3d3df builder: Allow GnuPG v2 or v1 to be used (RHBZ#1438939).
All of the GPG commands we run are compatible with either v1 or v2, so
this simply involves looking for either gpg2 or gpg binaries at
runtime.
2017-04-06 16:29:45 +01:00
Richard W.M. Jones
ee206d7ba8 Use Unicode single quotes ‘’ in place of short single quoted strings throughout.
Only in end-user messages and documentation.  This change was done
mostly mechanically using the Perl script attached below.

I also changed don't -> don’t etc and made some other simple fixes.

See also: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

----------
 #!/usr/bin/perl -w

use strict;
use Locale::PO;

my $re = qr{'([-\w%.,=?*/]+)'};

my %files = ();

foreach my $filename ("po/libguestfs.pot", "po-docs/libguestfs-docs.pot") {
    my $poref = Locale::PO->load_file_asarray($filename);

    foreach my $po (@$poref) {
        if ($po->msgid =~ $re) {
            my @refs = split /\s+/, $po->reference;
            foreach my $ref (@refs) {
                my ($file, $lineno) = split /:/, $ref, 2;
                $file =~ s{^\.\./}{};
                if (exists $files{$file}) {
                    push @{$files{$file}}, $lineno;
                } else {
                    $files{$file} = [$lineno];
                }
            }
        }
    }
}

foreach my $file (sort keys %files) {
    unless (-w $file) {
        warn "warning: $file is probably generated\n"; # have to edit generator
        next;
    }
    my @lines = sort { $a <=> $b } @{$files{$file}};

    #print "editing $file at lines ", join (", ", @lines), " ...\n";
    open FILE, "<$file" or die "$file: $!";
    my @all = ();
    push @all, $_ while <FILE>;
    close FILE;

    my $ext = $file;
    $ext =~ s/^.*\.//;

    foreach (@lines) {
        # Don't mess with verbatim sections in POD files.
        next if $ext eq "pod" && $all[$_-1] =~ m/^ /;

        unless ($all[$_-1] =~ $re) {
            # this can happen for multi-line strings, have to edit it
            # by hand
            warn "warning: $file:$_ does not contain expected content\n";
            next;
        }
        $all[$_-1] =~ s/$re/‘$1’/g;
    }

    rename "$file", "$file.bak";
    open FILE, ">$file" or die "$file: $!";
    print FILE $_ for @all;
    close FILE;
    my $mode = (stat ("$file.bak"))[2];
    chmod ($mode & 0777, "$file");
}
2017-04-04 18:47:37 +01:00
Richard W.M. Jones
8c58b62f9d Replace possessive ASCII apostrophe ('s) with Unicode apostrophe (’s).
Only replaced in end-user messages and documentation, not in code,
comments, or anything else that's not end-user visible.

See: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
2017-03-31 10:38:04 +01:00
Pino Toscano
5810e03023 p2v: move the license text to gui.c
It is used only for the about dialog, and this way it will be easier
to disable.
2017-03-30 16:29:45 +02:00