Commit Graph

1800 Commits

Author SHA1 Message Date
Alexander Larsson 96eed95720 repo: Allocate a tmpdir for each OstreeFetcher to isolate concurrent downloads
This way two pulls will not use the same tmpdir and accidentally
overwrite each other. However, consecutive OstreeFetchers will reuse
the tmpdirs, so that we can properly resume downloading large objects.

https://bugzilla.gnome.org/show_bug.cgi?id=757611
2015-12-14 08:39:11 +01:00
Alexander Larsson f771461b4a repo: Use per-transaction staging dir
Concurrent pulls break since we're sharing the staging directory for
all transactions in the repo. This makes us use a per-transaction directory.

However, in order for resumes to work we first look for existing
staging directories and try to aquire an exclusive lock for them. If
we can't find any staging directory or they are all already locked,
then we create a new one.

https://bugzilla.gnome.org/show_bug.cgi?id=757611
2015-12-14 08:38:51 +01:00
Alexander Larsson be19c88861 repo: Add _ostree_repo_allocate_tmpdir helper
This creates a subdirectory of the tmp dir with a selected prefix,
and takes a lockfile to ensure that nobody else is using the same directory.
However, if a directory with the same prefix already exists and is
not locked that is used instead.

The later is useful if you want to support some kind of resumed operation
on the tmpdir.

touch reused dirs

https://bugzilla.gnome.org/show_bug.cgi?id=757611
2015-12-14 08:37:55 +01:00
Colin Walters 76f4507557 build: Delete generated parse-datetime.c file, use AM_V_GEN
Bison is a well known external dependency, so just require it.
Including the generated content in git means it may or may not
be regenerated based randomly on timestamps, etc.

Also use `$(AM_V_GEN)` so we get prettier output.
2015-12-07 10:33:23 -05:00
Colin Walters 8ba90a3341 cmdline: Fatally error if the timestamp in a commit is invalid
Previously we were just ignoring this, which hid a bug in
an earlier commit that generated them.

Also change the `commit` program to use both APIs - this
involves extra code, but not too much.

This way, reverting the fix with this on top caused the test suite to
fail.  Adding an active test for this would need a custom test program
using the C API, or adding a cmdline flag to the client, neither of
which quite seemed worth it.
2015-12-04 11:26:07 -05:00
Giuseppe Scrivano 335ea3f339 parse-datetime: use the module from gnulib
Use the parse-datetime module from gnulib, and adapt it to not require
other modules as portability is not really an issue for us.

DATE can be specified in different formats, such as: "-1 week", "last
monday", "1 week ago".

Include the generated .c file in the repository so to not add another
dependency to Bison.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-12-04 11:10:46 -05:00
Colin Walters ed9f5ce031 gpg-verifier: Fix compiler warning 2015-12-04 09:51:14 -05:00
Matthew Barnes 94bc9765d5 repo: Fix backwards timestamp in ostree_repo_write_commit()
ostree_repo_write_commit_with_time() converts the timestamp to
big-endian byte order.

ostree_repo_write_commit() was also doing this when calling
ostree_repo_write_commit_with_time(), resulting in a corrupted
commit object (timestamp bytes were backwards).

Recent regression in 14ffd7022a
2015-12-03 12:43:52 -05:00
Matthew Barnes a02174b0ba remote: Print full refspec in "ostree remote refs"
Just to make copy-and-paste a little easier, as I often use this command
immediately before rebasing.

 e.g.

 # ostree remote refs fedora-atomic
 fedora-atomic:fedora-atomic/f23/x86_64/docker-host
 fedora-atomic:fedora-atomic/f23/x86_64/testing/docker-host
 ^^^^^^^^^^^^^^ (this part is new)

 # rpm-ostree rebase fedora-atomic:fedora-atomic/f23/x86_64/testing/docker-host
2015-12-02 23:13:44 -05:00
Matthew Barnes 581b7d6183 fetcher: Remove "total_requests" counter
Incremented, but not used for anything.
2015-12-01 12:34:34 -05:00
Matthew Barnes 97efe12ac6 fetcher: Remove "sending_messages" hash table
Vestige of ostree_fetcher_query_state_text(), removed last year.
2015-12-01 12:34:28 -05:00
Matthew Barnes 74d8e5f159 trivial-httpd: Avoid SoupBuffer when there's no content
This was supposed to be merged into the previous commit, but I
messed up.
2015-11-23 14:30:31 -05:00
Matthew Barnes df75fc232a repo: Never delete .commitmeta files
Do not delete a .commitmeta file after removing the last metadata entry.
This way a client will pull the empty .commitmeta file and overwrite old
metadata as expected.

https://bugzilla.gnome.org/750459
2015-11-23 14:22:45 -05:00
Matthew Barnes 5307af5a7a repo: Validate checksums have correct length
ostree_checksum_bytes_peek() can return NULL if the checksum has an
incorrect length (most likely from disk corruption) but most callers
are not prepared to handle this and would likely crash.

Use ostree_checksum_bytes_peek_validate() instead, which sets a
GError on an invalid checksum.
2015-11-17 20:35:54 -05:00
Giuseppe Scrivano 68f70d8e74 commit: add --timestamp=TIMESTAMP
It allows to override the timestamp of the commit.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 11:07:55 +01:00
Giuseppe Scrivano 14ffd7022a libostree: add new API ostree_repo_write_commit_with_time
It extends ostree_repo_write_commit as it permits to override the
commit timestamp.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 11:07:55 +01:00
Giuseppe Scrivano b393e5a2e9 ostree: do not print the usage on each G_IO_ERROR_NOT_SUPPORTED
It may have a different meaning, and the usage screen is not helpful.

Print the usage screen only when the command is not found.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 11:07:55 +01:00
Giuseppe Scrivano f506644830 pull: make slightly clearer when failing for missing xattrs support
It is not clear why pull fails on tmpfs.  The additional message might
be helpful.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 11:07:55 +01:00
Giuseppe Scrivano f56688da71 prune: add --keep-younger-than=DATE
The format used for DATE is "%Y-%m-%d %H:%M:%S %z"

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 11:07:38 +01:00
Giuseppe Scrivano 0dee70bcd6 fsck: create a tombstone when the parent is missing
Change the previous logic that a tombstone commit was created when
a partialcommit is found.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 10:57:33 +01:00
Giuseppe Scrivano 0aa836c205 prune: add --delete-commit
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-16 10:57:33 +01:00
Matthew Barnes a19a112d9d libostree: Fix a couple compiler warnings 2015-11-12 14:32:07 -05:00
Alexander Larsson 1c056eb282 deltas: Support including detached metadata in static deltas
This is very useful for the inline-parts case, as you can then include
detached signatures in a single file representing the commit.

It is not as important for the generic pull case, as the detached
metadata is only a single small file. Additionally the detached
metadata is not content referenced and may change after the static
delta file was created, so we need to pull the latest version anyway.
2015-11-10 08:56:16 +01:00
Alexander Larsson 598afd5030 pull: Verify checksums from static deltas unless gpg signed summary
Otherwise untrusted repos can lie about the commit ids.
2015-11-10 08:56:15 +01:00
Alexander Larsson ec56fea821 deltas: Support passing filename to ostree_repo_static_delta_execute_offline
If you pass a diriectory it will look for the "superblock" child, otherwise
it will use the file as the superblock. I need this in xdg-app to be able
to install any filename as a bundle.
2015-11-10 08:56:15 +01:00
Alexander Larsson dac57b6410 deltas: Support passing filename to delta generator 2015-11-10 08:56:15 +01:00
Alexander Larsson b22b859dc5 deltas: Make min-fallback-size 0 actually disable fallbacks
This is what the docs specify.
2015-11-10 08:56:14 +01:00
Alexander Larsson 78f14555c8 deltas: Verify checksums in apply-offline unless skip_validate is TRUE 2015-11-10 08:56:14 +01:00
Alexander Larsson 7a4fb1b2f1 Add _ostree_repo_open|commit_untrusted_content_bare
Also renames OstreeRepoTrustedContentBareCommit to
OstreeRepoContentBareCommit so that it can be used by both.

