allow net ads join accept new osServicePack parameter
authorNoel Power <noel.power@suse.com>
Thu, 2 Oct 2014 15:13:18 +0000 (16:13 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 7 Jan 2015 23:18:05 +0000 (00:18 +0100)
osServicePack paramater allows the default behaviour ( which is to use
the samba version string as the operatingSystemServicePack attribute )
to be overridden
Additionally make sure if blank string is passed that it is treated
as attribute deletion. This is necessary as values for the os attributes
are eventually passed to ads_modlist_add if the value is "" then the
attempt to add this attribute fails in the underlying ldap
'ldap_modfiy_ext_s' function. In this case we need to pass NULL as the
value to force deletion of the ldap attribute

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Thu Jan  8 00:18:05 CET 2015 on sn-devel-104

source3/libnet/libnet_join.c
source3/librpc/idl/libnet_join.idl
source3/utils/net_ads.c

index dd87c6d..c5a61fe 100644 (file)
@@ -574,8 +574,19 @@ static ADS_STATUS libnet_join_set_os_attributes(TALLOC_CTX *mem_ctx,
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
 
-       os_sp = talloc_asprintf(mem_ctx, "Samba %s", samba_version_string());
-       if (!os_sp) {
+       if (r->in.os_servicepack) {
+               /*
+                * if blank string then leave os_sp equal to NULL to force
+                * attribute delete (LDAP_MOD_DELETE)
+                */
+               if (!strequal(r->in.os_servicepack,"")) {
+                       os_sp = talloc_strdup(mem_ctx, r->in.os_servicepack);
+               }
+       } else {
+               os_sp = talloc_asprintf(mem_ctx, "Samba %s",
+                                       samba_version_string());
+       }
+       if (!os_sp && !strequal(r->in.os_servicepack,"")) {
                return ADS_ERROR(LDAP_NO_MEMORY);
        }
 
index ac0a350..cb2d9e4 100644 (file)
@@ -27,6 +27,7 @@ interface libnetjoin
                [in] wkssvc_joinflags join_flags,
                [in] string os_version,
                [in] string os_name,
+               [in] string os_servicepack,
                [in] boolean8 create_upn,
                [in] string upn,
                [in] boolean8 modify_config,
index ba500b5..b0e7112 100644 (file)
@@ -1329,6 +1329,9 @@ static int net_ads_join_usage(struct net_context *c, int argc, const char **argv
                   "                          Also, the operatingSystemService attribute is also set when along with\n"
                   "                          the two other attributes.\n"));
 
+       d_printf(_("   osServicePack=string Set the operatingSystemServicePack "
+                  "attribute during the join. Note: if not specified then by "
+                  "default the samba version string is used instead.\n"));
        return -1;
 }
 
@@ -1434,6 +1437,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        int i;
        const char *os_name = NULL;
        const char *os_version = NULL;
+       const char *os_servicepack = NULL;
        bool modify_config = lp_config_backend_is_registry();
 
        if (c->display_usage)
@@ -1491,6 +1495,13 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
                                goto fail;
                        }
                }
+               else if ( !strncasecmp_m(argv[i], "osServicePack", strlen("osServicePack")) ) {
+                       if ( (os_servicepack = get_string_param(argv[i])) == NULL ) {
+                               d_fprintf(stderr, _("Please supply a valid servicepack identifier.\n"));
+                               werr = WERR_INVALID_PARAM;
+                               goto fail;
+                       }
+               }
                else if ( !strncasecmp_m(argv[i], "machinepass", strlen("machinepass")) ) {
                        if ( (machine_password = get_string_param(argv[i])) == NULL ) {
                                d_fprintf(stderr, _("Please supply a valid password to set as trust account password.\n"));
@@ -1524,6 +1535,7 @@ int net_ads_join(struct net_context *c, int argc, const char **argv)
        r->in.account_ou        = create_in_ou;
        r->in.os_name           = os_name;
        r->in.os_version        = os_version;
+       r->in.os_servicepack    = os_servicepack;
        r->in.dc_name           = c->opt_host;
        r->in.admin_account     = c->opt_user_name;
        r->in.admin_password    = net_prompt_pass(c, c->opt_user_name);