aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-13 22:21:49 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-13 22:21:49 +0100
commite2de563d1ecb4585ce68521bd42f3ef45ac79f16 (patch)
tree94d57add5536e30b7296d6ab36d92d363441170b
parent12a227a2fc574cf0fd560453e1cdd15c50550abb (diff)
work in progress
Change-Id: I197678515772982ab6dd2fd949fa2a54ca4f268f
-rw-r--r--configure.ac1
-rw-r--r--src/Makefile.am6
-rw-r--r--src/appfwk.c262
-rw-r--r--src/secmgr-wrap.c15
-rw-r--r--src/simulation/security-manager.h53
-rw-r--r--src/verbose.c9
-rw-r--r--src/verbose.h23
-rw-r--r--src/wgt-config.c5
-rw-r--r--src/wgt-info.c14
-rw-r--r--src/wgtpkg-base64.c15
-rw-r--r--src/wgtpkg-certs.c5
-rw-r--r--src/wgtpkg-digsig.c44
-rw-r--r--src/wgtpkg-files.c17
-rw-r--r--src/wgtpkg-info.c10
-rw-r--r--src/wgtpkg-install.c28
-rw-r--r--src/wgtpkg-installer.c8
-rw-r--r--src/wgtpkg-pack.c22
-rw-r--r--src/wgtpkg-permissions.c3
-rw-r--r--src/wgtpkg-sign.c28
-rw-r--r--src/wgtpkg-workdir.c60
-rw-r--r--src/wgtpkg-xmlsec.c59
-rw-r--r--src/wgtpkg-zip.c47
22 files changed, 433 insertions, 301 deletions
diff --git a/configure.ac b/configure.ac
index ea099b0..04f21ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,7 @@ PKG_CHECK_MODULES([ZIP], [libzip >= 0.11])
PKG_CHECK_MODULES([XML2], [libxml-2.0])
PKG_CHECK_MODULES([OPENSSL], [openssl])
PKG_CHECK_MODULES([XMLSEC], [xmlsec1 xmlsec1-openssl])
+PKG_CHECK_MODULES([JSON], [json-c])
# Checks for header files.
AC_CHECK_HEADERS([fcntl.h limits.h stdlib.h string.h syslog.h unistd.h])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8b7abff..0826e12 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,7 +35,7 @@ deficondir = $(deffwdir)/icons
AM_CFLAGS = -Wall -Wno-pointer-sign
AM_CFLAGS += -ffunction-sections -fdata-sections
-AM_CFLAGS += ${ZIP_CFLAGS} ${XML2_CFLAGS} ${OPENSSL_CFLAGS} ${XMLSEC_CFLAGS}
+AM_CFLAGS += ${ZIP_CFLAGS} ${XML2_CFLAGS} ${OPENSSL_CFLAGS} ${XMLSEC_CFLAGS} ${JSON_CFLAGS}
AM_CFLAGS += -Isimulation
@@ -47,7 +47,7 @@ AM_CFLAGS += -DAPPDEFDIR=\"$(defappdir)\"
AM_LDFLAGS = -Wl,--gc-sections
-LDADD = ${ZIP_LIBS} ${XML2_LIBS} ${OPENSSL_LIBS} ${XMLSEC_LIBS}
+LDADD = ${ZIP_LIBS} ${XML2_LIBS} ${OPENSSL_LIBS} ${XMLSEC_LIBS} ${JSON_LIBS}
wgtpkg_sign_SOURCES = wgtpkg-sign.c ${WGTPKGSRCS} ${OTHERSRCS}
@@ -57,5 +57,5 @@ wgtpkg_installer_SOURCES = wgtpkg-installer.c ${WGTPKGSRCS} ${WGTSRCS} ${SECWRP}
wgtpkg_info_SOURCES = wgtpkg-info.c ${WGTPKGSRCS} ${WGTSRCS} ${OTHERSRCS}
-appfwk_SOURCES = ${APPFWK} ${OTHERSRCS}
+appfwk_SOURCES = ${APPFWK} ${WGTSRCS} ${OTHERSRCS}
diff --git a/src/appfwk.c b/src/appfwk.c
index 6dc7182..c6a874e 100644
--- a/src/appfwk.c
+++ b/src/appfwk.c
@@ -23,17 +23,15 @@
#include <unistd.h>
#include <sys/types.h>
-#include <wgt.h>
+#include <json.h>
-struct stringset {
- int count;
- char **strings;
-};
-
+#include <wgt-info.h>
struct appfwk {
int refcount;
- struct stringset paths;
+ int nrroots;
+ char **roots;
+ struct json_object *applications;
};
struct appfwk *appfwk_create()
@@ -43,8 +41,9 @@ struct appfwk *appfwk_create()
errno = ENOMEM;
else {
appfwk->refcount = 1;
- appfwk->paths.count = 0;
- appfwk->paths.strings = NULL;
+ appfwk->nrroots = 0;
+ appfwk->roots = NULL;
+ appfwk->applications = NULL;
}
return appfwk;
}
@@ -59,8 +58,9 @@ void appfwk_unref(struct appfwk *appfwk)
{
assert(appfwk);
if (!--appfwk->refcount) {
- while (appfwk->paths.count)
- free(appfwk->paths.strings[--appfwk->paths.count]);
+ while (appfwk->nrroots)
+ free(appfwk->roots[--appfwk->nrroots]);
+ free(appfwk->roots);
free(appfwk);
}
}
@@ -69,19 +69,23 @@ int appfwk_add_root(struct appfwk *appfwk, const char *path)
{
int i, n;
char *r, **roots;
+
assert(appfwk);
+
+ /* don't depend on the cwd and unique name */
r = realpath(path, NULL);
if (!r)
return -1;
/* avoiding duplications */
- n = appfwk->paths.count;
- roots = appfwk->paths.strings;
- for (i = 0 ; i < n ; i++)
+ n = appfwk->nrroots;
+ roots = appfwk->roots;
+ for (i = 0 ; i < n ; i++) {
if (!strcmp(r, roots[i])) {
free(r);
return 0;
}
+ }
/* add */
roots = realloc(roots, (n + 1) * sizeof(roots[0]));
@@ -91,92 +95,119 @@ int appfwk_add_root(struct appfwk *appfwk, const char *path)
return -1;
}
roots[n++] = r;
- appfwk->paths.strings = roots;
- appfwk->paths.count = n;
+ appfwk->roots = roots;
+ appfwk->nrroots = n;
return 0;
}
-struct aea {
- char *path;
- char *appver;
- char *ver;
- const char *root;
- const char *appid;
- const char *version;
- int (*callback)(struct wgt *wgt, void *data);
- void *data;
-};
-struct appfwk_enumerate_applications_context {
- const char *dirpath;
- const char *appid;
- const char *version;
-
- void *data;
-};
+static int json_add(struct json_object *obj, const char *key, struct json_object *val)
+{
+ json_object_object_add(obj, key, val);
+ return 0;
+}
-inline int testd(int dirfd, struct dirent *e)
+static int json_add_str(struct json_object *obj, const char *key, const char *val)
{
- return e->d_name[0] != '.' || (e->d_name[1] && (e->d_name[1] != '.' || e->d_name[2]));
+ struct json_object *str = json_object_new_string (val ? val : "");
+ return str ? json_add(obj, key, str) : -1;
}
-#include <stdio.h>
-static int aea3(int dirfd, struct aea *aea)
+static int json_add_int(struct json_object *obj, const char *key, int val)
{
- printf("aea3 %s *** %s *** %s\n", aea->path, aea->appver, aea->ver);
- return 0;
+ struct json_object *v = json_object_new_int (val);
+ return v ? json_add(obj, key, v) : -1;
}
-static int aea2(int dirfd, struct aea *aea)
+static struct json_object *read_app_desc(const char *path)
{
- DIR *dir;
- int rc, fd;
- struct dirent entry, *e;
+ struct wgt_info *info;
+ const struct wgt_desc *desc;
+ struct json_object *result;
+ char *appid, *end;
- dir = fdopendir(dirfd);
- if (!dir)
- return -1;
+ result = json_object_new_object();
+ if (!result)
+ goto error;
- aea->version = entry.d_name;
+ info = wgt_info_createat(AT_FDCWD, path, 0, 0, 0);
+ if (info == NULL)
+ goto error2;
+ desc = wgt_info_desc(info);
- rc = readdir_r(dir, &entry, &e);
- while (!rc && e) {
- if (testd(dirfd, &entry)) {
- fd = openat(dirfd, entry.d_name, O_DIRECTORY|O_RDONLY);
- if (fd >= 0) {
- strcpy(aea->ver, entry.d_name);
- rc = aea3(fd, aea);
- close(fd);
- }
- }
- rc = readdir_r(dir, &entry, &e);
+ appid = alloca(2 + strlen(desc->id) + strlen(desc->version));
+ end = stpcpy(appid, desc->id);
+ *end++ = '@';
+ strcpy(end, desc->version);
+
+ if(json_add_str(result, "appid", appid)
+ || json_add_str(result, "id", desc->id)
+ || json_add_str(result, "version", desc->version)
+ || json_add_str(result, "path", path)
+ || json_add_int(result, "width", desc->width)
+ || json_add_int(result, "height", desc->height)
+ || json_add_str(result, "name", desc->name)
+ || json_add_str(result, "description", desc->description)
+ || json_add_str(result, "shortname", desc->name_short)
+ || json_add_str(result, "author", desc->author))
+ goto error3;
+
+ wgt_info_unref(info);
+ return result;
+
+error3:
+ wgt_info_unref(info);
+error2:
+ json_object_put(result);
+error:
+ return NULL;
+}
+
+static int add_appdesc(struct json_object *appset, struct json_object *app)
+{
+ struct json_object *appid;
+
+ if (!json_object_object_get_ex(app, "appid", &appid)) {
+ errno = EINVAL;
+ return -1;
}
- closedir(dir);
- return rc;
+
+ return json_add(appset, json_object_get_string(appid), app);
}
-static int aea1(int dirfd, struct aea *aea)
+struct enumdata {
+ char path[PATH_MAX];
+ int length;
+ struct json_object *apps;
+};
+
+static int enumentries(struct enumdata *data, int (*callto)(struct enumdata *))
{
DIR *dir;
- int rc, fd;
+ int rc;
+ char *beg, *end;
struct dirent entry, *e;
- dir = fdopendir(dirfd);
+ /* opens the directory */
+ dir = opendir(data->path);
if (!dir)
return -1;
- aea->appid = entry.d_name;
+ /* prepare appending entry names */
+ beg = data->path + data->length;
+ *beg++ = '/';
+ /* enumerate entries */
rc = readdir_r(dir, &entry, &e);
while (!rc && e) {
- if (testd(dirfd, &entry)) {
- fd = openat(dirfd, entry.d_name, O_DIRECTORY|O_RDONLY);
- if (fd >= 0) {
- aea->ver = stpcpy(aea->appver, entry.d_name);
- *aea->ver++ = '/';
- rc = aea2(fd, aea);
- close(fd);
- }
+ if (entry.d_name[0] != '.' || (entry.d_name[1] && (entry.d_name[1] != '.' || entry.d_name[2]))) {
+ /* prepare callto */
+ end = stpcpy(beg, entry.d_name);
+ data->length = end - data->path;
+ /* call the function */
+ rc = callto(data);
+ if (rc)
+ break;
}
rc = readdir_r(dir, &entry, &e);
}
@@ -184,41 +215,64 @@ static int aea1(int dirfd, struct aea *aea)
return rc;
}
-int appfwk_enumerate_applications(struct appfwk *appfwk, int (*callback)(struct wgt *wgt, void *data), void *data)
+static int recordapp(struct enumdata *data)
{
- int rc, iroot, nroots;
- char **roots;
- int fd;
- char buffer[PATH_MAX];
- struct aea aea;
-
- aea.callback = callback;
- aea.data = data;
- aea.path = buffer;
-
- nroots = appfwk->paths.count;
- roots = appfwk->paths.strings;
- for (iroot = 0 ; iroot < nroots ; iroot++) {
- aea.root = roots[iroot];
- fd = openat(AT_FDCWD, aea.root, O_DIRECTORY|O_RDONLY);
- if (fd >= 0) {
- aea.appver = stpcpy(buffer, aea.root);
- *aea.appver++ = '/';
- rc = aea1(fd, &aea);
- close(fd);
+ struct json_object *app;
+
+ app = read_app_desc(data->path);
+ if (app != NULL) {
+ if (!add_appdesc(data->apps, app))
+ return 0;
+ json_object_put(app);
+ }
+ return -1;
+}
+
+/* enumerate the versions */
+static int enumvers(struct enumdata *data)
+{
+ int rc = enumentries(data, recordapp);
+ return !rc || errno != ENOTDIR ? 0 : rc;
+}
+
+/* regenerate the list of applications */
+int appfwk_update_applications(struct appfwk *af)
+{
+ int rc, iroot;
+ struct enumdata edata;
+ struct json_object *oldapps;
+
+ /* create the result */
+ edata.apps = json_object_new_object();
+ if (edata.apps == NULL) {
+ errno = ENOMEM;
+ return -1;
+ }
+ /* for each root */
+ for (iroot = 0 ; iroot < af->nrroots ; iroot++) {
+ edata.length = stpcpy(edata.path, af->roots[iroot]) - edata.path;
+ assert(edata.length < sizeof edata.path);
+ /* enumerate the applications */
+ rc = enumentries(&edata, enumvers);
+ if (rc) {
+ json_object_put(edata.apps);
+ return rc;
}
}
+ /* commit the result */
+ oldapps = af->applications;
+ af->applications = edata.apps;
+ if (oldapps)
+ json_object_put(oldapps);
return 0;
}
-/*
- struct wgt *wgt;
- wgt = wgt_create();
- if (!wgt)
- return -1;
- wgt_unref(wgt);
-
- rfd = AT_FDCWD;
- if (pathname) {
- rfd = openat(rfd, pathname, O_PATH|O_DIRECTORY);
-*/
+
+int main()
+{
+struct appfwk *af = appfwk_create();
+appfwk_add_root(af,"af/apps/");
+appfwk_update_applications(af);
+json_object_to_file("/dev/stdout", af->applications);
+return 0;
+}
diff --git a/src/secmgr-wrap.c b/src/secmgr-wrap.c
index 75c63ca..40c06b0 100644
--- a/src/secmgr-wrap.c
+++ b/src/secmgr-wrap.c
@@ -21,6 +21,7 @@
#include <security-manager.h>
+#include "verbose.h"
#include "secmgr-wrap.h"
static app_inst_req *request = NULL;
@@ -45,15 +46,15 @@ int secmgr_init(const char *id)
assert(request == NULL);
rc = security_manager_app_inst_req_new(&request);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_inst_req_new failed");
+ ERROR("security_manager_app_inst_req_new failed");
else {
rc = security_manager_app_inst_req_set_pkg_id(request, id);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_inst_req_set_pkg_id failed");
+ ERROR("security_manager_app_inst_req_set_pkg_id failed");
else {
rc = security_manager_app_inst_req_set_app_id(request, id);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_inst_req_set_app_id failed");
+ ERROR("security_manager_app_inst_req_set_app_id failed");
}
}
if (rc != SECURITY_MANAGER_SUCCESS)
@@ -73,8 +74,8 @@ int secmgr_install()
assert(request != NULL);
rc = security_manager_app_install(request);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_install failed");
- security_manager_app_inst_req_free(request);
+ ERROR("security_manager_app_install failed");
+ secmgr_cancel();
return retcode(rc);
}
@@ -84,7 +85,7 @@ int secmgr_permit(const char *permission)
assert(request != NULL);
rc = security_manager_app_inst_req_add_privilege(request, permission);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_inst_add_privilege %s failed", permission);
+ ERROR("security_manager_app_inst_add_privilege %s failed", permission);
return retcode(rc);
}
@@ -94,7 +95,7 @@ static int addpath(const char *pathname, enum app_install_path_type type)
assert(request != NULL);
rc = security_manager_app_inst_req_add_path(request, pathname, type);
if (rc != SECURITY_MANAGER_SUCCESS)
- syslog(LOG_ERR, "security_manager_app_inst_add_path %s failed", pathname);
+ ERROR("security_manager_app_inst_add_path %s failed", pathname);
return retcode(rc);
}
diff --git a/src/simulation/security-manager.h b/src/simulation/security-manager.h
new file mode 100644
index 0000000..4969555
--- /dev/null
+++ b/src/simulation/security-manager.h
@@ -0,0 +1,53 @@
+/*
+ Copyright 2015 IoT.bzh
+
+ 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 <stdio.h>
+#include <stdint.h>
+enum lib_retcode {
+ SECURITY_MANAGER_SUCCESS,
+ SECURITY_MANAGER_ERROR_INPUT_PARAM,
+ SECURITY_MANAGER_ERROR_MEMORY,
+ SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE,
+ SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED,
+ SECURITY_MANAGER_ERROR_ACCESS_DENIED
+};
+enum app_install_path_type {
+ SECURITY_MANAGER_PATH_PUBLIC_RO,
+ SECURITY_MANAGER_PATH_RO,
+ SECURITY_MANAGER_PATH_RW
+};
+typedef void app_inst_req;
+static int diese = 0;
+#define security_manager_app_inst_req_free(r) \
+ (printf("security_manager_app_inst_req_free(%p)\n",r),(void)0)
+
+#define security_manager_app_inst_req_new(pr) \
+ (*(pr)=(void*)(intptr_t)(++diese), printf("security_manager_app_inst_req_new(%p)\n",*pr), SECURITY_MANAGER_SUCCESS)
+
+#define security_manager_app_inst_req_set_pkg_id(r,i) \
+ (printf("security_manager_app_inst_req_set_pkg_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
+
+#define security_manager_app_inst_req_set_app_id(r,i) \
+ (printf("security_manager_app_inst_req_set_app_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
+
+#define security_manager_app_inst_req_add_privilege(r,p) \
+ (printf("security_manager_app_inst_req_add_privilege(%p,\"%s\")\n",r,p), SECURITY_MANAGER_SUCCESS)
+
+#define security_manager_app_inst_req_add_path(r,p,t) \
+ (printf("security_manager_app_inst_req_add_path(%p,\"%s\",%d)\n",r,p,t), SECURITY_MANAGER_SUCCESS)
+
+#define security_manager_app_install(r) \
+ (printf("security_manager_app_install(%p)\n",r), SECURITY_MANAGER_SUCCESS)
diff --git a/src/verbose.c b/src/verbose.c
index fa7ea3f..ad5d265 100644
--- a/src/verbose.c
+++ b/src/verbose.c
@@ -14,7 +14,14 @@
limitations under the License.
*/
-#include <string.h>
+#include "verbose.h"
+#if !defined(NDEBUG)
int verbosity = 1;
+#else
+void verbose_error(const char *file, int line)
+{
+ ERROR("error file %s line %d", file, line);
+}
+#endif
diff --git a/src/verbose.h b/src/verbose.h
index 9e5e784..8103539 100644
--- a/src/verbose.h
+++ b/src/verbose.h
@@ -14,11 +14,20 @@
limitations under the License.
*/
-
+#if !defined(NDEBUG)
+#include <syslog.h>
extern int verbosity;
-#define warning(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
-#define warning(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
-#define notice(...) do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
-#define info(...) do{if(verbosity)syslog(LOG_INFO,__VA_ARGS__);}while(0)
-#define debug(...) do{if(verbosity>1)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
-
+#define ERROR(...) syslog(LOG_ERR,__VA_ARGS__)
+#define WARNING(...) do{if(verbosity)syslog(LOG_WARNING,__VA_ARGS__);}while(0)
+#define NOTICE(...) do{if(verbosity)syslog(LOG_NOTICE,__VA_ARGS__);}while(0)
+#define INFO(...) do{if(verbosity)syslog(LOG_INFO,__VA_ARGS__);}while(0)
+#define DEBUG(...) do{if(verbosity>1)syslog(LOG_DEBUG,__VA_ARGS__);}while(0)
+#else
+#include <syslog.h>
+extern void verbose_error(const char *file, int line);
+#define ERROR(...) verbose_error(__FILE__,__LINE__)
+#define WARNING(...) do{/*nothing*/}while(0)
+#define NOTICE(...) do{/*nothing*/}while(0)
+#define INFO(...) do{/*nothing*/}while(0)
+#define DEBUG(...) do{/*nothing*/}while(0)
+#endif
diff --git a/src/wgt-config.c b/src/wgt-config.c
index 04548c3..2e32628 100644
--- a/src/wgt-config.c
+++ b/src/wgt-config.c
@@ -24,6 +24,7 @@
#include <libxml/tree.h>
#include <libxml/uri.h>
+#include "verbose.h"
#include "wgt.h"
#include "wgt-config.h"
@@ -115,13 +116,13 @@ int wgt_config_open(struct wgt *wgt)
assert(!configxml);
fd = wgt_open_read(wgt, wgt_config_string_xml_file);
if (fd < 0) {
- syslog(LOG_ERR, "can't open config file %s", wgt_config_string_xml_file);
+ ERROR("can't open config file %s", wgt_config_string_xml_file);
return fd;
}
configxml = xmlReadFd(fd, wgt_config_string_xml_file, NULL, 0);
close(fd);
if (configxml == NULL) {
- syslog(LOG_ERR, "xml parse of config file %s failed", wgt_config_string_xml_file);
+ ERROR("xml parse of config file %s failed", wgt_config_string_xml_file);
return -1;
}
assert(xmlDocGetRootElement(configxml));
diff --git a/src/wgt-info.c b/src/wgt-info.c
index 61779e0..019f8ce 100644
--- a/src/wgt-info.c
+++ b/src/wgt-info.c
@@ -83,7 +83,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
node = wgt_config_widget();
if (!node) {
- warning("no widget");
+ WARNING("no widget");
errno = EINVAL;
return -1;
}
@@ -113,7 +113,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
node = wgt_config_content();
desc->content_src = optprop(node, wgt_config_string_src);
if (node && desc->content_src == NULL) {
- warning("content without src");
+ WARNING("content without src");
errno = EINVAL;
return -1;
}
@@ -137,7 +137,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
*icontail = icon;
if (icon->src == NULL) {
- warning("icon without src");
+ WARNING("icon without src");
errno = EINVAL;
return -1;
}
@@ -163,7 +163,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
*featuretail = feature;
if (feature->name == NULL) {
- warning("feature without name");
+ WARNING("feature without name");
errno = EINVAL;
return -1;
}
@@ -183,7 +183,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
*paramtail = param;
if (param->name == NULL || param->value == NULL) {
- warning("param without name or value");
+ WARNING("param without name or value");
errno = EINVAL;
return -1;
}
@@ -214,7 +214,7 @@ static int fill_desc(struct wgt_desc *desc, int want_icons, int want_features, i
preference->next = NULL;
if (preference->name == NULL) {
- warning("preference without name");
+ WARNING("preference without name");
errno = EINVAL;
return -1;
}
@@ -416,7 +416,7 @@ void wgt_info_dump(struct wgt_info *ifo, int fd, const char *prefix)
assert(ifo);
f = fdopen(fd, "w");
if (f == NULL)
- warning("can't fdopen in wgt_info_dump");
+ WARNING("can't fdopen in wgt_info_dump");
else {
dump_desc(&ifo->desc, f, prefix);
fclose(f);
diff --git a/src/wgtpkg-base64.c b/src/wgtpkg-base64.c
index 5cf6f8a..4e6d84e 100644
--- a/src/wgtpkg-base64.c
+++ b/src/wgtpkg-base64.c
@@ -19,6 +19,7 @@
#include <string.h>
#include <syslog.h>
+#include "verbose.h"
#include "wgtpkg.h"
static char tob64(char x)
@@ -38,12 +39,12 @@ char *base64encw(const char *buffer, int length, int width)
char *result;
if (width == 0 || width % 4) {
- syslog(LOG_ERR, "bad width in base64enc");
+ ERROR("bad width in base64enc");
return NULL;
}
result = malloc(2 + 4 * ((length + 2) / 3) + (length / width));
if (result == NULL) {
- syslog(LOG_ERR, "malloc failed in base64enc");
+ ERROR("malloc failed in base64enc");
return NULL;
}
in = out = 0;
@@ -108,7 +109,7 @@ int base64dec(const char *buffer, char **output)
len = strlen(buffer);
result = malloc(3 * ((3 + len) / 4));
if (result == NULL) {
- syslog(LOG_ERR, "malloc failed in base64dec");
+ ERROR("malloc failed in base64dec");
return -1;
}
in = out = 0;
@@ -116,7 +117,7 @@ int base64dec(const char *buffer, char **output)
in++;
while (buffer[in]) {
if (in + 4 > len) {
- syslog(LOG_ERR, "unexpected input size in base64dec");
+ ERROR("unexpected input size in base64dec");
free(result);
return -1;
}
@@ -126,12 +127,12 @@ int base64dec(const char *buffer, char **output)
x3 = (unsigned char)fromb64(buffer[in+3]);
in += 4;
if (x0 == 'E' || x1 == 'E' || x2 == 'E' || x3 == 'E') {
- syslog(LOG_ERR, "unexpected input character in base64dec");
+ ERROR("unexpected input character in base64dec");
free(result);
return -1;
}
if (x0 == '@' || x1 == '@' || (x2 == '@' && x3 != '@')) {
- syslog(LOG_ERR, "unexpected termination character in base64dec");
+ ERROR("unexpected termination character in base64dec");
free(result);
return -1;
}
@@ -145,7 +146,7 @@ int base64dec(const char *buffer, char **output)
else if (!buffer[in])
out += 1 + (x2 != '@');
else {
- syslog(LOG_ERR, "unexpected continuation in base64dec");
+ ERROR("unexpected continuation in base64dec");
free(result);
return -1;
}
diff --git a/src/wgtpkg-certs.c b/src/wgtpkg-certs.c
index b4b45fd..98118f9 100644
--- a/src/wgtpkg-certs.c
+++ b/src/wgtpkg-certs.c
@@ -18,6 +18,7 @@
#include <syslog.h>
#include <openssl/x509.h>
+#include "verbose.h"
#include "wgtpkg.h"
struct x509l {
@@ -31,7 +32,7 @@ static int add_certificate_x509(X509 *x)
{
X509 **p = realloc(certificates.certs, (certificates.count + 1) * sizeof(X509*));
if (!p) {
- syslog(LOG_ERR, "reallocation failed for certificate");
+ ERROR("reallocation failed for certificate");
return -1;
}
certificates.certs = p;
@@ -48,7 +49,7 @@ static int add_certificate_bin(const char *bin, int len)
while (b < e) {
X509 *x = d2i_X509(NULL, (const unsigned char **)&b, e-b);
if (x == NULL) {
- syslog(LOG_ERR, "d2i_X509 failed");
+ ERROR("d2i_X509 failed");
return -1;
}
rc = add_certificate_x509(x);
diff --git a/src/wgtpkg-digsig.c b/src/wgtpkg-digsig.c
index 984127b..ed78354 100644
--- a/src/wgtpkg-digsig.c
+++ b/src/wgtpkg-digsig.c
@@ -83,7 +83,7 @@ static xmlNodePtr search_for(const char *attrname, const char *value)
val = xmlGetProp(iter, attrname);
if (val != NULL && !strcmp(val, value)) {
if (result != NULL) {
- syslog(LOG_ERR, "duplicated %s %s", attrname, value);
+ ERROR("duplicated %s %s", attrname, value);
free(val);
return NULL;
}
@@ -105,7 +105,7 @@ static xmlNodePtr search_for(const char *attrname, const char *value)
iter = next;
}
if (result == NULL)
- syslog(LOG_ERR, "node of %s '%s' not found", attrname, value);
+ ERROR("node of %s '%s' not found", attrname, value);
return result;
}
@@ -130,30 +130,30 @@ static int check_one_reference(xmlNodePtr ref)
/* get the uri */
uri = xmlGetProp(ref, "URI");
if (uri == NULL) {
- syslog(LOG_ERR, "attribute URI of element <Reference> not found");
+ ERROR("attribute URI of element <Reference> not found");
goto error;
}
/* parse the uri */
u = xmlParseURI(uri);
if (!u) {
- syslog(LOG_ERR, "error while parsing URI %s", uri);
+ ERROR("error while parsing URI %s", uri);
goto error2;
}
/* check that unexpected parts are not there */
if (u->scheme || u->opaque || u->authority || u->server || u->user || u->query) {
- syslog(LOG_ERR, "unexpected uri component in %s", uri);
+ ERROR("unexpected uri component in %s", uri);
goto error3;
}
/* check path and fragment */
if (!u->path && !u->fragment) {
- syslog(LOG_ERR, "invalid uri %s", uri);
+ ERROR("invalid uri %s", uri);
goto error3;
}
if (u->path && u->fragment) {
- syslog(LOG_ERR, "not allowed to sign foreign fragment in %s", uri);
+ ERROR("not allowed to sign foreign fragment in %s", uri);
goto error3;
}
@@ -161,15 +161,15 @@ static int check_one_reference(xmlNodePtr ref)
/* check that the path is valid */
fdesc = file_of_name(u->path);
if (fdesc == NULL) {
- syslog(LOG_ERR, "reference to unknown file %s", u->path);
+ ERROR("reference to unknown file %s", u->path);
goto error3;
}
if (fdesc->type != type_file) {
- syslog(LOG_ERR, "reference to directory %s", u->path);
+ ERROR("reference to directory %s", u->path);
goto error3;
}
if ((fdesc->flags & flag_distributor_signature) != 0) {
- syslog(LOG_ERR, "reference to signature %s", u->path);
+ ERROR("reference to signature %s", u->path);
goto error3;
}
fdesc->flags |= flag_referenced;
@@ -209,7 +209,7 @@ static int check_references(xmlNodePtr sinfo)
if (f->type == type_file) {
flags = f->flags;
if (!(flags & (flag_signature | flag_referenced))) {
- syslog(LOG_ERR, "file not referenced in signature: %s", f->name);
+ ERROR("file not referenced in signature: %s", f->name);
result = -1;
}
}
@@ -233,7 +233,7 @@ static int get_certificates(xmlNodePtr kinfo)
if (is_element(n2, "X509Certificate")) {
b = xmlNodeGetContent(n2);
if (b == NULL) {
- syslog(LOG_ERR, "xmlNodeGetContent of X509Certificate failed");
+ ERROR("xmlNodeGetContent of X509Certificate failed");
return -1;
}
rc = add_certificate_b64(b);
@@ -259,19 +259,19 @@ static int checkdocument()
rootsig = xmlDocGetRootElement(document);
if (!is_node(rootsig, "Signature")) {
- syslog(LOG_ERR, "root element <Signature> not found");
+ ERROR("root element <Signature> not found");
goto error;
}
sinfo = next_element(rootsig->children);
if (!is_node(sinfo, "SignedInfo")) {
- syslog(LOG_ERR, "element <SignedInfo> not found");
+ ERROR("element <SignedInfo> not found");
goto error;
}
svalue = next_element(sinfo->next);
if (!is_node(svalue, "SignatureValue")) {
- syslog(LOG_ERR, "element <SignatureValue> not found");
+ ERROR("element <SignatureValue> not found");
goto error;
}
@@ -303,7 +303,7 @@ int verify_digsig(struct filedesc *fdesc)
int res, fd;
assert ((fdesc->flags & flag_signature) != 0);
- debug("-- checking file %s",fdesc->name);
+ DEBUG("-- checking file %s",fdesc->name);
/* reset the flags */
file_clear_flags();
@@ -312,19 +312,19 @@ int verify_digsig(struct filedesc *fdesc)
/* reads and xml parses the signature file */
fd = openat(workdirfd, fdesc->name, O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "cant't open file %s", fdesc->name);
+ ERROR("cant't open file %s", fdesc->name);
return -1;
}
document = xmlReadFd(fd, fdesc->name, NULL, 0);
close(fd);
if (document == NULL) {
- syslog(LOG_ERR, "xml parse of file %s failed", fdesc->name);
+ ERROR("xml parse of file %s failed", fdesc->name);
return -1;
}
res = checkdocument();
if (res)
- syslog(LOG_ERR, "previous error was during check of file %s", fdesc->name);
+ ERROR("previous error was during check of file %s", fdesc->name);
xmlFreeDoc(document);
return res;
@@ -374,17 +374,17 @@ int create_digsig(int index, const char *key, const char **certs)
/* save the doc as file */
fd = openat(workdirfd, fdesc->name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
if (fd < 0) {
- syslog(LOG_ERR, "cant open %s for write", fdesc->name);
+ ERROR("cant open %s for write", fdesc->name);
goto error2;
}
ctx = xmlSaveToFd(fd, NULL, XML_SAVE_FORMAT);
if (!ctx) {
- syslog(LOG_ERR, "xmlSaveToFd failed for %s", fdesc->name);
+ ERROR("xmlSaveToFd failed for %s", fdesc->name);
goto error3;
}
len = xmlSaveDoc(ctx, doc);
if (len < 0) {
- syslog(LOG_ERR, "xmlSaveDoc to %s failed", fdesc->name);
+ ERROR("xmlSaveDoc to %s failed", fdesc->name);
goto error4;
}
diff --git a/src/wgtpkg-files.c b/src/wgtpkg-files.c
index 16d94e2..ed63726 100644
--- a/src/wgtpkg-files.c
+++ b/src/wgtpkg-files.c
@@ -24,6 +24,7 @@
#include <fcntl.h>
#include <unistd.h>
+#include "verbose.h"
#include "wgtpkg.h"
struct fdb {
@@ -95,7 +96,7 @@ static struct filedesc *get_filedesc(const char *name, int create)
/* allocations */
grow = realloc(allfiles.files, (allfiles.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
- syslog(LOG_ERR, "realloc failed in get_filedesc");
+ ERROR("realloc failed in get_filedesc");
return NULL;
}
allfiles.files = grow;
@@ -103,7 +104,7 @@ static struct filedesc *get_filedesc(const char *name, int create)
if (sig) {
grow = realloc(allsignatures.files, (allsignatures.count + 1) * sizeof(struct filedesc *));
if (grow == NULL) {
- syslog(LOG_ERR, "second realloc failed in get_filedesc");
+ ERROR("second realloc failed in get_filedesc");
return NULL;
}
allsignatures.files = grow;
@@ -111,7 +112,7 @@ static struct filedesc *get_filedesc(const char *name, int create)
result = malloc(sizeof(struct filedesc) + strlen(name));
if (!result) {
- syslog(LOG_ERR, "calloc failed in get_filedesc");
+ ERROR("calloc failed in get_filedesc");
return NULL;
}
@@ -149,7 +150,7 @@ static struct filedesc *file_add(const char *name, enum entrytype type)
else if (desc->type == type_unset)
desc->type = type;
else {
- syslog(LOG_ERR, "redeclaration of %s in file_add", name);
+ ERROR("redeclaration of %s in file_add", name);
errno = EEXIST;
desc = NULL;
}
@@ -228,7 +229,7 @@ struct filedesc *create_signature(unsigned int number)
len = asprintf(&name, "%s%u%s", distributor_file_prefix, number, distributor_file_suffix);
if (len < 0)
- syslog(LOG_ERR, "asprintf failed in create_signature");
+ ERROR("asprintf failed in create_signature");
else {
assert(len > 0);
result = file_of_name(name);
@@ -256,12 +257,12 @@ static int fill_files_rec(char name[PATH_MAX], int offset)
fd = openat(workdirfd, offset ? name : ".", O_DIRECTORY|O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "openat %.*s failed in fill_files_rec", offset, name);
+ ERROR("openat %.*s failed in fill_files_rec", offset, name);
return -1;
}
dir = fdopendir(fd);
if (!dir) {
- syslog(LOG_ERR, "opendir %.*s failed in fill_files_rec", offset, name);
+ ERROR("opendir %.*s failed in fill_files_rec", offset, name);
close(fd);
return -1;
}
@@ -276,7 +277,7 @@ static int fill_files_rec(char name[PATH_MAX], int offset)
;
else if (offset + len >= PATH_MAX) {
closedir(dir);
- syslog(LOG_ERR, "name too long in fill_files_rec");
+ ERROR("name too long in fill_files_rec");
errno = ENAMETOOLONG;
return -1;
} else {
diff --git a/src/wgtpkg-info.c b/src/wgtpkg-info.c
index 7854b09..f8778e0 100644
--- a/src/wgtpkg-info.c
+++ b/src/wgtpkg-info.c
@@ -79,10 +79,10 @@ int main(int ac, char **av)
verbosity++;
break;
case ':':
- syslog(LOG_ERR, "missing argument value");
+ ERROR("missing argument value");
return 1;
default:
- syslog(LOG_ERR, "unrecognized option");
+ ERROR("unrecognized option");
return 1;
}
}
@@ -92,7 +92,7 @@ int main(int ac, char **av)
for (i = 0 ; av[i] != NULL ; i++) {
wpath = realpath(av[i], NULL);
if (wpath == NULL) {
- syslog(LOG_ERR, "error while getting realpath of %dth widget: %s", i+1, av[i]);
+ ERROR("error while getting realpath of %dth widget: %s", i+1, av[i]);
return 1;
}
av[i] = wpath;
@@ -120,11 +120,11 @@ static int check_and_show()
/* install the widget of the file */
static void show(const char *wgtfile)
{
- notice("-- INFO for widget %s --", wgtfile);
+ NOTICE("-- INFO for widget %s --", wgtfile);
/* workdir */
if (make_workdir_base("/tmp", "UNPACK", 0)) {
- syslog(LOG_ERR, "failed to create a working directory");
+ ERROR("failed to create a working directory");
return;
}
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index 37a47ff..6a4a865 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -33,7 +33,7 @@ static int check_defined(const void *data, const char *name)
{
if (data)
return 0;
- syslog(LOG_ERR, "widget has no defined '%s' (temporary constraints)", name);
+ ERROR("widget has no defined '%s' (temporary constraints)", name);
errno = EINVAL;
return -1;
}
@@ -49,7 +49,7 @@ static int check_valid_string(const char *value, const char *name)
c = value[pos];
while(c) {
if (!isalnum(c) && !strchr(".-_", c)) {
- syslog(LOG_ERR, "forbidden char %c in '%s' -> '%s' (temporary constraints)", c, name, value);
+ ERROR("forbidden char %c in '%s' -> '%s' (temporary constraints)", c, name, value);
errno = EINVAL;
return -1;
}
@@ -67,7 +67,7 @@ static int check_temporary_constraints(const struct wgt_desc *desc)
if (result)
return result;
if (desc->icons->next) {
- syslog(LOG_ERR, "widget has more than one icon defined (temporary constraints)");
+ ERROR("widget has more than one icon defined (temporary constraints)");
errno = EINVAL;
result = -1;
}
@@ -78,13 +78,13 @@ static int check_permissions(const char *name, int required)
{
if (permission_exists(name)) {
if (request_permission(name)) {
- debug("granted permission: %s", name);
+ DEBUG("granted permission: %s", name);
} else if (required) {
- syslog(LOG_ERR, "ungranted permission required: %s", name);
+ ERROR("ungranted permission required: %s", name);
errno = EPERM;
return 0;
} else {
- notice("ungranted permission optional: %s", name);
+ INFO("ungranted permission optional: %s", name);
}
}
return 1;
@@ -112,7 +112,7 @@ static int move_widget(const char *root, const struct wgt_desc *desc, int force)
rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->version);
if (rc >= sizeof newdir) {
- syslog(LOG_ERR, "path to long in move_widget");
+ ERROR("path to long in move_widget");
errno = EINVAL;
return -1;
}
@@ -128,14 +128,14 @@ static int install_icon(const struct wgt_desc *desc)
rc = snprintf(link, sizeof link, "%s/%s@%s", ICONDESTDIR, desc->id, desc->version);
if (rc >= sizeof link) {
- syslog(LOG_ERR, "link to long in install_icon");
+ ERROR("link to long in install_icon");
errno = EINVAL;
return -1;
}
rc = snprintf(target, sizeof target, "%s/%s", workdir, desc->icons->src);
if (rc >= sizeof target) {
- syslog(LOG_ERR, "target to long in install_icon");
+ ERROR("target to long in install_icon");
errno = EINVAL;
return -1;
}
@@ -143,7 +143,7 @@ static int install_icon(const struct wgt_desc *desc)
unlink(link);
rc = symlink(target, link);
if (rc)
- syslog(LOG_ERR, "can't create link %s -> %s", link, target);
+ ERROR("can't create link %s -> %s", link, target);
return rc;
}
@@ -168,7 +168,7 @@ static int install_security(const struct wgt_desc *desc)
assert(sizeof path > (head - path));
len = (int)(sizeof path - (head - path));
if (!len) {
- syslog(LOG_ERR, "root path too long in install_security");
+ ERROR("root path too long in install_security");
errno = ENAMETOOLONG;
goto error2;
}
@@ -182,7 +182,7 @@ static int install_security(const struct wgt_desc *desc)
f = file_of_index(i++);
lf = (int)strlen(f->name);
if (lf >= len) {
- syslog(LOG_ERR, "path too long in install_security");
+ ERROR("path too long in install_security");
errno = ENAMETOOLONG;
goto error2;
}
@@ -218,11 +218,11 @@ void install_widget(const char *wgtfile, const char *root, int force)
struct wgt_info *ifo;
const struct wgt_desc *desc;
- notice("-- INSTALLING widget %s --", wgtfile);
+ NOTICE("-- INSTALLING widget %s --", wgtfile);
/* workdir */
if (make_workdir_base(root, "TMP", 0)) {
- syslog(LOG_ERR, "failed to create a working directory");
+ ERROR("failed to create a working directory");
goto error1;
}
diff --git a/src/wgtpkg-installer.c b/src/wgtpkg-installer.c
index e8568b8..62807aa 100644
--- a/src/wgtpkg-installer.c
+++ b/src/wgtpkg-installer.c
@@ -90,17 +90,17 @@ int main(int ac, char **av)
grant_permission_list(optarg);
break;
case ':':
- syslog(LOG_ERR, "missing argument value");
+ ERROR("missing argument value");
return 1;
default:
- syslog(LOG_ERR, "unrecognized option");
+ ERROR("unrecognized option");
return 1;
}
}
ac -= optind;
if (ac < 2) {
- syslog(LOG_ERR, "arguments are missing");
+ ERROR("arguments are missing");
return 1;
}
@@ -109,7 +109,7 @@ int main(int ac, char **av)
for (i = 0 ; av[i] != NULL ; i++) {
wpath = realpath(av[i], NULL);
if (wpath == NULL) {
- syslog(LOG_ERR, "error while getting realpath of %dth widget: %s", i+1, av[i]);
+ ERROR("error while getting realpath of %dth widget: %s", i+1, av[i]);
return 1;
}
av[i] = wpath;
diff --git a/src/wgtpkg-pack.c b/src/wgtpkg-pack.c
index 451d427..b8e49e2 100644
--- a/src/wgtpkg-pack.c
+++ b/src/wgtpkg-pack.c
@@ -97,51 +97,51 @@ int main(int ac, char **av)
usage();
return 0;
case ':':
- syslog(LOG_ERR, "missing argument");
+ ERROR("missing argument");
return 1;
default:
- syslog(LOG_ERR, "unrecognized option");
+ ERROR("unrecognized option");
return 1;
}
}
/* remaining arguments and final checks */
if (optind >= ac) {
- syslog(LOG_ERR, "no directory set");
+ ERROR("no directory set");
return 1;
}
directory = av[optind++];
if (optind < ac) {
- syslog(LOG_ERR, "extra parameters found");
+ ERROR("extra parameters found");
return 1;
}
/* set default values */
if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
- syslog(LOG_ERR, "asprintf failed");
+ ERROR("asprintf failed");
return 1;
}
/* check values */
if (stat(directory, &s)) {
- syslog(LOG_ERR, "can't find directory %s", directory);
+ ERROR("can't find directory %s", directory);
return 1;
}
if (!S_ISDIR(s.st_mode)) {
- syslog(LOG_ERR, "%s isn't a directory", directory);
+ ERROR("%s isn't a directory", directory);
return 1;
}
if (access(wgtfile, F_OK) == 0 && force == 0) {
- syslog(LOG_ERR, "can't overwrite existing %s", wgtfile);
+ ERROR("can't overwrite existing %s", wgtfile);
return 1;
}
- notice("-- PACKING widget %s from directory %s", wgtfile, directory);
+ 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) {
- syslog(LOG_ERR, "can't write widget %s", wgtfile);
+ ERROR("can't write widget %s", wgtfile);
return 1;
}
close(i);
@@ -149,7 +149,7 @@ int main(int ac, char **av)
/* compute absolutes paths */
x = realpath(wgtfile, NULL);
if (x == NULL) {
- syslog(LOG_ERR, "realpath failed for %s",wgtfile);
+ ERROR("realpath failed for %s",wgtfile);
return 1;
}
wgtfile = x;
diff --git a/src/wgtpkg-permissions.c b/src/wgtpkg-permissions.c
index e20cede..ee38988 100644
--- a/src/wgtpkg-permissions.c
+++ b/src/wgtpkg-permissions.c
@@ -20,6 +20,7 @@
#include <syslog.h>
#include <string.h>
+#include "verbose.h"
#include "wgtpkg.h"
struct permission {
@@ -103,7 +104,7 @@ void grant_permission_list(const char *list)
iter[n] = 0;
p = add_permission(iter);
if (!p) {
- syslog(LOG_ERR, "Can't allocate permission");
+ ERROR("Can't allocate permission");
exit(1);
}
p->granted = 1;
diff --git a/src/wgtpkg-sign.c b/src/wgtpkg-sign.c
index 031e1c3..be618a7 100644
--- a/src/wgtpkg-sign.c
+++ b/src/wgtpkg-sign.c
@@ -48,7 +48,7 @@ static unsigned int get_number(const char *value)
val = strtoul(value, &end, 10);
if (*end || 0 == val || val >= UINT_MAX || *value == '-') {
- syslog(LOG_ERR, "bad number value %s", value);
+ ERROR("bad number value %s", value);
exit(1);
}
return (unsigned int)val;
@@ -103,7 +103,7 @@ int main(int ac, char **av)
switch (i) {
case 'c':
if (ncert == MAXCERT) {
- syslog(LOG_ERR, "maximum count of certificates reached");
+ ERROR("maximum count of certificates reached");
return 1;
}
certfiles[ncert++] = optarg;
@@ -121,14 +121,14 @@ int main(int ac, char **av)
verbosity++;
break;
case ':':
- syslog(LOG_ERR, "missing argument");
+ ERROR("missing argument");
return 1;
default:
- syslog(LOG_ERR, "unrecognized option");
+ ERROR("unrecognized option");
return 1;
}
if (*x != NULL) {
- syslog(LOG_ERR, "option set twice");
+ ERROR("option set twice");
return 1;
}
*x = optarg;
@@ -136,12 +136,12 @@ int main(int ac, char **av)
/* remaining arguments and final checks */
if (optind >= ac) {
- syslog(LOG_ERR, "no directory set");
+ ERROR("no directory set");
return 1;
}
directory = av[optind++];
if (optind < ac) {
- syslog(LOG_ERR, "extra parameters found");
+ ERROR("extra parameters found");
return 1;
}
@@ -153,20 +153,20 @@ int main(int ac, char **av)
/* check values */
if (stat(directory, &s)) {
- syslog(LOG_ERR, "can't find directory %s", directory);
+ ERROR("can't find directory %s", directory);
return 1;
}
if (!S_ISDIR(s.st_mode)) {
- syslog(LOG_ERR, "%s isn't a directory", directory);
+ ERROR("%s isn't a directory", directory);
return 1;
}
if (access(keyfile, R_OK) != 0) {
- syslog(LOG_ERR, "can't access private key %s", keyfile);
+ ERROR("can't access private key %s", keyfile);
return 1;
}
for(i = 0 ; i < ncert ; i++)
if (access(certfiles[i], R_OK) != 0) {
- syslog(LOG_ERR, "can't access certificate %s", certfiles[i]);
+ ERROR("can't access certificate %s", certfiles[i]);
return 1;
}
@@ -176,7 +176,7 @@ int main(int ac, char **av)
/* compute absolutes paths */
-#define rp(x) do { char *p = realpath(x, NULL); if (p != NULL) x = p; else { syslog(LOG_ERR, "realpath failed for %s",x); return 1; } } while(0)
+#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]);
@@ -195,11 +195,11 @@ int main(int ac, char **av)
for (number = 1; get_signature(number) != NULL ; number++);
if (!force && get_signature(number) != NULL) {
- syslog(LOG_ERR, "can't overwrite existing signature %s", get_signature(number)->name);
+ ERROR("can't overwrite existing signature %s", get_signature(number)->name);
return 1;
}
- notice("-- SIGNING content of directory %s for number %u", directory, number);
+ 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-workdir.c b/src/wgtpkg-workdir.c
index 59da1e6..7f2c7e6 100644
--- a/src/wgtpkg-workdir.c
+++ b/src/wgtpkg-workdir.c
@@ -46,19 +46,19 @@ static int clean_dirfd(int dirfd)
dirfd = dup(dirfd);
if (dirfd < 0) {
- syslog(LOG_ERR, "failed to dup the dirfd");
+ ERROR("failed to dup the dirfd");
return -1;
}
dir = fdopendir(dirfd);
if (dir == NULL) {
- syslog(LOG_ERR, "fdopendir failed in clean_dirfd");
+ ERROR("fdopendir failed in clean_dirfd");
return -1;
}
cr = -1;
for (;;) {
if (readdir_r(dir, &entry.entry, &ent) != 0) {
- syslog(LOG_ERR, "readdir_r failed in clean_dirfd");
+ ERROR("readdir_r failed in clean_dirfd");
goto error;
}
if (ent == NULL)
@@ -70,12 +70,12 @@ static int clean_dirfd(int dirfd)
if (!cr)
continue;
if (errno != EISDIR) {
- syslog(LOG_ERR, "unlink of %s failed in clean_dirfd", ent->d_name);
+ ERROR("unlink of %s failed in clean_dirfd", ent->d_name);
goto error;
}
fd = openat(dirfd, ent->d_name, O_DIRECTORY|O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "opening directory %s failed in clean_dirfd", ent->d_name);
+ ERROR("opening directory %s failed in clean_dirfd", ent->d_name);
goto error;
}
cr = clean_dirfd(fd);
@@ -84,7 +84,7 @@ static int clean_dirfd(int dirfd)
goto error;
cr = unlinkat(dirfd, ent->d_name, AT_REMOVEDIR);
if (cr) {
- syslog(LOG_ERR, "rmdir of %s failed in clean_dirfd", ent->d_name);
+ ERROR("rmdir of %s failed in clean_dirfd", ent->d_name);
goto error;
}
}
@@ -101,7 +101,7 @@ static int clean_dir(const char *directory)
fd = openat(AT_FDCWD, directory, O_DIRECTORY|O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "opening directory %s failed in clean_dir", directory);
+ ERROR("opening directory %s failed in clean_dir", directory);
return fd;
}
rc = clean_dirfd(fd);
@@ -128,7 +128,7 @@ static int set_real_workdir(const char *name, int create)
/* check the length */
length = strlen(name);
if (length >= sizeof workdir) {
- syslog(LOG_ERR, "workdir name too long");
+ ERROR("workdir name too long");
errno = EINVAL;
return -1;
}
@@ -137,17 +137,17 @@ static int set_real_workdir(const char *name, int create)
dirfd = openat(AT_FDCWD, name, O_DIRECTORY|O_RDONLY);
if (dirfd < 0) {
if (!create || errno != ENOENT) {
- syslog(LOG_ERR, "no workdir %s", name);
+ ERROR("no workdir %s", name);
return -1;
}
rc = mkdir(name, mode);
if (rc) {
- syslog(LOG_ERR, "can't create workdir %s", name);
+ ERROR("can't create workdir %s", name);
return -1;
}
dirfd = open(name, O_PATH|O_DIRECTORY);
if (dirfd < 0) {
- syslog(LOG_ERR, "can't open workdir %s", name);
+ ERROR("can't open workdir %s", name);
return -1;
}
}
@@ -170,7 +170,7 @@ int set_workdir(const char *name, int create)
rp = realpath(name, NULL);
if (!rp) {
- syslog(LOG_ERR, "realpath failed for %s", name);
+ ERROR("realpath failed for %s", name);
return -1;
}
rc = set_real_workdir(rp, create);
@@ -184,7 +184,7 @@ static int make_real_workdir_base(const char *root, const char *prefix, int reus
n = snprintf(workdir, sizeof workdir, "%s/%s", root, prefix);
if (n >= sizeof workdir) {
- syslog(LOG_ERR, "workdir prefix too long");
+ ERROR("workdir prefix too long");
errno = EINVAL;
return -1;
}
@@ -197,19 +197,19 @@ static int make_real_workdir_base(const char *root, const char *prefix, int reus
/* create a temporary directory */
for (i = 0 ; ; i++) {
if (i == INT_MAX) {
- syslog(LOG_ERR, "exhaustion of workdirs");
+ ERROR("exhaustion of workdirs");
return -1;
}
l = snprintf(workdir + n, r, "%d", i);
if (l >= r) {
- syslog(LOG_ERR, "computed workdir too long");
+ ERROR("computed workdir too long");
errno = EINVAL;
return -1;
}
if (!mkdir(workdir, mode))
break;
if (errno != EEXIST) {
- syslog(LOG_ERR, "error in creation of workdir %s: %m", workdir);
+ ERROR("error in creation of workdir %s: %m", workdir);
return -1;
}
if (reuse)
@@ -217,7 +217,7 @@ static int make_real_workdir_base(const char *root, const char *prefix, int reus
}
workdirfd = openat(AT_FDCWD, workdir, O_RDONLY|O_DIRECTORY);
if (workdirfd < 0) {
- syslog(LOG_ERR, "error in onnection to workdir %s: %m", workdir);
+ ERROR("error in onnection to workdir %s: %m", workdir);
rmdir(workdir);
return -1;
}
@@ -235,7 +235,7 @@ int make_workdir_base(const char *root, const char *prefix, int reuse)
rp = realpath(root, NULL);
if (!rp) {
- syslog(LOG_ERR, "realpath failed for %s", root);
+ ERROR("realpath failed for %s", root);
return -1;
}
rc = make_real_workdir_base(rp, prefix, reuse);
@@ -257,7 +257,7 @@ static int move_real_workdir(const char *dest, int parents, int force)
/* check length */
if (strlen(dest) >= sizeof workdir) {
- syslog(LOG_ERR, "destination dirname too long");
+ ERROR("destination dirname too long");
errno = EINVAL;
return -1;
}
@@ -266,23 +266,23 @@ static int move_real_workdir(const char *dest, int parents, int force)
rc = stat(dest, &s);
if (rc == 0) {
if (!S_ISDIR(s.st_mode)) {
- syslog(LOG_ERR, "in move_real_workdir, can't overwrite regular file %s", dest);
+ ERROR("in move_real_workdir, can't overwrite regular file %s", dest);
errno = EEXIST;
return -1;
}
if (!force) {
- syslog(LOG_ERR, "in move_real_workdir, can't overwrite regular file %s", dest);
+ ERROR("in move_real_workdir, can't overwrite regular file %s", dest);
errno = EEXIST;
return -1;
}
rc = clean_dir(dest);
if (rc) {
- syslog(LOG_ERR, "in move_real_workdir, can't clean dir %s", dest);
+ ERROR("in move_real_workdir, can't clean dir %s", dest);
return rc;
}
rc = rmdir(dest);
if (rc) {
- syslog(LOG_ERR, "in move_real_workdir, can't remove dir %s", dest);
+ ERROR("in move_real_workdir, can't remove dir %s", dest);
return rc;
}
} else {
@@ -296,13 +296,13 @@ static int move_real_workdir(const char *dest, int parents, int force)
if (!rc) {
/* found an entry */
if (!S_ISDIR(s.st_mode)) {
- syslog(LOG_ERR, "in move_real_workdir, '%s' isn't a directory", copy);
+ ERROR("in move_real_workdir, '%s' isn't a directory", copy);
errno = ENOTDIR;
return -1;
}
} else if (!parents) {
/* parent entry not found but not allowed to create it */
- syslog(LOG_ERR, "in move_real_workdir, parent directory '%s' not found: %m", copy);
+ ERROR("in move_real_workdir, parent directory '%s' not found: %m", copy);
return -1;
} else {
/* parent entries to be created */
@@ -313,13 +313,13 @@ static int move_real_workdir(const char *dest, int parents, int force)
if (!rc)
break;
if (errno != ENOENT) {
- syslog(LOG_ERR, "in move_real_workdir, mkdir '%s' failed: %m", copy);
+ ERROR("in move_real_workdir, mkdir '%s' failed: %m", copy);
return -1;
}
while (l && copy[l] != '/')
l--;
if (l == 0) {
- syslog(LOG_ERR, "in move_real_workdir, internal error");
+ ERROR("in move_real_workdir, internal error");
errno = EINVAL;
return -1;
}
@@ -331,7 +331,7 @@ static int move_real_workdir(const char *dest, int parents, int force)
while (copy[++l]);
rc = mkdir(copy, mode);
if (rc && errno != EEXIST) {
- syslog(LOG_ERR, "in move_real_workdir, mkdir '%s' failed: %m", copy);
+ ERROR("in move_real_workdir, mkdir '%s' failed: %m", copy);
return -1;
}
}
@@ -344,7 +344,7 @@ static int move_real_workdir(const char *dest, int parents, int force)
workdirfd = -1;
rc = renameat(AT_FDCWD, workdir, AT_FDCWD, dest);
if (rc) {
- syslog(LOG_ERR, "in move_real_workdir, renameat failed %s -> %s: %m", workdir, dest);
+ ERROR("in move_real_workdir, renameat failed %s -> %s: %m", workdir, dest);
return -1;
}
@@ -361,7 +361,7 @@ int move_workdir(const char *dest, int parents, int force)
rp = realpath(dest, NULL);
if (!rp) {
- syslog(LOG_ERR, "realpath failed for %s", dest);
+ ERROR("realpath failed for %s", dest);
return -1;
}
rc = move_real_workdir(rp, parents, force);
diff --git a/src/wgtpkg-xmlsec.c b/src/wgtpkg-xmlsec.c
index 746ccc0..6b6302e 100644
--- a/src/wgtpkg-xmlsec.c
+++ b/src/wgtpkg-xmlsec.c
@@ -33,6 +33,7 @@
#include <xmlsec/io.h>
+#include "verbose.h"
#include "wgtpkg.h"
static int initstatus;
@@ -59,14 +60,14 @@ static void *file_open_cb(const char *file)
fdesc = file_of_name(file);
if (fdesc == NULL) {
- syslog(LOG_ERR, "shouldn't open uri %s", file);
+ ERROR("shouldn't open uri %s", file);
return NULL;
}
fd = openat(workdirfd, file, O_RDONLY);
f = fd < 0 ? NULL : fdopen(fd, "r");
if (f == NULL) {
- syslog(LOG_ERR, "can't open file %s for reading", file);
+ ERROR("can't open file %s for reading", file);
if (fd >= 0)
close(fd);
} else
@@ -91,7 +92,7 @@ static int file_close_cb(void *context)
/* echo an error message */
static void errors_cb(const char *file, int line, const char *func, const char *errorObject, const char *errorSubject, int reason, const char *msg)
{
- syslog(LOG_ERR, "xmlSec error %3d: %s (subject=\"%s\", object=\"%s\")", reason, msg, errorSubject ? errorSubject : "?", errorObject ? errorObject : "?");
+ ERROR("xmlSec error %3d: %s (subject=\"%s\", object=\"%s\")", reason, msg, errorSubject ? errorSubject : "?", errorObject ? errorObject : "?");
}
/* fills database with trusted keys */
@@ -99,7 +100,7 @@ static int fill_trusted_keys_file(const char *file)
{
int err = xmlSecCryptoAppKeysMngrCertLoad(keymgr, file, xmlSecKeyDataFormatPem, xmlSecKeyDataTypeTrusted);
if (err < 0) {
- syslog(LOG_ERR, "xmlSecCryptoAppKeysMngrCertLoadMemory failed for %s", file);
+ ERROR("xmlSecCryptoAppKeysMngrCertLoadMemory failed for %s", file);
return -1;
}
return 0;
@@ -116,7 +117,7 @@ static int fill_trusted_keys_dir(const char *directory)
e = stpcpy(path, directory);
dir = opendir(path);
if (!dir) {
- syslog(LOG_ERR, "opendir %s failed in fill_trusted_keys_dir", path);
+ ERROR("opendir %s failed in fill_trusted_keys_dir", path);
return -1;
}
@@ -150,24 +151,24 @@ int xmlsec_init()
initstatus = -1;
if(xmlSecInit() < 0) {
- syslog(LOG_ERR, "xmlSecInit failed.");
+ ERROR("xmlSecInit failed.");
goto end;
}
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if(xmlSecCryptoDLLoadLibrary(XMLSEC_CRYPTO) < 0) {
- syslog(LOG_ERR, "xmlSecCryptoDLLoadLibrary %s failed.", XMLSEC_CRYPTO);
+ ERROR("xmlSecCryptoDLLoadLibrary %s failed.", XMLSEC_CRYPTO);
goto end;
}
#endif
if(xmlSecCryptoAppInit(NULL) < 0) {
- syslog(LOG_ERR, "xmlSecCryptoAppInit failed.");
+ ERROR("xmlSecCryptoAppInit failed.");
goto end;
}
if(xmlSecCryptoInit() < 0) {
- syslog(LOG_ERR, "xmlSecCryptoInit failed.");
+ ERROR("xmlSecCryptoInit failed.");
goto end;
}
@@ -176,18 +177,18 @@ int xmlsec_init()
xmlSecIOCleanupCallbacks();
if (xmlSecIORegisterCallbacks(file_match_cb,
file_open_cb, file_read_cb, file_close_cb)) {
- syslog(LOG_ERR, "xmlSecIORegisterCallbacks failed.");
+ ERROR("xmlSecIORegisterCallbacks failed.");
goto end;
}
keymgr = xmlSecKeysMngrCreate();
if (keymgr == NULL) {
- syslog(LOG_ERR, "xmlSecKeysMngrCreate failed.");
+ ERROR("xmlSecKeysMngrCreate failed.");
goto end;
}
if(xmlSecCryptoAppDefaultKeysMngrInit(keymgr) < 0) {
- syslog(LOG_ERR, "xmlSecCryptoAppDefaultKeysMngrInit failed.");
+ ERROR("xmlSecCryptoAppDefaultKeysMngrInit failed.");
goto end;
}
fill_trusted_keys_dir(CA_ROOT_DIRECTORY);
@@ -219,14 +220,14 @@ int xmlsec_verify(xmlNodePtr node)
dsigctx = xmlSecDSigCtxCreate(keymgr);
if (dsigctx == NULL) {
- syslog(LOG_ERR, "xmlSecDSigCtxCreate failed.");
+ ERROR("xmlSecDSigCtxCreate failed.");
rc = -1;
} else {
rc = xmlSecDSigCtxVerify(dsigctx, node);
if (rc)
- syslog(LOG_ERR, "xmlSecDSigCtxVerify failed.");
+ ERROR("xmlSecDSigCtxVerify failed.");
else if (dsigctx->status != xmlSecDSigStatusSucceeded) {
- syslog(LOG_ERR, "invalid signature.");
+ ERROR("invalid signature.");
rc = -1;
}
xmlSecDSigCtxDestroy(dsigctx);
@@ -286,14 +287,14 @@ xmlDocPtr xmlsec_create(int index, const char *key, const char **certs)
/* create the document */
doc = xmlNewDoc("1.0");
if (doc == NULL) {
- syslog(LOG_ERR, "xmlNewDoc failed");
+ ERROR("xmlNewDoc failed");
goto error;
}
/* create the root signature node */
sign = xmlSecTmplSignatureCreate(doc, xmlSecTransformInclC14N11Id, xmlSecTransformRsaSha256Id, properties[!!index].id);
if (sign == NULL) {
- syslog(LOG_ERR, "xmlSecTmplSignatureCreate failed");
+ ERROR("xmlSecTmplSignatureCreate failed");
goto error2;
}
xmlDocSetRootElement(doc, sign);
@@ -301,16 +302,16 @@ xmlDocPtr xmlsec_create(int index, const char *key, const char **certs)
/* create the object and its reference */
obj = xmlSecTmplSignatureAddObject(sign, "prop", NULL, NULL);
if (obj == NULL) {
- syslog(LOG_ERR, "xmlSecTmplSignatureAddObject failed");
+ ERROR("xmlSecTmplSignatureAddObject failed");
goto error2;
}
rc = xmlParseBalancedChunkMemory(doc, NULL, NULL, 0, properties[!!index].xml, &props);
if (rc) {
- syslog(LOG_ERR, "xmlParseBalancedChunkMemory failed");
+ ERROR("xmlParseBalancedChunkMemory failed");
goto error2;
}
if (NULL == xmlAddChild(obj, props)) {
- syslog(LOG_ERR, "filling object node failed");
+ ERROR("filling object node failed");
xmlFreeNode(obj);
goto error2;
}
@@ -323,7 +324,7 @@ xmlDocPtr xmlsec_create(int index, const char *key, const char **certs)
if (fdesc->type == type_file && (fdesc->flags & mask) == 0) {
ref = xmlSecTmplSignatureAddReference(sign, xmlSecTransformSha256Id, NULL, fdesc->name, NULL);
if (ref == NULL) {
- syslog(LOG_ERR, "creation of reference to %s failed", fdesc->name);
+ ERROR("creation of reference to %s failed", fdesc->name);
goto error2;
}
}
@@ -332,45 +333,45 @@ xmlDocPtr xmlsec_create(int index, const char *key, const char **certs)
/* create reference to object having properties */
ref = xmlSecTmplSignatureAddReference(sign, xmlSecTransformSha256Id, NULL, "#prop", NULL);
if (ref == NULL) {
- syslog(LOG_ERR, "creation of reference to #prop failed");
+ ERROR("creation of reference to #prop failed");
goto error2;
}
if (NULL == xmlSecTmplReferenceAddTransform(ref, xmlSecTransformInclC14N11Id)) {
- syslog(LOG_ERR, "setting transform reference to #prop failed");
+ ERROR("setting transform reference to #prop failed");
goto error2;
}
/* adds the X509 data */
kinfo = xmlSecTmplSignatureEnsureKeyInfo(sign, NULL);
if (kinfo == NULL) {
- syslog(LOG_ERR, "xmlSecTmplSignatureEnsureKeyInfo failed");
+ ERROR("xmlSecTmplSignatureEnsureKeyInfo failed");
goto error2;
}
if (NULL == xmlSecTmplKeyInfoAddX509Data(kinfo)) {
- syslog(LOG_ERR, "xmlSecTmplKeyInfoAddX509Data failed");
+ ERROR("xmlSecTmplKeyInfoAddX509Data failed");
goto error2;
}
/* sign now */
dsigctx = xmlSecDSigCtxCreate(keymgr);
if (dsigctx == NULL) {
- syslog(LOG_ERR, "xmlSecDSigCtxCreate failed.");
+ ERROR("xmlSecDSigCtxCreate failed.");
goto error3;
}
dsigctx->signKey = xmlSecCryptoAppKeyLoad(key, xmlSecKeyDataFormatPem, NULL, NULL, NULL);
if (dsigctx->signKey == NULL) {
- syslog(LOG_ERR, "loading key %s failed.", key);
+ ERROR("loading key %s failed.", key);
goto error3;
}
while (*certs) {
if(xmlSecCryptoAppKeyCertLoad(dsigctx->signKey, *certs, xmlSecKeyDataFormatPem) < 0) {
- syslog(LOG_ERR, "loading certificate %s failed.", *certs);
+ ERROR("loading certificate %s failed.", *certs);
goto error3;
}
certs++;
}
if(xmlSecDSigCtxSign(dsigctx, sign) < 0) {
- syslog(LOG_ERR, "signing the document failed.");
+ ERROR("signing the document failed.");
goto error3;
}
xmlSecDSigCtxDestroy(dsigctx);
diff --git a/src/wgtpkg-zip.c b/src/wgtpkg-zip.c
index 8ad00bb..8234bae 100644
--- a/src/wgtpkg-zip.c
+++ b/src/wgtpkg-zip.c
@@ -28,6 +28,7 @@
#include <syslog.h>
#include <unistd.h>
+#include "verbose.h"
#include "wgtpkg.h"
@@ -76,7 +77,7 @@ static int create_directory(char *file, int mode)
}
}
if (rc)
- syslog(LOG_ERR, "can't create directory %s", file);
+ ERROR("can't create directory %s", file);
if (last != NULL)
*last = '/';
return rc;
@@ -90,7 +91,7 @@ static int create_file(char *file, int fmode, int dmode)
fd = openat(workdirfd, file, O_CREAT|O_WRONLY|O_TRUNC, fmode);
}
if (fd < 0)
- syslog(LOG_ERR, "can't create file %s", file);
+ ERROR("can't create file %s", file);
return fd;
}
@@ -111,13 +112,13 @@ int zread(const char *zipfile, unsigned long long maxsize)
/* open the zip file */
zip = zip_open(zipfile, ZIP_CHECKCONS, &err);
if (!zip) {
- syslog(LOG_ERR, "Can't connect to file %s", zipfile);
+ ERROR("Can't connect to file %s", zipfile);
return -1;
}
z64 = zip_get_num_entries(zip, 0);
if (z64 < 0 || z64 > UINT_MAX) {
- syslog(LOG_ERR, "too many entries in %s", zipfile);
+ ERROR("too many entries in %s", zipfile);
goto error;
}
count = (unsigned int)z64;
@@ -129,22 +130,22 @@ int zread(const char *zipfile, unsigned long long maxsize)
err = zip_stat_index(zip, index, ZIP_FL_ENC_GUESS, &zstat);
/* check the file name */
if (!is_valid_filename(zstat.name)) {
- syslog(LOG_ERR, "invalid entry %s found in %s", zstat.name, zipfile);
+ ERROR("invalid entry %s found in %s", zstat.name, zipfile);
goto error;
}
if (zstat.name[0] == '/') {
- syslog(LOG_ERR, "absolute entry %s found in %s", zstat.name, zipfile);
+ ERROR("absolute entry %s found in %s", zstat.name, zipfile);
goto error;
}
len = strlen(zstat.name);
if (len == 0) {
- syslog(LOG_ERR, "empty entry found in %s", zipfile);
+ ERROR("empty entry found in %s", zipfile);
goto error;
}
if (zstat.size == 0) {
/* directory name */
if (zstat.name[len - 1] != '/') {
- syslog(LOG_ERR, "bad directory name %s in %s", zstat.name, zipfile);
+ ERROR("bad directory name %s in %s", zstat.name, zipfile);
goto error;
}
/* record */
@@ -152,7 +153,7 @@ int zread(const char *zipfile, unsigned long long maxsize)
} else {
/* directory name */
if (zstat.name[len - 1] == '/') {
- syslog(LOG_ERR, "bad file name %s in %s", zstat.name, zipfile);
+ ERROR("bad file name %s in %s", zstat.name, zipfile);
goto error;
}
/* get the size */
@@ -167,7 +168,7 @@ int zread(const char *zipfile, unsigned long long maxsize)
/* check the size */
if (maxsize && esize > maxsize) {
- syslog(LOG_ERR, "extracted size %zu greater than allowed size %llu", esize, maxsize);
+ ERROR("extracted size %zu greater than allowed size %llu", esize, maxsize);
goto error;
}
@@ -187,7 +188,7 @@ int zread(const char *zipfile, unsigned long long maxsize)
/* file name */
zfile = zip_fopen_index(zip, fdesc->zindex, 0);
if (!zfile) {
- syslog(LOG_ERR, "Can't open %s in %s", zstat.name, zipfile);
+ ERROR("Can't open %s in %s", zstat.name, zipfile);
goto error;
}
fd = create_file((char*)zstat.name, MODE_OF_FILE_CREATION, MODE_OF_DIRECTORY_CREATION);
@@ -198,12 +199,12 @@ int zread(const char *zipfile, unsigned long long maxsize)
while (z64) {
sizr = zip_fread(zfile, buffer, sizeof buffer);
if (sizr < 0) {
- syslog(LOG_ERR, "error while reading %s in %s", zstat.name, zipfile);
+ ERROR("error while reading %s in %s", zstat.name, zipfile);
goto errorzf;
}
sizw = write(fd, buffer, sizr);
if (sizw < 0) {
- syslog(LOG_ERR, "error while writing %s", zstat.name);
+ ERROR("error while writing %s", zstat.name);
goto errorzf;
}
z64 -= sizw;
@@ -242,13 +243,13 @@ static int zwr(struct zws *zws, int offset)
fd = openat(workdirfd, offset ? zws->name : ".", O_DIRECTORY|O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "opendir %.*s failed in zwr", offset, zws->name);
+ ERROR("opendir %.*s failed in zwr", offset, zws->name);
return -1;
}
dir = fdopendir(fd);
if (!dir) {
close(fd);
- syslog(LOG_ERR, "opendir %.*s failed in zwr", offset, zws->name);
+ ERROR("opendir %.*s failed in zwr", offset, zws->name);
return -1;
}
@@ -262,20 +263,20 @@ static int zwr(struct zws *zws, int offset)
(ent->d_name[1] == '.' && len == 2)))
;
else if (offset + len >= sizeof(zws->name)) {
- syslog(LOG_ERR, "name too long in zwr");
+ ERROR("name too long in zwr");
errno = ENAMETOOLONG;
goto error;
} else {
memcpy(zws->name + offset, ent->d_name, 1+len);
if (!is_valid_filename(ent->d_name)) {
- syslog(LOG_ERR, "invalid name %s", zws->name);
+ ERROR("invalid name %s", zws->name);
goto error;
}
switch (ent->d_type) {
case DT_DIR:
z64 = zip_dir_add(zws->zip, zws->name, ZIP_FL_ENC_UTF_8);
if (z64 < 0) {
- syslog(LOG_ERR, "zip_dir_add of %s failed", zws->name);
+ ERROR("zip_dir_add of %s failed", zws->name);
goto error;
}
err = zwr(zws, offset + len);
@@ -285,24 +286,24 @@ static int zwr(struct zws *zws, int offset)
case DT_REG:
fd = openat(workdirfd, zws->name, O_RDONLY);
if (fd < 0) {
- syslog(LOG_ERR, "openat of %s failed", zws->name);
+ ERROR("openat of %s failed", zws->name);
goto error;
}
fp = fdopen(fd, "r");
if (fp == NULL) {
- syslog(LOG_ERR, "fdopen of %s failed", zws->name);
+ ERROR("fdopen of %s failed", zws->name);
close(fd);
goto error;
}
zsrc = zip_source_filep(zws->zip, fp, 0, 0);
if (zsrc == NULL) {
- syslog(LOG_ERR, "zip_source_file of %s failed", zws->name);
+ ERROR("zip_source_file of %s failed", zws->name);
fclose(fp);
goto error;
}
z64 = zip_file_add(zws->zip, zws->name, zsrc, ZIP_FL_ENC_UTF_8);
if (z64 < 0) {
- syslog(LOG_ERR, "zip_file_add of %s failed", zws->name);
+ ERROR("zip_file_add of %s failed", zws->name);
zip_source_free(zsrc);
goto error;
}
@@ -329,7 +330,7 @@ int zwrite(const char *zipfile)
zws.zip = zip_open(zipfile, ZIP_CREATE|ZIP_TRUNCATE, &err);
if (!zws.zip) {
- syslog(LOG_ERR, "Can't open %s for write", zipfile);
+ ERROR("Can't open %s for write", zipfile);
return -1;
}