Skip to content

Commit

Permalink
Merge pull request #69 from ejoerns/v0/topic/curl-configure
Browse files Browse the repository at this point in the history
allow to disable network support for not using libcurl
  • Loading branch information
jluebbe committed Aug 24, 2016
2 parents f57985c + b46ca49 commit 3877279
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 24 deletions.
11 changes: 8 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ librauc_la_SOURCES = \
src/install.c \
src/manifest.c \
src/mount.c \
src/network.c \
src/service.c \
src/signature.c \
src/utils.c \
Expand All @@ -55,12 +54,14 @@ librauc_la_SOURCES = \
include/install.h \
include/manifest.h \
include/mount.h \
include/network.h \
include/service.h \
include/signature.h \
include/update_handler.h \
include/utils.h

if WANT_NETWORK
librauc_la_SOURCES += src/network.c include/network.h
endif
nodist_librauc_la_SOURCES = \
$(gdbus_installer_generated)
librauc_la_CFLAGS = $(AM_CFLAGS) $(CODE_COVERAGE_CFLAGS)
Expand Down Expand Up @@ -106,10 +107,14 @@ check_PROGRAMS = \
test/signature.test \
test/update_handler.test \
test/install.test \
test/network.test \
test/service.test \
test/bundle.test \
test/progress.test

if WANT_NETWORK
check_PROGRAMS += test/network.test
endif

check_LTLIBRARIES = librauctest.la

EXTRA_DIST += tap-t \
Expand Down
13 changes: 12 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ AS_IF([test "x$enable_service" != "xno"], [

# Checks for libraries.
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.40 gio-2.0 gio-unix-2.0])
PKG_CHECK_MODULES([CURL], [libcurl])

AC_ARG_ENABLE([network],
AS_HELP_STRING([--disable-network], [Disable network update mode])
)
AM_CONDITIONAL([WANT_NETWORK], [test x$enable_network != xno])
AS_IF([test "x$enable_network" != "xno"], [
AC_DEFINE([ENABLE_NETWORK], [1], [Define to 1 to enable building with JSON support])
PKG_CHECK_MODULES([CURL], [libcurl])
], [
AC_DEFINE([ENABLE_NETWORK], [0])
])


AX_CHECK_OPENSSL([],[AC_MSG_ERROR([OpenSSL not found])])

Expand Down
2 changes: 1 addition & 1 deletion include/install.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GList* get_slot_class_members(const gchar* slotclass);
GHashTable* determine_target_install_group(RaucManifest *manifest);

gboolean do_install_bundle(RaucInstallArgs *args, GError **error);
gboolean do_install_network(const gchar *url);
gboolean do_install_network(const gchar *url, GError **error);


RaucInstallArgs *install_args_new(void);
Expand Down
5 changes: 5 additions & 0 deletions include/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
#include <glib.h>

#include <checksum.h>
#include <config.h>

#if ENABLE_NETWORK
void network_init(void);
#else
static inline void network_init(void) { return; }
#endif