This will be needed when we introduce checksum verification of objects
in static deltas.
2015-11-10 08:56:14 +01:00
Alexander Larsson 3fa3e12e02 static-delta apply-offline: Don't skip validation
This makes no sense, at least by default.
2015-11-10 08:56:13 +01:00
Alexander Larsson e418acb31b delta: Ensure the from commit exists when applying static delta 2015-11-10 08:56:13 +01:00
Alexander Larsson eaa678eaa4 deltas: Make apply-offline only read the parts once
No need to read() the file for the checksum if we then directly mmap it.
Instead we just mmap it initially and checksum from that.
2015-11-10 08:56:13 +01:00
Alexander Larsson ccb77d3bd8 static-deltas generate: Add --inline option to CLI tool 2015-11-10 08:56:12 +01:00
Alexander Larsson 11a79220e2 static deltas: Add support for inline-parts
In this mode the parts are stored in the metadata of the main delta
superblock file.  This can be useful if you want a single-file delta
for easy transport, or for http in the case the delta is very small.
2015-11-10 08:56:12 +01:00
Alexander Larsson 30768a979f generate-static-delta: Support min-fallback-size 0 to disable fallbacks 2015-11-10 08:56:12 +01:00
Giuseppe Scrivano 29c425e742 fsck: add argument --add-tombstones
It is used to create tombstones for missing commits

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-03 09:53:38 +01:00
Giuseppe Scrivano 646fe139e6 repo: create a tombstone commit when deleting a commit
When a commit is deleted and the repo is configured to use tombstone
commits, create one.  Delete the tombstone file only if the commit is
pulled again.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-03 09:53:38 +01:00
Giuseppe Scrivano 76c5cc07db pull: add support for tombstone commits
Add a new object type: OSTREE_OBJECT_TYPE_TOMBSTONE_COMMIT that is
used when a commit was intentionally removed.

If the remote repository doesn't use tombstone commits, do not fail on
a missing commit (change 0b795785dd).

When the remote repository uses tombstones, if a commit cannot be
found, check if the tombstone file is present and fail if it is not
present.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-03 09:53:38 +01:00
Giuseppe Scrivano 048c27588a core: use OSTREE_OBJECT_TYPE_LAST instead of OSTREE_OBJECT_TYPE_COMMIT
OSTREE_OBJECT_TYPE_LAST holds the value of the last element in the enum.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-11-03 09:53:38 +01:00
Colin Walters 7bf138b036 init-fs: Explicitly set /tmp to 01777
I think most people were using tmpfs-on-tmp and so didn't hit this.

See https://bugzilla.redhat.com/show_bug.cgi?id=1276775
2015-10-30 17:11:09 -04:00
Colin Walters 723705b803 sysroot: Write symlinks before calling fsync(), then rename after
There might be a race here in that we create new symlink files *after*
calling `syncfs`, and they are not guaranteed to end up on disk.

Rework the code so that we create symlinks before, and then only
rename them after (and `fsync()` the directory for good measure).

Additional-fixes-by: Giuseppe Scrivano <gscrivan@redhat.com>
Tested-by: Giuseppe Scrivano <gscrivan@redhat.com>

This still needs verification that we're fixing a real bug; but I'm
fairly confident this won't make the fsync situation worse.

https://bugzilla.gnome.org/show_bug.cgi?id=755595
2015-10-25 11:46:41 -04:00
John Hiesey 70c07a6338 static-delta: Fix annotation on ostree_repo_list_static_delta_names
out_deltas should be (transfer-container)
2015-10-21 21:09:23 -04:00
Daniel Drake 598530daf4 prepare-root: set up /boot bind-mount for single partition systems
When booting from a system with /boot on the main partition, set up
an appropriate bind mount during boot. The ostree runtime binary
expects to be able to access the bootloader configs at /boot.

See: https://mail.gnome.org/archives/ostree-list/2015-July/msg00015.html

https://bugzilla.gnome.org/show_bug.cgi?id=756267
2015-10-15 21:36:21 -04:00
Matthew Barnes 2210a79bfa upgrade: Add --override-commit=CHECKSUM option
Adds an entry to the origin file to force the OstreeSysrootUpgrader to
pull and deploy the given checksum.

  [origin]
  override-commit=CHECKSUM

If the option is not given, any such entry is explicitly removed from
the origin file to ensure we upgrade to the latest available commit.
2015-10-13 12:34:57 -04:00
Matthew Barnes 39b732ffaa upgrader: Allow overriding the commit to pull
Upgrader now looks for an "override-commit" key in the origin file
with a commit checksum, which causes the upgrader to pull and deploy
the specified commit rather than the latest available commit on the
origin refspec.
2015-10-13 12:34:56 -04:00
Matthew Barnes 41ab26356c upgrader: Add ostree_sysroot_upgrader_dup_origin()
Convenience function returns a copy of the origin file, useful when
modifying it.
2015-10-13 12:34:56 -04:00
Gatis Paeglis b69a88b111 Don't require /boot/uEnv.txt for u-boot support
The current code checks if /boot/uEnv.txt is a symlink to
decice if sysroot requires u-boot support. Why this is bad:

There are 2 ways to provide a custom env to u-boot from user space:

1) A compiled binary that is sourced from u-boot.
2) A text file (usually /uEnv.txt) that is imported into env from u-boot.

The current OSTree u-boot integration code was designed with the 1st
case in mind.

Many bootscripts provided by an embedded device vendors expect
to find uEnv.txt in the top level directory, it is often hardcoded
when building u-boot and is difficult to change later on. Or in other
cases it is stored in read-only memory so changing it would require
re-flushing boot loader with a new env. So the issue here is that
OSTree's and vendor uEnv.txt want to exist and the same path and OSTree
would throw away any changes added to /uEnv.txt by user on the next
upgrade/deploy.

This patch "hides" away the OSTree's env file loader/uEnv.txt from users
who are used to edditing uEnv.txt at the top level directory. Now to add
OSTree support on such boards you can simply add a custom logic in uEnv.txt
that loads ostree env from /loader/uEnv.txt

This change is backward compatible with the previous ostree releases and
solves the issue described in:

https://bugzilla.gnome.org/show_bug.cgi?id=755787
2015-10-12 10:22:12 -04:00
Leandro Santiago 5e98820b57 commit: Improve variable name
Using `commit_subject` instead of `arg` is clearer as it can refer to
a directory, archive or ref.

This is just an aesthetic change in the source code, having no impact
anywhere else.
2015-10-10 16:45:27 -04:00
John Hiesey 60e5529ba0 static-delta: Set error on bsdiff failure
bsdiff can fail when generating static deltas, particularly if
not enough memory is available. Set error properly when this happens.

https://bugzilla.gnome.org/show_bug.cgi?id=756260
2015-10-10 10:38:01 -04:00
John Hiesey f2b4a9e107 static-delta: Don't run bspatch when output object already exists
There is already a check that the destination object does not
exist in all other cases when processing an incoming static delta.
However, the bspatch case would still try to run and fail. Add
an analogous check to that case as well.

https://bugzilla.gnome.org/show_bug.cgi?id=756260
2015-10-10 10:31:10 -04:00
John Hiesey dd35e1b9cd static-delta: Handle LZMA_BUF_ERROR returned by zlib
zlib can return LZMA_BUF_ERROR, which indicates that either
the input or output buffer has size zero. This case should cause
the correct error to be passed back from g_converter_convert
to expand the relevant buffer. Since this error is ambiguous
as to which buffer is too small, an explicit check on the
output buffer size is added as well.

https://bugzilla.gnome.org/show_bug.cgi?id=756260
2015-10-10 10:27:17 -04:00
Matthew Barnes 0b795785dd pull: Recover from missing commits in recursive pulls
When traversing parents, do not fail on a missing commit.  We may
be pulling from a partial repository that ends in a dangling parent
reference.
2015-09-25 11:07:28 -04:00
Colin Walters bab6503b69 sysroot: Cleanup refs and prune even on last undeployment
I was working on a different test, and ended up being very confused at
the behavior where removing the last deployment didn't remove the last
`ostree/X/X/X` ref pointing to its commit.

There's no reason to special case the last undeployment AFAIK, and the
existing code handles this.
2015-09-24 12:25:23 -04:00
Matthew Barnes e21188a245 fetcher: Track outstanding requests with a table
Track outstanding HTTP requests in a table for easier debugging.

Also fixes a bug discussed in https://bugzilla.gnome.org/755224
where the outstanding request counter was not decremented in the
event of an error, which could result in the fetcher hitting its
max request limit and locking up.

