]> the.earth.li Git - onak.git/blobdiff - keydb_hkp.c
Cleanup postinst to avoid recursive chown of database
[onak.git] / keydb_hkp.c
index 0c6fd5a97f97f7eb50eecbe5a8d564430d3150e3..79d5c4b302e30d433a63664092fedba9895b2bc4 100644 (file)
  * more details.
  *
  * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <inttypes.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <curl/curl.h>
 
+#include "build-config.h"
+
 #include "armor.h"
 #include "charfuncs.h"
 #include "keydb.h"
 #include "mem.h"
 #include "onak-conf.h"
 #include "parsekey.h"
-#include "version.h"
 
 struct onak_hkp_dbctx {
+       struct onak_db_config *config; /* Our DB config info */
        CURL *curl;
-       char hkpbase[1024];
+       char hkpbase[512];
 };
 
 static int hkp_parse_url(struct onak_hkp_dbctx *privctx, const char *url)
@@ -48,11 +50,11 @@ static int hkp_parse_url(struct onak_hkp_dbctx *privctx, const char *url)
        proto[0] = host[0] = 0;
        port = 0;
 
-       matched = sscanf(url, "%5[a-z]://%256[a-zA-Z0-9.]:%u", proto, host,
+       matched = sscanf(url, "%5[a-z]://%256[a-zA-Z0-9.-]:%u", proto, host,
                        &port);
        if (matched < 2) {
                proto[0] = 0;
-               sscanf(url, "%256[a-zA-Z0-9.]:%u", host, &port);
+               sscanf(url, "%256[a-zA-Z0-9.-]:%u", host, &port);
        }
 
        if (host[0] == 0) {
@@ -269,13 +271,13 @@ static int hkp_store_key(struct onak_dbctx *dbctx,
 
 /**
  *     delete_key - Given a keyid delete the key from storage.
- *     @keyid: The keyid to delete.
+ *     @fp: The fingerprint of the key to delete.
  *     @intrans: If we're already in a transaction.
  *
  *     No op for HKP.
  */
 static int hkp_delete_key(struct onak_dbctx *dbctx,
-               uint64_t keyid, bool intrans)
+               struct openpgp_fingerprint *fp, bool intrans)
 {
        return -1;
 }
@@ -319,7 +321,6 @@ static void hkp_endtrans(struct onak_dbctx *dbctx)
  */
 #define NEED_KEYID2UID 1
 #define NEED_GETKEYSIGS 1
-#define NEED_GETFULLKEYID 1
 #define NEED_UPDATEKEYS 1
 #include "keydb.c"
 
@@ -346,7 +347,7 @@ static void hkp_cleanupdb(struct onak_dbctx *dbctx)
  *
  *     We initialize CURL here.
  */
-struct onak_dbctx *keydb_hkp_init(bool readonly)
+struct onak_dbctx *keydb_hkp_init(struct onak_db_config *dbcfg, bool readonly)
 {
        struct onak_dbctx *dbctx;
        struct onak_hkp_dbctx *privctx;
@@ -357,6 +358,7 @@ struct onak_dbctx *keydb_hkp_init(bool readonly)
                return NULL;
        }
 
+       dbctx->config = dbcfg;
        dbctx->priv = privctx = malloc(sizeof(*privctx));
        dbctx->cleanupdb                = hkp_cleanupdb;
        dbctx->starttrans               = hkp_starttrans;
@@ -370,12 +372,13 @@ struct onak_dbctx *keydb_hkp_init(bool readonly)
        dbctx->getkeysigs               = generic_getkeysigs;
        dbctx->cached_getkeysigs        = generic_cached_getkeysigs;
        dbctx->keyid2uid                = generic_keyid2uid;
-       dbctx->getfullkeyid             = generic_getfullkeyid;
        dbctx->iterate_keys             = hkp_iterate_keys;
 
-       if (!hkp_parse_url(privctx, config.db_dir)) {
+       if (!hkp_parse_url(privctx, dbcfg->location)) {
                exit(EXIT_FAILURE);
        }
+       logthing(LOGTHING_INFO, "Using %s as HKP forwarding URL.",
+               privctx->hkpbase);
        curl_global_init(CURL_GLOBAL_DEFAULT);
        privctx->curl = curl_easy_init();
        if (privctx->curl == NULL) {