+
+int attribute_update(LDAP *ldap_handle, char *distinguished_name,
+ char *attribute_value, char *attribute, char *user_name)
+{
+ char *mod_v[] = {NULL, NULL};
+ LDAPMod *DelMods[20];
+ LDAPMod *mods[20];
+ int n;
+ int i;
+ int rc;
+
+ if (strlen(attribute_value) == 0)
+ {
+ i = 0;
+ DEL_ATTR(attribute, LDAP_MOD_DELETE);
+ DelMods[i] = NULL;
+ rc = ldap_modify_s(ldap_handle, distinguished_name, DelMods);
+ free(DelMods[0]);
+ }
+ else
+ {
+ n = 0;
+ mod_v[0] = attribute_value;
+ ADD_ATTR(attribute, mod_v, LDAP_MOD_REPLACE);
+ mods[n] = NULL;
+ if ((rc = ldap_modify_s(ldap_handle, distinguished_name, mods)) != LDAP_SUCCESS)
+ {
+ free(mods[0]);
+ n = 0;
+ mod_v[0] = attribute_value;
+ ADD_ATTR(attribute, mod_v, LDAP_MOD_ADD);
+ mods[n] = NULL;
+ if ((rc = ldap_modify_s(ldap_handle, distinguished_name, mods)) != LDAP_SUCCESS)
+ {
+ com_err(whoami, 0, "Unable to change the %s attribute for %s in the AD : %s",
+ attribute, user_name, ldap_err2string(rc));
+ }
+ }
+ free(mods[0]);
+ }
+ return(rc);
+}