dtdocbook: Coverity 86763
[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 libraries 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 #if NeedWidePrototypes
96 int MitInitAuth (unsigned int name_len, char *name)
97 #else
98 int MitInitAuth (unsigned short name_len, char *name)
99 #endif /* NeedWidePrototypes */
100 {
101     if (name_len > 256)
102         name_len = 256;
103     auth_name_len = name_len;
104     memmove( auth_name, name, name_len);
105     return(0);
106 }
107
108 #if NeedWidePrototypes
109 Xauth *
110 MitGetAuth (unsigned int namelen, char *name)
111 #else
112 Xauth *
113 MitGetAuth (unsigned short namelen, char *name)
114 #endif /* NeedWidePrototypes */
115 {
116     Xauth   *new;
117     new = (Xauth *) malloc (sizeof (Xauth));
118
119     if (!new)
120         return (Xauth *) 0;
121     new->family = FamilyWild;
122     new->address_length = 0;
123     new->address = 0;
124     new->number_length = 0;
125     new->number = 0;
126
127     new->data = (char *) malloc (AUTH_DATA_LEN);
128     if (!new->data)
129     {
130         free ((char *) new);
131         return (Xauth *) 0;
132     }
133     new->name = (char *) malloc (namelen);
134     if (!new->name)
135     {
136         free ((char *) new->data);
137         free ((char *) new);
138         return (Xauth *) 0;
139     }
140     memmove( (char *)new->name, name, namelen);
141     new->name_length = namelen;
142     GenerateAuthData (new->data, AUTH_DATA_LEN);
143     new->data_length = AUTH_DATA_LEN;
144     return new;
145 }