summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@herrb.eu>2017-02-28 19:18:43 +0100
committerAdam Jackson <ajax@redhat.com>2017-02-28 14:02:37 -0500
commit957e8db38f27932d353e86e9aa69cf16778b18f1 (patch)
treee6238772aab3a0a5b928fa56eaec343d1553c36c /os
parentd7ac755f0b618eb1259d93c8a16ec6e39a18627c (diff)
Use arc4random_buf(3) if available to generate cookies.
Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Diffstat (limited to 'os')
-rw-r--r--os/auth.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/os/auth.c b/os/auth.c
index 7da6fc6ed..81164a2f5 100644
--- a/os/auth.c
+++ b/os/auth.c
@@ -45,6 +45,9 @@ from The Open Group.
#ifdef WIN32
#include <X11/Xw32defs.h>
#endif
+#ifdef HAVE_LIBBSD
+#include <bsd/stdlib.h> /* for arc4random_buf() */
+#endif
struct protocol {
unsigned short name_length;
@@ -303,11 +306,15 @@ GenerateAuthorization(unsigned name_length,
void
GenerateRandomData(int len, char *buf)
{
+#ifdef HAVE_ARC4RANDOMBUF
+ arc4random_buf(buf, len);
+#else
int fd;
fd = open("/dev/urandom", O_RDONLY);
read(fd, buf, len);
close(fd);
+#endif
}
#endif /* XCSECURITY */