turn off v4 conversion stuff
[heimdal.git] / lib / krb5 / deprecated.c
blob2a24b50f6662bd8b05d8d447345e2c570d336e3e
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 #define KRB5_DEPRECATED
36 #include "krb5_locl.h"
37 #include <com_right.h>
39 #undef __attribute__
40 #define __attribute__(x)
42 #ifndef HEIMDAL_SMALLER
44 /**
45 * Same as krb5_data_free(). MIT compat.
47 * @param context Kerberos 5 context.
48 * @param data krb5_data to free.
50 * @ingroup krb5
53 void KRB5_LIB_FUNCTION
54 krb5_free_data_contents(krb5_context context, krb5_data *data)
55 KRB5_DEPRECATED
57 krb5_data_free(data);
61 * First take the configured list of etypes for `keytype' if available,
62 * else, do `krb5_keytype_to_enctypes'.
65 krb5_error_code KRB5_LIB_FUNCTION
66 krb5_keytype_to_enctypes_default (krb5_context context,
67 krb5_keytype keytype,
68 unsigned *len,
69 krb5_enctype **val)
70 KRB5_DEPRECATED
72 unsigned int i, n;
73 krb5_enctype *ret;
75 if (keytype != KEYTYPE_DES || context->etypes_des == NULL)
76 return krb5_keytype_to_enctypes (context, keytype, len, val);
78 for (n = 0; context->etypes_des[n]; ++n)
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;
85 for (i = 0; i < n; ++i)
86 ret[i] = context->etypes_des[i];
87 *len = n;
88 *val = ret;
89 return 0;
93 static 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 }
106 static int num_keys = sizeof(keys) / sizeof(keys[0]);
108 krb5_error_code KRB5_LIB_FUNCTION
109 krb5_keytype_to_string(krb5_context context,
110 krb5_keytype keytype,
111 char **string)
112 KRB5_DEPRECATED
114 const char *name;
115 int i;
117 for(i = 0; i < num_keys; i++) {
118 if(keys[i].type == keytype) {
119 name = keys[i].name;
120 break;
124 if(i >= num_keys) {
125 krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
126 "key type %d not supported", keytype);
127 return KRB5_PROG_KEYTYPE_NOSUPP;
129 *string = strdup(name);
130 if(*string == NULL) {
131 krb5_set_error_message(context, ENOMEM,
132 N_("malloc: out of memory", ""));
133 return ENOMEM;
135 return 0;
138 krb5_error_code KRB5_LIB_FUNCTION
139 krb5_string_to_keytype(krb5_context context,
140 const char *string,
141 krb5_keytype *keytype)
142 KRB5_DEPRECATED
144 char *end;
145 int i;
147 for(i = 0; i < num_keys; i++)
148 if(strcasecmp(keys[i].name, string) == 0){
149 *keytype = keys[i].type;
150 return 0;
153 /* check if the enctype is a number */
154 *keytype = strtol(string, &end, 0);
155 if(*end == '\0' && *keytype != 0) {
156 if (krb5_enctype_valid(context, *keytype) == 0)
157 return 0;
160 krb5_set_error_message(context, KRB5_PROG_KEYTYPE_NOSUPP,
161 "key type %s not supported", string);
162 return KRB5_PROG_KEYTYPE_NOSUPP;
165 krb5_error_code KRB5_LIB_FUNCTION
166 krb5_password_key_proc (krb5_context context,
167 krb5_enctype type,
168 krb5_salt salt,
169 krb5_const_pointer keyseed,
170 krb5_keyblock **key)
171 KRB5_DEPRECATED
173 krb5_error_code ret;
174 const char *password = (const char *)keyseed;
175 char buf[BUFSIZ];
177 *key = malloc (sizeof (**key));
178 if (*key == NULL) {
179 krb5_set_error_message(context, ENOMEM, "malloc: out of memory");
180 return ENOMEM;
182 if (password == NULL) {
183 if(UI_UTIL_read_pw_string (buf, sizeof(buf), "Password: ", 0)) {
184 free (*key);
185 krb5_clear_error_message(context);
186 return KRB5_LIBOS_PWDINTR;
188 password = buf;
190 ret = krb5_string_to_key_salt (context, type, password, salt, *key);
191 memset (buf, 0, sizeof(buf));
192 return ret;
195 krb5_error_code KRB5_LIB_FUNCTION
196 krb5_get_in_tkt_with_password (krb5_context context,
197 krb5_flags options,
198 krb5_addresses *addrs,
199 const krb5_enctype *etypes,
200 const krb5_preauthtype *pre_auth_types,
201 const char *password,
202 krb5_ccache ccache,
203 krb5_creds *creds,
204 krb5_kdc_rep *ret_as_reply)
205 KRB5_DEPRECATED
207 return krb5_get_in_tkt (context,
208 options,
209 addrs,
210 etypes,
211 pre_auth_types,
212 krb5_password_key_proc,
213 password,
214 NULL,
215 NULL,
216 creds,
217 ccache,
218 ret_as_reply);
221 static krb5_error_code
222 krb5_skey_key_proc (krb5_context context,
223 krb5_enctype type,
224 krb5_salt salt,
225 krb5_const_pointer keyseed,
226 krb5_keyblock **key)
228 return krb5_copy_keyblock (context, keyseed, key);
231 krb5_error_code KRB5_LIB_FUNCTION
232 krb5_get_in_tkt_with_skey (krb5_context context,
233 krb5_flags options,
234 krb5_addresses *addrs,
235 const krb5_enctype *etypes,
236 const krb5_preauthtype *pre_auth_types,
237 const krb5_keyblock *key,
238 krb5_ccache ccache,
239 krb5_creds *creds,
240 krb5_kdc_rep *ret_as_reply)
241 KRB5_DEPRECATED
243 if(key == NULL)
244 return krb5_get_in_tkt_with_keytab (context,
245 options,
246 addrs,
247 etypes,
248 pre_auth_types,
249 NULL,
250 ccache,
251 creds,
252 ret_as_reply);
253 else
254 return krb5_get_in_tkt (context,
255 options,
256 addrs,
257 etypes,
258 pre_auth_types,
259 krb5_skey_key_proc,
260 key,
261 NULL,
262 NULL,
263 creds,
264 ccache,
265 ret_as_reply);
268 krb5_error_code KRB5_LIB_FUNCTION
269 krb5_keytab_key_proc (krb5_context context,
270 krb5_enctype enctype,
271 krb5_salt salt,
272 krb5_const_pointer keyseed,
273 krb5_keyblock **key)
274 KRB5_DEPRECATED
276 krb5_keytab_key_proc_args *args = rk_UNCONST(keyseed);
277 krb5_keytab keytab = args->keytab;
278 krb5_principal principal = args->principal;
279 krb5_error_code ret;
280 krb5_keytab real_keytab;
281 krb5_keytab_entry entry;
283 if(keytab == NULL)
284 krb5_kt_default(context, &real_keytab);
285 else
286 real_keytab = keytab;
288 ret = krb5_kt_get_entry (context, real_keytab, principal,
289 0, enctype, &entry);
291 if (keytab == NULL)
292 krb5_kt_close (context, real_keytab);
294 if (ret)
295 return ret;
297 ret = krb5_copy_keyblock (context, &entry.keyblock, key);
298 krb5_kt_free_entry(context, &entry);
299 return ret;
302 krb5_error_code KRB5_LIB_FUNCTION
303 krb5_get_in_tkt_with_keytab (krb5_context context,
304 krb5_flags options,
305 krb5_addresses *addrs,
306 const krb5_enctype *etypes,
307 const krb5_preauthtype *pre_auth_types,
308 krb5_keytab keytab,
309 krb5_ccache ccache,
310 krb5_creds *creds,
311 krb5_kdc_rep *ret_as_reply)
312 KRB5_DEPRECATED
314 krb5_keytab_key_proc_args a;
316 a.principal = creds->client;
317 a.keytab = keytab;
319 return krb5_get_in_tkt (context,
320 options,
321 addrs,
322 etypes,
323 pre_auth_types,
324 krb5_keytab_key_proc,
326 NULL,
327 NULL,
328 creds,
329 ccache,
330 ret_as_reply);
333 #ifdef KRB4
335 static krb5_boolean
336 convert_func(krb5_context conxtext, void *funcctx, krb5_principal principal)
338 krb5_boolean (*func)(krb5_context, krb5_principal) = funcctx;
339 return (*func)(conxtext, principal);
342 krb5_error_code KRB5_LIB_FUNCTION
343 krb5_425_conv_principal_ext(krb5_context context,
344 const char *name,
345 const char *instance,
346 const char *realm,
347 krb5_boolean (*func)(krb5_context, krb5_principal),
348 krb5_boolean resolve,
349 krb5_principal *principal)
350 KRB5_DEPRECATED
352 return krb5_425_conv_principal_ext2(context,
353 name,
354 instance,
355 realm,
356 func ? convert_func : NULL,
357 func,
358 resolve,
359 principal);
362 krb5_error_code KRB5_LIB_FUNCTION
363 krb5_425_conv_principal(krb5_context context,
364 const char *name,
365 const char *instance,
366 const char *realm,
367 krb5_principal *princ)
368 KRB5_DEPRECATED
370 krb5_boolean resolve = krb5_config_get_bool(context,
371 NULL,
372 "libdefaults",
373 "v4_instance_resolve",
374 NULL);
376 return krb5_425_conv_principal_ext(context, name, instance, realm,
377 NULL, resolve, princ);
380 #endif
383 * Generate a new ccache of type `ops' in `id'.
385 * Use krb5_cc_new_unique() instead.
387 * @return Return an error code or 0, see krb5_get_error_message().
389 * @ingroup krb5_ccache
393 krb5_error_code KRB5_LIB_FUNCTION
394 krb5_cc_gen_new(krb5_context context,
395 const krb5_cc_ops *ops,
396 krb5_ccache *id)
397 KRB5_DEPRECATED
399 return krb5_cc_new_unique(context, ops->prefix, NULL, id);
404 krb5_realm * KRB5_LIB_FUNCTION
405 krb5_princ_realm(krb5_context context,
406 krb5_principal principal)
407 KRB5_DEPRECATED
409 return &principal->realm;
413 void KRB5_LIB_FUNCTION
414 krb5_princ_set_realm(krb5_context context,
415 krb5_principal principal,
416 krb5_realm *realm)
417 KRB5_DEPRECATED
419 principal->realm = *realm;
422 /* keep this for compatibility with older code */
423 krb5_error_code KRB5_LIB_FUNCTION
424 krb5_free_creds_contents (krb5_context context, krb5_creds *c)
425 KRB5_DEPRECATED
427 return krb5_free_cred_contents (context, c);
431 * Free the error message returned by krb5_get_error_string(),
432 * deprecated, use krb5_free_error_message().
434 * @param context Kerberos context
435 * @param str error message to free
437 * @ingroup krb5_deprecated
440 void KRB5_LIB_FUNCTION
441 krb5_free_error_string(krb5_context context, char *str)
442 KRB5_DEPRECATED
444 krb5_free_error_message(context, str);
448 * Set the error message returned by krb5_get_error_string(),
449 * deprecated, use krb5_set_error_message().
451 * @param context Kerberos context
452 * @param fmt error message to free
454 * @return Return an error code or 0.
456 * @ingroup krb5_deprecated
459 krb5_error_code KRB5_LIB_FUNCTION
460 krb5_set_error_string(krb5_context context, const char *fmt, ...)
461 __attribute__((format (printf, 2, 3))) KRB5_DEPRECATED
463 va_list ap;
465 va_start(ap, fmt);
466 krb5_vset_error_message (context, 0, fmt, ap);
467 va_end(ap);
468 return 0;
472 * Set the error message returned by krb5_get_error_string(),
473 * deprecated, use krb5_set_error_message().
475 * @param context Kerberos context
476 * @param msg error message to free
478 * @return Return an error code or 0.
480 * @ingroup krb5_deprecated
483 krb5_error_code KRB5_LIB_FUNCTION
484 krb5_vset_error_string(krb5_context context, const char *fmt, va_list args)
485 __attribute__ ((format (printf, 2, 0))) KRB5_DEPRECATED
487 krb5_vset_error_message(context, 0, fmt, args);
488 return 0;
492 * Clar the error message returned by krb5_get_error_string(),
493 * deprecated, use krb5_clear_error_message().
495 * @param context Kerberos context
497 * @ingroup krb5_deprecated
500 void KRB5_LIB_FUNCTION
501 krb5_clear_error_string(krb5_context context)
502 KRB5_DEPRECATED
504 krb5_clear_error_message(context);
507 krb5_error_code KRB5_LIB_FUNCTION
508 krb5_get_cred_from_kdc_opt(krb5_context context,
509 krb5_ccache ccache,
510 krb5_creds *in_creds,
511 krb5_creds **out_creds,
512 krb5_creds ***ret_tgts,
513 krb5_flags flags) KRB5_DEPRECATED
515 krb5_kdc_flags f;
516 f.i = flags;
517 return _krb5_get_cred_kdc_any(context, f, ccache,
518 in_creds, NULL, NULL,
519 out_creds, ret_tgts);
522 krb5_error_code KRB5_LIB_FUNCTION
523 krb5_get_cred_from_kdc(krb5_context context,
524 krb5_ccache ccache,
525 krb5_creds *in_creds,
526 krb5_creds **out_creds,
527 krb5_creds ***ret_tgts) KRB5_DEPRECATED
529 return krb5_get_cred_from_kdc_opt(context, ccache,
530 in_creds, out_creds, ret_tgts, 0);
533 void KRB5_LIB_FUNCTION
534 krb5_free_unparsed_name(krb5_context context, char *str) KRB5_DEPRECATED
536 krb5_xfree(str);
539 krb5_error_code KRB5_LIB_FUNCTION
540 krb5_generate_subkey(krb5_context context,
541 const krb5_keyblock *key,
542 krb5_keyblock **subkey) KRB5_DEPRECATED
544 return krb5_generate_subkey_extended(context, key, ETYPE_NULL, subkey);
547 #endif /* HEIMDAL_SMALLER */