aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xwin/winauth.c
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/hw/xwin/winauth.c')
-rw-r--r--xorg-server/hw/xwin/winauth.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/xorg-server/hw/xwin/winauth.c b/xorg-server/hw/xwin/winauth.c
index 7efa1c00f..4e6c3814f 100644
--- a/xorg-server/hw/xwin/winauth.c
+++ b/xorg-server/hw/xwin/winauth.c
@@ -32,6 +32,10 @@
#include <xwin-config.h>
#endif
+#define GC X11_GC /* To avoid compilation errors later when including win.h (which also defines the GC type) */
+#include <X11/Xlib.h>
+#undef GC
+
#include "win.h"
/* Includes for authorization */
@@ -56,15 +60,28 @@ static char *g_pAuthData = NULL;
* Code to generate a MIT-MAGIC-COOKIE-1, copied from under XCSECURITY
*/
+
+
#ifndef XCSECURITY
void
GenerateRandomData(int len, char *buf)
{
int fd;
-
+#ifdef _MSC_VER
+ static HANDLE hAdvApi32;
+ static BOOLEAN (_stdcall * RtlGenRandom)(void *,unsigned long);
+
+ if (!hAdvApi32)
+ {
+ hAdvApi32=LoadLibrary("advapi32.dll");
+ RtlGenRandom=(BOOLEAN (_stdcall *)(void*,unsigned long))GetProcAddress(hAdvApi32,"SystemFunction036");
+ }
+ RtlGenRandom(buf, len);
+#else
fd = open("/dev/urandom", O_RDONLY);
read(fd, buf, len);
close(fd);
+#endif
}
static char cookie[16]; /* 128 bits */
@@ -114,7 +131,6 @@ GenerateAuthorization(unsigned name_length,
Bool
winGenerateAuthorization(void)
{
- Bool fFreeAuth = FALSE;
SecurityAuthorizationPtr pAuth = NULL;
/* Call OS layer to generate authorization key */
@@ -125,12 +141,13 @@ winGenerateAuthorization(void)
ErrorF("winGenerateAuthorization - GenerateAuthorization failed\n");
goto auth_bailout;
}
-
+#ifdef WINDBG
else {
winDebug("winGenerateAuthorization - GenerateAuthorization success!\n"
"AuthDataLen: %d AuthData: %s\n",
g_uiAuthDataLen, g_pAuthData);
}
+#endif
#ifdef XCSECURITY
/* Allocate structure for additional auth information */
@@ -155,19 +172,16 @@ winGenerateAuthorization(void)
/* Add the authorization to the server's auth list */
if (!AddResource(g_authId, SecurityAuthorizationResType, pAuth)) {
ErrorF("winGenerateAuthorization - AddResource failed for auth.\n");
- fFreeAuth = TRUE;
goto auth_bailout;
}
/* Don't free the auth data, since it is still used internally */
- pAuth = NULL;
#endif
return TRUE;
auth_bailout:
- if (fFreeAuth)
- free(pAuth);
+ free(pAuth);
return FALSE;
}
@@ -176,6 +190,7 @@ winGenerateAuthorization(void)
void
winSetAuthorization(void)
{
+ if (g_pAuthData)
XSetAuthorization(AUTH_NAME,
strlen(AUTH_NAME), g_pAuthData, g_uiAuthDataLen);
}