Changeset 745 for trunk/server/source4/heimdal/lib/hdb
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/heimdal/lib/hdb/db.c
r414 r745 319 319 (*db)->hdb_open = DB_open; 320 320 (*db)->hdb_close = DB_close; 321 (*db)->hdb_fetch = _hdb_fetch;321 (*db)->hdb_fetch_kvno = _hdb_fetch_kvno; 322 322 (*db)->hdb_store = _hdb_store; 323 323 (*db)->hdb_remove = _hdb_remove; -
trunk/server/source4/heimdal/lib/hdb/dbinfo.c
r414 r745 103 103 databases = NULL; 104 104 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); 109 109 if (db_binding) { 110 110 -
trunk/server/source4/heimdal/lib/hdb/ext.c
r414 r745 317 317 str = pw.data; 318 318 if (str[pw.length - 1] != '\0') { 319 krb5_set_error_message(context, EINVAL, " password malformated");319 krb5_set_error_message(context, EINVAL, "malformed password"); 320 320 return EINVAL; 321 321 } … … 333 333 ret = krb5_unparse_name(context, entry->principal, &str); 334 334 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); 336 337 free(str); 337 338 } else -
trunk/server/source4/heimdal/lib/hdb/hdb.c
r414 r745 3 3 * (Royal Institute of Technology, Stockholm, Sweden). 4 4 * All rights reserved. 5 * 6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved. 5 7 * 6 8 * Redistribution and use in source and binary forms, with or without … … 60 62 */ 61 63 62 64 const int hdb_interface_version = HDB_INTERFACE_VERSION; 63 65 64 66 static struct hdb_method methods[] = { … … 66 68 { HDB_INTERFACE_VERSION, "db:", hdb_db_create}, 67 69 #endif 70 #if HAVE_DB1 71 { HDB_INTERFACE_VERSION, "mit-db:", hdb_mdb_create}, 72 #endif 68 73 #if HAVE_NDBM 69 74 { HDB_INTERFACE_VERSION, "ndbm:", hdb_ndbm_create}, 70 75 #endif 76 { HDB_INTERFACE_VERSION, "keytab:", hdb_keytab_create}, 71 77 #if defined(OPENLDAP) && !defined(OPENLDAP_MODULE) 72 78 { HDB_INTERFACE_VERSION, "ldap:", hdb_ldap_create}, … … 313 319 krb5_errx(context, 1, "out of memory"); 314 320 315 mso = dlsym(dl, symbol);321 mso = (struct hdb_so_method *) dlsym(dl, symbol); 316 322 if (mso == NULL) { 317 323 krb5_warnx(context, "error finding symbol %s in %s: %s\n", … … 410 416 *list = buf; 411 417 return 0; 418 } 419 420 krb5_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); 412 439 } 413 440 -
trunk/server/source4/heimdal/lib/hdb/hdb.h
r414 r745 37 37 #define __HDB_H__ 38 38 39 #include <krb5.h> 40 39 41 #include <hdb_err.h> 40 42 … … 54 56 #define HDB_F_GET_ANY 28 /* fetch any of client,server,krbtgt */ 55 57 #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 */ 56 60 57 61 /* hdb_capability_flags */ … … 69 73 70 74 typedef 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 */ 71 82 72 83 typedef struct hdb_entry_ex { … … 120 131 * Fetch an entry from the backend, flags are what type of entry 121 132 * 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*); 126 138 /** 127 139 * Store an entry to database … … 158 170 /** 159 171 * Rename the data base. 172 * 173 * Assume that the database is not hdb_open'ed and not locked. 160 174 */ 161 175 krb5_error_code (*hdb_rename)(krb5_context, struct HDB*, const char*); … … 194 208 krb5_error_code (*hdb_destroy)(krb5_context, struct HDB*); 195 209 /** 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 /** 196 217 * Change password. 197 218 * 198 219 * Will update keys for the entry when given password. The new 199 * keys must be written into the entry and andwill then later be220 * keys must be written into the entry and will then later be 200 221 * ->hdb_store() into the database. The backend will still perform 201 222 * all other operations, increasing the kvno, and update 202 223 * modification timestamp. 203 224 * 204 * The backen needto call _kadm5_set_keys() and perform password225 * The backend needs to call _kadm5_set_keys() and perform password 205 226 * quality checks. 206 227 */ … … 218 239 krb5_error_code (*hdb_auth_status)(krb5_context, struct HDB *, hdb_entry_ex *, int); 219 240 /** 220 * Check i sdelegation is allowed.241 * Check if delegation is allowed. 221 242 */ 222 243 krb5_error_code (*hdb_check_constrained_delegation)(krb5_context, struct HDB *, hdb_entry_ex *, krb5_const_principal); … … 226 247 */ 227 248 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); 228 254 }HDB; 229 255 230 #define HDB_INTERFACE_VERSION 6256 #define HDB_INTERFACE_VERSION 7 231 257 232 258 struct hdb_so_method { … … 246 272 }; 247 273 274 extern const int hdb_interface_version; 275 248 276 #include <hdb-protos.h> 249 277 -
trunk/server/source4/heimdal/lib/hdb/hdb_err.et
r414 r745 25 25 error_code NO_MKEY, "No correct master key" 26 26 error_code MANDATORY_OPTION, "Entry contains unknown mandatory extension" 27 error_code NO_WRITE_SUPPORT, "HDB backend doesn't contain write support" 28 error_code NOT_FOUND_HERE, "The secret for this entry is not replicated to this database" 27 29 28 30 end -
trunk/server/source4/heimdal/lib/hdb/keytab.c
r414 r745 50 50 /* 51 51 * the format for HDB keytabs is: 52 * HDB:[ database:file:mkey]52 * HDB:[HDBFORMAT:database-specific-data[:mkey=mkey-file]] 53 53 */ 54 54 55 static krb5_error_code 55 static krb5_error_code KRB5_CALLCONV 56 56 hdb_resolve(krb5_context context, const char *name, krb5_keytab id) 57 57 { … … 65 65 } 66 66 db = name; 67 mkey = str chr(name, ':');68 if(mkey == NULL || mkey[ 1] == '\0') {67 mkey = strstr(name, ":mkey="); 68 if(mkey == NULL || mkey[5] == '\0') { 69 69 if(*name == '\0') 70 70 d->dbname = NULL; … … 79 79 d->mkey = NULL; 80 80 } 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; 92 86 } 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); 94 91 if(d->mkey == NULL) { 95 92 free(d->dbname); … … 103 100 } 104 101 105 static krb5_error_code 102 static krb5_error_code KRB5_CALLCONV 106 103 hdb_close(krb5_context context, krb5_keytab id) 107 104 { … … 114 111 } 115 112 116 static krb5_error_code 113 static krb5_error_code KRB5_CALLCONV 117 114 hdb_get_name(krb5_context context, 118 115 krb5_keytab id, … … 173 170 */ 174 171 175 static krb5_error_code 172 static krb5_error_code KRB5_CALLCONV 176 173 hdb_get_entry(krb5_context context, 177 174 krb5_keytab id, … … 214 211 goto out2; 215 212 } 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); 220 218 221 219 if(ret == HDB_ERR_NOENTRY) { … … 260 258 */ 261 259 262 static krb5_error_code 260 static krb5_error_code KRB5_CALLCONV 263 261 hdb_start_seq_get(krb5_context context, 264 262 krb5_keytab id, … … 313 311 } 314 312 315 static int 313 static int KRB5_CALLCONV 316 314 hdb_next_entry(krb5_context context, 317 315 krb5_keytab id, … … 395 393 396 394 397 static int 395 static int KRB5_CALLCONV 398 396 hdb_end_seq_get(krb5_context context, 399 397 krb5_keytab id, … … 402 400 struct hdb_cursor *c = cursor->data; 403 401 402 if (!c->next) 403 hdb_free_entry(context, &c->hdb_entry); 404 404 405 (c->db->hdb_close)(context, c->db); 405 406 (c->db->hdb_destroy)(context, c->db); 406 407 if (!c->next)408 hdb_free_entry(context, &c->hdb_entry);409 407 410 408 free(c); -
trunk/server/source4/heimdal/lib/hdb/mkey.c
r414 r745 147 147 static krb5_error_code 148 148 read_master_mit(krb5_context context, const char *filename, 149 hdb_master_key *mkey)149 int byteorder, hdb_master_key *mkey) 150 150 { 151 151 int fd; … … 167 167 return errno; 168 168 } 169 krb5_storage_set_flags(sp, KRB5_STORAGE_HOST_BYTEORDER);169 krb5_storage_set_flags(sp, byteorder); 170 170 /* could possibly use ret_keyblock here, but do it with more 171 171 checks for now */ … … 174 174 if (ret) 175 175 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; 183 179 key.keytype = enctype; 184 180 ret = krb5_ret_data(sp, &key.keyvalue); … … 186 182 goto out; 187 183 } 188 ret = hdb_process_master_key(context, 0, &key, 0, mkey);184 ret = hdb_process_master_key(context, 1, &key, 0, mkey); 189 185 krb5_free_keyblock_contents(context, &key); 190 186 out: … … 331 327 ret = read_master_keytab(context, filename, mkey); 332 328 } 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); 334 337 } 335 338 return ret; -
trunk/server/source4/heimdal/lib/hdb/ndbm.c
r414 r745 38 38 #if defined(HAVE_GDBM_NDBM_H) 39 39 #include <gdbm/ndbm.h> 40 #define WRITE_SUPPORT 1 40 41 #elif defined(HAVE_NDBM_H) 41 42 #include <ndbm.h> 42 43 #elif defined(HAVE_DBM_H) 44 #define WRITE_SUPPORT 1 43 45 #include <dbm.h> 44 46 #endif … … 132 134 133 135 static krb5_error_code 136 open_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 159 static krb5_error_code 134 160 NDBM_rename(krb5_context context, HDB *db, const char *new_name) 135 161 { 136 /* XXX this function will break */137 struct ndbm_db *d = db->hdb_db;138 139 162 int ret; 140 163 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; 143 165 144 166 /* 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); 165 172 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); 168 189 return ret; 169 190 } … … 175 196 176 197 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 177 205 free(old_dir); 178 206 free(old_pag); 179 207 free(new_dir); 180 208 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; 193 217 194 218 free(db->hdb_name); … … 222 246 krb5_data key, krb5_data value) 223 247 { 248 #ifdef WRITE_SUPPORT 224 249 struct ndbm_db *d = (struct ndbm_db *)db->hdb_db; 225 250 datum k, v; … … 241 266 return code; 242 267 return 0; 268 #else 269 return HDB_ERR_NO_WRITE_SUPPORT; 270 #endif 243 271 } 244 272 … … 278 306 krb5_error_code ret; 279 307 struct ndbm_db *d = malloc(sizeof(*d)); 280 char *lock_file;281 308 282 309 if(d == NULL) { … … 284 311 return ENOMEM; 285 312 } 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 292 314 d->db = dbm_open((char*)db->hdb_name, flags, mode); 293 315 if(d->db == NULL){ 294 316 ret = errno; 295 317 free(d); 296 free(lock_file);297 318 krb5_set_error_message(context, ret, "dbm_open(%s): %s", db->hdb_name, 298 319 strerror(ret)); 299 320 return ret; 300 321 } 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) { 303 325 ret = errno; 304 326 dbm_close(d->db); 305 327 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", 307 329 strerror(ret)); 308 free(lock_file); 309 return ret; 310 } 311 free(lock_file); 330 return ret; 331 } 332 312 333 db->hdb_db = d; 313 334 if((flags & O_ACCMODE) == O_RDONLY) … … 350 371 (*db)->hdb_open = NDBM_open; 351 372 (*db)->hdb_close = NDBM_close; 352 (*db)->hdb_fetch = _hdb_fetch;373 (*db)->hdb_fetch_kvno = _hdb_fetch_kvno; 353 374 (*db)->hdb_store = _hdb_store; 354 375 (*db)->hdb_remove = _hdb_remove;
Note:
See TracChangeset
for help on using the changeset viewer.