Allow configuration to ban debuginfo from manifests

Use server.ini to optionally ban debuginfo from the manifests at
configurable paths.

Signed-off-by: Matthew Johnson <matthew.johnson@intel.com>
This commit is contained in:
Matthew Johnson
2017-09-15 15:56:02 -07:00
parent 31aec4684f
commit 0fe32ce8fb
6 changed files with 93 additions and 0 deletions
+1
View File
@@ -111,6 +111,7 @@ dist_check_SCRIPTS = \
test/functional/contentsize-across-versions-includes/test.bats \
test/functional/delete-no-version-bump/test.bats \
test/functional/file-name-blacklisted/test.bats \
test/functional/file-name-debuginfo/test.bats \
test/functional/format-no-decrement/test.bats \
test/functional/full-run-delta/test.bats \
test/functional/full-run/test.bats \
+2
View File
@@ -175,7 +175,9 @@ extern void release_configuration_data(void);
extern char *config_image_base(void);
extern char *config_output_dir(void);
extern char *config_empty_dir(void);
extern char *config_debuginfo_path(const char *path);
extern int config_initial_version(void);
extern bool config_ban_debuginfo(void);
extern void read_current_version(char *filename);
extern void write_new_version(char *filename, int version);
+5
View File
@@ -2,3 +2,8 @@
emptydir=/var/lib/update/empty/
imagebase=/var/lib/update/image/
outputdir=/var/lib/update/www/
[Debuginfo]
banned=true
lib=/usr/lib/debug/
src=/usr/src/debug/
+33
View File
@@ -305,6 +305,32 @@ static bool illegal_characters(const char *filename)
return false;
}
static bool illegal_path(const char *path)
{
bool ret = false;
char *lib;
char *src;
lib = config_debuginfo_path("lib");
src = config_debuginfo_path("src");
// Don't allow debuginfo into the manifests
if (lib && (strncmp(path, lib, strlen(lib)) == 0)) {
ret = true;
goto out;
}
if (src && (strncmp(path, src, strlen(src)) == 0)) {
ret = true;
goto out;
}
out:
free(lib);
free(src);
return ret;
}
static struct file *add_file(struct manifest *manifest,
const char *entry_name,
char *sub_filename,
@@ -314,6 +340,13 @@ static struct file *add_file(struct manifest *manifest,
GError *err = NULL;
struct file *file;
if (config_ban_debuginfo() && illegal_path(sub_filename)) {
printf("WARNING: File %s is banned ...skipping.\n", sub_filename);
free(sub_filename);
free(fullname);
return NULL;
}
if (illegal_characters(entry_name)) {
printf("WARNING: Filename %s includes illegal character(s) ...skipping.\n", sub_filename);
free(sub_filename);
+14
View File
@@ -67,6 +67,20 @@ int config_initial_version(void)
return version;
}
bool config_ban_debuginfo(void)
{
assert(keyfile != NULL);
return g_key_file_get_boolean(keyfile, "Debuginfo", "banned", NULL);
}
char *config_debuginfo_path(const char *comp)
{
assert(keyfile != NULL);
return g_key_file_get_value(keyfile, "Debuginfo", comp, NULL);
}
bool read_configuration_file(char *filename)
{
GError *error = NULL;
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env bats
# common functions
load "../swupdlib"
setup() {
clean_test_dir
init_test_dir
init_server_ini
set_latest_ver 0
init_groups_ini os-core
init_groups_ini test-bundle
set_os_release 10 os-core
track_bundle 10 os-core
set_os_release 10 test-bundle
track_bundle 10 test-bundle
gen_file_plain 10 test-bundle "/usr/lib/debug/foo"
gen_file_plain 10 test-bundle "/usr/src/debug/bar"
gen_file_plain 10 test-bundle "/usr/bin/foobar"
}
@test "debuginfo files pruned" {
run sudo sh -c "$CREATE_UPDATE --osversion 10 --statedir $DIR --format 3"
echo "$output"
# This should not be pruned
[[ 1 -eq $(grep '/usr/bin/foobar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/usr/lib/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 1 -eq $(grep '/usr/src/debug$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
# These should be pruned
[[ 0 -eq $(grep '/usr/src/debug/bar$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
[[ 0 -eq $(grep '/usr/lib/debug/foo$' $DIR/www/10/Manifest.test-bundle | wc -l) ]]
}
# vi: ft=sh ts=8 sw=2 sts=2 et tw=80