diff -r f68fdcc18df9 -r f4bf6556fb9f packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php --- a/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php Sat Feb 23 14:26:05 2013 -0500 +++ b/packages/ssoinabox-webui/root/usr/local/share/ssoinabox/htdocs/index.php Sat Feb 23 14:26:38 2013 -0500 @@ -42,10 +42,36 @@ break; case 'profile-update': // header('Content-type: text/plain'); print_r(!empty($_POST['sshPublicKey']) ? $_POST['sshPublicKey'] : array()); exit; - $result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array( - 'mail' => array($_POST['mail']) - , 'sshPublicKey' => !empty($_POST['sshPublicKey']) ? array_unique($_POST['sshPublicKey']) : array() - )); + $ui = ldap_get_user($_SERVER['REMOTE_USER']); + + foreach ( array('mail', 'sshPublicKey') as $field ) + { + if ( empty($_POST[$field]) && empty($ui[$field]) ) + { + // both empty, do nothing + } + else if ( empty($_POST[$field]) && !empty($ui[$field]) ) + { + // POST empty, database not. Delete attr. + $result = ldap_mod_del($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array( + $field => array() + )); + } + else if ( !empty($_POST[$field]) && empty($ui[$field]) ) + { + // POST filled, database empty. Add attr. + $result = ldap_mod_add($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array( + $field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field]) + )); + } + else if ( !empty($_POST[$field]) && !empty($ui[$field]) ) + { + // POST and database filled. Replace attr. + $result = ldap_mod_replace($_ldapconn, ldap_make_user_dn($_SERVER['REMOTE_USER']), array( + $field => is_array($_POST[$field]) ? array_unique($_POST[$field]) : array($_POST[$field]) + )); + } + } if ( $result || ldap_error($_ldapconn) === 'Success' ) {