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

« back to all changes in this revision

Viewing changes to unix/xc/lib/SM/SMlibint.h

  • 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: SMlibint.h,v 1.4 2001/02/09 02:03:30 xorgcvs Exp $ */
 
2
 
 
3
/*
 
4
 
 
5
Copyright 1993, 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/SM/SMlibint.h,v 1.4 2001/12/14 19:53:55 dawes Exp $ */
 
29
 
 
30
/*
 
31
 * Author: Ralph Mor, X Consortium
 
32
 */
 
33
 
 
34
#ifndef _SMLIBINT_H_
 
35
#define _SMLIBINT_H_
 
36
 
 
37
#include <X11/Xos.h>
 
38
#include <X11/Xfuncs.h>
 
39
#include <X11/Xmd.h>
 
40
#include <X11/ICE/ICEmsg.h>
 
41
#include <X11/ICE/ICEproto.h>
 
42
#include <X11/SM/SMproto.h>
 
43
 
 
44
#include <stdlib.h>
 
45
 
 
46
#ifndef NULL
 
47
#include <stddef.h>
 
48
#endif
 
49
 
 
50
 
 
51
/*
 
52
 * Vendor & Release
 
53
 */
 
54
 
 
55
#define SmVendorString  "MIT"
 
56
#define SmReleaseString "1.0"
 
57
 
 
58
 
 
59
/*
 
60
 * Pad to a 64 bit boundary
 
61
 */
 
62
 
 
63
#define PAD64(_bytes) ((8 - ((unsigned int) (_bytes) % 8)) % 8)
 
64
 
 
65
#define PADDED_BYTES64(_bytes) (_bytes + PAD64 (_bytes))
 
66
 
 
67
 
 
68
/*
 
69
 * Pad to 32 bit boundary
 
70
 */
 
71
 
 
72
#define PAD32(_bytes) ((4 - ((unsigned int) (_bytes) % 4)) % 4)
 
73
 
 
74
#define PADDED_BYTES32(_bytes) (_bytes + PAD32 (_bytes))
 
75
 
 
76
 
 
77
/*
 
78
 * Number of 8 byte units in _bytes.
 
79
 */
 
80
 
 
81
#define WORD64COUNT(_bytes) (((unsigned int) ((_bytes) + 7)) >> 3)
 
82
 
 
83
 
 
84
/*
 
85
 * Compute the number of bytes for an ARRAY8 representation
 
86
 */
 
87
 
 
88
#define ARRAY8_BYTES(_len) (4 + _len + PAD64 (4 + _len))
 
89
 
 
90
 
 
91
 
 
92
/*
 
93
 * Byte swapping
 
94
 */
 
95
 
 
96
/* byte swap a long literal */
 
97
#define lswapl(_val) ((((_val) & 0xff) << 24) |\
 
98
                   (((_val) & 0xff00) << 8) |\
 
99
                   (((_val) & 0xff0000) >> 8) |\
 
100
                   (((_val) >> 24) & 0xff))
 
101
 
 
102
/* byte swap a short literal */
 
103
#define lswaps(_val) ((((_val) & 0xff) << 8) | (((_val) >> 8) & 0xff))
 
104
 
 
105
 
 
106
/*
 
107
 * STORE macros
 
108
 */
 
109
 
 
110
#ifndef WORD64
 
111
 
 
112
#define STORE_CARD32(_pBuf, _val) \
 
113
{ \
 
114
    *((CARD32 *) _pBuf) = _val; \
 
115
    _pBuf += 4; \
 
116
}
 
117
 
 
118
#else /* WORD64 */
 
119
 
 
120
#define STORE_CARD32(_pBuf, _val) \
 
121
{ \
 
122
    struct { \
 
123
        int value   :32; \
 
124
    } _d; \
 
125
    _d.value = _val; \
 
126
    memcpy (_pBuf, &_d, 4); \
 
127
    _pBuf += 4; \
 
128
}
 
129
 
 
130
#endif /* WORD64 */
 
131
 
 
132
 
 
133
/*
 
134
 * EXTRACT macros
 
135
 */
 
136
 
 
137
#ifndef WORD64
 
138
 
 
139
#define EXTRACT_CARD16(_pBuf, _swap, _val) \
 
140
{ \
 
141
    _val = *((CARD16 *) _pBuf); \
 
142
    _pBuf += 2; \
 
143
    if (_swap) \
 
144
        _val = lswaps (_val); \
 
145
}
 
146
 
 
147
#define EXTRACT_CARD32(_pBuf, _swap, _val) \
 
148
{ \
 
149
    _val = *((CARD32 *) _pBuf); \
 
150
    _pBuf += 4; \
 
151
    if (_swap) \
 
152
        _val = lswapl (_val); \
 
153
}
 