The bug is fixed by removing the request struct from the table in
pending_uri_free(), which is always called regardless of error,
so the outstanding request count is always accurate.
2015-09-24 10:01:01 -04:00
Matthew Barnes 771075d319 fetcher: Rework reference counting
Have OstreeFetcherPendingURI be the GTask's task_data and pass the GTask
around in queues and callback closures.  The reference counting before
was a little confusing and this helps clarify it, at least to me.

OstreeFetcherPendingURI no longer needs its own reference count.
2015-09-23 19:52:42 -04:00
Matthew Barnes 330a99c40b fetcher: Convert from GSimpleAsyncResult to GTask
Obsessive compulsive cleanup.
2015-09-23 19:52:10 -04:00
Matthew Barnes df4865e395 fetcher: Remove message_to_request table
Does not appear to be needed, no lookups on the table.
2015-09-23 13:50:50 -04:00
Gatis Paeglis 1181833e79 Remove unused variables 2015-09-23 08:39:01 -04:00
Leandro Santiago c61151d650 Mutable is a keyword in C++11
This fix allows including OSTree on C++ projects.
2015-09-23 08:29:35 -04:00
Matthew Barnes ed86160975 pull: Honor depth with OSTREE_REPO_PULL_FLAGS_COMMIT_ONLY
https://bugzilla.gnome.org/755224
2015-09-22 15:16:42 -04:00
Matthew Barnes 203d6ea65e repo: Fix build without libsoup
Had a rare situation where I had no libsoup development files, so I
took the opportunity to fix the build errors.  Ugly, but works now.

Would be nice if libsoup could be a hard dependency since we rarely
ever test a configuration without it.
2015-09-21 16:31:02 -04:00
Matthew Barnes 055b3aac32 reset: Simplify argument checking logic 2015-09-17 12:29:14 -04:00
Matthew Barnes 36d65b3cfc deploy: Do not prune repository
To support deploying older commits:

  ostree pull <remote> <checksum>
  ostree admin deploy <checksum>

Prior to this, the deploy command garbage collected <checksum> since
there's no ref pointing to it, and then ostree_sysroot_deploy_tree()
fails because it can't find the <checksum> commit.

https://bugzilla.gnome.org/732526
2015-09-16 09:23:37 -04:00
Matthew Barnes b0bd16ec11 sysroot: Add ostree_sysroot_prepare_cleanup()
New public function works like ostree_sysroot_cleanup() EXCEPT FOR
pruning the repository.

Under the hood, add _ostree_sysroot_piecemeal_cleanup() which takes
flags to better control what files are cleaned up.  Both public cleanup
functions are now wrappers for _ostree_sysroot_piecemeal_cleanup() with
different flags.
2015-09-16 09:23:37 -04:00
Alexander Larsson fd6c572c42 _ostree_static_delta_part_validate: Take a stream instead of a file as arg
This is only called in one place, and we have already opened the file there,
no need to open it twice.
2015-09-13 22:25:21 -04:00
Alexander Larsson 1ee4007a75 offline delta apply: Handle the version field
It seems the format changed and this code was not updated.
2015-09-13 22:23:56 -04:00
Matthew Barnes 2233d443e7 commit: Clarify reasoning for "commit-update-summary" default
In case anyone else gets the idea of changing the default for archive-z2
repos.  Should have the rationale captured in the source code somewhere.
2015-09-11 13:19:01 -04:00
Giuseppe Scrivano bddb25f79e pull: honor gpg-verify-summary=false when a summary signature is present
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-09-10 08:59:01 -04:00
Colin Walters 84fe2ffb2b pull: Go back to using one main context
xdg-app was hanging for me with v2015.8, but worked with v2015.7.
I narrowed things down to the GMainLoop/context commit, in which
we started pushing a temporary main context for synchronous
requests internally.

That's never really going to work with libsoup - there needs
to be a single main context which works on the socket.  Furthermore,
clients couldn't get progress messages that way.

For *other* internal uses where we added APIs that talk to the remote
repo, we cleanly push a temporary main context.

