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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/CrGlCur.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: CrGlCur.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1986, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included in
 
13
all copies or substantial portions of the Software.
 
14
 
 
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
16
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
18
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
19
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
20
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
Except as contained in this notice, the name of The Open Group shall not be
 
23
used in advertising or otherwise to promote the sale, use or other dealings
 
24
in this Software without prior written authorization from The Open Group.
 
25
 
 
26
*/
 
27
/* $XFree86: xc/lib/X11/CrGlCur.c,v 1.6 2002/09/05 18:17:31 keithp Exp $ */
 
28
 
 
29
#include "Xlibint.h"
 
30
 
 
31
#ifdef USE_DYNAMIC_XCURSOR
 
32
 
 
33
#include <stdio.h>
 
34
#include <string.h>
 
35
#if defined(hpux)
 
36
#include <dl.h>
 
37
#else
 
38
#include <dlfcn.h>
 
39
#endif
 
40
 
 
41
#if defined(hpux)
 
42
typedef shl_dt  XModuleType;
 
43
#else
 
44
typedef void *XModuleType;
 
45
#endif
 
46
 
 
47
#ifndef LIBXCURSOR
 
48
#define LIBXCURSOR "libXcursor.so"
 
49
#endif
 
50
 
 
51
static char libraryName[] = LIBXCURSOR;
 
52
 
 
53
static XModuleType
 
54
open_library (void)
 
55
{
 
56
    char        *library = libraryName;
 
57
    char        *dot;
 
58
    XModuleType module;
 
59
    for (;;)
 
60
    {
 
61
#if defined(hpux)
 
62
        module = shl_load(library, BIND_DEFERRED, 0L);
 
63
#else
 
64
        module =  dlopen(library, RTLD_LAZY);
 
65
#endif
 
66
        if (module)
 
67
            return module;
 
68
        dot = strrchr (library, '.');
 
69
        if (!dot)
 
70
            break;
 
71
        *dot = '\0';
 
72
    }
 
73
    return 0;
 
74
}
 
75
 
 
76
static void *
 
77
fetch_symbol (XModuleType module, char *under_symbol)
 
78
{
 
79
    void *result = NULL;
 
80
    char *symbol = under_symbol + 1;
 
81
#if defined(hpux)
 
82
    int getsyms_cnt, i;
 
83
    struct shl_symbol *symbols;
 
84
    
 
85
    getsyms_cnt = shl_getsymbols(module, TYPE_PROCEDURE,
 
86
                                 EXPORT_SYMBOLS, malloc, &symbols);
 
87
 
 
88
    for(i=0; i<getsyms_cnt; i++) {
 
89
        if(!strcmp(symbols[i].name, symbol)) {
 
90
            result = symbols[i].value;
 
91
            break;
 
92
         }
 
93
    }
 
94
 
 
95
    if(getsyms_cnt > 0) {
 
96
        free(symbols);
 
97
    }
 
98
#else
 
99
    result = dlsym (module, symbol);
 
100
    if (!result)
 
101
        result = dlsym (module, under_symbol);
 
102
#endif
 
103
    return result;
 
104
}
 
105
 
 
106
typedef void    (*NoticeCreateBitmapFunc) (Display          *dpy,
 
107
                                           Pixmap           pid,
 
108
                                           unsigned int width,
 
109
                                           unsigned int height);
 
110
 
 
111
typedef void    (*NoticePutBitmapFunc) (Display     *dpy,
 
112
                                        Drawable    draw,
 
113
                                        XImage      *image);
 
114
 
 
115
typedef Cursor  (*TryShapeBitmapCursorFunc) (Display        *dpy,
 
116
                                             Pixmap         source,
 
117
                                             Pixmap         mask,
 
118
                                             XColor         *foreground,
 
119
                                             XColor         *background,
 
120
                                             unsigned int   x,
 
121
                                             unsigned int   y);
 
122
 
 
123
typedef Cursor  (*TryShapeCursorFunc) (Display      *dpy,
 
124
                                       Font         source_font,
 
125
                                       Font         mask_font,
 
126
                                       unsigned int source_char,
 
127
                                       unsigned int mask_char,
 
128
                                       XColor _Xconst *foreground,
 
129
                                       XColor _Xconst *background);
 
130
 
 
131
static XModuleType  _XcursorModule;
 
132
static Bool         _XcursorModuleTried;
 
133
 
 
134
#define GetFunc(type,name,ret) {\
 
135
    static Bool     been_here; \
 
136
    static type     staticFunc; \
 
137
     \
 
