|
|
| 1 |
#ifdef HAVE_XWIN_CONFIG_H |
|
|
| 2 |
#include <xwin-config.h> |
| 3 |
#endif |
| 4 |
#if defined(XCSECURITY) |
| 5 |
/* |
1 |
/* |
| 6 |
*Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. |
2 |
*Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. |
| 7 |
* |
3 |
* |
|
|
| 32 |
* Authors: Harold L Hunt II |
28 |
* Authors: Harold L Hunt II |
| 33 |
*/ |
29 |
*/ |
| 34 |
|
30 |
|
|
|
31 |
#ifdef HAVE_XWIN_CONFIG_H |
| 32 |
#include <xwin-config.h> |
| 33 |
#endif |
| 34 |
|
| 35 |
#include "win.h" |
35 |
#include "win.h" |
| 36 |
|
36 |
|
| 37 |
/* Includes for authorization */ |
37 |
/* Includes for authorization */ |
| 38 |
#include <X11/Xauth.h> |
|
|
| 39 |
#include "securitysrv.h" |
38 |
#include "securitysrv.h" |
| 40 |
#include <X11/extensions/securstr.h> |
|
|
| 41 |
|
39 |
|
| 42 |
|
40 |
|
| 43 |
/* |
41 |
/* |
|
|
| 48 |
|
46 |
|
| 49 |
|
47 |
|
| 50 |
/* |
48 |
/* |
| 51 |
* Globals |
49 |
* Locals |
|
|
50 |
*/ |
| 51 |
|
| 52 |
static XID g_authId = 0; |
| 53 |
static unsigned int g_uiAuthDataLen = 0; |
| 54 |
static char *g_pAuthData = NULL; |
| 55 |
|
| 56 |
/* |
| 57 |
* Code to generate a MIT-MAGIC-COOKIE-1, copied from under XCSECURITY |
| 52 |
*/ |
58 |
*/ |
| 53 |
|
59 |
|
| 54 |
XID g_authId = 0; |
60 |
#ifndef XCSECURITY |
| 55 |
unsigned int g_uiAuthDataLen = 0; |
61 |
static |
| 56 |
char *g_pAuthData = NULL; |
62 |
void |
|
|
63 |
GenerateRandomData (int len, char *buf) |
| 64 |
{ |
| 65 |
int fd; |
| 66 |
|
| 67 |
fd = open("/dev/urandom", O_RDONLY); |
| 68 |
read(fd, buf, len); |
| 69 |
close(fd); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
static char cookie[16]; /* 128 bits */ |
| 74 |
|
| 75 |
XID |
| 76 |
static MitGenerateCookie ( |
| 77 |
unsigned data_length, |
| 78 |
char *data, |
| 79 |
XID id, |
| 80 |
unsigned *data_length_return, |
| 81 |
char **data_return) |
| 82 |
{ |
| 83 |
int i = 0; |
| 84 |
int status; |
| 85 |
|
| 86 |
while (data_length--) |
| 87 |
{ |
| 88 |
cookie[i++] += *data++; |
| 89 |
if (i >= sizeof (cookie)) i = 0; |
| 90 |
} |
| 91 |
GenerateRandomData(sizeof (cookie), cookie); |
| 92 |
status = MitAddCookie(sizeof (cookie), cookie, id); |
| 93 |
if (!status) |
| 94 |
{ |
| 95 |
id = -1; |
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
*data_return = cookie; |
| 100 |
*data_length_return = sizeof (cookie); |
| 101 |
} |
| 102 |
return id; |
| 103 |
} |
| 57 |
|
104 |
|
|
|
105 |
static |
| 106 |
XID |
| 107 |
GenerateAuthorization( |
| 108 |
unsigned name_length, |
| 109 |
char *name, |
| 110 |
unsigned data_length, |
| 111 |
char *data, |
| 112 |
unsigned *data_length_return, |
| 113 |
char **data_return) |
| 114 |
{ |
| 115 |
return MitGenerateCookie(data_length, data, |
| 116 |
FakeClientID(0), data_length_return, data_return); |
| 117 |
} |
| 118 |
#endif |
| 58 |
|
119 |
|
| 59 |
/* |
120 |
/* |
| 60 |
* Generate authorization cookie for internal server clients |
121 |
* Generate authorization cookie for internal server clients |
|
Lines 78-92
winGenerateAuthorization ()
|
Link Here
|
|---|
|
| 78 |
ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n"); |
139 |
ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n"); |
| 79 |
goto auth_bailout; |
140 |
goto auth_bailout; |
| 80 |
} |
141 |
} |
| 81 |
#if 0 |
142 |
|
| 82 |
else |
143 |
else |
| 83 |
{ |
144 |
{ |
| 84 |
ErrorF ("winGenerateAuthorization - GenerateAuthorization success!\n" |
145 |
winDebug("winGenerateAuthorization - GenerateAuthorization success!\n" |
| 85 |
"AuthDataLen: %d AuthData: %s\n", |
146 |
"AuthDataLen: %d AuthData: %s\n", |
| 86 |
g_uiAuthDataLen, g_pAuthData); |
147 |
g_uiAuthDataLen, g_pAuthData); |
| 87 |
} |
148 |
} |
| 88 |
#endif |
149 |
|
| 89 |
|
150 |
#ifdef XCSECURITY |
| 90 |
/* Allocate structure for additional auth information */ |
151 |
/* Allocate structure for additional auth information */ |
| 91 |
pAuth = (SecurityAuthorizationPtr) |
152 |
pAuth = (SecurityAuthorizationPtr) |
| 92 |
xalloc (sizeof (SecurityAuthorizationRec)); |
153 |
xalloc (sizeof (SecurityAuthorizationRec)); |
|
Lines 119-125
winGenerateAuthorization ()
|
Link Here
|
|---|
|
| 119 |
|
180 |
|
| 120 |
/* Don't free the auth data, since it is still used internally */ |
181 |
/* Don't free the auth data, since it is still used internally */ |
| 121 |
pAuth = NULL; |
182 |
pAuth = NULL; |
| 122 |
|
183 |
#endif |
|
|
184 |
|
| 123 |
return TRUE; |
185 |
return TRUE; |
| 124 |
|
186 |
|
| 125 |
auth_bailout: |
187 |
auth_bailout: |
|
Lines 128-131
winGenerateAuthorization ()
|
Link Here
|
|---|
|
| 128 |
|
190 |
|
| 129 |
return FALSE; |
191 |
return FALSE; |
| 130 |
} |
192 |
} |
| 131 |
#endif |
193 |
|
|
|
194 |
/* Use our generated cookie for authentication */ |
| 195 |
void |
| 196 |
winSetAuthorization(void) |
| 197 |
{ |
| 198 |
XSetAuthorization (AUTH_NAME, |
| 199 |
strlen (AUTH_NAME), |
| 200 |
g_pAuthData, |
| 201 |
g_uiAuthDataLen); |
| 202 |
} |