summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalter de Jong <walter@heiho.net>2013-03-28 21:18:42 +0100
committerWalter de Jong <walter@heiho.net>2013-03-28 21:18:42 +0100
commit06ab1ba46bfe9480e8763871df64c0205a977ceb (patch)
tree6439d293bc410daf956ccf03b72317aba0412178
parentfeb183b9c9b47e6a5e5e243534d32263f165ec33 (diff)
downloadpam_tacplus-06ab1ba46bfe9480e8763871df64c0205a977ceb.tar.gz
pam_tacplus-06ab1ba46bfe9480e8763871df64c0205a977ceb.zip
magic is always inited
-rw-r--r--libtac/lib/magic.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/libtac/lib/magic.c b/libtac/lib/magic.c
index ef3128c..528bedd 100644
--- a/libtac/lib/magic.c
+++ b/libtac/lib/magic.c
@@ -36,9 +36,10 @@ extern void srand48 __P((long));
/* on Linux we use /dev/urandom as random numbers source
I find it really cool :) */
int rfd = -1; /* /dev/urandom */
-int magic_inited = 0;
#endif
+static int magic_inited = 0;
+
/*
* magic_init - Initialize the magic number generator.
*
@@ -52,8 +53,10 @@ magic_init()
long seed;
struct timeval t;
+ if (magic_inited)
+ return;
+
#ifdef __linux__
- magic_inited = 1;
rfd = open("/dev/urandom", O_RDONLY);
if(rfd != -1)
return;
@@ -62,6 +65,8 @@ magic_init()
gettimeofday(&t, NULL);
seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid();
srand48(seed);
+
+ magic_inited = 1;
}
/*
@@ -70,12 +75,11 @@ magic_init()
u_int32_t
magic()
{
+ magic_init();
+
#ifdef __linux__
u_int32_t ret = 0;
- if (magic_inited == 0 )
- magic_init();
-
if(rfd > -1) {
if (read(rfd, &ret, sizeof(ret)) < sizeof(ret)) {
/* on read() error, fallback to other method */