Commit Graph

293 Commits

Author SHA1 Message Date
Matthias Clasen
3598cce951 Add utilities for showing/hiding the cursor
Closes: #2570
Approved by: alexlarsson
2019-01-14 11:41:42 +00:00
Matthias Clasen
e8e31edea2 Make number parsing more robust
We were parsing 2-6 with an out-of-range end value
as 2. Fix that.

Closes: #2578
Approved by: matthiasclasen
2019-01-12 02:05:05 +00:00
Matthias Clasen
b098d683e5 Export flatpak_parse_numbers
Export this function privately, so we can test it.

Closes: #2578
Approved by: matthiasclasen
2019-01-12 02:05:05 +00:00
Matthias Clasen
402e2020d8 Add a way to force fancy output on
This will be used for testing the table printer formatting.

Closes: #2498
Approved by: matthiasclasen
2019-01-11 18:32:44 +00:00
Matthias Clasen
9ff489519c Add a utility to prompty for multiple choices
This is a variant that allows to enter multiple numbers,
either individually, or as range. Parts can be separated
by space or comma. Examples:
1-3,5
1 2 4
6

Closes: #2559
Approved by: alexlarsson
2019-01-11 15:57:44 +00:00
Matthias Clasen
86f3077be3 Nicer formatting for many choices
'flatpak install sdk' offers me 34 choices, so double digits
seem very realistic here. Make the numbers line up in this
case.

Closes: #2476
Approved by: matthiasclasen
2019-01-07 23:42:19 +00:00
Alexander Larsson
1ff83a8a60 utils: Add flatpak_compare_ref
This compares the refs on a per-segment basis, so
org.foo.bar comes before org.foo.bar.suffix

Closes: #2450
Approved by: alexlarsson
2018-12-20 15:50:07 +00:00
Alexander Larsson
9a37475e76 deploy-data: Prepare for versioning
This adds a version to the deply data format, assuming that if
there is no version then it is 0. Also extends all loaders so that
it can specify a required version, with the goal that most users
are fine with old versions, but if you need more recent we have
a (costly) conversion process to upgrade (will be added later).

The library and the flatpak list/info commands require the most
current version for full info, all other users can use any version.

Also, as part of this we now pass the ref to flatpak_load_deploy_data()
as this will be needed later for the backwards compat support.

Closes: #2409
Approved by: alexlarsson
2018-12-19 15:45:35 +00:00
Matthias Clasen
a5b9b59c7b Add a utility for formatting choices
This prints the common pattern of

Choices:

  1) bla
  2) bla

with consistent formatting, so we don't have
to worry about matching newlines and spaces
all over the codebase.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
ba92cb7126 Add a way to disable fancy output
We disable fancy output when we can detect it,
but it is a good idea to have a way to explicitly
opt out too.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Matthias Clasen
732ee49fee Add some tty handling utilities
Add a function to query the window size and cursor position,
and definitions for some more ANSI escape sequences that we
will use in the following commits.

Closes: #2371
Approved by: alexlarsson
2018-12-18 14:50:26 +00:00
Aleix Pol
b6eddbccff Don't use the last percentage if the total size changed
It happens sometimes that the first processed total is 1, when this gets
downloaded we have 100% already and then the total changes making this
percentage faulty.
This makes the progress regress sometimes, but I'd say it's better than
a permanent, ficticious number.

Fixes #2428
2018-12-14 18:27:17 +01:00
Alexander Larsson
bfa9fabd52 Fix leak in flatpak_get_current_locale_langs() 2018-12-10 11:50:55 +01:00
Alexander Larsson
185fe43fb7 extra_data: In system-helper case, canonicalize uid/gid
Make sure all files produced by apply_extra are owned by root.

Closes: #2398
Approved by: matthiasclasen
2018-12-07 20:38:45 +00:00
Matthias Clasen
b8cad064eb Add our own polkit listener implementation
This lets us respect the fancy output setting, and
it lets us do some other things that make it better
integrated.

Closes: #2379
Approved by: alexlarsson
2018-12-06 15:01:14 +00:00
Patrick Griffis
182b2674aa Add condition for XDG_CURRENT_DESKTOP checks
Firstly this changes the "download-if" and "enable-if" properties
to accept a `;` separated list of multiple conditions.

Secondly it adds `on-xdg-desktop-*` which will check against
the XDG_CURRENT_DESKTOP env var (case-insensitively).

This is done entirely for the Qt GNOME Platform so it can do this:

```
"org.kde.PlatformTheme.QGnomePlugin" : {
  "download-if": "on-xdg-desktop-GNOME;on-xdg-desktop-GNOME-classic"
}
```

