107 Commits
Author SHA1 Message Date
Caio Marcelo de Oliveira Filho fe6040cca6 Add 'swupd clean' command
This command removes old files from statedir. The interface is a bit
opaque so there will be room to modify the policy later.

By default it will delete staged files that are older than
DAYS_TO_KEEP_FILES. For manifests this heuristic is not good as older
manifests might still be used for the current OS version being run, so
also ensure that those do not get deleted. This prevents 'swupd
search' to redownload files.

The default behavior should be suitable to use in combination with
automatic updates, to control the size of state dir. There is also an
--all option to remove all the state files regardless of dates and
usage.

To avoid "disasters" in case some paths are set wrong, the command
explicitly delete patterns of files create by swupd.
2018-02-27 09:46:19 -08:00
Matthew Johnson de9c2c4dd8 Make some small improvements to new swupd search
Remove some of the magic numbers, add some comments, fix some code
style, remove an unnecessary string duplication, free dynamically
allocated memory in response to feedback on PR #387.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-02-21 17:45:28 -08:00
Caio Marcelo de Oliveira Filho b0699e2a55 Fix invalid memory reads when listing local bundles
When closedir() is called, the directory names are not valid anymore,
but read_local_bundles() was returning a list of them. The related
valgrind message

==20540== Invalid read of size 1
==20540==    at 0x48353E8: mempcpy (vg_replace_strmem.c:1524)
==20540==    by 0x50F0E30: _IO_file_xsputn (in /usr/lib64/haswell/libc-2.26.so)
==20540==    by 0x50E5CAE: puts (in /usr/lib64/haswell/libc-2.26.so)
==20540==    by 0x408187: printf (stdio2.h:104)
==20540==    by 0x408187: bundle_list_main (clr_bundle_ls.c:232)
==20540==    by 0x508CF69: (below main) (in /usr/lib64/haswell/libc-2.26.so)
==20540==  Address 0x58a70fb is 859 bytes inside a block of size 32,816 free'd
==20540==    at 0x482CD0B: free (vg_replace_malloc.c:530)
==20540==    by 0x51481CC: closedir (in /usr/lib64/haswell/libc-2.26.so)
==20540==    by 0x484F4E3: read_local_bundles (bundle.c:937)
==20540==    by 0x408154: bundle_list_main (clr_bundle_ls.c:225)
==20540==    by 0x508CF69: (below main) (in /usr/lib64/haswell/libc-2.26.so)
==20540==  Block was alloc'd at
==20540==    at 0x482BADF: malloc (vg_replace_malloc.c:299)
==20540==    by 0x5147F2D: ??? (in /usr/lib64/haswell/libc-2.26.so)
==20540==    by 0x484F486: read_local_bundles (bundle.c:926)
==20540==    by 0x408154: bundle_list_main (clr_bundle_ls.c:225)
==20540==    by 0x508CF69: (below main) (in /usr/lib64/haswell/libc-2.26.so)

Instead of duplicating the strings to return, just renamed it to
list_local_bundles() and sorted / printed before closedir() call. This
makes that code similar to the other listing functions.
2018-02-09 21:22:00 -08:00
Caio Marcelo de Oliveira Filho 88eea5f9e9 Add info command to show OS version and URLs
Fixes #218.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
2018-01-25 10:02:44 -08:00
Matthew Johnson aef0cc4490 Add free_string function and use everywhere
Fixes #357
Add free_string() function to insure code is consistently resetting
pointers to NULL after resetting dynamic memory. Use this helper
everywhere strings are being freed.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2018-01-19 10:31:15 -08:00
Matthew Johnson 85cc5a7fe4 Do not try to resume failed bundle-add pack downloads
Fixes #352
This operation is fragile and can cause errors if a zero pack download
is interrupted resulting in an incomplete tar archive. A user reported
that having the incomplete pack around prevented the pack from being
re-downloaded and the content was incorrect so the bundle-add was not
completing. Instead of trying to resume a bundle-add pack download just
remove the old file and try again.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-12-13 16:00:04 -08:00
Matthew Johnson 6043f4700b Use libarchive instead of calling out to tar
Use libarchive in order to make use of its security features and avoid
calling out to tar via a shell. The TAR_COMMAND is still used in
staging.c to complete the copy when a hardlink fails.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-11-30 17:15:40 -08:00
Patrick Ohly d59738ece7 swupd verify: fix --picky, add --picky-tree and--picky-whitelist
The code implementing the suppression of /usr/lib/kernel,
/usr/lib/modules and /usr/local did a rather simplistic prefix
comparison with strncmp() to match path names against these
exceptions. As a result, paths like /usr/lib/kernel.old which should
get reported also got skipped.

