return;
}
+static bool keyd_send_cmd(int fd, enum keyd_ops _cmd)
+{
+ uint32_t cmd = _cmd;
+ ssize_t bytes;
+
+ bytes = write(fd, &cmd, sizeof(cmd));
+ if (bytes != sizeof(cmd)) {
+ return false;
+ }
+
+ bytes = read(fd, &cmd, sizeof(cmd));
+ if (bytes != sizeof(cmd)) {
+ return false;
+ }
+
+ if (cmd != KEYD_REPLY_OK) {
+ return false;
+ }
+
+ return true;
+}
+
/**
* fetch_key - Given a keyid fetch the key from storage.
* @keyid: The keyid to fetch.
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
- uint32_t cmd = KEYD_CMD_GET_ID;
ssize_t bytes = 0;
ssize_t count = 0;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_ID)) {
write(keyd_fd, &keyid, sizeof(keyid));
keybuf.offset = 0;
read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
- uint32_t cmd = KEYD_CMD_GET_FP;
ssize_t bytes = 0;
ssize_t count = 0;
uint8_t size;
return 0;
}
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_FP)) {
size = fingerprint->length;
write(keyd_fd, &size, sizeof(size));
write(keyd_fd, fingerprint->fp, size);
uint64_t keyid, bool intrans)
{
int keyd_fd = (intptr_t) dbctx->priv;
- uint32_t cmd = KEYD_CMD_DELETE;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_DELETE)) {
write(keyd_fd, &keyid, sizeof(keyid));
}
struct openpgp_packet_list *packets = NULL;
struct openpgp_packet_list *list_end = NULL;
struct openpgp_publickey *next = NULL;
- uint32_t cmd = KEYD_CMD_STORE;
uint64_t keyid;
if (get_keyid(publickey, &keyid) != ONAK_E_OK) {
keyd_delete_key(dbctx, keyid, false);
}
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_STORE)) {
keybuf.offset = 0;
keybuf.size = 8192;
keybuf.buffer = malloc(keybuf.size);
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
- uint32_t cmd = KEYD_CMD_GET_TEXT;
ssize_t bytes = 0;
ssize_t count = 0;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_TEXT)) {
bytes = strlen(search);
write(keyd_fd, &bytes, sizeof(bytes));
write(keyd_fd, search, bytes);
int keyd_fd = (intptr_t) dbctx->priv;
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
- uint32_t cmd = KEYD_CMD_GET_SKSHASH;
ssize_t bytes = 0;
ssize_t count = 0;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GET_SKSHASH)) {
write(keyd_fd, hash->hash, sizeof(hash->hash));
keybuf.offset = 0;
read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
int keyd_fd = (intptr_t) dbctx->priv;
uint32_t cmd = KEYD_CMD_GETFULLKEYID;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_GETFULLKEYID)) {
write(keyd_fd, &keyid, sizeof(keyid));
read(keyd_fd, &cmd, sizeof(cmd));
if (cmd != sizeof(keyid)) {
struct buffer_ctx keybuf;
struct openpgp_packet_list *packets = NULL;
struct openpgp_publickey *key = NULL;
- uint32_t cmd = KEYD_CMD_KEYITER;
ssize_t bytes = 0;
ssize_t count = 0;
int numkeys = 0;
- write(keyd_fd, &cmd, sizeof(cmd));
- read(keyd_fd, &cmd, sizeof(cmd));
- if (cmd == KEYD_REPLY_OK) {
+ if (keyd_send_cmd(keyd_fd, KEYD_CMD_KEYITER)) {
keybuf.offset = 0;
read(keyd_fd, &keybuf.size, sizeof(keybuf.size));
while (keybuf.size > 0) {