summaryrefslogtreecommitdiff
path: root/genauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'genauth.c')
-rw-r--r--genauth.c87
1 files changed, 62 insertions, 25 deletions
diff --git a/genauth.c b/genauth.c
index a4f8ced..0568e6f 100644
--- a/genauth.c
+++ b/genauth.c
@@ -26,6 +26,7 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
+/* $XFree86: xc/programs/xdm/genauth.c,v 3.15 2002/10/06 18:12:29 herrb Exp $ */
/*
* xdm - display manager daemon
@@ -34,18 +35,15 @@ from The Open Group.
# include <X11/Xauth.h>
# include <X11/Xos.h>
+
# include "dm.h"
+# include "dm_auth.h"
+# include "dm_error.h"
#include <errno.h>
-#ifdef X_NOT_STDC_ENV
-#define Time_t long
-extern Time_t time ();
-extern int errno;
-#else
#include <time.h>
#define Time_t time_t
-#endif
static unsigned char key[8];
@@ -57,10 +55,8 @@ typedef struct auth_ks_struct { auth_cblock _; } auth_wrapper_schedule[16];
extern void _XdmcpWrapperToOddParity();
-static
-longtochars (l, c)
- long l;
- unsigned char *c;
+static void
+longtochars (long l, unsigned char *c)
{
c[0] = (l >> 24) & 0xff;
c[1] = (l >> 16) & 0xff;
@@ -72,10 +68,9 @@ longtochars (l, c)
# define FILE_LIMIT 1024 /* no more than this many buffers */
+#if !defined(ARC4_RANDOM) && !defined(DEV_RANDOM)
static int
-sumFile (name, sum)
-char *name;
-long sum[2];
+sumFile (char *name, long sum[2])
{
long buf[1024*2];
int cnt;
@@ -85,7 +80,7 @@ long sum[2];
int i;
int ret_status = 0;
- fd = open (name, 0);
+ fd = open (name, O_RDONLY);
if (fd < 0) {
LogError("Cannot open randomFile \"%s\", errno = %d\n", name, errno);
return 0;
@@ -109,12 +104,37 @@ long sum[2];
close (fd);
return ret_status;
}
+#endif
#ifdef HASXDMAUTH
-
-static
-InitXdmcpWrapper ()
+static void
+InitXdmcpWrapper (void)
{
+
+#ifdef ARC4_RANDOM
+ u_int32_t sum[2];
+
+ sum[0] = arc4random();
+ sum[1] = arc4random();
+ *(u_char *)sum = 0;
+
+ _XdmcpWrapperToOddParity(sum, key);
+
+#elif defined(DEV_RANDOM)
+ int fd;
+ unsigned char tmpkey[8];
+
+ if ((fd = open(DEV_RANDOM, O_RDONLY)) >= 0) {
+ if (read(fd, tmpkey, 8) == 8) {
+ tmpkey[0] = 0;
+ _XdmcpWrapperToOddParity(tmpkey, key);
+ close(fd);
+ return;
+ } else {
+ close(fd);
+ }
+ }
+#else
long sum[2];
unsigned char tmpkey[8];
@@ -126,6 +146,7 @@ InitXdmcpWrapper ()
longtochars (sum[1], tmpkey+4);
tmpkey[0] = 0;
_XdmcpWrapperToOddParity (tmpkey, key);
+#endif
}
#endif
@@ -138,23 +159,21 @@ InitXdmcpWrapper ()
static unsigned long int next = 1;
static int
-xdm_rand()
+xdm_rand(void)
{
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
static void
-xdm_srand(seed)
- unsigned int seed;
+xdm_srand(unsigned int seed)
{
next = seed;
}
#endif /* no HASXDMAUTH */
-GenerateAuthData (auth, len)
-char *auth;
-int len;
+void
+GenerateAuthData (char *auth, int len)
{
long ldata[2];
@@ -168,7 +187,9 @@ int len;
}
#else
{
+#ifndef __UNIXOS2__
long time ();
+#endif
ldata[0] = time ((long *) 0);
ldata[1] = getpid ();
@@ -193,8 +214,8 @@ int len;
for (i = 0; i < len; i++) {
auth[i] = 0;
for (bit = 1; bit < 256; bit <<= 1) {
- _XdmcpAuthDoIt (data, data, schedule, 1);
- if (data[0] + data[1] & 0x4)
+ _XdmcpAuthDoIt (data, data, schedule, 1);
+ if ((data[0] + data[1]) & 0x4)
auth[i] |= bit;
}
}
@@ -207,9 +228,25 @@ int len;
static long localkey[2] = {0,0};
if ( (localkey[0] == 0) && (localkey[1] == 0) ) {
+#ifdef ARC4_RANDOM
+ localkey[0] = arc4random();
+ localkey[1] = arc4random();
+#elif defined(DEV_RANDOM)
+ int fd;
+
+ if ((fd = open(DEV_RANDOM, O_RDONLY)) >= 0) {
+ if (read(fd, (char *)localkey, 8) != 8) {
+ localkey[0] = 1;
+ }
+ close(fd);
+ } else {
+ localkey[0] = 1;
+ }
+#else
if (!sumFile (randomFile, localkey)) {
localkey[0] = 1; /* To keep from continually calling sumFile() */
}
+#endif
}
seed = (ldata[0]+localkey[0]) + ((ldata[1]+localkey[1]) << 16);