2 * Copyright (c) 1997 - 2009 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 #define KRB5_DEPRECATED
36 #include "krb5_locl.h"
37 #include <com_right.h>
40 #define __attribute__(x)
42 #ifndef HEIMDAL_SMALLER
45 * Same as krb5_data_free(). MIT compat.
47 * @param context Kerberos 5 context.
48 * @param data krb5_data to free.
53 void KRB5_LIB_FUNCTION
54 krb5_free_data_contents(krb5_context context
, krb5_data
*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
,
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", ""));
85 for (i
= 0; i
< n
; ++i
)
86 ret
[i
] = context
->etypes_des
[i
];
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
,
117 for(i
= 0; i
< num_keys
; i
++) {
118 if(keys
[i
].type
== keytype
) {
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", ""));
138 krb5_error_code KRB5_LIB_FUNCTION
139 krb5_string_to_keytype(krb5_context context
,
141 krb5_keytype
*keytype
)
147 for(i
= 0; i
< num_keys
; i
++)
148 if(strcasecmp(keys
[i
].name
, string
) == 0){
149 *keytype
= keys
[i
].type
;
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)
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
,
169 krb5_const_pointer keyseed
,
174 const char *password
= (const char *)keyseed
;
177 *key
= malloc (sizeof (**key
));
179 krb5_set_error_message(context
, ENOMEM
, "malloc: out of memory");
182 if (password
== NULL
) {
183 if(UI_UTIL_read_pw_string (buf
, sizeof(buf
), "Password: ", 0)) {
185 krb5_clear_error_message(context
);
186 return KRB5_LIBOS_PWDINTR
;
190 ret
= krb5_string_to_key_salt (context
, type
, password
, salt
, *key
);
191 memset (buf
, 0, sizeof(buf
));
195 krb5_error_code KRB5_LIB_FUNCTION
196 krb5_get_in_tkt_with_password (krb5_context context
,
198 krb5_addresses
*addrs
,
199 const krb5_enctype
*etypes
,
200 const krb5_preauthtype
*pre_auth_types
,
201 const char *password
,
204 krb5_kdc_rep
*ret_as_reply
)
207 return krb5_get_in_tkt (context
,
212 krb5_password_key_proc
,
221 static krb5_error_code
222 krb5_skey_key_proc (krb5_context context
,
225 krb5_const_pointer keyseed
,
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
,
234 krb5_addresses
*addrs
,
235 const krb5_enctype
*etypes
,
236 const krb5_preauthtype
*pre_auth_types
,
237 const krb5_keyblock
*key
,
240 krb5_kdc_rep
*ret_as_reply
)
244 return krb5_get_in_tkt_with_keytab (context
,
254 return krb5_get_in_tkt (context
,
268 krb5_error_code KRB5_LIB_FUNCTION
269 krb5_keytab_key_proc (krb5_context context
,
270 krb5_enctype enctype
,
272 krb5_const_pointer keyseed
,
276 krb5_keytab_key_proc_args
*args
= rk_UNCONST(keyseed
);
277 krb5_keytab keytab
= args
->keytab
;
278 krb5_principal principal
= args
->principal
;
280 krb5_keytab real_keytab
;
281 krb5_keytab_entry entry
;
284 krb5_kt_default(context
, &real_keytab
);
286 real_keytab
= keytab
;
288 ret
= krb5_kt_get_entry (context
, real_keytab
, principal
,
292 krb5_kt_close (context
, real_keytab
);
297 ret
= krb5_copy_keyblock (context
, &entry
.keyblock
, key
);
298 krb5_kt_free_entry(context
, &entry
);
302 krb5_error_code KRB5_LIB_FUNCTION
303 krb5_get_in_tkt_with_keytab (krb5_context context
,
305 krb5_addresses
*addrs
,
306 const krb5_enctype
*etypes
,
307 const krb5_preauthtype
*pre_auth_types
,
311 krb5_kdc_rep
*ret_as_reply
)
314 krb5_keytab_key_proc_args a
;
316 a
.principal
= creds
->client
;
319 return krb5_get_in_tkt (context
,
324 krb5_keytab_key_proc
,
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
,
345 const char *instance
,
347 krb5_boolean (*func
)(krb5_context
, krb5_principal
),
348 krb5_boolean resolve
,
349 krb5_principal
*principal
)
352 return krb5_425_conv_principal_ext2(context
,
356 func
? convert_func
: NULL
,
362 krb5_error_code KRB5_LIB_FUNCTION
363 krb5_425_conv_principal(krb5_context context
,
365 const char *instance
,
367 krb5_principal
*princ
)
370 krb5_boolean resolve
= krb5_config_get_bool(context
,
373 "v4_instance_resolve",
376 return krb5_425_conv_principal_ext(context
, name
, instance
, realm
,
377 NULL
, resolve
, princ
);
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
,
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
)
409 return &principal
->realm
;
413 void KRB5_LIB_FUNCTION
414 krb5_princ_set_realm(krb5_context context
,
415 krb5_principal principal
,
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
)
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
)
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
466 krb5_vset_error_message (context
, 0, fmt
, ap
);
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
);
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
)
504 krb5_clear_error_message(context
);
507 krb5_error_code KRB5_LIB_FUNCTION
508 krb5_get_cred_from_kdc_opt(krb5_context context
,
510 krb5_creds
*in_creds
,
511 krb5_creds
**out_creds
,
512 krb5_creds
***ret_tgts
,
513 krb5_flags flags
) KRB5_DEPRECATED
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
,
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
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 */