Closes: #1436
Approved by: matthiasclasen
2018-11-17 23:42:49 +00:00
Alexander Larsson
35598f46a5 extra-data: Don't allow creating files with non-canonical permissions in apply_extra
When installing a flatpak with extra-data we execute the apply_extra
script from the flatpak to extract the extra data files we
created. This script runs with very little filesystem acces, but it
does have write permissions to the location that will eventually be
/app/extra in the finished flatpak. This is especially problematic for
the systemwide install case, because the script is then run as root,
so it could potentially create a setuid file there.

Such a file would not be usable inside the sandbox (because setuid is
disabled in the sandbox), but it could potentially be a problem if the
user could be tricked into running the file directly on the host. This
is the same behaviour as e.g. rpm or deb which both can install setuid
files, but we want to guarantee that flatpak is better than that.

The fix is to run the script with all capabilities dropped (bwrap
--cap-drop ALL) which removes a bunch of possible attack vectors (for
instance setting file capabilities). However, even without
capabilities, it is possible for a user to make any file setuid to the
same user, so we also need to canonicalize the permissions of all
files generated by running the script.

Additionally, while running the script we set the toplevel directory
only be accessible to the user, meaning we will not temporarily leak
any potential setuid files to other users.

Note, this commit actually goes furthen than that and completely
canonicalizes all the file permissions to be the same as those
otherwise used by flatpak. For example we fix up cases where the
script creates files writable or unreadable by non-root users.

Closes: #2323
Approved by: alexlarsson
2018-11-16 10:20:20 +00:00
Matthew Leeds
a22dfbd7c1 Default to only choice in multiple choice prompts
This commit implements a feature in the multiple choice prompt that
mirrors the behavior in the yes/no prompt where it can default to "yes"
when the user only presses Enter. In the case of the multiple choice
prompt, it only defaults to the first choice on Enter if there's only
one option (e.g. you're asked if you want to install from the "flathub"
remote as opposed to being asked to choose between the "flathub" and
"eos-apps" remotes).

This feature can be turned off on a per-prompt basis if we want explicit
user input for something but I didn't find that necessary for any of the
existing prompts.

Also note that as with the yes/no prompt defaulting to yes on Enter,
this only applies for interactive terminals. If Flatpak is being run by
a script no choice will be made automatically.

This should save users unnecessary keystrokes, such as when they use
"flatpak install devhelp" and are asked to confirm that the Flathub
remote is the one to use (now they can just press Enter).

Closes: #2288
Approved by: matthiasclasen
2018-11-06 02:48:06 +00:00
Matthew Leeds
7b1a5c4fb9 Allow yes/no prompt to default to yes
Currently when the Flatpak command line prompts the user with a yes or
no question, the user must type "y" or "n" to respond. This commit
changes it so that the prompt can assume "yes" if the user just presses
Enter. In that case the prompt ends in "[Y/n]" rather than "[y/n]". If
there are some operations that are considered dangerous, we can still
require explicit user input on those, but as far as I can tell those
criteria don't apply to any existing prompts.

This behavior of allowing the user to just press Enter is consistent
with how apt works for example.

Note that this is distinct from the "--assume-yes" option we have, since
that won't prompt the user at all when a decision needs to be made.

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthew Leeds
7c86f12262 Move Levenshtein distance implementation
This moves the implementation of the Levenshtein "edit distance"
algorithm from app/ to common/ so it can be used in an upcoming commit.

Closes: #2113
Approved by: matthiasclasen
2018-10-31 22:48:56 +00:00
Matthias Clasen
2bbdd7712a Remove unused functions
Neither flatpak_variant_builder_init_from_variant nor
flatpak_gvariant_new_empty_string_dict are used anywhere.

Closes: #2252
Approved by: matthiasclasen
2018-10-23 20:10:37 +00:00
Matthias Clasen
12b5c36ec9 Remove an unused function
There were no calls to flatpak_zero_mtime anywhere.

Closes: #2245
Approved by: alexlarsson
2018-10-15 13:39:36 +00:00
Alexander Larsson
6dec266189 utils: Add flatpak_get_timezone()
This extracts the timezone from the symlink in /etc/localtime as
specified in e.g.
  https://www.freedesktop.org/software/systemd/man/localtime.html

If this doesn't exist, or is not a symlink, then it uses the old
debian /etc/timezone as specified in
  https://wiki.debian.org/TimeZoneChanges

If nothing else works it falls back to UTC.

