summaryrefslogtreecommitdiff
path: root/os/auth.c
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:18:26 -0500
commitab15f65fe5d6d50e705c1064a6a5c1a0c2a8e045 (patch)
tree05e009185721815e12a56c71e7c4d7af9f1ea6fe /os/auth.c
parent3f61c7a09b220805ee6778f4bf2f429e3df8e37a (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> (cherry picked from commit 957e8db38f27932d353e86e9aa69cf16778b18f1)
Diffstat (limited to 'os/auth.c')
-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 */