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
30 * MIT-MAGIC-COOKIE-1 authorization scheme
31 * Author: Keith Packard, MIT X Consortium
34 #ifdef HAVE_DIX_CONFIG_H
35 #include <dix-config.h>
41 #include "dixstruct.h"
52 unsigned short data_length
,
58 new = (struct auth
*) xalloc (sizeof (struct auth
));
61 new->data
= (char *) xalloc ((unsigned) data_length
);
68 memmove(new->data
, data
, (int) data_length
);
69 new->len
= data_length
;
76 unsigned short data_length
,
83 for (auth
= mit_auth
; auth
; auth
=auth
->next
) {
84 if (data_length
== auth
->len
&&
85 memcmp (data
, auth
->data
, (int) data_length
) == 0)
88 *reason
= "Invalid MIT-MAGIC-COOKIE-1 key";
95 struct auth
*auth
, *next
;
97 for (auth
= mit_auth
; auth
; auth
=next
) {
108 unsigned short data_length
,
113 for (auth
= mit_auth
; auth
; auth
=auth
->next
) {
114 if (data_length
== auth
->len
&&
115 memcmp (data
, auth
->data
, data_length
) == 0)
124 unsigned short *data_lenp
,
129 for (auth
= mit_auth
; auth
; auth
=auth
->next
) {
130 if (id
== auth
->id
) {
131 *data_lenp
= auth
->len
;
141 unsigned short data_length
,
144 struct auth
*auth
, *prev
;
147 for (auth
= mit_auth
; auth
; prev
= auth
, auth
=auth
->next
) {
148 if (data_length
== auth
->len
&&
149 memcmp (data
, auth
->data
, data_length
) == 0)
152 prev
->next
= auth
->next
;
154 mit_auth
= auth
->next
;
165 static char cookie
[16]; /* 128 bits */
169 unsigned data_length
,
172 unsigned *data_length_return
,
178 while (data_length
--)
180 cookie
[i
++] += *data
++;
181 if (i
>= sizeof (cookie
)) i
= 0;
183 GenerateRandomData(sizeof (cookie
), cookie
);
184 status
= MitAddCookie(sizeof (cookie
), cookie
, id
);
191 *data_return
= cookie
;
192 *data_length_return
= sizeof (cookie
);
197 #endif /* XCSECURITY */