]> andersk Git - openssh.git/blobdiff - bsd-misc.c
- Check for libwrap if --with-tcp-wrappers option specified. Suggestion
[openssh.git] / bsd-misc.c
index a4dafb9d9b1dab8332e481e649d6f029c762ed21..99fe298169027b274feffd9591b570417f4193ba 100644 (file)
@@ -1,9 +1,10 @@
 /*
 **
-** OpenBSD emulation routines
+** OpenBSD replacement routines
 **
 ** Damien Miller <djm@ibs.com.au>
 ** 
+** Copyright 1999 Damien Miller
 ** Copyright 1999 Internet Business Solutions
 **
 ** Permission is hereby granted, free of charge, to any person
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
 #include <fcntl.h>
+#ifdef HAVE_STDDEF_H
+#include <stddef.h>
+#endif
 
 #include "xmalloc.h"
 #include "ssh.h"
 #include "bsd-misc.h"
-
-#ifndef offsetof
-#define offsetof(type, member) ((size_t) &((type *)0)->member)
-#endif
+#include "random.h"
 
 #ifndef HAVE_ARC4RANDOM
 
@@ -64,7 +63,6 @@ typedef struct
        int j;
 } rc4_t;
 
-void get_random_bytes(unsigned char *buf, int len);
 void rc4_key(rc4_t *r, unsigned char *key, int len);
 void rc4_getbytes(rc4_t *r, unsigned char *buffer, int len);
 
@@ -130,59 +128,7 @@ void arc4random_stir(void)
        
        get_random_bytes(rand_buf, sizeof(rand_buf));
        rc4_key(rc4, rand_buf, sizeof(rand_buf));
-}
-
-void get_random_bytes(unsigned char *buf, int len)
-{
-       static int random_pool;
-       int c;
-#ifdef HAVE_EGD
-       char egd_message[2] = { 0x02, 0x00 };
-       struct sockaddr_un addr;
-       int addr_len;
-
-       memset(&addr, '\0', sizeof(addr));
-       addr.sun_family = AF_UNIX;
-       
-       /* FIXME: compile time check? */
-       if (sizeof(RANDOM_POOL) > sizeof(addr.sun_path))
-               fatal("Random pool path is too long");
-       
-       strcpy(addr.sun_path, RANDOM_POOL);
-       
-       addr_len = offsetof(struct sockaddr_un, sun_path) + sizeof(RANDOM_POOL);
-       
-       random_pool = socket(AF_UNIX, SOCK_STREAM, 0);
-       
-       if (random_pool == -1)
-               fatal("Couldn't create AF_UNIX socket: %s", strerror(errno));
-       
-       if (connect(random_pool, (struct sockaddr*)&addr, addr_len) == -1)
-               fatal("Couldn't connect to EGD socket \"%s\": %s", addr.sun_path, strerror(errno));
-
-       if (len > 255)
-               fatal("Too many bytes to read from EGD");
-       
-       /* Send blocking read request to EGD */
-       egd_message[1] = len;
-
-       c = atomicio(write, random_pool, egd_message, sizeof(egd_message));
-       if (c == -1)
-               fatal("Couldn't write to EGD socket \"%s\": %s", RANDOM_POOL, strerror(errno));
-
-#else /* HAVE_EGD */
-
-       random_pool = open(RANDOM_POOL, O_RDONLY);
-       if (random_pool == -1)
-               fatal("Couldn't open random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
-
-#endif /* HAVE_EGD */
-
-       c = atomicio(read, random_pool, buf, len);
-       if (c <= 0)
-               fatal("Couldn't read from random pool \"%s\": %s", RANDOM_POOL, strerror(errno));
-       
-       close(random_pool);
+       memset(rand_buf, 0, sizeof(rand_buf));
 }
 #endif /* !HAVE_ARC4RANDOM */
 
This page took 0.034235 seconds and 4 git commands to generate.