summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h2
-rw-r--r--daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_netlogon.c47
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 3f420ff2c..5e963e3f8 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 c03172d47..1d16de7be 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";