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"
51 MitAddCookie(unsigned short data_length
, const char *data
, XID id
)
55 new = malloc(sizeof(struct auth
));
58 new->data
= malloc((unsigned) data_length
);
65 memmove(new->data
, data
, (int) data_length
);
66 new->len
= data_length
;
72 MitCheckCookie(unsigned short data_length
,
73 const char *data
, ClientPtr client
, const char **reason
)
77 for (auth
= mit_auth
; auth
; auth
= auth
->next
) {
78 if (data_length
== auth
->len
&&
79 memcmp(data
, auth
->data
, (int) data_length
) == 0)
82 *reason
= "Invalid MIT-MAGIC-COOKIE-1 key";
89 struct auth
*auth
, *next
;
91 for (auth
= mit_auth
; auth
; auth
= next
) {
101 MitToID(unsigned short data_length
, char *data
)
105 for (auth
= mit_auth
; auth
; auth
= auth
->next
) {
106 if (data_length
== auth
->len
&&
107 memcmp(data
, auth
->data
, data_length
) == 0)
114 MitFromID(XID id
, unsigned short *data_lenp
, char **datap
)
118 for (auth
= mit_auth
; auth
; auth
= auth
->next
) {
119 if (id
== auth
->id
) {
120 *data_lenp
= auth
->len
;
129 MitRemoveCookie(unsigned short data_length
, const char *data
)
131 struct auth
*auth
, *prev
;
134 for (auth
= mit_auth
; auth
; prev
= auth
, auth
= auth
->next
) {
135 if (data_length
== auth
->len
&&
136 memcmp(data
, auth
->data
, data_length
) == 0) {
138 prev
->next
= auth
->next
;
140 mit_auth
= auth
->next
;
151 static char cookie
[16]; /* 128 bits */
154 MitGenerateCookie(unsigned data_length
,
156 XID id
, unsigned *data_length_return
, char **data_return
)
161 while (data_length
--) {
162 cookie
[i
++] += *data
++;
163 if (i
>= sizeof(cookie
))
166 GenerateRandomData(sizeof(cookie
), cookie
);
167 status
= MitAddCookie(sizeof(cookie
), cookie
, id
);
172 *data_return
= cookie
;
173 *data_length_return
= sizeof(cookie
);
178 #endif /* XCSECURITY */