Use __attribute__ ((__name__)) form
[heimdal.git] / lib / krb5 / deprecated.c
blobe3c142d889df33971cfe3100afebce3e4b4415e5
1 /*
2 * Copyright (c) 1997 - 2009 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #ifdef __GNUC__
35 /* For some GCCs there's no way to shut them up about deprecated functions */
36 #define KRB5_DEPRECATED_FUNCTION(x)
37 #endif
39 #include "krb5_locl.h"
42 #undef __attribute__
43 #define __attribute__(x)
45 #ifndef HEIMDAL_SMALLER
47 /**
48 * Same as krb5_data_free(). MIT compat.
50 * Deprecated: use krb5_data_free().
52 * @param context Kerberos 5 context.
53 * @param data krb5_data to free.
55 * @ingroup krb5_deprecated
58 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
59 krb5_free_data_contents(krb5_context context, krb5_data *data)
60 KRB5_DEPRECATED_FUNCTION("Use X instead")
62 krb5_data_free(data);
65 /**
66 * Deprecated: keytypes doesn't exists, they are really enctypes.
68 * @ingroup krb5_deprecated
71 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
72 krb5_keytype_to_enctypes_default (krb5_context context,
73 krb5_keytype keytype,
74 unsigned *len,
75 krb5_enctype **val)
76 KRB5_DEPRECATED_FUNCTION("Use X instead")
78 unsigned int i, n;
79 krb5_enctype *ret;
81 if (keytype != (krb5_keytype)KEYTYPE_DES || context->etypes_des == NULL)
82 return krb5_keytype_to_enctypes (context, keytype, len, val);
84 for (n = 0; context->etypes_des[n]; ++n)
86 ret = malloc (n * sizeof(*ret));
87 if (ret == NULL && n != 0)
88 return krb5_enomem(context);
89 for (i = 0; i < n; ++i)
90 ret[i] = context->etypes_des[i];
91 *len = n;
92 *val = ret;
93 return 0;
97 static struct {
98 const char *name;
99 krb5_keytype type;
100 } keys[] = {
101 { "null", KRB5_ENCTYPE_NULL },
102 { "des", KRB5_ENCTYPE_DES_CBC_CRC },
103 { "des3", KRB5_ENCTYPE_OLD_DES3_CBC_SHA1 },
104 { "aes-128", KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96 },
105 { "aes-256", KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96 },
106 { "arcfour", KRB5_ENCTYPE_ARCFOUR_HMAC_MD5 },
107 { "arcfour-56", KRB5_ENCTYPE_ARCFOUR_HMAC_MD5_56 }
110 static int num_keys = sizeof(keys) / sizeof(keys[0]);
113 * Deprecated: keytypes doesn't exists, they are really enctypes in
114 * most cases, use krb5_enctype_to_string().
116 * @ingroup krb5_deprecated
119 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
120 krb5_keytype_to_string(krb5_context context,
121 krb5_keytype keytype,
122 char **string)
123 KRB5_DEPRECATED_FUNCTION("Use X instead")
125 const char *name = NULL;
126 int i;
128 for(i = 0; i < num_keys; i++) {
129 if(keys[i].type == keytype) {
130 name = keys[i].name;
131 break;
135 if(i >= num_keys) {
136 krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
137 "key type %d not supported", keytype);
138 return KRB5_PROG_KEYTYPE_NOSUPP;
140 *string = strdup(name);
141 if (*string == NULL)
142 return krb5_enomem(context);
143 return 0;
147 * Deprecated: keytypes doesn't exists, they are really enctypes in
148 * most cases, use krb5_string_to_enctype().
150 * @ingroup krb5_deprecated
153 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
154 krb5_string_to_keytype(krb5_context context,
155 const char *string,
156 krb5_keytype *keytype)
157 KRB5_DEPRECATED_FUNCTION("Use X instead")
159 char *end;
160 int i;
162 for(i = 0; i < num_keys; i++)
163 if(strcasecmp(keys[i].name, string) == 0){
164 *keytype = keys[i].type;
165 return 0;
168 /* check if the enctype is a number */
169 *keytype = strtol(string, &end, 0);
170 if(*end == '\0' && *keytype != 0) {
171 if (krb5_enctype_valid(context, *keytype) == 0)
172 return 0;
175 krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
176 "key type %s not supported", string);
177 return KRB5_PROG_KEYTYPE_NOSUPP;
181 * Deprecated: use krb5_get_init_creds() and friends.
183 * @ingroup krb5_deprecated
186 KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV
187 krb5_password_key_proc (krb5_context context,
188 krb5_enctype type,
189 krb5_salt salt,
190 krb5_const_pointer keyseed,
191 krb5_keyblock **key)
192 KRB5_DEPRECATED_FUNCTION("Use X instead")
194 krb5_error_code ret;
195 const char *password = (const char *)keyseed;
196 char buf[BUFSIZ];
198 *key = malloc (sizeof (**key));
199 if (*key == NULL)
200 return krb5_enomem(context);
201 if (password == NULL) {
202 if(UI_UTIL_read_pw_string (buf, sizeof(buf), "Password: ", 0)) {
203 free (*key);
204 krb5_clear_error_message(context);
205 return KRB5_LIBOS_PWDINTR;
207 password = buf;
209 ret = krb5_string_to_key_salt (context, type, password, salt, *key);
210 memset (buf, 0, sizeof(buf));
211 return ret;
215 * Deprecated: use krb5_get_init_creds() and friends.
217 * @ingroup krb5_deprecated
220 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
221 krb5_get_in_tkt_with_password (krb5_context context,
222 krb5_flags options,
223 krb5_addresses *addrs,
224 const krb5_enctype *etypes,
225 const krb5_preauthtype *pre_auth_types,
226 const char *password,
227 krb5_ccache ccache,
228 krb5_creds *creds,
229 krb5_kdc_rep *ret_as_reply)
230 KRB5_DEPRECATED_FUNCTION("Use X instead")
232 return krb5_get_in_tkt (context,
233 options,
234 addrs,
235 etypes,
236 pre_auth_types,
237 krb5_password_key_proc,
238 password,
239 NULL,
240 NULL,
241 creds,
242 ccache,
243 ret_as_reply);
246 static krb5_error_code KRB5_CALLCONV
247 krb5_skey_key_proc (krb5_context context,
248 krb5_enctype type,
249 krb5_salt salt,
250 krb5_const_pointer keyseed,
251 krb5_keyblock **key)
253 return krb5_copy_keyblock (context, keyseed, key);
257 * Deprecated: use krb5_get_init_creds() and friends.
259 * @ingroup krb5_deprecated
262 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
263 krb5_get_in_tkt_with_skey (krb5_context context,
264 krb5_flags options,
265 krb5_addresses *addrs,
266 const krb5_enctype *etypes,
267 const krb5_preauthtype *pre_auth_types,
268 const krb5_keyblock *key,
269 krb5_ccache ccache,
270 krb5_creds *creds,
271 krb5_kdc_rep *ret_as_reply)
272 KRB5_DEPRECATED_FUNCTION("Use X instead")
274 if(key == NULL)
275 return krb5_get_in_tkt_with_keytab (context,
276 options,
277 addrs,
278 etypes,
279 pre_auth_types,
280 NULL,
281 ccache,
282 creds,
283 ret_as_reply);
284 else
285 return krb5_get_in_tkt (context,
286 options,
287 addrs,
288 etypes,
289 pre_auth_types,
290 krb5_skey_key_proc,
291 key,
292 NULL,
293 NULL,
294 creds,
295 ccache,
296 ret_as_reply);
300 * Deprecated: use krb5_get_init_creds() and friends.
302 * @ingroup krb5_deprecated
305 KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV
306 krb5_keytab_key_proc (krb5_context context,
307 krb5_enctype enctype,
308 krb5_salt salt,
309 krb5_const_pointer keyseed,
310 krb5_keyblock **key)
311 KRB5_DEPRECATED_FUNCTION("Use X instead")
313 krb5_keytab_key_proc_args *args = rk_UNCONST(keyseed);
314 krb5_keytab keytab = args->keytab;
315 krb5_principal principal = args->principal;
316 krb5_error_code ret;
317 krb5_keytab real_keytab;
318 krb5_keytab_entry entry;
320 if(keytab == NULL)
321 krb5_kt_default(context, &real_keytab);
322 else
323 real_keytab = keytab;
325 ret = krb5_kt_get_entry (context, real_keytab, principal,
326 0, enctype, &entry);
328 if (keytab == NULL)
329 krb5_kt_close (context, real_keytab);
331 if (ret)
332 return ret;
334 ret = krb5_copy_keyblock (context, &entry.keyblock, key);
335 krb5_kt_free_entry(context, &entry);
336 return ret;
340 * Deprecated: use krb5_get_init_creds() and friends.
342 * @ingroup krb5_deprecated
345 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
346 krb5_get_in_tkt_with_keytab (krb5_context context,
347 krb5_flags options,
348 krb5_addresses *addrs,
349 const krb5_enctype *etypes,
350 const krb5_preauthtype *pre_auth_types,
351 krb5_keytab keytab,
352 krb5_ccache ccache,
353 krb5_creds *creds,
354 krb5_kdc_rep *ret_as_reply)
355 KRB5_DEPRECATED_FUNCTION("Use X instead")
357 krb5_keytab_key_proc_args a;
359 a.principal = creds->client;
360 a.keytab = keytab;
362 return krb5_get_in_tkt (context,
363 options,
364 addrs,
365 etypes,
366 pre_auth_types,
367 krb5_keytab_key_proc,
369 NULL,
370 NULL,
371 creds,
372 ccache,
373 ret_as_reply);
377 * Generate a new ccache of type `ops' in `id'.
379 * Deprecated: use krb5_cc_new_unique() instead.
381 * @return Return an error code or 0, see krb5_get_error_message().
383 * @ingroup krb5_ccache
387 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
388 krb5_cc_gen_new(krb5_context context,
389 const krb5_cc_ops *ops,
390 krb5_ccache *id)
391 KRB5_DEPRECATED_FUNCTION("Use X instead")
393 return krb5_cc_new_unique(context, ops->prefix, NULL, id);
397 * Deprecated: use krb5_principal_get_realm()
399 * @ingroup krb5_deprecated
402 KRB5_LIB_FUNCTION krb5_realm * KRB5_LIB_CALL
403 krb5_princ_realm(krb5_context context,
404 krb5_principal principal)
405 KRB5_DEPRECATED_FUNCTION("Use X instead")
407 return &principal->realm;
412 * Deprecated: use krb5_principal_set_realm()
414 * @ingroup krb5_deprecated
417 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
418 krb5_princ_set_realm(krb5_context context,
419 krb5_principal principal,
420 krb5_realm *realm)
421 KRB5_DEPRECATED_FUNCTION("Use X instead")
423 principal->realm = *realm;
427 * Deprecated: use krb5_free_cred_contents()
429 * @ingroup krb5_deprecated
432 /* keep this for compatibility with older code */
433 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
434 krb5_free_creds_contents (krb5_context context, krb5_creds *c)
435 KRB5_DEPRECATED_FUNCTION("Use X instead")
437 return krb5_free_cred_contents (context, c);
441 * Free the error message returned by krb5_get_error_string().
443 * Deprecated: use krb5_free_error_message()
445 * @param context Kerberos context
446 * @param str error message to free
448 * @ingroup krb5_deprecated
451 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
452 krb5_free_error_string(krb5_context context, char *str)
453 KRB5_DEPRECATED_FUNCTION("Use X instead")
455 krb5_free_error_message(context, str);
459 * Set the error message returned by krb5_get_error_string().
461 * Deprecated: use krb5_get_error_message()
463 * @param context Kerberos context
464 * @param fmt error message to free
466 * @return Return an error code or 0.
468 * @ingroup krb5_deprecated
471 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
472 krb5_set_error_string(krb5_context context, const char *fmt, ...)
473 __attribute__ ((__format__ (__printf__, 2, 3)))
474 KRB5_DEPRECATED_FUNCTION("Use X instead")
476 va_list ap;
478 va_start(ap, fmt);
479 krb5_vset_error_message (context, 0, fmt, ap);
480 va_end(ap);
481 return 0;
485 * Set the error message returned by krb5_get_error_string(),
486 * deprecated, use krb5_set_error_message().
488 * Deprecated: use krb5_vset_error_message()
490 * @param context Kerberos context
491 * @param fmt error message to free
492 * @param args variable argument list vector
494 * @return Return an error code or 0.
496 * @ingroup krb5_deprecated
499 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
500 krb5_vset_error_string(krb5_context context, const char *fmt, va_list args)
501 __attribute__ ((__format__ (__printf__, 2, 0)))
502 KRB5_DEPRECATED_FUNCTION("Use X instead")
504 krb5_vset_error_message(context, 0, fmt, args);
505 return 0;
509 * Clear the error message returned by krb5_get_error_string().
511 * Deprecated: use krb5_clear_error_message()
513 * @param context Kerberos context
515 * @ingroup krb5_deprecated
518 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
519 krb5_clear_error_string(krb5_context context)
520 KRB5_DEPRECATED_FUNCTION("Use X instead")
522 krb5_clear_error_message(context);
526 * Deprecated: use krb5_get_credentials_with_flags().
528 * @ingroup krb5_deprecated
531 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
532 krb5_get_cred_from_kdc_opt(krb5_context context,
533 krb5_ccache ccache,
534 krb5_creds *in_creds,
535 krb5_creds **out_creds,
536 krb5_creds ***ret_tgts,
537 krb5_flags flags)
538 KRB5_DEPRECATED_FUNCTION("Use X instead")
540 krb5_kdc_flags f;
541 f.i = flags;
542 return _krb5_get_cred_kdc_any(context, f, ccache,
543 in_creds, NULL, NULL,
544 out_creds, ret_tgts);
548 * Deprecated: use krb5_get_credentials_with_flags().
550 * @ingroup krb5_deprecated
553 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
554 krb5_get_cred_from_kdc(krb5_context context,
555 krb5_ccache ccache,
556 krb5_creds *in_creds,
557 krb5_creds **out_creds,
558 krb5_creds ***ret_tgts)
559 KRB5_DEPRECATED_FUNCTION("Use X instead")
561 return krb5_get_cred_from_kdc_opt(context, ccache,
562 in_creds, out_creds, ret_tgts, 0);
566 * Deprecated: use krb5_xfree().
568 * @ingroup krb5_deprecated
571 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
572 krb5_free_unparsed_name(krb5_context context, char *str)
573 KRB5_DEPRECATED_FUNCTION("Use X instead")
575 krb5_xfree(str);
579 * Deprecated: use krb5_generate_subkey_extended()
581 * @ingroup krb5_deprecated
584 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
585 krb5_generate_subkey(krb5_context context,
586 const krb5_keyblock *key,
587 krb5_keyblock **subkey)
588 KRB5_DEPRECATED_FUNCTION("Use X instead")
590 return krb5_generate_subkey_extended(context, key, ETYPE_NULL, subkey);
594 * Deprecated: use krb5_auth_con_getremoteseqnumber()
596 * @ingroup krb5_deprecated
599 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
600 krb5_auth_getremoteseqnumber(krb5_context context,
601 krb5_auth_context auth_context,
602 int32_t *seqnumber)
603 KRB5_DEPRECATED_FUNCTION("Use X instead")
605 *seqnumber = auth_context->remote_seqnumber;
606 return 0;
610 * Return the error message in context. On error or no error string,
611 * the function returns NULL.
613 * @param context Kerberos 5 context
615 * @return an error string, needs to be freed with
616 * krb5_free_error_message(). The functions return NULL on error.
618 * @ingroup krb5_error
621 KRB5_LIB_FUNCTION char * KRB5_LIB_CALL
622 krb5_get_error_string(krb5_context context)
623 KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
625 char *ret = NULL;
627 HEIMDAL_MUTEX_lock(&context->mutex);
628 if (context->error_string)
629 ret = strdup(context->error_string);
630 HEIMDAL_MUTEX_unlock(&context->mutex);
631 return ret;
634 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
635 krb5_have_error_string(krb5_context context)
636 KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
638 char *str;
639 HEIMDAL_MUTEX_lock(&context->mutex);
640 str = context->error_string;
641 HEIMDAL_MUTEX_unlock(&context->mutex);
642 return str != NULL;
645 struct send_to_kdc {
646 krb5_send_to_kdc_func func;
647 void *data;
651 * Send the data `send' to one host from `handle` and get back the reply
652 * in `receive'.
655 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
656 krb5_sendto (krb5_context context,
657 const krb5_data *send_data,
658 krb5_krbhst_handle handle,
659 krb5_data *receive)
661 krb5_error_code ret;
662 krb5_sendto_ctx ctx;
664 ret = krb5_sendto_ctx_alloc(context, &ctx);
665 if (ret)
666 return ret;
667 _krb5_sendto_ctx_set_krb5hst(context, ctx, handle);
669 ret = krb5_sendto_context(context, ctx, send_data, (char *)_krb5_krbhst_get_realm(handle), receive);
670 krb5_sendto_ctx_free(context, ctx);
671 return ret;
674 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
675 krb5_sendto_kdc(krb5_context context,
676 const krb5_data *send_data,
677 const krb5_realm *realm,
678 krb5_data *receive)
680 return krb5_sendto_kdc_flags(context, send_data, realm, receive, 0);
683 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
684 krb5_sendto_kdc_flags(krb5_context context,
685 const krb5_data *send_data,
686 const krb5_realm *realm,
687 krb5_data *receive,
688 int flags)
690 krb5_error_code ret;
691 krb5_sendto_ctx ctx;
693 ret = krb5_sendto_ctx_alloc(context, &ctx);
694 if (ret)
695 return ret;
696 krb5_sendto_ctx_add_flags(ctx, flags);
697 krb5_sendto_ctx_set_func(ctx, _krb5_kdc_retry, NULL);
699 ret = krb5_sendto_context(context, ctx, send_data, *realm, receive);
700 krb5_sendto_ctx_free(context, ctx);
701 return ret;
704 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
705 krb5_set_send_to_kdc_func(krb5_context context,
706 krb5_send_to_kdc_func func,
707 void *data)
709 free(context->send_to_kdc);
710 if (func == NULL) {
711 context->send_to_kdc = NULL;
712 return 0;
715 context->send_to_kdc = malloc(sizeof(*context->send_to_kdc));
716 if (context->send_to_kdc == NULL) {
717 krb5_set_error_message(context, ENOMEM,
718 N_("malloc: out of memory", ""));
719 return ENOMEM;
722 context->send_to_kdc->func = func;
723 context->send_to_kdc->data = data;
724 return 0;
727 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
728 _krb5_copy_send_to_kdc_func(krb5_context context, krb5_context to)
730 if (context->send_to_kdc)
731 return krb5_set_send_to_kdc_func(to,
732 context->send_to_kdc->func,
733 context->send_to_kdc->data);
734 else
735 return krb5_set_send_to_kdc_func(to, NULL, NULL);
738 #endif /* HEIMDAL_SMALLER */