127 Commits

Author SHA1 Message Date
Cole Robinson
04705f2aba gobject: skip test run-tests-retvalues
This is currently broken, and gobject bits are slated to be
removed entirely, so just disable this test.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-11-03 15:54:03 -05:00
Cole Robinson
a2e7dfc73b New API: ntfs_chmod
Add an API to do the equivalent of `chmod [-r] MODE PATH` for
NTFS filesystems.

Files created on a linux ntfs-3g mount can not change permissions
directly. New files and directories are created with rough windows
equivalent of `chmod 777`. These wide open permissions can generate
security warnings on windows after virt-v2v installs bits into
`Program Files\Guestfs`.

Behind the scenes we use `ntfssecaudit(8)` from `ntfsprogs`
which is already part of the appliance. We only expose the chmod-style
feature; the rest of `ntfssecaudit` is concerned reporting and
managing fine grained windows security info which is way more than
we need.

Also note, `ntfssecaudit` needs to run on an unmounted partition
so using this is more complicated than a traditional `chmod` call.

Related: https://issues.redhat.com/browse/RHEL-104352

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2025-09-09 16:29:13 +01:00
Richard W.M. Jones
1c0b56158a daemon: Deprecate guestfs_selinux_relabel, replace with guestfs_setfiles
The guestfs_selinux_relabel function was very hard to use.  In
particular it didn't just do an SELinux relabel as you might expect.
Instead you have to write a whole bunch of code around it (example[1])
to make it useful.

Another problem is that it doesn't let you pass multiple paths to the
setfiles command, but the command itself does permit that (and, as it
turns out, will require it).  There is no backwards compatible way to
extend the existing definition to allow a list parameter without
breaking API.

So deprecate guestfs_selinux_relabel.  Reimplement it as
guestfs_setfiles.  The new function is basically the same as the old
one, but allows you to pass a list of paths.  The old function calls
the new function with a single path parameter.

[1] https://github.com/libguestfs/libguestfs-common/blob/master/mlcustomize/SELinux_relabel.ml
2025-08-13 16:08:28 +01:00
Richard W.M. Jones
a57f6b8e2c gobject: Mark the gobject bindings as deprecated
They will be removed in libguestfs 1.58 (the next but one version).
Currently they don't actually compile.  The larger problem is that
they don't handle 64 bit quantities properly (using floats instead),
meaning that any disk size or offset above a certain size will be
improperly passed through the API, usually rounded to the nearest
53 bits.
2025-06-10 11:57:55 +01:00
Richard W.M. Jones
ea3dd97f1d New API: Replace btrfs-fsck with btrfs-scrub-full
The old btrfs-fsck API used "btrfs check" which appears to be broken
or deprecated.  The real tool you should use is "btrfs scrub".  We
have already implemented that API, but it is very awkward to use from
libguestfs.  In particular there's no existing way to run the scrub
and wait for it to finish.

Fix this by deprecating btrfs-fsck.  Implement a new API
btrfs-scrub-full which runs btrfs scrub in the foreground, waits for
it to finish, and handles errors.  It's much more like fsck tools in
other filesystems.

Thanks: Eric Sandeen
Fixes: https://issues.redhat.com/browse/RHEL-91936
2025-05-19 13:42:44 +01:00
Richard W.M. Jones
72cfaff5c5 Update copyright dates for 2025
Automated using this command:

perl -pi.bak -e 's/(20[012][0-9])-20[12][01234]/$1-2025/g' `git ls-files`
2025-02-16 17:00:46 +00:00
Richard W.M. Jones
b5fbc7e617 tests: Replace $TEST_FUNCTIONS
Replace strange $TEST_FUNCTIONS variable/expansion thing with
something more like what we use in nbdkit, a simple tests/functions.sh
script that gets sourced into each test script.

Update the common submodule to get:

  commit 8137d47d0e654065391151eb275e3b64f230f6f5
  Author: Richard W.M. Jones <rjones@redhat.com>
  Date:   Thu Feb 13 11:13:55 2025 +0000

    mlcustomize, mltools: Replace $TEST_FUNCTIONS

    TEST_FUNCTIONS is being removed from libguestfs and guestfs-tools (it
    was removed from virt-v2v a while back).  Make the same adjustment in
    the common submodule.

