]> the.earth.li Git - onak.git/blobdiff - keydb_keyd.c
Change delete_key to use a full fingerprint
[onak.git] / keydb_keyd.c
index 33d2c21b4d15eac23e918073f2ca7399c037607e..597507e5e78d3ecb41b8043c9be162dfe65a9d62 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 <errno.h>
 #include <fcntl.h>
+#include <stdbool.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -34,6 +35,7 @@
 #include "keystructs.h"
 #include "log.h"
 #include "mem.h"
+#include "onak.h"
 #include "onak-conf.h"
 #include "parsekey.h"
 
@@ -185,19 +187,19 @@ static int keyd_fetch_key_fp(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.
 *
 *      This function deletes a public key from whatever storage mechanism we
 *      are using. Returns 0 if the key existed.
 */
 static int keyd_delete_key(struct onak_dbctx *dbctx,
-               uint64_t keyid, bool intrans)
+               struct openpgp_fingerprint *fp, bool intrans)
 {
        int keyd_fd = (intptr_t) dbctx->priv;
 
        if (keyd_send_cmd(keyd_fd, KEYD_CMD_DELETE)) {
-               write(keyd_fd, &keyid, sizeof(keyid));
+               write(keyd_fd, fp, sizeof(*fp));
        }
 
        return 0;
@@ -227,6 +229,7 @@ static int keyd_store_key(struct onak_dbctx *dbctx,
        struct openpgp_packet_list *list_end = NULL;
        struct openpgp_publickey   *next = NULL;
        uint64_t                    keyid;
+       enum keyd_ops               cmd = KEYD_CMD_STORE;
 
        if (get_keyid(publickey, &keyid) != ONAK_E_OK) {
                logthing(LOGTHING_ERROR, "Couldn't find key ID for key.");
@@ -234,10 +237,10 @@ static int keyd_store_key(struct onak_dbctx *dbctx,
        }
 
        if (update) {
-               keyd_delete_key(dbctx, keyid, false);
+               cmd = KEYD_CMD_UPDATE;
        }
 
-       if (keyd_send_cmd(keyd_fd, KEYD_CMD_STORE)) {
+       if (keyd_send_cmd(keyd_fd, cmd)) {
                keybuf.offset = 0;
                keybuf.size = 8192;
                keybuf.buffer = malloc(keybuf.size);
@@ -502,7 +505,7 @@ static void keyd_cleanupdb(struct onak_dbctx *dbctx)
  *     this file are called in order to allow the DB to be initialized ready
  *     for access.
  */
-struct onak_dbctx *keydb_keyd_init(bool readonly)
+struct onak_dbctx *keydb_keyd_init(struct onak_db_config *dbcfg, bool readonly)
 {
        struct sockaddr_un sock;
        uint32_t           cmd = KEYD_CMD_UNKNOWN;
@@ -515,6 +518,7 @@ struct onak_dbctx *keydb_keyd_init(bool readonly)
        if (dbctx == NULL) {
                return NULL;
        }
+       dbctx->config = dbcfg;
 
        keyd_fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (keyd_fd < 0) {