diff options
author | Pawel Krawczyk <pawel.krawczyk@hush.com> | 2014-11-26 23:19:59 +0000 |
---|---|---|
committer | Pawel Krawczyk <pawel.krawczyk@hush.com> | 2014-11-26 23:19:59 +0000 |
commit | e7cb27c9078779b40cc7080d0932ab8000f4d55b (patch) | |
tree | 5fb47a7655c451d450923425701241316136eef0 | |
parent | 4b142b06404e0536e98009d310d79d3b67b4bf90 (diff) | |
parent | d7210be00481f722a58042b5da8a46b78222bb39 (diff) | |
download | pam_tacplus-e7cb27c9078779b40cc7080d0932ab8000f4d55b.tar.gz pam_tacplus-e7cb27c9078779b40cc7080d0932ab8000f4d55b.zip |
Merge branch 'master' of github.com:jeroennijhof/pam_tacplus
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | libtac/lib/magic.c | 44 |
2 files changed, 17 insertions, 28 deletions
diff --git a/configure.ac b/configure.ac index 9314f8e..3ce026d 100644 --- a/configure.ac +++ b/configure.ac @@ -58,6 +58,7 @@ AX_CHECK_COMPILE_FLAG(["-Wl,-z,now"], [AX_APPEND_FLAG(["-Wl,-z,now"],[CFLAGS])], AX_CHECK_COMPILE_FLAG(["-fPIE"], [AX_APPEND_FLAG(["-fPIE"],[CFLAGS])], []) AX_CHECK_COMPILE_FLAG(["-pie"], [AX_APPEND_FLAG(["-pie"],[CFLAGS])], []) AX_APPEND_FLAG(["-O3"],[CFLAGS]) +AX_APPEND_FLAG(["-Wall"],[CFLAGS]) AX_APPEND_FLAG(["-D_FORTIFY_SOURCE=2"],[CFLAGS]) dnl -------------------------------------------------------------------- diff --git a/libtac/lib/magic.c b/libtac/lib/magic.c index 9785314..5e27596 100644 --- a/libtac/lib/magic.c +++ b/libtac/lib/magic.c @@ -28,8 +28,7 @@ #include "magic.h" -static int rfd = -1; /* fd for /dev/urandom */ -static int magic_inited = 0; +static int magic_initialised = 0; /* * magic_init - Initialize the magic number generator. @@ -45,26 +44,25 @@ magic_init() long seed; struct timeval t; - if (magic_inited) + if (magic_initialised) return; - magic_inited = 1; - - /* - try using /dev/urandom - also check that it's a character device - If it doesn't exist, fallback to other method - */ - + // try to initialise seed from urandom if (!lstat("/dev/urandom", &statbuf) && S_ISCHR(statbuf.st_mode)) { - rfd = open("/dev/urandom", O_RDONLY); - if (rfd >= 0) - return; - } + int rfd = open("/dev/urandom", O_RDONLY); + if(rfd > 0) { + int nb_read = read(rfd, &seed, sizeof(seed)); + close(rfd); + } + } + // add the deterministic data in case urandom failed gettimeofday(&t, NULL); - seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid(); + seed ^= gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid(); + + // finally seed the PRNG srandom(seed); + magic_initialised = 1; } /* @@ -73,19 +71,9 @@ magic_init() u_int32_t magic() { - magic_init(); - - if(rfd > -1) { - u_int32_t ret; - int nb_read = read(rfd, &ret, sizeof(ret)); - close(rfd); + if(!magic_initialised) + magic_init(); - if (nb_read < sizeof(ret)) { - /* on read() error fallback to other method */ - return (u_int32_t)random(); - } - return ret; - } return (u_int32_t)random(); } |