3 Copyright 1988, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
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)
51 XauGetBestAuthByAddr (
52 #if NeedWidePrototypes
54 unsigned int address_length,
56 unsigned short family,
57 unsigned short address_length,
59 _Xconst char* address,
60 #if NeedWidePrototypes
61 unsigned int number_length,
63 unsigned short number_length,
68 _Xconst int* type_lengths)
77 char *fully_qual_address;
78 unsigned short fully_qual_address_length;
81 auth_name = XauFileName ();
84 if (access (auth_name, R_OK) != 0) /* checks REAL id */
86 auth_file = fopen (auth_name, "rb");
91 if (family == FamilyLocal) {
92 #ifdef XTHREADS_NEEDS_BYNAMEPARAMS
93 _Xgethostbynameparams hparams;
95 struct hostent *hostp;
97 /* make sure we try fully-qualified hostname */
98 if ((hostp = _XGethostbyname(address,hparams)) != NULL) {
99 fully_qual_address = hostp->h_name;
100 fully_qual_address_length = strlen(fully_qual_address);
104 fully_qual_address = NULL;
105 fully_qual_address_length = 0;
111 best_type = types_length;
113 entry = XauReadAuth (auth_file);
118 * either family or entry->family are FamilyWild or
119 * family and entry->family are the same and
120 * address and entry->address are the same
122 * either number or entry->number are empty or
123 * number and entry->number are the same
125 * either name or entry->name are empty or
126 * name and entry->name are the same
129 if ((family == FamilyWild || entry->family == FamilyWild ||
130 (entry->family == family &&
131 ((address_length == entry->address_length &&
132 binaryEqual (entry->address, address, (int)address_length))
134 || (family == FamilyLocal &&
135 fully_qual_address_length == entry->address_length &&
136 binaryEqual (entry->address, fully_qual_address,
137 (int) fully_qual_address_length))
140 (number_length == 0 || entry->number_length == 0 ||
141 (number_length == entry->number_length &&
142 binaryEqual (entry->number, number, (int)number_length))))
149 for (type = 0; type < best_type; type++)
150 if (type_lengths[type] == entry->name_length &&
151 !(strncmp (types[type], entry->name, entry->name_length)))
155 if (type < best_type)
158 XauDisposeAuth (best);
166 XauDisposeAuth (entry);
168 (void) fclose (auth_file);