Xsession.src: setup proper cpp_* defines for linux
[oweals/cde.git] / cde / programs / dtlogin / mitauth.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: mitauth.c /main/7 1997/03/25 12:03:56 barstow $ */
24 /* (c) Copyright 1997 The Open Group */
25 /*                                                                      *
26  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
27  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
28  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
29  * (c) Copyright 1993, 1994 Novell, Inc.                                *
30  */
31
32 /*
33  * @DEC_COPYRIGHT@
34  */
35 /*
36  * HISTORY
37  * $Log$
38  * Revision 1.1.2.2  1995/04/21  13:05:26  Peter_Derr
39  *      dtlogin auth key fixes from deltacde
40  *      [1995/04/12  19:21:06  Peter_Derr]
41  *
42  *      R6 xdm code with minor changes used in dtlogin to handle multiple
43  *      authorizations.
44  *      [1995/04/12  18:05:42  Peter_Derr]
45  *
46  * $EndLog$
47  */
48 /*
49
50 Copyright (c) 1988  X Consortium
51
52 Permission is hereby granted, free of charge, to any person obtaining
53 a copy of this software and associated documentation files (the
54 "Software"), to deal in the Software without restriction, including
55 without limitation the rights to use, copy, modify, merge, publish,
56 distribute, sublicense, and/or sell copies of the Software, and to
57 permit persons to whom the Software is furnished to do so, subject to
58 the following conditions:
59
60 The above copyright notice and this permission notice shall be included
61 in all copies or substantial portions of the Software.
62
63 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
64 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
65 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
66 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
67 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
68 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
69 OTHER DEALINGS IN THE SOFTWARE.
70
71 Except as contained in this notice, the name of the X Consortium shall
72 not be used in advertising or otherwise to promote the sale, use or
73 other dealings in this Software without prior written authorization
74 from the X Consortium.
75
76 */
77
78 /*
79  * xdm - display manager daemon
80  * Author:  Keith Packard, MIT X Consortium
81  *
82  * mitauth
83  *
84  * generate authorization keys
85  * for MIT-MAGIC-COOKIE-1 type authorization
86  */
87
88 # include   <X11/Xos.h>
89 # include   "dm.h"
90
91 # define AUTH_DATA_LEN  16      /* bytes of authorization data */
92 static char     auth_name[256];
93 static int      auth_name_len;
94
95 int MitInitAuth (name_len, name)
96 #if NeedWidePrototypes
97     unsigned int name_len;
98 #else
99     unsigned short name_len;
100 #endif /* NeedWidePrototypes */
101     char *name;
102 {
103     if (name_len > 256)
104         name_len = 256;
105     auth_name_len = name_len;
106     memmove( auth_name, name, name_len);
107     return(0);
108 }
109
110 Xauth *
111 MitGetAuth (namelen, name)
112 #if NeedWidePrototypes
113     unsigned int namelen;
114 #else
115     unsigned short namelen;
116 #endif /* NeedWidePrototypes */
117     char *name;
118 {
119     Xauth   *new;
120     new = (Xauth *) malloc (sizeof (Xauth));
121
122     if (!new)
123         return (Xauth *) 0;
124     new->family = FamilyWild;
125     new->address_length = 0;
126     new->address = 0;
127     new->number_length = 0;
128     new->number = 0;
129
130     new->data = (char *) malloc (AUTH_DATA_LEN);
131     if (!new->data)
132     {
133         free ((char *) new);
134         return (Xauth *) 0;
135     }
136     new->name = (char *) malloc (namelen);
137     if (!new->name)
138     {
139         free ((char *) new->data);
140         free ((char *) new);
141         return (Xauth *) 0;
142     }
143     memmove( (char *)new->name, name, namelen);
144     new->name_length = namelen;
145     GenerateAuthData (new->data, AUTH_DATA_LEN);
146     new->data_length = AUTH_DATA_LEN;
147     return new;
148 }