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

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/lbx/lbxexts.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: lbxexts.c,v 1.3 2000/08/17 19:53:31 cpqbld Exp $ */
 
2
/*
 
3
 * Copyright 1994 Network Computing Devices, Inc.
 
4
 *
 
5
 * Permission to use, copy, modify, distribute, and sell this software and
 
6
 * its documentation for any purpose is hereby granted without fee, provided
 
7
 * that the above copyright notice appear in all copies and that both that
 
8
 * copyright notice and this permission notice appear in supporting
 
9
 * documentation, and that the name Network Computing Devices, Inc. not be
 
10
 * used in advertising or publicity pertaining to distribution of this
 
11
 * software without specific, written prior permission.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED `AS-IS'.  NETWORK COMPUTING DEVICES, INC.,
 
14
 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
 
15
 * LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 
16
 * PARTICULAR PURPOSE, OR NONINFRINGEMENT.  IN NO EVENT SHALL NETWORK
 
17
 * COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
 
18
 * SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
 
19
 * OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
 
20
 * WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
 
21
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 */
 
24
/* $XFree86: xc/programs/Xserver/lbx/lbxexts.c,v 1.4 2001/02/16 13:24:10 eich Exp $ */
 
25
 
 
26
#include "X.h"
 
27
#include "Xproto.h"
 
28
#include "misc.h"
 
29
#include "dixstruct.h"
 
30
#include "colormapst.h"
 
31
#include "propertyst.h"
 
32
#define _XLBX_SERVER_
 
33
#include "lbxstr.h"
 
34
#include "lbxserve.h"
 
35
#ifdef XCSECURITY
 
36
#define _SECURITY_SERVER
 
37
#include "extensions/security.h"
 
38
#endif
 
39
 
 
40
typedef struct _lbxext {
 
41
    char       *name;
 
42
    char      **aliases;
 
43
    int         num_aliases;
 
44
    int         idx;
 
45
    int         opcode;
 
46
    int         ev_base;
 
47
    int         err_base;
 
48
    int         num_reqs;
 
49
    CARD8      *rep_mask;
 
50
    CARD8      *ev_mask;
 
51
#ifdef XCSECURITY
 
52
    Bool        secure;
 
53
#endif
 
54
}           LbxExtensionEntry;
 
55
 
 
56
static LbxExtensionEntry **lbx_extensions = NULL;
 
57
static int  num_exts = 0;
 
58
 
 
59
 
 
60
Bool
 
61
LbxAddExtension(char       *name,
 
62
                int         opcode,
 
63
                int         ev_base,
 
64
                int         err_base)
 
65
{
 
66
    int         i;
 
67
    LbxExtensionEntry *ext,
 
68
        **newexts;
 
69
 
 
70
    ext = (LbxExtensionEntry *) xalloc(sizeof(LbxExtensionEntry));
 
71
    if (!ext)
 
72
        return FALSE;
 
73
    ext->name = (char *) xalloc(strlen(name) + 1);
 
74
    ext->num_aliases = 0;
 
75
    ext->aliases = (char **) NULL;
 
76
    if (!ext->name) {
 
77
        xfree(ext);
 
78
        return FALSE;
 
79
    }
 
80
    strcpy(ext->name, name);
 
81
    i = num_exts;
 
82
    newexts = (LbxExtensionEntry **) xrealloc(lbx_extensions,
 
83
                                      (i + 1) * sizeof(LbxExtensionEntry *));
 
84
    if (!newexts) {
 
85
        xfree(ext->name);
 
86
        xfree(ext);
 
87
        return FALSE;
 
88
    }
 
89
    num_exts++;
 
90
    lbx_extensions = newexts;
 
91
    lbx_extensions[i] = ext;
 
92
    ext->idx = i;
 
93
 
 
94
    ext->opcode = opcode;;
 
95
    ext->ev_base = ev_base;;
 
96
    ext->err_base = err_base;
 
97
    ext->ev_mask = NULL;
 
98
    ext->rep_mask = NULL;
 
99
    ext->num_reqs = 0;
 
100
#ifdef XCSECURITY
 
101
    ext->secure = FALSE;
 
102
#endif
 
103
 
 
104
    return TRUE;
 
105
}
 
106
 
 
107
Bool
 
108
LbxAddExtensionAlias(int         idx,
 
109
                     char       *alias)
 
110
{
 
111
    char       *name;
 
112
    char      **aliases;
 
113
    LbxExtensionEntry *ext = lbx_extensions[idx];
 
114
 
 
115
    aliases = (char **) xrealloc(ext->aliases,
 
116
                                 (ext->num_aliases + 1) * sizeof(char *));
 
117
    if (!aliases)
 
118
        return FALSE;
 
119
    ext->aliases = aliases;
 
120
    name = (char *) xalloc(strlen(alias) + 1);
 
121
    if (!name)
 
122
        return FALSE;
 
123
    strcpy(name, alias);
 
124
    ext->aliases[ext->num_aliases] = name;
 
125
    ext->num_aliases++;
 
126
    return TRUE;
 
127
}
 
128
 
 
129
static int
 
130
LbxFindExtension(char *extname,
 
131
                 int len)
 
132
{
 
133
    int i, j;
 
134
 
 
135
    for (i = 0; i < num_exts; i++) {
 
136
        if ((strlen(lbx_extensions[i]->name) == len) &&
 
137
                (strncmp(lbx_extensions[i]->name, extname, len) == 0))
 
138
            return i;
 
139
        for (j = lbx_extensions[i]->num_aliases; --j >= 0;) {
 
140
            if ((strlen(lbx_extensions[i]->aliases[j]) == len) &&
 
141
                (strncmp(lbx_extensions[i]->aliases[j], extname, len) == 0))
 
142
                return i;
 
143
        }
 
144
    }
 
145
    return -1;
 
146
}
 
