Home | History | Annotate | Line # | Download | only in xdm
      1 /*
      2 
      3 Copyright 1988, 1998  The Open Group
      4 
      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
      9 documentation.
     10 
     11 The above copyright notice and this permission notice shall be included
     12 in all copies or substantial portions of the Software.
     13 
     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.
     21 
     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
     25 from The Open Group.
     26 
     27 */
     28 
     29 /*
     30  * xdm - display manager daemon
     31  * Author:  Keith Packard, MIT X Consortium
     32  *
     33  * mitauth
     34  *
     35  * generate authorization keys
     36  * for MIT-MAGIC-COOKIE-1 type authorization
     37  */
     38 
     39 #include   <X11/Xos.h>
     40 
     41 #include   "dm.h"
     42 #include   "dm_auth.h"
     43 
     44 #define AUTH_DATA_LEN	16	/* bytes of authorization data */
     45 static char	auth_name[256];
     46 
     47 void
     48 MitInitAuth (unsigned short name_len, char *name)
     49 {
     50     if (name_len > 256)
     51 	name_len = 256;
     52     memmove( auth_name, name, name_len);
     53 }
     54 
     55 Xauth *
     56 MitGetAuth (unsigned short namelen, char *name)
     57 {
     58     Xauth   *new;
     59     new = malloc (sizeof (Xauth));
     60 
     61     if (!new)
     62 	return (Xauth *) 0;
     63     new->family = FamilyWild;
     64     new->address_length = 0;
     65     new->address = NULL;
     66     new->number_length = 0;
     67     new->number = NULL;
     68 
     69     new->data = malloc (AUTH_DATA_LEN);
     70     if (!new->data)
     71     {
     72 	free (new);
     73 	return (Xauth *) 0;
     74     }
     75     new->name = malloc (namelen);
     76     if (!new->name)
     77     {
     78 	free (new->data);
     79 	free (new);
     80 	return (Xauth *) 0;
     81     }
     82     memcpy(new->name, name, namelen);
     83     new->name_length = namelen;
     84     if (!GenerateAuthData (new->data, AUTH_DATA_LEN))
     85     {
     86 	free (new->name);
     87 	free (new->data);
     88 	free (new);
     89 	return (Xauth *) 0;
     90     }
     91     new->data_length = AUTH_DATA_LEN;
     92     return new;
     93 }
     94