X-Git-Url: http://the.earth.li/gitweb/?a=blobdiff_plain;f=keyd.c;h=8b61d0cece78569b0ca8079c1902f4d4e4db5a38;hb=f4734fb615e269af498d4c24ba402c2deba4730b;hp=5cd7b57564968e68680b3562103959638c025ef1;hpb=83ae316a7b14e55418349e87d1a1942a0627ae14;p=onak.git diff --git a/keyd.c b/keyd.c index 5cd7b57..8b61d0c 100644 --- a/keyd.c +++ b/keyd.c @@ -65,11 +65,35 @@ void daemonize(void) exit(EXIT_SUCCESS); } - setsid(); + if (setsid() == -1) { + logthing(LOGTHING_CRITICAL, + "Couldn't set process group leader: %d (%s)", + errno, + strerror(errno)); + exit(EXIT_FAILURE); + } - freopen("/dev/null", "r", stdin); - freopen("/dev/null", "w", stdout); - freopen("/dev/null", "w", stderr); + if (!freopen("/dev/null", "r", stdin)) { + logthing(LOGTHING_CRITICAL, + "Couldn't reopen stdin to NULL: %d (%s)", + errno, + strerror(errno)); + exit(EXIT_FAILURE); + } + if (!freopen("/dev/null", "w", stdout)) { + logthing(LOGTHING_CRITICAL, + "Couldn't reopen stdout to NULL: %d (%s)", + errno, + strerror(errno)); + exit(EXIT_FAILURE); + } + if (!freopen("/dev/null", "w", stderr)) { + logthing(LOGTHING_CRITICAL, + "Couldn't reopen stderr to NULL: %d (%s)", + errno, + strerror(errno)); + exit(EXIT_FAILURE); + } return; } @@ -155,13 +179,13 @@ int sock_do(struct onak_dbctx *dbctx, int fd) ssize_t count = 0; int ret = 0; uint64_t keyid = 0; - uint8_t fp[MAX_FINGERPRINT_LEN]; char *search = NULL; struct openpgp_publickey *key = NULL; struct openpgp_packet_list *packets = NULL; struct openpgp_packet_list *list_end = NULL; struct buffer_ctx storebuf; struct skshash hash; + struct openpgp_fingerprint fingerprint; /* * Get the command from the client. @@ -242,7 +266,8 @@ int sock_do(struct onak_dbctx *dbctx, int fd) if (bytes > MAX_FINGERPRINT_LEN) { ret = 1; } else { - read(fd, fp, bytes); + fingerprint.length = bytes; + read(fd, fingerprint.fp, bytes); } storebuf.offset = 0; if (ret == 0) { @@ -250,7 +275,7 @@ int sock_do(struct onak_dbctx *dbctx, int fd) "Fetching by fingerprint" ", result: %d", dbctx->fetch_key_fp(dbctx, - fp, bytes, + &fingerprint, &key, false)); if (key != NULL) { storebuf.size = 8192;