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

« back to all changes in this revision

Viewing changes to unix/xc/lib/X11/lcPublic.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: lcPublic.c,v 1.4 2000/12/12 12:44:05 coskrey Exp $ */
 
2
/*
 
3
 * Copyright 1992, 1993 by TOSHIBA Corp.
 
4
 *
 
5
 * Permission to use, copy, modify, and distribute this software and its
 
6
 * documentation for any purpose and without fee is hereby granted, 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 of TOSHIBA not be used in advertising
 
10
 * or publicity pertaining to distribution of the software without specific,
 
11
 * written prior permission. TOSHIBA make no representations about the
 
12
 * suitability of this software for any purpose.  It is provided "as is"
 
13
 * without express or implied warranty.
 
14
 *
 
15
 * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
16
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
17
 * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
18
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
19
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
20
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
21
 * SOFTWARE.
 
22
 *
 
23
 * Author: Katsuhisa Yano       TOSHIBA Corp.
 
24
 *                              mopi@osa.ilab.toshiba.co.jp
 
25
 */
 
26
/* $XFree86: xc/lib/X11/lcPublic.c,v 1.11 2001/11/16 00:52:28 dawes Exp $ */
 
27
 
 
28
#include <stdio.h>
 
29
#include "Xlibint.h"
 
30
#include "XlcPubI.h"
 
31
 
 
32
static const char *
 
33
default_string(
 
34
    XLCd lcd)
 
35
{
 
36
    return XLC_PUBLIC(lcd, default_string);
 
37
}
 
38
 
 
39
static XLCd create (const char *name, XLCdMethods methods);
 
40
static Bool initialize (XLCd lcd);
 
41
static void destroy (XLCd lcd);
 
42
static char *get_values (XLCd lcd, XlcArgList args, int num_args);
 
43
 
 
44
static XLCdPublicMethodsRec publicMethods = {
 
45
    {
 
46
        destroy,
 
47
        _XlcDefaultMapModifiers,
 
48
        NULL,
 
49
        NULL,
 
50
        _XrmDefaultInitParseInfo,
 
51
        _XmbTextPropertyToTextList,
 
52
        _XwcTextPropertyToTextList,
 
53
        _Xutf8TextPropertyToTextList,
 
54
        _XmbTextListToTextProperty,
 
55
        _XwcTextListToTextProperty,
 
56
        _Xutf8TextListToTextProperty,
 
57
        _XwcFreeStringList,
 
58
        default_string,
 
59
        NULL,
 
60
        NULL
 
61
    }, 
 
62
    {
 
63
        NULL,
 
64
        create,
 
65
        initialize,
 
66
        destroy,
 
67
        get_values,
 
68
        _XlcGetLocaleDataBase
 
69
    }
 
70
};
 
71
 
 
72
XLCdMethods _XlcPublicMethods = (XLCdMethods) &publicMethods;
 
73
 
 
74
static XLCd
 
75
create(
 
76
    const char *name,
 
77
    XLCdMethods methods)
 
78
{
 
79
    XLCd lcd;
 
80
    XLCdPublicMethods new;
 
81
 
 
82
    lcd = (XLCd) Xmalloc(sizeof(XLCdRec));
 
83
    if (lcd == NULL)
 
84
        return (XLCd) NULL;
 
85
    bzero((char *) lcd, sizeof(XLCdRec));
 
86
 
 
87
    lcd->core = (XLCdCore) Xmalloc(sizeof(XLCdPublicRec));
 
88
    if (lcd->core == NULL)
 
89
        goto err;
 
90
    bzero((char *) lcd->core, sizeof(XLCdPublicRec));
 
91
 
 
92
    new = (XLCdPublicMethods) Xmalloc(sizeof(XLCdPublicMethodsRec));
 
93
    if (new == NULL)
 
94
        goto err;
 
95
    memcpy(new,methods,sizeof(XLCdPublicMethodsRec));
 
96
    lcd->methods = (XLCdMethods) new;
 
97
 
 
98
    return lcd;
 
99
 
 
100
err:
 
101
    Xfree(lcd);
 
102
    return (XLCd) NULL;
 
103
}
 
104
 
 
105
static Bool
 
106
load_public(
 
107
    XLCd lcd)
 
