From 771dd0fb254f8cbf059a7f605bb0de0f9a3b7911 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 11 Apr 2013 16:37:04 +0200 Subject: [PATCH] Add the user-principal option and setting https://bugs.freedesktop.org/show_bug.cgi?id=62755 --- dbus/realm-dbus-constants.h | 1 + doc/manual/realmd-guide-configuring.xml | 16 ++++++++++++++++ service/realm-adcli-enroll.c | 22 ++++++++++++++++++---- service/realm-options.c | 11 +++++++++++ service/realm-options.h | 2 ++ service/realm-samba-enroll.c | 10 ++++++++++ service/realmd-defaults.conf | 1 + tools/realm-join.c | 5 +++++ 8 files changed, 64 insertions(+), 4 deletions(-) diff --git a/dbus/realm-dbus-constants.h b/dbus/realm-dbus-constants.h index c2797f6..ff1fa64 100644 --- a/dbus/realm-dbus-constants.h +++ b/dbus/realm-dbus-constants.h @@ -63,6 +63,7 @@ G_BEGIN_DECLS #define REALM_DBUS_OPTION_CLIENT_SOFTWARE "client-software" #define REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE "membership-software" #define REALM_DBUS_OPTION_ASSUME_PACKAGES "assume-packages" +#define REALM_DBUS_OPTION_USER_PRINCIPAL "user-principal" #define REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY "active-directory" #define REALM_DBUS_IDENTIFIER_WINBIND "winbind" diff --git a/doc/manual/realmd-guide-configuring.xml b/doc/manual/realmd-guide-configuring.xml index 86ffd13..1c488e6 100644 --- a/doc/manual/realmd-guide-configuring.xml +++ b/doc/manual/realmd-guide-configuring.xml @@ -105,6 +105,22 @@ os-version = 9.9.9.9.9 +
+ user-prinicpal + + Set the to yes + to create attributes for the + computer account in the domain, in the form + host/computer@REALM + + + +[active-directory] +user-principal = yes + + + +
diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c index d6d3c6e..f788d4b 100644 --- a/service/realm-adcli-enroll.c +++ b/service/realm-adcli-enroll.c @@ -81,9 +81,11 @@ realm_adcli_enroll_join_async (const gchar *realm, const gchar *computer_ou; GSimpleAsyncResult *async; GBytes *input = NULL; + const gchar *upn; GPtrArray *args; const gchar *os; - gchar *arg; + gchar *ccache_arg = NULL; + gchar *upn_arg = NULL; g_return_if_fail (cred != NULL); g_return_if_fail (realm != NULL); @@ -129,8 +131,8 @@ realm_adcli_enroll_join_async (const gchar *realm, case REALM_CREDENTIAL_CCACHE: g_ptr_array_add (args, "--login-type"); g_ptr_array_add (args, "user"); - arg = g_strdup_printf ("--login-ccache=%s", cred->x.ccache.file); - g_ptr_array_add (args, arg); + ccache_arg = g_strdup_printf ("--login-ccache=%s", cred->x.ccache.file); + g_ptr_array_add (args, ccache_arg); break; case REALM_CREDENTIAL_PASSWORD: input = realm_command_build_password_line (cred->x.password.value); @@ -147,6 +149,16 @@ realm_adcli_enroll_join_async (const gchar *realm, break; } + upn = realm_options_user_principal (options); + if (upn || realm_settings_boolean ("active-directory", "user-principal")) { + if (upn && !g_str_equal (upn, "")) { + upn_arg = g_strdup_printf ("--user-principal=%s", upn); + g_ptr_array_add (args, upn_arg); + } else { + g_ptr_array_add (args, "--user-principal"); + } + } + g_ptr_array_add (args, NULL); realm_command_runv_async ((gchar **)args->pdata, environ, input, @@ -158,7 +170,9 @@ realm_adcli_enroll_join_async (const gchar *realm, if (input) g_bytes_unref (input); - free (arg); + + free (ccache_arg); + free (upn_arg); } gboolean diff --git a/service/realm-options.c b/service/realm-options.c index 4201abf..9b45b87 100644 --- a/service/realm-options.c +++ b/service/realm-options.c @@ -30,6 +30,17 @@ realm_options_assume_packages (GVariant *options) } const gchar * +realm_options_user_principal (GVariant *options) +{ + const gchar *principal; + + if (!g_variant_lookup (options, REALM_DBUS_OPTION_USER_PRINCIPAL, "&s", &principal)) + principal = NULL; + + return principal; +} + +const gchar * realm_options_computer_ou (GVariant *options, const gchar *realm_name) { diff --git a/service/realm-options.h b/service/realm-options.h index bec1004..1a9b319 100644 --- a/service/realm-options.h +++ b/service/realm-options.h @@ -26,6 +26,8 @@ gboolean realm_options_assume_packages (GVariant *options); const gchar * realm_options_computer_ou (GVariant *options, const gchar *realm_name); +const gchar * realm_options_user_principal (GVariant *options); + G_END_DECLS #endif /* __REALM_OPTIONS_H__ */ diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c index 636ad47..ea4dafa 100644 --- a/service/realm-samba-enroll.c +++ b/service/realm-samba-enroll.c @@ -418,6 +418,7 @@ begin_join (GSimpleAsyncResult *async, const gchar *computer_ou; gchar *strange_ou; GError *error = NULL; + const gchar *upn; const gchar *os; int at = 0; @@ -442,6 +443,15 @@ begin_join (GSimpleAsyncResult *async, if (os != NULL && !g_str_equal (os, "")) join->join_args[at++] = g_strdup_printf ("osVer=%s", os); + upn = realm_options_user_principal (options); + if (upn || realm_settings_boolean ("active-directory", "user-principal")) { + if (upn && g_str_equal (upn, "")) + upn = NULL; + join->join_args[at++] = g_strdup_printf ("createupn%s%s", + upn ? "=" : "", + upn ? upn : ""); + } + g_assert (at < G_N_ELEMENTS (join->join_args)); if (error != NULL) { diff --git a/service/realmd-defaults.conf b/service/realmd-defaults.conf index f020bf0..cdc6edc 100644 --- a/service/realmd-defaults.conf +++ b/service/realmd-defaults.conf @@ -10,6 +10,7 @@ ipa-client-install = /usr/sbin/ipa-client-install [active-directory] default-client = sssd +user-principal = no os-name = os-version = diff --git a/tools/realm-join.c b/tools/realm-join.c index b23dd0e..d935a27 100644 --- a/tools/realm-join.c +++ b/tools/realm-join.c @@ -172,6 +172,7 @@ typedef struct { gchar *membership_software; gboolean no_password; gchar *one_time_password; + gchar *user_principal; } RealmJoinArgs; static int @@ -208,6 +209,7 @@ perform_join (RealmClient *client, options = realm_build_options (REALM_DBUS_OPTION_COMPUTER_OU, args->computer_ou, REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE, args->membership_software, + REALM_DBUS_OPTION_USER_PRINCIPAL, args->user_principal, NULL); g_variant_ref_sink (options); @@ -272,6 +274,8 @@ realm_join (RealmClient *client, N_("Join automatically without a password"), NULL }, { "one-time-password", 0, 0, G_OPTION_ARG_STRING, &args.one_time_password, N_("Join using a preset one time password"), NULL }, + { "user-principal", 0, 0, G_OPTION_ARG_STRING, &args.user_principal, + N_("Set the user principal for the computer account"), NULL }, { NULL, } }; @@ -312,6 +316,7 @@ realm_join (RealmClient *client, g_free (args.computer_ou); g_free (args.client_software); g_free (args.server_software); + g_free (args.user_principal); g_option_context_free (context); return ret; } -- 1.8.1.4