138
    _XLockMutex (_Xglobal_lock); \
 
139
    if (!been_here) \
 
140
    { \
 
141
        been_here = True; \
 
142
        if (!_XcursorModuleTried) \
 
143
        { \
 
144
            _XcursorModuleTried = True; \
 
145
            _XcursorModule = open_library (); \
 
146
        } \
 
147
        if (_XcursorModule) \
 
148
            staticFunc = (type) fetch_symbol (_XcursorModule, "_" name); \
 
149
    } \
 
150
    ret = staticFunc; \
 
151
    _XUnlockMutex (_Xglobal_lock); \
 
152
}
 
153
 
 
154
Cursor
 
155
_XTryShapeCursor (Display           *dpy,
 
156
                  Font              source_font,
 
157
                  Font              mask_font,
 
158
                  unsigned int      source_char,
 
159
                  unsigned int      mask_char,
 
160
                  XColor _Xconst    *foreground,
 
161
                  XColor _Xconst    *background)
 
162
{
 
163
    TryShapeCursorFunc          func;
 
164
 
 
165
    GetFunc (TryShapeCursorFunc, "XcursorTryShapeCursor", func);
 
166
    if (func)
 
167
        return (*func) (dpy, source_font, mask_font, source_char, mask_char,
 
168
                        foreground, background);
 
169
    return None;
 
170
}
 
171
 
 
172
void
 
173
_XNoticeCreateBitmap (Display       *dpy,
 
174
                      Pixmap        pid,
 
175
                      unsigned int  width,
 
176
                      unsigned int  height)
 
177
{
 
178
    NoticeCreateBitmapFunc  func;
 
179
 
 
180
    GetFunc (NoticeCreateBitmapFunc, "XcursorNoticeCreateBitmap", func);
 
181
    if (func)
 
182
        (*func) (dpy, pid, width, height);
 
183
}
 
184
 
 
185
void
 
186
_XNoticePutBitmap (Display      *dpy,
 
187
                   Drawable     draw,
 
188
                   XImage       *image)
 
189
{
 
190
    NoticePutBitmapFunc func;
 
191
 
 
192
    GetFunc (NoticePutBitmapFunc, "XcursorNoticePutBitmap", func);
 
193
    if (func)
 
194
        (*func) (dpy, draw, image);
 
195
}
 
196
 
 
197
Cursor
 
198
_XTryShapeBitmapCursor (Display         *dpy,
 
199
                        Pixmap          source,
 
200
                        Pixmap          mask,
 
201
                        XColor          *foreground,
 
202
                        XColor          *background,
 
203
                        unsigned int    x,
 
204
                        unsigned int    y)
 
205
{
 
206
    TryShapeBitmapCursorFunc    func;
 
207
 
 
208
    GetFunc (TryShapeBitmapCursorFunc, "XcursorTryShapeBitmapCursor", func);
 
209
    if (func)
 
210
        return (*func) (dpy, source, mask, foreground, background, x, y);
 
211
    return None;
 
212
}
 
213
#endif
 
214
 
 
215
Cursor XCreateGlyphCursor(dpy, source_font, mask_font,
 
216
                   source_char, mask_char,
 
217
                   foreground, background)
 
218
     register Display *dpy;
 
219
     Font source_font, mask_font;
 
220
     unsigned int source_char, mask_char;
 
221
     XColor _Xconst *foreground, *background;
 
222
 
 
223
{       
 
224
    Cursor cid;
 
225
    register xCreateGlyphCursorReq *req;
 
226
 
 
227
#ifdef USE_DYNAMIC_XCURSOR
 
228
    cid = _XTryShapeCursor (dpy, source_font, mask_font, 
 
229
                            source_char, mask_char, foreground, background);
 
230
    if (cid)
 
231
        return cid;
 
232
#endif
 
233
    LockDisplay(dpy);
 
234
    GetReq(CreateGlyphCursor, req);
 
235
    cid = req->cid = XAllocID(dpy);
 
236
    req->source = source_font;
 
237
    req->mask = mask_font;
 
238
    req->sourceChar = source_char;
 
239
    req->maskChar = mask_char;
 
240
    req->foreRed = foreground->red;
 
241
    req->foreGreen = foreground->green;
 
242
    req->foreBlue = foreground->blue;
 
243
    req->backRed = background->red;
 
244
    req->backGreen = background->green;
 
245
    req->backBlue = background->blue;
 
246
    UnlockDisplay(dpy);
 
247
    SyncHandle();
 
248
    return (cid);
 
249
}
 
250