home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xdm / mitauth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-23  |  2.0 KB  |  80 lines

  1. /*
  2.  * xdm - display manager daemon
  3.  *
  4.  * $XConsortium: mitauth.c,v 1.9 91/07/24 00:06:43 keith Exp $
  5.  *
  6.  * Copyright 1988 Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of M.I.T. not be used in advertising or
  13.  * publicity pertaining to distribution of the software without specific,
  14.  * written prior permission.  M.I.T. makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * Author:  Keith Packard, MIT X Consortium
  19.  */
  20.  
  21. /*
  22.  * mitauth
  23.  *
  24.  * generate authorization keys
  25.  * for MIT-MAGIC-COOKIE-1 type authorization
  26.  */
  27.  
  28. # include   <X11/Xos.h>
  29. # include   "dm.h"
  30.  
  31. # define AUTH_DATA_LEN    16    /* bytes of authorization data */
  32. static char    auth_name[256];
  33. static int    auth_name_len;
  34.  
  35. MitInitAuth (name_len, name)
  36.     unsigned short  name_len;
  37.     char        *name;
  38. {
  39.     if (name_len > 256)
  40.     name_len = 256;
  41.     auth_name_len = name_len;
  42.     bcopy (name, auth_name, name_len);
  43. }
  44.  
  45. Xauth *
  46. MitGetAuth (namelen, name)
  47.     unsigned short  namelen;
  48.     char        *name;
  49. {
  50.     Xauth   *new;
  51.     new = (Xauth *) malloc (sizeof (Xauth));
  52.  
  53.     if (!new)
  54.     return (Xauth *) 0;
  55.     new->family = FamilyWild;
  56.     new->address_length = 0;
  57.     new->address = 0;
  58.     new->number_length = 0;
  59.     new->number = 0;
  60.  
  61.     new->data = (char *) malloc (AUTH_DATA_LEN);
  62.     if (!new->data)
  63.     {
  64.     free ((char *) new);
  65.     return (Xauth *) 0;
  66.     }
  67.     new->name = (char *) malloc (namelen);
  68.     if (!new->name)
  69.     {
  70.     free ((char *) new->data);
  71.     free ((char *) new);
  72.     return (Xauth *) 0;
  73.     }
  74.     bcopy (name, (char *)new->name, namelen);
  75.     new->name_length = namelen;
  76.     GenerateAuthorization (new->data, AUTH_DATA_LEN);
  77.     new->data_length = AUTH_DATA_LEN;
  78.     return new;
  79. }
  80.