diff options
author | Stefan Metzmacher <metze@samba.org> | 2011-07-15 09:10:30 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2011-07-15 11:15:05 +0200 |
commit | 255e3e18e00f717d99f3bc57c8a8895ff624f3c3 (patch) | |
tree | a2933c88f38e8dd7fe612be8dd458d05918b1f15 /source4/heimdal/lib/krb5/keytab.c | |
parent | 70da27838bb3f6ed9c36add06ce0ccdf467ab1c3 (diff) | |
download | samba-255e3e18e00f717d99f3bc57c8a8895ff624f3c3.tar.gz samba-255e3e18e00f717d99f3bc57c8a8895ff624f3c3.tar.bz2 samba-255e3e18e00f717d99f3bc57c8a8895ff624f3c3.zip |
s4:heimdal: import lorikeet-heimdal-201107150856 (commit 48936803fae4a2fb362c79365d31f420c917b85b)
Diffstat (limited to 'source4/heimdal/lib/krb5/keytab.c')
-rw-r--r-- | source4/heimdal/lib/krb5/keytab.c | 73 |
1 files changed, 57 insertions, 16 deletions
diff --git a/source4/heimdal/lib/krb5/keytab.c b/source4/heimdal/lib/krb5/keytab.c index 96c0bce273..8ca515f213 100644 --- a/source4/heimdal/lib/krb5/keytab.c +++ b/source4/heimdal/lib/krb5/keytab.c @@ -50,7 +50,7 @@ * * A keytab name is on the form type:residual. The residual part is * specific to each keytab-type. - * + * * When a keytab-name is resolved, the type is matched with an internal * list of keytab types. If there is no matching keytab type, * the default keytab is used. The current default type is FILE. @@ -60,7 +60,7 @@ * [defaults]default_keytab_name. * * The keytab types that are implemented in Heimdal are: - * - file + * - file * store the keytab in a file, the type's name is FILE . The * residual part is a filename. For compatibility with other * Kerberos implemtation WRFILE and JAVA14 is also accepted. WRFILE @@ -166,29 +166,27 @@ krb5_kt_register(krb5_context context, } static const char * -keytab_name(const char * name, const char ** ptype, size_t * ptype_len) +keytab_name(const char *name, const char **type, size_t *type_len) { - const char * residual; + const char *residual; residual = strchr(name, ':'); - if (residual == NULL - + if (residual == NULL || + name[0] == '/' #ifdef _WIN32 - /* Avoid treating <drive>:<path> as a keytab type * specification */ - || name + 1 == residual #endif ) { - *ptype = "FILE"; - *ptype_len = strlen(*ptype); + *type = "FILE"; + *type_len = strlen(*type); residual = name; } else { - *ptype = name; - *ptype_len = residual - name; + *type = name; + *type_len = residual - name; residual++; } @@ -439,7 +437,7 @@ krb5_kt_get_full_name(krb5_context context, char type[KRB5_KT_PREFIX_MAX_LEN]; char name[MAXPATHLEN]; krb5_error_code ret; - + *str = NULL; ret = krb5_kt_get_type(context, keytab, type, sizeof(type)); @@ -568,16 +566,16 @@ _krb5_kt_principal_not_found(krb5_context context, { char princ[256], kvno_str[25], *kt_name; char *enctype_str = NULL; - + krb5_unparse_name_fixed (context, principal, princ, sizeof(princ)); krb5_kt_get_full_name (context, id, &kt_name); krb5_enctype_to_string(context, enctype, &enctype_str); - + if (kvno) snprintf(kvno_str, sizeof(kvno_str), "(kvno %d)", kvno); else kvno_str[0] = '\0'; - + krb5_set_error_message (context, ret, N_("Failed to find %s%s in keytab %s (%s)", "principal, kvno, keytab file, enctype"), @@ -850,3 +848,46 @@ krb5_kt_remove_entry(krb5_context context, } return (*id->remove)(context, id, entry); } + +/** + * Return true if the keytab exists and have entries + * + * @param context a Keberos context. + * @param id a keytab. + * + * @return Return an error code or 0, see krb5_get_error_message(). + * + * @ingroup krb5_keytab + */ + +KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL +krb5_kt_have_content(krb5_context context, + krb5_keytab id) +{ + krb5_keytab_entry entry; + krb5_kt_cursor cursor; + krb5_error_code ret; + char *name; + + ret = krb5_kt_start_seq_get(context, id, &cursor); + if (ret) + goto notfound; + + ret = krb5_kt_next_entry(context, id, &entry, &cursor); + krb5_kt_end_seq_get(context, id, &cursor); + if (ret) + goto notfound; + + krb5_kt_free_entry(context, &entry); + + return 0; + + notfound: + ret = krb5_kt_get_full_name(context, id, &name); + if (ret == 0) { + krb5_set_error_message(context, KRB5_KT_NOTFOUND, + N_("No entry in keytab: %s", ""), name); + free(name); + } + return KRB5_KT_NOTFOUND; +} |