#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/ICE/ICElib.h>
#include "ICElibint.h"
#include <X11/ICE/ICEutil.h>
static Bool auth_valid ();
extern int _IcePaAuthDataEntryCount;
extern IceAuthDataEntry _IcePaAuthDataEntries[];
void
_IceGetPoAuthData (protocolName, networkId, authName,
authDataLenRet, authDataRet)
char *protocolName;
char *networkId;
char *authName;
unsigned short *authDataLenRet;
char **authDataRet;
{
IceAuthFileEntry *entry;
entry = IceGetAuthFileEntry (protocolName, networkId, authName);
if (entry)
{
*authDataLenRet = entry->auth_data_length;
if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL)
memcpy (*authDataRet, entry->auth_data, entry->auth_data_length);
}
else
{
*authDataLenRet = 0;
*authDataRet = NULL;
}
IceFreeAuthFileEntry (entry);
}
void
_IceGetPaAuthData (protocolName, networkId, authName,
authDataLenRet, authDataRet)
char *protocolName;
char *networkId;
char *authName;
unsigned short *authDataLenRet;
char **authDataRet;
{
IceAuthDataEntry *entry = NULL;
int found = 0;
int i;
for (i = 0; i < _IcePaAuthDataEntryCount && !found; i++)
{
entry = &_IcePaAuthDataEntries[i];
found =
strcmp (protocolName, entry->protocol_name) == 0 &&
strcmp (networkId, entry->network_id) == 0 &&
strcmp (authName, entry->auth_name) == 0;
}
if (found)
{
*authDataLenRet = entry->auth_data_length;
if ((*authDataRet = (char *) malloc (entry->auth_data_length)) != NULL)
memcpy (*authDataRet, entry->auth_data, entry->auth_data_length);
}
else
{
*authDataLenRet = 0;
*authDataRet = NULL;
}
}
void
_IceGetPoValidAuthIndices (protocol_name, network_id,
num_auth_names, auth_names, num_indices_ret, indices_ret)
char *protocol_name;
char *network_id;
int num_auth_names;
char **auth_names;
int *num_indices_ret;
int *indices_ret;
{
FILE *auth_file;
char *filename;
IceAuthFileEntry *entry;
int index_ret, i;
*num_indices_ret = 0;
if (!(filename = IceAuthFileName ()))
return;
if (access (filename, R_OK) != 0)
return;
if (!(auth_file = fopen (filename, "rb")))
return;
for (;;)
{
if (!(entry = IceReadAuthFileEntry (auth_file)))
break;
if (strcmp (protocol_name, entry->protocol_name) == 0 &&
strcmp (network_id, entry->network_id) == 0 &&
auth_valid (entry->auth_name, num_auth_names,
auth_names, &index_ret))
{
for (i = 0; i < *num_indices_ret; i++)
if (index_ret == indices_ret[i])
break;
if (i >= *num_indices_ret)
{
indices_ret[*num_indices_ret] = index_ret;
*num_indices_ret += 1;
}
}
IceFreeAuthFileEntry (entry);
}
fclose (auth_file);
}
void
_IceGetPaValidAuthIndices (protocol_name, network_id,
num_auth_names, auth_names, num_indices_ret, indices_ret)
char *protocol_name;
char *network_id;
int num_auth_names;
char **auth_names;
int *num_indices_ret;
int *indices_ret;
{
int index_ret;
int i, j;
IceAuthDataEntry *entry;
*num_indices_ret = 0;
for (i = 0; i < _IcePaAuthDataEntryCount; i++)
{
entry = &_IcePaAuthDataEntries[i];
if (strcmp (protocol_name, entry->protocol_name) == 0 &&
strcmp (network_id, entry->network_id) == 0 &&
auth_valid (entry->auth_name, num_auth_names,
auth_names, &index_ret))
{
for (j = 0; j < *num_indices_ret; j++)
if (index_ret == indices_ret[j])
break;
if (j >= *num_indices_ret)
{
indices_ret[*num_indices_ret] = index_ret;
*num_indices_ret += 1;
}
}
}
}
static Bool
auth_valid (auth_name, num_auth_names, auth_names, index_ret)
char *auth_name;
int num_auth_names;
char **auth_names;
int *index_ret;
{
int i;
for (i = 0; i < num_auth_names; i++)
if (strcmp (auth_name, auth_names[i]) == 0)
{
break;
}
if (i < num_auth_names)
{
*index_ret = i;
return (1);
}
else
return (0);
}