154
 
 
155
#else /* WORD64 */
 
156
 
 
157
#define EXTRACT_CARD16(_pBuf, _swap, _val) \
 
158
{ \
 
159
    _val = *(_pBuf + 0) & 0xff;         /* 0xff incase _pBuf is signed */ \
 
160
    _val <<= 8; \
 
161
    _val |= *(_pBuf + 1) & 0xff;\
 
162
    _pBuf += 2; \
 
163
    if (_swap) \
 
164
        _val = lswaps (_val); \
 
165
}
 
166
 
 
167
#define EXTRACT_CARD32(_pBuf, _swap, _val) \
 
168
{ \
 
169
    _val = *(_pBuf + 0) & 0xff;         /* 0xff incase _pBuf is signed */ \
 
170
    _val <<= 8; \
 
171
    _val |= *(_pBuf + 1) & 0xff;\
 
172
    _val <<= 8; \
 
173
    _val |= *(_pBuf + 2) & 0xff;\
 
174
    _val <<= 8; \
 
175
    _val |= *(_pBuf + 3) & 0xff;\
 
176
    _pBuf += 4; \
 
177
    if (_swap) \
 
178
        _val = lswapl (_val); \
 
179
}
 
180
 
 
181
#endif /* WORD64 */
 
182
 
 
183
 
 
184
/*
 
185
 * Compute the number of bytes for a LISTofPROPERTY representation
 
186
 */
 
187
 
 
188
#define LISTOF_PROP_BYTES(_numProps, _props, _bytes) \
 
189
{ \
 
190
    int _i, _j; \
 
191
    _bytes = 8; \
 
192
    for (_i = 0; _i < _numProps; _i++) \
 
193
    { \
 
194
        _bytes += (8 + ARRAY8_BYTES (strlen (_props[_i]->name)) + \
 
195
            ARRAY8_BYTES (strlen (_props[_i]->type))); \
 
196
\
 
197
        for (_j = 0; _j < _props[_i]->num_vals; _j++) \
 
198
            _bytes += ARRAY8_BYTES (_props[_i]->vals[_j].length); \
 
199
    } \
 
200
}
 
201
 
 
202
 
 
203
/*
 
204
 * STORE FOO
 
205
 */
 
206
 
 
207
#define STORE_ARRAY8(_pBuf, _len, _array8) \
 
208
{ \
 
209
    STORE_CARD32 (_pBuf, _len); \
 
210
    memcpy (_pBuf, _array8, _len); \
 
211
    _pBuf += _len; \
 
212
    if (PAD64 (4 + _len)) \
 
213
        _pBuf += PAD64 (4 + _len); \
 
214
}
 
215
 
 
216
#define STORE_LISTOF_PROPERTY(_pBuf, _count, _props) \
 
217
{ \
 
218
    int _i, _j; \
 
219
    STORE_CARD32 (_pBuf, _count); \
 
220
    _pBuf += 4; \
 
221
    for (_i = 0; _i < _count; _i++) \
 
222
    { \
 
223
        STORE_ARRAY8 (_pBuf, strlen (_props[_i]->name), _props[_i]->name); \
 
224
        STORE_ARRAY8 (_pBuf, strlen (_props[_i]->type), _props[_i]->type); \
 
225
        STORE_CARD32 (_pBuf, _props[_i]->num_vals); \
 
226
        _pBuf += 4; \
 
227
        for (_j = 0; _j < _props[_i]->num_vals; _j++) \
 
228
        { \
 
229
            STORE_ARRAY8 (_pBuf, _props[_i]->vals[_j].length, \
 
230
                (char *) _props[_i]->vals[_j].value); \
 
231
        } \
 
232
    } \
 
233
}
 
234
 
 
235
 
 
236
/*
 
237
 * EXTRACT FOO
 
238
 */
 
239
 
 
240
#define EXTRACT_ARRAY8(_pBuf, _swap, _len, _array8) \
 
241
{ \
 
242
    EXTRACT_CARD32 (_pBuf, _swap, _len); \
 
243
    _array8 = (char *) malloc (_len + 1); \
 
244
    memcpy (_array8, _pBuf, _len); \
 
245
    _array8[_len] = '\0'; \
 
246
    _pBuf += _len; \
 
247
    if (PAD64 (4 + _len)) \
 
248
        _pBuf += PAD64 (4 + _len); \
 
249
}
 
250
 
 
251
#define EXTRACT_ARRAY8_AS_STRING(_pBuf, _swap, _string) \
 
252
{ \
 
253
    CARD32 _len; \
 
254
    EXTRACT_CARD32 (_pBuf, _swap, _len); \
 
255
    _string = (char *) malloc (_len + 1); \
 
256
    memcpy (_string, _pBuf, _len); \
 
257
    _string[_len] = '\0'; \
 
258
    _pBuf += _len; \
 
259
    if (PAD64 (4 + _len)) \
 
260
        _pBuf += PAD64 (4 + _len); \
 
261
}
 
