From 0083ad3751cd2b088b5c5d0dea727671ea2a3cca Mon Sep 17 00:00:00 2001 From: José Bollo Date: Fri, 13 Sep 2019 16:46:39 +0200 Subject: Rename source files and improve readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also rename wgtpkg-installer tools as wgtpkg-install. Shorter and obvious. Bug-AGL: SPEC-2840 Change-Id: Ifed072bfef488700807613dd61875a30a4041d7a Signed-off-by: José Bollo --- README.md | 4 +- docs/2.1-widgets.md | 2 +- src/CMakeLists.txt | 12 +-- src/README.md | 8 +- src/main-wgtpkg-info.c | 167 ++++++++++++++++++++++++++++++ src/main-wgtpkg-install.c | 147 +++++++++++++++++++++++++++ src/main-wgtpkg-pack.c | 184 +++++++++++++++++++++++++++++++++ src/main-wgtpkg-sign.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++ src/wgtpkg-info.c | 167 ------------------------------ src/wgtpkg-installer.c | 147 --------------------------- src/wgtpkg-pack.c | 184 --------------------------------- src/wgtpkg-sign.c | 230 ----------------------------------------- 12 files changed, 765 insertions(+), 741 deletions(-) create mode 100644 src/main-wgtpkg-info.c create mode 100644 src/main-wgtpkg-install.c create mode 100644 src/main-wgtpkg-pack.c create mode 100644 src/main-wgtpkg-sign.c delete mode 100644 src/wgtpkg-info.c delete mode 100644 src/wgtpkg-installer.c delete mode 100644 src/wgtpkg-pack.c delete mode 100644 src/wgtpkg-sign.c diff --git a/README.md b/README.md index 49993bf..9c040f5 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ The installed programs are: - ***wgtpkg-info***: command line tool to display information about a widget file. -- ***wgtpkg-installer***: command line tool to +- ***wgtpkg-install***: command line tool to install a widget file. - ***wgtpkg-pack***: command line tool to create @@ -199,7 +199,7 @@ The current version of afm allows to install widgets from local files (either pre-installed or downloaded). To install a widget, you can use either the program -***wgtpkg-installer*** while being the framework user. +***wgtpkg-install*** while being the framework user. TO BE CONTINUED diff --git a/docs/2.1-widgets.md b/docs/2.1-widgets.md index f799133..f41e2d9 100644 --- a/docs/2.1-widgets.md +++ b/docs/2.1-widgets.md @@ -6,7 +6,7 @@ These tools are: - ***wgtpkg-info***: command line tool to display informations about a widget file. -- ***wgtpkg-installer***: command line tool to +- ***wgtpkg-install***: command line tool to install a widget file. - ***wgtpkg-pack***: command line tool to create diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0fde569..3a94d0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -148,19 +148,19 @@ add_library(afm STATIC MESSAGE(STATUS "Creating packaging tools") -add_executable(wgtpkg-sign wgtpkg-sign.c) +add_executable(wgtpkg-sign main-wgtpkg-sign.c) target_link_libraries(wgtpkg-sign wgtpkg utils) -add_executable(wgtpkg-pack wgtpkg-pack.c) +add_executable(wgtpkg-pack main-wgtpkg-pack.c) target_link_libraries(wgtpkg-pack wgtpkg utils) -add_executable(wgtpkg-info wgtpkg-info.c) +add_executable(wgtpkg-info main-wgtpkg-info.c) target_link_libraries(wgtpkg-info wgtpkg wgt utils) -add_executable(wgtpkg-installer wgtpkg-installer.c) -target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils) +add_executable(wgtpkg-install main-wgtpkg-install.c) +target_link_libraries(wgtpkg-install wgtpkg wgt secwrp utils) -install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-install DESTINATION ${CMAKE_INSTALL_BINDIR}) ########################################################################### # dynamic tool daemons diff --git a/src/README.md b/src/README.md index df62fe3..49c48e9 100644 --- a/src/README.md +++ b/src/README.md @@ -53,13 +53,13 @@ widget package management wgtpkg-certs.c wgtpkg-digsig.c wgtpkg-files.c -wgtpkg-info.c +main-wgtpkg-info.c wgtpkg-install.c -wgtpkg-installer.c +main-wgtpkg-instal.c wgtpkg-mustach.c -wgtpkg-pack.c +main-wgtpkg-pack.c wgtpkg-permissions.c -wgtpkg-sign.c +main-wgtpkg-sign.c wgtpkg-uninstall.c wgtpkg-unit.c wgtpkg-workdir.c diff --git a/src/main-wgtpkg-info.c b/src/main-wgtpkg-info.c new file mode 100644 index 0000000..a6d7e6e --- /dev/null +++ b/src/main-wgtpkg-info.c @@ -0,0 +1,167 @@ +/* + Copyright (C) 2015-2020 IoT.bzh + + author: José Bollo + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "verbose.h" +#include "wgtpkg-workdir.h" +#include "wgtpkg-files.h" +#include "wgtpkg-zip.h" +#include "wgtpkg-digsig.h" +#include "wgtpkg-xmlsec.h" +#include "wgt.h" +#include "wgt-info.h" + +static const char appname[] = "wgtpkg-info"; + +static void show(const char *wgtfile); + +static void version() +{ + printf( + "\n" + " %s version="AFM_VERSION"\n" + "\n" + " Copyright (C) 2015-2020 \"IoT.bzh\"\n" + " AFB comes with ABSOLUTELY NO WARRANTY.\n" + " Licence Apache 2\n" + "\n", + appname + ); +} + +static void usage() +{ + printf( + "usage: %s [-q] [-v] wgtfile...\n" + "\n" + " -q quiet\n" + " -v verbose\n" + " -V version\n" + "\n", + appname + ); +} + +static struct option options[] = { + { "help", no_argument, NULL, 'h' }, + { "quiet", no_argument, NULL, 'q' }, + { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +/* info the widgets of the list */ +int main(int ac, char **av) +{ + int i; + char *wpath; + + LOGUSER(appname); + + xmlsec_init(); + + for (;;) { + i = getopt_long(ac, av, "hqvV", options, NULL); + if (i < 0) + break; + switch (i) { + case 'h': + usage(); + return 0; + case 'q': + if (verbosity) + verbosity--; + break; + case 'v': + verbosity++; + break; + case 'V': + version(); + return 0; + case ':': + ERROR("missing argument value"); + return 1; + default: + ERROR("unrecognized option"); + return 1; + } + } + + /* canonic names for files */ + av += optind; + for (i = 0 ; av[i] != NULL ; i++) { + wpath = realpath(av[i], NULL); + if (wpath == NULL) { + ERROR("error while getting realpath of %dth widget: %s", i+1, av[i]); + return 1; + } + av[i] = wpath; + } + + /* info widgets */ + for ( ; *av ; av++) + show(*av); + + return 0; +} + +static int check_and_show() +{ + struct wgt_info *ifo; + + ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1); + if (!ifo) + return -1; + wgt_info_dump(ifo, 1, ""); + wgt_info_unref(ifo); + return 0; +} + +/* install the widget of the file */ +static void show(const char *wgtfile) +{ + NOTICE("-- INFO for widget %s --", wgtfile); + + /* workdir */ + if (make_workdir("/tmp", "UNPACK", 0)) { + ERROR("failed to create a working directory"); + return; + } + + if (zread(wgtfile, 0)) + goto error2; + + if (check_all_signatures(1)) /* info even on WGT without signature */ + goto error2; + + check_and_show(); + +error2: + remove_workdir(); + return; +} + diff --git a/src/main-wgtpkg-install.c b/src/main-wgtpkg-install.c new file mode 100644 index 0000000..7f6f187 --- /dev/null +++ b/src/main-wgtpkg-install.c @@ -0,0 +1,147 @@ +/* + Copyright (C) 2015-2020 IoT.bzh + + author: José Bollo + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "verbose.h" +#include "wgtpkg-permissions.h" +#include "wgtpkg-xmlsec.h" +#include "wgt-info.h" +#include "wgtpkg-install.h" + +static const char appname[] = "wgtpkg-install"; +static const char *root; +static int force; + +static void version() +{ + printf( + "\n" + " %s version="AFM_VERSION"\n" + "\n" + " Copyright (C) 2015-2020 \"IoT.bzh\"\n" + " AFB comes with ABSOLUTELY NO WARRANTY.\n" + " Licence Apache 2\n" + "\n", + appname + ); +} + +static void usage() +{ + printf( + "usage: %s [-f] [-q] [-v] [-p list] rootdir wgtfile...\n" + "\n" + " rootdir the root directory for installing\n" + " -p list a list of comma separated permissions to allow\n" + " -f force overwriting\n" + " -q quiet\n" + " -v verbose\n" + " -V version\n" + "\n", + appname + ); +} + +static struct option options[] = { + { "permissions", required_argument, NULL, 'p' }, + { "force", no_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { "quiet", no_argument, NULL, 'q' }, + { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +/* install the widgets of the list */ +int main(int ac, char **av) +{ + int i, rc; + struct wgt_info *ifo; + + LOGAUTH(appname); + + xmlsec_init(); + + force = 0; + for (;;) { + i = getopt_long(ac, av, "hfqvVp:", options, NULL); + if (i < 0) + break; + switch (i) { + case 'f': + force = 1; + break; + case 'h': + usage(); + return 0; + case 'q': + if (verbosity) + verbosity--; + break; + case 'v': + verbosity++; + break; + case 'V': + version(); + return 0; + case 'p': + rc = grant_permission_list(optarg); + if (rc < 0) { + ERROR("Can't set granted permission list"); + exit(1); + } + break; + case ':': + ERROR("missing argument value"); + return 1; + default: + ERROR("unrecognized option"); + return 1; + } + } + + ac -= optind; + if (ac < 2) { + ERROR("arguments are missing"); + return 1; + } + + /* install widgets */ + av += optind; + root = *av++; + for ( ; *av ; av++) { + ifo = install_widget(*av, root, force); + if (ifo) + wgt_info_unref(ifo); + } + + return 0; +} + diff --git a/src/main-wgtpkg-pack.c b/src/main-wgtpkg-pack.c new file mode 100644 index 0000000..e448497 --- /dev/null +++ b/src/main-wgtpkg-pack.c @@ -0,0 +1,184 @@ +/* + Copyright (C) 2015-2020 IoT.bzh + + author: José Bollo + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "verbose.h" +#include "wgtpkg-files.h" +#include "wgtpkg-workdir.h" +#include "wgtpkg-zip.h" + +const char appname[] = "wgtpkg-pack"; + +static void version() +{ + printf( + "\n" + " %s version="AFM_VERSION"\n" + "\n" + " Copyright (C) 2015-2020 \"IoT.bzh\"\n" + " AFB comes with ABSOLUTELY NO WARRANTY.\n" + " Licence Apache 2\n" + "\n", + appname + ); +} + +static void usage() +{ + printf( + "usage: %s [-f] [-o wgtfile] directory\n" + "\n" + " -o wgtfile the output widget file\n" + " -f force overwriting\n" + " -q quiet\n" + " -v verbose\n" + " -V version\n" + "\n", + appname + ); +} + +static struct option options[] = { + { "output", required_argument, NULL, 'o' }, + { "force", no_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { "quiet", no_argument, NULL, 'q' }, + { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +/* install the widgets of the list */ +int main(int ac, char **av) +{ + int i, force; + char *wgtfile, *directory, *x; + struct stat s; + + LOGUSER(appname); + + force = 0; + wgtfile = directory = NULL; + for (;;) { + i = getopt_long(ac, av, "qvVhfo:", options, NULL); + if (i < 0) + break; + switch (i) { + case 'o': + wgtfile = optarg; + break; + case 'q': + if (verbosity) + verbosity--; + break; + case 'v': + verbosity++; + break; + case 'f': + force = 1; + break; + case 'h': + usage(); + return 0; + case 'V': + version(); + return 0; + case ':': + ERROR("missing argument"); + return 1; + default: + ERROR("unrecognized option"); + return 1; + } + } + + /* remaining arguments and final checks */ + if (optind >= ac) { + ERROR("no directory set"); + return 1; + } + directory = av[optind++]; + if (optind < ac) { + ERROR("extra parameters found"); + return 1; + } + + /* set default values */ + if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) { + ERROR("asprintf failed"); + return 1; + } + + /* check values */ + if (stat(directory, &s)) { + ERROR("can't find directory %s", directory); + return 1; + } + if (!S_ISDIR(s.st_mode)) { + ERROR("%s isn't a directory", directory); + return 1; + } + if (access(wgtfile, F_OK) == 0 && force == 0) { + ERROR("can't overwrite existing %s", wgtfile); + return 1; + } + + NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory); + + /* creates an existing widget (for realpath it must exist) */ + i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644); + if (i < 0) { + ERROR("can't write widget %s", wgtfile); + return 1; + } + close(i); + + /* compute absolutes paths */ + x = realpath(wgtfile, NULL); + if (x == NULL) { + ERROR("realpath failed for %s", wgtfile); + return 1; + } + wgtfile = x; + + /* set and enter the workdir */ + if (chdir(directory)) { + ERROR("failed to enter directory %s", directory); + return 1; + } + if (set_workdir(".", 0)) + return 1; + + + if (fill_files()) + return 1; + + return !!zwrite(wgtfile); +} + + diff --git a/src/main-wgtpkg-sign.c b/src/main-wgtpkg-sign.c new file mode 100644 index 0000000..d40ddaf --- /dev/null +++ b/src/main-wgtpkg-sign.c @@ -0,0 +1,254 @@ +/* + Copyright (C) 2015-2020 IoT.bzh + + author: José Bollo + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "verbose.h" +#include "wgtpkg-files.h" +#include "wgtpkg-workdir.h" +#include "wgtpkg-digsig.h" +#include "wgtpkg-xmlsec.h" + +#if !defined(MAXCERT) +#define MAXCERT 20 +#endif +#if !defined(DEFAULT_KEY_FILE) +#define DEFAULT_KEY_FILE "key.pem" +#endif +#if !defined(DEFAULT_CERT_FILE) +#define DEFAULT_CERT_FILE "cert.pem" +#endif + +const char appname[] = "wgtpkg-sign"; + +static unsigned int get_number(const char *value) +{ + char *end; + unsigned long int val; + + val = strtoul(value, &end, 10); + if (*end || 0 == val || val >= UINT_MAX || *value == '-') { + ERROR("bad number value %s", value); + exit(1); + } + return (unsigned int)val; +} + +static void make_realpath(char **x) +{ + char *p = realpath(*x, NULL); + if (p == NULL) { + ERROR("realpath failed for %s", *x); + exit(1); + } + *x = p; +} + +static void version() +{ + printf( + "\n" + " %s version="AFM_VERSION"\n" + "\n" + " Copyright (C) 2015-2020 \"IoT.bzh\"\n" + " AFB comes with ABSOLUTELY NO WARRANTY.\n" + " Licence Apache 2\n" + "\n", + appname + ); +} + +static void usage() +{ + printf( + "usage: %s [-f] [-k keyfile] [-c certfile]... [-d number | -a] directory\n" + "\n" + " -k keyfile the private key to use for author signing\n" + " -c certfile the certificate(s) to use for author signing\n" + " -d number the number of the distributor signature (zero for automatic)\n" + " -a the author signature\n" + " -f force overwriting\n" + " -q quiet\n" + " -v verbose\n" + " -V version\n" + "\n", + appname + ); +} + +static struct option options_l[] = { + { "author", no_argument, NULL, 'a' }, + { "certificate", required_argument, NULL, 'c' }, + { "distributor", required_argument, NULL, 'd' }, + { "force", no_argument, NULL, 'f' }, + { "help", no_argument, NULL, 'h' }, + { "key", required_argument, NULL, 'k' }, + { "quiet", no_argument, NULL, 'q' }, + { "verbose", no_argument, NULL, 'v' }, + { "version", no_argument, NULL, 'V' }, + { NULL, 0, NULL, 0 } +}; + +static const char options_s[] = "ac:d:fhk:qvV"; + +/* install the widgets of the list */ +int main(int ac, char **av) +{ + int i, force, ncert, author; + unsigned int number; + char *keyfile, *certfiles[MAXCERT+1], *directory; + struct stat s; + + LOGUSER(appname); + + force = ncert = author = 0; + number = UINT_MAX; + keyfile = directory = NULL; + for (;;) { + i = getopt_long(ac, av, options_s, options_l, NULL); + if (i < 0) + break; + switch (i) { + case 'c': + if (ncert == MAXCERT) { + ERROR("maximum count of certificates reached"); + return 1; + } + certfiles[ncert++] = optarg; + break; + case 'k': + if (keyfile) { + ERROR("key already set"); + return 1; + } + keyfile = optarg; + break; + case 'd': + if (number != UINT_MAX) { + ERROR("number already set"); + return 1; + } + number = get_number(optarg); + break; + case 'f': + force = 1; + break; + case 'a': + author = 1; + break; + case 'h': + usage(); + return 0; + case 'V': + version(); + return 0; + case 'q': + if (verbosity) + verbosity--; + break; + case 'v': + verbosity++; + break; + case ':': + ERROR("missing argument"); + return 1; + default: + ERROR("unrecognized option"); + return 1; + } + } + + /* remaining arguments and final checks */ + if (optind >= ac) { + ERROR("no directory set"); + return 1; + } + directory = av[optind++]; + if (optind < ac) { + ERROR("extra parameters found"); + return 1; + } + + /* set default values */ + if (keyfile == NULL) + keyfile = DEFAULT_KEY_FILE; + if (ncert == 0) + certfiles[ncert++] = DEFAULT_CERT_FILE; + + /* check values */ + if (stat(directory, &s)) { + ERROR("can't find directory %s", directory); + return 1; + } + if (!S_ISDIR(s.st_mode)) { + ERROR("%s isn't a directory", directory); + return 1; + } + if (access(keyfile, R_OK) != 0) { + ERROR("can't access private key %s", keyfile); + return 1; + } + for(i = 0 ; i < ncert ; i++) + if (access(certfiles[i], R_OK) != 0) { + ERROR("can't access certificate %s", certfiles[i]); + return 1; + } + + /* init xmlsec module */ + if (xmlsec_init()) + return 1; + + /* compute absolutes paths */ + make_realpath(&keyfile); + for(i = 0 ; i < ncert ; i++) + make_realpath(&certfiles[i]); + + /* set and enter the workdir */ + if (set_workdir(directory, 0)) + return 1; + + if (fill_files()) + return 1; + + if (author) + number = 0; + else if (number == UINT_MAX) + for (number = 1; get_signature(number) != NULL ; number++); + + if (!force && get_signature(number) != NULL) { + ERROR("can't overwrite existing signature %s", get_signature(number)->name); + return 1; + } + + NOTICE("-- SIGNING content of directory %s for number %u", directory, number); + + certfiles[ncert] = NULL; + return !!create_digsig(number, keyfile, (const char**)certfiles); +} + diff --git a/src/wgtpkg-info.c b/src/wgtpkg-info.c deleted file mode 100644 index a6d7e6e..0000000 --- a/src/wgtpkg-info.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - Copyright (C) 2015-2020 IoT.bzh - - author: José Bollo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "verbose.h" -#include "wgtpkg-workdir.h" -#include "wgtpkg-files.h" -#include "wgtpkg-zip.h" -#include "wgtpkg-digsig.h" -#include "wgtpkg-xmlsec.h" -#include "wgt.h" -#include "wgt-info.h" - -static const char appname[] = "wgtpkg-info"; - -static void show(const char *wgtfile); - -static void version() -{ - printf( - "\n" - " %s version="AFM_VERSION"\n" - "\n" - " Copyright (C) 2015-2020 \"IoT.bzh\"\n" - " AFB comes with ABSOLUTELY NO WARRANTY.\n" - " Licence Apache 2\n" - "\n", - appname - ); -} - -static void usage() -{ - printf( - "usage: %s [-q] [-v] wgtfile...\n" - "\n" - " -q quiet\n" - " -v verbose\n" - " -V version\n" - "\n", - appname - ); -} - -static struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, NULL, 'q' }, - { "verbose", no_argument, NULL, 'v' }, - { "version", no_argument, NULL, 'V' }, - { NULL, 0, NULL, 0 } -}; - -/* info the widgets of the list */ -int main(int ac, char **av) -{ - int i; - char *wpath; - - LOGUSER(appname); - - xmlsec_init(); - - for (;;) { - i = getopt_long(ac, av, "hqvV", options, NULL); - if (i < 0) - break; - switch (i) { - case 'h': - usage(); - return 0; - case 'q': - if (verbosity) - verbosity--; - break; - case 'v': - verbosity++; - break; - case 'V': - version(); - return 0; - case ':': - ERROR("missing argument value"); - return 1; - default: - ERROR("unrecognized option"); - return 1; - } - } - - /* canonic names for files */ - av += optind; - for (i = 0 ; av[i] != NULL ; i++) { - wpath = realpath(av[i], NULL); - if (wpath == NULL) { - ERROR("error while getting realpath of %dth widget: %s", i+1, av[i]); - return 1; - } - av[i] = wpath; - } - - /* info widgets */ - for ( ; *av ; av++) - show(*av); - - return 0; -} - -static int check_and_show() -{ - struct wgt_info *ifo; - - ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1); - if (!ifo) - return -1; - wgt_info_dump(ifo, 1, ""); - wgt_info_unref(ifo); - return 0; -} - -/* install the widget of the file */ -static void show(const char *wgtfile) -{ - NOTICE("-- INFO for widget %s --", wgtfile); - - /* workdir */ - if (make_workdir("/tmp", "UNPACK", 0)) { - ERROR("failed to create a working directory"); - return; - } - - if (zread(wgtfile, 0)) - goto error2; - - if (check_all_signatures(1)) /* info even on WGT without signature */ - goto error2; - - check_and_show(); - -error2: - remove_workdir(); - return; -} - diff --git a/src/wgtpkg-installer.c b/src/wgtpkg-installer.c deleted file mode 100644 index a19c21a..0000000 --- a/src/wgtpkg-installer.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - Copyright (C) 2015-2020 IoT.bzh - - author: José Bollo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "verbose.h" -#include "wgtpkg-permissions.h" -#include "wgtpkg-xmlsec.h" -#include "wgt-info.h" -#include "wgtpkg-install.h" - -static const char appname[] = "wgtpkg-installer"; -static const char *root; -static int force; - -static void version() -{ - printf( - "\n" - " %s version="AFM_VERSION"\n" - "\n" - " Copyright (C) 2015-2020 \"IoT.bzh\"\n" - " AFB comes with ABSOLUTELY NO WARRANTY.\n" - " Licence Apache 2\n" - "\n", - appname - ); -} - -static void usage() -{ - printf( - "usage: %s [-f] [-q] [-v] [-p list] rootdir wgtfile...\n" - "\n" - " rootdir the root directory for installing\n" - " -p list a list of comma separated permissions to allow\n" - " -f force overwriting\n" - " -q quiet\n" - " -v verbose\n" - " -V version\n" - "\n", - appname - ); -} - -static struct option options[] = { - { "permissions", required_argument, NULL, 'p' }, - { "force", no_argument, NULL, 'f' }, - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, NULL, 'q' }, - { "verbose", no_argument, NULL, 'v' }, - { "version", no_argument, NULL, 'V' }, - { NULL, 0, NULL, 0 } -}; - -/* install the widgets of the list */ -int main(int ac, char **av) -{ - int i, rc; - struct wgt_info *ifo; - - LOGAUTH(appname); - - xmlsec_init(); - - force = 0; - for (;;) { - i = getopt_long(ac, av, "hfqvVp:", options, NULL); - if (i < 0) - break; - switch (i) { - case 'f': - force = 1; - break; - case 'h': - usage(); - return 0; - case 'q': - if (verbosity) - verbosity--; - break; - case 'v': - verbosity++; - break; - case 'V': - version(); - return 0; - case 'p': - rc = grant_permission_list(optarg); - if (rc < 0) { - ERROR("Can't set granted permission list"); - exit(1); - } - break; - case ':': - ERROR("missing argument value"); - return 1; - default: - ERROR("unrecognized option"); - return 1; - } - } - - ac -= optind; - if (ac < 2) { - ERROR("arguments are missing"); - return 1; - } - - /* install widgets */ - av += optind; - root = *av++; - for ( ; *av ; av++) { - ifo = install_widget(*av, root, force); - if (ifo) - wgt_info_unref(ifo); - } - - return 0; -} - diff --git a/src/wgtpkg-pack.c b/src/wgtpkg-pack.c deleted file mode 100644 index e448497..0000000 --- a/src/wgtpkg-pack.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - Copyright (C) 2015-2020 IoT.bzh - - author: José Bollo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "verbose.h" -#include "wgtpkg-files.h" -#include "wgtpkg-workdir.h" -#include "wgtpkg-zip.h" - -const char appname[] = "wgtpkg-pack"; - -static void version() -{ - printf( - "\n" - " %s version="AFM_VERSION"\n" - "\n" - " Copyright (C) 2015-2020 \"IoT.bzh\"\n" - " AFB comes with ABSOLUTELY NO WARRANTY.\n" - " Licence Apache 2\n" - "\n", - appname - ); -} - -static void usage() -{ - printf( - "usage: %s [-f] [-o wgtfile] directory\n" - "\n" - " -o wgtfile the output widget file\n" - " -f force overwriting\n" - " -q quiet\n" - " -v verbose\n" - " -V version\n" - "\n", - appname - ); -} - -static struct option options[] = { - { "output", required_argument, NULL, 'o' }, - { "force", no_argument, NULL, 'f' }, - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, NULL, 'q' }, - { "verbose", no_argument, NULL, 'v' }, - { "version", no_argument, NULL, 'V' }, - { NULL, 0, NULL, 0 } -}; - -/* install the widgets of the list */ -int main(int ac, char **av) -{ - int i, force; - char *wgtfile, *directory, *x; - struct stat s; - - LOGUSER(appname); - - force = 0; - wgtfile = directory = NULL; - for (;;) { - i = getopt_long(ac, av, "qvVhfo:", options, NULL); - if (i < 0) - break; - switch (i) { - case 'o': - wgtfile = optarg; - break; - case 'q': - if (verbosity) - verbosity--; - break; - case 'v': - verbosity++; - break; - case 'f': - force = 1; - break; - case 'h': - usage(); - return 0; - case 'V': - version(); - return 0; - case ':': - ERROR("missing argument"); - return 1; - default: - ERROR("unrecognized option"); - return 1; - } - } - - /* remaining arguments and final checks */ - if (optind >= ac) { - ERROR("no directory set"); - return 1; - } - directory = av[optind++]; - if (optind < ac) { - ERROR("extra parameters found"); - return 1; - } - - /* set default values */ - if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) { - ERROR("asprintf failed"); - return 1; - } - - /* check values */ - if (stat(directory, &s)) { - ERROR("can't find directory %s", directory); - return 1; - } - if (!S_ISDIR(s.st_mode)) { - ERROR("%s isn't a directory", directory); - return 1; - } - if (access(wgtfile, F_OK) == 0 && force == 0) { - ERROR("can't overwrite existing %s", wgtfile); - return 1; - } - - NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory); - - /* creates an existing widget (for realpath it must exist) */ - i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644); - if (i < 0) { - ERROR("can't write widget %s", wgtfile); - return 1; - } - close(i); - - /* compute absolutes paths */ - x = realpath(wgtfile, NULL); - if (x == NULL) { - ERROR("realpath failed for %s", wgtfile); - return 1; - } - wgtfile = x; - - /* set and enter the workdir */ - if (chdir(directory)) { - ERROR("failed to enter directory %s", directory); - return 1; - } - if (set_workdir(".", 0)) - return 1; - - - if (fill_files()) - return 1; - - return !!zwrite(wgtfile); -} - - diff --git a/src/wgtpkg-sign.c b/src/wgtpkg-sign.c deleted file mode 100644 index 4e2adf2..0000000 --- a/src/wgtpkg-sign.c +++ /dev/null @@ -1,230 +0,0 @@ -/* - Copyright (C) 2015-2020 IoT.bzh - - author: José Bollo - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "verbose.h" -#include "wgtpkg-files.h" -#include "wgtpkg-workdir.h" -#include "wgtpkg-digsig.h" -#include "wgtpkg-xmlsec.h" - -#if !defined(MAXCERT) -#define MAXCERT 20 -#endif -#if !defined(DEFAULT_KEY_FILE) -#define DEFAULT_KEY_FILE "key.pem" -#endif -#if !defined(DEFAULT_CERT_FILE) -#define DEFAULT_CERT_FILE "cert.pem" -#endif - -const char appname[] = "wgtpkg-sign"; - -static unsigned int get_number(const char *value) -{ - char *end; - unsigned long int val; - - val = strtoul(value, &end, 10); - if (*end || 0 == val || val >= UINT_MAX || *value == '-') { - ERROR("bad number value %s", value); - exit(1); - } - return (unsigned int)val; -} - -static void version() -{ - printf( - "\n" - " %s version="AFM_VERSION"\n" - "\n" - " Copyright (C) 2015-2020 \"IoT.bzh\"\n" - " AFB comes with ABSOLUTELY NO WARRANTY.\n" - " Licence Apache 2\n" - "\n", - appname - ); -} - -static void usage() -{ - printf( - "usage: %s [-f] [-k keyfile] [-c certfile]... [-d number | -a] directory\n" - "\n" - " -k keyfile the private key to use for author signing\n" - " -c certfile the certificate(s) to use for author signing\n" - " -d number the number of the distributor signature (zero for automatic)\n" - " -a the author signature\n" - " -f force overwriting\n" - " -q quiet\n" - " -v verbose\n" - " -V version\n" - "\n", - appname - ); -} - -static struct option options[] = { - { "key", required_argument, NULL, 'k' }, - { "certificate", required_argument, NULL, 'c' }, - { "distributor", required_argument, NULL, 'd' }, - { "author", no_argument, NULL, 'a' }, - { "force", no_argument, NULL, 'f' }, - { "help", no_argument, NULL, 'h' }, - { "quiet", no_argument, NULL, 'q' }, - { "verbose", no_argument, NULL, 'v' }, - { "version", no_argument, NULL, 'V' }, - { NULL, 0, NULL, 0 } -}; - -/* install the widgets of the list */ -int main(int ac, char **av) -{ - int i, force, ncert, author; - unsigned int number; - char *keyfile, *certfiles[MAXCERT+1], *directory, **x; - struct stat s; - - LOGUSER(appname); - - force = ncert = author = 0; - number = UINT_MAX; - keyfile = directory = NULL; - for (;;) { - i = getopt_long(ac, av, "hfqvVak:c:d:", options, NULL); - if (i < 0) - break; - switch (i) { - case 'c': - if (ncert == MAXCERT) { - ERROR("maximum count of certificates reached"); - return 1; - } - certfiles[ncert++] = optarg; - continue; - case 'k': x = &keyfile; break; - case 'd': number = get_number(optarg); continue; - case 'f': force = 1; continue; - case 'a': author = 1; continue; - case 'h': usage(); return 0; - case 'V': version(); return 0; - case 'q': - if (verbosity) - verbosity--; - break; - case 'v': - verbosity++; - break; - case ':': - ERROR("missing argument"); - return 1; - default: - ERROR("unrecognized option"); - return 1; - } - if (*x != NULL) { - ERROR("option set twice"); - return 1; - } - *x = optarg; - } - - /* remaining arguments and final checks */ - if (optind >= ac) { - ERROR("no directory set"); - return 1; - } - directory = av[optind++]; - if (optind < ac) { - ERROR("extra parameters found"); - return 1; - } - - /* set default values */ - if (keyfile == NULL) - keyfile = DEFAULT_KEY_FILE; - if (ncert == 0) - certfiles[ncert++] = DEFAULT_CERT_FILE; - - /* check values */ - if (stat(directory, &s)) { - ERROR("can't find directory %s", directory); - return 1; - } - if (!S_ISDIR(s.st_mode)) { - ERROR("%s isn't a directory", directory); - return 1; - } - if (access(keyfile, R_OK) != 0) { - ERROR("can't access private key %s", keyfile); - return 1; - } - for(i = 0 ; i < ncert ; i++) - if (access(certfiles[i], R_OK) != 0) { - ERROR("can't access certificate %s", certfiles[i]); - return 1; - } - - /* init xmlsec module */ - if (xmlsec_init()) - return 1; - - - /* compute absolutes paths */ -#define rp(x) do { char *p = realpath(x, NULL); if (p != NULL) x = p; else { ERROR("realpath failed for %s",x); return 1; } } while(0) - rp(keyfile); - for(i = 0 ; i < ncert ; i++) - rp(certfiles[i]); -#undef rp - - /* set and enter the workdir */ - if (set_workdir(directory, 0)) - return 1; - - if (fill_files()) - return 1; - - if (author) - number = 0; - else if (number == UINT_MAX) - for (number = 1; get_signature(number) != NULL ; number++); - - if (!force && get_signature(number) != NULL) { - ERROR("can't overwrite existing signature %s", get_signature(number)->name); - return 1; - } - - NOTICE("-- SIGNING content of directory %s for number %u", directory, number); - - certfiles[ncert] = NULL; - return !!create_digsig(number, keyfile, (const char**)certfiles); -} - -- cgit 1.2.3-korg