setauth.c revision 266e564d
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 (numEntries, entries) 64 65int numEntries; 66IceAuthDataEntry *entries; 67 68{ 69 /* 70 * _IcePaAuthDataEntries should really be a linked list. 71 * On my list of TO DO stuff. 72 */ 73 74 int i, j; 75 76 for (i = 0; i < numEntries; i++) 77 { 78 for (j = 0; j < _IcePaAuthDataEntryCount; j++) 79 if (strcmp (entries[i].protocol_name, 80 _IcePaAuthDataEntries[j].protocol_name) == 0 && 81 strcmp (entries[i].network_id, 82 _IcePaAuthDataEntries[j].network_id) == 0 && 83 strcmp (entries[i].auth_name, 84 _IcePaAuthDataEntries[j].auth_name) == 0) 85 break; 86 87 if (j < _IcePaAuthDataEntryCount) 88 { 89 free (_IcePaAuthDataEntries[j].protocol_name); 90 free (_IcePaAuthDataEntries[j].network_id); 91 free (_IcePaAuthDataEntries[j].auth_name); 92 free (_IcePaAuthDataEntries[j].auth_data); 93 } 94 else 95 { 96 _IcePaAuthDataEntryCount++; 97 } 98 99 _IcePaAuthDataEntries[j].protocol_name 100 = strdup(entries[i].protocol_name); 101 102 _IcePaAuthDataEntries[j].network_id 103 = strdup(entries[i].network_id); 104 105 _IcePaAuthDataEntries[j].auth_name 106 = strdup(entries[i].auth_name); 107 108 _IcePaAuthDataEntries[j].auth_data_length = 109 entries[i].auth_data_length; 110 _IcePaAuthDataEntries[j].auth_data = (char *) malloc ( 111 entries[i].auth_data_length); 112 memcpy (_IcePaAuthDataEntries[j].auth_data, 113 entries[i].auth_data, entries[i].auth_data_length); 114 } 115} 116