Commit Graph

366 Commits

Author SHA1 Message Date
Alexander Larsson
bf0bd3874b Add extra data download size to sparse cache in summary
This adds the nr of extra datas, as well as the total size in the sparse
cache for all refs that has them. This is what we need for in the download,
and having it in the summary means we don't have to separately download
the commit.

Additionally we add a cache version field to the summary so that we
can know if we can rely on the existance of the new data.
2020-04-03 16:27:33 +02:00
Matthew Leeds
e7fd267ac7 common: Delete no longer relevant comment 2020-03-30 13:55:47 -07:00
Abderrahim Kitouni
192d31d315 Add a FlatpakProgress object
To avoid the complexities of passing (and chaining) OstreeAsyncProgress
objects around, we only create one just before calling to ostree.
The rest of flatpak only ever uses the new FlatpakProgress object.

Co-authored by: Philip Chimento <philip@endlessm.com>
2020-03-26 21:09:19 +01:00
Alexander Larsson
05eba2b32c Merge pull request #3474 from flatpak/wip/hadess/more-similar-appids
common: Allow version numbers in app-id for DConf migration
2020-03-25 09:57:43 +01:00
Alexander Larsson
d30e902d9f Add build-update-repo --deploy-sideload-collection-id option
This is a new version of --deploy-collection-id that only applies
the collection id update for new (1.7.x+) version of flatpak clients.
This allows you to enable collection ids for sideload use but not
affect older clients where the p2p codepaths are not as tested.
2020-03-23 17:58:04 +01:00
Alexander Larsson
316baff539 Don't enforce gpg-verify false when using collection id
With the new sideload approach to collection ids it is fine to require
gpg signed summaries. (Not for the child repos or the sideload repos
though, but thoser are either trusted (sideload) or safe for other
reasons like ref-bindings and signed commits).
2020-03-23 17:58:04 +01:00
Bastien Nocera
98c4b07322 common: Allow version numbers in app-id for DConf migration
Allow the app-id or the DConf path to finish with a digit and still be
considered similar enough for DConf migration purposes.

This allows the org.gnome.Rhythmbox3 app-id to migrate its
/org/gnome/rhythmbox DConf path.

See https://github.com/flathub/org.gnome.Rhythmbox3/pull/26
2020-03-17 13:12:57 +01:00
Alexander Larsson
ff317fd4fb Enforce little endian for token-type
When storing the token-type in the commit and the summary cache we
hardcode it to little-endian.

In theory this breaks the "ABI", but in practice this change is a
no-op on little-endian systems which is what most are. Additionally as most
servers are little-endian this also fixes using big-endian clients with
such servers.

This fixes:
https://github.com/flatpak/flatpak/issues/3434
2020-03-16 11:26:10 +01:00
Matthew Leeds
6aa3ff0d6f common: Don't shadow parameter variables 2020-03-16 09:29:31 +01:00
Alexander Larsson
61da44a5e3 Convert flatpak_summary_lookup_ref from GVariants
Now it returns a VarRefInfoRef instead of a GVariant
2020-02-17 16:10:50 +01:00
Alexander Larsson
9f6c60405d utils: Convert summary ref lookup code to variant codegen
We can't use the built-in bsearch from the codegen because its an array
instead of a dict, so we have to keep that but its now not using
variant at least.
2020-02-17 16:10:50 +01:00
Alexander Larsson
7c4fd8891e Convert deploy data to use variant schemas 2020-02-17 16:10:50 +01:00
Alexander Larsson
ebca05ff10 utils: Add flatpak_bytes_save() 2020-02-17 16:10:50 +01:00
Alexander Larsson
3c6c51f46b build-commit-from: Fix generation of download-size
In flatpak-builtins-build-commit-from.c we call flatpak_repo_collect_sizes()
without initializing the passed in download size to zero, which mean
we sum with sizes with some random value as the start.

This is fixed by having flatpak_repo_collect_sizes() always initialize
the counters to 0 at the start.

