~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/lib/Xau/AuGetBest.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: AuGetBest.c,v 1.4 2001/02/09 02:03:42 xorgcvs Exp $ */
 
2
 
 
3
/*
 
4
 
 
5
Copyright 1988, 1998  The Open Group
 
6
 
 
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
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
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.
 
22
 
 
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.
 
26
 
 
27
*/
 
28
/* $XFree86: xc/lib/Xau/AuGetBest.c,v 1.7 2001/12/14 19:54:36 dawes Exp $ */
 
29
 
 
30
#include <X11/Xauth.h>
 
31
#include <X11/Xos.h>
 
32
#ifdef XTHREADS
 
33
#include <X11/Xthreads.h>
 
34
#endif
 
35
#ifdef hpux
 
36
#define X_INCLUDE_NETDB_H
 
37
#define XOS_USE_NO_LOCKING
 
38
#include <X11/Xos_r.h>
 
39
#endif
 
40
 
 
41
static int
 
42
binaryEqual (_Xconst char *a, _Xconst char *b, int len)
 
43
{
 
44
    while (len--)
 
45
        if (*a++ != *b++)
 
46
            return 0;
 
47
    return 1;
 
48
}
 
49
 
 
50
#if NeedFunctionPrototypes
 
51
Xauth *
 
52
XauGetBestAuthByAddr (
 
53
#if NeedWidePrototypes
 
54
    unsigned int        family,
 
55
    unsigned int        address_length,
 
56
#else
 
57
    unsigned short      family,
 
58
    unsigned short      address_length,
 
59
#endif
 
60
    _Xconst char*       address,
 
61
#if NeedWidePrototypes
 
62
    unsigned int        number_length,
 
63
#else
 
64
    unsigned short      number_length,
 
65
#endif
 
66
    _Xconst char*       number,
 
67
    int                 types_length,
 
68
    char**              types,
 
69
    _Xconst int*        type_lengths)
 
70
#else
 
71
Xauth *
 
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;
 
77
    char                *address;
 
78
    unsigned short      number_length;
 
79
    char                *number;
 
80
    int                 types_length;
 
81
    char                **types;
 
82
    int                 *type_lengths;
 
83
#endif
 
84
{
 
85
    FILE    *auth_file;
 
86
    char    *auth_name;
 
87
    Xauth   *entry;
 
88
    Xauth   *best;
 
89
    int     best_type;
 
90
    int     type;
 
91
#ifdef hpux
 
92
    char                *fully_qual_address;
 
93
    unsigned short      fully_qual_address_length;
 
94
#endif
 
95
 
 
96
    auth_name = XauFileName ();
 
97
    if (!auth_name)
 
98
        return 0;
 
99
    if (access (auth_name, R_OK) != 0)          /* checks REAL id */
 
100
        return 0;
 
101
    auth_file = fopen (auth_name, "rb");
 
102
    if (!auth_file)
 
103
        return 0;
 
104
 
 
105
#ifdef hpux
 
106
    if (family == FamilyLocal) {
 
107
#ifdef XTHREADS_NEEDS_BYNAMEPARAMS
 
108
        _Xgethostbynameparams hparams;
 
109
#endif
 
110
        struct hostent *hostp;
 
111
 
 
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);
 
116
        }
 
117
        else
 
118
        {
 
119
            fully_qual_address = NULL;
 
120
            fully_qual_address_length = 0;
 
121
        }
 
122
    }
 
123
#endif /* hpux */
 
124
 
 
125
    best = 0;
 
126
    best_type = types_length;
 
127
    for (;;) {
 
128
        entry = XauReadAuth (auth_file);
 
129
        if (!entry)
 
130
            break;
 
131
        /*
 
132
         * Match when:
 
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
 
136
         *  and
 
137
         *   either number or entry->number are empty or
 
138
         *    number and entry->number are the same
 
139
         *  and
 
140
         *   either name or entry->name are empty or
 
141
         *    name and entry->name are the same
 
142
         */
 
143
 
 
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))
 
148
#ifdef hpux
 
149
             || (family == FamilyLocal &&
 
150
                fully_qual_address_length == entry->address_length &&
 
151
                binaryEqual (entry->address, fully_qual_address,
 
152
                    (int) fully_qual_address_length))
 
153
#endif
 
154
            ))) &&
 
155
            (number_length == 0 || entry->number_length == 0 ||
 
156
             (number_length == entry->number_length &&
 
157
              binaryEqual (entry->number, number, (int)number_length))))
 
158
        {
 
159
            if (best_type == 0)
 
160
            {
 
161
                best = entry;
 
162
                break;
 
163
            }
 
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)))
 
167
                {
 
168
                    break;
 
169
                }
 
170
            if (type < best_type)
 
171
            {
 
172
                if (best)
 
173
                    XauDisposeAuth (best);
 
174
                best = entry;
 
175
                best_type = type;
 
176
                if (type == 0)
 
177
                    break;
 
178
                continue;
 
179
            }
 
180
        }
 
181
        XauDisposeAuth (entry);
 
182
    }
 
183
    (void) fclose (auth_file);
 
184
    return best;
 
185
}