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