Git init
[framework/uifw/xorg/lib/libice.git] / src / setauth.c
1 /******************************************************************************
2
3
4 Copyright 1993, 1998  The Open Group
5
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
25
26 Author: 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 \f
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
52 int              _IcePaAuthDataEntryCount = 0;
53 #ifndef __UNIXOS2__
54 IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES];
55 #else
56 IceAuthDataEntry _IcePaAuthDataEntries[ICE_MAX_AUTH_DATA_ENTRIES] = {0};
57 #endif
58
59
60 void
61 IceSetPaAuthData (
62         int                     numEntries,
63         IceAuthDataEntry        *entries
64 )
65 {
66     /*
67      * _IcePaAuthDataEntries should really be a linked list.
68      * On my list of TO DO stuff.
69      */
70
71     int i, j;
72
73     for (i = 0; i < numEntries; i++)
74     {
75         for (j = 0; j < _IcePaAuthDataEntryCount; j++)
76             if (strcmp (entries[i].protocol_name,
77                 _IcePaAuthDataEntries[j].protocol_name) == 0 &&
78                 strcmp (entries[i].network_id,
79                 _IcePaAuthDataEntries[j].network_id) == 0 &&
80                 strcmp (entries[i].auth_name,
81                 _IcePaAuthDataEntries[j].auth_name) == 0)
82                 break;
83
84         if (j < _IcePaAuthDataEntryCount)
85         {
86             free (_IcePaAuthDataEntries[j].protocol_name);
87             free (_IcePaAuthDataEntries[j].network_id);
88             free (_IcePaAuthDataEntries[j].auth_name);
89             free (_IcePaAuthDataEntries[j].auth_data);
90         }
91         else
92         {
93             _IcePaAuthDataEntryCount++;
94         }
95
96         _IcePaAuthDataEntries[j].protocol_name
97             = strdup(entries[i].protocol_name);
98
99         _IcePaAuthDataEntries[j].network_id
100             = strdup(entries[i].network_id);
101
102         _IcePaAuthDataEntries[j].auth_name
103             = strdup(entries[i].auth_name);
104
105         _IcePaAuthDataEntries[j].auth_data_length =
106             entries[i].auth_data_length;
107         _IcePaAuthDataEntries[j].auth_data = (char *) malloc (
108             entries[i].auth_data_length);
109         memcpy (_IcePaAuthDataEntries[j].auth_data,
110             entries[i].auth_data, entries[i].auth_data_length);
111     }
112 }