1266e564dSmrg/******************************************************************************
2266e564dSmrg
3266e564dSmrg
4266e564dSmrgCopyright 1993, 1998  The Open Group
5266e564dSmrg
6266e564dSmrgPermission to use, copy, modify, distribute, and sell this software and its
7266e564dSmrgdocumentation for any purpose is hereby granted without fee, provided that
8266e564dSmrgthe above copyright notice appear in all copies and that both that
9266e564dSmrgcopyright notice and this permission notice appear in supporting
10266e564dSmrgdocumentation.
11266e564dSmrg
12266e564dSmrgThe above copyright notice and this permission notice shall be included in
13266e564dSmrgall copies or substantial portions of the Software.
14266e564dSmrg
15266e564dSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16266e564dSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17266e564dSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18266e564dSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19266e564dSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20266e564dSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21266e564dSmrg
22266e564dSmrgExcept as contained in this notice, the name of The Open Group shall not be
23266e564dSmrgused in advertising or otherwise to promote the sale, use or other dealings
24266e564dSmrgin this Software without prior written authorization from The Open Group.
25266e564dSmrg
26266e564dSmrgAuthor: Ralph Mor, X Consortium
27266e564dSmrg******************************************************************************/
28266e564dSmrg
29266e564dSmrg#ifdef HAVE_CONFIG_H
30266e564dSmrg#include <config.h>
31266e564dSmrg#endif
32266e564dSmrg#include <X11/ICE/ICElib.h>
33266e564dSmrg#include "ICElibint.h"
34266e564dSmrg#include <X11/ICE/ICEutil.h>
35266e564dSmrg
36a3129944Smrg
37266e564dSmrg/*
38266e564dSmrg * IceSetPaAuthData is not a standard part of ICElib, it is specific
39266e564dSmrg * to the sample implementation.
40266e564dSmrg *
41266e564dSmrg * For the client that initiates a Protocol Setup, we look in the
42266e564dSmrg * .ICEauthority file to get authentication data.
43266e564dSmrg *
44266e564dSmrg * For the client accepting the Protocol Setup, we get the data
45266e564dSmrg * from an in-memory database of authentication data (set by the
46266e564dSmrg * application calling IceSetPaAuthData).  We have to get the data
47266e564dSmrg * from memory because getting it directly from the .ICEauthority
48266e564dSmrg * file is not secure - someone can just modify the contents of the
49266e564dSmrg * .ICEauthority file behind our back.
50266e564dSmrg */
51266e564dSmrg
52266e564dSmrgint		 _IcePaAuthDataEntryCount = 0;
53266e564dSmrgIceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES];
54266e564dSmrg
55266e564dSmrg
56266e564dSmrgvoid
57c5629e66SmrgIceSetPaAuthData (
58c5629e66Smrg	int			numEntries,
59c5629e66Smrg	IceAuthDataEntry	*entries
60c5629e66Smrg)
61266e564dSmrg{
62266e564dSmrg    /*
63266e564dSmrg     * _IcePaAuthDataEntries should really be a linked list.
64266e564dSmrg     * On my list of TO DO stuff.
65266e564dSmrg     */
66266e564dSmrg
67266e564dSmrg    int i, j;
68266e564dSmrg
69266e564dSmrg    for (i = 0; i < numEntries; i++)
70266e564dSmrg    {
71266e564dSmrg	for (j = 0; j < _IcePaAuthDataEntryCount; j++)
72266e564dSmrg	    if (strcmp (entries[i].protocol_name,
73266e564dSmrg		_IcePaAuthDataEntries[j].protocol_name) == 0 &&
74266e564dSmrg                strcmp (entries[i].network_id,
75266e564dSmrg		_IcePaAuthDataEntries[j].network_id) == 0 &&
76266e564dSmrg                strcmp (entries[i].auth_name,
77266e564dSmrg		_IcePaAuthDataEntries[j].auth_name) == 0)
78266e564dSmrg		break;
79266e564dSmrg
80266e564dSmrg	if (j < _IcePaAuthDataEntryCount)
81266e564dSmrg	{
82266e564dSmrg	    free (_IcePaAuthDataEntries[j].protocol_name);
83266e564dSmrg	    free (_IcePaAuthDataEntries[j].network_id);
84266e564dSmrg	    free (_IcePaAuthDataEntries[j].auth_name);
85266e564dSmrg	    free (_IcePaAuthDataEntries[j].auth_data);
86266e564dSmrg	}
87266e564dSmrg	else
88266e564dSmrg	{
89266e564dSmrg	    _IcePaAuthDataEntryCount++;
90266e564dSmrg	}
91266e564dSmrg
92266e564dSmrg	_IcePaAuthDataEntries[j].protocol_name
93266e564dSmrg	    = strdup(entries[i].protocol_name);
94266e564dSmrg
95266e564dSmrg	_IcePaAuthDataEntries[j].network_id
96266e564dSmrg	    = strdup(entries[i].network_id);
97266e564dSmrg
98266e564dSmrg	_IcePaAuthDataEntries[j].auth_name
99266e564dSmrg            = strdup(entries[i].auth_name);
100266e564dSmrg
101266e564dSmrg	_IcePaAuthDataEntries[j].auth_data_length =
102266e564dSmrg            entries[i].auth_data_length;
103fb5e8d76Smrg	_IcePaAuthDataEntries[j].auth_data = malloc (
104266e564dSmrg            entries[i].auth_data_length);
105266e564dSmrg	memcpy (_IcePaAuthDataEntries[j].auth_data,
106266e564dSmrg            entries[i].auth_data, entries[i].auth_data_length);
107266e564dSmrg    }
108266e564dSmrg}
109