summaryrefslogtreecommitdiff
path: root/src/libotutil
Commit message (Collapse)AuthorAgeFilesLines
* libotutil: avoid leaking builder memory on errorLuca BRUNO2022-01-101-4/+4
| | | | | | | | | This swaps the order of a couple of input sanity checks, in order to fix a minor memory leak due to an early-return on the error path. Memory for the result is now allocated only after input has been sanity-checked. It fixes a static analysis warning highlighted by Coverity.
* Update FSF license notices to use URL instead of addressJoseph Marrero2021-12-0723-69/+23
|
* variantutil: Fix gcc `-fanalyzer` warninColin Walters2021-10-131-8/+7
| | | | | Add some not-NULL assertions for return values from glib, and upgrade some `g_return_if_fail` to `g_assert`.
* utils: Fix unreachable `NULL` deref by adding assertionColin Walters2021-10-131-2/+5
| | | | Again this one is just in theory, but let's add an assertion.
* libotutil: Add helper for GPG WKD update URLsDan Nicholson2021-07-152-0/+80
| | | | | | | | | Calculate the advanced and direct update URLs for the key discovery portion[1] of the OpenPGP Web Key Directory specification, and include the URLs in the key listing in ostree_repo_remote_get_gpg_keys(). These URLs can be used to locate updated GPG keys for the remote. 1. https://datatracker.ietf.org/doc/html/draft-koch-openpgp-webkey-service#section-3.1
* libotutil: Import implementation of zbase32 encodingDan Nicholson2021-07-152-0/+190
| | | | | | | | | | | | | | | This will be used to implement the PGP Web Key Directory (WKD) URL generation. This is a slightly cleaned up implementation[1] taken from the zbase32 author's original implementation[2]. It provides a single zbase32_encode API to convert a set of bytes to the zbase32 encoding. I believe this should be acceptable for inclusion in ostree. The license in the source files is BSD style while the original repo LICENSE file claims the Creative Commons CC0 1.0 Universal license, which is public domain. 1. https://github.com/dbnicholson/libbase32/tree/for-ostree 2. https://github.com/zooko/libbase32
* sysroot: Handle ro /boot but rw /sysrootColin Walters2021-01-101-0/+6
| | | | | | | | | | | | | | | | | The recent change in https://github.com/coreos/fedora-coreos-config/pull/659 broke some of our tests that do `mount -o remount,rw /sysroot` but leave `/boot` read-only. We had code for having `/boot` read-only before `/sysroot` but in practice we had a file descriptor for `/sysroot` that we opened before the remount that would happen later on. Clean things up here so that in the library, we also remount `/boot` at the same time we remount `/sysroot` if either are readonly. Delete the legacy code for remounting `/boot` rw if we're not in a mount namespace. I am fairly confident most users are either using the `ostree` CLI, or they're using the mount namespace.
* Add g_autoptr helper for pushing a thread default main contextAlexander Larsson2020-09-111-0/+25
| | | | | | This happens in a bunch of places, and currently each time it does we have to use "goto out" style cleanups, which just isn't looking very nice.
* Add and use ot_checksum_bytes helperAlexander Larsson2020-09-112-0/+13
| | | | This removes some duplicated code (and will be use even more later).
* lib/keyfile: Treat "group not found" the same as "key not found"Colin Walters2019-11-071-4/+10
| | | | | | | Prep for fsverity, where I want to create a new group `[fsverity]` in the keyfile that has default values. We should treat the absence of a group the same as absence of a key in these "with defaults" APIs.
* lib/checksum-utils: Use g_memdup()Colin Walters2019-10-181-3/+2
| | | | This is clearer and silences a scan-build warning.
* lib: Port variant-builder.c to new styleColin Walters2019-10-181-14/+7
| | | | Seeing `scan-build` warning here, prep for fixing it.
* libotutil: Port keyfile-utils.c to new styleColin Walters2019-10-161-39/+25
| | | | | | | | | | | | | I was trying to fix a clang `scan-build` error that jlebon ended up tracking down in https://github.com/ostreedev/ostree/pull/1939/commits/9344de1ce1e8c185e01988277606ba1ed7f9d16b But in the process of tracing through this I found it way easier to read as "new style" code, so this also ports the code. I added a `g_assert()` in there too to help assert that `g_key_file_get_value` won't leak in the error path.
* src/libotutil: Fix strv memory leakJonathan Lebon2019-10-151-4/+4
| | | | | | | We were only freeing the array and not the members. Caught by `clang-analyzer` in: https://github.com/ostreedev/ostree/pull/1931
* lib/gpg: Use g_spawn_sync to kill gpg-agentDan Nicholson2019-09-071-25/+26
| | | | | | | | | | | | | For reasons I don't understand, GSubprocess doesn't play nice with KDE's plasmashell. I assume this has something to do with the GSubprocess using the glib worker thread while plasmashell uses the glib main loop. Instead, just use g_spawn_sync to fork and wait in the current thread. Fixes: #1913 Closes: #1917 Approved by: cgwalters
* lib/gpg: Don't kill gpg-agent on newer gnupgDan Nicholson2019-09-061-0/+65
| | | | | | | | | | | | | | | GnuPG 2.1.17 contains a bug fix so that `gpg-agent` is killed when the entire GPG home directory is deleted[1]. If the host's GnuPG is new enough, then we don't need to bother calling `gpg-connect-agent` to kill the agent since it will be cleaned up on its own. Get the GnuPG version from the GPGME OpenPGP engine info and parse it to see if it matches this criteria. 1. https://dev.gnupg.org/T2756 Closes: #1915 Approved by: cgwalters
* lib/gpg: Only show gpg-connect-agent stderr on failuresDan Nicholson2019-09-021-8/+17
| | | | | | | | | | | | | | | | | | | | When listing GPG keys, the temporary GPG homedir will be constructed by simply copying the remote's trusted keys to the pubring.gpg file. In that case, no GPG operations spawning gpg-agent will be run. When gpg-connect-agent is run to cleanup the homedir, it will helpfully print on stderr that it's starting gpg-agent like so: gpg-connect-agent: no running gpg-agent - starting '/usr/bin/gpg-agent' gpg-connect-agent: waiting for the agent to come up ... (5s) gpg-connect-agent: connection to agent established Send gpg-connect-agent's stderr to a pipe and only send it to the application's stderr if an error was encountered. Fixes: #1907 Closes: #1908 Approved by: cgwalters
* gpg: conditionally build GPG-related code for sign/verificationDenis Pynkin2019-08-011-1/+4
| | | | | | | | | | | | Do not build the code related to GPG sign and verification if GPGME support is disabled. Public functions return error 'G_IO_ERROR_NOT_SUPPORTED' in case if gpg-related check is rquested. Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com> Closes: #1889 Approved by: cgwalters
* lib/gpg: Add helper to kill GPG agentDan Nicholson2019-06-192-0/+28
| | | | | | | | | | With GnuPG 2, any time you do basically any operation, a gpg-agent will be spawned for the GPG home directory in use. The classic way to kill a gpg-agent is to use `gpg-connect-agent` and send the `killagent` command as is done in libtest.sh. Closes: #1799 Approved by: cgwalters
* lib/kargs: Make API public and upstream new rpm-ostree APIsAllen Bai2019-06-183-0/+58
| | | | | | | | | | | | | | | | This change makes public the current kargs API in src/libostree/ostree-kernel-args.c and adds documentations. Upstreams the new kargs API from rpm-ostree/src/libpriv/rpmostree-kargs-process.c Merges libostree_kernel_args_la_SOURCES to libostree_1_la_SOURCES in Makefile-libostree.am Upstreams tests/check/test-kargs.c from rpm-ostree. Closes: #1833 Closes: #1869 Approved by: jlebon
* lib/util: Fix segfault when validating filenameAllen Bai2019-06-061-0/+2
| | | | | | | | | This change fixes the segfault issue when calling ostree_repo_checkout_tree with empty GFileInfo. A simple condition check for NULL value is added at src/libotutil/ot-unix-utils.c:46. Closes: ostreedev#1864. Closes: #1868 Approved by: jlebon
* lib: Add ot_journal_* helper macrosJonathan Lebon2019-04-241-0/+8
| | | | | | | | | Rather than wrapping each instance of `sd_journal_*` with `HAVE_SYSTEMD`, let's just add some convenience macros that are just no-op if we're not compiling with systemd. Closes: #1841 Approved by: cgwalters
* libotutil: Add ot_keyfile_get_value_with_default_group_optional()Robert Fairley2019-03-012-0/+44
| | | | | | | | | | Add ot_keyfile_get_value_with_default_group_optional() which allows getting values from keys where the group is optional in the config file. This is preparatory to add the sysroot.bootloader repo config key, where the sysroot group is optional. Closes: #1814 Approved by: jlebon
* libotutil: Rename to ot_keyfile_get_string_list_with_separator_choice()Robert Fairley2019-03-012-18/+17
| | | | | | | | | | Rename ot_keyfile_get_string_as_list() to ot_keyfile_get_string_list_with_separator_choice() which expresses more clearly why the function is needed. Also shorten the function comment. Closes: #1814 Approved by: jlebon
* lib/repo: Search a list of paths in gpgkeypath for gpg keysrfairley2018-11-212-0/+118
| | | | | | | | | | | | | | | | | | This allows specifying gpgpath as list of paths that can point to a file or a directory. If a directory path is given, paths to all regular files in the directory are added to the remote as gpg ascii keys. If the path is not a directory, the file is directly added (whether regular file, empty - errors will be reported later when verifying gpg keys e.g. when pulling). Adding the gpgkeypath property looks like: ostree --repo=repo remote add --set=gpgpath="/path/key1.asc,/path/keys.d" R1 https://example.com/some/remote/ostree/repo Closes #773 Closes: #1773 Approved by: cgwalters
* lib: Fix some logic/error-checking codeJonathan Lebon2018-07-261-5/+3
| | | | | | | | | | | | | | | | | Using `MAX(0, $x)` here is useless since we're comparing against an unsigned integer. Just unpack this and only subtract if it's safe to do so. Also, explicitly check for `fd >= 0` rather than just `!= -1` to be sure it's a valid fd. And finally, explicitly check the return value of `g_input_stream_read_all` as is done everywhere else in the tree and make it clear that we're purposely ignoring the return value of `_flush` here, but not in other places. Discovered by Coverity. Closes: #1692 Approved by: cgwalters
* libotutil/checksum-utils: Fix memory managementMatthew Leeds2018-03-291-2/+4
| | | | | | | | | | | | | | | Ostree uses the OtChecksum data structure as a wrapper around GChecksum (depending on what libraries are available at compile time). According to the docs for g_checksum_get_digest(), a GChecksum value can no longer be updated after that function is called. Ostree enforces this by setting "initialized" to FALSE after getting the digest, but this leads to ot_checksum_clear() avoiding freeing any memory, leading to leaks. So this commit adds a "closed" value that gets set when getting a digest and checked when updating the value, so the initialized value can be used only for memory management. Closes: #1521 Approved by: jlebon
* libotutil: factor out utility to parse file by lineJonathan Lebon2018-02-022-0/+33
| | | | | | | This will be used in the checkout CLI as well. Closes: #1442 Approved by: cgwalters
* Add SPDX-License-Identifier to source filesMarcus Folkesson2018-01-3023-0/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | SPDX License List is a list of (common) open source licenses that can be referred to by a “short identifier”. It has several advantages compared to the common "license header texts" usually found in source files. Some of the advantages: * It is precise; there is no ambiguity due to variations in license header text * It is language neutral * It is easy to machine process * It is concise * It is simple and can be used without much cost in interpreted environments like java Script, etc. * An SPDX license identifier is immutable. * It provides simple guidance for developers who want to make sure the license for their code is respected See http://spdx.org for further reading. Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com> Closes: #1439 Approved by: cgwalters
* lib/commit: Use more direct path for regfile commitsColin Walters2017-12-122-0/+14
| | | | | | | | | | | | | | | | | | | | | In the non-`CONSUME` path for regfiles (which happens currently for `bare-user`), we go to a lot of contortions to make an "object stream", only to immediately parse it again. Fixing this will also enable the `G_IS_FILE_DESCRIPTOR_BASED()` fast path in commit, since the input stream will actually reference the file descriptor and not be an `_OstreeChainInputStream`. There's a slight concern here in that we're no longer checksumming *literally* the object stream passed in for the stream case, but I mention in the comment, the data should be the same, and if it's not somehow we're not adding risk, since the checksum is still covering the data we actually care about. Prep for further changes to break up the `write_content_object()` path into separate paths for archive, as well as regfile vs symlink in non-archive. Closes: #1371 Approved by: jlebon
* Add OtVariantBuilderAlexander Larsson2017-10-273-0/+1281
| | | | | | | | | | This is similar to GVariantBuilder in that it constructs variant containers, but it writes it directly to a file descriptor rather than keep the entier thing in memory. This is useful to create large variants without using a lot of memory. Closes: #1309 Approved by: cgwalters
* lib/repo: Update summary code to use newer hashing APIColin Walters2017-10-182-16/+0
| | | | | | | And drop the unnecessary wrapper. Closes: #1287 Approved by: jlebon
* lib/utils: Check for invalid UTF-8 in filenamesMatthew Leeds2017-10-141-0/+2
| | | | | | | | | | In case a filename contains invalid UTF-8 characters, libostree will pass it to g_variant_builder_add() in create_tree_variant_from_hashes() anyway, which leads to a critical warning from glib and an invalid commit. This commit makes ostree print a useful error and exit instead. Closes: #1271 Approved by: cgwalters
* tree-wide: Update to new libglnx fd APIsColin Walters2017-10-111-2/+2
| | | | | | | | | | | | | | | | | | | This ends up a lot better IMO. This commit is *mostly* just `s/glnx_close_fd/glnx_autofd`, but there's also a number of hunks like: ``` - if (self->sysroot_fd != -1) - { - (void) close (self->sysroot_fd); - self->sysroot_fd = -1; - } + glnx_close_fd (&self->sysroot_fd); ``` Update submodule: libglnx Closes: #1259 Approved by: jlebon
* lib/core: Use GBytes for file headersColin Walters2017-10-111-0/+8
| | | | | | | | | | | | | | | | | | | This simplifies a lot of code; the header function was structured to write to an input stream, but many callers only wanted the checksum, so it's simpler (and error-free) to simply allocate a whole buffer and checksum that. For the callers that want to write it, it's also still simpler to allocate the buffer and write the whole thing rather than having this function do the writing. A lot of the complexity here again is a legacy of the packfile code, which is dead. This is prep for faster regfile commits where we can avoid `G{In,Out}putStream`. Closes: #1257 Approved by: jlebon
* libotutil/checksum-utils: fix openssl compilationJonathan Lebon2017-10-111-2/+3
| | | | | Closes: #1261 Approved by: cgwalters
* lib: Add a lighter weight internal checksum wrapperColin Walters2017-10-104-149/+177
| | | | | | | | | | | | | | | | The faster (OpenSSL/GnuTLS) code lived in a `GInputStream` wrapper, and that adds a lot of weight (GObject + vtable calls). Move it into a simple autoptr-struct wrapper, and use it in the metadata path, so we're now using the faster checksums there too. This also drops a malloc there as the new API does hexdigest in place to a buffer. Prep for more work in the commit path to avoid `GInputStream` for local file commits, and ["adopting" files](https://github.com/ostreedev/ostree/pull/1255). Closes: #1256 Approved by: jlebon
* lib/deltas: Move variant read helper into the deltas codeColin Walters2017-10-052-15/+0
| | | | | | | | | What the deltas code is doing is weird/unfortunate. The name `ot_variant_read()` conflicts too much with `ot_variant_read_fd()`. Since nothing else uses it, move it into the deltas code. Closes: #1254 Approved by: jlebon
* lib/util: Delete some unused functionsColin Walters2017-10-054-68/+0
| | | | | | | Hooray, dead code. Closes: #1254 Approved by: jlebon
* lib/utils: Port a bit to decl-after-stmt styleColin Walters2017-10-053-82/+55
| | | | | | | Add add some more comments. Closes: #1247 Approved by: jlebon
* Deduplicate and fix up our use of mmap()Colin Walters2017-10-044-111/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Buried in this large patch is a logical fix: ``` - if (!map) - return glnx_throw_errno_prefix (error, "mmap"); + if (map == (void*)-1) + return glnx_null_throw_errno_prefix (error, "mmap"); ``` Which would have helped me debug another patch I was working on. But it turns out that actually correctly checking for errors from `mmap()` triggers lots of other bugs - basically because we sometimes handle zero-length variants (in detached metadata). When we start actually returning errors due to this, things break. (It wasn't a problem in practice before because most things looked at the zero size, not the data). Anyways there's a bigger picture issue here - a while ago we made a fix to only use `mmap()` for reading metadata from disk only if it was large enough (i.e. `>16k`). But that didn't help various other paths in the pull code and others that were directly doing the `mmap()`. Fix this by having a proper low level fs helper that does "read all data from fd+offset into GBytes", which handles the size check. Then the `GVariant` bits are just a clean layer on top of this. (At the small cost of an additional allocation) Side note: I had to remind myself, but the reason we can't just use `GMappedFile` here is it doesn't support passing an offset into `mmap()`. Closes: #1251 Approved by: jlebon
* Add --with-crypto=gnutlsJussi Laako2017-09-251-9/+49
| | | | | | | | | | | | | | | | | | | | | | | | | Introduce support for GnuTLS for computing cryptograpic hashes, similar to the OpenSSL backend. A reason to do this is some distributors want to avoid GPLv3, and GPG pulls that in. A possible extension of using GnuTLS would be replacing the GPG signing with `PKCS#7` signatures and `X.509` keys. We also support `--with-crypto=openssl`, which has the same effect as `--with-openssl`, and continues to be supported. Changes by Colin Walters <walters@verbum.org>: - Drop libgcrypt option for now - Unify buildsystem on --with-crypto Link: https://mail.gnome.org/archives/ostree-list/2017-June/msg00002.html Signed-off-by: Jussi Laako <jussi.laako@linux.intel.com> Closes: #1189 Approved by: cgwalters
* tree-wide: Remove Emacs modelinesColin Walters2017-09-2122-44/+22
| | | | | | | | | We added a `.dir-locals.el` in commit: 9a77017d87b74c5e2895cdd64ad098018929403f There's no need to have it per-file, with that people might think to add other editors, which is the wrong direction. Closes: #1206 Approved by: jlebon
* tree-wide: Some glnx_fstatat_allow_noent() portingColin Walters2017-09-192-26/+0
| | | | | | | The new API is definitely nicer. Closes: #1180 Approved by: jlebon
* tree-wide: Use helpers for unlinkat()Colin Walters2017-09-071-0/+1
| | | | | | | | | | | | We have `ot_ensure_unlinked_at()` for the "ignore ENOENT" case, and `glnx_unlinkat()` otherwise. Port all in-tree callers to one or the other as appropriate. Just noticed an unprefixed error in the refs case and decided to do a tree-wide check. Closes: #1142 Approved by: jlebon
* lib/gpg: Use nicer helper for gpg error messagesColin Walters2017-09-072-20/+19
| | | | | | | | | | | | The vast majority of invocations of `ot_gpgme_error_to_gio_error()` were paired with `g_prefix_error()`; let's combine them for the same reason we do `glnx_throw_errno_prefix()`. For the few cases that don't we might as well add some prefix. I also changed it to `return FALSE` in prep for more style porting. Closes: #1135 Approved by: jlebon
* lib/sysroot: Add journal-msg signalColin Walters2017-08-103-197/+0
| | | | | | | | | | | | | | | This will allow us to drop the awful hack in rpm-ostree where we watch our own stdout. In general, libraries shouldn't write to stdout. Also we can kill the systemd journal wrapper code. There's some duplication at each call site now...but it's easier than trying to write a `sd_journal_send()` wrapper. I was originally going to have this emit all of the structured data too as a `GVariant` but decided it wasn't worth it right now. Closes: #1052 Approved by: jlebon
* tree-wide: Remove trailing semicolon from autoptr declarationsColin Walters2017-08-072-3/+3
| | | | | | | It confuses `g-ir-scanner`, and isn't necessary. Closes: #1056 Approved by: pwithnall
* lib: Define and use an autoptr cleanup for gpgme_key_tColin Walters2017-08-031-0/+1
| | | | | | | Followup for previous patch, allows porting a bit to new code style. Closes: #1039 Approved by: jlebon
* lib/deploy: Add structured logging info for syncfs() timesColin Walters2017-08-022-1/+3
| | | | | | | | I plan to at some point change rpm-ostree to read the journal messages from libostree and render things like the time we spent in syncfs(). Closes: #1044 Approved by: jlebon