[PATCH 1/2] Set os attribute and version during domain join

Gerald (Jerry) Carter jerry at samba.org
Fri Mar 16 17:16:56 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[This time with the patch]

ok.  I admit that I'm caving on this one.  This patch
adds osname and osver options to 'net ads join' which
sets the operatingSystemName and operatingSystemVersion
attributes strings in the machine object.  The
operatingSystemServicePack is set to "samba %v".

For example:

 $ net ads join osname=`uname -s` osver=`uname -r`

would yield

 operatingSystemName: Linux
 operatingSsystemVersion: 2.6.18.6-2-gwc
 operatingsystemServicePack: Samba 3.0.25pre2-SVN-build-21792

Do people want this or should I just keep it as a local
patch?




cheers, jerry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF+tEHIR7qMdg1EfYRArfVAJ4xYay5eOlRAhUXEU4Tsrd2eUTxUwCfZd2Z
d9ImfnTWupEnbPAqEkX+2zg=
=uMsu
-----END PGP SIGNATURE-----
-------------- next part --------------
=== modified file 'source/utils/net_ads.c'
--- source/utils/net_ads.c	2007-03-01 15:11:22 +0000
+++ source/utils/net_ads.c	2007-03-16 17:07:29 +0000
@@ -1118,6 +1118,72 @@
 }
 
 /*******************************************************************
+ Set a machines dNSHostName and servicePrincipalName attributes
+ ********************************************************************/
+
+static ADS_STATUS net_set_os_attributes(TALLOC_CTX *ctx, ADS_STRUCT *ads_s, 
+					const char *os_name, const char *os_version )
+{
+	ADS_STATUS status = ADS_ERROR(LDAP_SERVER_DOWN);
+	char *new_dn;
+	ADS_MODLIST mods;
+	LDAPMessage *res = NULL;
+	char *dn_string = NULL;
+	const char *machine_name = global_myname();
+	int count;
+	char *os_sp = NULL;
+	
+	if ( !os_name || !os_version ) {
+		return ADS_ERROR(LDAP_NO_MEMORY);
+	}
+	
+	/* Find our DN */
+	
+	status = ads_find_machine_acct(ads_s, &res, machine_name);
+	if (!ADS_ERR_OK(status)) 
+		return status;
+		
+	if ( (count = ads_count_replies(ads_s, res)) != 1 ) {
+		DEBUG(1,("net_set_machine_spn: %d entries returned!\n", count));
+		return ADS_ERROR(LDAP_NO_MEMORY);	
+	}
+	
+	if ( (dn_string = ads_get_dn(ads_s, res)) == NULL ) {
+		DEBUG(1, ("ads_add_machine_acct: ads_get_dn returned NULL (malloc failure?)\n"));
+		goto done;
+	}
+	
+	new_dn = talloc_strdup(ctx, dn_string);
+	ads_memfree(ads_s, dn_string);
+	if (!new_dn) {
+		return ADS_ERROR(LDAP_NO_MEMORY);
+	}
+	
+	/* now do the mods */
+	
+	if (!(mods = ads_init_mods(ctx))) {
+		goto done;
+	}
+
+	os_sp = talloc_asprintf( ctx, "Samba %s", SAMBA_VERSION_STRING );
+	
+	/* fields of primary importance */
+	
+	ads_mod_str(ctx, &mods, "operatingSystem", os_name);
+	ads_mod_str(ctx, &mods, "operatingSystemVersion", os_version);
+	if ( os_sp )
+		ads_mod_str(ctx, &mods, "operatingSystemServicePack", os_sp);
+
+	status = ads_gen_mod(ads_s, new_dn, mods);
+
+done:
+	ads_msgfree(ads_s, res);
+	TALLOC_FREE( os_sp );	
+	
+	return status;
+}
+
+/*******************************************************************
   join a domain using ADS (LDAP mods)
  ********************************************************************/
 
@@ -1386,6 +1452,8 @@
 	int i;
 	fstring dc_name;
 	struct in_addr dcip;
+	const char *os_name = NULL;
+	const char *os_version = NULL;
 	
 	nt_status = check_ads_config();
 	if (!NT_STATUS_IS_OK(nt_status)) {
@@ -1427,7 +1495,21 @@
 		}
 		else if ( !StrnCaseCmp(argv[i], "createcomputer", strlen("createcomputer")) ) {
 			if ( (create_in_ou = get_string_param(argv[i])) == NULL ) {
-				d_fprintf(stderr, "Please supply a valid OU path\n");
+				d_fprintf(stderr, "Please supply a valid OU path.\n");
+				nt_status = NT_STATUS_INVALID_PARAMETER;
+				goto fail;
+			}		
+		}
+		else if ( !StrnCaseCmp(argv[i], "osName", strlen("osName")) ) {
+			if ( (os_name = get_string_param(argv[i])) == NULL ) {
+				d_fprintf(stderr, "Please supply a operating system name.\n");
+				nt_status = NT_STATUS_INVALID_PARAMETER;
+				goto fail;
+			}		
+		}
+		else if ( !StrnCaseCmp(argv[i], "osVer", strlen("osVer")) ) {
+			if ( (os_version = get_string_param(argv[i])) == NULL ) {
+				d_fprintf(stderr, "Please supply a valid operating system version.\n");
 				nt_status = NT_STATUS_INVALID_PARAMETER;
 				goto fail;
 			}		
@@ -1546,7 +1628,18 @@
 		}
 	}
 
+	/* Try to set the operatingSystem attributes if asked */
+
+	if ( os_name && os_version ) {
+		status = net_set_os_attributes( ctx, ads, os_name, os_version );
+		if ( !ADS_ERR_OK(status) )  {
+			d_fprintf(stderr, "Failed to set operatingSystem attributes.  "
+				  "Are you a Domain Admin?\n");
+		}
+	}
+
 	/* Now build the keytab, using the same ADS connection */
+
 	if (lp_use_kerberos_keytab() && ads_keytab_create_default(ads)) {
 		DEBUG(1,("Error creating host keytab!\n"));
 	}


More information about the samba-technical mailing list