X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/blobdiff_plain/759c7b91290f7321629507f237669b33f27ed9cb..d03186af8de9b660564ccc1804d2a9c2e93b2e58:/ssh-rand-helper.c diff --git a/ssh-rand-helper.c b/ssh-rand-helper.c index 28c93b6f..0fcda7ff 100644 --- a/ssh-rand-helper.c +++ b/ssh-rand-helper.c @@ -24,6 +24,30 @@ #include "includes.h" +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#ifdef HAVE_SYS_UN_H +# include +#endif + +#include +#include +#include +#include +#include +#include + #include #include #include @@ -39,8 +63,6 @@ #include "pathnames.h" #include "log.h" -RCSID("$Id$"); - /* Number of bytes we write out */ #define OUTPUT_SEED_SIZE 48 @@ -123,7 +145,7 @@ get_random_bytes_prngd(unsigned char *buf, int len, unsigned short tcp_port, char *socket_path) { int fd, addr_len, rval, errors; - char msg[2]; + u_char msg[2]; struct sockaddr_storage addr; struct sockaddr_in *addr_in = (struct sockaddr_in *)&addr; struct sockaddr_un *addr_un = (struct sockaddr_un *)&addr; @@ -135,8 +157,8 @@ get_random_bytes_prngd(unsigned char *buf, int len, if (socket_path != NULL && strlen(socket_path) >= sizeof(addr_un->sun_path)) fatal("Random pool path is too long"); - if (len > 255) - fatal("Too many bytes to read from PRNGD"); + if (len <= 0 || len > 255) + fatal("Too many bytes (%d) to read from PRNGD", len); memset(&addr, '\0', sizeof(addr)); @@ -190,7 +212,7 @@ reopen: goto done; } - if (atomicio(read, fd, buf, len) != len) { + if (atomicio(read, fd, buf, len) != (size_t)len) { if (errno == EPIPE && errors < 10) { close(fd); errors++; @@ -398,8 +420,8 @@ hash_command_output(entropy_cmd_t *src, unsigned char *hash) debug3("Time elapsed: %d msec", msec_elapsed); if (waitpid(pid, &status, 0) == -1) { - error("Couldn't wait for child '%s' completion: %s", - src->cmdstring, strerror(errno)); + error("Couldn't wait for child '%s' completion: %s", + src->cmdstring, strerror(errno)); return 0.0; } @@ -564,7 +586,8 @@ prng_write_seedfile(void) /* Try to ensure that the parent directory is there */ snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir, _PATH_SSH_USER_DIR); - mkdir(filename, 0700); + if (mkdir(filename, 0700) < 0 && errno != EEXIST) + fatal("mkdir %.200s: %s", filename, strerror(errno)); snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir, SSH_PRNG_SEED_FILE); @@ -600,7 +623,7 @@ prng_write_seedfile(void) save_errno = errno; unlink(tmpseed); fatal("problem renaming PRNG seedfile from %.100s " - "to %.100s (%.100s)", tmpseed, filename, + "to %.100s (%.100s)", tmpseed, filename, strerror(save_errno)); } } @@ -665,8 +688,7 @@ prng_read_commands(char *cmdfilename) } num_cmds = 64; - entcmd = xmalloc(num_cmds * sizeof(entropy_cmd_t)); - memset(entcmd, '\0', num_cmds * sizeof(entropy_cmd_t)); + entcmd = xcalloc(num_cmds, sizeof(entropy_cmd_t)); /* Read in file */ cur_cmd = linenum = 0; @@ -759,7 +781,7 @@ prng_read_commands(char *cmdfilename) */ if (cur_cmd == num_cmds) { num_cmds *= 2; - entcmd = xrealloc(entcmd, num_cmds * + entcmd = xrealloc(entcmd, num_cmds, sizeof(entropy_cmd_t)); } } @@ -768,12 +790,13 @@ prng_read_commands(char *cmdfilename) memset(&entcmd[cur_cmd], '\0', sizeof(entropy_cmd_t)); /* trim to size */ - entropy_cmds = xrealloc(entcmd, (cur_cmd + 1) * + entropy_cmds = xrealloc(entcmd, (cur_cmd + 1), sizeof(entropy_cmd_t)); debug("Loaded %d entropy commands from %.100s", cur_cmd, cmdfilename); + fclose(f); return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; } @@ -830,11 +853,17 @@ main(int argc, char **argv) default: error("Invalid commandline option"); usage(); + exit(1); } } - log_init(argv[0], ll, SYSLOG_FACILITY_USER, 1); + if (argc != optind) { + error("Unexpected commandline arguments."); + usage(); + exit(1); + } + #ifdef USE_SEED_FILES prng_read_seedfile(); #endif