108
{
 
109
    XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
 
110
    char **values, *str;
 
111
    int num;
 
112
 
 
113
    if(_XlcCreateLocaleDataBase(lcd) == NULL)
 
114
        return False;
 
115
 
 
116
    _XlcGetResource(lcd, "XLC_XLOCALE", "mb_cur_max", &values, &num);
 
117
    if (num > 0) {
 
118
        pub->mb_cur_max = atoi(values[0]);
 
119
        if (pub->mb_cur_max < 1)
 
120
            pub->mb_cur_max = 1;
 
121
    } else
 
122
        pub->mb_cur_max = 1;
 
123
 
 
124
    _XlcGetResource(lcd, "XLC_XLOCALE", "state_depend_encoding", &values, &num);
 
125
    if (num > 0 && !_XlcCompareISOLatin1(values[0], "True"))
 
126
        pub->is_state_depend = True;
 
127
    else
 
128
        pub->is_state_depend = False;
 
129
 
 
130
    _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
 
131
    str = (num > 0) ? values[0] : "STRING";
 
132
    pub->encoding_name = (char*) Xmalloc(strlen(str) + 1);
 
133
    if (pub->encoding_name == NULL)
 
134
        return False;
 
135
    strcpy(pub->encoding_name, str);
 
136
 
 
137
    return True;
 
138
}
 
139
 
 
140
static Bool
 
141
initialize_core(
 
142
    XLCd lcd)
 
143
{
 
144
    XLCdMethods methods = lcd->methods;
 
145
    XLCdMethods core = &publicMethods.core;
 
146
 
 
147
    if (methods->close == NULL)
 
148
        methods->close = core->close;
 
149
 
 
150
    if (methods->map_modifiers == NULL)
 
151
        methods->map_modifiers = core->map_modifiers;
 
152
 
 
153
    if (methods->open_om == NULL)
 
154
#ifdef USE_DYNAMIC_LC
 
155
        _XInitDefaultOM(lcd);
 
156
#else
 
157
        _XInitOM(lcd);
 
158
#endif
 
159
 
 
160
    if (methods->open_im == NULL)
 
161
#ifdef USE_DYNAMIC_LC
 
162
        _XInitDefaultIM(lcd);
 
163
#else
 
164
        _XInitIM(lcd);
 
165
#endif
 
166
 
 
167
    if (methods->init_parse_info == NULL)
 
168
        methods->init_parse_info = core->init_parse_info;
 
169
 
 
170
    if (methods->mb_text_prop_to_list == NULL)
 
171
        methods->mb_text_prop_to_list = core->mb_text_prop_to_list;
 
172
 
 
173
    if (methods->wc_text_prop_to_list == NULL)
 
174
        methods->wc_text_prop_to_list = core->wc_text_prop_to_list;
 
175
 
 
176
    if (methods->utf8_text_prop_to_list == NULL)
 
177
        methods->utf8_text_prop_to_list = core->utf8_text_prop_to_list;
 
178
 
 
179
    if (methods->mb_text_list_to_prop == NULL)
 
180
        methods->mb_text_list_to_prop = core->mb_text_list_to_prop;
 
181
 
 
182
    if (methods->wc_text_list_to_prop == NULL)
 
183
        methods->wc_text_list_to_prop = core->wc_text_list_to_prop;
 
184
 
 
185
    if (methods->utf8_text_list_to_prop == NULL)
 
186
        methods->utf8_text_list_to_prop = core->utf8_text_list_to_prop;
 
187
 
 
188
    if (methods->wc_free_string_list == NULL)
 
189
        methods->wc_free_string_list = core->wc_free_string_list;
 
190
 
 
191
    if (methods->default_string == NULL)
 
192
        methods->default_string = core->default_string;
 
193
 
 
194
    return True;
 
195
}
 
196
 
 
197
static Bool
 
198
initialize(
 
199
    XLCd lcd)
 
