| @@ -27,74 +27,83 @@ in this Software without prior written a | | | @@ -27,74 +27,83 @@ in this Software without prior written a |
27 | Author: Ralph Mor, X Consortium | | 27 | Author: Ralph Mor, X Consortium |
28 | ******************************************************************************/ | | 28 | ******************************************************************************/ |
29 | /* $XFree86: xc/lib/ICE/iceauth.c,v 3.6 2002/05/31 18:45:41 dawes Exp $ */ | | 29 | /* $XFree86: xc/lib/ICE/iceauth.c,v 3.6 2002/05/31 18:45:41 dawes Exp $ */ |
30 | | | 30 | |
31 | #include <X11/ICE/ICElib.h> | | 31 | #include <X11/ICE/ICElib.h> |
32 | #include "ICElibint.h" | | 32 | #include "ICElibint.h" |
33 | #include <X11/ICE/ICEutil.h> | | 33 | #include <X11/ICE/ICEutil.h> |
34 | | | 34 | |
35 | #include <time.h> | | 35 | #include <time.h> |
36 | #define Time_t time_t | | 36 | #define Time_t time_t |
37 | | | 37 | |
38 | static int binaryEqual (); | | 38 | static int binaryEqual (); |
39 | | | 39 | |
| | | 40 | #ifdef HAVE_LIBBSD |
| | | 41 | #include <bsd/stdlib.h> /* for arc4random_buf() */ |
| | | 42 | #endif |
| | | 43 | |
40 | static int was_called_state; | | 44 | static int was_called_state; |
41 | | | 45 | |
42 | /* | | 46 | /* |
43 | * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by | | 47 | * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by |
44 | * the SI. It is not part of standard ICElib. | | 48 | * the SI. It is not part of standard ICElib. |
45 | */ | | 49 | */ |
46 | | | 50 | |
47 | | | 51 | |
48 | char * | | 52 | char * |
49 | IceGenerateMagicCookie (len) | | 53 | IceGenerateMagicCookie (len) |
50 | | | 54 | |
51 | int len; | | 55 | int len; |
52 | | | 56 | |
53 | { | | 57 | { |
54 | char *auth; | | 58 | char *auth; |
| | | 59 | #ifndef HAVE_ARC4RANDOM_BUF |
55 | long ldata[2]; | | 60 | long ldata[2]; |
56 | int seed; | | 61 | int seed; |
57 | int value; | | 62 | int value; |
58 | int i; | | 63 | int i; |
| | | 64 | #endif |
59 | | | 65 | |
60 | if ((auth = (char *) malloc (len + 1)) == NULL) | | 66 | if ((auth = (char *) malloc (len + 1)) == NULL) |
61 | return (NULL); | | 67 | return (NULL); |
62 | | | 68 | |
| | | 69 | #ifdef HAVE_ARC4RANDOM_BUF |
| | | 70 | arc4random_buf(auth, len); |
| | | 71 | #else |
63 | #ifdef ITIMER_REAL | | 72 | #ifdef ITIMER_REAL |
64 | { | | 73 | { |
65 | struct timeval now; | | 74 | struct timeval now; |
66 | X_GETTIMEOFDAY (&now); | | 75 | X_GETTIMEOFDAY (&now); |
67 | ldata[0] = now.tv_sec; | | 76 | ldata[0] = now.tv_sec; |
68 | ldata[1] = now.tv_usec; | | 77 | ldata[1] = now.tv_usec; |
69 | } | | 78 | } |
70 | #else | | 79 | #else |
71 | { | | 80 | { |
72 | #ifndef __UNIXOS2__ | | 81 | #ifndef __UNIXOS2__ |
73 | long time (); | | 82 | long time (); |
74 | #endif | | 83 | #endif |
75 | ldata[0] = time ((long *) 0); | | 84 | ldata[0] = time ((long *) 0); |
76 | ldata[1] = getpid (); | | 85 | ldata[1] = getpid (); |
77 | } | | 86 | } |
78 | #endif | | 87 | #endif |
79 | seed = (ldata[0]) + (ldata[1] << 16); | | 88 | seed = (ldata[0]) + (ldata[1] << 16); |
80 | srand (seed); | | 89 | srand (seed); |
81 | for (i = 0; i < len; i++) | | 90 | for (i = 0; i < len; i++) |
82 | { | | 91 | { |
83 | value = rand (); | | 92 | value = rand (); |
84 | auth[i] = value & 0xff; | | 93 | auth[i] = value & 0xff; |
85 | } | | 94 | } |
| | | 95 | #endif |
86 | auth[len] = '\0'; | | 96 | auth[len] = '\0'; |
87 | | | | |
88 | return (auth); | | 97 | return (auth); |
89 | } | | 98 | } |
90 | | | 99 | |
91 | | | 100 | |
92 | | | 101 | |
93 | IcePoAuthStatus | | 102 | IcePoAuthStatus |
94 | _IcePoMagicCookie1Proc (iceConn, authStatePtr, cleanUp, swap, | | 103 | _IcePoMagicCookie1Proc (iceConn, authStatePtr, cleanUp, swap, |
95 | authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet) | | 104 | authDataLen, authData, replyDataLenRet, replyDataRet, errorStringRet) |
96 | | | 105 | |
97 | IceConn iceConn; | | 106 | IceConn iceConn; |
98 | IcePointer *authStatePtr; | | 107 | IcePointer *authStatePtr; |
99 | Bool cleanUp; | | 108 | Bool cleanUp; |
100 | Bool swap; | | 109 | Bool swap; |