diff options
author | Andrew Bartlett <abartlet@samba.org> | 2003-07-04 13:29:42 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2003-07-04 13:29:42 +0000 |
commit | 4168d61fb22e19a248a6c3d3ad43e2f73e37fc6a (patch) | |
tree | 01be3640a7c53378fb4a2edf69ecd4c3306db83f /source3/lib | |
parent | cd6687673a2d741c32997c8d3ce1df8bc61915fa (diff) | |
download | samba-4168d61fb22e19a248a6c3d3ad43e2f73e37fc6a.tar.gz samba-4168d61fb22e19a248a6c3d3ad43e2f73e37fc6a.tar.bz2 samba-4168d61fb22e19a248a6c3d3ad43e2f73e37fc6a.zip |
This patch cleans up some of our ldap code, for better behaviour:
We now always read the Domain SID out of LDAP. If the local secrets.tdb
is ever different to LDAP, it is overwritten out of LDAP. We also
store the 'algorithmic rid base' into LDAP, and assert if it changes.
(This ensures cross-host synchronisation, and allows for possible
integration with idmap). If we fail to read/add the domain entry, we just
fallback to the old behaviour.
We always use an existing DN when adding IDMAP entries to LDAP, unless
no suitable entry is available. This means that a user's posixAccount
will have a SID added to it, or a user's sambaSamAccount will have a UID
added. Where we cannot us an existing DN, we use
'sambaSid=S-x-y-z,....' as the DN.
The code now allows modifications to the ID mapping in many cases.
Likewise, we now check more carefully when adding new user entires to LDAP,
to not duplicate SIDs (for users, at this stage), and to add the sambaSamAccount
onto the idmap entry for that user, if it is already established (ensuring
we do not duplicate sambaSid entries in the directory).
The allocated UID code has been expanded to take into account the space
between '1000 - algorithmic rid base'. This much better fits into what
an NT4 does - allocating in the bottom part of the RID range.
On the code cleanup side of things, we now share as much code as
possible between idmap_ldap and pdb_ldap.
We also no longer use the race-prone 'enumerate all users' method for
finding the next RID to allocate. Instead, we just start at the bottom
of the range, and increment again if the user already exists. The first
time this is run, it may well take a long time, but next time will just
be able to use the next Rid.
Thanks to metze and AB for double-checking parts of this.
Andrew Bartlett
(This used to be commit 9c595c8c2327b92a86901d84c3f2c284dabd597e)
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/smbldap.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c index 8401787317..f65860d1b8 100644 --- a/source3/lib/smbldap.c +++ b/source3/lib/smbldap.c @@ -102,9 +102,11 @@ ATTRIB_MAP_ENTRY attrib_map_v30[] = { ATTRIB_MAP_ENTRY dominfo_attr_list[] = { { LDAP_ATTR_DOMAIN, "sambaDomainName" }, + { LDAP_ATTR_NEXT_RID, "sambaNextRid" }, { LDAP_ATTR_NEXT_USERRID, "sambaNextUserRid" }, { LDAP_ATTR_NEXT_GROUPRID, "sambaNextGroupRid" }, { LDAP_ATTR_DOM_SID, LDAP_ATTRIBUTE_SID }, + { LDAP_ATTR_ALGORITHMIC_RID_BASE,"sambaAlgorithmicRidBase"}, { LDAP_ATTR_LIST_END, NULL }, }; @@ -271,6 +273,40 @@ BOOL fetch_ldap_pw(char **dn, char** pw) return True; } +/******************************************************************* +search an attribute and return the first value found. +******************************************************************/ + BOOL smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry, + const char *attribute, pstring value) +{ + char **values; + + if ( !attribute ) + return False; + + value[0] = '\0'; + + if ((values = ldap_get_values (ldap_struct, entry, attribute)) == NULL) { + DEBUG (10, ("smbldap_get_single_attribute: [%s] = [<does not exist>]\n", attribute)); + + return False; + } + + if (convert_string(CH_UTF8, CH_UNIX,values[0], -1, value, sizeof(pstring)) == (size_t)-1) + { + DEBUG(1, ("smbldap_get_single_attribute: string conversion of [%s] = [%s] failed!\n", + attribute, values[0])); + ldap_value_free(values); + return False; + } + + ldap_value_free(values); +#ifdef DEBUG_PASSWORDS + DEBUG (100, ("smbldap_get_single_attribute: [%s] = [%s]\n", attribute, value)); +#endif + return True; +} + /************************************************************************ Routine to manage the LDAPMod structure array manage memory used by the array, by each struct, and values @@ -819,7 +855,7 @@ static NTSTATUS smbldap_close(struct smbldap_state *ldap_state) return NT_STATUS_OK; } -static int smbldap_retry_open(struct smbldap_state *ldap_state, int *attempts) +int smbldap_retry_open(struct smbldap_state *ldap_state, int *attempts) { int rc; |