Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LDAP raw user filter gets reset when in admin page #6651

Closed
sshipway opened this issue Jan 7, 2014 · 14 comments
Closed

LDAP raw user filter gets reset when in admin page #6651

sshipway opened this issue Jan 7, 2014 · 14 comments
Labels

Comments

@sshipway
Copy link

sshipway commented Jan 7, 2014

Occasionally, the LDAP raw user filter setting is changed back to the default when viewing the ldap settings in the Admin page. Since we have a restrictive filter it results in ldap no longer working correctly until I fix it in the database.

I am not able to replicate this at will, but it has occurred three times since upgrading to OC6 today.

@karlitschek
Copy link
Contributor

@blizzz

@blizzz
Copy link
Contributor

blizzz commented Jan 10, 2014

race condition, ick hör dir trapsen

@blizzz
Copy link
Contributor

blizzz commented Jan 14, 2014

@sshipway could you apply following patch and observer whether this behaviour still occurs?

diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index acf88ef..8098967 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -138,6 +138,105 @@ var LdapConfiguration = {
    }
 };

+
+// LdapFilter object.
+
+function LdapFilter(target)  {
+   this.locked = true;
+   this.target = false;
+   this.mode = LdapWizard.filterModeAssisted;
+   this.lazyRunCompose = false;
+
+   if( target === 'User' ||
+       target === 'Login' ||
+       target === 'Group') {
+       this.target = target;
+       this.determineMode();
+   }
+}
+
+LdapFilter.prototype.compose = function() {
+   if(this.locked) {
+       this.lazyRunCompose = true;
+       return false;
+   }
+
+   if(this.target === 'User') {
+       action = 'getUserListFilter';
+   } else if(this.target === 'Login') {
+       action = 'getUserLoginFilter';
+   } else if(this.target === 'Group') {
+       action = 'getGroupFilter';
+   }
+
+   if(!$('#raw'+this.target+'FilterContainer').hasClass('invisible')) {
+       //Raw filter editing, i.e. user defined filter, don't compose
+       return;
+   }
+
+   param = 'action='+action+
+           '&ldap_serverconfig_chooser='+
+           encodeURIComponent($('#ldap_serverconfig_chooser').val());
+
+   filter = this;
+
+   LdapWizard.ajax(param,
+       function(result) {
+           LdapWizard.applyChanges(result);
+           if(filter.target === 'User') {
+               LdapWizard.countUsers();
+           } else if(filter.target === 'Group') {
+               LdapWizard.countGroups();
+               LdapWizard.detectGroupMemberAssoc();
+           }
+       },
+       function (result) {
+           // error handling
+       }
+   );
+}
+
+LdapFilter.prototype.determineMode = function() {
+   param = 'action=get'+encodeURIComponent(this.target)+'FilterMode'+
+           '&ldap_serverconfig_chooser='+
+           encodeURIComponent($('#ldap_serverconfig_chooser').val());
+
+   filter = this;
+   LdapWizard.ajax(param,
+       function(result) {
+           property = 'ldap' + filter.target + 'FilterMode';
+           filter.mode = result.changes[property];
+           if(filter.mode == LdapWizard.filterModeRaw
+               && $('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+               LdapWizard['toggleRaw'+filter.target+'Filter']();
+           } else if(filter.mode == LdapWizard.filterModeAssisted
+               && !$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+               LdapWizard['toggleRaw'+filter.target+'Filter']();
+           }
+           filter.unlock();
+       },
+       function (result) {
+           //on error case get back to default i.e. Assisted
+           if(!$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
+               LdapWizard['toggleRaw'+filter.target+'Filter']();
+               filter.mode = LdapWizard.filterModeAssisted;
+           }
+           filter.unlock();
+       }
+   );
+
+}
+
+LdapFilter.prototype.unlock = function() {
+   this.locked = false;
+   if(this.lazyRunCompose) {
+       this.lazyRunCompose = false;
+       this.composeFilter();
+   }
+}
+
+// end of LdapFilter object.
+
 var LdapWizard = {
    checkPortInfoShown: false,
    saveBlacklist: {},
@@ -145,6 +244,7 @@ var LdapWizard = {
    spinner: '<img class="wizSpinner" src="'+ OC.imagePath('core', 'loading.gif') +'">',
    filterModeAssisted: 0,
    filterModeRaw: 1,
+   userFilter: false,

    ajax: function(param, fnOnSuccess, fnOnError) {
        $.post(
@@ -600,7 +700,8 @@ var LdapWizard = {
    initUserFilter: function() {
        LdapWizard.userFilterObjectClassesHasRun = false;
        LdapWizard.userFilterAvailableGroupsHasRun = false;
-       LdapWizard.regardFilterMode('User');
+       LdapWizard.userFilterModeWasDetermined = false,
+       LdapWizard.userFilter = new LdapFilter('User');
        LdapWizard.findObjectClasses('ldap_userfilter_objectclass', 'User');
        LdapWizard.findAvailableGroups('ldap_userfilter_groups', 'Users');
    },
@@ -608,7 +709,7 @@ var LdapWizard = {
    postInitUserFilter: function() {
        if(LdapWizard.userFilterObjectClassesHasRun
           && LdapWizard.userFilterAvailableGroupsHasRun) {
-           LdapWizard.composeFilter('user');
+           LdapWizard.userFilter.compose();
            LdapWizard.countUsers();
        }
    },
@@ -682,12 +783,14 @@ var LdapWizard = {
                    && !$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
                    LdapWizard['toggleRaw'+subject+'Filter']();
                }
+               LdapWizard.userFilterModeWasDetermined = true;
            },
            function (result) {
                //on error case get back to default i.e. Assisted
                if(!$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
                    LdapWizard['toggleRaw'+subject+'Filter']();
                }
+               LdapWizard.userFilterModeWasDetermined = true;
            }
        );
    },
@@ -713,7 +816,7 @@ var LdapWizard = {
        LdapWizard._save($('#'+originalObj)[0], $.trim(values));
        if(originalObj == 'ldap_userfilter_objectclass'
           || originalObj == 'ldap_userfilter_groups') {
-           LdapWizard.composeFilter('user');
+           LdapWizard.userFilter.compose();
            //when user filter is changed afterwards, login filter needs to
            //be adjusted, too
            LdapWizard.composeFilter('login');
@@ -777,7 +880,7 @@ var LdapWizard = {
            LdapWizard._save({ id: modeKey }, LdapWizard.filterModeAssisted);
            if(moc.indexOf('user') >= 0) {
                LdapWizard.blacklistRemove('ldap_userlist_filter');
-               LdapWizard.composeFilter('user');
+               LdapWizard.userFilter.compose();
            } else {
                LdapWizard.blacklistRemove('ldap_group_filter');
                LdapWizard.composeFilter('group');

It is not the full solution, but should solve overwriting of the user filter. I will complete it when I know I works this way.

@sshipway
Copy link
Author

I’ll give it a go. The problem only pops up sometimes – since I’m doing evaluation I was making a lot of changes to the LDAP – so it will be hard to say for sure if the change fixes it, but I’ll make a number of changes and go in and out of the pages and see what happens.

Since our LDAP is very big (tens of thousands of users and thousands of groups) I’ve had to add filters to restrict the groups and users loaded, plus patch the loading functions to load in chunks of 500 rather than 30 (my test subset is <500 users) as otherwise the loading works weirdly due to LDAP not returning users alphabetically. When the bug wipes out the ldap filter, it causes everything to hang as it attempts to load the entire userbase or list of groups in one go and times out; the only fix is to add the filters to the database table manually and restart.

I’ll let you know after I’ve installed it and run some tests.

Steve


Steve Shipway

ITS Unix Services Design Lead

University of Auckland, New Zealand

Floor 1, 58 Symonds Street, Auckland

Phone: +64 (0)9 3737599 ext 86487

DDI: +64 (0)9 923 6487

Mobile: +64 (0)21 753 189

Email: mailto:s.shipway@auckland.ac.nz s.shipway@auckland.ac.nz

P Please consider the environment before printing this e-mail : 打印本邮件,将减少一棵树存活的机会

From: blizzz [mailto:notifications@github.com]
Sent: Wednesday, 15 January 2014 1:42 a.m.
To: owncloud/core
Cc: Steve Shipway
Subject: Re: [core] LDAP raw user filter gets reset when in admin page (#6651)

@sshipway https://github.com/sshipway could you apply following patch and observer whether this behaviour still occurs?

diff --git a/apps/user_ldap/js/settings.js b/apps/user_ldap/js/settings.js
index acf88ef..8098967 100644
--- a/apps/user_ldap/js/settings.js
+++ b/apps/user_ldap/js/settings.js
@@ -138,6 +138,105 @@ var LdapConfiguration = {
}
};

+// LdapFilter object.
+
+function LdapFilter(target) {

  • this.locked = true;
  • this.target = false;
  • this.mode = LdapWizard.filterModeAssisted;
  • this.lazyRunCompose = false;
  • if( target === 'User' ||
  •   target === 'Login' ||
    
  •   target === 'Group') {
    
  •   this.target = target;
    
  •   this.determineMode();
    
  • }
    +}

+LdapFilter.prototype.compose = function() {

  • if(this.locked) {
  •   this.lazyRunCompose = true;
    
  •   return false;
    
  • }
  • if(this.target === 'User') {
  •   action = 'getUserListFilter';
    
  • } else if(this.target === 'Login') {
  •   action = 'getUserLoginFilter';
    
  • } else if(this.target === 'Group') {
  •   action = 'getGroupFilter';
    
  • }
  • if(!$('#raw'+this.target+'FilterContainer').hasClass('invisible')) {
  •   //Raw filter editing, i.e. user defined filter, don't compose
    
  •   return;
    
  • }
  • param = 'action='+action+
  •       '&ldap_serverconfig_chooser='+
    
  •       encodeURIComponent($('#ldap_serverconfig_chooser').val());
    
  • filter = this;
  • LdapWizard.ajax(param,
  •   function(result) {
    
  •       LdapWizard.applyChanges(result);
    
  •       if(filter.target === 'User') {
    
  •           LdapWizard.countUsers();
    
  •       } else if(filter.target === 'Group') {
    
  •           LdapWizard.countGroups();
    
  •           LdapWizard.detectGroupMemberAssoc();
    
  •       }
    
  •   },
    
  •   function (result) {
    
  •       // error handling
    
  •   }
    
  • );
    +}

+LdapFilter.prototype.determineMode = function() {

  • param = 'action=get'+encodeURIComponent(this.target)+'FilterMode'+
  •       '&ldap_serverconfig_chooser='+
    
  •       encodeURIComponent($('#ldap_serverconfig_chooser').val());
    
  • filter = this;
  • LdapWizard.ajax(param,
  •   function(result) {
    
  •       property = 'ldap' + filter.target + 'FilterMode';
    
  •       filter.mode = result.changes[property];
    
  •       if(filter.mode == LdapWizard.filterModeRaw
    
  •           && $('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
    
  •           LdapWizard['toggleRaw'+filter.target+'Filter']();
    
  •       } else if(filter.mode == LdapWizard.filterModeAssisted
    
  •           && !$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
    
  •           LdapWizard['toggleRaw'+filter.target+'Filter']();
    
  •       }
    
  •       filter.unlock();
    
  •   },
    
  •   function (result) {
    
  •       //on error case get back to default i.e. Assisted
    
  •       if(!$('#raw'+filter.target+'FilterContainer').hasClass('invisible')) {
    
  •           LdapWizard['toggleRaw'+filter.target+'Filter']();
    
  •           filter.mode = LdapWizard.filterModeAssisted;
    
  •       }
    
  •       filter.unlock();
    
  •   }
    
  • );

+}
+
+LdapFilter.prototype.unlock = function() {

  • this.locked = false;
  • if(this.lazyRunCompose) {
  •   this.lazyRunCompose = false;
    
  •   this.composeFilter();
    
  • }
    +}

+// end of LdapFilter object.
+
var LdapWizard = {
checkPortInfoShown: false,
saveBlacklist: {},
@@ -145,6 +244,7 @@ var LdapWizard = {
spinner: '',
filterModeAssisted: 0,
filterModeRaw: 1,

  • userFilter: false,

ajax: function(param, fnOnSuccess, fnOnError) {
$.post(
@@ -600,7 +700,8 @@ var LdapWizard = {
initUserFilter: function() {
LdapWizard.userFilterObjectClassesHasRun = false;
LdapWizard.userFilterAvailableGroupsHasRun = false;

  •   LdapWizard.regardFilterMode('User');
    
  •   LdapWizard.userFilterModeWasDetermined = false,
    
  •   LdapWizard.userFilter = new LdapFilter('User');
    LdapWizard.findObjectClasses('ldap_userfilter_objectclass', 'User');
    LdapWizard.findAvailableGroups('ldap_userfilter_groups', 'Users');
    
    },
    @@ -608,7 +709,7 @@ var LdapWizard = {
    postInitUserFilter: function() {
    if(LdapWizard.userFilterObjectClassesHasRun
    && LdapWizard.userFilterAvailableGroupsHasRun) {
  •       LdapWizard.composeFilter('user');
    
  •       LdapWizard.userFilter.compose();
        LdapWizard.countUsers();
    }
    
    },
    @@ -682,12 +783,14 @@ var LdapWizard = {
    && !$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
    LdapWizard'toggleRaw'+subject+'Filter';
    }
  •           LdapWizard.userFilterModeWasDetermined = true;
        },
        function (result) {
            //on error case get back to default i.e. Assisted
            if(!$('#raw'+subject+'FilterContainer').hasClass('invisible')) {
                LdapWizard['toggleRaw'+subject+'Filter']();
            }
    
  •           LdapWizard.userFilterModeWasDetermined = true;
        }
    );
    
    },
    @@ -713,7 +816,7 @@ var LdapWizard = {
    LdapWizard._save($('#'+originalObj)[0], $.trim(values));
    if(originalObj == 'ldap_userfilter_objectclass'
    || originalObj == 'ldap_userfilter_groups') {
  •       LdapWizard.composeFilter('user');
    
  •       LdapWizard.userFilter.compose();
        //when user filter is changed afterwards, login filter needs to
        //be adjusted, too
        LdapWizard.composeFilter('login');
    
    @@ -777,7 +880,7 @@ var LdapWizard = {
    LdapWizard._save({ id: modeKey }, LdapWizard.filterModeAssisted);
    if(moc.indexOf('user') >= 0) {
    LdapWizard.blacklistRemove('ldap_userlist_filter');
  •           LdapWizard.composeFilter('user');
    
  •           LdapWizard.userFilter.compose();
        } else {
            LdapWizard.blacklistRemove('ldap_group_filter');
            LdapWizard.composeFilter('group');
    

It is not the full solution, but should solve overwriting of the user filter. I will complete it when I know I works this way.


Reply to this email directly or view it on GitHub #6651 (comment) . https://github.com/notifications/beacon/1400897__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcwNTIzNjEwNCwiZGF0YSI6eyJpZCI6MjMwMTc0Njh9fQ==--0275c1f594d5a57954c470e005b7099d2a041151.gif

@blizzz
Copy link
Contributor

blizzz commented Feb 7, 2014

@sshipway after some days have passed, how does it look like?

@sshipway
Copy link
Author

sshipway commented Feb 9, 2014

After the patch, I have not experienced the problem again, so it may well have fixed it.

Of course, the problem only appears when the LDAP settings are being viewed or updated, which is not a frequent occurrence, so I suppose it may still be there. It’s a difficult thing to test definitively.

Thanks,

Steve

Steve Shipway

s.shipway@auckland.ac.nz

@blizzz
Copy link
Contributor

blizzz commented Feb 10, 2014

OK, thank you. Good enough for me, I will follow it as it will also improve the code.

@integras
Copy link

I can cautiously support your analysis. I have done exactly the same upgrade on a second host with exactly the same versions (synology hardware and DSM version, owncloud version from 5.0.14a to 6.0.1).

On one instance everything works fine, on the other one i have a problem. The only difference I can see is that on one machine i looked into the LDAP settings (but without changing them), on the other not.

Now the question is: how can I look into the working one to see what I have configured without breaking that one too? ;-)

@integras
Copy link

Ok, I configured it again. For the record of those who need to do it on a synology diskstation

Setup the LDAP interface in:
admin -> Admin, enter host, BaseDN, UserDN and password as defined during LDAP setup

For synology DSM LDAP server select the following (wait until selection becomes accessible and then tick the entries in the dropdown lists):
User List: inetOrPerson
Login List: displayName
Group List: poosixGroup

The following is needed, if the certificate is self-signed (no, you should not do this, get a decent certificate):
Advanced Settings -> Turn off SSL certificate validation = on

To make groups work:
Advanced Settings -> Group-Member association = memberUid

@heavymanto
Copy link

I have make 2 test.

  1. Remove oc6.0.1 after update from oc6.0.0 and reintall oc6.0.1 from new, with drop of database. LDAP work fine

  2. Rollback from backup to oc6.0.0. LDAP Not work. I have see LDAP is already conf. I have remove configuration by buttom "delete", Now i have reconfig and it have found base DC and user but it said "wrong config" and i not see user in user panel.

You have a script to delete all config LDAP in the database? I think that there is same error in config table

screenshot 275
screenshot 276

@ben-denham
Copy link
Member

We were experiencing the same issue with the login filter field.

I could also repeat the issue with the user filter field, but after applying the patch (with a couple of minor alterations), the user filter field was no longer being reset.

I have made a pull request (#7469) that incorporates @blizz's patch with a few more alterations so that it works for all of the filter fields (user, login, and group).

@blizzz
Copy link
Contributor

blizzz commented Feb 28, 2014

@ben-denham the patch is part of the story, I am working on a more complete solution, but was distracted recently unfortunately. But the smaller is maybe the better approach for the stable6-series. I'll have a look on your PR.

ben-denham pushed a commit to ben-denham/core that referenced this issue Mar 6, 2014
…to stop filter settings from being reset under a race condition.
@blizzz
Copy link
Contributor

blizzz commented Mar 12, 2014

Thanks to @ben-denham for the short-cut, those who are already plagued by this bug can try the solution in #7469

ben-denham pushed a commit that referenced this issue Apr 23, 2014
Added improved version of patch by @blizzz in #6651 (comment) to stop filter settings from being reset under a race condition.

Moved LdapFilter into a separate js file in user_ldap.

Changed conditions in user_ldap's ldapFilter.js to use ===, fixed indentation.

fix comparison in determineMode, fixes problems with restoring the filter mode (assisted or manually) on page refresh

Give hint when composing filter failed

fixing some JSHint warnings
@blizzz
Copy link
Contributor

blizzz commented Apr 23, 2014

Fixed with #8164

@blizzz blizzz closed this as completed Apr 23, 2014
DeepDiver1975 pushed a commit to owncloud/user_ldap that referenced this issue Sep 6, 2016
…ment) to stop filter settings from being reset under a race condition.
@lock lock bot locked as resolved and limited conversation to collaborators Aug 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants