~ubuntu-branches/ubuntu/precise/xdm/precise

« back to all changes in this revision

Viewing changes to genauth.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2011-01-30 00:53:09 UTC
  • mfrom: (9.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110130005309-30mjjyk7div7d494
Tags: 1:1.1.10-3ubuntu1
* Merge from debian unstable.  Remaining changes: (LP: #682196)
  - debian/{rules, xdm.install, local/ubuntu*}:
    + Add Ubuntu graphics and configure xdm to use them by default.
  - debian/patches/ubuntu_no_whiteglass.diff: Don't hardcode
    the default Xcursor theme to whiteglass. Use the Ubuntu
    default x-cursor-theme instead.
* debian/patches/ftbfs_binutils-gold.diff: Fix FTBFS with binutils-gold
  and ld --as-needed. (Closes: #556694)
* Dropped changes, no longer applicable:
  - debian/{xdm.postinst.in, xdm.postrm.in, xdm.preinst.in}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $XdotOrg: xc/programs/xdm/genauth.c,v 1.1.4.5 2003/12/20 00:28:31 kaleb Exp $ */
2
 
/* $Xorg: genauth.c,v 1.5 2001/02/09 02:05:40 xorgcvs Exp $ */
3
1
/*
4
2
 
5
3
Copyright 1988, 1998  The Open Group
27
25
from The Open Group.
28
26
 
29
27
*/
30
 
/* $XFree86: xc/programs/xdm/genauth.c,v 3.23 2003/12/20 19:45:12 dawes Exp $ */
31
28
 
32
29
/*
33
30
 * xdm - display manager daemon
34
31
 * Author:  Keith Packard, MIT X Consortium
35
32
 */
36
33
 
37
 
# include   <X11/Xauth.h>
38
 
# include   <X11/Xos.h>
 
34
#include   <X11/Xauth.h>
 
35
#include   <X11/Xos.h>
39
36
 
40
 
# include   "dm.h"
41
 
# include   "dm_auth.h"
42
 
# include   "dm_error.h"
 
37
#include   "dm.h"
 
38
#include   "dm_auth.h"
 
39
#include   "dm_error.h"
43
40
 
44
41
#include <errno.h>
45
42
 
61
58
typedef struct auth_ks_struct { auth_cblock _; } auth_wrapper_schedule[16];
62
59
 
63
60
extern int _XdmcpAuthSetup(unsigned char *, auth_wrapper_schedule);
64
 
extern int _XdmcpAuthDoIt(unsigned char *, unsigned char *, 
 
61
extern int _XdmcpAuthDoIt(unsigned char *, unsigned char *,
65
62
    auth_wrapper_schedule, int);
66
63
extern void _XdmcpWrapperToOddParity(unsigned char *, unsigned char *);
67
64
 
77
74
#endif
78
75
 
79
76
#ifdef POLL_DEV_RANDOM
80
 
#include <poll.h>
 
77
# include <poll.h>
81
78
static int
82
79
pollRandomDevice (int fd)
83
80
{
89
86
    return poll(&fds, 1, 5000);
90
87
}
91
88
#else
92
 
#define pollRandomDevice(fd) 1
 
89
# define pollRandomDevice(fd) 1
93
90
#endif
94
91
 
95
92
#if !defined(ARC4_RANDOM)
166
163
 */
167
164
 
168
165
/* The four core functions - F1 is optimized somewhat */
169
 
#define F1(x, y, z) (z ^ (x & (y ^ z)))
170
 
#define F2(x, y, z) F1 (z, x, y)
171
 
#define F3(x, y, z) (x ^ y ^ z)
172
 
#define F4(x, y, z) (y ^ (x | ~z))
 
166
# define F1(x, y, z) (z ^ (x & (y ^ z)))
 
167
# define F2(x, y, z) F1 (z, x, y)
 
168
# define F3(x, y, z) (x ^ y ^ z)
 
169
# define F4(x, y, z) (y ^ (x | ~z))
173
170
 
174
171
/* This is the central step in the MD5 algorithm. */
175
 
#define pmd5_step(f, w, x, y, z, data, s) \
 
172
# define pmd5_step(f, w, x, y, z, data, s) \
176
173
        ( w += (f(x, y, z) + data) & 0xffffffff,  w = w<<s | w>>(32-s),  w += x )
177
174
 
178
175
/*
179
176
 * The core of the MD5 algorithm, this alters an existing MD5 hash to
180
177
 * reflect the addition of 16 longwords of new data.
181
178
 */
182
 
static void 
 
179
static void
183
180
pmd5_hash (CARD32 *out, const CARD32 in[16])
184
181
{
185
182
    CARD32 a, b, c, d;
205
202
    pmd5_step(F1, d, a, b, c, in[13] + 0xfd987193, 12);
206
203
    pmd5_step(F1, c, d, a, b, in[14] + 0xa679438e, 17);
207
204
    pmd5_step(F1, b, c, d, a, in[15] + 0x49b40821, 22);
208
 
                
 
205
 
209
206
    pmd5_step(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
210
207
    pmd5_step(F2, d, a, b, c, in[6] + 0xc040b340, 9);
211
208
    pmd5_step(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
222
219
    pmd5_step(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
223
220
    pmd5_step(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
224
221
    pmd5_step(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
225
 
                
 
222
 
226
223
    pmd5_step(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
227
224
    pmd5_step(F3, d, a, b, c, in[8] + 0x8771f681, 11);
228
225
    pmd5_step(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
239
236
    pmd5_step(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
240
237
    pmd5_step(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
241
238
    pmd5_step(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
242
 
                
 
239
 
243
240
    pmd5_step(F4, a, b, c, d, in[0] + 0xf4292244, 6);
244
241
    pmd5_step(F4, d, a, b, c, in[7] + 0x432aff97, 10);
245
242
    pmd5_step(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
282
279
            break;
283
280
        if (cnt < 0) {
284
281
            close (fd);
285
 
            Debug("cannot read entropy source \"%s\", errno=%d\n", 
 
282
            Debug("cannot read entropy source \"%s\", errno=%d\n",
286
283
                  name, errno);
287
284
            return -1;
288
285
        }
302
299
    add_entropy((CARD32 *)&now, sizeof(now)/sizeof(CARD32));
303
300
}
304
301
 
305
 
#define BSIZ 0x10000
 
302
# define BSIZ 0x10000
306
303
 
307
304
void
308
305
AddOtherEntropy (void)
325
322
    AddTimerEntropy();
326
323
    if ((readlen = sumFile (randomFile, BSIZ, SEEK_SET, offset)) == BSIZ) {
327
324
        offset += readlen;
328
 
#ifdef FRAGILE_DEV_MEM
 
325
# ifdef FRAGILE_DEV_MEM
329
326
        if (!strcmp (randomFile, "/dev/mem")) {
330
327
            if (offset == 0xa0000) /* skip 640kB-1MB ROM mappings */
331
328
                offset = 0x100000;
332
329
            else if (offset == 0xf00000) /* skip 15-16MB memory hole */
333
330
                offset = 0x1000000;
334
331
        }
335
 
#endif
 
332
# endif
336
333
        return;
337
334
    } else if (readlen >= 0 && offset) {
338
335
        if ((offset = sumFile (randomFile, BSIZ, SEEK_SET, 0)) == BSIZ)
349
346
{
350
347
    CARD32 sum[4];
351
348
 
352
 
#ifdef  ARC4_RANDOM
 
349
# ifdef ARC4_RANDOM
353
350
    sum[0] = arc4random();
354
351
    sum[1] = arc4random();
355
352
    *(u_char *)sum = 0;
356
353
 
357
354
    _XdmcpWrapperToOddParity((unsigned char *)sum, key);
358
 
#else
 
355
# else
359
356
    unsigned char   tmpkey[8];
360
357
 
361
 
#ifdef DEV_RANDOM
 
358
#  ifdef DEV_RANDOM
362
359
    int fd;
363
 
    
 
360
 
364
361
    if ((fd = open(randomDevice, O_RDONLY)) >= 0) {
365
362
        if (pollRandomDevice(fd) && read(fd, tmpkey, 8) == 8) {
366
363
            tmpkey[0] = 0;
367
364
            _XdmcpWrapperToOddParity(tmpkey, key);
368
365
            close(fd);
369
 
            return;     
 
366
            return;
370
367
        } else {
371
368
            close(fd);
372
369
        }
373
370
    } else {
374
 
        LogError("Cannot open randomDevice \"%s\", errno = %d\n", 
 
371
        LogError("Cannot open randomDevice \"%s\", errno = %d\n",
375
372
          randomDevice, errno);
376
373
    }
377
 
#endif    
 
374
#  endif
378
375
    /*  Try some pseudo-random number genrator daemon next */
379
376
    if (prngdSocket != NULL || prngdPort != 0) {
380
 
            if (get_prngd_bytes(tmpkey, sizeof(tmpkey), prngdPort, 
 
377
            if (get_prngd_bytes((char *)tmpkey, sizeof(tmpkey), prngdPort,
381
378
                    prngdSocket) == 0) {
382
379
                    tmpkey[0] = 0;
383
380
                    _XdmcpWrapperToOddParity(tmpkey, key);
395
392
    longtochars (sum[1], tmpkey+4);
396
393
    tmpkey[0] = 0;
397
394
    _XdmcpWrapperToOddParity (tmpkey, key);
398
 
#endif
 
395
# endif
399
396
}
400
397
 
401
398
#endif
411
408
    static int      xdmcpAuthInited;
412
409
    long            ldata[2];
413
410
 
414
 
#ifdef ITIMER_REAL
 
411
# ifdef ITIMER_REAL
415
412
    struct timeval  now;
416
413
 
417
414
    X_GETTIMEOFDAY (&now);
418
415
    ldata[0] = now.tv_usec;
419
416
    ldata[1] = now.tv_sec;
420
 
#else
 
417
# else
421
418
    ldata[0] = time ((long *) 0);
422
419
    ldata[1] = getpid ();
423
 
#endif
424
 
    
 
420
# endif
 
421
 
425
422
    longtochars (ldata[0], data+0);
426
423
    longtochars (ldata[1], data+4);
427
424
    if (!xdmcpAuthInited)
440
437
    }
441
438
    return 1;
442
439
#else /* !XDMAUTH */
443
 
#ifdef ARC4_RANDOM
 
440
# ifdef ARC4_RANDOM
444
441
    CARD32 *rnd = (CARD32 *)auth;
445
442
    int i;
446
443
 
447
444
    for (i = 0; i < len; i += 4)
448
445
        rnd[i / 4] = arc4random();
449
446
    return 1;
450
 
#else /* !ARC4_RANDOM */
 
447
# else /* !ARC4_RANDOM */
451
448
    CARD32 tmp[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 };
452
 
#ifdef DEV_RANDOM
 
449
#  ifdef DEV_RANDOM
453
450
    int fd;
454
 
    
 
451
 
455
452
    if ((fd = open(randomDevice, O_RDONLY)) >= 0) {
456
 
        if (pollRandomDevice(fd) && 
 
453
        if (pollRandomDevice(fd) &&
457
454
            read(fd, auth, len) == len) {
458
455
            close(fd);
459
456
            return 1;
461
458
        close(fd);
462
459
        LogError("Cannot read randomDevice \"%s\", errno=%d\n",
463
460
                 randomDevice, errno);
464
 
    } else 
465
 
        LogError("Cannot open randomDevice \"%s\", errno = %d\n", 
 
461
    } else
 
462
        LogError("Cannot open randomDevice \"%s\", errno = %d\n",
466
463
                 randomDevice, errno);
467
 
#endif /* DEV_RANDOM */
 
464
#  endif /* DEV_RANDOM */
468
465
    /*  Try some pseudo-random number genrator daemon next */
469
466
    if (prngdSocket != NULL || prngdPort != 0) {
470
467
            if (get_prngd_bytes(auth, len, prngdPort, prngdSocket) == 0) {
479
476
    add_entropy (tmp + 2, 1);
480
477
    memcpy (auth, tmp, len);
481
478
    return 1;
482
 
#endif /* !ARC4_RANDOM */
 
479
# endif /* !ARC4_RANDOM */
483
480
#endif /* !HASXDMAUTH */
484
481
}