(Note that I kind of snuck in a change here around the GError handling
 in pulls that isn't strictly related but came up in testing)
2015-09-01 14:39:24 -04:00
Colin Walters ef56321354 pull: Only fetch all refs if we're mirroring
I noticed xdg-app was looping trying to fetch 1427 refs.  We
don't want to do that unless asked to.

(And also, we need to make static delta requests async)
2015-08-31 22:59:08 -04:00
Colin Walters 0110183675 fetcher: Use 0666 (-umask) for temporary files
There's no reason to keep them hidden.  I have a hard policy that
OSTree should *not* be used to carry secrets.  Things like host ssh
private keys should be set up out of band by an OS-external
configuration mechanism such as kickstart, cloud-init, etc.

We also assume that hiding binaries is not very useful as most
attackers would be able to find them on the Internet or (for
subscribed content) acting as a customer.

This fixes a bug with mirroring because we changed to take the
unmodified upstream objects rather than uncompress <-> recompress.

https://bugzilla.gnome.org/show_bug.cgi?id=748959
2015-08-27 11:36:48 -04:00
John Hiesey 153f092d51 static-delta: assert on non-regular files
Now that the computed similar objects are all regular files,
get_unpacked_unlinked_content should never be called on any other
object type. Assert that this is true instead of silently succeeding.
2015-08-26 16:25:28 -04:00
John Hiesey 43d045309c static-delta: Ignore symlinks when computing similar objects
_ostree_delta_compute_similar_objects should not output symlinks.
Previously, a symlink in the "from" commit could be matched to a
real file in the "to" commit, since nothing was filtering symlinks
on the "from" side. This led to failures running the bzdiff
algorithm.
2015-08-26 16:25:28 -04:00
Jasper St. Pierre 20647edcbf repo-pull: Add a queue for scanning
On systems with slow disks, the recursive scanning of directories can
be expensive -- it takes upwards of 2 minutes on our systems. This can
block the main loop for such a long time that it allows the download to
time out...

As such, move all the scanning of objects to a queue, processed from
an idle, to make sure that we don't block the main loop when scanning.

https://bugzilla.gnome.org/show_bug.cgi?id=753336
2015-08-26 12:15:38 -07:00
Colin Walters b89326ac41 rollsum: Fix assertion for CRC matches
It's possible for two blocks to have the same CRC but different
length.  Rather than asserting, treat them as not matching.
2015-08-25 09:26:22 -04:00
Colin Walters 9f3d586993 pull: Stop using GMainLoop
First of all, what we were doing with having GMainLoop in the internal
APIs is wrong.  Synchronous APIs should always create their own main
context and not iterate the caller's.  Doing the latter creates
potential for evil reentrancy issues.  Sync API should block, async
API is for not blocking.

Now that's out of the way, fix the pull code to do the clean

```
while (termination_condition (state))
  g_main_context_iteration (mainctx, TRUE);
```

model for looping.  This is a lot easier to understand and ultimately
more reliable than having other code call `g_main_loop_quit()`, as the
loop condition is in exactly one place.

We can also remove the idle source which only fired once.

Note we have to add a hack here to discard the synchronous session and
create a new one which we only use async.

https://bugzilla.gnome.org/show_bug.cgi?id=753336
2015-08-13 22:02:00 -04:00
Colin Walters 5c20ea920e sysroot: Add an unload() API
This will be used by gnome-continuous at least to drop the reference
to the fd so that unmounting can proceed.  See
https://git.gnome.org/browse/gnome-continuous/commit/?id=95e9910ea288d302509ca667e0d190dd89377dd5
2015-08-13 12:43:14 -04:00
Cosimo Cecchi a5f266f25d repo: don't forget to abort the transaction when failed
ostree_repo_prepare_transaction() should always be matched with a call
to either ostree_repo_commit_transaction() or
ostree_repo_abort_transaction().

Since ostree_repo_pull_with_options() does not call
ostree_repo_abort_transaction() on errors, the OstreeRepo instance will
hit an assertion when it's re-used later for another attempt, such as
when the update is driven by an external component through libostree and
network temporarily goes down.

This commit simply always calls ostree_repo_abort_transaction() in the
exit path of ostree_repo_pull_with_options(), since the function is safe
to call even when we're not in a transaction, and that matches e.g. what
ostree-sysroot-cleanup.c does.
2015-07-28 11:35:42 -04:00
Cosimo Cecchi 939a7aebfb repo: fix an incorrect comment 2015-07-28 11:35:33 -04:00
Giuseppe Scrivano b7063ed1ae static-delta: add max-bsdiff-size option
It allows to specify the maximum size for input files to attempt
bsdiff compression for.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-28 13:02:27 +02:00
Giuseppe Scrivano cac92f62c4 static-delta: do not fail compilation with big files
Just skip the bsdiff compression instead of failing the operation.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-28 12:28:25 +02:00
Giuseppe Scrivano 11ba9056ea pull: new option --commit-metadata-only
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-24 12:43:35 -04:00
Giuseppe Scrivano 56f0ae6a4a repo: new function _ostree_preload_metadata_file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-24 12:37:42 -04:00
Giuseppe Scrivano 783e83c62c repo: merge repo_remote_fetch_summary_{metalink,url}
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-24 12:37:42 -04:00
Giuseppe Scrivano 133fb5ffdc libostree: new API ostree_repo_remote_list_refs
The new API permits to query a remote repository summary file and
retrieve the list of available refs.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-07-24 12:37:42 -04:00
Matthew Barnes 254def3584 main: Fix UID check based on sysroot path
This is another place where we were hard-coding a default.  Create the
OstreeSysroot first and THEN check if its path is the root directory.
2015-07-16 12:49:28 -04:00
Matthew Barnes 708d923125 repo: Fix location of remote configs for system repos
Need to respect the repo's system root directory instead of assuming the
compile-time $(sysconfdir).
2015-07-16 12:49:18 -04:00
Matthew Barnes 74fb777edb sysroot: Pass the internal repo a system root path 2015-07-16 12:49:11 -04:00
Matthew Barnes 104b8bf6fb repo: Add a "sysroot-path" property
Adds ostree_repo_new_for_sysroot_path() to specify a system root path.
OstreeRepo otherwise uses _ostree_get_default_sysroot_path().
2015-07-16 12:48:56 -04:00
Matthew Barnes 26225cb198 sysroot: Use _ostree_get_default_sysroot_path()
Instead of hard-coding the root directory as default.
2015-07-16 12:48:44 -04:00
Matthew Barnes f2ddf10d4e core: Add _ostree_get_default_sysroot_path()
Returns a GFile for the default system root, which is usually the root
directory unless overridden by the OSTREE_SYSROOT environment variable
(which is mainly intended for testing).
2015-07-16 12:48:11 -04:00
Colin Walters 31d16c9cce pull: Plug a memory leak 2015-06-29 21:57:44 -04:00
Colin Walters 889b86e96d pull: Avoid leaking signal handlers across fetch requests
libsoup will cache sessions, so it might be the case that we get a
reused session when pulling from the same repo multiple times in one
process.

In this case we were leaking signal connections, which caused
callbacks into freed memory with bad consequences.

Fix it by tying the signal connection to the object lifetime.
2015-06-29 21:56:03 -04:00
Colin Walters c8c239f94c pull: Also fix misplaced remote name handling
We want to set the remote name only if we're operating on a remote
URL.
2015-06-29 11:20:41 -04:00
Colin Walters 536d6fb083 core: Fix inverted conditional in GPG checking 2015-06-29 11:09:00 -04:00
Colin Walters 720e3b5f83 pull: Error if gpg=true and summary is 404, add more tests
I did a quick audit pass through the pull code.  What I focused on the
most is the case where `gpg-verify-summary=true`, and in particular
where `gpg-verify=false` too.  This should be a valid and secure
configuration.

The primary change here is to error out very quickly if either
`summary` or `summary.sig` are 404.  Previously, we'd only error out
if we were processing deltas.

Expand the existing test case to cover this, plus invalid summary and
invalid sig.  (The test case was failing with current git master too).
2015-06-27 12:04:18 -04:00
Giuseppe Scrivano 3737b9851a ostree_repo_remote_fetch_summary: honor gpg-verify-summary
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-06-26 11:02:25 +02:00
Giuseppe Scrivano 19ce011e1f pull: fail if GPG is enabled and the summary is not signed
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-06-26 11:02:25 +02:00
Giuseppe Scrivano b09c9b7005 repo: new function ostree_repo_remote_get_gpg_verify_summary
It allows to specify whether GPG verification for the summary file is
enabled for a specific repository.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-06-26 11:02:25 +02:00
Giuseppe Scrivano 6bf067411d pull: verify summary signatures also when not mirroring
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-06-26 11:02:24 +02:00
Matthew Barnes 6284beb2b6 ostree: Add a "remote refs" command
Works like "ostree refs" but fetches refs from a remote repo.

This depends on the remote repo having a summary file, but any repo
being served over HTTP *ought* to have one.
2015-06-26 11:02:24 +02:00
Matthew Barnes 0dbf91484b repo: Add ostree_repo_remote_fetch_summary()
Reusable method for fetching a summary file and signatures.
2015-06-26 11:02:24 +02:00
Matthew Barnes 87851c7bbe metalink: Return requested file as a GBytes
This may not be the best idea for general usage, but the only use case
for metalinks currently is fetching a summary file and those are pretty
small.  Far more convenient to return the file content in a GBytes.
2015-06-26 11:02:24 +02:00
Matthew Barnes ebef43eabe metalink: Allow NULL for "out" params in metalink requests
Caller may not be interested in all the outbound params, particularly
"fetching_sync_uri".
2015-06-26 11:02:24 +02:00
Matthew Barnes 3515e01f6a repo: Redo ostree_repo_remote_get_url()
Make it work like in ostree_repo_pull_with_options(), handling "file://"
remotes and inheriting the "url" option from parent repos if needed.
2015-06-26 11:02:24 +02:00
Matthew Barnes d4111aeac0 repo: Handle "file" remotes in ostree_repo_remote_get_gpg_verify() 2015-06-26 11:02:24 +02:00
Matthew Barnes e592faec43 repo: Add _ostree_repo_get_remote_option_inherit()
Split out from ostree-repo-pull.c.  Still private but more reusable now.
2015-06-26 11:02:24 +02:00
Matthew Barnes b02777accd repo: Add _ostree_repo_remote_new_fetcher()
Creates and configures an OstreeFetcher instance for a given remote.

Split out from ostree_repo_pull_with_options().
2015-06-26 11:02:24 +02:00
Matthew Barnes 6e3cb828b6 diff: Fix adding CLI options twice 2015-06-18 17:58:13 -04:00
Matthew Barnes b6722f9d80 metalink: Fix behavior when requested file is not found
The state machine's "passthrough_previous" field never got set, so the
machine gets put back into the wrong state after a passthrough phase.
Couple other minor issues around error handling.
2015-06-15 21:20:52 -04:00
Dan Nicholson 5af7e8e8c2 pull-local: Support --depth option
Like pull, allow pull-local to mirror another another repository by
specifying how many parents to traverse.

https://bugzilla.gnome.org/show_bug.cgi?id=750581
2015-06-14 08:49:35 -04:00
Matthew Barnes 9f1b50d41c repo: Change GPG verification policy
The global keyring directory (trusted.gpg.d) is deprecated.  Only use it
when a specified remote does NOT have its own keyring, or when verifying
local repository objects.

Note, because mixing in the global keyring directory is now an explicit
choice, OstreeGpgVerifier no longer needs to implement GInitableIface.
2015-06-10 12:28:57 -04:00
John Hiesey 4f6f97caf0 Fix double free in ostree_repo_pull_with_options
Duplicate the commit checksum for expected_commit_sizes since it's also
used as a value in requested_refs_to_fetch.

https://bugzilla.gnome.org/show_bug.cgi?id=750366
2015-06-05 17:27:38 -04:00
John Hiesey 06fc597762 Fix tests on 32 bit systems
Use guint64 when the 't' format is used for GVariant
2015-06-04 17:58:12 -04:00
Matthew Barnes 94ef7669d7 gpg: Gracefully handle no trusted.gpg.d directory
This is a deprecated fallback method anyway.  We prefer
remote-specific keyrings now.

https://bugzilla.gnome.org/750049
2015-06-04 17:54:42 -04:00
Colin Walters acf1caa12f repo: Don't crash when creating a summary if we have --empty deltas 2015-06-02 09:07:28 -04:00
Colin Walters 9161e35d20 pull: Validate delta checksums more strongly
We need to check that it's 'ay'.  Also reuse the existing validation
function to check it's 32 bytes rather than potentially crashing with
assertion.

Just noticed this during a code review.
2015-06-02 09:07:28 -04:00
Colin Walters 0bd1ff3939 pull: Ensure console state for multiple GPG verification messages
If there are multiple signatures to verify, we would attempt to
display them multiple times, but we can only call
`gs_console_end_status_line()` if the console has been enabled.

Ensure we turn back on the console after printing our status.  This
will result in extra newlines, but fixing that cleanly would require a
saner GSConsole API.
2015-06-02 09:07:28 -04:00
Colin Walters 3300ee6259 sysroot: Sort returned boot loader configs
I haven't done a full dig through the history, but it seems quite
possible right now we've been relying on inode enumeration
order for generating bootloader configuration.

Most of the time, newer inodes (i.e. later written files) will win.
But that's obviously not reliable.

Fix this by sorting the returned configuration internally.
2015-05-28 14:21:30 -04:00
Jeff Ortel ca0f02a54b Fix annotations on ostree_repo_remote_gpg_import(). 2015-05-27 15:03:25 -04:00
Giuseppe Scrivano 96baf34edf ostree-repo: document OSTREE_REPO_COMMIT_MODIFIER_FLAGS_GENERATE_SIZES
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-19 11:13:34 +02:00
Colin Walters bf59d0c6f5 admin: Ensure instutil commands and usage help don't grab lock
When I was introducing the `_UNLOCKED` flag, I only audited
subcommands of `ostree admin`, but I missed that `ostree admin
instutil` also used the option parsing.  Those are only used by
Anaconda today so we can ignore them for locking purposes.

Also, the usage help generation was grabbing the lock unnecessarily.
2015-05-15 09:13:50 -04:00
Matthew Barnes 6a6479c355 repo: Prevent GPG keys from being imported to keybox format
If a remote keyring does not already exist, create an empty pubring.gpg
file in the temporary directory prior to importing keys.  This prevents
gpg2 from creating a pubring.kbx file in the new keybox format [1].  We
want to stay with the older keyring format since its performances issues
are not relevant here.

[1] https://gnupg.org/faq/whats-new-in-2.1.html#keybox
2015-05-14 17:02:39 -04:00
Colin Walters efcdf4c3f8 repo: Bump mtime any time we write a ref
External daemons like rpm-ostree want push notification any time a
change is made by an external entity.  inotify provides notification,
but a problem is there's no easy way to monitor all of the refs.

In the past, there has been discussion of opt-in recursive timestamps:
https://lkml.org/lkml/2013/4/5/307

But in today's world, let's just bump the mtime on the repo itself, as
a central inotify point.

Closes: https://github.com/GNOME/ostree/pull/111
2015-05-14 06:33:31 -04:00
Giuseppe Scrivano 7224450591 ostree-repo: replace more gs_unref_(variant|bytes) with g_autoptr
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-14 10:04:16 +02:00
Colin Walters c10bc00249 admin: Use locking for most sysroot commands
The previous commit introduced locking for `ostree admin deploy`, but
we do expect people to possibly accidentally do e.g.
`ostree admin upgrade` concurrently.

Using consistent locking in the admin commands will help rpm-ostree.

Closes: https://github.com/GNOME/ostree/pull/110
2015-05-13 17:23:07 -04:00
Matthew Barnes 64252a4a39 ostree: Add --gpg-import to the "remote add" command
Convenience option imports GPG keys for a newly-created remote.
2015-05-13 13:08:49 -04:00
Matthew Barnes c287a7419c ostree: Add a "remote gpg-import" command
Imports GPG keys into a remote-specific keyring.
2015-05-13 13:08:49 -04:00
Matthew Barnes a9b87ebc18 repo: Add remote's keyring during GPG verification
This is pretty fugly but it at least avoids new public API.
2015-05-13 13:08:49 -04:00
Matthew Barnes 4d7e73ede1 repo: Add ostree_repo_remote_gpg_import()
Imports one or more GPG keys from a source stream or from the user's
personal keyring into a remote-specific keyring.  The keys to import
can optionally be restricted by a list of key IDs.

The imported keys are used to conduct GPG verification when pulling
from the given remote.
2015-05-13 13:08:49 -04:00
Matthew Barnes 0c92d7a8d0 repo: Delete a remote's keyring when deleting a remote 2015-05-13 13:08:48 -04:00
Matthew Barnes 56d684173d repo: Stash keyring name in OstreeRemote 2015-05-13 12:25:58 -04:00
Giuseppe Scrivano e3a3e2b618 syntax-check: add syntactic rule to prohibit gs_strfreev
and fix an instance.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-13 10:02:47 +02:00
Giuseppe Scrivano 45cb5b5f42 pull: add new switch option --disable-static-deltas
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-13 09:38:04 +02:00
Giuseppe Scrivano f6d16a6d95 ostree-repo-pull: add option to disable static-deltas
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-12 10:06:56 +02:00
Colin Walters 2dfe24632a sysroot: Add a try_lock() API
The blocking locking API wasn't sufficient for use in the rpm-ostree
daemon; it really wants to know if the lock is held, then continue to
do other things (like service DBus requests), and get notification
when the lock is available.

We also add an async variant that can be called if the lock is not
available.

Implement a higher level "loop until lock is available" method in the
`ostree admin` commandline.
2015-05-10 16:20:53 -04:00
Matthew Barnes d0edf63346 repo: Simplify sign_data() a little
Use ot_gpgme_data_output() to wrapper a GOutputStream.
2015-05-07 17:50:22 -04:00
Matthew Barnes 239f05ecdd gpg: Add custom data buffers to wrapper GIO streams
ot_gpgme_data_input() and ot_gpgme_data_output(), shamelessly ripped
off from seahorse_gpgme_data_input() and seahorse_gpgme_data_output().
2015-05-07 17:07:36 -04:00
Matthew Barnes cd1551b1ee gpg: Fix ot_gpgme_error_to_gio_error()
Need to extract the error code from a gpgme_error_t, can't just compare
it directly.
2015-05-07 16:02:39 -04:00
Giuseppe Scrivano 223a9eaaa5 ot-fs-utils: remove empty line at EOF
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:59:30 +02:00
Giuseppe Scrivano 70d9599246 summary: delete summary.sig on an update
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano ef7a4dee10 pull: verify signature for the summary file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano 5f33133054 summary: add new command line arguments to sign the summary file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano fee785a72e ostree-repo: add new API to sign the summary file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano 94360d3d1c pull: get rid of detached metadata for deltas
Once the summary file will be signed, we can validate the superblock
from there.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano 8c3d4eb7b2 pull: check that the superblock checksum is the same as in the summary
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano 222696996f core: store information about delta files checksums
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano ae672c3c9f core: new function _ostree_parse_delta_name
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano e0da4db77c summary: list the available static deltas
Write the information in the additional_metadata element for backward
compatibility.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 21:58:04 +02:00
Giuseppe Scrivano 0f8f668cd3 trivial-httpd: add option to specify the port
I use the trivial httpd server locally. Each time I restart the
server, I end up modifying manually the config file for other repos so
to point to the correct port. In this way I can just re-use the same
port.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 16:16:27 +02:00
Giuseppe Scrivano 26bb93ac24 trivial-httpd: fix indentation
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-07 16:16:23 +02:00
Matthew Barnes 4ef0280941 Remove unnecessary #include "libgsystem.h" 2015-05-06 22:07:11 -04:00
Matthew Barnes 302ac4dd89 Use g_auto(GStrv) instead of gs_strfreev 2015-05-06 22:07:11 -04:00
Matthew Barnes cca69b3f55 Use g_autoptr(GVariantBuilder) instead of gs_unref_variant_builder 2015-05-06 22:07:11 -04:00
Matthew Barnes c69347b622 Use g_autoptr(GKeyFile) instead of gs_unref_keyfile 2015-05-06 22:07:10 -04:00
Matthew Barnes c2c322efa9 Use g_autoptr(GVariant) instead of gs_unref_variant 2015-05-06 22:07:10 -04:00
Matthew Barnes bb231fdf74 Use g_autoptr(GPtrArray) instead of gs_unref_ptrarray 2015-05-06 22:07:10 -04:00
Matthew Barnes 196d983af9 Use g_autoptr(GHashTable) instead of gs_unref_hashtable 2015-05-06 22:07:10 -04:00
Matthew Barnes e6556dd223 Use g_autoptr(GBytes) instead of gs_unref_bytes 2015-05-06 22:07:10 -04:00
Matthew Barnes 3f044267b5 Use g_autoptr(GChecksum) instead of gs_free_checksum 2015-05-06 22:07:10 -04:00
Matthew Barnes 6a5f7b1288 Use glnx_unref_object instead of gs_unref_object
For non-GIO object types, at least until autocleanup support for GObject
based types becomes more widespread.
2015-05-06 22:07:04 -04:00
Matthew Barnes 4ee1acd981 Use g_autoptr() for GIO object types
GLib 2.44 supplies all the necessary autocleanup macros for GIO types,
and libglnx backports the relevant macros for ostree.
2015-05-06 21:51:19 -04:00
Matthew Barnes 7a62d64968 Use g_autofree instead of gs_free 2015-05-06 21:50:17 -04:00
Matthew Barnes 4f33515316 Juggling libglnx.h includes 2015-05-06 21:50:06 -04:00
Matthew Barnes 83aac088d1 gpg: Add ostree_gpg_verify_result_describe_variant()
Needed for printing signature details in places where
OstreeGpgVerifyResult cannot go.
2015-05-06 21:04:40 -04:00
Colin Walters 4a3c2a25b7 repo: Stop creating "transaction" symlink
This originally was a way that we detected the case where a pull was
interrupted.  Later, we added `.commitpartial` files which also cover
this case.

See also https://github.com/GNOME/ostree/pull/85

We still want to honor their existence (and unlink them) in case an
old version of ostree was in use, but I believe it's safe to stop
creating them now.

The only case where this would break is if you have a version of
ostree that predates commitpartial in your rollback history, but such
old versions are no longer in use by operating systems I support at
least.

Closes: https://github.com/GNOME/ostree/pull/100
2015-05-06 13:26:47 -04:00
Colin Walters 5becd5ccad Teach fsck about partial commits
An OSTree user noticed that `ostree fsck` would produce `missing
object` errors in the case of interrupted pulls.

It's possible to do e.g. `ostree pull --subpath=/usr/share/rpm ...`,
which gets you just that portion of the commit.  The use case for this
was being able to see what changes would appear in an update before
actually downloading all of it.

(I think this would be better covered by static deltas, but those
 aren't final yet, and `--subpath` predates it)

Further, `.commitpartial` is used as a successor to the `transaction`
symlink for more precise knowledge in the case where a pull was
interrupted that we needed to resume scanning.

So it makes sense for `ostree fsck` to be aware of it.
2015-05-06 08:07:20 -04:00
Colin Walters 279308b5b9 core: Cleanup commitpartial file with fd-relative lookups
First, this is just a general continuation of the `GFile -> openat`
transition.

Second, it's preparatory work for fsck to gain awareness of partial
commits.
2015-05-06 08:07:20 -04:00
Giuseppe Scrivano a68242c6c9 doc: remove unknown parameter from inline documentation
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-05 16:29:20 +02:00
Matthew Barnes 81138963c3 repo: Fix an obvious typo 2015-05-05 10:25:00 -04:00
Colin Walters 9ef98fd05a sysroot: Add an API to lock
If a system administrator happens to type `ostree admin upgrade`
multiple times, currently that will lead to a potentially corrupted
system.

I originally attempted to do locking *internally* in `libostree`, but
that didn't work out because currently a number of the commands
perform multi-step operations that all need to be serialized.  All of
the current code in `ostree admin deploy` is an example.

Therefore, allow callers to perform locking, as most of the higher
level logic is presently implemented there.

At some point, we can revisit having internal locking, but it will be
difficult.  A more likely approach would be similar to Java's approach
with concurrency on iterators - a "fail fast" method.
2015-05-05 08:52:44 -04:00
Matthew Barnes 33b0667597 Fix build when using GLib < 2.44 2015-05-04 12:02:02 -04:00
Giuseppe Scrivano 857a852540 pull: the commit size in the summary is not for the detached metadata
Use the size specified in the summary file only for the not detached
metadata.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-05-03 21:44:09 +02:00
Matthew Barnes f162c0b6d6 gpg: Fix _ostree_gpg_verifier_add_keyring()
The function never fails, but its API makes it look like it can.

Fortunately it's private, so just fix it.
2015-05-01 15:24:11 -04:00
Matthew Barnes e7246e6d64 ostree: Split up "remote" subcommands
To make room for "remote gpg-import", which will be non-trivial.
ot-builtin-remote.c was already a little too crowded anyway.

Also while we're at it, port this bit of code away from libgsystem.
2015-05-01 14:38:17 -04:00
Matthew Barnes ca63fab6b1 repo: Initialize GPGME in instance init()
Initially I had this in class_init() but there it would get invoked
during introspection scanning.
2015-05-01 14:38:17 -04:00
Matthew Barnes 97379ec38c libotutil: Add ot_gpgme_ctx_tmp_home_dir()
Currently used for signature verification, will also be used for
importing GPG keys.
2015-05-01 10:21:40 -04:00
Matthew Barnes ceacc57206 libotutil: Establish a place for GPG utilities
Add ot-gpg-utils.[ch] and move _ostree_gpg_error_to_gio_error() here.
2015-05-01 10:20:34 -04:00
Giuseppe Scrivano cd93780d97 show: add option --gpg-homedir
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-27 15:22:41 +02:00
Giuseppe Scrivano f37cbe1fc9 gpg: do not use secring.gpg
It contains the secret keyring

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-27 15:22:41 +02:00
Giuseppe Scrivano cf30f8717a g_output_stream_splice: check correctly the error code
While at it, change the style of other two occurrences.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-24 18:26:22 +02:00
Matthew Barnes 9c449624f2 pull: Always request detached metadata for commits
Always request detached metadata for commit objects, even if we already
have the commit object.  This ensures we fetch any post facto detached
metadata updates such as new GPG signatures.

https://bugzilla.gnome.org/748220
2015-04-23 19:57:10 -04:00
Micah Abbott d801d347f7 reset: update help output
The inline help for 'ostree reset' now correctly shows that it
requires a REF and a COMMIT as arguments.
2015-04-23 14:32:11 -04:00
Colin Walters e0b73d0742 deploy: Drop a fsync, use fd-relative APIs
Now that we can rely on `syncfs()`, drop another fsync in the deploy
path.  While we're here, convert it to fd-relative.
2015-04-20 21:03:23 -04:00
Colin Walters 45406bf815 deploy: Drop fsync of modified config files
These fsyncs were added for what turned out to be a fairly bogus
reason; I was hitting read errors from extlinux after upgrades and out
of conservatisim tried adding fsync calls, but the *actual* problem
was that extlinux didn't support 64 bit ext4.  Now that at least for
Project Atomic hosts we're just targeting grub2, we can drop these
fsync calls and rely on `syncfs()` being both faster and catching any
errors.
2015-04-20 21:03:23 -04:00
Colin Walters c58a5c0cb3 deploy: Use syncfs() in addition to sync()
For some sort of crazy reason, the `sync()` system call doesn't
actually return an error code, even though from what I can tell in the
kernel it wouldn't be terribly hard to add.

Regardless though, it is better for userspace apps to use `syncfs()`
to avoid flushing filesystems unrelated to what they want to sync.  In
the case of OSTree, this does matter - for example you might have a
network mount point backing your database, and we don't want to block
upgrades on syncing it.

This change is safe because we're doing syncfs in *addition* to the
previous global `sync()` (a revision from an earlier patch).

Now because OSTree only touches the `/` mount point which covers the
repository, the deployment roots (including their copy of `/etc`), as
well as `/boot`, we should at some point later be able to drop the
`sync()` call.  Note that on initial system installs we do relabel
`/var` but that shouldn't happen at ostree time - any new directories
are taken care of via `systemd-tmpfiles` on boot.
2015-04-20 21:03:22 -04:00
Colin Walters 6d84321a16 status: Don't crash if we deployed a local refspec
In the case we built a local tree, we'd pass `NULL` as a remote down
to the GPG checking code.  Noticed this in the test suite.
2015-04-20 21:02:25 -04:00
Colin Walters f08cb802ea sysroot: Close sysroot fd in finalize
Just noticed this while I was going to add another one there.
2015-04-20 16:51:05 -04:00
Colin Walters 24087d477c sysroot: Add ostree_sysroot_get_fd()
This way external programs like rpm-ostree can do fd-relative
operations on the deployment directories, like inspecting the RPM
database.

Closes: https://github.com/GNOME/ostree/pull/91
2015-04-17 14:15:11 -04:00
Matthew Barnes 60ebec770e main: Tweak GPG output to match rpm-ostree 2015-04-17 12:43:46 -04:00
Matthew Barnes a6bbcf2ba7 sysroot: Cache an OstreeRepo instance
Rather than returning a new OstreeRepo instance in each call to
ostree_sysroot_get_repo(), cache one internally so the same instance
is returned each time.
2015-04-17 11:19:08 -04:00
Matthew Barnes 6a7b9defb8 admin: Conditionally show GPG signatures in status command
Only if GPG verification is enabled for a deployment's origin.
2015-04-16 18:13:17 -04:00
Matthew Barnes 54bf665521 repo: Add ostree_repo_remote_get_gpg_verify()
Trivial function, but it does at least centralize the default value.
2015-04-16 18:13:13 -04:00
Matthew Barnes d7a6f257a0 pull: Print GPG signature status as soon as its known 2015-04-16 18:13:08 -04:00
Matthew Barnes 20076ff201 repo: Add a "gpg-verify-result" signal
Emitted during a pull operation upon GPG verification (if enabled).
Applications can connect to this signal to output the verification
results if desired.
2015-04-16 18:13:04 -04:00
Matthew Barnes d0770e9993 repo: Improve error handling in sign_data()
Use _ostree_gpg_error_to_gio_error() so the actual GPG error message is
included in the GError.  Then apply an "Unable to blah: " message prefix.
2015-04-16 18:12:58 -04:00
Colin Walters ab15eafe56 reset: Don't enforce parent commits
First, git doesn't do this, and whatever Linus thinks is right or
something.

Second specifically to OSTree, it's quite common to not have
intermediate commits.  If one wants to reset a ref in order to prune
data after a deployment, the parentage check will fail.

Closes: https://github.com/GNOME/ostree/pull/87
2015-04-15 07:12:20 -04:00
Giuseppe Scrivano 9e6ac6d822 config: add new parameter "commit-update-summary" to core section
When set to true, the summary file is automatically updated after
a commit.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-14 17:46:53 +02:00
Giuseppe Scrivano 362771aa98 summary: write the contents to a temporary file
do not write directly to the summary file but use a temporary file
first.  It avoids to create an empty file if "ot_util_variant_save"
fails.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-14 17:42:25 +02:00
Giuseppe Scrivano 69184e70e9 _ostree_repo_file_replace_contents: make buf const
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-14 17:42:24 +02:00
Colin Walters fff8ffdd2f repo: Add a private helper to replace a file, honoring fsync policy
Extracted from discussion in https://github.com/GNOME/ostree/pull/83
2015-04-13 13:28:02 -04:00
Colin Walters 1892a6fe13 refs: Use *at for writes, honor repo fsync flag
I was looking at https://bugzilla.gnome.org/show_bug.cgi?id=738954
which wants us to ensure we chown() the refs.  As part of that,
I did a generic conversion to use `*at()` (which naturally gives
us more low level control so we can call `fchown` etc.

This patch also sneaks in a change to respect the repo's
`disable_fsync` flag - if fsync is not set, then we never
`fdatasync()` (unlike the `g_file_replace_contents()` default.  Also
unlike it, if fsync is enabled, we *always* sync even if the file
didn't exist.
2015-04-13 08:47:05 -04:00
Giuseppe Scrivano c648fada30 ostree_repo_checkout_tree_at: remove @subpath documentation
It is not an argument of the function.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-13 11:55:25 +02:00
Colin Walters 42744628b3 Add an API to set/unset a deployment tree's mutability
This will be used by rpm-ostree to unset the immutable bit temporarily
in order to do package layering.  We could add an API to deploy a tree
without the immutable bit, but this is simpler.
2015-04-10 17:54:08 -04:00
Matthew Barnes 18fdc7cb97 admin: Show GPG signatures in status command 2015-04-08 10:18:53 -04:00
Matthew Barnes 7956b0a5c5 gpg: Add ostree_gpg_verify_result_describe()
Internalizes the signature output of "ostree show" so it can be reused
elsewhere.
2015-04-08 10:18:48 -04:00
Colin Walters c2aabcac3b ostree_repo_checkout_tree_at: New API for checkouts
rpm-ostree currently uses ostree_repo_checkout_tree(), which as a side
effect will use the uncompressed objects cache by default.  This is
rather annoying if you're using rpm-ostree on a server-side
repository, because if you then rsync the repo, you'll be syncing out
the uncompressed objects unless you exclude them.

We added the ability to disable the uncompressed cache in the
repository config to fix this, but it's better to allow application
control over this.  The uncompressed cache will in some future version
become opt in as well.

This new API further:
 - Drops the `GFile` usage in favor of `openat` APIs
 - Improves ergonomics by avoiding callers having to query the source
   `GFileInfo` (and carry around a copy of `OSTREE_GIO_FAST_QUERYINFO`)
 - Has a more extensible options structure

Per the comment, I rather crudely have the `ostree checkout` builtin
call both APIs to ensure some testing coverage.

However, I'd like to in the future have easier-to-set-up testing code
that calls `libtest.sh` to set up dummy data.
2015-04-07 15:12:16 -04:00
Colin Walters 115e05746b pull: Handle remote web server not honoring range requests
It's valid for the remote server to say 200 OK and give us the entire
file instead of a 206 Partial Content, and in that case we should blow
away the previous cached data, rather than blindly appending to it and
thus creating multiple copies of the data inside the file.

This problem primarily occurs when we do have the complete file, and
we're interrupted, then try again, where the new process didn't record
the download was already complete.  We do a range request for bytes
past the end, and some web servers (e.g. Akamai) will return 200 OK
with the whole content again, rather than a 416 Requested Range Not
Satisfiable.

Thus we could also fix this by saner caching strategy - since we know
the file is complete, rename it again to $checksum.done or something
before it's processed.  (Or really, rework how we do caching more
intelligently in general).

This fixes the issue that interrupted pulls failed with such
webservers, although repeated attempts would eventually succeed
because we'd unlink files that failed to pull.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1207292
2015-04-06 14:33:16 -04:00
Matthew Barnes f2b2d7c3f2 core: Actually allow none in ostree_parse_refspec()
Both 'out_remote' and 'out_ref' parameters already have the (allow-none)
annotation but that wasn't actually true.
2015-04-06 12:08:27 -04:00
Giuseppe Scrivano 1de4035d49 src/ostree/ot-main.c: drop empty newline at end of file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-04-03 09:57:20 +02:00
Daniel Svensson 534c4c20c3 build: Use glibc's xattr support instead of requiring libattr
Fixes the build on Debian, and is one library less.

Closes: #78
2015-04-01 06:35:53 -04:00
Colin Walters 2a30af72db main: Only verify SUPERUSER flag if using default sysroot
The use case for non-default sysroots that I know of are:
 1) The current test suite
 2) Installers (Anaconda)
 3) Inspecting VM disks

