1/*
2 * Copyright (c) 1997 - 2009 Kungliga Tekniska H�gskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 *
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.
16 *
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.
20 *
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.
32 */
33
34#include "krb5_locl.h"
35
36#undef __attribute__
37#define __attribute__(x)
38
39#ifndef HEIMDAL_SMALLER
40
41/**
42 * Same as krb5_data_free(). MIT compat.
43 *
44 * Deprecated: use krb5_data_free().
45 *
46 * @param context Kerberos 5 context.
47 * @param data krb5_data to free.
48 *
49 * @ingroup krb5_deprecated
50 */
51
52KRB5_LIB_FUNCTION void KRB5_LIB_CALL
53krb5_free_data_contents(krb5_context context, krb5_data *data)
54    KRB5_DEPRECATED_FUNCTION("Use X instead")
55{
56    krb5_data_free(data);
57}
58
59/**
60 * Deprecated: keytypes doesn't exists, they are really enctypes.
61 *
62 * @ingroup krb5_deprecated
63 */
64
65KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
66krb5_keytype_to_enctypes_default (krb5_context context,
67				  krb5_keytype keytype,
68				  unsigned *len,
69				  krb5_enctype **val)
70    KRB5_DEPRECATED_FUNCTION("Use X instead")
71{
72    unsigned int i, n;
73    krb5_enctype *ret;
74
75    if (keytype != KEYTYPE_DES || context->etypes_des == NULL)
76	return krb5_keytype_to_enctypes (context, keytype, len, val);
77
78    for (n = 0; context->etypes_des[n]; ++n)
79	;
80    ret = malloc (n * sizeof(*ret));
81    if (ret == NULL && n != 0) {
82	krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
83	return ENOMEM;
84    }
85    for (i = 0; i < n; ++i)
86	ret[i] = context->etypes_des[i];
87    *len = n;
88    *val = ret;
89    return 0;
90}
91
92
93static struct {
94    const char *name;
95    krb5_keytype type;
96} keys[] = {
97    { "null", ENCTYPE_NULL },
98    { "des", ETYPE_DES_CBC_CRC },
99    { "des3", ETYPE_OLD_DES3_CBC_SHA1 },
100    { "aes-128", ETYPE_AES128_CTS_HMAC_SHA1_96 },
101    { "aes-256", ETYPE_AES256_CTS_HMAC_SHA1_96 },
102    { "arcfour", ETYPE_ARCFOUR_HMAC_MD5 },
103    { "arcfour-56", ETYPE_ARCFOUR_HMAC_MD5_56 }
104};
105
106static int num_keys = sizeof(keys) / sizeof(keys[0]);
107
108/**
109 * Deprecated: keytypes doesn't exists, they are really enctypes in
110 * most cases, use krb5_enctype_to_string().
111 *
112 * @ingroup krb5_deprecated
113 */
114
115KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
116krb5_keytype_to_string(krb5_context context,
117		       krb5_keytype keytype,
118		       char **string)
119    KRB5_DEPRECATED_FUNCTION("Use X instead")
120{
121    const char *name = NULL;
122    int i;
123
124    for(i = 0; i < num_keys; i++) {
125	if(keys[i].type == keytype) {
126	    name = keys[i].name;
127	    break;
128	}
129    }
130
131    if(i >= num_keys) {
132	krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
133			       "key type %d not supported", keytype);
134	return KRB5_PROG_KEYTYPE_NOSUPP;
135    }
136    *string = strdup(name);
137    if(*string == NULL) {
138	krb5_set_error_message(context, ENOMEM,
139			       N_("malloc: out of memory", ""));
140	return ENOMEM;
141    }
142    return 0;
143}
144
145/**
146 * Deprecated: keytypes doesn't exists, they are really enctypes in
147 * most cases, use krb5_string_to_enctype().
148 *
149 * @ingroup krb5_deprecated
150 */
151
152KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
153krb5_string_to_keytype(krb5_context context,
154		       const char *string,
155		       krb5_keytype *keytype)
156    KRB5_DEPRECATED_FUNCTION("Use X instead")
157{
158    char *end;
159    int i;
160
161    for(i = 0; i < num_keys; i++)
162	if(strcasecmp(keys[i].name, string) == 0){
163	    *keytype = keys[i].type;
164	    return 0;
165	}
166
167    /* check if the enctype is a number */
168    *keytype = strtol(string, &end, 0);
169    if(*end == '\0' && *keytype != 0) {
170	if (krb5_enctype_valid(context, *keytype) == 0)
171	    return 0;
172    }
173
174    krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
175			   "key type %s not supported", string);
176    return KRB5_PROG_KEYTYPE_NOSUPP;
177}
178
179/**
180 * Deprecated: use krb5_get_init_creds() and friends.
181 *
182 * @ingroup krb5_deprecated
183 */
184
185KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV
186krb5_password_key_proc (krb5_context context,
187			krb5_enctype type,
188			krb5_salt salt,
189			krb5_const_pointer keyseed,
190			krb5_keyblock **key)
191    KRB5_DEPRECATED_FUNCTION("Use X instead")
192{
193    krb5_error_code ret;
194    const char *password = (const char *)keyseed;
195    char buf[BUFSIZ];
196
197    *key = malloc (sizeof (**key));
198    if (*key == NULL) {
199	krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
200	return ENOMEM;
201    }
202    if (password == NULL) {
203	if(UI_UTIL_read_pw_string (buf, sizeof(buf), "Password: ", 0)) {
204	    free (*key);
205	    krb5_clear_error_message(context);
206	    return KRB5_LIBOS_PWDINTR;
207	}
208	password = buf;
209    }
210    ret = krb5_string_to_key_salt (context, type, password, salt, *key);
211    memset (buf, 0, sizeof(buf));
212    return ret;
213}
214
215/**
216 * Deprecated: use krb5_get_init_creds() and friends.
217 *
218 * @ingroup krb5_deprecated
219 */
220
221KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
222krb5_get_in_tkt_with_password (krb5_context context,
223			       krb5_flags options,
224			       krb5_addresses *addrs,
225			       const krb5_enctype *etypes,
226			       const krb5_preauthtype *pre_auth_types,
227			       const char *password,
228			       krb5_ccache ccache,
229			       krb5_creds *creds,
230			       krb5_kdc_rep *ret_as_reply)
231    KRB5_DEPRECATED_FUNCTION("Use X instead")
232{
233     return krb5_get_in_tkt (context,
234			     options,
235			     addrs,
236			     etypes,
237			     pre_auth_types,
238			     krb5_password_key_proc,
239			     password,
240			     NULL,
241			     NULL,
242			     creds,
243			     ccache,
244			     ret_as_reply);
245}
246
247static krb5_error_code KRB5_CALLCONV
248krb5_skey_key_proc (krb5_context context,
249		    krb5_enctype type,
250		    krb5_salt salt,
251		    krb5_const_pointer keyseed,
252		    krb5_keyblock **key)
253{
254    return krb5_copy_keyblock (context, keyseed, key);
255}
256
257/**
258 * Deprecated: use krb5_get_init_creds() and friends.
259 *
260 * @ingroup krb5_deprecated
261 */
262
263KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
264krb5_get_in_tkt_with_skey (krb5_context context,
265			   krb5_flags options,
266			   krb5_addresses *addrs,
267			   const krb5_enctype *etypes,
268			   const krb5_preauthtype *pre_auth_types,
269			   const krb5_keyblock *key,
270			   krb5_ccache ccache,
271			   krb5_creds *creds,
272			   krb5_kdc_rep *ret_as_reply)
273    KRB5_DEPRECATED_FUNCTION("Use X instead")
274{
275    if(key == NULL)
276	return krb5_get_in_tkt_with_keytab (context,
277					    options,
278					    addrs,
279					    etypes,
280					    pre_auth_types,
281					    NULL,
282					    ccache,
283					    creds,
284					    ret_as_reply);
285    else
286	return krb5_get_in_tkt (context,
287				options,
288				addrs,
289				etypes,
290				pre_auth_types,
291				krb5_skey_key_proc,
292				key,
293				NULL,
294				NULL,
295				creds,
296				ccache,
297				ret_as_reply);
298}
299
300/**
301 * Deprecated: use krb5_get_init_creds() and friends.
302 *
303 * @ingroup krb5_deprecated
304 */
305
306KRB5_LIB_FUNCTION krb5_error_code KRB5_CALLCONV
307krb5_keytab_key_proc (krb5_context context,
308		      krb5_enctype enctype,
309		      krb5_salt salt,
310		      krb5_const_pointer keyseed,
311		      krb5_keyblock **key)
312    KRB5_DEPRECATED_FUNCTION("Use X instead")
313{
314    krb5_keytab_key_proc_args *args  = rk_UNCONST(keyseed);
315    krb5_keytab keytab = args->keytab;
316    krb5_principal principal  = args->principal;
317    krb5_error_code ret;
318    krb5_keytab real_keytab;
319    krb5_keytab_entry entry;
320
321    if(keytab == NULL)
322	krb5_kt_default(context, &real_keytab);
323    else
324	real_keytab = keytab;
325
326    ret = krb5_kt_get_entry (context, real_keytab, principal,
327			     0, enctype, &entry);
328    if (ret == 0) {
329        ret = krb5_copy_keyblock (context, &entry.keyblock, key);
330        krb5_kt_free_entry(context, &entry);
331    }
332
333    if (keytab == NULL)
334	krb5_kt_close (context, real_keytab);
335    return ret;
336}
337
338/**
339 * Deprecated: use krb5_get_init_creds() and friends.
340 *
341 * @ingroup krb5_deprecated
342 */
343
344KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
345krb5_get_in_tkt_with_keytab (krb5_context context,
346			     krb5_flags options,
347			     krb5_addresses *addrs,
348			     const krb5_enctype *etypes,
349			     const krb5_preauthtype *pre_auth_types,
350			     krb5_keytab keytab,
351			     krb5_ccache ccache,
352			     krb5_creds *creds,
353			     krb5_kdc_rep *ret_as_reply)
354    KRB5_DEPRECATED_FUNCTION("Use X instead")
355{
356    krb5_keytab_key_proc_args a;
357
358    a.principal = creds->client;
359    a.keytab    = keytab;
360
361    return krb5_get_in_tkt (context,
362			    options,
363			    addrs,
364			    etypes,
365			    pre_auth_types,
366			    krb5_keytab_key_proc,
367			    &a,
368			    NULL,
369			    NULL,
370			    creds,
371			    ccache,
372			    ret_as_reply);
373}
374
375/**
376 * Generate a new ccache of type `ops' in `id'.
377 *
378 * Deprecated: use krb5_cc_new_unique() instead.
379 *
380 * @return Return an error code or 0, see krb5_get_error_message().
381 *
382 * @ingroup krb5_ccache
383 */
384
385
386KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
387krb5_cc_gen_new(krb5_context context,
388		const krb5_cc_ops *ops,
389		krb5_ccache *id)
390    KRB5_DEPRECATED_FUNCTION("Use X instead")
391{
392    return krb5_cc_new_unique(context, ops->prefix, NULL, id);
393}
394
395/**
396 * Deprecated: use krb5_principal_get_realm()
397 *
398 * @ingroup krb5_deprecated
399 */
400
401KRB5_LIB_FUNCTION krb5_realm * KRB5_LIB_CALL
402krb5_princ_realm(krb5_context context,
403		 krb5_principal principal)
404    KRB5_DEPRECATED_FUNCTION("Use X instead")
405{
406    return &principal->realm;
407}
408
409
410/**
411 * Deprecated: use krb5_principal_set_realm()
412 *
413 * @ingroup krb5_deprecated
414 */
415
416KRB5_LIB_FUNCTION void KRB5_LIB_CALL
417krb5_princ_set_realm(krb5_context context,
418		     krb5_principal principal,
419		     krb5_realm *realm)
420    KRB5_DEPRECATED_FUNCTION("Use X instead")
421{
422    principal->realm = *realm;
423}
424
425/**
426 * Deprecated: use krb5_free_cred_contents()
427 *
428 * @ingroup krb5_deprecated
429 */
430
431/* keep this for compatibility with older code */
432KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
433krb5_free_creds_contents (krb5_context context, krb5_creds *c)
434    KRB5_DEPRECATED_FUNCTION("Use X instead")
435{
436    return krb5_free_cred_contents (context, c);
437}
438
439/**
440 * Free the error message returned by krb5_get_error_string().
441 *
442 * Deprecated: use krb5_free_error_message()
443 *
444 * @param context Kerberos context
445 * @param str error message to free
446 *
447 * @ingroup krb5_deprecated
448 */
449
450KRB5_LIB_FUNCTION void KRB5_LIB_CALL
451krb5_free_error_string(krb5_context context, char *str)
452    KRB5_DEPRECATED_FUNCTION("Use X instead")
453{
454    krb5_free_error_message(context, str);
455}
456
457/**
458 * Set the error message returned by krb5_get_error_string().
459 *
460 * Deprecated: use krb5_get_error_message()
461 *
462 * @param context Kerberos context
463 * @param fmt error message to free
464 *
465 * @return Return an error code or 0.
466 *
467 * @ingroup krb5_deprecated
468 */
469
470KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
471krb5_set_error_string(krb5_context context, const char *fmt, ...)
472    __attribute__((format (printf, 2, 3)))
473    KRB5_DEPRECATED_FUNCTION("Use X instead")
474{
475    va_list ap;
476
477    va_start(ap, fmt);
478    krb5_vset_error_message (context, 0, fmt, ap);
479    va_end(ap);
480    return 0;
481}
482
483/**
484 * Set the error message returned by krb5_get_error_string(),
485 * deprecated, use krb5_set_error_message().
486 *
487 * Deprecated: use krb5_vset_error_message()
488 *
489 * @param context Kerberos context
490 * @param msg error message to free
491 *
492 * @return Return an error code or 0.
493 *
494 * @ingroup krb5_deprecated
495 */
496
497KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
498krb5_vset_error_string(krb5_context context, const char *fmt, va_list args)
499    __attribute__ ((format (printf, 2, 0)))
500    KRB5_DEPRECATED_FUNCTION("Use X instead")
501{
502    krb5_vset_error_message(context, 0, fmt, args);
503    return 0;
504}
505
506/**
507 * Clear the error message returned by krb5_get_error_string().
508 *
509 * Deprecated: use krb5_clear_error_message()
510 *
511 * @param context Kerberos context
512 *
513 * @ingroup krb5_deprecated
514 */
515
516KRB5_LIB_FUNCTION void KRB5_LIB_CALL
517krb5_clear_error_string(krb5_context context)
518    KRB5_DEPRECATED_FUNCTION("Use X instead")
519{
520    krb5_clear_error_message(context);
521}
522
523/**
524 * Deprecated: use krb5_get_credentials_with_flags().
525 *
526 * @ingroup krb5_deprecated
527 */
528
529KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
530krb5_get_cred_from_kdc_opt(krb5_context context,
531			   krb5_ccache ccache,
532			   krb5_creds *in_creds,
533			   krb5_creds **out_creds,
534			   krb5_creds ***ret_tgts,
535			   krb5_flags flags)
536    KRB5_DEPRECATED_FUNCTION("Use X instead")
537{
538    krb5_kdc_flags f;
539    f.i = flags;
540    return _krb5_get_cred_kdc_any(context, f, ccache,
541				  in_creds, NULL, NULL,
542				  out_creds, ret_tgts);
543}
544
545/**
546 * Deprecated: use krb5_get_credentials_with_flags().
547 *
548 * @ingroup krb5_deprecated
549 */
550
551KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
552krb5_get_cred_from_kdc(krb5_context context,
553		       krb5_ccache ccache,
554		       krb5_creds *in_creds,
555		       krb5_creds **out_creds,
556		       krb5_creds ***ret_tgts)
557    KRB5_DEPRECATED_FUNCTION("Use X instead")
558{
559    return krb5_get_cred_from_kdc_opt(context, ccache,
560				      in_creds, out_creds, ret_tgts, 0);
561}
562
563/**
564 * Deprecated: use krb5_xfree().
565 *
566 * @ingroup krb5_deprecated
567 */
568
569KRB5_LIB_FUNCTION void KRB5_LIB_CALL
570krb5_free_unparsed_name(krb5_context context, char *str)
571    KRB5_DEPRECATED_FUNCTION("Use X instead")
572{
573    krb5_xfree(str);
574}
575
576/**
577 * Deprecated: use krb5_generate_subkey_extended()
578 *
579 * @ingroup krb5_deprecated
580 */
581
582KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
583krb5_generate_subkey(krb5_context context,
584		     const krb5_keyblock *key,
585		     krb5_keyblock **subkey)
586    KRB5_DEPRECATED_FUNCTION("Use X instead")
587{
588    return krb5_generate_subkey_extended(context, key, ETYPE_NULL, subkey);
589}
590
591/**
592 * Deprecated: use krb5_auth_con_getremoteseqnumber()
593 *
594 * @ingroup krb5_deprecated
595 */
596
597KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
598krb5_auth_getremoteseqnumber(krb5_context context,
599			     krb5_auth_context auth_context,
600			     int32_t *seqnumber)
601    KRB5_DEPRECATED_FUNCTION("Use X instead")
602{
603  *seqnumber = auth_context->remote_seqnumber;
604  return 0;
605}
606
607#endif /* HEIMDAL_SMALLER */
608