*/
static void keyd_cleanupdb(void)
{
+ int cmd = KEYD_CMD_CLOSE;
+
+ if (write(keyd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
+ logthing(LOGTHING_CRITICAL,
+ "Couldn't send close cmd: %s (%d)",
+ strerror(errno),
+ errno);
+ }
+
if (shutdown(keyd_fd, SHUT_RDWR) < 0) {
logthing(LOGTHING_NOTICE, "Error shutting down socket: %d",
errno);
}
+ if (close(keyd_fd) < 0) {
+ logthing(LOGTHING_NOTICE, "Error closing down socket: %d",
+ errno);
+ }
keyd_fd = -1;
return;
return (count > 0) ? 1 : 0;
}
+/**
+* delete_key - Given a keyid delete the key from storage.
+* @keyid: The keyid 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(uint64_t keyid, bool intrans)
+{
+ int cmd = KEYD_CMD_DELETE;
+
+ write(keyd_fd, &cmd, sizeof(cmd));
+ read(keyd_fd, &cmd, sizeof(cmd));
+ if (cmd == KEYD_REPLY_OK) {
+ write(keyd_fd, &keyid, sizeof(keyid));
+ }
+
+ return 0;
+}
+
/**
* store_key - Takes a key and stores it.
* @publickey: A pointer to the public key to store.
keyid = get_keyid(publickey);
if (update) {
- delete_key(keyid, false);
+ keyd_delete_key(keyid, false);
}
write(keyd_fd, &cmd, sizeof(cmd));
return 0;
}
-/**
- * delete_key - Given a keyid delete the key from storage.
- * @keyid: The keyid 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(uint64_t keyid, bool intrans)
-{
- int cmd = KEYD_CMD_DELETE;
-
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
- write(keyd_fd, &keyid, sizeof(keyid));
- }
-
- return 0;
-}
-
/**
* fetch_key_text - Trys to find the keys that contain the supplied text.
* @search: The text to search for.