200
{
 
201
    XLCdPublicMethodsPart *methods = XLC_PUBLIC_METHODS(lcd);
 
202
    XLCdPublicMethodsPart *pub_methods = &publicMethods.pub;
 
203
    XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
 
204
    char *name;
 
205
#if !defined(X_LOCALE)
 
206
    int len;
 
207
    char sinamebuf[256];
 
208
    char* siname;
 
209
    char *_XlcMapOSLocaleName();
 
210
#endif
 
211
 
 
212
    _XlcInitCTInfo();
 
213
 
 
214
    if (initialize_core(lcd) == False)
 
215
        return False;
 
216
 
 
217
    name = lcd->core->name;
 
218
#if !defined(X_LOCALE)
 
219
    /* 
 
220
     * _XlMapOSLocaleName will return the same string or a substring 
 
221
     * of name, so strlen(name) is okay 
 
222
     */
 
223
    if ((len = strlen(name)) < sizeof sinamebuf)
 
224
        siname = sinamebuf;
 
225
    else
 
226
        siname = Xmalloc (len + 1);
 
227
    if (siname == NULL)
 
228
        return False;
 
229
    name = _XlcMapOSLocaleName(name, siname);
 
230
#endif
 
231
    /* _XlcResolveLocaleName will lookup the SI's name for the locale */
 
232
    if (_XlcResolveLocaleName(name, pub) == 0) {
 
233
#if !defined(X_LOCALE)
 
234
        if (siname != sinamebuf) Xfree (siname);
 
235
#endif
 
236
        return False;
 
237
    }
 
238
#if !defined(X_LOCALE)
 
239
    if (siname != sinamebuf)
 
240
        Xfree (siname);
 
241
#endif
 
242
 
 
243
    if (pub->default_string == NULL)
 
244
        pub->default_string = "";
 
245
 
 
246
    if (methods->get_values == NULL)
 
247
        methods->get_values = pub_methods->get_values;
 
248
 
 
249
    if (methods->get_resource == NULL)
 
250
        methods->get_resource = pub_methods->get_resource;
 
251
 
 
252
    return load_public(lcd);
 
253
}
 
254
 
 
255
static void
 
256
destroy_core(
 
257
    XLCd lcd)
 
258
{
 
259
    if (lcd->core) {
 
260
        if (lcd->core->name)
 
261
            Xfree(lcd->core->name);
 
262
        Xfree(lcd->core);
 
263
    }
 
264
 
 
265
    if (lcd->methods)
 
266
        Xfree(lcd->methods);
 
267
 
 
268
    Xfree(lcd);
 
269
}
 
270
 
 
271
static void
 
272
destroy(
 
273
    XLCd lcd)
 
274
{
 
275
    XLCdPublicPart *pub = XLC_PUBLIC_PART(lcd);
 
276
 
 
277
    _XlcDestroyLocaleDataBase(lcd);
 
278
 
 
279
    if (pub->siname)
 
280
        Xfree(pub->siname);
 
281
    if (pub->encoding_name)
 
282
        Xfree(pub->encoding_name);
 
283
 
 
284
    destroy_core(lcd);
 
285
}
 
286
 
 
287
static XlcResource resources[] = {
 
288
    { XlcNCodeset, NULLQUARK, sizeof(char *),
 
289
      XOffsetOf(XLCdPublicRec, pub.codeset), XlcGetMask },
 
290
    { XlcNDefaultString, NULLQUARK, sizeof(char *),
 
291
      XOffsetOf(XLCdPublicRec, pub.default_string), XlcGetMask },
 
292
    { XlcNEncodingName, NULLQUARK, sizeof(char *),
 
293
      XOffsetOf(XLCdPublicRec, pub.encoding_name), XlcGetMask },
 
294
    { XlcNLanguage, NULLQUARK, sizeof(char *),
 
295
      XOffsetOf(XLCdPublicRec, pub.language), XlcGetMask },
 
296
    { XlcNMbCurMax, NULLQUARK, sizeof(int),
 
297
      XOffsetOf(XLCdPublicRec, pub.mb_cur_max), XlcGetMask },
 
298
    { XlcNStateDependentEncoding, NULLQUARK, sizeof(Bool),
 
299
      XOffsetOf(XLCdPublicRec, pub.is_state_depend), XlcGetMask },
 
300
    { XlcNTerritory, NULLQUARK, sizeof(char *),
 
301
      XOffsetOf(XLCdPublicRec, pub.territory), XlcGetMask }
 
302
};
 
303
 
 
304
static char *
 
305
get_values(
 
306
    XLCd lcd,
 
307
    XlcArgList args,
 
308
    int num_args)
 
309
{
 
310
    XLCdPublic pub = (XLCdPublic) lcd->core;
 
311
 
 
312
    if (resources[0].xrm_name == NULLQUARK)
 
313
        _XlcCompileResourceList(resources, XlcNumber(resources));
 
314
 
 
315
    return _XlcGetValues((XPointer) pub, resources, XlcNumber(resources), args,
 
316
                         num_args, XlcGetMask);
 
317
}