(and some other commits which are not relevant to libguestfs)
2025-02-13 11:15:34 +00:00
Richard W.M. Jones
27deba4074 gobject: Add libguestfs-gobject-1.0.deps to main EXTRA_DIST line
Move this outside the 'if HAVE_INTROSPECTION' conditional so that we
get this object in the tarball even if using ./configure --disable-gobject
2024-05-13 14:52:21 +01:00
Richard W.M. Jones
e0ffe31e96 gobject: tests: Don't erase error messages 2024-04-25 13:17:02 +01:00
Richard W.M. Jones
e2c7bddf10 Update copyright dates for 2023
Run this command across the source:

  perl -pi.bak -e 's/(20[012][0-9])-20[12][012]/$1-2023/g' `git ls-files`

and remove changes to po{,-docs}/*.po{,t} (these will be regenerated
later when we run 'make dist').
2023-02-07 10:50:48 +00: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
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
0e17236d7d Update copyright dates to 2020. 2020-03-06 19:32:32 +00:00
Corentin Noël
4f96e823d3 gobject: Add Vala binding support
RWMJ: Add optional dependency on vala to the docs.
2019-01-23 13:05:59 +00: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
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
Pino Toscano
a903f8912e gobject: use bash for running the tests
Since the introduction of the TEST_FUNCTIONS framework in tests, with
commit 2cb0413049, using a non-bash shell
will not work anymore, since the framework currently relies on bash.

Hence, switch the interpreter of these tests to bash, so they can run
also on systems where /bin/sh is not bash (e.g. default Ubuntu
installations).
2017-07-31 12:09:26 +02: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
f5f7f00a46 gobject: Remove gtk-doc (RHBZ#1465665).
The gobject bindings are adequately covered in the usual manual pages:
guestfs(3).  There is no need for separate generation of gtk-doc.
Also generating gtk documentation is the slowest part of the build,
and the tooling around gtk-doc is broken
(https://bugzilla.redhat.com/show_bug.cgi?id=1465665).

Note this removes the configure ‘--enable-gtk-doc’ option.  Using this
option now gives a warning, but is otherwise ignored:

  configure: WARNING: unrecognized options: --enable-gtk-doc
2017-07-10 17:03:19 +01:00
Richard W.M. Jones
2cb0413049 gobject: Use TEST_FUNCTIONS framework in tests. 2017-07-10 17:03:19 +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
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
Richard W.M. Jones
f161c9ea57 Rename src/ to lib/ 2017-01-26 15:05:46 +00:00
Richard W.M. Jones
e285566369 gobject: Avoid multiply defined CLEANFILES.
The error is:

gobject/docs/gtk-doc.make:52: warning: CLEANFILES multiply defined in condition TRUE ...
gobject/docs/Makefile.am:95:   'gobject/docs/gtk-doc.make' included from here
common-rules.mk:28: ... 'CLEANFILES' previously defined here
gobject/docs/Makefile.am:18:   'subdir-rules.mk' included from here
subdir-rules.mk:20:   'common-rules.mk' included from here
2017-01-26 15:05:46 +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
Richard W.M. Jones
76c0a67d30 build: Add common CLEANFILES and DISTCLEANFILES to common-rules.mk.
By adding common CLEANFILES and DISTCLEANFILES variables to
common-rules.mk, we can remove these from most other Makefiles, and
also clean files more consistently.

Note that bin_PROGRAMS are already cleaned by 'make clean', so I
removed cases where these were unnecessarily added to CLEANFILES.
2016-08-25 16:54:34 +01:00
Pino Toscano
cf5915aee3 New API: aug_transform
Expose the aug_transform API through the library, so it's possible to
add/remove Augeas transformations to handle files in custom places using
existing lenses.
2016-08-25 15:22:23 +02:00
Matteo Cafasso
007ef02e7d New API: download_blocks
This function allows to download file system data units (blocks) from
the given partition.

The API can be used to detect data hidden within filesystem bad blocks
or slack space.

Moreover for filesystems such as Ext3 and Ext4, this function is the
only way to retrieve deleted files. An example is given in the function
tests.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-07-20 15:26:50 +02:00
Richard W.M. Jones
9d205f1c28 New API: selinux_relabel - SELinux relabel parts of the filesystem. 2016-07-14 15:28:10 +01:00
Matteo Cafasso
3de8abac4a New API: internal_filesystem_walk
- generator: Added tsk_dirent struct

The tsk_dirent struct contains the information gathered via TSK APIs.

The struct contains the following fields:
 * tsk_inode: inode of a file
 * tsk_type: type of file such as for dirwalk command
 * tsk_size: file size in bytes
 * tsk_name: path relative to its disk partition
 * tsk_flags: bitfield containing extra information
 * tsk_spare[1-5]: extra space for future usage

 - configure: Added libtsk compile-time check

Ensure libtsk is available at compile time.
If not, daemon routines depending on it won't be available.

 - API: internal_filesystem_walk

The internal_filesystem_walk command walks through the FS structures
of a disk partition and returns all the files or directories
which could be found.

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-06-22 18:43:51 +01:00
Richard W.M. Jones
ae3c051567 generator: Declare which input file(s) generate each output file. 2016-02-23 10:40:06 +00:00
Richard W.M. Jones
52b5ddf23e generator: Make the 'this file is generated' warning clearer.
Also rename the ~extra_inputs parameter as plain ~inputs.  We will use
~inputs more widely in following commit.
2016-02-23 10:40:06 +00:00
Pino Toscano
9854ea913a gobject: ship also run-tests-retvalues
Fixes commit f7765ea6e4 and
commit 3787ebace4.
2016-02-19 09:47:37 +01:00
Pino Toscano
3787ebace4 gobject: ship correct .js file
Fixes commit f7765ea6e4.
2016-02-17 10:26:35 +01:00
Pino Toscano
f7765ea6e4 Start adding return values tests for bindings
Introduce a new kind of bindings tests, 090-retvalues, to check all the
possible return values in bindings; start implementing them for
scripting languages such as GObject introspection, Perl, PHP, Python,
and Ruby, reusing existing implementations where existing.
2016-02-15 18:32:07 +01:00
Pino Toscano
01f46e4e31 daemon: glob: add optarg to control trailing slash for dirs
Add a new optional bool "directoryslash" to indicate whether the caller
wants trailing slashes in names of directories, defaulting to true (the
current behaviour); this helps with interoperability with other tools
(such as rm).

Related to RHBZ#1293271.
2016-02-04 11:25:56 +01:00
Richard W.M. Jones
307c83177c Update copyright dates for 2016.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2015/$1-2016/g' `git ls-files`
2016-01-02 21:19:51 +00:00
Richard W.M. Jones
dc1d0880b0 tests: Move the tests/data and tests/guests directories to test-data.
Create a new top-level directory called test-data, which will carry
all the test data which is large and/or shared between multiple tests.

There are actually several new subdirectories created:

test-data/binaries: The pre-built binary and library files for random
architectures that we use to test various architecture detection
features (was part of tests/data).

test-data/blank-disks: The blank disks which are used for disk format
detection (was part of tests/data).

test-data/files: Other miscellaneous test files from tests/data that
are not included in the above.

test-data/phony-guests: The phony guests (was tests/guests).

test-data: The top-level directory builds the 'test.iso' image file
that is used for testing the C API and in miscellaneous other tests.
2015-10-30 16:07:32 +00:00
Richard W.M. Jones
2c519cf055 Add missing generated files to generator_built and EXTRA_DIST.
Use the generator_built variable to list any files which are built by
the generator.  This ensures they get automatically rebuilt.

Three files were missing from EXTRA_DIST, so they were not included in
the tarball, meaning you would have needed OCaml to build from the
tarball.  You would have seen this when building:

  cd .. && /builddir/build/BUILD/libguestfs-1.31.9/generator/generator
  written gobject/docs/guestfs-title.sgml
  written customize/customize-synopsis.pod
  written customize/customize-options.pod
  generated 476921 lines of code
2015-10-01 14:13:30 +01:00
Chen Hanxiao
52d1b0c593 New API: btrfs-image
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-03-24 13:35:28 +00:00
Hu Tao
f265371868 New API: btfs_scrub_status
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-02-16 18:05:30 +00:00
Hu Tao
88dbae4cbf New API: btrfs_balance_status
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-02-16 18:05:30 +00:00
Hu Tao
e32b59c926 New API: add btrfs_filesystem_defragment
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
2015-01-21 14:28:10 +00:00
Richard W.M. Jones
9d9ef2960c Version 1.29.20. 2015-01-17 11:45:31 +00:00
Hu Tao
2b7f7810ed New API: btrfs_qgroup_show
btrfs_qgroup_show shows all qgroups on a btrfs filesystem.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
2014-12-15 16:22:46 +00:00
Richard W.M. Jones
96158d42f5 New(ish) API: guestfs_add_libvirt_dom.
This API already existed (as guestfs___add_libvirt_dom), and was used
by a few tools.

This commit changes it to a public API.

Note that for reasons outlined in the previous commit message, it is
impossible to call this from guestfish or from non-C language
bindings.
2014-12-11 14:15:00 +00:00
Pino Toscano
1033847f00 gobject: link against uninstalled libraries
Make sure to link the gobject library and the gir using the in-tree
built libguestfs, so a system library won't be used accidentally.
2014-12-04 17:09:32 +01:00
Pino Toscano
5e81c838e8 Update gobject/Makefile.inc and POTFILES
Followup of commit a120449c979993f4b5bd458ece00fadb339546d3.
2014-11-26 17:22:02 +01:00
Pino Toscano
5f608f0735 Update gobject/Makefile.inc and POTFILES
Followup of commit 0b3c1762965f339915fd080884a61dbb36545204.
2014-11-26 17:22:01 +01:00
Richard W.M. Jones
8664337cc3 New APIs: Implement stat calls that return nanosecond timestamps (RHBZ#1144891).
The existing APIs guestfs_stat, guestfs_lstat and guestfs_lstatlist
return a stat structure that contains atime, mtime and ctime fields
that store only the timestamp in seconds.

Modern filesystems can store timestamps down to nanosecond
granularity, and the ordinary glibc stat(2) wrapper will return these
in "hidden" stat fields:

  struct timespec st_atim;            /* Time of last access.  */
  struct timespec st_mtim;            /* Time of last modification.  */
  struct timespec st_ctim;            /* Time of last status change.  */

