Re-arrange dns update block during "net ads join" a little.
authorGünther Deschner <gd@samba.org>
Thu, 28 Feb 2008 12:04:30 +0000 (13:04 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 28 Feb 2008 12:04:30 +0000 (13:04 +0100)
Guenther
(This used to be commit 5d30e9f9fef98de7764ae53d3cbe659b78ae9fce)

source3/utils/net_ads.c

index 8cf76ecbb6004b78d2fd14e6062ce0a156a1dc45..daddbfae73c5125383e0b3ee9771a130c69c15c9 100644 (file)
@@ -1645,34 +1645,36 @@ int net_ads_join(int argc, const char **argv)
                DEBUG(1,("Error creating host keytab!\n"));
        }
 
-#if defined(WITH_DNS_UPDATES)
-       /* We enter this block with user creds */
+       d_printf("Joined '%s' to realm '%s'\n", global_myname(), ads->server.realm);
+
        ads_kdestroy( NULL );
        ads_destroy(&ads);
-       ads = NULL;
 
-       if ( (ads = ads_init( lp_realm(), NULL, NULL )) != NULL ) {
-               /* kinit with the machine password */
+#if defined(WITH_DNS_UPDATES)
+       {
+               /* We enter this block with user creds */
+               ADS_STRUCT *ads_dns = NULL;
+
+               if ( (ads_dns = ads_init( lp_realm(), NULL, NULL )) != NULL ) {
+                       /* kinit with the machine password */
+
+                       use_in_memory_ccache();
+                       asprintf( &ads_dns->auth.user_name, "%s$", global_myname() );
+                       ads_dns->auth.password = secrets_fetch_machine_password(
+                               lp_workgroup(), NULL, NULL );
+                       ads_dns->auth.realm = SMB_STRDUP( lp_realm() );
+                       ads_kinit_password( ads_dns );
+               }
 
-               use_in_memory_ccache();
-               asprintf( &ads->auth.user_name, "%s$", global_myname() );
-               ads->auth.password = secrets_fetch_machine_password(
-                       lp_workgroup(), NULL, NULL );
-               ads->auth.realm = SMB_STRDUP( lp_realm() );
-               ads_kinit_password( ads );
-       }
+               if ( !ads_dns || !NT_STATUS_IS_OK(net_update_dns( ctx, ads_dns )) ) {
+                       d_fprintf( stderr, "DNS update failed!\n" );
+               }
 
-       if ( !ads || !NT_STATUS_IS_OK(net_update_dns( ctx, ads )) ) {
-               d_fprintf( stderr, "DNS update failed!\n" );
+               /* exit from this block using machine creds */
+               ads_destroy(&ads_dns);
        }
-
-       /* exit from this block using machine creds */
 #endif
-
-       d_printf("Joined '%s' to realm '%s'\n", global_myname(), ads->server.realm);
-
        TALLOC_FREE( ctx );
-       ads_destroy(&ads);
 
        return 0;