diff options
author | Andrew Tridgell <tridge@samba.org> | 2002-01-16 02:22:30 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2002-01-16 02:22:30 +0000 |
commit | 9f85d4ad5f2bb5fdb7739b3f90c4bfac705393ce (patch) | |
tree | 013b7f83aeb828c9fb42591d07abab9d234f4e84 /source3/libads/ldap.c | |
parent | 3fee2ac712c5fe7a85b89ba3a3c19ab8801f0b22 (diff) | |
download | samba-9f85d4ad5f2bb5fdb7739b3f90c4bfac705393ce.tar.gz samba-9f85d4ad5f2bb5fdb7739b3f90c4bfac705393ce.tar.bz2 samba-9f85d4ad5f2bb5fdb7739b3f90c4bfac705393ce.zip |
much better support for organisational units in ADS join
(This used to be commit 7e876057d5e392f85e6fdb0f2c233b0fe76df688)
Diffstat (limited to 'source3/libads/ldap.c')
-rw-r--r-- | source3/libads/ldap.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 2e93e11603..d922e4c7c5 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -173,6 +173,23 @@ ADS_STATUS ads_gen_add(ADS_STRUCT *ads, const char *new_dn, ...) } /* + build an org unit string + if org unit is Computers or blank then assume a container, otherwise + assume a \ separated list of organisational units + caller must free +*/ +char *ads_ou_string(const char *org_unit) +{ + if (!org_unit || !*org_unit || strcasecmp(org_unit, "Computers") == 0) { + return strdup("cn=Computers"); + } + + return ads_build_path(org_unit, "\\/", "ou=", 1); +} + + + +/* add a machine account to the ADS server */ static ADS_STATUS ads_add_machine_acct(ADS_STRUCT *ads, const char *hostname, @@ -180,10 +197,13 @@ static ADS_STATUS ads_add_machine_acct(ADS_STRUCT *ads, const char *hostname, { ADS_STATUS ret; char *host_spn, *host_upn, *new_dn, *samAccountName, *controlstr; + char *ou_str; asprintf(&host_spn, "HOST/%s", hostname); asprintf(&host_upn, "%s@%s", host_spn, ads->realm); - asprintf(&new_dn, "cn=%s,cn=%s,%s", hostname, org_unit, ads->bind_path); + ou_str = ads_ou_string(org_unit); + asprintf(&new_dn, "cn=%s,%s,%s", hostname, ou_str, ads->bind_path); + free(ou_str); asprintf(&samAccountName, "%s$", hostname); asprintf(&controlstr, "%u", UF_DONT_EXPIRE_PASSWD | UF_WORKSTATION_TRUST_ACCOUNT | |