For 2) and 3), it'll quickly be obvious if they're not running as
root, and these are more obscure cases.  We want to allow 1), and this
is a simple way to do it.

https://bugzilla.gnome.org/show_bug.cgi?id=747164
2015-04-01 06:21:34 -04:00
Matthew Barnes e92fd9a83d Include ostree-gpg-verify-result.h in ostree.h 2015-03-31 19:48:55 -04:00
Sam Thursfield d667ebe156 core: Fix possible crash in ostree_mutable_tree_walk()
If the starting index is beyond the end of the list, it's a programming
error. Previously, the code was trying to raise a runtime error, but
actually causing a segfault.

This was detected by test code in test-mutable-tree.c, which is removed
in this commit because it should now not be possible to crash here.

https://bugzilla.gnome.org/747032
2015-03-31 13:04:31 -04:00
Matthew Barnes aeab9df4fe Add OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER
Indicates the command requires superuser privilege.  Fails early with
a more helpful message than would otherwise be returned by libostree.

Currently all admin commands except 'status' require superuser.
2015-03-25 17:24:06 -04:00
Matthew Barnes e48ea0ba05 Add OstreeAdminBuiltinFlags for admin commands
Only OSTREE_ADMIN_BUILTIN_FLAG_NONE so far; does nothing.
2015-03-25 17:24:06 -04:00
Matthew Barnes 1d5e2682fd Check repo permission prior to attempting to modify it
Fail early with a helpful message if the user does not have sufficient
permission to modify an OSTree repository.
2015-03-25 17:24:05 -04:00
Matthew Barnes 7941189dfd Add ostree_ensure_repo_writable()
Commands that need to write files within the repo directory can call
this early to ensure the directory is writable for the current user.
If not, it fails with a helpful "You need to be root to perform this
command" message.
2015-03-25 17:24:05 -04:00
Matthew Barnes a25c7fab12 Add ostree_repo_is_writable() 2015-03-25 17:24:05 -04:00
Colin Walters 6c787093e8 gpg-sign: Add missing NULL terminator in options 2015-03-24 09:57:52 -04:00
Alexander Larsson 74f4fc2bc8 Fix build with !HAVE_LIBSOUP
Fix up ostree_repo_pull to match the new declaration
2015-03-23 14:26:01 +01:00
Alexander Larsson d26359f823 Fix build failure on g_autoptr(gchar) with glib master
This was removed in favour of g_autofree
2015-03-20 15:36:56 +01:00
Matthew Barnes f9e95e2cd3 gpg: Link to GPGME bug about GPGME_SIGSUM_KEY_REVOKED 2015-03-19 10:21:08 -04:00
Matthew Barnes e48fd5e6bb show: Print a blurb for each signature on a commit
Roughly mimics the output of "gpg --verify".
2015-03-18 11:53:20 -04:00
Matthew Barnes d886c9ccb5 gpg-sign: Add a --delete option to delete signatures 2015-03-18 11:53:13 -04:00
Matthew Barnes 9033cf5da1 repo: Reject duplicate signatures when signing commit
Uses OstreeGpgVerifyResult to catch duplicate signatures.

