From c57ff0a9aae8e51de1de8671dc6c8d91a1f1af66 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Thu, 23 Jan 2014 14:39:24 +0100 Subject: [PATCH] CLDAP: generate NetBIOS name like ipa-adtrust-install does Fixes https://fedorahosted.org/freeipa/ticket/4116 --- daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h | 2 + .../ipa-cldap/ipa_cldap_netlogon.c | 47 +++++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h index 3f420ff2c5acc7bd75bff7f042f76b9c61144461..5e963e3f8557d468d646e6343366921d17242e2d 100644 --- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h +++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h @@ -51,6 +51,7 @@ #include #include #include +#include #include "util.h" #define IPA_CLDAP_PLUGIN_NAME "CLDAP Server" @@ -106,4 +107,5 @@ int ipa_cldap_netlogon(struct ipa_cldap_ctx *ctx, struct ipa_cldap_req *req, struct berval *reply); +char *make_netbios_name(TALLOC_CTX *mem_ctx, const char *s); #endif /* _IPA_CLDAP_H_ */ diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c index c03172d474589ddee84f1cfa5395c23fdba83bcb..1d16de7be09cf9675c2ee1a602ddfb800cd6e7af 100644 --- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c +++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c @@ -121,6 +121,38 @@ done: return ret; } +char *make_netbios_name(TALLOC_CTX *mem_ctx, const char *s) +{ + char *nb_name; + const char *p; + size_t c = 0; + + if (s == NULL) { + return NULL; + } + + nb_name = talloc_zero_size(mem_ctx, NETBIOS_NAME_MAX + 1); + if (nb_name == NULL) { + return NULL; + } + + for (p = s; *p && c < NETBIOS_NAME_MAX; p++) { + /* Create the NetBIOS name from the first segment of the hostname */ + if (*p == '.') { + break; + } else if (isalnum(*p)) { + nb_name[c++] = toupper(*p); + } + } + + if (*nb_name == '\0') { + talloc_free(nb_name); + return NULL; + } + + return nb_name; +} + #define NETLOGON_SAM_LOGON_RESPONSE_EX_pusher \ (ndr_push_flags_fn_t)ndr_push_NETLOGON_SAM_LOGON_RESPONSE_EX @@ -131,8 +163,6 @@ static int ipa_cldap_encode_netlogon(char *fq_hostname, char *domain, struct NETLOGON_SAM_LOGON_RESPONSE_EX *nlr; enum ndr_err_code ndr_err; DATA_BLOB blob; - char *pdc_name; - char *p; int ret; nlr = talloc_zero(NULL, struct NETLOGON_SAM_LOGON_RESPONSE_EX); @@ -162,18 +192,7 @@ static int ipa_cldap_encode_netlogon(char *fq_hostname, char *domain, nlr->pdc_dns_name = fq_hostname; nlr->domain_name = name; - /* copy the first 15 characters of the fully qualified hostname*/ - pdc_name = talloc_asprintf(nlr, "%.*s", NETBIOS_NAME_MAX, fq_hostname); - - for (p = pdc_name; *p; p++) { - /* Create the NetBIOS name from the first segment of the hostname */ - if (*p == '.') { - *p = '\0'; - break; - } - *p = toupper(*p); - } - nlr->pdc_name = pdc_name; + nlr->pdc_name = make_netbios_name(nlr, fq_hostname); nlr->user_name = ""; nlr->server_site = "Default-First-Site-Name"; nlr->client_site = "Default-First-Site-Name"; -- 1.8.3.1