with the following macros defined for backwards compatibility:

  #define st_atime st_atim.tv_sec
  #define st_mtime st_mtim.tv_sec
  #define st_ctime st_ctim.tv_sec

It is not possible to redefine guestfs_stat to return a longer struct
guestfs_stat with room for the extra nanosecond fields, because that
would break the ABI of guestfs_lstatlist as it returns an array
containing consecutive stat structs (not pointers).  Changing the
return type of guestfs_stat would break API.  Changing the generator
to support symbol versioning is judged to be too intrusive.

Therefore this adds a new struct (guestfs_statns) and new APIs:

  guestfs_statns
  guestfs_lstatns
  guestfs_lstatnslist

which return the new struct (or array of structs in the last case).

The old APIs may of course still be used, forever, but are deprecated
and shouldn't be used in new programs.

Because virt tools are compiled with -DGUESTFS_WARN_DEPRECATED=1, I
have updated all the places calling the deprecated functions.  This
has revealed some areas for improvement: in particular virt-diff and
virt-ls could be changed to print the nanosecond fields.

FUSE now returns nanoseconds in stat calls where available, fixing
https://bugzilla.redhat.com/show_bug.cgi?id=1144891

Notes about the implementation:

- guestfs_internal_lstatlist has been removed and replaced by
  guestfs_internal_lstatnslist.  As the former was an internal API no
  one should have been calling it, or indeed can call it unless they
  start defining their own header files.

- guestfs_stat and guestfs_lstat have been changed into library-side
  functions.  They, along with guestfs_lstatlist, are now implemented
  as wrappers around the new functions which just throw away the
  nanosecond fields.
2014-09-22 15:47:48 +01:00