diff --git a/SOURCES/0001-Add-os-name-and-os-version-command-line-options.patch b/SOURCES/0001-Add-os-name-and-os-version-command-line-options.patch
new file mode 100644
index 0000000..6d282c4
--- /dev/null
+++ b/SOURCES/0001-Add-os-name-and-os-version-command-line-options.patch
@@ -0,0 +1,182 @@
+From ca6684a68d2a9887c2e06e58a7fdfa3d327c8052 Mon Sep 17 00:00:00 2001
+From: Sumit Bose <sbose@redhat.com>
+Date: Tue, 28 Jun 2016 18:14:09 +0200
+Subject: [PATCH] Add os-name and os-version command line options
+
+---
+ dbus/realm-dbus-constants.h  |  2 ++
+ doc/manual/realm.xml         | 12 ++++++++++++
+ doc/manual/realmd.conf.xml   |  5 +++++
+ service/realm-adcli-enroll.c |  4 ++--
+ service/realm-options.c      | 18 ++++++++++++++++++
+ service/realm-options.h      |  3 +++
+ service/realm-samba-enroll.c |  4 ++--
+ tools/realm-join.c           |  8 ++++++++
+ 8 files changed, 52 insertions(+), 4 deletions(-)
+
+diff --git a/dbus/realm-dbus-constants.h b/dbus/realm-dbus-constants.h
+index 3a67a00..9cd30ef 100644
+--- a/dbus/realm-dbus-constants.h
++++ b/dbus/realm-dbus-constants.h
+@@ -67,6 +67,8 @@ G_BEGIN_DECLS
+ #define   REALM_DBUS_OPTION_USER_PRINCIPAL         "user-principal"
+ #define   REALM_DBUS_OPTION_MANAGE_SYSTEM          "manage-system"
+ #define   REALM_DBUS_OPTION_COMPUTER_NAME          "computer-name"
++#define   REALM_DBUS_OPTION_OS_NAME                "os-name"
++#define   REALM_DBUS_OPTION_OS_VERSION             "os-version"
+ 
+ #define   REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY   "active-directory"
+ #define   REALM_DBUS_IDENTIFIER_WINBIND            "winbind"
+diff --git a/doc/manual/realm.xml b/doc/manual/realm.xml
+index baa0d8c..6724d80 100644
+--- a/doc/manual/realm.xml
++++ b/doc/manual/realm.xml
+@@ -243,6 +243,18 @@ $ realm join --user=admin --computer-ou=OU=Special domain.example.com
+ 			the value for this option, then a principal will be set
+ 			in the form of <literal>host/shortname@REALM</literal></para></listitem>
+ 		</varlistentry>
++		<varlistentry>
++			<term><option>--os-name=xxx</option></term>
++			<listitem><para>The name of the operation system of the
++			client. When joining an AD domain the value is store in
++			the matching AD attribute.</para></listitem>
++		</varlistentry>
++		<varlistentry>
++			<term><option>--os-version=xxx</option></term>
++			<listitem><para>The version of the operation system of the
++			client. When joining an AD domain the value is store in
++			the matching AD attribute.</para></listitem>
++		</varlistentry>
+ 	</variablelist>
+ 
+ </refsect1>
+diff --git a/doc/manual/realmd.conf.xml b/doc/manual/realmd.conf.xml
+index f8c87b9..7853230 100644
+--- a/doc/manual/realmd.conf.xml
++++ b/doc/manual/realmd.conf.xml
+@@ -149,6 +149,11 @@ domain.example.com
+ 
+ 		<para>This is an Active Directory specific option.</para>
+ 
++		<para>It is also possible to use the <option>--os-name</option>
++		or <option>--os-version</option> argument of the
++		<command>realm</command> command to override the default
++		values.</para>
++
+ 		<informalexample>
+ <programlisting language="js">
+ [active-directory]
+diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
+index 0c506f9..05947fa 100644
+--- a/service/realm-adcli-enroll.c
++++ b/service/realm-adcli-enroll.c
+@@ -139,13 +139,13 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 			g_ptr_array_add (args, (gpointer)computer_ou);
+ 	}
+ 
+-	os = realm_settings_value ("active-directory", "os-name");
++	os = realm_options_ad_specific (options, "os-name");
+ 	if (os != NULL && !g_str_equal (os, "")) {
+ 		g_ptr_array_add (args, "--os-name");
+ 		g_ptr_array_add (args, (gpointer)os);
+ 	}
+ 
+-	os = realm_settings_value ("active-directory", "os-version");
++	os = realm_options_ad_specific (options, "os-version");
+ 	if (os != NULL && !g_str_equal (os, "")) {
+ 		g_ptr_array_add (args, "--os-version");
+ 		g_ptr_array_add (args, (gpointer)os);
+diff --git a/service/realm-options.c b/service/realm-options.c
+index b9f59c6..bd804ea 100644
+--- a/service/realm-options.c
++++ b/service/realm-options.c
+@@ -180,3 +180,21 @@ realm_options_computer_name (GVariant *options,
+ 
+ 	return g_strdup (computer_name);
+ }
++
++const gchar *
++realm_options_ad_specific (GVariant *options,
++                           const gchar *option_name)
++{
++	const gchar *value = NULL;
++
++	if (options) {
++		if (!g_variant_lookup (options, option_name, "&s", &value))
++			value = NULL;
++	}
++
++	if (!value) {
++		value = realm_settings_value ("active-directory", option_name);
++	}
++
++	return g_strdup (value);
++}
+diff --git a/service/realm-options.h b/service/realm-options.h
+index e31cddc..7a1355e 100644
+--- a/service/realm-options.h
++++ b/service/realm-options.h
+@@ -44,6 +44,9 @@ gboolean       realm_options_check_domain_name        (const gchar *domain_name)
+ const gchar *  realm_options_computer_name           (GVariant *options,
+                                                        const gchar *realm_name);
+ 
++const gchar *  realm_options_ad_specific              (GVariant *options,
++                                                       const gchar *option_name);
++
+ G_END_DECLS
+ 
+ #endif /* __REALM_OPTIONS_H__ */
+diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
+index f2392a9..c81aed2 100644
+--- a/service/realm-samba-enroll.c
++++ b/service/realm-samba-enroll.c
+@@ -335,11 +335,11 @@ begin_join (GTask *task,
+ 		}
+ 	}
+ 
+-	os = realm_settings_value ("active-directory", "os-name");
++	os = realm_options_ad_specific(options, "os-name");
+ 	if (os != NULL && !g_str_equal (os, ""))
+ 		join->join_args[at++] = g_strdup_printf ("osName=%s", os);
+ 
+-	os = realm_settings_value ("active-directory", "os-version");
++	os = realm_options_ad_specific(options, "os-version");
+ 	if (os != NULL && !g_str_equal (os, ""))
+ 		join->join_args[at++] = g_strdup_printf ("osVer=%s", os);
+ 
+diff --git a/tools/realm-join.c b/tools/realm-join.c
+index 3685bb9..8e46c20 100644
+--- a/tools/realm-join.c
++++ b/tools/realm-join.c
+@@ -169,6 +169,8 @@ typedef struct {
+ 	gchar *user;
+ 	gchar *computer_ou;
+ 	gchar *computer_name;
++	gchar *os_name;
++	gchar *os_version;
+ 	gchar *client_software;
+ 	gchar *server_software;
+ 	gchar *membership_software;
+@@ -241,6 +243,8 @@ perform_join (RealmClient *client,
+ 
+ 	options = realm_build_options (REALM_DBUS_OPTION_COMPUTER_OU, args->computer_ou,
+ 	                               REALM_DBUS_OPTION_COMPUTER_NAME, args->computer_name,
++	                               REALM_DBUS_OPTION_OS_NAME, args->os_name,
++	                               REALM_DBUS_OPTION_OS_VERSION, args->os_version,
+ 	                               REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE, args->membership_software,
+ 	                               REALM_DBUS_OPTION_USER_PRINCIPAL, args->user_principal,
+ 	                               args->automatic_id_mapping_set ?
+@@ -288,6 +292,10 @@ realm_join (RealmClient *client,
+ 		  N_("Computer OU DN to join"), NULL },
+ 		{ "computer-name", 0, 0, G_OPTION_ARG_STRING, &args.computer_name,
+ 			N_("Use specific computer name instead of hostname"), NULL },
++		{ "os-name", 0, 0, G_OPTION_ARG_STRING, &args.os_name,
++			N_("Use specific operation system name"), NULL },
++		{ "os-version", 0, 0, G_OPTION_ARG_STRING, &args.os_version,
++			N_("Use specific operation system version"), NULL },
+ 		{ "client-software", 0, 0, G_OPTION_ARG_STRING, &args.client_software,
+ 		  N_("Use specific client software"), NULL },
+ 		{ "server-software", 0, 0, G_OPTION_ARG_STRING, &args.server_software,
+-- 
+2.7.4
+
diff --git a/SOURCES/0001-Fix-man-page-reference-in-systemd-service-file.patch b/SOURCES/0001-Fix-man-page-reference-in-systemd-service-file.patch
new file mode 100644
index 0000000..fe46620
--- /dev/null
+++ b/SOURCES/0001-Fix-man-page-reference-in-systemd-service-file.patch
@@ -0,0 +1,24 @@
+From e8d9d5e9817627dcf208ac742debcc9dc320752d Mon Sep 17 00:00:00 2001
+From: Sumit Bose <sbose@redhat.com>
+Date: Wed, 27 Jul 2016 19:06:29 +0200
+Subject: [PATCH] Fix man page reference in systemd service file
+
+---
+ dbus/realmd.service.in | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/dbus/realmd.service.in b/dbus/realmd.service.in
+index b3bcf7a..64c1090 100644
+--- a/dbus/realmd.service.in
++++ b/dbus/realmd.service.in
+@@ -1,6 +1,6 @@
+ [Unit]
+ Description=Realm and Domain Configuration
+-Documentation=man:realmd(8)
++Documentation=man:realm(8)
+ 
+ [Service]
+ Type=dbus
+-- 
+2.7.4
+
diff --git a/SOURCES/0001-Make-DBus-aware-of-systemd.patch b/SOURCES/0001-Make-DBus-aware-of-systemd.patch
new file mode 100644
index 0000000..a12ff02
--- /dev/null
+++ b/SOURCES/0001-Make-DBus-aware-of-systemd.patch
@@ -0,0 +1,53 @@
+From 03f949a0b394ab954fc68f33e092dc0bb1fec406 Mon Sep 17 00:00:00 2001
+From: Sumit Bose <sbose@redhat.com>
+Date: Tue, 28 Jun 2016 14:41:01 +0200
+Subject: [PATCH] Make DBus aware of systemd
+
+---
+ Makefile.am                            | 1 +
+ configure.ac                           | 7 +++++++
+ dbus/org.freedesktop.realmd.service.in | 1 +
+ 3 files changed, 9 insertions(+)
+
+diff --git a/Makefile.am b/Makefile.am
+index 52de3dc..c81f048 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -49,6 +49,7 @@ SED_SUBST = sed \
+ 	-e 's,[@]abs_srcdir[@],$(abs_srcdir),g' \
+ 	-e 's,[@]srcdir[@],$(srcdir),g' \
+ 	-e 's,[@]privatedir[@],$(privatedir),g' \
++	-e 's,[@]dbus_systemd_service[@],$(dbus_systemd_service),g' \
+ 	-e 's,[@]PACKAGE[@],$(PACKAGE),g' \
+ 	-e 's,[@]VERSION[@],$(VERSION),g' \
+ 	$(NULL)
+diff --git a/configure.ac b/configure.ac
+index 032cdaa..0376887 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -110,6 +110,13 @@ fi
+ SYSTEMD_UNIT_DIR="$with_systemd_unit_dir"
+ AC_SUBST(SYSTEMD_UNIT_DIR)
+ AM_CONDITIONAL(WITH_SYSTEMD, [test -n "$with_systemd_unit_dir"])
++
++dbus_systemd_service=""
++if test -n "$with_systemd_unit_dir"; then
++	dbus_systemd_service="SystemdService=realmd.service"
++fi
++AC_SUBST(dbus_systemd_service)
++
+ AC_MSG_RESULT($with_systemd_unit_dir)
+ 
+ AC_ARG_WITH(systemd-journal,
+diff --git a/dbus/org.freedesktop.realmd.service.in b/dbus/org.freedesktop.realmd.service.in
+index 834e23f..51132f6 100644
+--- a/dbus/org.freedesktop.realmd.service.in
++++ b/dbus/org.freedesktop.realmd.service.in
+@@ -2,3 +2,4 @@
+ Name=org.freedesktop.realmd
+ Exec=@privatedir@/realmd
+ User=root
++@dbus_systemd_service@
+-- 
+2.7.4
+
diff --git a/SOURCES/0001-Support-manually-setting-computer-name.patch b/SOURCES/0001-Support-manually-setting-computer-name.patch
new file mode 100644
index 0000000..985e340
--- /dev/null
+++ b/SOURCES/0001-Support-manually-setting-computer-name.patch
@@ -0,0 +1,261 @@
+From ec3c397cf50ace03f920502f34bca612f62333bf Mon Sep 17 00:00:00 2001
+From: Andrew Austin <aaustin@one.verizon.com>
+Date: Sun, 17 Apr 2016 12:17:04 -0500
+Subject: [PATCH 1/3] Support manually setting computer name
+
+This change adds a computer-name option to the realm configuration.
+When set, the computer-name string will be used in place of either the
+system's hostname or an automatically truncated netbios name when joining
+an active directory domain.
+
+https://bugs.freedesktop.org/show_bug.cgi?id=93739
+
+Signed-off-by: Stef Walter <stefw@redhat.com>
+ * Squashed fixup patch
+---
+ dbus/realm-dbus-constants.h  |  1 +
+ service/realm-adcli-enroll.c | 11 +++++++++--
+ service/realm-options.c      | 21 +++++++++++++++++++++
+ service/realm-options.h      |  3 +++
+ service/realm-samba-enroll.c | 26 ++++++++++++++++++++------
+ service/realm-samba.c        | 10 +++++++++-
+ service/realm-sssd-ad.c      |  9 ++++++---
+ 7 files changed, 69 insertions(+), 12 deletions(-)
+
+diff --git a/dbus/realm-dbus-constants.h b/dbus/realm-dbus-constants.h
+index c68e958..3a67a00 100644
+--- a/dbus/realm-dbus-constants.h
++++ b/dbus/realm-dbus-constants.h
+@@ -66,6 +66,7 @@ G_BEGIN_DECLS
+ #define   REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE    "membership-software"
+ #define   REALM_DBUS_OPTION_USER_PRINCIPAL         "user-principal"
+ #define   REALM_DBUS_OPTION_MANAGE_SYSTEM          "manage-system"
++#define   REALM_DBUS_OPTION_COMPUTER_NAME          "computer-name"
+ 
+ #define   REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY   "active-directory"
+ #define   REALM_DBUS_IDENTIFIER_WINBIND            "winbind"
+diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
+index ef1b563..0c506f9 100644
+--- a/service/realm-adcli-enroll.c
++++ b/service/realm-adcli-enroll.c
+@@ -84,6 +84,7 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 	gchar *upn_arg = NULL;
+ 	gchar *server_arg = NULL;
+ 	gchar *ou_arg = NULL;
++	const gchar *computer_name = NULL;
+ 
+ 	g_return_if_fail (cred != NULL);
+ 	g_return_if_fail (disco != NULL);
+@@ -114,7 +115,14 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 		g_ptr_array_add (args, (gpointer)disco->explicit_server);
+ 	}
+ 
+-	if (disco->explicit_netbios) {
++		/* Pass manually configured or truncated computer name to adcli */
++		computer_name = realm_options_computer_name (options, disco->domain_name);
++		if (computer_name != NULL) {
++			realm_diagnostics_info (invocation, "Joining using a manual netbios name: %s",
++			                        computer_name);
++			g_ptr_array_add (args, "--computer-name");
++			g_ptr_array_add (args, (gpointer)computer_name);
++		} else if (disco->explicit_netbios) {
+ 		realm_diagnostics_info (invocation, "Joining using a truncated netbios name: %s",
+ 		                        disco->explicit_netbios);
+ 		g_ptr_array_add (args, "--computer-name");
+@@ -192,7 +200,6 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 
+ 	if (input)
+ 		g_bytes_unref (input);
+-
+ 	free (ccache_arg);
+ 	free (upn_arg);
+ 	free (server_arg);
+diff --git a/service/realm-options.c b/service/realm-options.c
+index bba3ee4..b9f59c6 100644
+--- a/service/realm-options.c
++++ b/service/realm-options.c
+@@ -159,3 +159,24 @@ realm_options_check_domain_name (const gchar *name)
+ 
+ 	return TRUE;
+ }
++
++const gchar *
++realm_options_computer_name (GVariant *options,
++                           const gchar *realm_name)
++{
++	const gchar *computer_name = NULL;
++	gchar *section;
++
++	if (options) {
++		if (!g_variant_lookup (options, REALM_DBUS_OPTION_COMPUTER_NAME, "&s", &computer_name))
++			computer_name = NULL;
++	}
++
++	if (realm_name && !computer_name) {
++		section = g_utf8_casefold (realm_name, -1);
++		computer_name = realm_settings_value (section, REALM_DBUS_OPTION_COMPUTER_NAME);
++		g_free (section);
++	}
++
++	return g_strdup (computer_name);
++}
+diff --git a/service/realm-options.h b/service/realm-options.h
+index 4890cba..e31cddc 100644
+--- a/service/realm-options.h
++++ b/service/realm-options.h
+@@ -41,6 +41,9 @@ gboolean       realm_options_qualify_names            (const gchar *realm_name);
+ 
+ gboolean       realm_options_check_domain_name        (const gchar *domain_name);
+ 
++const gchar *  realm_options_computer_name           (GVariant *options,
++                                                       const gchar *realm_name);
++
+ G_END_DECLS
+ 
+ #endif /* __REALM_OPTIONS_H__ */
+diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
+index e749764..f2392a9 100644
+--- a/service/realm-samba-enroll.c
++++ b/service/realm-samba-enroll.c
+@@ -84,27 +84,37 @@ fallback_workgroup (const gchar *realm)
+ static JoinClosure *
+ join_closure_init (GTask *task,
+                    RealmDisco *disco,
++                   GVariant *options,
+                    GDBusMethodInvocation *invocation)
+ {
+ 	JoinClosure *join;
+ 	gchar *workgroup;
+ 	GError *error = NULL;
+ 	int temp_fd;
++	const gchar *explicit_computer_name = NULL;
++	const gchar *authid = NULL;
+ 
+ 	join = g_new0 (JoinClosure, 1);
+ 	join->disco = realm_disco_ref (disco);
+ 	join->invocation = invocation ? g_object_ref (invocation) : NULL;
+ 	g_task_set_task_data (task, join, join_closure_free);
+ 
++	explicit_computer_name = realm_options_computer_name (options, disco->domain_name);
++	/* Set netbios name to explicit or truncated name if available */
++	if (explicit_computer_name != NULL)
++		authid = explicit_computer_name;
++	else if (disco->explicit_netbios)
++		authid = disco->explicit_netbios;
++
+ 	join->config = realm_ini_config_new (REALM_INI_NO_WATCH | REALM_INI_PRIVATE);
+ 	realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL,
+ 	                      "security", "ads",
+ 	                      "kerberos method", "system keytab",
+ 	                      "realm", disco->kerberos_realm,
+-	                      "netbios name", disco->explicit_netbios,
++	                      "netbios name", authid,
+ 	                      NULL);
+ 
+-	/*
++    /*
+ 	 * Samba complains if we don't set a 'workgroup' setting for the realm we're
+ 	 * going to join. If we didn't yet manage to lookup the workgroup, then go ahead
+ 	 * and assume that the first domain component is the workgroup name.
+@@ -377,14 +387,18 @@ realm_samba_enroll_join_async (RealmDisco *disco,
+ {
+ 	GTask *task;
+ 	JoinClosure *join;
++	const gchar *explicit_computer_name;
+ 
+ 	g_return_if_fail (disco != NULL);
+ 	g_return_if_fail (cred != NULL);
+ 
+ 	task = g_task_new (NULL, NULL, callback, user_data);
+-	join = join_closure_init (task, disco, invocation);
+-
+-	if (disco->explicit_netbios) {
++	join = join_closure_init (task, disco, options, invocation);
++	explicit_computer_name = realm_options_computer_name (options, disco->domain_name);
++	if (explicit_computer_name != NULL) {
++		realm_diagnostics_info (invocation, "Joining using a manual netbios name: %s",
++		                        explicit_computer_name);
++	} else if (disco->explicit_netbios) {
+ 		realm_diagnostics_info (invocation, "Joining using a truncated netbios name: %s",
+ 		                        disco->explicit_netbios);
+ 	}
+@@ -448,7 +462,7 @@ realm_samba_enroll_leave_async (RealmDisco *disco,
+ 	JoinClosure *join;
+ 
+ 	task = g_task_new (NULL, NULL, callback, user_data);
+-	join = join_closure_init (task, disco, invocation);
++	join = join_closure_init (task, disco, options, invocation);
+ 
+ 	switch (cred->type) {
+ 	case REALM_CREDENTIAL_PASSWORD:
+diff --git a/service/realm-samba.c b/service/realm-samba.c
+index eca65aa..5cf2aa8 100644
+--- a/service/realm-samba.c
++++ b/service/realm-samba.c
+@@ -183,6 +183,13 @@ on_join_do_winbind (GObject *source,
+ 	GHashTable *settings = NULL;
+ 	GError *error = NULL;
+ 	const gchar *name;
++	const gchar *computer_name;
++
++	computer_name = realm_options_computer_name (enroll->options, enroll->disco->domain_name);
++	/* Use truncated name if set and explicit name is not available */
++	if (enroll->disco->explicit_netbios && computer_name == NULL)
++		computer_name = enroll->disco->explicit_netbios;
++
+ 
+ 	realm_samba_enroll_join_finish (result, &error);
+ 	if (error == NULL) {
+@@ -192,12 +199,13 @@ on_join_do_winbind (GObject *source,
+ 		                         "workgroup", enroll->disco->workgroup,
+ 		                         "template homedir", realm_settings_string ("users", "default-home"),
+ 		                         "template shell", realm_settings_string ("users", "default-shell"),
+-		                         "netbios name", enroll->disco->explicit_netbios,
++		                         "netbios name", computer_name,
+ 		                         "password server", enroll->disco->explicit_server,
+ 		                         "kerberos method", "system keytab",
+ 		                         NULL);
+ 	}
+ 
++
+ 	if (error == NULL) {
+ 		name = realm_kerberos_get_name (REALM_KERBEROS (self));
+ 		realm_samba_winbind_configure_async (self->config, name, enroll->options,
+diff --git a/service/realm-sssd-ad.c b/service/realm-sssd-ad.c
+index c7ffe8a..5ed384d 100644
+--- a/service/realm-sssd-ad.c
++++ b/service/realm-sssd-ad.c
+@@ -163,6 +163,7 @@ configure_sssd_for_domain (RealmIniConfig *config,
+ 	GString *realmd_tags;
+ 	const gchar *access_provider;
+ 	const gchar *shell;
++    const gchar *explicit_computer_name;
+ 	gchar *authid = NULL;
+ 	gboolean qualify;
+ 	gboolean ret;
+@@ -172,17 +173,19 @@ configure_sssd_for_domain (RealmIniConfig *config,
+ 	home = realm_sssd_build_default_home (realm_settings_string ("users", "default-home"));
+ 	qualify = realm_options_qualify_names (disco->domain_name);
+ 	shell = realm_settings_string ("users", "default-shell");
+-
++	explicit_computer_name = realm_options_computer_name (options, disco->domain_name);
+ 	realmd_tags = g_string_new ("");
+ 	if (realm_options_manage_system (options, disco->domain_name))
+ 		g_string_append (realmd_tags, "manages-system ");
+ 	g_string_append (realmd_tags, use_adcli ? "joined-with-adcli " : "joined-with-samba ");
+ 
+ 	/*
+-	 * Explicitly set the netbios authid for sssd to use in this case, since
++	 * Explicitly set the netbios authid for sssd to use in these cases, since
+ 	 * otherwise sssd won't know which kerberos principal to use
+ 	 */
+-	if (disco->explicit_netbios)
++	if (explicit_computer_name != NULL)
++		authid = g_strdup_printf ("%s$", explicit_computer_name);
++	else if (disco->explicit_netbios)
+ 		authid = g_strdup_printf ("%s$", disco->explicit_netbios);
+ 
+ 	ret = realm_sssd_config_add_domain (config, disco->domain_name, error,
+-- 
+2.7.4
+
diff --git a/SOURCES/0001-doc-add-computer-name-to-realm-man-page.patch b/SOURCES/0001-doc-add-computer-name-to-realm-man-page.patch
new file mode 100644
index 0000000..c12ee98
--- /dev/null
+++ b/SOURCES/0001-doc-add-computer-name-to-realm-man-page.patch
@@ -0,0 +1,36 @@
+From e427f89fa4f41356525797170729c2dc5d9fa045 Mon Sep 17 00:00:00 2001
+From: Sumit Bose <sbose@redhat.com>
+Date: Mon, 25 Jul 2016 15:25:20 +0200
+Subject: [PATCH] doc: add computer-name to realm man page
+
+---
+ doc/manual/realm.xml | 13 +++++++++++++
+ 1 file changed, 13 insertions(+)
+
+diff --git a/doc/manual/realm.xml b/doc/manual/realm.xml
+index 6724d80..ebaebd3 100644
+--- a/doc/manual/realm.xml
++++ b/doc/manual/realm.xml
+@@ -202,6 +202,19 @@ $ realm join --user=admin --computer-ou=OU=Special domain.example.com
+ 			Directory specific option.</para></listitem>
+ 		</varlistentry>
+ 		<varlistentry>
++			<term><option>--computer-name=xxx</option></term>
++			<listitem>
++				<para>This option only applies to Active
++				Directory realms. Specify this option to
++				override the default name used when creating
++				the computer account. The system's FQDN will
++				still be saved in the dNSHostName attribute.</para>
++				<para>Specify the name as a string of 15 or
++				fewer characters that is a valid NetBIOS
++				computer name.</para>
++			</listitem>
++		</varlistentry>
++		<varlistentry>
+ 			<term><option>--no-password</option></term>
+ 			<listitem><para>Perform the join automatically without
+ 			a password.</para></listitem>
+-- 
+2.7.4
+
diff --git a/SOURCES/0002-Add-computer-name-support-to-realm-join-CLI.patch b/SOURCES/0002-Add-computer-name-support-to-realm-join-CLI.patch
new file mode 100644
index 0000000..c4ceb81
--- /dev/null
+++ b/SOURCES/0002-Add-computer-name-support-to-realm-join-CLI.patch
@@ -0,0 +1,56 @@
+From 92087e73c87b4afc01c32f572d202919cac09d41 Mon Sep 17 00:00:00 2001
+From: Andrew Austin <aaustin@one.verizon.com>
+Date: Sun, 17 Apr 2016 12:52:15 -0500
+Subject: [PATCH 2/3] Add computer-name support to realm join CLI
+
+This exposes the computer-name option on the CLI for use
+when joining an active directory domain.
+
+https://bugs.freedesktop.org/show_bug.cgi?id=93739
+
+Signed-off-by: Stef Walter <stefw@redhat.com>
+ * Squashed fixup patch
+---
+ tools/realm-join.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/tools/realm-join.c b/tools/realm-join.c
+index feb6edc..3685bb9 100644
+--- a/tools/realm-join.c
++++ b/tools/realm-join.c
+@@ -168,6 +168,7 @@ perform_user_join (RealmClient *client,
+ typedef struct {
+ 	gchar *user;
+ 	gchar *computer_ou;
++	gchar *computer_name;
+ 	gchar *client_software;
+ 	gchar *server_software;
+ 	gchar *membership_software;
+@@ -184,6 +185,7 @@ realm_join_args_clear (gpointer data)
+ 	RealmJoinArgs *args = data;
+ 	g_free (args->user);
+ 	g_free (args->computer_ou);
++	g_free (args->computer_name);
+ 	g_free (args->client_software);
+ 	g_free (args->server_software);
+ 	g_free (args->user_principal);
+@@ -238,6 +240,7 @@ perform_join (RealmClient *client,
+ 	}
+ 
+ 	options = realm_build_options (REALM_DBUS_OPTION_COMPUTER_OU, args->computer_ou,
++	                               REALM_DBUS_OPTION_COMPUTER_NAME, args->computer_name,
+ 	                               REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE, args->membership_software,
+ 	                               REALM_DBUS_OPTION_USER_PRINCIPAL, args->user_principal,
+ 	                               args->automatic_id_mapping_set ?
+@@ -283,6 +286,8 @@ realm_join (RealmClient *client,
+ 		  N_("User name to use for enrollment"), NULL },
+ 		{ "computer-ou", 0, 0, G_OPTION_ARG_STRING, &args.computer_ou,
+ 		  N_("Computer OU DN to join"), NULL },
++		{ "computer-name", 0, 0, G_OPTION_ARG_STRING, &args.computer_name,
++			N_("Use specific computer name instead of hostname"), NULL },
+ 		{ "client-software", 0, 0, G_OPTION_ARG_STRING, &args.client_software,
+ 		  N_("Use specific client software"), NULL },
+ 		{ "server-software", 0, 0, G_OPTION_ARG_STRING, &args.server_software,
+-- 
+2.7.4
+
diff --git a/SOURCES/0003-Add-documentation-for-computer-name-setting.patch b/SOURCES/0003-Add-documentation-for-computer-name-setting.patch
new file mode 100644
index 0000000..259581d
--- /dev/null
+++ b/SOURCES/0003-Add-documentation-for-computer-name-setting.patch
@@ -0,0 +1,65 @@
+From 5482e0e3b4e59de0c30b37e7e3ed8b54eff1c493 Mon Sep 17 00:00:00 2001
+From: Andrew Austin <aaustin@one.verizon.com>
+Date: Fri, 22 Apr 2016 00:08:43 +0000
+Subject: [PATCH 3/3] Add documentation for computer-name setting.
+
+https://bugs.freedesktop.org/show_bug.cgi?id=93739
+
+Signed-off-by: Stef Walter <stefw@redhat.com>
+ * Fixed up indentation
+---
+ doc/manual/realmd-guide-active-directory.xml |  5 ++++-
+ doc/manual/realmd.conf.xml                   | 20 ++++++++++++++++++++
+ 2 files changed, 24 insertions(+), 1 deletion(-)
+
+diff --git a/doc/manual/realmd-guide-active-directory.xml b/doc/manual/realmd-guide-active-directory.xml
+index 9b4535d..362cf94 100644
+--- a/doc/manual/realmd-guide-active-directory.xml
++++ b/doc/manual/realmd-guide-active-directory.xml
+@@ -166,7 +166,10 @@ $ <command>getent passwd DOMAIN\Administrator</command>
+ 		<para>The join operation will create or update a computer account
+ 		in the domain. If you wish to specify a specific organizational unit
+ 		where this account is created, you can use the
+-		<link linkend="realmd-conf-active-directory"><option>computer-ou</option> setting</link>.</para>
++		<link linkend="realmd-conf-active-directory"><option>computer-ou</option> setting</link>.
++	        Additonally, you can override the default name for the computer account with the
++		<link linkend="realmd-conf-active-directory"><option>computer-name</option>
++		setting</link>.</para>
+ 
+ 		<para>Specify the <option>--user</option> to choose a different
+ 		user name than the default <literal>Administrator</literal> user.</para>
+diff --git a/doc/manual/realmd.conf.xml b/doc/manual/realmd.conf.xml
+index d9703f6..f8c87b9 100644
+--- a/doc/manual/realmd.conf.xml
++++ b/doc/manual/realmd.conf.xml
+@@ -321,7 +321,27 @@ computer-ou = OU=Linux Computers,DC=domain,DC=example,DC=com
+ 		create a computer account at a specific OU.</para>
+ 	</listitem>
+ 	</varlistentry>
++	<varlistentry>
++	<term><option>computer-name</option></term>
++	<listitem>
++		<para>This option only applied to Active Directory realms. Specify this
++		option to override the default name used when creating the computer
++		account. The system's FQDN will still be saved in the dNSHostName attribute.</para>
++		<informalexample>
++<programlisting language="js">
++[domain.example.com]
++computer-name = SERVER01
++</programlisting>
++		</informalexample>
++
++		<para>Specify the name as a string of 15 or fewer characters that is
++		a valid NetBIOS computer name.</para>
+ 
++		<para>It is also possible to use the <option>--computer-name</option>
++		argument of the <command>realm</command> command to override the default
++		computer account name.</para>
++	</listitem>
++	</varlistentry>
+ 	<varlistentry>
+ 	<term><option>user-prinicpal</option></term>
+ 	<listitem>
+-- 
+2.7.4
+
diff --git a/SOURCES/Fix-invalid-unrefs-on-realm_invocation_get_cancellab.patch b/SOURCES/Fix-invalid-unrefs-on-realm_invocation_get_cancellab.patch
new file mode 100644
index 0000000..b52d6aa
--- /dev/null
+++ b/SOURCES/Fix-invalid-unrefs-on-realm_invocation_get_cancellab.patch
@@ -0,0 +1,37 @@
+From 8b8b7bf8eb651c56d6e85101d9ff277155981cb3 Mon Sep 17 00:00:00 2001
+From: Sumit Bose <sbose@redhat.com>
+Date: Wed, 18 May 2016 14:42:46 +0200
+Subject: [PATCH] Fix invalid unrefs on realm_invocation_get_cancellable()
+ retval
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1330766
+
+Signed-off-by: Stef Walter <stefw@redhat.com>
+---
+ service/realm-packages.c | 3 ---
+ 1 file changed, 3 deletions(-)
+
+diff --git a/service/realm-packages.c b/service/realm-packages.c
+index 321921a..9a6984c 100644
+--- a/service/realm-packages.c
++++ b/service/realm-packages.c
+@@ -479,8 +479,6 @@ on_install_resolved (GObject *source,
+ 			packages_install_async (install->connection,
+ 			                        (const gchar **)package_ids, cancellable,
+ 			                        on_install_installed, g_object_ref (task));
+-			if (cancellable)
+-				g_object_unref (cancellable);
+ 		}
+ 
+ 		g_free (missing);
+@@ -649,7 +647,6 @@ realm_packages_install_async (const gchar **package_sets,
+ 		cancellable = realm_invocation_get_cancellable (install->invocation);
+ 		packages_resolve_async (connection, (const gchar **)install->packages, cancellable,
+ 		                        on_install_resolved, g_object_ref (task));
+-		g_object_unref (cancellable);
+ 	}
+ 
+ 	g_object_unref (task);
+-- 
+2.7.4
+
diff --git a/SOURCES/computer-ou.patch b/SOURCES/computer-ou.patch
new file mode 100644
index 0000000..add7d8c
--- /dev/null
+++ b/SOURCES/computer-ou.patch
@@ -0,0 +1,894 @@
+From 3db35ad73ec57c8af499a0dcef96ffd4da914236 Mon Sep 17 00:00:00 2001
+From: Stef Walter <stefw@redhat.com>
+Date: Mon, 7 Sep 2015 13:49:10 +0200
+Subject: [PATCH 2/2] service: Fully qualify --computer-ou DN before passing to
+ adcli
+
+This allows us to have a similar behavior for both the Samba and
+adcli membership software.
+---
+ service/Makefile.am          |   4 +-
+ service/realm-adcli-enroll.c |  11 +-
+ service/realm-dn-util.c      | 239 +++++++++++++++++++++++++++++++++++++++++++
+ service/realm-dn-util.h      |  32 ++++++
+ service/realm-samba-enroll.c |   4 +-
+ service/realm-samba-util.c   | 172 -------------------------------
+ service/realm-samba-util.h   |  29 ------
+ tests/Makefile.am            |  16 +--
+ tests/test-dn-util.c         | 129 +++++++++++++++++++++++
+ tests/test-samba-ou-format.c |  89 ----------------
+ 11 files changed, 422 insertions(+), 305 deletions(-)
+ create mode 100644 service/realm-dn-util.c
+ create mode 100644 service/realm-dn-util.h
+ delete mode 100644 service/realm-samba-util.c
+ delete mode 100644 service/realm-samba-util.h
+ create mode 100644 tests/test-dn-util.c
+ delete mode 100644 tests/test-samba-ou-format.c
+
+diff --git a/service/Makefile.am b/service/Makefile.am
+index 06a95ef..88ee780 100644
+--- a/service/Makefile.am
++++ b/service/Makefile.am
+@@ -43,6 +43,8 @@ realmd_SOURCES = \
+ 	service/realm-disco-mscldap.h \
+ 	service/realm-disco-rootdse.c \
+ 	service/realm-disco-rootdse.h \
++	service/realm-dn-util.c \
++	service/realm-dn-util.h \
+ 	service/realm-errors.c \
+ 	service/realm-errors.h \
+ 	service/realm-example.c \
+@@ -79,8 +81,6 @@ realmd_SOURCES = \
+ 	service/realm-samba-enroll.h \
+ 	service/realm-samba-provider.c \
+ 	service/realm-samba-provider.h \
+-	service/realm-samba-util.c \
+-	service/realm-samba-util.h \
+ 	service/realm-samba-winbind.c \
+ 	service/realm-samba-winbind.h \
+ 	service/realm-service.c \
+diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c
+index 7448647..ef1b563 100644
+--- a/service/realm-adcli-enroll.c
++++ b/service/realm-adcli-enroll.c
+@@ -18,6 +18,7 @@
+ #include "realm-command.h"
+ #include "realm-daemon.h"
+ #include "realm-diagnostics.h"
++#include "realm-dn-util.h"
+ #include "realm-errors.h"
+ #include "realm-ini-config.h"
+ #include "realm-options.h"
+@@ -82,6 +83,7 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 	gchar *ccache_arg = NULL;
+ 	gchar *upn_arg = NULL;
+ 	gchar *server_arg = NULL;
++	gchar *ou_arg = NULL;
+ 
+ 	g_return_if_fail (cred != NULL);
+ 	g_return_if_fail (disco != NULL);
+@@ -120,9 +122,13 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 	}
+ 
+ 	computer_ou = realm_options_computer_ou (options, disco->domain_name);
+-	if (computer_ou) {
++	if (computer_ou != NULL) {
++		ou_arg = realm_dn_util_build_qualified (computer_ou, disco->domain_name);
+ 		g_ptr_array_add (args, "--computer-ou");
+-		g_ptr_array_add (args, (gpointer)computer_ou);
++		if (ou_arg)
++			g_ptr_array_add (args, ou_arg);
++		else
++			g_ptr_array_add (args, (gpointer)computer_ou);
+ 	}
+ 
+ 	os = realm_settings_value ("active-directory", "os-name");
+@@ -190,6 +196,7 @@ realm_adcli_enroll_join_async (RealmDisco *disco,
+ 	free (ccache_arg);
+ 	free (upn_arg);
+ 	free (server_arg);
++	free (ou_arg);
+ }
+ 
+ gboolean
+diff --git a/service/realm-dn-util.c b/service/realm-dn-util.c
+new file mode 100644
+index 0000000..85bcdb9
+--- /dev/null
++++ b/service/realm-dn-util.c
+@@ -0,0 +1,239 @@
++/* realmd -- Realm configuration service
++ *
++ * Copyright 2012 Red Hat Inc
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License as published
++ * by the Free Software Foundation; either version 2 of the licence or (at
++ * your option) any later version.
++ *
++ * See the included COPYING file for more information.
++ *
++ * Author: Stef Walter <stefw@gnome.org>
++ */
++
++#include "config.h"
++
++#include "realm-dn-util.h"
++
++#include <glib.h>
++
++#include <ldap.h>
++
++static gboolean
++berval_is_string (const struct berval *bv,
++                  const gchar *string,
++                  gsize length)
++{
++	return (bv->bv_len == length &&
++	        g_ascii_strncasecmp (bv->bv_val, string, length) == 0);
++
++}
++
++static gboolean
++berval_case_equals (const struct berval *v1,
++                    const struct berval *v2)
++{
++	return (v1->bv_len == v2->bv_len &&
++	        g_ascii_strncasecmp (v1->bv_val, v2->bv_val, v1->bv_len) == 0);
++}
++
++static gboolean
++dn_equals_domain (LDAPDN dn,
++                  const gchar *domain_dn_str,
++                  const gchar *domain)
++{
++	LDAPDN domain_dn;
++	gboolean ret;
++	int rc;
++	gint i, j;
++
++	rc = ldap_str2dn (domain_dn_str, &domain_dn, LDAP_DN_FORMAT_LDAPV3);
++	g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
++
++	for (i = 0; dn[i] != NULL && domain_dn[i] != NULL; i++) {
++		for (j = 0; dn[i][j] != NULL && domain_dn[i][j] != NULL; j++) {
++			if (!berval_case_equals (&(dn[i][j]->la_attr), &(domain_dn[i][j]->la_attr)) ||
++			    !berval_case_equals (&(dn[i][j]->la_value), &(domain_dn[i][j]->la_value)))
++				break;
++		}
++
++		if (dn[i][j] != NULL && domain_dn[i][j] != NULL)
++			break;
++	}
++
++	/* Did we reach end of both DNs? */
++	ret = (dn[i] == NULL && domain_dn[i] == NULL);
++
++	ldap_dnfree (domain_dn);
++
++	return ret;
++}
++
++gchar *
++realm_dn_util_build_samba_ou (const gchar *ldap_dn,
++                              const gchar *domain)
++{
++	gchar *domain_dn_str = NULL;
++	GArray *parts;
++	GString *part;
++	gchar **strv;
++	gchar *str;
++	LDAPAVA* ava;
++	gboolean ret;
++	LDAPDN dn;
++	int rc;
++	gint i, j;
++
++	/*
++	 * Here we convert a standard LDAP DN to the strange samba net format,
++	 * as "documented" here:
++	 *
++	 * createcomputer=OU  Precreate the computer account in a specific OU.
++	 *                    The OU string read from top to bottom without RDNs and delimited by a '/'.
++	 *                    E.g. "createcomputer=Computers/Servers/Unix"
++	 *                    NB: A backslash '\' is used as escape at multiple levels and may
++	 *                        need to be doubled or even quadrupled.  It is not used as a separator.
++	 */
++
++	/* ldap_str2dn doesn't like empty strings */
++	while (g_ascii_isspace (ldap_dn[0]))
++		ldap_dn++;
++	if (g_str_equal (ldap_dn, ""))
++		return NULL;
++
++	rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
++	if (rc != LDAP_SUCCESS)
++		return NULL;
++
++	ret = TRUE;
++	parts = g_array_new (TRUE, TRUE, sizeof (gchar *));
++
++	for (i = 0; dn[i] != NULL; i++) {
++		ava = dn[i][0];
++
++		/*
++		 * Make sure this is a valid DN, we only support one value per
++		 * RDN, string values, and must be an OU. DC values are allowed
++		 * but only at the end of the DN.
++		 */
++
++		if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
++			ret = FALSE;
++			break;
++
++		/* A DC, remainder must match the domain */
++		} else if (berval_is_string (&ava->la_attr, "DC", 2)) {
++			rc = ldap_domain2dn (domain, &domain_dn_str);
++			if (rc != LDAP_SUCCESS)
++				ret = FALSE;
++			else
++				ret = dn_equals_domain (dn + i, domain_dn_str, domain);
++			break;
++
++		/* An OU, include */
++		} else if (berval_is_string (&ava->la_attr, "OU", 2)) {
++			part = g_string_sized_new (ava->la_value.bv_len);
++			for (j = 0; j < ava->la_value.bv_len; j++) {
++				switch (ava->la_value.bv_val[j]) {
++				case '\\':
++					g_string_append (part, "\\\\");
++					break;
++				case '/':
++					g_string_append (part, "\\/");
++					break;
++				default:
++					g_string_append_c (part, ava->la_value.bv_val[j]);
++					break;
++				}
++			}
++			str = g_string_free (part, FALSE);
++			g_array_insert_val (parts, 0, str);
++
++		/* Invalid, stop */
++		} else {
++			ret = FALSE;
++			break;
++		}
++	}
++
++	ldap_dnfree (dn);
++	if (domain_dn_str)
++		ldap_memfree (domain_dn_str);
++
++	strv = (gchar **)g_array_free (parts, FALSE);
++	str = NULL;
++
++	/* Loop completed successfully */
++	if (ret)
++		str = g_strjoinv ("/", strv);
++
++	g_strfreev (strv);
++
++	return str;
++}
++
++gchar *
++realm_dn_util_build_qualified (const gchar *ldap_dn,
++                               const gchar *domain)
++{
++	gchar *domain_dn_str = NULL;
++	gboolean had_dc = FALSE;
++	gchar *str;
++	LDAPAVA* ava;
++	gboolean ret;
++	LDAPDN dn;
++	int rc;
++	gint i;
++
++	/* ldap_str2dn doesn't like empty strings */
++	while (g_ascii_isspace (ldap_dn[0]))
++		ldap_dn++;
++	if (g_str_equal (ldap_dn, ""))
++		return NULL;
++
++	rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
++	if (rc != LDAP_SUCCESS)
++		return NULL;
++
++	rc = ldap_domain2dn (domain, &domain_dn_str);
++	if (rc != LDAP_SUCCESS) {
++		ldap_dnfree (dn);
++		return NULL;
++	}
++
++	ret = TRUE;
++
++	for (i = 0; dn[i] != NULL; i++) {
++		ava = dn[i][0];
++
++		/*
++		 * Make sure this is a valid DN, we only support one value per
++		 * RDN, string values. DC values are allowed but only at the end of the DN.
++		 */
++
++		if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
++			ret = FALSE;
++			break;
++
++		/* A DC, remainder must match the domain */
++		} else if (berval_is_string (&ava->la_attr, "DC", 2)) {
++			had_dc = TRUE;
++			ret = dn_equals_domain (dn + i, domain_dn_str, domain);
++			break;
++		}
++	}
++
++	ldap_dnfree (dn);
++
++	if (!ret)
++		return NULL;
++
++	if (had_dc)
++		str = g_strdup (ldap_dn);
++	else
++		str = g_strdup_printf ("%s,%s", ldap_dn, domain_dn_str);
++
++	ldap_memfree (domain_dn_str);
++	return str;
++}
+diff --git a/service/realm-dn-util.h b/service/realm-dn-util.h
+new file mode 100644
+index 0000000..f5e5e69
+--- /dev/null
++++ b/service/realm-dn-util.h
+@@ -0,0 +1,32 @@
++/* realmd -- Realm configuration service
++ *
++ * Copyright 2012 Red Hat Inc
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License as published
++ * by the Free Software Foundation; either version 2 of the licence or (at
++ * your option) any later version.
++ *
++ * See the included COPYING file for more information.
++ *
++ * Author: Stef Walter <stefw@gnome.org>
++ */
++
++#include "config.h"
++
++#ifndef __REALM_DN_UTIL_H__
++#define __REALM_DN_UTIL_H__
++
++#include <gio/gio.h>
++
++G_BEGIN_DECLS
++
++gchar *           realm_dn_util_build_samba_ou     (const gchar *ldap_dn,
++                                                    const gchar *domain);
++
++gchar *           realm_dn_util_build_qualified    (const gchar *ldap_dn,
++                                                    const gchar *domain);
++
++G_END_DECLS
++
++#endif /* __REALM_DN_UTIL_H__ */
+diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c
+index e8739d7..e749764 100644
+--- a/service/realm-samba-enroll.c
++++ b/service/realm-samba-enroll.c
+@@ -18,12 +18,12 @@
+ #include "realm-daemon.h"
+ #include "realm-dbus-constants.h"
+ #include "realm-diagnostics.h"
++#include "realm-dn-util.h"
+ #include "realm-errors.h"
+ #include "realm-options.h"
+ #include "realm-samba-config.h"
+ #include "realm-samba-enroll.h"
+ #include "realm-samba-provider.h"
+-#include "realm-samba-util.h"
+ #include "realm-settings.h"
+ 
+ #include <glib/gstdio.h>
+@@ -314,7 +314,7 @@ begin_join (GTask *task,
+ 
+ 	computer_ou = realm_options_computer_ou (options, join->disco->domain_name);
+ 	if (computer_ou != NULL) {
+-		strange_ou = realm_samba_util_build_strange_ou (computer_ou, join->disco->domain_name);
++		strange_ou = realm_dn_util_build_samba_ou (computer_ou, join->disco->domain_name);
+ 		if (strange_ou) {
+ 			if (!g_str_equal (strange_ou, ""))
+ 				join->join_args[at++] = g_strdup_printf ("createcomputer=%s", strange_ou);
+diff --git a/service/realm-samba-util.c b/service/realm-samba-util.c
+deleted file mode 100644
+index 3f6a53e..0000000
+--- a/service/realm-samba-util.c
++++ /dev/null
+@@ -1,172 +0,0 @@
+-/* realmd -- Realm configuration service
+- *
+- * Copyright 2012 Red Hat Inc
+- *
+- * This program is free software: you can redistribute it and/or modify
+- * it under the terms of the GNU Lesser General Public License as published
+- * by the Free Software Foundation; either version 2 of the licence or (at
+- * your option) any later version.
+- *
+- * See the included COPYING file for more information.
+- *
+- * Author: Stef Walter <stefw@gnome.org>
+- */
+-
+-#include "config.h"
+-
+-#include "realm-samba-util.h"
+-
+-#include <glib.h>
+-
+-#include <ldap.h>
+-
+-static gboolean
+-berval_is_string (const struct berval *bv,
+-                  const gchar *string,
+-                  gsize length)
+-{
+-	return (bv->bv_len == length &&
+-	        g_ascii_strncasecmp (bv->bv_val, string, length) == 0);
+-
+-}
+-
+-static gboolean
+-berval_case_equals (const struct berval *v1,
+-                    const struct berval *v2)
+-{
+-	return (v1->bv_len == v2->bv_len &&
+-	        g_ascii_strncasecmp (v1->bv_val, v2->bv_val, v1->bv_len) == 0);
+-}
+-
+-static gboolean
+-dn_equals_domain (LDAPDN dn,
+-                  const gchar *domain)
+-{
+-	LDAPDN domain_dn;
+-	gchar *domain_dn_str;
+-	gboolean ret;
+-	int rc;
+-	gint i, j;
+-
+-	rc = ldap_domain2dn (domain, &domain_dn_str);
+-	g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
+-
+-	rc = ldap_str2dn (domain_dn_str, &domain_dn, LDAP_DN_FORMAT_LDAPV3);
+-	g_return_val_if_fail (rc == LDAP_SUCCESS, FALSE);
+-
+-	ldap_memfree (domain_dn_str);
+-
+-	for (i = 0; dn[i] != NULL && domain_dn[i] != NULL; i++) {
+-		for (j = 0; dn[i][j] != NULL && domain_dn[i][j] != NULL; j++) {
+-			if (!berval_case_equals (&(dn[i][j]->la_attr), &(domain_dn[i][j]->la_attr)) ||
+-			    !berval_case_equals (&(dn[i][j]->la_value), &(domain_dn[i][j]->la_value)))
+-				break;
+-		}
+-
+-		if (dn[i][j] != NULL && domain_dn[i][j] != NULL)
+-			break;
+-	}
+-
+-	/* Did we reach end of both DNs? */
+-	ret = (dn[i] == NULL && domain_dn[i] == NULL);
+-
+-	ldap_dnfree (domain_dn);
+-
+-	return ret;
+-}
+-
+-gchar *
+-realm_samba_util_build_strange_ou (const gchar *ldap_dn,
+-                                   const gchar *domain)
+-{
+-	GArray *parts;
+-	GString *part;
+-	gchar **strv;
+-	gchar *str;
+-	LDAPAVA* ava;
+-	gboolean ret;
+-	LDAPDN dn;
+-	int rc;
+-	gint i, j;
+-
+-	/*
+-	 * Here we convert a standard LDAP DN to the strange samba net format,
+-	 * as "documented" here:
+-	 *
+-	 * createcomputer=OU  Precreate the computer account in a specific OU.
+-	 *                    The OU string read from top to bottom without RDNs and delimited by a '/'.
+-	 *                    E.g. "createcomputer=Computers/Servers/Unix"
+-	 *                    NB: A backslash '\' is used as escape at multiple levels and may
+-	 *                        need to be doubled or even quadrupled.  It is not used as a separator.
+-	 */
+-
+-	/* ldap_str2dn doesn't like empty strings */
+-	while (g_ascii_isspace (ldap_dn[0]))
+-		ldap_dn++;
+-	if (g_str_equal (ldap_dn, ""))
+-		return NULL;
+-
+-	rc = ldap_str2dn (ldap_dn, &dn, LDAP_DN_FORMAT_LDAPV3);
+-	if (rc != LDAP_SUCCESS)
+-		return NULL;
+-
+-	ret = TRUE;
+-	parts = g_array_new (TRUE, TRUE, sizeof (gchar *));
+-
+-	for (i = 0; dn[i] != NULL; i++) {
+-		ava = dn[i][0];
+-
+-		/*
+-		 * Make sure this is a valid DN, we only support one value per
+-		 * RDN, string values, and must be an OU. DC values are allowed
+-		 * but only at the end of the DN.
+-		 */
+-
+-		if (ava == NULL || dn[i][1] != NULL || !(ava->la_flags & LDAP_AVA_STRING)) {
+-			ret = FALSE;
+-			break;
+-
+-		/* A DC, remainder must match the domain */
+-		} else if (berval_is_string (&ava->la_attr, "DC", 2)) {
+-			ret = dn_equals_domain (dn + i, domain);
+-			break;
+-
+-		/* An OU, include */
+-		} else if (berval_is_string (&ava->la_attr, "OU", 2)) {
+-			part = g_string_sized_new (ava->la_value.bv_len);
+-			for (j = 0; j < ava->la_value.bv_len; j++) {
+-				switch (ava->la_value.bv_val[j]) {
+-				case '\\':
+-					g_string_append (part, "\\\\");
+-					break;
+-				case '/':
+-					g_string_append (part, "\\/");
+-					break;
+-				default:
+-					g_string_append_c (part, ava->la_value.bv_val[j]);
+-					break;
+-				}
+-			}
+-			str = g_string_free (part, FALSE);
+-			g_array_insert_val (parts, 0, str);
+-
+-		/* Invalid, stop */
+-		} else {
+-			ret = FALSE;
+-			break;
+-		}
+-	}
+-
+-	ldap_dnfree (dn);
+-
+-	strv = (gchar **)g_array_free (parts, FALSE);
+-	str = NULL;
+-
+-	/* Loop completed successfully */
+-	if (ret)
+-		str = g_strjoinv ("/", strv);
+-
+-	g_strfreev (strv);
+-
+-	return str;
+-}
+diff --git a/service/realm-samba-util.h b/service/realm-samba-util.h
+deleted file mode 100644
+index 2a680e7..0000000
+--- a/service/realm-samba-util.h
++++ /dev/null
+@@ -1,29 +0,0 @@
+-/* realmd -- Realm configuration service
+- *
+- * Copyright 2012 Red Hat Inc
+- *
+- * This program is free software: you can redistribute it and/or modify
+- * it under the terms of the GNU Lesser General Public License as published
+- * by the Free Software Foundation; either version 2 of the licence or (at
+- * your option) any later version.
+- *
+- * See the included COPYING file for more information.
+- *
+- * Author: Stef Walter <stefw@gnome.org>
+- */
+-
+-#include "config.h"
+-
+-#ifndef __REALM_SAMBA_UTIL_H__
+-#define __REALM_SAMBA_UTIL_H__
+-
+-#include <gio/gio.h>
+-
+-G_BEGIN_DECLS
+-
+-gchar *           realm_samba_util_build_strange_ou   (const gchar *ldap_dn,
+-                                                       const gchar *suffix_dn);
+-
+-G_END_DECLS
+-
+-#endif /* __REALM_SAMBA_UTIL_H__ */
+diff --git a/tests/Makefile.am b/tests/Makefile.am
+index ddeba4d..3b05066 100644
+--- a/tests/Makefile.am
++++ b/tests/Makefile.am
+@@ -12,11 +12,11 @@ TEST_LIBS = \
+ 	$(GLIB_LIBS)
+ 
+ TEST_PROGS = \
++	test-dn-util \
+ 	test-ini-config \
+ 	test-sssd-config \
+ 	test-safe-format \
+ 	test-login-name \
+-	test-samba-ou-format \
+ 	test-settings \
+ 	$(NULL)
+ 
+@@ -27,6 +27,13 @@ noinst_PROGRAMS +=  \
+ 	frob-install-packages \
+ 	$(NULL)
+ 
++test_dn_util_SOURCES = \
++	tests/test-dn-util.c \
++	service/realm-dn-util.c \
++	$(NULL)
++test_dn_util_LDADD = $(TEST_LIBS)
++test_dn_util_CFLAGS = $(TEST_CFLAGS)
++
+ test_ini_config_SOURCES = \
+ 	tests/test-ini-config.c \
+ 	service/realm-ini-config.c \
+@@ -59,13 +66,6 @@ test_login_name_SOURCES = \
+ test_login_name_LDADD = $(TEST_LIBS)
+ test_login_name_CFLAGS = $(TEST_CFLAGS)
+ 
+-test_samba_ou_format_SOURCES = \
+-	tests/test-samba-ou-format.c \
+-	service/realm-samba-util.c \
+-	$(NULL)
+-test_samba_ou_format_LDADD = $(TEST_LIBS)
+-test_samba_ou_format_CFLAGS = $(TEST_CFLAGS)
+-
+ test_settings_SOURCES = \
+ 	tests/test-settings.c \
+ 	service/realm-settings.c \
+diff --git a/tests/test-dn-util.c b/tests/test-dn-util.c
+new file mode 100644
+index 0000000..c62a40f
+--- /dev/null
++++ b/tests/test-dn-util.c
+@@ -0,0 +1,129 @@
++/* realmd -- Realm configuration service
++ *
++ * Copyright 2012 Red Hat Inc
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU Lesser General Public License as published
++ * by the Free Software Foundation; either version 2 of the licence or (at
++ * your option) any later version.
++ *
++ * See the included COPYING file for more information.
++ *
++ * Author: Stef Walter <stefw@gnome.org>
++ */
++
++#include "config.h"
++
++#include "service/realm-dn-util.h"
++
++#include <glib/gstdio.h>
++
++#include <string.h>
++
++typedef struct {
++	const gchar *ldap_dn;
++	const gchar *domain;
++	const gchar *result;
++} Fixture;
++
++static void
++test_samba_ou_format (gconstpointer user_data)
++{
++	const Fixture *fixture = user_data;
++	gchar *result;
++
++	result = realm_dn_util_build_samba_ou (fixture->ldap_dn, fixture->domain);
++	g_assert_cmpstr (result, ==, fixture->result);
++	g_free (result);
++}
++
++static const Fixture samba_ou_fixtures[] = {
++	{ "OU=One", "domain.example.com", "One" },
++	{ "OU=One,ou=two", "domain.example.com", "two/One" },
++	{ "Ou=One Long,OU=two", "domain.example.com", "two/One Long" },
++	{ "Ou=One,OU=two, ou=Three", "domain.example.com", "Three/two/One" },
++	{ "Ou=Test/Escape,Ou=Two", "domain.example.com", "Two/Test\\/Escape" },
++	{ "Ou=Test\\\\Escape,Ou=Two", "domain.example.com", "Two/Test\\\\Escape" },
++	{ "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "One" },
++	{ "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM", "domain.example.com", "Two Here/One" },
++	{ "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
++	{ " ", "domain.example.com", NULL },
++	{ "", "domain.example.com", NULL },
++	{ "OU", "domain.example.com", NULL },
++	{ "OU=One,", "domain.example.com", NULL },
++	{ "CN=Unsupported", "domain.example.com", NULL },
++	{ "OU=One+CN=Unsupported", "domain.example.com", NULL },
++	{ "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
++
++};
++
++static void
++test_qualify_dn (gconstpointer user_data)
++{
++	const Fixture *fixture = user_data;
++	gchar *result;
++
++	result = realm_dn_util_build_qualified (fixture->ldap_dn, fixture->domain);
++	g_assert_cmpstr (result, ==, fixture->result);
++	g_free (result);
++}
++
++static const Fixture qualify_fixtures[] = {
++	{ "OU=One", "domain.example.com", "OU=One,dc=domain,dc=example,dc=com" },
++	{ "OU=One,ou=two", "domain.example.com", "OU=One,ou=two,dc=domain,dc=example,dc=com" },
++	{ "Ou=One Long,OU=two", "domain.example.com", "Ou=One Long,OU=two,dc=domain,dc=example,dc=com" },
++	{ "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "OU=One,DC=domain,dc=example,Dc=COM" },
++	{ "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" },
++	{ "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
++	{ " ", "domain.example.com", NULL },
++	{ "", "domain.example.com", NULL },
++	{ "OU", "domain.example.com", NULL },
++	{ "OU=One,", "domain.example.com", NULL },
++	{ "CN=Test", "domain.example.com", "CN=Test,dc=domain,dc=example,dc=com" },
++	{ "OU=One+CN=Unsupported", "domain.example.com", NULL },
++	{ "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
++};
++
++int
++main (int argc,
++      char **argv)
++{
++	gchar *escaped;
++	gchar *name;
++	gint i;
++
++#if !GLIB_CHECK_VERSION(2, 36, 0)
++	g_type_init ();
++#endif
++
++	g_test_init (&argc, &argv, NULL);
++	g_set_prgname ("test-dn-util");
++
++	for (i = 0; i < G_N_ELEMENTS (samba_ou_fixtures); i++) {
++		if (g_str_equal (samba_ou_fixtures[i].ldap_dn, ""))
++			escaped = g_strdup ("_empty_");
++		else
++			escaped = g_strdup (samba_ou_fixtures[i].ldap_dn);
++		g_strdelimit (escaped, ", =\\/", '_');
++		name = g_strdup_printf ("/realmd/samba-ou-format/%s", escaped);
++		g_free (escaped);
++
++		g_test_add_data_func (name, samba_ou_fixtures + i, test_samba_ou_format);
++		g_free (name);
++	}
++
++	for (i = 0; i < G_N_ELEMENTS (qualify_fixtures); i++) {
++		if (g_str_equal (qualify_fixtures[i].ldap_dn, ""))
++			escaped = g_strdup ("_empty_");
++		else
++			escaped = g_strdup (qualify_fixtures[i].ldap_dn);
++		g_strdelimit (escaped, ", =\\/", '_');
++		name = g_strdup_printf ("/realmd/qualify-dn/%s", escaped);
++		g_free (escaped);
++
++		g_test_add_data_func (name, qualify_fixtures + i, test_qualify_dn);
++		g_free (name);
++	}
++
++	return g_test_run ();
++}
+diff --git a/tests/test-samba-ou-format.c b/tests/test-samba-ou-format.c
+deleted file mode 100644
+index 0a482ee..0000000
+--- a/tests/test-samba-ou-format.c
++++ /dev/null
+@@ -1,89 +0,0 @@
+-/* realmd -- Realm configuration service
+- *
+- * Copyright 2012 Red Hat Inc
+- *
+- * This program is free software: you can redistribute it and/or modify
+- * it under the terms of the GNU Lesser General Public License as published
+- * by the Free Software Foundation; either version 2 of the licence or (at
+- * your option) any later version.
+- *
+- * See the included COPYING file for more information.
+- *
+- * Author: Stef Walter <stefw@gnome.org>
+- */
+-
+-#include "config.h"
+-
+-#include "service/realm-samba-util.h"
+-
+-#include <glib/gstdio.h>
+-
+-#include <string.h>
+-
+-typedef struct {
+-	const gchar *ldap_dn;
+-	const gchar *domain;
+-	const gchar *ou_format;
+-} Fixture;
+-
+-static void
+-test_samba_ou_format (gconstpointer user_data)
+-{
+-	const Fixture *fixture = user_data;
+-	gchar *result;
+-
+-	result = realm_samba_util_build_strange_ou (fixture->ldap_dn, fixture->domain);
+-	g_assert_cmpstr (result, ==, fixture->ou_format);
+-	g_free (result);
+-}
+-
+-static const Fixture samba_ou_fixtures[] = {
+-	{ "OU=One", "domain.example.com", "One" },
+-	{ "OU=One,ou=two", "domain.example.com", "two/One" },
+-	{ "Ou=One Long,OU=two", "domain.example.com", "two/One Long" },
+-	{ "Ou=One,OU=two, ou=Three", "domain.example.com", "Three/two/One" },
+-	{ "Ou=Test/Escape,Ou=Two", "domain.example.com", "Two/Test\\/Escape" },
+-	{ "Ou=Test\\\\Escape,Ou=Two", "domain.example.com", "Two/Test\\\\Escape" },
+-	{ "OU=One,DC=domain,dc=example,Dc=COM", "domain.example.com", "One" },
+-	{ "OU=One,OU=Two Here,DC=domain,dc=example,Dc=COM", "domain.example.com", "Two Here/One" },
+-	{ "OU=One,OU=Two Here,DC=invalid,Dc=COM", "domain.example.com", NULL },
+-	{ " ", "domain.example.com", NULL },
+-	{ "", "domain.example.com", NULL },
+-	{ "OU", "domain.example.com", NULL },
+-	{ "OU=One,", "domain.example.com", NULL },
+-	{ "CN=Unsupported", "domain.example.com", NULL },
+-	{ "OU=One+CN=Unsupported", "domain.example.com", NULL },
+-	{ "DC=radi07, DC=segad, DC=lab, DC=sjc, DC=redhat, DC=com", "radi08.segad.lab.sjc.redhat.com", NULL },
+-
+-};
+-
+-int
+-main (int argc,
+-      char **argv)
+-{
+-	gchar *escaped;
+-	gchar *name;
+-	gint i;
+-
+-#if !GLIB_CHECK_VERSION(2, 36, 0)
+-	g_type_init ();
+-#endif
+-
+-	g_test_init (&argc, &argv, NULL);
+-	g_set_prgname ("test-samba-ou-format");
+-
+-	for (i = 0; i < G_N_ELEMENTS (samba_ou_fixtures); i++) {
+-		if (g_str_equal (samba_ou_fixtures[i].ldap_dn, ""))
+-			escaped = g_strdup ("_empty_");
+-		else
+-			escaped = g_strdup (samba_ou_fixtures[i].ldap_dn);
+-		g_strdelimit (escaped, ", =\\/", '_');
+-		name = g_strdup_printf ("/realmd/samba-ou-format/%s", escaped);
+-		g_free (escaped);
+-
+-		g_test_add_data_func (name, samba_ou_fixtures + i, test_samba_ou_format);
+-		g_free (name);
+-	}
+-
+-	return g_test_run ();
+-}
+-- 
+2.7.4
+
diff --git a/SOURCES/install-diagnostic.patch b/SOURCES/install-diagnostic.patch
new file mode 100644
index 0000000..d75bdff
--- /dev/null
+++ b/SOURCES/install-diagnostic.patch
@@ -0,0 +1,29 @@
+From ef0797e5ed116a98cc074a6d4e1d1d6b6e6384db Mon Sep 17 00:00:00 2001
+From: Stef Walter <stefw@redhat.com>
+Date: Mon, 7 Sep 2015 12:53:02 +0200
+Subject: [PATCH 1/2] service: Fix issue where diagnostics about package
+ install hidden
+
+Due to the recent refactoring the diagnostics about package
+installation were hidden (even when --verbose).
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1258745
+---
+ service/realm-packages.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/service/realm-packages.c b/service/realm-packages.c
+index 9da852c..321921a 100644
+--- a/service/realm-packages.c
++++ b/service/realm-packages.c
+@@ -615,6 +615,7 @@ realm_packages_install_async (const gchar **package_sets,
+ 	task = g_task_new (NULL, NULL, callback, user_data);
+ 	install = g_new0 (InstallClosure, 1);
+ 	install->automatic = realm_options_automatic_install ();
++	install->invocation = invocation ? g_object_ref (invocation) : NULL;
+ 	install->connection = g_object_ref (connection);
+ 	g_task_set_task_data (task, install, install_closure_free);
+ 
+-- 
+2.7.4
+
diff --git a/SOURCES/net-in-samba-common.patch b/SOURCES/net-in-samba-common.patch
deleted file mode 100644
index 6903373..0000000
--- a/SOURCES/net-in-samba-common.patch
+++ /dev/null
@@ -1,27 +0,0 @@
-From 3d510c6a42ce2fa8e00b6e36487a6e7c7047b0d6 Mon Sep 17 00:00:00 2001
-From: Stef Walter <stefw@redhat.com>
-Date: Tue, 14 Jul 2015 20:40:04 +0200
-Subject: [PATCH] Revert "service: /usr/bin/net is provided by
- samba-common-tools"
-
-This reverts commit ccb21883a515f17e8a4f6076a585450e20bcd933.
----
- service/realmd-redhat.conf | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git a/service/realmd-redhat.conf b/service/realmd-redhat.conf
-index e39fad5..e0bfbf5 100644
---- a/service/realmd-redhat.conf
-+++ b/service/realmd-redhat.conf
-@@ -3,7 +3,7 @@
- smb.conf = /etc/samba/smb.conf
- 
- [samba-packages]
--samba-common-tools = /usr/bin/net
-+samba-common = /usr/bin/net
- 
- [winbind-packages]
- samba-winbind = /usr/sbin/winbindd
--- 
-2.4.3
-
diff --git a/SPECS/realmd.spec b/SPECS/realmd.spec
index 0a9df5a..3a46971 100644
--- a/SPECS/realmd.spec
+++ b/SPECS/realmd.spec
@@ -1,20 +1,29 @@
 Name:		realmd
 Version:	0.16.1
-Release:	5%{?dist}
+Release:	9%{?dist}
 Summary:	Kerberos realm enrollment service
 License:	LGPLv2+
 URL:		http://cgit.freedesktop.org/realmd/realmd/
 Source0:	http://www.freedesktop.org/software/realmd/releases/realmd-%{version}.tar.gz
 
 Patch0:         ipa-packages.patch
-Patch1:		net-in-samba-common.patch
 Patch2:		remove-spurious-print.patch
 Patch3:         increase-packagekit-timeout.patch
 Patch4:         dns-domain-name-liberal.patch
 
+Patch11:        install-diagnostic.patch
+Patch12:        computer-ou.patch
 Patch13:        duplicate-test-path.patch
 
 Patch20:        samba-by-default.patch
+Patch21:        Fix-invalid-unrefs-on-realm_invocation_get_cancellab.patch
+Patch22:        0001-Support-manually-setting-computer-name.patch
+Patch23:        0002-Add-computer-name-support-to-realm-join-CLI.patch
+Patch24:        0003-Add-documentation-for-computer-name-setting.patch
+Patch25:        0001-Make-DBus-aware-of-systemd.patch
+Patch26:        0001-Add-os-name-and-os-version-command-line-options.patch
+Patch27:        0001-doc-add-computer-name-to-realm-man-page.patch
+Patch28:        0001-Fix-man-page-reference-in-systemd-service-file.patch
 
 BuildRequires:  automake
 BuildRequires:  autoconf
@@ -49,12 +58,21 @@ applications that use %{name}.
 %prep
 %setup -q
 %patch0 -p1
-%patch1 -p1
 %patch2 -p1
 %patch3 -p1
 %patch4 -p1
+%patch11 -p1
+%patch12 -p1
 %patch13 -p1
 %patch20 -p1
+%patch21 -p1
+%patch22 -p1
+%patch23 -p1
+%patch24 -p1
+%patch25 -p1
+%patch26 -p1
+%patch27 -p1
+%patch28 -p1
 
 %build
 aclocal
@@ -71,6 +89,15 @@ make install DESTDIR=%{buildroot}
 
 %find_lang realmd
 
+%post
+%systemd_post realmd.service
+
+%preun
+%systemd_preun realmd.service
+
+%postun
+%systemd_postun_with_restart realmd.service
+
 %files -f realmd.lang
 %doc AUTHORS COPYING NEWS README
 %{_sysconfdir}/dbus-1/system.d/org.freedesktop.realmd.conf
@@ -91,6 +118,27 @@ make install DESTDIR=%{buildroot}
 %doc ChangeLog
 
 %changelog
+* Wed Sep 07 2016 Sumit Bose <sbose@redhat.com> - 0.16.1-9
+Rebuild to fix wrong doc path
+- Resolves: rhbz#1360702
+
+* Wed Jul 27 2016 Sumit Bose <sbose@redhat.com> - 0.16.1-8
+Fix man page reference in systemd service file
+- Resolves: rhbz#1360702
+
+* Mon Jul 25 2016 Sumit Bose <sbose@redhat.com> - 0.16.1-7
+doc: add computer-name to realm man page
+- Related: rhbz#1293390
+
+* Tue Jun 28 2016 Sumit Bose <sbose@redhat.com> - 0.16.1-6
+- Resolves: rhbz#1258745
+- Resolves: rhbz#1258488
+- Resolves: rhbz#1267563
+- Resolves: rhbz#1293390
+- Resolves: rhbz#1273924
+- Resolves: rhbz#1274368
+- Resolves: rhbz#1291924
+
 * Fri Oct 16 2015 Stef Walter <stefw@redhat.com> - 0.16.1-5
 - Revert 0.16.1-4
 - Use samba by default