If the commit has already been signed with the given GPG key ID, fail
with a G_IO_ERROR_EXISTS error code.
2015-03-18 11:53:04 -04:00
Matthew Barnes 8d127b9dcb repo: Add ostree_repo_verify_commit_ext()
Similar to ostree_repo_verify_commit(), but returns more verification
details by way of an OstreeGpgVerifyResult object instead of a boolean.
2015-03-18 11:52:47 -04:00
Matthew Barnes 4a2733f9e7 gpg: Add OstreeGpgVerifyResult
Wrappers a referenced gpgme_verify_result_t so detailed verify results
can be examined independently of executing a verify operation.

_ostree_gpg_verifier_check_signature() now returns this object instead
of a single valid/invalid boolean, but the idea is for OstreeRepo to also
return this object for commit signature verification so it can be utilized
at the CLI layer (and possibly by other programs).
2015-03-18 11:52:22 -04:00
Dan Nicholson 553d7840d5 fsck: Fix object count output
The object count comes from g_hash_table_size(), so it's not a 0 based
index. In order to maintain the mod calculations correctly, just print
out index + 1.

https://bugzilla.gnome.org/show_bug.cgi?id=746360
2015-03-18 09:31:07 -04:00
Matthew Barnes f47693440d OstreeGpgVerifier: Take the signed data as a GBytes
Similar to c2b01ad.  For some reason I was thinking the commit data
still needed to be written to disk prior to verifying, but it's just
another artifact of spawning gpgv2 (predates using GPGME).