An if check tested the wrong variable, so the result from strdup()
wasn't checked.

The replacement code uses regular expression matching and allows
replacing the default (--picky-whitelist
"/ignore-this-top-level-dir"). A single parameter is enough when using
the | operator.

A/B partition update must remove extra files in the entire partition,
which can be selected with --picky-tree=/, and also needs to override
the default whitelist.

Fixes #336
Implements #239

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2017-11-30 17:15:09 -08:00
Tudor Marcu 2793bda3a6 Move bsearch_helper into only file it is used
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu be4c7bdba1 Block on manifest collisions but allow override
When content mismatches in the user manifest and the upstream content,
that is - the filenames are equal but the hashes are not, this signifies
that something is being introduced that already exists and is not the
same. Currently, only additive functionality is fully guaranteed to work,
so existing packages can be added as long as they are the same as the ones
provided by upstream. If non-unique content is added, all conflicts will be
printed out to the user so it can be fixed, and swupd will exit unless it
is given the allow-mix-collisions override flag.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu 71a58815bd Replace hardcoded paths and update URL comparison
Use defines instead, and check the user passed in URL against the URLs listed
in the official upstream contenturl file vs a static hardcoded URL.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu e910900b1b Add better error handling throughout and cleanup
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu e18eb6917f Update to support new state if system is on a mix
This patch adds the logic required to handle files and manifests
differently if it is detected that the system is on a mix, or the
content being provided is local mix content.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu e9cb557676 Convert manifest to array
Until internal data structures are fully migrated, provide a helper function
to transform a loaded manifest to an array. We can then do file lookups in
O(logn) time using binary search instead of traversing linked lists.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu c7f37aec32 Move bsearch helper out to use in other functions
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Tudor Marcu 20dc4ed84f Store 'filecount' field from manifest header
The filecount field becomes relevant when using an array implementation
of the manifest contents, so store it in the struct.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-11-03 11:50:08 -07:00
Matthew Johnson 2658bd4959 Add --no-scripts flag to skip post-update scripts
Add the --no-scripts flag to update, verify, and bundle-add commands to
allow users to skip the post update scripts for these commands. This is
useful when running in environments when systemctl is not available such
as containers.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-11-02 09:07:39 -07:00
Matthew Johnson c79297886b Fix re-exec capabilities over format bumps
Instead of relying on swupd-server to put the post-update action in the
correct manifest and in the correct format, do the format change
detection on the client.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-10-19 09:51:08 -07:00
Patrick McCarty ed7a52aa1c Remove unused check_network() declaration
The check_network() function definition was recently removed, but the
declaration remained. Remove the declaration as well.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2017-10-19 09:46:13 -07:00
Matthew Johnson 44cdf0c44c Implement ghosted file handling
Implement handling of ghosted files in manifests via the 'g' flag. These
files are treated the same as deleted files except that they are not
actually deleted during the update. This allows ghosted files to serve
as the basis for renames while not actually being deleted by swupd.

This change also covers the verify --fix and verify --fix --picky paths.
Ghosted files will be ignored in these cases.

An example of where this is useful is with kernel files, which are
deleted from /usr/lib/kernel/ by clr-boot-manager but should still be
marked as deleted to utilize the rename functionality.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-10-16 14:16:31 -07:00
Arzhan Kinzhalin feadea96b6 Implement fallback CApath support.
A colon-separated list of alternative CApath options can be passed to
swupd-client at the configuration time using --with-fallback-capaths
option.

In runtime, fallback CApath support is implemented as part of the
connectivity check. The implementation will try the default (built into
curl) and then will iterate through the list in the order they were
specified. It is done only once on the first call.

The code is reorganized to keep the connectivity check inside curl
wrapper:

* Deleted check_network implementation from version.c
* Removed have_network global (globals.c)
* Scoped swupd_curl_test_resume to curl.c
* Change use of check_network to swupd_curl_check_network