Fixes https://github.com/flatpak/flatpak/issues/3362
2020-01-23 09:04:29 +01:00
Alexander Larsson
a98d655f4f Fix build on older glib
Don't use G_VARIANT_BUILDER_INIT() which is glib 2.50 only
2019-12-20 13:25:20 +01:00
Alexander Larsson
202b2508d5 filters: Fix some leaks 2019-12-20 11:15:39 +01:00
Alexander Larsson
7a8801da50 Fix leak in flatpak_repo_update() 2019-12-19 16:53:14 +01:00
Alexander Larsson
04162f3286 repo support for setting authenticator options
flatpak build-update-repo now lets you modify the
autenticator-name/install/options keys, and these are migrated to
the summary/metadata during update.
2019-12-19 10:33:21 +01:00
Alexander Larsson
798d90ef0c flatpakrepo files: Support Authenticator keys
This parses AuthenticatorName and AuthenticatorInstall
2019-12-19 10:33:21 +01:00
Alexander Larsson
4c3e59cd12 utils: Fix chaining of progress
With the latest ostree that enables the chaining of progress the
testsuite broke because we were not getting changed events. Looking
into this the reason seems to be that when we run the
ostree_async_progress_finish() on the chained progress it is marked
as dead, which causes ostree_async_progress_copy_state() to not copy
any data when called from handle_chained_progress().

The fix is to copy the content manually before calling the finish().

Also, the entire callback chaining system seems wildly
overcomplicated, so I simplified it by relying on the existing change
notification of OstreeAsyncProgress.
2019-12-18 09:46:39 +01:00
Alexander Larsson
b3ab31e18a FlatpakAsyncProgressChained: Don't leak chained progress
If we're using a chained progress, it will be unchained
in the destroy notifier. However, it was newly constructed so we
need to also unref it or we'll leak it.

This also makes some minor cleanups:

1) Centralize version checks to one place and replace users
   with #ifdef FLATPAK_DO_CHAIN_PROGRESS which makes it
   easier to read and to test the fallback.

2) Make flatpak_progress_chain return a FlatpakAsyncProgressChained
   to make it clear the two needs to be paired.
2019-12-17 14:55:13 +01:00
Alexander Larsson
7fedf3578f OCI: Only use labels, never annotations
This is a slightly incompatible change, as we now only support
oci images generated with (what was before) build-export --oci-use-labels.
However, there are not a lot of OCI implementations in the wild, and
we can modify the ones in use to ensure there are labels (and
annotations if needed for older flatpak clients).

This also removes the --oci-use-label option from build-bundle --oci as
this is now the default.
2019-12-16 09:23:49 +01:00
Alexander Larsson
c6aa7f56a1 password prompt: Emit newline (as we stole it during input) 2019-12-12 14:27:59 +01:00
Alexander Larsson
2601b4cb1a utils: Add helpers for text prompts and password prompts 2019-12-12 12:16:53 +01:00
Philip Chimento
0da49895ab Alphabetize and standardize some header includes
Cleanup commit, doesn't change functionality, but we'll be adding some
files to these lists in a subsequent commit.
2019-12-06 13:26:49 -08:00
Alexander Larsson
077006ecc8 Add token-type per-commit metadata key and export it to summary
We store this in the sparse cache, because we don't expect it to be
set for everything.
2019-11-26 16:37:01 +01:00
Alexander Larsson
b1eaad3fa2 p2p: Generate xa.commits array in ostree-metadata
This is in the same order as the xa.cache array and contains the id of
the commit that the cached data is about. This is not necessary in the
non-p2p summary metadata, because in that we always have a matching
ref -> commit array.

However, in the p2p case this information can be useful.
2019-11-26 16:37:01 +01:00
Alexander Larsson
2db1c6e6c4 Add defines for existing summary sparse cache keys
These are explicitly made short to save space, so lets have defines
for them to make sure we don't mistype them, especially as we
will be adding new keys.
2019-11-26 16:37:01 +01:00
Philip Chimento
91f1280e73 utils: Check outstanding-extra-data in progress callback early return
The previous code checked whether the progress object had
"outstanding-fetches" set in order to decide whether it had been
initialized enough to show progress information. However, if the
callback saw a progress object on which flatpak_dir_setup_extra_data()
had not yet been called, then it would crash.

