Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/heimdal/lib/hdb/db.c

    r414 r745  
    319319    (*db)->hdb_open = DB_open;
    320320    (*db)->hdb_close = DB_close;
    321     (*db)->hdb_fetch = _hdb_fetch;
     321    (*db)->hdb_fetch_kvno = _hdb_fetch_kvno;
    322322    (*db)->hdb_store = _hdb_store;
    323323    (*db)->hdb_remove = _hdb_remove;
  • trunk/server/source4/heimdal/lib/hdb/dbinfo.c

    r414 r745  
    103103    databases = NULL;
    104104
    105     db_binding = krb5_config_get(context, NULL, krb5_config_list,
    106                                  "kdc",
    107                                  "database",
    108                                  NULL);
     105    db_binding = krb5_config_get_list(context, NULL,
     106                                      "kdc",
     107                                      "database",
     108                                      NULL);
    109109    if (db_binding) {
    110110
  • trunk/server/source4/heimdal/lib/hdb/ext.c

    r414 r745  
    317317        str = pw.data;
    318318        if (str[pw.length - 1] != '\0') {
    319             krb5_set_error_message(context, EINVAL, "password malformated");
     319            krb5_set_error_message(context, EINVAL, "malformed password");
    320320            return EINVAL;
    321321        }
     
    333333    ret = krb5_unparse_name(context, entry->principal, &str);
    334334    if (ret == 0) {
    335         krb5_set_error_message(context, ENOENT, "no password attributefor %s", str);
     335        krb5_set_error_message(context, ENOENT,
     336                               "no password attribute for %s", str);
    336337        free(str);
    337338    } else
  • trunk/server/source4/heimdal/lib/hdb/hdb.c

    r414 r745  
    33 * (Royal Institute of Technology, Stockholm, Sweden).
    44 * All rights reserved.
     5 *
     6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
    57 *
    68 * Redistribution and use in source and binary forms, with or without
     
    6062 */
    6163
    62 
     64const int hdb_interface_version = HDB_INTERFACE_VERSION;
    6365
    6466static struct hdb_method methods[] = {
     
    6668    { HDB_INTERFACE_VERSION, "db:",     hdb_db_create},
    6769#endif
     70#if HAVE_DB1
     71    { HDB_INTERFACE_VERSION, "mit-db:", hdb_mdb_create},
     72#endif
    6873#if HAVE_NDBM
    6974    { HDB_INTERFACE_VERSION, "ndbm:",   hdb_ndbm_create},
    7075#endif
     76    { HDB_INTERFACE_VERSION, "keytab:", hdb_keytab_create},
    7177#if defined(OPENLDAP) && !defined(OPENLDAP_MODULE)
    7278    { HDB_INTERFACE_VERSION, "ldap:",   hdb_ldap_create},
     
    313319        krb5_errx(context, 1, "out of memory");
    314320       
    315     mso = dlsym(dl, symbol);
     321    mso = (struct hdb_so_method *) dlsym(dl, symbol);
    316322    if (mso == NULL) {
    317323        krb5_warnx(context, "error finding symbol %s in %s: %s\n",
     
    410416    *list = buf;
    411417    return 0;
     418}
     419
     420krb5_error_code
     421_hdb_keytab2hdb_entry(krb5_context context,
     422                      const krb5_keytab_entry *ktentry,
     423                      hdb_entry_ex *entry)
     424{
     425    entry->entry.kvno = ktentry->vno;
     426    entry->entry.created_by.time = ktentry->timestamp;
     427
     428    entry->entry.keys.val = calloc(1, sizeof(entry->entry.keys.val[0]));
     429    if (entry->entry.keys.val == NULL)
     430        return ENOMEM;
     431    entry->entry.keys.len = 1;
     432
     433    entry->entry.keys.val[0].mkvno = NULL;
     434    entry->entry.keys.val[0].salt = NULL;
     435   
     436    return krb5_copy_keyblock_contents(context,
     437                                       &ktentry->keyblock,
     438                                       &entry->entry.keys.val[0].key);
    412439}
    413440
  • trunk/server/source4/heimdal/lib/hdb/hdb.h

    r414 r745  
    3737#define __HDB_H__
    3838
     39#include <krb5.h>
     40
    3941#include <hdb_err.h>
    4042
     
    5456#define HDB_F_GET_ANY           28      /* fetch any of client,server,krbtgt */
    5557#define HDB_F_CANON             32      /* want canonicalition */
     58#define HDB_F_ADMIN_DATA        64      /* want data that kdc don't use  */
     59#define HDB_F_KVNO_SPECIFIED    128     /* we want a particular KVNO */
    5660
    5761/* hdb_capability_flags */
     
    6973
    7074typedef struct hdb_master_key_data *hdb_master_key;
     75
     76/**
     77 * hdb_entry_ex is a wrapper structure around the hdb_entry structure
     78 * that allows backends to keep a pointer to the backing store, ie in
     79 * ->hdb_fetch_kvno(), so that we the kadmin/kpasswd backend gets around to
     80 * ->hdb_store(), the backend doesn't need to lookup the entry again.
     81 */
    7182
    7283typedef struct hdb_entry_ex {
     
    120131     * Fetch an entry from the backend, flags are what type of entry
    121132     * should be fetch: client, server, krbtgt.
    122      */
    123     krb5_error_code (*hdb_fetch)(krb5_context, struct HDB*,
    124                                  krb5_const_principal, unsigned,
    125                                  hdb_entry_ex*);
     133     * knvo (if specified and flags HDB_F_KVNO_SPECIFIED set) is the kvno to get
     134     */
     135    krb5_error_code (*hdb_fetch_kvno)(krb5_context, struct HDB*,
     136                                      krb5_const_principal, unsigned, krb5_kvno,
     137                                      hdb_entry_ex*);
    126138    /**
    127139     * Store an entry to database
     
    158170    /**
    159171     * Rename the data base.
     172     *
     173     * Assume that the database is not hdb_open'ed and not locked.
    160174     */
    161175    krb5_error_code (*hdb_rename)(krb5_context, struct HDB*, const char*);
     
    194208    krb5_error_code (*hdb_destroy)(krb5_context, struct HDB*);
    195209    /**
     210     * Get the list of realms this backend handles.
     211     * This call is optional to support. The returned realms are used
     212     * for announcing the realms over bonjour. Free returned array
     213     * with krb5_free_host_realm().
     214     */
     215    krb5_error_code (*hdb_get_realms)(krb5_context, struct HDB *, krb5_realm **);
     216    /**
    196217     * Change password.
    197218     *
    198219     * Will update keys for the entry when given password.  The new
    199      * keys must be written into the entry and and will then later be
     220     * keys must be written into the entry and will then later be
    200221     * ->hdb_store() into the database. The backend will still perform
    201222     * all other operations, increasing the kvno, and update
    202223     * modification timestamp.
    203224     *
    204      * The backen need to call _kadm5_set_keys() and perform password
     225     * The backend needs to call _kadm5_set_keys() and perform password
    205226     * quality checks.
    206227     */
     
    218239    krb5_error_code (*hdb_auth_status)(krb5_context, struct HDB *, hdb_entry_ex *, int);
    219240    /**
    220      * Check is delegation is allowed.
     241     * Check if delegation is allowed.
    221242     */
    222243    krb5_error_code (*hdb_check_constrained_delegation)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);
     
    226247     */
    227248    krb5_error_code (*hdb_check_pkinit_ms_upn_match)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);
     249
     250    /**
     251     * Check if s4u2self is allowed from this client to this server
     252     */
     253    krb5_error_code (*hdb_check_s4u2self)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal);
    228254}HDB;
    229255
    230 #define HDB_INTERFACE_VERSION   6
     256#define HDB_INTERFACE_VERSION   7
    231257
    232258struct hdb_so_method {
     
    246272};
    247273
     274extern const int hdb_interface_version;
     275
    248276#include <hdb-protos.h>
    249277
  • trunk/server/source4/heimdal/lib/hdb/hdb_err.et

    r414 r745  
    2525error_code NO_MKEY,             "No correct master key"
    2626error_code MANDATORY_OPTION,    "Entry contains unknown mandatory extension"
     27error_code NO_WRITE_SUPPORT,    "HDB backend doesn't contain write support"
     28error_code NOT_FOUND_HERE,      "The secret for this entry is not replicated to this database"
    2729
    2830end
  • trunk/server/source4/heimdal/lib/hdb/keytab.c

    r414 r745  
    5050/*
    5151 * the format for HDB keytabs is:
    52  * HDB:[database:file:mkey]
     52 * HDB:[HDBFORMAT:database-specific-data[:mkey=mkey-file]]
    5353 */
    5454
    55 static krb5_error_code
     55static krb5_error_code KRB5_CALLCONV
    5656hdb_resolve(krb5_context context, const char *name, krb5_keytab id)
    5757{
     
    6565    }
    6666    db = name;
    67     mkey = strchr(name, ':');
    68     if(mkey == NULL || mkey[1] == '\0') {
     67    mkey = strstr(name, ":mkey=");
     68    if(mkey == NULL || mkey[5] == '\0') {
    6969        if(*name == '\0')
    7070            d->dbname = NULL;
     
    7979        d->mkey = NULL;
    8080    } else {
    81         if((mkey - db) == 0) {
    82             d->dbname = NULL;
    83         } else {
    84             d->dbname = malloc(mkey - db + 1);
    85             if(d->dbname == NULL) {
    86                 free(d);
    87                 krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
    88                 return ENOMEM;
    89             }
    90             memmove(d->dbname, db, mkey - db);
    91             d->dbname[mkey - db] = '\0';
     81        d->dbname = malloc(mkey - db + 1);
     82        if(d->dbname == NULL) {
     83            free(d);
     84            krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
     85            return ENOMEM;
    9286        }
    93         d->mkey = strdup(mkey + 1);
     87        memmove(d->dbname, db, mkey - db);
     88        d->dbname[mkey - db] = '\0';
     89
     90        d->mkey = strdup(mkey + 5);
    9491        if(d->mkey == NULL) {
    9592            free(d->dbname);
     
    103100}
    104101
    105 static krb5_error_code
     102static krb5_error_code KRB5_CALLCONV
    106103hdb_close(krb5_context context, krb5_keytab id)
    107104{
     
    114111}
    115112
    116 static krb5_error_code
     113static krb5_error_code KRB5_CALLCONV
    117114hdb_get_name(krb5_context context,
    118115             krb5_keytab id,
     
    173170 */
    174171
    175 static krb5_error_code
     172static krb5_error_code KRB5_CALLCONV
    176173hdb_get_entry(krb5_context context,
    177174              krb5_keytab id,
     
    214211        goto out2;
    215212    }
    216     ret = (*db->hdb_fetch)(context, db, principal,
    217                            HDB_F_DECRYPT|
    218                            HDB_F_GET_CLIENT|HDB_F_GET_SERVER|HDB_F_GET_KRBTGT,
    219                            &ent);
     213   
     214    ret = (*db->hdb_fetch_kvno)(context, db, principal,
     215                                HDB_F_DECRYPT|HDB_F_KVNO_SPECIFIED|
     216                                HDB_F_GET_CLIENT|HDB_F_GET_SERVER|HDB_F_GET_KRBTGT,
     217                                kvno, &ent);
    220218
    221219    if(ret == HDB_ERR_NOENTRY) {
     
    260258 */
    261259
    262 static krb5_error_code
     260static krb5_error_code KRB5_CALLCONV
    263261hdb_start_seq_get(krb5_context context,
    264262                  krb5_keytab id,
     
    313311}
    314312
    315 static int
     313static int KRB5_CALLCONV
    316314hdb_next_entry(krb5_context context,
    317315               krb5_keytab id,
     
    395393
    396394
    397 static int
     395static int KRB5_CALLCONV
    398396hdb_end_seq_get(krb5_context context,
    399397                krb5_keytab id,
     
    402400    struct hdb_cursor *c = cursor->data;
    403401
     402    if (!c->next)
     403        hdb_free_entry(context, &c->hdb_entry);
     404
    404405    (c->db->hdb_close)(context, c->db);
    405406    (c->db->hdb_destroy)(context, c->db);
    406 
    407     if (!c->next)
    408         hdb_free_entry(context, &c->hdb_entry);
    409407
    410408    free(c);
  • trunk/server/source4/heimdal/lib/hdb/mkey.c

    r414 r745  
    147147static krb5_error_code
    148148read_master_mit(krb5_context context, const char *filename,
    149                 hdb_master_key *mkey)
     149                int byteorder, hdb_master_key *mkey)
    150150{
    151151    int fd;
     
    167167        return errno;
    168168    }
    169     krb5_storage_set_flags(sp, KRB5_STORAGE_HOST_BYTEORDER);
     169    krb5_storage_set_flags(sp, byteorder);
    170170    /* could possibly use ret_keyblock here, but do it with more
    171171       checks for now */
     
    174174        if (ret)
    175175            goto out;
    176         if((htons(enctype) & 0xff00) == 0x3000) {
    177             ret = HEIM_ERR_BAD_MKEY;
    178             krb5_set_error_message(context, ret, "unknown keytype in %s: "
    179                                    "%#x, expected %#x",
    180                                    filename, htons(enctype), 0x3000);
    181             goto out;
    182         }
     176        ret = krb5_enctype_valid(context, enctype);
     177        if (ret)
     178           goto out;
    183179        key.keytype = enctype;
    184180        ret = krb5_ret_data(sp, &key.keyvalue);
     
    186182            goto out;
    187183    }
    188     ret = hdb_process_master_key(context, 0, &key, 0, mkey);
     184    ret = hdb_process_master_key(context, 1, &key, 0, mkey);
    189185    krb5_free_keyblock_contents(context, &key);
    190186  out:
     
    331327        ret = read_master_keytab(context, filename, mkey);
    332328    } else {
    333         ret = read_master_mit(context, filename, mkey);
     329      /*
     330       * Check both LittleEndian and BigEndian since they key file
     331       * might be moved from a machine with diffrent byte order, or
     332       * its running on MacOS X that always uses BE master keys.
     333       */
     334      ret = read_master_mit(context, filename, KRB5_STORAGE_BYTEORDER_LE, mkey);
     335      if (ret)
     336          ret = read_master_mit(context, filename, KRB5_STORAGE_BYTEORDER_BE, mkey);
    334337    }
    335338    return ret;
  • trunk/server/source4/heimdal/lib/hdb/ndbm.c

    r414 r745  
    3838#if defined(HAVE_GDBM_NDBM_H)
    3939#include <gdbm/ndbm.h>
     40#define WRITE_SUPPORT 1
    4041#elif defined(HAVE_NDBM_H)
    4142#include <ndbm.h>
    4243#elif defined(HAVE_DBM_H)
     44#define WRITE_SUPPORT 1
    4345#include <dbm.h>
    4446#endif
     
    132134
    133135static krb5_error_code
     136open_lock_file(krb5_context context, const char *db_name, int *fd)
     137{
     138    char *lock_file;
     139
     140    /* lock old and new databases */
     141    asprintf(&lock_file, "%s.lock", db_name);
     142    if(lock_file == NULL) {
     143        krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
     144        return ENOMEM;
     145    }
     146
     147    *fd = open(lock_file, O_RDWR | O_CREAT, 0600);
     148    free(lock_file);
     149    if(*fd < 0) {
     150        int ret = errno;
     151        krb5_set_error_message(context, ret, "open(%s): %s", lock_file,
     152                               strerror(ret));
     153        return ret;
     154    }
     155    return 0;
     156}
     157
     158
     159static krb5_error_code
    134160NDBM_rename(krb5_context context, HDB *db, const char *new_name)
    135161{
    136     /* XXX this function will break */
    137     struct ndbm_db *d = db->hdb_db;
    138 
    139162    int ret;
    140163    char *old_dir, *old_pag, *new_dir, *new_pag;
    141     char *new_lock;
    142     int lock_fd;
     164    int old_lock_fd, new_lock_fd;
    143165
    144166    /* lock old and new databases */
    145     ret = db->hdb_lock(context, db, HDB_WLOCK);
    146     if(ret)
    147         return ret;
    148     asprintf(&new_lock, "%s.lock", new_name);
    149     if(new_lock == NULL) {
    150         db->hdb_unlock(context, db);
    151         krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
    152         return ENOMEM;
    153     }
    154     lock_fd = open(new_lock, O_RDWR | O_CREAT, 0600);
    155     if(lock_fd < 0) {
    156         ret = errno;
    157         db->hdb_unlock(context, db);
    158         krb5_set_error_message(context, ret, "open(%s): %s", new_lock,
    159                                strerror(ret));
    160         free(new_lock);
    161         return ret;
    162     }
    163     free(new_lock);
    164     ret = hdb_lock(lock_fd, HDB_WLOCK);
     167    ret = open_lock_file(context, db->hdb_name, &old_lock_fd);
     168    if (ret)
     169        return ret;
     170
     171    ret = hdb_lock(old_lock_fd, HDB_WLOCK);
    165172    if(ret) {
    166         db->hdb_unlock(context, db);
    167         close(lock_fd);
     173        close(old_lock_fd);
     174        return ret;
     175    }
     176
     177    ret = open_lock_file(context, new_name, &new_lock_fd);
     178    if (ret) {
     179        hdb_unlock(old_lock_fd);
     180        close(old_lock_fd);
     181        return ret;
     182    }
     183
     184    ret = hdb_lock(new_lock_fd, HDB_WLOCK);
     185    if(ret) {
     186        hdb_unlock(old_lock_fd);
     187        close(old_lock_fd);
     188        close(new_lock_fd);
    168189        return ret;
    169190    }
     
    175196
    176197    ret = rename(old_dir, new_dir) || rename(old_pag, new_pag);
     198    if (ret) {
     199        ret = errno;
     200        if (ret == 0)
     201            ret = EPERM;
     202        krb5_set_error_message(context, ret, "rename: %s", strerror(ret));
     203    }
     204
    177205    free(old_dir);
    178206    free(old_pag);
    179207    free(new_dir);
    180208    free(new_pag);
    181     hdb_unlock(lock_fd);
    182     db->hdb_unlock(context, db);
    183 
    184     if(ret) {
    185         ret = errno;
    186         close(lock_fd);
    187         krb5_set_error_message(context, ret, "rename: %s", strerror(ret));
    188         return ret;
    189     }
    190 
    191     close(d->lock_fd);
    192     d->lock_fd = lock_fd;
     209
     210    hdb_unlock(new_lock_fd);
     211    hdb_unlock(old_lock_fd);
     212    close(new_lock_fd);
     213    close(old_lock_fd);
     214
     215    if(ret)
     216        return ret;
    193217
    194218    free(db->hdb_name);
     
    222246        krb5_data key, krb5_data value)
    223247{
     248#ifdef WRITE_SUPPORT
    224249    struct ndbm_db *d = (struct ndbm_db *)db->hdb_db;
    225250    datum k, v;
     
    241266        return code;
    242267    return 0;
     268#else
     269    return HDB_ERR_NO_WRITE_SUPPORT;
     270#endif
    243271}
    244272
     
    278306    krb5_error_code ret;
    279307    struct ndbm_db *d = malloc(sizeof(*d));
    280     char *lock_file;
    281308
    282309    if(d == NULL) {
     
    284311        return ENOMEM;
    285312    }
    286     asprintf(&lock_file, "%s.lock", (char*)db->hdb_name);
    287     if(lock_file == NULL) {
    288         free(d);
    289         krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
    290         return ENOMEM;
    291     }
     313
    292314    d->db = dbm_open((char*)db->hdb_name, flags, mode);
    293315    if(d->db == NULL){
    294316        ret = errno;
    295317        free(d);
    296         free(lock_file);
    297318        krb5_set_error_message(context, ret, "dbm_open(%s): %s", db->hdb_name,
    298319                               strerror(ret));
    299320        return ret;
    300321    }
    301     d->lock_fd = open(lock_file, O_RDWR | O_CREAT, 0600);
    302     if(d->lock_fd < 0){
     322
     323    ret = open_lock_file(context, db->hdb_name, &d->lock_fd);
     324    if (ret) {
    303325        ret = errno;
    304326        dbm_close(d->db);
    305327        free(d);
    306         krb5_set_error_message(context, ret, "open(%s): %s", lock_file,
     328        krb5_set_error_message(context, ret, "open(lock file): %s",
    307329                               strerror(ret));
    308         free(lock_file);
    309         return ret;
    310     }
    311     free(lock_file);
     330        return ret;
     331    }
     332
    312333    db->hdb_db = d;
    313334    if((flags & O_ACCMODE) == O_RDONLY)
     
    350371    (*db)->hdb_open = NDBM_open;
    351372    (*db)->hdb_close = NDBM_close;
    352     (*db)->hdb_fetch = _hdb_fetch;
     373    (*db)->hdb_fetch_kvno = _hdb_fetch_kvno;
    353374    (*db)->hdb_store = _hdb_store;
    354375    (*db)->hdb_remove = _hdb_remove;
Note: See TracChangeset for help on using the changeset viewer.