Closes: #2214
Approved by: alexlarsson
2018-10-10 15:12:21 +00:00
Matthias Clasen
40f413836a Drop xdg-app migration support
It has been long enough. It is unlikely that we can still
find any xdg-app installations in the wild.
2018-10-10 12:20:27 +02:00
Matthias Clasen
740b1d696c utils: remove unused functions
These are not used at all.

Closes: #2206
Approved by: alexlarsson
2018-10-08 08:25:10 +00:00
Alexander Larsson
a94eea8cc7 build-update-repo: Add appstream2 to the metadata cache
The old "appstream" is there already, and this allows us to get
things like download size info for it.

Closes: #2182
Approved by: alexlarsson
2018-10-04 06:58:23 +00:00
Matthias Clasen
868552cb1f Fix localization
On the library side, we need to include gi18n-lib in order
to use dgettext for _().

Closes: #2163

Closes: #2150
Approved by: alexlarsson
2018-10-02 06:21:49 +00:00
Matthias Clasen
e9bf1c3f75 Replace a warning with an error
It is not really nice to have g_warnings pop out of
the library left and right, they should be replaced
by proper errors as far as possible. This is a small
start.

Closes: #2150
Approved by: alexlarsson
2018-10-02 06:21:49 +00:00
Matthias Clasen
56d975f8c4 Add a few more error codes
Add FLATPAK_ERROR_INVALID_DATA and use if for cases where
the incoming data for an update or install is faulty, and
add FLATPAK_ERROR_UNTRUSTED, FLATPAK_ERROR_SETUP_FAILED and
FLATPAK_ERROR_EXPORT_FAILED to cover more error conditions.

Closes: #2150
Approved by: alexlarsson
2018-10-02 06:21:49 +00:00
Matthias Clasen
5b9d8e5ab8 Translate more error messages
As a rule of thumb, if we use a FlatpakError, the message
is probably worth translating.

Closes: #2150
Approved by: alexlarsson
2018-10-02 06:21:49 +00:00
Matthias Clasen
38eebef90c Avoid flatpak_fail in ref parsing
Add an error code for invalid refs, and use it when
composing or decomposing refs.

Closes: #2150
Approved by: alexlarsson
2018-10-02 06:21:49 +00:00
Matthias Clasen
2290099ead Add a new utility function for finding deploys
flatpak_find_deploy_for_ref_in is a variation of
flatpak_find_deploy_for_ref that allows to restrict
what installations to search in.

Closes: #2158
Approved by: alexlarsson
2018-10-01 13:05:12 +00:00
Matthias Clasen
14cd84fa68 Be stricter about exports
We were exporting files in subdirectories of all the common
directories. This only really makes sense for icons. For
desktop files, D-Bus service files and mime types, we should
only export from the exact directory itself.

Note that this makes us no longer support the obsolescent
vendor-prefix convention of the desktop entry spec, which was
only relevant for KDE4 and breaks app-id matching.

Closes: #2142

Closes: #2152
Approved by: alexlarsson
2018-10-01 11:26:34 +00:00
Matthew Leeds
48ceed70be Replace xa.collection-id with ostree.deploy-collection-id
Currently Flatpak reads a repo metadata key called "xa.collection-id" to
decide whether to configure a collection ID on a remote. This commit
drops support for xa.collection-id and replaces it with
ostree.deploy-collection-id, which is a key defined by OSTree but so far
only implemented here.

The reason for the change is so that collection IDs can only be deployed
to users running recent versions of Flatpak and OSTree. The current
situation is that Endless wants to deploy collection IDs (and therefore
support for doing USB updates) to users, but servers such as Flathub
can't safely set xa.collection-id in their metadata, because many users
are still using old versions of Flatpak and OSTree[1] which would hit
various bugs[2][3][4] on the P2P code paths that are enabled by
collection IDs. Defining a new key means that only users running
recent (as-yet-unreleased) versions of Flatpak and OSTree will pay
attention to it and deploy the collection ID, leaving the users on old
versions unaffected.

The reason this metadata key is being defined at the level of OSTree
instead of Flatpak, is that OSTree may want to implement it in the
future.

The functionality of deploying a collection ID by setting the
"deploy-collection-id" key in the config on the server side (which in
turn causes ostree.deploy-collection-id to be set) is already covered by
the unit tests in test-update-remote-configuration.sh; this commit just
tweaks them to use the new key.

Another solution I proposed to this problem was to have a key
"eos.collection-id" which would only be understood by the Endless fork
of Flatpak, and use that temporarily until enough people are running
recent versions of Flatpak, at which point "xa.collection-id" can be
used. But this solution (abandoning xa.collection-id upstream) allows us
to avoid that migration step and leave users on old versions of Flatpak
completely unaffected.

