3
Copyright 1988, 1998 The Open Group
5
Permission to use, copy, modify, distribute, and sell this software and its
6
documentation for any purpose is hereby granted without fee, provided that
7
the above copyright notice appear in all copies and that both that
8
copyright notice and this permission notice appear in supporting
11
The above copyright notice and this permission notice shall be included
12
in all copies or substantial portions of the Software.
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
OTHER DEALINGS IN THE SOFTWARE.
22
Except as contained in this notice, the name of The Open Group shall
23
not be used in advertising or otherwise to promote the sale, use or
24
other dealings in this Software without prior written authorization
29
* xdm - display manager daemon
30
* Author: Keith Packard, MIT X Consortium
34
* generate authorization data for XDM-AUTHORIZATION-1 as per XDMCP spec
43
static char auth_name[256];
44
static int auth_name_len;
47
XdmPrintDataHex (char *s, char *a, int l)
52
for (i = 0; i < l; i++)
53
Debug (" %02x", a[i] & 0xff);
59
XdmPrintArray8Hex (char *s, ARRAY8Ptr a)
61
XdmPrintDataHex (s, (char *) a->data, a->length);
66
XdmInitAuth (unsigned short name_len, char *name)
70
auth_name_len = name_len;
71
memmove( auth_name, name, name_len);
75
* Generate authorization for XDM-AUTHORIZATION-1
77
* When being used with XDMCP, 8 bytes are generated for the session key
78
* (sigma), as the random number (rho) is already shared between xdm and
79
* the server. Otherwise, we'll prepend a random number to pass in the file
80
* between xdm and the server (16 bytes total)
84
XdmGetAuthHelper (unsigned short namelen, char *name, int includeRho)
87
new = (Xauth *) malloc (sizeof (Xauth));
91
new->family = FamilyWild;
92
new->address_length = 0;
94
new->number_length = 0;
97
new->data_length = 16;
101
new->data = (char *) malloc (new->data_length);
107
new->name = (char *) malloc (namelen);
110
free ((char *) new->data);
114
memmove( (char *)new->name, name, namelen);
115
new->name_length = namelen;
116
if (!GenerateAuthData ((char *)new->data, new->data_length))
118
free ((char *) new->name);
119
free ((char *) new->data);
124
* set the first byte of the session key to zero as it
125
* is a DES key and only uses 56 bits
127
((char *)new->data)[new->data_length - 8] = '\0';
128
XdmPrintDataHex ("Local server auth", (char *)new->data, new->data_length);
133
XdmGetAuth (unsigned short namelen, char *name)
135
return XdmGetAuthHelper (namelen, name, TRUE);
141
XdmGetXdmcpAuth (struct protoDisplay *pdpy,
142
unsigned short authorizationNameLen, char *authorizationName)
144
Xauth *fileauth, *xdmcpauth;
146
if (pdpy->fileAuthorization && pdpy->xdmcpAuthorization)
148
xdmcpauth = XdmGetAuthHelper (authorizationNameLen, authorizationName, FALSE);
151
fileauth = (Xauth *) malloc (sizeof (Xauth));
154
XauDisposeAuth(xdmcpauth);
157
/* build the file auth from the XDMCP auth */
158
*fileauth = *xdmcpauth;
159
fileauth->name = malloc (xdmcpauth->name_length);
160
fileauth->data = malloc (16);
161
fileauth->data_length = 16;
162
if (!fileauth->name || !fileauth->data)
164
XauDisposeAuth (xdmcpauth);
166
free ((char *) fileauth->name);
168
free ((char *) fileauth->data);
169
free ((char *) fileauth);
173
* for the file authorization, prepend the random number (rho)
174
* which is simply the number we've been passing back and
177
memmove( fileauth->name, xdmcpauth->name, xdmcpauth->name_length);
178
memmove( fileauth->data, pdpy->authenticationData.data, 8);
179
memmove( fileauth->data + 8, xdmcpauth->data, 8);
180
XdmPrintDataHex ("Accept packet auth", xdmcpauth->data, xdmcpauth->data_length);
181
XdmPrintDataHex ("Auth file auth", fileauth->data, fileauth->data_length);
182
/* encrypt the session key for its trip back to the server */
183
XdmcpWrap ((unsigned char *)xdmcpauth->data, (unsigned char *)&pdpy->key,
184
(unsigned char *)xdmcpauth->data, 8);
185
pdpy->fileAuthorization = fileauth;
186
pdpy->xdmcpAuthorization = xdmcpauth;
189
# define atox(c) ('0' <= c && c <= '9' ? c - '0' : \
190
'a' <= c && c <= 'f' ? c - 'a' + 10 : \
191
'A' <= c && c <= 'F' ? c - 'A' + 10 : -1)
194
HexToBinary(char *key)
201
while (in[0] && in[1])
206
bottom = atox(in[1]);
209
*out++ = (top << 4) | bottom;
219
* Search the Keys file for the entry matching this display. This
220
* routine accepts either plain ascii strings for keys, or hex-encoded numbers
224
XdmGetKey(struct protoDisplay *pdpy, ARRAY8Ptr displayID)
227
char line[1024], id[1024], key[1024];
230
Debug ("Lookup key for %*.*s\n", displayID->length, displayID->length, displayID->data);
231
keys = fopen (keyFile, "r");
234
while (fgets (line, sizeof (line) - 1, keys))
236
if (line[0] == '#' || sscanf (line, "%s %s", id, key) != 2)
238
bzero(line, sizeof(line));
239
Debug ("Key entry for \"%s\" %d bytes\n", id, strlen(key));
240
if (strlen (id) == displayID->length &&
241
!strncmp (id, (char *)displayID->data, displayID->length))
243
if (!strncmp (key, "0x", 2) || !strncmp (key, "0X", 2))
244
if (!HexToBinary (key))
246
keylen = strlen (key);
248
key[keylen++] = '\0';
249
pdpy->key.data[0] = '\0';
250
memmove( pdpy->key.data + 1, key, 7);
251
bzero(key, sizeof(key));
256
bzero(line, sizeof(line));
257
bzero(key, sizeof(key));
264
XdmCheckAuthentication(struct protoDisplay *pdpy, ARRAY8Ptr displayID,
265
ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData)
267
XdmAuthKeyPtr incoming;
269
if (!XdmGetKey (pdpy, displayID))
271
if (authenticationData->length != 8)
273
XdmcpUnwrap (authenticationData->data, (unsigned char *)&pdpy->key,
274
authenticationData->data, 8);
275
XdmPrintArray8Hex ("Request packet auth", authenticationData);
276
if (!XdmcpCopyARRAY8(authenticationData, &pdpy->authenticationData))
278
incoming = (XdmAuthKeyPtr) authenticationData->data;
279
XdmcpIncrementKey (incoming);
280
XdmcpWrap (authenticationData->data, (unsigned char *)&pdpy->key,
281
authenticationData->data, 8);
286
#endif /* HASXDMAUTH (covering the entire file) */