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 * Default ktname from context with possible environment
249 static const char *default_ktname(krb5_context context
)
251 const char *tmp
= NULL
;
254 tmp
= getenv("KRB5_KTNAME");
257 return context
->default_keytab
;
261 * copy the name of the default keytab into `name'.
263 * @param context a Keberos context.
264 * @param name buffer where the name will be written
265 * @param namesize length of name
267 * @return Return an error code or 0, see krb5_get_error_message().
269 * @ingroup krb5_keytab
272 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
273 krb5_kt_default_name(krb5_context context
, char *name
, size_t namesize
)
275 if (strlcpy (name
, default_ktname(context
), namesize
) >= namesize
) {
276 krb5_clear_error_message (context
);
277 return KRB5_CONFIG_NOTENUFSPACE
;
283 * Copy the name of the default modify keytab into `name'.
285 * @param context a Keberos context.
286 * @param name buffer where the name will be written
287 * @param namesize length of name
289 * @return Return an error code or 0, see krb5_get_error_message().
291 * @ingroup krb5_keytab
294 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
295 krb5_kt_default_modify_name(krb5_context context
, char *name
, size_t namesize
)
299 if(context
->default_keytab_modify
== NULL
) {
300 kt
= default_ktname(context
);
302 if (strncasecmp(kt
, "ANY:", 4) == 0) {
303 size_t len
= strcspn(kt
+ 4, ",");
304 if (len
>= namesize
) {
305 krb5_clear_error_message(context
);
306 return KRB5_CONFIG_NOTENUFSPACE
;
308 strlcpy(name
, kt
+ 4, namesize
);
313 kt
= context
->default_keytab_modify
;
314 if (strlcpy (name
, kt
, namesize
) >= namesize
) {
315 krb5_clear_error_message (context
);
316 return KRB5_CONFIG_NOTENUFSPACE
;
322 * Set `id' to the default keytab.
324 * @param context a Keberos context.
325 * @param id the new default keytab.
327 * @return Return an error code or 0, see krb5_get_error_message().
329 * @ingroup krb5_keytab
332 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
333 krb5_kt_default(krb5_context context
, krb5_keytab
*id
)
335 return krb5_kt_resolve (context
, default_ktname(context
), id
);
339 * Read the key identified by `(principal, vno, enctype)' from the
340 * keytab in `keyprocarg' (the default if == NULL) into `*key'.
342 * @param context a Keberos context.
349 * @return Return an error code or 0, see krb5_get_error_message().
351 * @ingroup krb5_keytab
354 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
355 krb5_kt_read_service_key(krb5_context context
,
356 krb5_pointer keyprocarg
,
357 krb5_principal principal
,
359 krb5_enctype enctype
,
363 krb5_keytab_entry entry
;
367 ret
= krb5_kt_resolve (context
, keyprocarg
, &keytab
);
369 ret
= krb5_kt_default (context
, &keytab
);
374 ret
= krb5_kt_get_entry (context
, keytab
, principal
, vno
, enctype
, &entry
);
375 krb5_kt_close (context
, keytab
);
378 ret
= krb5_copy_keyblock (context
, &entry
.keyblock
, key
);
379 krb5_kt_free_entry(context
, &entry
);
384 * Return the type of the `keytab' in the string `prefix of length
387 * @param context a Keberos context.
388 * @param keytab the keytab to get the prefix for
389 * @param prefix prefix buffer
390 * @param prefixsize length of prefix buffer
392 * @return Return an error code or 0, see krb5_get_error_message().
394 * @ingroup krb5_keytab
397 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
398 krb5_kt_get_type(krb5_context context
,
403 strlcpy(prefix
, keytab
->prefix
, prefixsize
);
408 * Retrieve the name of the keytab `keytab' into `name', `namesize'
410 * @param context a Keberos context.
411 * @param keytab the keytab to get the name for.
412 * @param name name buffer.
413 * @param namesize size of name buffer.
415 * @return Return an error code or 0, see krb5_get_error_message().
417 * @ingroup krb5_keytab
420 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
421 krb5_kt_get_name(krb5_context context
,
426 return (*keytab
->get_name
)(context
, keytab
, name
, namesize
);
430 * Retrieve the full name of the keytab `keytab' and store the name in
433 * @param context a Keberos context.
434 * @param keytab keytab to get name for.
435 * @param str the name of the keytab name, usee krb5_xfree() to free
436 * the string. On error, *str is set to NULL.
438 * @return Return an error code or 0, see krb5_get_error_message().
440 * @ingroup krb5_keytab
443 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
444 krb5_kt_get_full_name(krb5_context context
,
448 char type
[KRB5_KT_PREFIX_MAX_LEN
];
449 char name
[MAXPATHLEN
];
454 ret
= krb5_kt_get_type(context
, keytab
, type
, sizeof(type
));
458 ret
= krb5_kt_get_name(context
, keytab
, name
, sizeof(name
));
462 if (asprintf(str
, "%s:%s", type
, name
) == -1) {
464 return krb5_enomem(context
);
471 * Finish using the keytab in `id'. All resources will be released,
474 * @param context a Keberos context.
475 * @param id keytab to close.
477 * @return Return an error code or 0, see krb5_get_error_message().
479 * @ingroup krb5_keytab
482 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
483 krb5_kt_close(krb5_context context
,
488 ret
= (*id
->close
)(context
, id
);
489 memset(id
, 0, sizeof(*id
));
495 * Destroy (remove) the keytab in `id'. All resources will be released,
496 * even on errors, does the equvalment of krb5_kt_close() on the resources.
498 * @param context a Keberos context.
499 * @param id keytab to destroy.
501 * @return Return an error code or 0, see krb5_get_error_message().
503 * @ingroup krb5_keytab
506 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
507 krb5_kt_destroy(krb5_context context
,
512 ret
= (*id
->destroy
)(context
, id
);
513 krb5_kt_close(context
, id
);
518 * Match any aliases in keytab `entry' with `principal'.
522 compare_aliases(krb5_context context
,
523 krb5_keytab_entry
*entry
,
524 krb5_const_principal principal
)
527 if (entry
->aliases
== NULL
)
529 for (i
= 0; i
< entry
->aliases
->len
; i
++)
530 if (krb5_principal_compare(context
, &entry
->aliases
->val
[i
], principal
))
536 * Compare `entry' against `principal, vno, enctype'.
537 * Any of `principal, vno, enctype' might be 0 which acts as a wildcard.
538 * Return TRUE if they compare the same, FALSE otherwise.
540 * @param context a Keberos context.
541 * @param entry an entry to match with.
542 * @param principal principal to match, NULL matches all principals.
543 * @param vno key version to match, 0 matches all key version numbers.
544 * @param enctype encryption type to match, 0 matches all encryption types.
546 * @return Return TRUE or match, FALSE if not matched.
548 * @ingroup krb5_keytab
551 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
552 krb5_kt_compare(krb5_context context
,
553 krb5_keytab_entry
*entry
,
554 krb5_const_principal principal
,
556 krb5_enctype enctype
)
558 /* krb5_principal_compare() does not special-case the referral realm */
559 if (principal
!= NULL
&& strcmp(principal
->realm
, "") == 0 &&
560 !(krb5_principal_compare_any_realm(context
, entry
->principal
, principal
) ||
561 compare_aliases(context
, entry
, principal
))) {
563 } else if (principal
!= NULL
&& strcmp(principal
->realm
, "") != 0 &&
564 !(krb5_principal_compare(context
, entry
->principal
, principal
) ||
565 compare_aliases(context
, entry
, principal
))) {
568 if (vno
&& vno
!= entry
->vno
)
570 if (enctype
&& enctype
!= entry
->keyblock
.keytype
)
575 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
576 _krb5_kt_principal_not_found(krb5_context context
,
579 krb5_const_principal principal
,
580 krb5_enctype enctype
,
583 char princ
[256], kvno_str
[25], *kt_name
;
584 char *enctype_str
= NULL
;
586 krb5_unparse_name_fixed (context
, principal
, princ
, sizeof(princ
));
587 krb5_kt_get_full_name (context
, id
, &kt_name
);
589 krb5_enctype_to_string(context
, enctype
, &enctype_str
);
592 snprintf(kvno_str
, sizeof(kvno_str
), "(kvno %d)", kvno
);
596 krb5_set_error_message (context
, ret
,
597 N_("Failed to find %s%s in keytab %s (%s)",
598 "principal, kvno, keytab file, enctype"),
601 kt_name
? kt_name
: "unknown keytab",
602 enctype_str
? enctype_str
: "unknown enctype");
609 static krb5_error_code
610 krb5_kt_get_entry_wrapped(krb5_context context
,
612 krb5_const_principal principal
,
614 krb5_enctype enctype
,
615 krb5_keytab_entry
*entry
)
617 krb5_keytab_entry tmp
;
619 krb5_kt_cursor cursor
;
622 return (*id
->get
)(context
, id
, principal
, kvno
, enctype
, entry
);
624 ret
= krb5_kt_start_seq_get (context
, id
, &cursor
);
626 /* This is needed for krb5_verify_init_creds, but keep error
627 * string from previous error for the human. */
628 context
->error_code
= KRB5_KT_NOTFOUND
;
629 return KRB5_KT_NOTFOUND
;
633 while (krb5_kt_next_entry(context
, id
, &tmp
, &cursor
) == 0) {
634 if (krb5_kt_compare(context
, &tmp
, principal
, 0, enctype
)) {
635 /* the file keytab might only store the lower 8 bits of
636 the kvno, so only compare those bits */
638 || (tmp
.vno
< 256 && kvno
% 256 == tmp
.vno
)) {
639 krb5_kt_copy_entry_contents (context
, &tmp
, entry
);
640 krb5_kt_free_entry (context
, &tmp
);
641 krb5_kt_end_seq_get(context
, id
, &cursor
);
643 } else if (kvno
== 0 && tmp
.vno
> entry
->vno
) {
645 krb5_kt_free_entry (context
, entry
);
646 krb5_kt_copy_entry_contents (context
, &tmp
, entry
);
649 krb5_kt_free_entry(context
, &tmp
);
651 krb5_kt_end_seq_get (context
, id
, &cursor
);
653 return _krb5_kt_principal_not_found(context
, KRB5_KT_NOTFOUND
,
654 id
, principal
, enctype
, kvno
);
659 * Retrieve the keytab entry for `principal, kvno, enctype' into `entry'
660 * from the keytab `id'. Matching is done like krb5_kt_compare().
662 * @param context a Keberos context.
663 * @param id a keytab.
664 * @param principal principal to match, NULL matches all principals.
665 * @param kvno key version to match, 0 matches all key version numbers.
666 * @param enctype encryption type to match, 0 matches all encryption types.
667 * @param entry the returned entry, free with krb5_kt_free_entry().
669 * @return Return an error code or 0, see krb5_get_error_message().
671 * @ingroup krb5_keytab
674 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
675 krb5_kt_get_entry(krb5_context context
,
677 krb5_const_principal principal
,
679 krb5_enctype enctype
,
680 krb5_keytab_entry
*entry
)
683 krb5_const_principal try_princ
;
684 krb5_name_canon_iterator name_canon_iter
;
687 return krb5_kt_get_entry_wrapped(context
, id
, principal
, kvno
, enctype
,
690 ret
= krb5_name_canon_iterator_start(context
, principal
, &name_canon_iter
);
695 ret
= krb5_name_canon_iterate(context
, &name_canon_iter
, &try_princ
,
699 if (try_princ
== NULL
) {
700 ret
= KRB5_KT_NOTFOUND
;
703 ret
= krb5_kt_get_entry_wrapped(context
, id
, try_princ
, kvno
,
705 } while (ret
== KRB5_KT_NOTFOUND
&& name_canon_iter
);
707 if (ret
!= KRB5_KT_NOTFOUND
)
708 krb5_set_error_message(context
, ret
,
709 N_("Name canon failed while searching keytab",
711 krb5_free_name_canon_iterator(context
, name_canon_iter
);
716 * Copy the contents of `in' into `out'.
718 * @param context a Keberos context.
719 * @param in the keytab entry to copy.
720 * @param out the copy of the keytab entry, free with krb5_kt_free_entry().
722 * @return Return an error code or 0, see krb5_get_error_message().
724 * @ingroup krb5_keytab
727 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
728 krb5_kt_copy_entry_contents(krb5_context context
,
729 const krb5_keytab_entry
*in
,
730 krb5_keytab_entry
*out
)
734 memset(out
, 0, sizeof(*out
));
737 ret
= krb5_copy_principal (context
, in
->principal
, &out
->principal
);
740 ret
= krb5_copy_keyblock_contents (context
,
745 out
->timestamp
= in
->timestamp
;
748 krb5_kt_free_entry (context
, out
);
753 * Free the contents of `entry'.
755 * @param context a Keberos context.
756 * @param entry the entry to free
758 * @return Return an error code or 0, see krb5_get_error_message().
760 * @ingroup krb5_keytab
763 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
764 krb5_kt_free_entry(krb5_context context
,
765 krb5_keytab_entry
*entry
)
767 krb5_free_principal (context
, entry
->principal
);
768 krb5_free_keyblock_contents (context
, &entry
->keyblock
);
769 memset(entry
, 0, sizeof(*entry
));
774 * Set `cursor' to point at the beginning of `id'.
776 * @param context a Keberos context.
777 * @param id a keytab.
778 * @param cursor a newly allocated cursor, free with krb5_kt_end_seq_get().
780 * @return Return an error code or 0, see krb5_get_error_message().
782 * @ingroup krb5_keytab
785 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
786 krb5_kt_start_seq_get(krb5_context context
,
788 krb5_kt_cursor
*cursor
)
790 if(id
->start_seq_get
== NULL
) {
791 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
792 N_("start_seq_get is not supported "
793 "in the %s keytab type", ""),
795 return HEIM_ERR_OPNOTSUPP
;
797 return (*id
->start_seq_get
)(context
, id
, cursor
);
801 * Get the next entry from keytab, advance the cursor. On last entry
802 * the function will return KRB5_KT_END.
804 * @param context a Keberos context.
805 * @param id a keytab.
806 * @param entry the returned entry, free with krb5_kt_free_entry().
807 * @param cursor the cursor of the iteration.
809 * @return Return an error code or 0, see krb5_get_error_message().
811 * @ingroup krb5_keytab
814 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
815 krb5_kt_next_entry(krb5_context context
,
817 krb5_keytab_entry
*entry
,
818 krb5_kt_cursor
*cursor
)
820 if(id
->next_entry
== NULL
) {
821 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
822 N_("next_entry is not supported in the %s "
825 return HEIM_ERR_OPNOTSUPP
;
827 return (*id
->next_entry
)(context
, id
, entry
, cursor
);
831 * Release all resources associated with `cursor'.
833 * @param context a Keberos context.
834 * @param id a keytab.
835 * @param cursor the cursor to free.
837 * @return Return an error code or 0, see krb5_get_error_message().
839 * @ingroup krb5_keytab
842 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
843 krb5_kt_end_seq_get(krb5_context context
,
845 krb5_kt_cursor
*cursor
)
847 if(id
->end_seq_get
== NULL
) {
848 krb5_set_error_message(context
, HEIM_ERR_OPNOTSUPP
,
849 "end_seq_get is not supported in the %s "
850 " keytab", id
->prefix
);
851 return HEIM_ERR_OPNOTSUPP
;
853 return (*id
->end_seq_get
)(context
, id
, cursor
);
857 * Add the entry in `entry' to the keytab `id'.
859 * @param context a Keberos context.
860 * @param id a keytab.
861 * @param entry the entry to add
863 * @return Return an error code or 0, see krb5_get_error_message().
865 * @ingroup krb5_keytab
868 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
869 krb5_kt_add_entry(krb5_context context
,
871 krb5_keytab_entry
*entry
)
873 if(id
->add
== NULL
) {
874 krb5_set_error_message(context
, KRB5_KT_NOWRITE
,
875 N_("Add is not supported in the %s keytab", ""),
877 return KRB5_KT_NOWRITE
;
879 entry
->timestamp
= time(NULL
);
880 return (*id
->add
)(context
, id
,entry
);
884 * Remove an entry from the keytab, matching is done using
887 * @param context a Keberos context.
888 * @param id a keytab.
889 * @param entry the entry to remove
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_remove_entry(krb5_context context
,
899 krb5_keytab_entry
*entry
)
901 if(id
->remove
== NULL
) {
902 krb5_set_error_message(context
, KRB5_KT_NOWRITE
,
903 N_("Remove is not supported in the %s keytab", ""),
905 return KRB5_KT_NOWRITE
;
907 return (*id
->remove
)(context
, id
, entry
);
911 * Return true if the keytab exists and have entries
913 * @param context a Keberos context.
914 * @param id a keytab.
916 * @return Return an error code or 0, see krb5_get_error_message().
918 * @ingroup krb5_keytab
921 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
922 krb5_kt_have_content(krb5_context context
,
925 krb5_keytab_entry entry
;
926 krb5_kt_cursor cursor
;
930 ret
= krb5_kt_start_seq_get(context
, id
, &cursor
);
934 ret
= krb5_kt_next_entry(context
, id
, &entry
, &cursor
);
935 krb5_kt_end_seq_get(context
, id
, &cursor
);
939 krb5_kt_free_entry(context
, &entry
);
944 ret
= krb5_kt_get_full_name(context
, id
, &name
);
946 krb5_set_error_message(context
, KRB5_KT_NOTFOUND
,
947 N_("No entry in keytab: %s", ""), name
);
950 return KRB5_KT_NOTFOUND
;