1 /* 2 * lib/kdb/kdb_ldap/ldap_fetch_mkey.c 3 * 4 * Copyright (c) 2004-2005, Novell, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * * Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * * The copyright holder's name is not used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #include "ldap_main.h" 32 #include "kdb_ldap.h" 33 34 /* 35 * get the master key from the database specific context 36 */ 37 38 krb5_error_code 39 krb5_ldap_get_mkey (context, key) 40 krb5_context context; 41 krb5_keyblock **key; 42 43 { 44 kdb5_dal_handle *dal_handle=NULL; 45 krb5_ldap_context *ldap_context=NULL; 46 47 /* Clear the global error string */ 48 krb5_clear_error_message(context); 49 50 dal_handle = (kdb5_dal_handle *) context->db_context; 51 ldap_context = (krb5_ldap_context *) dal_handle->db_context; 52 53 if (ldap_context == NULL || ldap_context->lrparams == NULL) 54 return KRB5_KDB_DBNOTINITED; 55 56 *key = &ldap_context->lrparams->mkey; 57 return 0; 58 } 59 60 61 /* 62 * set the master key into the database specific context 63 */ 64 65 krb5_error_code 66 krb5_ldap_set_mkey (context, pwd, key) 67 krb5_context context; 68 char *pwd; 69 krb5_keyblock *key; 70 { 71 kdb5_dal_handle *dal_handle=NULL; 72 krb5_ldap_context *ldap_context=NULL; 73 krb5_ldap_realm_params *r_params = NULL; 74 75 /* Clear the global error string */ 76 krb5_clear_error_message(context); 77 78 dal_handle = (kdb5_dal_handle *) context->db_context; 79 ldap_context = (krb5_ldap_context *) dal_handle->db_context; 80 81 if (ldap_context == NULL || ldap_context->lrparams == NULL) 82 return KRB5_KDB_DBNOTINITED; 83 84 r_params = ldap_context->lrparams; 85 86 if (r_params->mkey.contents) { 87 free (r_params->mkey.contents); 88 r_params->mkey.contents=NULL; 89 } 90 91 r_params->mkey.magic = key->magic; 92 r_params->mkey.enctype = key->enctype; 93 r_params->mkey.length = key->length; 94 r_params->mkey.contents = malloc(key->length); 95 if (r_params->mkey.contents == NULL) 96 return ENOMEM; 97 98 memcpy(r_params->mkey.contents, key->contents, key->length); 99 return 0; 100 } 101