diff --git a/os/auth.c b/os/auth.c index de2aae917..3152d7963 100644 --- a/os/auth.c +++ b/os/auth.c @@ -302,17 +302,3 @@ GenerateAuthorization(unsigned name_length, } #endif /* XCSECURITY */ - -void -GenerateRandomData(int len, char *buf) -{ -#ifdef HAVE_ARC4RANDOM_BUF - arc4random_buf(buf, len); -#else - int fd; - - fd = open("/dev/urandom", O_RDONLY); - read(fd, buf, len); - close(fd); -#endif -} diff --git a/os/mitauth.c b/os/mitauth.c index 4383ac7ae..8a9ae1ccd 100644 --- a/os/mitauth.c +++ b/os/mitauth.c @@ -147,7 +147,7 @@ MitGenerateCookie(unsigned data_length, if (i >= sizeof(cookie)) i = 0; } - GenerateRandomData(sizeof(cookie), cookie); + arc4random_buf(cookie, sizeof(cookie)); status = MitAddCookie(sizeof(cookie), cookie, id); if (!status) { id = -1; diff --git a/os/osdep.h b/os/osdep.h index 45ee3dda4..ffc43834f 100644 --- a/os/osdep.h +++ b/os/osdep.h @@ -130,8 +130,17 @@ extern Bool NewOutputPending; /* in access.c */ extern Bool ComputeLocalClient(ClientPtr client); -/* in auth.c */ -extern void GenerateRandomData(int len, char *buf); +/* for platforms lacking arc4random_buf() libc function */ +#ifndef HAVE_ARC4RANDOM_BUF +static inline void arc4random_buf(char *buf, size_t len) +{ + int fd; + + fd = open("/dev/urandom", O_RDONLY); + read(fd, buf, len); + close(fd); +} +#endif /* HAVE_ARC4RANDOM_BUF */ /* OsTimer functions */ void TimerInit(void);