summaryrefslogtreecommitdiff
path: root/ssh-rand-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'ssh-rand-helper.c')
-rw-r--r--ssh-rand-helper.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/ssh-rand-helper.c b/ssh-rand-helper.c
index 87e52cf75..8520c3a62 100644
--- a/ssh-rand-helper.c
+++ b/ssh-rand-helper.c
@@ -24,6 +24,29 @@
24 24
25#include "includes.h" 25#include "includes.h"
26 26
27#include <sys/types.h>
28#include <sys/resource.h>
29#include <sys/stat.h>
30#include <sys/wait.h>
31#include <sys/socket.h>
32
33#include <stdarg.h>
34#include <stddef.h>
35
36#include <netinet/in.h>
37#include <arpa/inet.h>
38
39#ifdef HAVE_SYS_UN_H
40# include <sys/un.h>
41#endif
42
43#include <errno.h>
44#include <fcntl.h>
45#include <pwd.h>
46#include <signal.h>
47#include <time.h>
48#include <unistd.h>
49
27#include <openssl/rand.h> 50#include <openssl/rand.h>
28#include <openssl/sha.h> 51#include <openssl/sha.h>
29#include <openssl/crypto.h> 52#include <openssl/crypto.h>
@@ -39,8 +62,6 @@
39#include "pathnames.h" 62#include "pathnames.h"
40#include "log.h" 63#include "log.h"
41 64
42RCSID("$Id: ssh-rand-helper.c,v 1.26 2005/07/17 07:26:44 djm Exp $");
43
44/* Number of bytes we write out */ 65/* Number of bytes we write out */
45#define OUTPUT_SEED_SIZE 48 66#define OUTPUT_SEED_SIZE 48
46 67
@@ -564,7 +585,8 @@ prng_write_seedfile(void)
564 /* Try to ensure that the parent directory is there */ 585 /* Try to ensure that the parent directory is there */
565 snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir, 586 snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir,
566 _PATH_SSH_USER_DIR); 587 _PATH_SSH_USER_DIR);
567 mkdir(filename, 0700); 588 if (mkdir(filename, 0700) < 0 && errno != EEXIST)
589 fatal("mkdir %.200s: %s", filename, strerror(errno));
568 590
569 snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir, 591 snprintf(filename, sizeof(filename), "%.512s/%s", pw->pw_dir,
570 SSH_PRNG_SEED_FILE); 592 SSH_PRNG_SEED_FILE);
@@ -665,8 +687,7 @@ prng_read_commands(char *cmdfilename)
665 } 687 }
666 688
667 num_cmds = 64; 689 num_cmds = 64;
668 entcmd = xmalloc(num_cmds * sizeof(entropy_cmd_t)); 690 entcmd = xcalloc(num_cmds, sizeof(entropy_cmd_t));
669 memset(entcmd, '\0', num_cmds * sizeof(entropy_cmd_t));
670 691
671 /* Read in file */ 692 /* Read in file */
672 cur_cmd = linenum = 0; 693 cur_cmd = linenum = 0;
@@ -759,7 +780,7 @@ prng_read_commands(char *cmdfilename)
759 */ 780 */
760 if (cur_cmd == num_cmds) { 781 if (cur_cmd == num_cmds) {
761 num_cmds *= 2; 782 num_cmds *= 2;
762 entcmd = xrealloc(entcmd, num_cmds * 783 entcmd = xrealloc(entcmd, num_cmds,
763 sizeof(entropy_cmd_t)); 784 sizeof(entropy_cmd_t));
764 } 785 }
765 } 786 }
@@ -768,12 +789,13 @@ prng_read_commands(char *cmdfilename)
768 memset(&entcmd[cur_cmd], '\0', sizeof(entropy_cmd_t)); 789 memset(&entcmd[cur_cmd], '\0', sizeof(entropy_cmd_t));
769 790
770 /* trim to size */ 791 /* trim to size */
771 entropy_cmds = xrealloc(entcmd, (cur_cmd + 1) * 792 entropy_cmds = xrealloc(entcmd, (cur_cmd + 1),
772 sizeof(entropy_cmd_t)); 793 sizeof(entropy_cmd_t));
773 794
774 debug("Loaded %d entropy commands from %.100s", cur_cmd, 795 debug("Loaded %d entropy commands from %.100s", cur_cmd,
775 cmdfilename); 796 cmdfilename);
776 797
798 fclose(f);
777 return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0; 799 return cur_cmd < MIN_ENTROPY_SOURCES ? -1 : 0;
778} 800}
779 801