9 #include "repo_pubkey.h"
17 cleanupgpg(char *gpgdir)
20 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg", gpgdir);
22 snprintf(cmd, sizeof(cmd), "%s/pubring.gpg~", gpgdir);
24 snprintf(cmd, sizeof(cmd), "%s/secring.gpg", gpgdir);
26 snprintf(cmd, sizeof(cmd), "%s/trustdb.gpg", gpgdir);
28 snprintf(cmd, sizeof(cmd), "%s/keys", gpgdir);
34 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
43 off_t posfp, possigfp;
46 gpgdir = mkdtemp(pool_tmpjoin(sigpool, "/var/tmp/solvgpg.XXXXXX", 0, 0));
49 keysfile = pool_tmpjoin(sigpool, gpgdir, "/keys", 0);
50 if (!(kfp = fopen(keysfile, "w")) )
56 for (p = 1, s = sigpool->solvables + p; p < sigpool->nsolvables; p++, s++)
60 pubkey = solvable_lookup_str(s, SOLVABLE_DESCRIPTION);
61 if (!pubkey || !*pubkey)
63 if (fwrite(pubkey, strlen(pubkey), 1, kfp) != 1)
65 if (fputc('\n', kfp) == EOF) /* Just in case... */
69 if (fclose(kfp) || !nkeys || p < sigpool->nsolvables)
74 snprintf(cmd, sizeof(cmd), "gpg2 -q --homedir %s --import %s", gpgdir, keysfile);
77 fprintf(stderr, "key import error\n");
82 posfp = lseek(fileno(fp), 0, SEEK_CUR);
83 lseek(fileno(fp), 0, SEEK_SET);
84 possigfp = lseek(fileno(sigfp), 0, SEEK_CUR);
85 lseek(fileno(sigfp), 0, SEEK_SET);
86 snprintf(cmd, sizeof(cmd), "gpgv -q --homedir %s --keyring %s/pubring.gpg /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", gpgdir, gpgdir, fileno(sigfp), fileno(fp));
87 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
88 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
90 lseek(fileno(sigfp), possigfp, SEEK_SET);
91 lseek(fileno(fp), posfp, SEEK_SET);
92 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
93 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
95 return r == 0 ? 1 : 0;
101 checksig(Pool *sigpool, FILE *fp, FILE *sigfp)
106 snprintf(cmd, sizeof(cmd), "gpgv -q --keyring /etc/apt/trusted.gpg /dev/fd/%d /dev/fd/%d >/dev/null 2>&1", fileno(sigfp), fileno(fp));
107 fcntl(fileno(fp), F_SETFD, 0); /* clear CLOEXEC */
108 fcntl(fileno(sigfp), F_SETFD, 0); /* clear CLOEXEC */
110 fcntl(fileno(fp), F_SETFD, FD_CLOEXEC);
111 fcntl(fileno(sigfp), F_SETFD, FD_CLOEXEC);
112 return r == 0 ? 1 : 0;
120 Pool *sigpool = pool_create();
121 #if defined(ENABLE_PUBKEY) && defined(ENABLE_RPMDB)
122 Repo *repo = repo_create(sigpool, "pubkeys");
123 repo_add_rpmdb_pubkeys(repo, 0);