[1] https://ahayzen.com/direct/flathub.html#downloadsbyflatpakstacked
[2] https://github.com/ostreedev/ostree/commit/e4e6d85ea
[3] https://github.com/flatpak/flatpak/commit/5813639f
[4] https://github.com/flatpak/flatpak/commit/5b21a5b7
2018-09-19 17:23:08 -07:00
Alexander Larsson
d16b393a34 bundles: Fix leak
The collection id check that was added leaks if we were able
to read the collection-id, but then it was ignored.

Closes: #2093
Approved by: alexlarsson
2018-09-13 09:53:25 +00:00
Matthew Leeds
e4befb12ac common: Better handle NULL collection IDs
Currently if you install from a flatpak bundle that doesn't have a
collection ID set or from a flatpakref file that has the CollectionID
key set to the empty sting, you end up with an invalid configuration on
the origin remote created. This is because the collection_id parameter
of flatpak_dir_create_origin_remote() is set to the empty string, not
NULL, and create_origin_remote_config() then only checks for NULL when
deciding whether to set gpg-verify-summary to true or false. Then
because there's no collection ID configured but gpg-verify-summary is
set to false, you get the error "Can't pull from untrusted non-gpg
verified remote" when trying to pull related refs or update the app.

This commit fixes the bug by checking for the empty string when the
collection ID is read from a bundle or ref file, and collapsing that
into NULL.

Closes: #2081
Approved by: alexlarsson
2018-09-12 07:07:13 +00:00
Alexander Larsson
a7c88682d3 Don't use G_NUMBER_PARSER_ERROR as it requires a newer glib
Closes: #1987
Approved by: alexlarsson
2018-08-20 10:42:21 +00:00
Matthew Leeds
fb989a62a1 common: Add and use FLATPAK_ERROR_DOWNGRADE
This will be useful in distinguishing downgrade errors from other
errors, which I'll need in the next commit.

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Matthew Leeds
1ff0cf8c16 common: Register all FlatpakError codes as D-Bus errors
This will allow us to return anything in the FlatpakError domain using
g_dbus_method_invocation_return_gerror().

Closes: #1965
Approved by: alexlarsson
2018-08-20 06:58:01 +00:00
Matthew Leeds
c3a0617557 NULL initialize g_auto variables
It's a good idea to NULL initialize g_autoptr/g_autofree variables, so
we can be sure uninitialized memory isn't passed to g_free or similar.

Closes: #1968
Approved by: alexlarsson
2018-08-17 08:06:51 +00:00
Alexander Larsson
4b8624e705 flatpak_yes_no_prompt: Fix leak of formated string
Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
ebb3ff532d Fix GVariant leak
ostree_async_progress_get_variant returns a ref, so free it.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Alexander Larsson
7df3f9f1ba appstream: Fix leak
Move some autoptr to the inner scope of the loop over each
appstream branch to avoid leaking.

Closes: #1964
Approved by: mwleeds
2018-08-13 21:31:09 +00:00
Owen W. Taylor
4dfa7721bb Remove unused etag functionality
Checking the registry against a previous etag is now handled inside
flatpak_cache_http_uri(), so remove the etag parameters that were
previously passed around in various places for simplicity.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Owen W. Taylor
cd6a10cb66 flatpak-utils-http.c: Split HTTP functionality into a separate file
In preparation for extending the HTTP downloading function to include
caching, split HTTP related utilities into a separate file with a
separate header.

Closes: #1910
Approved by: alexlarsson
2018-08-09 12:49:35 +00:00
Umang Jain
d34d117ae4 utils: Copy g_ascii_string_to_unsigned from glib-2.54.0
This avoids the glib's version bump needed for the subsequent min-free-space-size
porting patches.

Closes: #1912
Approved by: alexlarsson
2018-08-08 14:29:45 +00:00
Richard Hughes
0afef8a38a Fix a memory leak when calling flatpak_build_file()
Closes: #1898
Approved by: mwleeds
2018-07-12 13:14:03 +00:00
Alexander Larsson
aecc6285d6 utils: Add flatpak_fail_error that takes an error code
This makes it easy to return FlatpakErrors
2018-07-10 19:26:16 +02:00
Alexander Larsson
3f4518b15c Run uncrustify
Closes: #1870
Approved by: alexlarsson
2018-07-08 10:05:37 +00:00
Alexander Larsson
491d174879 Make p2p build non-optional
Closes: #1800
Approved by: alexlarsson
2018-06-19 18:10:56 +00:00