2 * Copyright (c) 1997 - 2005 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 #include "krb5_locl.h"
37 * @page krb5_keytab_intro The keytab handing functions
38 * @section section_krb5_keytab Kerberos Keytabs
40 * See the library functions here: @ref krb5_keytab
42 * Keytabs are long term key storage for servers, their equvalment of
45 * Normally the only function that useful for server are to specify
46 * what keytab to use to other core functions like krb5_rd_req()
47 * krb5_kt_resolve(), and krb5_kt_close().
49 * @subsection krb5_keytab_names Keytab names
51 * A keytab name is on the form type:residual. The residual part is
52 * specific to each keytab-type.
54 * When a keytab-name is resolved, the type is matched with an internal
55 * list of keytab types. If there is no matching keytab type,
56 * the default keytab is used. The current default type is FILE.
58 * The default value can be changed in the configuration file
59 * /etc/krb5.conf by setting the variable
60 * [defaults]default_keytab_name.
62 * The keytab types that are implemented in Heimdal are:
64 * store the keytab in a file, the type's name is FILE . The
65 * residual part is a filename. For compatibility with other
66 * Kerberos implemtation WRFILE and JAVA14 is also accepted. WRFILE
67 * has the same format as FILE. JAVA14 have a format that is
68 * compatible with older versions of MIT kerberos and SUN's Java
69 * based installation. They store a truncted kvno, so when the knvo
70 * excess 255, they are truncted in this format.
73 * store the keytab in a AFS keyfile (usually /usr/afs/etc/KeyFile ),
74 * the type's name is AFSKEYFILE. The residual part is a filename.
77 * The keytab is stored in a memory segment. This allows sensitive
78 * and/or temporary data not to be stored on disk. The type's name
79 * is MEMORY. Each MEMORY keytab is referenced counted by and
80 * opened by the residual name, so two handles can point to the
81 * same memory area. When the last user closes using krb5_kt_close()
82 * the keytab, the keys in they keytab is memset() to zero and freed
83 * and can no longer be looked up by name.
86 * @subsection krb5_keytab_example Keytab example
88 * This is a minimalistic version of ktutil.
92 main (int argc, char **argv)
96 krb5_kt_cursor cursor;
97 krb5_keytab_entry entry;
101 if (krb5_init_context (&context) != 0)
102 errx(1, "krb5_context");
104 ret = krb5_kt_default (context, &keytab);
106 krb5_err(context, 1, ret, "krb5_kt_default");
108 ret = krb5_kt_start_seq_get(context, keytab, &cursor);
110 krb5_err(context, 1, ret, "krb5_kt_start_seq_get");
111 while((ret = krb5_kt_next_entry(context, keytab, &entry, &cursor)) == 0){
112 krb5_unparse_name(context, entry.principal, &principal);
113 printf("principal: %s\n", principal);
115 krb5_kt_free_entry(context, &entry);
117 ret = krb5_kt_end_seq_get(context, keytab, &cursor);
119 krb5_err(context, 1, ret, "krb5_kt_end_seq_get");
120 ret = krb5_kt_close(context, keytab);
122 krb5_err(context, 1, ret, "krb5_kt_close");
123 krb5_free_context(context);
132 * Register a new keytab backend.
134 * @param context a Keberos context.
135 * @param ops a backend to register.
137 * @return Return an error code or 0, see krb5_get_error_message().
139 * @ingroup krb5_keytab
142 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
143 krb5_kt_register(krb5_context context
,
144 const krb5_kt_ops
*ops
)
146 struct krb5_keytab_data
*tmp
;
148 if (strlen(ops
->prefix
) > KRB5_KT_PREFIX_MAX_LEN
- 1) {
149 krb5_set_error_message(context
, KRB5_KT_BADNAME
,
150 N_("can't register cache type, prefix too long", ""));
151 return KRB5_KT_BADNAME
;
154 tmp
= realloc(context
->kt_types
,
155 (context
->num_kt_types
+ 1) * sizeof(*context
->kt_types
));
157 return krb5_enomem(context
);
158 memcpy(&tmp
[context
->num_kt_types
], ops
,
159 sizeof(tmp
[context
->num_kt_types
]));
160 context
->kt_types
= tmp
;
161 context
->num_kt_types
++;
166 keytab_name(const char *name
, const char **type
, size_t *type_len
)
168 const char *residual
;
170 residual
= strchr(name
, ':');
172 if (residual
== NULL
||
175 /* Avoid treating <drive>:<path> as a keytab type
177 || name
+ 1 == residual
182 *type_len
= strlen(*type
);
186 *type_len
= residual
- name
;
194 * Resolve the keytab name (of the form `type:residual') in `name'
195 * into a keytab in `id'.
197 * @param context a Keberos context.
198 * @param name name to resolve
199 * @param id resulting keytab, free with krb5_kt_close().
201 * @return Return an error code or 0, see krb5_get_error_message().
203 * @ingroup krb5_keytab
207 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
208 krb5_kt_resolve(krb5_context context
,
214 const char *type
, *residual
;
218 residual
= keytab_name(name
, &type
, &type_len
);
220 for(i
= 0; i
< context
->num_kt_types
; i
++) {
221 if(strncasecmp(type
, context
->kt_types
[i
].prefix
, type_len
) == 0)
224 if(i
== context
->num_kt_types
) {
225 krb5_set_error_message(context
, KRB5_KT_UNKNOWN_TYPE
,
226 N_("unknown keytab type %.*s", "type"),
227 (int)type_len
, type
);
228 return KRB5_KT_UNKNOWN_TYPE
;
231 k
= malloc (sizeof(*k
));
233 return krb5_enomem(context
);
234 memcpy(k
, &context
->kt_types
[i
], sizeof(*k
));
236 ret
= (*k
->resolve
)(context
, residual
, k
);
246 * copy the name of the default keytab into `name'.
248 * @param context a Keberos context.
249 * @param name buffer where the name will be written
250 * @param namesize length of name
252 * @return Return an error code or 0, see krb5_get_error_message().
254 * @ingroup krb5_keytab
257 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
258 krb5_kt_default_name(krb5_context context
, char *name
, size_t namesize
)
260 if (strlcpy (name
, context
->default_keytab
, namesize
) >= namesize
) {
261 krb5_clear_error_message (context
);
262 return KRB5_CONFIG_NOTENUFSPACE
;
268 * Copy the name of the default modify keytab into `name'.
270 * @param context a Keberos context.
271 * @param name buffer where the name will be written
272 * @param namesize length of name
274 * @return Return an error code or 0, see krb5_get_error_message().
276 * @ingroup krb5_keytab
279 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
280 krb5_kt_default_modify_name(krb5_context context
, char *name
, size_t namesize
)
282 const char *kt
= NULL
;
283 if(context
->default_keytab_modify
== NULL
) {
284 if(strncasecmp(context
->default_keytab
, "ANY:", 4) != 0)
285 kt
= context
->default_keytab
;
287 size_t len
= strcspn(context
->default_keytab
+ 4, ",");
288 if(len
>= namesize
) {
289 krb5_clear_error_message(context
);
290 return KRB5_CONFIG_NOTENUFSPACE
;
292 strlcpy(name
, context
->default_keytab
+ 4, namesize
);
297 kt
= context
->default_keytab_modify
;
298 if (strlcpy (name
, kt
, namesize
) >= namesize
) {
299 krb5_clear_error_message (context
);
300 return KRB5_CONFIG_NOTENUFSPACE
;
306 * Set `id' to the default keytab.
308 * @param context a Keberos context.
309 * @param id the new default keytab.
311 * @return Return an error code or 0, see krb5_get_error_message().
313 * @ingroup krb5_keytab
316 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
317 krb5_kt_default(krb5_context context
, krb5_keytab
*id
)
319 return krb5_kt_resolve (context
, context
->default_keytab
, id
);
323 * Read the key identified by `(principal, vno, enctype)' from the
324 * keytab in `keyprocarg' (the default if == NULL) into `*key'.
326 * @param context a Keberos context.
333 * @return Return an error code or 0, see krb5_get_error_message().
335 * @ingroup krb5_keytab
338 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
339 krb5_kt_read_service_key(krb5_context context
,
340 krb5_pointer keyprocarg
,
341 krb5_principal principal
,
343 krb5_enctype enctype
,
347 krb5_keytab_entry entry
;
351 ret
= krb5_kt_resolve (context
, keyprocarg
, &keytab
);
353 ret
= krb5_kt_default (context
, &keytab
);
358 ret
= krb5_kt_get_entry (context
, keytab
, principal
, vno
, enctype
, &entry
);
359 krb5_kt_close (context
, keytab
);
362 ret
= krb5_copy_keyblock (context
, &entry
.keyblock
, key
);
363 krb5_kt_free_entry(context
, &entry
);
368 * Return the type of the `keytab' in the string `prefix of length
371 * @param context a Keberos context.
372 * @param keytab the keytab to get the prefix for
373 * @param prefix prefix buffer
374 * @param prefixsize length of prefix buffer
376 * @return Return an error code or 0, see krb5_get_error_message().
378 * @ingroup krb5_keytab
381 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
382 krb5_kt_get_type(krb5_context context
,
387 strlcpy(prefix
, keytab
->prefix
, prefixsize
);
392 * Retrieve the name of the keytab `keytab' into `name', `namesize'
394 * @param context a Keberos context.
395 * @param keytab the keytab to get the name for.
396 * @param name name buffer.
397 * @param namesize size of name buffer.
399 * @return Return an error code or 0, see krb5_get_error_message().
401 * @ingroup krb5_keytab
404 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
405 krb5_kt_get_name(krb5_context context
,
410 return (*keytab
->get_name
)(context
, keytab
, name
, namesize
);
414 * Retrieve the full name of the keytab `keytab' and store the name in
417 * @param context a Keberos context.
418 * @param keytab keytab to get name for.
419 * @param str the name of the keytab name, usee krb5_xfree() to free
420 * the string. On error, *str is set to NULL.
422 * @return Return an error code or 0, see krb5_get_error_message().
424 * @ingroup krb5_keytab
427 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
428 krb5_kt_get_full_name(krb5_context context
,
432 char type
[KRB5_KT_PREFIX_MAX_LEN
];
433 char name
[MAXPATHLEN
];
438 ret
= krb5_kt_get_type(context
, keytab
, type
, sizeof(type
));
442 ret
= krb5_kt_get_name(context
, keytab
, name
, sizeof(name
));
446 if (asprintf(str
, "%s:%s", type
, name
) == -1) {
448 return krb5_enomem(context
);
455 * Finish using the keytab in `id'. All resources will be released,
458 * @param context a Keberos context.
459 * @param id keytab to close.
461 * @return Return an error code or 0, see krb5_get_error_message().
463 * @ingroup krb5_keytab
466 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
467 krb5_kt_close(krb5_context context
,
472 ret
= (*id
->close
)(context
, id
);
473 memset(id
, 0, sizeof(*id
));
479 * Destroy (remove) the keytab in `id'. All resources will be released,
480 * even on errors, does the equvalment of krb5_kt_close() on the resources.
482 * @param context a Keberos context.
483 * @param id keytab to destroy.
485 * @return Return an error code or 0, see krb5_get_error_message().
487 * @ingroup krb5_keytab
490 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
491 krb5_kt_destroy(krb5_context context
,
496 ret
= (*id
->destroy
)(context
, id
);
497 krb5_kt_close(context
, id
);
502 * Match any aliases in keytab `entry' with `principal'.
506 compare_aliseses(krb5_context context
,
507 krb5_keytab_entry
*entry
,
508 krb5_const_principal principal
)
511 if (entry
->aliases
== NULL
)
513 for (i
= 0; i
< entry
->aliases
->len
; i
++)
514 if (krb5_principal_compare(context
, &entry
->aliases
->val
[i
], principal
))
520 * Compare `entry' against `principal, vno, enctype'.
521 * Any of `principal, vno, enctype' might be 0 which acts as a wildcard.
522 * Return TRUE if they compare the same, FALSE otherwise.
524 * @param context a Keberos context.
525 * @param entry an entry to match with.
526 * @param principal principal to match, NULL matches all principals.
527 * @param vno key version to match, 0 matches all key version numbers.
528 * @param enctype encryption type to match, 0 matches all encryption types.
530 * @return Return TRUE or match, FALSE if not matched.
532 * @ingroup krb5_keytab
535 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
536 krb5_kt_compare(krb5_context context
,
537 krb5_keytab_entry
*entry
,
538 krb5_const_principal principal
,
540 krb5_enctype enctype
)
542 if(principal
!= NULL
&&
543 !(krb5_principal_compare(context
, entry
->principal
, principal
) ||
544 compare_aliseses(context
, entry
, principal
)))
546 if(vno
&& vno
!= entry
->vno
)
548 if(enctype
&& enctype
!= entry
->keyblock
.keytype
)
553 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
554 _krb5_kt_principal_not_found(krb5_context context
,
557 krb5_const_principal principal
,
558 krb5_enctype enctype
,
561 char princ
[256], kvno_str
[25], *kt_name
;
562 char *enctype_str
= NULL
;
564 krb5_unparse_name_fixed (context
, principal
, princ
, sizeof(princ
));
565 krb5_kt_get_full_name (context
, id
, &kt_name
);
567 krb5_enctype_to_string(context
, enctype
, &enctype_str
);
570 snprintf(kvno_str
, sizeof(kvno_str
), "(kvno %d)", kvno
);
574 krb5_set_error_message (context
, ret
,
575 N_("Failed to find %s%s in keytab %s (%s)",
576 "principal, kvno, keytab file, enctype"),
579 kt_name
? kt_name
: "unknown keytab",
580 enctype_str
? enctype_str
: "unknown enctype");
587 static krb5_error_code
588 krb5_kt_get_entry_wrapped(krb5_context context
,
590 krb5_const_principal principal
,
592 krb5_enctype enctype
,
593 krb5_keytab_entry
*entry
)
595 krb5_keytab_entry tmp
;
597 krb5_kt_cursor cursor
;
600 return (*id
->get
)(context
, id
, principal
, kvno
, enctype
, entry
);
602 ret
= krb5_kt_start_seq_get (context
, id
, &cursor
);
604 /* This is needed for krb5_verify_init_creds, but keep error
605 * string from previous error for the human. */
606 context
->error_code
= KRB5_KT_NOTFOUND
;
607 return KRB5_KT_NOTFOUND
;
611 while (krb5_kt_next_entry(context
, id
, &tmp
, &cursor
) == 0) {
612 if (krb5_kt_compare(context
, &tmp
, principal
, 0, enctype
)) {
613 /* the file keytab might only store the lower 8 bits of
614 the kvno, so only compare those bits */
616 || (tmp
.vno
< 256 && kvno
% 256 == tmp
.vno
)) {
617 krb5_kt_copy_entry_contents (context
, &tmp
, entry
);
618 krb5_kt_free_entry (context
, &tmp
);
619 krb5_kt_end_seq_get(context
, id
, &cursor
);
621 } else if (kvno
== 0 && tmp
.vno
> entry
->vno
) {
623 krb5_kt_free_entry (context
, entry
);
624 krb5_kt_copy_entry_contents (context
, &tmp
, entry
);
627 krb5_kt_free_entry(context
, &tmp
);
629 krb5_kt_end_seq_get (context
, id
, &cursor
);
631 return _krb5_kt_principal_not_found(context
, KRB5_KT_NOTFOUND
,
632 id
, principal
, enctype
, kvno
);
637 * Retrieve the keytab entry for `principal, kvno, enctype' into `entry'
638 * from the keytab `id'. Matching is done like krb5_kt_compare().
640 * @param context a Keberos context.
641 * @param id a keytab.
642 * @param principal principal to match, NULL matches all principals.
643 * @param kvno key version to match, 0 matches all key version numbers.
644 * @param enctype encryption type to match, 0 matches all encryption types.
645 * @param entry the returned entry, free with krb5_kt_free_entry().
647 * @return Return an error code or 0, see krb5_get_error_message().
649 * @ingroup krb5_keytab
652 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
653 krb5_kt_get_entry(krb5_context context
,
655 krb5_const_principal principal
,
657 krb5_enctype enctype
,
658 krb5_keytab_entry
*entry
)
661 krb5_principal try_princ
;
662 krb5_name_canon_iterator name_canon_iter
;
664 if (!principal
|| principal
->name
.name_type
!= KRB5_NT_SRV_HST_NEEDS_CANON
)
665 return krb5_kt_get_entry_wrapped(context
, id
, principal
, kvno
, enctype
,
668 ret
= krb5_name_canon_iterator_start(context
, principal
, NULL
,
674 ret
= krb5_name_canon_iterate_princ(context
, &name_canon_iter
,
678 ret
= krb5_kt_get_entry_wrapped(context
, id
, try_princ
, kvno
,
680 } while (ret
== KRB5_KT_NOTFOUND
&& name_canon_iter
);
682 if (ret
!= KRB5_KT_NOTFOUND
)
683 krb5_set_error_message(context
, ret
,
684 N_("Name canon failed while searching keytab",
686 krb5_free_name_canon_iterator(context
, name_canon_iter
);
691 * Copy the contents of `in' into `out'.
693 * @param context a Keberos context.
694 * @param in the keytab entry to copy.
695 * @param out the copy of the keytab entry, free with krb5_kt_free_entry().
697 * @return Return an error code or 0, see krb5_get_error_message().
699 * @ingroup krb5_keytab
702 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
703 krb5_kt_copy_entry_contents(krb5_context context
,
704 const krb5_keytab_entry
*in
,
705 krb5_keytab_entry
*out
)
709 memset(out
, 0, sizeof(*out
));
712 ret
= krb5_copy_principal (context
, in
->principal
, &out
->principal
);
715 ret
= krb5_copy_keyblock_contents (context
,
720 out
->timestamp
= in
->timestamp
;
723 krb5_kt_free_entry (context
, out
);
728 * Free the contents of `entry'.
730 * @param context a Keberos context.
731 * @param entry the entry to free
733 * @return Return an error code or 0, see krb5_get_error_message().
735 * @ingroup krb5_keytab
738 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
739 krb5_kt_free_entry(krb5_context context
,
740 krb5_keytab_entry
*entry
)
742 krb5_free_principal (context
, entry
->principal
);
743 krb5_free_keyblock_contents (context
, &entry
->keyblock
);
744 memset(entry
, 0, sizeof(*entry
));
749 * Set `cursor' to point at the beginning of `id'.
751 * @param context a Keberos context.
752 * @param id a keytab.
753 * @param cursor a newly allocated cursor, free with krb5_kt_end_seq_get().
755 * @return Return an error code or 0, see krb5_get_error_message().
757 * @ingroup krb5_keytab
760 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
761 krb5_kt_start_seq_get(krb5_context context
,
763 krb5_kt_cursor
*cursor
)
765 if(id
->start_seq_get
== NULL
) {
766 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
767 N_("start_seq_get is not supported "
768 "in the %s keytab type", ""),
770 return HEIM_ERR_OPNOTSUPP
;
772 return (*id
->start_seq_get
)(context
, id
, cursor
);
776 * Get the next entry from keytab, advance the cursor. On last entry
777 * the function will return KRB5_KT_END.
779 * @param context a Keberos context.
780 * @param id a keytab.
781 * @param entry the returned entry, free with krb5_kt_free_entry().
782 * @param cursor the cursor of the iteration.
784 * @return Return an error code or 0, see krb5_get_error_message().
786 * @ingroup krb5_keytab
789 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
790 krb5_kt_next_entry(krb5_context context
,
792 krb5_keytab_entry
*entry
,
793 krb5_kt_cursor
*cursor
)
795 if(id
->next_entry
== NULL
) {
796 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
797 N_("next_entry is not supported in the %s "
800 return HEIM_ERR_OPNOTSUPP
;
802 return (*id
->next_entry
)(context
, id
, entry
, cursor
);
806 * Release all resources associated with `cursor'.
808 * @param context a Keberos context.
809 * @param id a keytab.
810 * @param cursor the cursor to free.
812 * @return Return an error code or 0, see krb5_get_error_message().
814 * @ingroup krb5_keytab
817 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
818 krb5_kt_end_seq_get(krb5_context context
,
820 krb5_kt_cursor
*cursor
)
822 if(id
->end_seq_get
== NULL
) {
823 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
824 "end_seq_get is not supported in the %s "
825 " keytab", id
->prefix
);
826 return HEIM_ERR_OPNOTSUPP
;
828 return (*id
->end_seq_get
)(context
, id
, cursor
);
832 * Add the entry in `entry' to the keytab `id'.
834 * @param context a Keberos context.
835 * @param id a keytab.
836 * @param entry the entry to add
838 * @return Return an error code or 0, see krb5_get_error_message().
840 * @ingroup krb5_keytab
843 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
844 krb5_kt_add_entry(krb5_context context
,
846 krb5_keytab_entry
*entry
)
848 if(id
->add
== NULL
) {
849 krb5_set_error_message(context
, KRB5_KT_NOWRITE
,
850 N_("Add is not supported in the %s keytab", ""),
852 return KRB5_KT_NOWRITE
;
854 entry
->timestamp
= time(NULL
);
855 return (*id
->add
)(context
, id
,entry
);
859 * Remove an entry from the keytab, matching is done using
862 * @param context a Keberos context.
863 * @param id a keytab.
864 * @param entry the entry to remove
866 * @return Return an error code or 0, see krb5_get_error_message().
868 * @ingroup krb5_keytab
871 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
872 krb5_kt_remove_entry(krb5_context context
,
874 krb5_keytab_entry
*entry
)
876 if(id
->remove
== NULL
) {
877 krb5_set_error_message(context
, KRB5_KT_NOWRITE
,
878 N_("Remove is not supported in the %s keytab", ""),
880 return KRB5_KT_NOWRITE
;
882 return (*id
->remove
)(context
, id
, entry
);
886 * Return true if the keytab exists and have entries
888 * @param context a Keberos context.
889 * @param id a keytab.
891 * @return Return an error code or 0, see krb5_get_error_message().
893 * @ingroup krb5_keytab
896 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
897 krb5_kt_have_content(krb5_context context
,
900 krb5_keytab_entry entry
;
901 krb5_kt_cursor cursor
;
905 ret
= krb5_kt_start_seq_get(context
, id
, &cursor
);
909 ret
= krb5_kt_next_entry(context
, id
, &entry
, &cursor
);
910 krb5_kt_end_seq_get(context
, id
, &cursor
);
914 krb5_kt_free_entry(context
, &entry
);
919 ret
= krb5_kt_get_full_name(context
, id
, &name
);
921 krb5_set_error_message(context
, KRB5_KT_NOTFOUND
,
922 N_("No entry in keytab: %s", ""), name
);
925 return KRB5_KT_NOTFOUND
;