summaryrefslogtreecommitdiff
path: root/libtac/lib
diff options
context:
space:
mode:
authorJeroen Nijhof <jeroen@jeroennijhof.nl>2013-04-28 17:54:47 +0200
committerJeroen Nijhof <jeroen@jeroennijhof.nl>2013-04-28 17:54:47 +0200
commit117013b4c159cad96d92a24d5ea53a5adf74c58b (patch)
treeccc0d0c092de0b8677e7a89baad1a0daa957bb54 /libtac/lib
parent10df9486a13dc38349e0e7e0fbe9df35f0750071 (diff)
downloadpam_tacplus-117013b4c159cad96d92a24d5ea53a5adf74c58b.tar.gz
pam_tacplus-117013b4c159cad96d92a24d5ea53a5adf74c58b.zip
/dev/urandom improvements, thanks Walter. Fixed active_server check
Diffstat (limited to 'libtac/lib')
-rw-r--r--libtac/lib/crypt.c10
-rw-r--r--libtac/lib/magic.c77
2 files changed, 24 insertions, 63 deletions
diff --git a/libtac/lib/crypt.c b/libtac/lib/crypt.c
index 5ecdbd6..9f57106 100644
--- a/libtac/lib/crypt.c
+++ b/libtac/lib/crypt.c
@@ -64,15 +64,7 @@ u_char *_tac_md5_pad(int len, HDR *hdr) {
MD5Init(&mdcontext);
MD5Update(&mdcontext, buf, bp);
- /* this is because MD5 implementation has changed between
- * pppd versions 2.2.0g and 2.3.4
- */
-#if 1
- MD5Final(pad+pp, &mdcontext); /* correct for pppd-2.3.4 */
-#else
- MD5Final(&mdcontext); /* correct for pppd-2.2.0g */
- bcopy(&mdcontext.digest, pad+pp, MD5_LEN);
-#endif
+ MD5Final(pad+pp, &mdcontext);
pp += MD5_LEN;
}
diff --git a/libtac/lib/magic.c b/libtac/lib/magic.c
index 6af5bb6..308dc03 100644
--- a/libtac/lib/magic.c
+++ b/libtac/lib/magic.c
@@ -23,21 +23,12 @@
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
-
-#include "magic.h"
-
-#ifndef __linux__
-extern long mrand48 __P((void));
-extern void srand48 __P((long));
-#else
#include <sys/stat.h>
#include <fcntl.h>
-/* on Linux we use /dev/urandom as random numbers source
- I find it really cool :) */
-int rfd = -1; /* /dev/urandom */
-#endif
+#include "magic.h"
+static int rfd = -1; /* fd for /dev/urandom */
static int magic_inited = 0;
/*
@@ -50,24 +41,30 @@ static int magic_inited = 0;
void
magic_init()
{
+ struct stat statbuf;
long seed;
struct timeval t;
if (magic_inited)
return;
-/* FIXME this should be ifdef HAVE_DEV_URANDOM + test for /dev/urandom in configure */
-#ifdef __linux__
- rfd = open("/dev/urandom", O_RDONLY);
- if(rfd != -1)
- return;
-#endif
- /* if /dev/urandom fails, we try traditional method */
+ magic_inited = 1;
+
+ /*
+ try using /dev/urandom
+ also check that it's a character device
+ If it doesn't exist, fallback to other method
+ */
+
+ if (!lstat("/dev/urandom", &statbuf) && S_ISCHR(statbuf.st_mode)) {
+ rfd = open("/dev/urandom", O_RDONLY);
+ if (rfd >= 0)
+ return;
+ }
+
gettimeofday(&t, NULL);
seed = gethostid() ^ t.tv_sec ^ t.tv_usec ^ getpid();
- srand48(seed);
-
- magic_inited = 1;
+ srandom(seed);
}
/*
@@ -78,43 +75,15 @@ magic()
{
magic_init();
-#ifdef __linux__
- u_int32_t ret = 0;
-
if(rfd > -1) {
+ u_int32_t ret;
+
if (read(rfd, &ret, sizeof(ret)) < sizeof(ret)) {
- /* on read() error, fallback to other method */
- return (u_int32_t) mrand48();
+ /* on read() error fallback to other method */
+ return (u_int32_t)random();
}
return ret;
}
-#endif
- return (u_int32_t) mrand48();
-}
-
-#ifdef NO_DRAND48
-/*
- * Substitute procedures for those systems which don't have
- * drand48 et al.
- */
-
-double
-drand48()
-{
- return (double)random() / (double)0x7fffffffL; /* 2**31-1 */
-}
-
-long
-mrand48()
-{
- return random();
-}
-
-void
-srand48(seedval)
-long seedval;
-{
- srandom((int)seedval);
+ return (u_int32_t)random();
}
-#endif