Makes for a nice cleanup in fetch_metadata_to_verify_delta_superblock()
as well.
2015-03-16 16:37:11 -04:00
Matthew Barnes c4998ab33f OstreeGpgVerifier: Don't add trustdb.gpg to the keyring list
In case someone like me is mucking around in $OSTREE_GPG_HOME and
accidentally creates a trust database there.
2015-03-16 10:06:43 -04:00
Giuseppe Scrivano ccbb10d107 ostree-repo.c: fix typo
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-16 11:34:48 +01:00
Matthew Barnes 5a3300fe5b repo: Delete .commitmeta file on empty metadata
The API docs for ostree_repo_write_commit_detached_metadata() were
written as though it already behaved that way.

https://bugzilla.gnome.org/746123
2015-03-13 12:34:19 -04:00
Matthew Barnes 187e8d632e configure.ac: Make gpgme a hard dependency
In anticipation of API enhancements for GPG signature verification, which
would otherwise require a non-functional stub version were GPGME excluded.

GPGME is a pretty lightweight dependency, and the motivation to exclude
it is not clear.
2015-03-11 12:03:33 -04:00
Colin Walters 9630d06ec7 sysroot: Port some deployment reading code to fd-relative APIs
More low hanging fruit in the sysroot department.
2015-03-10 10:47:47 -04:00
Colin Walters 6ac880c959 deployment: Add an API to get relative origin path
This will be used for fd-relative cleanups.
2015-03-10 10:47:47 -04:00
Colin Walters c86a86f742 sysroot: Drop unnecessary new sysroot object
We're asserting that "/" is the same as our path, so we don't need to
make a new object.
2015-03-10 08:41:04 -04:00
Daniel Drake 5c1839c4db ostree-prepare-root: log informational messages to stdout
ostree-prepare-root was logging normal, informational messages
to stderr which the systemd unit points to the console.

