]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xau/AuGetAddr.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xau / AuGetAddr.c
1 /* $XConsortium: AuGetAddr.c,v 1.13 94/04/17 20:15:43 rws Exp $ */
2
3 /*
4
5 Copyright (c) 1988  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 Except as contained in this notice, the name of the X Consortium shall not be
25 used in advertising or otherwise to promote the sale, use or other dealings
26 in this Software without prior written authorization from the X Consortium.
27
28 */
29
30 #include <X11/Xauth.h>
31 #include <X11/Xos.h>
32
33 static
34 binaryEqual (a, b, len)
35 register char   *a, *b;
36 register int    len;
37 {
38     while (len--)
39         if (*a++ != *b++)
40             return 0;
41     return 1;
42 }
43
44 #if NeedFunctionPrototypes
45 Xauth *
46 XauGetAuthByAddr (
47 #if NeedWidePrototypes
48 unsigned int    family,
49 unsigned int    address_length,
50 #else
51 unsigned short  family,
52 unsigned short  address_length,
53 #endif
54 _Xconst char*   address,
55 #if NeedWidePrototypes
56 unsigned int    number_length,
57 #else
58 unsigned short  number_length,
59 #endif
60 _Xconst char*   number,
61 #if NeedWidePrototypes
62 unsigned int    name_length,
63 #else
64 unsigned short  name_length,
65 #endif
66 _Xconst char*   name)
67 #else
68 Xauth *
69 XauGetAuthByAddr (family, address_length, address,
70                           number_length, number,
71                           name_length, name)
72 unsigned short  family;
73 unsigned short  address_length;
74 char    *address;
75 unsigned short  number_length;
76 char    *number;
77 unsigned short  name_length;
78 char    *name;
79 #endif
80 {
81     FILE    *auth_file;
82     char    *auth_name;
83     Xauth   *entry;
84
85     auth_name = XauFileName ();
86     if (!auth_name)
87         return 0;
88     if (access (auth_name, R_OK) != 0)          /* checks REAL id */
89         return 0;
90     auth_file = fopen (auth_name, "rb");
91     if (!auth_file)
92         return 0;
93     for (;;) {
94         entry = XauReadAuth (auth_file);
95         if (!entry)
96             break;
97         /*
98          * Match when:
99          *   either family or entry->family are FamilyWild or
100          *    family and entry->family are the same
101          *  and
102          *   either address or entry->address are empty or
103          *    address and entry->address are the same
104          *  and
105          *   either number or entry->number are empty or
106          *    number and entry->number are the same
107          *  and
108          *   either name or entry->name are empty or
109          *    name and entry->name are the same
110          */
111
112         if ((family == FamilyWild || entry->family == FamilyWild ||
113              (entry->family == family &&
114               address_length == entry->address_length &&
115               binaryEqual (entry->address, address, (int)address_length))) &&
116             (number_length == 0 || entry->number_length == 0 ||
117              (number_length == entry->number_length &&
118               binaryEqual (entry->number, number, (int)number_length))) &&
119             (name_length == 0 || entry->name_length == 0 ||
120              (entry->name_length == name_length &&
121               binaryEqual (entry->name, name, (int)name_length))))
122             break;
123         XauDisposeAuth (entry);
124     }
125     (void) fclose (auth_file);
126     return entry;
127 }