diff options
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_ads.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 8cf76ecbb6..daddbfae73 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -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; |