|
|
8e731f |
From 3db35ad73ec57c8af499a0dcef96ffd4da914236 Mon Sep 17 00:00:00 2001
|
|
|
8e731f |
From: Stef Walter <stefw@redhat.com>
|
|
|
8e731f |
Date: Mon, 7 Sep 2015 13:49:10 +0200
|
|
|
8e731f |
Subject: [PATCH 2/2] service: Fully qualify --computer-ou DN before passing to
|
|
|
8e731f |
adcli
|
|
|
8e731f |
|
|
|
8e731f |
This allows us to have a similar behavior for both the Samba and
|
|
|
8e731f |
adcli membership software.
|
|
|
8e731f |
---
|
|
|
8e731f |
service/Makefile.am | 4 +-
|
|
|
8e731f |
service/realm-adcli-enroll.c | 11 +-
|
|
|
8e731f |
service/realm-dn-util.c | 239 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
8e731f |
service/realm-dn-util.h | 32 ++++++
|
|
|
8e731f |
service/realm-samba-enroll.c | 4 +-
|
|
|
8e731f |
service/realm-samba-util.c | 172 -------------------------------
|
|
|
8e731f |
service/realm-samba-util.h | 29 ------
|
|
|
8e731f |
tests/Makefile.am | 16 +--
|
|
|
8e731f |
tests/test-dn-util.c | 129 +++++++++++++++++++++++
|
|
|
8e731f |
tests/test-samba-ou-format.c | 89 ----------------
|
|
|
8e731f |
11 files changed, 422 insertions(+), 305 deletions(-)
|
|
|
8e731f |
create mode 100644 service/realm-dn-util.c
|
|
|
8e731f |
create mode 100644 service/realm-dn-util.h
|
|
|
8e731f |
delete mode 100644 service/realm-samba-util.c
|
|
|
8e731f |
delete mode 100644 service/realm-samba-util.h
|
|
|
8e731f |
create mode 100644 tests/test-dn-util.c
|
|
|
8e731f |
delete mode 100644 tests/test-samba-ou-format.c
|
|
|
8e731f |
|
|
|
8e731f |
diff --git a/service/Makefile.am b/service/Makefile.am
|
|
|
8e731f |
index 06a95ef..88ee780 100644
|
|
|
8e731f |
--- a/service/Makefile.am
|
|
|
8e731f |
+++ b/service/Makefile.am
|
|
|
8e731f |
@@ -43,6 +43,8 @@ realmd_SOURCES = \
|
|
|
8e731f |
service/realm-disco-mscldap.h \
|
|
|
8e731f |
service/realm-disco-rootdse.c \
|
|
|
8e731f |
service/realm-disco-rootdse.h \
|
|
|
8e731f |
+ service/realm-dn-util.c \
|
|
|
8e731f |
+ service/realm-dn-util.h \
|
|
|
8e731f |
service/realm-errors.c \
|
|
|
8e731f |
service/realm-errors.h \
|
|
|
8e731f |
service/realm-example.c \
|
|
|
8e731f |
@@ -79,8 +81,6 @@ realmd_SOURCES = \
|
|
|
8e731f |
service/realm-samba-enroll.h \
|
|
|
8e731f |
service/realm-samba-provider.c \
|
|
|
8e731f |
service/realm-samba-provider.h \
|
|
|
8e731f |
- service/realm-samba-util.c \
|
|
|
8e731f |
- service/realm-samba-util.h \
|
|
|
8e731f |
service/realm-samba-winbind.c \
|
|
|
8e731f |
service/realm-samba-winbind.h \
|
|
|
8e731f |
service/realm-service.c \
|
|
|
8e731f |
diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
|
|
|
8e731f |
index 7448647..ef1b563 100644
|
|
|
8e731f |
--- a/service/realm-adcli-enroll.c
|
|
|
8e731f |
+++ b/service/realm-adcli-enroll.c
|
|
|
8e731f |
@@ -18,6 +18,7 @@
|
|
|
8e731f |
#include "realm-command.h"
|
|
|
8e731f |
#include "realm-daemon.h"
|
|
|
8e731f |
#include "realm-diagnostics.h"
|
|
|
8e731f |
+#include "realm-dn-util.h"
|
|
|
8e731f |
#include "realm-errors.h"
|
|
|
8e731f |
#include "realm-ini-config.h"
|
|
|
8e731f |
#include "realm-options.h"
|
|
|
8e731f |
@@ -82,6 +83,7 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
|
|
|
8e731f |
gchar *ccache_arg = NULL;
|
|
|
8e731f |
gchar *upn_arg = NULL;
|
|
|
8e731f |
gchar *server_arg = NULL;
|
|
|
8e731f |
+ gchar *ou_arg = NULL;
|
|
|
8e731f |
|
|
|
8e731f |
g_return_if_fail (cred != NULL);
|
|
|
8e731f |
g_return_if_fail (disco != NULL);
|
|
|
8e731f |
@@ -120,9 +122,13 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
|
|
|
8e731f |
}
|
|
|
8e731f |
|
|
|
8e731f |
computer_ou = realm_options_computer_ou (options, disco->domain_name);
|
|
|
8e731f |
- if (computer_ou) {
|
|
|
8e731f |
+ if (computer_ou != NULL) {
|
|
|
8e731f |
+ ou_arg = realm_dn_util_build_qualified (computer_ou, disco->domain_name);
|
|
|
8e731f |
g_ptr_array_add (args, "--computer-ou");
|
|
|
8e731f |
- g_ptr_array_add (args, (gpointer)computer_ou);
|
|
|
8e731f |
+ if (ou_arg)
|
|
|
8e731f |
+ g_ptr_array_add (args, ou_arg);
|
|
|
8e731f |
+ else
|
|
|
8e731f |
+ g_ptr_array_add (args, (gpointer)computer_ou);
|
|
|
8e731f |
}
|
|
|
8e731f |
|
|
|
8e731f |
os = realm_settings_value ("active-directory", "os-name");
|
|
|
8e731f |
@@ -190,6 +196,7 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
|
|
|
8e731f |
free (ccache_arg);
|
|
|
8e731f |
free (upn_arg);
|
|
|
8e731f |
free (server_arg);
|
|
|
8e731f |
+ free (ou_arg);
|
|
|
8e731f |
}
|
|
|
8e731f |
|
|
|
8e731f |
gboolean
|
|
|
8e731f |
diff --git a/service/realm-dn-util.c b/service/realm-dn-util.c
|
|
|
8e731f |
new file mode 100644
|
|
|
8e731f |
index 0000000..85bcdb9
|
|
|
8e731f |
--- /dev/null
|
|
|
8e731f |
+++ b/service/realm-dn-util.c
|
|
|
8e731f |
@@ -0,0 +1,239 @@
|
|
|
8e731f |
+/* realmd -- Realm configuration service
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
+ * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
+ * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
+ * your option) any later version.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * See the included COPYING file for more information.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include "config.h"
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include "realm-dn-util.h"
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include <glib.h>
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include <ldap.h>
|
|
|
8e731f |
+
|
|
|
8e731f |
+static gboolean
|
|
|
8e731f |
+berval_is_string (const struct berval *bv,
|
|
|
8e731f |
+ const gchar *string,
|
|
|
8e731f |
+ gsize length)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ return (bv->bv_len == length &&
|
|
|
8e731f |
+ g_ascii_strncasecmp (bv->bv_val, string, length) == 0);
|
|
|
8e731f |
+
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+static gboolean
|
|
|
8e731f |
+berval_case_equals (const struct berval *v1,
|
|
|
8e731f |
+ const struct berval *v2)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ return (v1->bv_len == v2->bv_len &&
|
|
|
8e731f |
+ g_ascii_strncasecmp (v1->bv_val, v2->bv_val, v1->bv_len) == 0);
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+static gboolean
|
|
|
8e731f |
+dn_equals_domain (LDAPDN dn,
|
|
|
8e731f |
+ const gchar *domain_dn_str,
|
|
|
8e731f |
+ const gchar *domain)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ LDAPDN domain_dn;
|
|
|
8e731f |
+ gboolean ret;
|
|
|
8e731f |
+ int rc;
|
|
|
8e731f |
+ gint i, j;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ rc = ldap_str2dn (domain_dn_str, &domain_dn, LDAP_DN_FORMAT_LDAPV3);
|
|
|
8e731f |
+ g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ for (i = 0; dn[i] != NULL && domain_dn[i] != NULL; i++) {
|
|
|
8e731f |
+ for (j = 0; dn[i][j] != NULL && domain_dn[i][j] != NULL; j++) {
|
|
|
8e731f |
+ if (!berval_case_equals (&(dn[i][j]->la_attr), &(domain_dn[i][j]->la_attr)) ||
|
|
|
8e731f |
+ !berval_case_equals (&(dn[i][j]->la_value), &(domain_dn[i][j]->la_value)))
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ if (dn[i][j] != NULL && domain_dn[i][j] != NULL)
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* Did we reach end of both DNs? */
|
|
|
8e731f |
+ ret = (dn[i] == NULL && domain_dn[i] == NULL);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ldap_dnfree (domain_dn);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ return ret;
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+gchar *
|
|
|
8e731f |
+realm_dn_util_build_samba_ou (const gchar *ldap_dn,
|
|
|
8e731f |
+ const gchar *domain)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ gchar *domain_dn_str = NULL;
|
|
|
8e731f |
+ GArray *parts;
|
|
|
8e731f |
+ GString *part;
|
|
|
8e731f |
+ gchar **strv;
|
|
|
8e731f |
+ gchar *str;
|
|
|
8e731f |
+ LDAPAVA* ava;
|
|
|
8e731f |
+ gboolean ret;
|
|
|
8e731f |
+ LDAPDN dn;
|
|
|
8e731f |
+ int rc;
|
|
|
8e731f |
+ gint i, j;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /*
|
|
|
8e731f |
+ * Here we convert a standard LDAP DN to the strange samba net format,
|
|
|
8e731f |
+ * as "documented" here:
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * createcomputer=OU Precreate the computer account in a specific OU.
|
|
|
8e731f |
+ * The OU string read from top to bottom without RDNs and delimited by a '/'.
|
|
|
8e731f |
+ * E.g. "createcomputer=Computers/Servers/Unix"
|
|
|
8e731f |
+ * NB: A backslash '\' is used as escape at multiple levels and may
|
|
|
8e731f |
+ * need to be doubled or even quadrupled. It is not used as a separator.
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* ldap_str2dn doesn't like empty strings */
|
|
|
8e731f |
+ while (g_ascii_isspace (ldap_dn[0]))
|
|
|
8e731f |
+ ldap_dn++;
|
|
|
8e731f |
+ if (g_str_equal (ldap_dn, ""))
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
|
|
|
8e731f |
+ if (rc != LDAP_SUCCESS)
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ret = TRUE;
|
|
|
8e731f |
+ parts = g_array_new (TRUE, TRUE, sizeof (gchar *));
|
|
|
8e731f |
+
|
|
|
8e731f |
+ for (i = 0; dn[i] != NULL; i++) {
|
|
|
8e731f |
+ ava = dn[i][0];
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /*
|
|
|
8e731f |
+ * Make sure this is a valid DN, we only support one value per
|
|
|
8e731f |
+ * RDN, string values, and must be an OU. DC values are allowed
|
|
|
8e731f |
+ * but only at the end of the DN.
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+ if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
|
|
|
8e731f |
+ ret = FALSE;
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* A DC, remainder must match the domain */
|
|
|
8e731f |
+ } else if (berval_is_string (&ava->la_attr, "DC", 2)) {
|
|
|
8e731f |
+ rc = ldap_domain2dn (domain, &domain_dn_str);
|
|
|
8e731f |
+ if (rc != LDAP_SUCCESS)
|
|
|
8e731f |
+ ret = FALSE;
|
|
|
8e731f |
+ else
|
|
|
8e731f |
+ ret = dn_equals_domain (dn + i, domain_dn_str, domain);
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* An OU, include */
|
|
|
8e731f |
+ } else if (berval_is_string (&ava->la_attr, "OU", 2)) {
|
|
|
8e731f |
+ part = g_string_sized_new (ava->la_value.bv_len);
|
|
|
8e731f |
+ for (j = 0; j < ava->la_value.bv_len; j++) {
|
|
|
8e731f |
+ switch (ava->la_value.bv_val[j]) {
|
|
|
8e731f |
+ case '\\':
|
|
|
8e731f |
+ g_string_append (part, "\\\\");
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ case '/':
|
|
|
8e731f |
+ g_string_append (part, "\\/");
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ default:
|
|
|
8e731f |
+ g_string_append_c (part, ava->la_value.bv_val[j]);
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+ str = g_string_free (part, FALSE);
|
|
|
8e731f |
+ g_array_insert_val (parts, 0, str);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* Invalid, stop */
|
|
|
8e731f |
+ } else {
|
|
|
8e731f |
+ ret = FALSE;
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ldap_dnfree (dn);
|
|
|
8e731f |
+ if (domain_dn_str)
|
|
|
8e731f |
+ ldap_memfree (domain_dn_str);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ strv = (gchar **)g_array_free (parts, FALSE);
|
|
|
8e731f |
+ str = NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* Loop completed successfully */
|
|
|
8e731f |
+ if (ret)
|
|
|
8e731f |
+ str = g_strjoinv ("/", strv);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ g_strfreev (strv);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ return str;
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+gchar *
|
|
|
8e731f |
+realm_dn_util_build_qualified (const gchar *ldap_dn,
|
|
|
8e731f |
+ const gchar *domain)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ gchar *domain_dn_str = NULL;
|
|
|
8e731f |
+ gboolean had_dc = FALSE;
|
|
|
8e731f |
+ gchar *str;
|
|
|
8e731f |
+ LDAPAVA* ava;
|
|
|
8e731f |
+ gboolean ret;
|
|
|
8e731f |
+ LDAPDN dn;
|
|
|
8e731f |
+ int rc;
|
|
|
8e731f |
+ gint i;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* ldap_str2dn doesn't like empty strings */
|
|
|
8e731f |
+ while (g_ascii_isspace (ldap_dn[0]))
|
|
|
8e731f |
+ ldap_dn++;
|
|
|
8e731f |
+ if (g_str_equal (ldap_dn, ""))
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
|
|
|
8e731f |
+ if (rc != LDAP_SUCCESS)
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ rc = ldap_domain2dn (domain, &domain_dn_str);
|
|
|
8e731f |
+ if (rc != LDAP_SUCCESS) {
|
|
|
8e731f |
+ ldap_dnfree (dn);
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ret = TRUE;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ for (i = 0; dn[i] != NULL; i++) {
|
|
|
8e731f |
+ ava = dn[i][0];
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /*
|
|
|
8e731f |
+ * Make sure this is a valid DN, we only support one value per
|
|
|
8e731f |
+ * RDN, string values. DC values are allowed but only at the end of the DN.
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+ if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
|
|
|
8e731f |
+ ret = FALSE;
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ /* A DC, remainder must match the domain */
|
|
|
8e731f |
+ } else if (berval_is_string (&ava->la_attr, "DC", 2)) {
|
|
|
8e731f |
+ had_dc = TRUE;
|
|
|
8e731f |
+ ret = dn_equals_domain (dn + i, domain_dn_str, domain);
|
|
|
8e731f |
+ break;
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ldap_dnfree (dn);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ if (!ret)
|
|
|
8e731f |
+ return NULL;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ if (had_dc)
|
|
|
8e731f |
+ str = g_strdup (ldap_dn);
|
|
|
8e731f |
+ else
|
|
|
8e731f |
+ str = g_strdup_printf ("%s,%s", ldap_dn, domain_dn_str);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ ldap_memfree (domain_dn_str);
|
|
|
8e731f |
+ return str;
|
|
|
8e731f |
+}
|
|
|
8e731f |
diff --git a/service/realm-dn-util.h b/service/realm-dn-util.h
|
|
|
8e731f |
new file mode 100644
|
|
|
8e731f |
index 0000000..f5e5e69
|
|
|
8e731f |
--- /dev/null
|
|
|
8e731f |
+++ b/service/realm-dn-util.h
|
|
|
8e731f |
@@ -0,0 +1,32 @@
|
|
|
8e731f |
+/* realmd -- Realm configuration service
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
+ * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
+ * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
+ * your option) any later version.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * See the included COPYING file for more information.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include "config.h"
|
|
|
8e731f |
+
|
|
|
8e731f |
+#ifndef __REALM_DN_UTIL_H__
|
|
|
8e731f |
+#define __REALM_DN_UTIL_H__
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include <gio/gio.h>
|
|
|
8e731f |
+
|
|
|
8e731f |
+G_BEGIN_DECLS
|
|
|
8e731f |
+
|
|
|
8e731f |
+gchar * realm_dn_util_build_samba_ou (const gchar *ldap_dn,
|
|
|
8e731f |
+ const gchar *domain);
|
|
|
8e731f |
+
|
|
|
8e731f |
+gchar * realm_dn_util_build_qualified (const gchar *ldap_dn,
|
|
|
8e731f |
+ const gchar *domain);
|
|
|
8e731f |
+
|
|
|
8e731f |
+G_END_DECLS
|
|
|
8e731f |
+
|
|
|
8e731f |
+#endif /* __REALM_DN_UTIL_H__ */
|
|
|
8e731f |
diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
|
|
|
8e731f |
index e8739d7..e749764 100644
|
|
|
8e731f |
--- a/service/realm-samba-enroll.c
|
|
|
8e731f |
+++ b/service/realm-samba-enroll.c
|
|
|
8e731f |
@@ -18,12 +18,12 @@
|
|
|
8e731f |
#include "realm-daemon.h"
|
|
|
8e731f |
#include "realm-dbus-constants.h"
|
|
|
8e731f |
#include "realm-diagnostics.h"
|
|
|
8e731f |
+#include "realm-dn-util.h"
|
|
|
8e731f |
#include "realm-errors.h"
|
|
|
8e731f |
#include "realm-options.h"
|
|
|
8e731f |
#include "realm-samba-config.h"
|
|
|
8e731f |
#include "realm-samba-enroll.h"
|
|
|
8e731f |
#include "realm-samba-provider.h"
|
|
|
8e731f |
-#include "realm-samba-util.h"
|
|
|
8e731f |
#include "realm-settings.h"
|
|
|
8e731f |
|
|
|
8e731f |
#include <glib/gstdio.h>
|
|
|
8e731f |
@@ -314,7 +314,7 @@ begin_join (GTask *task,
|
|
|
8e731f |
|
|
|
8e731f |
computer_ou = realm_options_computer_ou (options, join->disco->domain_name);
|
|
|
8e731f |
if (computer_ou != NULL) {
|
|
|
8e731f |
- strange_ou = realm_samba_util_build_strange_ou (computer_ou, join->disco->domain_name);
|
|
|
8e731f |
+ strange_ou = realm_dn_util_build_samba_ou (computer_ou, join->disco->domain_name);
|
|
|
8e731f |
if (strange_ou) {
|
|
|
8e731f |
if (!g_str_equal (strange_ou, ""))
|
|
|
8e731f |
join->join_args[at++] = g_strdup_printf ("createcomputer=%s", strange_ou);
|
|
|
8e731f |
diff --git a/service/realm-samba-util.c b/service/realm-samba-util.c
|
|
|
8e731f |
deleted file mode 100644
|
|
|
8e731f |
index 3f6a53e..0000000
|
|
|
8e731f |
--- a/service/realm-samba-util.c
|
|
|
8e731f |
+++ /dev/null
|
|
|
8e731f |
@@ -1,172 +0,0 @@
|
|
|
8e731f |
-/* realmd -- Realm configuration service
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
- * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
- * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
- * your option) any later version.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * See the included COPYING file for more information.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
- */
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include "config.h"
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include "realm-samba-util.h"
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include <glib.h>
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include <ldap.h>
|
|
|
8e731f |
-
|
|
|
8e731f |
-static gboolean
|
|
|
8e731f |
-berval_is_string (const struct berval *bv,
|
|
|
8e731f |
- const gchar *string,
|
|
|
8e731f |
- gsize length)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- return (bv->bv_len == length &&
|
|
|
8e731f |
- g_ascii_strncasecmp (bv->bv_val, string, length) == 0);
|
|
|
8e731f |
-
|
|
|
8e731f |
-}
|
|
|
8e731f |
-
|
|
|
8e731f |
-static gboolean
|
|
|
8e731f |
-berval_case_equals (const struct berval *v1,
|
|
|
8e731f |
- const struct berval *v2)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- return (v1->bv_len == v2->bv_len &&
|
|
|
8e731f |
- g_ascii_strncasecmp (v1->bv_val, v2->bv_val, v1->bv_len) == 0);
|
|
|
8e731f |
-}
|
|
|
8e731f |
-
|
|
|
8e731f |
-static gboolean
|
|
|
8e731f |
-dn_equals_domain (LDAPDN dn,
|
|
|
8e731f |
- const gchar *domain)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- LDAPDN domain_dn;
|
|
|
8e731f |
- gchar *domain_dn_str;
|
|
|
8e731f |
- gboolean ret;
|
|
|
8e731f |
- int rc;
|
|
|
8e731f |
- gint i, j;
|
|
|
8e731f |
-
|
|
|
8e731f |
- rc = ldap_domain2dn (domain, &domain_dn_str);
|
|
|
8e731f |
- g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
|
|
|
8e731f |
-
|
|
|
8e731f |
- rc = ldap_str2dn (domain_dn_str, &domain_dn, LDAP_DN_FORMAT_LDAPV3);
|
|
|
8e731f |
- g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
|
|
|
8e731f |
-
|
|
|
8e731f |
- ldap_memfree (domain_dn_str);
|
|
|
8e731f |
-
|
|
|
8e731f |
- for (i = 0; dn[i] != NULL && domain_dn[i] != NULL; i++) {
|
|
|
8e731f |
- for (j = 0; dn[i][j] != NULL && domain_dn[i][j] != NULL; j++) {
|
|
|
8e731f |
- if (!berval_case_equals (&(dn[i][j]->la_attr), &(domain_dn[i][j]->la_attr)) ||
|
|
|
8e731f |
- !berval_case_equals (&(dn[i][j]->la_value), &(domain_dn[i][j]->la_value)))
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- }
|
|
|
8e731f |
-
|
|
|
8e731f |
- if (dn[i][j] != NULL && domain_dn[i][j] != NULL)
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- }
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* Did we reach end of both DNs? */
|
|
|
8e731f |
- ret = (dn[i] == NULL && domain_dn[i] == NULL);
|
|
|
8e731f |
-
|
|
|
8e731f |
- ldap_dnfree (domain_dn);
|
|
|
8e731f |
-
|
|
|
8e731f |
- return ret;
|
|
|
8e731f |
-}
|
|
|
8e731f |
-
|
|
|
8e731f |
-gchar *
|
|
|
8e731f |
-realm_samba_util_build_strange_ou (const gchar *ldap_dn,
|
|
|
8e731f |
- const gchar *domain)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- GArray *parts;
|
|
|
8e731f |
- GString *part;
|
|
|
8e731f |
- gchar **strv;
|
|
|
8e731f |
- gchar *str;
|
|
|
8e731f |
- LDAPAVA* ava;
|
|
|
8e731f |
- gboolean ret;
|
|
|
8e731f |
- LDAPDN dn;
|
|
|
8e731f |
- int rc;
|
|
|
8e731f |
- gint i, j;
|
|
|
8e731f |
-
|
|
|
8e731f |
- /*
|
|
|
8e731f |
- * Here we convert a standard LDAP DN to the strange samba net format,
|
|
|
8e731f |
- * as "documented" here:
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * createcomputer=OU Precreate the computer account in a specific OU.
|
|
|
8e731f |
- * The OU string read from top to bottom without RDNs and delimited by a '/'.
|
|
|
8e731f |
- * E.g. "createcomputer=Computers/Servers/Unix"
|
|
|
8e731f |
- * NB: A backslash '\' is used as escape at multiple levels and may
|
|
|
8e731f |
- * need to be doubled or even quadrupled. It is not used as a separator.
|
|
|
8e731f |
- */
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* ldap_str2dn doesn't like empty strings */
|
|
|
8e731f |
- while (g_ascii_isspace (ldap_dn[0]))
|
|
|
8e731f |
- ldap_dn++;
|
|
|
8e731f |
- if (g_str_equal (ldap_dn, ""))
|
|
|
8e731f |
- return NULL;
|
|
|
8e731f |
-
|
|
|
8e731f |
- rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
|
|
|
8e731f |
- if (rc != LDAP_SUCCESS)
|
|
|
8e731f |
- return NULL;
|
|
|
8e731f |
-
|
|
|
8e731f |
- ret = TRUE;
|
|
|
8e731f |
- parts = g_array_new (TRUE, TRUE, sizeof (gchar *));
|
|
|
8e731f |
-
|
|
|
8e731f |
- for (i = 0; dn[i] != NULL; i++) {
|
|
|
8e731f |
- ava = dn[i][0];
|
|
|
8e731f |
-
|
|
|
8e731f |
- /*
|
|
|
8e731f |
- * Make sure this is a valid DN, we only support one value per
|
|
|
8e731f |
- * RDN, string values, and must be an OU. DC values are allowed
|
|
|
8e731f |
- * but only at the end of the DN.
|
|
|
8e731f |
- */
|
|
|
8e731f |
-
|
|
|
8e731f |
- if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
|
|
|
8e731f |
- ret = FALSE;
|
|
|
8e731f |
- break;
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* A DC, remainder must match the domain */
|
|
|
8e731f |
- } else if (berval_is_string (&ava->la_attr, "DC", 2)) {
|
|
|
8e731f |
- ret = dn_equals_domain (dn + i, domain);
|
|
|
8e731f |
- break;
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* An OU, include */
|
|
|
8e731f |
- } else if (berval_is_string (&ava->la_attr, "OU", 2)) {
|
|
|
8e731f |
- part = g_string_sized_new (ava->la_value.bv_len);
|
|
|
8e731f |
- for (j = 0; j < ava->la_value.bv_len; j++) {
|
|
|
8e731f |
- switch (ava->la_value.bv_val[j]) {
|
|
|
8e731f |
- case '\\':
|
|
|
8e731f |
- g_string_append (part, "\\\\");
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- case '/':
|
|
|
8e731f |
- g_string_append (part, "\\/");
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- default:
|
|
|
8e731f |
- g_string_append_c (part, ava->la_value.bv_val[j]);
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- }
|
|
|
8e731f |
- }
|
|
|
8e731f |
- str = g_string_free (part, FALSE);
|
|
|
8e731f |
- g_array_insert_val (parts, 0, str);
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* Invalid, stop */
|
|
|
8e731f |
- } else {
|
|
|
8e731f |
- ret = FALSE;
|
|
|
8e731f |
- break;
|
|
|
8e731f |
- }
|
|
|
8e731f |
- }
|
|
|
8e731f |
-
|
|
|
8e731f |
- ldap_dnfree (dn);
|
|
|
8e731f |
-
|
|
|
8e731f |
- strv = (gchar **)g_array_free (parts, FALSE);
|
|
|
8e731f |
- str = NULL;
|
|
|
8e731f |
-
|
|
|
8e731f |
- /* Loop completed successfully */
|
|
|
8e731f |
- if (ret)
|
|
|
8e731f |
- str = g_strjoinv ("/", strv);
|
|
|
8e731f |
-
|
|
|
8e731f |
- g_strfreev (strv);
|
|
|
8e731f |
-
|
|
|
8e731f |
- return str;
|
|
|
8e731f |
-}
|
|
|
8e731f |
diff --git a/service/realm-samba-util.h b/service/realm-samba-util.h
|
|
|
8e731f |
deleted file mode 100644
|
|
|
8e731f |
index 2a680e7..0000000
|
|
|
8e731f |
--- a/service/realm-samba-util.h
|
|
|
8e731f |
+++ /dev/null
|
|
|
8e731f |
@@ -1,29 +0,0 @@
|
|
|
8e731f |
-/* realmd -- Realm configuration service
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
- * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
- * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
- * your option) any later version.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * See the included COPYING file for more information.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
- */
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include "config.h"
|
|
|
8e731f |
-
|
|
|
8e731f |
-#ifndef __REALM_SAMBA_UTIL_H__
|
|
|
8e731f |
-#define __REALM_SAMBA_UTIL_H__
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include <gio/gio.h>
|
|
|
8e731f |
-
|
|
|
8e731f |
-G_BEGIN_DECLS
|
|
|
8e731f |
-
|
|
|
8e731f |
-gchar * realm_samba_util_build_strange_ou (const gchar *ldap_dn,
|
|
|
8e731f |
- const gchar *suffix_dn);
|
|
|
8e731f |
-
|
|
|
8e731f |
-G_END_DECLS
|
|
|
8e731f |
-
|
|
|
8e731f |
-#endif /* __REALM_SAMBA_UTIL_H__ */
|
|
|
8e731f |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
|
|
8e731f |
index ddeba4d..3b05066 100644
|
|
|
8e731f |
--- a/tests/Makefile.am
|
|
|
8e731f |
+++ b/tests/Makefile.am
|
|
|
8e731f |
@@ -12,11 +12,11 @@ TEST_LIBS = \
|
|
|
8e731f |
$(GLIB_LIBS)
|
|
|
8e731f |
|
|
|
8e731f |
TEST_PROGS = \
|
|
|
8e731f |
+ test-dn-util \
|
|
|
8e731f |
test-ini-config \
|
|
|
8e731f |
test-sssd-config \
|
|
|
8e731f |
test-safe-format \
|
|
|
8e731f |
test-login-name \
|
|
|
8e731f |
- test-samba-ou-format \
|
|
|
8e731f |
test-settings \
|
|
|
8e731f |
$(NULL)
|
|
|
8e731f |
|
|
|
8e731f |
@@ -27,6 +27,13 @@ noinst_PROGRAMS += \
|
|
|
8e731f |
frob-install-packages \
|
|
|
8e731f |
$(NULL)
|
|
|
8e731f |
|
|
|
8e731f |
+test_dn_util_SOURCES = \
|
|
|
8e731f |
+ tests/test-dn-util.c \
|
|
|
8e731f |
+ service/realm-dn-util.c \
|
|
|
8e731f |
+ $(NULL)
|
|
|
8e731f |
+test_dn_util_LDADD = $(TEST_LIBS)
|
|
|
8e731f |
+test_dn_util_CFLAGS = $(TEST_CFLAGS)
|
|
|
8e731f |
+
|
|
|
8e731f |
test_ini_config_SOURCES = \
|
|
|
8e731f |
tests/test-ini-config.c \
|
|
|
8e731f |
service/realm-ini-config.c \
|
|
|
8e731f |
@@ -59,13 +66,6 @@ test_login_name_SOURCES = \
|
|
|
8e731f |
test_login_name_LDADD = $(TEST_LIBS)
|
|
|
8e731f |
test_login_name_CFLAGS = $(TEST_CFLAGS)
|
|
|
8e731f |
|
|
|
8e731f |
-test_samba_ou_format_SOURCES = \
|
|
|
8e731f |
- tests/test-samba-ou-format.c \
|
|
|
8e731f |
- service/realm-samba-util.c \
|
|
|
8e731f |
- $(NULL)
|
|
|
8e731f |
-test_samba_ou_format_LDADD = $(TEST_LIBS)
|
|
|
8e731f |
-test_samba_ou_format_CFLAGS = $(TEST_CFLAGS)
|
|
|
8e731f |
-
|
|
|
8e731f |
test_settings_SOURCES = \
|
|
|
8e731f |
tests/test-settings.c \
|
|
|
8e731f |
service/realm-settings.c \
|
|
|
8e731f |
diff --git a/tests/test-dn-util.c b/tests/test-dn-util.c
|
|
|
8e731f |
new file mode 100644
|
|
|
8e731f |
index 0000000..c62a40f
|
|
|
8e731f |
--- /dev/null
|
|
|
8e731f |
+++ b/tests/test-dn-util.c
|
|
|
8e731f |
@@ -0,0 +1,129 @@
|
|
|
8e731f |
+/* realmd -- Realm configuration service
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
+ * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
+ * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
+ * your option) any later version.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * See the included COPYING file for more information.
|
|
|
8e731f |
+ *
|
|
|
8e731f |
+ * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
+ */
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include "config.h"
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include "service/realm-dn-util.h"
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include <glib/gstdio.h>
|
|
|
8e731f |
+
|
|
|
8e731f |
+#include <string.h>
|
|
|
8e731f |
+
|
|
|
8e731f |
+typedef struct {
|
|
|
8e731f |
+ const gchar *ldap_dn;
|
|
|
8e731f |
+ const gchar *domain;
|
|
|
8e731f |
+ const gchar *result;
|
|
|
8e731f |
+} Fixture;
|
|
|
8e731f |
+
|
|
|
8e731f |
+static void
|
|
|
8e731f |
+test_samba_ou_format (gconstpointer user_data)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ const Fixture *fixture = user_data;
|
|
|
8e731f |
+ gchar *result;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ result = realm_dn_util_build_samba_ou (fixture->ldap_dn, fixture->domain);
|
|
|
8e731f |
+ g_assert_cmpstr (result, ==, fixture->result);
|
|
|
8e731f |
+ g_free (result);
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+static const Fixture samba_ou_fixtures[] = {
|
|
|
8e731f |
+ { "OU=One", "domain.example.com", "One" },
|
|
|
8e731f |
+ { "OU=One,ou=two", "domain.example.com", "two/One" },
|
|
|
8e731f |
+ { "Ou=One Long,OU=two", "domain.example.com", "two/One Long" },
|
|
|
8e731f |
+ { "Ou=One,OU=two, ou=Three", "domain.example.com", "Three/two/One" },
|
|
|
8e731f |
+ { "Ou=Test/Escape,Ou=Two", "domain.example.com", "Two/Test\\/Escape" },
|
|
|
8e731f |
+ { "Ou=Test\\\\Escape,Ou=Two", "domain.example.com", "Two/Test\\\\Escape" },
|
|
|
8e731f |
+ { "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "One" },
|
|
|
8e731f |
+ { "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM", "domain.example.com", "Two Here/One" },
|
|
|
8e731f |
+ { "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
|
|
|
8e731f |
+ { " ", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "OU", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "OU=One,", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "CN=Unsupported", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "OU=One+CN=Unsupported", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
|
|
|
8e731f |
+
|
|
|
8e731f |
+};
|
|
|
8e731f |
+
|
|
|
8e731f |
+static void
|
|
|
8e731f |
+test_qualify_dn (gconstpointer user_data)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ const Fixture *fixture = user_data;
|
|
|
8e731f |
+ gchar *result;
|
|
|
8e731f |
+
|
|
|
8e731f |
+ result = realm_dn_util_build_qualified (fixture->ldap_dn, fixture->domain);
|
|
|
8e731f |
+ g_assert_cmpstr (result, ==, fixture->result);
|
|
|
8e731f |
+ g_free (result);
|
|
|
8e731f |
+}
|
|
|
8e731f |
+
|
|
|
8e731f |
+static const Fixture qualify_fixtures[] = {
|
|
|
8e731f |
+ { "OU=One", "domain.example.com", "OU=One,dc=domain,dc=example,dc=com" },
|
|
|
8e731f |
+ { "OU=One,ou=two", "domain.example.com", "OU=One,ou=two,dc=domain,dc=example,dc=com" },
|
|
|
8e731f |
+ { "Ou=One Long,OU=two", "domain.example.com", "Ou=One Long,OU=two,dc=domain,dc=example,dc=com" },
|
|
|
8e731f |
+ { "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "OU=One,DC=domain,dc=example,Dc=COM" },
|
|
|
8e731f |
+ { "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM", "domain.example.com", "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM" },
|
|
|
8e731f |
+ { "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
|
|
|
8e731f |
+ { " ", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "OU", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "OU=One,", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "CN=Test", "domain.example.com", "CN=Test,dc=domain,dc=example,dc=com" },
|
|
|
8e731f |
+ { "OU=One+CN=Unsupported", "domain.example.com", NULL },
|
|
|
8e731f |
+ { "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
|
|
|
8e731f |
+};
|
|
|
8e731f |
+
|
|
|
8e731f |
+int
|
|
|
8e731f |
+main (int argc,
|
|
|
8e731f |
+ char **argv)
|
|
|
8e731f |
+{
|
|
|
8e731f |
+ gchar *escaped;
|
|
|
8e731f |
+ gchar *name;
|
|
|
8e731f |
+ gint i;
|
|
|
8e731f |
+
|
|
|
8e731f |
+#if !GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
8e731f |
+ g_type_init ();
|
|
|
8e731f |
+#endif
|
|
|
8e731f |
+
|
|
|
8e731f |
+ g_test_init (&argc, &argv, NULL);
|
|
|
8e731f |
+ g_set_prgname ("test-dn-util");
|
|
|
8e731f |
+
|
|
|
8e731f |
+ for (i = 0; i < G_N_ELEMENTS (samba_ou_fixtures); i++) {
|
|
|
8e731f |
+ if (g_str_equal (samba_ou_fixtures[i].ldap_dn, ""))
|
|
|
8e731f |
+ escaped = g_strdup ("_empty_");
|
|
|
8e731f |
+ else
|
|
|
8e731f |
+ escaped = g_strdup (samba_ou_fixtures[i].ldap_dn);
|
|
|
8e731f |
+ g_strdelimit (escaped, ", =\\/", '_');
|
|
|
8e731f |
+ name = g_strdup_printf ("/realmd/samba-ou-format/%s", escaped);
|
|
|
8e731f |
+ g_free (escaped);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ g_test_add_data_func (name, samba_ou_fixtures + i, test_samba_ou_format);
|
|
|
8e731f |
+ g_free (name);
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ for (i = 0; i < G_N_ELEMENTS (qualify_fixtures); i++) {
|
|
|
8e731f |
+ if (g_str_equal (qualify_fixtures[i].ldap_dn, ""))
|
|
|
8e731f |
+ escaped = g_strdup ("_empty_");
|
|
|
8e731f |
+ else
|
|
|
8e731f |
+ escaped = g_strdup (qualify_fixtures[i].ldap_dn);
|
|
|
8e731f |
+ g_strdelimit (escaped, ", =\\/", '_');
|
|
|
8e731f |
+ name = g_strdup_printf ("/realmd/qualify-dn/%s", escaped);
|
|
|
8e731f |
+ g_free (escaped);
|
|
|
8e731f |
+
|
|
|
8e731f |
+ g_test_add_data_func (name, qualify_fixtures + i, test_qualify_dn);
|
|
|
8e731f |
+ g_free (name);
|
|
|
8e731f |
+ }
|
|
|
8e731f |
+
|
|
|
8e731f |
+ return g_test_run ();
|
|
|
8e731f |
+}
|
|
|
8e731f |
diff --git a/tests/test-samba-ou-format.c b/tests/test-samba-ou-format.c
|
|
|
8e731f |
deleted file mode 100644
|
|
|
8e731f |
index 0a482ee..0000000
|
|
|
8e731f |
--- a/tests/test-samba-ou-format.c
|
|
|
8e731f |
+++ /dev/null
|
|
|
8e731f |
@@ -1,89 +0,0 @@
|
|
|
8e731f |
-/* realmd -- Realm configuration service
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Copyright 2012 Red Hat Inc
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * This program is free software: you can redistribute it and/or modify
|
|
|
8e731f |
- * it under the terms of the GNU Lesser General Public License as published
|
|
|
8e731f |
- * by the Free Software Foundation; either version 2 of the licence or (at
|
|
|
8e731f |
- * your option) any later version.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * See the included COPYING file for more information.
|
|
|
8e731f |
- *
|
|
|
8e731f |
- * Author: Stef Walter <stefw@gnome.org>
|
|
|
8e731f |
- */
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include "config.h"
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include "service/realm-samba-util.h"
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include <glib/gstdio.h>
|
|
|
8e731f |
-
|
|
|
8e731f |
-#include <string.h>
|
|
|
8e731f |
-
|
|
|
8e731f |
-typedef struct {
|
|
|
8e731f |
- const gchar *ldap_dn;
|
|
|
8e731f |
- const gchar *domain;
|
|
|
8e731f |
- const gchar *ou_format;
|
|
|
8e731f |
-} Fixture;
|
|
|
8e731f |
-
|
|
|
8e731f |
-static void
|
|
|
8e731f |
-test_samba_ou_format (gconstpointer user_data)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- const Fixture *fixture = user_data;
|
|
|
8e731f |
- gchar *result;
|
|
|
8e731f |
-
|
|
|
8e731f |
- result = realm_samba_util_build_strange_ou (fixture->ldap_dn, fixture->domain);
|
|
|
8e731f |
- g_assert_cmpstr (result, ==, fixture->ou_format);
|
|
|
8e731f |
- g_free (result);
|
|
|
8e731f |
-}
|
|
|
8e731f |
-
|
|
|
8e731f |
-static const Fixture samba_ou_fixtures[] = {
|
|
|
8e731f |
- { "OU=One", "domain.example.com", "One" },
|
|
|
8e731f |
- { "OU=One,ou=two", "domain.example.com", "two/One" },
|
|
|
8e731f |
- { "Ou=One Long,OU=two", "domain.example.com", "two/One Long" },
|
|
|
8e731f |
- { "Ou=One,OU=two, ou=Three", "domain.example.com", "Three/two/One" },
|
|
|
8e731f |
- { "Ou=Test/Escape,Ou=Two", "domain.example.com", "Two/Test\\/Escape" },
|
|
|
8e731f |
- { "Ou=Test\\\\Escape,Ou=Two", "domain.example.com", "Two/Test\\\\Escape" },
|
|
|
8e731f |
- { "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "One" },
|
|
|
8e731f |
- { "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM", "domain.example.com", "Two Here/One" },
|
|
|
8e731f |
- { "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
|
|
|
8e731f |
- { " ", "domain.example.com", NULL },
|
|
|
8e731f |
- { "", "domain.example.com", NULL },
|
|
|
8e731f |
- { "OU", "domain.example.com", NULL },
|
|
|
8e731f |
- { "OU=One,", "domain.example.com", NULL },
|
|
|
8e731f |
- { "CN=Unsupported", "domain.example.com", NULL },
|
|
|
8e731f |
- { "OU=One+CN=Unsupported", "domain.example.com", NULL },
|
|
|
8e731f |
- { "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
|
|
|
8e731f |
-
|
|
|
8e731f |
-};
|
|
|
8e731f |
-
|
|
|
8e731f |
-int
|
|
|
8e731f |
-main (int argc,
|
|
|
8e731f |
- char **argv)
|
|
|
8e731f |
-{
|
|
|
8e731f |
- gchar *escaped;
|
|
|
8e731f |
- gchar *name;
|
|
|
8e731f |
- gint i;
|
|
|
8e731f |
-
|
|
|
8e731f |
-#if !GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
8e731f |
- g_type_init ();
|
|
|
8e731f |
-#endif
|
|
|
8e731f |
-
|
|
|
8e731f |
- g_test_init (&argc, &argv, NULL);
|
|
|
8e731f |
- g_set_prgname ("test-samba-ou-format");
|
|
|
8e731f |
-
|
|
|
8e731f |
- for (i = 0; i < G_N_ELEMENTS (samba_ou_fixtures); i++) {
|
|
|
8e731f |
- if (g_str_equal (samba_ou_fixtures[i].ldap_dn, ""))
|
|
|
8e731f |
- escaped = g_strdup ("_empty_");
|
|
|
8e731f |
- else
|
|
|
8e731f |
- escaped = g_strdup (samba_ou_fixtures[i].ldap_dn);
|
|
|
8e731f |
- g_strdelimit (escaped, ", =\\/", '_');
|
|
|
8e731f |
- name = g_strdup_printf ("/realmd/samba-ou-format/%s", escaped);
|
|
|
8e731f |
- g_free (escaped);
|
|
|
8e731f |
-
|
|
|
8e731f |
- g_test_add_data_func (name, samba_ou_fixtures + i, test_samba_ou_format);
|
|
|
8e731f |
- g_free (name);
|
|
|
8e731f |
- }
|
|
|
8e731f |
-
|
|
|
8e731f |
- return g_test_run ();
|
|
|
8e731f |
-}
|
|
|
8e731f |
--
|
|
|
8e731f |
2.7.4
|
|
|
8e731f |
|