diff options
author | Gerald Carter <jerry@samba.org> | 2007-05-06 21:45:53 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:21:51 -0500 |
commit | 3eca3af1bcd92e575b8c5d1034efd8d516df5e6c (patch) | |
tree | 718287701b35bd1e12777c3665b9c1d424e04924 /source3/utils | |
parent | 3df5bc872867036c07d4fdf580f8c5a3abfc1f18 (diff) | |
download | samba-3eca3af1bcd92e575b8c5d1034efd8d516df5e6c.tar.gz samba-3eca3af1bcd92e575b8c5d1034efd8d516df5e6c.tar.xz samba-3eca3af1bcd92e575b8c5d1034efd8d516df5e6c.zip |
r22728: Patch from Danilo Almeida <dalmeida@centeris.com>:
When asked to create a machine account in an OU as part
of "net ads join" and the account already exists in another
OU, simply move the machine object to the requested OU.
(This used to be commit 3004cc6e593e6659a618de66f659f579e71c07f7)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_ads.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c index 37ede28a97..030c5762f3 100644 --- a/source3/utils/net_ads.c +++ b/source3/utils/net_ads.c @@ -1190,28 +1190,50 @@ done: static ADS_STATUS net_precreate_machine_acct( ADS_STRUCT *ads, const char *ou ) { ADS_STATUS rc = ADS_ERROR(LDAP_SERVER_DOWN); - char *dn, *ou_str; + char *ou_str = NULL; + char *dn = NULL; LDAPMessage *res = NULL; + BOOL moved; ou_str = ads_ou_string(ads, ou); - if ((asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path)) == -1) { - SAFE_FREE(ou_str); - return ADS_ERROR(LDAP_NO_MEMORY); + if (asprintf(&dn, "%s,%s", ou_str, ads->config.bind_path) == -1) { + rc = ADS_ERROR(LDAP_NO_MEMORY); + goto done; } rc = ads_search_dn(ads, &res, dn, NULL); - ads_msgfree(ads, res); + if (!ADS_ERR_OK(rc)) { + d_fprintf(stderr, "The specified OU does not exist.\n"); + goto done; + } - if (ADS_ERR_OK(rc)) { /* Attempt to create the machine account and bail if this fails. Assume that the admin wants exactly what they requested */ rc = ads_create_machine_acct( ads, global_myname(), dn ); - if ( rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_ALREADY_EXISTS ) { - rc = ADS_SUCCESS; + if (ADS_ERR_OK(rc)) { + DEBUG(1, ("machine account created\n")); + goto done; } + if ( !(rc.error_type == ENUM_ADS_ERROR_LDAP && rc.err.rc == LDAP_ALREADY_EXISTS) ) { + DEBUG(1, ("machine account creation failed\n")); + goto done; + } + + rc = ads_move_machine_acct(ads, global_myname(), dn, &moved); + if (!ADS_ERR_OK(rc)) { + DEBUG(1, ("failure to locate/move pre-existing machine account\n")); + goto done; } + if (moved) { + d_printf("The machine account was moved into the specified OU.\n"); + } else { + d_printf("The machine account already exists in the specified OU.\n"); + } + +done: + ads_msgfree(ads, res); SAFE_FREE( ou_str ); SAFE_FREE( dn ); @@ -1528,7 +1550,7 @@ int net_ads_join(int argc, const char **argv) status = net_precreate_machine_acct( ads, create_in_ou ); if ( !ADS_ERR_OK(status) ) { d_fprintf( stderr, "Failed to pre-create the machine object " - "in OU %s.\n", argv[0]); + "in OU %s.\n", create_in_ou); DEBUG(1, ("error calling net_precreate_machine_acct: %s\n", ads_errstr(status))); nt_status = ads_ntstatus(status); |