1629baa8cSmrg/*
2629baa8cSmrg
3629baa8cSmrgCopyright 1988, 1998  The Open Group
4629baa8cSmrg
5629baa8cSmrgPermission to use, copy, modify, distribute, and sell this software and its
6629baa8cSmrgdocumentation for any purpose is hereby granted without fee, provided that
7629baa8cSmrgthe above copyright notice appear in all copies and that both that
8629baa8cSmrgcopyright notice and this permission notice appear in supporting
9629baa8cSmrgdocumentation.
10629baa8cSmrg
11629baa8cSmrgThe above copyright notice and this permission notice shall be included
12629baa8cSmrgin all copies or substantial portions of the Software.
13629baa8cSmrg
14629baa8cSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15629baa8cSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16629baa8cSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17629baa8cSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18629baa8cSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19629baa8cSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20629baa8cSmrgOTHER DEALINGS IN THE SOFTWARE.
21629baa8cSmrg
22629baa8cSmrgExcept as contained in this notice, the name of The Open Group shall
23629baa8cSmrgnot be used in advertising or otherwise to promote the sale, use or
24629baa8cSmrgother dealings in this Software without prior written authorization
25629baa8cSmrgfrom The Open Group.
26629baa8cSmrg
27629baa8cSmrg*/
28629baa8cSmrg
29629baa8cSmrg/*
30629baa8cSmrg * xdm - display manager daemon
31629baa8cSmrg * Author:  Keith Packard, MIT X Consortium
32629baa8cSmrg *
33629baa8cSmrg * mitauth
34629baa8cSmrg *
35629baa8cSmrg * generate authorization keys
36629baa8cSmrg * for MIT-MAGIC-COOKIE-1 type authorization
37629baa8cSmrg */
38629baa8cSmrg
39629baa8cSmrg#include   <X11/Xos.h>
40629baa8cSmrg
41629baa8cSmrg#include   "dm.h"
42629baa8cSmrg#include   "dm_auth.h"
43629baa8cSmrg
44629baa8cSmrg#define AUTH_DATA_LEN	16	/* bytes of authorization data */
45629baa8cSmrgstatic char	auth_name[256];
46629baa8cSmrg
47629baa8cSmrgvoid
48629baa8cSmrgMitInitAuth (unsigned short name_len, char *name)
49629baa8cSmrg{
50629baa8cSmrg    if (name_len > 256)
51629baa8cSmrg	name_len = 256;
52629baa8cSmrg    memmove( auth_name, name, name_len);
53629baa8cSmrg}
54629baa8cSmrg
55629baa8cSmrgXauth *
56629baa8cSmrgMitGetAuth (unsigned short namelen, char *name)
57629baa8cSmrg{
58629baa8cSmrg    Xauth   *new;
59629baa8cSmrg    new = malloc (sizeof (Xauth));
60629baa8cSmrg
61629baa8cSmrg    if (!new)
62629baa8cSmrg	return (Xauth *) 0;
63629baa8cSmrg    new->family = FamilyWild;
64629baa8cSmrg    new->address_length = 0;
65629baa8cSmrg    new->address = NULL;
66629baa8cSmrg    new->number_length = 0;
67629baa8cSmrg    new->number = NULL;
68629baa8cSmrg
69629baa8cSmrg    new->data = malloc (AUTH_DATA_LEN);
70629baa8cSmrg    if (!new->data)
71629baa8cSmrg    {
72629baa8cSmrg	free (new);
73629baa8cSmrg	return (Xauth *) 0;
74629baa8cSmrg    }
75629baa8cSmrg    new->name = malloc (namelen);
76629baa8cSmrg    if (!new->name)
77629baa8cSmrg    {
78629baa8cSmrg	free (new->data);
79629baa8cSmrg	free (new);
80629baa8cSmrg	return (Xauth *) 0;
81629baa8cSmrg    }
82f9f7a7f2Smrg    memcpy(new->name, name, namelen);
83629baa8cSmrg    new->name_length = namelen;
84629baa8cSmrg    if (!GenerateAuthData (new->data, AUTH_DATA_LEN))
85629baa8cSmrg    {
86629baa8cSmrg	free (new->name);
87629baa8cSmrg	free (new->data);
88629baa8cSmrg	free (new);
89629baa8cSmrg	return (Xauth *) 0;
90629baa8cSmrg    }
91629baa8cSmrg    new->data_length = AUTH_DATA_LEN;
92629baa8cSmrg    return new;
93629baa8cSmrg}
94