~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/lib/kdb/kdb_cpw.c

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
/* lib/kdb/kdb_cpw.c */
2
3
/*
3
 
 * lib/kdb/kdb_cpw.c
4
 
 *
5
4
 * Copyright 1995, 2009 by the Massachusetts Institute of Technology.
6
5
 * All Rights Reserved.
7
6
 *
23
22
 * M.I.T. makes no representations about the suitability of
24
23
 * this software for any purpose.  It is provided "as is" without express
25
24
 * or implied warranty.
26
 
 *
27
25
 */
28
 
 
29
26
/*
30
27
 * Copyright (C) 1998 by the FundsXpress, INC.
31
28
 *
342
339
    return(retval);
343
340
}
344
341
 
 
342
/* Construct a random explicit salt. */
 
343
static krb5_error_code
 
344
make_random_salt(krb5_context context, krb5_keysalt *salt_out)
 
345
{
 
346
    krb5_error_code retval;
 
347
    unsigned char rndbuf[8];
 
348
    krb5_data salt, rnd = make_data(rndbuf, sizeof(rndbuf));
 
349
    unsigned int i;
 
350
 
 
351
    /*
 
352
     * Salts are limited by RFC 4120 to 7-bit ASCII.  For ease of examination
 
353
     * and to avoid certain folding issues for older enctypes, we use printable
 
354
     * characters with four fixed bits and four random bits, encoding 64
 
355
     * psuedo-random bits into 16 bytes.
 
356
     */
 
357
    retval = krb5_c_random_make_octets(context, &rnd);
 
358
    if (retval)
 
359
        return retval;
 
360
    retval = alloc_data(&salt, sizeof(rndbuf) * 2);
 
361
    if (retval)
 
362
        return retval;
 
363
    for (i = 0; i < sizeof(rndbuf); i++) {
 
364
        salt.data[i * 2] = 0x40 | (rndbuf[i] >> 4);
 
365
        salt.data[i * 2 + 1] = 0x40 | (rndbuf[i] & 0xf);
 
366
    }
 
367
 
 
368
    salt_out->type = KRB5_KDB_SALTTYPE_SPECIAL;
 
369
    salt_out->data = salt;
 
370
    return 0;
 
371
}
 
372
 
345
373
/*
346
374
 * Add key_data for a krb5_db_entry
347
375
 * If passwd is NULL the assumes that the caller wants a random password.
434
462
                return retval;
435
463
            key_salt.data.length = SALT_TYPE_AFS_LENGTH; /*length actually used below...*/
436
464
            break;
 
465
        case KRB5_KDB_SALTTYPE_SPECIAL:
 
466
            retval = make_random_salt(context, &key_salt);
 
467
            if (retval)
 
468
                return retval;
 
469
            break;
437
470
        default:
438
471
            return(KRB5_KDB_BAD_SALTTYPE);
439
472
        }