On 11/27/2013 03:38 PM, Simo Sorce wrote:
On Wed, 2013-11-27 at 08:50 +0100, Tomas Babej wrote:
Sorry to nitpick but ...

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
7d29fe559be55607fcb6b83fa521372e5197b848..f2e74e2c5b6e0d04dd3dc0eb15f25593aa91da8e
 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
@@ -161,9 +161,13 @@ static int ipa_cldap_encode_netlogon(char
*fq_hostname, char *domain,
      nlr->dns_domain = domain;
      nlr->pdc_dns_name = fq_hostname;
      nlr->domain_name = name;
-    pdc_name = talloc_asprintf(nlr, "\\\\%s", fq_hostname);
+
+    /* copy the first 15 characters of the fully qualified hostname*/
+    pdc_name = talloc_asprintf(nlr, "\\\\%.*s", 15, fq_hostname);
Probably better to #define NETBIOS_NAME_MAX 15 somewhere above and then
use the macro here.

+
      for (p = pdc_name; *p; p++) {
-        if (*p == '.') {
+        /* Create the NetBIOS name from the first segment of the
hostname */
+        if ((*p == '.') || (*p == '\0')) {
The second check is redundant, you'll never get there, the for loop will
bail earlier. I think you only need to add the comment here and not
touch the code as the asprintf above took care of properly terminating
the name at the 15 chars mark already.

              *p = '\0';
              break;
          }
Simo.


Thanks for the catches.

Updated patch attached.

--
Tomas Babej
Associate Software Engeneer | Red Hat | Identity Management
RHCE | Brno Site | IRC: tbabej | freeipa.org

From c97a6fc38466a71b1717e3b89b405986645de6f6 Mon Sep 17 00:00:00 2001
From: Tomas Babej <tba...@redhat.com>
Date: Tue, 26 Nov 2013 12:14:39 +0100
Subject: [PATCH] ipa-cldap: Cut NetBIOS name after 15 characters

The CLDAP DS plugin uses the uppercased first segment of the fully
qualified hostname as the NetBIOS name. We need to limit its size
to 15 characters.

https://fedorahosted.org/freeipa/ticket/4028
---
 daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h          | 1 +
 daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c | 6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
index 7b0c2aad1991f5f5958db62844f5777f71534794..3f420ff2c5acc7bd75bff7f042f76b9c61144461 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
@@ -59,6 +59,7 @@
 #define IPA_PLUGIN_NAME IPA_CLDAP_PLUGIN_NAME
 #define CLDAP_PORT 389
 #define MAX_DG_SIZE 4096
+#define NETBIOS_NAME_MAX 15
 
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN 64
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 7d29fe559be55607fcb6b83fa521372e5197b848..9ba05829418a0d1de46f2c7776cc15c54a9eab1c 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c
@@ -161,8 +161,12 @@ static int ipa_cldap_encode_netlogon(char *fq_hostname, char *domain,
     nlr->dns_domain = domain;
     nlr->pdc_dns_name = fq_hostname;
     nlr->domain_name = name;
-    pdc_name = talloc_asprintf(nlr, "\\\\%s", fq_hostname);
+
+    /* 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;
-- 
1.8.3.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to