From 0c7d58a51d6f5eb4ad33e03630206bbb4e559779 Mon Sep 17 00:00:00 2001 From: Amin Ben Romdhane <amin.benromdhane@iopsys.eu> Date: Wed, 2 Oct 2024 17:11:55 +0200 Subject: [PATCH] Align with new code-analysis image --- .gitlab-ci.yml | 18 ++++++++----- gitlab-ci/install-dependencies.sh | 7 +++++ gitlab-ci/shared.sh | 2 +- src/sshmngr.c | 45 ++++++------------------------- 4 files changed, 27 insertions(+), 45 deletions(-) create mode 100755 gitlab-ci/install-dependencies.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 03146ac..df790d0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,15 +1,19 @@ +variables: + SOURCE_FOLDER: "src" + include: - project: 'iopsys/gitlab-ci-pipeline' file: '/static-code-analysis.yml' - ref: '0.31' + ref: '1.2' stages: - static_code_analysis + - compilation_test -variables: - DEBUG: 'TRUE' - SOURCE_FOLDER: "./src" - FLAWFINDER_OPTIONS: "-m 4 --error-level=5" - CPPCHECK_OPTIONS: "--enable=all --error-exitcode=1" - COMPILE: "./gitlab-ci/compile.sh" +run_compilation_test: + image: ${COMMON_IMAGE} + stage: compilation_test + allow_failure: false + script: + - "./gitlab-ci/compile.sh" diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh new file mode 100755 index 0000000..285cc18 --- /dev/null +++ b/gitlab-ci/install-dependencies.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "install dependencies for tests" +source ./gitlab-ci/shared.sh + +# install bbfdm +install_bbfdm diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh index f098751..dc60651 100644 --- a/gitlab-ci/shared.sh +++ b/gitlab-ci/shared.sh @@ -13,7 +13,7 @@ function exec_cmd() function install_bbfdm() { - [ -d "/opt/dev/bbfdm" ] && rm -rf /opt/dev/bbfdm + [ -d "/opt/dev/bbfdm" ] && return 0 if [ -n "${BBFDM_BRANCH}" ]; then exec_cmd git clone -b ${BBFDM_BRANCH} https://dev.iopsys.eu/bbf/bbfdm.git /opt/dev/bbfdm diff --git a/src/sshmngr.c b/src/sshmngr.c index bbccd1e..59fa163 100644 --- a/src/sshmngr.c +++ b/src/sshmngr.c @@ -141,26 +141,9 @@ static int addObjSSHServer(char *refparam, struct dmctx *ctx, void *data, char * static int delObjSSHServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct uci_section *s = NULL, *stmp = NULL; - - switch (del_action) { - case DEL_INST: - close_active_sessions(((struct dm_data *)data)->config_section); - dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); - dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - break; - case DEL_ALL: - uci_foreach_sections_safe(BACKEND_UCI, BACKEND_SECTION_TYPE, stmp, s) { - struct uci_section *dmmap_section = NULL; - - get_dmmap_section_of_config_section("dmmap_sshmngr", BACKEND_SECTION_TYPE, section_name(s), &dmmap_section); - dmuci_delete_by_section(dmmap_section, NULL, NULL); - - close_active_sessions(s); - dmuci_delete_by_section(s, NULL, NULL); - } - break; - } + close_active_sessions(((struct dm_data *)data)->config_section); + dmuci_delete_by_section(((struct dm_data *)data)->config_section, NULL, NULL); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); return 0; } @@ -174,23 +157,11 @@ static int addObjSSHKey(char *refparam, struct dmctx *ctx, void *data, char **in static int delObjSSHKey(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action) { - struct uci_section *s = NULL, *stmp = NULL; char *value = NULL; - switch (del_action) { - case DEL_INST: - dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", &value); - remove_pubkey(value); - dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); - break; - case DEL_ALL: - uci_path_foreach_sections_safe(bbfdm, "dmmap_sshmngr", "authkey", stmp, s) { - dmuci_get_value_by_section_string(s, "pubkey", &value); - remove_pubkey(value); - dmuci_delete_by_section(s, NULL, NULL); - } - break; - } + dmuci_get_value_by_section_string(((struct dm_data *)data)->dmmap_section, "pubkey", &value); + remove_pubkey(value); + dmuci_delete_by_section(((struct dm_data *)data)->dmmap_section, NULL, NULL); return 0; } @@ -344,7 +315,7 @@ static int get_ssh_key_num(char *refparam, struct dmctx *ctx, void *data, char * static int get_ssh_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "Enabled"; + *value = dmstrdup("Enabled"); return 0; } @@ -599,7 +570,7 @@ static int get_ssh_server_pid(char *refparam, struct dmctx *ctx, void *data, cha struct uci_section *s = ((struct dm_data *)data)->config_section; char *en = dmuci_get_value_by_section_fallback_def(s, "enable", "0"); - *value = "0"; + *value = dmstrdup("0"); string_to_bool(en, &b); if (!b) return 0; -- GitLab