Code Review
/
src
/
app-framework-main.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Rework on parsing units conf
[src/app-framework-main.git]
/
src
/
wgtpkg-sign.c
diff --git
a/src/wgtpkg-sign.c
b/src/wgtpkg-sign.c
index
031e1c3
..
68f3d5c
100644
(file)
--- a/
src/wgtpkg-sign.c
+++ b/
src/wgtpkg-sign.c
@@
-1,5
+1,7
@@
/*
/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016, 2017 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@
-21,13
+23,17
@@
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
-#include <syslog.h>
#include <getopt.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <libxml/tree.h>
+
#include "verbose.h"
#include "verbose.h"
-#include "wgtpkg.h"
+#include "wgtpkg-files.h"
+#include "wgtpkg-workdir.h"
+#include "wgtpkg-digsig.h"
+#include "wgtpkg-xmlsec.h"
#if !defined(MAXCERT)
#define MAXCERT 20
#if !defined(MAXCERT)
#define MAXCERT 20
@@
-48,7
+54,7
@@
static unsigned int get_number(const char *value)
val = strtoul(value, &end, 10);
if (*end || 0 == val || val >= UINT_MAX || *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;
exit(1);
}
return (unsigned int)val;
@@
-57,7
+63,7
@@
static unsigned int get_number(const char *value)
static void usage()
{
printf(
static void usage()
{
printf(
- "usage: %s [-f] [-k keyfile] [-c certfile]... [-
o wgtfile] [-
d number | -a] directory\n"
+ "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"
"\n"
" -k keyfile the private key to use for author signing\n"
" -c certfile the certificate(s) to use for author signing\n"
@@
-91,7
+97,7
@@
int main(int ac, char **av)
char *keyfile, *certfiles[MAXCERT+1], *directory, **x;
struct stat s;
char *keyfile, *certfiles[MAXCERT+1], *directory, **x;
struct stat s;
-
openlog(appname, LOG_PERROR, LOG_USER
);
+
LOGUSER(appname
);
force = ncert = author = 0;
number = UINT_MAX;
force = ncert = author = 0;
number = UINT_MAX;
@@
-103,7
+109,7
@@
int main(int ac, char **av)
switch (i) {
case 'c':
if (ncert == MAXCERT) {
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;
return 1;
}
certfiles[ncert++] = optarg;
@@
-121,14
+127,14
@@
int main(int ac, char **av)
verbosity++;
break;
case ':':
verbosity++;
break;
case ':':
-
syslog(LOG_ERR,
"missing argument");
+
ERROR(
"missing argument");
return 1;
default:
return 1;
default:
-
syslog(LOG_ERR,
"unrecognized option");
+
ERROR(
"unrecognized option");
return 1;
}
if (*x != NULL) {
return 1;
}
if (*x != NULL) {
-
syslog(LOG_ERR,
"option set twice");
+
ERROR(
"option set twice");
return 1;
}
*x = optarg;
return 1;
}
*x = optarg;
@@
-136,12
+142,12
@@
int main(int ac, char **av)
/* remaining arguments and final checks */
if (optind >= ac) {
/* 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) {
return 1;
}
directory = av[optind++];
if (optind < ac) {
-
syslog(LOG_ERR,
"extra parameters found");
+
ERROR(
"extra parameters found");
return 1;
}
return 1;
}
@@
-153,20
+159,20
@@
int main(int ac, char **av)
/* check values */
if (stat(directory, &s)) {
/* 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)) {
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) {
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) {
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;
}
return 1;
}
@@
-176,7
+182,7
@@
int main(int ac, char **av)
/* compute absolutes paths */
/* 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]);
rp(keyfile);
for(i = 0 ; i < ncert ; i++)
rp(certfiles[i]);
@@
-195,11
+201,11
@@
int main(int ac, char **av)
for (number = 1; get_signature(number) != NULL ; number++);
if (!force && get_signature(number) != NULL) {
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;
}
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);
certfiles[ncert] = NULL;
return !!create_digsig(number, keyfile, (const char**)certfiles);