262
 
 
263
#define EXTRACT_LISTOF_PROPERTY(_pBuf, _swap, _count, _props) \
 
264
{ \
 
265
    int _i, _j; \
 
266
    EXTRACT_CARD32 (_pBuf, _swap, _count); \
 
267
    _pBuf += 4; \
 
268
    _props = (SmProp **) malloc (_count * sizeof (SmProp *)); \
 
269
    for (_i = 0; _i < _count; _i++) \
 
270
    { \
 
271
        _props[_i] = (SmProp *) malloc (sizeof (SmProp)); \
 
272
        EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->name); \
 
273
        EXTRACT_ARRAY8_AS_STRING (_pBuf, _swap, _props[_i]->type); \
 
274
        EXTRACT_CARD32 (_pBuf, _swap, _props[_i]->num_vals); \
 
275
        _pBuf += 4; \
 
276
        _props[_i]->vals = (SmPropValue *) malloc ( \
 
277
            _props[_i]->num_vals * sizeof (SmPropValue)); \
 
278
        for (_j = 0; _j < _props[_i]->num_vals; _j++) \
 
279
        { \
 
280
            char *_temp; \
 
281
            EXTRACT_ARRAY8 (_pBuf, _swap, _props[_i]->vals[_j].length, _temp);\
 
282
            _props[_i]->vals[_j].value = (SmPointer) _temp; \
 
283
        } \
 
284
    } \
 
285
}
 
286
 
 
287
 
 
288
#define SKIP_ARRAY8(_pBuf, _swap) \
 
289
{ \
 
290
    CARD32 _len; \
 
291
    EXTRACT_CARD32 (_pBuf, _swap, _len); \
 
292
    _pBuf += _len; \
 
293
    if (PAD64 (4 + _len)) \
 
294
        _pBuf += PAD64 (4 + _len); \
 
295
}
 
296
 
 
297
#define SKIP_LISTOF_PROPERTY(_pBuf, _swap) \
 
298
{ \
 
299
    int _i, _j; \
 
300
    CARD32 _count; \
 
301
    EXTRACT_CARD32 (_pBuf, _swap, _count); \
 
302
    _pBuf += 4; \
 
303
    for (_i = 0; _i < _count; _i++) \
 
304
    { \
 
305
        CARD32 _numvals; \
 
306
        SKIP_ARRAY8 (_pBuf, _swap); \
 
307
        SKIP_ARRAY8 (_pBuf, _swap); \
 
308
        EXTRACT_CARD32 (_pBuf, _swap, _numvals); \
 
309
        _pBuf += 4; \
 
310
        for (_j = 0; _j < _numvals; _j++) \
 
311
            SKIP_ARRAY8 (_pBuf, _swap);\
 
312
    } \
 
313
}
 
314
 
 
315
 
 
316
/*
 
317
 * Client replies not processed by callbacks (we block for them).
 
318
 */
 
319
 
 
320
typedef struct {
 
321
    Status      status;         /* if 1, client successfully registered */
 
322
    char        *client_id;
 
323
} _SmcRegisterClientReply;
 
324
 
 
325
 
 
326
/*
 
327
 * Waiting for Interact
 
328
 */
 
329
 
 
330
typedef struct _SmcInteractWait {
 
331
    SmcInteractProc             interact_proc;
 
332
    SmPointer                   client_data;
 
333
    struct _SmcInteractWait     *next;
 
334
} _SmcInteractWait;
 
335
 
 
336
 
 
337
/*
 
338
 * Waiting for SaveYourselfPhase2
 
339
 */
 
340
 
 
341
typedef struct _SmcPhase2Wait {
 
342
    SmcSaveYourselfPhase2Proc   phase2_proc;
 
343
    SmPointer                   client_data;
 
344
} _SmcPhase2Wait;
 
345
 
 
346
 
 
347
/*
 
348
 * Waiting for Properties Reply
 
349
 */
 
350
 
 
351
typedef struct _SmcPropReplyWait {
 
352
    SmcPropReplyProc            prop_reply_proc;
 
353
    SmPointer                   client_data;
 
354
    struct _SmcPropReplyWait    *next;
 
355
} _SmcPropReplyWait;
 
356
 
 
357
 
 
358
 
 
359
/*
 
360
 * Client connection object
 
361
 */
 
