case KEYD_CMD_VERSION:
cmd = KEYD_REPLY_OK;
write(fd, &cmd, sizeof(cmd));
+ cmd = sizeof(keyd_version);
+ write(fd, &cmd, sizeof(cmd));
write(fd, &keyd_version, sizeof(keyd_version));
break;
case KEYD_CMD_GET:
}
if (ret == 0) {
keyid = config.dbbackend->getfullkeyid(keyid);
+ cmd = sizeof(keyid);
+ write(fd, &cmd, sizeof(cmd));
write(fd, &keyid, sizeof(keyid));
}
break;
write(fd, &bytes, sizeof(bytes));
break;
case KEYD_CMD_CLOSE:
+ cmd = KEYD_REPLY_OK;
+ write(fd, &cmd, sizeof(cmd));
ret = 1;
break;
case KEYD_CMD_QUIT:
+ cmd = KEYD_REPLY_OK;
+ write(fd, &cmd, sizeof(cmd));
+ ret = 1;
trytocleanup();
break;
default:
errno);
} else {
count = read(keyd_fd, &reply, sizeof(reply));
- if (count == sizeof(reply)) {
- if (reply == KEYD_REPLY_OK) {
- count = read(keyd_fd, &reply, sizeof(reply));
- logthing(LOGTHING_DEBUG,
- "keyd protocol version %d",
- reply);
- if (reply != keyd_version) {
- logthing(LOGTHING_CRITICAL,
- "Error! keyd protocol version "
- "mismatch. (us = %d, it = %d)",
+ if (count == sizeof(reply) && reply == KEYD_REPLY_OK) {
+ count = read(keyd_fd, &reply, sizeof(reply));
+ if (count != sizeof(reply) || reply != sizeof(reply)) {
+ logthing(LOGTHING_CRITICAL,
+ "Error! Unexpected keyd version "
+ "length: %d != %d",
+ reply, sizeof(reply));
+ exit(EXIT_FAILURE);
+ }
+
+ count = read(keyd_fd, &reply, sizeof(reply));
+ logthing(LOGTHING_DEBUG,
+ "keyd protocol version %d",
+ reply);
+ if (reply != keyd_version) {
+ logthing(LOGTHING_CRITICAL,
+ "Error! keyd protocol version "
+ "mismatch. (us = %d, it = %d)",
keyd_version, reply);
- }
}
}
}
strerror(errno),
errno);
}
+
+ if (read(keyd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
+ logthing(LOGTHING_CRITICAL,
+ "Couldn't read close cmd reply: %s (%d)",
+ strerror(errno),
+ errno);
+ } else if (cmd != KEYD_REPLY_OK) {
+ logthing(LOGTHING_CRITICAL,
+ "Got bad reply to KEYD_CMD_CLOSE: %d", cmd);
+ }
if (shutdown(keyd_fd, SHUT_RDWR) < 0) {
logthing(LOGTHING_NOTICE, "Error shutting down socket: %d",
read(keyd_fd, &cmd, sizeof(cmd));
if (cmd == KEYD_REPLY_OK) {
write(keyd_fd, &keyid, sizeof(keyid));
+ read(keyd_fd, &cmd, sizeof(cmd));
+ if (cmd != sizeof(keyid)) {
+ return 0;
+ }
read(keyd_fd, &keyid, sizeof(keyid));
}