mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-10-04 07:48:47 +00:00
Initial commit
Signed-off-by: Patrick McCarty <patrick.mccarty@intel.com>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#ifndef __LIST__
|
||||
#define __LIST__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct list {
|
||||
void *data;
|
||||
struct list *prev;
|
||||
struct list *next;
|
||||
};
|
||||
|
||||
typedef int (*comparison_fn_t)(const void *a, const void *b);
|
||||
typedef void (*list_free_data_fn_t) (void *data);
|
||||
|
||||
/* creates a new list item, store data, and inserts item in list (which can
|
||||
* be NULL). Returns created link, or NULL if failure. Created link can be
|
||||
* used as the list parameter to efficiently append new elements without
|
||||
* having to traverse the whole list to find the last one. */
|
||||
struct list *list_append_data(struct list *list, void *data);
|
||||
struct list *list_prepend_data(struct list *list, void *data);
|
||||
|
||||
/* Returns the head or the tail of a list given anyone of its items */
|
||||
struct list *list_head(struct list *item);
|
||||
struct list *list_tail(struct list *item);
|
||||
|
||||
/* Returns the length of a list given anyone of its items */
|
||||
unsigned int list_len(struct list *list);
|
||||
|
||||
#if 0
|
||||
/* Finds and returns the list item containing the parameter data */
|
||||
struct list *list_find_data(struct list *list, void *data);
|
||||
#endif
|
||||
|
||||
/* Sorts the list using the comparison function. list can be any item in the
|
||||
* list, the complete list will still be sorted. Returns the first item in
|
||||
* the sorted list. */
|
||||
struct list *list_sort(struct list *list, comparison_fn_t comparison_fn);
|
||||
|
||||
/* appends list2 at the tail of list1. Either list1 or list2 can be NULL.
|
||||
* returns the head of the resulting concatenation */
|
||||
struct list *list_concat(struct list *list1, struct list *list2);
|
||||
|
||||
/* unlink item from its list, call list_free_data_fn to free its data,
|
||||
* and free the item itself. Always returns the preceding item, except in
|
||||
* case head is freed - then return the new head. If this was the last item,
|
||||
* returns NULL */
|
||||
struct list *list_free_item(struct list *item, list_free_data_fn_t list_free_data_fn);
|
||||
/* destroy all items in the list, calling list_free_data_fn for each
|
||||
* item to let user free its own item data. list_free_data_fn can be NULL */
|
||||
void list_free_list_and_data(struct list *list, list_free_data_fn_t list_free_data_fn);
|
||||
/* destroy all items in the list without disposing item data */
|
||||
void list_free_list(struct list *list);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
#ifndef SIGNATURE_H_
|
||||
#define SIGNATURE_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
/*
|
||||
* Initialize this module.
|
||||
* @param ca_cert_filename - the file containing the CA certificate
|
||||
* @return true <=> no error
|
||||
*/
|
||||
bool signature_initialize(const char *ca_cert_filename);
|
||||
|
||||
/*
|
||||
* Terminate usage of this module, free resources.
|
||||
*/
|
||||
void signature_terminate(void);
|
||||
|
||||
/*
|
||||
* Verify data file contents against a purported signature.
|
||||
* @param data_filename - the file containing the data
|
||||
* @param sig_filename - the file containing the signature
|
||||
* @return true <=> no error
|
||||
*/
|
||||
bool signature_verify(const char *data_filename, const char *sig_filename);
|
||||
|
||||
/*
|
||||
* The given data file has already been downloaded from the given URL.
|
||||
* Download the corresponding signature file, and verify the data against the signature.
|
||||
* Delete the signature file if and only if the verification fails.
|
||||
* @param data_url - the URL from which the data came
|
||||
* @param data_filename - the file containing the data
|
||||
*/
|
||||
bool signature_download_and_verify(const char *data_url, const char *data_filename);
|
||||
|
||||
/*
|
||||
* Delete the signature file corresponding to given data file.
|
||||
* @param data_filename - the file containing the data
|
||||
*/
|
||||
void signature_delete(const char *data_filename);
|
||||
|
||||
#endif /* SIGNATURE_H_ */
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef __INCLUDE_GUARD_SWUPD_BUILD_VARIANT_H
|
||||
#define __INCLUDE_GUARD_SWUPD_BUILD_VARIANT_H
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "list.h"
|
||||
#include "swupd.h"
|
||||
|
||||
#ifdef SWUPD_WITH_SELINUX
|
||||
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*' --selinux"
|
||||
#else /* SWUPD_WITHOUT_SELINUX */
|
||||
#define TAR_PERM_ATTR_ARGS "--preserve-permissions --xattrs --xattrs-include='*'"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef __INCLUDE_GUARD_SWUPD_ERROR_H
|
||||
#define __INCLUDE_GUARD_SWUPD_ERROR_H
|
||||
|
||||
#define EBUNDLE_MISMATCH 2 /* at least one local bundle mismatches from MoM */
|
||||
#define EBUNDLE_REMOVE 3 /* cannot delete local bundle filename */
|
||||
#define EMOM_NOTFOUND 4 /* MoM cannot be loaded into memory (this could imply network issue) */
|
||||
#define ETYPE_CHANGED_FILE_RM 5 /* do_staging() couldn't delete a file which must be deleted */
|
||||
#define EDIR_OVERWRITE 6 /* do_staging() couldn't overwrite a directory */
|
||||
#define EDOTFILE_WRITE 7 /* do_staging() couldn't create a dotfile */
|
||||
#define ERECURSE_MANIFEST 8 /* error while recursing a manifest */
|
||||
#define ELOCK_FILE 9 /* cannot get the lock */
|
||||
#define EPREP_MOUNT 10 /* failed to prepare mount points */
|
||||
#define ECURL_INIT 11 /* cannot initialize curl agent */
|
||||
#define EINIT_GLOBALS 12 /* cannot initialize globals */
|
||||
#define EBUNDLE_NOT_TRACKED 13 /* bundle is not tracked on the system */
|
||||
#define EMANIFEST_LOAD 14 /* cannot load manifest into memory */
|
||||
#define EINVALID_OPTION 15 /* invalid command option */
|
||||
#define ENOSWUPDSERVER 16 /* no net connection to swupd server */
|
||||
#define EFULLDOWNLOAD 17 /* full_download problem */
|
||||
#define ENET404 404 /* download 404'd */
|
||||
#define EBUNDLE_INSTALL 18 /* Cannot install bundles */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef __INCLUDE_GUARD_SWUPD_INTERNAL_H
|
||||
#define __INCLUDE_GUARD_SWUPD_INTERNAL_H
|
||||
|
||||
extern int bundle_add_main(int argc, char **argv);
|
||||
extern int bundle_remove_main(int argc, char **argv);
|
||||
extern int hashdump_main(int argc, char **argv);
|
||||
extern int update_main(int argc, char **argv);
|
||||
extern int verify_main(int argc, char **argv);
|
||||
extern int check_update_main(int argc, char **argv);
|
||||
|
||||
#endif
|
||||
+268
@@ -0,0 +1,268 @@
|
||||
#ifndef __INCLUDE_GUARD_SWUPD_H
|
||||
#define __INCLUDE_GUARD_SWUPD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <curl/curl.h>
|
||||
#include "list.h"
|
||||
#include <limits.h>
|
||||
#include <dirent.h>
|
||||
#include "swupd-error.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* WARNING: keep SWUPD_VERSION_INCR in sync with server definition */
|
||||
#define SWUPD_VERSION_INCR 10
|
||||
#define SWUPD_VERSION_IS_DEVEL(v) (((v) % SWUPD_VERSION_INCR) == 8)
|
||||
#define SWUPD_VERSION_IS_RESVD(v) (((v) % SWUPD_VERSION_INCR) == 9)
|
||||
|
||||
#ifndef LINE_MAX
|
||||
#define LINE_MAX _POSIX2_LINE_MAX
|
||||
#endif
|
||||
|
||||
#define PATH_MAXLEN 4096
|
||||
#define CURRENT_OS_VERSION -1
|
||||
|
||||
#define UNUSED_PARAM __attribute__ ((__unused__))
|
||||
|
||||
#define MAX_TRIES 3
|
||||
|
||||
struct sub {
|
||||
/* name of bundle/component/subscription */
|
||||
char *component;
|
||||
|
||||
/* version meanings:
|
||||
* non-zero -> version has been read from MoM
|
||||
* -1 -> error, local bundle do not match any bundle on MoM */
|
||||
int version;
|
||||
|
||||
/* oldversion: set to 0 by calloc(), possibly overridden by MoM read */
|
||||
int oldversion;
|
||||
};
|
||||
|
||||
struct manifest {
|
||||
int version;
|
||||
int manifest_version;
|
||||
uint64_t contentsize;
|
||||
struct list *files;
|
||||
struct list *manifests; /* struct file for possible manifests */
|
||||
struct list *submanifests; /* struct manifest for subscribed manifests */
|
||||
char *component;
|
||||
};
|
||||
|
||||
struct header;
|
||||
|
||||
extern bool force;
|
||||
extern int verbose;
|
||||
extern int update_count;
|
||||
extern int update_skip;
|
||||
extern bool update_complete;
|
||||
extern bool need_update_boot;
|
||||
extern bool need_update_bootloader;
|
||||
|
||||
struct update_stat {
|
||||
uint64_t st_mode;
|
||||
uint64_t st_uid;
|
||||
uint64_t st_gid;
|
||||
uint64_t st_rdev;
|
||||
uint64_t st_size;
|
||||
};
|
||||
|
||||
#define DIGEST_LEN_SHA256 64
|
||||
/* +1 for null termination */
|
||||
#define SWUPD_HASH_LEN (DIGEST_LEN_SHA256+1)
|
||||
|
||||
struct file {
|
||||
char *filename;
|
||||
char hash[SWUPD_HASH_LEN];
|
||||
bool use_xattrs;
|
||||
int last_change;
|
||||
struct update_stat stat;
|
||||
|
||||
unsigned int is_dir : 1;
|
||||
unsigned int is_file : 1;
|
||||
unsigned int is_link : 1;
|
||||
unsigned int is_deleted : 1;
|
||||
unsigned int is_manifest : 1;
|
||||
|
||||
unsigned int is_config : 1;
|
||||
unsigned int is_state : 1;
|
||||
unsigned int is_boot : 1;
|
||||
unsigned int is_rename : 1;
|
||||
unsigned int is_orphan : 1;
|
||||
unsigned int do_not_update : 1;
|
||||
|
||||
struct file *peer; /* same file in another manifest */
|
||||
struct file *deltapeer; /* the file to do the binary delta against; often same as "peer" except in rename cases */
|
||||
struct header *header;
|
||||
|
||||
char *staging; /* output name used during download & staging */
|
||||
CURL *curl; /* curl handle if downloading */
|
||||
};
|
||||
|
||||
extern bool download_only;
|
||||
extern bool verify_esp_only;
|
||||
extern bool have_manifest_diskspace;
|
||||
extern bool have_network;
|
||||
extern bool verify_bundles_only;
|
||||
extern bool ignore_config;
|
||||
extern bool ignore_state;
|
||||
extern bool ignore_orphans;
|
||||
extern bool fix;
|
||||
extern char *format_string;
|
||||
extern char *path_prefix;
|
||||
extern bool set_format_string(char *userinput);
|
||||
extern bool init_globals(void);
|
||||
extern void free_globals(void);
|
||||
extern bool has_telemetry;
|
||||
extern void *tm_dlhandle;
|
||||
extern char *bundle_to_add;
|
||||
extern struct timeval start_time;
|
||||
|
||||
extern char *version_server_urls[];
|
||||
extern char *preferred_version_url;
|
||||
extern char *content_server_urls[];
|
||||
extern char *preferred_content_url;
|
||||
extern long update_server_port;
|
||||
|
||||
extern void check_root(void);
|
||||
extern void clean_curl_multi_queue(void);
|
||||
extern void increment_retries(int *retries, int *timeout);
|
||||
|
||||
extern int main_update(void);
|
||||
extern int main_verify(int current_version);
|
||||
|
||||
extern void read_versions(int *current_version, int *latest_version, int *server_version, char *path_prefix);
|
||||
extern int check_versions(int *current_version, int *latest_version, int *server_version, char *path_prefix);
|
||||
extern int read_version_from_subvol_file(char *path_prefix);
|
||||
|
||||
extern bool check_network(void);
|
||||
|
||||
extern bool ignore(struct file *file);
|
||||
extern bool is_config(char *filename);
|
||||
extern bool is_state(char *filename);
|
||||
extern void apply_heuristics(struct file *file);
|
||||
|
||||
extern int file_sort_filename(const void *a, const void *b);
|
||||
extern int load_manifests(int current, int version, char *component, struct file *file, struct manifest **manifest);
|
||||
extern struct list *create_update_list(struct manifest *current, struct manifest *server);
|
||||
extern void link_manifests(struct manifest *m1, struct manifest *m2);
|
||||
extern void link_submanifests(struct manifest *m1, struct manifest *m2);
|
||||
extern void free_manifest(struct manifest *manifest);
|
||||
|
||||
extern void account_new_file(void);
|
||||
extern void account_deleted_file(void);
|
||||
extern void account_changed_file(void);
|
||||
extern void account_new_manifest(void);
|
||||
extern void account_deleted_manifest(void);
|
||||
extern void account_changed_manifest(void);
|
||||
extern void account_delta_hit(void);
|
||||
extern void account_delta_miss(void);
|
||||
extern void print_statistics(int version1, int version2);
|
||||
|
||||
extern int download_subscribed_packs(int oldversion, int newversion, bool required);
|
||||
|
||||
extern void try_delta(struct file *file);
|
||||
extern void full_download(struct file *file);
|
||||
extern int start_full_download(bool pipelining);
|
||||
extern struct list *end_full_download(void);
|
||||
|
||||
extern int do_staging(struct file *file);
|
||||
extern int rename_all_files_to_final(struct list *updates);
|
||||
extern int rename_staged_file_to_final(struct file *file);
|
||||
|
||||
extern int update_device_latest_version(int version);
|
||||
|
||||
extern int swupd_curl_init(void);
|
||||
extern void swupd_curl_cleanup(void);
|
||||
extern void swupd_curl_set_current_version(int v);
|
||||
extern void swupd_curl_set_requested_version(int v);
|
||||
extern size_t swupd_download_file(void *ptr, size_t size, size_t nmemb, void *userdata);
|
||||
extern int swupd_curl_get_file(const char *url, char *filename, struct file *file,
|
||||
char *tmp_version, bool pack);
|
||||
#define SWUPD_CURL_LOW_SPEED_LIMIT 1
|
||||
#define SWUPD_CURL_CONNECT_TIMEOUT 30
|
||||
#define SWUPD_CURL_RCV_TIMEOUT 120
|
||||
extern CURLcode swupd_curl_set_basic_options(CURL *curl, const char *url);
|
||||
|
||||
extern struct list *subs;
|
||||
extern void free_subscriptions(void);
|
||||
extern void read_subscriptions(void);
|
||||
extern void read_subscriptions_alt(void);
|
||||
extern int component_subscribed(char *component);
|
||||
extern int subscription_versions_from_MoM(struct manifest *MoM, int is_old);
|
||||
|
||||
extern void hash_assign(char *src, char *dest);
|
||||
extern bool hash_compare(char *hash1, char *hash2);
|
||||
extern bool hash_is_zeros(char *hash);
|
||||
extern int compute_hash_lazy(struct file *file, char *filename);
|
||||
extern int compute_hash(struct file *file, char *filename) __attribute__((warn_unused_result));
|
||||
|
||||
/* manifest.c */
|
||||
extern int recurse_manifest(struct manifest *manifest, const char *component);
|
||||
extern void consolidate_submanifests(struct manifest *manifest);
|
||||
extern void debug_write_manifest(struct manifest *manifest, char *filename);
|
||||
extern void populate_file_struct(struct file *file, char *filename);
|
||||
extern bool verify_file(struct file* file, char *filename);
|
||||
extern void unlink_all_staged_content(struct file *file);
|
||||
extern void link_renames(struct list *newfiles, struct manifest *from_manifest);
|
||||
extern void dump_file_descriptor_leaks(void);
|
||||
extern FILE * fopen_exclusive(const char *filename); /* no mode, opens for write only */
|
||||
extern int rm_staging_dir_contents(const char *rel_path);
|
||||
extern int create_required_dirs(void);
|
||||
extern void dump_file_info(struct file *file);
|
||||
void free_file_data(void *data);
|
||||
void remove_files_in_manifest_from_fs(struct manifest *m);
|
||||
void deduplicate_files_from_manifest(struct manifest **m1, struct manifest *m2);
|
||||
bool manifest_has_component(struct manifest *manifest, const char *component);
|
||||
|
||||
extern char *mounted_dirs;
|
||||
extern void get_mounted_directories(void);
|
||||
extern char *mk_full_filename(const char *prefix, const char *path);
|
||||
extern bool is_directory_mounted(const char *filename);
|
||||
extern bool is_under_mounted_directory(const char *filename);
|
||||
|
||||
extern void run_scripts(void);
|
||||
extern void run_preupdate_scripts(struct manifest *manifest);
|
||||
|
||||
/* lock.c */
|
||||
int p_lockfile(void);
|
||||
void v_lockfile(int fd);
|
||||
|
||||
/* helpers.c */
|
||||
extern int swupd_rm(const char *path);
|
||||
extern int rm_bundle_file(const char *bundle);
|
||||
extern void print_manifest_files(struct manifest *m);
|
||||
extern int swupd_init(int *lock_fd);
|
||||
extern void copyright_header(const char *name);
|
||||
extern void string_or_die(char **strp, const char *fmt, ...);
|
||||
void update_motd(int new_release);
|
||||
void delete_motd(void);
|
||||
extern int is_dirname_link(const char *fullname);
|
||||
|
||||
/* subscription.c */
|
||||
struct list *free_list_file(struct list *item);
|
||||
struct list *free_bundle(struct list *item);
|
||||
extern void create_and_append_subscription(const char *component);
|
||||
|
||||
/* bundle.c */
|
||||
extern int remove_bundle(const char *bundle_name);
|
||||
extern int list_installable_bundles();
|
||||
extern int install_bundles(char **bundles);
|
||||
|
||||
/* some disk sizes constants for the various features:
|
||||
* ...consider adding build automation to catch at build time
|
||||
* if the build's artifacts are larger than these thresholds */
|
||||
#define MANIFEST_REQUIRED_SIZE (1024 * 1024 * 100) /* 100M */
|
||||
#define FREE_MARGIN 10 /* 10% */
|
||||
|
||||
/****************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef __INCLUDE_GUARD_XATTRS_H
|
||||
#define __INCLUDE_GUARD_XATTRS_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Best effort to copy the extended attributes from one file to another.
|
||||
*
|
||||
* @param src_filename - The source file from which the extended attributes
|
||||
* will be read.
|
||||
* @param dst_filename - The destination file where the source file extended
|
||||
* attributes have to be copied.
|
||||
* @return - None.
|
||||
*/
|
||||
void xattrs_copy(const char *src_filename, const char *dst_filename);
|
||||
|
||||
/*
|
||||
* Attempt to pack into a data blob the extended attributes of the given file.
|
||||
* The data blob will be allocated and possibly filled with first the list
|
||||
* of all the extended attributes names, and then their values.
|
||||
* @param filename - The file from which the extended attributes will be
|
||||
* read and packed into the data blob.
|
||||
* @param blob - The data blob pointer into which the extended attributes will
|
||||
* be packed. (the data blob content has to be freed by the caller).
|
||||
* @param blob_len - The returned data blob length.
|
||||
* @return - None.
|
||||
*/
|
||||
void xattrs_get_blob(const char *filename, char **blob, size_t *blob_len);
|
||||
|
||||
/*
|
||||
* Compare the extended attributes from one file to another.
|
||||
*
|
||||
* @param filename1 - The first file used for the extended attributes
|
||||
* comparison.
|
||||
* @param filename2 - The second file used for the extended attributes
|
||||
* comparison.
|
||||
* @return - 0 if the extended attributes are identical, -1 if they are
|
||||
* different.
|
||||
*/
|
||||
int xattrs_compare(const char *filename1, const char *filename2);
|
||||
|
||||
#endif /* __INCLUDE_GUARD_XATTRS_H */
|
||||
Reference in New Issue
Block a user