summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-09-10 23:14:18 +0000
committerJeremy Allison <jra@samba.org>2003-09-10 23:14:18 +0000
commitc068cd37b911b28cef8754cbd61d2fde44650530 (patch)
tree50c65a5a2c0d9b47d960fe1824c0ab588e483fe0 /source3/lib
parentca1c6ebb11361dabaca22015736f3876d51833a2 (diff)
downloadsamba-c068cd37b911b28cef8754cbd61d2fde44650530.tar.gz
samba-c068cd37b911b28cef8754cbd61d2fde44650530.tar.bz2
samba-c068cd37b911b28cef8754cbd61d2fde44650530.zip
Still on my mb rampage. Ensure smbldap_make_mod() correctly detects old
values. Jeremy. (This used to be commit 41e4479aa9f186d68300086984d6f4c8f9fd2a27)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/smbldap.c28
1 files changed, 13 insertions, 15 deletions
diff --git a/source3/lib/smbldap.c b/source3/lib/smbldap.c
index 7bdb8ea5a5..781e6b976c 100644
--- a/source3/lib/smbldap.c
+++ b/source3/lib/smbldap.c
@@ -282,8 +282,9 @@ BOOL fetch_ldap_pw(char **dn, char** pw)
}
/*******************************************************************
-search an attribute and return the first value found.
+ Search an attribute and return the first value found.
******************************************************************/
+
BOOL smbldap_get_single_attribute (LDAP * ldap_struct, LDAPMessage * entry,
const char *attribute, pstring value)
{
@@ -300,8 +301,7 @@ search an attribute and return the first value found.
return False;
}
- if (convert_string(CH_UTF8, CH_UNIX,values[0], -1, value, sizeof(pstring)) == (size_t)-1)
- {
+ 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);
@@ -402,32 +402,32 @@ search an attribute and return the first value found.
*modlist = mods;
}
-
/**********************************************************************
Set attribute to newval in LDAP, regardless of what value the
attribute had in LDAP before.
*********************************************************************/
+
void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
LDAPMod ***mods,
const char *attribute, const char *newval)
{
- char **values = NULL;
+ pstring oldval;
+ BOOL existed;
if (existing != NULL) {
- values = ldap_get_values(ldap_struct, existing, attribute);
+ existed = smbldap_get_single_attribute(ldap_struct, existing, attribute, oldval);
+ } else {
+ existed = False;
+ *oldval = '\0';
}
/* all of our string attributes are case insensitive */
- if ((values != NULL) && (values[0] != NULL) &&
- StrCaseCmp(values[0], newval) == 0)
- {
+ if (existed && (StrCaseCmp(oldval, newval) == 0)) {
/* Believe it or not, but LDAP will deny a delete and
an add at the same time if the values are the
same... */
-
- ldap_value_free(values);
return;
}
@@ -439,7 +439,7 @@ search an attribute and return the first value found.
smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval);
}
- if (values == NULL) {
+ if (!existed) {
/* There has been no value before, so don't delete it.
Here's a possible race: We might end up with
duplicate attributes */
@@ -451,11 +451,9 @@ search an attribute and return the first value found.
deny the complete operation if somebody changed the
attribute behind our back. */
- smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, values[0]);
- ldap_value_free(values);
+ smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval);
}
-
/**********************************************************************
Some varients of the LDAP rebind code do not pass in the third 'arg'
pointer to a void*, so we try and work around it by assuming that the