tAdd pack checking with sick(1) - repo - list/download/sync packs with remote repositories
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit ec303804d9ff0363169e863506238d7096f45bfb
(DIR) parent 81dc1063bc4d2c14ed10f5f2c8b2aec3392391dd
(HTM) Author: z3bra <contactatz3bradotorg>
Date: Thu, 4 May 2017 13:30:41 +0200
Add pack checking with sick(1)
Packs downloaded will now be checked against the local keyring using
sick[0]. Packs won't be written on disk if the signature does not
match any of the private key in the KEYRING (check sick(1) for more
informations)
t[0] http://z3bra.org/sick
Diffstat:
M repo.c | 87 +++++++++++++++++++++++--------
1 file changed, 65 insertions(+), 22 deletions(-)
---
(DIR) diff --git a/repo.c b/repo.c
t@@ -1,4 +1,5 @@
#include <errno.h>
+#include <fcntl.h>
#include <libgen.h>
#include <limits.h>
#include <stdio.h>
t@@ -7,6 +8,7 @@
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#include <curl/curl.h>
t@@ -16,8 +18,12 @@
void usage(char *);
int download(char *, FILE *);
+int cachepack(char *, char *, struct packs *);
int verbose = 0;
+int fflag, lflag, sflag;
+
+char *sickexec[] = { "sick", "-a", NULL };
void
usage(char *name)
t@@ -137,9 +143,64 @@ download(char *url, FILE *fd)
}
int
+cachepack(char *name, char *localrepo, struct packs *plist)
+{
+ FILE *pip;
+ int fd[2], fil, status;
+ char fn[PATH_MAX];;
+ struct pack *p = NULL;
+ struct stat sb;
+
+ TAILQ_FOREACH(p, plist, entries) {
+ if (!strncmp(p->name, name, PATH_MAX)) {
+ snprintf(fn, PATH_MAX, "%s/%s", localrepo, basename(p->url));
+ if (!stat(fn, &sb) && !fflag) {
+ puts(fn);
+ continue;
+ }
+
+ pipe(fd);
+ if (!fork()) {
+ close(0);
+ close(1);
+ close(fd[1]);
+ dup2(fd[0], 0);
+
+ if ((fil = open(fn, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
+ perror(fn);
+ return -1;
+ }
+ dup2(fil, 1);
+ execvp(sickexec[0], sickexec);
+ perror(sickexec[0]);
+ }
+
+ close(fd[0]);
+ pip = fdopen(fd[1], "a");
+ if (!pip) {
+ perror("pipe");
+ exit(1);
+ }
+ download(p->url, pip);
+ fflush(pip);
+ fclose(pip);
+
+ wait(&status);
+ if (status) {
+ fprintf(stderr, "%s: Pack verification failed\n", basename(fn));
+ unlink(fn);
+ continue;
+ }
+ puts(fn);
+ break;
+ }
+ }
+ return 0;
+}
+
+int
main (int argc, char *argv[])
{
- int fflag, lflag, sflag;
char *argv0, *n;
char cfgfile[PATH_MAX] = DEFCFGFILE;
char localrepo[PATH_MAX] = DEFLOCALREPO;
t@@ -205,26 +266,8 @@ main (int argc, char *argv[])
return 0;
}
- while ((n = *(argv++))) {
- TAILQ_FOREACH(p, &plist, entries) {
- if (!strncmp(p->name, n, PATH_MAX)) {
- snprintf(fn, PATH_MAX, "%s/%s", localrepo, basename(p->url));
- if (!stat(fn, &sb) && !fflag) {
- puts(fn);
- continue;
- }
-
- fd = fopen(fn, "w");
- if (!fd) {
- perror(fn);
- exit(1);
- }
- download(p->url, fd);
- fclose(fd);
- puts(fn);
- break;
- }
- }
- }
+ while ((n = *(argv++)))
+ cachepack(n, localrepo, &plist);
+
return 0;
}