147
 
 
148
void
 
149
LbxDeclareExtensionSecurity(char *extname,
 
150
                            Bool secure)
 
151
{
 
152
#ifdef XCSECURITY
 
153
    int i = LbxFindExtension(extname, strlen(extname));
 
154
    if (i >= 0)
 
155
        lbx_extensions[i]->secure = secure;
 
156
#endif
 
157
}
 
158
 
 
159
Bool
 
160
LbxRegisterExtensionGenerationMasks(int         idx,
 
161
                                    int         num_reqs,
 
162
                                    char       *rep_mask,
 
163
                                    char       *ev_mask)
 
164
{
 
165
    LbxExtensionEntry *ext = lbx_extensions[idx];
 
166
    CARD8      *nrm,
 
167
               *nem;
 
168
    int         mlen = mlen = num_reqs / (8 * sizeof(CARD8)) + 1;
 
169
 
 
170
    nrm = (CARD8 *) xalloc(sizeof(CARD8) * mlen);
 
171
    nem = (CARD8 *) xalloc(sizeof(CARD8) * mlen);
 
172
 
 
173
    if (!nrm || !nem) {
 
174
        xfree(nrm);
 
175
        xfree(nem);
 
176
        return FALSE;
 
177
    }
 
178
    memcpy((char *) nrm, (char *) rep_mask, mlen);
 
179
    memcpy((char *) nem, (char *) ev_mask, mlen);
 
180
    ext->rep_mask = nrm;
 
181
    ext->ev_mask = nem;
 
182
    ext->num_reqs = num_reqs;
 
183
 
 
184
    return TRUE;
 
185
}
 
186
 
 
187
int
 
188
LbxQueryExtension(ClientPtr   client,
 
189
                  char       *ename,
 
190
                  int         nlen)
 
191
{
 
192
    xLbxQueryExtensionReply rep;
 
193
    int         i;
 
194
    int         mlen = 0;
 
195
 
 
196
    rep.type = X_Reply;
 
197
    rep.sequenceNumber = client->sequence;
 
198
    rep.major_opcode = 0;
 
199
    rep.present = FALSE;
 
200
    rep.length = 0;
 
201
    rep.pad0 = rep.pad1 = rep.pad2 = rep.pad3 = rep.pad4 = 0;
 
202
 
 
203
    i = LbxFindExtension(ename, nlen);
 
204
 
 
205
    if (i < 0
 
206
#ifdef XCSECURITY
 
207
            /* don't show insecure extensions to untrusted clients */
 
208
            || (client->trustLevel == XSecurityClientUntrusted &&
 
209
                !lbx_extensions[i]->secure)
 
210
#endif
 
211
        )
 
212
        rep.present = FALSE;
 
213
    else {
 
214
        rep.present = TRUE;
 
215
        rep.major_opcode = lbx_extensions[i]->opcode;
 
216
        rep.first_event = lbx_extensions[i]->ev_base;
 
217
        rep.first_error = lbx_extensions[i]->err_base;
 
218
        rep.numReqs = lbx_extensions[i]->num_reqs;
 
219
        if (lbx_extensions[i]->rep_mask) {
 
220
            mlen = (lbx_extensions[i]->num_reqs + 7) >> 3;
 
221
            rep.length = ((mlen + 3) >> 2) * 2;
 
222
        }
 
223
    }
 
224
    if (client->swapped) {
 
225
        char    n;
 
226
 
 
227
        swaps(&rep.sequenceNumber, n);
 
228
        swapl(&rep.length, n);
 
229
    }
 
230
    WriteToClient(client, sizeof(xLbxQueryExtensionReply), (char *)&rep);
 
231
    if (mlen) {
 
232
        WriteToClient(client, mlen, (char *)lbx_extensions[i]->rep_mask);
 
233
        WriteToClient(client, mlen, (char *)lbx_extensions[i]->ev_mask);
 
234
    }
 
235
    return Success;
 
236
}
 
237
 
 
238
void
 
239
LbxCloseDownExtensions(void)
 
240
{
 
241
    int         i,j;
 
242
 
 
243
    for (i = 0; i < num_exts; i++) {
 
244
        xfree(lbx_extensions[i]->name);
 
245
        for (j = 0; j < lbx_extensions[i]->num_aliases; j++)
 
246
          xfree(lbx_extensions[i]->aliases[j]);
 
247
        xfree(lbx_extensions[i]->aliases);
 
248
        xfree(lbx_extensions[i]->rep_mask);
 
249
        xfree(lbx_extensions[i]->ev_mask);
 
250
        xfree(lbx_extensions[i]);
 
251
    }
 
252
    xfree(lbx_extensions);
 
253
    lbx_extensions = NULL;
 
254
    num_exts = 0;
 
255
 
 
256
}
 
257
 
 
258
void
 
259
LbxSetReqMask(CARD8      *mask,
 
260
              int         req,
 
261
              Bool        on)
 
262
{
 
263
    int         mword = req / (8 * sizeof(CARD8));
 
264
 
 
265
    req = req % (8 * sizeof(CARD8));
 
266
    if (on) {
 
267
        mask[mword] |= (1 << req);
 
268
    } else {
 
269
        mask[mword] &= ~(1 << req);
 
270
    }
 
271
}