Therefore it seems that we should additionally be checking for the
presence of "outstanding-extra-data" which is set in
flatpak_dir_setup_extra_data().

It's likely that this wasn't previously a problem because the callback
would never get called due to the progress object's associated main
context not being iterated. It crashes now because that problem was
fixed in a previous commit.
2019-11-22 16:03:26 +01:00
Philip Chimento
529783e56b dir: Fix varargs argument width mismatch
Previously, in flatpak_dir_setup_extra_data(), n_extra_data (a gsize
which is 8 bytes wide on x86_64) was passed in a varargs list where an
unsigned int (4 bytes wide) was expected due to the "u" variant type
specifier.

This doesn't seem to have directly caused any crashes for me, but it's
undefined behaviour.

Therefore, this changes the affected keys "outstanding-extra-data" and
"total-extra-data" to be guint64 types instead of unsigned ints. The
gsize returned from g_variant_n_children() is cast to guint64 by virtue
of being assigned to a guint64-typed variable, but should not lose any
bits on supported platforms.
2019-11-22 16:03:26 +01:00
Philip Chimento
6b2c47a334 utils: Allow chaining OstreeAsyncProgress when pushing GMainContext
It's a common idiom in this codebase to push a temporary GMainContext as
the thread default context in order to run an async operation as if it
were sync. If we are not expecting progress callbacks this isn't a
problem, but it becomes a problem if we pass in an OstreeAsyncProgress
object that was created under a different GMainContext. The reason for
this is that OstreeAsyncProgress creates an idle source and attaches it
to the thread default context, so if we are iterating a temporary
context then the OstreeAsyncProgress's context never gets iterated, and
so no progress signals are fired.

To fix this, we introduce flatpak_progress_chain() and a RAII helper
FlatpakAsyncProgressChained which creates a new OstreeAsyncProgress
under the temporary GMainContext, but forwards all its state and updates
to the previous OstreeAsyncProgress's callbacks.

This is documented in a comment in the code as well.

All known instances of this problem in the existing code are fixed in
this commit.

This uses new API in libostree which is proposed in
ostreedev/ostree#1968. In anticipation of it being included in libostree
version 2019.6, the bug fix is predicated on that version being present.
If compiling against an older version, the old buggy behaviour will be
the fallback.

This problem was solved conceptually by Philip Withnall, I only wrote
the code.
2019-11-22 16:03:26 +01:00
Philip Withnall
62b0d3f4f1 common: Bump version numbers for new parental controls API
The PR was written before 1.5.0 was released, but was then merged after
1.5.0 was released — so bump the version numbers to 1.5.1.

See https://github.com/flatpak/flatpak/pull/2797.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-03 13:54:37 +02:00
Philip Withnall
c40223267c error: Add a ‘permission denied’ error code
This will be used for parental controls, and potentially other reasons
for denying installation of an app.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-03 10:42:04 +02:00
Philip Withnall
de1759e2b4 utils: Add missing D-Bus error serialisation
FLATPAK_ERROR_REF_NOT_FOUND was missing its serialisation for sending
over D-Bus.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2019-10-03 10:42:04 +02:00
Alexander Larsson
9f6fc5591c common: Export glob_to_regexp util and make it handle empty parts as *
This means you can use "org.foo.bar//stable" instead of "org.foo.bar/*/stable"
which is similar to what other APIs do.

We want to use this for masking extensions too, thus the export.
2019-09-30 10:52:06 +02:00
Alexander Larsson
5026f01153 Support multiple versions in required-flatpak metadata key
Support a list of versions that are supported. This will be useful
for e.g. the extra_data for extensions once that is backported to
1.2, because that will require it to say that it is supported for
> 1.2.5 in the 1.2 series and > 1.4.2 otherwise.

Closes: #3112
Approved by: alexlarsson
2019-09-18 14:55:38 +00:00
Matthew Leeds
3706695fb3 common: Fix misordering of branch and arch arguments
flatpak_dir_collect_deployed_refs() has the order of its "branch" and "arch"
arguments wrong, as does its only caller flatpak_list_deployed_refs().
When flatpak_list_deployed_refs() is called by add_extension() the arch
is put in the branch argument and vice versa. But then in the
implementation the arch is used as if it's the branch and vice versa, so
there's no functional bug here. Fix the order for readability.