To achieve silent boot, log these ordinary messages to stdout only.
2015-03-09 21:26:13 -04:00
Colin Walters a282f94f5d sysroot: Make origin parsing code fd-relative
Just more API conversion.
2015-03-09 14:29:14 -04:00
Colin Walters 68ce554202 sysroot: Read the bootloader configuration with fd-relative API
Another piece of the conversion.
2015-03-09 14:29:14 -04:00
Colin Walters a5ffaca9d7 sysroot: Read some bootloader state with fd-relative API
This is the start of migrating the deployment path to fd-relative
code.
2015-03-09 14:29:14 -04:00
Giuseppe Scrivano ab39f59249 src: Drop unused argument "value" from ot_parse_boolean
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:38 +01:00
Giuseppe Scrivano c70abfd43c src: Move ot-tool-util from ostree/ to libotutil/
These utilities are not actually specific to the ostree commandline.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:38 +01:00
Giuseppe Scrivano 479b5ab4fc libotutil: remove ot-waitable-queue.
The module is not not used anymore.  It can be restored from git if
needed again.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:38 +01:00
Giuseppe Scrivano 021c55f430 ot_keyfile_copy_group: return FALSE on invalid inputs
The function returns a gboolean, replace g_return_if_fail with
g_return_val_if_fail.

Add similar checks to the other functions.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:37 +01:00
Giuseppe Scrivano bfd92653c3 ostree-repo-refs: Drop unused function "parse_rev_file".
If it will be needed in future, it can be retrieved from the git
history.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:37 +01:00
Giuseppe Scrivano 150048f9b8 src: drop some dead assignments
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2015-03-06 18:45:37 +01:00
Matthew Barnes c2b01adbf0 OstreeGpgVerifier: Take the signature as a GBytes
The signature data is in memory to begin with, so there's no need to
write it to disk only to immediately read it back.

Also, because the GPGME multi-keyring workaround is somewhat expensive
to setup and teardown, concatenate all signatures into a single GBytes
so _ostree_gpg_verifier_check_signature() is only called once.  We're
currently only looking for one valid signature anyway.
2015-03-06 08:22:44 -05:00
Matthew Barnes 70cabcea0a gpg: Rewrite OstreeGpgVerifier to use GPGME
This sets the stage for more advanced signature management.

(Also, talking to GPG over pipes sucks.)

Previously we were spawning gpgv2 with a bunch of --keyring options
for /usr/share/ostree/trusted.gpg.d/ and whatever other keyring files
were explicitly added.  GPGME has no public API for multiple keyrings,
so we work around the issue by setting up a temp directory to serve as
a fake "home" directory for the crypto engine and then concatenate all
the keyring files into a single public keyring (pubring.gpg).

Unfortunately at present we do this on every signature verification.
There's a desire to cache this concatenation, but the problem is the
user may be unprivileged.  So it seems the cache would have to be per
user under $XDG_CACHE_HOME, which OSTree doesn't otherwise use.  I'm
open to suggestions.

We do at least clean up the temp directory when finished, and I have
further API changes planned to OstreeGpgVerifier to help mitigate the
performance impact.
2015-03-06 08:22:44 -05:00
Colin Walters 191d78ebfc repo: Fix assertion to allow NULL options
Spotted by Adam Coldrick.
2015-03-03 21:18:40 -05:00