diff options
author | bubulle <bubulle@alioth.debian.org> | 2010-04-04 16:44:16 +0000 |
---|---|---|
committer | bubulle <bubulle@alioth.debian.org> | 2010-04-04 16:44:16 +0000 |
commit | 9e2f5a6ab663f7a111832217c527508c75ddae8a (patch) | |
tree | 2e74616febbb3fb658ce2dcc5f9cff00ad4fdb4a /source3/libads/kerberos.c | |
parent | b5556af8f75a4f74db404dd43ee7abafa2be6ca4 (diff) | |
download | samba-9e2f5a6ab663f7a111832217c527508c75ddae8a.tar.gz |
Merge 3.5.1 from experimental
git-svn-id: svn://svn.debian.org/svn/pkg-samba/trunk/samba@3414 fc4039ab-9d04-0410-8cac-899223bdd6b0
Diffstat (limited to 'source3/libads/kerberos.c')
-rw-r--r-- | source3/libads/kerberos.c | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/source3/libads/kerberos.c b/source3/libads/kerberos.c index f5f7f3d2e6..7fb4ec33e4 100644 --- a/source3/libads/kerberos.c +++ b/source3/libads/kerberos.c @@ -47,9 +47,9 @@ kerb_prompter(krb5_context ctx, void *data, memset(prompts[0].reply->data, '\0', prompts[0].reply->length); if (prompts[0].reply->length > 0) { if (data) { - strncpy(prompts[0].reply->data, (const char *)data, + strncpy((char *)prompts[0].reply->data, (const char *)data, prompts[0].reply->length-1); - prompts[0].reply->length = strlen(prompts[0].reply->data); + prompts[0].reply->length = strlen((const char *)prompts[0].reply->data); } else { prompts[0].reply->length = 0; } @@ -525,6 +525,58 @@ char *kerberos_get_default_realm_from_ccache( void ) return realm; } +/************************************************************************ + Routine to get the realm from a given DNS name. Returns malloc'ed memory. + Caller must free() if the return value is not NULL. +************************************************************************/ + +char *kerberos_get_realm_from_hostname(const char *hostname) +{ +#if defined(HAVE_KRB5_GET_HOST_REALM) && defined(HAVE_KRB5_FREE_HOST_REALM) +#if defined(HAVE_KRB5_REALM_TYPE) + /* Heimdal. */ + krb5_realm *realm_list = NULL; +#else + /* MIT */ + char **realm_list = NULL; +#endif + char *realm = NULL; + krb5_error_code kerr; + krb5_context ctx = NULL; + + initialize_krb5_error_table(); + if (krb5_init_context(&ctx)) { + return NULL; + } + + kerr = krb5_get_host_realm(ctx, hostname, &realm_list); + if (kerr != 0) { + DEBUG(3,("kerberos_get_realm_from_hostname %s: " + "failed %s\n", + hostname ? hostname : "(NULL)", + error_message(kerr) )); + goto out; + } + + if (realm_list && realm_list[0]) { + realm = SMB_STRDUP(realm_list[0]); + } + + out: + + if (ctx) { + if (realm_list) { + krb5_free_host_realm(ctx, realm_list); + realm_list = NULL; + } + krb5_free_context(ctx); + ctx = NULL; + } + return realm; +#else + return NULL; +#endif +} /************************************************************************ Routine to get the salting principal for this service. This is @@ -818,7 +870,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm, const char *sitename, struct sockaddr_storage *pss) { - char *dname = lock_path("smb_krb5"); + char *dname; char *tmpname = NULL; char *fname = NULL; char *file_contents = NULL; @@ -829,6 +881,11 @@ bool create_local_private_krb5_conf_for_domain(const char *realm, char *realm_upper = NULL; bool result = false; + if (!lp_create_krb5_conf()) { + return false; + } + + dname = lock_path("smb_krb5"); if (!dname) { return false; } @@ -875,7 +932,7 @@ bool create_local_private_krb5_conf_for_domain(const char *realm, flen = strlen(file_contents); - fd = smb_mkstemp(tmpname); + fd = mkstemp(tmpname); if (fd == -1) { DEBUG(0,("create_local_private_krb5_conf_for_domain: smb_mkstemp failed," " for file %s. Errno %s\n", |