Still on my mb rampage. Ensure smbldap_make_mod() correctly detects old
authorJeremy Allison <jra@samba.org>
Wed, 10 Sep 2003 23:14:18 +0000 (23:14 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 10 Sep 2003 23:14:18 +0000 (23:14 +0000)
values.
Jeremy.

source/lib/smbldap.c

index 7bdb8ea5a5d812a6b0d1047dcd8c44c6a37fb8ef..781e6b976c37cf0c4d8a8f624bd74163dde14325 100644 (file)
@@ -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