setauth.c revision c5629e66
1/* $Xorg: setauth.c,v 1.4 2001/02/09 02:03:26 xorgcvs Exp $ */
2/******************************************************************************
3
4
5Copyright 1993, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of The Open Group shall not be
24used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from The Open Group.
26
27Author: Ralph Mor, X Consortium
28******************************************************************************/
29/* $XFree86: xc/lib/ICE/setauth.c,v 1.4 2001/12/14 19:53:36 dawes Exp $ */
30
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34#include <X11/ICE/ICElib.h>
35#include "ICElibint.h"
36#include <X11/ICE/ICEutil.h>
37
38
39/*
40 * IceSetPaAuthData is not a standard part of ICElib, it is specific
41 * to the sample implementation.
42 *
43 * For the client that initiates a Protocol Setup, we look in the
44 * .ICEauthority file to get authentication data.
45 *
46 * For the client accepting the Protocol Setup, we get the data
47 * from an in-memory database of authentication data (set by the
48 * application calling IceSetPaAuthData).  We have to get the data
49 * from memory because getting it directly from the .ICEauthority
50 * file is not secure - someone can just modify the contents of the
51 * .ICEauthority file behind our back.
52 */
53
54int		 _IcePaAuthDataEntryCount = 0;
55#ifndef __UNIXOS2__
56IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES];
57#else
58IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES] = {0};
59#endif
60
61
62void
63IceSetPaAuthData (
64	int			numEntries,
65	IceAuthDataEntry	*entries
66)
67{
68    /*
69     * _IcePaAuthDataEntries should really be a linked list.
70     * On my list of TO DO stuff.
71     */
72
73    int i, j;
74
75    for (i = 0; i < numEntries; i++)
76    {
77	for (j = 0; j < _IcePaAuthDataEntryCount; j++)
78	    if (strcmp (entries[i].protocol_name,
79		_IcePaAuthDataEntries[j].protocol_name) == 0 &&
80                strcmp (entries[i].network_id,
81		_IcePaAuthDataEntries[j].network_id) == 0 &&
82                strcmp (entries[i].auth_name,
83		_IcePaAuthDataEntries[j].auth_name) == 0)
84		break;
85
86	if (j < _IcePaAuthDataEntryCount)
87	{
88	    free (_IcePaAuthDataEntries[j].protocol_name);
89	    free (_IcePaAuthDataEntries[j].network_id);
90	    free (_IcePaAuthDataEntries[j].auth_name);
91	    free (_IcePaAuthDataEntries[j].auth_data);
92	}
93	else
94	{
95	    _IcePaAuthDataEntryCount++;
96	}
97
98	_IcePaAuthDataEntries[j].protocol_name
99	    = strdup(entries[i].protocol_name);
100
101	_IcePaAuthDataEntries[j].network_id
102	    = strdup(entries[i].network_id);
103
104	_IcePaAuthDataEntries[j].auth_name
105            = strdup(entries[i].auth_name);
106
107	_IcePaAuthDataEntries[j].auth_data_length =
108            entries[i].auth_data_length;
109	_IcePaAuthDataEntries[j].auth_data = (char *) malloc (
110            entries[i].auth_data_length);
111	memcpy (_IcePaAuthDataEntries[j].auth_data,
112            entries[i].auth_data, entries[i].auth_data_length);
113    }
114}
115