#############################################################################*/
#include <errno.h>
+#include <fts.h>
#include <gpgme.h>
return 0;
}
+static int pakfire_keystore_import(struct pakfire* pakfire, gpgme_ctx_t ctx) {
+ char path[PATH_MAX];
+
+ // Make path
+ int r = pakfire_make_path(pakfire, path, "/etc/pakfire/trusted.keys.d");
+ if (r < 0)
+ return r;
+
+ DEBUG(pakfire, "Loading keys from %s\n", path);
+
+ char* paths[] = {
+ path, NULL,
+ };
+
+ FTS* fts = fts_open(paths, FTS_NOCHDIR|FTS_NOSTAT, NULL);
+ if (!fts)
+ goto ERROR;
+
+ for (;;) {
+ FTSENT* fent = fts_read(fts);
+ if (!fent)
+ break;
+
+ // Only handle files
+ if (fent->fts_info == FTS_F) {
+ FILE* f = fopen(fent->fts_path, "r");
+ if (!f) {
+ ERROR(pakfire, "Could not open %s: %m\n", fent->fts_path);
+ continue;
+ }
+
+ // Import keys from file
+ r = pakfire_key_import(pakfire, f, NULL);
+ fclose(f);
+
+ // End if key import was unsuccessful
+ if (r)
+ break;
+ }
+ }
+
+ERROR:
+ if (fts)
+ fts_close(fts);
+
+ return r;
+}
+
int pakfire_keystore_init(struct pakfire* pakfire, gpgme_ctx_t* ctx) {
char path[PATH_MAX] = PAKFIRE_CACHE_PATH "/tmp/pakfire-keystore.XXXXXX";
char* tmp = NULL;
DEBUG(pakfire, "GPGME engine info: %s, path = %s\n",
engine_info->file_name, engine_info->home_dir);
+ // Import keys
+ r = pakfire_keystore_import(pakfire, *ctx);
+ if (r) {
+ ERROR(pakfire, "Could not import keys: %m\n");
+ goto ERROR;
+ }
+
// Success
r = 0;