]> andersk Git - openssh.git/blobdiff - ssh-rand-helper.c
- dtucker@cvs.openbsd.org 2010/01/09 11:17:56
[openssh.git] / ssh-rand-helper.c
index bdf73ec4841826270dfb3b6dec5ec57cd21db114..0fcda7fff169f8b9ea2b0b959ab0b34158a2b776 100644 (file)
 #include <sys/resource.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <sys/socket.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <string.h>
+
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #ifdef HAVE_SYS_UN_H
 # include <sys/un.h>
 #endif
 
+#include <errno.h>
+#include <fcntl.h>
+#include <pwd.h>
 #include <signal.h>
+#include <time.h>
+#include <unistd.h>
 
 #include <openssl/rand.h>
 #include <openssl/sha.h>
@@ -573,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);
@@ -674,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;
@@ -768,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));
                }
        }
@@ -777,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;
 }
 
@@ -839,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
This page took 0.226546 seconds and 4 git commands to generate.