mirror of
https://github.com/samba-team/samba.git
synced 2025-08-02 00:22:11 +03:00
r17383: Patch from Michael Adams <ma@sernet.de> to catch
some memory leaks on error paths in net_ads_join()
(This used to be commit 24de2d83ff
)
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
dca7d08e61
commit
e5f6544df1
@ -1169,7 +1169,7 @@ static int net_ads_join_usage(int argc, const char **argv)
|
|||||||
|
|
||||||
int net_ads_join(int argc, const char **argv)
|
int net_ads_join(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
ADS_STRUCT *ads;
|
ADS_STRUCT *ads = NULL;
|
||||||
ADS_STATUS status;
|
ADS_STATUS status;
|
||||||
char *machine_account = NULL;
|
char *machine_account = NULL;
|
||||||
const char *short_domain_name = NULL;
|
const char *short_domain_name = NULL;
|
||||||
@ -1184,24 +1184,23 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
|
|
||||||
if ( check_ads_config() != 0 ) {
|
if ( check_ads_config() != 0 ) {
|
||||||
d_fprintf(stderr, "Invalid configuration. Exiting....\n");
|
d_fprintf(stderr, "Invalid configuration. Exiting....\n");
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( (ads = ads_startup(True)) == NULL ) {
|
if ( (ads = ads_startup(True)) == NULL ) {
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(ads->config.realm, lp_realm()) != 0) {
|
if (strcmp(ads->config.realm, lp_realm()) != 0) {
|
||||||
d_fprintf(stderr, "realm of remote server (%s) and realm in smb.conf "
|
d_fprintf(stderr, "realm of remote server (%s) and realm in smb.conf "
|
||||||
"(%s) DO NOT match. Aborting join\n", ads->config.realm,
|
"(%s) DO NOT match. Aborting join\n", ads->config.realm,
|
||||||
lp_realm());
|
lp_realm());
|
||||||
ads_destroy(&ads);
|
goto fail;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctx = talloc_init("net_ads_join"))) {
|
if (!(ctx = talloc_init("net_ads_join"))) {
|
||||||
DEBUG(0, ("Could not initialise talloc context\n"));
|
DEBUG(0, ("Could not initialise talloc context\n"));
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* process additional command line args */
|
/* process additional command line args */
|
||||||
@ -1214,12 +1213,12 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
else if ( !StrnCaseCmp(argv[i], "createcomputer", strlen("createcomputer")) ) {
|
else if ( !StrnCaseCmp(argv[i], "createcomputer", strlen("createcomputer")) ) {
|
||||||
if ( (create_in_ou = get_string_param(argv[i])) == NULL ) {
|
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");
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
d_fprintf(stderr, "Bad option: %s\n", argv[i]);
|
d_fprintf(stderr, "Bad option: %s\n", argv[i]);
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1231,8 +1230,7 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
if ( !ADS_ERR_OK(status) ) {
|
if ( !ADS_ERR_OK(status) ) {
|
||||||
d_fprintf( stderr, "Failed to pre-create the machine object "
|
d_fprintf( stderr, "Failed to pre-create the machine object "
|
||||||
"in OU %s.\n", argv[0]);
|
"in OU %s.\n", argv[0]);
|
||||||
ads_destroy( &ads );
|
goto fail;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1243,7 +1241,7 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
|
|
||||||
if ( net_join_domain( ctx, ads->config.ldap_server_name, &ads->ldap_ip, &domain_sid, password ) != 0 ) {
|
if ( net_join_domain( ctx, ads->config.ldap_server_name, &ads->ldap_ip, &domain_sid, password ) != 0 ) {
|
||||||
d_fprintf(stderr, "Failed to join domain!\n");
|
d_fprintf(stderr, "Failed to join domain!\n");
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check the short name of the domain */
|
/* Check the short name of the domain */
|
||||||
@ -1274,15 +1272,14 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
if ( (netdom_store_machine_account( lp_workgroup(), domain_sid, password ) == -1)
|
if ( (netdom_store_machine_account( lp_workgroup(), domain_sid, password ) == -1)
|
||||||
|| (netdom_store_machine_account( short_domain_name, domain_sid, password ) == -1) )
|
|| (netdom_store_machine_account( short_domain_name, domain_sid, password ) == -1) )
|
||||||
{
|
{
|
||||||
ads_destroy(&ads);
|
goto fail;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify that everything is ok */
|
/* Verify that everything is ok */
|
||||||
|
|
||||||
if ( net_rpc_join_ok(short_domain_name, ads->config.ldap_server_name, &ads->ldap_ip) != 0 ) {
|
if ( net_rpc_join_ok(short_domain_name, ads->config.ldap_server_name, &ads->ldap_ip) != 0 ) {
|
||||||
d_fprintf(stderr, "Failed to verify membership in domain!\n");
|
d_fprintf(stderr, "Failed to verify membership in domain!\n");
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the dNSHostName & servicePrincipalName values */
|
/* create the dNSHostName & servicePrincipalName values */
|
||||||
@ -1306,13 +1303,12 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
netdom_store_machine_account( lp_workgroup(), domain_sid, "" );
|
netdom_store_machine_account( lp_workgroup(), domain_sid, "" );
|
||||||
netdom_store_machine_account( short_domain_name, domain_sid, "" );
|
netdom_store_machine_account( short_domain_name, domain_sid, "" );
|
||||||
|
|
||||||
return -1;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !net_derive_salting_principal( ctx, ads ) ) {
|
if ( !net_derive_salting_principal( ctx, ads ) ) {
|
||||||
DEBUG(1,("Failed to determine salting principal\n"));
|
DEBUG(1,("Failed to determine salting principal\n"));
|
||||||
ads_destroy(&ads);
|
goto fail;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( createupn ) {
|
if ( createupn ) {
|
||||||
@ -1343,6 +1339,10 @@ int net_ads_join(int argc, const char **argv)
|
|||||||
ads_destroy(&ads);
|
ads_destroy(&ads);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
ads_destroy(&ads);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
Reference in New Issue
Block a user