[Freeipa-devel] [PATCH] 126 CLDAP: generate NetBIOS name like ipa-adtrust-install does
Sumit Bose
sbose at redhat.com
Thu Jan 23 14:09:03 UTC 2014
On Thu, Jan 23, 2014 at 03:07:05PM +0200, Alexander Bokovoy wrote:
> On Thu, 23 Jan 2014, Sumit Bose wrote:
> >Hi,
> >
> >here is another one for the CLDAP NetBIOS name issue.
>
> ACK but could you please split the patch into two:
> - adding make_netbios_name() and using it
> - CMocka test for make_netbios_name()
> ?
sure, new version attached.
bye,
Sumit
>
> --
> / Alexander Bokovoy
-------------- next part --------------
From 6e2d4d3cfa77b3bd4ce08024b7251d51d6caed6c Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 23 Jan 2014 14:39:24 +0100
Subject: [PATCH 126/127] 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 <stdlib.h>
#include <pthread.h>
#include <dirsrv/slapi-plugin.h>
+#include <talloc.h>
#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.1.4
-------------- next part --------------
From ab9d06b87f81187c6f6fcd3da941791f166d33fc Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Thu, 23 Jan 2014 14:44:08 +0100
Subject: [PATCH 127/127] CLDAP: add unit tests for make_netbios_name
---
daemons/ipa-slapi-plugins/ipa-cldap/Makefile.am | 19 ++++++
.../ipa-slapi-plugins/ipa-cldap/ipa_cldap_tests.c | 68 ++++++++++++++++++++++
2 files changed, 87 insertions(+)
create mode 100644 daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_tests.c
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/Makefile.am b/daemons/ipa-slapi-plugins/ipa-cldap/Makefile.am
index 70b08835e5629026c80c21c83e0c749a387b73a4..8e35cdbd4499582dd0e14562f05e4eda5bb3ec5b 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/Makefile.am
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/Makefile.am
@@ -35,6 +35,25 @@ libipa_cldap_la_LIBADD = \
$(NDRNBT_LIBS) \
$(NULL)
+if HAVE_CMOCKA
+TESTS = ipa_cldap_tests
+check_PROGRAMS = ipa_cldap_tests
+endif
+
+ipa_cldap_tests_SOURCES = \
+ ipa_cldap_tests.c \
+ ipa_cldap_netlogon.c \
+ $(NULL)
+ipa_cldap_tests_CFLAGS = $(CMOCKA_FLAGS)
+ipa_cldap_tests_LDFLAGS = \
+ -rpath $(shell pkg-config --libs-only-L dirsrv | sed -e 's/-L//') \
+ $(NULL)
+ipa_cldap_tests_LDADD = \
+ $(CMOCKA_LIBS) \
+ $(NDRNBT_LIBS) \
+ $(DIRSRV_LIBS) \
+ $(NULL)
+
appdir = $(IPA_DATA_DIR)
app_DATA = \
ipa-cldap-conf.ldif \
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_tests.c b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_tests.c
new file mode 100644
index 0000000000000000000000000000000000000000..8f579cb0c051551471a55273c4bce97717200ffd
--- /dev/null
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_tests.c
@@ -0,0 +1,68 @@
+/*
+ Authors:
+ Sumit Bose <sbose at redhat.com>
+
+ Copyright (C) 2014 Red Hat
+
+ Tests for FreeIPA CLDAP plugin
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include "ipa_cldap.h"
+
+void test_make_netbios_name(void **state)
+{
+ char *r;
+ size_t c;
+
+ struct test_data {
+ char *i;
+ char *o;
+ } d[] = {
+ {"abc", "ABC"},
+ {"long-host-name-12345", "LONGHOSTNAME123"},
+ {"abc.def.123", "ABC"},
+ {"####", NULL},
+ {NULL, NULL}
+ };
+
+ r = make_netbios_name(NULL, NULL);
+ assert_null(r);
+
+ for (c = 0; d[c].i != NULL; c++) {
+ r = make_netbios_name(NULL, d[c].i);
+ if (d[c].o != NULL) {
+ assert_string_equal(r, d[c].o);
+ } else {
+ assert_null(r);
+ }
+ }
+}
+
+int main(int argc, const char *argv[])
+{
+
+ const UnitTest tests[] = {
+ unit_test(test_make_netbios_name),
+ };
+
+ return run_tests(tests);
+}
+
--
1.8.1.4
More information about the Freeipa-devel
mailing list