gboolean download_file(const gchar *target, const gchar *url, gsize limit);
gboolean download_file_checksum(const gchar *target, const gchar *url,
Expand Down
53 changes: 39 additions & 14 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <config.h>

#define R_SLOT_ERROR r_slot_error_quark ()

Expand Down Expand Up @@ -779,6 +780,7 @@ static gboolean launch_and_wait_default_handler(RaucInstallArgs *args, gchar* bu
return res;
}

#if ENABLE_NETWORK
static gboolean reuse_existing_file_checksum(const RaucChecksum *checksum, const gchar *filename) {
GError *error = NULL;
gboolean res = FALSE;
Expand Down Expand Up @@ -945,6 +947,7 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
out:
return res;
}
#endif

static void print_slot_hash_table(GHashTable *hash_table) {
GHashTableIter iter;
Expand Down Expand Up @@ -1062,7 +1065,8 @@ gboolean do_install_bundle(RaucInstallArgs *args, GError **error) {
return res;
}

gboolean do_install_network(const gchar *url) {
gboolean do_install_network(const gchar *url, GError **error) {
#if ENABLE_NETWORK
gboolean res = FALSE;
GError *ierror = NULL;
gchar *base_url = NULL, *signature_url = NULL;
Expand All @@ -1074,13 +1078,13 @@ gboolean do_install_network(const gchar *url) {

res = determine_slot_states(&ierror);
if (!res) {
g_warning("%s", ierror->message);
g_propagate_error(error, ierror);
goto out;
}

res = download_mem(&manifest_data, url, 64*1024);
if (!res) {
g_warning("Failed to download manifest");
g_set_error_literal(error, R_INSTALL_ERROR, 4, "Failed to download manifest");
goto out;
}

Expand All @@ -1091,21 +1095,27 @@ gboolean do_install_network(const gchar *url) {
goto out;
}

res = cms_verify(manifest_data, signature_data, NULL);
res = cms_verify(manifest_data, signature_data, &ierror);
if (!res) {
g_warning("Failed to verify manifest signature");
g_propagate_prefixed_error(
error,
ierror,
"Failed verifying manifest: ");
goto out;
}

res = load_manifest_mem(manifest_data, &manifest, NULL);
res = load_manifest_mem(manifest_data, &manifest, &ierror);
if (!res) {
g_warning("Failed to verify manifest signature");
g_propagate_prefixed_error(
error,
ierror,
"Failed loading manifest: ");
goto out;
}

target_group = determine_target_install_group(manifest);
if (!target_group) {
g_warning("Could not determine target group");
g_set_error_literal(error, R_INSTALL_ERROR, 3, "Could not determine target group");
goto out;
}

Expand All @@ -1116,28 +1126,29 @@ gboolean do_install_network(const gchar *url) {

if (r_context()->config->preinstall_handler) {
g_print("Starting pre install handler: %s\n", r_context()->config->preinstall_handler);
res = launch_and_wait_handler(base_url, r_context()->config->preinstall_handler, manifest, target_group, NULL);
res = launch_and_wait_handler(base_url, r_context()->config->preinstall_handler, manifest, target_group, &ierror);
}

if (!res) {
g_print("Handler error: %s\n", r_context()->config->preinstall_handler);
g_propagate_prefixed_error(error, ierror, "Handler error: ");
goto out;
}

g_print("Using network handler for %s\n", base_url);
res = launch_and_wait_network_handler(base_url, manifest, target_group);
if (!res) {
g_warning("Starting handler failed");
g_set_error_literal(error, R_HANDLER_ERROR, 0,
"Handler error");
goto out;
}

if (r_context()->config->postinstall_handler) {
g_print("Starting post install handler: %s\n", r_context()->config->postinstall_handler);
res = launch_and_wait_handler(base_url, r_context()->config->postinstall_handler, manifest, target_group, NULL);
res = launch_and_wait_handler(base_url, r_context()->config->postinstall_handler, manifest, target_group, &ierror);
}

if (!res) {
g_print("Handler error: %s\n", r_context()->config->postinstall_handler);
g_propagate_prefixed_error(error, ierror, "Handler error: ");
goto out;
}

Expand All @@ -1152,6 +1163,14 @@ gboolean do_install_network(const gchar *url) {
g_clear_pointer(&signature_data, g_bytes_unref);

return res;
#else
g_set_error_literal(
error,
R_HANDLER_ERROR,
255,
"Compiled without network support");
return FALSE;
#endif
}

static gboolean install_done(gpointer data) {
Expand Down Expand Up @@ -1184,7 +1203,13 @@ static gpointer install_thread(gpointer data) {
g_clear_error(&ierror);
}
} else {
result = !do_install_network(args->name);
result = !do_install_network(args->name, &ierror);
if (result != 0) {
g_warning("%s", ierror->message);
install_args_update(args, ierror->message);
set_last_error(ierror->message);
g_clear_error(&ierror);
}
}

g_mutex_lock(&args->status_mutex);
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ static gboolean install_start(int argc, char **argv)
r_exit_status = args->status_result;
g_clear_pointer(&r_loop, g_main_loop_unref);

g_signal_handlers_disconnect_by_data(installer, args);
if (installer)
g_signal_handlers_disconnect_by_data(installer, args);
g_clear_pointer(&installer, g_object_unref);
install_args_free(args);

Expand Down
23 changes: 19 additions & 4 deletions test/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <bundle.h>
#include <context.h>
#include <config.h>
#include <install.h>
#include <manifest.h>
#include <mount.h>
Expand Down Expand Up @@ -299,6 +300,10 @@ static void install_fixture_set_up_network(InstallFixture *fixture,
gchar *contentdir;
gchar *manifestpath;

#if !ENABLE_NETWORK
return;
#endif

/* needs to run as root */
if (!test_running_as_root())
return;
Expand Down Expand Up @@ -504,6 +509,11 @@ static void install_test_network(InstallFixture *fixture,
{
gchar *manifesturl, *mountdir;

#if !ENABLE_NETWORK
g_test_skip("Compiled without network support");
return;
#endif

/* needs to run as root */
if (!test_running_as_root())
return;
Expand All @@ -516,17 +526,17 @@ static void install_test_network(InstallFixture *fixture,

manifesturl = g_strconcat("file://", fixture->tmpdir,
"/content/manifest-1.raucm", NULL);
g_assert_true(do_install_network(manifesturl));
g_assert_true(do_install_network(manifesturl, NULL));
g_free(manifesturl);

manifesturl = g_strconcat("file://", fixture->tmpdir,
"/content/manifest-2.raucm", NULL);
g_assert_true(do_install_network(manifesturl));
g_assert_true(do_install_network(manifesturl, NULL));
g_free(manifesturl);

manifesturl = g_strconcat("file://", fixture->tmpdir,
"/content/manifest-3.raucm", NULL);
g_assert_true(do_install_network(manifesturl));
g_assert_true(do_install_network(manifesturl, NULL));
g_free(manifesturl);
}

Expand Down Expand Up @@ -567,6 +577,11 @@ static void install_test_network_thread(InstallFixture *fixture,
RaucInstallArgs *args = install_args_new();
gchar *manifesturl, *mountdir;

#if !ENABLE_NETWORK
g_test_skip("Compiled without network support");
return;
#endif

/* needs to run as root */
if (!test_running_as_root())
return;
Expand All @@ -579,7 +594,7 @@ static void install_test_network_thread(InstallFixture *fixture,

manifesturl = g_strconcat("file://", fixture->tmpdir,
"/content/manifest-1.raucm", NULL);
g_assert_true(do_install_network(manifesturl));
g_assert_true(do_install_network(manifesturl, NULL));
args->name = g_strdup(manifesturl);
args->notify = install_notify;
args->cleanup = install_cleanup;
Expand Down

0 comments on commit 3877279

Please sign in to comment.