Similarly, flatpak_list_unmaintained_refs() has the order wrong, but the
confusion is only within that function, since the order is correct in
its caller add_extension() and in the function it uses,
flatpak_dir_collect_unmaintained_refs(). So there's no functional bug
there either, but fix the order.

Closes: #3067
Approved by: alexlarsson
2019-09-09 10:20:33 +00:00
Alexander Larsson
51fe0307ef OCI: Handle manifests without annotations in index.json
When we export a manifest to the index, always pass the ref we're
targeting instead of relying on the org.opencontainers.image.ref.name
annotation, because that may not be set if we're using labels instead.

This is no big deal, because we know what ref we're handling anyway.

Closes: #2978
Approved by: alexlarsson
2019-09-06 12:49:40 +00:00
Alexander Larsson
58d9a257aa OCI: Use labels as commit metadata source as well as annotations
We now pull the image config as well as the manifest and fall
back on the labels field if the keys we're looking for are not
in the annotations field.

This lets us support docker manifests too, which don't have
annotations (but do have labels).

Closes: #2978
Approved by: alexlarsson
2019-09-06 12:49:40 +00:00
Debarshi Ray
e82efa8603 Trim unused shared library linkages from the session helper
The org.freedesktop.Flatpak user D-Bus service isn't just used by
flatpak(1) or applications running as Flatpaks. It's also used by
toolbox(1) for similar reasons:
 * To keep various configuration files inside the container
   synchronized with the host
 * To let the container request certain commands to be run on the host

The org.freedesktop.Flatpak D-Bus service itself doesn't need much in
the way of dependencies, but inherits a lot of unused shared library
linkages through the libflatpak-common.la convenience library. Removing
these unused shared libraries reduces the footprint of toolbox(1) for
those who care about such things. eg., Fedora CoreOS.

This commit brings down the number of shared libraries to 19 from 62.

Closes: #3052
Approved by: alexlarsson
2019-08-16 09:13:43 +00:00
Matthew Leeds
9a258e8a0c common: Use correct flag for ostree_repo_resolve_rev_ext()
Use the correct NONE flag, although both are 0 so this change won't make
any functional difference.

Closes: #3032
Approved by: alexlarsson
2019-08-15 19:42:45 +00:00
Matthew Leeds
f09049b7aa common: Fix branch validation docs
The docs for flatpak_is_valid_branch() say branch names can't start with
a digit but the implementation doesn't enforce this, and we have lots of
branches out in the wild that start with a digit (e.g. "3.32" and
"5.12"). So make the docs imply that branches can start with a digit.

The implementation also disallows "." as the leading character for a
branch, so add that to the docs. I'm just guessing that "." was intended
to be disallowed but it makes sense; otherwise the file we create named
with the branch would be hidden.

Closes: #3023
Approved by: alexlarsson
2019-08-15 09:07:14 +00:00
Matthew Leeds
3164c68e31 common: Fix double free of GError
Closes: #2919
Approved by: alexlarsson
2019-05-27 10:58:33 +00:00
Matthew Leeds
c0d5f1bfc8 Add FLATPAK_ERROR_REF_NOT_FOUND
This adds a new error to FlatpakError and uses it everywhere a ref is not
found, either locally or in a remote. This should hopefully be more useful than
the status quo of either returning FLATPAK_ERROR_INVALID_DATA or
G_IO_ERROR_NOT_FOUND or something else. Technically this is an API break but it
seems worth the risk. I checked gnome-software which does not seem affected by
this, and I checked eos-updater which does check for G_IO_ERROR_NOT_FOUND in
one place that will be affected by this but we can patch that.

