mitauth.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * @DEC_COPYRIGHT@
  33. */
  34. /*
  35. * HISTORY
  36. * $Log$
  37. * Revision 1.1.2.2 1995/04/21 13:05:26 Peter_Derr
  38. * dtlogin auth key fixes from deltacde
  39. * [1995/04/12 19:21:06 Peter_Derr]
  40. *
  41. * R6 xdm code with minor changes used in dtlogin to handle multiple
  42. * authorizations.
  43. * [1995/04/12 18:05:42 Peter_Derr]
  44. *
  45. * $EndLog$
  46. */
  47. /*
  48. Copyright (c) 1988 X Consortium
  49. Permission is hereby granted, free of charge, to any person obtaining
  50. a copy of this software and associated documentation files (the
  51. "Software"), to deal in the Software without restriction, including
  52. without limitation the rights to use, copy, modify, merge, publish,
  53. distribute, sublicense, and/or sell copies of the Software, and to
  54. permit persons to whom the Software is furnished to do so, subject to
  55. the following conditions:
  56. The above copyright notice and this permission notice shall be included
  57. in all copies or substantial portions of the Software.
  58. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  59. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  60. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  61. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
  62. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  63. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  64. OTHER DEALINGS IN THE SOFTWARE.
  65. Except as contained in this notice, the name of the X Consortium shall
  66. not be used in advertising or otherwise to promote the sale, use or
  67. other dealings in this Software without prior written authorization
  68. from the X Consortium.
  69. */
  70. /*
  71. * xdm - display manager daemon
  72. * Author: Keith Packard, MIT X Consortium
  73. *
  74. * mitauth
  75. *
  76. * generate authorization keys
  77. * for MIT-MAGIC-COOKIE-1 type authorization
  78. */
  79. # include <X11/Xos.h>
  80. # include "dm.h"
  81. # define AUTH_DATA_LEN 16 /* bytes of authorization data */
  82. static char auth_name[256];
  83. static int auth_name_len;
  84. #if NeedWidePrototypes
  85. int MitInitAuth (unsigned int name_len, char *name)
  86. #else
  87. int MitInitAuth (unsigned short name_len, char *name)
  88. #endif /* NeedWidePrototypes */
  89. {
  90. if (name_len > 256)
  91. name_len = 256;
  92. auth_name_len = name_len;
  93. memmove( auth_name, name, name_len);
  94. return(0);
  95. }
  96. #if NeedWidePrototypes
  97. Xauth *
  98. MitGetAuth (unsigned int namelen, char *name)
  99. #else
  100. Xauth *
  101. MitGetAuth (unsigned short namelen, char *name)
  102. #endif /* NeedWidePrototypes */
  103. {
  104. Xauth *new;
  105. new = (Xauth *) malloc (sizeof (Xauth));
  106. if (!new)
  107. return (Xauth *) 0;
  108. new->family = FamilyWild;
  109. new->address_length = 0;
  110. new->address = 0;
  111. new->number_length = 0;
  112. new->number = 0;
  113. new->data = (char *) malloc (AUTH_DATA_LEN);
  114. if (!new->data)
  115. {
  116. free ((char *) new);
  117. return (Xauth *) 0;
  118. }
  119. new->name = (char *) malloc (namelen);
  120. if (!new->name)
  121. {
  122. free ((char *) new->data);
  123. free ((char *) new);
  124. return (Xauth *) 0;
  125. }
  126. memmove( (char *)new->name, name, namelen);
  127. new->name_length = namelen;
  128. GenerateAuthData (new->data, AUTH_DATA_LEN);
  129. new->data_length = AUTH_DATA_LEN;
  130. return new;
  131. }