Path: blob/main/crypto/heimdal/lib/krb5/deprecated.c
34878 views
/*1* Copyright (c) 1997 - 2009 Kungliga Tekniska H�gskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "krb5_locl.h"3435#undef __attribute__36#define __attribute__(x)3738#ifndef HEIMDAL_SMALLER3940/**41* Same as krb5_data_free(). MIT compat.42*43* Deprecated: use krb5_data_free().44*45* @param context Kerberos 5 context.46* @param data krb5_data to free.47*48* @ingroup krb5_deprecated49*/5051KRB5_LIB_FUNCTION void KRB5_LIB_CALL52krb5_free_data_contents(krb5_context context, krb5_data *data)53KRB5_DEPRECATED_FUNCTION("Use X instead")54{55krb5_data_free(data);56}5758/**59* Deprecated: keytypes doesn't exists, they are really enctypes.60*61* @ingroup krb5_deprecated62*/6364KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL65krb5_keytype_to_enctypes_default (krb5_context context,66krb5_keytype keytype,67unsigned *len,68krb5_enctype **val)69KRB5_DEPRECATED_FUNCTION("Use X instead")70{71unsigned int i, n;72krb5_enctype *ret;7374if (keytype != (krb5_keytype)KEYTYPE_DES || context->etypes_des == NULL)75return krb5_keytype_to_enctypes (context, keytype, len, val);7677for (n = 0; context->etypes_des[n]; ++n)78;79ret = malloc (n * sizeof(*ret));80if (ret == NULL && n != 0) {81krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));82return ENOMEM;83}84for (i = 0; i < n; ++i)85ret[i] = context->etypes_des[i];86*len = n;87*val = ret;88return 0;89}909192static struct {93const char *name;94krb5_keytype type;95} keys[] = {96{ "null", ENCTYPE_NULL },97{ "des", ETYPE_DES_CBC_CRC },98{ "des3", ETYPE_OLD_DES3_CBC_SHA1 },99{ "aes-128", ETYPE_AES128_CTS_HMAC_SHA1_96 },100{ "aes-256", ETYPE_AES256_CTS_HMAC_SHA1_96 },101{ "arcfour", ETYPE_ARCFOUR_HMAC_MD5 },102{ "arcfour-56", ETYPE_ARCFOUR_HMAC_MD5_56 }103};104105static int num_keys = sizeof(keys) / sizeof(keys[0]);106107/**108* Deprecated: keytypes doesn't exists, they are really enctypes in109* most cases, use krb5_enctype_to_string().110*111* @ingroup krb5_deprecated112*/113114KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL115krb5_keytype_to_string(krb5_context context,116krb5_keytype keytype,117char **string)118KRB5_DEPRECATED_FUNCTION("Use X instead")119{120const char *name = NULL;121int i;122123for(i = 0; i < num_keys; i++) {124if(keys[i].type == keytype) {125name = keys[i].name;126break;127}128}129130if(i >= num_keys) {131krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,132"key type %d not supported", keytype);133return KRB5_PROG_KEYTYPE_NOSUPP;134}135*string = strdup(name);136if(*string == NULL) {137krb5_set_error_message(context, ENOMEM,138N_("malloc: out of memory", ""));139return ENOMEM;140}141return 0;142}143144/**145* Deprecated: keytypes doesn't exists, they are really enctypes in146* most cases, use krb5_string_to_enctype().147*148* @ingroup krb5_deprecated149*/150151KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL152krb5_string_to_keytype(krb5_context context,153const char *string,154krb5_keytype *keytype)155KRB5_DEPRECATED_FUNCTION("Use X instead")156{157char *end;158int i;159160for(i = 0; i < num_keys; i++)161if(strcasecmp(keys[i].name, string) == 0){162*keytype = keys[i].type;163return 0;164}165166/* check if the enctype is a number */167*keytype = strtol(string, &end, 0);168if(*end == '\0' && *keytype != 0) {169if (krb5_enctype_valid(context, *keytype) == 0)170return 0;171}172173krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,174"key type %s not supported", string);175return KRB5_PROG_KEYTYPE_NOSUPP;176}177178/**179* Deprecated: use krb5_get_init_creds() and friends.180*181* @ingroup krb5_deprecated182*/183184KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV185krb5_password_key_proc (krb5_context context,186krb5_enctype type,187krb5_salt salt,188krb5_const_pointer keyseed,189krb5_keyblock **key)190KRB5_DEPRECATED_FUNCTION("Use X instead")191{192krb5_error_code ret;193const char *password = (const char *)keyseed;194char buf[BUFSIZ];195196*key = malloc (sizeof (**key));197if (*key == NULL) {198krb5_set_error_message(context, ENOMEM, "malloc: out of memory");199return ENOMEM;200}201if (password == NULL) {202if(UI_UTIL_read_pw_string (buf, sizeof(buf), "Password: ", 0)) {203free (*key);204krb5_clear_error_message(context);205return KRB5_LIBOS_PWDINTR;206}207password = buf;208}209ret = krb5_string_to_key_salt (context, type, password, salt, *key);210memset (buf, 0, sizeof(buf));211return ret;212}213214/**215* Deprecated: use krb5_get_init_creds() and friends.216*217* @ingroup krb5_deprecated218*/219220KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL221krb5_get_in_tkt_with_password (krb5_context context,222krb5_flags options,223krb5_addresses *addrs,224const krb5_enctype *etypes,225const krb5_preauthtype *pre_auth_types,226const char *password,227krb5_ccache ccache,228krb5_creds *creds,229krb5_kdc_rep *ret_as_reply)230KRB5_DEPRECATED_FUNCTION("Use X instead")231{232return krb5_get_in_tkt (context,233options,234addrs,235etypes,236pre_auth_types,237krb5_password_key_proc,238password,239NULL,240NULL,241creds,242ccache,243ret_as_reply);244}245246static krb5_error_code KRB5_CALLCONV247krb5_skey_key_proc (krb5_context context,248krb5_enctype type,249krb5_salt salt,250krb5_const_pointer keyseed,251krb5_keyblock **key)252{253return krb5_copy_keyblock (context, keyseed, key);254}255256/**257* Deprecated: use krb5_get_init_creds() and friends.258*259* @ingroup krb5_deprecated260*/261262KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL263krb5_get_in_tkt_with_skey (krb5_context context,264krb5_flags options,265krb5_addresses *addrs,266const krb5_enctype *etypes,267const krb5_preauthtype *pre_auth_types,268const krb5_keyblock *key,269krb5_ccache ccache,270krb5_creds *creds,271krb5_kdc_rep *ret_as_reply)272KRB5_DEPRECATED_FUNCTION("Use X instead")273{274if(key == NULL)275return krb5_get_in_tkt_with_keytab (context,276options,277addrs,278etypes,279pre_auth_types,280NULL,281ccache,282creds,283ret_as_reply);284else285return krb5_get_in_tkt (context,286options,287addrs,288etypes,289pre_auth_types,290krb5_skey_key_proc,291key,292NULL,293NULL,294creds,295ccache,296ret_as_reply);297}298299/**300* Deprecated: use krb5_get_init_creds() and friends.301*302* @ingroup krb5_deprecated303*/304305KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV306krb5_keytab_key_proc (krb5_context context,307krb5_enctype enctype,308krb5_salt salt,309krb5_const_pointer keyseed,310krb5_keyblock **key)311KRB5_DEPRECATED_FUNCTION("Use X instead")312{313krb5_keytab_key_proc_args *args = rk_UNCONST(keyseed);314krb5_keytab keytab = args->keytab;315krb5_principal principal = args->principal;316krb5_error_code ret;317krb5_keytab real_keytab;318krb5_keytab_entry entry;319320if(keytab == NULL)321krb5_kt_default(context, &real_keytab);322else323real_keytab = keytab;324325ret = krb5_kt_get_entry (context, real_keytab, principal,3260, enctype, &entry);327if (ret == 0) {328ret = krb5_copy_keyblock (context, &entry.keyblock, key);329krb5_kt_free_entry(context, &entry);330}331332if (keytab == NULL)333krb5_kt_close (context, real_keytab);334return ret;335}336337/**338* Deprecated: use krb5_get_init_creds() and friends.339*340* @ingroup krb5_deprecated341*/342343KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL344krb5_get_in_tkt_with_keytab (krb5_context context,345krb5_flags options,346krb5_addresses *addrs,347const krb5_enctype *etypes,348const krb5_preauthtype *pre_auth_types,349krb5_keytab keytab,350krb5_ccache ccache,351krb5_creds *creds,352krb5_kdc_rep *ret_as_reply)353KRB5_DEPRECATED_FUNCTION("Use X instead")354{355krb5_keytab_key_proc_args a;356357a.principal = creds->client;358a.keytab = keytab;359360return krb5_get_in_tkt (context,361options,362addrs,363etypes,364pre_auth_types,365krb5_keytab_key_proc,366&a,367NULL,368NULL,369creds,370ccache,371ret_as_reply);372}373374/**375* Generate a new ccache of type `ops' in `id'.376*377* Deprecated: use krb5_cc_new_unique() instead.378*379* @return Return an error code or 0, see krb5_get_error_message().380*381* @ingroup krb5_ccache382*/383384385KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL386krb5_cc_gen_new(krb5_context context,387const krb5_cc_ops *ops,388krb5_ccache *id)389KRB5_DEPRECATED_FUNCTION("Use X instead")390{391return krb5_cc_new_unique(context, ops->prefix, NULL, id);392}393394/**395* Deprecated: use krb5_principal_get_realm()396*397* @ingroup krb5_deprecated398*/399400KRB5_LIB_FUNCTION krb5_realm * KRB5_LIB_CALL401krb5_princ_realm(krb5_context context,402krb5_principal principal)403KRB5_DEPRECATED_FUNCTION("Use X instead")404{405return &principal->realm;406}407408409/**410* Deprecated: use krb5_principal_set_realm()411*412* @ingroup krb5_deprecated413*/414415KRB5_LIB_FUNCTION void KRB5_LIB_CALL416krb5_princ_set_realm(krb5_context context,417krb5_principal principal,418krb5_realm *realm)419KRB5_DEPRECATED_FUNCTION("Use X instead")420{421principal->realm = *realm;422}423424/**425* Deprecated: use krb5_free_cred_contents()426*427* @ingroup krb5_deprecated428*/429430/* keep this for compatibility with older code */431KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL432krb5_free_creds_contents (krb5_context context, krb5_creds *c)433KRB5_DEPRECATED_FUNCTION("Use X instead")434{435return krb5_free_cred_contents (context, c);436}437438/**439* Free the error message returned by krb5_get_error_string().440*441* Deprecated: use krb5_free_error_message()442*443* @param context Kerberos context444* @param str error message to free445*446* @ingroup krb5_deprecated447*/448449KRB5_LIB_FUNCTION void KRB5_LIB_CALL450krb5_free_error_string(krb5_context context, char *str)451KRB5_DEPRECATED_FUNCTION("Use X instead")452{453krb5_free_error_message(context, str);454}455456/**457* Set the error message returned by krb5_get_error_string().458*459* Deprecated: use krb5_get_error_message()460*461* @param context Kerberos context462* @param fmt error message to free463*464* @return Return an error code or 0.465*466* @ingroup krb5_deprecated467*/468469KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL470krb5_set_error_string(krb5_context context, const char *fmt, ...)471__attribute__((format (printf, 2, 3)))472KRB5_DEPRECATED_FUNCTION("Use X instead")473{474va_list ap;475476va_start(ap, fmt);477krb5_vset_error_message (context, 0, fmt, ap);478va_end(ap);479return 0;480}481482/**483* Set the error message returned by krb5_get_error_string(),484* deprecated, use krb5_set_error_message().485*486* Deprecated: use krb5_vset_error_message()487*488* @param context Kerberos context489* @param msg error message to free490*491* @return Return an error code or 0.492*493* @ingroup krb5_deprecated494*/495496KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL497krb5_vset_error_string(krb5_context context, const char *fmt, va_list args)498__attribute__ ((format (printf, 2, 0)))499KRB5_DEPRECATED_FUNCTION("Use X instead")500{501krb5_vset_error_message(context, 0, fmt, args);502return 0;503}504505/**506* Clear the error message returned by krb5_get_error_string().507*508* Deprecated: use krb5_clear_error_message()509*510* @param context Kerberos context511*512* @ingroup krb5_deprecated513*/514515KRB5_LIB_FUNCTION void KRB5_LIB_CALL516krb5_clear_error_string(krb5_context context)517KRB5_DEPRECATED_FUNCTION("Use X instead")518{519krb5_clear_error_message(context);520}521522/**523* Deprecated: use krb5_get_credentials_with_flags().524*525* @ingroup krb5_deprecated526*/527528KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL529krb5_get_cred_from_kdc_opt(krb5_context context,530krb5_ccache ccache,531krb5_creds *in_creds,532krb5_creds **out_creds,533krb5_creds ***ret_tgts,534krb5_flags flags)535KRB5_DEPRECATED_FUNCTION("Use X instead")536{537krb5_kdc_flags f;538f.i = flags;539return _krb5_get_cred_kdc_any(context, f, ccache,540in_creds, NULL, NULL,541out_creds, ret_tgts);542}543544/**545* Deprecated: use krb5_get_credentials_with_flags().546*547* @ingroup krb5_deprecated548*/549550KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL551krb5_get_cred_from_kdc(krb5_context context,552krb5_ccache ccache,553krb5_creds *in_creds,554krb5_creds **out_creds,555krb5_creds ***ret_tgts)556KRB5_DEPRECATED_FUNCTION("Use X instead")557{558return krb5_get_cred_from_kdc_opt(context, ccache,559in_creds, out_creds, ret_tgts, 0);560}561562/**563* Deprecated: use krb5_xfree().564*565* @ingroup krb5_deprecated566*/567568KRB5_LIB_FUNCTION void KRB5_LIB_CALL569krb5_free_unparsed_name(krb5_context context, char *str)570KRB5_DEPRECATED_FUNCTION("Use X instead")571{572krb5_xfree(str);573}574575/**576* Deprecated: use krb5_generate_subkey_extended()577*578* @ingroup krb5_deprecated579*/580581KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL582krb5_generate_subkey(krb5_context context,583const krb5_keyblock *key,584krb5_keyblock **subkey)585KRB5_DEPRECATED_FUNCTION("Use X instead")586{587return krb5_generate_subkey_extended(context, key, ETYPE_NULL, subkey);588}589590/**591* Deprecated: use krb5_auth_con_getremoteseqnumber()592*593* @ingroup krb5_deprecated594*/595596KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL597krb5_auth_getremoteseqnumber(krb5_context context,598krb5_auth_context auth_context,599int32_t *seqnumber)600KRB5_DEPRECATED_FUNCTION("Use X instead")601{602*seqnumber = auth_context->remote_seqnumber;603return 0;604}605606#endif /* HEIMDAL_SMALLER */607608609