~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source4/heimdal/lib/hcrypto/rand-fortuna.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#include <stdio.h>
35
35
#include <stdlib.h>
36
36
#include <rand.h>
 
37
#include <heim_threads.h>
37
38
 
 
39
#ifdef KRB5
 
40
#include <krb5-types.h>
 
41
#endif
38
42
#include <roken.h>
39
43
 
40
44
#include "randi.h"
439
443
static unsigned resend_bytes;
440
444
 
441
445
/*
 
446
 * This mutex protects all of the above static elements from concurrent
 
447
 * access by multiple threads
 
448
 */
 
449
static HEIMDAL_MUTEX fortuna_mutex = HEIMDAL_MUTEX_INITIALIZER;
 
450
 
 
451
/*
442
452
 * Try our best to do an inital seed
443
453
 */
444
454
#define INIT_BYTES      128
445
455
 
 
456
/*
 
457
 * fortuna_mutex must be held across calls to this function
 
458
 */
 
459
 
446
460
static int
447
461
fortuna_reseed(void)
448
462
{
451
465
    if (!init_done)
452
466
        abort();
453
467
 
 
468
#ifndef NO_RAND_UNIX_METHOD
454
469
    {
455
470
        unsigned char buf[INIT_BYTES];
456
471
        if ((*hc_rand_unix_method.bytes)(buf, sizeof(buf)) == 1) {
459
474
            memset(buf, 0, sizeof(buf));
460
475
        }
461
476
    }
 
477
#endif
462
478
#ifdef HAVE_ARC4RANDOM
463
479
    {
464
480
        uint32_t buf[INIT_BYTES / sizeof(uint32_t)];
470
486
        entropy_p = 1;
471
487
    }
472
488
#endif
 
489
#ifndef NO_RAND_EGD_METHOD
473
490
    /*
474
491
     * Only to get egd entropy if /dev/random or arc4rand failed since
475
492
     * it can be horribly slow to generate new bits.
482
499
            memset(buf, 0, sizeof(buf));
483
500
        }
484
501
    }
 
502
#endif
485
503
    /*
486
504
     * Fall back to gattering data from timer and secret files, this
487
505
     * is really the last resort.
521
539
        gettimeofday(&tv, NULL);
522
540
        add_entropy(&main_state, (void *)&tv, sizeof(tv));
523
541
    }
 
542
#ifdef HAVE_GETUID
524
543
    {
525
544
        uid_t u = getuid();
526
545
        add_entropy(&main_state, (void *)&u, sizeof(u));
527
546
    }
 
547
#endif
528
548
    return entropy_p;
529
549
}
530
550
 
 
551
/*
 
552
 * fortuna_mutex must be held by callers of this function
 
553
 */
531
554
static int
532
555
fortuna_init(void)
533
556
{
546
569
static void
547
570
fortuna_seed(const void *indata, int size)
548
571
{
 
572
    HEIMDAL_MUTEX_lock(&fortuna_mutex);
 
573
 
549
574
    fortuna_init();
550
575
    add_entropy(&main_state, indata, size);
551
576
    if (size >= INIT_BYTES)
552
577
        have_entropy = 1;
 
578
 
 
579
    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
553
580
}
554
581
 
555
582
static int
556
583
fortuna_bytes(unsigned char *outdata, int size)
557
584
{
 
585
    int ret = 0;
 
586
 
 
587
    HEIMDAL_MUTEX_lock(&fortuna_mutex);
 
588
 
558
589
    if (!fortuna_init())
559
 
        return 0;
 
590
        goto out;
 
591
 
560
592
    resend_bytes += size;
561
593
    if (resend_bytes > FORTUNA_RESEED_BYTE || resend_bytes < size) {
562
594
        resend_bytes = 0;
563
595
        fortuna_reseed();
564
596
    }
565
597
    extract_data(&main_state, size, outdata);
566
 
    return 1;
 
598
    ret = 1;
 
599
 
 
600
out:
 
601
    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
 
602
 
 
603
    return ret;
567
604
}
568
605
 
569
606
static void
570
607
fortuna_cleanup(void)
571
608
{
 
609
    HEIMDAL_MUTEX_lock(&fortuna_mutex);
 
610
 
572
611
    init_done = 0;
573
612
    have_entropy = 0;
574
613
    memset(&main_state, 0, sizeof(main_state));
 
614
 
 
615
    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
575
616
}
576
617
 
577
618
static void
589
630
static int
590
631
fortuna_status(void)
591
632
{
592
 
    return fortuna_init() ? 1 : 0;
 
633
    int result;
 
634
 
 
635
    HEIMDAL_MUTEX_lock(&fortuna_mutex);
 
636
    result = fortuna_init();
 
637
    HEIMDAL_MUTEX_unlock(&fortuna_mutex);
 
638
 
 
639
    return result ? 1 : 0;
593
640
}
594
641
 
595
642
const RAND_METHOD hc_rand_fortuna_method = {