Commit Graph

320 Commits

Author SHA1 Message Date
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
Alexander Larsson
4b39b5c9c0 utils: Add utils to parse and apply ref filter globs
Filters are specified as a list of
op glob

where op can be allow or deny, and the blogs are partial refs
where * means anything in this part of the ref, and non-specified
trailing parts of the ref matches anything.

By default everything is allowed, but if you specify some
deny rules all that they match is denied, except if there is
an specific allow rule.

Internally this takes all the allow and deny globs and convert
them into two combined regular expressions.

Some examples:
 * - match anything
 app/* - match all apps
 runtime/* - match all runtimes
 app/*/x86_64 - match all x86-64 apps
 app/org.gnome.*/*/stable - match all stable gnome apps
 org.gnome.frogr* - match frogr and extensions

This means you can do a both whitelisting:
 deny *
 allow org.the.good.app*
Or blacklisting:
 deny org.the.bad.app*

Closes: #2869
Approved by: alexlarsson
2019-05-06 13:58:58 +00:00
Simon McVittie
62629b44b8 app, common: Use glnx_readlinkat_malloc()
readlink() and readlinkat() have weird semantics (they return the
number of bytes they would have written if there was enough space,
even if that's larger than the buffer), but glnx_readlinkat_malloc()
takes care to do the right thing in all situations.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2873
Approved by: matthiasclasen
2019-05-01 16:39:18 +00:00
Alexander Larsson
aa24754aa0 FlatpakError: Add more dbus error names
Closes: #2859
Approved by: alexlarsson
2019-04-26 08:00:27 +00:00
Alexander Larsson
3607e8f7f7 utils: Add flatpak_has_name_prefix helper
Closes: #2775
Approved by: alexlarsson
2019-04-12 08:59:35 +00:00
Ryan Gonzalez
89a6782c55 utils: Add flatpak_strv_merge
Closes: #2775
Approved by: alexlarsson
2019-04-12 08:59:35 +00:00
Alexander Larsson
4c9cc48572 build-update: Inject comment/description/homepage/icon into the summary file
This is the same that we do for the title, and will allow clients to
updating its copy of the fields.

Closes: #2814
Approved by: alexlarsson
2019-04-10 14:34:32 +00:00
Alexander Larsson
889e3b862a build-update-repo: Support setting comment/description/homepage/icon
This just sets the option in the "flatpak" group, similar to how
the title works. Nothing uses this yet.

Closes: #2814
Approved by: alexlarsson
2019-04-10 14:34:32 +00:00
Rafael Fontenelle
95e692794b Fix misspellings
Closes: #2807
Approved by: matthiasclasen
2019-04-08 12:50:42 +00:00
Alexander Larsson
2d2ad94ea2 appstream: Fix permission of compat symlink 2019-03-27 11:02:07 +01:00
Alexander Larsson
4c8409ed6a appstream: Create symlinks for the icons/$origin subdirectory
For compatibility with libappstream we create a $origin ("flatpak")
subdirectory with symlinks to the size directories thus matching the
standard merged appstream layout if we assume the appstream has
origin=flatpak, which flatpak-builder creates.

See https://github.com/ximion/appstream/pull/224 for details.

Fixes https://github.com/flatpak/flatpak/pull/2779

Closes: #2789
Approved by: alexlarsson
2019-03-27 09:38:57 +00:00
Alexander Larsson
7df32ae388 utils: Add flatpak_mtree_create_symlink()
Closes: #2789
Approved by: alexlarsson
2019-03-27 09:38:57 +00:00
Alexander Larsson
2bb84cc522 More efficient appstream generation
Rather than creating a real temp directory and
then commiting that we generate an in-memory mtree
which mostly refers to pre-existing icon file
objects, and then the newly created appdata xml.

Closes: #2753
Approved by: alexlarsson
2019-03-12 09:08:12 +00:00
Alexander Larsson
e3357bacad utils: Add some mtree helpers and rename create_root to something more correct
Closes: #2753
Approved by: alexlarsson
2019-03-12 09:08:12 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
a0d3d65476 Remove extra newlines near curly braces
Edit uncrustify.cfg to add options to remove extra newlines near opening
and closing braces, and run uncrustify again.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Alexander Larsson
28e96288c4 Fix issues with XDG_RUNTIME_DIR being /var/run which is a symlink
Whenever we use $XDG_RUNTIME_DIR and expose it somehow in the sandbox
we fully resolve the path, because if (as happens on gentoo for instance)
it contains /var/run -> ../run, then flatpak thinks we need to
add the /var/run symlink in the runtime even though we already
exposed that.

Closes: #2710
Approved by: matthiasclasen
2019-02-20 19:43:28 +00:00
Matthew Leeds
4607739677 Delete stray semicolons
Closes: #2703
Approved by: matthiasclasen
2019-02-14 06:14:59 +00:00
Alexander Larsson
7c9368d100 CLI: Handle consoles reporting zero size
For whatever reason, in the buildbot environment the TIOCGWINSZ
ioctl returns a 0x0 size, which causes a divide by zero. We
handle this by returning a default 80x24 size.

Closes: #2685
Approved by: alexlarsson
2019-02-06 09:31:45 +00:00
Alexander Larsson
f0c404d104 Add backported version of g_date_time_new_from_iso8601
Closes: #2642
Approved by: matthiasclasen
2019-01-28 16:36:38 +00:00
Matthias Clasen
a0d579bb9b Add utilities to switch in and out of raw mode
Closes: #2638
Approved by: alexlarsson
2019-01-25 12:03:47 +00:00
Matthias Clasen
7b94d827d7 Allow multiple name segments after prefix
This lets us export D-Bus service files for
names like org.foo.Bar.Application.Tracker.service
when the app-id is org.foo.Bar.

Closes: #2615

Closes: #2616
Approved by: alexlarsson
2019-01-21 08:27:09 +00:00
Matthew Leeds
1ea2864088 Remove no longer needed #define directives
Now that we depend on libostree 2018.9, these aren't needed.

Closes: #2593
Approved by: matthiasclasen
2019-01-15 20:02:17 +00:00
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