lib/gssapi/krb5: implement GSS_C_CHANNEL_BOUND_FLAG for gss_init_sec_context()
[heimdal.git] / lib / krb5 / deprecated.c
blob172f089175cc9937f1737e29af8703d141c5beb2
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 krb5_data_free 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 krb5_enctype_to_string 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 krb5_string_to_enctype 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_s(buf, sizeof(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);
327 if (ret == 0) {
328 ret = krb5_copy_keyblock (context, &entry.keyblock, key);
329 krb5_kt_free_entry(context, &entry);
332 if (keytab == NULL)
333 krb5_kt_close (context, real_keytab);
334 return ret;
338 * Deprecated: use krb5_get_init_creds() and friends.
340 * @ingroup krb5_deprecated
343 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
344 krb5_get_in_tkt_with_keytab (krb5_context context,
345 krb5_flags options,
346 krb5_addresses *addrs,
347 const krb5_enctype *etypes,
348 const krb5_preauthtype *pre_auth_types,
349 krb5_keytab keytab,
350 krb5_ccache ccache,
351 krb5_creds *creds,
352 krb5_kdc_rep *ret_as_reply)
353 KRB5_DEPRECATED_FUNCTION("Use X instead")
355 krb5_keytab_key_proc_args a;
357 a.principal = creds->client;
358 a.keytab = keytab;
360 return krb5_get_in_tkt (context,
361 options,
362 addrs,
363 etypes,
364 pre_auth_types,
365 krb5_keytab_key_proc,
367 NULL,
368 NULL,
369 creds,
370 ccache,
371 ret_as_reply);
375 * Generate a new ccache of type `ops' in `id'.
377 * Deprecated: use krb5_cc_new_unique() instead.
379 * @return Return an error code or 0, see krb5_get_error_message().
381 * @ingroup krb5_ccache
385 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
386 krb5_cc_gen_new(krb5_context context,
387 const krb5_cc_ops *ops,
388 krb5_ccache *id)
389 KRB5_DEPRECATED_FUNCTION("Use krb5_cc_new_unique instead")
391 return krb5_cc_new_unique(context, ops->prefix, NULL, id);
395 * Deprecated: use krb5_principal_get_realm()
397 * @ingroup krb5_deprecated
400 KRB5_LIB_FUNCTION krb5_realm * KRB5_LIB_CALL
401 krb5_princ_realm(krb5_context context,
402 krb5_principal principal)
403 KRB5_DEPRECATED_FUNCTION("Use krb5_principal_get_realm instead")
405 return &principal->realm;
410 * Deprecated: use krb5_principal_set_realm()
412 * @ingroup krb5_deprecated
415 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
416 krb5_princ_set_realm(krb5_context context,
417 krb5_principal principal,
418 krb5_realm *realm)
419 KRB5_DEPRECATED_FUNCTION("Use krb5_principal_set_realm instead")
421 principal->realm = *realm;
425 * Deprecated: use krb5_free_cred_contents()
427 * @ingroup krb5_deprecated
430 /* keep this for compatibility with older code */
431 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
432 krb5_free_creds_contents (krb5_context context, krb5_creds *c)
433 KRB5_DEPRECATED_FUNCTION("Use krb5_free_cred_contents instead")
435 return krb5_free_cred_contents (context, c);
439 * Free the error message returned by krb5_get_error_string().
441 * Deprecated: use krb5_free_error_message()
443 * @param context Kerberos context
444 * @param str error message to free
446 * @ingroup krb5_deprecated
449 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
450 krb5_free_error_string(krb5_context context, char *str)
451 KRB5_DEPRECATED_FUNCTION("Use krb5_free_error_message instead")
453 krb5_free_error_message(context, str);
457 * Set the error message returned by krb5_get_error_string().
459 * Deprecated: use krb5_set_error_message()
461 * @param context Kerberos context
462 * @param fmt error message to free
464 * @return Return an error code or 0.
466 * @ingroup krb5_deprecated
469 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
470 krb5_set_error_string(krb5_context context, const char *fmt, ...)
471 __attribute__ ((__format__ (__printf__, 2, 3)))
472 KRB5_DEPRECATED_FUNCTION("Use krb5_set_error_message instead")
474 va_list ap;
476 va_start(ap, fmt);
477 krb5_vset_error_message (context, 0, fmt, ap);
478 va_end(ap);
479 return 0;
483 * Set the error message returned by krb5_get_error_string().
485 * Deprecated: use krb5_vset_error_message()
487 * @param context Kerberos context
488 * @param fmt error message to free
489 * @param args variable argument list vector
491 * @return Return an error code or 0.
493 * @ingroup krb5_deprecated
496 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
497 krb5_vset_error_string(krb5_context context, const char *fmt, va_list args)
498 __attribute__ ((__format__ (__printf__, 2, 0)))
499 KRB5_DEPRECATED_FUNCTION("Use krb5_vset_error_message instead")
501 krb5_vset_error_message(context, 0, fmt, args);
502 return 0;
506 * Clear the error message returned by krb5_get_error_string().
508 * Deprecated: use krb5_clear_error_message()
510 * @param context Kerberos context
512 * @ingroup krb5_deprecated
515 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
516 krb5_clear_error_string(krb5_context context)
517 KRB5_DEPRECATED_FUNCTION("Use krb5_clear_error_message instead")
519 krb5_clear_error_message(context);
523 * Deprecated: use krb5_get_credentials_with_flags().
525 * @ingroup krb5_deprecated
528 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
529 krb5_get_cred_from_kdc_opt(krb5_context context,
530 krb5_ccache ccache,
531 krb5_creds *in_creds,
532 krb5_creds **out_creds,
533 krb5_creds ***ret_tgts,
534 krb5_flags flags)
535 KRB5_DEPRECATED_FUNCTION("Use krb5_get_credentials_with_flags instead")
537 krb5_kdc_flags f;
538 f.i = flags;
539 return _krb5_get_cred_kdc_any(context, f, ccache, NULL,
540 in_creds, NULL, NULL,
541 out_creds, ret_tgts);
545 * Deprecated: use krb5_get_credentials_with_flags().
547 * @ingroup krb5_deprecated
550 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
551 krb5_get_cred_from_kdc(krb5_context context,
552 krb5_ccache ccache,
553 krb5_creds *in_creds,
554 krb5_creds **out_creds,
555 krb5_creds ***ret_tgts)
556 KRB5_DEPRECATED_FUNCTION("Use krb5_get_credentials_with_flags instead")
558 return krb5_get_cred_from_kdc_opt(context, ccache,
559 in_creds, out_creds, ret_tgts, 0);
563 * Deprecated: use krb5_xfree().
565 * @ingroup krb5_deprecated
568 KRB5_LIB_FUNCTION void KRB5_LIB_CALL
569 krb5_free_unparsed_name(krb5_context context, char *str)
570 KRB5_DEPRECATED_FUNCTION("Use krb5_xfree instead")
572 krb5_xfree(str);
576 * Deprecated: use krb5_generate_subkey_extended()
578 * @ingroup krb5_deprecated
581 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
582 krb5_generate_subkey(krb5_context context,
583 const krb5_keyblock *key,
584 krb5_keyblock **subkey)
585 KRB5_DEPRECATED_FUNCTION("Use krb5_generate_subkey_extended instead")
587 return krb5_generate_subkey_extended(context, key, ETYPE_NULL, subkey);
591 * Deprecated: use krb5_auth_con_getremoteseqnumber()
593 * @ingroup krb5_deprecated
596 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
597 krb5_auth_getremoteseqnumber(krb5_context context,
598 krb5_auth_context auth_context,
599 int32_t *seqnumber)
600 KRB5_DEPRECATED_FUNCTION("Use krb5_auth_con_getremoteseqnumber instead")
602 *seqnumber = auth_context->remote_seqnumber;
603 return 0;
607 * Return the error message in context. On error or no error string,
608 * the function returns NULL.
610 * @param context Kerberos 5 context
612 * @return an error string, needs to be freed with
613 * krb5_free_error_message(). The functions return NULL on error.
615 * @ingroup krb5_error
618 KRB5_LIB_FUNCTION const char * KRB5_LIB_CALL
619 krb5_get_error_string(krb5_context context)
620 KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
622 return heim_get_error_string(context->hcontext);
625 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
626 krb5_have_error_string(krb5_context context)
627 KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
629 return heim_have_error_string(context->hcontext);
632 struct send_to_kdc {
633 krb5_send_to_kdc_func func;
634 void *data;
638 * Send the data `send' to one host from `handle` and get back the reply
639 * in `receive'.
642 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
643 krb5_sendto (krb5_context context,
644 const krb5_data *send_data,
645 krb5_krbhst_handle handle,
646 krb5_data *receive)
648 krb5_error_code ret;
649 krb5_sendto_ctx ctx;
651 ret = krb5_sendto_ctx_alloc(context, &ctx);
652 if (ret)
653 return ret;
654 _krb5_sendto_ctx_set_krb5hst(context, ctx, handle);
656 ret = krb5_sendto_context(context, ctx, send_data, (char *)_krb5_krbhst_get_realm(handle), receive);
657 krb5_sendto_ctx_free(context, ctx);
658 return ret;
661 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
662 krb5_sendto_kdc(krb5_context context,
663 const krb5_data *send_data,
664 const krb5_realm *realm,
665 krb5_data *receive)
667 return krb5_sendto_kdc_flags(context, send_data, realm, receive, 0);
670 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
671 krb5_sendto_kdc_flags(krb5_context context,
672 const krb5_data *send_data,
673 const krb5_realm *realm,
674 krb5_data *receive,
675 int flags)
677 krb5_error_code ret;
678 krb5_sendto_ctx ctx;
680 ret = krb5_sendto_ctx_alloc(context, &ctx);
681 if (ret)
682 return ret;
683 krb5_sendto_ctx_add_flags(ctx, flags);
684 krb5_sendto_ctx_set_func(ctx, _krb5_kdc_retry, NULL);
686 ret = krb5_sendto_context(context, ctx, send_data, *realm, receive);
687 krb5_sendto_ctx_free(context, ctx);
688 return ret;
691 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
692 krb5_set_send_to_kdc_func(krb5_context context,
693 krb5_send_to_kdc_func func,
694 void *data)
696 free(context->send_to_kdc);
697 if (func == NULL) {
698 context->send_to_kdc = NULL;
699 return 0;
702 context->send_to_kdc = malloc(sizeof(*context->send_to_kdc));
703 if (context->send_to_kdc == NULL) {
704 krb5_set_error_message(context, ENOMEM,
705 N_("malloc: out of memory", ""));
706 return ENOMEM;
709 context->send_to_kdc->func = func;
710 context->send_to_kdc->data = data;
711 return 0;
714 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
715 _krb5_copy_send_to_kdc_func(krb5_context context, krb5_context to)
717 if (context->send_to_kdc)
718 return krb5_set_send_to_kdc_func(to,
719 context->send_to_kdc->func,
720 context->send_to_kdc->data);
721 else
722 return krb5_set_send_to_kdc_func(to, NULL, NULL);
725 #endif /* HEIMDAL_SMALLER */