1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/ICE/ICElib.h>
33 #include "ICElibint.h"
34 #include <X11/ICE/ICEutil.h>
39 static int was_called_state;
42 * MIT-MAGIC-COOKIE-1 is a sample authentication method implemented by
43 * the SI. It is not part of standard ICElib.
48 IceGenerateMagicCookie (
58 if ((auth = (char *) malloc (len + 1)) == NULL)
64 X_GETTIMEOFDAY (&now);
65 ldata[0] = now.tv_sec;
66 ldata[1] = now.tv_usec;
73 ldata[0] = time ((long *) 0);
77 seed = (ldata[0]) + (ldata[1] << 16);
79 for (i = 0; i < len; i++)
82 auth[i] = value & 0xff;
92 _IcePoMagicCookie1Proc (
94 IcePointer *authStatePtr,
100 IcePointer *replyDataRet,
101 char **errorStringRet
107 * We didn't allocate any state. We're done.
110 return (IcePoAuthDoneCleanup);
113 *errorStringRet = NULL;
115 if (*authStatePtr == NULL)
118 * This is the first time we're being called. Search the
119 * authentication data for the first occurence of
120 * MIT-MAGIC-COOKIE-1 that matches iceConn->connection_string.
123 unsigned short length;
126 _IceGetPoAuthData ("ICE", iceConn->connection_string,
127 "MIT-MAGIC-COOKIE-1", &length, &data);
131 const char *tempstr =
132 "Could not find correct MIT-MAGIC-COOKIE-1 authentication";
134 *errorStringRet = strdup(tempstr);
136 return (IcePoAuthFailed);
140 *authStatePtr = (IcePointer) &was_called_state;
142 *replyDataLenRet = length;
143 *replyDataRet = data;
145 return (IcePoAuthHaveReply);
151 * We should never get here for MIT-MAGIC-COOKIE-1 since it is
152 * a single pass authentication method.
155 const char *tempstr =
156 "MIT-MAGIC-COOKIE-1 authentication internal error";
158 *errorStringRet = strdup(tempstr);
160 return (IcePoAuthFailed);
164 IcePoAuthProc _IcePoAuthProcs[] = {_IcePoMagicCookie1Proc};
168 _IcePaMagicCookie1Proc (
170 IcePointer *authStatePtr,
174 int *replyDataLenRet,
175 IcePointer *replyDataRet,
176 char **errorStringRet
179 *errorStringRet = NULL;
180 *replyDataLenRet = 0;
181 *replyDataRet = NULL;
183 if (*authStatePtr == NULL)
186 * This is the first time we're being called. We don't have
187 * any data to pass to the other client.
190 *authStatePtr = (IcePointer) &was_called_state;
192 return (IcePaAuthContinue);
197 * Search the authentication data for the first occurence of
198 * MIT-MAGIC-COOKIE-1 that matches iceConn->connection_string.
201 unsigned short length;
204 _IceGetPaAuthData ("ICE", iceConn->connection_string,
205 "MIT-MAGIC-COOKIE-1", &length, &data);
209 IcePaAuthStatus stat;
211 if (authDataLen == length &&
212 memcmp (authData, data, authDataLen) == 0)
214 stat = IcePaAuthAccepted;
219 = "MIT-MAGIC-COOKIE-1 authentication rejected";
221 *errorStringRet = strdup(tempstr);
223 stat = IcePaAuthRejected;
232 * We should never get here because in the ConnectionReply
233 * we should have passed all the valid methods. So we should
234 * always find a valid entry.
237 const char *tempstr =
238 "MIT-MAGIC-COOKIE-1 authentication internal error";
240 *errorStringRet = strdup(tempstr);
242 return (IcePaAuthFailed);
247 IcePaAuthProc _IcePaAuthProcs[] = {_IcePaMagicCookie1Proc};