Blame src/setauth.c

Packit e18bd3
/******************************************************************************
Packit e18bd3
Packit e18bd3
Packit e18bd3
Copyright 1993, 1998  The Open Group
Packit e18bd3
Packit e18bd3
Permission to use, copy, modify, distribute, and sell this software and its
Packit e18bd3
documentation for any purpose is hereby granted without fee, provided that
Packit e18bd3
the above copyright notice appear in all copies and that both that
Packit e18bd3
copyright notice and this permission notice appear in supporting
Packit e18bd3
documentation.
Packit e18bd3
Packit e18bd3
The above copyright notice and this permission notice shall be included in
Packit e18bd3
all copies or substantial portions of the Software.
Packit e18bd3
Packit e18bd3
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Packit e18bd3
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Packit e18bd3
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
Packit e18bd3
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
Packit e18bd3
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit e18bd3
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit e18bd3
Packit e18bd3
Except as contained in this notice, the name of The Open Group shall not be
Packit e18bd3
used in advertising or otherwise to promote the sale, use or other dealings
Packit e18bd3
in this Software without prior written authorization from The Open Group.
Packit e18bd3
Packit e18bd3
Author: Ralph Mor, X Consortium
Packit e18bd3
******************************************************************************/
Packit e18bd3
Packit e18bd3
#ifdef HAVE_CONFIG_H
Packit e18bd3
#include <config.h>
Packit e18bd3
#endif
Packit e18bd3
#include <X11/ICE/ICElib.h>
Packit e18bd3
#include "ICElibint.h"
Packit e18bd3
#include <X11/ICE/ICEutil.h>
Packit e18bd3
Packit e18bd3

Packit e18bd3
/*
Packit e18bd3
 * IceSetPaAuthData is not a standard part of ICElib, it is specific
Packit e18bd3
 * to the sample implementation.
Packit e18bd3
 *
Packit e18bd3
 * For the client that initiates a Protocol Setup, we look in the
Packit e18bd3
 * .ICEauthority file to get authentication data.
Packit e18bd3
 *
Packit e18bd3
 * For the client accepting the Protocol Setup, we get the data
Packit e18bd3
 * from an in-memory database of authentication data (set by the
Packit e18bd3
 * application calling IceSetPaAuthData).  We have to get the data
Packit e18bd3
 * from memory because getting it directly from the .ICEauthority
Packit e18bd3
 * file is not secure - someone can just modify the contents of the
Packit e18bd3
 * .ICEauthority file behind our back.
Packit e18bd3
 */
Packit e18bd3
Packit e18bd3
int		 _IcePaAuthDataEntryCount = 0;
Packit e18bd3
IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES];
Packit e18bd3
Packit e18bd3
Packit e18bd3
void
Packit e18bd3
IceSetPaAuthData (
Packit e18bd3
	int			numEntries,
Packit e18bd3
	IceAuthDataEntry	*entries
Packit e18bd3
)
Packit e18bd3
{
Packit e18bd3
    /*
Packit e18bd3
     * _IcePaAuthDataEntries should really be a linked list.
Packit e18bd3
     * On my list of TO DO stuff.
Packit e18bd3
     */
Packit e18bd3
Packit e18bd3
    int i, j;
Packit e18bd3
Packit e18bd3
    for (i = 0; i < numEntries; i++)
Packit e18bd3
    {
Packit e18bd3
	for (j = 0; j < _IcePaAuthDataEntryCount; j++)
Packit e18bd3
	    if (strcmp (entries[i].protocol_name,
Packit e18bd3
		_IcePaAuthDataEntries[j].protocol_name) == 0 &&
Packit e18bd3
                strcmp (entries[i].network_id,
Packit e18bd3
		_IcePaAuthDataEntries[j].network_id) == 0 &&
Packit e18bd3
                strcmp (entries[i].auth_name,
Packit e18bd3
		_IcePaAuthDataEntries[j].auth_name) == 0)
Packit e18bd3
		break;
Packit e18bd3
Packit e18bd3
	if (j < _IcePaAuthDataEntryCount)
Packit e18bd3
	{
Packit e18bd3
	    free (_IcePaAuthDataEntries[j].protocol_name);
Packit e18bd3
	    free (_IcePaAuthDataEntries[j].network_id);
Packit e18bd3
	    free (_IcePaAuthDataEntries[j].auth_name);
Packit e18bd3
	    free (_IcePaAuthDataEntries[j].auth_data);
Packit e18bd3
	}
Packit e18bd3
	else
Packit e18bd3
	{
Packit e18bd3
	    _IcePaAuthDataEntryCount++;
Packit e18bd3
	}
Packit e18bd3
Packit e18bd3
	_IcePaAuthDataEntries[j].protocol_name
Packit e18bd3
	    = strdup(entries[i].protocol_name);
Packit e18bd3
Packit e18bd3
	_IcePaAuthDataEntries[j].network_id
Packit e18bd3
	    = strdup(entries[i].network_id);
Packit e18bd3
Packit e18bd3
	_IcePaAuthDataEntries[j].auth_name
Packit e18bd3
            = strdup(entries[i].auth_name);
Packit e18bd3
Packit e18bd3
	_IcePaAuthDataEntries[j].auth_data_length =
Packit e18bd3
            entries[i].auth_data_length;
Packit e18bd3
	_IcePaAuthDataEntries[j].auth_data = malloc (
Packit e18bd3
            entries[i].auth_data_length);
Packit e18bd3
	memcpy (_IcePaAuthDataEntries[j].auth_data,
Packit e18bd3
            entries[i].auth_data, entries[i].auth_data_length);
Packit e18bd3
    }
Packit e18bd3
}