1 /******************************************************************************
4 Copyright 1993, 1998 The Open Group
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
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
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.
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.
26 Author: Ralph Mor, X Consortium
27 ******************************************************************************/
32 #include <X11/ICE/ICElib.h>
33 #include "ICElibint.h"
35 static Bool auth_valid (const char *auth_name, int num_auth_names,
36 const char **auth_names, int *index_ret);
40 * The functions in this file are not a standard part of ICElib.
42 * The sample implementation uses an .ICEauthority to manipulate
43 * authentication data.
45 * For the client that initiates a Protocol Setup, we look in the
46 * .ICEauthority file to get the data.
48 * For the client accepting the Protocol Setup, we get the data
49 * from an in-memory database of authentication data (set by the
50 * application calling IceSetPaAuthData). We have to get the data
51 * from memory because getting it directly from the .ICEauthority
52 * file is not secure - someone can just modify the contents of the
53 * .ICEauthority file behind our back.
58 const char *protocolName,
59 const char *networkId,
61 unsigned short *authDataLenRet,
65 IceAuthFileEntry *entry;
67 entry = IceGetAuthFileEntry (protocolName, networkId, authName);
71 *authDataLenRet = entry->auth_data_length;
73 if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL)
74 memcpy (*authDataRet, entry->auth_data, entry->auth_data_length);
82 IceFreeAuthFileEntry (entry);
89 const char *protocolName,
90 const char *networkId,
92 unsigned short *authDataLenRet,
96 IceAuthDataEntry *entry = NULL;
100 for (i = 0; i < _IcePaAuthDataEntryCount && !found; i++)
102 entry = &_IcePaAuthDataEntries[i];
105 strcmp (protocolName, entry->protocol_name) == 0 &&
106 strcmp (networkId, entry->network_id) == 0 &&
107 strcmp (authName, entry->auth_name) == 0;
112 *authDataLenRet = entry->auth_data_length;
114 if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL)
115 memcpy (*authDataRet, entry->auth_data, entry->auth_data_length);
127 _IceGetPoValidAuthIndices (
128 const char *protocol_name,
129 const char *network_id,
131 const char **auth_names,
132 int *num_indices_ret,
133 int *indices_ret /* in/out arg */
138 IceAuthFileEntry *entry;
141 *num_indices_ret = 0;
143 if (!(filename = IceAuthFileName ()))
146 if (access (filename, R_OK) != 0) /* checks REAL id */
149 if (!(auth_file = fopen (filename, "rb")))
154 if (!(entry = IceReadAuthFileEntry (auth_file)))
157 if (strcmp (protocol_name, entry->protocol_name) == 0 &&
158 strcmp (network_id, entry->network_id) == 0 &&
159 auth_valid (entry->auth_name, num_auth_names,
160 auth_names, &index_ret))
163 * Make sure we didn't store this index already.
166 for (i = 0; i < *num_indices_ret; i++)
167 if (index_ret == indices_ret[i])
170 if (i >= *num_indices_ret)
172 indices_ret[*num_indices_ret] = index_ret;
173 *num_indices_ret += 1;
177 IceFreeAuthFileEntry (entry);
186 _IceGetPaValidAuthIndices (
187 const char *protocol_name,
188 const char *network_id,
190 const char **auth_names,
191 int *num_indices_ret,
192 int *indices_ret /* in/out arg */
197 IceAuthDataEntry *entry;
199 *num_indices_ret = 0;
201 for (i = 0; i < _IcePaAuthDataEntryCount; i++)
203 entry = &_IcePaAuthDataEntries[i];
205 if (strcmp (protocol_name, entry->protocol_name) == 0 &&
206 strcmp (network_id, entry->network_id) == 0 &&
207 auth_valid (entry->auth_name, num_auth_names,
208 auth_names, &index_ret))
211 * Make sure we didn't store this index already.
214 for (j = 0; j < *num_indices_ret; j++)
215 if (index_ret == indices_ret[j])
218 if (j >= *num_indices_ret)
220 indices_ret[*num_indices_ret] = index_ret;
221 *num_indices_ret += 1;
234 auth_valid (const char *auth_name, int num_auth_names,
235 const char **auth_names, int *index_ret)
239 * Check if auth_name is in auth_names. Return index.
244 for (i = 0; i < num_auth_names; i++)
245 if (strcmp (auth_name, auth_names[i]) == 0)
250 if (i < num_auth_names)