Also:

* Fixed an issue where SSL was only enabled if a URL was matching the
  content URL
2017-10-02 11:30:48 -07:00
Patrick Ohly e562379004 downloads: support mixing http and file URLs
swupd used to enforce that version and content URL had to use the same
protocol because then it only needed to check once whether it was
downloading locally.

However, it's not that much more difficult to check each individual
URL, so now that's what swupd does now and thus the restriction is
gone.

Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
2017-09-28 15:03:31 -07:00
Matthew Johnson c23dfb558c Add --no-boot-update flag for container usage
Since clr-boot-manager does not work in a container add the
--no-boot-update option to allow installation into a container to skip
the boot partition management. This also calls apply_heuristics when
running bundle-add, with the result of running CBM when necessary for
bundle-adds and skipping CBM when the --no-boot-update flag is
specified.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-09-15 10:44:32 -07:00
Matthew Johnson 5bc1a646bd Require -x or -Y when verifying to different version
When running verify --fix with -m specifying a different version than
the current OS version, require --picky to enforce management of files
under /usr or require --force as an override. Adding --picky can solve
issues such as issue #238 where fixing backward caused glibc library
confusion.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-09-12 11:48:44 -07:00
Matthew Johnson da21ad7eef Add bundlelist --deps subcommand
Allow user to list all bundle dependencies of a bundle passed to

swupd bundle-list --deps BUNDLE

This lists all included bundles (included those recursively included)
for the BUNDLE. This is particularly useful when applications or users
need to determine just how large the bundle addition will be. For
example, a user may not be aware that by bundle-adding desktop-dev they
are recursively adding 12 other bundles. This command allows the user to
make this check before installation.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-31 09:50:50 -07:00
Matthew Johnson ee06e85931 Add --has-dep argument to bundle list
The --has-dep=BUNDLE argument will display a tree representing all
installed bundles that recursively include BUNDLE.

One may pass the --all argument as well to list the dependency tree for
BUNDLE including all installable bundles available on the server.

**Example output without --all:**

Installed bundles that have os-installer as a dependency:
format:
 # * is-required-by
 #   |-- is-required-by
 # * is-also-required-by
 # ...

  * mixer
    |-- os-clr-on-clr

**Example output with --all:**

Attempting to download version string to memory
All installable and installed bundles that have os-installer as a dependency:
format:
 # * is-required-by
 #   |-- is-required-by
 # * is-also-required-by
 # ...

  * clr-devops
  * mixer
    |-- os-clr-on-clr
        |-- os-clr-on-clr-dev
    |-- clr-devops
    |-- os-clr-on-clr-dev

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-31 09:50:50 -07:00
Patrick McCarty e6cdcf8aa1 verify: enforce format transitions
When using verify's -m option, it generally only makes sense to verify a
build within the same format, since the subsequent format (if any) might
not be compatible. Therefore, we should disallow verifying to a build
with a different format by default. This commit adds the proper
enforcement by making this condition a fatal error. The early exit can
be bypassed using the -x/--force option, which will print a warning
message instead.

For now, this compatibility check is targeting the use case of verifying
to a newer build, so I also report the latest supported build for the
current format. Verifying to an older build is not guaranteed to succeed
at present, and swupd-client does not yet understand the
version/formatN/first file. In other words, reporting to the user the
oldest build they can verify to will be a future improvement.

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2017-08-30 11:12:50 -07:00
Matthew Johnson 43689e86d0 Add basic progress status for long-running tasks
Add a basic progress indication for a couple potentially long-running
swupd tasks (download_pack and add_missing_files). The progress
indication is displayed as a percentage:

...85%

It overwrites its own line so the progress will update in place. It may
be interrupted by other swupd output:

...45%
Extracting os-core pack for version 10000
...50%
Extracting os-core-update pack for version 9000
...55%

The progress indication will then resume updating in place, on the same
line.

This progress is only displayed when outputting to a TTY, and will not
output anything when the output is being redirected. This is nice for
testing and logging, but means that these progress updates will not be
caught by processes that capture swupd output, such as ister.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-08-17 15:37:15 -07:00
Matthew Johnson 89af564256 Convert post_update_actions to list-based approach
Instead of allowing only one "actions:" field in the Manifest.MoM, allow
for several and read each into the post_udpate_actions list. This allows
us to add more actions down the road if desired.