Closes: #2895
Approved by: matthiasclasen
2019-05-13 10:57:11 +00:00
Matthew Leeds
253fcc6e35 Made wider use of flatpak_repo_resolve_rev()
As described in the last commit message, it makes sense to move toward
using flatpak_repo_resolve_rev() rather than ostree_repo_resolve_rev()
for a few reasons:
1) It means we can use OSTREE_REPO_PULL_FLAGS_MIRROR which causes refs
to be pulled into repo/refs/mirrors/ rather than repo/refs/remotes/
which fixes a few edge cases of using collection IDs[1]
2) It falls back to using ostree_repo_resolve_rev() if
ostree_repo_resolve_collection_ref() fails so we can maintain backwards
compatibility for repo/refs/remotes/
3) It distinguishes between remote and local refs, and in the local case
uses OSTREE_REPO_RESOLVE_REV_EXT_LOCAL_ONLY and
ostree_repo_resolve_rev_ext() to make sure we don't for example
accidentally use a remote's repo metadata rather than the local repo's
metadata for the "flatpak repo" command.

So this commit changes every instance of ostree_repo_resolve_rev() in
the codebase to flatpak_repo_resolve_rev().

[1] https://github.com/flatpak/flatpak/issues/1832

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Matthew Leeds
8cea78db1f dir: Fix an edge case of resolving collection-refs
In flatpak_dir_do_resolve_p2p_refs() after pulling a ref we use
ostree_repo_resolve_rev() and pass a refspec with the remote from which
the ref originated. This has a couple side effects, one good and one
bad:
1) The good side effect is that the attack I speculated about in this
comment[1] is not exploitable. Because if the ref in question is pulled
from any remote other than its origin (or a LAN/USB source using another
remote's keyring) it will not be found by ostree_repo_resolve_rev() and
the malicious commit will not be used.
2) The bad side effect is that there are some legitimate reasons a ref
could be pulled from another remote (say, a configured mirror), and in
those cases the pulled ref will not be found. So if I have remote A and
remote B both configured with the same collection ID, a ref installed
from one could be pulled from the other. See this issue[2] for a
concrete example.

The solution is to use OSTREE_REPO_PULL_FLAGS_MIRROR for the pull and
use ostree_repo_resolve_collection_ref() to resolve the ref. This is
done in the caller as well for consistency
(flatpak_dir_resolve_p2p_refs()). This fixes the bad side effect
described above and brings us a step closer to fixing issue #1832. This
also means the attack from #1447 is exploitable, but that is addressed
in a subsequent commit.

This change is conditional on a version check for OSTree 2019.2 because
we need this bug fix[3].

Also, add a helper function flatpak_repo_resolve_rev() which falls back
to using ostree_repo_resolve_rev() when
ostree_repo_resolve_collection_ref() fails, so we start to move toward
using /refs/mirrors/ but maintain backwards compatibility for
/refs/remotes/. A subsequent commit will make wider use of
flatpak_repo_resolve_rev() across the codebase; for now just use it for
the case described above.

[1] https://github.com/flatpak/flatpak/issues/1447#issuecomment-445347590
[2] https://github.com/flatpak/flatpak/issues/1832
[3] https://github.com/ostreedev/ostree/pull/1821

Closes: #2705
Approved by: alexlarsson
2019-05-09 09:12:26 +00:00
Alexander Larsson
6278420ba8 dir: Add flatpak_dir_compare_remote_filter and handle canonicalization
In general xa.filter being "" means don't filter, so that it can be
used to override-unset a previous filter. However, We canonicalize
to unset/NULL when comparing, returing, or setting the ostree config.

Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Alexander Larsson
e31023c32f Move flatpak_dir_parse_repofile to utils (and drop the unused dir)
Closes: #2884
Approved by: alexlarsson
2019-05-08 08:13:52 +00:00
Matthias Clasen
74d83d8111 Move dconf utilities to flatpak-utils
This is in preparation for writing some unit tests
for these functions. Apparently they are not too
trivial to get them wrong.

Closes: #2880
Approved by: alexlarsson
2019-05-07 06:11:18 +00:00
Alexander Larsson
d45c98c0bd utils: Add flatpak_appstream_xml_filter
This applies a ref filter to an appstreaml xml file

Closes: #2869
Approved by: alexlarsson
2019-05-06 13:58:58 +00:00