Commit Graph

1172 Commits

Author SHA1 Message Date
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
8a98fe91b8 daemon: lvm: Pass --yes option to force pvresize (RHBZ#1460577).
LVM2 >= 2.02.171 requires the ‘--yes’ option to force pvresize to work
in various circumstances, eg. reducing the size of an existing PV.

Pass this flag unconditionally.

Note this does NOT break earlier versions which just ignore this flag.
2017-06-12 13:24:26 +01:00
Richard W.M. Jones
0b8556695f daemon: ldm: Use CLEANUP_FREE on list of static strings.
This likely causes a double-free in the ‘ldmtool_scan_devices’ API.
2017-06-09 12:57:03 +01:00
Pino Toscano
2c41f001de btrfs_replace: fix position of subcommand options
btrfs-progs 4.11 is more strict with option parsing, so subcommand
options must appear now before the subcommand arguments.
2017-05-30 13:15:55 +02:00
Pino Toscano
5cbedebdb0 daemon: lvm: use 'yes' as boolean for lvm2
It looks like older versions of lvm2 (recent enough to have selectors)
do not recognize '1' (and '0') as boolean values.  Switch to 'yes',
which seems to be supported.

Updates commit 7367945647.
2017-05-12 17:03:01 +02:00
Richard W.M. Jones
b4728fd004 generator: Annotate returned strings which are devices or mountables.
Previously the generator did not change any string returned from the
daemon.  Thus guestfs_list_devices (for example) might return internal
device names like /dev/vda (if virtio-blk was in use).

This changes calls to the daemon so that returned strings are
annotated as plain strings, devices or mountables:

    old               --->     new
  RString "uuid"             RString (RPlainString "uuid")
  RString "device"           RString (RDevice "device")
  RString "fs"               RString (RMountable "fs")

For hash tables, keys and values must be annotated separately.  For
example a hash table of mountables (keys) -> plain strings (values)
would be annotated like this:

    old               --->     new
  RHashtable "fses"          RHashtable (RMountable, RPlainString, "fses")

The daemon calls reverse_device_name_translation (currently a no-op)
for devices and mountables.

Note that this has no effect for calls which are handled on the
library side.

(cherry picked from commit 6b77cc196ecb8d7e1d73592ef65a189a7412c97c)
2017-05-08 11:14:45 +01:00
Richard W.M. Jones
8a545c0b1e daemon: Move device_name_translation function to its own file.
Just code motion.

(cherry picked from commit c75d873568e95fb7845c6e3913347c4bf267f4e9)
2017-05-08 11:14:45 +01:00
Richard W.M. Jones
9013a93d0e lib: Remove internal details of device name translation from API docs.
Remove much of the text detailing how device name translation
happened.  Since we removed support for virtio-blk
(commit 9e0294f88f) and deprecated the
‘iface’ parameter, only /dev/sdX device names should be visible
through the public APIs, both in parameters and in return values from
calls like guestfs_list_devices and guestfs_list_partitions.

Note the above is in fact not true for the UML backend, but UML is
broken in the kernel and in any case this will be fixed later.

(cherry picked from commit 2727e589db216bf0731385966889a4f66dbfe225)
2017-05-08 11:14:45 +01:00
Matteo Cafasso
d00dc913aa New API: internal_yara_scan
The internal_yara_scan runs the Yara engine with the previously loaded
rules against the given file.

For each rule matching against the scanned file, a struct containing
the file name and the rule identifier is returned.

The gathered list of yara_detection structs is serialised into XDR format
and written to a file.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:34:42 +01:00
Matteo Cafasso
09bab5d38c New API: yara_destroy
The yara_destroy API allows to claim resources back via the removal of
the previously loaded Yara rules.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:34:42 +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
Matteo Cafasso
29af0500c2 daemon: expose file upload logic
Allows other modules to use the same logic for uploading files.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-05-02 13:01:11 +01:00
Matteo Cafasso
ffbf1b5605 daemon: ignore unused return value in upload function
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2017-04-25 09:33:26 +01:00
Richard W.M. Jones
99813d1195 daemon: stubs.h is generated, so should be listed in generator_built.
Fixes commit 20f190617a.
2017-04-21 15:20:18 +01:00
Richard W.M. Jones
ca12aaa90c generator: daemon: Move *RESOLVE* macros to an ordinary header file.
It's clumsy to define these in the generator, as they are essentially
just static text.
2017-04-21 15:20:17 +01:00
Richard W.M. Jones
3f3dfe68de generator: daemon: Replace ‘cancel_stmt’ with ‘is_filein’ flag.
In every instance where we used the ‘cancel_stmt’ parameter of
these macros:

  ABS_PATH
  NEED_ROOT

the value was only ever ‘cancel_receive ()’ or empty.  We only use
‘cancel_receive’ for FileIn functions, so replace it with a simple
flag for whether the current function is a FileIn function.

This also removes some incorrect comments about macros that cannot be
used with FileIn functions when in fact they can.
2017-04-21 15:20:17 +01:00
Richard W.M. Jones
8b68d00977 daemon: Add an assertion to suppress a warning with GCC.
swap.c: In function 'do_mkswap_U':
swap.c:62:9: error: argument 1 null where non-null expected [-Werror=nonnull]
     if (strlen (label) > SWAP_LABEL_MAX) {
         ^~~~~~~~~~~~~~
2017-04-20 14:38:08 +01:00
Richard W.M. Jones
2de5e317ad daemon: Remove use of fixed-size stack buffers.
GCC 7 complains that the fixed size buffers are not large enough
(at least in theory) when using ‘-O3 -mtune=broadwell’.
2017-04-20 14:38:08 +01:00
Richard W.M. Jones
c0fdeb36c7 daemon: Move the useful 'is_zero' function into common code.
This is largely a simple refactoring, but it combines another
definition of this function from virt-builder which had a slightly
different prototype.
2017-04-19 17:30:58 +01:00
Pavel Butsykin
684aa26115 daemon: add udev_settle_file to is_root_device
It fixes a fail with ENOENT when device is not yet present after system boot.

Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
2017-04-14 11:08:07 +01:00
Pavel Butsykin
93664d38d2 daemon: run 'udevadm settle' with --exit-if-exists option
Add udev_settle_file() to run 'udevadm settle' with --exit-if-exists option. It
will slightly reduce the waiting-time for pending events if we need to wait
for events related to a particular device/file.

Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>

RWMJ:
 - Use local variable for MAX_ARGS.
 - Use commandv instead of commandrv, fix checking of return code.
2017-04-14 11:07:58 +01:00
Richard W.M. Jones
07cb3591b7 daemon: selinux: Add setfiles -v flag when verbose.
This shows which files are being relabelled.  Also only use -q
(suppress non-error output) when we are not verbose.
2017-03-21 14:54:48 +00:00
Richard W.M. Jones
fc0abf2354 daemon: selinux: Add setfiles -m option to suppress extra excludes (RHBZ#1433577). 2017-03-20 16:55:20 +00:00
Pino Toscano
12bfb3c631 btrfs_filesystem_show: work with another old btrfs version
An old version of btrfs-progs (3.17 in this case) has a different
version string, so adapt our filtering to include this line as well.

Related to/updates commit 839ae5bcd5.
2017-03-20 10:20:20 +01:00
Pino Toscano
31fb6e2041 daemon: fix memory leak in xfs implementation of vfs_minimum_size
Use the proper cleanup handler for deleting the guestfs_int_xfsinfo
struct (so the string fields are deleted too).

Fixes commit f5caa421d1.
2017-03-13 08:53:49 +01:00
Pino Toscano
32f0f9b032 daemon: generate cleanup handlers for structs
This way it is possible to cleanup properly structs in the daemon, when
using them within other daemon functions.
2017-03-13 08:53:49 +01:00
Richard W.M. Jones
4bbb1f7490 lib: Prefer tirpc for XDR, and rationalise how we search for alternatives.
glibc in Fedora is currently configured with `--enable-obsolete-rpc',
so I guess we can see which way the wind is blowing.

(1) This changes our configure script to prefer libtirpc if it is
available.

If libtirpc is _not_ available then:

(a) Headers must be located in <rpc/xdr.h>, or the user must supply
the right CFLAGS.

(b) XDR functions must be located in one of -lportablexdr, -lrpc,
-lxdr, -lnsl or no library at all (ie. -lc), and the user must set
LDFLAGS if needed.

(2) We no longer add these paths automatically to $(CFLAGS)/$(LIBS).
Any part of libguestfs which needs <rpc/*.h> or the xdr_* functions
must use $(RPC_CFLAGS)/$(RPC_LIBS) explicitly.

(3) Previously Mac OS X had a workaround for the broken 64 bit support
in the supplied rpcgen.  This workaround "activates" all the time if
you use tirpc, so breaking Linux after the above changes.  tirpc is
supported on OS X, so I think it's just better to use that rather than
the broken rpcgen.  For that reason I removed the workaround
completely.

Thanks: Roy Keene
2017-03-07 12:54:17 +00:00
Pino Toscano
c5fa352087 daemon: btrfs: check end_stringsbuf return values everywhere
Make sure to check the return value of end_stringsbuf everywhere, as
that would generate invalid string lists.
2017-03-06 15:04:24 +01:00
Richard W.M. Jones
e5474df1ac Use gnulib set_cloexec_flag in a few places. 2017-03-06 10:52:35 +00:00
Richard W.M. Jones
58d6becc8a Use gnulib set_nonblocking_flag function instead of fcntl.
The previous code:

  fcntl (fd, F_SETFL, O_NONBLOCK)

was technically incorrect, because it would have reset any
other flags on the file descriptor.

Thanks: Eric Blake
2017-03-06 10:52:35 +00:00
Pino Toscano
9aef2c7e3a daemon: tsk: properly use GUESTFS_MAX_CHUNK_SIZE
Pass to fread the size of the buffer allocated, so it can be filled
completely. This is even faster than reading only 4/8 bytes each
iteration.
2017-03-03 16:36:26 +01:00
Richard W.M. Jones
7a26804569 Use AC_HEADER_MAJOR to find definitions of major, minor, makedev.
Note this requires either the following fix in autoconf:

http://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=e17a30e98

OR gnulib sys_types module plus gnulib
commit a512e041120e9012e69afa2f5c3adc196ec4999a (any gnulib more
recent than Sep 2016) which corrects the AC_HEADER_MAJOR macro in a
similar way.
2017-03-03 11:32:37 +00:00
Dawid Zamirski
4fd6c3ad6e parted: add more udev_settle calls.
add udev_settle calls to print_partition_table and
sgdisk_info_extract_field because the inspect-os calls
guestfs_part_get_parttype and guestfs_part_get_gpt_guid for all
parition devices found and this causes intermittent with opening block
devices that are certainly present yet RESOLVE_DEVICE macro would fail
wiht ENOENT.
2017-03-03 10:24:48 +00:00
Richard W.M. Jones
1f99251223 hivex: Map new HIVEX_OPEN_UNSAFE flag into the API.
In hivex >= 1.3.14, there is a new HIVEX_OPEN_UNSAFE flag allowing
heuristics to be used to deal with corrupted hives.  Map this flag
into the libguestfs API.

If the flag is not supported (because libguestfs was compiled with
hivex < 1.3.14) then the flag is ignored.  This is safe behaviour:
opening corrupted hives will give an error, as happened previously.
2017-02-17 10:15:09 +00:00
Pino Toscano
7a3854001e New API: mksquashfs
Introduce a new API to create a new squashfs filesystem out of a path
in the guest.  It can be configured to exclude paths based on patterns,
and to select which compression use for the filesystem.

The advantage of running mksquashfs directly in the appliance is that
ownerships are properly saved, as opposed to tar_out + local untar.
2017-02-15 14:44:13 +01:00
Pino Toscano
35d97daa5a daemon: move make_exclude_from_file as common helper
It will be useful also for APIs different than tar-out, so move it to
guestfsd.c, and add it a parameter to specify the function name that
invoked it.

This is mostly code motion.
2017-02-15 14:44:12 +01:00
Richard W.M. Jones
a75076f271 GCC 7: Allocate sufficient space for sprintf output.
GCC 7.0.1 can determine if there is likely to be sufficient space in
the output buffer when using sprintf/snprintf, based on the format
string.

The errors were all either of this form:

bindtests.c:717:29: error: '%zu' directive output may be truncated writing between 1 and 19 bytes into a region of size 16 [-Werror=format-truncation=]
     snprintf (strs[i], 16, "%zu", i);
                             ^~~
bindtests.c:717:28: note: directive argument in the range [0, 2305843009213693951]
     snprintf (strs[i], 16, "%zu", i);
                             ^~~~~

or this form:

sync.c: In function 'fsync_devices':
sync.c:108:50: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size 251 [-Werror=format-truncation=]
       snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name);
                                                  ^~

Fixed by converting these into dynamic allocation, or making the
output buffer larger, whichever was easier.

There is a gnulib macro we can use to make this simpler for integers.
It requires a new gnulib module (intprops), but it turns out that we
were already pulling that in through dependencies, so the change to
bootstrap is a no-op.  (thanks: Dan Berrange)
2017-02-14 17:53:28 +00:00
Richard W.M. Jones
2c340682b5 daemon: selinux: Document cases where setfiles takes a long time to run.
Just adding a comment pointed back to the bug.
2017-02-10 10:14:15 +00:00
Richard W.M. Jones
0de08f6527 daemon: Allow ADD_ARG macro to be used everywhere.
This is a simple macro with no dependencies.  Allow it to be used from
any program.
2017-02-08 12:47:17 +00:00
Richard W.M. Jones
f161c9ea57 Rename src/ to lib/ 2017-01-26 15:05:46 +00:00
Richard W.M. Jones
88c0ce2397 lib: Share common protocol and errnostring libraries with the library and daemon.
This commit, which is just code motion, moves the common XDR protocol
code (libprotocol) and the common errno handling (liberrnostring) into
libraries which are each built once and shared between the library and
daemon.
2017-01-26 15:05:46 +00:00
Richard W.M. Jones
1aefcbcc9b daemon: Add comment explaining why we remove 'p' character.
No code change, just a comment.

Updates commit 6fd2ddb350.
2017-01-19 12:06:25 +00:00
Pino Toscano
5b02e7e6df daemon: Return MD partitions in guestfs_list_partitions (RHBZ#1414510). 2017-01-19 12:03:55 +00:00
Pino Toscano
6fd2ddb350 daemon: Fix part-to-dev when the partition name includes p<N>.
If the device name ends with a number, Linux uses partition names of
the form <device>p<N>.  Handle this case by knocking off the 'p'
character.
2017-01-19 11:00:21 +00:00
Pino Toscano
55bf7de97c Update copyright dates for 2017
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2016/$1-2017/g' `git ls-files`

(Thanks Rich for the perl snippet, as used in past years.)
2017-01-03 16:48:21 +01:00
Pino Toscano
aad24f4d56 daemon: allow to change the labels of swap partitions 2016-12-07 14:20:31 +01:00
Matteo Cafasso
5d36f5ae82 upload: improve file write callback
As noted by Pino in another patch, the logic passes the first member of
the struct which happens to be the right address to the callback
function.

This will break the callback if order of the members of the struct will
change.

As the callback is using the entire struct, better to pass the pointer
to the struct itself.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-11-09 21:09:24 +00:00
Matteo Cafasso
eccce186a3 New API: internal_find_inode
The internal_find_inode command searches all entries referring to the
given inode and returns a tsk_dirent structure for each of them.

The command is able to retrieve information regarding deleted
or unaccessible files where other commands such as stat or find
would fail.

The gathered list of tsk_dirent structs is serialised into XDR format
and written to a file by the appliance.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-09-19 19:53:07 +02:00
Matteo Cafasso
a1b5bbfced daemon: refactor tsk code
Refactor logic in preparation for new APIs.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-09-19 11:12:48 +02:00