Currently the only use for the "actions:" field is to indicate when a
re-update is required. This is handled by checking if the string
"update" is in the post_update_actions list.

Finally, remove the warning to the user to perform the post update
action themselves, as this will be handled by swupd itself. Functional
tests updated to reflect the missing output.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-07-28 23:19:54 -07:00
Matthew Johnson 9b0701cf77 Add inconsistent version files check while re-updating
Adds a check to compare version numbers in <state_dir>/version and
<target_dir>/usr/lib/os-release when attempting to re-update after a
format bump.

os-release should always be equal to <state_dir>/version for normal
updates and potentially greater than <state_dir>/version for format
bumps.

In the event of a bad build where os-release does not get updated to the
new version, this check will prevent an infinite loop where swupd reads
the current version from os-release, sees it is out of date, attempts to
update again, but the file does not get updated.

This occasion is very unlikely but the guard is nice to have
re(guard)less.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-07-28 23:19:54 -07:00
Matthew Johnson 0bc2cdb790 Re-execute swupd update for format bumps
When a device is out of date by more than a format bump re-exec swupd
update until the device version matches the server version. This is
achieved by reading the "actions" field in the Manifest.MoM, which is
yet to be implemented in swupd-server. When "update" is specified in the
actions of the current manifest and the current update is successful,
swupd will re-exec itself with the same flags it was originally called
with.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
2017-07-28 23:19:54 -07:00
Auke Kok 22cccd9a04 Differentiate between various early network failures.
We draw a hard line with error codes, such that:

Error code 16 is reserved for failures resulting from the basic
network check. Any call to check_network() that fails will
return this error code. No other error path returns this
error code.

Additionally, check_network() is called in every normal code path.

All other, possibly network related issues, return a different
error code. If the basic network check succeeds, but e.g. pack
downloads fail, we return a new (23) error code so that we
can better establish the conditions through telemetry and
determine whether the error is on the client or the server,
which is highly likely with this new error code 23.
2017-07-20 16:18:33 -07:00
Tudor Marcu ca3401e7fa Add verify --fix --picky functionality
This is the basic implementation for a "factory reset" type of command.
It will take the functionality of verify --picky and act on the files found
as verify --fix does with files found mismatching in the manifest.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-05-25 16:41:13 -07:00
Icarus Sparry 2487e5b5d0 Add swupd autoupdate command
"swupd autoupdate" returns 0 if autoupdates are enabled.
"sudo autoupdate --enable" will unmask swupd-update.service
"sudo autoupdate --disable" will mask swupd-update.service

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2017-05-17 15:28:44 -07:00
Icarus Sparry 4afaf2c312 Add verify --picky command
Add a "swupd verify --picky" command which lists files under
/usr (modified by the --path option) which are not listed in the
current manifest. Exceptions /usr/local and /usr/lib/modules. The
former to allow for local changes, the latter because the clear boot
manager owns that directory.

Signed-off-by: Icarus Sparry <icarus.w.sparry@intel.com>
2017-05-09 12:53:14 -07:00
Tudor Marcu 55cca1291a Only take actions from newest MoM
The update process should only read in post update action from the newest
MoM. This makes it so that even with a previous MoM having an action, only
the new one will be taken, and if none exist, the old one will be ignored
so swupd will not take the same action as the previous update.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-05-09 09:40:47 -07:00
Tudor Marcu 0fbc8cb6b1 Add support for new manifest header line
The swupd client should support parsing extra data in the case that a format
bump occurred, or other possibly breaking change, so that it can at least
notify the user of more action needing to be taken post update.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-05-09 09:40:47 -07:00
Tudor Marcu 64ff23d329 Refactor flow of manifest loading
The current implementation is not setup to optimally load manifests and attempt deltas.
This changes the flow to be as follows:
1.) Load current Manifest.MoM
2.) Load server Manifest.MoM
3.) Recurse and load all current manifests, since we know exactly which are needed already
4.) Link current and server Manifest.MoMs, setting versions and peers
5.) Load server manifests recursively adding their includes
6.) Recurse the server manifests to find and load any new included bundles
7.) Link current and server Manifest.MoMs again to account for new bundles

