Explicitly use 32 bits for keyd socket commands
authorJonathan McDowell <noodles@earth.li>
Tue, 29 Mar 2011 15:14:31 +0000 (07:14 -0800)
committerJonathan McDowell <noodles@earth.li>
Tue, 29 Mar 2011 15:14:31 +0000 (07:14 -0800)
  While cross machine compatibility is not currently an aim for keyd
  we should specify the word size for commands to help down the line
  if we decide to do this.

keyd.c
keyd.h
keydb_keyd.c

diff --git a/keyd.c b/keyd.c
index eab3b5495b951ecbe52b023829975b9b4e61a294..987724db53320bae70f708bf7f68d2a438eddd35 100644 (file)
--- a/keyd.c
+++ b/keyd.c
@@ -125,7 +125,7 @@ int sock_init(const char *sockname)
 
 int sock_do(int fd)
 {
-       int      cmd = KEYD_CMD_UNKNOWN;
+       uint32_t cmd = KEYD_CMD_UNKNOWN;
        ssize_t  bytes = 0;
        ssize_t  count = 0;
        int      ret = 0;
diff --git a/keyd.h b/keyd.h
index 3bc252a3920835cad3fdb56f9479a82e07567917..9dd72277f6694f2e4e001370c8ebd33b48b39db3 100644 (file)
--- a/keyd.h
+++ b/keyd.h
@@ -9,6 +9,8 @@
 #ifndef __KEYD_H__
 #define __KEYD_H__
 
+#include <stdint.h>
+
 #define KEYD_SOCKET "keyd.sock"
 
 enum keyd_ops {
@@ -29,6 +31,6 @@ enum keyd_reply {
        KEYD_REPLY_UNKNOWN_CMD = 1
 };
 
-static int keyd_version = 2;
+static uint32_t keyd_version = 2;
 
 #endif /* __KEYD_H__ */
index 35d2dc4cab504d388a5e2d3e7bcd4cd693c6fa93..e5d46a335a4b1ea17d3a13bf3c39a04d22de0666 100644 (file)
@@ -42,8 +42,8 @@ static int keyd_fd = -1;
 static void keyd_initdb(bool readonly)
 {
        struct sockaddr_un sock;
-       int                cmd = KEYD_CMD_UNKNOWN;
-       int                reply = KEYD_REPLY_UNKNOWN_CMD;
+       uint32_t           cmd = KEYD_CMD_UNKNOWN;
+       uint32_t           reply = KEYD_REPLY_UNKNOWN_CMD;
        ssize_t            count;
 
        keyd_fd = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -103,7 +103,7 @@ static void keyd_initdb(bool readonly)
  */
 static void keyd_cleanupdb(void)
 {
-       int cmd = KEYD_CMD_CLOSE;
+       uint32_t cmd = KEYD_CMD_CLOSE;
 
        if (write(keyd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) {
                logthing(LOGTHING_CRITICAL,
@@ -164,7 +164,7 @@ static int keyd_fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
 {
        struct buffer_ctx           keybuf;
        struct openpgp_packet_list *packets = NULL;
-       int                         cmd = KEYD_CMD_GET;
+       uint32_t                    cmd = KEYD_CMD_GET;
        ssize_t                     bytes = 0;
        ssize_t                     count = 0;
 
@@ -211,7 +211,7 @@ static int keyd_fetch_key(uint64_t keyid, struct openpgp_publickey **publickey,
 */
 static int keyd_delete_key(uint64_t keyid, bool intrans)
 {
-       int cmd = KEYD_CMD_DELETE;
+       uint32_t cmd = KEYD_CMD_DELETE;
 
        write(keyd_fd, &cmd, sizeof(cmd));
        read(keyd_fd, &cmd, sizeof(cmd));
@@ -243,7 +243,7 @@ static int keyd_store_key(struct openpgp_publickey *publickey, bool intrans,
        struct openpgp_packet_list *packets = NULL;
        struct openpgp_packet_list *list_end = NULL;
        struct openpgp_publickey   *next = NULL;
-       int                         cmd = KEYD_CMD_STORE;
+       uint32_t                    cmd = KEYD_CMD_STORE;
        uint64_t                    keyid;
 
        keyid = get_keyid(publickey);
@@ -294,7 +294,7 @@ static int keyd_fetch_key_text(const char *search,
 {
        struct buffer_ctx           keybuf;
        struct openpgp_packet_list *packets = NULL;
-       int                         cmd = KEYD_CMD_GETTEXT;
+       uint32_t                    cmd = KEYD_CMD_GETTEXT;
        ssize_t                     bytes = 0;
        ssize_t                     count = 0;
 
@@ -344,7 +344,7 @@ static int keyd_fetch_key_text(const char *search,
  */
 static uint64_t keyd_getfullkeyid(uint64_t keyid)
 {
-       int cmd = KEYD_CMD_GETFULLKEYID;
+       uint32_t cmd = KEYD_CMD_GETFULLKEYID;
 
        write(keyd_fd, &cmd, sizeof(cmd));
        read(keyd_fd, &cmd, sizeof(cmd));
@@ -373,7 +373,7 @@ static int keyd_iterate_keys(void (*iterfunc)(void *ctx,
        struct buffer_ctx           keybuf;
        struct openpgp_packet_list *packets = NULL;
        struct openpgp_publickey   *key = NULL;
-       int                         cmd = KEYD_CMD_KEYITER;
+       uint32_t                    cmd = KEYD_CMD_KEYITER;
        ssize_t                     bytes = 0;
        ssize_t                     count = 0;
        int                         numkeys = 0;