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