mitauth.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. void GenerateAuthData (char *auth, int len); // genauth.c
  85. #if NeedWidePrototypes
  86. int MitInitAuth (unsigned int name_len, char *name)
  87. #else
  88. int MitInitAuth (unsigned short name_len, char *name)
  89. #endif /* NeedWidePrototypes */
  90. {
  91. if (name_len > 256)
  92. name_len = 256;
  93. auth_name_len = name_len;
  94. memmove( auth_name, name, name_len);
  95. return(0);
  96. }
  97. #if NeedWidePrototypes
  98. Xauth *
  99. MitGetAuth (unsigned int namelen, char *name)
  100. #else
  101. Xauth *
  102. MitGetAuth (unsigned short namelen, char *name)
  103. #endif /* NeedWidePrototypes */
  104. {
  105. Xauth *new;
  106. new = (Xauth *) malloc (sizeof (Xauth));
  107. if (!new)
  108. return (Xauth *) 0;
  109. new->family = FamilyWild;
  110. new->address_length = 0;
  111. new->address = 0;
  112. new->number_length = 0;
  113. new->number = 0;
  114. new->data = (char *) malloc (AUTH_DATA_LEN);
  115. if (!new->data)
  116. {
  117. free ((char *) new);
  118. return (Xauth *) 0;
  119. }
  120. new->name = (char *) malloc (namelen);
  121. if (!new->name)
  122. {
  123. free ((char *) new->data);
  124. free ((char *) new);
  125. return (Xauth *) 0;
  126. }
  127. memmove( (char *)new->name, name, namelen);
  128. new->name_length = namelen;
  129. GenerateAuthData (new->data, AUTH_DATA_LEN);
  130. new->data_length = AUTH_DATA_LEN;
  131. return new;
  132. }