1
/* $Xorg: AuGetBest.c,v 1.4 2001/02/09 02:03:42 xorgcvs Exp $ */
5
Copyright 1988, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
28
/* $XFree86: xc/lib/Xau/AuGetBest.c,v 1.7 2001/12/14 19:54:36 dawes Exp $ */
30
#include <X11/Xauth.h>
33
#include <X11/Xthreads.h>
36
#define X_INCLUDE_NETDB_H
37
#define XOS_USE_NO_LOCKING
38
#include <X11/Xos_r.h>
42
binaryEqual (_Xconst char *a, _Xconst char *b, int len)
50
#if NeedFunctionPrototypes
52
XauGetBestAuthByAddr (
53
#if NeedWidePrototypes
55
unsigned int address_length,
57
unsigned short family,
58
unsigned short address_length,
60
_Xconst char* address,
61
#if NeedWidePrototypes
62
unsigned int number_length,
64
unsigned short number_length,
69
_Xconst int* type_lengths)
72
XauGetBestAuthByAddr (family, address_length, address,
73
number_length, number,
74
types_length, types, type_lengths)
75
unsigned short family;
76
unsigned short address_length;
78
unsigned short number_length;
92
char *fully_qual_address;
93
unsigned short fully_qual_address_length;
96
auth_name = XauFileName ();
99
if (access (auth_name, R_OK) != 0) /* checks REAL id */
101
auth_file = fopen (auth_name, "rb");
106
if (family == FamilyLocal) {
107
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
108
_Xgethostbynameparams hparams;
110
struct hostent *hostp;
112
/* make sure we try fully-qualified hostname */
113
if ((hostp = _XGethostbyname(address,hparams)) != NULL) {
114
fully_qual_address = hostp->h_name;
115
fully_qual_address_length = strlen(fully_qual_address);
119
fully_qual_address = NULL;
120
fully_qual_address_length = 0;
126
best_type = types_length;
128
entry = XauReadAuth (auth_file);
133
* either family or entry->family are FamilyWild or
134
* family and entry->family are the same and
135
* address and entry->address are the same
137
* either number or entry->number are empty or
138
* number and entry->number are the same
140
* either name or entry->name are empty or
141
* name and entry->name are the same
144
if ((family == FamilyWild || entry->family == FamilyWild ||
145
(entry->family == family &&
146
((address_length == entry->address_length &&
147
binaryEqual (entry->address, address, (int)address_length))
149
|| (family == FamilyLocal &&
150
fully_qual_address_length == entry->address_length &&
151
binaryEqual (entry->address, fully_qual_address,
152
(int) fully_qual_address_length))
155
(number_length == 0 || entry->number_length == 0 ||
156
(number_length == entry->number_length &&
157
binaryEqual (entry->number, number, (int)number_length))))
164
for (type = 0; type < best_type; type++)
165
if (type_lengths[type] == entry->name_length &&
166
!(strncmp (types[type], entry->name, entry->name_length)))
170
if (type < best_type)
173
XauDisposeAuth (best);
181
XauDisposeAuth (entry);
183
(void) fclose (auth_file);