362
 
 
363
struct _SmcConn {
 
364
 
 
365
    /*
 
366
     * Some state.
 
367
     */
 
368
 
 
369
    unsigned int save_yourself_in_progress : 1;
 
370
    unsigned int shutdown_in_progress : 1;
 
371
    unsigned int unused1 : 6;                /* future use */
 
372
    unsigned int unused2 : 8;                /* future use */
 
373
 
 
374
 
 
375
    /*
 
376
     * We use ICE to esablish a connection with the SM.
 
377
     */
 
378
 
 
379
    IceConn             iceConn;
 
380
 
 
381
 
 
382
    /*
 
383
     * Major and minor versions of the XSMP.
 
384
     */
 
385
 
 
386
    int                 proto_major_version;
 
387
    int                 proto_minor_version;
 
388
 
 
389
 
 
390
    /*
 
391
     * The session manager vendor and release number.
 
392
     */
 
393
 
 
394
    char                *vendor;
 
395
    char                *release;
 
396
 
 
397
 
 
398
    /*
 
399
     * The Client Id uniquely identifies this client to the session manager.
 
400
     */
 
401
 
 
402
    char                *client_id;
 
403
 
 
404
 
 
405
    /*
 
406
     * Callbacks to be invoked when messages arrive from the session manager.
 
407
     * These callbacks are specified at SmcOpenConnection time.
 
408
     */
 
409
 
 
410
    SmcCallbacks        callbacks;
 
411
 
 
412
 
 
413
    /*
 
414
     * We keep track of all Interact Requests sent by the client.  When the
 
415
     * Interact message arrives, we remove it from the list (a FIFO list
 
416
     * is maintained).
 
417
     */
 
418
 
 
419
    _SmcInteractWait    *interact_waits;
 
420
 
 
421
 
 
422
    /*
 
423
     * If we send a SaveYourselfPhase2Request, we wait for SaveYourselfPhase2.
 
424
     */
 
425
 
 
426
    _SmcPhase2Wait      *phase2_wait;
 
427
 
 
428
 
 
429
    /*
 
430
     * We keep track of all Get Properties sent by the client.  When the
 
431
     * Properties Reply arrives, we remove it from the list (a FIFO list
 
432
     * is maintained).
 
433
     */
 
434
 
 
435
    _SmcPropReplyWait   *prop_reply_waits;
 
436
};
 
437
 
 
438
 
 
439
 
 
440
/*
 
441
 * Session manager connection object
 
442
 */
 
443
 
 
444
struct _SmsConn {
 
445
 
 
446
    /*
 
447
     * Some state.
 
448
     */
 
449
 
 
450
    unsigned int save_yourself_in_progress : 1;
 
451
    unsigned int can_cancel_shutdown : 1;
 
452
    unsigned int interact_in_progress : 1;
 
453
    unsigned int unused1 : 5;                /* future use */
 
454
    unsigned int unused2 : 8;                /* future use */
 
455
 
 
456
 
 
457
    /*
 
458
     * We use ICE to esablish a connection with the client.
 
459
     */
 
460
 
 
461
    IceConn             iceConn;
 
462
 
 
463
 
 
464
    /*
 
465
     * Major and minor versions of the XSMP.
 
466
     */
 
467
 
 
468
    int                 proto_major_version;
 
469
    int                 proto_minor_version;
 
470
 
 
471
 
 
472
    /*
 
473
     * The Client Id uniquely identifies this client to the session manager.
 
474
     */
 
475
 
 
476
    char                *client_id;
 
477
 
 
478
 
 
479
    /*
 
480
     * Callbacks to be invoked when messages arrive from the client.
 
481
     */
 
482
 
 
483
    SmsCallbacks        callbacks;
 
484
 
 
485
 
 
486
    /*
 
487
     * What type of interaction is allowed - SmInteractStyle{None,Errors,Any}
 
488
     */
 
489
 
 
490
    char                interaction_allowed;
 
491
};
 
492
 
 
493
 
 
494
 
 
495
/*
 
496
 * Extern declarations
 
497
 */
 
498
 
 
499
extern int     _SmcOpcode;
 
500
extern int     _SmsOpcode;
 
501
 
 
502
extern int              _SmVersionCount;
 
503
extern IcePoVersionRec  _SmcVersions[];
 
504
extern IcePaVersionRec  _SmsVersions[];
 
505
 
 
506
extern int              _SmAuthCount;
 
507
extern char             *_SmAuthNames[];
 
508
extern IcePoAuthProc    _SmcAuthProcs[];
 
509
extern IcePaAuthProc    _SmsAuthProcs[];
 
510
 
 
511
extern SmsNewClientProc _SmsNewClientProc;
 
512
extern SmPointer        _SmsNewClientData;
 
513
 
 
514
extern SmcErrorHandler _SmcErrorHandler;
 
515
extern SmsErrorHandler _SmsErrorHandler;
 
516
 
 
517
#endif /* _SMLIBINT_H_ */