When loading the server manifests, deltas will attempt to be applied to
current manifests before doing a full download. Following this flow enables
swupd to load manifests in a logical order, and short circuit trying to
reload them later on as manifests are recursed for includes again later.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-04-19 16:41:59 -07:00
Tudor Marcu 3c87523101 Use correct version for adding included manifests
The current version must be passed to add_subscriptions, else it will call
load_manifest() with equal current and server versions and never enter the
try_delta_manifest code path.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-04-19 16:41:59 -07:00
Tudor Marcu 9868bedb83 Need to reexec systemd if it changed
We must not run these with --no-block because order must be preserved,
and critical components may need to be reexec'd, making this a core piece
of the swupd update process.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-04-17 17:10:34 -07:00
Tudor Marcu 14abf7027e Remove bad or unusable Manifest content and retry
For various reasons - partial downloads, power failure, user exiting -
the /var/lib/swupd state directory may become corrupt. When this happens,
manifests can be rendered unusable, causing various errors in swupd such as
signature failures, or errors reading the manifest. This patch attempts to
avoid such things causing updates or verifies to fail by cleaning up the
Manifests artifacts of what it could not use, and re-downloading them to
try again.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-04-04 11:48:26 -07:00
Tudor Marcu a668c07265 Fix code style issues
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-03-29 10:11:08 -07:00
Tudor Marcu 0d346c3b7f Add verbose timing to swupd operation
This introduces a -t/--time option to update, verify, and bundle-add commands, displaying raw elapsed time and CPU process time for integral swupd operations within the given code paths.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-03-29 09:42:21 -07:00
Tudor Marcu 0b60890bd1 Fix code style compliance
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-03-25 00:06:35 -07:00
Tudor Marcu fd6b54d964 Try to recover from invalid certificate date
The system clock may be terribly off, especially on new hardware that has not
yet been calibrated. Updates rely on the certificate and system time being
sane to verify validity, so if a mismatch is found the certificate will
be deemed invalid and the update stopped. This patch attempts to fix the
system time to something sane using the time from the swupd binary itself,
which should not have been touched by any user except root. If the time is
normal and verification fails, the cert cannot be trusted.

Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-03-25 00:00:41 -07:00
Tudor Marcu 428d09d003 Move signature verification to mandatory
This sets swupd signature verification to mandatory, failing and exiting
for any verify error, though --nosigcheck enables user to bypass all
signature-based security checks.

The signed MoM serves as the top level chain of trust, and it is used to
extend content trust down to the individual file level. When the signature
of the top-level MoM is invalid or cannot be verified for any reason, we
warn and abort the operation.

Passing --nosigcheck will allow this to proceed, explicitly accepting the
unverifiable MoM and outputting a log entry to the Journal. This is not
recommended and unsupported by upstream once the chain of security is broken,
because it may imply update content was or may be installed that was not
generated by the official upstream.

Signed-off-by: Brad T. Peters <brad.t.peters@intel.com>
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-01-25 15:00:24 -08:00
Tudor Marcu 06c6211561 Fix style for compliance
Signed-off-by: Tudor Marcu <tudor.marcu@intel.com>
2017-01-24 17:27:15 -08:00
Mario Alfredo Carrillo Arevalo bcce348e1b Add new bundle-list sub-command
This is a new sub-command for swupd called
"bundle-list", this command will show which
bundles are installed in the local system.
This information is obtained reading
/usr/share/clear/bundles path in local filesystem.

Signed-off-by: Mario Alfredo Carrillo Arevalo <mario.alfredo.c.arevalo@intel.com>
2017-01-18 09:52:49 -08:00
Mario Alfredo Carrillo Arevalo c244d36be3 Add function that reads local installed bundles
This function reads installed bundles from local standard
directory and store them in a list pointer passed as argument, this
function is the base for functionality as listing installed bundles to
user.

Signed-off-by: Mario Alfredo Carrillo Arevalo <mario.alfredo.c.arevalo@intel.com>
2017-01-18 09:52:49 -08:00
Patrick McCarty 0d85b51731 Add runtime override capability for the cert path
There is a need to override the cert path at runtime, so migrate to
using a global variable that is set in init_globals().

Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
2016-12-20 15:39:13 -08:00